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