1 //----------------------------------------------------------------------------
2 // Class definition include
3 //----------------------------------------------------------------------------
4 #include "pPlotterWindow.h"
5 #include "MaximumsDialog.h"
10 // ----------------------------------------------------------------------------
11 // WX headers inclusion.
12 // For compilers that support precompilation, includes <wx/wx.h>.
13 // ----------------------------------------------------------------------------
19 #include "wx/colordlg.h"
20 //----------------------------------------------------------------------------
21 //DECLARING THE NEW EVENT
22 //wxEVT_TSBAR= event of the two side bar
23 //----------------------------------------------------------------------------
24 BEGIN_DECLARE_EVENT_TYPES()
25 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER, -1)
26 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_CHANGED_FUNCTION, -1)
27 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_MOVE, -1)
28 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_ADD, -1)
29 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_DELETE, -1)
30 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_GUIDELINES, -1)
31 END_DECLARE_EVENT_TYPES()
34 DEFINE_EVENT_TYPE(wxEVT_PPLOTTER)
35 DEFINE_EVENT_TYPE(wxEVT_PPLOTTER_CHANGED_FUNCTION)
36 DEFINE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_MOVE)
37 DEFINE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_ADD)
38 DEFINE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_DELETE)
39 DEFINE_EVENT_TYPE(wxEVT_PPLOTTER_GUIDELINES)
42 //----------------------------------------------------------------------------
43 // Class implementation
44 //----------------------------------------------------------------------------
46 IMPLEMENT_CLASS(pPlotterWindow, mpWindow)
48 //----------------------------------------------------------------------------
50 //----------------------------------------------------------------------------
52 BEGIN_EVENT_TABLE(pPlotterWindow,mpWindow)
53 EVT_MOTION (pPlotterWindow::onMouseMove)
54 EVT_LEFT_DCLICK(pPlotterWindow::onChangeActual)
55 EVT_LEFT_DOWN(pPlotterWindow::onAddPoint)
56 EVT_MENU(pwID_DELPOINT, pPlotterWindow::onDeletePoint)
57 EVT_MENU(pwID_SHOWPOINTS, pPlotterWindow::onShowPoints)
58 EVT_MENU(pwID_STARTDRAWING, pPlotterWindow::onStartDrawing)
59 //EVT_MENU(pwID_DELFUNCTION,pPlotterWindow::onDeleteFunction)
60 EVT_MENU(pwID_STOPDRAWING, pPlotterWindow::onStopDrawing)
61 EVT_MENU(pwID_ADDNEWPOINT, pPlotterWindow::onAddNewPoint)
62 EVT_MENU(pwID_NOSHOWPOINTS, pPlotterWindow::onNoShowPoints)
63 EVT_MENU(pwID_MYZOOMOUT,pPlotterWindow::onMyZoomOut)
64 EVT_MENU(pwID_MYZOOMIN,pPlotterWindow::onMyZoomIn)
65 EVT_MENU(pwID_SPLINE,pPlotterWindow::onSplinePoints)
66 EVT_MENU(pwID_LINE,pPlotterWindow::onLine)
67 EVT_MENU(pwID_SAVE,pPlotterWindow::onSave)
68 EVT_MENU(pwID_LOAD,pPlotterWindow::onLoad)
69 EVT_MENU(pwID_CHANGECOLOR,pPlotterWindow::onChangeColor)
70 EVT_MENU( mpID_LINE_GUIDES, pPlotterWindow::OnGuideLines)
71 EVT_MENU( pwID_TRASLATEACTUALFUNCTION, pPlotterWindow::onMoveFunction)
72 EVT_LEFT_UP(pPlotterWindow::onLeftUp)
75 //----------------------------------------------------------------------------
77 //----------------------------------------------------------------------------
79 pPlotterWindow::pPlotterWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag )
80 : mpWindow( parent, id, pos, size, flag)
85 scaleWay=DEFAULT_SCALE;
87 //drawGuideLines=true;
91 initialMovingCLick=-1;
97 m_popmenu.Remove( mpID_ZOOM_IN);
98 m_popmenu.Remove( mpID_ZOOM_OUT);
99 m_popmenu.Remove( mpID_CENTER);
100 m_popmenu.Remove( mpID_FIT);
101 m_popmenu.Remove( mpID_LOCKASPECT);
103 m_popmenu.Append(pwID_STARTDRAWING , _("Start Drawing"), _("Starts to draw a new function"));//it changes the actual function
104 m_popmenu.Append(pwID_STOPDRAWING , _("Stop drawing"), _("Stops of drawing the new function"));
105 m_popmenu.Append(pwID_LOAD, _("Load"), _("Load the actual function from a plane file"));
106 m_popmenu.Append(pwID_SHOWPOINTS , _("Show Points"), _("shows the discrete points of the function"));
107 m_popmenu.Append(pwID_NOSHOWPOINTS, _("No show Points"), _("Dont show the points of the function"));
108 m_popmenu.Append(pwID_ADDNEWPOINT, _("Add point"), _("Add New point to the actual function"));
109 m_popmenu.Append(pwID_DELPOINT , _("Delete point"), _("Deletes a point from the actual function."));
110 m_popmenu.Append(pwID_MYZOOMIN, _("Zoom in"), _("Zoom in the points of the function"));
111 m_popmenu.Append(pwID_MYZOOMOUT, _("Zoom out"), _("Zoom out the points of the function"));
112 m_popmenu.Append(pwID_SPLINE, _("Smooth"), _("Splines the points ofthe actual curve"));
113 m_popmenu.Append(pwID_LINE, _("Line"), _("Piecewise the points ofthe actual curve"));
114 m_popmenu.Append(pwID_SAVE, _("Save"), _("Save the actual function in plane file"));
115 m_popmenu.Append(pwID_CHANGECOLOR, _("Change Color"), _("Change the color of the function"));
116 m_popmenu.Append(pwID_TRASLATEACTUALFUNCTION, _("Start Moving Function"), _("Move the actual Function"));
118 m_popmenu.Enable(pwID_NOSHOWPOINTS,false);
119 m_popmenu.Enable(pwID_ADDNEWPOINT,false);
120 m_popmenu.Enable(pwID_SHOWPOINTS,false);
121 m_popmenu.Enable(pwID_DELPOINT,false);
122 m_popmenu.Enable(pwID_STOPDRAWING,false);
123 m_popmenu.Enable(pwID_MYZOOMIN,false);
124 m_popmenu.Enable(pwID_MYZOOMOUT,false);
125 m_popmenu.Enable(pwID_SPLINE,false);
126 m_popmenu.Enable(pwID_LINE,false);
127 m_popmenu.Enable(pwID_SAVE,false);
128 m_popmenu.Enable(pwID_LOAD,true);
129 m_popmenu.Enable(pwID_CHANGECOLOR,false);
130 m_popmenu.Enable(pwID_STARTDRAWING,true);
131 m_popmenu.Enable(pwID_LOAD,true);
132 //m_popmenu.Enable(pwID_STARTDRAWING,false);
133 m_popmenu.Enable(mpID_LINE_GUIDES,false);
134 m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,false);
140 pPlotterWindow::~pPlotterWindow()
143 //----------------------------------------------------------------------------
145 //----------------------------------------------------------------------------
148 * Sets the actual function
150 void pPlotterWindow::setActualFunction(pGraphicalFunction* newActual)
153 actual->setActual(false);
154 newActual->setActual(true);
159 * Gets the actual function
161 pGraphicalFunction* pPlotterWindow:: getActualFunction()
167 * Transform the point clicked from window
168 * to the real value,given by the scale
169 * Pre: m_scaleX and m_scaleY are already actualized
170 * with setActualScales() method
172 wxPoint pPlotterWindow:: getRealPoint(wxPoint pixelPoint)
177 //real point on the function
179 int xS=(x-offsetPixelX)/m_scaleX + offsetX + minScrX;
180 int yS=(y-offsetPixelY)/m_scaleY + offsetY + minScrY;
182 if(xS<=maxScrX && yS<=maxScrY )
196 Set the scales according to the size of the window
197 and the maximum given by the user
200 void pPlotterWindow::setActualScales()
202 // int maxX,maxY,minX,minY; // JPRx
204 if the function is drawed interactively the maxX and the
205 maxY in actual are sets by the user
208 maxX=actual->getMaxX();
209 maxY=actual->getMaxY();
215 int dx=actual->getMaxXShowed()-actual->getMinXShowed();
216 int dy=actual->getMaxYShowed()-actual->getMinYShowed();
220 m_scaleX= (((float)m_scrX-100)/dx)*zoomFactor;
221 m_scaleY= (((float)m_scrY-50)/dy)*zoomFactor;
223 //setting the maximums and minimums showed in the window
228 setMaxScrX(actual->getMaxXShowed());
229 setMinScrX(actual->getMinXShowed());
230 setMaxScrY(actual->getMaxYShowed());
231 setMinScrY(actual->getMinYShowed());
232 actual->setScreens(m_scrX,m_scrY);
235 //-------------------------
236 // Methods for interaction
237 //-------------------------
239 //------------------------------------
240 // Manipulating clicks on the plotter
241 //-------------------------------------
245 Manipulating clicks on the plotter
247 void pPlotterWindow::onLeftUp(wxMouseEvent& event)
255 //-------------------------------
256 //Traslating the actual function
257 //-------------------------------
259 Move the actual function when the user
262 void pPlotterWindow::onMoveFunction(wxCommandEvent& aEvent)
266 movingFunction=false;
267 m_popmenu.SetLabel(pwID_TRASLATEACTUALFUNCTION, _("Start Moving Function"));
272 m_popmenu.SetLabel(pwID_TRASLATEACTUALFUNCTION, _("Stop Moving Function"));
276 //-----------------------
278 //-----------------------
282 * Change the color of the function
284 void pPlotterWindow::onChangeColor(wxCommandEvent& aEvent)
289 wxColourDialog dialog(this, &data);
291 if ( dialog.ShowModal() == wxID_OK )
293 colour = dialog.GetColourData().GetColour();
298 actual->SetPen( mypen);
303 //----------------------
305 //----------------------
309 * Load the function from a .txt file
311 void pPlotterWindow::onLoad(wxCommandEvent& aEvent)
314 actual=new pGraphicalFunction(wxT("f(x) = function1(x)"),mpALIGN_NE);
315 actual->setActual(true);
316 actual->setFromWindow(false);
317 actual->SetDrawing(drawing);
318 actual->setFactorZoom(zoomFactor);
320 wxPen mypen(*wxRED, 5, wxSOLID);
322 actual->SetPen( mypen);
324 wxString nameF=wxFileSelector(_T("Save Function"));
328 functions.Append(actual);
329 addFunctionToMove(actual);
331 m_popmenu.Enable(pwID_STARTDRAWING,true);
335 //------------------------------------------
336 //Sending the paarticular event of changed actual function
337 //-------------------------------------------
338 wxCommandEvent cevent( wxEVT_PPLOTTER_CHANGED_FUNCTION, GetId() );
339 cevent.SetEventObject(this);
340 GetEventHandler()->ProcessEvent( cevent );
345 * Save the points of the function in a .txt file
347 void pPlotterWindow::onSave(wxCommandEvent& aEvent)
349 wxString nameF=wxFileSelector(_T("Save Function"));
353 //-----------------------
355 //----------------------
357 * Spline the points of the actual curve
360 void pPlotterWindow::onSplinePoints(wxCommandEvent& aEvent)
363 actual->initializeSplines();
364 actual->initializeSplineVectors();
366 m_popmenu.Enable(pwID_SPLINE,false);
367 m_popmenu.Enable(pwID_LINE,true);
371 * Change the type of drawing of the actual function
372 * to a piecewise function
374 void pPlotterWindow::onLine(wxCommandEvent& aEvent)
376 actual->clearSplineVectors();
379 m_popmenu.Enable(pwID_SPLINE,true);
380 m_popmenu.Enable(pwID_LINE,false);
384 //--------------------------
386 //---------------------------
389 * Zoom out the functions
391 void pPlotterWindow::onMyZoomOut(wxCommandEvent& aEvent)
393 wxNode* node=functions.GetFirst();
394 zoomFactor=zoomFactor*(float)(1/(float)ZOOM_FACTOR);
397 pGraphicalFunction* f= (pGraphicalFunction*)node->GetData();
399 f->setScreenX(m_scrX);
400 f->setScreenY(m_scrY);
405 f->setOffsets(m_clickedX-70,m_scrY-m_clickedY-40);
406 f->setFactorZoom(zoomFactor);
411 f->setOffsetPixelX(0);
412 f->setOffsetPixelY(0);
415 f->setFactorZoom(zoomFactor);
421 //TODO: send a event of resize
422 //setMinScrX(f->getMinXShowed());
423 //setMinScrY(f->getMinYShowed());
424 setOffsetPixelX(f->getOffsetPixelsX());
425 setOffsetPixelY(f->getOffsetPixelsY());
426 setOffsetX(f->getOffsetX());
427 setOffsetY(f->getOffsetY());
429 node=node->GetNext();
434 * Zoom in the functions
436 void pPlotterWindow::onMyZoomIn(wxCommandEvent& aEvent)
439 zoomFactor=zoomFactor*(float)ZOOM_FACTOR;
440 wxNode* node=functions.GetFirst();
443 pGraphicalFunction* f= (pGraphicalFunction*)node->GetData();
444 if(zoomFactor > 1.01)
446 f->setScreenX(m_scrX);
447 f->setScreenY(m_scrY);
448 f->setOffsets(m_clickedX-70,m_scrY-m_clickedY-40);
449 f->setFactorZoom(zoomFactor);
453 f->setOffsetPixelX(0);
454 f->setOffsetPixelY(0);
457 f->setFactorZoom(zoomFactor);
461 //TODO: send an event of resize
462 //setMinScrX(f->getMinXShowed());
463 //setMinScrY(f->getMinYShowed());
464 setOffsetPixelX(f->getOffsetPixelsX());
465 setOffsetPixelY(f->getOffsetPixelsY());
466 setOffsetX(f->getOffsetX());
467 setOffsetY(f->getOffsetY());
471 node=node->GetNext();
478 //-------------------------
480 //-------------------------
484 * Let to the user to start drawing
486 void pPlotterWindow::onStartDrawing(wxCommandEvent& aEvent)
491 actual->setActual(false);
492 if(actual->getShowPoints())
493 actual->SetShowPoints(false);
495 m_popmenu.Enable(pwID_NOSHOWPOINTS,false);
496 m_popmenu.Enable(pwID_ADDNEWPOINT,false);
497 m_popmenu.Enable(pwID_SHOWPOINTS,false);
498 m_popmenu.Enable(pwID_DELPOINT,false);
499 m_popmenu.Enable(pwID_MYZOOMIN,false);
500 m_popmenu.Enable(pwID_MYZOOMOUT,false);
501 m_popmenu.Enable(pwID_STARTDRAWING,false);
502 m_popmenu.Enable(pwID_SPLINE,false);
503 m_popmenu.Enable(pwID_LINE,false);
504 m_popmenu.Enable(pwID_STOPDRAWING,true);
505 m_popmenu.Enable(pwID_SAVE,false);
506 m_popmenu.Enable(pwID_LOAD,false);
507 m_popmenu.Enable(pwID_CHANGECOLOR,false);
508 m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,false);
515 actual=new pGraphicalFunction(wxT("f(x) = function1(x)"),mpALIGN_NE);
516 actual->setActual(true);
517 actual->setFromWindow(true);
518 actual->setScaleWay(USER_SCALE);
519 actual->SetDrawing(drawing);
520 actual->setFactorZoom(zoomFactor);
522 //we change the offsets
523 setOffsetPixelX(actual->getOffsetPixelsX());
524 setOffsetPixelY(actual->getOffsetPixelsY());
525 setOffsetX(actual->getOffsetX());
526 setOffsetY(actual->getOffsetY());
529 wxPen mypen(*wxRED, 5, wxSOLID);
531 actual->SetPen( mypen);
534 int result = wxMessageBox("Do you Want a Smooth Curve?", "Spline Points", wxYES_NO | wxCANCEL);
541 /**************************************************************************/
543 /**************************************************************************/
545 //opening the dialog of maximums
547 MaximumsDialog *dlg=new MaximumsDialog(this,_T("Set Maximums"));
549 if(dlg->ShowModal()== wxID_OK )
551 maxX=dlg->getXValue();
552 maxY=dlg->getYValue();
553 if(maxX>0 && maxY>0 && actual->getFromWindow())
558 actual->setMaxX(maxScrX);
559 actual->setMinX(minScrX);
560 actual->setMaxY(maxY);
563 actual->setMinShowedX(0);
564 actual->setMinShowedY(0);
565 actual->setMaxShowedX(maxX);
566 actual->setMaxShowedY(maxY);
570 else if(maxX<0 || maxY<0)
572 wxMessageBox(_T("Both numbers have to be positive, please enter valid numbers"), _T("Error"),
578 m_popmenu.Enable(pwID_NOSHOWPOINTS,false);
579 m_popmenu.Enable(pwID_ADDNEWPOINT,false);
580 m_popmenu.Enable(pwID_SHOWPOINTS,false);
581 m_popmenu.Enable(pwID_DELPOINT,false);
582 m_popmenu.Enable(pwID_MYZOOMIN,false);
583 m_popmenu.Enable(pwID_MYZOOMOUT,false);
584 m_popmenu.Enable(pwID_STARTDRAWING,true);
585 m_popmenu.Enable(pwID_SPLINE,false);
586 m_popmenu.Enable(pwID_LINE,false);
587 m_popmenu.Enable(pwID_STOPDRAWING,false);
588 m_popmenu.Enable(pwID_SAVE,false);
589 m_popmenu.Enable(pwID_LOAD,true);
590 m_popmenu.Enable(pwID_CHANGECOLOR,false);
591 m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,false);
593 //actual->SetDrawing(false);
597 else if(maxX==0 && maxY==0)
599 actual->setMaxX(100);
601 actual->setMaxY(100);
604 actual->setMinShowedX(0);
605 actual->setMinShowedY(0);
606 actual->setMaxShowedX(100);
607 actual->setMaxShowedY(100);
619 else if(dlg->ShowModal()== wxID_CANCEL)
624 m_popmenu.Enable(pwID_NOSHOWPOINTS,false);
625 m_popmenu.Enable(pwID_ADDNEWPOINT,false);
626 m_popmenu.Enable(pwID_SHOWPOINTS,false);
627 m_popmenu.Enable(pwID_DELPOINT,false);
628 m_popmenu.Enable(pwID_MYZOOMIN,false);
629 m_popmenu.Enable(pwID_MYZOOMOUT,false);
630 m_popmenu.Enable(pwID_STARTDRAWING,true);
631 m_popmenu.Enable(pwID_SPLINE,false);
632 m_popmenu.Enable(pwID_LINE,false);
633 m_popmenu.Enable(pwID_STOPDRAWING,false);
634 m_popmenu.Enable(pwID_SAVE,false);
635 m_popmenu.Enable(pwID_LOAD,true);
636 m_popmenu.Enable(pwID_CHANGECOLOR,false);
637 m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,false);
639 //actual->SetDrawing(false);
645 //------------------------------------------
646 //Sending the paarticular event of changed actual function
647 //-------------------------------------------
648 wxCommandEvent cevent( wxEVT_PPLOTTER_CHANGED_FUNCTION, GetId() );
649 cevent.SetEventObject(this);
650 GetEventHandler()->ProcessEvent( cevent );
656 Stop the drawing of the actual function
658 void pPlotterWindow::onStopDrawing(wxCommandEvent& aEvent)
661 actual->SetDrawing(drawing);
662 functions.Append(actual);
663 addFunctionToMove(actual);
664 m_popmenu.Enable(pwID_ADDNEWPOINT,true);
665 m_popmenu.Enable(pwID_DELPOINT,true);
666 m_popmenu.Enable(pwID_SHOWPOINTS,true);
667 m_popmenu.Enable(pwID_MYZOOMIN,true);
668 m_popmenu.Enable(pwID_MYZOOMOUT,true);
669 m_popmenu.Enable(pwID_STARTDRAWING,true);
670 m_popmenu.Enable(pwID_SPLINE,true);
671 m_popmenu.Enable(pwID_STOPDRAWING,false);
672 m_popmenu.Enable(pwID_LINE,false);
673 m_popmenu.Enable(pwID_CHANGECOLOR,true);
674 m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,true);
676 if(actual->getSizePoints()==0||actual->getSizePoints()==1)
679 m_popmenu.Enable(pwID_ADDNEWPOINT,false);
680 //functions.DeleteObject(actual);
689 * The user wants to see the points(given) of the function
691 void pPlotterWindow::onShowPoints(wxCommandEvent& aEvent)
693 actual->SetShowPoints(true);
694 m_popmenu.Enable(pwID_NOSHOWPOINTS,true);
695 m_popmenu.Enable(pwID_SHOWPOINTS,false);
699 * The user doesnt want see the points of the function
701 void pPlotterWindow::onNoShowPoints(wxCommandEvent& aEvent)
703 actual->SetShowPoints(false);
704 m_popmenu.Enable(pwID_NOSHOWPOINTS,false);
705 m_popmenu.Enable(pwID_SHOWPOINTS,true);
709 * if the user is going to add a point to the function
711 void pPlotterWindow::onAddPoint(wxMouseEvent& aEvent)
714 wxPoint point=aEvent.GetPosition();
716 point.y=m_scrY-point.y;
717 wxPoint realPoint=getRealPoint(point);
719 bool isAValidPoint=realPoint.x>=0 && realPoint.y>=0;
721 if(isAValidPoint && drawing)
723 if(actual->AddPoint(realPoint.x,realPoint.y))
725 text = wxString::Format(_T("added point ( %d, %d)\n"), realPoint.x, realPoint.y);
727 //m_log->AppendText(text);
729 //if the function is smooth
730 if(actual->getType()==2)
732 actual->clearSplineVectors();
733 actual->addSplinesPoints();
734 actual->initializeSplineVectors();
740 else if(isAValidPoint && !drawing && aEvent.m_shiftDown && actual!=NULL)
742 if(actual->AddNewPoint(realPoint.x,realPoint.y))
744 text = wxString::Format(_T("added point ( %d, %d)\n"), realPoint.x, realPoint.y);
745 //if the function is smooth
746 if(actual->getType()==2)
748 actual->clearSplineVectors();
749 actual->addSplinesPoints();
750 actual->initializeSplineVectors();
756 //made a click for moving the points
757 else if(!movingPoints)
760 movingPointIndex=actual->validPointOnFunction(realPoint);
761 if(movingPointIndex>=0)
765 //------------------------------------------
767 //-------------------------------------------
768 wxCommandEvent cevent( wxEVT_PPLOTTER_POINT_ADD, GetId() );
769 cevent.SetEventObject(this);
771 //------------------------------------------
772 //Sending the general event
773 //-------------------------------------------
774 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
775 pevent.SetEventObject(this);
777 GetEventHandler()->ProcessEvent( cevent );
778 GetEventHandler()->ProcessEvent( pevent );
782 * Adds a point to the function after the definition of the initial points of the function
783 * know this point is a point of the function
786 void pPlotterWindow::onAddNewPoint(wxCommandEvent& aEvent)
790 point.y=m_scrY-m_clickedY;
792 wxPoint realPoint=getRealPoint(point);
793 bool isAValidPoint=realPoint.x>=0 && realPoint.y>=0;
796 if(isAValidPoint && actual->AddNewPoint(realPoint.x,realPoint.y))
798 text = wxString::Format(_T("added point ( %d, %d)\n"), realPoint.x, realPoint.y);
799 //if the function is smooth
800 if(actual->getType()==2)
802 actual->clearSplineVectors();
803 actual->addSplinesPoints();
804 actual->initializeSplineVectors();
808 //------------------------------------------
810 //-------------------------------------------
811 wxCommandEvent cevent( wxEVT_PPLOTTER_POINT_ADD, GetId() );
812 cevent.SetEventObject(this);
814 //------------------------------------------
815 //Sending the general event
816 //-------------------------------------------
817 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
818 pevent.SetEventObject(this);
820 GetEventHandler()->ProcessEvent( cevent );
821 GetEventHandler()->ProcessEvent( pevent );
827 * if the user is going to delete a point of the function
829 void pPlotterWindow::onDeletePoint(wxCommandEvent& aEvent)
833 point.y=m_scrY-m_clickedY;
835 //actual->setScreenX(m_scrX);
836 //actual->setScreenY(m_scrY);
838 wxPoint realPoint=getRealPoint(point);
840 bool isAValidPoint=realPoint.x>=0 && realPoint.y>=0;
842 //this method verify a sensible region in every point of actual
843 int pointIndex=actual->validPointOnFunction(realPoint);
844 if(isAValidPoint && actual->deletePointAt(pointIndex))
847 if(actual->getSizePoints()==0)
849 //functions.DeleteObject(actual);
853 //if the function is smooth
854 if(actual->getType()==2)
856 actual->clearSplineVectors();
857 actual->addSplinesPoints();
858 actual->initializeSplineVectors();
861 text = wxString::Format(_T("deleted point ( %d, %d)\n"), realPoint.x, realPoint.y);
863 //------------------------------------------
865 //-------------------------------------------
866 wxCommandEvent cevent( wxEVT_PPLOTTER_POINT_DELETE, GetId() );
867 cevent.SetEventObject(this);
868 //------------------------------------------
869 //Sending the general event
870 //-------------------------------------------
871 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
872 pevent.SetEventObject(this);
874 GetEventHandler()->ProcessEvent( cevent );
875 GetEventHandler()->ProcessEvent( pevent );
881 * If the mouse is moving in the plot area
882 * is because the user is moving a point of the current curve
883 * the user has to call before show points, to see the points of the
887 void pPlotterWindow::onMouseMove(wxMouseEvent& event)
889 wxPoint point=event.GetPosition();
891 point.y=m_scrY-point.y;
893 wxPoint realPoint=getRealPoint(point);
894 bool isAValidPoint=realPoint.x>=0 && realPoint.y>=0;
896 if(isAValidPoint && !drawing && actual!=NULL && !movingFunction && movingPoints)
898 //never is going to get in
899 if(movingPointIndex==-1)
901 //this method verify a sensible region in every point of _actualFunction
902 movingPointIndex=actual->validPointOnFunction(realPoint);
905 else if(event.LeftIsDown())
908 /*if((movingPointIndex-1)>=0 && (movingPointIndex+1)<actual->getSizePoints() && actual->getEditable())
910 wxNode* next= actual->GetPointAt(movingPointIndex+1);
911 wxNode* before=actual->GetPointAt(movingPointIndex-1);
914 pFunctionPoint* np=(pFunctionPoint*)(next->GetData());
917 int n=np->getRealX();
921 p.x=np->getRealX()-1;
923 change=actual->changePoint(p,movingPointIndex);
928 //if the function is smooth
929 if(actual->getType()==2)
931 actual->clearSplineVectors();
932 actual->addSplinesPoints();
933 actual->initializeSplineVectors();
937 text = wxString::Format(_T("Moved point ( %d, %d)\n"), p.x, p.y);
939 //------------------------------------------
940 //Sending the particular event
941 //-------------------------------------------
942 wxCommandEvent cevent( wxEVT_PPLOTTER_POINT_MOVE, GetId() );
943 cevent.SetEventObject(this);
945 //------------------------------------------
946 //Sending the general event
947 //-------------------------------------------
948 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
949 pevent.SetEventObject(this);
952 GetEventHandler()->ProcessEvent( cevent );
953 GetEventHandler()->ProcessEvent( pevent );
960 pFunctionPoint* bp=(pFunctionPoint*)(before->GetData());
963 int b=bp->getRealX();
967 p.x=bp->getRealX()+1;
969 change=actual->changePoint(p,movingPointIndex);
973 //if the function is smooth
974 if(actual->getType()==2)
976 actual->clearSplineVectors();
977 actual->addSplinesPoints();
978 actual->initializeSplineVectors();
981 text = wxString::Format(_T("Moved point ( %d, %d)\n"), p.x, p.y);
983 //------------------------------------------
984 //Sending the particular event
985 //-------------------------------------------
986 wxCommandEvent cevent( wxEVT_PPLOTTER_POINT_MOVE, GetId() );
987 cevent.SetEventObject(this);
989 //------------------------------------------
990 //Sending the general event
991 //-------------------------------------------
992 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
993 pevent.SetEventObject(this);
996 GetEventHandler()->ProcessEvent( cevent );
997 GetEventHandler()->ProcessEvent( pevent );
1004 // SIL ******************************************************************* // SIL
1005 if((movingPointIndex-1)>=0 && (movingPointIndex+1)<actual->getSizePoints() && actual->getEditable())
1007 change=actual->changePoint(realPoint,movingPointIndex);
1012 //if the function is smooth
1013 if(actual->getType()==2)
1015 actual->clearSplineVectors();
1016 actual->addSplinesPoints();
1017 actual->initializeSplineVectors();
1019 text = wxString::Format(_T("Moved point ( %d, %d)\n"), realPoint.x, realPoint.y);
1021 //------------------------------------------
1022 //Sending the particular event
1023 //-------------------------------------------
1024 wxCommandEvent cevent( wxEVT_PPLOTTER_POINT_MOVE, GetId() );
1025 cevent.SetEventObject(this);
1027 //------------------------------------------
1028 //Sending the general event
1029 //-------------------------------------------
1030 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
1031 pevent.SetEventObject(this);
1034 GetEventHandler()->ProcessEvent( cevent );
1035 GetEventHandler()->ProcessEvent( pevent );
1037 // SIL ******************************************************************* // SIL
1039 //change the point that is in the index, returns true if could be changed.
1040 if(!change && actual->changePoint(realPoint,movingPointIndex)&& actual->getEditable())
1043 //if the function is smooth
1044 if(actual->getType()==2)
1046 actual->clearSplineVectors();
1047 actual->addSplinesPoints();
1048 actual->initializeSplineVectors();
1051 text = wxString::Format(_T("Moved point ( %d, %d)\n"), realPoint.x,realPoint.y);
1055 //------------------------------------------
1056 //Sending the particular event
1057 //-------------------------------------------
1058 wxCommandEvent cevent( wxEVT_PPLOTTER_POINT_MOVE, GetId() );
1059 cevent.SetEventObject(this);
1061 //------------------------------------------
1062 //Sending the general event
1063 //-------------------------------------------
1064 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
1065 pevent.SetEventObject(this);
1068 GetEventHandler()->ProcessEvent( cevent );
1069 GetEventHandler()->ProcessEvent( pevent );
1074 movingPointIndex=-1;
1078 //if the user is drawing
1079 else if(isAValidPoint && drawing)
1082 actual->SetMousePoint(realPoint);
1085 //is moving the function
1086 else if(isAValidPoint && movingFunction && actual!=NULL)
1088 actual->setScreenX(m_scrX);
1089 actual->setScreenY(m_scrY);
1091 if((initialMovingCLick==-1) && event.LeftIsDown() )
1093 if(actual->isInFunction(realPoint.x,realPoint.y))
1095 initialMovingCLick=event.GetPosition().x;
1096 int numPoints=actual->getSizePoints();
1098 backUpActualVector.clear();
1101 //if(i>0 && i< (numPoints-1))
1103 wxNode* pointNode=actual->GetPointAt(i);
1104 pFunctionPoint* point= (pFunctionPoint*)pointNode->GetData();
1105 backUpActualVector.push_back(point->getRealX());
1112 else if(event.LeftIsDown())
1114 wxPoint aux(initialMovingCLick,0);
1116 wxPoint p1r=getRealPoint(event.GetPosition());
1117 wxPoint p2r=getRealPoint(aux);
1119 double delta = p1r.x-p2r.x;
1120 int numPoints=actual->getSizePoints();
1127 if(i>0 && i<(numPoints-1))
1129 wxNode* pointNode=actual->GetPointAt(i);
1130 pFunctionPoint* point= (pFunctionPoint*)pointNode->GetData();
1131 int xNew=backUpActualVector[i]+delta;
1132 //it has to preserve the state of functin
1133 if(backUpActualVector[0]<xNew && backUpActualVector[numPoints-1]>xNew)
1134 point->setRealX(xNew);
1145 wxNode* pointNode=actual->GetPointAt(i);
1146 pFunctionPoint* point= (pFunctionPoint*)pointNode->GetData();
1147 int xNew=backUpActualVector[i]+delta;
1148 point->setRealX(xNew);
1153 if(actual->getType()==2)
1155 actual->clearSplineVectors();
1156 actual->addSplinesPoints();
1157 actual->initializeSplineVectors();
1165 initialMovingCLick=-1;
1171 * if the user give us a double click is because he wants to change
1172 * the actual function to the function that has that point
1174 void pPlotterWindow::onChangeActual(wxMouseEvent& event)
1176 wxString text = _T("\n points \n");
1181 //we have to call showpoints before changing the function
1182 wxPoint point=event.GetPosition();
1183 /*****************************/
1184 point.y=m_scrY-point.y;
1185 /*****************************/
1189 //real point on the function
1190 wxPoint realPoint;//=getRealPoint(point);
1191 bool isAValidPoint=realPoint.x>=0 && realPoint.y>=0;
1194 wxNode * node= functions.GetFirst();
1197 pGraphicalFunction* fnode=(pGraphicalFunction*)node->GetData();
1200 int maxX=fnode->getMaxXShowed();
1201 int maxY=fnode->getMaxYShowed();
1202 int minX=fnode->getMinXShowed();
1203 int minY=fnode->getMinYShowed();
1207 float sx=(((float)m_scrX-100)/(maxScrX-minScrX))*zoomFactor;
1208 float sy=(((float)m_scrY-50)/(maxScrY-minScrY))*zoomFactor;
1212 float sx=(((float)m_scrX-100)/(maxX-minX))*zoomFactor;
1213 float sy=(((float)m_scrY-50)/(maxY-minY))*zoomFactor;
1216 realPoint.x=((point.x-70-fnode->getOffsetPixelsX())/sx)+ fnode->getOffsetX()+ minX;
1217 realPoint.y=((point.y-40-fnode->getOffsetPixelsY())/sy)+ fnode->getOffsetY()+ minY;
1221 if(fnode->getActual())
1222 text = wxString::Format(_T("Selected point ( %d, %d)\n"), realPoint.x, realPoint.y);
1223 //m_log->AppendText(text);
1225 bool hasIt=fnode->isInFunction(realPoint.x,realPoint.y);
1227 if(fnode->getEditable())
1228 hasIt=fnode->isInFunction(realPoint.x,realPoint.y);
1236 setActualFunction(fnode);
1237 //we change the offsets
1238 setOffsetPixelX(fnode->getOffsetPixelsX());
1239 setOffsetPixelY(fnode->getOffsetPixelsY());
1240 setOffsetX(fnode->getOffsetX());
1241 setOffsetY(fnode->getOffsetY());
1245 if(!actual->getFromWindow() && actual->getEditable()||actual->getFromWindow() && actual->getEditable())
1247 m_popmenu.Enable(pwID_ADDNEWPOINT,true);
1248 m_popmenu.Enable(pwID_DELPOINT,true);
1249 if(actual->getShowPoints())
1251 m_popmenu.Enable(pwID_SHOWPOINTS,false);
1252 m_popmenu.Enable(pwID_NOSHOWPOINTS,true);
1256 m_popmenu.Enable(pwID_SHOWPOINTS,true);
1257 m_popmenu.Enable(pwID_NOSHOWPOINTS,false);
1259 m_popmenu.Enable(pwID_MYZOOMIN,true);
1260 m_popmenu.Enable(pwID_MYZOOMOUT,true);
1261 if(actual->getType()==2)//Smoothed function
1263 m_popmenu.Enable(pwID_SPLINE,false);
1264 m_popmenu.Enable(pwID_LINE,true);
1268 m_popmenu.Enable(pwID_SPLINE,true);
1269 m_popmenu.Enable(pwID_LINE,false);
1274 m_popmenu.Enable(pwID_LOAD,false);
1275 m_popmenu.Enable(pwID_STARTDRAWING,false);
1279 m_popmenu.Enable(pwID_LOAD,true);
1280 m_popmenu.Enable(pwID_STARTDRAWING,true);
1283 m_popmenu.Enable(pwID_SAVE,true);
1284 m_popmenu.Enable(pwID_LOAD,false);
1285 m_popmenu.Enable(pwID_STOPDRAWING,false);
1286 m_popmenu.Enable(pwID_CHANGECOLOR,true);
1287 m_popmenu.Enable(mpID_LINE_GUIDES,true);
1288 m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,true);
1290 //for the functions that came from data and arent editables
1291 else if(!actual->getFromWindow() && !actual->getEditable()||actual->getFromWindow() && !actual->getEditable())
1293 if(actual->getShowPoints())
1295 m_popmenu.Enable(pwID_SHOWPOINTS,false);
1296 m_popmenu.Enable(pwID_NOSHOWPOINTS,true);
1300 m_popmenu.Enable(pwID_SHOWPOINTS,true);
1301 m_popmenu.Enable(pwID_NOSHOWPOINTS,false);
1303 if(actual->getType()==2)//Smoothed function
1305 m_popmenu.Enable(pwID_SPLINE,false);
1306 m_popmenu.Enable(pwID_LINE,true);
1310 m_popmenu.Enable(pwID_SPLINE,true);
1311 m_popmenu.Enable(pwID_LINE,false);
1316 m_popmenu.Enable(pwID_LOAD,false);
1317 m_popmenu.Enable(pwID_STARTDRAWING,false);
1319 m_popmenu.Enable(pwID_SAVE,false);
1320 m_popmenu.Enable(pwID_LOAD,false);
1321 m_popmenu.Enable(pwID_STOPDRAWING,false);
1322 m_popmenu.Enable(pwID_MYZOOMIN,true);
1323 m_popmenu.Enable(pwID_MYZOOMOUT,true);
1324 m_popmenu.Enable(pwID_CHANGECOLOR,true);
1325 m_popmenu.Enable(mpID_LINE_GUIDES,true);
1326 m_popmenu.Enable(pwID_SAVE,true);
1327 m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,true);
1330 //if the function is smooth
1331 if(actual->getType()==2)
1333 actual->clearSplineVectors();
1334 actual->addSplinesPoints();
1335 actual->initializeSplineVectors();
1340 //------------------------------------------
1341 //Sending the particular event
1342 //-------------------------------------------
1343 wxCommandEvent cevent( wxEVT_PPLOTTER_CHANGED_FUNCTION, GetId() );
1344 cevent.SetEventObject(this);
1346 //------------------------------------------
1347 //Sending the general event
1348 //-------------------------------------------
1349 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
1350 pevent.SetEventObject(this);
1352 GetEventHandler()->ProcessEvent( cevent );
1353 GetEventHandler()->ProcessEvent( pevent );
1356 node=node->GetNext();
1360 //the user is finishing the drawing of the function
1364 functions.Append(actual);
1369 * The user wants to change the type of function: line, smooth
1370 * TODO is an extension
1372 void pPlotterWindow::changeFuntionType(int aTheType, bool aForAll)
1376 //------------------------------------------
1377 //If the data doesnt come from interaction
1378 //-------------------------------------------
1380 * Add a function to the window, given its points
1382 int pPlotterWindow:: addFunction(pGraphicalFunction * function)
1384 if(function->getType()==2)
1386 function->initializeSplines();
1387 function->initializeSplineVectors();
1390 // bool added1= functions.Append(function)!=NULL; // JPRx
1392 int id=functions.IndexOf(function);
1393 /* bool added2= */ AddLayer(function);// JPRx
1395 return id;//added1 && added2;
1398 * Delete a point of a function
1399 * @param point: is the real value that the functon takes, and is gointg to be deleted
1402 bool pPlotterWindow::DeletePointFunction(pGraphicalFunction* function,wxPoint point)
1405 wxNode* node= functions.GetFirst();
1408 pGraphicalFunction* f= (pGraphicalFunction*)node->GetData();
1411 return function->DeletePoint(point.x,point.y);
1413 node=node->GetNext();
1418 * Delete a function of the plotter
1420 bool pPlotterWindow::deleteFunction(pGraphicalFunction * f)
1422 functions.DeleteObject(f);
1423 functionsToMove.DeleteObject(f);
1427 * Creates and returns a graphical funcion according to the indicated vectors.
1429 pGraphicalFunction * pPlotterWindow::getFunctionForVectors( std::vector<double> *vectorX, std::vector<double> *vectorY )
1431 double coordX = -1 ;
1434 pGraphicalFunction * ff = new pGraphicalFunction( _T(" "), 1);
1437 int sizeX = vectorX->size();
1438 int sizeY = vectorY->size();
1439 if( sizeX == sizeY )
1443 coordX = (*vectorX)[i];
1444 coordY = (*vectorY)[i];
1445 ff -> AddPoint( coordX, coordY);
1450 InitFunctionForVectors( ff );
1454 pGraphicalFunction * pPlotterWindow::getFunctionForVectors( double * vectorX, int sizeX, double * vectorY, int sizeY )
1456 double coordX = -1 ;
1459 pGraphicalFunction * ff = new pGraphicalFunction( _T(" "), 1);
1461 /*wxString text = "\n Including points from two vectors \n";
1462 m_log->AppendText(text);*/
1471 ff -> AddPoint( coordX, coordY);
1472 /* text = wxString::Format("Included point ( %d, %d)\n", coordX, coordY);
1473 m_log->AppendText(text);*/
1481 InitFunctionForVectors( ff );
1487 void pPlotterWindow::InitFunctionForVectors( pGraphicalFunction *ff )
1489 int maxX,maxY,minX,minY;
1491 if the function is not drawed interactively the maxX and the
1492 maxY are the from the points of the function
1496 minX= ff->getMinX();
1497 minY= ff->getMinY();
1500 ff->setMinShowedX(minX);
1501 ff->setMinShowedY(minY);
1502 ff->setMaxShowedX(maxX);
1503 ff->setMaxShowedY(maxY);
1505 GetClientSize(&m_scrX,&m_scrY);
1508 if((maxX-minX)!=0 && (maxY-minY)!=0)
1510 m_scaleX= ((float)m_scrX-100)/(maxX-minX);
1511 m_scaleY= ((float)m_scrY-50)/(maxY-minY);
1523 m_popmenu.Enable(pwID_NOSHOWPOINTS,true);
1524 m_popmenu.Enable(pwID_ADDNEWPOINT,true);
1525 m_popmenu.Enable(pwID_SHOWPOINTS,false);
1526 m_popmenu.Enable(pwID_DELPOINT,true);
1527 //m_popmenu.Enable(pwID_SPLINE,false);
1528 //m_popmenu.Enable(pwID_LINE,true);
1529 m_popmenu.Enable(pwID_SAVE,true);
1530 m_popmenu.Enable(pwID_LOAD,false);
1531 m_popmenu.Enable(pwID_CHANGECOLOR,true);
1532 //m_popmenu.Enable(pwID_STARTDRAWING,false);
1533 m_popmenu.Enable(mpID_LINE_GUIDES,true);
1534 m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,true);
1535 //------------------------------------------
1536 //Sending the particular event of changed actual function
1537 //-------------------------------------------
1538 wxCommandEvent cevent( wxEVT_PPLOTTER_CHANGED_FUNCTION, GetId() );
1539 cevent.SetEventObject(this);
1540 GetEventHandler()->ProcessEvent( cevent );
1549 //actual->setScreens(scrX,scrY);
1550 //actual->setScales();
1551 //setActualScales();
1554 bool pPlotterWindow::AddFunction(wxPoint realPoints[],int numberOfPoints,wxString name,int flags)
1556 pGraphicalFunction* function= new pGraphicalFunction(name,flags);
1558 for(int i= 0; i<numberOfPoints;i++)
1560 int x=realPoints[i].x;
1561 int y=realPoints[i].y;
1562 bool added=function->AddPoint(x,y);
1566 functions.Append(function);
1567 bool addL=mpWindow::AddLayer(function);
1570 mpWindow::UpdateAll();
1577 * Actualizes the view range of the plotter and the actual function
1578 * @param newMinX Is the min-value to be shown in the x-scale
1579 * @param newMaxX Is the max-value to be shown in the x-scale
1584 void pPlotterWindow :: actualizeViewRange(int newMinX, int newMaxX)
1586 int minPixX,maxPixX/*, min, max*/; // JPRx
1591 int dx=newMaxX-newMinX;
1595 sx= (((float)m_scrX-100)/dx)*zoomFactor;
1601 //vx.at(i)-offsetX)*scaleX+offsetpx
1602 if(minScrX!=newMinX)
1604 setOffsetX(newMinX);
1605 setMinScrX(newMinX);
1606 actual->setOffsetX(newMinX);
1607 actual->setMinShowedX(newMinX);
1609 wxNode * node= functions.GetFirst();
1612 pGraphicalFunction* fnode=(pGraphicalFunction*)node->GetData();
1615 if(!fnode->getActual())
1617 fnode->setScreens(m_scrX,m_scrY);
1619 //max=minPixX/fnode->getScaleX();
1620 min=minPixX/fnode->getScaleX();
1621 fnode->setOffsetX(min);
1622 fnode->setMinShowedX(min);
1626 node=node->GetNext();
1631 if(maxScrX!=newMaxX)
1633 setMaxScrX(newMaxX);
1634 actual->setMaxShowedX(newMaxX);
1636 wxNode * node= functions.GetFirst();
1640 pGraphicalFunction* fnode=(pGraphicalFunction*)node->GetData();
1643 if(!fnode->getActual())
1645 fnode->setScreens(m_scrX,m_scrY);
1647 max=maxPixX/fnode->getScaleX();
1648 //min=maxPixX/fnode->getScaleX();
1649 //fnode->setOffsetX(max);
1650 //fnode->setMinShowedX(min);
1651 fnode->setMaxShowedX(max);
1655 node=node->GetNext();
1660 if(actual->getMinXShowed()!=actual->getMinX() || actual->getMinYShowed()!=actual->getMinY()||
1661 actual->getMaxXShowed()!=actual->getMaxX() || actual->getMaxYShowed()!=actual->getMaxY())
1663 m_popmenu.Enable(pwID_MYZOOMIN,false);
1664 m_popmenu.Enable(pwID_MYZOOMOUT,false);
1666 else if(actual->getMinXShowed()==actual->getMinX() && actual->getMaxXShowed()==actual->getMaxX())
1669 m_popmenu.Enable(pwID_MYZOOMIN,true);
1670 m_popmenu.Enable(pwID_MYZOOMOUT,true);
1677 * Guide lines menu handler method that reacts to the mpID_LINE_GUIDES command event
1678 * event The corresponding event to handle
1680 void pPlotterWindow :: OnGuideLines (wxCommandEvent &event)
1682 wxString nextAction_text;
1685 setLineGuidesCondition(false);
1686 // nextAction_text << "Turn on guide lines";
1687 nextAction_text = _T("Turn on guide lines");
1692 setLineGuidesCondition(true);
1693 // nextAction_text << "Turn off guide lines";
1694 nextAction_text = _T("Turn off guide lines");
1697 //------------------------------------------
1698 //Sending the paarticular event of changed actual function
1699 //-------------------------------------------
1700 wxCommandEvent cevent( wxEVT_PPLOTTER_GUIDELINES, GetId() );
1701 cevent.SetEventObject(this);
1702 GetEventHandler()->ProcessEvent( cevent );
1705 m_popmenu.SetLabel ( mpID_LINE_GUIDES, nextAction_text );
1708 Get a function in the plotter given the index
1710 pGraphicalFunction* pPlotterWindow::getFunction(int index)
1712 wxNode* node=functions.Item(index);
1713 return (pGraphicalFunction*)node->GetData();
1716 move the functions that the user wants to move
1717 and that were set in functionsToMove
1718 @param porcentageMinX:the percentage that the minShowed
1719 of the functions have to be move
1720 0<=porcentageMinX<=1
1721 @param porcentageMaxX:the percentage that the maxShowed
1722 of the functions have to be move
1723 0<=porcentageMaxX<=1
1727 void pPlotterWindow::moveFunctions( float porcentageMinX,float porcentageMaxX)
1729 //Adding the actual function
1731 //functionsToMove.Append(actual);
1734 //float minShowed,maxShowed,fMaxXShowed,fMinXShowed;
1738 int minShowed,maxShowed,fMaxXShowed,fMinXShowed;
1739 wxNode* fnode=functionsToMove.GetFirst();
1742 pGraphicalFunction* fg=(pGraphicalFunction*)fnode->GetData();
1743 x=porcentageMaxX*(fg->getMaxX()-fg->getMinX());
1744 y=porcentageMinX*(fg->getMaxX()-fg->getMinX());
1746 maxShowed=fg->getMinX()+ x;
1747 minShowed=fg->getMinX()+ y;
1749 fMinXShowed=fg->getMinXShowed();
1750 fMaxXShowed=fg->getMaxXShowed();
1752 if(fMinXShowed!=minShowed)
1756 setOffsetX(minShowed);
1757 setMinScrX(minShowed);
1759 fg->setOffsetX(minShowed);
1760 fg->setMinShowedX(minShowed);
1762 if(fMaxXShowed!=maxShowed)
1766 setMaxScrX(maxShowed);
1768 fg->setMaxShowedX(maxShowed);
1770 if(fg->getActual()&& (fg->getMinXShowed()!=fg->getMinX() || fg->getMinYShowed()!=fg->getMinY()||
1771 fg->getMaxXShowed()!=fg->getMaxX() || fg->getMaxYShowed()!=fg->getMaxY()))
1775 m_popmenu.Enable(pwID_MYZOOMIN,false);
1776 m_popmenu.Enable(pwID_MYZOOMOUT,false);
1779 else if(fg->getActual()&& fg->getMinXShowed()==fg->getMinX() && fg->getMaxXShowed()==fg->getMaxX())
1783 m_popmenu.Enable(pwID_MYZOOMIN,true);
1784 m_popmenu.Enable(pwID_MYZOOMOUT,true);
1789 fnode=fnode->GetNext();
1794 adds a function such that when the min or max of the bar
1795 changes it is going to that function
1797 int pPlotterWindow::addFunctionToMove(pGraphicalFunction *function)
1799 // bool added1= functionsToMove.Append(function)!=NULL; // JPRx
1800 int id=functionsToMove.IndexOf(function);
1804 //----------------------------
1805 //Handling Options Menu
1806 //----------------------------
1807 void pPlotterWindow::setPopUpMenu(bool startD,bool stopD,bool smooth,bool line, bool zoomIn,
1808 bool zoomOut,bool showPoints,bool noShowPoints,bool changeColor, bool addP,
1809 bool delPoint,bool load,bool save)
1812 pwID_ADDPOINT = 2010, //!< add a point to the function
1813 pwID_DELPOINT, //!< delete a point of the function
1814 pwID_SHOWPOINTS, //!<shows the points that the function has
1815 pwID_STARTDRAWING, //!<let to the user to start drawing the curve
1816 pwID_DELFUNCTION, //!<delete a function that is in the plotter
1817 pwID_STOPDRAWING,//!<Stops the drawing of the function
1818 pwID_ADDNEWPOINT,//!<add a new point to the function.
1819 pwID_NOSHOWPOINTS, //!<No show the points of the function.
1820 pwID_MYZOOMIN,//!<Zoom in the function
1821 pwID_MYZOOMOUT,//!<Zoom out the points of the function.
1822 pwID_SPLINE,//!<Spline the actual curve.
1823 pwID_LINE,//!<Piecewise the actual curve.
1824 pwID_SAVE,//!<Save the function in a .txt file.
1825 pwID_LOAD, //!<Load the function from a .txt file.
1826 pwID_CHANGECOLOR, //!<Change the color of the function
1827 pwID_TRASLATEACTUALFUNCTION //!<move the actual function
1830 m_popmenu.Remove( pwID_STARTDRAWING);
1832 m_popmenu.Remove( pwID_STOPDRAWING);
1834 m_popmenu.Remove( pwID_LOAD);
1836 m_popmenu.Remove( pwID_SAVE);
1838 m_popmenu.Remove( pwID_SHOWPOINTS);
1840 m_popmenu.Remove( pwID_NOSHOWPOINTS);
1842 m_popmenu.Remove( pwID_SPLINE);
1844 m_popmenu.Remove( pwID_LINE);
1846 m_popmenu.Remove( pwID_MYZOOMIN);
1848 m_popmenu.Remove( pwID_MYZOOMOUT);
1850 m_popmenu.Remove( pwID_CHANGECOLOR);
1852 m_popmenu.Remove( pwID_ADDPOINT);
1854 m_popmenu.Remove( pwID_DELPOINT);