COPASI API  4.16.103
CGraphCurve.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/layoutUI/CGraphCurve.cpp,v $
3 // $Revision: 1.19 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2011/03/07 19:29:15 $
7 // End CVS Header
8 
9 // Copyright (C) 2011 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
20 // Properties, Inc. and EML Research, gGmbH.
21 // All rights reserved.
22 
23 #include <algorithm>
24 
25 #include "copasi.h"
26 
27 #include "CGraphCurve.h"
28 #include "BezierCurve.h"
30  : CLCurve()
31 {
32  mHasArrow = false;
33 }
34 
36  : CLCurve(c)
37 {
38  mHasArrow = false;
39 }
40 
42  : CLCurve(c)
43 {
44  mHasArrow = c.mHasArrow;
45  mArrow = c.mArrow;
46  mRole = c.mRole;
47 }
48 
49 void CGraphCurve::scale(const double & scaleFactor)
50 {
51  unsigned int i; // scale all segments
52 
53  for (i = 0; i < mvCurveSegments.size(); i++)
54  {
55  mvCurveSegments[i].scale(scaleFactor);
56  }
57 
58  if (mHasArrow)
59  mArrow.scale(scaleFactor);
60 }
61 
63 {
64  unsigned int i; // invert order of points in each segment
65  CLPoint h; // puffer variable
66 
67  for (i = 0; i < mvCurveSegments.size(); i++)
68  {
69  h = mvCurveSegments[i].getStart();
70  mvCurveSegments[i].setStart(mvCurveSegments[i].getEnd());
71  mvCurveSegments[i].setEnd(h);
72 
73  if (mvCurveSegments[i].isBezier())
74  {
75  h = mvCurveSegments[i].getBase1();
76  mvCurveSegments[i].setBase1(mvCurveSegments[i].getBase2());
77  mvCurveSegments[i].setBase2(h);
78  }
79  }
80 
81  // now invert order of segments
82  std::reverse(mvCurveSegments.begin(), mvCurveSegments.end());
83 
84  if (mHasArrow)
85  {// exchange line segment and end point
86  CLLineSegment lastSeg = mvCurveSegments[mvCurveSegments.size() - 1];
87  CLPoint p = lastSeg.getEnd();
88 
89  if (lastSeg.isBezier())
90  {
91  BezierCurve *bezier = new BezierCurve();
92  std::vector<CLPoint> pts = std::vector<CLPoint>();
93  pts.push_back(lastSeg.getStart());
94  pts.push_back(lastSeg.getBase1());
95  pts.push_back(lastSeg.getBase2());
96  pts.push_back(lastSeg.getEnd());
97  std::vector<CLPoint> bezierPts = bezier->curvePts(pts);
98  size_t num = bezierPts.size();
99  CLLineSegment segForArrow = CLLineSegment(bezierPts[num - 2], bezierPts[num - 1]);
100  mArrow.setLine(segForArrow);
101  mArrow.setPoint(CLPoint(bezierPts[num - 1].getX(), bezierPts[num - 1].getY()));
102  //ar = new CArrow(segForArrow, bezierPts[num - 1].getX(), bezierPts[num - 1].getY(), this->currentZoom);
103  }
104  else
105  {
106  mArrow.setLine(lastSeg);
107  mArrow.setPoint(CLPoint(p.getX(), p.getY()));
108  }
109 
110  //ar = new CArrow(lastSeg, p.getX(), p.getY(), this->currentZoom);
111  }
112 }
void scale(C_FLOAT64 zoomFactor)
Definition: CArrow.cpp:36
const CLPoint & getBase1() const
Definition: CLCurve.h:82
const CLPoint & getBase2() const
Definition: CLCurve.h:83
const CLPoint & getEnd() const
Definition: CLCurve.h:75
const C_FLOAT64 & getX() const
Definition: CLBase.h:83
Definition: CLBase.h:54
CArrow mArrow
Definition: CGraphCurve.h:34
Header file of class BezierCurve.
const C_FLOAT64 & getY() const
Definition: CLBase.h:84
bool isBezier() const
Definition: CLCurve.h:90
std::vector< CLPoint > curvePts(const std::vector< CLPoint > &pts)
Definition: BezierCurve.cpp:49
void invertOrderOfPoints()
Definition: CGraphCurve.cpp:62
CLMetabReferenceGlyph::Role mRole
Definition: CGraphCurve.h:36
void setPoint(CLPoint p)
Definition: CArrow.h:45
bool mHasArrow
Definition: CGraphCurve.h:35
void scale(const double &scaleFactor)
Definition: CGraphCurve.cpp:49
void setLine(CLLineSegment l)
Definition: CArrow.h:43
const CLPoint & getStart() const
Definition: CLCurve.h:74
std::vector< CLLineSegment > mvCurveSegments
Definition: CLCurve.h:135