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