Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IShapesOperations.hxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //=============================================================================
21 // File      : GEOMImpl_IShapesOperations.hxx
22 // Created   : 
23 // Author    : modified by Lioka RAZAFINDRAZAKA (CEA) 22/06/2007
24 // Project   : SALOME
25 // Copyright : CEA 2003
26 // $Header$
27 //=============================================================================
28 #ifndef _GEOMImpl_IShapesOperations_HXX_
29 #define _GEOMImpl_IShapesOperations_HXX_
30
31 using namespace std;
32
33 #include "GEOM_IOperations.hxx"
34
35 #include "GEOMAlgo_State.hxx"
36
37 #include <TopTools_ListOfShape.hxx>
38 #include <TColStd_HSequenceOfTransient.hxx>
39 #include <TColStd_HSequenceOfInteger.hxx>
40
41 #include <list>
42 #include <Handle_Geom_Surface.hxx>
43
44 #include <gp_Pnt.hxx>
45
46 class GEOM_Engine;
47 class Handle(GEOM_Object);
48 class Handle(TColStd_HArray1OfInteger);
49
50 class GEOMImpl_IShapesOperations : public GEOM_IOperations
51 {
52  public:
53   Standard_EXPORT GEOMImpl_IShapesOperations(GEOM_Engine* theEngine, int theDocID);
54   Standard_EXPORT ~GEOMImpl_IShapesOperations();
55
56   Standard_EXPORT Handle(GEOM_Object) MakeEdge (Handle(GEOM_Object) thePoint1,
57                                 Handle(GEOM_Object) thePoint2);
58
59   Standard_EXPORT Handle(GEOM_Object) MakeWire (list<Handle(GEOM_Object)> theEdgesAndWires);
60
61   Standard_EXPORT Handle(GEOM_Object) MakeFace (Handle(GEOM_Object) theWire, const bool isPlanarWanted);
62
63   Standard_EXPORT Handle(GEOM_Object) MakeFaceWires (list<Handle(GEOM_Object)> theWires,
64                                      const bool isPlanarWanted);
65
66   Standard_EXPORT Handle(GEOM_Object) MakeShell (list<Handle(GEOM_Object)> theShapes);
67
68   Standard_EXPORT Handle(GEOM_Object) MakeSolidShell (Handle(GEOM_Object) theShell);
69
70   Standard_EXPORT Handle(GEOM_Object) MakeSolidShells (list<Handle(GEOM_Object)> theShells);
71
72   Standard_EXPORT Handle(GEOM_Object) MakeCompound (list<Handle(GEOM_Object)> theShapes);
73
74   Standard_EXPORT Handle(GEOM_Object) MakeGlueFaces (Handle(GEOM_Object) theShape,
75                                                      const Standard_Real theTolerance,
76                                                      const Standard_Boolean doKeepNonSolids);
77
78   Standard_EXPORT Handle(TColStd_HSequenceOfTransient) GetGlueFaces (Handle(GEOM_Object) theShape,
79                                                                      const Standard_Real theTolerance);
80
81   Standard_EXPORT Handle(GEOM_Object) MakeGlueFacesByList (Handle(GEOM_Object) theShape,
82                                                            const Standard_Real theTolerance,
83                                                            list<Handle(GEOM_Object)> theFaces,
84                                                            const Standard_Boolean doKeepNonSolids);
85
86   Standard_EXPORT Handle(TColStd_HSequenceOfTransient) MakeExplode (Handle(GEOM_Object)    theShape,
87                                                                     const Standard_Integer theShapeType,
88                                                                     const Standard_Boolean isSorted);
89
90   Standard_EXPORT Handle(TColStd_HSequenceOfInteger) SubShapeAllIDs (Handle(GEOM_Object)    theShape,
91                                                                      const Standard_Integer theShapeType,
92                                                                      const Standard_Boolean isSorted);
93
94   Standard_EXPORT Handle(GEOM_Object) GetSubShape (Handle(GEOM_Object)    theMainShape,
95                                                    const Standard_Integer theID);
96
97   Standard_EXPORT Standard_Integer GetSubShapeIndex (Handle(GEOM_Object) theMainShape,
98                                                      Handle(GEOM_Object) theSubShape);
99
100   Standard_EXPORT Standard_Integer GetTopologyIndex (Handle(GEOM_Object) theMainShape,
101                                                      Handle(GEOM_Object) theSubShape);
102
103   Standard_EXPORT TCollection_AsciiString GetShapeTypeString (Handle(GEOM_Object) theShape);
104
105   Standard_EXPORT Standard_Integer NumberOfFaces (Handle(GEOM_Object) theShape);
106   Standard_EXPORT Standard_Integer NumberOfEdges (Handle(GEOM_Object) theShape);
107
108   Standard_EXPORT Handle(GEOM_Object) ReverseShape(Handle(GEOM_Object) theShapes);
109
110   Standard_EXPORT Handle(TColStd_HSequenceOfInteger) GetFreeFacesIDs (Handle(GEOM_Object) theShape);
111
112   Standard_EXPORT Handle(TColStd_HSequenceOfTransient) GetSharedShapes (Handle(GEOM_Object)    theShape1,
113                                                         Handle(GEOM_Object)    theShape2,
114                                                         const Standard_Integer theShapeType);
115
116   Standard_EXPORT Handle(TColStd_HSequenceOfTransient) GetShapesOnPlane (const Handle(GEOM_Object)& theShape,
117                                                          const Standard_Integer     theShapeType,
118                                                          const Handle(GEOM_Object)& theAx1,
119                                                          const GEOMAlgo_State       theState);
120
121   Standard_EXPORT Handle(TColStd_HSequenceOfTransient)
122     GetShapesOnPlaneWithLocation (const Handle(GEOM_Object)& theShape,
123                                   const Standard_Integer     theShapeType,
124                                   const Handle(GEOM_Object)& theAx1,
125                                   const Handle(GEOM_Object)& thePnt,
126                                   const GEOMAlgo_State       theState);
127
128
129   Standard_EXPORT Handle(TColStd_HSequenceOfTransient)
130     GetShapesOnCylinder (const Handle(GEOM_Object)& theShape,
131                          const Standard_Integer     theShapeType,
132                          const Handle(GEOM_Object)& theAxis,
133                          const Standard_Real        theRadius,
134                          const GEOMAlgo_State       theState);
135
136   Standard_EXPORT Handle(TColStd_HSequenceOfTransient)
137     GetShapesOnSphere (const Handle(GEOM_Object)& theShape,
138                        const Standard_Integer     theShapeType,
139                        const Handle(GEOM_Object)& theCenter,
140                        const Standard_Real        theRadius,
141                        const GEOMAlgo_State       theState);
142
143   Standard_EXPORT Handle(TColStd_HSequenceOfInteger)
144     GetShapesOnPlaneIDs (const Handle(GEOM_Object)& theShape,
145                          const Standard_Integer     theShapeType,
146                          const Handle(GEOM_Object)& theAx1,
147                          const GEOMAlgo_State       theState);
148
149   Standard_EXPORT Handle(TColStd_HSequenceOfInteger)
150     GetShapesOnPlaneWithLocationIDs (const Handle(GEOM_Object)& theShape,
151                                      const Standard_Integer     theShapeType,
152                                      const Handle(GEOM_Object)& theAx1,
153                                      const Handle(GEOM_Object)& thePnt,
154                                      const GEOMAlgo_State       theState);
155
156   Standard_EXPORT Handle(TColStd_HSequenceOfInteger)
157     GetShapesOnCylinderIDs (const Handle(GEOM_Object)& theShape,
158                             const Standard_Integer     theShapeType,
159                             const Handle(GEOM_Object)& theAxis,
160                             const Standard_Real        theRadius,
161                             const GEOMAlgo_State       theState);
162
163   Standard_EXPORT Handle(TColStd_HSequenceOfInteger)
164     GetShapesOnSphereIDs (const Handle(GEOM_Object)& theShape,
165                           const Standard_Integer     theShapeType,
166                           const Handle(GEOM_Object)& theCenter,
167                           const Standard_Real        theRadius,
168                           const GEOMAlgo_State       theState);
169
170   /*!
171    * \brief Find subshapes complying with given status about quadrangle
172     * \param theShape - the shape to explore
173     * \param theShapeType - type of subshape of theShape
174     * \param theTopLeftPoint - top left quadrangle corner
175     * \param theTopRigthPoint - top right quadrangle corner
176     * \param theBottomLeftPoint - bottom left quadrangle corner
177     * \param theBottomRigthPoint - bottom right quadrangle corner
178     * \param theState - required state
179     * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
180    */
181   Standard_EXPORT Handle(TColStd_HSequenceOfTransient)
182     GetShapesOnQuadrangle (const Handle(GEOM_Object)& theShape,
183                            const Standard_Integer     theShapeType,
184                            const Handle(GEOM_Object)& theTopLeftPoint,
185                            const Handle(GEOM_Object)& theTopRigthPoint,
186                            const Handle(GEOM_Object)& theBottomLeftPoint,
187                            const Handle(GEOM_Object)& theBottomRigthPoint,
188                            const GEOMAlgo_State       theState);
189
190   /*!
191    * \brief Find IDs of subshapes complying with given status about quadrangle
192     * \param theShape - the shape to explore
193     * \param theShapeType - type of subshape of theShape
194     * \param theTopLeftPoint - top left quadrangle corner
195     * \param theTopRigthPoint - top right quadrangle corner
196     * \param theBottomLeftPoint - bottom left quadrangle corner
197     * \param theBottomRigthPoint - bottom right quadrangle corner
198     * \param theState - required state
199     * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
200    */
201   Standard_EXPORT Handle(TColStd_HSequenceOfInteger)
202     GetShapesOnQuadrangleIDs (const Handle(GEOM_Object)& theShape,
203                               const Standard_Integer     theShapeType,
204                               const Handle(GEOM_Object)& theTopLeftPoint,
205                               const Handle(GEOM_Object)& theTopRigthPoint,
206                               const Handle(GEOM_Object)& theBottomLeftPoint,
207                               const Handle(GEOM_Object)& theBottomRigthPoint,
208                               const GEOMAlgo_State       theState);
209
210   Standard_EXPORT Handle(GEOM_Object) GetShapesOnCylinderOld (Handle(GEOM_Object)    theShape,
211                                               const Standard_Integer theShapeType,
212                                               Handle(GEOM_Object)    theAxis,
213                                               const Standard_Real    theRadius);
214
215   Standard_EXPORT Handle(GEOM_Object) GetShapesOnSphereOld (Handle(GEOM_Object)    theShape,
216                                             const Standard_Integer theShapeType,
217                                             Handle(GEOM_Object)    theCenter,
218                                             const Standard_Real    theRadius);
219
220   void GetShapeProperties(const TopoDS_Shape aShape, Standard_Real propertiesArray[], gp_Pnt & aPnt);
221
222   Standard_EXPORT Handle(GEOM_Object) GetInPlace (Handle(GEOM_Object) theShapeWhere,
223                                                   Handle(GEOM_Object) theShapeWhat);
224
225   Standard_EXPORT Handle(GEOM_Object) GetInPlaceByHistory (Handle(GEOM_Object) theShapeWhere,
226                                                            Handle(GEOM_Object) theShapeWhat);
227
228   /*!
229    * \brief Searches a shape equal to theWhat in the context of theWhere
230    * \param theShapeWhere - a context shap
231    * \param theShapeWhat - a sample shape
232    * \retval Handle(GEOM_Object) - found shape
233    */
234   Standard_EXPORT Handle(GEOM_Object) GetSame(const Handle(GEOM_Object)& theShapeWhere,
235                                               const Handle(GEOM_Object)& theShapeWhat);
236
237   /*!
238    * \brief Find IDs of subshapes complying with given status about surface
239     * \param theBox - the box to check state of subshapes against
240     * \param theShape - the shape to explore
241     * \param theShapeType - type of subshape of theShape
242     * \param theState - required state
243     * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
244    */
245   Standard_EXPORT Handle(TColStd_HSequenceOfInteger)
246                               GetShapesOnBoxIDs(const Handle(GEOM_Object)& theBox,
247                                                 const Handle(GEOM_Object)& theShape,
248                                                 const Standard_Integer theShapeType,
249                                                 GEOMAlgo_State theState);
250
251   /*!
252    * \brief Find subshapes complying with given status about surface
253    * \param theBox - the box to check state of subshapes against
254    * \param theShape - the shape to explore
255    * \param theShapeType - type of subshape of theShape
256    * \param theState - required state
257    * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
258    */
259   Standard_EXPORT Handle(TColStd_HSequenceOfTransient)
260                                 GetShapesOnBox(const Handle(GEOM_Object)& theBox,
261                                                const Handle(GEOM_Object)& theShape,
262                                                const Standard_Integer theShapeType,
263                                                GEOMAlgo_State theState);
264
265  public:
266   /*!
267    * \brief Sort shapes in the list by their coordinates.
268    * \param SL The list of shapes to sort.
269    */
270   Standard_EXPORT static void SortShapes (TopTools_ListOfShape& SL);
271
272   /*!
273    * \brief Convert TopoDS_COMPSOLID to TopoDS_COMPOUND.
274    *
275    * If the argument shape is not of type TopoDS_COMPSOLID, this method returns it as is.
276    *
277    * \param theCompsolid The compsolid to be converted.
278    * \retval TopoDS_Shape Returns the resulting compound.
279    */
280   Standard_EXPORT static TopoDS_Shape CompsolidToCompound (const TopoDS_Shape& theCompsolid);
281
282   /*!
283    * \brief Build a triangulation on \a theShape if it is absent.
284    * \param theShape The shape to check/build triangulation on.
285    * \retval bool Returns false if the shape has no faces, i.e. impossible to build triangulation.
286    */
287   Standard_EXPORT static bool CheckTriangulation (const TopoDS_Shape& theShape);
288
289  private:
290   Handle(GEOM_Object) MakeShape (list<Handle(GEOM_Object)>      theShapes,
291                                  const Standard_Integer         theObjectType,
292                                  const Standard_Integer         theFunctionType,
293                                  const TCollection_AsciiString& theMethodName);
294
295 // ----------------------------------------------------
296 // methods common for all GetShapesOnXXX() functions
297 // ----------------------------------------------------
298
299   /*!
300    * \brief Checks if theShapeType parameter of GetShapesOnXXX() is OK
301     * \param theShapeType - the shape type to check
302     * \retval bool  - result of the check
303    */
304   bool checkTypeShapesOn(const Standard_Integer theShapeType);
305
306   /*!
307    * \brief Creates Geom_Plane
308     * \param theAx1 - edge defining plane normal
309     * \retval Handle(Geom_Surface) - resulting surface
310    */
311   Handle(Geom_Surface) makePlane(const TopoDS_Shape& theAx1);
312
313   /*!
314    * \brief Creates Geom_CylindricalSurface
315     * \param theAx1 - edge defining cylinder axis
316     * \param theRadius - cylinder radius
317     * \retval Handle(Geom_Surface) - resulting surface
318    */
319   Handle(Geom_Surface) makeCylinder(const TopoDS_Shape& theAx1,
320                                     const Standard_Real theRadius);
321
322   /*!
323    * \brief Find IDs of subshapes complying with given status about surface
324     * \param theSurface - the surface to check state of subshapes against
325     * \param theShape - the shape to explore
326     * \param theShapeType - type of subshape of theShape
327     * \param theState - required state
328     * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
329    */
330   Handle(TColStd_HSequenceOfInteger)
331     getShapesOnSurfaceIDs(const Handle(Geom_Surface)& theSurface,
332                           const TopoDS_Shape&         theShape,
333                           TopAbs_ShapeEnum            theShapeType,
334                           GEOMAlgo_State              theState);
335
336   /*!
337    * \brief Find subshapes complying with given status about surface
338     * \param theSurface - the surface to check state of subshapes against
339     * \param theShape - the shape to explore
340     * \param theShapeType - type of subshape of theShape
341     * \param theState - required state
342     * \param theShapeEntries - outgoing entries like "entry1, entry2, ..."
343     * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
344    */
345   Handle(TColStd_HSequenceOfTransient)
346     getShapesOnSurface(const Handle(Geom_Surface)& theSurface,
347                        const Handle(GEOM_Object)&  theShape,
348                        TopAbs_ShapeEnum            theShapeType,
349                        GEOMAlgo_State              theState,
350                        TCollection_AsciiString &   theShapeEntries);
351
352   /*!
353    * \brief Find IDs of subshapes complying with given status about quadrangle
354     * \param theShape - the shape to explore
355     * \param theShapeType - type of subshape of theShape
356     * \param theTopLeftPoint - top left quadrangle corner
357     * \param theTopRigthPoint - top right quadrangle corner
358     * \param theBottomLeftPoint - bottom left quadrangle corner
359     * \param theBottomRigthPoint - bottom right quadrangle corner
360     * \param theState - required state
361     * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
362    */
363   Handle(TColStd_HSequenceOfInteger)
364     getShapesOnQuadrangleIDs (const Handle(GEOM_Object)& theShape,
365                               const Standard_Integer     theShapeType,
366                               const Handle(GEOM_Object)& theTopLeftPoint,
367                               const Handle(GEOM_Object)& theTopRigthPoint,
368                               const Handle(GEOM_Object)& theBottomLeftPoint,
369                               const Handle(GEOM_Object)& theBottomRigthPoint,
370                               const GEOMAlgo_State       theState);
371
372   /*!
373    * \brief Find IDs of subshapes complying with given status about surface
374     * \param theBox - the box to check state of subshapes against
375     * \param theShape - the shape to explore
376     * \param theShapeType - type of subshape of theShape
377     * \param theState - required state
378     * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
379    */
380   Handle(TColStd_HSequenceOfInteger) getShapesOnBoxIDs(const Handle(GEOM_Object)& theBox,
381                                                        const Handle(GEOM_Object)& theShape,
382                                                        const Standard_Integer theShapeType,
383                                                        GEOMAlgo_State theState);
384
385   /*!
386    * \brief Find shape objects and their entries by their ids
387     * \param theShape - the main shape
388     * \param theShapeIDs - theShapeIDs - incoming shape ids
389     * \param theShapeEntries - outgoing entries like "entry1, entry2, ..."
390     * \retval Handle(TColStd_HSequenceOfTransient) - found shape objects
391    */
392   Handle(TColStd_HSequenceOfTransient)
393     getObjectsShapesOn(const Handle(GEOM_Object)&                theShape,
394                        const Handle(TColStd_HSequenceOfInteger)& theShapeIDs,
395                        TCollection_AsciiString &                 theShapeEntries);
396
397   /*!
398    * \brief Select the object created last
399     * \param theObj1 - Object 1
400     * \param theObj2 - Object 2
401     * \retval Handle(GEOM_Object) - selected object
402    */
403   static Handle(GEOM_Object) getCreatedLast(const Handle(GEOM_Object)& theObj1,
404                                             const Handle(GEOM_Object)& theObj2);
405 };
406
407 #endif