Salome HOME
f2c5f7e58a358a3a7db31508ad9f0f3bc55116b3
[modules/geom.git] / src / GEOMGUI / GEOMGUI_DimensionProperty.h
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File   : GEOMGUI_DimensionProperty.h
24 // Author : Anton POLETAEV, Open CASCADE S.A.S.
25 //
26
27 #ifndef GEOMGUI_DIMENSIONPROPERTY_H
28 #define GEOMGUI_DIMENSIONPROPERTY_H
29
30 // OCCT includes
31 #include <AIS_DiameterDimension.hxx>
32 #include <AIS_LengthDimension.hxx>
33 #include <AIS_AngleDimension.hxx>
34 #include <gp_Ax3.hxx>
35 #include <QVariant>
36 #include <QVector>
37 #include <QSharedPointer>
38
39 #include <string>
40 #include <vector>
41 #include <list>
42
43 class SalomeApp_Study;
44
45 /*!
46  * \brief Utility class to unpack/pack dimension presentations as object property of study.
47  *
48  * Dimension presentations are store in relative coordinate system (LCS).
49  * To ensure that dimension is bound to the equal shape irrespectively of its location
50  * transformation.
51  *
52  * The record is a list of qvariant, containing packed dimension properties and its attributes:
53  * (name);(is_visible);(dimension type);(dimension property list);
54  * 
55  * The following packing scheme is used to store dimension data:
56  * Length: (plane)[0-3] (flyout)[4] (text flags)[5-6] (p1)[7-9] (pnt2)[10-12]
57  * Diam:   (plane)[0-3] (flyout)[4] (text flags)[5-6] (circle loc, xdir, ydir, rad)[7-16]
58  * Angle:               (flyout)[0] (text flags)[1-2] (p1)[3-5] (p2)[6-8] (center)[9-11]
59  */
60 class Standard_EXPORT GEOMGUI_DimensionProperty
61 {
62 public:
63
64   /*!
65    * \brief Type of packed presentation.
66    */
67   enum DimensionType
68   {
69     DimensionType_Length,
70     DimensionType_Diameter,
71     DimensionType_Angle
72   };
73
74   /*!
75    * \brief Base class for pointer-optimized records storing.
76    */
77   struct Length;
78   struct Diameter;
79   struct Angle;
80   struct Record
81   {
82   public:
83     Record( const DimensionType theType ) 
84       : myType( theType )
85       {}
86
87     DimensionType Type() const
88     {
89       return myType;
90     }
91
92     Length*   AsLength()   { return static_cast<Length*>( this ); }
93     Diameter* AsDiameter() { return static_cast<Diameter*>( this ); }
94     Angle*    AsAngle()    { return static_cast<Angle*>( this ); }
95
96   private:
97     DimensionType myType;
98   };
99
100   /*!
101    * \brief Declaration of properties for length dimensions.
102    */
103   struct Standard_EXPORT Length : public Record
104   {
105     Length() :
106       Record( DimensionType_Length ),
107       FirstPoint( gp::Origin() ),
108       SecondPoint( gp::Origin() ),
109       Plane( gp::XOY() ),
110       Flyout( 0.0 ),
111       TextHPos( Prs3d_DTHP_Fit ),
112       TextVPos( Prs3d_DTVP_Center )
113       {}
114
115     Length( const Length& theOther ) :
116       Record( DimensionType_Length ),
117       FirstPoint( theOther.FirstPoint ),
118       SecondPoint( theOther.SecondPoint ),
119       Plane( theOther.Plane ),
120       Flyout( theOther.Flyout ),
121       TextHPos( theOther.TextHPos ),
122       TextVPos( theOther.TextVPos )
123       {}
124
125     ~Length() {}
126
127     /*!
128      * \brief Inits property fields from the passed length object.
129      * \param theIO [in] the interactive presentation.
130      * \param theLCS [in] the local coordiante system of parent object.
131      */
132     void Init( const Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS );
133
134     /*!
135      * \brief Updates length object properties from the fields.
136      * \param theIO [in/out] the interactive presentation.
137      * \param theLCS [in] the local coordiante system of parent object.
138      */
139     void Update( Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS );
140
141     /*!
142      * \brief Overload comparsion.
143      */
144     bool operator == (const Length &theOther) const;
145     bool operator != (const Length &theOther) const { return !(operator == (theOther)); }
146
147     gp_Pnt FirstPoint;
148     gp_Pnt SecondPoint;
149     gp_Pln Plane;
150     double Flyout;
151     Prs3d_DimensionTextHorizontalPosition TextHPos;
152     Prs3d_DimensionTextVerticalPosition   TextVPos;
153   };
154
155   /*!
156    * \brief Declaration of properties for diameter dimensions.
157    */
158   struct Standard_EXPORT Diameter : public Record
159   {
160     Diameter() :
161       Record( DimensionType_Diameter ),
162       Plane( gp::XOY() ),
163       Flyout( 0.0 ),
164       TextHPos( Prs3d_DTHP_Fit ),
165       TextVPos( Prs3d_DTVP_Center )
166       {}
167
168      Diameter( const Diameter& theOther ) :
169        Record( DimensionType_Diameter ),
170        Circle( theOther.Circle ),
171        Plane( theOther.Plane ),
172        Flyout( theOther.Flyout ),
173        TextHPos( theOther.TextHPos ),
174        TextVPos( theOther.TextVPos )
175        {}
176
177     ~Diameter() {}
178
179     /*!
180      * \brief Inits property fields from the passed length object.
181      * \param theIO [in] the interactive presentation.
182      * \param theLCS [in] the local coordiante system of parent object.
183      */
184     void Init( const Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS );
185
186     /*!
187      * \brief Updates length object properties from the fields.
188      * \param theIO [in/out] the interactive presentation.
189      * \param theLCS [in] the local coordiante system of parent object.
190      */
191     void Update( Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS );
192
193     /*!
194      * \brief Overload comparsion.
195      */
196     bool operator == (const Diameter &theOther) const;
197     bool operator != (const Diameter &theOther) const { return !(operator == (theOther)); }
198
199     gp_Circ Circle;
200     gp_Pln  Plane;
201     double Flyout;
202     Prs3d_DimensionTextHorizontalPosition TextHPos;
203     Prs3d_DimensionTextVerticalPosition   TextVPos;
204   };
205
206   /*!
207    * \brief Declaration of properties for angle dimensions.
208    */
209   struct Standard_EXPORT Angle : public Record
210   {
211     Angle() :
212       Record( DimensionType_Angle ),
213       FirstPoint( gp::Origin() ),
214       SecondPoint( gp::Origin() ),
215       CenterPoint( gp::Origin() ),
216       Flyout( 0.0 ),
217       TextHPos( Prs3d_DTHP_Fit ),
218       TextVPos( Prs3d_DTVP_Center )
219       {}
220
221     Angle( const Angle& theOther ) :
222       Record( DimensionType_Angle ),
223       FirstPoint( theOther.FirstPoint ),
224       SecondPoint( theOther.SecondPoint ),
225       CenterPoint( theOther.CenterPoint ),
226       Flyout( theOther.Flyout ),
227       TextHPos( theOther.TextHPos ),
228       TextVPos( theOther.TextVPos )
229       {}
230
231     ~Angle() {}
232
233     /*!
234      * \brief Inits property fields from the passed length object.
235      * \param theIO [in] the interactive presentation.
236      * \param theLCS [in] the local coordiante system of parent object.
237      */
238     void Init( const Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS );
239
240     /*!
241      * \brief Updates length object properties from the fields.
242      * \param theIO [in/out] the interactive presentation.
243      * \param theLCS [in] the local coordiante system of parent object.
244      */
245     void Update( Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS );
246
247     /*!
248      * \brief Overload comparsion.
249      */
250     bool operator == (const Angle &theOther) const;
251     bool operator != (const Angle &theOther) const { return !(operator == (theOther)); }
252
253     gp_Pnt FirstPoint;
254     gp_Pnt SecondPoint;
255     gp_Pnt CenterPoint;
256     double Flyout;
257     Prs3d_DimensionTextHorizontalPosition TextHPos;
258     Prs3d_DimensionTextVerticalPosition   TextVPos;
259   };
260
261   typedef QSharedPointer<Record> RecordPtr;
262
263 public:
264
265   /*!
266    * \brief Constructor. Inits empty property.
267    */
268   GEOMGUI_DimensionProperty();
269
270   /*!
271    * \brief Copy constructor.
272    */
273   GEOMGUI_DimensionProperty( const GEOMGUI_DimensionProperty& theOther );
274
275   /*!
276    * \brief Destructor.
277    */
278   ~GEOMGUI_DimensionProperty();
279
280   /*!
281    * \brief Overload QVariant cast operator.
282    */
283   operator QVariant();
284
285   /*!
286    * \brief Overload comparsion.
287    */
288   bool operator == (const GEOMGUI_DimensionProperty &theOther) const;
289
290 public:
291
292   /*!
293    * \brief Returns number of dimension records.
294    */
295   int GetNumber() const;
296
297   /*!
298    * \brief Adds new record for the passed interactive object. Convenience method.
299    * \param theIO [in] the interactive dimension to append as new record.
300    * \param theLCS [in] the local coordinate system of parent object.
301    */
302   void AddRecord( const Handle(AIS_Dimension)& theIO, const gp_Ax3& theLCS );
303
304   /*!
305    * \brief Adds new dimension record.
306    * \param theRecord [in] the record to add.
307    */
308   void AddRecord( const RecordPtr& theRecord );
309
310   /*!
311    * \brief Update dimension record data.
312    * \param theIndex [in] the index of the record.
313    * \param theIO [in] the interactive dimension to update properties.
314    * \param theLCS [in] the local coordinate system of parent object.
315    */
316   void SetRecord( const int theIndex,
317                   const Handle(AIS_Dimension)& theIO,
318                   const gp_Ax3& theLCS );
319
320   /*!
321    * \brief Update dimension record data.
322    * \param theIndex [in] the index of the dimension record.
323    * \param theRecord [in] the record to replace with.
324    */
325   void SetRecord( const int theIndex, const RecordPtr& theRecord );
326
327   /*!
328    * \brief Access record by index.
329    * \param theIndex [in] the index of the dimension record.
330    */
331   const RecordPtr& GetRecord( const int theIndex ) const;
332
333   /*!
334    * \brief Removes record by its index.
335    * \param theIndex [in] the index of dimension record.
336    */
337   void RemoveRecord( const int theIndex );
338
339   /*!
340    * \brief Clears property data.
341    */
342   void Clear();
343
344 public:
345
346   /*!
347    * \brief Returns visibility state of dimension record by its index.
348    *
349    * \param theIndex [in] the index of the dimension record.
350    */
351   bool IsVisible( const int theIndex ) const;
352
353   /*!
354    * \brief Changes visibility state of the dimension record.
355    *
356    * \param theIndex [in] the index of the dimension record.
357    * \param theIsVisible [in] the new visibility state.
358    */
359   void SetVisible( const int theIndex, const bool theIsVisible );
360
361   /*!
362    * \brief Returns name of dimension record by its index.
363    *
364    * \param theIndex [in] the index of the dimension record.
365    */
366   QString GetName( const int theIndex ) const;
367
368   /*!
369    * \brief Changes name of dimension record.
370    *
371    * \param theIndex [in] the index of the dimension record.
372    * \param theName [in] the new name.
373    */
374   void SetName( const int theIndex, const QString& theName );
375
376   /*!
377    * \brief Returns dimension type.
378    */
379   int GetType( const int theIndex ) const;
380
381 public:
382
383   /*!
384    * \brief Loads properties data from attribute "AttributeTableOfReal".
385    * \param theStudy [in] the study.
386    * \param theEntry [in] the entry of GEOM object to operate with.
387    */
388   void LoadFromAttribute( SalomeApp_Study* theStudy, const std::string& theEntry );
389
390   /*!
391    * \brief Saves properties data to attribute "AttributeTableOfReal".
392    * \param theStudy [in] the study.
393    * \param theEntry [in] the entry of GEOM object to operate with.
394    */
395   void SaveToAttribute( SalomeApp_Study* theStudy, const std::string& theEntry );
396
397 private:
398
399   /*!
400    * \brief Determines dimension type code.
401    */
402   int TypeFromIO( const Handle(AIS_Dimension)& theIO ) const;
403
404 private:
405
406   typedef QVector<bool>      VectorOfVisibility;
407   typedef QVector<QString>   VectorOfNames;
408   typedef QVector<RecordPtr> VectorOfRecords;
409
410 private:
411
412   VectorOfVisibility         myVisibility;
413   VectorOfNames              myNames;
414   VectorOfRecords            myRecords;
415 };
416
417 Q_DECLARE_METATYPE(GEOMGUI_DimensionProperty);
418
419 #endif