1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : GEOMGUI_DimensionProperty.h
24 // Author : Anton POLETAEV, Open CASCADE S.A.S.
27 #ifndef GEOMGUI_DIMENSIONPROPERTY_H
28 #define GEOMGUI_DIMENSIONPROPERTY_H
31 #include <AIS_DiameterDimension.hxx>
32 #include <AIS_LengthDimension.hxx>
33 #include <AIS_AngleDimension.hxx>
37 #include <QSharedPointer>
43 class SalomeApp_Study;
46 * \brief Utility class to unpack/pack dimension presentations as object property of study.
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
52 * The record is a list of qvariant, containing packed dimension properties and its attributes:
53 * (name);(is_visible);(dimension type);(dimension property list);
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]
60 class Standard_EXPORT GEOMGUI_DimensionProperty
65 * \brief Type of packed presentation.
70 DimensionType_Diameter,
75 * \brief Base class for pointer-optimized records storing.
83 Record( const DimensionType theType )
87 DimensionType Type() const
92 Length* AsLength() { return static_cast<Length*>( this ); }
93 Diameter* AsDiameter() { return static_cast<Diameter*>( this ); }
94 Angle* AsAngle() { return static_cast<Angle*>( this ); }
96 virtual void ToValues(std::vector<double>& theValues) const = 0;
97 virtual void FromValues(int& theIt, const std::vector<double>& theValues) = 0;
100 DimensionType myType;
104 * \brief Declaration of properties for length dimensions.
106 struct Standard_EXPORT Length : public Record
109 Record( DimensionType_Length ),
110 FirstPoint( gp::Origin() ),
111 SecondPoint( gp::Origin() ),
114 TextHPos( Prs3d_DTHP_Fit ),
115 TextVPos( Prs3d_DTVP_Center ),
116 ArrowPos( Prs3d_DAO_Fit )
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 )
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.
137 void Init( const Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS );
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.
144 void Update( Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS );
147 * \brief Packs properties to array of doubles.
148 * \param theValues [out] the values vector to populate.
150 void ToValues(std::vector<double>& theValues) const;
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.
157 void FromValues(int& theIt, const std::vector<double>& theValues);
160 * \brief Overload comparsion.
162 bool operator == (const Length &theOther) const;
163 bool operator != (const Length &theOther) const { return !(operator == (theOther)); }
169 Prs3d_DimensionTextHorizontalPosition TextHPos;
170 Prs3d_DimensionTextVerticalPosition TextVPos;
171 Prs3d_DimensionArrowOrientation ArrowPos;
175 * \brief Declaration of properties for diameter dimensions.
177 struct Standard_EXPORT Diameter : public Record
180 Record( DimensionType_Diameter ),
183 TextHPos( Prs3d_DTHP_Fit ),
184 TextVPos( Prs3d_DTVP_Center ),
185 ArrowPos( Prs3d_DAO_Fit )
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 )
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.
205 void Init( const Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS );
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.
212 void Update( Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS );
215 * \brief Packs properties to array of doubles.
216 * \param theValues [out] the values vector to populate.
218 void ToValues(std::vector<double>& theValues) const;
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.
225 void FromValues(int& theIt, const std::vector<double>& theValues);
228 * \brief Overload comparsion.
230 bool operator == (const Diameter &theOther) const;
231 bool operator != (const Diameter &theOther) const { return !(operator == (theOther)); }
236 Prs3d_DimensionTextHorizontalPosition TextHPos;
237 Prs3d_DimensionTextVerticalPosition TextVPos;
238 Prs3d_DimensionArrowOrientation ArrowPos;
242 * \brief Declaration of properties for angle dimensions.
244 struct Standard_EXPORT Angle : public Record
247 Record( DimensionType_Angle ),
248 FirstPoint( gp::Origin() ),
249 SecondPoint( gp::Origin() ),
250 CenterPoint( gp::Origin() ),
252 TextHPos( Prs3d_DTHP_Fit ),
253 TextVPos( Prs3d_DTVP_Center ),
254 ArrowPos( Prs3d_DAO_Fit )
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 )
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.
275 void Init( const Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS );
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.
282 void Update( Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS );
285 * \brief Packs properties to array of doubles.
286 * \param theValues [out] the values vector to populate.
288 void ToValues(std::vector<double>& theValues) const;
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.
295 void FromValues(int& theIt, const std::vector<double>& theValues);
298 * \brief Overload comparsion.
300 bool operator == (const Angle &theOther) const;
301 bool operator != (const Angle &theOther) const { return !(operator == (theOther)); }
307 Prs3d_DimensionTextHorizontalPosition TextHPos;
308 Prs3d_DimensionTextVerticalPosition TextVPos;
309 Prs3d_DimensionArrowOrientation ArrowPos;
312 typedef QSharedPointer<Record> RecordPtr;
317 * \brief Constructor. Inits empty property.
319 GEOMGUI_DimensionProperty();
322 * \brief Copy constructor.
324 GEOMGUI_DimensionProperty( const GEOMGUI_DimensionProperty& theOther );
327 * \brief Constructor. Inits property from attribute.
329 GEOMGUI_DimensionProperty( SalomeApp_Study* theStudy, const std::string& theEntry );
332 * \brief Constructor. Inits property from formatted QString.
334 GEOMGUI_DimensionProperty( const QString& theProperty );
339 ~GEOMGUI_DimensionProperty();
342 * \brief Overload QVariant cast operator.
344 operator QVariant() const;
347 * \brief Overload QString cast operator.
349 operator QString() const;
352 * \brief Overload comparsion.
354 bool operator == (const GEOMGUI_DimensionProperty &theOther) const;
357 * \brief Overload comparsion.
359 bool operator != (const GEOMGUI_DimensionProperty &theOther) const
361 return !(operator == (theOther));
367 * \brief Returns number of dimension records.
369 int GetNumber() const;
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.
376 void AddRecord( const Handle(AIS_Dimension)& theIO, const gp_Ax3& theLCS );
379 * \brief Adds new dimension record.
380 * \param theRecord [in] the record to add.
382 void AddRecord( const RecordPtr& theRecord );
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.
390 void SetRecord( const int theIndex,
391 const Handle(AIS_Dimension)& theIO,
392 const gp_Ax3& theLCS );
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.
399 void SetRecord( const int theIndex, const RecordPtr& theRecord );
402 * \brief Access record by index.
403 * \param theIndex [in] the index of the dimension record.
405 const RecordPtr& GetRecord( const int theIndex ) const;
408 * \brief Removes record by its index.
409 * \param theIndex [in] the index of dimension record.
411 void RemoveRecord( const int theIndex );
414 * \brief Clears property data.
421 * \brief Returns visibility state of dimension record by its index.
423 * \param theIndex [in] the index of the dimension record.
425 bool IsVisible( const int theIndex ) const;
428 * \brief Changes visibility state of the dimension record.
430 * \param theIndex [in] the index of the dimension record.
431 * \param theIsVisible [in] the new visibility state.
433 void SetVisible( const int theIndex, const bool theIsVisible );
436 * \brief Returns name of dimension record by its index.
438 * \param theIndex [in] the index of the dimension record.
440 QString GetName( const int theIndex ) const;
443 * \brief Changes name of dimension record.
445 * \param theIndex [in] the index of the dimension record.
446 * \param theName [in] the new name.
448 void SetName( const int theIndex, const QString& theName );
451 * \brief Returns dimension type.
453 int GetType( const int theIndex ) const;
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.
462 void LoadFromAttribute( SalomeApp_Study* theStudy, const std::string& theEntry );
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.
469 void SaveToAttribute( SalomeApp_Study* theStudy, const std::string& theEntry );
474 * \brief Determines dimension type code.
476 int TypeFromIO( const Handle(AIS_Dimension)& theIO ) const;
480 typedef QVector<bool> VectorOfVisibility;
481 typedef QVector<QString> VectorOfNames;
482 typedef QVector<RecordPtr> VectorOfRecords;
486 VectorOfVisibility myVisibility;
487 VectorOfNames myNames;
488 VectorOfRecords myRecords;
491 Q_DECLARE_METATYPE(GEOMGUI_DimensionProperty);