Salome HOME
56142f26468cb1407f7b809f5656d27e644d4aaa
[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] (arrow flag)[7] (p1)[8-10] (pnt2)[11-13]
57  * Diam:   (plane)[0-3] (flyout)[4] (text flags)[5-6] (arrow flag)[7] (circle loc, xdir, ydir, rad)[8-17]
58  * Angle:               (flyout)[0] (text flags)[1-2] (arrow flag)[3] (p1)[4-6] (p2)[7-9] (center)[10-12]
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     virtual void ToValues(std::vector<double>& theValues) const = 0;
97     virtual void FromValues(int& theIt, const std::vector<double>& theValues) = 0;
98
99   private:
100     DimensionType myType;
101   };
102
103   /*!
104    * \brief Declaration of properties for length dimensions.
105    */
106   struct Standard_EXPORT Length : public Record
107   {
108     Length() :
109       Record( DimensionType_Length ),
110       FirstPoint( gp::Origin() ),
111       SecondPoint( gp::Origin() ),
112       Plane( gp::XOY() ),
113       Flyout( 0.0 ),
114       TextHPos( Prs3d_DTHP_Fit ),
115       TextVPos( Prs3d_DTVP_Center ),
116       ArrowPos( Prs3d_DAO_Fit )
117       {}
118
119     Length( const Length& theOther ) :
120       Record( DimensionType_Length ),
121       FirstPoint( theOther.FirstPoint ),
122       SecondPoint( theOther.SecondPoint ),
123       Plane( theOther.Plane ),
124       Flyout( theOther.Flyout ),
125       TextHPos( theOther.TextHPos ),
126       TextVPos( theOther.TextVPos ),
127       ArrowPos( theOther.ArrowPos )
128       {}
129
130     ~Length() {}
131
132     /*!
133      * \brief Inits property fields from the passed length object.
134      * \param theIO [in] the interactive presentation.
135      * \param theLCS [in] the local coordiante system of parent object.
136      */
137     void Init( const Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS );
138
139     /*!
140      * \brief Updates length object properties from the fields.
141      * \param theIO [in/out] the interactive presentation.
142      * \param theLCS [in] the local coordiante system of parent object.
143      */
144     void Update( Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS );
145
146     /*!
147      * \brief Packs properties to array of doubles.
148      * \param theValues [out] the values vector to populate.
149      */
150     void ToValues(std::vector<double>& theValues) const;
151
152     /*!
153      * \brief Unpacks properties from array of doubles.
154      * \param theIt [in/out] the array index iterator.
155      * \param theValues [in] the vector of values.
156      */
157     void FromValues(int& theIt, const std::vector<double>& theValues);
158
159     /*!
160      * \brief Overload comparsion.
161      */
162     bool operator == (const Length &theOther) const;
163     bool operator != (const Length &theOther) const { return !(operator == (theOther)); }
164
165     gp_Pnt FirstPoint;
166     gp_Pnt SecondPoint;
167     gp_Pln Plane;
168     double Flyout;
169     Prs3d_DimensionTextHorizontalPosition TextHPos;
170     Prs3d_DimensionTextVerticalPosition   TextVPos;
171     Prs3d_DimensionArrowOrientation       ArrowPos;
172   };
173
174   /*!
175    * \brief Declaration of properties for diameter dimensions.
176    */
177   struct Standard_EXPORT Diameter : public Record
178   {
179     Diameter() :
180       Record( DimensionType_Diameter ),
181       Plane( gp::XOY() ),
182       Flyout( 0.0 ),
183       TextHPos( Prs3d_DTHP_Fit ),
184       TextVPos( Prs3d_DTVP_Center ),
185       ArrowPos( Prs3d_DAO_Fit )
186       {}
187
188      Diameter( const Diameter& theOther ) :
189        Record( DimensionType_Diameter ),
190        Circle( theOther.Circle ),
191        Plane( theOther.Plane ),
192        Flyout( theOther.Flyout ),
193        TextHPos( theOther.TextHPos ),
194        TextVPos( theOther.TextVPos ),
195        ArrowPos( theOther.ArrowPos )
196        {}
197
198     ~Diameter() {}
199
200     /*!
201      * \brief Inits property fields from the passed length object.
202      * \param theIO [in] the interactive presentation.
203      * \param theLCS [in] the local coordiante system of parent object.
204      */
205     void Init( const Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS );
206
207     /*!
208      * \brief Updates length object properties from the fields.
209      * \param theIO [in/out] the interactive presentation.
210      * \param theLCS [in] the local coordiante system of parent object.
211      */
212     void Update( Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS );
213
214     /*!
215      * \brief Packs properties to array of doubles.
216      * \param theValues [out] the values vector to populate.
217      */
218     void ToValues(std::vector<double>& theValues) const;
219
220     /*!
221      * \brief Unpacks properties from array of doubles.
222      * \param theIt [in/out] the array index iterator.
223      * \param theValues [in] the vector of values.
224      */
225     void FromValues(int& theIt, const std::vector<double>& theValues);
226
227     /*!
228      * \brief Overload comparsion.
229      */
230     bool operator == (const Diameter &theOther) const;
231     bool operator != (const Diameter &theOther) const { return !(operator == (theOther)); }
232
233     gp_Circ Circle;
234     gp_Pln  Plane;
235     double Flyout;
236     Prs3d_DimensionTextHorizontalPosition TextHPos;
237     Prs3d_DimensionTextVerticalPosition   TextVPos;
238     Prs3d_DimensionArrowOrientation       ArrowPos;
239   };
240
241   /*!
242    * \brief Declaration of properties for angle dimensions.
243    */
244   struct Standard_EXPORT Angle : public Record
245   {
246     Angle() :
247       Record( DimensionType_Angle ),
248       FirstPoint( gp::Origin() ),
249       SecondPoint( gp::Origin() ),
250       CenterPoint( gp::Origin() ),
251       Flyout( 0.0 ),
252       TextHPos( Prs3d_DTHP_Fit ),
253       TextVPos( Prs3d_DTVP_Center ),
254       ArrowPos( Prs3d_DAO_Fit )
255       {}
256
257     Angle( const Angle& theOther ) :
258       Record( DimensionType_Angle ),
259       FirstPoint( theOther.FirstPoint ),
260       SecondPoint( theOther.SecondPoint ),
261       CenterPoint( theOther.CenterPoint ),
262       Flyout( theOther.Flyout ),
263       TextHPos( theOther.TextHPos ),
264       TextVPos( theOther.TextVPos ),
265       ArrowPos( theOther.ArrowPos )
266       {}
267
268     ~Angle() {}
269
270     /*!
271      * \brief Inits property fields from the passed length object.
272      * \param theIO [in] the interactive presentation.
273      * \param theLCS [in] the local coordiante system of parent object.
274      */
275     void Init( const Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS );
276
277     /*!
278      * \brief Updates length object properties from the fields.
279      * \param theIO [in/out] the interactive presentation.
280      * \param theLCS [in] the local coordiante system of parent object.
281      */
282     void Update( Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS );
283
284     /*!
285      * \brief Packs properties to array of doubles.
286      * \param theValues [out] the values vector to populate.
287      */
288     void ToValues(std::vector<double>& theValues) const;
289
290     /*!
291      * \brief Unpacks properties from array of doubles.
292      * \param theIt [in/out] the array index iterator.
293      * \param theValues [in] the vector of values.
294      */
295     void FromValues(int& theIt, const std::vector<double>& theValues);
296
297     /*!
298      * \brief Overload comparsion.
299      */
300     bool operator == (const Angle &theOther) const;
301     bool operator != (const Angle &theOther) const { return !(operator == (theOther)); }
302
303     gp_Pnt FirstPoint;
304     gp_Pnt SecondPoint;
305     gp_Pnt CenterPoint;
306     double Flyout;
307     Prs3d_DimensionTextHorizontalPosition TextHPos;
308     Prs3d_DimensionTextVerticalPosition   TextVPos;
309     Prs3d_DimensionArrowOrientation       ArrowPos;
310   };
311
312   typedef QSharedPointer<Record> RecordPtr;
313
314 public:
315
316   /*!
317    * \brief Constructor. Inits empty property.
318    */
319   GEOMGUI_DimensionProperty();
320
321   /*!
322    * \brief Copy constructor.
323    */
324   GEOMGUI_DimensionProperty( const GEOMGUI_DimensionProperty& theOther );
325
326    /*!
327    * \brief Constructor. Inits property from attribute.
328    */
329   GEOMGUI_DimensionProperty( SalomeApp_Study* theStudy, const std::string& theEntry );
330
331    /*!
332    * \brief Constructor. Inits property from formatted QString.
333    */
334   GEOMGUI_DimensionProperty( const QString& theProperty );
335
336   /*!
337    * \brief Destructor.
338    */
339   ~GEOMGUI_DimensionProperty();
340
341   /*!
342    * \brief Overload QVariant cast operator.
343    */
344   operator QVariant() const;
345
346   /*!
347    * \brief Overload QString cast operator.
348    */
349   operator QString() const;
350
351   /*!
352    * \brief Overload comparsion.
353    */
354   bool operator == (const GEOMGUI_DimensionProperty &theOther) const;
355
356   /*!
357    * \brief Overload comparsion.
358    */
359   bool operator != (const GEOMGUI_DimensionProperty &theOther) const
360   {
361     return !(operator == (theOther));
362   }
363
364 public:
365
366   /*!
367    * \brief Returns number of dimension records.
368    */
369   int GetNumber() const;
370
371   /*!
372    * \brief Adds new record for the passed interactive object. Convenience method.
373    * \param theIO [in] the interactive dimension to append as new record.
374    * \param theLCS [in] the local coordinate system of parent object.
375    */
376   void AddRecord( const Handle(AIS_Dimension)& theIO, const gp_Ax3& theLCS );
377
378   /*!
379    * \brief Adds new dimension record.
380    * \param theRecord [in] the record to add.
381    */
382   void AddRecord( const RecordPtr& theRecord );
383
384   /*!
385    * \brief Update dimension record data.
386    * \param theIndex [in] the index of the record.
387    * \param theIO [in] the interactive dimension to update properties.
388    * \param theLCS [in] the local coordinate system of parent object.
389    */
390   void SetRecord( const int theIndex,
391                   const Handle(AIS_Dimension)& theIO,
392                   const gp_Ax3& theLCS );
393
394   /*!
395    * \brief Update dimension record data.
396    * \param theIndex [in] the index of the dimension record.
397    * \param theRecord [in] the record to replace with.
398    */
399   void SetRecord( const int theIndex, const RecordPtr& theRecord );
400
401   /*!
402    * \brief Access record by index.
403    * \param theIndex [in] the index of the dimension record.
404    */
405   const RecordPtr& GetRecord( const int theIndex ) const;
406
407   /*!
408    * \brief Removes record by its index.
409    * \param theIndex [in] the index of dimension record.
410    */
411   void RemoveRecord( const int theIndex );
412
413   /*!
414    * \brief Clears property data.
415    */
416   void Clear();
417
418 public:
419
420   /*!
421    * \brief Returns visibility state of dimension record by its index.
422    *
423    * \param theIndex [in] the index of the dimension record.
424    */
425   bool IsVisible( const int theIndex ) const;
426
427   /*!
428    * \brief Changes visibility state of the dimension record.
429    *
430    * \param theIndex [in] the index of the dimension record.
431    * \param theIsVisible [in] the new visibility state.
432    */
433   void SetVisible( const int theIndex, const bool theIsVisible );
434
435   /*!
436    * \brief Returns name of dimension record by its index.
437    *
438    * \param theIndex [in] the index of the dimension record.
439    */
440   QString GetName( const int theIndex ) const;
441
442   /*!
443    * \brief Changes name of dimension record.
444    *
445    * \param theIndex [in] the index of the dimension record.
446    * \param theName [in] the new name.
447    */
448   void SetName( const int theIndex, const QString& theName );
449
450   /*!
451    * \brief Returns dimension type.
452    */
453   int GetType( const int theIndex ) const;
454
455 public:
456
457   /*!
458    * \brief Loads properties data from attribute "AttributeTableOfReal".
459    * \param theStudy [in] the study.
460    * \param theEntry [in] the entry of GEOM object to operate with.
461    */
462   void LoadFromAttribute( SalomeApp_Study* theStudy, const std::string& theEntry );
463
464   /*!
465    * \brief Saves properties data to attribute "AttributeTableOfReal".
466    * \param theStudy [in] the study.
467    * \param theEntry [in] the entry of GEOM object to operate with.
468    */
469   void SaveToAttribute( SalomeApp_Study* theStudy, const std::string& theEntry );
470
471 private:
472
473   /*!
474    * \brief Determines dimension type code.
475    */
476   int TypeFromIO( const Handle(AIS_Dimension)& theIO ) const;
477
478 private:
479
480   typedef QVector<bool>      VectorOfVisibility;
481   typedef QVector<QString>   VectorOfNames;
482   typedef QVector<RecordPtr> VectorOfRecords;
483
484 private:
485
486   VectorOfVisibility         myVisibility;
487   VectorOfNames              myNames;
488   VectorOfRecords            myRecords;
489 };
490
491 Q_DECLARE_METATYPE(GEOMGUI_DimensionProperty);
492
493 #endif