Salome HOME
5a5b3cbfcff9f4cce7aa31c2ffd5434bca8f3b36
[modules/geom.git] / src / GEOMGUI / GEOMGUI_AnnotationAttrs.h
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File   : GEOMGUI_AnnotationAttrs.h
24 // Author : Anton POLETAEV, Open CASCADE S.A.S.
25 //
26
27 #ifndef GEOMGUI_ANNOTATIONATTRS_H
28 #define GEOMGUI_ANNOTATIONATTRS_H
29
30 // SALOME GUI includes
31 #include <GEOMGUI.h>
32 #include <SalomeApp_Study.h>
33
34 // OCCT includes
35 #include <gp_Ax3.hxx>
36 #include <gp_Pnt.hxx>
37 #include <Standard_Transient.hxx>
38
39 // Qt, STL includes
40 #include <QString>
41
42 class GEOM_Annotation;
43 class gp_Ax3;
44
45 /*!
46  * \brief Attribute-style helper tool to manage shape annotation data of an object.
47  */
48 class GEOMGUI_AnnotationAttrs : public Standard_Transient
49 {
50 public:
51
52   DEFINE_STANDARD_RTTIEXT( GEOMGUI_AnnotationAttrs, Standard_Transient )
53
54   //! Find annotation data defined for an object.
55   GEOMGUI_EXPORT static Handle(GEOMGUI_AnnotationAttrs) FindAttributes( const _PTR(SObject)& theObject );
56
57   //! Find or create annotation data fields for an object.
58   GEOMGUI_EXPORT static Handle(GEOMGUI_AnnotationAttrs) FindOrCreateAttributes( const _PTR(SObject)& theObject,
59                                                                                 SalomeApp_Study* theStudy );
60
61   //! Remove annotation data fields for an object.
62   GEOMGUI_EXPORT static void Remove( const _PTR(SObject)& theObject );
63
64 // Import / Export
65 public:
66
67   //! Exports annotation records as a property string.
68   GEOMGUI_EXPORT QString ExportAsPropertyString() const;
69
70   //! Imports annotation records from a property string.
71   GEOMGUI_EXPORT void ImportFromPropertyString( const QString& theString );
72
73 public:
74
75   /*!
76    * \ brief Structure representing visual properties of the shape annotation.
77    */
78   struct Properties
79   {
80     QString Text;          //!< Displayed annotation text.
81     bool    IsVisible;     //!< Application visibility flag of annotation.
82     bool    IsScreenFixed; //!< Fixed screen mode flag.
83     gp_Pnt  Position;      //!< Position of the annotation.
84     gp_Pnt  Attach;        //!< Attachment point of the annotation.
85     int     ShapeIndex;    //!< Index of the annotated subshape.
86     int     ShapeType;     //!< Type of the annotated subshape.
87   };
88
89   //! Setup parameters of the annotation presentation with the properties given.
90   //! @param thePresentation [in] the presentation to setup.
91   //! @param theProps [in] the set of properties.
92   //! @param theShapeLCS [in] the local coordinate system of the shape.
93   GEOMGUI_EXPORT static void SetupPresentation( const Handle(GEOM_Annotation)& thePresentation,
94                                                 const Properties& theProps,
95                                                 const gp_Ax3& theShapeLCS );
96
97   //! Setup parameters of the annotation presentation with the properties of a definition.
98   //! @param thePresentation [in] the presentation to setup.
99   //! @param theIndex [in] the index of the annotation definition.
100   //! @param theShapeLCS [in] the local coordinate system of the shape.
101   GEOMGUI_EXPORT void SetupPresentation( const Handle(GEOM_Annotation)& thePresentation,
102                                          const int theIndex,
103                                          const gp_Ax3& theShapeLCS );
104
105 public:
106
107   //! Changes count of annotation definitions stored on the object.
108   //! If the count is decreased the extra annotation definitions are
109   //! cleared out from the attribute.
110   //! @param theNumber [in] the new number of annotation definitions.
111   GEOMGUI_EXPORT void SetNbAnnotation( const int theCount ) const;
112
113   //! Returns number of annotation definitions stored on the object.
114   GEOMGUI_EXPORT int GetNbAnnotation() const;
115
116   //! Sets application visibility state of an annotation definition.
117   //! @param theIndex [in] the index of the annotation definition.
118   //! @param theIsVisible [in] the visibility state.
119   GEOMGUI_EXPORT void SetIsVisible( const int theIndex, const bool theIsVisible );
120
121   //! Returns application visibility state of an annotation definition.
122   GEOMGUI_EXPORT bool GetIsVisible( const int theIndex ) const;
123
124   //! Sets annotation label's text.
125   //! @param theIndex [in] the index of the annotation definition.
126   //! @param theText [in] the text string.
127   GEOMGUI_EXPORT void SetText( const int theIndex, const QString& theText );
128
129   //! Returns annotation label's text.
130   GEOMGUI_EXPORT QString GetText( const int theIndex ) const;
131
132   //! Sets screen fixed flag of the annotation definition.
133   //! @param theIndex [in] the index of the annotation definition.
134   //! @param theIsScreenFixed [in] the presentation flag.
135   GEOMGUI_EXPORT void SetIsScreenFixed( const int theIndex, const bool theIsScreenFixed );
136
137   //! Returns screen fixed flag of the annotation definition.
138   GEOMGUI_EXPORT bool GetIsScreenFixed( const int theIndex ) const;
139
140   //! Sets position of the annotation definition.
141   //! @param theIndex [in] the index of the annotation definition.
142   //! @param thePosition [in] the position of the annotation label.
143   GEOMGUI_EXPORT void SetPosition( const int theIndex, const gp_Pnt& thePosition );
144
145   //! Returns position of the annotation definition.
146   GEOMGUI_EXPORT gp_Pnt GetPosition( const int theIndex ) const;
147
148   //! Sets attach point of the annotation definition.
149   //! @param theIndex [in] the index of the annotation definition.
150   //! @param theAttach [in] the attach point of the annotation.
151   GEOMGUI_EXPORT void SetAttach( const int theIndex, const gp_Pnt& theAttach );
152
153   //! Returns attach point of the annotation definition.
154   GEOMGUI_EXPORT gp_Pnt GetAttach( const int theIndex ) const;
155
156   //! Sets shape selection arguments.
157   //! @param theIndex [in] the index of the annotation definition.
158   //! @param theShapeType, theSubIdx [in] the type of the selected shape and the sub-shape index.
159   GEOMGUI_EXPORT void SetShapeSel( const int theIndex, const int theShapeType, const int theSubIdx );
160
161   //! Returns shape selection arguments.
162   //! @param theIndex [in] the index of the annotation definition.
163   //! @param theShapeType, theSubIdx [out] the type of the selected shape and the sub-shape index.
164   GEOMGUI_EXPORT void GetShapeSel( const int theIndex, int& theShapeType, int& theSubIdx ) const;
165
166 public:
167
168   //! Appends new annotation definition with the given properties.
169   GEOMGUI_EXPORT void Append( const Properties& theProps );
170
171   //! Appends new annotation definition with the given properties and converts
172   //! position and attachment points to the given shape's local frame of reference.
173   //! @param theShapeLCS [in] the position of shape's local frame of reference with respect
174   //!        to the world frame of reference.
175   GEOMGUI_EXPORT void Append( const Properties& theProps, const gp_Ax3& theShapeLCS );
176
177   //! Removes annotation definition by the given index.
178   //! This methods performs iterative reindexing of elements starting
179   //! from the given index, so sequential removal should be performed
180   //! from the last element, or avoided at all.
181   GEOMGUI_EXPORT void Remove( const Standard_Integer theIndex );
182
183   //! Sets complete properties of an annotation definition.
184   //! @param theIndex [in] the index of the annotation definition.
185   //! @param theProps [in] the structure containing the properties.
186   GEOMGUI_EXPORT void SetProperties( const int theIndex, const Properties& theProps );
187
188   //! Sets complete properties of an annotation definition with converting
189   //! position and attachment points to the given shape's local frame
190   //! of reference.
191   //! @param theIndex [in] the index of the annotation definition.
192   //! @param theProps [in] the structure containing the properties.
193   //! @param theShapeLCS [in] the position of shape's local frame of reference with respect
194   //!        to the world frame of reference.
195   GEOMGUI_EXPORT void SetProperties( const int theIndex, const Properties& theProps, const gp_Ax3& theShapeLCS );
196
197   //! Returns complete properties of an annotation definition.
198   //! @param theIndex [in] the index of the annotation definition.
199   //! @param theProps [out] the structure containing the properties.
200   GEOMGUI_EXPORT void GetProperties( const int theIndex, Properties& theProps ) const;
201
202 private:
203
204   GEOMGUI_AnnotationAttrs( const _PTR(SObject)& theObject, const _PTR(AttributeParameter)& theParameter )
205   : myObj( theObject ),
206     myParameterMap( theParameter ) {}
207
208   GEOMGUI_AnnotationAttrs( const GEOMGUI_AnnotationAttrs& ); // private copy constructor, must be never called
209   void operator=( const GEOMGUI_AnnotationAttrs& ); // private assignment operator, must be never called
210
211 private:
212
213   _PTR(SObject) myObj;
214   _PTR(AttributeParameter) myParameterMap;
215 };
216
217 DEFINE_STANDARD_HANDLE( GEOMGUI_AnnotationAttrs, Standard_Transient )
218
219 #endif