Salome HOME
PR: mergefrom_BSEC_br1_14Mar04
[modules/kernel.git] / src / Plot2d / Plot2d_Curve.cxx
1 //  Copyright (C) 2003  CEA/DEN, EDF R&D
2 //
3 //
4 //
5 //  File   : Plot2d_Curve.cxx
6 //  Author : Vadim SANDLER
7 //  Module : SALOME
8 //  $Header$
9
10 #include "Plot2d_Curve.h"
11 #include "utilities.h"
12 using namespace std;
13
14 /*!
15   Constructor
16 */
17 Plot2d_Curve::Plot2d_Curve()
18      : myHorTitle( "" ), myVerTitle( "" ), 
19        myHorUnits( "" ), myVerUnits( "" ), 
20        myAutoAssign( true ), myColor( 0,0,0 ), myMarker( Circle ), myLine( Solid ), myLineWidth( 0 )
21 {
22 }
23 /*!
24   Destructor
25 */
26 Plot2d_Curve::~Plot2d_Curve()
27 {
28 //  MESSAGE("Plot2d_Curve::~Plot2d_Curve");
29 }
30 /*!
31   Copy constructor. Makes deep copy of data.
32 */
33 Plot2d_Curve::Plot2d_Curve( const Plot2d_Curve& curve )
34 {
35   myAutoAssign = curve.isAutoAssign();
36   myHorTitle   = curve.getHorTitle();
37   myVerTitle   = curve.getVerTitle();
38   myHorUnits   = curve.getHorUnits();
39   myVerUnits   = curve.getVerUnits();
40   myColor      = curve.getColor();
41   myMarker     = curve.getMarker();
42   myLine       = curve.getLine();
43   myLineWidth  = curve.getLineWidth();
44   myHorData.duplicate( curve.horData(), curve.nbPoints() );
45   myVerData.duplicate( curve.verData(), curve.nbPoints() );
46 }
47 /*!
48   operator=. Makes deep copy of data.
49 */
50 Plot2d_Curve& Plot2d_Curve::operator=( const Plot2d_Curve& curve )
51 {
52   myAutoAssign = curve.isAutoAssign();
53   myHorTitle   = curve.getHorTitle();
54   myVerTitle   = curve.getVerTitle();
55   myHorUnits   = curve.getHorUnits();
56   myVerUnits   = curve.getVerUnits();
57   myColor      = curve.getColor();
58   myMarker     = curve.getMarker();
59   myLine       = curve.getLine();
60   myLineWidth  = curve.getLineWidth();
61   myHorData.duplicate( curve.horData(), curve.nbPoints() );
62   myVerData.duplicate( curve.verData(), curve.nbPoints() );
63   return *this;
64 }
65 /*!
66   Sets curve's horizontal title
67 */
68 void Plot2d_Curve::setHorTitle( const QString& title )
69 {
70   myHorTitle = title;
71 }
72 /*!
73   Gets curve's horizontal title
74 */
75 QString Plot2d_Curve::getHorTitle() const
76 {
77   return myHorTitle;
78 }
79 /*!
80   Sets curve's vertical title
81 */
82 void Plot2d_Curve::setVerTitle( const QString& title )
83 {
84   myVerTitle = title;
85 }
86 /*!
87   Gets curve's vertical title
88 */
89 QString Plot2d_Curve::getVerTitle() const
90 {
91   return myVerTitle;
92 }
93 /*!
94   Sets curve's horizontal units
95 */
96 void Plot2d_Curve::setHorUnits( const QString& units )
97 {
98   myHorUnits = units;
99 }
100 /*!
101   Gets curve's horizontal units
102 */
103 QString Plot2d_Curve::getHorUnits() const
104 {
105   return myHorUnits;
106 }
107 /*!
108   Sets curve's vertical units
109 */
110 void Plot2d_Curve::setVerUnits( const QString& units )
111 {
112   myVerUnits = units;
113 }
114 /*!
115   Gets curve's vertical units
116 */
117 QString Plot2d_Curve::getVerUnits() const
118 {
119   return myVerUnits;
120 }
121 /*!
122   Sets curve's data. Makes shallow copy of data.
123 */
124 void Plot2d_Curve::setData( const double* hData, const double* vData, long size )
125 {
126   myHorData.assign( hData, size );
127   myVerData.assign( vData, size );
128 }
129 /*!
130   Gets curve's data : abscissas of points
131 */
132 double* Plot2d_Curve::horData() const
133 {
134   return myHorData.data();
135 }
136 /*!
137   Gets curve's data : ordinates of points
138 */
139 double* Plot2d_Curve::verData() const
140 {
141   return myVerData.data();
142 }
143 /*!
144   Gets curve's data : number of points
145 */
146 long Plot2d_Curve::nbPoints() const
147 {
148   return myHorData.size();
149 }
150 /*!
151   Returns true if curve has no data
152 */
153 bool Plot2d_Curve::isEmpty() const
154 {
155   return ( myHorData.isEmpty() || myVerData.isEmpty() );
156 }
157 /*!
158   Sets curve's AutoAssign flag - in this case attributes will be set automatically
159 */
160 void Plot2d_Curve::setAutoAssign( bool on )
161 {
162   myAutoAssign = on;
163 }
164 /*!
165   Gets curve's AutoAssign flag state
166 */
167 bool Plot2d_Curve::isAutoAssign() const
168 {
169   return myAutoAssign;
170 }
171 /*!
172   Sets curve's color ( and resets AutoAssign flag )
173 */
174 void Plot2d_Curve::setColor( const QColor color )
175 {
176   myColor = color;
177   myAutoAssign = false;
178 }
179 /*!
180   Gets curve's color
181 */
182 QColor Plot2d_Curve::getColor() const
183 {
184   return myColor;
185 }
186 /*!
187   Sets curve's marker ( and resets AutoAssign flag )
188 */
189 void Plot2d_Curve::setMarker( MarkerType marker )
190 {
191   myMarker = marker;
192   myAutoAssign = false;
193 }
194 /*!
195   Gets curve's marker
196 */
197 Plot2d_Curve::MarkerType Plot2d_Curve::getMarker() const
198 {
199   return myMarker;
200 }
201 /*!
202   Sets curve's line type and width ( and resets AutoAssign flag )
203   NOTE : A line width of 0 will produce a 1 pixel wide line using a fast algorithm for diagonals. 
204          A line width of 1 will also produce a 1 pixel wide line, but uses a slower more accurate algorithm for diagonals. 
205          For horizontal and vertical lines a line width of 0 is the same as a line width of 1.
206 */
207 void Plot2d_Curve::setLine( LineType line, const int lineWidth )
208 {
209   myLine = line;
210   myLineWidth = lineWidth;
211   if ( myLineWidth < 0 ) myLineWidth = 0;
212   myAutoAssign = false;
213 }
214 /*!
215   Gets curve's line type
216 */
217 Plot2d_Curve::LineType Plot2d_Curve::getLine() const
218 {
219   return myLine;
220 }
221 /*!
222   Gets curve's line width
223 */
224 int Plot2d_Curve::getLineWidth() const
225 {
226   return myLineWidth;
227 }