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 ); }
101 * \brief Declaration of properties for length dimensions.
103 struct Standard_EXPORT Length : public Record
106 Record( DimensionType_Length ),
107 FirstPoint( gp::Origin() ),
108 SecondPoint( gp::Origin() ),
111 TextHPos( Prs3d_DTHP_Fit ),
112 TextVPos( Prs3d_DTVP_Center ),
113 ArrowPos( Prs3d_DAO_Fit )
116 Length( const Length& theOther ) :
117 Record( DimensionType_Length ),
118 FirstPoint( theOther.FirstPoint ),
119 SecondPoint( theOther.SecondPoint ),
120 Plane( theOther.Plane ),
121 Flyout( theOther.Flyout ),
122 TextHPos( theOther.TextHPos ),
123 TextVPos( theOther.TextVPos ),
124 ArrowPos( theOther.ArrowPos )
130 * \brief Inits property fields from the passed length object.
131 * \param theIO [in] the interactive presentation.
132 * \param theLCS [in] the local coordiante system of parent object.
134 void Init( const Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS );
137 * \brief Updates length object properties from the fields.
138 * \param theIO [in/out] the interactive presentation.
139 * \param theLCS [in] the local coordiante system of parent object.
141 void Update( Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS );
144 * \brief Overload comparsion.
146 bool operator == (const Length &theOther) const;
147 bool operator != (const Length &theOther) const { return !(operator == (theOther)); }
153 Prs3d_DimensionTextHorizontalPosition TextHPos;
154 Prs3d_DimensionTextVerticalPosition TextVPos;
155 Prs3d_DimensionArrowOrientation ArrowPos;
159 * \brief Declaration of properties for diameter dimensions.
161 struct Standard_EXPORT Diameter : public Record
164 Record( DimensionType_Diameter ),
167 TextHPos( Prs3d_DTHP_Fit ),
168 TextVPos( Prs3d_DTVP_Center ),
169 ArrowPos( Prs3d_DAO_Fit )
172 Diameter( const Diameter& theOther ) :
173 Record( DimensionType_Diameter ),
174 Circle( theOther.Circle ),
175 Plane( theOther.Plane ),
176 Flyout( theOther.Flyout ),
177 TextHPos( theOther.TextHPos ),
178 TextVPos( theOther.TextVPos ),
179 ArrowPos( theOther.ArrowPos )
185 * \brief Inits property fields from the passed length object.
186 * \param theIO [in] the interactive presentation.
187 * \param theLCS [in] the local coordiante system of parent object.
189 void Init( const Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS );
192 * \brief Updates length object properties from the fields.
193 * \param theIO [in/out] the interactive presentation.
194 * \param theLCS [in] the local coordiante system of parent object.
196 void Update( Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS );
199 * \brief Overload comparsion.
201 bool operator == (const Diameter &theOther) const;
202 bool operator != (const Diameter &theOther) const { return !(operator == (theOther)); }
207 Prs3d_DimensionTextHorizontalPosition TextHPos;
208 Prs3d_DimensionTextVerticalPosition TextVPos;
209 Prs3d_DimensionArrowOrientation ArrowPos;
213 * \brief Declaration of properties for angle dimensions.
215 struct Standard_EXPORT Angle : public Record
218 Record( DimensionType_Angle ),
219 FirstPoint( gp::Origin() ),
220 SecondPoint( gp::Origin() ),
221 CenterPoint( gp::Origin() ),
223 TextHPos( Prs3d_DTHP_Fit ),
224 TextVPos( Prs3d_DTVP_Center ),
225 ArrowPos( Prs3d_DAO_Fit )
228 Angle( const Angle& theOther ) :
229 Record( DimensionType_Angle ),
230 FirstPoint( theOther.FirstPoint ),
231 SecondPoint( theOther.SecondPoint ),
232 CenterPoint( theOther.CenterPoint ),
233 Flyout( theOther.Flyout ),
234 TextHPos( theOther.TextHPos ),
235 TextVPos( theOther.TextVPos ),
236 ArrowPos( theOther.ArrowPos )
242 * \brief Inits property fields from the passed length object.
243 * \param theIO [in] the interactive presentation.
244 * \param theLCS [in] the local coordiante system of parent object.
246 void Init( const Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS );
249 * \brief Updates length object properties from the fields.
250 * \param theIO [in/out] the interactive presentation.
251 * \param theLCS [in] the local coordiante system of parent object.
253 void Update( Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS );
256 * \brief Overload comparsion.
258 bool operator == (const Angle &theOther) const;
259 bool operator != (const Angle &theOther) const { return !(operator == (theOther)); }
265 Prs3d_DimensionTextHorizontalPosition TextHPos;
266 Prs3d_DimensionTextVerticalPosition TextVPos;
267 Prs3d_DimensionArrowOrientation ArrowPos;
270 typedef QSharedPointer<Record> RecordPtr;
275 * \brief Constructor. Inits empty property.
277 GEOMGUI_DimensionProperty();
280 * \brief Copy constructor.
282 GEOMGUI_DimensionProperty( const GEOMGUI_DimensionProperty& theOther );
285 * \brief Constructor. Inits property from attribute.
287 GEOMGUI_DimensionProperty( SalomeApp_Study* theStudy, const std::string& theEntry );
292 ~GEOMGUI_DimensionProperty();
295 * \brief Overload QVariant cast operator.
300 * \brief Overload comparsion.
302 bool operator == (const GEOMGUI_DimensionProperty &theOther) const;
305 * \brief Overload comparsion.
307 bool operator != (const GEOMGUI_DimensionProperty &theOther) const
309 return !(operator == (theOther));
315 * \brief Returns number of dimension records.
317 int GetNumber() const;
320 * \brief Adds new record for the passed interactive object. Convenience method.
321 * \param theIO [in] the interactive dimension to append as new record.
322 * \param theLCS [in] the local coordinate system of parent object.
324 void AddRecord( const Handle(AIS_Dimension)& theIO, const gp_Ax3& theLCS );
327 * \brief Adds new dimension record.
328 * \param theRecord [in] the record to add.
330 void AddRecord( const RecordPtr& theRecord );
333 * \brief Update dimension record data.
334 * \param theIndex [in] the index of the record.
335 * \param theIO [in] the interactive dimension to update properties.
336 * \param theLCS [in] the local coordinate system of parent object.
338 void SetRecord( const int theIndex,
339 const Handle(AIS_Dimension)& theIO,
340 const gp_Ax3& theLCS );
343 * \brief Update dimension record data.
344 * \param theIndex [in] the index of the dimension record.
345 * \param theRecord [in] the record to replace with.
347 void SetRecord( const int theIndex, const RecordPtr& theRecord );
350 * \brief Access record by index.
351 * \param theIndex [in] the index of the dimension record.
353 const RecordPtr& GetRecord( const int theIndex ) const;
356 * \brief Removes record by its index.
357 * \param theIndex [in] the index of dimension record.
359 void RemoveRecord( const int theIndex );
362 * \brief Clears property data.
369 * \brief Returns visibility state of dimension record by its index.
371 * \param theIndex [in] the index of the dimension record.
373 bool IsVisible( const int theIndex ) const;
376 * \brief Changes visibility state of the dimension record.
378 * \param theIndex [in] the index of the dimension record.
379 * \param theIsVisible [in] the new visibility state.
381 void SetVisible( const int theIndex, const bool theIsVisible );
384 * \brief Returns name of dimension record by its index.
386 * \param theIndex [in] the index of the dimension record.
388 QString GetName( const int theIndex ) const;
391 * \brief Changes name of dimension record.
393 * \param theIndex [in] the index of the dimension record.
394 * \param theName [in] the new name.
396 void SetName( const int theIndex, const QString& theName );
399 * \brief Returns dimension type.
401 int GetType( const int theIndex ) const;
406 * \brief Loads properties data from attribute "AttributeTableOfReal".
407 * \param theStudy [in] the study.
408 * \param theEntry [in] the entry of GEOM object to operate with.
410 void LoadFromAttribute( SalomeApp_Study* theStudy, const std::string& theEntry );
413 * \brief Saves properties data to attribute "AttributeTableOfReal".
414 * \param theStudy [in] the study.
415 * \param theEntry [in] the entry of GEOM object to operate with.
417 void SaveToAttribute( SalomeApp_Study* theStudy, const std::string& theEntry );
422 * \brief Determines dimension type code.
424 int TypeFromIO( const Handle(AIS_Dimension)& theIO ) const;
428 typedef QVector<bool> VectorOfVisibility;
429 typedef QVector<QString> VectorOfNames;
430 typedef QVector<RecordPtr> VectorOfRecords;
434 VectorOfVisibility myVisibility;
435 VectorOfNames myNames;
436 VectorOfRecords myRecords;
439 Q_DECLARE_METATYPE(GEOMGUI_DimensionProperty);