00001
00002
00003
00004
00005
00006
00007
00008 #include "PnlGraphFrame.h"
00009
00010
00011
00012
00013
00014
00015
00016 IMPLEMENT_CLASS(PnlGraphFrame,TBasePanel)
00017
00018 BEGIN_EVENT_TABLE(PnlGraphFrame,TBasePanel)
00019 EVT_SIZE(PnlGraphFrame::OnSize)
00020 EVT_MENU(1026,PnlGraphFrame::WxdeleteClick)
00021 EVT_VALUE_CHANGED(PnlGraphFrame::TxtValueChanged)
00022 EVT_POINTER_MOVED(PnlGraphFrame::PointerMoved)
00023 EVT_GRAPH_LCLICK(PnlGraphFrame::OnGraphLClick)
00024 EVT_GRAPH_RCLICK(PnlGraphFrame::OnGraphRClick)
00025 END_EVENT_TABLE()
00026
00027
00028
00029
00030
00031
00032
00033
00034 PnlGraphFrame::PnlGraphFrame(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name,gestione* gpannello) : TBasePanel(parent,id,pos,size,style,name,2)
00035 {
00036
00037 char value[13];
00038
00039 ImpostaUtilita(gpannello);
00040
00041 SetCursor(wxCURSOR_HAND);
00042
00043 Grafico=new PnlGraph(this,-1,wxPoint(deltax_2D,deltay_2D),wxSize(this->GetSize().GetWidth()-80,this->GetSize().GetHeight()-40));
00044 sprintf(value,"%f",Grafico->options.ymax);
00045 TxtYMax=new TxtValue(this,2001,value,wxPoint(20,10),wxSize(50,20),wxNO_BORDER);
00046 sprintf(value,"%f",Grafico->options.ymin);
00047 TxtYMin=new TxtValue(this,2002,value,wxPoint(20,this->GetSize().GetHeight()-50),wxSize(50,20),wxNO_BORDER);
00048 sprintf(value,"%f",Grafico->options.xmin);
00049 TxtXMin=new TxtValue(this,2003,value,wxPoint(70,this->GetSize().GetHeight()-30),wxSize(50,20),wxNO_BORDER);
00050 sprintf(value,"%f",Grafico->options.xmax);
00051 TxtXMax=new TxtValue(this,2004,value,wxPoint(this->GetSize().GetWidth()-60,this->GetSize().GetHeight()-30),wxSize(50,20),wxNO_BORDER);
00052
00053 ImpostaSelezione();
00054 }
00055
00056
00057 int PnlGraphFrame::GetMinWidth()
00058 {
00059 return 200;
00060 }
00061
00062 int PnlGraphFrame::GetMinHeight()
00063 {
00064 return 200;
00065 }
00066
00067
00068
00069 void PnlGraphFrame::CheckOptions()
00070 {
00071 bool errore=false;
00072
00073 if((Grafico->options.xmin>=Grafico->options.xmax))
00074 {errore=true;
00075 TxtXMin->SetForegroundColour(wxColour(0xff,0x0,0x0));
00076 TxtXMax->SetForegroundColour(wxColour(0xff,0x0,0x0));
00077 TxtXMin->SetToolTip("Il limite inferiore deve essere minore di quello superiore");
00078 TxtXMax->SetToolTip("Il limite inferiore deve essere minore di quello superiore");
00079 }
00080 else
00081 {TxtXMin->SetForegroundColour(wxColour(0x0,0x0,0x0));
00082 TxtXMax->SetForegroundColour(wxColour(0x0,0x0,0x0));
00083 TxtXMin->SetToolTip("");
00084 TxtXMax->SetToolTip("");
00085
00086 }
00087
00088 if((Grafico->options.ymin>=Grafico->options.ymax))
00089 {errore=true;
00090 TxtYMin->SetForegroundColour(wxColour(0xff,0x0,0x0));
00091 TxtYMax->SetForegroundColour(wxColour(0xff,0x0,0x0));
00092 TxtYMin->SetToolTip("Il limite inferiore deve essere minore di quello superiore");
00093 TxtYMax->SetToolTip("Il limite inferiore deve essere minore di quello superiore");
00094
00095 }
00096 else
00097 {TxtYMin->SetForegroundColour(wxColour(0x0,0x0,0x0));
00098 TxtYMax->SetForegroundColour(wxColour(0x0,0x0,0x0));
00099 TxtYMin->SetToolTip("");
00100 TxtYMax->SetToolTip("");
00101
00102
00103 }
00104
00105 if(errore)
00106 Grafico->Hide();
00107 else
00108 Grafico->Show();
00109
00110 this->Refresh();
00111 }
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 void PnlGraphFrame::OnSize(wxSizeEvent& event)
00122 {
00123
00124 Grafico->SetSize(wxSize(event.GetSize().GetWidth()-80,event.GetSize().GetHeight()-40));
00125 TxtYMin->Move(wxPoint(20,this->GetSize().GetHeight()-50));
00126 TxtXMin->Move(wxPoint(70,this->GetSize().GetHeight()-30));
00127 TxtXMax->Move(wxPoint(this->GetSize().GetWidth()-60,this->GetSize().GetHeight()-30));
00128 event.Skip();
00129 }
00130
00131
00132
00133 void PnlGraphFrame::WxdeleteClick(wxCommandEvent& event)
00134 {
00135
00136 Elimina();
00137 event.Skip();
00138
00139 }
00140
00141
00142
00143 void PnlGraphFrame::PointerMoved(wxMouseEvent& event)
00144 {
00145 wxPoint posizione_mouse=event.GetPosition();
00146
00147 GraphInfoEvent cevent(EVT_GRAPH_INFO);
00148
00149 sprintf(cevent.strposx,"%12.4f",Grafico->calculate_ascissa(posizione_mouse.x));
00150 sprintf(cevent.strposy,"%12.4f",Grafico->calculate_ordinata(posizione_mouse.y));
00151 sprintf(cevent.strobject,"Grafico 2D");
00152
00153 if (GetParent())
00154 GetParent()->AddPendingEvent(cevent);
00155 event.Skip();
00156 }
00157
00158
00159
00160 void PnlGraphFrame::OnGraphLClick(wxMouseEvent& event)
00161 {
00162 ImpostaBordi();
00163 event.Skip();
00164 }
00165
00166
00167
00168 void PnlGraphFrame::OnGraphRClick(wxMouseEvent& event)
00169 {
00170 ImpostaBordi();
00171 event.Skip();
00172 }
00173
00174
00175
00176 void PnlGraphFrame::TxtValueChanged(ValueChangedEvent& event)
00177 {
00178
00179 if(event.IsValid())
00180 {
00181 switch(((wxTextCtrl*)event.GetEventObject())->GetId())
00182 {
00183 case 2001:
00184 Grafico->options.ymax=event.GetValue();
00185 break;
00186 case 2002:
00187 Grafico->options.ymin=event.GetValue();
00188 break;
00189 case 2003:
00190 Grafico->options.xmin=event.GetValue();
00191 break;
00192 case 2004:
00193 Grafico->options.xmax=event.GetValue();
00194 break;
00195 }
00196 CheckOptions();
00197 }
00198 else
00199 {
00200 char value[13];
00201
00202 switch(((wxTextCtrl*)event.GetEventObject())->GetId())
00203 {
00204 case 2001:
00205 sprintf(value,"%10f",Grafico->options.ymax);
00206 break;
00207 case 2002:
00208 sprintf(value,"%10f",Grafico->options.ymin);
00209 break;
00210 case 2003:
00211 sprintf(value,"%10f",Grafico->options.xmin);
00212 break;
00213 case 2004:
00214 sprintf(value,"%10f",Grafico->options.xmax);
00215 break;
00216 }
00217 wxMessageDialog *error=new wxMessageDialog(this,"Inserire un valore numerico","Errore inserimento",wxICON_ERROR | wxOK);
00218 error->ShowModal();
00219 error->Destroy();
00220 ((wxTextCtrl*)event.GetEventObject())->SetValue(value);
00221 }
00222 event.Skip();
00223
00224 }
00225
00226
00227
00228
00229
00230
00231 DEFINE_EVENT_TYPE( EVT_GRAPH_INFO)
00232
00233 GraphInfoEvent::GraphInfoEvent( wxEventType commandType):wxEvent(-1, commandType){}
00234