pPlotterWindow.cxx

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 // Class definition include
00003 //----------------------------------------------------------------------------
00004 #include "pPlotterWindow.h"
00005 #include "MaximumsDialog.h"
00006 #include <iostream>
00007 #include <fstream>
00008 #include <string>
00009 
00010 // ----------------------------------------------------------------------------
00011 // WX headers inclusion.
00012 // For compilers that support precompilation, includes <wx/wx.h>.
00013 // ----------------------------------------------------------------------------
00014 
00015 #ifndef WX_PRECOMP
00016 #include <wx/wx.h>
00017 #endif
00018 
00019 #include "wx/colordlg.h"
00020 //----------------------------------------------------------------------------
00021 //DECLARING THE NEW EVENT
00022 //wxEVT_TSBAR= event of the two side bar
00023 //----------------------------------------------------------------------------
00024 BEGIN_DECLARE_EVENT_TYPES()
00025 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER, -1)
00026 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_CHANGED_FUNCTION, -1)
00027 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_MOVE, -1)
00028 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_ADD, -1)
00029 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_DELETE, -1)
00030 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_GUIDELINES, -1)
00031 END_DECLARE_EVENT_TYPES()
00032 
00033 //definitions
00034 DEFINE_EVENT_TYPE(wxEVT_PPLOTTER)
00035 DEFINE_EVENT_TYPE(wxEVT_PPLOTTER_CHANGED_FUNCTION)
00036 DEFINE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_MOVE)
00037 DEFINE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_ADD)
00038 DEFINE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_DELETE)
00039 DEFINE_EVENT_TYPE(wxEVT_PPLOTTER_GUIDELINES)
00040 
00041 
00042 //----------------------------------------------------------------------------
00043 // Class implementation
00044 //----------------------------------------------------------------------------
00045 
00046 IMPLEMENT_CLASS(pPlotterWindow, mpWindow)
00047 
00048 //----------------------------------------------------------------------------
00049 // Event Table
00050 //----------------------------------------------------------------------------
00051 
00052 BEGIN_EVENT_TABLE(pPlotterWindow,mpWindow)
00053 EVT_MOTION (pPlotterWindow::onMouseMove)
00054 EVT_LEFT_DCLICK(pPlotterWindow::onChangeActual)
00055 EVT_LEFT_DOWN(pPlotterWindow::onAddPoint)
00056 EVT_MENU(pwID_DELPOINT, pPlotterWindow::onDeletePoint)
00057 EVT_MENU(pwID_SHOWPOINTS, pPlotterWindow::onShowPoints)
00058 EVT_MENU(pwID_STARTDRAWING, pPlotterWindow::onStartDrawing)
00059 //EVT_MENU(pwID_DELFUNCTION,pPlotterWindow::onDeleteFunction)
00060 EVT_MENU(pwID_STOPDRAWING, pPlotterWindow::onStopDrawing)
00061 EVT_MENU(pwID_ADDNEWPOINT, pPlotterWindow::onAddNewPoint)
00062 EVT_MENU(pwID_NOSHOWPOINTS, pPlotterWindow::onNoShowPoints)
00063 EVT_MENU(pwID_MYZOOMOUT,pPlotterWindow::onMyZoomOut)
00064 EVT_MENU(pwID_MYZOOMIN,pPlotterWindow::onMyZoomIn)
00065 EVT_MENU(pwID_SPLINE,pPlotterWindow::onSplinePoints)
00066 EVT_MENU(pwID_LINE,pPlotterWindow::onLine)
00067 EVT_MENU(pwID_SAVE,pPlotterWindow::onSave)
00068 EVT_MENU(pwID_LOAD,pPlotterWindow::onLoad)
00069 EVT_MENU(pwID_CHANGECOLOR,pPlotterWindow::onChangeColor)
00070 EVT_MENU( mpID_LINE_GUIDES, pPlotterWindow::OnGuideLines)
00071 EVT_MENU( pwID_TRASLATEACTUALFUNCTION, pPlotterWindow::onMoveFunction)
00072 EVT_LEFT_UP(pPlotterWindow::onLeftUp)
00073 END_EVENT_TABLE()
00074 
00075 //----------------------------------------------------------------------------
00076 // Constructors
00077 //----------------------------------------------------------------------------
00078 
00079 pPlotterWindow::pPlotterWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag )
00080 : mpWindow( parent, id, pos, size, flag)
00081 {
00082         drawing=false;
00083         movingPointIndex=-1;
00084         actual=NULL;
00085         scaleWay=DEFAULT_SCALE;
00086         zoomFactor=1;
00087         //drawGuideLines=true;
00088         type=DEFAULT_PLOTTER;
00089         drawGuides=false;
00090         movingFunction=false;
00091         initialMovingCLick=-1;
00092         movingPoints=false;
00093         
00094         /*
00095         PopMenu options
00096         */
00097         m_popmenu.Remove( mpID_ZOOM_IN);
00098         m_popmenu.Remove( mpID_ZOOM_OUT);
00099         m_popmenu.Remove( mpID_CENTER);
00100         m_popmenu.Remove( mpID_FIT);
00101         m_popmenu.Remove( mpID_LOCKASPECT);
00102 
00103         m_popmenu.Append(pwID_STARTDRAWING ,   _("Start Drawing"),    _("Starts to draw a new function"));//it changes the actual function
00104         m_popmenu.Append(pwID_STOPDRAWING ,   _("Stop drawing"),    _("Stops of drawing the new function"));
00105         m_popmenu.Append(pwID_LOAD,   _("Load"),    _("Load the actual function from a plane file"));
00106         m_popmenu.Append(pwID_SHOWPOINTS ,   _("Show Points"),    _("shows the discrete points of the function"));
00107         m_popmenu.Append(pwID_NOSHOWPOINTS,  _("No show Points"),    _("Dont show the points of the function"));
00108         m_popmenu.Append(pwID_ADDNEWPOINT,   _("Add point"),    _("Add New point to the actual function"));
00109         m_popmenu.Append(pwID_DELPOINT ,   _("Delete point"),    _("Deletes a point from the actual function."));
00110         m_popmenu.Append(pwID_MYZOOMIN,   _("Zoom in"),    _("Zoom in the points of the function"));
00111         m_popmenu.Append(pwID_MYZOOMOUT,   _("Zoom out"),    _("Zoom out the points of the function"));
00112         m_popmenu.Append(pwID_SPLINE,   _("Smooth"),    _("Splines the points ofthe actual curve"));
00113         m_popmenu.Append(pwID_LINE,   _("Line"),    _("Piecewise the points ofthe actual curve"));      
00114         m_popmenu.Append(pwID_SAVE,   _("Save"),    _("Save the actual function in plane file"));       
00115         m_popmenu.Append(pwID_CHANGECOLOR,   _("Change Color"),    _("Change the color of the function"));              
00116         m_popmenu.Append(pwID_TRASLATEACTUALFUNCTION, _("Start Moving Function"),  _("Move the actual Function"));
00117         
00118         m_popmenu.Enable(pwID_NOSHOWPOINTS,false);
00119         m_popmenu.Enable(pwID_ADDNEWPOINT,false);
00120         m_popmenu.Enable(pwID_SHOWPOINTS,false);
00121         m_popmenu.Enable(pwID_DELPOINT,false);
00122         m_popmenu.Enable(pwID_STOPDRAWING,false);
00123         m_popmenu.Enable(pwID_MYZOOMIN,false);
00124         m_popmenu.Enable(pwID_MYZOOMOUT,false);
00125         m_popmenu.Enable(pwID_SPLINE,false);
00126         m_popmenu.Enable(pwID_LINE,false);
00127         m_popmenu.Enable(pwID_SAVE,false);
00128         m_popmenu.Enable(pwID_LOAD,true);
00129         m_popmenu.Enable(pwID_CHANGECOLOR,false);
00130         m_popmenu.Enable(pwID_STARTDRAWING,true);
00131         m_popmenu.Enable(pwID_LOAD,true);
00132         //m_popmenu.Enable(pwID_STARTDRAWING,false);
00133         m_popmenu.Enable(mpID_LINE_GUIDES,false);
00134         m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,false);
00135         
00136          
00137 }
00138 
00139 
00140 pPlotterWindow::~pPlotterWindow()
00141 {
00142 }
00143 //----------------------------------------------------------------------------
00144 // Methods
00145 //----------------------------------------------------------------------------
00146 
00150 void  pPlotterWindow::setActualFunction(pGraphicalFunction* newActual)
00151 {
00152         if(actual!=NULL)
00153                 actual->setActual(false);
00154         newActual->setActual(true);
00155         actual=newActual;
00156 }
00157 
00161 pGraphicalFunction* pPlotterWindow:: getActualFunction()
00162 {
00163         return actual;
00164 }
00165 
00172 wxPoint pPlotterWindow:: getRealPoint(wxPoint pixelPoint)
00173 {
00174         int x,y;        
00175         x=pixelPoint.x-70;
00176         y=pixelPoint.y-40;                      
00177         //real point on the function
00178         wxPoint realPoint;
00179         int xS=(x-offsetPixelX)/m_scaleX + offsetX + minScrX;
00180         int yS=(y-offsetPixelY)/m_scaleY + offsetY + minScrY;
00181         
00182         if(xS<=maxScrX && yS<=maxScrY )
00183         {
00184                 //setActualScales();
00185                 realPoint.x= xS;
00186                 realPoint.y= yS;                
00187         }
00188         else
00189         {
00190                 realPoint.x= -1;
00191                 realPoint.y= -1;                
00192         }
00193         return realPoint;
00194 }
00195 /*
00196  Set the scales according to the size of the window
00197  and the maximum given by the user
00198 */
00199 
00200 void pPlotterWindow::setActualScales()
00201 {
00202         // int maxX,maxY,minX,minY; // JPRx
00203         int maxX,maxY;//,minX,minY; // JPRx  //EED
00204         /*
00205         if the function is drawed interactively the maxX and the 
00206         maxY in actual are sets by the user
00207         */
00208         /*
00209         maxX=actual->getMaxX();
00210         maxY=actual->getMaxY();
00211 
00212         int dx=maxX;
00213         int dy=maxY;
00214         
00215         */
00216         int dx=actual->getMaxXShowed()-actual->getMinXShowed();
00217         int dy=actual->getMaxYShowed()-actual->getMinYShowed();
00218         
00219         if(dx!=0 && dy!=0)
00220         {
00221                 m_scaleX= (((float)m_scrX-100)/dx)*zoomFactor;
00222                 m_scaleY= (((float)m_scrY-50)/dy)*zoomFactor;
00223         }
00224         //setting the maximums and minimums showed in the window
00225         /*
00226         setMaxScrX(maxX);
00227         setMaxScrY(maxY);
00228         */
00229         setMaxScrX(actual->getMaxXShowed());
00230         setMinScrX(actual->getMinXShowed());
00231         setMaxScrY(actual->getMaxYShowed());
00232         setMinScrY(actual->getMinYShowed());
00233         actual->setScreens(m_scrX,m_scrY);
00234         actual->setScales();
00235 }
00236 //-------------------------
00237 // Methods for interaction
00238 //-------------------------
00239 
00240         //------------------------------------
00241         //      Manipulating clicks on the plotter
00242         //-------------------------------------
00243         
00244 
00245         /*
00246                 Manipulating clicks on the plotter
00247         */
00248         void pPlotterWindow::onLeftUp(wxMouseEvent& event)
00249         {
00250                 movingPoints=false;
00251                 movingPointIndex=-1;
00252         }
00253 
00254 
00255 
00256         //-------------------------------
00257         //Traslating the actual function
00258         //-------------------------------
00259         /*
00260          Move the actual function  when the user
00261          is moving the mouse
00262         */
00263         void pPlotterWindow::onMoveFunction(wxCommandEvent& aEvent)
00264         {
00265                 if(movingFunction)
00266                 {
00267                         movingFunction=false;
00268                         m_popmenu.SetLabel(pwID_TRASLATEACTUALFUNCTION, _("Start Moving Function"));
00269                 }
00270                 else
00271                 {
00272                         movingFunction=true;
00273                         m_popmenu.SetLabel(pwID_TRASLATEACTUALFUNCTION, _("Stop Moving Function"));
00274                 }
00275         }
00276 
00277 //-----------------------
00278 // Color Function
00279 //-----------------------
00280 
00281 
00285 void pPlotterWindow::onChangeColor(wxCommandEvent& aEvent)
00286         {
00287                         
00288                 wxColour colour;
00289                 wxColourData data;
00290                 wxColourDialog dialog(this, &data);
00291 
00292                 if ( dialog.ShowModal() == wxID_OK )
00293                 {
00294                         colour = dialog.GetColourData().GetColour();
00295                 }
00296         
00297                 wxPen mypen(colour);
00298                 mypen.SetWidth(2);
00299                 actual->SetPen( mypen);
00300                 UpdateAll();
00301         }
00302 
00303 
00304 //----------------------
00305 //Persistence
00306 //----------------------
00307         
00308 
00312         void pPlotterWindow::onLoad(wxCommandEvent& aEvent)
00313         {
00314                 
00315                 actual=new pGraphicalFunction(wxT("f(x) = function1(x)"),mpALIGN_NE);
00316                 actual->setActual(true);
00317                 actual->setFromWindow(false);
00318                 actual->SetDrawing(drawing);
00319                 actual->setFactorZoom(zoomFactor);
00320                 
00321                 wxPen mypen(*wxRED, 5, wxSOLID);
00322                 mypen.SetWidth(2);
00323                 actual->SetPen( mypen);
00324                                 
00325                 wxString nameF=wxFileSelector(_T("Save Function"));
00326                 actual->load(nameF);
00327                 AddLayer(actual);
00328                 
00329                 functions.Append(actual);
00330                 addFunctionToMove(actual);
00331                 
00332                 m_popmenu.Enable(pwID_STARTDRAWING,true);
00333                 
00334                 UpdateAll();
00335 
00336                 //------------------------------------------
00337                 //Sending the paarticular event of changed actual function
00338                 //-------------------------------------------
00339                 wxCommandEvent cevent( wxEVT_PPLOTTER_CHANGED_FUNCTION, GetId() );
00340                 cevent.SetEventObject(this);
00341         GetEventHandler()->ProcessEvent( cevent );
00342         }
00343 
00344 
00348         void pPlotterWindow::onSave(wxCommandEvent& aEvent)
00349         {
00350                 wxString nameF=wxFileSelector(_T("Save Function"));
00351                 actual->save(nameF);
00352         }
00353 
00354 //-----------------------
00355 // Spline
00356 //----------------------
00361 void pPlotterWindow::onSplinePoints(wxCommandEvent& aEvent)
00362 {
00363         actual->setType(2);
00364         actual->initializeSplines();
00365         actual->initializeSplineVectors();
00366         UpdateAll();
00367         m_popmenu.Enable(pwID_SPLINE,false);
00368         m_popmenu.Enable(pwID_LINE,true);
00369 }
00370 
00375 void pPlotterWindow::onLine(wxCommandEvent& aEvent)
00376 {
00377         actual->clearSplineVectors();
00378         actual->setType(1);
00379         UpdateAll();
00380         m_popmenu.Enable(pwID_SPLINE,true);
00381         m_popmenu.Enable(pwID_LINE,false);
00382 
00383 }
00384 
00385 //--------------------------
00386 // Zooming
00387 //---------------------------
00388 
00392 void pPlotterWindow::onMyZoomOut(wxCommandEvent& aEvent)
00393 {
00394         wxNode* node=functions.GetFirst();
00395         zoomFactor=zoomFactor*(float)(1/(float)ZOOM_FACTOR);
00396         while(node)
00397         {
00398                 pGraphicalFunction* f= (pGraphicalFunction*)node->GetData();
00399                 
00400                 f->setScreenX(m_scrX);
00401                 f->setScreenY(m_scrY);
00402 
00403                 
00404                 if(zoomFactor>1.01)
00405                 {       
00406                         f->setOffsets(m_clickedX-70,m_scrY-m_clickedY-40);
00407                         f->setFactorZoom(zoomFactor);
00408                 }
00409                 
00410                 else
00411                 {
00412                         f->setOffsetPixelX(0);
00413                         f->setOffsetPixelY(0);
00414                         f->setOffsetX(0);
00415                         f->setOffsetY(0);
00416                         f->setFactorZoom(zoomFactor);
00417                 }
00418                 
00419 
00420                 if(f->getActual())
00421                 {
00422                         //TODO: send a event of resize
00423                         //setMinScrX(f->getMinXShowed());
00424                         //setMinScrY(f->getMinYShowed());
00425                         setOffsetPixelX(f->getOffsetPixelsX());
00426                         setOffsetPixelY(f->getOffsetPixelsY());
00427                         setOffsetX(f->getOffsetX());
00428                         setOffsetY(f->getOffsetY());
00429                 }
00430                 node=node->GetNext();
00431         }
00432         UpdateAll();
00433 }
00437 void pPlotterWindow::onMyZoomIn(wxCommandEvent& aEvent)
00438 {
00439                 
00440         zoomFactor=zoomFactor*(float)ZOOM_FACTOR;
00441         wxNode* node=functions.GetFirst();
00442         while(node)
00443         {
00444                 pGraphicalFunction* f= (pGraphicalFunction*)node->GetData();
00445                 if(zoomFactor > 1.01)
00446                 {       
00447                         f->setScreenX(m_scrX);
00448                         f->setScreenY(m_scrY);
00449                         f->setOffsets(m_clickedX-70,m_scrY-m_clickedY-40);
00450                         f->setFactorZoom(zoomFactor);
00451                 }
00452                 else 
00453                 {
00454                         f->setOffsetPixelX(0);
00455                         f->setOffsetPixelY(0);
00456                         f->setOffsetX(0);
00457                         f->setOffsetY(0);
00458                         f->setFactorZoom(zoomFactor);
00459                 }
00460                 if(f->getActual())
00461                 {
00462                         //TODO: send an event of resize
00463                         //setMinScrX(f->getMinXShowed());
00464                         //setMinScrY(f->getMinYShowed());
00465                         setOffsetPixelX(f->getOffsetPixelsX());
00466                         setOffsetPixelY(f->getOffsetPixelsY());
00467                         setOffsetX(f->getOffsetX());
00468                         setOffsetY(f->getOffsetY());
00469 
00470                 }
00471                 
00472                 node=node->GetNext();
00473         }
00474 
00475         UpdateAll();
00476 }
00477 
00478 
00479 //-------------------------
00480 // Drawing
00481 //-------------------------
00482 
00483 
00487 void pPlotterWindow::onStartDrawing(wxCommandEvent& aEvent)
00488 {
00489 
00490         if(actual!=NULL)
00491         {
00492                 actual->setActual(false);
00493                 if(actual->getShowPoints())
00494                         actual->SetShowPoints(false);
00495         }       
00496         m_popmenu.Enable(pwID_NOSHOWPOINTS,false);
00497         m_popmenu.Enable(pwID_ADDNEWPOINT,false);
00498         m_popmenu.Enable(pwID_SHOWPOINTS,false);
00499         m_popmenu.Enable(pwID_DELPOINT,false);
00500         m_popmenu.Enable(pwID_MYZOOMIN,false);
00501         m_popmenu.Enable(pwID_MYZOOMOUT,false);
00502         m_popmenu.Enable(pwID_STARTDRAWING,false);
00503         m_popmenu.Enable(pwID_SPLINE,false);
00504         m_popmenu.Enable(pwID_LINE,false);
00505         m_popmenu.Enable(pwID_STOPDRAWING,true);
00506         m_popmenu.Enable(pwID_SAVE,false);
00507         m_popmenu.Enable(pwID_LOAD,false);
00508         m_popmenu.Enable(pwID_CHANGECOLOR,false);
00509         m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,false);
00510 
00511         if(!drawing)
00512         {
00513                 drawing=true;
00514                 
00515                 
00516                 actual=new pGraphicalFunction(wxT("f(x) = function1(x)"),mpALIGN_NE);
00517                 actual->setActual(true);
00518                 actual->setFromWindow(true);
00519                 actual->setScaleWay(USER_SCALE);
00520                 actual->SetDrawing(drawing);
00521                 actual->setFactorZoom(zoomFactor);
00522                 
00523                 //we change the offsets
00524                 setOffsetPixelX(actual->getOffsetPixelsX());
00525                 setOffsetPixelY(actual->getOffsetPixelsY());
00526                 setOffsetX(actual->getOffsetX());
00527                 setOffsetY(actual->getOffsetY());
00528         
00529                 AddLayer(actual);
00530                 wxPen mypen(*wxRED, 5, wxSOLID);
00531                 mypen.SetWidth(2);
00532                 actual->SetPen( mypen);
00533                 
00534                 /*
00535                 int result = wxMessageBox("Do you Want a Smooth Curve?", "Spline Points", wxYES_NO | wxCANCEL);
00536                 if(result==wxYES)
00537                 {
00538                         actual->setType(2);
00539                 }
00540                 */
00541                 
00542                 /**************************************************************************/
00543                 // Setting Maximums
00544                 /**************************************************************************/
00545         
00546                 //opening  the dialog of maximums
00547                 float maxX=0,maxY=0;
00548                 MaximumsDialog *dlg=new MaximumsDialog(this,_T("Set Maximums"));
00549                 
00550                 if(dlg->ShowModal()== wxID_OK )
00551                 {
00552                         maxX=dlg->getXValue();
00553                         maxY=dlg->getYValue();
00554                         if(maxX>0 && maxY>0 && actual->getFromWindow())
00555                         {
00556                                 setMaxScrX(maxX);
00557                                 setMaxScrY(maxY);
00558                                 
00559                                 actual->setMaxX(maxScrX);                               
00560                                 actual->setMinX(minScrX);
00561                                 actual->setMaxY(maxY);
00562                                 actual->setMinY(0);
00563                                 
00564                                 actual->setMinShowedX(0);
00565                                 actual->setMinShowedY(0);
00566                                 actual->setMaxShowedX(maxX);
00567                                 actual->setMaxShowedY(maxY);
00568                                 
00569                                 setActualScales();
00570                         }
00571                         else if(maxX<0 || maxY<0)
00572                         {
00573                                  wxMessageBox(_T("Both numbers have to be positive, please enter valid numbers"), _T("Error"),
00574                             wxOK);
00575                                  
00576                                  DelLayer(actual);
00577                                  actual=NULL;
00578                                                 
00579                                 m_popmenu.Enable(pwID_NOSHOWPOINTS,false);
00580                                 m_popmenu.Enable(pwID_ADDNEWPOINT,false);
00581                                 m_popmenu.Enable(pwID_SHOWPOINTS,false);
00582                                 m_popmenu.Enable(pwID_DELPOINT,false);
00583                                 m_popmenu.Enable(pwID_MYZOOMIN,false);
00584                                 m_popmenu.Enable(pwID_MYZOOMOUT,false);
00585                                 m_popmenu.Enable(pwID_STARTDRAWING,true);
00586                                 m_popmenu.Enable(pwID_SPLINE,false);
00587                                 m_popmenu.Enable(pwID_LINE,false);
00588                                 m_popmenu.Enable(pwID_STOPDRAWING,false);
00589                                 m_popmenu.Enable(pwID_SAVE,false);
00590                                 m_popmenu.Enable(pwID_LOAD,true);
00591                                 m_popmenu.Enable(pwID_CHANGECOLOR,false);
00592                                 m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,false);
00593                                 drawing=false;
00594                                 //actual->SetDrawing(false);
00595 
00596                         }
00597 
00598                         else if(maxX==0 && maxY==0)
00599                         {
00600                                 actual->setMaxX(100);
00601                                 actual->setMinX(0);
00602                                 actual->setMaxY(100);
00603                                 actual->setMinY(0);
00604                                         
00605                                 actual->setMinShowedX(0);
00606                                 actual->setMinShowedY(0);
00607                                 actual->setMaxShowedX(100);
00608                                 actual->setMaxShowedY(100);
00609 
00610                                 maxScrX=100;
00611                                 maxScrY=100;
00612                                 minScrX=0;
00613                                 minScrY=0;
00614 
00615                                 setActualScales();
00616                         }
00617                         
00618                 }
00619                 
00620         else if(dlg->ShowModal()== wxID_CANCEL)
00621                 {
00622                         DelLayer(actual);
00623                         actual=NULL;
00624                                         
00625                         m_popmenu.Enable(pwID_NOSHOWPOINTS,false);
00626                         m_popmenu.Enable(pwID_ADDNEWPOINT,false);
00627                         m_popmenu.Enable(pwID_SHOWPOINTS,false);
00628                         m_popmenu.Enable(pwID_DELPOINT,false);
00629                         m_popmenu.Enable(pwID_MYZOOMIN,false);
00630                         m_popmenu.Enable(pwID_MYZOOMOUT,false);
00631                         m_popmenu.Enable(pwID_STARTDRAWING,true);
00632                         m_popmenu.Enable(pwID_SPLINE,false);
00633                         m_popmenu.Enable(pwID_LINE,false);
00634                         m_popmenu.Enable(pwID_STOPDRAWING,false);
00635                         m_popmenu.Enable(pwID_SAVE,false);
00636                         m_popmenu.Enable(pwID_LOAD,true);
00637                         m_popmenu.Enable(pwID_CHANGECOLOR,false);
00638                         m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,false);
00639                         drawing=false;
00640                         //actual->SetDrawing(false);
00641 
00642                 }
00643                 dlg->Destroy();
00644                 if(drawing)
00645                 {
00646                         //------------------------------------------
00647                         //Sending the paarticular event of changed actual function
00648                         //-------------------------------------------
00649                         wxCommandEvent cevent( wxEVT_PPLOTTER_CHANGED_FUNCTION, GetId() );
00650                         cevent.SetEventObject(this);
00651                         GetEventHandler()->ProcessEvent( cevent );
00652                 }
00653         }
00654         
00655 }
00659 void pPlotterWindow::onStopDrawing(wxCommandEvent& aEvent)
00660 {
00661         drawing=false;
00662         actual->SetDrawing(drawing);
00663         functions.Append(actual);
00664         addFunctionToMove(actual);
00665         m_popmenu.Enable(pwID_ADDNEWPOINT,true);
00666         m_popmenu.Enable(pwID_DELPOINT,true);
00667         m_popmenu.Enable(pwID_SHOWPOINTS,true);
00668         m_popmenu.Enable(pwID_MYZOOMIN,true);
00669         m_popmenu.Enable(pwID_MYZOOMOUT,true);
00670         m_popmenu.Enable(pwID_STARTDRAWING,true);
00671         m_popmenu.Enable(pwID_SPLINE,true);
00672         m_popmenu.Enable(pwID_STOPDRAWING,false);
00673         m_popmenu.Enable(pwID_LINE,false);
00674         m_popmenu.Enable(pwID_CHANGECOLOR,true);
00675         m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,true);
00676 
00677         if(actual->getSizePoints()==0||actual->getSizePoints()==1)
00678         {         
00679         
00680           m_popmenu.Enable(pwID_ADDNEWPOINT,false);
00681           //functions.DeleteObject(actual);
00682           DelLayer(actual);
00683           actual=NULL;   
00684          
00685         }
00686         
00687         UpdateAll();
00688 }
00692 void pPlotterWindow::onShowPoints(wxCommandEvent& aEvent)
00693 {
00694         actual->SetShowPoints(true);
00695         m_popmenu.Enable(pwID_NOSHOWPOINTS,true);
00696         m_popmenu.Enable(pwID_SHOWPOINTS,false);        
00697         UpdateAll();
00698 }
00702 void pPlotterWindow::onNoShowPoints(wxCommandEvent& aEvent)
00703 {       
00704         actual->SetShowPoints(false);
00705         m_popmenu.Enable(pwID_NOSHOWPOINTS,false);
00706         m_popmenu.Enable(pwID_SHOWPOINTS,true);
00707         UpdateAll();    
00708 }
00712 void pPlotterWindow::onAddPoint(wxMouseEvent& aEvent)
00713 {
00714         
00715         wxPoint point=aEvent.GetPosition();
00716         
00717         point.y=m_scrY-point.y;
00718         wxPoint realPoint=getRealPoint(point);
00719 
00720         bool isAValidPoint=realPoint.x>=0 && realPoint.y>=0;
00721 
00722         if(isAValidPoint && drawing)
00723         {
00724                 if(actual->AddPoint(realPoint.x,realPoint.y))
00725                 {
00726                         text = wxString::Format(_T("added  point ( %d, %d)\n"), realPoint.x, realPoint.y);
00727                         
00728                         //m_log->AppendText(text);
00729 
00730                         //if the function is smooth
00731                         if(actual->getType()==2)
00732                         {
00733                                 actual->clearSplineVectors();
00734                                 actual->addSplinesPoints();
00735                                 actual->initializeSplineVectors();                              
00736                         }
00737                         
00738                         UpdateAll();
00739                 }
00740         }
00741         else if(isAValidPoint && !drawing && aEvent.m_shiftDown && actual!=NULL)
00742         {
00743                 if(actual->AddNewPoint(realPoint.x,realPoint.y))
00744                 {
00745                         text = wxString::Format(_T("added  point ( %d, %d)\n"), realPoint.x, realPoint.y);
00746                         //if the function is smooth
00747                         if(actual->getType()==2)
00748                         {
00749                                 actual->clearSplineVectors();
00750                                 actual->addSplinesPoints();
00751                                 actual->initializeSplineVectors();                              
00752                         }
00753                         
00754                         UpdateAll();
00755                 }
00756         }
00757         //made a click for moving the points
00758         else if(!movingPoints)
00759         {
00760                 if(actual)      
00761                         movingPointIndex=actual->validPointOnFunction(realPoint);
00762                 if(movingPointIndex>=0)
00763                         movingPoints=true;
00764         }
00765                                         
00766         //------------------------------------------
00767         //Sending the  event
00768         //-------------------------------------------
00769         wxCommandEvent cevent( wxEVT_PPLOTTER_POINT_ADD, GetId() );
00770         cevent.SetEventObject(this);
00771 
00772         //------------------------------------------
00773         //Sending the  general event
00774         //-------------------------------------------
00775         wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
00776         pevent.SetEventObject(this);
00777         //send the events
00778         GetEventHandler()->ProcessEvent( cevent );
00779         GetEventHandler()->ProcessEvent( pevent );
00780 }
00781 
00787 void pPlotterWindow::onAddNewPoint(wxCommandEvent& aEvent)
00788 {
00789         wxPoint point;
00790         point.x=m_clickedX;
00791         point.y=m_scrY-m_clickedY;
00792 
00793         wxPoint realPoint=getRealPoint(point);
00794         bool isAValidPoint=realPoint.x>=0 && realPoint.y>=0;
00795 
00796         
00797         if(isAValidPoint && actual->AddNewPoint(realPoint.x,realPoint.y))
00798         {
00799                 text = wxString::Format(_T("added  point ( %d, %d)\n"), realPoint.x, realPoint.y);
00800                 //if the function is smooth
00801                 if(actual->getType()==2)
00802                 {
00803                         actual->clearSplineVectors();
00804                         actual->addSplinesPoints();
00805                         actual->initializeSplineVectors();
00806                         
00807                 }
00808                 UpdateAll();
00809                 //------------------------------------------
00810                 //Sending the  event
00811                 //-------------------------------------------
00812                 wxCommandEvent cevent( wxEVT_PPLOTTER_POINT_ADD, GetId() );
00813                 cevent.SetEventObject(this);
00814 
00815                 //------------------------------------------
00816                 //Sending the  general event
00817                 //-------------------------------------------
00818                 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
00819                 pevent.SetEventObject(this);
00820                 //send the events
00821                 GetEventHandler()->ProcessEvent( cevent );
00822                 GetEventHandler()->ProcessEvent( pevent );
00823 
00824         }
00825 }
00826 
00830 void pPlotterWindow::onDeletePoint(wxCommandEvent& aEvent)
00831 {
00832         wxPoint point;
00833         point.x=m_clickedX;
00834         point.y=m_scrY-m_clickedY;
00835 
00836         //actual->setScreenX(m_scrX);
00837         //actual->setScreenY(m_scrY);
00838 
00839         wxPoint realPoint=getRealPoint(point);
00840         
00841         bool isAValidPoint=realPoint.x>=0 && realPoint.y>=0;
00842 
00843         //this method verify a sensible region in every point of actual
00844         int pointIndex=actual->validPointOnFunction(realPoint);
00845         if(isAValidPoint && actual->deletePointAt(pointIndex))
00846         {
00847                 setActualScales();
00848                 if(actual->getSizePoints()==0)
00849                 {
00850                         //functions.DeleteObject(actual);
00851                         //DelLayer(actual);
00852                         //actual=NULL;
00853                 }
00854                 //if the function is smooth
00855                 if(actual->getType()==2)
00856                 {
00857                         actual->clearSplineVectors();
00858                         actual->addSplinesPoints();
00859                         actual->initializeSplineVectors();
00860                         
00861                 }
00862                 text = wxString::Format(_T("deleted  point ( %d, %d)\n"), realPoint.x, realPoint.y);
00863                 UpdateAll();
00864                 //------------------------------------------
00865                 //Sending the  event
00866                 //-------------------------------------------
00867                 wxCommandEvent cevent( wxEVT_PPLOTTER_POINT_DELETE, GetId() );
00868                 cevent.SetEventObject(this);
00869                 //------------------------------------------
00870                 //Sending the  general event
00871                 //-------------------------------------------
00872                 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
00873                 pevent.SetEventObject(this);
00874                 //send the events
00875                 GetEventHandler()->ProcessEvent( cevent );
00876                 GetEventHandler()->ProcessEvent( pevent );
00877         }  
00878 }
00879 
00880 
00888 void pPlotterWindow::onMouseMove(wxMouseEvent& event)
00889 {
00890         wxPoint point=event.GetPosition();
00891         bool change=false;
00892         point.y=m_scrY-point.y;
00893         
00894         wxPoint realPoint=getRealPoint(point);
00895         bool isAValidPoint=realPoint.x>=0 && realPoint.y>=0;
00896 
00897         if(isAValidPoint && !drawing && actual!=NULL && !movingFunction && movingPoints)
00898         {
00899                 //never is going to get in
00900                 if(movingPointIndex==-1)
00901                 {       
00902                         //this method verify a sensible region in every point of _actualFunction
00903                         movingPointIndex=actual->validPointOnFunction(realPoint);
00904                                         
00905                 }
00906                 else if(event.LeftIsDown())
00907                 {                               
00908                         
00909                         /*if((movingPointIndex-1)>=0 && (movingPointIndex+1)<actual->getSizePoints() && actual->getEditable())
00910                         {
00911                                 wxNode* next= actual->GetPointAt(movingPointIndex+1);
00912                                 wxNode* before=actual->GetPointAt(movingPointIndex-1);
00913                                 if(next)
00914                                 {       
00915                                         pFunctionPoint* np=(pFunctionPoint*)(next->GetData());
00916                                         if(np)
00917                                                 {
00918                                                         int n=np->getRealX();
00919                                                         if(realPoint.x>n)
00920                                                         {
00921                                                                 wxPoint p;
00922                                                                 p.x=np->getRealX()-1;
00923                                                                 p.y=realPoint.y;
00924                                                                 change=actual->changePoint(p,movingPointIndex);
00925                                                                 if(change)
00926                                                                 {
00927                                                                         setActualScales();
00928                                                                                                                         
00929                                                                         //if the function is smooth
00930                                                                         if(actual->getType()==2)
00931                                                                         {
00932                                                                                 actual->clearSplineVectors();
00933                                                                                 actual->addSplinesPoints();
00934                                                                                 actual->initializeSplineVectors();
00935                                                                                 
00936                                                                         }
00937                                                                         
00938                                                                         text = wxString::Format(_T("Moved  point ( %d, %d)\n"), p.x, p.y);
00939                                                                         UpdateAll();
00940                                                                         //------------------------------------------
00941                                                                         //Sending the particular event
00942                                                                         //-------------------------------------------
00943                                                                         wxCommandEvent cevent( wxEVT_PPLOTTER_POINT_MOVE, GetId() );
00944                                                                         cevent.SetEventObject(this);
00945 
00946                                                                         //------------------------------------------
00947                                                                         //Sending the  general event
00948                                                                         //-------------------------------------------
00949                                                                         wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
00950                                                                         pevent.SetEventObject(this);
00951 
00952                                                                         //send the events
00953                                                                         GetEventHandler()->ProcessEvent( cevent );
00954                                                                         GetEventHandler()->ProcessEvent( pevent );
00955                                                                 }
00956                                                         }
00957                                                 }
00958                                 }
00959                                 if(before)
00960                                 {
00961                                         pFunctionPoint* bp=(pFunctionPoint*)(before->GetData());        
00962                                         if(bp)
00963                                          { 
00964                                                  int b=bp->getRealX();
00965                                                  if(realPoint.x<b)
00966                                                 {
00967                                                         wxPoint p;
00968                                                         p.x=bp->getRealX()+1;
00969                                                         p.y=realPoint.y;
00970                                                         change=actual->changePoint(p,movingPointIndex);
00971                                                         if(change)
00972                                                         {
00973                                                                 setActualScales();
00974                                                                 //if the function is smooth
00975                                                                 if(actual->getType()==2)
00976                                                                 {
00977                                                                         actual->clearSplineVectors();
00978                                                                         actual->addSplinesPoints();
00979                                                                         actual->initializeSplineVectors();
00980                                                                         
00981                                                                 }
00982                                                                 text = wxString::Format(_T("Moved  point ( %d, %d)\n"), p.x, p.y);
00983                                                                 UpdateAll();
00984                                                                 //------------------------------------------
00985                                                                 //Sending the particular event
00986                                                                 //-------------------------------------------
00987                                                                 wxCommandEvent cevent( wxEVT_PPLOTTER_POINT_MOVE, GetId() );
00988                                                                 cevent.SetEventObject(this);
00989 
00990                                                                 //------------------------------------------
00991                                                                 //Sending the  general event
00992                                                                 //-------------------------------------------
00993                                                                 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
00994                                                                 pevent.SetEventObject(this);
00995 
00996                                                                 //send the events
00997                                                                 GetEventHandler()->ProcessEvent( cevent );
00998                                                                 GetEventHandler()->ProcessEvent( pevent );
00999                                                         }
01000 
01001                                                 }
01002                                           }
01003                                 }       
01004                         }       */
01005                         // SIL ******************************************************************* // SIL
01006                         if((movingPointIndex-1)>=0 && (movingPointIndex+1)<actual->getSizePoints() && actual->getEditable())
01007                         {
01008                                 change=actual->changePoint(realPoint,movingPointIndex);
01009                         }
01010                         if(change)
01011                         {
01012                                 setActualScales();
01013                                 //if the function is smooth
01014                                 if(actual->getType()==2)
01015                                 {
01016                                         actual->clearSplineVectors();
01017                                         actual->addSplinesPoints();
01018                                         actual->initializeSplineVectors();                                      
01019                                 }
01020                                 text = wxString::Format(_T("Moved  point ( %d, %d)\n"), realPoint.x, realPoint.y);
01021                                 UpdateAll();
01022                                 //------------------------------------------
01023                                 //Sending the particular event
01024                                 //-------------------------------------------
01025                                 wxCommandEvent cevent( wxEVT_PPLOTTER_POINT_MOVE, GetId() );
01026                                 cevent.SetEventObject(this);
01027 
01028                                 //------------------------------------------
01029                                 //Sending the  general event
01030                                 //-------------------------------------------
01031                                 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
01032                                 pevent.SetEventObject(this);
01033 
01034                                 //send the events
01035                                 GetEventHandler()->ProcessEvent( cevent );
01036                                 GetEventHandler()->ProcessEvent( pevent );
01037                         }
01038                         // SIL ******************************************************************* // SIL
01039 
01040                         //change the point that is in the index, returns true if could be changed.
01041                         if(!change && actual->changePoint(realPoint,movingPointIndex)&& actual->getEditable())
01042                         {
01043                                 setActualScales();
01044                                 //if the function is smooth
01045                                 if(actual->getType()==2)
01046                                 {
01047                                         actual->clearSplineVectors();
01048                                         actual->addSplinesPoints();
01049                                         actual->initializeSplineVectors();
01050                                         
01051                                 }
01052                                 text = wxString::Format(_T("Moved  point ( %d, %d)\n"), realPoint.x,realPoint.y);
01053                                 
01054                                 UpdateAll();
01055 
01056                                 //------------------------------------------
01057                                 //Sending the particular event
01058                                 //-------------------------------------------
01059                                 wxCommandEvent cevent( wxEVT_PPLOTTER_POINT_MOVE, GetId() );
01060                                 cevent.SetEventObject(this);
01061 
01062                                 //------------------------------------------
01063                                 //Sending the  general event
01064                                 //-------------------------------------------
01065                                 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
01066                                 pevent.SetEventObject(this);
01067 
01068                                 //send the events
01069                                 GetEventHandler()->ProcessEvent( cevent );
01070                                 GetEventHandler()->ProcessEvent( pevent );
01071                         }
01072                 }
01073                 else
01074                 {
01075                         movingPointIndex=-1;
01076                         movingPoints=false;
01077                 }
01078         }
01079         //if the user is drawing
01080         else if(isAValidPoint && drawing)
01081         {
01082 
01083                 actual->SetMousePoint(realPoint);               
01084                 UpdateAll();
01085         }
01086         //is moving the function
01087         else if(isAValidPoint && movingFunction && actual!=NULL)
01088         {
01089                 actual->setScreenX(m_scrX);
01090                 actual->setScreenY(m_scrY);
01091                 //int j=0; // JPRx
01092                 if((initialMovingCLick==-1) && event.LeftIsDown()  )
01093                  {
01094                         if(actual->isInFunction(realPoint.x,realPoint.y))
01095                         {
01096                                 initialMovingCLick=event.GetPosition().x;
01097                                 int numPoints=actual->getSizePoints();
01098                                 int i=0;
01099                                 backUpActualVector.clear();
01100                                 while(i<numPoints)
01101                                 {
01102                                         //if(i>0 && i< (numPoints-1))
01103                                         //{
01104                                                 wxNode* pointNode=actual->GetPointAt(i);
01105                                                 pFunctionPoint* point= (pFunctionPoint*)pointNode->GetData();
01106                                                 backUpActualVector.push_back(point->getRealX());
01107                                                 
01108                                         //}
01109                                         i++;
01110                                 }
01111                         }
01112                  }      
01113                 else if(event.LeftIsDown())
01114                 {
01115                         wxPoint aux(initialMovingCLick,0);
01116 
01117                         wxPoint p1r=getRealPoint(event.GetPosition());
01118                         wxPoint p2r=getRealPoint(aux);
01119 
01120                         double delta = p1r.x-p2r.x;
01121                         int numPoints=actual->getSizePoints();
01122                         int i=0;
01123                         wxPoint p;
01124                         if(type==HISTOGRAM)
01125                         {
01126                                 while(i<numPoints)
01127                                 {
01128                                         if(i>0 && i<(numPoints-1))
01129                                         {
01130                                                 wxNode* pointNode=actual->GetPointAt(i);
01131                                                 pFunctionPoint* point= (pFunctionPoint*)pointNode->GetData();
01132                                                 int xNew=backUpActualVector[i]+delta;
01133                                                 //it has to preserve the state of functin                               
01134                                                 if(backUpActualVector[0]<xNew && backUpActualVector[numPoints-1]>xNew)
01135                                                                 point->setRealX(xNew);
01136                                         }
01137                                         i++;
01138                                 }
01139                         }
01140                         else
01141                         {
01142                                 i=0;
01143                                 while(i<numPoints)
01144                                 {
01145                                 
01146                                         wxNode* pointNode=actual->GetPointAt(i);
01147                                         pFunctionPoint* point= (pFunctionPoint*)pointNode->GetData();
01148                                         int xNew=backUpActualVector[i]+delta;
01149                                         point->setRealX(xNew);
01150                                         i++;
01151                                 }
01152                         }
01153                         //If is a spline
01154                         if(actual->getType()==2)
01155                         {
01156                                 actual->clearSplineVectors();
01157                                 actual->addSplinesPoints();
01158                                 actual->initializeSplineVectors();
01159 
01160                         }
01161                         UpdateAll();
01162 
01163                 }
01164                 else 
01165                 {       
01166                         initialMovingCLick=-1;
01167                 }
01168                 
01169         }
01170 }
01175 void pPlotterWindow::onChangeActual(wxMouseEvent& event)
01176 {
01177         wxString text = _T("\n points \n");
01178         
01179         
01180         if(!drawing)
01181         {
01182                 //we have to call showpoints before changing the function
01183                 wxPoint point=event.GetPosition();
01184                 /*****************************/
01185                 point.y=m_scrY-point.y;
01186                 /*****************************/
01187        
01188         
01189                 
01190                 //real point on the function
01191                 wxPoint realPoint;//=getRealPoint(point);
01192                 bool isAValidPoint=realPoint.x>=0 && realPoint.y>=0;
01193                 if(isAValidPoint)
01194                 {
01195                         wxNode * node= functions.GetFirst();
01196                         while (node)
01197                         {
01198                                 pGraphicalFunction* fnode=(pGraphicalFunction*)node->GetData();
01199                                 
01200                                 
01201                                 int maxX=fnode->getMaxXShowed();
01202                                 int maxY=fnode->getMaxYShowed();
01203                                 int minX=fnode->getMinXShowed();
01204                                 int minY=fnode->getMinYShowed();
01205                                 
01206                                 
01207                                 /*
01208                                 float sx=(((float)m_scrX-100)/(maxScrX-minScrX))*zoomFactor;
01209                                 float sy=(((float)m_scrY-50)/(maxScrY-minScrY))*zoomFactor;
01210                                 */
01211                                 
01212                                 
01213                                 float sx=(((float)m_scrX-100)/(maxX-minX))*zoomFactor;
01214                                 float sy=(((float)m_scrY-50)/(maxY-minY))*zoomFactor;
01215                                 
01216 
01217                                 realPoint.x=((point.x-70-fnode->getOffsetPixelsX())/sx)+ fnode->getOffsetX()+ minX;
01218                                 realPoint.y=((point.y-40-fnode->getOffsetPixelsY())/sy)+ fnode->getOffsetY()+ minY;
01219                                 /*
01220                                 LOG
01221                                 */
01222                                 if(fnode->getActual())
01223                                         text = wxString::Format(_T("Selected point ( %d, %d)\n"), realPoint.x, realPoint.y);
01224                                 //m_log->AppendText(text);
01225                                 
01226                                 bool hasIt=fnode->isInFunction(realPoint.x,realPoint.y);
01227                                         /*
01228                                         if(fnode->getEditable())        
01229                                                 hasIt=fnode->isInFunction(realPoint.x,realPoint.y);
01230                                         else
01231                                                 hasIt=false;
01232                                         */
01233                                 if(hasIt)
01234                                 {
01235                                         if(actual!=fnode)
01236                                         {
01237                                                 setActualFunction(fnode);
01238                                                 //we change the offsets
01239                                                 setOffsetPixelX(fnode->getOffsetPixelsX());
01240                                                 setOffsetPixelY(fnode->getOffsetPixelsY());
01241                                                 setOffsetX(fnode->getOffsetX());
01242                                                 setOffsetY(fnode->getOffsetY());
01243 
01244 
01245                                                 setActualScales();
01246                                                 if(!actual->getFromWindow() && actual->getEditable()||actual->getFromWindow() && actual->getEditable())
01247                                                 {
01248                                                         m_popmenu.Enable(pwID_ADDNEWPOINT,true);
01249                                                         m_popmenu.Enable(pwID_DELPOINT,true);
01250                                                         if(actual->getShowPoints())
01251                                                         {
01252                                                                 m_popmenu.Enable(pwID_SHOWPOINTS,false);
01253                                                                 m_popmenu.Enable(pwID_NOSHOWPOINTS,true);
01254                                                         }
01255                                                         else
01256                                                         {
01257                                                                 m_popmenu.Enable(pwID_SHOWPOINTS,true);
01258                                                                 m_popmenu.Enable(pwID_NOSHOWPOINTS,false);
01259                                                         }
01260                                                         m_popmenu.Enable(pwID_MYZOOMIN,true);
01261                                                         m_popmenu.Enable(pwID_MYZOOMOUT,true);
01262                                                         if(actual->getType()==2)//Smoothed function
01263                                                         {
01264                                                                 m_popmenu.Enable(pwID_SPLINE,false);
01265                                                                 m_popmenu.Enable(pwID_LINE,true);
01266                                                         }
01267                                                         else
01268                                                         {
01269                                                                 m_popmenu.Enable(pwID_SPLINE,true);
01270                                                                 m_popmenu.Enable(pwID_LINE,false);
01271 
01272                                                         }
01273                                                         if(type==2)
01274                                                         {
01275                                                                 m_popmenu.Enable(pwID_LOAD,false);
01276                                                                 m_popmenu.Enable(pwID_STARTDRAWING,false);
01277                                                         }       
01278                                                         else
01279                                                         {
01280                                                             m_popmenu.Enable(pwID_LOAD,true);
01281                                                                 m_popmenu.Enable(pwID_STARTDRAWING,true);
01282                                                         }
01283 
01284                                                         m_popmenu.Enable(pwID_SAVE,true);
01285                                                         m_popmenu.Enable(pwID_LOAD,false);
01286                                                         m_popmenu.Enable(pwID_STOPDRAWING,false);
01287                                                         m_popmenu.Enable(pwID_CHANGECOLOR,true);
01288                                                         m_popmenu.Enable(mpID_LINE_GUIDES,true);
01289                                                         m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,true);
01290                                                 }
01291                                                 //for the functions that came from data and arent editables
01292                                                 else if(!actual->getFromWindow() && !actual->getEditable()||actual->getFromWindow() && !actual->getEditable())
01293                                                 {
01294                                                         if(actual->getShowPoints())
01295                                                         {
01296                                                                 m_popmenu.Enable(pwID_SHOWPOINTS,false);
01297                                                                 m_popmenu.Enable(pwID_NOSHOWPOINTS,true);
01298                                                         }
01299                                                         else
01300                                                         {
01301                                                                 m_popmenu.Enable(pwID_SHOWPOINTS,true);
01302                                                                 m_popmenu.Enable(pwID_NOSHOWPOINTS,false);
01303                                                         }
01304                                                         if(actual->getType()==2)//Smoothed function
01305                                                         {
01306                                                                 m_popmenu.Enable(pwID_SPLINE,false);
01307                                                                 m_popmenu.Enable(pwID_LINE,true);
01308                                                         }
01309                                                         else
01310                                                         {
01311                                                                 m_popmenu.Enable(pwID_SPLINE,true);
01312                                                                 m_popmenu.Enable(pwID_LINE,false);
01313 
01314                                                         }
01315                                                         if(type==2)
01316                                                         {
01317                                                                 m_popmenu.Enable(pwID_LOAD,false);
01318                                                                 m_popmenu.Enable(pwID_STARTDRAWING,false);
01319                                                         }       
01320                                                         m_popmenu.Enable(pwID_SAVE,false);
01321                                                         m_popmenu.Enable(pwID_LOAD,false);
01322                                                         m_popmenu.Enable(pwID_STOPDRAWING,false);
01323                                                         m_popmenu.Enable(pwID_MYZOOMIN,true);
01324                                                         m_popmenu.Enable(pwID_MYZOOMOUT,true);
01325                                                         m_popmenu.Enable(pwID_CHANGECOLOR,true);
01326                                                         m_popmenu.Enable(mpID_LINE_GUIDES,true);
01327                                                         m_popmenu.Enable(pwID_SAVE,true);
01328                                                         m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,true);
01329 
01330                                                 }
01331                                                 //if the function is smooth
01332                                                 if(actual->getType()==2)
01333                                                 {
01334                                                         actual->clearSplineVectors();
01335                                                         actual->addSplinesPoints();
01336                                                         actual->initializeSplineVectors();
01337                                                         
01338                                                 }
01339                 
01340                                                 UpdateAll();
01341                                                 //------------------------------------------
01342                                                 //Sending the particular event
01343                                                 //-------------------------------------------
01344                                                 wxCommandEvent cevent( wxEVT_PPLOTTER_CHANGED_FUNCTION, GetId() );
01345                                                 cevent.SetEventObject(this);
01346 
01347                                                 //------------------------------------------
01348                                                 //Sending the  general event
01349                                                 //-------------------------------------------
01350                                                 wxCommandEvent pevent( wxEVT_PPLOTTER, GetId() );
01351                                                 pevent.SetEventObject(this);
01352                                                 //send the events
01353                                                 GetEventHandler()->ProcessEvent( cevent );
01354                                                 GetEventHandler()->ProcessEvent( pevent );
01355                                         }
01356                                 }
01357                                 node=node->GetNext();
01358                         }
01359                   }
01360                 }
01361                 //the user is finishing the drawing of the function
01362                 else
01363                 {
01364                         drawing=false;
01365                         functions.Append(actual);
01366                 }
01367 }
01368 
01373 void pPlotterWindow::changeFuntionType(int aTheType, bool aForAll)
01374 {
01375 
01376 }
01377 //------------------------------------------
01378 //If the data doesnt come from interaction
01379 //-------------------------------------------
01383 int pPlotterWindow:: addFunction(pGraphicalFunction * function)
01384 {
01385         if(function->getType()==2)
01386         {
01387                 function->initializeSplines();
01388                 function->initializeSplineVectors();
01389                 UpdateAll();
01390         }
01391         
01392 //      bool added1= functions.Append(function)!=NULL; // JPRx
01393         functions.Append(function);  //EED      
01394         
01395         int id=functions.IndexOf(function);
01396         
01397         // bool added2=  AddLayer(function);// JPRx
01398         AddLayer(function); //EED
01399          
01400         UpdateAll();
01401         return id;//added1 && added2;
01402 }
01408 bool pPlotterWindow::DeletePointFunction(pGraphicalFunction* function,wxPoint point)
01409 {
01410 
01411         wxNode* node= functions.GetFirst();
01412         while(node)
01413         {
01414                 pGraphicalFunction* f= (pGraphicalFunction*)node->GetData();
01415                 if(f==function)
01416                 {
01417                         return function->DeletePoint(point.x,point.y);
01418                 }
01419                 node=node->GetNext();
01420         }
01421         return false;
01422 }
01426 bool pPlotterWindow::deleteFunction(pGraphicalFunction * f)
01427 {
01428         functions.DeleteObject(f);
01429         functionsToMove.DeleteObject(f);
01430         return true;
01431 }
01435 pGraphicalFunction * pPlotterWindow::getFunctionForVectors( std::vector<double> *vectorX, std::vector<double> *vectorY )
01436 {
01437         double coordX = -1 ;    
01438         double coordY = -1;
01439 
01440         pGraphicalFunction * ff = new pGraphicalFunction( _T(" "), 1);
01441 
01442         int i=0;
01443         int sizeX = vectorX->size();
01444         int sizeY = vectorY->size();
01445         if( sizeX == sizeY )
01446         {
01447                 while ( i < sizeX )
01448                 {
01449                         coordX = (*vectorX)[i];                 
01450                         coordY = (*vectorY)[i];
01451                         ff -> AddPoint( coordX, coordY);                
01452                         i++;
01453                 }
01454         }
01455 
01456    InitFunctionForVectors( ff );
01457    return ff;
01458 }
01459 
01460 pGraphicalFunction * pPlotterWindow::getFunctionForVectors( double * vectorX, int sizeX, double * vectorY, int sizeY )
01461 {
01462         double coordX = -1 ;    
01463         double coordY = -1;
01464 
01465         pGraphicalFunction * ff = new pGraphicalFunction( _T(" "), 1);
01466 
01467         /*wxString text = "\n Including points from two vectors \n";
01468         m_log->AppendText(text);*/
01469 
01470         int i=0;
01471         if(sizeX == sizeY)
01472         {
01473                 while ( i < sizeX )
01474                 {
01475                         coordX = *vectorX;                      
01476                         coordY = *vectorY;
01477                         ff -> AddPoint( coordX, coordY);                
01478         /*              text = wxString::Format("Included point ( %d, %d)\n", coordX, coordY);
01479                         m_log->AppendText(text);*/
01480 
01481                         vectorX++;
01482                         vectorY++;              
01483                         i++;
01484                 }
01485         }
01486 
01487    InitFunctionForVectors( ff );
01488    return ff;
01489 }
01490 
01491 
01492 
01493 void pPlotterWindow::InitFunctionForVectors( pGraphicalFunction *ff )
01494 {
01495         int maxX,maxY,minX,minY;
01496         /*
01497         if the function is  not drawed interactively the maxX and the 
01498         maxY are the from the points of the function
01499         */
01500         maxX=ff->getMaxX();
01501         maxY=ff->getMaxY();
01502         minX= ff->getMinX();
01503         minY= ff->getMinY();
01504 
01505                 
01506         ff->setMinShowedX(minX);
01507         ff->setMinShowedY(minY);
01508         ff->setMaxShowedX(maxX);
01509         ff->setMaxShowedY(maxY);
01510         
01511         GetClientSize(&m_scrX,&m_scrY);
01512         //set
01513 
01514         if((maxX-minX)!=0 && (maxY-minY)!=0)
01515         {
01516                 m_scaleX= ((float)m_scrX-100)/(maxX-minX);
01517                 m_scaleY= ((float)m_scrY-50)/(maxY-minY);
01518         }
01519         maxScrX=maxX;
01520         maxScrY=maxY;
01521         minScrX=minX;
01522         minScrY=minY;
01523         
01524         
01525         if(type==HISTOGRAM)
01526         {       
01527                 actual=ff;
01528                 setActualScales();
01529                 m_popmenu.Enable(pwID_NOSHOWPOINTS,true);
01530                 m_popmenu.Enable(pwID_ADDNEWPOINT,true);
01531                 m_popmenu.Enable(pwID_SHOWPOINTS,false);
01532                 m_popmenu.Enable(pwID_DELPOINT,true);
01533                 //m_popmenu.Enable(pwID_SPLINE,false);
01534                 //m_popmenu.Enable(pwID_LINE,true);
01535                 m_popmenu.Enable(pwID_SAVE,true);
01536                 m_popmenu.Enable(pwID_LOAD,false);
01537                 m_popmenu.Enable(pwID_CHANGECOLOR,true);
01538                 //m_popmenu.Enable(pwID_STARTDRAWING,false);
01539                 m_popmenu.Enable(mpID_LINE_GUIDES,true);
01540                 m_popmenu.Enable(pwID_TRASLATEACTUALFUNCTION,true);
01541                 //------------------------------------------
01542                 //Sending the particular event of changed actual function
01543                 //-------------------------------------------
01544                 wxCommandEvent cevent( wxEVT_PPLOTTER_CHANGED_FUNCTION, GetId() );
01545                 cevent.SetEventObject(this);
01546                 GetEventHandler()->ProcessEvent( cevent );
01547         }
01548         
01549         /*
01550         maxScrX=100;
01551         minScrX=50;
01552         offsetX=50;
01553         ff->setOffsetX(50);
01554         */
01555         //actual->setScreens(scrX,scrY);
01556         //actual->setScales();
01557         //setActualScales();
01558 }
01559 /*
01560 bool pPlotterWindow::AddFunction(wxPoint realPoints[],int numberOfPoints,wxString name,int flags)
01561 {
01562 pGraphicalFunction* function= new pGraphicalFunction(name,flags);
01563 
01564 for(int i= 0; i<numberOfPoints;i++)
01565 {
01566 int x=realPoints[i].x;
01567 int y=realPoints[i].y;
01568 bool added=function->AddPoint(x,y);
01569 if(!added )
01570 return added;
01571 }
01572 functions.Append(function);
01573 bool addL=mpWindow::AddLayer(function);
01574 if(addL)
01575 {
01576 mpWindow::UpdateAll();
01577 }
01578 return addL;
01579 }
01580 */
01581 
01582 /*
01583 * Actualizes the view range of the plotter and the actual function
01584 * @param newMinX Is the min-value to be shown in the x-scale
01585 * @param newMaxX Is the max-value to be shown in the x-scale
01586 */
01587 /*
01588 DEPRECATED
01589 */
01590 void pPlotterWindow :: actualizeViewRange(int newMinX, int newMaxX)
01591 {
01592         int minPixX,maxPixX/*, min, max*/;  // JPRx
01593         double sx;
01594         /*
01595                 getiing pixels
01596         */
01597         int dx=newMaxX-newMinX;
01598         
01599         if(dx!=0)
01600         {
01601                 sx= (((float)m_scrX-100)/dx)*zoomFactor;
01602         }
01603         
01604          minPixX=newMinX*sx;
01605          maxPixX=newMaxX*sx;
01606 
01607                 //vx.at(i)-offsetX)*scaleX+offsetpx
01608         if(minScrX!=newMinX)
01609         {
01610                 setOffsetX(newMinX);
01611                 setMinScrX(newMinX);
01612                 actual->setOffsetX(newMinX);
01613                 actual->setMinShowedX(newMinX);                         
01614                 /*
01615                 wxNode * node= functions.GetFirst();
01616                 while (node)
01617                         {
01618                                 pGraphicalFunction* fnode=(pGraphicalFunction*)node->GetData();
01619                                 if(fnode)
01620                                 {
01621                                         if(!fnode->getActual())
01622                                         {
01623                                                 fnode->setScreens(m_scrX,m_scrY);
01624                                                 fnode->setScales();
01625                                                 //max=minPixX/fnode->getScaleX();
01626                                                 min=minPixX/fnode->getScaleX();
01627                                                 fnode->setOffsetX(min);
01628                                                 fnode->setMinShowedX(min);
01629                                                 
01630                                         }
01631                                 }
01632                                 node=node->GetNext();
01633                         }
01634                 */
01635             
01636         }
01637         if(maxScrX!=newMaxX)
01638         {
01639                 setMaxScrX(newMaxX);
01640             actual->setMaxShowedX(newMaxX);
01641                 /*
01642                 wxNode * node= functions.GetFirst();
01643                 while (node)
01644                         {
01645                                 
01646                                 pGraphicalFunction* fnode=(pGraphicalFunction*)node->GetData();
01647                                 if(fnode)
01648                                 {
01649                                         if(!fnode->getActual())
01650                                         {
01651                                                 fnode->setScreens(m_scrX,m_scrY);
01652                                                 fnode->setScales();
01653                                                 max=maxPixX/fnode->getScaleX();
01654                                                 //min=maxPixX/fnode->getScaleX();
01655                                                 //fnode->setOffsetX(max);
01656                                                 //fnode->setMinShowedX(min);
01657                                                 fnode->setMaxShowedX(max);
01658                                         }
01659                                 }
01660 
01661                                 node=node->GetNext();
01662                         }
01663                 */
01664         }
01665         /*
01666         if(actual->getMinXShowed()!=actual->getMinX() || actual->getMinYShowed()!=actual->getMinY()||
01667                 actual->getMaxXShowed()!=actual->getMaxX() || actual->getMaxYShowed()!=actual->getMaxY())
01668         {
01669                 m_popmenu.Enable(pwID_MYZOOMIN,false);
01670                 m_popmenu.Enable(pwID_MYZOOMOUT,false);
01671         }
01672         else if(actual->getMinXShowed()==actual->getMinX() && actual->getMaxXShowed()==actual->getMaxX())
01673         {
01674                 
01675                 m_popmenu.Enable(pwID_MYZOOMIN,true);
01676                 m_popmenu.Enable(pwID_MYZOOMOUT,true);
01677         }
01678         */
01679                  
01680         UpdateAll();
01681 }
01682 /*
01683 * Guide lines menu handler method that reacts to the mpID_LINE_GUIDES command event
01684 * event The corresponding event to handle
01685 */
01686 void pPlotterWindow :: OnGuideLines (wxCommandEvent   &event)
01687 {
01688         wxString nextAction_text;
01689         if( drawGuides )
01690         {
01691                 setLineGuidesCondition(false);
01692 //              nextAction_text << "Turn on guide lines";
01693                 nextAction_text = _T("Turn on guide lines");
01694                 UpdateAll();
01695         }
01696         else
01697         {
01698                 setLineGuidesCondition(true);
01699 //              nextAction_text << "Turn off guide lines";
01700                 nextAction_text = _T("Turn off guide lines");
01701                 UpdateAll();
01702         }
01703         //------------------------------------------
01704         //Sending the paarticular event of changed actual function
01705         //-------------------------------------------
01706         wxCommandEvent cevent( wxEVT_PPLOTTER_GUIDELINES, GetId() );
01707         cevent.SetEventObject(this);
01708     GetEventHandler()->ProcessEvent( cevent );
01709         
01710         //SETTING LABEL
01711         m_popmenu.SetLabel ( mpID_LINE_GUIDES, nextAction_text ); 
01712 }
01713 /*
01714         Get a function in the plotter given the index
01715 */
01716 pGraphicalFunction* pPlotterWindow::getFunction(int index)
01717 {
01718         wxNode* node=functions.Item(index);
01719         if(node==NULL){
01720                 return NULL;
01721         }
01722         return (pGraphicalFunction*)node->GetData();
01723 }
01724 /*
01725           move the functions that the user wants to move
01726           and that were set in functionsToMove
01727           @param porcentageMinX:the percentage that the minShowed
01728           of the functions have to be move
01729                 0<=porcentageMinX<=1
01730           @param porcentageMaxX:the percentage that the maxShowed
01731           of the functions have to be move
01732                 0<=porcentageMaxX<=1
01733 
01734         */
01735 
01736 void pPlotterWindow::moveFunctions( float porcentageMinX,float porcentageMaxX)
01737         {
01738                 //Adding the actual function
01739         
01740                 //functionsToMove.Append(actual);
01741 
01742                 //
01743                 //float minShowed,maxShowed,fMaxXShowed,fMinXShowed;
01744                 float x,y;
01745                  
01746                 
01747                 int minShowed,maxShowed,fMaxXShowed,fMinXShowed;
01748                 wxNode* fnode=functionsToMove.GetFirst();
01749                 while(fnode)
01750                 {
01751                         pGraphicalFunction* fg=(pGraphicalFunction*)fnode->GetData();
01752                         x=porcentageMaxX*(fg->getMaxX()-fg->getMinX());
01753                         y=porcentageMinX*(fg->getMaxX()-fg->getMinX());
01754                         
01755                         maxShowed=fg->getMinX()+ x;
01756                         minShowed=fg->getMinX()+ y;
01757 
01758                         fMinXShowed=fg->getMinXShowed();
01759                         fMaxXShowed=fg->getMaxXShowed();
01760                         
01761                         if(fMinXShowed!=minShowed)
01762                         {
01763                                 if(fg->getActual())
01764                                 {
01765                                         setOffsetX(minShowed);
01766                                         setMinScrX(minShowed);
01767                                 }
01768                                 fg->setOffsetX(minShowed);
01769                                 fg->setMinShowedX(minShowed);                             
01770                         }
01771                         if(fMaxXShowed!=maxShowed)
01772                         {
01773                                 if(fg->getActual())
01774                                 {
01775                                         setMaxScrX(maxShowed);
01776                                 }
01777                                 fg->setMaxShowedX(maxShowed);   
01778                         }
01779                         if(fg->getActual()&& (fg->getMinXShowed()!=fg->getMinX() || fg->getMinYShowed()!=fg->getMinY()||
01780                                                                   fg->getMaxXShowed()!=fg->getMaxX() || fg->getMaxYShowed()!=fg->getMaxY()))
01781                         {
01782                                 if(type!=HISTOGRAM)
01783                                 {
01784                                         m_popmenu.Enable(pwID_MYZOOMIN,false);
01785                                         m_popmenu.Enable(pwID_MYZOOMOUT,false);
01786                                 }
01787                         }
01788                         else if(fg->getActual()&& fg->getMinXShowed()==fg->getMinX() && fg->getMaxXShowed()==fg->getMaxX())
01789                         {
01790                                 if(type!=HISTOGRAM)
01791                                 {
01792                                         m_popmenu.Enable(pwID_MYZOOMIN,true);
01793                                         m_popmenu.Enable(pwID_MYZOOMOUT,true);
01794                                 }
01795                         }
01796 
01797 
01798                                         fnode=fnode->GetNext();
01799                 }
01800 }
01801 
01802 /*
01803  adds a function such that when the min or max of the bar
01804  changes it is going to that function
01805 */
01806 int pPlotterWindow::addFunctionToMove(pGraphicalFunction *function)
01807 {
01808         //bool added1=  functionsToMove.Append(function)!=NULL; // JPRx
01809         functionsToMove.Append(function); // EED
01810         
01811         int id=functionsToMove.IndexOf(function);
01812         UpdateAll();
01813         return id;
01814 }
01815 //----------------------------
01816 //Handling Options Menu
01817 //----------------------------
01818 void pPlotterWindow::setPopUpMenu(bool startD,bool stopD,bool smooth,bool line, bool zoomIn,
01819                                           bool zoomOut,bool showPoints,bool noShowPoints,bool changeColor, bool addP,
01820                                           bool delPoint,bool load,bool save)
01821 {
01822         /*
01823         pwID_ADDPOINT = 2010,    //!< add a point to the function
01824         pwID_DELPOINT,       //!< delete a point of the function
01825         pwID_SHOWPOINTS,  //!<shows the points that the function has
01826         pwID_STARTDRAWING, //!<let to the user to start drawing the curve
01827         pwID_DELFUNCTION, //!<delete a function that is in the plotter
01828         pwID_STOPDRAWING,//!<Stops the drawing of the function
01829         pwID_ADDNEWPOINT,//!<add a new point to the function.
01830         pwID_NOSHOWPOINTS, //!<No show the points of the function.
01831         pwID_MYZOOMIN,//!<Zoom in the function
01832         pwID_MYZOOMOUT,//!<Zoom out the points of the function.
01833         pwID_SPLINE,//!<Spline the actual curve.
01834         pwID_LINE,//!<Piecewise the actual curve.
01835         pwID_SAVE,//!<Save the function in a .txt file.
01836         pwID_LOAD, //!<Load the function from a .txt file.
01837         pwID_CHANGECOLOR, //!<Change the color of the function
01838         pwID_TRASLATEACTUALFUNCTION //!<move the actual function
01839 */
01840         if(startD)
01841                 m_popmenu.Remove( pwID_STARTDRAWING);
01842         if(stopD)
01843                 m_popmenu.Remove( pwID_STOPDRAWING);
01844         if(load)
01845                 m_popmenu.Remove( pwID_LOAD);
01846         if(save)
01847                 m_popmenu.Remove( pwID_SAVE);
01848         if(showPoints)
01849                 m_popmenu.Remove( pwID_SHOWPOINTS);
01850         if(noShowPoints)
01851                 m_popmenu.Remove( pwID_NOSHOWPOINTS);
01852         if(smooth)
01853                 m_popmenu.Remove( pwID_SPLINE);
01854         if(line)
01855                 m_popmenu.Remove( pwID_LINE);
01856         if(zoomIn)
01857                 m_popmenu.Remove( pwID_MYZOOMIN);
01858         if(zoomOut)
01859                 m_popmenu.Remove( pwID_MYZOOMOUT);
01860         if(changeColor)
01861                 m_popmenu.Remove( pwID_CHANGECOLOR);
01862         if(addP)
01863                 m_popmenu.Remove( pwID_ADDPOINT);
01864         if(delPoint)
01865                 m_popmenu.Remove( pwID_DELPOINT);
01866 }
01867 
01868 

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1