Salome HOME
Copyright update 2022
[modules/geom.git] / src / GEOMGUI / GEOMGUI_DimensionProperty.h
1 // Copyright (C) 2007-2022  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, or (at your option) any later version.
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 #include <Basics_OCCTVersion.hxx>
31
32 // OCCT includes
33 #include <AIS_Dimension.hxx>
34 #include <AIS_DiameterDimension.hxx>
35 #if OCC_VERSION_LARGE >= 0x070400ff
36 #include <PrsDim_LengthDimension.hxx>
37 #else
38 #include <AIS_LengthDimension.hxx>
39 #endif
40 #include <AIS_AngleDimension.hxx>
41 #include <gp_Ax3.hxx>
42 #include <QVariant>
43 #include <QVector>
44 #include <QSharedPointer>
45
46 #include <string>
47 #include <vector>
48 #include <list>
49
50 class SalomeApp_Study;
51
52 class GEOMGUI_DimensionProperty;
53 typedef QSharedPointer<GEOMGUI_DimensionProperty> DimensionPropertyPtr;
54
55 /*!
56  * \brief Utility class to unpack/pack dimension presentations as object property of study.
57  *
58  * Dimension presentations are store in relative coordinate system (LCS).
59  * To ensure that dimension is bound to the equal shape irrespectively of its location
60  * transformation.
61  *
62  * The record is a list of qvariant, containing packed dimension properties and its attributes:
63  * (name);(is_visible);(dimension type);(dimension property list);
64  * 
65  * The following packing scheme is used to store dimension data:
66  * Length: (plane)[0-3] (flyout)[4] (text flags)[5-6] (arrow flag)[7] (p1)[8-10] (pnt2)[11-13]
67  * Diam:   (plane)[0-3] (flyout)[4] (text flags)[5-6] (arrow flag)[7] (circle loc, xdir, ydir, rad)[8-17]
68  * Angle:               (flyout)[0] (text flags)[1-2] (arrow flag)[3] (p1)[4-6] (p2)[7-9] (center)[10-12]
69  */
70 class Standard_EXPORT GEOMGUI_DimensionProperty
71 {
72 public:
73
74   /*!
75    * \brief Type of packed presentation.
76    */
77   enum DimensionType
78   {
79     DimensionType_Length,
80     DimensionType_Diameter,
81     DimensionType_Angle
82   };
83
84   /*!
85    * \brief Base class for pointer-optimized records storing.
86    */
87   struct Length;
88   struct Diameter;
89   struct Angle;
90   struct Record
91   {
92   public:
93     Record( const DimensionType theType ) 
94       : myType( theType )
95       {}
96
97     DimensionType Type() const
98     {
99       return myType;
100     }
101
102     Length*   AsLength()   { return static_cast<Length*>( this ); }
103     Diameter* AsDiameter() { return static_cast<Diameter*>( this ); }
104     Angle*    AsAngle()    { return static_cast<Angle*>( this ); }
105
106     virtual void ToValues(std::vector<double>& theValues) const = 0;
107     virtual void FromValues(int& theIt, const std::vector<double>& theValues) = 0;
108
109   private:
110     DimensionType myType;
111   };
112
113   /*!
114    * \brief Declaration of properties for length dimensions.
115    */
116   struct Standard_EXPORT Length : public Record
117   {
118     Length() :
119       Record( DimensionType_Length ),
120       FirstPoint( gp::Origin() ),
121       SecondPoint( gp::Origin() ),
122       Plane( gp::XOY() ),
123       Flyout( 0.0 ),
124       TextHPos( Prs3d_DTHP_Fit ),
125       TextVPos( Prs3d_DTVP_Center ),
126       ArrowPos( Prs3d_DAO_Fit )
127       {}
128
129     Length( const Length& theOther ) :
130       Record( DimensionType_Length ),
131       FirstPoint( theOther.FirstPoint ),
132       SecondPoint( theOther.SecondPoint ),
133       Plane( theOther.Plane ),
134       Flyout( theOther.Flyout ),
135       TextHPos( theOther.TextHPos ),
136       TextVPos( theOther.TextVPos ),
137       ArrowPos( theOther.ArrowPos )
138       {}
139
140     ~Length() {}
141
142     /*!
143      * \brief Inits property fields from the passed length object.
144      * \param theIO [in] the interactive presentation.
145      * \param theLCS [in] the local coordinate system of parent object.
146      */
147 #if OCC_VERSION_LARGE >= 0x070400ff
148     void Init( const Handle(PrsDim_LengthDimension)& theIO, const gp_Ax3& theLCS );
149 #else
150     void Init( const Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS );
151 #endif
152
153     /*!
154      * \brief Updates length object properties from the fields.
155      * \param theIO [in/out] the interactive presentation.
156      * \param theLCS [in] the local coordinate system of parent object.
157      */
158 #if OCC_VERSION_LARGE >= 0x070400ff
159     void Update( Handle(PrsDim_LengthDimension)& theIO, const gp_Ax3& theLCS );
160 #else
161     void Update( Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS );
162 #endif
163
164     /*!
165      * \brief Packs properties to array of doubles.
166      * \param theValues [out] the values vector to populate.
167      */
168     void ToValues(std::vector<double>& theValues) const;
169
170     /*!
171      * \brief Unpacks properties from array of doubles.
172      * \param theIt [in/out] the array index iterator.
173      * \param theValues [in] the vector of values.
174      */
175     void FromValues(int& theIt, const std::vector<double>& theValues);
176
177     /*!
178      * \brief Overload comparison.
179      */
180     bool operator == (const Length &theOther) const;
181     bool operator != (const Length &theOther) const { return !(operator == (theOther)); }
182
183     gp_Pnt FirstPoint;
184     gp_Pnt SecondPoint;
185     gp_Pln Plane;
186     double Flyout;
187     Prs3d_DimensionTextHorizontalPosition TextHPos;
188     Prs3d_DimensionTextVerticalPosition   TextVPos;
189     Prs3d_DimensionArrowOrientation       ArrowPos;
190   };
191
192   /*!
193    * \brief Declaration of properties for diameter dimensions.
194    */
195   struct Standard_EXPORT Diameter : public Record
196   {
197     Diameter() :
198       Record( DimensionType_Diameter ),
199       Plane( gp::XOY() ),
200       Flyout( 0.0 ),
201       TextHPos( Prs3d_DTHP_Fit ),
202       TextVPos( Prs3d_DTVP_Center ),
203       ArrowPos( Prs3d_DAO_Fit )
204       {}
205
206      Diameter( const Diameter& theOther ) :
207        Record( DimensionType_Diameter ),
208        Circle( theOther.Circle ),
209        Plane( theOther.Plane ),
210        Flyout( theOther.Flyout ),
211        TextHPos( theOther.TextHPos ),
212        TextVPos( theOther.TextVPos ),
213        ArrowPos( theOther.ArrowPos )
214        {}
215
216     ~Diameter() {}
217
218     /*!
219      * \brief Inits property fields from the passed length object.
220      * \param theIO [in] the interactive presentation.
221      * \param theLCS [in] the local coordinate system of parent object.
222      */
223     void Init( const Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS );
224
225     /*!
226      * \brief Updates length object properties from the fields.
227      * \param theIO [in/out] the interactive presentation.
228      * \param theLCS [in] the local coordinate system of parent object.
229      */
230     void Update( Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS );
231
232     /*!
233      * \brief Packs properties to array of doubles.
234      * \param theValues [out] the values vector to populate.
235      */
236     void ToValues(std::vector<double>& theValues) const;
237
238     /*!
239      * \brief Unpacks properties from array of doubles.
240      * \param theIt [in/out] the array index iterator.
241      * \param theValues [in] the vector of values.
242      */
243     void FromValues(int& theIt, const std::vector<double>& theValues);
244
245     /*!
246      * \brief Overload comparison.
247      */
248     bool operator == (const Diameter &theOther) const;
249     bool operator != (const Diameter &theOther) const { return !(operator == (theOther)); }
250
251     gp_Circ Circle;
252     gp_Pln  Plane;
253     double Flyout;
254     Prs3d_DimensionTextHorizontalPosition TextHPos;
255     Prs3d_DimensionTextVerticalPosition   TextVPos;
256     Prs3d_DimensionArrowOrientation       ArrowPos;
257   };
258
259   /*!
260    * \brief Declaration of properties for angle dimensions.
261    */
262   struct Standard_EXPORT Angle : public Record
263   {
264     Angle() :
265       Record( DimensionType_Angle ),
266       FirstPoint( gp::Origin() ),
267       SecondPoint( gp::Origin() ),
268       CenterPoint( gp::Origin() ),
269       Flyout( 0.0 ),
270       TextHPos( Prs3d_DTHP_Fit ),
271       TextVPos( Prs3d_DTVP_Center ),
272       ArrowPos( Prs3d_DAO_Fit )
273       {}
274
275     Angle( const Angle& theOther ) :
276       Record( DimensionType_Angle ),
277       FirstPoint( theOther.FirstPoint ),
278       SecondPoint( theOther.SecondPoint ),
279       CenterPoint( theOther.CenterPoint ),
280       Flyout( theOther.Flyout ),
281       TextHPos( theOther.TextHPos ),
282       TextVPos( theOther.TextVPos ),
283       ArrowPos( theOther.ArrowPos )
284       {}
285
286     ~Angle() {}
287
288     /*!
289      * \brief Inits property fields from the passed length object.
290      * \param theIO [in] the interactive presentation.
291      * \param theLCS [in] the local coordinate system of parent object.
292      */
293     void Init( const Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS );
294
295     /*!
296      * \brief Updates length object properties from the fields.
297      * \param theIO [in/out] the interactive presentation.
298      * \param theLCS [in] the local coordinate system of parent object.
299      */
300     void Update( Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS );
301
302     /*!
303      * \brief Packs properties to array of doubles.
304      * \param theValues [out] the values vector to populate.
305      */
306     void ToValues(std::vector<double>& theValues) const;
307
308     /*!
309      * \brief Unpacks properties from array of doubles.
310      * \param theIt [in/out] the array index iterator.
311      * \param theValues [in] the vector of values.
312      */
313     void FromValues(int& theIt, const std::vector<double>& theValues);
314
315     /*!
316      * \brief Overload comparison.
317      */
318     bool operator == (const Angle &theOther) const;
319     bool operator != (const Angle &theOther) const { return !(operator == (theOther)); }
320
321     gp_Pnt FirstPoint;
322     gp_Pnt SecondPoint;
323     gp_Pnt CenterPoint;
324     double Flyout;
325     Prs3d_DimensionTextHorizontalPosition TextHPos;
326     Prs3d_DimensionTextVerticalPosition   TextVPos;
327     Prs3d_DimensionArrowOrientation       ArrowPos;
328   };
329
330   typedef QSharedPointer<Record> RecordPtr;
331
332 public:
333
334   /*!
335    * \brief Constructor. Inits empty property.
336    */
337   GEOMGUI_DimensionProperty();
338
339   /*!
340    * \brief Copy constructor.
341    */
342   GEOMGUI_DimensionProperty( const GEOMGUI_DimensionProperty& theOther );
343
344    /*!
345    * \brief Constructor. Inits property from attribute.
346    */
347   GEOMGUI_DimensionProperty( const std::string& theEntry );
348
349    /*!
350    * \brief Constructor. Inits property from formatted QString.
351    */
352   GEOMGUI_DimensionProperty( const QString& theProperty );
353
354   /*!
355    * \brief Destructor.
356    */
357   ~GEOMGUI_DimensionProperty();
358
359   /*!
360    * \brief Overload QVariant cast operator.
361    */
362   operator QVariant() const;
363
364   /*!
365    * \brief Overload QString cast operator.
366    */
367   operator QString() const;
368
369   /*!
370    * \brief Overload comparison.
371    */
372   bool operator == (const GEOMGUI_DimensionProperty &theOther) const;
373
374   /*!
375    * \brief Overload comparison.
376    */
377   bool operator != (const GEOMGUI_DimensionProperty &theOther) const
378   {
379     return !(operator == (theOther));
380   }
381
382 public:
383
384   /*!
385    * \brief Returns number of dimension records.
386    */
387   int GetNumber() const;
388
389   /*!
390    * \brief Adds new record for the passed interactive object. Convenience method.
391    * \param theIO [in] the interactive dimension to append as new record.
392    * \param theLCS [in] the local coordinate system of parent object.
393    */
394   void AddRecord( const Handle(AIS_Dimension)& theIO, const gp_Ax3& theLCS );
395
396   /*!
397    * \brief Adds new dimension record.
398    * \param theRecord [in] the record to add.
399    */
400   void AddRecord( const RecordPtr& theRecord );
401
402   /*!
403    * \brief Update dimension record data.
404    * \param theIndex [in] the index of the record.
405    * \param theIO [in] the interactive dimension to update properties.
406    * \param theLCS [in] the local coordinate system of parent object.
407    */
408   void SetRecord( const int theIndex,
409                   const Handle(AIS_Dimension)& theIO,
410                   const gp_Ax3& theLCS );
411
412   /*!
413    * \brief Update dimension record data.
414    * \param theIndex [in] the index of the dimension record.
415    * \param theRecord [in] the record to replace with.
416    */
417   void SetRecord( const int theIndex, const RecordPtr& theRecord );
418
419   /*!
420    * \brief Access record by index.
421    * \param theIndex [in] the index of the dimension record.
422    */
423   const RecordPtr& GetRecord( const int theIndex ) const;
424
425   /*!
426    * \brief Removes record by its index.
427    * \param theIndex [in] the index of dimension record.
428    */
429   void RemoveRecord( const int theIndex );
430
431   /*!
432    * \brief Clears property data.
433    */
434   void Clear();
435
436 public:
437
438   /*!
439    * \brief Returns visibility state of dimension record by its index.
440    *
441    * \param theIndex [in] the index of the dimension record.
442    */
443   bool IsVisible( const int theIndex ) const;
444
445   /*!
446    * \brief Changes visibility state of the dimension record.
447    *
448    * \param theIndex [in] the index of the dimension record.
449    * \param theIsVisible [in] the new visibility state.
450    */
451   void SetVisible( const int theIndex, const bool theIsVisible );
452
453   /*!
454    * \brief Returns name of dimension record by its index.
455    *
456    * \param theIndex [in] the index of the dimension record.
457    */
458   QString GetName( const int theIndex ) const;
459
460   /*!
461    * \brief Changes name of dimension record.
462    *
463    * \param theIndex [in] the index of the dimension record.
464    * \param theName [in] the new name.
465    */
466   void SetName( const int theIndex, const QString& theName );
467
468   /*!
469    * \brief Returns dimension type.
470    */
471   int GetType( const int theIndex ) const;
472
473 public:
474
475   /*!
476    * \brief Loads properties data from attribute "AttributeTableOfReal".
477    * \param theEntry [in] the entry of GEOM object to operate with.
478    */
479   void LoadFromAttribute( const std::string& theEntry );
480
481   /*!
482    * \brief Saves properties data to attribute "AttributeTableOfReal".
483    * \param theEntry [in] the entry of GEOM object to operate with.
484    */
485   void SaveToAttribute( const std::string& theEntry );
486
487 private:
488
489   /*!
490    * \brief Determines dimension type code.
491    */
492   int TypeFromIO( const Handle(AIS_Dimension)& theIO ) const;
493
494 private:
495
496   typedef QVector<bool>      VectorOfVisibility;
497   typedef QVector<QString>   VectorOfNames;
498   typedef QVector<RecordPtr> VectorOfRecords;
499
500 private:
501
502   VectorOfVisibility         myVisibility;
503   VectorOfNames              myNames;
504   VectorOfRecords            myRecords;
505 };
506
507 Q_DECLARE_METATYPE(GEOMGUI_DimensionProperty)
508
509 #endif