]> SALOME platform Git repositories - modules/gui.git/blob - src/Plot2d/Plot2d_Curve.cxx
Salome HOME
b4c8e68d93a8261d9ecd7e6d6bc7477eb97ad06a
[modules/gui.git] / src / Plot2d / Plot2d_Curve.cxx
1 #include "Plot2d_Curve.h"
2 #include <qcolor.h>
3
4 /*!
5   Constructor
6 */
7 Plot2d_Curve::Plot2d_Curve()
8 : myHorTitle( "" ), myVerTitle( "" ), 
9 myHorUnits( "" ), myVerUnits( "" ), 
10 myAutoAssign( true ), myColor( 0,0,0 ), myMarker( Circle ), myLine( Solid ), myLineWidth( 0 ),
11 myYAxis( QwtPlot::yLeft )
12 {
13 }
14
15 /*!
16   Destructor
17 */
18 Plot2d_Curve::~Plot2d_Curve()
19 {
20 }
21
22 /*!
23   Copy constructor. Makes deep copy of data.
24 */
25 Plot2d_Curve::Plot2d_Curve( const Plot2d_Curve& curve )
26 {
27   myAutoAssign = curve.isAutoAssign();
28   myHorTitle   = curve.getHorTitle();
29   myVerTitle   = curve.getVerTitle();
30   myHorUnits   = curve.getHorUnits();
31   myVerUnits   = curve.getVerUnits();
32   myColor      = curve.getColor();
33   myMarker     = curve.getMarker();
34   myLine       = curve.getLine();
35   myLineWidth  = curve.getLineWidth();
36   myPoints     = curve.getPointList();
37 }
38
39 /*!
40   operator=. Makes deep copy of data.
41 */
42 Plot2d_Curve& Plot2d_Curve::operator=( const Plot2d_Curve& curve )
43 {
44   myAutoAssign = curve.isAutoAssign();
45   myHorTitle   = curve.getHorTitle();
46   myVerTitle   = curve.getVerTitle();
47   myHorUnits   = curve.getHorUnits();
48   myVerUnits   = curve.getVerUnits();
49   myColor      = curve.getColor();
50   myMarker     = curve.getMarker();
51   myLine       = curve.getLine();
52   myLineWidth  = curve.getLineWidth();
53   myPoints     = curve.getPointList();
54   return *this;
55 }
56
57 QString Plot2d_Curve::getTableTitle() const
58 {
59   return QString();
60 }
61
62 /*!
63   Sets curve's horizontal title
64 */
65 void Plot2d_Curve::setHorTitle( const QString& title )
66 {
67   myHorTitle = title;
68 }
69
70 /*!
71   Gets curve's horizontal title
72 */
73 QString Plot2d_Curve::getHorTitle() const
74 {
75   return myHorTitle;
76 }
77
78 /*!
79   Sets curve's vertical title
80 */
81 void Plot2d_Curve::setVerTitle( const QString& title )
82 {
83   myVerTitle = title;
84 }
85
86 /*!
87   Gets curve's vertical title
88 */
89 QString Plot2d_Curve::getVerTitle() const
90 {
91   return myVerTitle;
92 }
93
94 /*!
95   Sets curve's horizontal units
96 */
97 void Plot2d_Curve::setHorUnits( const QString& units )
98 {
99   myHorUnits = units;
100 }
101
102 /*!
103   Gets curve's horizontal units
104 */
105 QString Plot2d_Curve::getHorUnits() const
106 {
107   return myHorUnits;
108 }
109
110 /*!
111   Sets curve's vertical units
112 */
113 void Plot2d_Curve::setVerUnits( const QString& units )
114 {
115   myVerUnits = units;
116 }
117
118 /*!
119   Gets curve's vertical units
120 */
121 QString Plot2d_Curve::getVerUnits() const
122 {
123   return myVerUnits;
124 }
125
126 /*!
127   Adds one point for curve.
128 */
129 void Plot2d_Curve::addPoint(double theX, double theY)
130 {
131   Plot2d_Point aPoint;
132   aPoint.x = theX;
133   aPoint.y = theY;
134   myPoints.append(aPoint);
135 }
136
137 /*!
138   Insert one point for curve on some position.
139 */
140 void Plot2d_Curve::insertPoint(int thePos, double theX, double theY)
141 {
142   Plot2d_Point aPoint;
143   aPoint.x = theX;
144   aPoint.y = theY;
145
146   QValueList<Plot2d_Point>::iterator aIt;
147   int aCurrent = 0;
148   for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
149     if (thePos == aCurrent) {
150       myPoints.insert(aIt, aPoint);
151       return;
152     }
153     aCurrent++;  
154   }
155   myPoints.append(aPoint);
156 }
157
158 /*!
159   Delete one point for curve on some position.
160 */
161 void Plot2d_Curve::deletePoint(int thePos)
162 {
163   QValueList<Plot2d_Point>::iterator aIt;
164   int aCurrent = 0;
165   for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
166     if (thePos == aCurrent) {
167       myPoints.remove(aIt);
168       return;
169     }
170     aCurrent++;  
171   }
172 }
173
174 /*!
175   Remove all points for curve.
176 */
177 void Plot2d_Curve::clearAllPoints()
178 {
179   myPoints.clear();
180 }
181
182 /*!
183   Gets curve's data : abscissas of points
184 */
185 pointList Plot2d_Curve::getPointList() const
186 {
187   return myPoints;
188 }
189
190 /*!
191   Sets curve's data. 
192 */
193 void Plot2d_Curve::setData( const double* hData, const double* vData, long size )
194 {
195   clearAllPoints();
196   for(long i = 0; i < size; i++) addPoint(hData[i], vData[i]);
197 }
198
199 /*!
200   Gets curve's data : abscissas of points
201 */
202 double* Plot2d_Curve::horData() const
203 {
204   int aNPoints = nbPoints();
205   double* aX = new double[aNPoints];
206   for (int i = 0; i < aNPoints; i++) {
207     aX[i] = myPoints[i].x;
208   }
209   return aX;
210 }
211
212 /*!
213   Gets curve's data : ordinates of points
214 */
215 double* Plot2d_Curve::verData() const
216 {
217   int aNPoints = nbPoints();
218   double* aY = new double[aNPoints];
219   for (int i = 0; i < aNPoints; i++) {
220     aY[i] = myPoints[i].y;
221   }
222   return aY;
223 }
224
225 /*!
226   Gets curve's data : number of points
227 */
228 int Plot2d_Curve::nbPoints() const
229 {
230   return myPoints.count();
231 }
232
233 /*!
234   Returns true if curve has no data
235 */
236 bool Plot2d_Curve::isEmpty() const
237 {
238   return myPoints.isEmpty();
239 }
240
241 /*!
242   Sets curve's AutoAssign flag - in this case attributes will be set automatically
243 */
244 void Plot2d_Curve::setAutoAssign( bool on )
245 {
246   myAutoAssign = on;
247 }
248
249 /*!
250   Gets curve's AutoAssign flag state
251 */
252 bool Plot2d_Curve::isAutoAssign() const
253 {
254   return myAutoAssign;
255 }
256
257 /*!
258   Sets curve's color ( and resets AutoAssign flag )
259 */
260 void Plot2d_Curve::setColor( const QColor& color )
261 {
262   myColor = color;
263   myAutoAssign = false;
264 }
265
266 /*!
267   Gets curve's color
268 */
269 QColor Plot2d_Curve::getColor() const
270 {
271   return myColor;
272 }
273
274 /*!
275   Sets curve's marker ( and resets AutoAssign flag )
276 */
277 void Plot2d_Curve::setMarker( MarkerType marker )
278 {
279   myMarker = marker;
280   myAutoAssign = false;
281 }
282
283 /*!
284   Gets curve's marker
285 */
286 Plot2d_Curve::MarkerType Plot2d_Curve::getMarker() const
287 {
288   return myMarker;
289 }
290
291 /*!
292   Sets curve's line type and width ( and resets AutoAssign flag )
293   NOTE : A line width of 0 will produce a 1 pixel wide line using a fast algorithm for diagonals. 
294          A line width of 1 will also produce a 1 pixel wide line, but uses a slower more accurate 
295          algorithm for diagonals. 
296          For horizontal and vertical lines a line width of 0 is the same as a line width of 1.
297 */
298 void Plot2d_Curve::setLine( LineType line, const int lineWidth )
299 {
300   myLine = line;
301   myLineWidth = lineWidth;
302   if ( myLineWidth < 0 ) myLineWidth = 0;
303   myAutoAssign = false;
304 }
305
306 /*!
307   Gets curve's line type
308 */
309 Plot2d_Curve::LineType Plot2d_Curve::getLine() const
310 {
311   return myLine;
312 }
313
314 /*!
315   Gets curve's line width
316 */
317 int Plot2d_Curve::getLineWidth() const
318 {
319   return myLineWidth;
320 }
321
322 /*!
323   Sets curve's y axis
324 */
325 void Plot2d_Curve::setYAxis(QwtPlot::Axis theYAxis)
326 {
327   if(theYAxis == QwtPlot::yLeft || theYAxis == QwtPlot::yRight)
328     myYAxis = theYAxis;
329 }
330
331 /*!
332   Gets curve's y axis
333 */
334 QwtPlot::Axis Plot2d_Curve::getYAxis() const
335 {
336   return myYAxis;
337 }