Salome HOME
3a61cfed304d47f0a0280bcc74605f194295ca2c
[modules/geom.git] / src / OBJECT / GEOM_AISShape.hxx
1 // Copyright (C) 2007-2013  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.
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 //  GEOM OBJECT : interactive object for Geometry entities visualization
24 //  File   : GEOM_AISShape.hxx
25 //  Module : GEOM
26 //
27 #ifndef _GEOM_AISShape_HeaderFile
28 #define _GEOM_AISShape_HeaderFile
29
30 #include "GEOM_OBJECT_defs.hxx"
31
32 #include <GEOM_Gen.hh>
33
34 #ifndef _Standard_HeaderFile
35 #include <Standard.hxx>
36 #endif
37 #ifndef _Handle_GEOM_AISShape_HeaderFile
38 #include "Handle_GEOM_AISShape.hxx"
39 #endif
40
41 #ifndef _Handle_SALOME_InteractiveObject_HeaderFile
42 #include "Handle_SALOME_InteractiveObject.hxx"
43 #endif
44 #ifndef _Standard_CString_HeaderFile
45 #include <Standard_CString.hxx>
46 #endif
47 #ifndef _SALOME_AISShape_HeaderFile
48 #include "SALOME_AISShape.hxx"
49 #endif
50 #ifndef _Standard_Boolean_HeaderFile
51 #include <Standard_Boolean.hxx>
52 #endif
53 #ifndef _Handle_PrsMgr_PresentationManager3d_HeaderFile
54 #include <Handle_PrsMgr_PresentationManager3d.hxx>
55 #endif
56 #ifndef _Handle_Prs3d_Presentation_HeaderFile
57 #include <Handle_Prs3d_Presentation.hxx>
58 #endif
59
60 #include <TCollection_AsciiString.hxx>
61
62 #include <AIS_DisplayMode.hxx>
63 #include <Graphic3d_MaterialAspect.hxx>
64
65 #include <QList>
66 #include <QVariant>
67
68 class PrsMgr_PresentationManager3d;
69 class Prs3d_Presentation;
70 class SALOME_InteractiveObject;
71 class TopoDS_Shape;
72
73 class GEOM_OBJECT_EXPORT GEOM_AISShape : public SALOME_AISShape {
74
75 public:
76
77     //! Enumeration of display modes
78     typedef enum {
79       //WireFrame,       //!< the same as AIS_WireFrame
80       //Shading,         //!< the same as AIS_Shaded
81       ShadingWithEdges = AIS_Shaded+1, //!< shading with edges
82       TexturedShape = ShadingWithEdges+1, //!< the same as AIS_ExactHLR
83       CustomHighlight = TexturedShape+1
84     } DispMode;
85
86     //! Enumeration of top level display modes
87     typedef enum {
88       TopShowAdditionalWActor = 0,
89       TopKeepCurrent, //!< Keep current display mode
90       TopWireFrame, 
91       TopShading, 
92       TopShadingWithEdges,
93     } TopLevelDispMode;
94
95
96     inline void* operator new(size_t,void* anAddress) 
97       {
98         return anAddress;
99       }
100     inline void* operator new(size_t size) 
101       { 
102         return Standard::Allocate(size); 
103       }
104     inline void  operator delete(void *anAddress) 
105       { 
106         if (anAddress) Standard::Free((Standard_Address&)anAddress); 
107       }
108 //    inline void  operator delete(void *anAddress, size_t size) 
109 //      { 
110 //        if (anAddress) Standard::Free((Standard_Address&)anAddress,size); 
111 //      }
112  // Methods PUBLIC
113  // 
114         GEOM_AISShape(const TopoDS_Shape& shape, const Standard_CString aName);
115         Standard_Boolean hasIO() ;
116         void setIO(const Handle(SALOME_InteractiveObject)& name) ;
117         void setName(const Standard_CString aName) ;
118         Standard_CString getName() ;
119         Standard_Boolean isTopLevel();
120         void setTopLevel(Standard_Boolean);
121         Handle_SALOME_InteractiveObject getIO() ;
122         void highlightSubShapes(const TColStd_IndexedMapOfInteger& aIndexMap, const Standard_Boolean aHighlight );
123         ~GEOM_AISShape();
124
125         void SetShadingColor(const Quantity_Color &aCol);
126         void SetEdgesInShadingColor(const Quantity_Color &aCol);
127         void SetDisplayVectors(bool isShow);
128
129         virtual  void Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
130                                       const Handle(Prs3d_Presentation)& aPresentation,
131                                       const Standard_Integer aMode = 0) ;
132
133         virtual  bool isShowVectors () { return myDisplayVectors; }
134                 virtual  Standard_Boolean switchTopLevel();
135                 virtual  Standard_Boolean toActivate();
136         
137  // Type management
138  //
139         friend Handle_Standard_Type& GEOM_AISShape_Type_();
140         const Handle(Standard_Type)& DynamicType() const;
141         Standard_Boolean             IsKind(const Handle(Standard_Type)&) const;
142
143         void storeIsoNumbers();
144         void restoreIsoNumbers();
145         void resetIsoNumbers();
146
147         void storeBoundaryColors();
148
149         static Quantity_Color topLevelColor();
150   static void           setTopLevelColor(const Quantity_Color c);
151
152   static TopLevelDispMode topLevelDisplayMode();
153   static void             setTopLevelDisplayMode(const TopLevelDispMode dm);
154
155   void setPrevDisplayMode(const Standard_Integer mode);
156   Standard_Integer prevDisplayMode() const {return myPrevDisplayMode;}
157
158   // Field step information
159   void setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
160                          const int theFieldDimension,
161                          const QList<QVariant>& theFieldStepData,
162                          const TCollection_AsciiString& theFieldStepName,
163                          const double theFieldStepRangeMin,
164                          const double theFieldStepRangeMax );
165   void getFieldStepInfo( GEOM::field_data_type& theFieldDataType,
166                          int& theFieldDimension,
167                          QList<QVariant>& theFieldStepData,
168                          TCollection_AsciiString& theFieldStepName,
169                          double& theFieldStepRangeMin,
170                          double& theFieldStepRangeMax ) const;
171
172 protected: 
173   void shadingMode(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
174                    const Handle(Prs3d_Presentation)& aPrs,
175                    const Standard_Integer aMode);
176
177   void restoreBoundaryColors();
178
179   // Displaying the field data
180   void drawField( const Handle(Prs3d_Presentation)& thePrs,
181                   const bool theIsText = false,
182                   const bool theIsHighlight = false );
183
184   // Auxiliary method to compute a center of mass for the specified shape
185   static Standard_Boolean computeMassCenter( const TopoDS_Shape& theShape,
186                                              gp_Pnt& theCenter );
187
188   Quantity_Color myShadingColor;
189
190   Quantity_Color myFreeBoundaryColor;
191   Quantity_Color myUnFreeBoundaryColor;
192
193   Quantity_Color myEdgesInShadingColor;
194
195   int            myUIsoNumber;
196   int            myVIsoNumber;
197
198 private: 
199   TCollection_AsciiString  myName;
200   bool                     myDisplayVectors;
201   Standard_Boolean         myTopLevel;
202   Standard_Integer         myPrevDisplayMode;
203
204   GEOM::field_data_type    myFieldDataType;
205   int                      myFieldDimension;
206   QList<QVariant>          myFieldStepData;
207   TCollection_AsciiString  myFieldStepName;
208   double                   myFieldStepRangeMin;
209   double                   myFieldStepRangeMax;
210
211   static TopLevelDispMode myTopLevelDm;
212   static Quantity_Color   myTopLevelColor;
213 };
214
215
216 // other inline functions and methods (like "C++: function call" methods)
217 //
218
219
220 #endif