]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/pPlotterLayer.cxx
*** empty log message ***
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / pPlotterLayer.cxx
index 37c7ba27e888de661a642d41591f83af455fd833..c8c64d66267484952324d736535856044a361b7b 100644 (file)
@@ -41,7 +41,7 @@ pPlotterLayer:: pPlotterLayer(wxString name , int flags )
 Draw the line from (x1,y1) to (x2,y2) only passing by the 
 positive points in the line
 */
-void  pPlotterLayer::draw(wxDC & dc,mpWindow & w,double x1,double y1,double x2,double y2)
+void  pPlotterLayer::draw(wxDC & dc,mpWindow & w,double x1,double y1,double x2,double y2, int orgy)
 {
        
        //intercepts
@@ -49,23 +49,24 @@ void  pPlotterLayer::draw(wxDC & dc,mpWindow & w,double x1,double y1,double x2,d
        float x0=-y1/m+x1;
        float y0=-m*x1+y1;      
 
+       double sizedc = dc.GetSize().GetHeight()-orgy;
 
        //analyzing the curve
 
                if(x1<=0 && x2>=0)
                {
                        if(y2>=0 && y1>=0)
-                                       dc.DrawLine(0,y0, x2,y2);
+                                       dc.DrawLine(0,GetYTranslated(sizedc,y0), x2,GetYTranslated(sizedc,y2));
 
                        else if(y2<=0 && y1>=0)
                        {
                                if(y0>=0 && x0>=0)
-                                       dc.DrawLine(0,y0,x0,0 );
+                                       dc.DrawLine(0,GetYTranslated(sizedc,y0),x0,GetYTranslated(sizedc,0) );
                        }
                        else if(y2>=0 && y1<=0)
                        {
                                if(y0>=0) 
-                               dc.DrawLine(0,y0,x2,y2 );
+                               dc.DrawLine(0,GetYTranslated(sizedc,y0),x2,GetYTranslated(sizedc,y2) );
                        }
        
                }
@@ -73,11 +74,11 @@ void  pPlotterLayer::draw(wxDC & dc,mpWindow & w,double x1,double y1,double x2,d
                if(x1>=0 && x2>=0)
                {
                        if(y1>=0 && y2>=0 )
-                               dc.DrawLine(x1,y1, x2,y2);
+                               dc.DrawLine(x1,GetYTranslated(sizedc,y1), x2,GetYTranslated(sizedc,y2));
                        else if(y1>=0 && y2<=0)
-                               dc.DrawLine(x1,y1,x0,0 );
+                               dc.DrawLine(x1,GetYTranslated(sizedc,y1),x0,GetYTranslated(sizedc,0) );
                        else if(y1<=0 && y2>=0) 
-                                       dc.DrawLine(x0,0,x2,y2);
+                                       dc.DrawLine(x0,GetYTranslated(sizedc,0),x2,GetYTranslated(sizedc,y2));
                }
                
                
@@ -87,7 +88,7 @@ void  pPlotterLayer::draw(wxDC & dc,mpWindow & w,double x1,double y1,double x2,d
 * Draw the function with th spline points
 *
 */
-void pPlotterLayer::drawSplineCurve(wxDC & dc,mpWindow & w)
+void pPlotterLayer::drawSplineCurve(wxDC & dc,mpWindow & w, int orgy)
 {
        std::vector<double> vx=getXSpline();
        std::vector<double> vy=getYSpline();
@@ -139,7 +140,7 @@ void pPlotterLayer::drawSplineCurve(wxDC & dc,mpWindow & w)
                
                
                if(type!=2)     
-                       draw(dc,w,cxi,cyi,cxj,cyj);
+                       draw(dc,w,cxi,cyi,cxj,cyj,orgy);
                else if(type==2)
                {
                        if(!initializePolygon(ppoints,cxi,cyi,cxj,cyj) && ((cxi<=0 && cxj>=0)||(cxi>=0 && cxj>=0)))
@@ -174,6 +175,10 @@ void pPlotterLayer::drawSplineCurve(wxDC & dc,mpWindow & w)
                dc.SetBrush(wxBrush( wxColour(239,238,242) ,wxSOLID  ));
                dc.SetPen(wxPen( wxColour(0,0,0) ,1,wxSOLID  ));
                //dc.DrawPolygon(vx.size()+2,ppoints,0,0);
+               for(int i = 0; i <= j + 1; i++){
+                       int sizedc = dc.GetSize().GetHeight()-orgy;
+                       ppoints[i].y = GetYTranslated(sizedc, ppoints[i].y);
+               }       
                dc.DrawPolygon(j+2,ppoints,0,0);
        }
        
@@ -282,7 +287,7 @@ bool pPlotterLayer::initializePolygon(wxPoint* points,double x1, double y1,doubl
 /**
 * Draw the lines between the points of the function
 */
-void pPlotterLayer::drawFunction(wxDC & dc,mpWindow & w)
+void pPlotterLayer::drawFunction(wxDC & dc,mpWindow & w, int orgy)
 {
 
        
@@ -301,6 +306,8 @@ void pPlotterLayer::drawFunction(wxDC & dc,mpWindow & w)
        dc.GetSize(&scrwX, &scrwY);
        
        //Lines between the points
+
+       int sizedc = dc.GetSize().GetHeight()-orgy;
        
        GetPoints(points);
 
@@ -329,7 +336,7 @@ void pPlotterLayer::drawFunction(wxDC & dc,mpWindow & w)
                ppoints=(wxPoint*)malloc(sizeof(int)*2*(points.GetCount()+2));
                //initialize points
                point.x=-5000;
-               point.y=-5000;
+               point.y=GetYTranslated(sizedc,-5000);
                ppoints[0]=point;
                ppoints[1]=point;
 
@@ -355,14 +362,14 @@ void pPlotterLayer::drawFunction(wxDC & dc,mpWindow & w)
                int cyj=pyj* scaleY+ offsetpy ;
                //dc.DrawLine(pxi* scaleX + offsetpx,pyi* scaleY+ offsetpy, pxj* scaleX + offsetpx,pyj* scaleY+ offsetpy );
                if(type!=2)
-                       draw(dc,w,pxi* scaleX + offsetpx,pyi* scaleY+ offsetpy, pxj* scaleX + offsetpx,pyj* scaleY+ offsetpy );
+                       draw(dc,w,pxi* scaleX + offsetpx,pyi* scaleY+ offsetpy, pxj* scaleX + offsetpx,pyj* scaleY+ offsetpy,orgy );
                        //dc.DrawLine(pxi* scaleX + offsetpx,pyi* scaleY+ offsetpy, pxj* scaleX + offsetpx,pyj* scaleY+ offsetpy );
                else if(type==2)
                {
                        if(!initializePolygon(ppoints,cxi,cyi,cxj,cyj) && ((cxi<=0 && cxj>=0)||(cxi>=0 && cxj>=0)))
                        {
                                        point.x=cxj;
-                                       point.y=cyj;
+                                       point.y=GetYTranslated(sizedc,cyj);
                                        ppoints[j]=point;
                                        j++;
                
@@ -376,7 +383,7 @@ void pPlotterLayer::drawFunction(wxDC & dc,mpWindow & w)
        {
                //point.x=vx.at(size-1)* scaleX + offsetpx;
                point.x=ppoints[j-1].x;
-               point.y=0;
+               point.y=GetYTranslated(sizedc,0);
                //ppoints[vx.size()]=point;
                ppoints[j]=point;
                /*
@@ -386,7 +393,7 @@ void pPlotterLayer::drawFunction(wxDC & dc,mpWindow & w)
                //settings for fill
                //point.x=vx.at(0)*scaleX + offsetpx;
                point.x=ppoints[0].x;
-               point.y=0;
+               point.y=GetYTranslated(sizedc,0);
                //ppoints[vx.size()+1]=point;
                ppoints[j+1]=point;
 
@@ -402,13 +409,14 @@ void pPlotterLayer::drawFunction(wxDC & dc,mpWindow & w)
 /**
 *  Draw the points of the function
 */
-void pPlotterLayer::drawPoints(wxDC & dc,mpWindow & w)
+void pPlotterLayer::drawPoints(wxDC & dc,mpWindow & w, int orgy)
 {
        
        Rewind();
        double x, y;
        int minX,maxX,minY,maxY;
 
+       double sizedc = dc.GetSize().GetHeight()-orgy;
        
        /*
        This is the offset of every point scale to the window
@@ -434,13 +442,13 @@ void pPlotterLayer::drawPoints(wxDC & dc,mpWindow & w)
                dc.SetBrush(wxBrush( wxColour(255,0,0),wxSOLID  ));
                //dc.SetPen(wxPen(wxColour(0,0,0),1,wxSOLID) );
                points[0].x=((x-minX-offsetX)*scaleX + offsetpx-MOVE);
-               points[0].y=((y-minY-offsetY)*scaleY+ offsetpy-MOVE);
+               points[0].y=GetYTranslated(sizedc,((y-minY-offsetY)*scaleY+ offsetpy-MOVE));
                points[1].x=((x-minX-offsetX)*scaleX+ offsetpx+MOVE);
-               points[1].y=((y-minY-offsetY)*scaleY+ offsetpy-MOVE);
+               points[1].y=GetYTranslated(sizedc,((y-minY-offsetY)*scaleY+ offsetpy-MOVE));
                points[2].x=((x-minX-offsetX)*scaleX+ offsetpx+MOVE);
-               points[2].y=((y-minY-offsetY)*scaleY+ offsetpy+MOVE);
+               points[2].y=GetYTranslated(sizedc,((y-minY-offsetY)*scaleY+ offsetpy+MOVE));
                points[3].x=((x-minX-offsetX)*scaleX+ offsetpx-MOVE);
-               points[3].y=((y-minY-offsetY)*scaleY+ offsetpy+MOVE);
+               points[3].y=GetYTranslated(sizedc,((y-minY-offsetY)*scaleY+ offsetpy+MOVE));
                if((x-minX-offsetX)*scaleX >=0 && (y-minY-offsetY/*w.getMinScrY()*/)*scaleY>=0)
                dc.DrawPolygon(4,points,0,0);
        }
@@ -450,7 +458,7 @@ void pPlotterLayer::drawPoints(wxDC & dc,mpWindow & w)
 * Draw the line between the last point of the function
 * and the position of the mouse
 */
-void pPlotterLayer::drawLineToMousePoint(wxDC & dc,mpWindow & w)
+void pPlotterLayer::drawLineToMousePoint(wxDC & dc,mpWindow & w, int orgy)
 {
        int x,y,sizeP,maxX,maxY,minX,minY;
        bool direction;
@@ -535,6 +543,7 @@ void pPlotterLayer::Plot(wxDC & dc, mpWindow & w)
         */
        
        dc.GetSize(&scrwX, &scrwY);
+       
        getIfActual(actual);
        //getMax(maxX, maxY);
        /***********/
@@ -576,39 +585,41 @@ void pPlotterLayer::Plot(wxDC & dc, mpWindow & w)
 //     dc.SetAxisOrientation(true,true);
        
        int orgy = 40;  
-       dc.SetDeviceOrigin( orgx ,orgy);
-       dc.SetAxisOrientation(true,false);
+       //dc.SetDeviceOrigin( orgx ,orgy);
+       dc.SetDeviceOrigin( orgx ,0);
+       int sizedc = dc.GetSize().GetHeight()-orgy;
+       //dc.SetAxisOrientation(true,false);
 
        
 
        //if the user dont want to see the points of the function and if he stops drawing
        //we have to draw the function
        if(!show && !drawing && type==1)
-               drawFunction(dc,w);
+               drawFunction(dc,w,orgy);
        else if(!show && !drawing && type==2)
-               drawSplineCurve(dc,w);
+               drawSplineCurve(dc,w,orgy);
        //we just draw the point that the user just clicked
        else if(drawing && type==1)
        { 
-               drawFunction(dc,w);
-               drawLineToMousePoint(dc,w);
-               drawPoints(dc,w);
+               drawFunction(dc,w,orgy);
+               drawLineToMousePoint(dc,w,orgy);
+               drawPoints(dc,w,orgy);
        }
        else if(drawing && type==1)
        {
-               drawSplineCurve(dc,w);
-               drawLineToMousePoint(dc,w);
-               drawPoints(dc,w);
+               drawSplineCurve(dc,w,orgy);
+               drawLineToMousePoint(dc,w,orgy);
+               drawPoints(dc,w,orgy);
        }
        else if(show && type==1)
        {
-               drawFunction(dc,w);
-               drawPoints(dc,w);
+               drawFunction(dc,w,orgy);
+               drawPoints(dc,w,orgy);
        }
        else if(show && type==2)
        {
-               drawSplineCurve(dc,w);
-               drawPoints(dc,w);
+               drawSplineCurve(dc,w,orgy);
+               drawPoints(dc,w,orgy);
        }
 
        // Drawing the guides according to real values entered according to the integrated interaction (IS NOT WORKING!!!)
@@ -621,13 +632,19 @@ void pPlotterLayer::Plot(wxDC & dc, mpWindow & w)
                int realX_guide = w.getRealGuideX();
                if( realX_guide!=-1 )
                {
-               dc.DrawLine( (realX_guide/*-w.getMinScrX()*/-offsetX)*scaleX + offsetpx, 0, (realX_guide/*-w.getMinScrX()*/-offsetX)*scaleX + offsetpx, scrwY);                 
+               dc.DrawLine( (realX_guide/*-w.getMinScrX()*/-offsetX)*scaleX + offsetpx, 
+                       GetYTranslated(sizedc,0), 
+                       (realX_guide/*-w.getMinScrX()*/-offsetX)*scaleX + offsetpx, 
+                       GetYTranslated(sizedc,scrwY));                  
                }
                        
                int realY_guide = w.getRealGuideY();
                if( realY_guide!=-1 )
                {
-                       dc.DrawLine( 0,(realY_guide/*-w.getMinScrY()*/-offsetX)*scaleX + offsetpx, scrwX, (realY_guide/*-w.getMinScrY()*/-offsetX)*scaleX + offsetpx);
+                       dc.DrawLine( 0,
+                               GetYTranslated(sizedc,(realY_guide/*-w.getMinScrY()*/-offsetX)*scaleX + offsetpx), 
+                               scrwX, 
+                               GetYTranslated(sizedc,(realY_guide/*-w.getMinScrY()*/-offsetX)*scaleX + offsetpx));
                }
        }