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