Skip to content

Commit b64313a

Browse files
authored
Merge pull request #1820 from lixun910/fix_197
Fix for version 201
2 parents 1df6808 + d4b8550 commit b64313a

21 files changed

+1624
-1511
lines changed

DataViewer/DataViewerAddColDlg.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,9 @@ void DataViewerAddColDlg::OnOkClick( wxCommandEvent& ev )
358358

359359
int time_steps = 1; // non-space-time column by default
360360

361-
wxLogMessage(wxString::Format(_("Inserting new column %s into Table"),
362-
colname));
361+
//wxString log_msg = wxString::Format(_("Inserting new column %s into Table"),
362+
//colname);
363+
//wxLogMessage(log_msg);
363364

364365
bool success;
365366
if (fixed_lengths) {

DataViewer/OGRColumn.cpp

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ OGRColumnInteger::OGRColumnInteger(wxString name, int field_length, int decimals
289289
undef_markers.resize(rows);
290290
for (int i=0; i<rows; ++i) {
291291
new_data[i] = 0;
292-
undef_markers[i] = false;
292+
undef_markers[i] = true;
293293
}
294294
}
295295

@@ -303,7 +303,7 @@ OGRColumnInteger::OGRColumnInteger(OGRLayerProxy* ogr_layer, wxString name,
303303
undef_markers.resize(rows);
304304
for (int i=0; i<rows; ++i) {
305305
new_data[i] = 0;
306-
undef_markers[i] = false;
306+
undef_markers[i] = true;
307307
}
308308
}
309309

@@ -467,8 +467,8 @@ void OGRColumnInteger::SetValueAt(int row_idx, const wxString &value,
467467
}
468468

469469
wxInt64 l_val;
470-
if ( GenUtils::validInt(value) ) {
471-
GenUtils::strToInt64(value, &l_val);
470+
471+
if (value.ToLongLong(&l_val)) {
472472
if (is_new) {
473473
new_data[row_idx] = l_val;
474474
} else {
@@ -741,7 +741,7 @@ OGRColumnString::OGRColumnString(wxString name, int field_length,
741741
undef_markers.resize(rows);
742742
for (int i=0; i<rows; ++i) {
743743
new_data[i] = wxEmptyString;
744-
undef_markers[i] = false;
744+
undef_markers[i] = true;
745745
}
746746
}
747747
OGRColumnString::OGRColumnString(OGRLayerProxy* ogr_layer, wxString name,
@@ -754,7 +754,7 @@ OGRColumnString::OGRColumnString(OGRLayerProxy* ogr_layer, wxString name,
754754
undef_markers.resize(rows);
755755
for (int i=0; i<rows; ++i) {
756756
new_data[i] = wxEmptyString;
757-
undef_markers[i] = false;
757+
undef_markers[i] = true;
758758
}
759759
}
760760

@@ -787,9 +787,6 @@ void OGRColumnString::FillData(vector<double>& data)
787787
for (int i=0; i<rows; ++i) {
788788
double val = 0.0;
789789
if ( !new_data[i].ToDouble(&val) ) {
790-
// internal is always local "C"
791-
//wxString error_msg = wxString::Format( "Fill data error: can't convert '%s' to floating-point number.", new_data[i]);
792-
//throw GdaException(error_msg.c_str());
793790
undef_markers[i] = true;
794791
}
795792
data[i] = val;
@@ -798,35 +795,44 @@ void OGRColumnString::FillData(vector<double>& data)
798795
} else {
799796
int col_idx = GetColIndex();
800797
wxString tmp;
801-
802-
// default C locale
798+
char *old_locale, *saved_locale = 0;
799+
803800
for (int i=0; i<rows; ++i) {
804801
if ( undef_markers[i] == true) {
805802
data[i] = 0.0;
806803
continue;
807804
}
808-
809805
tmp = wxString(ogr_layer->data[i]->GetFieldAsString(col_idx));
810-
811806
double val;
812807
if (tmp.IsEmpty()) {
813808
data[i] = 0.0;
814809
undef_markers[i] = true;
815810
} else if (tmp.ToDouble(&val)) {
816811
data[i] = val;
817812
} else {
818-
// try comma as decimal point
819-
setlocale(LC_NUMERIC, "de_DE");
813+
// try to use different locale
814+
if (i==0) {
815+
// get name of current locale
816+
old_locale = setlocale(LC_NUMERIC, NULL);
817+
// Copy the name so it won’t be clobbered by setlocale
818+
saved_locale = strdup (old_locale);
819+
// try comma as decimal point
820+
setlocale(LC_NUMERIC, "de_DE");
821+
}
820822
double _val;
821823
if (tmp.ToDouble(&_val)) {
822824
data[i] = _val;
823825
} else {
824826
data[i] = 0.0;
825827
undef_markers[i] = true;
826828
}
827-
setlocale(LC_NUMERIC, "C");
828829
}
829830
}
831+
if (saved_locale) {
832+
// restore locale
833+
setlocale(LC_NUMERIC, saved_locale);
834+
free(saved_locale);
835+
}
830836
}
831837
}
832838

@@ -855,14 +861,13 @@ void OGRColumnString::FillData(vector<wxInt64> &data)
855861
int col_idx = GetColIndex();
856862
bool conv_success = true;
857863
wxString tmp;
858-
859-
// default C locale
864+
char *old_locale, *saved_locale = 0;
865+
860866
for (int i=0; i<rows; ++i) {
861867
if ( undef_markers[i] == true) {
862868
data[i] = 0;
863869
continue;
864870
}
865-
866871
tmp = wxString(ogr_layer->data[i]->GetFieldAsString(col_idx));
867872
wxInt64 val;
868873
double val_d;
@@ -879,7 +884,15 @@ void OGRColumnString::FillData(vector<wxInt64> &data)
879884
data[i] = val;
880885

881886
} else {
882-
setlocale(LC_NUMERIC, "de_DE");
887+
// try to use different locale
888+
if (i==0) {
889+
// get name of current locale
890+
old_locale = setlocale(LC_NUMERIC, NULL);
891+
// Copy the name so it won’t be clobbered by setlocale
892+
saved_locale = strdup (old_locale);
893+
// try comma as decimal point
894+
setlocale(LC_NUMERIC, "de_DE");
895+
}
883896
wxInt64 val_;
884897
double val_d_;
885898
if (tmp.ToLongLong(&val_)) {
@@ -893,9 +906,13 @@ void OGRColumnString::FillData(vector<wxInt64> &data)
893906
data[i] = 0;
894907
undef_markers[i] = true;
895908
}
896-
setlocale(LC_NUMERIC, "C");
897909
}
898910
}
911+
if (saved_locale) {
912+
// restore locale
913+
setlocale(LC_NUMERIC, saved_locale);
914+
free(saved_locale);
915+
}
899916
}
900917
}
901918

@@ -1074,7 +1091,10 @@ void OGRColumnString::SetValueAt(int row_idx, const wxString &value,
10741091
new_data[row_idx] = value;
10751092
} else {
10761093
int col_idx = GetColIndex();
1077-
ogr_layer->data[row_idx]->SetField(col_idx, value.mb_str(*m_wx_encoding));
1094+
if (m_wx_encoding)
1095+
ogr_layer->data[row_idx]->SetField(col_idx, value.mb_str(*m_wx_encoding));
1096+
else
1097+
ogr_layer->data[row_idx]->SetField(col_idx, value.mb_str());
10781098
}
10791099
undef_markers[row_idx] = false;
10801100
}

DataViewer/TableBase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ void TableBase::update(TableState* o)
506506
BOOST_FOREACH(const TableDeltaEntry& e, o->GetTableDeltaListRef()) {
507507
if (e.insert) {
508508
if (e.type == GdaConst::long64_type) {
509-
GetView()->SetColFormatNumber(e.pos_final);
509+
// leave as a string: for more than 10 digts 64-bit number
510510
} else if (e.type == GdaConst::double_type) {
511511
int dd = e.displayed_decimals;
512512
if (dd == -1) dd = e.decimals;

DataViewer/TableFrame.cpp

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -106,42 +106,30 @@ TableFrame::TableFrame(wxFrame *parent, Project* project,
106106
for (int i=0, iend=table_base->GetNumberCols(); i<iend; i++) {
107107
double cur_col_size = grid->GetColSize(i);
108108
double cur_lbl_len = grid->GetColLabelValue(i).length();
109-
double avg_cell_len = 0;
109+
double max_cell_len = 0;
110110
for (int j=0; j<sample-1; ++j) {
111111
wxString cv = grid->GetCellValue(j, i);
112112
cv.Trim(true);
113113
cv.Trim(false);
114-
avg_cell_len += cv.length();
114+
if (cv.length() > max_cell_len) max_cell_len = cv.length();
115115
}
116-
if (sample >= 1) { // sample last row
117-
wxString txt = grid->GetCellValue(table_base->GetNumberRows()-1, i);
118-
avg_cell_len += txt.length();
119-
}
120-
avg_cell_len /= (double) sample;
121-
if (avg_cell_len > cur_lbl_len &&
122-
avg_cell_len >= 1 && cur_lbl_len >= 1) {
116+
if (max_cell_len > cur_lbl_len &&
117+
max_cell_len >= 1 && cur_lbl_len >= 1) {
123118
// attempt to scale up col width based on cur_col_size
124-
double fac = avg_cell_len / cur_lbl_len;
125-
fac *= 1.2;
119+
double fac = max_cell_len / cur_lbl_len;
126120
if (fac < 1) fac = 1;
127-
if (fac < 1.5 && fac > 1) fac = 1.5;
128121
if (fac > 5) fac = 5;
129-
grid->SetColMinimalWidth(i, cur_col_size*fac);
130-
grid->SetColSize(i, cur_col_size*fac);
122+
fac = fac * 1.2;
123+
grid->SetColMinimalWidth(i, cur_col_size * fac);
124+
grid->SetColSize(i, cur_col_size * fac);
131125
} else {
132126
// add a few pixels of buffer to current label
133127
grid->SetColMinimalWidth(i, cur_col_size+6);
134128
grid->SetColSize(i, cur_col_size+6);
135129
}
136130
}
137-
138-
//if (!project->IsFileDataSource()) {
139-
// grid->DisableDragColMove();
140-
//}
141-
142-
//grid->SetMargins(0 - wxSYS_VSCROLL_X, 0);
143131
grid->ForceRefresh();
144-
132+
145133
wxBoxSizer *box = new wxBoxSizer(wxVERTICAL);
146134
box->Add(grid, 1, wxEXPAND | wxALL, 0);
147135
panel->SetSizerAndFit(box);
@@ -223,7 +211,6 @@ void TableFrame::OnMenuClose(wxCommandEvent& event)
223211
void TableFrame::MapMenus()
224212
{
225213
// Map Default Options Menus
226-
//wxMenu* optMenu=wxXmlResource::Get()->LoadMenu("ID_DEFAULT_MENU_OPTIONS");
227214
wxMenu* optMenu=wxXmlResource::Get()->LoadMenu("ID_TABLE_VIEW_MENU_CONTEXT");
228215
GeneralWxUtils::ReplaceMenu(GdaFrame::GetGdaFrame()->GetMenuBar(), _("Options"), optMenu);
229216
}

DialogTools/CreatingWeightDlg.cpp

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ w_man_int(project_s->GetWManInt()),
9797
w_man_state(project_s->GetWManState()),
9898
m_num_obs(project_s->GetNumRecords()),
9999
m_cbx_precision_threshold_first_click(true),
100-
suspend_table_state_updates(false)
100+
suspend_table_state_updates(false),
101+
is_table_only(project_s->IsTableOnlyProject())
101102
{
102103
wxLogMessage("Open CreatingWeightDlg");
103104
Create(parent, id, caption, pos, size, style);
@@ -219,13 +220,37 @@ void CreatingWeightDlg::CreateControls()
219220
m_power->Enable(false);
220221
m_power_knn->Enable(false);
221222

222-
m_nb_distance_variables->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED, &CreatingWeightDlg::OnDistanceWeightsInputUpdate, this);
223+
m_nb_weights_type->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED,
224+
&CreatingWeightDlg::OnWeightTypeSelect, this);
225+
m_nb_distance_variables->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED,
226+
&CreatingWeightDlg::OnWeightVariableSelect, this);
227+
m_nb_distance_variables->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED,
228+
&CreatingWeightDlg::OnDistanceWeightsInputUpdate, this);
223229
m_Vars->Bind(wxEVT_LISTBOX, &CreatingWeightDlg::OnDistanceWeightsVarsSel, this);
224230
m_dist_choice_vars->Bind(wxEVT_CHOICE, &CreatingWeightDlg::OnDistanceMetricVarsSel, this);
225231
m_trans_choice_vars->Bind(wxEVT_CHOICE, &CreatingWeightDlg::OnDistanceMetricVarsSel, this);
226232
InitDlg();
227233
}
228234

235+
void CreatingWeightDlg::OnWeightTypeSelect( wxCommandEvent& event )
236+
{
237+
int sel = event.GetSelection();
238+
if (is_table_only && sel == 0) {
239+
// force to "distance weight"
240+
m_nb_weights_type->SetSelection(1);
241+
m_nb_distance_variables->SetSelection(1);
242+
}
243+
}
244+
245+
void CreatingWeightDlg::OnWeightVariableSelect( wxCommandEvent& event )
246+
{
247+
int sel = event.GetSelection();
248+
if (is_table_only && sel == 0) {
249+
// force to "distance weight"
250+
m_nb_distance_variables->SetSelection(1);
251+
}
252+
}
253+
229254
void CreatingWeightDlg::OnDistanceMetricVarsSel( wxCommandEvent& event )
230255
{
231256
int metric = m_dist_choice_vars->GetSelection();
@@ -964,7 +989,12 @@ void CreatingWeightDlg::InitDlg()
964989
FindWindow(XRCID("IDC_STATIC_YCOORD_VAR"))->Hide();
965990
m_nb_distance_variables->Hide();
966991
}
967-
992+
993+
if (is_table_only) {
994+
// force to "distance weight"
995+
m_nb_weights_type->SetSelection(1);
996+
m_nb_distance_variables->SetSelection(1);
997+
}
968998
Refresh();
969999
}
9701000

DialogTools/CreatingWeightDlg.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ public TableStateObserver, public WeightsManStateObserver
9494
void OnDistanceWeightsInputUpdate( wxBookCtrlEvent& event );
9595
void OnDistanceWeightsVarsSel( wxCommandEvent& event );
9696
void OnDistanceMetricVarsSel( wxCommandEvent& event );
97+
void OnWeightTypeSelect( wxCommandEvent& event );
98+
void OnWeightVariableSelect( wxCommandEvent& event );
9799
/** Implementation of FramesManagerObserver interface */
98100
virtual void update(FramesManager* o);
99101

@@ -165,7 +167,7 @@ public TableStateObserver, public WeightsManStateObserver
165167
TableState* table_state;
166168
WeightsManState* w_man_state;
167169
WeightsManInterface* w_man_int;
168-
170+
bool is_table_only;
169171
bool user_xy;
170172
// col_id_map[i] is a map from the i'th numeric item in the
171173
// fields drop-down to the actual col_id_map. Items

DialogTools/CsvFieldConfDlg.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,9 @@ CsvFieldConfDlg::CsvFieldConfDlg(wxWindow* parent,
212212

213213
fieldGrid->Connect(wxEVT_COMMAND_COMBOBOX_SELECTED,
214214
wxCommandEventHandler(CsvFieldConfDlg::OnFieldSelected),
215-
NULL,
216-
this);
215+
NULL, this);
216+
// hide locale button, since it will be handled in Table directly
217+
btn_locale->Hide();
217218
}
218219

219220
CsvFieldConfDlg::~CsvFieldConfDlg()

DialogTools/LocaleSetupDlg.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ LocaleSetupDlg::LocaleSetupDlg(wxWindow* parent,
5959
m_txt_decimal = XRCCTRL(*this, "IDC_FIELD_DECIMAL",wxTextCtrl);
6060
m_txt_thousands->SetMaxLength(1);
6161
m_txt_decimal->SetMaxLength(1);
62-
wxString thousands_sep = CPLGetConfigOption("GDAL_LOCALE_SEPARATOR", "");
63-
wxString decimal_point = CPLGetConfigOption("GDAL_LOCALE_DECIMAL", "");
62+
63+
struct lconv *poLconv = localeconv();
64+
wxString thousands_sep = poLconv->thousands_sep;
65+
wxString decimal_point = poLconv->decimal_point;
6466

6567
m_txt_thousands->SetValue(thousands_sep);
6668
m_txt_decimal->SetValue(decimal_point);
@@ -74,13 +76,7 @@ void LocaleSetupDlg::OnResetSysLocale( wxCommandEvent& event )
7476
{
7577
wxLogMessage("Click LocaleSetupDlg::OnResetSysLocale");
7678

77-
setlocale(LC_ALL, "");
78-
struct lconv *poLconv = localeconv();
79-
CPLSetConfigOption("GDAL_LOCALE_SEPARATOR", poLconv->thousands_sep);
80-
CPLSetConfigOption("GDAL_LOCALE_DECIMAL", poLconv->decimal_point);
81-
// forcing to C locale, which is used internally in GeoDa
82-
setlocale(LC_ALL, "C");
83-
79+
struct lconv *poLconv = localeconv();
8480
wxString thousands_sep = poLconv->thousands_sep;
8581
wxString decimal_point = poLconv->decimal_point;
8682

0 commit comments

Comments
 (0)