1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 //----------------------------------------------------------------------------
27 // Class definition include
28 //----------------------------------------------------------------------------
29 #include "pPlotterWindow.h"
30 #include "MaximumsDialog.h"
35 // ----------------------------------------------------------------------------
36 // WX headers inclusion.
37 // For compilers that support precompilation, includes <wx/wx.h>.
38 // ----------------------------------------------------------------------------
44 #include "wx/colordlg.h"
45 //----------------------------------------------------------------------------
46 //DECLARING THE NEW EVENT
47 //wxEVT_TSBAR= event of the two side bar
48 //----------------------------------------------------------------------------
49 BEGIN_DECLARE_EVENT_TYPES()
50 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER, -1)
51 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_CHANGED_FUNCTION, -1)
52 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_MOVE, -1)
53 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_ADD, -1)
54 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_DELETE, -1)
55 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_GUIDELINES, -1)
56 END_DECLARE_EVENT_TYPES()
59 DEFINE_EVENT_TYPE(wxEVT_PPLOTTER)
60 DEFINE_EVENT_TYPE(wxEVT_PPLOTTER_CHANGED_FUNCTION)
61 DEFINE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_MOVE)
62 DEFINE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_ADD)
63 DEFINE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_DELETE)
64 DEFINE_EVENT_TYPE(wxEVT_PPLOTTER_GUIDELINES)
67 //----------------------------------------------------------------------------
68 // Class implementation
69 //----------------------------------------------------------------------------
71 IMPLEMENT_CLASS(pPlotterWindow, mpWindow)
73 //----------------------------------------------------------------------------
75 //----------------------------------------------------------------------------
77 BEGIN_EVENT_TABLE(pPlotterWindow,mpWindow)
78 EVT_MOTION (pPlotterWindow::onMouseMove)
79 EVT_LEFT_DCLICK(pPlotterWindow::onChangeActual)
80 EVT_LEFT_DOWN(pPlotterWindow::onAddPoint)
81 EVT_MENU(pwID_DELPOINT, pPlotterWindow::onDeletePoint)
82 EVT_MENU(pwID_SHOWPOINTS, pPlotterWindow::onShowPoints)
83 EVT_MENU(pwID_STARTDRAWING, pPlotterWindow::onStartDrawing)
84 //EVT_MENU(pwID_DELFUNCTION,pPlotterWindow::onDeleteFunction)
85 EVT_MENU(pwID_STOPDRAWING, pPlotterWindow::onStopDrawing)
86 EVT_MENU(pwID_ADDNEWPOINT, pPlotterWindow::onAddNewPoint)
87 EVT_MENU(pwID_NOSHOWPOINTS, pPlotterWindow::onNoShowPoints)
88 EVT_MENU(pwID_MYZOOMOUT,pPlotterWindow::onMyZoomOut)
89 EVT_MENU(pwID_MYZOOMIN,pPlotterWindow::onMyZoomIn)
90 EVT_MENU(pwID_SPLINE,pPlotterWindow::onSplinePoints)
91 EVT_MENU(pwID_LINE,pPlotterWindow::onLine)
92 EVT_MENU(pwID_SAVE,pPlotterWindow::onSave)
93 EVT_MENU(pwID_LOAD,pPlotterWindow::onLoad)
94 EVT_MENU(pwID_CHANGECOLOR,pPlotterWindow::onChangeColor)
95 EVT_MENU( mpID_LINE_GUIDES, pPlotterWindow::OnGuideLines)
96 EVT_MENU( pwID_TRASLATEACTUALFUNCTION, pPlotterWindow::onMoveFunction)
97 EVT_LEFT_UP(pPlotterWindow::onLeftUp)
100 //----------------------------------------------------------------------------
102 //----------------------------------------------------------------------------
104 pPlotterWindow::pPlotterWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag )
105 : mpWindow( parent, id, pos, size, flag)
110 scaleWay=DEFAULT_SCALE;
112 //drawGuideLines=true;
113 type=DEFAULT_PLOTTER;
115 movingFunction=false;
116 initialMovingCLick=-1;
122 m_popmenu.Remove( mpID_ZOOM_IN);
123 m_popmenu.Remove( mpID_ZOOM_OUT);
124 m_popmenu.Remove( mpID_CENTER);
125 m_popmenu.Remove( mpID_FIT);
126 m_popmenu.Remove( mpID_LOCKASPECT);
128 m_popmenu.Append(pwID_STARTDRAWING , _("Start Drawing"), _("Starts to draw a new function"));//it changes the actual function
129 m_popmenu.Append(pwID_STOPDRAWING , _("Stop drawing"), _("Stops of drawing the new function"));
130 m_popmenu.Append(pwID_LOAD, _("Load"), _("Load the actual function from a plane file"));
131 m_popmenu.Append(pwID_SHOWPOINTS , _("Show Points"), _("shows the discrete points of the function"));
132 m_popmenu.Append(pwID_NOSHOWPOINTS, _("No show Points"), _("Dont show the points of the function"));
133 m_popmenu.Append(pwID_ADDNEWPOINT, _("Add point"), _("Add New point to the actual function"));
134 m_popmenu.Append(pwID_DELPOINT , _("Delete point"), _("Deletes a point from the actual function."));
135 m_popmenu.Append(pwID_MYZOOMIN, _("Zoom in"), _("Zoom in the points of the function"));
136 m_popmenu.Append(pwID_MYZOOMOUT, _("Zoom out"), _("Zoom out the points of the function"));
137 m_popmenu.Append(pwID_SPLINE, _("Smooth"), _("Splines the points ofthe actual curve"));
138 m_popmenu.Append(pwID_LINE, _("Line"), _("Piecewise the points ofthe actual curve"));
139 m_popmenu.Append(pwID_SAVE, _("Save"), _("Save the actual function in plane file"));
140 m_popmenu.Append(pwID_CHANGECOLOR, _("Change Color"), _("Change the color of the function"));
141 m_popmenu.Append(pwID_TRASLATEACTUALFUNCTION, _("Start Moving Function"), _("Move the actual Function"));
143 m_popmenu.Enable(pwID_NOSHOWPOINTS,false);
144 m_popmenu.Enable(pwID_ADDNEWPOINT,false);
145 m_popmenu.Enable(pwID_SHOWPOINTS,false);
146 m_popmenu.Enable(pwID_DELPOINT,false);
147 m_popmenu.Enable(pwID_STOPDRAWING,false);
148 m_popmenu.Enable(pwID_MYZOOMIN,false);
149 m_popmenu.Enable(pwID_MYZOOMOUT,false);
150 m_popmenu.Enable(pwID_SPLINE,false);
151 m_popmenu.Enable(pwID_LINE,false);
152 m_popmenu.Enable(pwID_SAVE,false);
153 m_popmenu.Enable(pwID_LOAD,true);
154 m_popmenu.Enable(pwID_CHANGECOLOR,false);
155 m_popmenu.Enable(pwID_STARTDRAWING,true);
156 m_popmenu.Enable(pwID_LOAD,true);
157 //m_popmenu.Enable(pwID_STARTDRAWING,false);
158 m_popmenu.Enable(mpID_LINE_GUIDES,false);
159 m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,false);
165 pPlotterWindow::~pPlotterWindow()
168 //----------------------------------------------------------------------------
170 //----------------------------------------------------------------------------
173 * Sets the actual function
175 void pPlotterWindow::setActualFunction(pGraphicalFunction* newActual)
178 actual->setActual(false);
179 newActual->setActual(true);
184 * Gets the actual function
186 pGraphicalFunction* pPlotterWindow:: getActualFunction()
192 * Transform the point clicked from window
193 * to the real value,given by the scale
194 * Pre: m_scaleX and m_scaleY are already actualized
195 * with setActualScales() method
197 wxPoint pPlotterWindow:: getRealPoint(wxPoint pixelPoint)
202 //real point on the function
204 int xS=(x-offsetPixelX)/m_scaleX + offsetX + minScrX;
205 int yS=(y-offsetPixelY)/m_scaleY + offsetY + minScrY;
207 if(xS<=maxScrX && yS<=maxScrY )
221 Set the scales according to the size of the window
222 and the maximum given by the user
225 void pPlotterWindow::setActualScales()
227 // int maxX,maxY,minX,minY; // JPRx
228 int maxX,maxY;//,minX,minY; // JPRx //EED
230 if the function is drawed interactively the maxX and the
231 maxY in actual are sets by the user
234 maxX=actual->getMaxX();
235 maxY=actual->getMaxY();
241 int dx=actual->getMaxXShowed()-actual->getMinXShowed();
242 int dy=actual->getMaxYShowed()-actual->getMinYShowed();
246 m_scaleX= (((float)m_scrX-100)/dx)*zoomFactor;
247 m_scaleY= (((float)m_scrY-50)/dy)*zoomFactor;
249 //setting the maximums and minimums showed in the window
254 setMaxScrX(actual->getMaxXShowed());
255 setMinScrX(actual->getMinXShowed());
256 setMaxScrY(actual->getMaxYShowed());
257 setMinScrY(actual->getMinYShowed());
258 actual->setScreens(m_scrX,m_scrY);
261 //-------------------------
262 // Methods for interaction
263 //-------------------------
265 //------------------------------------
266 // Manipulating clicks on the plotter
267 //-------------------------------------
271 Manipulating clicks on the plotter
273 void pPlotterWindow::onLeftUp(wxMouseEvent& event)
281 //-------------------------------
282 //Traslating the actual function
283 //-------------------------------
285 Move the actual function when the user
288 void pPlotterWindow::onMoveFunction(wxCommandEvent& aEvent)
292 movingFunction=false;
293 m_popmenu.SetLabel(pwID_TRASLATEACTUALFUNCTION, _("Start Moving Function"));
298 m_popmenu.SetLabel(pwID_TRASLATEACTUALFUNCTION, _("Stop Moving Function"));
302 //-----------------------
304 //-----------------------
308 * Change the color of the function
310 void pPlotterWindow::onChangeColor(wxCommandEvent& aEvent)
315 wxColourDialog dialog(this, &data);
317 if ( dialog.ShowModal() == wxID_OK )
319 colour = dialog.GetColourData().GetColour();
324 actual->SetPen( mypen);
329 //----------------------
331 //----------------------
335 * Load the function from a .txt file
337 void pPlotterWindow::onLoad(wxCommandEvent& aEvent)
340 actual=new pGraphicalFunction(wxT("f(x) = function1(x)"),mpALIGN_NE);
341 actual->setActual(true);
342 actual->setFromWindow(false);
343 actual->SetDrawing(drawing);
344 actual->setFactorZoom(zoomFactor);
346 wxPen mypen(*wxRED, 5, wxSOLID);
348 actual->SetPen( mypen);
350 wxString nameF=wxFileSelector(_T("Save Function"));
354 functions.Append(actual);
355 addFunctionToMove(actual);
357 m_popmenu.Enable(pwID_STARTDRAWING,true);
361 //------------------------------------------
362 //Sending the paarticular event of changed actual function
363 //-------------------------------------------
364 wxCommandEvent cevent( wxEVT_PPLOTTER_CHANGED_FUNCTION, GetId() );
365 cevent.SetEventObject(this);
366 GetEventHandler()->ProcessEvent( cevent );
371 * Save the points of the function in a .txt file
373 void pPlotterWindow::onSave(wxCommandEvent& aEvent)
375 wxString nameF=wxFileSelector(_T("Save Function"));
379 //-----------------------
381 //----------------------
383 * Spline the points of the actual curve
386 void pPlotterWindow::onSplinePoints(wxCommandEvent& aEvent)
389 actual->initializeSplines();
390 actual->initializeSplineVectors();
392 m_popmenu.Enable(pwID_SPLINE,false);
393 m_popmenu.Enable(pwID_LINE,true);
397 * Change the type of drawing of the actual function
398 * to a piecewise function
400 void pPlotterWindow::onLine(wxCommandEvent& aEvent)
402 actual->clearSplineVectors();
405 m_popmenu.Enable(pwID_SPLINE,true);
406 m_popmenu.Enable(pwID_LINE,false);
410 //--------------------------
412 //---------------------------
415 * Zoom out the functions
417 void pPlotterWindow::onMyZoomOut(wxCommandEvent& aEvent)
419 wxNode* node=functions.GetFirst();
420 zoomFactor=zoomFactor*(float)(1/(float)ZOOM_FACTOR);
423 pGraphicalFunction* f= (pGraphicalFunction*)node->GetData();
425 f->setScreenX(m_scrX);
426 f->setScreenY(m_scrY);
431 f->setOffsets(m_clickedX-70,m_scrY-m_clickedY-40);
432 f->setFactorZoom(zoomFactor);
437 f->setOffsetPixelX(0);
438 f->setOffsetPixelY(0);
441 f->setFactorZoom(zoomFactor);
447 //TODO: send a event of resize
448 //setMinScrX(f->getMinXShowed());
449 //setMinScrY(f->getMinYShowed());
450 setOffsetPixelX(f->getOffsetPixelsX());
451 setOffsetPixelY(f->getOffsetPixelsY());
452 setOffsetX(f->getOffsetX());
453 setOffsetY(f->getOffsetY());
455 node=node->GetNext();
460 * Zoom in the functions
462 void pPlotterWindow::onMyZoomIn(wxCommandEvent& aEvent)
465 zoomFactor=zoomFactor*(float)ZOOM_FACTOR;
466 wxNode* node=functions.GetFirst();
469 pGraphicalFunction* f= (pGraphicalFunction*)node->GetData();
470 if(zoomFactor > 1.01)
472 f->setScreenX(m_scrX);
473 f->setScreenY(m_scrY);
474 f->setOffsets(m_clickedX-70,m_scrY-m_clickedY-40);
475 f->setFactorZoom(zoomFactor);
479 f->setOffsetPixelX(0);
480 f->setOffsetPixelY(0);
483 f->setFactorZoom(zoomFactor);
487 //TODO: send an event of resize
488 //setMinScrX(f->getMinXShowed());
489 //setMinScrY(f->getMinYShowed());
490 setOffsetPixelX(f->getOffsetPixelsX());
491 setOffsetPixelY(f->getOffsetPixelsY());
492 setOffsetX(f->getOffsetX());
493 setOffsetY(f->getOffsetY());
497 node=node->GetNext();
504 //-------------------------
506 //-------------------------
510 * Let to the user to start drawing
512 void pPlotterWindow::onStartDrawing(wxCommandEvent& aEvent)
517 actual->setActual(false);
518 if(actual->getShowPoints())
519 actual->SetShowPoints(false);
521 m_popmenu.Enable(pwID_NOSHOWPOINTS,false);
522 m_popmenu.Enable(pwID_ADDNEWPOINT,false);
523 m_popmenu.Enable(pwID_SHOWPOINTS,false);
524 m_popmenu.Enable(pwID_DELPOINT,false);
525 m_popmenu.Enable(pwID_MYZOOMIN,false);
526 m_popmenu.Enable(pwID_MYZOOMOUT,false);
527 m_popmenu.Enable(pwID_STARTDRAWING,false);
528 m_popmenu.Enable(pwID_SPLINE,false);
529 m_popmenu.Enable(pwID_LINE,false);
530 m_popmenu.Enable(pwID_STOPDRAWING,true);
531 m_popmenu.Enable(pwID_SAVE,false);
532 m_popmenu.Enable(pwID_LOAD,false);
533 m_popmenu.Enable(pwID_CHANGECOLOR,false);
534 m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,false);
541 actual=new pGraphicalFunction(wxT("f(x) = function1(x)"),mpALIGN_NE);
542 actual->setActual(true);
543 actual->setFromWindow(true);
544 actual->setScaleWay(USER_SCALE);
545 actual->SetDrawing(drawing);
546 actual->setFactorZoom(zoomFactor);
548 //we change the offsets
549 setOffsetPixelX(actual->getOffsetPixelsX());
550 setOffsetPixelY(actual->getOffsetPixelsY());
551 setOffsetX(actual->getOffsetX());
552 setOffsetY(actual->getOffsetY());
555 wxPen mypen(*wxRED, 5, wxSOLID);
557 actual->SetPen( mypen);
560 int result = wxMessageBox("Do you Want a Smooth Curve?", "Spline Points", wxYES_NO | wxCANCEL);
567 /**************************************************************************/
569 /**************************************************************************/
571 //opening the dialog of maximums
573 MaximumsDialog *dlg=new MaximumsDialog(this,_T("Set Maximums"));
575 if(dlg->ShowModal()== wxID_OK )
577 maxX=dlg->getXValue();
578 maxY=dlg->getYValue();
579 if(maxX>0 && maxY>0 && actual->getFromWindow())
584 actual->setMaxX(maxScrX);
585 actual->setMinX(minScrX);
586 actual->setMaxY(maxY);
589 actual->setMinShowedX(0);
590 actual->setMinShowedY(0);
591 actual->setMaxShowedX(maxX);
592 actual->setMaxShowedY(maxY);
596 else if(maxX<0 || maxY<0)
598 wxMessageBox(_T("Both numbers have to be positive, please enter valid numbers"), _T("Error"),
604 m_popmenu.Enable(pwID_NOSHOWPOINTS,false);
605 m_popmenu.Enable(pwID_ADDNEWPOINT,false);
606 m_popmenu.Enable(pwID_SHOWPOINTS,false);
607 m_popmenu.Enable(pwID_DELPOINT,false);
608 m_popmenu.Enable(pwID_MYZOOMIN,false);
609 m_popmenu.Enable(pwID_MYZOOMOUT,false);
610 m_popmenu.Enable(pwID_STARTDRAWING,true);
611 m_popmenu.Enable(pwID_SPLINE,false);
612 m_popmenu.Enable(pwID_LINE,false);
613 m_popmenu.Enable(pwID_STOPDRAWING,false);
614 m_popmenu.Enable(pwID_SAVE,false);
615 m_popmenu.Enable(pwID_LOAD,true);
616 m_popmenu.Enable(pwID_CHANGECOLOR,false);
617 m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,false);
619 //actual->SetDrawing(false);
623 else if(maxX==0 && maxY==0)
625 actual->setMaxX(100);
627 actual->setMaxY(100);
630 actual->setMinShowedX(0);
631 actual->setMinShowedY(0);
632 actual->setMaxShowedX(100);
633 actual->setMaxShowedY(100);
645 else if(dlg->ShowModal()== wxID_CANCEL)
650 m_popmenu.Enable(pwID_NOSHOWPOINTS,false);
651 m_popmenu.Enable(pwID_ADDNEWPOINT,false);
652 m_popmenu.Enable(pwID_SHOWPOINTS,false);
653 m_popmenu.Enable(pwID_DELPOINT,false);
654 m_popmenu.Enable(pwID_MYZOOMIN,false);
655 m_popmenu.Enable(pwID_MYZOOMOUT,false);
656 m_popmenu.Enable(pwID_STARTDRAWING,true);
657 m_popmenu.Enable(pwID_SPLINE,false);
658 m_popmenu.Enable(pwID_LINE,false);
659 m_popmenu.Enable(pwID_STOPDRAWING,false);
660 m_popmenu.Enable(pwID_SAVE,false);
661 m_popmenu.Enable(pwID_LOAD,true);
662 m_popmenu.Enable(pwID_CHANGECOLOR,false);
663 m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,false);
665 //actual->SetDrawing(false);
671 //------------------------------------------
672 //Sending the paarticular event of changed actual function
673 //-------------------------------------------
674 wxCommandEvent cevent( wxEVT_PPLOTTER_CHANGED_FUNCTION, GetId() );
675 cevent.SetEventObject(this);
676 GetEventHandler()->ProcessEvent( cevent );
682 Stop the drawing of the actual function
684 void pPlotterWindow::onStopDrawing(wxCommandEvent& aEvent)
687 actual->SetDrawing(drawing);
688 functions.Append(actual);
689 addFunctionToMove(actual);
690 m_popmenu.Enable(pwID_ADDNEWPOINT,true);
691 m_popmenu.Enable(pwID_DELPOINT,true);
692 m_popmenu.Enable(pwID_SHOWPOINTS,true);
693 m_popmenu.Enable(pwID_MYZOOMIN,true);
694 m_popmenu.Enable(pwID_MYZOOMOUT,true);
695 m_popmenu.Enable(pwID_STARTDRAWING,true);
696 m_popmenu.Enable(pwID_SPLINE,true);
697 m_popmenu.Enable(pwID_STOPDRAWING,false);
698 m_popmenu.Enable(pwID_LINE,false);
699 m_popmenu.Enable(pwID_CHANGECOLOR,true);
700 m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,true);
702 if(actual->getSizePoints()==0||actual->getSizePoints()==1)
705 m_popmenu.Enable(pwID_ADDNEWPOINT,false);
706 //functions.DeleteObject(actual);
715 * The user wants to see the points(given) of the function
717 void pPlotterWindow::onShowPoints(wxCommandEvent& aEvent)
719 actual->SetShowPoints(true);
720 m_popmenu.Enable(pwID_NOSHOWPOINTS,true);
721 m_popmenu.Enable(pwID_SHOWPOINTS,false);
725 * The user doesnt want see the points of the function
727 void pPlotterWindow::onNoShowPoints(wxCommandEvent& aEvent)
729 actual->SetShowPoints(false);
730 m_popmenu.Enable(pwID_NOSHOWPOINTS,false);
731 m_popmenu.Enable(pwID_SHOWPOINTS,true);
735 * if the user is going to add a point to the function
737 void pPlotterWindow::onAddPoint(wxMouseEvent& aEvent)
740 wxPoint point=aEvent.GetPosition();
742 point.y=m_scrY-point.y;
743 wxPoint realPoint=getRealPoint(point);
745 bool isAValidPoint=realPoint.x>=0 && realPoint.y>=0;
747 if(isAValidPoint && drawing)
749 if(actual->AddPoint(realPoint.x,realPoint.y))
751 text = wxString::Format(_T("added point ( %d, %d)\n"), realPoint.x, realPoint.y);
753 //m_log->AppendText(text);
755 //if the function is smooth
756 if(actual->getType()==2)
758 actual->clearSplineVectors();
759 actual->addSplinesPoints();
760 actual->initializeSplineVectors();
766 else if(isAValidPoint && !drawing && aEvent.m_shiftDown && actual!=NULL)
768 if(actual->AddNewPoint(realPoint.x,realPoint.y))
770 text = wxString::Format(_T("added point ( %d, %d)\n"), realPoint.x, realPoint.y);
771 //if the function is smooth
772 if(actual->getType()==2)
774 actual->clearSplineVectors();
775 actual->addSplinesPoints();
776 actual->initializeSplineVectors();
782 //made a click for moving the points
783 else if(!movingPoints)
786 movingPointIndex=actual->validPointOnFunction(realPoint);
787 if(movingPointIndex>=0)
791 //------------------------------------------
793 //-------------------------------------------
794 wxCommandEvent cevent( wxEVT_PPLOTTER_POINT_ADD, GetId() );
795 cevent.SetEventObject(this);
797 //------------------------------------------
798 //Sending the general event
799 //-------------------------------------------
800 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
801 pevent.SetEventObject(this);
803 GetEventHandler()->ProcessEvent( cevent );
804 GetEventHandler()->ProcessEvent( pevent );
808 * Adds a point to the function after the definition of the initial points of the function
809 * know this point is a point of the function
812 void pPlotterWindow::onAddNewPoint(wxCommandEvent& aEvent)
816 point.y=m_scrY-m_clickedY;
818 wxPoint realPoint=getRealPoint(point);
819 bool isAValidPoint=realPoint.x>=0 && realPoint.y>=0;
822 if(isAValidPoint && actual->AddNewPoint(realPoint.x,realPoint.y))
824 text = wxString::Format(_T("added point ( %d, %d)\n"), realPoint.x, realPoint.y);
825 //if the function is smooth
826 if(actual->getType()==2)
828 actual->clearSplineVectors();
829 actual->addSplinesPoints();
830 actual->initializeSplineVectors();
834 //------------------------------------------
836 //-------------------------------------------
837 wxCommandEvent cevent( wxEVT_PPLOTTER_POINT_ADD, GetId() );
838 cevent.SetEventObject(this);
840 //------------------------------------------
841 //Sending the general event
842 //-------------------------------------------
843 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
844 pevent.SetEventObject(this);
846 GetEventHandler()->ProcessEvent( cevent );
847 GetEventHandler()->ProcessEvent( pevent );
853 * if the user is going to delete a point of the function
855 void pPlotterWindow::onDeletePoint(wxCommandEvent& aEvent)
859 point.y=m_scrY-m_clickedY;
861 //actual->setScreenX(m_scrX);
862 //actual->setScreenY(m_scrY);
864 wxPoint realPoint=getRealPoint(point);
866 bool isAValidPoint=realPoint.x>=0 && realPoint.y>=0;
868 //this method verify a sensible region in every point of actual
869 int pointIndex=actual->validPointOnFunction(realPoint);
870 if(isAValidPoint && actual->deletePointAt(pointIndex))
873 if(actual->getSizePoints()==0)
875 //functions.DeleteObject(actual);
879 //if the function is smooth
880 if(actual->getType()==2)
882 actual->clearSplineVectors();
883 actual->addSplinesPoints();
884 actual->initializeSplineVectors();
887 text = wxString::Format(_T("deleted point ( %d, %d)\n"), realPoint.x, realPoint.y);
889 //------------------------------------------
891 //-------------------------------------------
892 wxCommandEvent cevent( wxEVT_PPLOTTER_POINT_DELETE, GetId() );
893 cevent.SetEventObject(this);
894 //------------------------------------------
895 //Sending the general event
896 //-------------------------------------------
897 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
898 pevent.SetEventObject(this);
900 GetEventHandler()->ProcessEvent( cevent );
901 GetEventHandler()->ProcessEvent( pevent );
907 * If the mouse is moving in the plot area
908 * is because the user is moving a point of the current curve
909 * the user has to call before show points, to see the points of the
913 void pPlotterWindow::onMouseMove(wxMouseEvent& event)
915 wxPoint point=event.GetPosition();
917 point.y=m_scrY-point.y;
919 wxPoint realPoint=getRealPoint(point);
920 bool isAValidPoint=realPoint.x>=0 && realPoint.y>=0;
922 if(isAValidPoint && !drawing && actual!=NULL && !movingFunction && movingPoints)
924 //never is going to get in
925 if(movingPointIndex==-1)
927 //this method verify a sensible region in every point of _actualFunction
928 movingPointIndex=actual->validPointOnFunction(realPoint);
931 else if(event.LeftIsDown())
934 /*if((movingPointIndex-1)>=0 && (movingPointIndex+1)<actual->getSizePoints() && actual->getEditable())
936 wxNode* next= actual->GetPointAt(movingPointIndex+1);
937 wxNode* before=actual->GetPointAt(movingPointIndex-1);
940 pFunctionPoint* np=(pFunctionPoint*)(next->GetData());
943 int n=np->getRealX();
947 p.x=np->getRealX()-1;
949 change=actual->changePoint(p,movingPointIndex);
954 //if the function is smooth
955 if(actual->getType()==2)
957 actual->clearSplineVectors();
958 actual->addSplinesPoints();
959 actual->initializeSplineVectors();
963 text = wxString::Format(_T("Moved point ( %d, %d)\n"), p.x, p.y);
965 //------------------------------------------
966 //Sending the particular event
967 //-------------------------------------------
968 wxCommandEvent cevent( wxEVT_PPLOTTER_POINT_MOVE, GetId() );
969 cevent.SetEventObject(this);
971 //------------------------------------------
972 //Sending the general event
973 //-------------------------------------------
974 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
975 pevent.SetEventObject(this);
978 GetEventHandler()->ProcessEvent( cevent );
979 GetEventHandler()->ProcessEvent( pevent );
986 pFunctionPoint* bp=(pFunctionPoint*)(before->GetData());
989 int b=bp->getRealX();
993 p.x=bp->getRealX()+1;
995 change=actual->changePoint(p,movingPointIndex);
999 //if the function is smooth
1000 if(actual->getType()==2)
1002 actual->clearSplineVectors();
1003 actual->addSplinesPoints();
1004 actual->initializeSplineVectors();
1007 text = wxString::Format(_T("Moved point ( %d, %d)\n"), p.x, p.y);
1009 //------------------------------------------
1010 //Sending the particular event
1011 //-------------------------------------------
1012 wxCommandEvent cevent( wxEVT_PPLOTTER_POINT_MOVE, GetId() );
1013 cevent.SetEventObject(this);
1015 //------------------------------------------
1016 //Sending the general event
1017 //-------------------------------------------
1018 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
1019 pevent.SetEventObject(this);
1022 GetEventHandler()->ProcessEvent( cevent );
1023 GetEventHandler()->ProcessEvent( pevent );
1030 // SIL ******************************************************************* // SIL
1031 if((movingPointIndex-1)>=0 && (movingPointIndex+1)<actual->getSizePoints() && actual->getEditable())
1033 change=actual->changePoint(realPoint,movingPointIndex);
1038 //if the function is smooth
1039 if(actual->getType()==2)
1041 actual->clearSplineVectors();
1042 actual->addSplinesPoints();
1043 actual->initializeSplineVectors();
1045 text = wxString::Format(_T("Moved point ( %d, %d)\n"), realPoint.x, realPoint.y);
1047 //------------------------------------------
1048 //Sending the particular event
1049 //-------------------------------------------
1050 wxCommandEvent cevent( wxEVT_PPLOTTER_POINT_MOVE, GetId() );
1051 cevent.SetEventObject(this);
1053 //------------------------------------------
1054 //Sending the general event
1055 //-------------------------------------------
1056 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
1057 pevent.SetEventObject(this);
1060 GetEventHandler()->ProcessEvent( cevent );
1061 GetEventHandler()->ProcessEvent( pevent );
1063 // SIL ******************************************************************* // SIL
1065 //change the point that is in the index, returns true if could be changed.
1066 if(!change && actual->changePoint(realPoint,movingPointIndex)&& actual->getEditable())
1069 //if the function is smooth
1070 if(actual->getType()==2)
1072 actual->clearSplineVectors();
1073 actual->addSplinesPoints();
1074 actual->initializeSplineVectors();
1077 text = wxString::Format(_T("Moved point ( %d, %d)\n"), realPoint.x,realPoint.y);
1081 //------------------------------------------
1082 //Sending the particular event
1083 //-------------------------------------------
1084 wxCommandEvent cevent( wxEVT_PPLOTTER_POINT_MOVE, GetId() );
1085 cevent.SetEventObject(this);
1087 //------------------------------------------
1088 //Sending the general event
1089 //-------------------------------------------
1090 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
1091 pevent.SetEventObject(this);
1094 GetEventHandler()->ProcessEvent( cevent );
1095 GetEventHandler()->ProcessEvent( pevent );
1100 movingPointIndex=-1;
1104 //if the user is drawing
1105 else if(isAValidPoint && drawing)
1108 actual->SetMousePoint(realPoint);
1111 //is moving the function
1112 else if(isAValidPoint && movingFunction && actual!=NULL)
1114 actual->setScreenX(m_scrX);
1115 actual->setScreenY(m_scrY);
1117 if((initialMovingCLick==-1) && event.LeftIsDown() )
1119 if(actual->isInFunction(realPoint.x,realPoint.y))
1121 initialMovingCLick=event.GetPosition().x;
1122 int numPoints=actual->getSizePoints();
1124 backUpActualVector.clear();
1127 //if(i>0 && i< (numPoints-1))
1129 wxNode* pointNode=actual->GetPointAt(i);
1130 pFunctionPoint* point= (pFunctionPoint*)pointNode->GetData();
1131 backUpActualVector.push_back(point->getRealX());
1138 else if(event.LeftIsDown())
1140 wxPoint aux(initialMovingCLick,0);
1142 wxPoint p1r=getRealPoint(event.GetPosition());
1143 wxPoint p2r=getRealPoint(aux);
1145 double delta = p1r.x-p2r.x;
1146 int numPoints=actual->getSizePoints();
1153 if(i>0 && i<(numPoints-1))
1155 wxNode* pointNode=actual->GetPointAt(i);
1156 pFunctionPoint* point= (pFunctionPoint*)pointNode->GetData();
1157 int xNew=backUpActualVector[i]+delta;
1158 //it has to preserve the state of functin
1159 if(backUpActualVector[0]<xNew && backUpActualVector[numPoints-1]>xNew)
1160 point->setRealX(xNew);
1171 wxNode* pointNode=actual->GetPointAt(i);
1172 pFunctionPoint* point= (pFunctionPoint*)pointNode->GetData();
1173 int xNew=backUpActualVector[i]+delta;
1174 point->setRealX(xNew);
1179 if(actual->getType()==2)
1181 actual->clearSplineVectors();
1182 actual->addSplinesPoints();
1183 actual->initializeSplineVectors();
1191 initialMovingCLick=-1;
1197 * if the user give us a double click is because he wants to change
1198 * the actual function to the function that has that point
1200 void pPlotterWindow::onChangeActual(wxMouseEvent& event)
1202 wxString text = _T("\n points \n");
1207 //we have to call showpoints before changing the function
1208 wxPoint point=event.GetPosition();
1209 /*****************************/
1210 point.y=m_scrY-point.y;
1211 /*****************************/
1215 //real point on the function
1216 wxPoint realPoint;//=getRealPoint(point);
1217 bool isAValidPoint=realPoint.x>=0 && realPoint.y>=0;
1220 wxNode * node= functions.GetFirst();
1223 pGraphicalFunction* fnode=(pGraphicalFunction*)node->GetData();
1226 int maxX=fnode->getMaxXShowed();
1227 int maxY=fnode->getMaxYShowed();
1228 int minX=fnode->getMinXShowed();
1229 int minY=fnode->getMinYShowed();
1233 float sx=(((float)m_scrX-100)/(maxScrX-minScrX))*zoomFactor;
1234 float sy=(((float)m_scrY-50)/(maxScrY-minScrY))*zoomFactor;
1238 float sx=(((float)m_scrX-100)/(maxX-minX))*zoomFactor;
1239 float sy=(((float)m_scrY-50)/(maxY-minY))*zoomFactor;
1242 realPoint.x=((point.x-70-fnode->getOffsetPixelsX())/sx)+ fnode->getOffsetX()+ minX;
1243 realPoint.y=((point.y-40-fnode->getOffsetPixelsY())/sy)+ fnode->getOffsetY()+ minY;
1247 if(fnode->getActual())
1248 text = wxString::Format(_T("Selected point ( %d, %d)\n"), realPoint.x, realPoint.y);
1249 //m_log->AppendText(text);
1251 bool hasIt=fnode->isInFunction(realPoint.x,realPoint.y);
1253 if(fnode->getEditable())
1254 hasIt=fnode->isInFunction(realPoint.x,realPoint.y);
1262 setActualFunction(fnode);
1263 //we change the offsets
1264 setOffsetPixelX(fnode->getOffsetPixelsX());
1265 setOffsetPixelY(fnode->getOffsetPixelsY());
1266 setOffsetX(fnode->getOffsetX());
1267 setOffsetY(fnode->getOffsetY());
1271 if(!actual->getFromWindow() && actual->getEditable()||actual->getFromWindow() && actual->getEditable())
1273 m_popmenu.Enable(pwID_ADDNEWPOINT,true);
1274 m_popmenu.Enable(pwID_DELPOINT,true);
1275 if(actual->getShowPoints())
1277 m_popmenu.Enable(pwID_SHOWPOINTS,false);
1278 m_popmenu.Enable(pwID_NOSHOWPOINTS,true);
1282 m_popmenu.Enable(pwID_SHOWPOINTS,true);
1283 m_popmenu.Enable(pwID_NOSHOWPOINTS,false);
1285 m_popmenu.Enable(pwID_MYZOOMIN,true);
1286 m_popmenu.Enable(pwID_MYZOOMOUT,true);
1287 if(actual->getType()==2)//Smoothed function
1289 m_popmenu.Enable(pwID_SPLINE,false);
1290 m_popmenu.Enable(pwID_LINE,true);
1294 m_popmenu.Enable(pwID_SPLINE,true);
1295 m_popmenu.Enable(pwID_LINE,false);
1300 m_popmenu.Enable(pwID_LOAD,false);
1301 m_popmenu.Enable(pwID_STARTDRAWING,false);
1305 m_popmenu.Enable(pwID_LOAD,true);
1306 m_popmenu.Enable(pwID_STARTDRAWING,true);
1309 m_popmenu.Enable(pwID_SAVE,true);
1310 m_popmenu.Enable(pwID_LOAD,false);
1311 m_popmenu.Enable(pwID_STOPDRAWING,false);
1312 m_popmenu.Enable(pwID_CHANGECOLOR,true);
1313 m_popmenu.Enable(mpID_LINE_GUIDES,true);
1314 m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,true);
1316 //for the functions that came from data and arent editables
1317 else if(!actual->getFromWindow() && !actual->getEditable()||actual->getFromWindow() && !actual->getEditable())
1319 if(actual->getShowPoints())
1321 m_popmenu.Enable(pwID_SHOWPOINTS,false);
1322 m_popmenu.Enable(pwID_NOSHOWPOINTS,true);
1326 m_popmenu.Enable(pwID_SHOWPOINTS,true);
1327 m_popmenu.Enable(pwID_NOSHOWPOINTS,false);
1329 if(actual->getType()==2)//Smoothed function
1331 m_popmenu.Enable(pwID_SPLINE,false);
1332 m_popmenu.Enable(pwID_LINE,true);
1336 m_popmenu.Enable(pwID_SPLINE,true);
1337 m_popmenu.Enable(pwID_LINE,false);
1342 m_popmenu.Enable(pwID_LOAD,false);
1343 m_popmenu.Enable(pwID_STARTDRAWING,false);
1345 m_popmenu.Enable(pwID_SAVE,false);
1346 m_popmenu.Enable(pwID_LOAD,false);
1347 m_popmenu.Enable(pwID_STOPDRAWING,false);
1348 m_popmenu.Enable(pwID_MYZOOMIN,true);
1349 m_popmenu.Enable(pwID_MYZOOMOUT,true);
1350 m_popmenu.Enable(pwID_CHANGECOLOR,true);
1351 m_popmenu.Enable(mpID_LINE_GUIDES,true);
1352 m_popmenu.Enable(pwID_SAVE,true);
1353 m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,true);
1356 //if the function is smooth
1357 if(actual->getType()==2)
1359 actual->clearSplineVectors();
1360 actual->addSplinesPoints();
1361 actual->initializeSplineVectors();
1366 //------------------------------------------
1367 //Sending the particular event
1368 //-------------------------------------------
1369 wxCommandEvent cevent( wxEVT_PPLOTTER_CHANGED_FUNCTION, GetId() );
1370 cevent.SetEventObject(this);
1372 //------------------------------------------
1373 //Sending the general event
1374 //-------------------------------------------
1375 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
1376 pevent.SetEventObject(this);
1378 GetEventHandler()->ProcessEvent( cevent );
1379 GetEventHandler()->ProcessEvent( pevent );
1382 node=node->GetNext();
1386 //the user is finishing the drawing of the function
1390 functions.Append(actual);
1395 * The user wants to change the type of function: line, smooth
1396 * TODO is an extension
1398 void pPlotterWindow::changeFuntionType(int aTheType, bool aForAll)
1402 //------------------------------------------
1403 //If the data doesnt come from interaction
1404 //-------------------------------------------
1406 * Add a function to the window, given its points
1408 int pPlotterWindow:: addFunction(pGraphicalFunction * function)
1410 if(function->getType()==2)
1412 function->initializeSplines();
1413 function->initializeSplineVectors();
1417 // bool added1= functions.Append(function)!=NULL; // JPRx
1418 functions.Append(function); //EED
1420 int id=functions.IndexOf(function);
1422 // bool added2= AddLayer(function);// JPRx
1423 AddLayer(function); //EED
1426 return id;//added1 && added2;
1429 * Delete a point of a function
1430 * @param point: is the real value that the functon takes, and is gointg to be deleted
1433 bool pPlotterWindow::DeletePointFunction(pGraphicalFunction* function,wxPoint point)
1436 wxNode* node= functions.GetFirst();
1439 pGraphicalFunction* f= (pGraphicalFunction*)node->GetData();
1442 return function->DeletePoint(point.x,point.y);
1444 node=node->GetNext();
1449 * Delete a function of the plotter
1451 bool pPlotterWindow::deleteFunction(pGraphicalFunction * f)
1453 functions.DeleteObject(f);
1454 functionsToMove.DeleteObject(f);
1458 * Creates and returns a graphical funcion according to the indicated vectors.
1460 pGraphicalFunction * pPlotterWindow::getFunctionForVectors( std::vector<double> *vectorX, std::vector<double> *vectorY )
1462 double coordX = -1 ;
1465 pGraphicalFunction * ff = new pGraphicalFunction( _T(" "), 1);
1468 int sizeX = vectorX->size();
1469 int sizeY = vectorY->size();
1470 if( sizeX == sizeY )
1474 coordX = (*vectorX)[i];
1475 coordY = (*vectorY)[i];
1476 ff -> AddPoint( coordX, coordY);
1481 InitFunctionForVectors( ff );
1485 pGraphicalFunction * pPlotterWindow::getFunctionForVectors( double * vectorX, int sizeX, double * vectorY, int sizeY )
1487 double coordX = -1 ;
1490 pGraphicalFunction * ff = new pGraphicalFunction( _T(" "), 1);
1492 /*wxString text = "\n Including points from two vectors \n";
1493 m_log->AppendText(text);*/
1502 ff -> AddPoint( coordX, coordY);
1503 /* text = wxString::Format("Included point ( %d, %d)\n", coordX, coordY);
1504 m_log->AppendText(text);*/
1512 InitFunctionForVectors( ff );
1518 void pPlotterWindow::InitFunctionForVectors( pGraphicalFunction *ff )
1520 int maxX,maxY,minX,minY;
1522 if the function is not drawed interactively the maxX and the
1523 maxY are the from the points of the function
1527 minX= ff->getMinX();
1528 minY= ff->getMinY();
1531 ff->setMinShowedX(minX);
1532 ff->setMinShowedY(minY);
1533 ff->setMaxShowedX(maxX);
1534 ff->setMaxShowedY(maxY);
1536 GetClientSize(&m_scrX,&m_scrY);
1539 if((maxX-minX)!=0 && (maxY-minY)!=0)
1541 m_scaleX= ((float)m_scrX-100)/(maxX-minX);
1542 m_scaleY= ((float)m_scrY-50)/(maxY-minY);
1554 m_popmenu.Enable(pwID_NOSHOWPOINTS,true);
1555 m_popmenu.Enable(pwID_ADDNEWPOINT,true);
1556 m_popmenu.Enable(pwID_SHOWPOINTS,false);
1557 m_popmenu.Enable(pwID_DELPOINT,true);
1558 //m_popmenu.Enable(pwID_SPLINE,false);
1559 //m_popmenu.Enable(pwID_LINE,true);
1560 m_popmenu.Enable(pwID_SAVE,true);
1561 m_popmenu.Enable(pwID_LOAD,false);
1562 m_popmenu.Enable(pwID_CHANGECOLOR,true);
1563 //m_popmenu.Enable(pwID_STARTDRAWING,false);
1564 m_popmenu.Enable(mpID_LINE_GUIDES,true);
1565 m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,true);
1566 //------------------------------------------
1567 //Sending the particular event of changed actual function
1568 //-------------------------------------------
1569 wxCommandEvent cevent( wxEVT_PPLOTTER_CHANGED_FUNCTION, GetId() );
1570 cevent.SetEventObject(this);
1571 GetEventHandler()->ProcessEvent( cevent );
1580 //actual->setScreens(scrX,scrY);
1581 //actual->setScales();
1582 //setActualScales();
1585 bool pPlotterWindow::AddFunction(wxPoint realPoints[],int numberOfPoints,wxString name,int flags)
1587 pGraphicalFunction* function= new pGraphicalFunction(name,flags);
1589 for(int i= 0; i<numberOfPoints;i++)
1591 int x=realPoints[i].x;
1592 int y=realPoints[i].y;
1593 bool added=function->AddPoint(x,y);
1597 functions.Append(function);
1598 bool addL=mpWindow::AddLayer(function);
1601 mpWindow::UpdateAll();
1608 * Actualizes the view range of the plotter and the actual function
1609 * @param newMinX Is the min-value to be shown in the x-scale
1610 * @param newMaxX Is the max-value to be shown in the x-scale
1615 void pPlotterWindow :: actualizeViewRange(int newMinX, int newMaxX)
1617 int minPixX,maxPixX/*, min, max*/; // JPRx
1622 int dx=newMaxX-newMinX;
1626 sx= (((float)m_scrX-100)/dx)*zoomFactor;
1632 //vx.at(i)-offsetX)*scaleX+offsetpx
1633 if(minScrX!=newMinX)
1635 setOffsetX(newMinX);
1636 setMinScrX(newMinX);
1637 actual->setOffsetX(newMinX);
1638 actual->setMinShowedX(newMinX);
1640 wxNode * node= functions.GetFirst();
1643 pGraphicalFunction* fnode=(pGraphicalFunction*)node->GetData();
1646 if(!fnode->getActual())
1648 fnode->setScreens(m_scrX,m_scrY);
1650 //max=minPixX/fnode->getScaleX();
1651 min=minPixX/fnode->getScaleX();
1652 fnode->setOffsetX(min);
1653 fnode->setMinShowedX(min);
1657 node=node->GetNext();
1662 if(maxScrX!=newMaxX)
1664 setMaxScrX(newMaxX);
1665 actual->setMaxShowedX(newMaxX);
1667 wxNode * node= functions.GetFirst();
1671 pGraphicalFunction* fnode=(pGraphicalFunction*)node->GetData();
1674 if(!fnode->getActual())
1676 fnode->setScreens(m_scrX,m_scrY);
1678 max=maxPixX/fnode->getScaleX();
1679 //min=maxPixX/fnode->getScaleX();
1680 //fnode->setOffsetX(max);
1681 //fnode->setMinShowedX(min);
1682 fnode->setMaxShowedX(max);
1686 node=node->GetNext();
1691 if(actual->getMinXShowed()!=actual->getMinX() || actual->getMinYShowed()!=actual->getMinY()||
1692 actual->getMaxXShowed()!=actual->getMaxX() || actual->getMaxYShowed()!=actual->getMaxY())
1694 m_popmenu.Enable(pwID_MYZOOMIN,false);
1695 m_popmenu.Enable(pwID_MYZOOMOUT,false);
1697 else if(actual->getMinXShowed()==actual->getMinX() && actual->getMaxXShowed()==actual->getMaxX())
1700 m_popmenu.Enable(pwID_MYZOOMIN,true);
1701 m_popmenu.Enable(pwID_MYZOOMOUT,true);
1708 * Guide lines menu handler method that reacts to the mpID_LINE_GUIDES command event
1709 * event The corresponding event to handle
1711 void pPlotterWindow :: OnGuideLines (wxCommandEvent &event)
1713 wxString nextAction_text;
1716 setLineGuidesCondition(false);
1717 // nextAction_text << "Turn on guide lines";
1718 nextAction_text = _T("Turn on guide lines");
1723 setLineGuidesCondition(true);
1724 // nextAction_text << "Turn off guide lines";
1725 nextAction_text = _T("Turn off guide lines");
1728 //------------------------------------------
1729 //Sending the paarticular event of changed actual function
1730 //-------------------------------------------
1731 wxCommandEvent cevent( wxEVT_PPLOTTER_GUIDELINES, GetId() );
1732 cevent.SetEventObject(this);
1733 GetEventHandler()->ProcessEvent( cevent );
1736 m_popmenu.SetLabel ( mpID_LINE_GUIDES, nextAction_text );
1739 Get a function in the plotter given the index
1741 pGraphicalFunction* pPlotterWindow::getFunction(int index)
1743 wxNode* node=functions.Item(index);
1747 return (pGraphicalFunction*)node->GetData();
1750 move the functions that the user wants to move
1751 and that were set in functionsToMove
1752 @param porcentageMinX:the percentage that the minShowed
1753 of the functions have to be move
1754 0<=porcentageMinX<=1
1755 @param porcentageMaxX:the percentage that the maxShowed
1756 of the functions have to be move
1757 0<=porcentageMaxX<=1
1761 void pPlotterWindow::moveFunctions( float porcentageMinX,float porcentageMaxX)
1763 //Adding the actual function
1765 //functionsToMove.Append(actual);
1768 //float minShowed,maxShowed,fMaxXShowed,fMinXShowed;
1772 int minShowed,maxShowed,fMaxXShowed,fMinXShowed;
1773 wxNode* fnode=functionsToMove.GetFirst();
1776 pGraphicalFunction* fg=(pGraphicalFunction*)fnode->GetData();
1777 x=porcentageMaxX*(fg->getMaxX()-fg->getMinX());
1778 y=porcentageMinX*(fg->getMaxX()-fg->getMinX());
1780 maxShowed=fg->getMinX()+ x;
1781 minShowed=fg->getMinX()+ y;
1783 fMinXShowed=fg->getMinXShowed();
1784 fMaxXShowed=fg->getMaxXShowed();
1786 if(fMinXShowed!=minShowed)
1790 setOffsetX(minShowed);
1791 setMinScrX(minShowed);
1793 fg->setOffsetX(minShowed);
1794 fg->setMinShowedX(minShowed);
1796 if(fMaxXShowed!=maxShowed)
1800 setMaxScrX(maxShowed);
1802 fg->setMaxShowedX(maxShowed);
1804 if(fg->getActual()&& (fg->getMinXShowed()!=fg->getMinX() || fg->getMinYShowed()!=fg->getMinY()||
1805 fg->getMaxXShowed()!=fg->getMaxX() || fg->getMaxYShowed()!=fg->getMaxY()))
1809 m_popmenu.Enable(pwID_MYZOOMIN,false);
1810 m_popmenu.Enable(pwID_MYZOOMOUT,false);
1813 else if(fg->getActual()&& fg->getMinXShowed()==fg->getMinX() && fg->getMaxXShowed()==fg->getMaxX())
1817 m_popmenu.Enable(pwID_MYZOOMIN,true);
1818 m_popmenu.Enable(pwID_MYZOOMOUT,true);
1823 fnode=fnode->GetNext();
1828 adds a function such that when the min or max of the bar
1829 changes it is going to that function
1831 int pPlotterWindow::addFunctionToMove(pGraphicalFunction *function)
1833 //bool added1= functionsToMove.Append(function)!=NULL; // JPRx
1834 functionsToMove.Append(function); // EED
1836 int id=functionsToMove.IndexOf(function);
1840 //----------------------------
1841 //Handling Options Menu
1842 //----------------------------
1843 void pPlotterWindow::setPopUpMenu(bool startD,bool stopD,bool smooth,bool line, bool zoomIn,
1844 bool zoomOut,bool showPoints,bool noShowPoints,bool changeColor, bool addP,
1845 bool delPoint,bool load,bool save)
1848 pwID_ADDPOINT = 2010, //!< add a point to the function
1849 pwID_DELPOINT, //!< delete a point of the function
1850 pwID_SHOWPOINTS, //!<shows the points that the function has
1851 pwID_STARTDRAWING, //!<let to the user to start drawing the curve
1852 pwID_DELFUNCTION, //!<delete a function that is in the plotter
1853 pwID_STOPDRAWING,//!<Stops the drawing of the function
1854 pwID_ADDNEWPOINT,//!<add a new point to the function.
1855 pwID_NOSHOWPOINTS, //!<No show the points of the function.
1856 pwID_MYZOOMIN,//!<Zoom in the function
1857 pwID_MYZOOMOUT,//!<Zoom out the points of the function.
1858 pwID_SPLINE,//!<Spline the actual curve.
1859 pwID_LINE,//!<Piecewise the actual curve.
1860 pwID_SAVE,//!<Save the function in a .txt file.
1861 pwID_LOAD, //!<Load the function from a .txt file.
1862 pwID_CHANGECOLOR, //!<Change the color of the function
1863 pwID_TRASLATEACTUALFUNCTION //!<move the actual function
1866 m_popmenu.Remove( pwID_STARTDRAWING);
1868 m_popmenu.Remove( pwID_STOPDRAWING);
1870 m_popmenu.Remove( pwID_LOAD);
1872 m_popmenu.Remove( pwID_SAVE);
1874 m_popmenu.Remove( pwID_SHOWPOINTS);
1876 m_popmenu.Remove( pwID_NOSHOWPOINTS);
1878 m_popmenu.Remove( pwID_SPLINE);
1880 m_popmenu.Remove( pwID_LINE);
1882 m_popmenu.Remove( pwID_MYZOOMIN);
1884 m_popmenu.Remove( pwID_MYZOOMOUT);
1886 m_popmenu.Remove( pwID_CHANGECOLOR);
1888 m_popmenu.Remove( pwID_ADDPOINT);
1890 m_popmenu.Remove( pwID_DELPOINT);