1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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;
45 class GEOMGUI_DimensionProperty;
46 typedef QSharedPointer<GEOMGUI_DimensionProperty> DimensionPropertyPtr;
49 * \brief Utility class to unpack/pack dimension presentations as object property of study.
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
55 * The record is a list of qvariant, containing packed dimension properties and its attributes:
56 * (name);(is_visible);(dimension type);(dimension property list);
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]
63 class Standard_EXPORT GEOMGUI_DimensionProperty
68 * \brief Type of packed presentation.
73 DimensionType_Diameter,
78 * \brief Base class for pointer-optimized records storing.
86 Record( const DimensionType theType )
90 DimensionType Type() const
95 Length* AsLength() { return static_cast<Length*>( this ); }
96 Diameter* AsDiameter() { return static_cast<Diameter*>( this ); }
97 Angle* AsAngle() { return static_cast<Angle*>( this ); }
99 virtual void ToValues(std::vector<double>& theValues) const = 0;
100 virtual void FromValues(int& theIt, const std::vector<double>& theValues) = 0;
103 DimensionType myType;
107 * \brief Declaration of properties for length dimensions.
109 struct Standard_EXPORT Length : public Record
112 Record( DimensionType_Length ),
113 FirstPoint( gp::Origin() ),
114 SecondPoint( gp::Origin() ),
117 TextHPos( Prs3d_DTHP_Fit ),
118 TextVPos( Prs3d_DTVP_Center ),
119 ArrowPos( Prs3d_DAO_Fit )
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 )
136 * \brief Inits property fields from the passed length object.
137 * \param theIO [in] the interactive presentation.
138 * \param theLCS [in] the local coordiante system of parent object.
140 void Init( const Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS );
143 * \brief Updates length object properties from the fields.
144 * \param theIO [in/out] the interactive presentation.
145 * \param theLCS [in] the local coordiante system of parent object.
147 void Update( Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS );
150 * \brief Packs properties to array of doubles.
151 * \param theValues [out] the values vector to populate.
153 void ToValues(std::vector<double>& theValues) const;
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.
160 void FromValues(int& theIt, const std::vector<double>& theValues);
163 * \brief Overload comparsion.
165 bool operator == (const Length &theOther) const;
166 bool operator != (const Length &theOther) const { return !(operator == (theOther)); }
172 Prs3d_DimensionTextHorizontalPosition TextHPos;
173 Prs3d_DimensionTextVerticalPosition TextVPos;
174 Prs3d_DimensionArrowOrientation ArrowPos;
178 * \brief Declaration of properties for diameter dimensions.
180 struct Standard_EXPORT Diameter : public Record
183 Record( DimensionType_Diameter ),
186 TextHPos( Prs3d_DTHP_Fit ),
187 TextVPos( Prs3d_DTVP_Center ),
188 ArrowPos( Prs3d_DAO_Fit )
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 )
204 * \brief Inits property fields from the passed length object.
205 * \param theIO [in] the interactive presentation.
206 * \param theLCS [in] the local coordiante system of parent object.
208 void Init( const Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS );
211 * \brief Updates length object properties from the fields.
212 * \param theIO [in/out] the interactive presentation.
213 * \param theLCS [in] the local coordiante system of parent object.
215 void Update( Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS );
218 * \brief Packs properties to array of doubles.
219 * \param theValues [out] the values vector to populate.
221 void ToValues(std::vector<double>& theValues) const;
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.
228 void FromValues(int& theIt, const std::vector<double>& theValues);
231 * \brief Overload comparsion.
233 bool operator == (const Diameter &theOther) const;
234 bool operator != (const Diameter &theOther) const { return !(operator == (theOther)); }
239 Prs3d_DimensionTextHorizontalPosition TextHPos;
240 Prs3d_DimensionTextVerticalPosition TextVPos;
241 Prs3d_DimensionArrowOrientation ArrowPos;
245 * \brief Declaration of properties for angle dimensions.
247 struct Standard_EXPORT Angle : public Record
250 Record( DimensionType_Angle ),
251 FirstPoint( gp::Origin() ),
252 SecondPoint( gp::Origin() ),
253 CenterPoint( gp::Origin() ),
255 TextHPos( Prs3d_DTHP_Fit ),
256 TextVPos( Prs3d_DTVP_Center ),
257 ArrowPos( Prs3d_DAO_Fit )
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 )
274 * \brief Inits property fields from the passed length object.
275 * \param theIO [in] the interactive presentation.
276 * \param theLCS [in] the local coordiante system of parent object.
278 void Init( const Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS );
281 * \brief Updates length object properties from the fields.
282 * \param theIO [in/out] the interactive presentation.
283 * \param theLCS [in] the local coordiante system of parent object.
285 void Update( Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS );
288 * \brief Packs properties to array of doubles.
289 * \param theValues [out] the values vector to populate.
291 void ToValues(std::vector<double>& theValues) const;
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.
298 void FromValues(int& theIt, const std::vector<double>& theValues);
301 * \brief Overload comparsion.
303 bool operator == (const Angle &theOther) const;
304 bool operator != (const Angle &theOther) const { return !(operator == (theOther)); }
310 Prs3d_DimensionTextHorizontalPosition TextHPos;
311 Prs3d_DimensionTextVerticalPosition TextVPos;
312 Prs3d_DimensionArrowOrientation ArrowPos;
315 typedef QSharedPointer<Record> RecordPtr;
320 * \brief Constructor. Inits empty property.
322 GEOMGUI_DimensionProperty();
325 * \brief Copy constructor.
327 GEOMGUI_DimensionProperty( const GEOMGUI_DimensionProperty& theOther );
330 * \brief Constructor. Inits property from attribute.
332 GEOMGUI_DimensionProperty( SalomeApp_Study* theStudy, const std::string& theEntry );
335 * \brief Constructor. Inits property from formatted QString.
337 GEOMGUI_DimensionProperty( const QString& theProperty );
342 ~GEOMGUI_DimensionProperty();
345 * \brief Overload QVariant cast operator.
347 operator QVariant() const;
350 * \brief Overload QString cast operator.
352 operator QString() const;
355 * \brief Overload comparsion.
357 bool operator == (const GEOMGUI_DimensionProperty &theOther) const;
360 * \brief Overload comparsion.
362 bool operator != (const GEOMGUI_DimensionProperty &theOther) const
364 return !(operator == (theOther));
370 * \brief Returns number of dimension records.
372 int GetNumber() const;
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.
379 void AddRecord( const Handle(AIS_Dimension)& theIO, const gp_Ax3& theLCS );
382 * \brief Adds new dimension record.
383 * \param theRecord [in] the record to add.
385 void AddRecord( const RecordPtr& theRecord );
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.
393 void SetRecord( const int theIndex,
394 const Handle(AIS_Dimension)& theIO,
395 const gp_Ax3& theLCS );
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.
402 void SetRecord( const int theIndex, const RecordPtr& theRecord );
405 * \brief Access record by index.
406 * \param theIndex [in] the index of the dimension record.
408 const RecordPtr& GetRecord( const int theIndex ) const;
411 * \brief Removes record by its index.
412 * \param theIndex [in] the index of dimension record.
414 void RemoveRecord( const int theIndex );
417 * \brief Clears property data.
424 * \brief Returns visibility state of dimension record by its index.
426 * \param theIndex [in] the index of the dimension record.
428 bool IsVisible( const int theIndex ) const;
431 * \brief Changes visibility state of the dimension record.
433 * \param theIndex [in] the index of the dimension record.
434 * \param theIsVisible [in] the new visibility state.
436 void SetVisible( const int theIndex, const bool theIsVisible );
439 * \brief Returns name of dimension record by its index.
441 * \param theIndex [in] the index of the dimension record.
443 QString GetName( const int theIndex ) const;
446 * \brief Changes name of dimension record.
448 * \param theIndex [in] the index of the dimension record.
449 * \param theName [in] the new name.
451 void SetName( const int theIndex, const QString& theName );
454 * \brief Returns dimension type.
456 int GetType( const int theIndex ) const;
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.
465 void LoadFromAttribute( SalomeApp_Study* theStudy, const std::string& theEntry );
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.
472 void SaveToAttribute( SalomeApp_Study* theStudy, const std::string& theEntry );
477 * \brief Determines dimension type code.
479 int TypeFromIO( const Handle(AIS_Dimension)& theIO ) const;
483 typedef QVector<bool> VectorOfVisibility;
484 typedef QVector<QString> VectorOfNames;
485 typedef QVector<RecordPtr> VectorOfRecords;
489 VectorOfVisibility myVisibility;
490 VectorOfNames myNames;
491 VectorOfRecords myRecords;
494 Q_DECLARE_METATYPE(GEOMGUI_DimensionProperty);