1 //---------------------------------------------------------------------------------------------
2 // Class definition include
3 //---------------------------------------------------------------------------------------------
6 // --------------------------------------------------------------------------------------------
7 // WX headers inclusion.
8 // For compilers that support precompilation, includes <wx/wx.h>.
9 // --------------------------------------------------------------------------------------------
15 //---------------------------------------------------------------------------------------------
16 // Class implementation
17 //---------------------------------------------------------------------------------------------
19 IMPLEMENT_CLASS(pPlotter, wxPanel)
21 //------------------------------------------------------------------------------------------------------------
22 // Generated events declaration and definition
23 //------------------------------------------------------------------------------------------------------------
24 BEGIN_DECLARE_EVENT_TYPES()
25 DECLARE_EVENT_TYPE( wxEVT_NW_TEXT_MESAGGE, -1 )
26 END_DECLARE_EVENT_TYPES()
28 DEFINE_EVENT_TYPE( wxEVT_NW_TEXT_MESAGGE )
30 // ----------------------------------------------------------------------------------------------------
31 // Handdled events from pColorBar
32 // ----------------------------------------------------------------------------------------------------
33 DECLARE_EVENT_TYPE(wxEVT_ADDED_POINT, -1)
34 DECLARE_EVENT_TYPE(wxEVT_REMOVED_POINT, -1)
35 DECLARE_EVENT_TYPE(wxEVT_MOVED_POINT, -1)
36 DECLARE_EVENT_TYPE(wxEVT_CHANGED_POINT, -1)
37 DECLARE_EVENT_TYPE(wxEVT_ON_COLOR_BAR, -1)
39 // ----------------------------------------------------------------------------------------------------
40 // Handdled events from plotter
41 // ----------------------------------------------------------------------------------------------------
42 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_CHANGED_FUNCTION, -1)
43 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_MOVE, -1)
44 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_ADD, -1)
45 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_DELETE, -1)
46 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_GUIDELINES, -1)
48 // ----------------------------------------------------------------------------------------------------
49 // Handdled events from max-min barrange
50 // ----------------------------------------------------------------------------------------------------
51 DECLARE_EVENT_TYPE(wxEVT_TSBAR, -1)
52 DECLARE_EVENT_TYPE(wxEVT_TSBAR_ACTUAL, -1)
53 DECLARE_EVENT_TYPE(wxEVT_TSBAR_START, -1)
54 DECLARE_EVENT_TYPE(wxEVT_TSBAR_END, -1)
55 DECLARE_EVENT_TYPE(wxEVT_TSBAR_MOVED, -1)
56 DECLARE_EVENT_TYPE(wxEVT_SELECTION_END, -1)
59 // ----------------------------------------------------------------------------------------------------
60 // EVENT TABLE (->Connect: analogous)
61 //-----------------------------------------------------------------------------------------------------
62 BEGIN_EVENT_TABLE(pPlotter, wxPanel)
64 //EVT_SIZE (pPlotter::OnSize)
66 // Connectting the handled envents for the plotter to the corresponding methods
67 EVT_COMMAND (-1,wxEVT_PPLOTTER_CHANGED_FUNCTION, pPlotter::onChangeFunction)
68 EVT_COMMAND (-1,wxEVT_PPLOTTER_POINT_MOVE, pPlotter::onMovePoint_Plotter)
69 EVT_COMMAND (-1,wxEVT_PPLOTTER_POINT_ADD, pPlotter::onAddedPoint_Plotter)
70 EVT_COMMAND (-1,wxEVT_PPLOTTER_POINT_DELETE, pPlotter::onRemovedPoint_Plotter)
71 EVT_COMMAND (-1,wxEVT_PPLOTTER_GUIDELINES, pPlotter::onGuideLines)
73 // Connectting the handled envents for the color bar to the corresponding methods
74 EVT_COMMAND (-1,wxEVT_ADDED_POINT, pPlotter :: onAdded_ColorPoint )
75 EVT_COMMAND (-1,wxEVT_REMOVED_POINT, pPlotter :: onRemoved_ColorPoint )
76 EVT_COMMAND (-1,wxEVT_MOVED_POINT, pPlotter :: onMoved_ColorPoint )
77 EVT_COMMAND (-1,wxEVT_CHANGED_POINT, pPlotter :: onChanged_ColorPoint )
78 EVT_COMMAND (-1,wxEVT_ON_COLOR_BAR, pPlotter :: onColorBar )
80 // Connectting the handled envents from the max-min barrange to the corresponding methods
81 EVT_COMMAND (-1,wxEVT_TSBAR, pPlotter::onBarrange)
82 EVT_COMMAND (-1,wxEVT_SELECTION_END, pPlotter::onSelectionEnd)
83 EVT_COMMAND (-1,wxEVT_TSBAR_MOVED, pPlotter::onMovedBar)
84 EVT_COMMAND (-1,wxEVT_TSBAR_ACTUAL, pPlotter:: onActualChange_Bar)
85 EVT_COMMAND (-1,wxEVT_TSBAR_START, pPlotter::onStartChange_Bar)
86 EVT_COMMAND (-1,wxEVT_TSBAR_END, pPlotter::onEndChange_Bar)
91 //---------------------------------------------------------------------------------------------
92 // Constructors & Destructors
93 //---------------------------------------------------------------------------------------------
95 * Creates an integrated plotter instance
96 * @param *parent Container window
98 pPlotter :: pPlotter (wxWindow *parent,int nWidth, int nHeight)
99 :wxPanel(parent,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL)
101 SetBackgroundColour(wxColour(255,255,255));
102 m_plot = new pPlotterWindow( this, -1, wxPoint(0,0), wxSize(nWidth,nHeight), wxSUNKEN_BORDER );
104 // Adding the axis layers to the plotter
105 m_plot->AddLayer( new pPlotterScaleX() );
106 m_plot->AddLayer( new pPlotterScaleY() );
108 // Creating the log window
111 m_log = new wxTextCtrl( panel, -1, wxT("This is the log window.\n"), wxPoint(0,0), wxSize(400,100), wxTE_MULTILINE );
112 // Sharing the log window of the application with the plotter widget
113 m_plot->setmLog(m_log);
118 // Creating a function for the plotter with given points x-vector and y-vector
121 double vectX_F1 [] = { 0, 20, 50, 80, 100, 115, 120, 210, 220,250 };
124 // double vectX_F1 [] = { 0, 20, 50, 80, 100, 115, 120, 210, 220,250 };
126 double vectY_F1 [] = { 0, 40, 70, 100, 200, 100, 40, 170, 0, 50 };
127 pGraphicalFunction * f1 = m_plot ->getFunctionForVectors( vectX_F1, 10, vectY_F1, 10 );
128 // Including and drawing the created function in the plotter
131 m_plot->addFunction( f1 );
132 m_plot->addFunctionToMove(f1);
133 //m_plot->addFunctionToMove(f1);
134 wxPen mypen1(*wxBLUE, 2, wxDOT_DASH );
136 f1->SetPen( mypen1 );
140 //=================== lines to sychronyze the bars width with the drawed plotter--------------------------
142 mpWindow* mplotWindow = ((mpWindow*)m_plot);
143 float minReal_X = 0; //(float)mplotWindow->getMinScrX();
144 float maxReal_X =(float)mplotWindow->getMaxScrX();
145 //float scrX=(float)mplotWindow->GetScrX()-100; // JPRx
146 //double scaleX=(scrX/(maxReal_X))* (mplotWindow->getZoomFactor()); // JPRx
148 // Creating the color bar with values according to the plotter added widget
149 color_bar = new pColorBar(this, (m_plot->GetSize()).GetWidth(),40, true);
150 color_bar -> setRepresentedValues ((int)minReal_X, (int)maxReal_X);
151 color_bar -> setDeviceBlitStart (70,0);
152 color_bar -> setVisibleRange ((int)minReal_X,(int) maxReal_X);
153 color_bar -> setDeviceEndMargin (50);
156 // Creating the min-max barrange bar with values according to the plotter added widget
157 barrange = new mBarRange(this, (m_plot->GetSize()).GetWidth(),30);
158 barrange -> setVisibleLabels (false);
159 barrange -> setRepresentedValues (minReal_X, maxReal_X);
160 barrange -> setDeviceBlitStart (70,0);
161 barrange -> setDeviceEndMargin (50);
163 // Adding the components to the sizer
165 if(m_plot->getActualFunction())
168 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
169 sizer->Add( m_plot, 4, wxEXPAND);
170 sizer->Add( color_bar,0, wxEXPAND );
171 sizer->Add( barrange, 0, wxEXPAND );
173 // sizer->Add( m_log, 0, wxEXPAND);
175 // Stablishing the layout and sizer of the panel
176 /*panel->*/SetAutoLayout(true);
177 /*panel->*/SetSizer(sizer);
180 /*panel->*/Refresh();
184 pPlotter :: ~pPlotter ()
189 //---------------------------------------------------------------------------------------------
191 //---------------------------------------------------------------------------------------------
193 Set the bars according to the actual function
196 void pPlotter::setAll()
198 actualFunction = m_plot->getActualFunction();
200 if (actualFunction != NULL)
202 barrange -> setActiveStateTo(true);
203 color_bar -> setActiveStateTo(true);
207 double realMin_X = actualFunction->getMinX();
208 text = text + realMin_X;
209 text = text + _T(" maxX=");
210 double realMax_X = actualFunction->getMaxX();
211 text = text + realMax_X;
213 int minShowed = actualFunction->getMinXShowed();
214 int maxShowed = actualFunction->getMaxXShowed();
216 barrange -> setRepresentedValues (realMin_X, realMax_X);
217 barrange->SetStart( minShowed );
218 barrange->SetEnd( maxShowed );
221 std::vector<pColorPoint *> actualColorPoints;
222 actualFunction -> getColorPoints(actualColorPoints);
223 if(actualColorPoints.empty())
224 color_bar ->reinitiateColorBar (realMin_X, realMax_X);
226 color_bar ->reinitiateColorBarTo(actualColorPoints);
228 color_bar -> setVisibleRange (minShowed, maxShowed);
231 color_bar -> RefreshForce();
232 barrange -> RefreshForce();
239 //*****************************************************************************************************
240 // Color bar control methods
241 //*****************************************************************************************************
243 //-----------------------------------------------------------------------------------------------------
244 // Updating methods for occured events in the color bar
245 //-----------------------------------------------------------------------------------------------------
246 void pPlotter :: onAdded_ColorPoint(wxCommandEvent& event)
249 text = _T( "Last event was on color bar: Color point added, total#");
251 actualFunction = m_plot->getActualFunction();
252 if(actualFunction!=NULL)
254 std::vector<pColorPoint *> actualColorPoints;
255 color_bar ->getAddedColorsPointsList(actualColorPoints);
256 actualFunction -> setColorPoints(actualColorPoints);
257 text << actualColorPoints.size();
262 void pPlotter :: onRemoved_ColorPoint(wxCommandEvent& event)
265 text = _T( "Last event on color bar: Color point removed total#");
267 actualFunction = m_plot->getActualFunction();
268 std::vector<pColorPoint *> actualColorPoints;
269 color_bar ->getAddedColorsPointsList(actualColorPoints);
270 actualFunction -> setColorPoints(actualColorPoints);
271 text << actualColorPoints.size();
275 void pPlotter :: onMoved_ColorPoint(wxCommandEvent& event)
278 text = _T( "Last event was on color bar: Color point moved to: ");
279 int lastReal_X = (int)(color_bar->getLastMovedColorPoint())->getRealX();
282 barrange ->setRealX_vertical_line (lastReal_X);
283 barrange -> RefreshForce();
285 m_plot->setRealGuideX (lastReal_X);
290 void pPlotter:: onChanged_ColorPoint(wxCommandEvent& event)
293 sendTMessage(_T("Last event was on color bar: Color point changed color"));
296 void pPlotter :: onColorBar( wxCommandEvent& event )
298 if( (barrange->getRealX_vertical_line())!=-1)
300 barrange ->setRealX_vertical_line (-1);
301 m_plot->setRealGuideX (-1);
303 barrange -> RefreshForce();
308 //*****************************************************************************************************
309 // Plotter control methods
310 //*****************************************************************************************************
314 * Method called when actual function is changed
316 void pPlotter :: onChangeFunction (wxCommandEvent& event)
318 actualFunction = m_plot->getActualFunction();
320 if (actualFunction != NULL)
322 if( !barrange->isActive() )
324 barrange -> setActiveStateTo(true);
325 color_bar -> setActiveStateTo(true);
329 text = _T("Last event was on plotter: function changed, minX=");
330 double realMin_X = actualFunction->getMinX();
332 text << _T(" maxX=");
333 double realMax_X = actualFunction->getMaxX();
336 int minShowed = actualFunction->getMinXShowed();
337 int maxShowed = actualFunction->getMaxXShowed();
339 barrange -> setRepresentedValues (realMin_X, realMax_X);
340 barrange->SetStart( minShowed );
341 barrange->SetEnd( maxShowed );
343 std::vector<pColorPoint *> actualColorPoints;
344 actualFunction -> getColorPoints(actualColorPoints);
345 if(actualColorPoints.empty())
346 color_bar ->reinitiateColorBar (realMin_X, realMax_X);
348 color_bar ->reinitiateColorBarTo(actualColorPoints);
350 color_bar -> setVisibleRange ((int)realMin_X, maxShowed);
353 color_bar -> RefreshForce();
354 barrange -> RefreshForce();
362 * Method called when a point is added to the actual function on the plotter
365 void pPlotter :: onAddedPoint_Plotter (wxCommandEvent& event)
368 m_plot->writeInText(text);
373 * Method called when a point is removed to the actual function on the plotter
375 void pPlotter :: onRemovedPoint_Plotter (wxCommandEvent& event)
378 m_plot->writeInText(text);
383 * Method called when a point is moved from the actual function on the plotter
385 void pPlotter :: onMovePoint_Plotter (wxCommandEvent& event)
388 m_plot->writeInText(text);
392 * Method called when turn off the guide line from the actual function on the plotter
394 void pPlotter::onGuideLines(wxCommandEvent& event)
401 //*****************************************************************************************************
402 // Max-Min Barrange control methods
403 //*****************************************************************************************************
407 void pPlotter::onBarrange(wxCommandEvent& event)
414 void pPlotter::onActualChange_Bar(wxCommandEvent& event)
417 text = _T( "Last event was on min-max bar: Actual triangle moved to: " );
418 int lastActual_X = barrange->GetActual();
420 text << lastActual_X;
422 color_bar ->setRealX_vertical_line (lastActual_X);
423 m_plot->setRealGuideX (lastActual_X);
425 color_bar -> RefreshForce();
432 * Method called when the start triangle is moved. Adjusts the plotter and color bar view-range.
434 void pPlotter::onStartChange_Bar(wxCommandEvent& event)
438 text = _T( "Last event was on min-max bar: Start triangle moved to: ");
439 int realMin_X = barrange->GetStart();
440 text += wxString::Format(_T("%d"), realMin_X);
441 double realMax_X = m_plot->getMaxScrX();
443 color_bar -> setVisibleRange (realMin_X, (int)realMax_X);
445 m_plot->actualizeViewRange(realMin_X, (int)realMax_X);
447 //setting the plotter for draw the functions that
450 float startP=(float)barrange->getStartShowPorcentage();
451 float endP=(float)barrange->getEndShowPorcentage();
452 m_plot->moveFunctions(startP,endP);
455 color_bar -> RefreshForce();
456 m_plot -> UpdateAll();
460 void pPlotter::onEndChange_Bar(wxCommandEvent& event)
463 text += _T("Last event was on min-max bar: End triangle moved to: ");
464 int realMax_X = barrange->GetEnd();
465 text += wxString::Format(_T("%d"),realMax_X);
466 double realMin_X = m_plot->getMinScrX();
467 color_bar -> setVisibleRange ((int)realMin_X, realMax_X);
468 m_plot->actualizeViewRange((int)realMin_X,realMax_X);
470 float startP=(float)barrange->getStartShowPorcentage();
471 float endP=(float)barrange->getEndShowPorcentage();
472 m_plot->moveFunctions(startP,endP);
474 color_bar -> RefreshForce();
475 m_plot -> UpdateAll();
480 void pPlotter :: onSelectionEnd(wxCommandEvent& event)
482 if( (color_bar->getRealX_vertical_line())!=-1)
484 color_bar ->setRealX_vertical_line (-1);
485 m_plot->setRealGuideX (-1);
487 color_bar -> RefreshForce();
491 void pPlotter :: onMovedBar(wxCommandEvent& event)
494 text = _T( "Last event was on min-max bar: Moved bar to min:" );
496 int realMin_X = barrange->GetStart();
497 text += wxString::Format(_T("%d"),realMin_X);
500 int realMax_X = barrange->GetEnd();
501 text += wxString::Format(_T("%d"),realMax_X);
503 color_bar -> setVisibleRange (realMin_X, realMax_X);
505 float startP=(float)barrange->getStartShowPorcentage();
506 float endP=(float)barrange->getEndShowPorcentage();
507 m_plot->moveFunctions(startP,endP);
509 color_bar -> RefreshForce();
510 m_plot -> UpdateAll();
516 * Method for sending a text message to the container window
517 * @param theText Is the text of the message
519 void pPlotter :: sendTMessage(wxString theText)
521 //Creating a message event
522 wxCommandEvent puntualMSG_Event( wxEVT_NW_TEXT_MESAGGE, GetId() );
523 puntualMSG_Event.SetEventObject(this);
525 GetEventHandler()->ProcessEvent( puntualMSG_Event );
529 * Sets the text message
530 * @param nMessage Is the text message to set
532 void pPlotter :: setTextMessage(wxString nMessage)
538 * Gets the text message
539 * @param text Is the actual text message
541 wxString pPlotter :: getTextMessage()
546 * Add a function to the plotter
547 * when the function doesnt come from window
549 int pPlotter:: addFunction(pGraphicalFunction * function)
551 return m_plot->addFunction(function);
554 * Creates and returns a graphical funcion according to the indicated vectors.
556 pGraphicalFunction* pPlotter::getFunctionForVectors( double* vectorX, int sizeX,double * vectorY, int sizeY )
558 return m_plot->getFunctionForVectors(vectorX,sizeX, vectorY, sizeY );
563 void pPlotter::setType(int t)
568 Get a function in the plotter given the index
570 pGraphicalFunction* pPlotter:: getFunction(int index)
572 return m_plot->getFunction(index);
575 Adds function to move with the bar min max
577 int pPlotter::addFunctionToMove(pGraphicalFunction * function)
579 return m_plot->addFunctionToMove(function);
583 move the functions that the user wants to move
584 and that were setted in functionsToMove
585 @param porcentageMinX:the porcentage that the minShowed
586 of the funcntions have to be move
587 @param porcentageMaxX:the porcentage that the maxShowed
588 of the funcntions have to be move
591 void pPlotter:: moveFunctions(float porcentageMinX,float porcentageMaxX)
593 m_plot->moveFunctions(porcentageMinX,porcentageMaxX);
596 * deletes the function from the plotter
599 bool pPlotter::deleteFunction(pGraphicalFunction * function);
601 return m_plot->deleteFunction(function);
606 //--------------------
608 //---------------------
610 Returns the number of points that the bar color has
612 int pPlotter::getColorPointsSize()
614 return color_bar->getColorPointsSize();
617 Get the RGB values of the color point that is in the
620 void pPlotter::getBarColorDataAt(int index,double& x, int& red,int& green,int& blue)
622 color_bar->getDataAt(index,x,red,green,blue);
626 returns true if the point was succesfully added
627 PRE: 0<=red<=255 0<=green<=255 0<=blue<=255
629 bool pPlotter::addColorPoint(int x,int red,int green, int blue)
631 wxColour color= wxColour(red,green,blue);
632 return color_bar->addColorPoint((double)x, color);
634 void pPlotter::eraseColorPoints()
636 int min=(int)color_bar->getMinValue();
637 int max=(int)color_bar->getMaxValue();
638 color_bar->reinitiateColorBar(min,max);
641 //--------------------
643 //---------------------
644 float pPlotter::getMaxShowedPorcentage()
646 return barrange->getEndShowPorcentage();
648 float pPlotter::getMinShowedPorcentage()
650 return barrange->getStartShowPorcentage();
652 float pPlotter::getActualShowedPorcentage()
654 return barrange->getActualShowPorcentage();
657 //--------------------
658 // plotter Information
659 //---------------------
660 void pPlotter::setActual(pGraphicalFunction* nActual)
662 m_plot->setActualFunction(nActual);
664 void pPlotter::update()
666 //if it is a plotter of histograms
667 if(m_plot->getType()==2)
669 pGraphicalFunction* tf= m_plot->getActualFunction();
672 tf->clearSplineVectors();
673 tf->addSplinesPoints();
674 tf->initializeSplineVectors();
680 //----------------------------
681 //Handling Options Menu
682 //----------------------------
684 void pPlotter::setPopUpMenu(bool startD,bool stopD,bool smooth,bool line, bool zoomIn,
685 bool zoomOut,bool showPoints,bool noShowPoints,bool changeColor, bool addP,
686 bool delPoint,bool load,bool save)
688 m_plot->setPopUpMenu(startD, stopD, smooth, line, zoomIn,
689 zoomOut, showPoints, noShowPoints, changeColor, addP,
690 delPoint, load, save);
695 if the user resize the window
701 void pPlotter::OnSize( wxSizeEvent &WXUNUSED(event) )
704 GetClientSize(&scrX,&scrY);
705 m_plot->SetSize(scrX,scrY);
708 pGraphicalFunction* actual=m_plot->getActualFunction();
711 actual->setScreens(scrX,scrY);