00001
00002
00003
00004
00005
00006
00007
00008 #include "../../include/Grafico2D/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 wxString value;
00038
00039 ImpostaUtilita(gpannello);
00040
00041 SetCursor(wxCURSOR_HAND);
00042
00043 Grafico=new PnlGraph(this,-1,wxPoint(deltax_2D,10),wxSize(this->GetSize().GetWidth()-deltax_2D-10,this->GetSize().GetHeight()-deltay_2D-10));
00044 value.Printf(_T("%f"),Grafico->options.ymax);
00045 TxtYMax=new TxtValue(this,2001,value,wxPoint(0,Grafico->GetPosition().y),wxSize(deltax_2D,deltay_2D),wxNO_BORDER);
00046 value.Printf(_T("%f"),Grafico->options.ymin);
00047 TxtYMin=new TxtValue(this,2002,value,wxPoint(0,GetSize().GetHeight()-deltay_2D-10),wxSize(deltax_2D,deltay_2D),wxNO_BORDER);
00048 value.Printf(_T("%f"),Grafico->options.xmin);
00049 TxtXMin=new TxtValue(this,2003,value,wxPoint(deltax_2D,GetSize().GetHeight()-deltay_2D),wxSize(deltax_2D,deltay_2D),wxNO_BORDER);
00050 value.Printf(_T("%f"),Grafico->options.xmax);
00051 TxtXMax=new TxtValue(this,2004,value,wxPoint(GetSize().GetWidth()-deltax_2D-10,GetSize().GetHeight()-deltay_2D),wxSize(deltax_2D,deltay_2D),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(_T("Il limite inferiore deve essere minore di quello superiore"));
00078 TxtXMax->SetToolTip(_T("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(_T(""));
00084 TxtXMax->SetToolTip(_T(""));
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(_T("Il limite inferiore deve essere minore di quello superiore"));
00093 TxtYMax->SetToolTip(_T("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(_T(""));
00100 TxtYMax->SetToolTip(_T(""));
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()-deltax_2D-10,event.GetSize().GetHeight()-deltay_2D-10));
00125
00126 TxtYMin->Move(wxPoint(0,event.GetSize().GetHeight()-deltay_2D-10));
00127 TxtXMin->Move(wxPoint(deltax_2D,event.GetSize().GetHeight()-deltay_2D));
00128 TxtXMax->Move(wxPoint(event.GetSize().GetWidth()-deltax_2D-10,event.GetSize().GetHeight()-deltay_2D));
00129
00130 }
00131
00132
00133
00134 void PnlGraphFrame::WxdeleteClick(wxCommandEvent& event)
00135 {
00136
00137 Elimina();
00138 event.Skip();
00139
00140 }
00141
00142
00143
00144 void PnlGraphFrame::PointerMoved(wxMouseEvent& event)
00145 {
00146 wxPoint posizione_mouse=event.GetPosition();
00147
00148 GraphInfoEvent cevent(EVT_GRAPH_INFO);
00149
00150 sprintf(cevent.strposx,"%12.4f",Grafico->calculate_ascissa(posizione_mouse.x));
00151 sprintf(cevent.strposy,"%12.4f",Grafico->calculate_ordinata(posizione_mouse.y));
00152 sprintf(cevent.strobject,"Grafico 2D");
00153
00154 if (GetParent())
00155 GetParent()->AddPendingEvent(cevent);
00156 event.Skip();
00157 }
00158
00159
00160
00161 void PnlGraphFrame::OnGraphLClick(wxMouseEvent& event,int i)
00162 {
00163 ImpostaBordi();
00164 event.Skip();
00165 }
00166
00167
00168
00169 void PnlGraphFrame::OnGraphRClick(wxMouseEvent& event)
00170 {
00171 ImpostaBordi();
00172 event.Skip();
00173 }
00174
00175
00176
00177 void PnlGraphFrame::TxtValueChanged(ValueChangedEvent& event)
00178 {
00179
00180 if(event.IsValid())
00181 {
00182 switch(((wxTextCtrl*)event.GetEventObject())->GetId())
00183 {
00184 case 2001:
00185 Grafico->options.ymax=event.GetValue();
00186 break;
00187 case 2002:
00188 Grafico->options.ymin=event.GetValue();
00189 break;
00190 case 2003:
00191 Grafico->options.xmin=event.GetValue();
00192 break;
00193 case 2004:
00194 Grafico->options.xmax=event.GetValue();
00195 break;
00196 }
00197 CheckOptions();
00198 }
00199 else
00200 {
00201 wxString value;
00202
00203 switch(((wxTextCtrl*)event.GetEventObject())->GetId())
00204 {
00205 case 2001:
00206 value.Printf(_T("%10f"),Grafico->options.ymax);
00207 break;
00208 case 2002:
00209 value.Printf(_T("%10f"),Grafico->options.ymin);
00210 break;
00211 case 2003:
00212 value.Printf(_T("%10f"),Grafico->options.xmin);
00213 break;
00214 case 2004:
00215 value.Printf(_T("%10f"),Grafico->options.xmax);
00216 break;
00217 }
00218 wxMessageDialog *error=new wxMessageDialog(this,_T("Inserire un valore numerico"),_T("Errore inserimento"),wxICON_ERROR | wxOK);
00219 error->ShowModal();
00220 error->Destroy();
00221 ((wxTextCtrl*)event.GetEventObject())->SetValue(value);
00222 }
00223 event.Skip();
00224
00225 }
00226
00227
00228
00229
00230
00231
00232 DEFINE_EVENT_TYPE( EVT_GRAPH_INFO)
00233
00234 GraphInfoEvent::GraphInfoEvent( wxEventType commandType):wxEvent(-1, commandType){}
00235