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 );
103 actualFunction =NULL;
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 ()
190 //---------------------------------------------------------------------------------------------
192 //---------------------------------------------------------------------------------------------
194 Set the bars according to the actual function
197 void pPlotter::setAll()
199 actualFunction = m_plot->getActualFunction();
201 if (actualFunction != NULL)
203 barrange -> setActiveStateTo(true);
204 color_bar -> setActiveStateTo(true);
208 double realMin_X = actualFunction->getMinX();
209 text = text + realMin_X;
210 text = text + _T(" maxX=");
211 double realMax_X = actualFunction->getMaxX();
212 text = text + realMax_X;
214 int minShowed = actualFunction->getMinXShowed();
215 int maxShowed = actualFunction->getMaxXShowed();
217 barrange -> setRepresentedValues (realMin_X, realMax_X);
218 barrange->SetStart( minShowed );
219 barrange->SetEnd( maxShowed );
222 std::vector<pColorPoint *> actualColorPoints;
223 actualFunction -> getColorPoints(actualColorPoints);
224 if(actualColorPoints.empty())
225 color_bar ->reinitiateColorBar (realMin_X, realMax_X);
227 color_bar ->reinitiateColorBarTo(actualColorPoints);
229 color_bar -> setVisibleRange (minShowed, maxShowed);
232 color_bar -> RefreshForce();
233 barrange -> RefreshForce();
240 //*****************************************************************************************************
241 // Color bar control methods
242 //*****************************************************************************************************
244 //-----------------------------------------------------------------------------------------------------
245 // Updating methods for occured events in the color bar
246 //-----------------------------------------------------------------------------------------------------
247 void pPlotter :: onAdded_ColorPoint(wxCommandEvent& event)
250 text = _T( "Last event was on color bar: Color point added, total#");
252 actualFunction = m_plot->getActualFunction();
253 if(actualFunction!=NULL)
255 std::vector<pColorPoint *> actualColorPoints;
256 color_bar ->getAddedColorsPointsList(actualColorPoints);
257 actualFunction -> setColorPoints(actualColorPoints);
258 text << actualColorPoints.size();
263 void pPlotter :: onRemoved_ColorPoint(wxCommandEvent& event)
266 text = _T( "Last event on color bar: Color point removed total#");
268 actualFunction = m_plot->getActualFunction();
269 std::vector<pColorPoint *> actualColorPoints;
270 color_bar ->getAddedColorsPointsList(actualColorPoints);
271 actualFunction -> setColorPoints(actualColorPoints);
272 text << actualColorPoints.size();
276 void pPlotter :: onMoved_ColorPoint(wxCommandEvent& event)
279 text = _T( "Last event was on color bar: Color point moved to: ");
280 int lastReal_X = (int)(color_bar->getLastMovedColorPoint())->getRealX();
283 barrange ->setRealX_vertical_line (lastReal_X);
284 barrange -> RefreshForce();
286 m_plot->setRealGuideX (lastReal_X);
291 void pPlotter:: onChanged_ColorPoint(wxCommandEvent& event)
294 sendTMessage(_T("Last event was on color bar: Color point changed color"));
297 void pPlotter :: onColorBar( wxCommandEvent& event )
299 if( (barrange->getRealX_vertical_line())!=-1)
301 barrange ->setRealX_vertical_line (-1);
302 m_plot->setRealGuideX (-1);
304 barrange -> RefreshForce();
309 //*****************************************************************************************************
310 // Plotter control methods
311 //*****************************************************************************************************
315 * Method called when actual function is changed
317 void pPlotter :: onChangeFunction (wxCommandEvent& event)
319 actualFunction = m_plot->getActualFunction();
321 if (actualFunction != NULL)
323 if( !barrange->isActive() )
325 barrange -> setActiveStateTo(true);
326 color_bar -> setActiveStateTo(true);
330 text = _T("Last event was on plotter: function changed, minX=");
331 double realMin_X = actualFunction->getMinX();
333 text << _T(" maxX=");
334 double realMax_X = actualFunction->getMaxX();
337 int minShowed = actualFunction->getMinXShowed();
338 int maxShowed = actualFunction->getMaxXShowed();
340 barrange -> setRepresentedValues (realMin_X, realMax_X);
341 barrange->SetStart( minShowed );
342 barrange->SetEnd( maxShowed );
344 std::vector<pColorPoint *> actualColorPoints;
345 actualFunction -> getColorPoints(actualColorPoints);
346 if(actualColorPoints.empty())
347 color_bar ->reinitiateColorBar (realMin_X, realMax_X);
349 color_bar ->reinitiateColorBarTo(actualColorPoints);
351 color_bar -> setVisibleRange ((int)realMin_X, maxShowed);
354 color_bar -> RefreshForce();
355 barrange -> RefreshForce();
363 * Method called when a point is added to the actual function on the plotter
366 void pPlotter :: onAddedPoint_Plotter (wxCommandEvent& event)
369 m_plot->writeInText(text);
374 * Method called when a point is removed to the actual function on the plotter
376 void pPlotter :: onRemovedPoint_Plotter (wxCommandEvent& event)
379 m_plot->writeInText(text);
384 * Method called when a point is moved from the actual function on the plotter
386 void pPlotter :: onMovePoint_Plotter (wxCommandEvent& event)
389 m_plot->writeInText(text);
393 * Method called when turn off the guide line from the actual function on the plotter
395 void pPlotter::onGuideLines(wxCommandEvent& event)
402 //*****************************************************************************************************
403 // Max-Min Barrange control methods
404 //*****************************************************************************************************
408 void pPlotter::onBarrange(wxCommandEvent& event)
415 void pPlotter::onActualChange_Bar(wxCommandEvent& event)
418 text = _T( "Last event was on min-max bar: Actual triangle moved to: " );
419 int lastActual_X = barrange->GetActual();
421 text << lastActual_X;
423 color_bar ->setRealX_vertical_line (lastActual_X);
424 m_plot->setRealGuideX (lastActual_X);
426 color_bar -> RefreshForce();
433 * Method called when the start triangle is moved. Adjusts the plotter and color bar view-range.
435 void pPlotter::onStartChange_Bar(wxCommandEvent& event)
439 text = _T( "Last event was on min-max bar: Start triangle moved to: ");
440 int realMin_X = barrange->GetStart();
441 text += wxString::Format(_T("%d"), realMin_X);
442 double realMax_X = m_plot->getMaxScrX();
444 color_bar -> setVisibleRange (realMin_X, (int)realMax_X);
446 m_plot->actualizeViewRange(realMin_X, (int)realMax_X);
448 //setting the plotter for draw the functions that
451 float startP=(float)barrange->getStartShowPorcentage();
452 float endP=(float)barrange->getEndShowPorcentage();
453 m_plot->moveFunctions(startP,endP);
456 color_bar -> RefreshForce();
457 m_plot -> UpdateAll();
461 void pPlotter::onEndChange_Bar(wxCommandEvent& event)
464 text += _T("Last event was on min-max bar: End triangle moved to: ");
465 int realMax_X = barrange->GetEnd();
466 text += wxString::Format(_T("%d"),realMax_X);
467 double realMin_X = m_plot->getMinScrX();
468 color_bar -> setVisibleRange ((int)realMin_X, realMax_X);
469 m_plot->actualizeViewRange((int)realMin_X,realMax_X);
471 float startP=(float)barrange->getStartShowPorcentage();
472 float endP=(float)barrange->getEndShowPorcentage();
473 m_plot->moveFunctions(startP,endP);
475 color_bar -> RefreshForce();
476 m_plot -> UpdateAll();
481 void pPlotter :: onSelectionEnd(wxCommandEvent& event)
483 if( (color_bar->getRealX_vertical_line())!=-1)
485 color_bar ->setRealX_vertical_line (-1);
486 m_plot->setRealGuideX (-1);
488 color_bar -> RefreshForce();
492 void pPlotter :: onMovedBar(wxCommandEvent& event)
495 text = _T( "Last event was on min-max bar: Moved bar to min:" );
497 int realMin_X = barrange->GetStart();
498 text += wxString::Format(_T("%d"),realMin_X);
501 int realMax_X = barrange->GetEnd();
502 text += wxString::Format(_T("%d"),realMax_X);
504 color_bar -> setVisibleRange (realMin_X, realMax_X);
506 float startP=(float)barrange->getStartShowPorcentage();
507 float endP=(float)barrange->getEndShowPorcentage();
508 m_plot->moveFunctions(startP,endP);
510 color_bar -> RefreshForce();
511 m_plot -> UpdateAll();
517 * Method for sending a text message to the container window
518 * @param theText Is the text of the message
520 void pPlotter :: sendTMessage(wxString theText)
522 //Creating a message event
523 wxCommandEvent puntualMSG_Event( wxEVT_NW_TEXT_MESAGGE, GetId() );
524 puntualMSG_Event.SetEventObject(this);
526 GetEventHandler()->ProcessEvent( puntualMSG_Event );
530 * Sets the text message
531 * @param nMessage Is the text message to set
533 void pPlotter :: setTextMessage(wxString nMessage)
539 * Gets the text message
540 * @param text Is the actual text message
542 wxString pPlotter :: getTextMessage()
547 * Add a function to the plotter
548 * when the function doesnt come from window
550 int pPlotter:: addFunction(pGraphicalFunction * function)
552 return m_plot->addFunction(function);
555 * Creates and returns a graphical funcion according to the indicated vectors.
557 pGraphicalFunction* pPlotter::getFunctionForVectors( double* vectorX, int sizeX,double * vectorY, int sizeY )
559 return m_plot->getFunctionForVectors(vectorX,sizeX, vectorY, sizeY );
564 void pPlotter::setType(int t)
569 Get a function in the plotter given the index
571 pGraphicalFunction* pPlotter:: getFunction(int index)
573 return m_plot->getFunction(index);
576 Adds function to move with the bar min max
578 int pPlotter::addFunctionToMove(pGraphicalFunction * function)
580 return m_plot->addFunctionToMove(function);
584 move the functions that the user wants to move
585 and that were setted in functionsToMove
586 @param porcentageMinX:the porcentage that the minShowed
587 of the funcntions have to be move
588 @param porcentageMaxX:the porcentage that the maxShowed
589 of the funcntions have to be move
592 void pPlotter:: moveFunctions(float porcentageMinX,float porcentageMaxX)
594 m_plot->moveFunctions(porcentageMinX,porcentageMaxX);
597 * deletes the function from the plotter
600 bool pPlotter::deleteFunction(pGraphicalFunction * function);
602 return m_plot->deleteFunction(function);
607 //--------------------
609 //---------------------
611 Returns the number of points that the bar color has
613 int pPlotter::getColorPointsSize()
615 return color_bar->getColorPointsSize();
618 Get the RGB values of the color point that is in the
621 void pPlotter::getBarColorDataAt(int index,double& x, int& red,int& green,int& blue)
623 color_bar->getDataAt(index,x,red,green,blue);
627 returns true if the point was succesfully added
628 PRE: 0<=red<=255 0<=green<=255 0<=blue<=255
630 bool pPlotter::addColorPoint(int x,int red,int green, int blue)
632 wxColour color= wxColour(red,green,blue);
633 return color_bar->addColorPoint((double)x, color);
635 void pPlotter::eraseColorPoints()
637 int min=(int)color_bar->getMinValue();
638 int max=(int)color_bar->getMaxValue();
639 color_bar->reinitiateColorBar(min,max);
642 //--------------------
644 //---------------------
645 float pPlotter::getMaxShowedPorcentage()
647 return barrange->getEndShowPorcentage();
649 float pPlotter::getMinShowedPorcentage()
651 return barrange->getStartShowPorcentage();
653 float pPlotter::getActualShowedPorcentage()
655 return barrange->getActualShowPorcentage();
658 //--------------------
659 // plotter Information
660 //---------------------
661 void pPlotter::setActual(pGraphicalFunction* nActual)
663 m_plot->setActualFunction(nActual);
665 void pPlotter::update()
667 //if it is a plotter of histograms
668 if(m_plot->getType()==2)
670 pGraphicalFunction* tf= m_plot->getActualFunction();
673 tf->clearSplineVectors();
674 tf->addSplinesPoints();
675 tf->initializeSplineVectors();
681 //----------------------------
682 //Handling Options Menu
683 //----------------------------
685 void pPlotter::setPopUpMenu(bool startD,bool stopD,bool smooth,bool line, bool zoomIn,
686 bool zoomOut,bool showPoints,bool noShowPoints,bool changeColor, bool addP,
687 bool delPoint,bool load,bool save)
689 m_plot->setPopUpMenu(startD, stopD, smooth, line, zoomIn,
690 zoomOut, showPoints, noShowPoints, changeColor, addP,
691 delPoint, load, save);
696 if the user resize the window
702 void pPlotter::OnSize( wxSizeEvent &WXUNUSED(event) )
705 GetClientSize(&scrX,&scrY);
706 m_plot->SetSize(scrX,scrY);
709 pGraphicalFunction* actual=m_plot->getActualFunction();
712 actual->setScreens(scrX,scrY);
722 ** Returns two vectors, the grey level of the point and its value, the value is between [0,1]
724 void pPlotter::GetValuesPointsFunction(std::vector<double>& greylevel,std::vector<double>& value, int histogramsize)
726 if(actualFunction != NULL){
727 double* xval = actualFunction->getX_RealValues();
728 double* yval = actualFunction->getY_RealValues();
730 actualFunction->getScaleY();
731 for(int i = 0; i < actualFunction->getSizePoints();i++){
732 greylevel.push_back(xval[i]);
733 value.push_back(yval[i]/histogramsize);
739 ** Returns two vectors, the grey level of the point and its value, the red, green
740 ** and blue value is between [0,1]
742 void pPlotter::GetValuesColorPointsFunction(std::vector<double>& greylevel,
743 std::vector<double>& red,
744 std::vector<double>& green,
745 std::vector<double>& blue)
748 if(color_bar != NULL){
750 std::vector<pColorPoint*> colors;
751 color_bar->getAddedColorsPointsList(colors);
753 for(int i = 0; i < colors.size();i++){
754 pColorPoint* pcolor = colors[i];
756 greylevel.push_back(pcolor->getRealX());
757 wxColour colour = pcolor->getColor();
759 double _red = (double)(colour.Red())/255.0;
760 double _green = (double)(colour.Green())/255.0;
761 double _blue = (double)(colour.Blue())/255.0;
764 green.push_back(_green);
765 blue.push_back(_blue);