1 // Copyright (C) 2007-2021 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
30 #include <Basics_OCCTVersion.hxx>
33 #include <AIS_Dimension.hxx>
34 #include <AIS_DiameterDimension.hxx>
35 #if OCC_VERSION_LARGE >= 0x070400ff
36 #include <PrsDim_LengthDimension.hxx>
38 #include <AIS_LengthDimension.hxx>
40 #include <AIS_AngleDimension.hxx>
44 #include <QSharedPointer>
50 class SalomeApp_Study;
52 class GEOMGUI_DimensionProperty;
53 typedef QSharedPointer<GEOMGUI_DimensionProperty> DimensionPropertyPtr;
56 * \brief Utility class to unpack/pack dimension presentations as object property of study.
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
62 * The record is a list of qvariant, containing packed dimension properties and its attributes:
63 * (name);(is_visible);(dimension type);(dimension property list);
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]
70 class Standard_EXPORT GEOMGUI_DimensionProperty
75 * \brief Type of packed presentation.
80 DimensionType_Diameter,
85 * \brief Base class for pointer-optimized records storing.
93 Record( const DimensionType theType )
97 DimensionType Type() const
102 Length* AsLength() { return static_cast<Length*>( this ); }
103 Diameter* AsDiameter() { return static_cast<Diameter*>( this ); }
104 Angle* AsAngle() { return static_cast<Angle*>( this ); }
106 virtual void ToValues(std::vector<double>& theValues) const = 0;
107 virtual void FromValues(int& theIt, const std::vector<double>& theValues) = 0;
110 DimensionType myType;
114 * \brief Declaration of properties for length dimensions.
116 struct Standard_EXPORT Length : public Record
119 Record( DimensionType_Length ),
120 FirstPoint( gp::Origin() ),
121 SecondPoint( gp::Origin() ),
124 TextHPos( Prs3d_DTHP_Fit ),
125 TextVPos( Prs3d_DTVP_Center ),
126 ArrowPos( Prs3d_DAO_Fit )
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 )
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.
147 #if OCC_VERSION_LARGE >= 0x070400ff
148 void Init( const Handle(PrsDim_LengthDimension)& theIO, const gp_Ax3& theLCS );
150 void Init( const Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS );
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.
158 #if OCC_VERSION_LARGE >= 0x070400ff
159 void Update( Handle(PrsDim_LengthDimension)& theIO, const gp_Ax3& theLCS );
161 void Update( Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS );
165 * \brief Packs properties to array of doubles.
166 * \param theValues [out] the values vector to populate.
168 void ToValues(std::vector<double>& theValues) const;
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.
175 void FromValues(int& theIt, const std::vector<double>& theValues);
178 * \brief Overload comparison.
180 bool operator == (const Length &theOther) const;
181 bool operator != (const Length &theOther) const { return !(operator == (theOther)); }
187 Prs3d_DimensionTextHorizontalPosition TextHPos;
188 Prs3d_DimensionTextVerticalPosition TextVPos;
189 Prs3d_DimensionArrowOrientation ArrowPos;
193 * \brief Declaration of properties for diameter dimensions.
195 struct Standard_EXPORT Diameter : public Record
198 Record( DimensionType_Diameter ),
201 TextHPos( Prs3d_DTHP_Fit ),
202 TextVPos( Prs3d_DTVP_Center ),
203 ArrowPos( Prs3d_DAO_Fit )
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 )
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.
223 void Init( const Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS );
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.
230 void Update( Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS );
233 * \brief Packs properties to array of doubles.
234 * \param theValues [out] the values vector to populate.
236 void ToValues(std::vector<double>& theValues) const;
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.
243 void FromValues(int& theIt, const std::vector<double>& theValues);
246 * \brief Overload comparison.
248 bool operator == (const Diameter &theOther) const;
249 bool operator != (const Diameter &theOther) const { return !(operator == (theOther)); }
254 Prs3d_DimensionTextHorizontalPosition TextHPos;
255 Prs3d_DimensionTextVerticalPosition TextVPos;
256 Prs3d_DimensionArrowOrientation ArrowPos;
260 * \brief Declaration of properties for angle dimensions.
262 struct Standard_EXPORT Angle : public Record
265 Record( DimensionType_Angle ),
266 FirstPoint( gp::Origin() ),
267 SecondPoint( gp::Origin() ),
268 CenterPoint( gp::Origin() ),
270 TextHPos( Prs3d_DTHP_Fit ),
271 TextVPos( Prs3d_DTVP_Center ),
272 ArrowPos( Prs3d_DAO_Fit )
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 )
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.
293 void Init( const Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS );
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.
300 void Update( Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS );
303 * \brief Packs properties to array of doubles.
304 * \param theValues [out] the values vector to populate.
306 void ToValues(std::vector<double>& theValues) const;
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.
313 void FromValues(int& theIt, const std::vector<double>& theValues);
316 * \brief Overload comparison.
318 bool operator == (const Angle &theOther) const;
319 bool operator != (const Angle &theOther) const { return !(operator == (theOther)); }
325 Prs3d_DimensionTextHorizontalPosition TextHPos;
326 Prs3d_DimensionTextVerticalPosition TextVPos;
327 Prs3d_DimensionArrowOrientation ArrowPos;
330 typedef QSharedPointer<Record> RecordPtr;
335 * \brief Constructor. Inits empty property.
337 GEOMGUI_DimensionProperty();
340 * \brief Copy constructor.
342 GEOMGUI_DimensionProperty( const GEOMGUI_DimensionProperty& theOther );
345 * \brief Constructor. Inits property from attribute.
347 GEOMGUI_DimensionProperty( const std::string& theEntry );
350 * \brief Constructor. Inits property from formatted QString.
352 GEOMGUI_DimensionProperty( const QString& theProperty );
357 ~GEOMGUI_DimensionProperty();
360 * \brief Overload QVariant cast operator.
362 operator QVariant() const;
365 * \brief Overload QString cast operator.
367 operator QString() const;
370 * \brief Overload comparison.
372 bool operator == (const GEOMGUI_DimensionProperty &theOther) const;
375 * \brief Overload comparison.
377 bool operator != (const GEOMGUI_DimensionProperty &theOther) const
379 return !(operator == (theOther));
385 * \brief Returns number of dimension records.
387 int GetNumber() const;
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.
394 void AddRecord( const Handle(AIS_Dimension)& theIO, const gp_Ax3& theLCS );
397 * \brief Adds new dimension record.
398 * \param theRecord [in] the record to add.
400 void AddRecord( const RecordPtr& theRecord );
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.
408 void SetRecord( const int theIndex,
409 const Handle(AIS_Dimension)& theIO,
410 const gp_Ax3& theLCS );
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.
417 void SetRecord( const int theIndex, const RecordPtr& theRecord );
420 * \brief Access record by index.
421 * \param theIndex [in] the index of the dimension record.
423 const RecordPtr& GetRecord( const int theIndex ) const;
426 * \brief Removes record by its index.
427 * \param theIndex [in] the index of dimension record.
429 void RemoveRecord( const int theIndex );
432 * \brief Clears property data.
439 * \brief Returns visibility state of dimension record by its index.
441 * \param theIndex [in] the index of the dimension record.
443 bool IsVisible( const int theIndex ) const;
446 * \brief Changes visibility state of the dimension record.
448 * \param theIndex [in] the index of the dimension record.
449 * \param theIsVisible [in] the new visibility state.
451 void SetVisible( const int theIndex, const bool theIsVisible );
454 * \brief Returns name of dimension record by its index.
456 * \param theIndex [in] the index of the dimension record.
458 QString GetName( const int theIndex ) const;
461 * \brief Changes name of dimension record.
463 * \param theIndex [in] the index of the dimension record.
464 * \param theName [in] the new name.
466 void SetName( const int theIndex, const QString& theName );
469 * \brief Returns dimension type.
471 int GetType( const int theIndex ) const;
476 * \brief Loads properties data from attribute "AttributeTableOfReal".
477 * \param theEntry [in] the entry of GEOM object to operate with.
479 void LoadFromAttribute( const std::string& theEntry );
482 * \brief Saves properties data to attribute "AttributeTableOfReal".
483 * \param theEntry [in] the entry of GEOM object to operate with.
485 void SaveToAttribute( const std::string& theEntry );
490 * \brief Determines dimension type code.
492 int TypeFromIO( const Handle(AIS_Dimension)& theIO ) const;
496 typedef QVector<bool> VectorOfVisibility;
497 typedef QVector<QString> VectorOfNames;
498 typedef QVector<RecordPtr> VectorOfRecords;
502 VectorOfVisibility myVisibility;
503 VectorOfNames myNames;
504 VectorOfRecords myRecords;
507 Q_DECLARE_METATYPE(GEOMGUI_DimensionProperty)