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] (p1)[7-9] (pnt2)[10-12]
57 * Diam: (plane)[0-3] (flyout)[4] (text flags)[5-6] (circle loc, xdir, ydir, rad)[7-16]
58 * Angle: (flyout)[0] (text flags)[1-2] (p1)[3-5] (p2)[6-8] (center)[9-11]
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 )
115 Length( const Length& theOther ) :
116 Record( DimensionType_Length ),
117 FirstPoint( theOther.FirstPoint ),
118 SecondPoint( theOther.SecondPoint ),
119 Plane( theOther.Plane ),
120 Flyout( theOther.Flyout ),
121 TextHPos( theOther.TextHPos ),
122 TextVPos( theOther.TextVPos )
128 * \brief Inits property fields from the passed length object.
129 * \param theIO [in] the interactive presentation.
130 * \param theLCS [in] the local coordiante system of parent object.
132 void Init( const Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS );
135 * \brief Updates length object properties from the fields.
136 * \param theIO [in/out] the interactive presentation.
137 * \param theLCS [in] the local coordiante system of parent object.
139 void Update( Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS );
142 * \brief Overload comparsion.
144 bool operator == (const Length &theOther) const;
145 bool operator != (const Length &theOther) const { return !(operator == (theOther)); }
151 Prs3d_DimensionTextHorizontalPosition TextHPos;
152 Prs3d_DimensionTextVerticalPosition TextVPos;
156 * \brief Declaration of properties for diameter dimensions.
158 struct Standard_EXPORT Diameter : public Record
161 Record( DimensionType_Diameter ),
164 TextHPos( Prs3d_DTHP_Fit ),
165 TextVPos( Prs3d_DTVP_Center )
168 Diameter( const Diameter& theOther ) :
169 Record( DimensionType_Diameter ),
170 Circle( theOther.Circle ),
171 Plane( theOther.Plane ),
172 Flyout( theOther.Flyout ),
173 TextHPos( theOther.TextHPos ),
174 TextVPos( theOther.TextVPos )
180 * \brief Inits property fields from the passed length object.
181 * \param theIO [in] the interactive presentation.
182 * \param theLCS [in] the local coordiante system of parent object.
184 void Init( const Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS );
187 * \brief Updates length object properties from the fields.
188 * \param theIO [in/out] the interactive presentation.
189 * \param theLCS [in] the local coordiante system of parent object.
191 void Update( Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS );
194 * \brief Overload comparsion.
196 bool operator == (const Diameter &theOther) const;
197 bool operator != (const Diameter &theOther) const { return !(operator == (theOther)); }
202 Prs3d_DimensionTextHorizontalPosition TextHPos;
203 Prs3d_DimensionTextVerticalPosition TextVPos;
207 * \brief Declaration of properties for angle dimensions.
209 struct Standard_EXPORT Angle : public Record
212 Record( DimensionType_Angle ),
213 FirstPoint( gp::Origin() ),
214 SecondPoint( gp::Origin() ),
215 CenterPoint( gp::Origin() ),
217 TextHPos( Prs3d_DTHP_Fit ),
218 TextVPos( Prs3d_DTVP_Center )
221 Angle( const Angle& theOther ) :
222 Record( DimensionType_Angle ),
223 FirstPoint( theOther.FirstPoint ),
224 SecondPoint( theOther.SecondPoint ),
225 CenterPoint( theOther.CenterPoint ),
226 Flyout( theOther.Flyout ),
227 TextHPos( theOther.TextHPos ),
228 TextVPos( theOther.TextVPos )
234 * \brief Inits property fields from the passed length object.
235 * \param theIO [in] the interactive presentation.
236 * \param theLCS [in] the local coordiante system of parent object.
238 void Init( const Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS );
241 * \brief Updates length object properties from the fields.
242 * \param theIO [in/out] the interactive presentation.
243 * \param theLCS [in] the local coordiante system of parent object.
245 void Update( Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS );
248 * \brief Overload comparsion.
250 bool operator == (const Angle &theOther) const;
251 bool operator != (const Angle &theOther) const { return !(operator == (theOther)); }
257 Prs3d_DimensionTextHorizontalPosition TextHPos;
258 Prs3d_DimensionTextVerticalPosition TextVPos;
261 typedef QSharedPointer<Record> RecordPtr;
266 * \brief Constructor. Inits empty property.
268 GEOMGUI_DimensionProperty();
271 * \brief Copy constructor.
273 GEOMGUI_DimensionProperty( const GEOMGUI_DimensionProperty& theOther );
278 ~GEOMGUI_DimensionProperty();
281 * \brief Overload QVariant cast operator.
286 * \brief Overload comparsion.
288 bool operator == (const GEOMGUI_DimensionProperty &theOther) const;
293 * \brief Returns number of dimension records.
295 int GetNumber() const;
298 * \brief Adds new record for the passed interactive object. Convenience method.
299 * \param theIO [in] the interactive dimension to append as new record.
300 * \param theLCS [in] the local coordinate system of parent object.
302 void AddRecord( const Handle(AIS_Dimension)& theIO, const gp_Ax3& theLCS );
305 * \brief Adds new dimension record.
306 * \param theRecord [in] the record to add.
308 void AddRecord( const RecordPtr& theRecord );
311 * \brief Update dimension record data.
312 * \param theIndex [in] the index of the record.
313 * \param theIO [in] the interactive dimension to update properties.
314 * \param theLCS [in] the local coordinate system of parent object.
316 void SetRecord( const int theIndex,
317 const Handle(AIS_Dimension)& theIO,
318 const gp_Ax3& theLCS );
321 * \brief Update dimension record data.
322 * \param theIndex [in] the index of the dimension record.
323 * \param theRecord [in] the record to replace with.
325 void SetRecord( const int theIndex, const RecordPtr& theRecord );
328 * \brief Access record by index.
329 * \param theIndex [in] the index of the dimension record.
331 const RecordPtr& GetRecord( const int theIndex ) const;
334 * \brief Removes record by its index.
335 * \param theIndex [in] the index of dimension record.
337 void RemoveRecord( const int theIndex );
340 * \brief Clears property data.
347 * \brief Returns visibility state of dimension record by its index.
349 * \param theIndex [in] the index of the dimension record.
351 bool IsVisible( const int theIndex ) const;
354 * \brief Changes visibility state of the dimension record.
356 * \param theIndex [in] the index of the dimension record.
357 * \param theIsVisible [in] the new visibility state.
359 void SetVisible( const int theIndex, const bool theIsVisible );
362 * \brief Returns name of dimension record by its index.
364 * \param theIndex [in] the index of the dimension record.
366 QString GetName( const int theIndex ) const;
369 * \brief Changes name of dimension record.
371 * \param theIndex [in] the index of the dimension record.
372 * \param theName [in] the new name.
374 void SetName( const int theIndex, const QString& theName );
377 * \brief Returns dimension type.
379 int GetType( const int theIndex ) const;
384 * \brief Loads properties data from attribute "AttributeTableOfReal".
385 * \param theStudy [in] the study.
386 * \param theEntry [in] the entry of GEOM object to operate with.
388 void LoadFromAttribute( SalomeApp_Study* theStudy, const std::string& theEntry );
391 * \brief Saves properties data to attribute "AttributeTableOfReal".
392 * \param theStudy [in] the study.
393 * \param theEntry [in] the entry of GEOM object to operate with.
395 void SaveToAttribute( SalomeApp_Study* theStudy, const std::string& theEntry );
400 * \brief Determines dimension type code.
402 int TypeFromIO( const Handle(AIS_Dimension)& theIO ) const;
406 typedef QVector<bool> VectorOfVisibility;
407 typedef QVector<QString> VectorOfNames;
408 typedef QVector<RecordPtr> VectorOfRecords;
412 VectorOfVisibility myVisibility;
413 VectorOfNames myNames;
414 VectorOfRecords myRecords;
417 Q_DECLARE_METATYPE(GEOMGUI_DimensionProperty);