Skip to content

Commit dee1592

Browse files
authored
Merge pull request #1901 from lixun910/fix_201
V241
2 parents 5e1403a + e2c9032 commit dee1592

File tree

18 files changed

+5099
-4897
lines changed

18 files changed

+5099
-4897
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*.gal
66
*.pyc
77

8+
.vscode/
89
deps/
910

1011
swig/*.gwt

BuildTools/macosx/GNUmakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ build-geoda-mac:
130130
install_name_tool -change "$(GEODA_HOME)/libraries/lib/libspatialite.5.dylib" "@executable_path/../Resources/plugins/libspatialite.5.dylib" build/GeoDa.app/Contents/Resources/plugins/libgdal.20.dylib
131131
install_name_tool -change "$(GEODA_HOME)/libraries/lib/libfreexl.1.dylib" "@executable_path/../Resources/plugins/libfreexl.1.dylib" build/GeoDa.app/Contents/Resources/plugins/libgdal.20.dylib
132132
install_name_tool -change "$(GEODA_HOME)/libraries/lib/libproj.0.dylib" "@executable_path/../Resources/plugins/libproj.0.dylib" build/GeoDa.app/Contents/Resources/plugins/libgdal.20.dylib
133+
install_name_tool -change "/usr/local/opt/openssl/lib/libssl.1.0.0.dylib" "@executable_path/../Resources/plugins/libssl.1.0.0.dylib" build/GeoDa.app/Contents/Resources/plugins/libgdal.20.dylib
134+
install_name_tool -change "/usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib" "@executable_path/../Resources/plugins/libcrypto.1.0.0.dylib" build/GeoDa.app/Contents/Resources/plugins/libgdal.20.dylib
133135
install_name_tool -change "$(GEODA_HOME)/libraries/lib/libsqlite3.0.dylib" "@executable_path/../Resources/plugins/libsqlite3.0.dylib" build/GeoDa.app/Contents/Resources/plugins/libgdal.20.dylib
134136
install_name_tool -change "$(GEODA_HOME)/libraries/lib/libgeos_c.1.dylib" "@executable_path/../Resources/plugins/libgeos_c.1.dylib" build/GeoDa.app/Contents/Resources/plugins/libgdal.20.dylib
135137
install_name_tool -change "$(GEODA_HOME)/libraries/lib/libgeos-3.3.8.dylib" "@executable_path/../Resources/plugins/libgeos-3.3.8.dylib" build/GeoDa.app/Contents/Resources/plugins/libgdal.20.dylib

BuildTools/ubuntu/create_deb_18.04.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fi
3939

4040
rm -f *.deb
4141
if [ $# -ne 1 ]; then
42-
dpkg -b product/ geoda_1.12-1xenial1.deb
42+
dpkg -b product/ geoda_1.12-1bionic1.deb
4343
else
4444
dpkg -b product/ geoda_1.12-1$1.deb
4545
fi

BuildTools/ubuntu/package/DEBIAN/control1804

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: geoda
2-
Version: 1.12-1xenial1
2+
Version: 1.12-1bionic1
33
Architecture: amd64
44
Priority: optional
55
Section: graphics

DataViewer/OGRColumn.cpp

Lines changed: 45 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
*/
1919

20+
#include <string.h>
2021
#include <istream>
2122
#include <time.h>
2223
#include <sstream>
@@ -30,7 +31,7 @@
3031
#include <wx/numformatter.h>
3132

3233
#include "../GenUtils.h"
33-
#include "../GeoDa.h"
34+
//#include "../GeoDa.h"
3435
#include "../logger.h"
3536
#include "../ShapeOperations/OGRDataAdapter.h"
3637
#include "../GdaException.h"
@@ -789,135 +790,91 @@ OGRColumnString::~OGRColumnString()
789790
// This column -> vector<double>
790791
void OGRColumnString::FillData(vector<double>& data)
791792
{
793+
const char* thousand_sep = CPLGetConfigOption("GEODA_LOCALE_SEPARATOR", ",");
794+
const char* decimal_sep = CPLGetConfigOption("GEODA_LOCALE_DECIMAL", ".");
795+
bool use_custom_locale = false;
796+
if ((strlen(thousand_sep) > 0 && strcmp(thousand_sep, ",") != 0) ||
797+
(strlen(decimal_sep) > 0 && strcmp(decimal_sep, ".") != 0)) {
798+
// customized locale numeric
799+
use_custom_locale = true;
800+
}
801+
792802
if (is_new) {
793803
for (int i=0; i<rows; ++i) {
794804
double val = 0.0;
795-
if ( !new_data[i].ToDouble(&val) ) {
796-
undef_markers[i] = true;
805+
if (use_custom_locale) {
806+
new_data[i].Replace(thousand_sep, "");
807+
new_data[i].Replace(decimal_sep, ".");
797808
}
809+
wxNumberFormatter::FromString(new_data[i], &val);
798810
data[i] = val;
799811
}
800812

801813
} else {
802814
int col_idx = GetColIndex();
803815
wxString tmp;
804-
char *old_locale, *saved_locale = 0;
805816

806817
for (int i=0; i<rows; ++i) {
807818
if ( undef_markers[i] == true) {
808819
data[i] = 0.0;
809820
continue;
810821
}
811822
tmp = wxString(ogr_layer->data[i]->GetFieldAsString(col_idx));
812-
double val;
813-
if (tmp.IsEmpty()) {
814-
data[i] = 0.0;
815-
undef_markers[i] = true;
816-
} else if (tmp.ToDouble(&val)) {
817-
data[i] = val;
818-
} else {
819-
// try to use different locale
820-
if (i==0) {
821-
// get name of current locale
822-
old_locale = setlocale(LC_NUMERIC, NULL);
823-
// Copy the name so it won’t be clobbered by setlocale
824-
saved_locale = strdup (old_locale);
825-
// try comma as decimal point
826-
setlocale(LC_NUMERIC, "de_DE");
827-
}
828-
double _val;
829-
if (tmp.ToDouble(&_val)) {
830-
data[i] = _val;
831-
} else {
832-
data[i] = 0.0;
833-
undef_markers[i] = true;
834-
}
823+
824+
if (use_custom_locale) {
825+
tmp.Replace(thousand_sep, "");
826+
tmp.Replace(decimal_sep, ".");
835827
}
836-
}
837-
if (saved_locale) {
838-
// restore locale
839-
setlocale(LC_NUMERIC, saved_locale);
840-
free(saved_locale);
828+
829+
double val = 0.0;
830+
wxNumberFormatter::FromString(tmp, &val);
831+
data[i] = val;
841832
}
842833
}
843834
}
844835

845836
// This column -> vector<wxInt64>
846837
void OGRColumnString::FillData(vector<wxInt64> &data)
847838
{
839+
const char* thousand_sep = CPLGetConfigOption("GEODA_LOCALE_SEPARATOR", ",");
840+
const char* decimal_sep = CPLGetConfigOption("GEODA_LOCALE_DECIMAL", ".");
841+
bool use_custom_locale = false;
842+
if ((strlen(thousand_sep) > 0 && strcmp(thousand_sep, ",") != 0) ||
843+
(strlen(decimal_sep) > 0 && strcmp(decimal_sep, ".") != 0)) {
844+
// customized locale numeric
845+
use_custom_locale = true;
846+
}
847+
848848
if (is_new) {
849849
for (int i=0; i<rows; ++i) {
850850
wxInt64 val = 0;
851-
if (!new_data[i].ToLongLong(&val)) {
852-
//wxString error_msg = wxString::Format("Fill data error: can't convert '%s' to integer number.", new_data[i]);
853-
//throw GdaException(error_msg.mb_str());
854-
double d_val;
855-
if (new_data[i].ToDouble(&d_val)) {
856-
val = static_cast<wxInt64>(d_val);
857-
data[i] = val;
858-
} else {
859-
undef_markers[i] = true;
860-
data[i] = 0;
861-
}
862-
} else {
863-
data[i] = val;
851+
if (use_custom_locale) {
852+
new_data[i].Replace(thousand_sep, "");
853+
new_data[i].Replace(decimal_sep, ".");
864854
}
855+
wxNumberFormatter::FromString(new_data[i], &val);
856+
data[i] = val;
865857
}
866858
} else {
867859
int col_idx = GetColIndex();
868860
bool conv_success = true;
869861
wxString tmp;
870-
char *old_locale, *saved_locale = 0;
871862

872863
for (int i=0; i<rows; ++i) {
873864
if ( undef_markers[i] == true) {
874865
data[i] = 0;
875866
continue;
876867
}
877868
tmp = wxString(ogr_layer->data[i]->GetFieldAsString(col_idx));
878-
wxInt64 val;
879-
double val_d;
880-
881-
if (tmp.IsEmpty()) {
882-
undef_markers[i] = true;
883-
data[i] = 0;
884-
885-
} else if (tmp.ToLongLong(&val)) {
886-
data[i] = val;
887-
888-
} else if (tmp.ToDouble(&val_d)) {
889-
val = static_cast<wxInt64>(val_d);
890-
data[i] = val;
891-
892-
} else {
893-
// try to use different locale
894-
if (i==0) {
895-
// get name of current locale
896-
old_locale = setlocale(LC_NUMERIC, NULL);
897-
// Copy the name so it won’t be clobbered by setlocale
898-
saved_locale = strdup (old_locale);
899-
// try comma as decimal point
900-
setlocale(LC_NUMERIC, "de_DE");
901-
}
902-
wxInt64 val_;
903-
double val_d_;
904-
if (tmp.ToLongLong(&val_)) {
905-
data[i] = val_;
906-
907-
} else if (tmp.ToDouble(&val_d_)) {
908-
val_ = static_cast<wxInt64>(val_d_);
909-
data[i] = val_;
910-
911-
} else {
912-
data[i] = 0;
913-
undef_markers[i] = true;
914-
}
869+
wxInt64 val = 0;
870+
871+
if (use_custom_locale) {
872+
tmp.Replace(thousand_sep, "");
873+
tmp.Replace(decimal_sep, ".");
915874
}
916-
}
917-
if (saved_locale) {
918-
// restore locale
919-
setlocale(LC_NUMERIC, saved_locale);
920-
free(saved_locale);
875+
876+
wxNumberFormatter::FromString(tmp, &val);
877+
data[i] = val;
921878
}
922879
}
923880
}

DataViewer/OGRTable.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,18 @@ bool OGRTable::RenameSimpleCol(int col, int time, const wxString& new_name)
11891189
return true;
11901190
}
11911191

1192-
wxString OGRTable::GetCellString(int row, int col, int time)
1192+
int OGRTable::GetCellStringLength(int row, int col, bool use_disp_decimal)
1193+
{
1194+
int str_length = 0;
1195+
int ts = GetColTimeSteps(col);
1196+
for (int t=0; t<ts; ++t) {
1197+
wxString val = GetCellString(row, col, t, use_disp_decimal);
1198+
if (val.length() > str_length) str_length = val.length();
1199+
}
1200+
return str_length;
1201+
}
1202+
1203+
wxString OGRTable::GetCellString(int row, int col, int time, bool use_disp_decimal)
11931204
{
11941205
// NOTE: if called from wxGrid, must use row_order[row] to permute
11951206
if (row < 0 || row >= rows) return wxEmptyString;
@@ -1198,15 +1209,16 @@ wxString OGRTable::GetCellString(int row, int col, int time)
11981209
cur_type == GdaConst::unknown_type) {
11991210
return wxEmptyString;
12001211
}
1201-
// get display number of decimals
1202-
int disp_dec = GetColDispDecimals(col);
12031212

12041213
// mapping col+time to underneath OGR col
12051214
OGRColumn* ogr_col = FindOGRColumn(col, time);
12061215
if (ogr_col == NULL) {
12071216
return "";
12081217
}
1209-
return ogr_col->GetValueAt(row, disp_dec, m_wx_encoding);
1218+
// get display number of decimals
1219+
int col_dec = GetColDecimals(col, time);
1220+
if (use_disp_decimal) col_dec = GetColDispDecimals(col);
1221+
return ogr_col->GetValueAt(row, col_dec, m_wx_encoding);
12101222
}
12111223

12121224

DataViewer/OGRTable.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,9 @@ class OGRTable : public TableInterface, TableStateObserver
174174
virtual bool ColChangeDisplayedDecimals(int col, int new_disp_dec);
175175
virtual bool RenameGroup(int col, const wxString& new_name);
176176
virtual bool RenameSimpleCol(int col, int time, const wxString& new_name);
177-
virtual wxString GetCellString(int row, int col, int time=0);
178-
virtual bool SetCellFromString(int row, int col, int time,
177+
virtual wxString GetCellString(int row, int col, int time=0, bool use_disp_decimal=false);
178+
virtual int GetCellStringLength(int row, int col, bool use_disp_decimal=true);
179+
virtual bool SetCellFromString(int row, int col, int time,
179180
const wxString &value);
180181
virtual int InsertCol(GdaConst::FieldType type, const wxString& name,
181182
int pos=-1, int time_steps=1,

DataViewer/TableFrame.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,27 +113,18 @@ TableFrame::TableFrame(wxFrame *parent, Project* project,
113113
for (int i=0, iend=table_base->GetNumberCols(); i<iend; i++) {
114114
double cur_col_size = grid->GetColSize(i);
115115
double cur_lbl_len = grid->GetColLabelValue(i).length();
116-
double max_cell_len = 0;
116+
double max_cell_len = cur_lbl_len;
117117
for (int j=0; j<sample-1; ++j) {
118-
wxString cv = grid->GetCellValue(j, i);
119-
cv.Trim(true);
120-
cv.Trim(false);
121-
if (cv.length() > max_cell_len) max_cell_len = cv.length();
122-
}
123-
if (max_cell_len > cur_lbl_len &&
124-
max_cell_len >= 1 && cur_lbl_len >= 1) {
125-
// attempt to scale up col width based on cur_col_size
126-
double fac = max_cell_len / cur_lbl_len;
127-
if (fac < 1) fac = 1;
128-
if (fac > 5) fac = 5;
129-
fac = fac * 1.2;
130-
grid->SetColMinimalWidth(i, cur_col_size);
131-
grid->SetColSize(i, cur_col_size * fac);
132-
} else {
133-
// add a few pixels of buffer to current label
134-
grid->SetColMinimalWidth(i, cur_col_size+6);
135-
grid->SetColSize(i, cur_col_size+6);
118+
//wxString cv = grid->GetCellValue(j, i);
119+
int cv_length = table_int->GetCellStringLength(j,i,true);
120+
if (cv_length > max_cell_len) max_cell_len = cv_length;
136121
}
122+
// width (pixel) per number
123+
double pw = 10;
124+
grid->SetColMinimalWidth(i, cur_lbl_len * pw + 8);
125+
// attempt to scale up col width based on cur_col_size
126+
//double fac = 1.2;
127+
grid->SetColSize(i, max_cell_len * pw);
137128
}
138129
grid->ForceRefresh();
139130

DataViewer/TableInterface.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,10 @@ class TableInterface
226226
const wxString& new_name) = 0;
227227
/** wxGrid will call this function to fill data in displayed part
228228
automatically. Returns formated string (e.g. nummeric numbers) */
229-
virtual wxString GetCellString(int row, int col, int time=0) = 0;
230-
/** Attempts to set the wxGrid cell from a user-entered value. Returns
229+
virtual wxString GetCellString(int row, int col, int time=0, bool use_disp_decimal = false) = 0;
230+
virtual int GetCellStringLength(int row, int col, bool use_disp_decimal=true) = 0;
231+
232+
/** Attempts to set the wxGrid cell from a user-entered value. Returns
231233
true on success. If failured, then IsCellFromStringFail() returns false
232234
and GetSetCellFromStringFailMsg() retuns a meaningful failure message
233235
that can be displayed to the user. */

DialogTools/CreatingWeightDlg.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ bool CreatingWeightDlg::Create(wxWindow* parent, wxWindowID id, const wxString&
159159

160160
SetParent(parent);
161161
CreateControls();
162-
GetSizer()->Fit(this);
163-
GetSizer()->SetSizeHints(this);
162+
//GetSizer()->Fit(this);
163+
//GetSizer()->SetSizeHints(this);
164164
Centre();
165165

166166
return true;
@@ -212,7 +212,15 @@ void CreatingWeightDlg::CreateControls()
212212
m_spinn_inverse_knn = XRCCTRL(*this, "IDC_SPIN_POWER_KNN", wxSpinButton);
213213

214214
m_btn_ok = XRCCTRL(*this, "wxID_OK", wxButton);
215-
215+
216+
wxScrolledWindow* win = wxDynamicCast(FindWindow( XRCID("ID_CREATE_WEIGHT_SCROLL_WIN")), wxScrolledWindow);
217+
218+
win->SetAutoLayout(true);
219+
win->FitInside();
220+
win->SetScrollRate(5, 5);
221+
222+
FitInside();
223+
216224
m_X_time->Show(false);
217225
m_Y_time->Show(false);
218226

0 commit comments

Comments
 (0)