Salome HOME
3deb09d0abdd2e9712d944b729d5fb8356fa3124
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IShapesOperations.hxx
1 //  Copyright (C) 2007-2008  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 // File      : GEOMImpl_IShapesOperations.hxx
24 // Created   : 
25 // Author    : modified by Lioka RAZAFINDRAZAKA (CEA) 22/06/2007
26 // Project   : SALOME
27 // $Header$
28 //=============================================================================
29 //
30 #ifndef _GEOMImpl_IShapesOperations_HXX_
31 #define _GEOMImpl_IShapesOperations_HXX_
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 (std::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 (std::list<Handle(GEOM_Object)> theWires,
64                                      const bool isPlanarWanted);
65
66   Standard_EXPORT Handle(GEOM_Object) MakeShell (std::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 (std::list<Handle(GEOM_Object)> theShells);
71
72   Standard_EXPORT Handle(GEOM_Object) MakeCompound (std::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                                                            std::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_HSequenceOfTransient) - found shape objects
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   /*!
266    * \brief Find IDs of subshapes complying with given status about surface
267    * \param theCheckShape - the shape to check state of subshapes against
268    * \param theShape - the shape to explore
269    * \param theShapeType - type of subshape of theShape
270    * \param theState - required state
271    * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
272    */
273   Standard_EXPORT Handle(TColStd_HSequenceOfInteger)
274                    GetShapesOnShapeIDs(const Handle(GEOM_Object)& theCheckShape,
275                                        const Handle(GEOM_Object)& theShape,
276                                        const Standard_Integer theShapeType,
277                                        GEOMAlgo_State theState);
278
279   /*!
280    * \brief Find subshapes complying with given status about surface
281    * \param theCheckShape - the shape to check state of subshapes against
282    * \param theShape - the shape to explore
283    * \param theShapeType - type of subshape of theShape
284    * \param theState - required state
285    * \retval Handle(TColStd_HSequenceOfTransient) - found shape objects
286    */
287   Standard_EXPORT Handle(TColStd_HSequenceOfTransient)
288                       GetShapesOnShape(const Handle(GEOM_Object)& theCheckShape,
289                                        const Handle(GEOM_Object)& theShape,
290                                        const Standard_Integer theShapeType,
291                                        GEOMAlgo_State theState);
292   Standard_EXPORT Handle(GEOM_Object)
293             GetShapesOnShapeAsCompound(const Handle(GEOM_Object)& theCheckShape,
294                                        const Handle(GEOM_Object)& theShape,
295                                        const Standard_Integer theShapeType,
296                                        GEOMAlgo_State theState);
297
298  public:
299   /*!
300    * \brief Sort shapes in the list by their coordinates.
301    * \param SL The list of shapes to sort.
302    */
303   Standard_EXPORT static void SortShapes (TopTools_ListOfShape& SL);
304
305   /*!
306    * \brief Convert TopoDS_COMPSOLID to TopoDS_COMPOUND.
307    *
308    * If the argument shape is not of type TopoDS_COMPSOLID, this method returns it as is.
309    *
310    * \param theCompsolid The compsolid to be converted.
311    * \retval TopoDS_Shape Returns the resulting compound.
312    */
313   Standard_EXPORT static TopoDS_Shape CompsolidToCompound (const TopoDS_Shape& theCompsolid);
314
315   /*!
316    * \brief Build a triangulation on \a theShape if it is absent.
317    * \param theShape The shape to check/build triangulation on.
318    * \retval bool Returns false if the shape has no faces, i.e. impossible to build triangulation.
319    */
320   Standard_EXPORT static bool CheckTriangulation (const TopoDS_Shape& theShape);
321
322  private:
323   Handle(GEOM_Object) MakeShape (std::list<Handle(GEOM_Object)>      theShapes,
324                                  const Standard_Integer         theObjectType,
325                                  const Standard_Integer         theFunctionType,
326                                  const TCollection_AsciiString& theMethodName);
327
328 // ----------------------------------------------------
329 // methods common for all GetShapesOnXXX() functions
330 // ----------------------------------------------------
331
332   /*!
333    * \brief Checks if theShapeType parameter of GetShapesOnXXX() is OK
334    * \param theShapeType - the shape type to check
335    * \retval bool  - result of the check
336    */
337   bool checkTypeShapesOn(const Standard_Integer theShapeType);
338
339   /*!
340    * \brief Creates Geom_Plane
341    * \param theAx1 - edge defining plane normal
342    * \retval Handle(Geom_Surface) - resulting surface
343    */
344   Handle(Geom_Surface) makePlane(const TopoDS_Shape& theAx1);
345
346   /*!
347    * \brief Creates Geom_CylindricalSurface
348    * \param theAx1 - edge defining cylinder axis
349    * \param theRadius - cylinder radius
350    * \retval Handle(Geom_Surface) - resulting surface
351    */
352   Handle(Geom_Surface) makeCylinder(const TopoDS_Shape& theAx1,
353                                     const Standard_Real theRadius);
354
355   /*!
356    * \brief Find IDs of subshapes complying with given status about surface
357    * \param theSurface - the surface to check state of subshapes against
358    * \param theShape - the shape to explore
359    * \param theShapeType - type of subshape of theShape
360    * \param theState - required state
361    * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
362    */
363   Handle(TColStd_HSequenceOfInteger)
364     getShapesOnSurfaceIDs(const Handle(Geom_Surface)& theSurface,
365                           const TopoDS_Shape&         theShape,
366                           TopAbs_ShapeEnum            theShapeType,
367                           GEOMAlgo_State              theState);
368
369   /*!
370    * \brief Find subshapes complying with given status about surface
371    * \param theSurface - the surface to check state of subshapes against
372    * \param theShape - the shape to explore
373    * \param theShapeType - type of subshape of theShape
374    * \param theState - required state
375    * \param theShapeEntries - outgoing entries like "entry1, entry2, ..."
376    * \retval Handle(TColStd_HSequenceOfTransient) - found shape objects
377    */
378   Handle(TColStd_HSequenceOfTransient)
379     getShapesOnSurface(const Handle(Geom_Surface)& theSurface,
380                        const Handle(GEOM_Object)&  theShape,
381                        TopAbs_ShapeEnum            theShapeType,
382                        GEOMAlgo_State              theState,
383                        TCollection_AsciiString &   theShapeEntries);
384
385   /*!
386    * \brief Find IDs of subshapes complying with given status about quadrangle
387    * \param theShape - the shape to explore
388    * \param theShapeType - type of subshape of theShape
389    * \param theTopLeftPoint - top left quadrangle corner
390    * \param theTopRigthPoint - top right quadrangle corner
391    * \param theBottomLeftPoint - bottom left quadrangle corner
392    * \param theBottomRigthPoint - bottom right quadrangle corner
393    * \param theState - required state
394    * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
395    */
396   Handle(TColStd_HSequenceOfInteger)
397     getShapesOnQuadrangleIDs (const Handle(GEOM_Object)& theShape,
398                               const Standard_Integer     theShapeType,
399                               const Handle(GEOM_Object)& theTopLeftPoint,
400                               const Handle(GEOM_Object)& theTopRigthPoint,
401                               const Handle(GEOM_Object)& theBottomLeftPoint,
402                               const Handle(GEOM_Object)& theBottomRigthPoint,
403                               const GEOMAlgo_State       theState);
404
405   /*!
406    * \brief Find IDs of subshapes complying with given status about surface
407    * \param theBox - the box to check state of subshapes against
408    * \param theShape - the shape to explore
409    * \param theShapeType - type of subshape of theShape
410    * \param theState - required state
411    * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
412    */
413   Handle(TColStd_HSequenceOfInteger) getShapesOnBoxIDs(const Handle(GEOM_Object)& theBox,
414                                                        const Handle(GEOM_Object)& theShape,
415                                                        const Standard_Integer theShapeType,
416                                                        GEOMAlgo_State theState);
417
418   /*!
419    * \brief Find IDs of subshapes complying with given status about surface
420    * \param theCheckShape - the shape to check state of subshapes against
421    * \param theShape - the shape to explore
422    * \param theShapeType - type of subshape of theShape
423    * \param theState - required state
424    * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
425    */
426   Handle(TColStd_HSequenceOfInteger) getShapesOnShapeIDs
427                                       (const Handle(GEOM_Object)& theCheckShape,
428                                        const Handle(GEOM_Object)& theShape,
429                                        const Standard_Integer theShapeType,
430                                        GEOMAlgo_State theState);
431
432   /*!
433    * \brief Find shape objects and their entries by their ids
434    * \param theShape - the main shape
435    * \param theShapeIDs - theShapeIDs - incoming shape ids
436    * \param theShapeEntries - outgoing entries like "entry1, entry2, ..."
437    * \retval Handle(TColStd_HSequenceOfTransient) - found shape objects
438    */
439   Handle(TColStd_HSequenceOfTransient)
440     getObjectsShapesOn(const Handle(GEOM_Object)&                theShape,
441                        const Handle(TColStd_HSequenceOfInteger)& theShapeIDs,
442                        TCollection_AsciiString &                 theShapeEntries);
443
444   /*!
445    * \brief Select the object created last
446    * \param theObj1 - Object 1
447    * \param theObj2 - Object 2
448    * \retval Handle(GEOM_Object) - selected object
449    */
450   static Handle(GEOM_Object) getCreatedLast(const Handle(GEOM_Object)& theObj1,
451                                             const Handle(GEOM_Object)& theObj2);
452 };
453
454 #endif