Skip to content

Commit

Permalink
Merge pull request #1820 from lixun910/fix_197
Browse files Browse the repository at this point in the history
Fix for version 201
  • Loading branch information
lixun910 committed Feb 21, 2019
2 parents 1df6808 + d4b8550 commit b64313a
Show file tree
Hide file tree
Showing 21 changed files with 1,624 additions and 1,511 deletions.
5 changes: 3 additions & 2 deletions DataViewer/DataViewerAddColDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,9 @@ void DataViewerAddColDlg::OnOkClick( wxCommandEvent& ev )

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

wxLogMessage(wxString::Format(_("Inserting new column %s into Table"),
colname));
//wxString log_msg = wxString::Format(_("Inserting new column %s into Table"),
//colname);
//wxLogMessage(log_msg);

bool success;
if (fixed_lengths) {
Expand Down
64 changes: 42 additions & 22 deletions DataViewer/OGRColumn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ OGRColumnInteger::OGRColumnInteger(wxString name, int field_length, int decimals
undef_markers.resize(rows);
for (int i=0; i<rows; ++i) {
new_data[i] = 0;
undef_markers[i] = false;
undef_markers[i] = true;
}
}

Expand All @@ -303,7 +303,7 @@ OGRColumnInteger::OGRColumnInteger(OGRLayerProxy* ogr_layer, wxString name,
undef_markers.resize(rows);
for (int i=0; i<rows; ++i) {
new_data[i] = 0;
undef_markers[i] = false;
undef_markers[i] = true;
}
}

Expand Down Expand Up @@ -467,8 +467,8 @@ void OGRColumnInteger::SetValueAt(int row_idx, const wxString &value,
}

wxInt64 l_val;
if ( GenUtils::validInt(value) ) {
GenUtils::strToInt64(value, &l_val);

if (value.ToLongLong(&l_val)) {
if (is_new) {
new_data[row_idx] = l_val;
} else {
Expand Down Expand Up @@ -741,7 +741,7 @@ OGRColumnString::OGRColumnString(wxString name, int field_length,
undef_markers.resize(rows);
for (int i=0; i<rows; ++i) {
new_data[i] = wxEmptyString;
undef_markers[i] = false;
undef_markers[i] = true;
}
}
OGRColumnString::OGRColumnString(OGRLayerProxy* ogr_layer, wxString name,
Expand All @@ -754,7 +754,7 @@ OGRColumnString::OGRColumnString(OGRLayerProxy* ogr_layer, wxString name,
undef_markers.resize(rows);
for (int i=0; i<rows; ++i) {
new_data[i] = wxEmptyString;
undef_markers[i] = false;
undef_markers[i] = true;
}
}

Expand Down Expand Up @@ -787,9 +787,6 @@ void OGRColumnString::FillData(vector<double>& data)
for (int i=0; i<rows; ++i) {
double val = 0.0;
if ( !new_data[i].ToDouble(&val) ) {
// internal is always local "C"
//wxString error_msg = wxString::Format( "Fill data error: can't convert '%s' to floating-point number.", new_data[i]);
//throw GdaException(error_msg.c_str());
undef_markers[i] = true;
}
data[i] = val;
Expand All @@ -798,35 +795,44 @@ void OGRColumnString::FillData(vector<double>& data)
} else {
int col_idx = GetColIndex();
wxString tmp;

// default C locale
char *old_locale, *saved_locale = 0;

for (int i=0; i<rows; ++i) {
if ( undef_markers[i] == true) {
data[i] = 0.0;
continue;
}

tmp = wxString(ogr_layer->data[i]->GetFieldAsString(col_idx));

double val;
if (tmp.IsEmpty()) {
data[i] = 0.0;
undef_markers[i] = true;
} else if (tmp.ToDouble(&val)) {
data[i] = val;
} else {
// try comma as decimal point
setlocale(LC_NUMERIC, "de_DE");
// try to use different locale
if (i==0) {
// get name of current locale
old_locale = setlocale(LC_NUMERIC, NULL);
// Copy the name so it won’t be clobbered by setlocale
saved_locale = strdup (old_locale);
// try comma as decimal point
setlocale(LC_NUMERIC, "de_DE");
}
double _val;
if (tmp.ToDouble(&_val)) {
data[i] = _val;
} else {
data[i] = 0.0;
undef_markers[i] = true;
}
setlocale(LC_NUMERIC, "C");
}
}
if (saved_locale) {
// restore locale
setlocale(LC_NUMERIC, saved_locale);
free(saved_locale);
}
}
}

Expand Down Expand Up @@ -855,14 +861,13 @@ void OGRColumnString::FillData(vector<wxInt64> &data)
int col_idx = GetColIndex();
bool conv_success = true;
wxString tmp;

// default C locale
char *old_locale, *saved_locale = 0;

for (int i=0; i<rows; ++i) {
if ( undef_markers[i] == true) {
data[i] = 0;
continue;
}

tmp = wxString(ogr_layer->data[i]->GetFieldAsString(col_idx));
wxInt64 val;
double val_d;
Expand All @@ -879,7 +884,15 @@ void OGRColumnString::FillData(vector<wxInt64> &data)
data[i] = val;

} else {
setlocale(LC_NUMERIC, "de_DE");
// try to use different locale
if (i==0) {
// get name of current locale
old_locale = setlocale(LC_NUMERIC, NULL);
// Copy the name so it won’t be clobbered by setlocale
saved_locale = strdup (old_locale);
// try comma as decimal point
setlocale(LC_NUMERIC, "de_DE");
}
wxInt64 val_;
double val_d_;
if (tmp.ToLongLong(&val_)) {
Expand All @@ -893,9 +906,13 @@ void OGRColumnString::FillData(vector<wxInt64> &data)
data[i] = 0;
undef_markers[i] = true;
}
setlocale(LC_NUMERIC, "C");
}
}
if (saved_locale) {
// restore locale
setlocale(LC_NUMERIC, saved_locale);
free(saved_locale);
}
}
}

Expand Down Expand Up @@ -1074,7 +1091,10 @@ void OGRColumnString::SetValueAt(int row_idx, const wxString &value,
new_data[row_idx] = value;
} else {
int col_idx = GetColIndex();
ogr_layer->data[row_idx]->SetField(col_idx, value.mb_str(*m_wx_encoding));
if (m_wx_encoding)
ogr_layer->data[row_idx]->SetField(col_idx, value.mb_str(*m_wx_encoding));
else
ogr_layer->data[row_idx]->SetField(col_idx, value.mb_str());
}
undef_markers[row_idx] = false;
}
Expand Down
2 changes: 1 addition & 1 deletion DataViewer/TableBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ void TableBase::update(TableState* o)
BOOST_FOREACH(const TableDeltaEntry& e, o->GetTableDeltaListRef()) {
if (e.insert) {
if (e.type == GdaConst::long64_type) {
GetView()->SetColFormatNumber(e.pos_final);
// leave as a string: for more than 10 digts 64-bit number
} else if (e.type == GdaConst::double_type) {
int dd = e.displayed_decimals;
if (dd == -1) dd = e.decimals;
Expand Down
31 changes: 9 additions & 22 deletions DataViewer/TableFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,42 +106,30 @@ TableFrame::TableFrame(wxFrame *parent, Project* project,
for (int i=0, iend=table_base->GetNumberCols(); i<iend; i++) {
double cur_col_size = grid->GetColSize(i);
double cur_lbl_len = grid->GetColLabelValue(i).length();
double avg_cell_len = 0;
double max_cell_len = 0;
for (int j=0; j<sample-1; ++j) {
wxString cv = grid->GetCellValue(j, i);
cv.Trim(true);
cv.Trim(false);
avg_cell_len += cv.length();
if (cv.length() > max_cell_len) max_cell_len = cv.length();
}
if (sample >= 1) { // sample last row
wxString txt = grid->GetCellValue(table_base->GetNumberRows()-1, i);
avg_cell_len += txt.length();
}
avg_cell_len /= (double) sample;
if (avg_cell_len > cur_lbl_len &&
avg_cell_len >= 1 && cur_lbl_len >= 1) {
if (max_cell_len > cur_lbl_len &&
max_cell_len >= 1 && cur_lbl_len >= 1) {
// attempt to scale up col width based on cur_col_size
double fac = avg_cell_len / cur_lbl_len;
fac *= 1.2;
double fac = max_cell_len / cur_lbl_len;
if (fac < 1) fac = 1;
if (fac < 1.5 && fac > 1) fac = 1.5;
if (fac > 5) fac = 5;
grid->SetColMinimalWidth(i, cur_col_size*fac);
grid->SetColSize(i, cur_col_size*fac);
fac = fac * 1.2;
grid->SetColMinimalWidth(i, cur_col_size * fac);
grid->SetColSize(i, cur_col_size * fac);
} else {
// add a few pixels of buffer to current label
grid->SetColMinimalWidth(i, cur_col_size+6);
grid->SetColSize(i, cur_col_size+6);
}
}

//if (!project->IsFileDataSource()) {
// grid->DisableDragColMove();
//}

//grid->SetMargins(0 - wxSYS_VSCROLL_X, 0);
grid->ForceRefresh();

wxBoxSizer *box = new wxBoxSizer(wxVERTICAL);
box->Add(grid, 1, wxEXPAND | wxALL, 0);
panel->SetSizerAndFit(box);
Expand Down Expand Up @@ -223,7 +211,6 @@ void TableFrame::OnMenuClose(wxCommandEvent& event)
void TableFrame::MapMenus()
{
// Map Default Options Menus
//wxMenu* optMenu=wxXmlResource::Get()->LoadMenu("ID_DEFAULT_MENU_OPTIONS");
wxMenu* optMenu=wxXmlResource::Get()->LoadMenu("ID_TABLE_VIEW_MENU_CONTEXT");
GeneralWxUtils::ReplaceMenu(GdaFrame::GetGdaFrame()->GetMenuBar(), _("Options"), optMenu);
}
Expand Down
36 changes: 33 additions & 3 deletions DialogTools/CreatingWeightDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ w_man_int(project_s->GetWManInt()),
w_man_state(project_s->GetWManState()),
m_num_obs(project_s->GetNumRecords()),
m_cbx_precision_threshold_first_click(true),
suspend_table_state_updates(false)
suspend_table_state_updates(false),
is_table_only(project_s->IsTableOnlyProject())
{
wxLogMessage("Open CreatingWeightDlg");
Create(parent, id, caption, pos, size, style);
Expand Down Expand Up @@ -219,13 +220,37 @@ void CreatingWeightDlg::CreateControls()
m_power->Enable(false);
m_power_knn->Enable(false);

m_nb_distance_variables->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED, &CreatingWeightDlg::OnDistanceWeightsInputUpdate, this);
m_nb_weights_type->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED,
&CreatingWeightDlg::OnWeightTypeSelect, this);
m_nb_distance_variables->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED,
&CreatingWeightDlg::OnWeightVariableSelect, this);
m_nb_distance_variables->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED,
&CreatingWeightDlg::OnDistanceWeightsInputUpdate, this);
m_Vars->Bind(wxEVT_LISTBOX, &CreatingWeightDlg::OnDistanceWeightsVarsSel, this);
m_dist_choice_vars->Bind(wxEVT_CHOICE, &CreatingWeightDlg::OnDistanceMetricVarsSel, this);
m_trans_choice_vars->Bind(wxEVT_CHOICE, &CreatingWeightDlg::OnDistanceMetricVarsSel, this);
InitDlg();
}

void CreatingWeightDlg::OnWeightTypeSelect( wxCommandEvent& event )
{
int sel = event.GetSelection();
if (is_table_only && sel == 0) {
// force to "distance weight"
m_nb_weights_type->SetSelection(1);
m_nb_distance_variables->SetSelection(1);
}
}

void CreatingWeightDlg::OnWeightVariableSelect( wxCommandEvent& event )
{
int sel = event.GetSelection();
if (is_table_only && sel == 0) {
// force to "distance weight"
m_nb_distance_variables->SetSelection(1);
}
}

void CreatingWeightDlg::OnDistanceMetricVarsSel( wxCommandEvent& event )
{
int metric = m_dist_choice_vars->GetSelection();
Expand Down Expand Up @@ -964,7 +989,12 @@ void CreatingWeightDlg::InitDlg()
FindWindow(XRCID("IDC_STATIC_YCOORD_VAR"))->Hide();
m_nb_distance_variables->Hide();
}


if (is_table_only) {
// force to "distance weight"
m_nb_weights_type->SetSelection(1);
m_nb_distance_variables->SetSelection(1);
}
Refresh();
}

Expand Down
4 changes: 3 additions & 1 deletion DialogTools/CreatingWeightDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public TableStateObserver, public WeightsManStateObserver
void OnDistanceWeightsInputUpdate( wxBookCtrlEvent& event );
void OnDistanceWeightsVarsSel( wxCommandEvent& event );
void OnDistanceMetricVarsSel( wxCommandEvent& event );
void OnWeightTypeSelect( wxCommandEvent& event );
void OnWeightVariableSelect( wxCommandEvent& event );
/** Implementation of FramesManagerObserver interface */
virtual void update(FramesManager* o);

Expand Down Expand Up @@ -165,7 +167,7 @@ public TableStateObserver, public WeightsManStateObserver
TableState* table_state;
WeightsManState* w_man_state;
WeightsManInterface* w_man_int;

bool is_table_only;
bool user_xy;
// col_id_map[i] is a map from the i'th numeric item in the
// fields drop-down to the actual col_id_map. Items
Expand Down
5 changes: 3 additions & 2 deletions DialogTools/CsvFieldConfDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,9 @@ CsvFieldConfDlg::CsvFieldConfDlg(wxWindow* parent,

fieldGrid->Connect(wxEVT_COMMAND_COMBOBOX_SELECTED,
wxCommandEventHandler(CsvFieldConfDlg::OnFieldSelected),
NULL,
this);
NULL, this);
// hide locale button, since it will be handled in Table directly
btn_locale->Hide();
}

CsvFieldConfDlg::~CsvFieldConfDlg()
Expand Down
14 changes: 5 additions & 9 deletions DialogTools/LocaleSetupDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ LocaleSetupDlg::LocaleSetupDlg(wxWindow* parent,
m_txt_decimal = XRCCTRL(*this, "IDC_FIELD_DECIMAL",wxTextCtrl);
m_txt_thousands->SetMaxLength(1);
m_txt_decimal->SetMaxLength(1);
wxString thousands_sep = CPLGetConfigOption("GDAL_LOCALE_SEPARATOR", "");
wxString decimal_point = CPLGetConfigOption("GDAL_LOCALE_DECIMAL", "");

struct lconv *poLconv = localeconv();
wxString thousands_sep = poLconv->thousands_sep;
wxString decimal_point = poLconv->decimal_point;

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

setlocale(LC_ALL, "");
struct lconv *poLconv = localeconv();
CPLSetConfigOption("GDAL_LOCALE_SEPARATOR", poLconv->thousands_sep);
CPLSetConfigOption("GDAL_LOCALE_DECIMAL", poLconv->decimal_point);
// forcing to C locale, which is used internally in GeoDa
setlocale(LC_ALL, "C");

struct lconv *poLconv = localeconv();
wxString thousands_sep = poLconv->thousands_sep;
wxString decimal_point = poLconv->decimal_point;

Expand Down
Loading

0 comments on commit b64313a

Please sign in to comment.