5 Star 22 Fork 10

geoda/geoda_mirror

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
GeneralWxUtils.cpp 22.61 KB
一键复制 编辑 原始数据 按行查看 历史
lixun910 提交于 2020-08-02 23:44 . #2186 fix bug in "Save MST" menu item
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
/**
* GeoDa TM, Copyright (C) 2011-2015 by Luc Anselin - all rights reserved
*
* This file is part of GeoDa.
*
* GeoDa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GeoDa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <wx/tokenzr.h>
#include <wx/filename.h>
#include <wx/platinfo.h>
#include <wx/log.h>
#include <wx/window.h>
#include <wx/xrc/xmlres.h>
#include <wx/wfstream.h>
#include <wx/colordlg.h>
#include <wx/txtstrm.h>
#include "DialogTools/AddIdVariable.h"
#include "GeneralWxUtils.h"
#include "Project.h"
////////////////////////////////////////////////////////////////////////
//
//
////////////////////////////////////////////////////////////////////////
BEGIN_EVENT_TABLE(SimpleReportTextCtrl, wxTextCtrl)
EVT_CONTEXT_MENU(SimpleReportTextCtrl::OnContextMenu)
END_EVENT_TABLE()
void SimpleReportTextCtrl::OnContextMenu(wxContextMenuEvent& event)
{
wxMenu* menu = new wxMenu;
// Some standard items
menu->Append(XRCID("SAVE_SIMPLE_REPORT"), _("Save"));
menu->AppendSeparator();
menu->Append(wxID_UNDO, _("Undo"));
menu->Append(wxID_REDO, _("Redo"));
menu->AppendSeparator();
menu->Append(wxID_CUT, _("Cut"));
menu->Append(wxID_COPY, _("Copy"));
menu->Append(wxID_PASTE, _("Paste"));
menu->Append(wxID_CLEAR, _("Delete"));
menu->AppendSeparator();
menu->Append(wxID_SELECTALL, _("Select All"));
// Add any custom items here
Connect(XRCID("SAVE_SIMPLE_REPORT"), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(SimpleReportTextCtrl::OnSaveClick));
PopupMenu(menu);
}
void SimpleReportTextCtrl::OnSaveClick( wxCommandEvent& event )
{
wxLogMessage("In SimpleReportTextCtrl::OnSaveClick()");
wxFileDialog dlg( this, "Save Results", wxEmptyString,
wxEmptyString,
"TXT files (*.txt)|*.txt",
wxFD_SAVE );
if (dlg.ShowModal() != wxID_OK) return;
wxFileName new_txt_fname(dlg.GetPath());
wxString new_txt = new_txt_fname.GetFullPath();
wxFFileOutputStream output(new_txt);
if (output.IsOk()) {
wxTextOutputStream txt_out( output );
txt_out << this->GetValue();
txt_out.Flush();
output.Close();
}
}
////////////////////////////////////////////////////////////////////////
//
//
////////////////////////////////////////////////////////////////////////
ScrolledDetailMsgDialog::ScrolledDetailMsgDialog(const wxString & title, const wxString & msg, const wxString & details, const wxSize &size, const wxArtID & art_id)
: wxDialog(NULL, wxID_ANY, title, wxDefaultPosition, size, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
wxPanel *panel = new wxPanel(this, -1);
wxBoxSizer *vbox0 = new wxBoxSizer(wxVERTICAL);
wxStaticText *st = new wxStaticText(panel, wxID_ANY, msg, wxDefaultPosition, wxDefaultSize, wxTE_WORDWRAP);
tc = new SimpleReportTextCtrl(panel, XRCID("ID_TEXTCTRL_1"), details, wxDefaultPosition, wxSize(-1, 300));
vbox0->Add(st, 0, wxBOTTOM, 10);
vbox0->Add(tc, 1, wxEXPAND);
wxBoxSizer *hbox0 = new wxBoxSizer(wxHORIZONTAL);
wxBitmap save = wxArtProvider::GetBitmap(wxART_WARNING);
wxStaticBitmap *warn = new wxStaticBitmap(panel, wxID_ANY, save);
hbox0->Add(warn, 0, wxRIGHT, 5);
hbox0->Add(vbox0, 1);
panel->SetSizer(hbox0);
wxBoxSizer *hbox1 = new wxBoxSizer(wxHORIZONTAL);
wxButton *saveButton = new wxButton(this, XRCID("SAVE_DETAILS"), _("Save Details"), wxDefaultPosition, wxSize(130, -1));
wxButton *okButton = new wxButton(this, wxID_OK, _("Ok"), wxDefaultPosition, wxSize(110, -1));
hbox1->Add(saveButton, 1, wxRIGHT, 30);
hbox1->Add(okButton, 1);
Connect(XRCID("SAVE_DETAILS"), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ScrolledDetailMsgDialog::OnSaveClick));
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
vbox->Add(panel, 1, wxEXPAND | wxALL, 20);
vbox->Add(hbox1, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, 10);
SetSizer(vbox);
Centre();
ShowModal();
Destroy();
}
void ScrolledDetailMsgDialog::OnSaveClick( wxCommandEvent& event )
{
wxLogMessage("In ScrolledDetailMsgDialog::OnSaveClick()");
wxFileDialog dlg( this, "Save results", wxEmptyString,
wxEmptyString,
"TXT files (*.txt)|*.txt",
wxFD_SAVE );
if (dlg.ShowModal() != wxID_OK) return;
wxFileName new_txt_fname(dlg.GetPath());
wxString new_txt = new_txt_fname.GetFullPath();
wxFFileOutputStream output(new_txt);
if (output.IsOk()) {
wxTextOutputStream txt_out( output );
txt_out << tc->GetValue();
txt_out.Flush();
output.Close();
}
}
////////////////////////////////////////////////////////////////////////
//
//
////////////////////////////////////////////////////////////////////////
wxOperatingSystemId GeneralWxUtils::GetOsId()
{
static wxOperatingSystemId osId =
wxPlatformInfo::Get().GetOperatingSystemId();
return osId;
}
wxString GeneralWxUtils::LogOsId()
{
wxString oslog;
int os = 0;
if (isMac()) {
os = 1;
} else if (isWindows()) {
os = 2;
} else if (isUnix()) {
os = 3;
}
int majorVsn = 0;
int minorVsn = 0;
wxGetOsVersion(&majorVsn, &minorVsn);
oslog = wxString::Format("\nos: %d-%d-%d", os, majorVsn, minorVsn);
return oslog;
}
bool GeneralWxUtils::isMac()
{
static bool r = (GetOsId() & wxOS_MAC ? true : false);
return r;
}
bool GeneralWxUtils::isMac106()
{
static bool r = (GetOsId() & wxOS_MAC ? true : false);
int majorVsn = 0;
int minorVsn = 0;
wxGetOsVersion(&majorVsn, &minorVsn);
r = r & (minorVsn == 6);
return r;
}
bool GeneralWxUtils::isMac1014plus()
{
static bool r = (GetOsId() & wxOS_MAC ? true : false);
int majorVsn = 0;
int minorVsn = 0;
wxGetOsVersion(&majorVsn, &minorVsn);
r = r & (majorVsn > 10 || minorVsn >= 14);
return r;
}
bool GeneralWxUtils::isWindows()
{
static bool r = (GetOsId() & wxOS_WINDOWS ? true : false);
return r;
}
bool GeneralWxUtils::isUnix()
{
static bool r = (GetOsId() & wxOS_UNIX ? true : false);
return r;
}
bool GeneralWxUtils::isXP()
{
static bool r = (GetOsId() & wxOS_WINDOWS ? true : false);
if (r) {
int majorVsn = 0;
int minorVsn = 0;
wxGetOsVersion(&majorVsn, &minorVsn);
r = r && (majorVsn == 5);
// This includes Windows 2000 (5.0),
// XP (5.1) and Windows Server 2003 (5.3)
}
return r;
}
bool GeneralWxUtils::isVista()
{
static bool r = (GetOsId() & wxOS_WINDOWS ? true : false);
if (r) {
int majorVsn = 0;
int minorVsn = 0;
wxGetOsVersion(&majorVsn, &minorVsn);
r = r && (majorVsn == 6) && (minorVsn == 0);
// This includes Windows Server 2008 and Vista
}
return r;
}
bool GeneralWxUtils::isX86()
{
#if defined(_WIN64) || defined(__amd64__)
return false;
#else
return true;
#endif
}
bool GeneralWxUtils::isX64()
{
return !isX86();
}
bool GeneralWxUtils::isDebug()
{
#if defined(__WXDEBUG__) || defined(DEBUG)
return true;
#else
return false;
#endif
}
bool GeneralWxUtils::isBigEndian()
{
static bool r =
(wxPlatformInfo::Get().GetEndianness() & wxENDIAN_BIG);
return r;
}
bool GeneralWxUtils::isLittleEndian()
{
static bool r =
(wxPlatformInfo::Get().GetEndianness() & wxENDIAN_LITTLE);
return r;
}
/*
* ReplaceMenu: finds MenuBar menu with given title and replaces with newMenu
* additionally, the previous menu is deleted. Returns true on success.
*/
bool GeneralWxUtils::ReplaceMenu(wxMenuBar* mb, const wxString& title,
wxMenu* newMenu)
{
//int menu_count = mb->GetMenuCount();
//LOG(menu_count);
//for (int i=0; i<menu_count; i++) {
// LOG_MSG(mb->GetMenuLabelText(i));
//}
int m_ind = mb->FindMenu(title);
if (m_ind == wxNOT_FOUND) {
delete newMenu;
return false;
}
//wxMenu* prev_opt_menu = mb->GetMenu(m_ind);
//mb->Replace(m_ind, newMenu, title);
wxMenu* prev_opt_menu = mb->Remove(m_ind);
mb->Insert(m_ind, newMenu, title);
// The following line shouldn't be needed, but on wxWidgets 2.9.2, the
// menu label is set to empty after Replace is called.
//mb->SetMenuLabel(m_ind, title);
if (prev_opt_menu) delete prev_opt_menu;
return true;
}
/*
* EnableMenuAll: Given a menubar pointer and top-level menu title,
* this method traverses every menu item in the menu tree (menu items
* include actual clickable menu items and submenus) and either enables
* or disables the item according to the value of bool enable. This
* is useful in situations where one wants to disable everything in
* a menu except for one deeply-nested menu item (see EnableMenuItem).
* Boolean value 'true' is returned iff the top-level menu is found.
* The enable/disable state of the actual top-level menu is not changed.
*/
bool GeneralWxUtils::EnableMenuAll(wxMenuBar* mb, const wxString& title,
bool enable)
{
if (!mb ) return false;
int mPos = mb->FindMenu(title);
if (mPos == wxNOT_FOUND) return false;
wxMenu* menu = mb->GetMenu(mPos);
GeneralWxUtils::EnableMenuRecursive(menu, enable);
return true;
}
/*
* This is intended to be a helper function to EnableMenuAll with
* the menubar argument, but can be called directly on an valid wxMenu.
*/
void GeneralWxUtils::EnableMenuRecursive(wxMenu* menu, bool enable)
{
if (!menu) return;
int cnt = menu->GetMenuItemCount();
for (int i=0; i<cnt; i++) {
wxMenuItem* mItem = menu->FindItemByPosition(i);
//wxString msg("menu item '");
//msg << mItem->GetItemLabelText() << "' enable = " << enable;
//LOG_MSG(msg);
mItem->Enable(enable);
//wxString msg2("menu item '");
//msg2 << mItem->GetItemLabelText() << "' IsEnabled() = ";
//msg2 << mItem->IsEnabled();
//LOG_MSG(msg2);
GeneralWxUtils::EnableMenuRecursive(mItem->GetSubMenu(), enable);
}
}
/*
* EnableMenuItem: This method assumes there are no submenus within
* submenus.
*/
bool GeneralWxUtils::EnableMenuItem(wxMenuBar* mb, const wxString& menuTitle,
int id, bool enable)
{
if (!mb) return false;
wxMenu* menu = NULL;
wxMenuItem* mItem = mb->FindItem(id);
menu=mb->GetMenu(mb->FindMenu(menuTitle));
if (!mItem || !menu) return false;
//LOG_MSG("item title:") + mItem->GetText();
mItem->Enable(enable);
// Check if embedded in a submenu and enable as needed.
wxMenu* subMenu = NULL;
menu->FindItem(id, &subMenu);
if (menu == subMenu) return true;
int menuCnt = menu->GetMenuItemCount();
int subMenuCnt = subMenu->GetMenuItemCount();
int subMenuIndex = wxNOT_FOUND;
int i = 0;
while (subMenuIndex == wxNOT_FOUND && i < menuCnt) {
mItem = menu->FindItemByPosition(i);
if (mItem->IsSubMenu() && mItem->GetSubMenu() == subMenu)
subMenuIndex = i;
i++;
}
if (enable) {
menu->FindItemByPosition(subMenuIndex)->Enable(true);
return true;
}
bool anyEnabled = false;
// Check if there are any other items enabled in the submenu.
for (i = 0; i<subMenuCnt; i++) {
mItem = subMenu->FindItemByPosition(i);
if (!mItem->IsSeparator())
anyEnabled = anyEnabled || mItem->IsEnabled();
}
if (!anyEnabled)
menu->FindItemByPosition(subMenuIndex)->Enable(false);
return true;
}
bool GeneralWxUtils::EnableMenuItem(wxMenuBar* m, int id, bool enable)
{
if (!m) return false;
wxMenuItem* mi = m->FindItem(id);
if (mi) {
mi->Enable(enable);
return true;
}
return false;
}
bool GeneralWxUtils::EnableMenuItem(wxMenu* m, int id, bool enable)
{
if (!m) return false;
wxMenuItem* mi = m->FindItem(id);
if (mi) {
mi->Enable(enable);
return true;
}
return false;
}
bool GeneralWxUtils::CheckMenuItem(wxMenuBar* m, int id, bool check)
{
if (!m) return false;
wxMenuItem* mi = m->FindItem(id);
if (mi && mi->IsCheckable()) {
mi->Check(check);
return true;
}
return false;
}
bool GeneralWxUtils::CheckMenuItem(wxMenu* menu, int id, bool check)
{
if (!menu) return false;
wxMenuItem* mItem = menu->FindItem(id);
if (!mItem) return false;
if (!mItem->IsCheckable()) return false;
mItem->Check(check);
return true;
}
bool GeneralWxUtils::SetMenuItemText(wxMenu* menu, int id,
const wxString& text)
{
if (!menu) return false;
wxMenuItem* mItem = menu->FindItem(id);
if (!mItem) return false;
mItem->SetItemLabel(text);
return true;
}
wxMenu* GeneralWxUtils::FindMenu(wxMenuBar* mb, const wxString& menuTitle)
{
if (!mb) return 0;
int menu = mb->FindMenu(menuTitle);
if (menu == wxNOT_FOUND) return 0;
return mb->GetMenu(menu);
}
wxColour GeneralWxUtils::PickColor(wxWindow *parent, wxColour& col)
{
wxColourData data;
data.SetColour(col);
data.SetChooseFull(true);
int ki;
for (ki = 0; ki < 16; ki++) {
wxColour colour(ki * 16, ki * 16, ki * 16);
data.SetCustomColour(ki, colour);
}
wxColourDialog dialog(parent, &data);
dialog.SetTitle(_("Choose Cateogry Color"));
if (dialog.ShowModal() == wxID_OK) {
wxColourData retData = dialog.GetColourData();
return retData.GetColour();
}
return col;
}
void GeneralWxUtils::SaveWindowAsImage(wxWindow *win, wxString title)
{
//Create a DC for the whole screen area
wxWindowDC dcScreen(win);
//Get the size of the screen/DC
wxCoord screenWidth, screenHeight;
dcScreen.GetSize(&screenWidth, &screenHeight);
//Create a Bitmap that will later on hold the screenshot image
//Note that the Bitmap must have a size big enough to hold the screenshot
//-1 means using the current default colour depth
wxSize new_sz = win->FromDIP(wxSize(screenWidth, screenHeight));
wxBitmap screenshot(new_sz);
//Create a memory DC that will be used for actually taking the screenshot
wxMemoryDC memDC;
//Tell the memory DC to use our Bitmap
//all drawing action on the memory DC will go to the Bitmap now
memDC.SelectObject(screenshot);
//Blit (in this case copy) the actual screen on the memory DC
//and thus the Bitmap
memDC.Blit( 0, //Copy to this X coordinate
0, //Copy to this Y coordinate
screenWidth, //Copy this width
screenHeight, //Copy this height
&dcScreen, //From where do we copy?
0, //What's the X offset in the original DC?
0 //What's the Y offset in the original DC?
);
//Select the Bitmap out of the memory DC by selecting a new
//uninitialized Bitmap
memDC.SelectObject(wxNullBitmap);
//Our Bitmap now has the screenshot, so let's save it :-)
wxString default_fname(title);
wxString filter = "BMP|*.bmp|PNG|*.png";
wxFileDialog dialog(NULL, _("Save Image to File"), wxEmptyString,
default_fname, filter,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal() != wxID_OK) return;
wxFileName fname = wxFileName(dialog.GetPath());
wxString str_fname = fname.GetPathWithSep() + fname.GetName();
if (dialog.GetFilterIndex() == 0) {
screenshot.SaveFile(str_fname + ".bmp", wxBITMAP_TYPE_BMP);
} else if (dialog.GetFilterIndex() == 1) {
screenshot.SaveFile(str_fname + ".png", wxBITMAP_TYPE_PNG);
}
}
///////////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////////
TransparentSettingDialog::TransparentSettingDialog(
wxWindow * parent,
double _transparency,
wxWindowID id,
const wxString & caption,
const wxPoint & position,
const wxSize & size,
long style )
: wxDialog( parent, id, caption, position, size, style),
transparency(_transparency)
{
wxLogMessage("Open TransparentSettingDialog");
wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
this->SetSizer(topSizer);
wxBoxSizer* boxSizer = new wxBoxSizer(wxVERTICAL);
topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
// A text control for the users name
int trasp_scale = 100 * transparency;
wxBoxSizer* subSizer = new wxBoxSizer(wxHORIZONTAL);
slider = new wxSlider(this, wxID_ANY, trasp_scale, 0, 100,
wxDefaultPosition, wxSize(200, -1),
wxSL_HORIZONTAL);
subSizer->Add(new wxStaticText(this, wxID_ANY,"1.0"), 0,
wxALIGN_CENTER_VERTICAL|wxALL);
subSizer->Add(slider, 0, wxALIGN_CENTER_VERTICAL|wxALL);
subSizer->Add(new wxStaticText(this, wxID_ANY,"0.0"), 0,
wxALIGN_CENTER_VERTICAL|wxALL);
boxSizer->Add(subSizer);
wxString txt_transparency = wxString::Format(_("Current Opacity: %.2f"), 1.0 - transparency);
slider_text = new wxStaticText(
this,
wxID_ANY,
txt_transparency,
wxDefaultPosition,
wxSize(100, -1));
boxSizer->Add(slider_text, 0, wxGROW|wxALL, 5);
boxSizer->Add(new wxButton(this, wxID_OK, _("OK")), 0, wxALIGN_CENTER|wxALL, 10);
topSizer->Fit(this);
slider->Bind(wxEVT_SLIDER, &TransparentSettingDialog::OnSliderChange, this);
}
TransparentSettingDialog::~TransparentSettingDialog()
{
}
void TransparentSettingDialog::OnSliderChange( wxCommandEvent & event )
{
int val = event.GetInt();
double trasp = 1.0 - val / 100.0;
slider_text->SetLabel(wxString::Format(_("Current Transparency: %.2f"), trasp));
transparency = trasp;
}
double TransparentSettingDialog::GetTransparency()
{
return transparency;
}
///////////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////////
CheckSpatialRefDialog::CheckSpatialRefDialog(wxWindow * parent,
const wxString& msg,
wxWindowID id,
const wxString & caption,
const wxPoint & position,
const wxSize & size,
long style)
: wxDialog(parent, id, caption, position, size, style)
{
wxLogMessage("Open TransparentSettingDialog");
wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
this->SetSizer(topSizer);
wxBoxSizer* boxSizer = new wxBoxSizer(wxVERTICAL);
topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 20);
wxBitmap bmp = wxArtProvider::GetBitmap(wxART_WARNING);
wxStaticBitmap *warning_icon = new wxStaticBitmap(this, wxID_ANY, bmp);
wxStaticText* textctrl = new wxStaticText(this, wxID_ANY, msg);
wxBoxSizer *msgbox = new wxBoxSizer(wxHORIZONTAL);
msgbox->Add(warning_icon, 0, wxRIGHT, 10);
msgbox->Add(textctrl, 1, wxEXPAND);
cb = new wxCheckBox(this, wxID_ANY, _("Don't ask again"));
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
wxButton *yes_btn = new wxButton(this, wxID_OK, _("Yes"));
wxButton *no_btn = new wxButton(this, wxID_CANCEL, _("No"));
hbox->Add(yes_btn, 1, wxALL, 5);
hbox->Add(no_btn, 1, wxALL, 5);
boxSizer->Add(msgbox, 1, wxEXPAND | wxALL, 10);
boxSizer->Add(cb, 0, wxALIGN_CENTER | wxTOP, 20);
boxSizer->Add(hbox, 0, wxALIGN_CENTER | wxALL, 10);
topSizer->Fit(this);
no_btn->SetDefault();
}
bool CheckSpatialRefDialog::IsCheckAgain()
{
return !cb->GetValue();
}
////////////////////////////////////////////////////////////////////////
//
//
////////////////////////////////////////////////////////////////////////
SelectWeightsIdDialog::SelectWeightsIdDialog(wxWindow * parent, Project* project,
wxWindowID id,
const wxString & caption,
const wxPoint & position,
const wxSize & size,
long style)
: wxDialog(parent, id, caption, position, size, style),
project(project)
{
wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
this->SetSizer(topSizer);
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
wxStaticText* textctrl = new wxStaticText(this, wxID_ANY, _("Select ID Variable"));
m_id_field = new wxChoice (this, wxID_ANY, wxDefaultPosition, wxSize(200, -1));
InitVariableChoice(); // fill content for id dropdown list
wxButton* btn_add_id_var = new wxButton(this, wxID_ANY, _("Add ID Variable..."));
hbox->Add(textctrl, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
hbox->Add(m_id_field, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 15);
hbox->Add(btn_add_id_var, 0, wxALIGN_CENTER_VERTICAL);
wxBoxSizer *btnbox = new wxBoxSizer(wxHORIZONTAL);
wxButton *yes_btn = new wxButton(this, wxID_OK, _("OK"));
wxButton *no_btn = new wxButton(this, wxID_CANCEL, _("Cancel"));
btnbox->Add(yes_btn, 1, wxALL, 5);
btnbox->Add(no_btn, 1, wxALL, 5);
topSizer->Add(hbox, 0, wxEXPAND | wxALL, 20);
topSizer->Add(btnbox, 0, wxALIGN_CENTER | wxALL, 10);
topSizer->Fit(this);
//events
btn_add_id_var->Bind(wxEVT_BUTTON, &SelectWeightsIdDialog::OnAddIDVariable, this);
m_id_field->Bind(wxEVT_CHOICE, &SelectWeightsIdDialog::OnIdVariableSelected, this);
}
wxString SelectWeightsIdDialog::GetIDVariable()
{
return m_id_field->GetStringSelection();
}
void SelectWeightsIdDialog::OnAddIDVariable(wxCommandEvent& evt)
{
TableInterface* table_int = project->GetTableInt();
AddIdVariable dlg(table_int, this);
if (dlg.ShowModal() == wxID_OK) {
// We know that the new id has been added to the the table in memory
InitVariableChoice();
m_id_field->SetSelection(0);
OnIdVariableSelected(evt);
}
}
void SelectWeightsIdDialog::InitVariableChoice()
{
TableInterface* table_int = project->GetTableInt();
col_id_map.clear();
table_int->FillColIdMap(col_id_map);
m_id_field->Clear();
for (int i=0, iend=col_id_map.size(); i<iend; i++) {
int col = col_id_map[i];
if (table_int->GetColType(col) == GdaConst::long64_type ||
table_int->GetColType(col) == GdaConst::string_type) {
if (!table_int->IsColTimeVariant(col)) {
m_id_field->Append(table_int->GetColName(col));
}
}
}
m_id_field->SetSelection(-1);
}
void SelectWeightsIdDialog::OnIdVariableSelected(wxCommandEvent& evt)
{
if (m_id_field->GetSelection() < 0) return;
wxString sel_var = m_id_field->GetStringSelection();
TableInterface* table_int = project->GetTableInt();
if (table_int->CheckID(sel_var) == false) {
m_id_field->SetSelection(-1);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/geoda/geoda_mirror.git
[email protected]:geoda/geoda_mirror.git
geoda
geoda_mirror
geoda_mirror
master

搜索帮助