Salome HOME
Mantis issue 0020998: EDF 1572 GEOM: Some limitations to the PipeTShape.
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IShapesOperations.hxx
1 //  Copyright (C) 2007-2010  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 //=============================================================================
24 // File      : GEOMImpl_IShapesOperations.hxx
25 // Created   : 
26 // Author    : modified by Lioka RAZAFINDRAZAKA (CEA) 22/06/2007
27 // Project   : SALOME
28 // $Header$
29 //=============================================================================
30 //
31 #ifndef _GEOMImpl_IShapesOperations_HXX_
32 #define _GEOMImpl_IShapesOperations_HXX_
33
34 #include "GEOM_IOperations.hxx"
35
36 #include "GEOMAlgo_State.hxx"
37
38 #include <TopTools_ListOfShape.hxx>
39 #include <TColStd_HSequenceOfTransient.hxx>
40 #include <TColStd_HSequenceOfInteger.hxx>
41
42 #include <list>
43 #include <Handle_Geom_Surface.hxx>
44
45 #include <gp_Pnt.hxx>
46
47 class GEOM_Engine;
48 class Handle(GEOM_Object);
49 class Handle(TColStd_HArray1OfInteger);
50
51 class GEOMImpl_IShapesOperations : public GEOM_IOperations
52 {
53  public:
54   Standard_EXPORT GEOMImpl_IShapesOperations(GEOM_Engine* theEngine, int theDocID);
55   Standard_EXPORT ~GEOMImpl_IShapesOperations();
56
57   Standard_EXPORT Handle(GEOM_Object) MakeEdge (Handle(GEOM_Object) thePoint1,
58                                                 Handle(GEOM_Object) thePoint2);
59   Standard_EXPORT Handle(GEOM_Object) MakeEdgeWire (Handle(GEOM_Object) theWire,
60                                                     const Standard_Real theLinearTolerance,
61                                                     const Standard_Real theAngularTolerance);
62
63   Standard_EXPORT Handle(GEOM_Object) MakeWire (std::list<Handle(GEOM_Object)> theEdgesAndWires,
64                                                 const Standard_Real            theTolerance);
65
66   Standard_EXPORT Handle(GEOM_Object) MakeFace (Handle(GEOM_Object) theWire, const bool isPlanarWanted);
67
68   Standard_EXPORT Handle(GEOM_Object) MakeFaceWires (std::list<Handle(GEOM_Object)> theWires,
69                                      const bool isPlanarWanted);
70
71   Standard_EXPORT Handle(GEOM_Object) MakeShell (std::list<Handle(GEOM_Object)> theShapes);
72
73   Standard_EXPORT Handle(GEOM_Object) MakeSolidShells (std::list<Handle(GEOM_Object)> theShells);
74
75   Standard_EXPORT Handle(GEOM_Object) MakeCompound (std::list<Handle(GEOM_Object)> theShapes);
76
77   Standard_EXPORT Handle(GEOM_Object) MakeGlueFaces (Handle(GEOM_Object) theShape,
78                                                      const Standard_Real theTolerance,
79                                                      const Standard_Boolean doKeepNonSolids);
80
81   Standard_EXPORT Handle(TColStd_HSequenceOfTransient) GetGlueFaces (Handle(GEOM_Object) theShape,
82                                                                      const Standard_Real theTolerance);
83
84   Standard_EXPORT Handle(GEOM_Object) MakeGlueFacesByList (Handle(GEOM_Object) theShape,
85                                                            const Standard_Real theTolerance,
86                                                            std::list<Handle(GEOM_Object)> theFaces,
87                                                            const Standard_Boolean doKeepNonSolids);
88
89   Standard_EXPORT Handle(TColStd_HSequenceOfTransient) GetExistingSubObjects
90     (Handle(GEOM_Object)    theShape,
91      const Standard_Boolean theGroupsOnly);
92
93   Standard_EXPORT Handle(TColStd_HSequenceOfTransient) MakeExplode (Handle(GEOM_Object)    theShape,
94                                                                     const Standard_Integer theShapeType,
95                                                                     const Standard_Boolean isSorted);
96
97   Standard_EXPORT Handle(TColStd_HSequenceOfInteger) SubShapeAllIDs (Handle(GEOM_Object)    theShape,
98                                                                      const Standard_Integer theShapeType,
99                                                                      const Standard_Boolean isSorted);
100
101   Standard_EXPORT Handle(GEOM_Object) GetSubShape (Handle(GEOM_Object)    theMainShape,
102                                                    const Standard_Integer theID);
103
104   Standard_EXPORT Standard_Integer GetSubShapeIndex (Handle(GEOM_Object) theMainShape,
105                                                      Handle(GEOM_Object) theSubShape);
106
107   Standard_EXPORT Standard_Integer GetTopologyIndex (Handle(GEOM_Object) theMainShape,
108                                                      Handle(GEOM_Object) theSubShape);
109
110   Standard_EXPORT TCollection_AsciiString GetShapeTypeString (Handle(GEOM_Object) theShape);
111
112   Standard_EXPORT Standard_Integer NumberOfSubShapes (Handle(GEOM_Object)    theShape,
113                                                       const Standard_Integer theShapeType);
114
115   Standard_EXPORT Handle(GEOM_Object) ReverseShape(Handle(GEOM_Object) theShapes);
116
117   Standard_EXPORT Handle(TColStd_HSequenceOfInteger) GetFreeFacesIDs (Handle(GEOM_Object) theShape);
118
119   Standard_EXPORT Handle(TColStd_HSequenceOfTransient) GetSharedShapes (Handle(GEOM_Object)    theShape1,
120                                                         Handle(GEOM_Object)    theShape2,
121                                                         const Standard_Integer theShapeType);
122
123   Standard_EXPORT Handle(TColStd_HSequenceOfTransient) GetShapesOnPlane (const Handle(GEOM_Object)& theShape,
124                                                          const Standard_Integer     theShapeType,
125                                                          const Handle(GEOM_Object)& theAx1,
126                                                          const GEOMAlgo_State       theState);
127
128   Standard_EXPORT Handle(TColStd_HSequenceOfTransient)
129     GetShapesOnPlaneWithLocation (const Handle(GEOM_Object)& theShape,
130                                   const Standard_Integer     theShapeType,
131                                   const Handle(GEOM_Object)& theAx1,
132                                   const Handle(GEOM_Object)& thePnt,
133                                   const GEOMAlgo_State       theState);
134
135
136   Standard_EXPORT Handle(TColStd_HSequenceOfTransient)
137     GetShapesOnCylinder (const Handle(GEOM_Object)& theShape,
138                          const Standard_Integer     theShapeType,
139                          const Handle(GEOM_Object)& theAxis,
140                          const Standard_Real        theRadius,
141                          const GEOMAlgo_State       theState);
142
143   Standard_EXPORT Handle(TColStd_HSequenceOfTransient)
144     GetShapesOnCylinderWithLocation (const Handle(GEOM_Object)& theShape,
145                                      const Standard_Integer     theShapeType,
146                                      const Handle(GEOM_Object)& theAxis,
147                                      const Handle(GEOM_Object)& thePnt,
148                                      const Standard_Real        theRadius,
149                                      const GEOMAlgo_State       theState);
150
151   Standard_EXPORT Handle(TColStd_HSequenceOfTransient)
152     GetShapesOnSphere (const Handle(GEOM_Object)& theShape,
153                        const Standard_Integer     theShapeType,
154                        const Handle(GEOM_Object)& theCenter,
155                        const Standard_Real        theRadius,
156                        const GEOMAlgo_State       theState);
157
158   Standard_EXPORT Handle(TColStd_HSequenceOfInteger)
159     GetShapesOnPlaneIDs (const Handle(GEOM_Object)& theShape,
160                          const Standard_Integer     theShapeType,
161                          const Handle(GEOM_Object)& theAx1,
162                          const GEOMAlgo_State       theState);
163
164   Standard_EXPORT Handle(TColStd_HSequenceOfInteger)
165     GetShapesOnPlaneWithLocationIDs (const Handle(GEOM_Object)& theShape,
166                                      const Standard_Integer     theShapeType,
167                                      const Handle(GEOM_Object)& theAx1,
168                                      const Handle(GEOM_Object)& thePnt,
169                                      const GEOMAlgo_State       theState);
170
171   Standard_EXPORT Handle(TColStd_HSequenceOfInteger)
172     GetShapesOnCylinderIDs (const Handle(GEOM_Object)& theShape,
173                             const Standard_Integer     theShapeType,
174                             const Handle(GEOM_Object)& theAxis,
175                             const Standard_Real        theRadius,
176                             const GEOMAlgo_State       theState);
177
178   Standard_EXPORT Handle(TColStd_HSequenceOfInteger)
179     GetShapesOnCylinderWithLocationIDs (const Handle(GEOM_Object)& theShape,
180                                         const Standard_Integer     theShapeType,
181                                         const Handle(GEOM_Object)& theAxis,
182                                         const Handle(GEOM_Object)& thePnt,
183                                         const Standard_Real        theRadius,
184                                         const GEOMAlgo_State       theState);
185
186   Standard_EXPORT Handle(TColStd_HSequenceOfInteger)
187     GetShapesOnSphereIDs (const Handle(GEOM_Object)& theShape,
188                           const Standard_Integer     theShapeType,
189                           const Handle(GEOM_Object)& theCenter,
190                           const Standard_Real        theRadius,
191                           const GEOMAlgo_State       theState);
192
193   /*!
194    * \brief Find subshapes complying with given status about quadrangle
195     * \param theShape - the shape to explore
196     * \param theShapeType - type of subshape of theShape
197     * \param theTopLeftPoint - top left quadrangle corner
198     * \param theTopRigthPoint - top right quadrangle corner
199     * \param theBottomLeftPoint - bottom left quadrangle corner
200     * \param theBottomRigthPoint - bottom right quadrangle corner
201     * \param theState - required state
202     * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
203    */
204   Standard_EXPORT Handle(TColStd_HSequenceOfTransient)
205     GetShapesOnQuadrangle (const Handle(GEOM_Object)& theShape,
206                            const Standard_Integer     theShapeType,
207                            const Handle(GEOM_Object)& theTopLeftPoint,
208                            const Handle(GEOM_Object)& theTopRigthPoint,
209                            const Handle(GEOM_Object)& theBottomLeftPoint,
210                            const Handle(GEOM_Object)& theBottomRigthPoint,
211                            const GEOMAlgo_State       theState);
212
213   /*!
214    * \brief Find IDs of subshapes complying with given status about quadrangle
215     * \param theShape - the shape to explore
216     * \param theShapeType - type of subshape of theShape
217     * \param theTopLeftPoint - top left quadrangle corner
218     * \param theTopRigthPoint - top right quadrangle corner
219     * \param theBottomLeftPoint - bottom left quadrangle corner
220     * \param theBottomRigthPoint - bottom right quadrangle corner
221     * \param theState - required state
222     * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
223    */
224   Standard_EXPORT Handle(TColStd_HSequenceOfInteger)
225     GetShapesOnQuadrangleIDs (const Handle(GEOM_Object)& theShape,
226                               const Standard_Integer     theShapeType,
227                               const Handle(GEOM_Object)& theTopLeftPoint,
228                               const Handle(GEOM_Object)& theTopRigthPoint,
229                               const Handle(GEOM_Object)& theBottomLeftPoint,
230                               const Handle(GEOM_Object)& theBottomRigthPoint,
231                               const GEOMAlgo_State       theState);
232
233   Standard_EXPORT Handle(GEOM_Object) GetShapesOnCylinderOld (Handle(GEOM_Object)    theShape,
234                                               const Standard_Integer theShapeType,
235                                               Handle(GEOM_Object)    theAxis,
236                                               const Standard_Real    theRadius);
237
238   Standard_EXPORT Handle(GEOM_Object) GetShapesOnSphereOld (Handle(GEOM_Object)    theShape,
239                                             const Standard_Integer theShapeType,
240                                             Handle(GEOM_Object)    theCenter,
241                                             const Standard_Real    theRadius);
242
243   void GetShapeProperties(const TopoDS_Shape aShape, Standard_Real propertiesArray[], gp_Pnt & aPnt);
244
245   Standard_EXPORT Handle(GEOM_Object) GetInPlace (Handle(GEOM_Object) theShapeWhere,
246                                                   Handle(GEOM_Object) theShapeWhat);
247
248   Standard_EXPORT Handle(GEOM_Object) GetInPlaceByHistory (Handle(GEOM_Object) theShapeWhere,
249                                                            Handle(GEOM_Object) theShapeWhat);
250
251   /*!
252    * \brief Searches a shape equal to theWhat in the context of theWhere
253    * \param theShapeWhere - a context shap
254    * \param theShapeWhat - a sample shape
255    * \retval Handle(GEOM_Object) - found shape
256    */
257   Standard_EXPORT Handle(GEOM_Object) GetSame(const Handle(GEOM_Object)& theShapeWhere,
258                                               const Handle(GEOM_Object)& theShapeWhat);
259
260   /*!
261    * \brief Find IDs of subshapes complying with given status about surface
262     * \param theBox - the box to check state of subshapes against
263     * \param theShape - the shape to explore
264     * \param theShapeType - type of subshape of theShape
265     * \param theState - required state
266     * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
267    */
268   Standard_EXPORT Handle(TColStd_HSequenceOfInteger)
269                               GetShapesOnBoxIDs(const Handle(GEOM_Object)& theBox,
270                                                 const Handle(GEOM_Object)& theShape,
271                                                 const Standard_Integer theShapeType,
272                                                 GEOMAlgo_State theState);
273
274   /*!
275    * \brief Find subshapes complying with given status about surface
276    * \param theBox - the box to check state of subshapes against
277    * \param theShape - the shape to explore
278    * \param theShapeType - type of subshape of theShape
279    * \param theState - required state
280    * \retval Handle(TColStd_HSequenceOfTransient) - found shape objects
281    */
282   Standard_EXPORT Handle(TColStd_HSequenceOfTransient)
283                              GetShapesOnBox(const Handle(GEOM_Object)& theBox,
284                                             const Handle(GEOM_Object)& theShape,
285                                             const Standard_Integer theShapeType,
286                                             GEOMAlgo_State theState);
287
288   /*!
289    * \brief Find IDs of subshapes complying with given status about surface
290    * \param theCheckShape - the shape to check state of subshapes against
291    * \param theShape - the shape to explore
292    * \param theShapeType - type of subshape of theShape
293    * \param theState - required state
294    * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
295    */
296   Standard_EXPORT Handle(TColStd_HSequenceOfInteger)
297                    GetShapesOnShapeIDs(const Handle(GEOM_Object)& theCheckShape,
298                                        const Handle(GEOM_Object)& theShape,
299                                        const Standard_Integer theShapeType,
300                                        GEOMAlgo_State theState);
301
302   /*!
303    * \brief Find subshapes complying with given status about surface
304    * \param theCheckShape - the shape to check state of subshapes against
305    * \param theShape - the shape to explore
306    * \param theShapeType - type of subshape of theShape
307    * \param theState - required state
308    * \retval Handle(TColStd_HSequenceOfTransient) - found shape objects
309    */
310   Standard_EXPORT Handle(TColStd_HSequenceOfTransient)
311                       GetShapesOnShape(const Handle(GEOM_Object)& theCheckShape,
312                                        const Handle(GEOM_Object)& theShape,
313                                        const Standard_Integer theShapeType,
314                                        GEOMAlgo_State theState);
315   Standard_EXPORT Handle(GEOM_Object)
316             GetShapesOnShapeAsCompound(const Handle(GEOM_Object)& theCheckShape,
317                                        const Handle(GEOM_Object)& theShape,
318                                        const Standard_Integer theShapeType,
319                                        GEOMAlgo_State theState);
320
321  public:
322   /*!
323    * \brief Sort shapes in the list by their coordinates.
324    * \param SL The list of shapes to sort.
325    */
326   Standard_EXPORT static void SortShapes (TopTools_ListOfShape& SL);
327
328   /*!
329    * \brief Convert TopoDS_COMPSOLID to TopoDS_COMPOUND.
330    *
331    * If the argument shape is not of type TopoDS_COMPSOLID, this method returns it as is.
332    *
333    * \param theCompsolid The compsolid to be converted.
334    * \retval TopoDS_Shape Returns the resulting compound.
335    */
336   Standard_EXPORT static TopoDS_Shape CompsolidToCompound (const TopoDS_Shape& theCompsolid);
337
338   /*!
339    * \brief Build a triangulation on \a theShape if it is absent.
340    * \param theShape The shape to check/build triangulation on.
341    * \retval bool Returns false if the shape has no faces, i.e. impossible to build triangulation.
342    */
343   Standard_EXPORT static bool CheckTriangulation (const TopoDS_Shape& theShape);
344
345  private:
346   Handle(GEOM_Object) MakeShape (std::list<Handle(GEOM_Object)>      theShapes,
347                                  const Standard_Integer         theObjectType,
348                                  const Standard_Integer         theFunctionType,
349                                  const TCollection_AsciiString& theMethodName);
350
351 // ----------------------------------------------------
352 // methods common for all GetShapesOnXXX() functions
353 // ----------------------------------------------------
354
355   /*!
356    * \brief Checks if theShapeType parameter of GetShapesOnXXX() is OK
357    * \param theShapeType - the shape type to check
358    * \retval bool  - result of the check
359    */
360   bool checkTypeShapesOn(const Standard_Integer theShapeType);
361
362   /*!
363    * \brief Creates Geom_Plane
364    * \param theAx1 - edge defining plane normal
365    * \retval Handle(Geom_Surface) - resulting surface
366    */
367   Handle(Geom_Surface) makePlane(const TopoDS_Shape& theAx1);
368
369   /*!
370    * \brief Creates Geom_CylindricalSurface
371    * \param theAx1 - edge defining cylinder axis
372    * \param theRadius - cylinder radius
373    * \retval Handle(Geom_Surface) - resulting surface
374    */
375   Handle(Geom_Surface) makeCylinder(const TopoDS_Shape& theAx1,
376                                     const Standard_Real theRadius);
377
378   /*!
379    * \brief Find IDs of subshapes complying with given status about surface
380    * \param theSurface - the surface to check state of subshapes against
381    * \param theShape - the shape to explore
382    * \param theShapeType - type of subshape of theShape
383    * \param theState - required state
384    * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
385    */
386   Handle(TColStd_HSequenceOfInteger)
387     getShapesOnSurfaceIDs(const Handle(Geom_Surface)& theSurface,
388                           const TopoDS_Shape&         theShape,
389                           TopAbs_ShapeEnum            theShapeType,
390                           GEOMAlgo_State              theState);
391
392   /*!
393    * \brief Find subshapes complying with given status about surface
394    * \param theSurface - the surface to check state of subshapes against
395    * \param theShape - the shape to explore
396    * \param theShapeType - type of subshape of theShape
397    * \param theState - required state
398    * \param theShapeEntries - outgoing entries like "entry1, entry2, ..."
399    * \retval Handle(TColStd_HSequenceOfTransient) - found shape objects
400    */
401   Handle(TColStd_HSequenceOfTransient)
402     getShapesOnSurface(const Handle(Geom_Surface)& theSurface,
403                        const Handle(GEOM_Object)&  theShape,
404                        TopAbs_ShapeEnum            theShapeType,
405                        GEOMAlgo_State              theState,
406                        TCollection_AsciiString &   theShapeEntries);
407
408   /*!
409    * \brief Find IDs of subshapes complying with given status about quadrangle
410    * \param theShape - the shape to explore
411    * \param theShapeType - type of subshape of theShape
412    * \param theTopLeftPoint - top left quadrangle corner
413    * \param theTopRigthPoint - top right quadrangle corner
414    * \param theBottomLeftPoint - bottom left quadrangle corner
415    * \param theBottomRigthPoint - bottom right quadrangle corner
416    * \param theState - required state
417    * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
418    */
419   Handle(TColStd_HSequenceOfInteger)
420     getShapesOnQuadrangleIDs (const Handle(GEOM_Object)& theShape,
421                               const Standard_Integer     theShapeType,
422                               const Handle(GEOM_Object)& theTopLeftPoint,
423                               const Handle(GEOM_Object)& theTopRigthPoint,
424                               const Handle(GEOM_Object)& theBottomLeftPoint,
425                               const Handle(GEOM_Object)& theBottomRigthPoint,
426                               const GEOMAlgo_State       theState);
427
428   /*!
429    * \brief Find IDs of subshapes complying with given status about surface
430    * \param theBox - the box to check state of subshapes against
431    * \param theShape - the shape to explore
432    * \param theShapeType - type of subshape of theShape
433    * \param theState - required state
434    * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
435    */
436   Handle(TColStd_HSequenceOfInteger) getShapesOnBoxIDs(const Handle(GEOM_Object)& theBox,
437                                                        const Handle(GEOM_Object)& theShape,
438                                                        const Standard_Integer theShapeType,
439                                                        GEOMAlgo_State theState);
440
441   /*!
442    * \brief Find IDs of subshapes complying with given status about surface
443    * \param theCheckShape - the shape to check state of subshapes against
444    * \param theShape - the shape to explore
445    * \param theShapeType - type of subshape of theShape
446    * \param theState - required state
447    * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes
448    */
449   Handle(TColStd_HSequenceOfInteger) getShapesOnShapeIDs
450                                       (const Handle(GEOM_Object)& theCheckShape,
451                                        const Handle(GEOM_Object)& theShape,
452                                        const Standard_Integer theShapeType,
453                                        GEOMAlgo_State theState);
454
455   /*!
456    * \brief Find shape objects and their entries by their ids
457    * \param theShape - the main shape
458    * \param theShapeIDs - theShapeIDs - incoming shape ids
459    * \param theShapeEntries - outgoing entries like "entry1, entry2, ..."
460    * \retval Handle(TColStd_HSequenceOfTransient) - found shape objects
461    */
462   Handle(TColStd_HSequenceOfTransient)
463     getObjectsShapesOn(const Handle(GEOM_Object)&                theShape,
464                        const Handle(TColStd_HSequenceOfInteger)& theShapeIDs,
465                        TCollection_AsciiString &                 theShapeEntries);
466
467   /*!
468    * \brief Select the object created last
469    * \param theObj1 - Object 1
470    * \param theObj2 - Object 2
471    * \retval Handle(GEOM_Object) - selected object
472    */
473   static Handle(GEOM_Object) getCreatedLast(const Handle(GEOM_Object)& theObj1,
474                                             const Handle(GEOM_Object)& theObj2);
475 };
476
477 #endif