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