Salome HOME
Issue #2971: Naming issue in a group when loading a dump file
[modules/shaper.git] / src / SketchAPI / SketchAPI_Sketch.h
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_
21 #define SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_
22
23 //--------------------------------------------------------------------------------------
24 #include "SketchAPI.h"
25
26 #include <list>
27
28 #include <SketchPlugin_Sketch.h>
29 #include <SketchPlugin_SketchEntity.h>
30
31 #include <ModelHighAPI_Interface.h>
32 #include <ModelHighAPI_Macro.h>
33 //--------------------------------------------------------------------------------------
34 class ModelAPI_CompositeFeature;
35 class ModelAPI_Object;
36 class ModelHighAPI_Double;
37 class ModelHighAPI_Integer;
38 class ModelHighAPI_RefAttr;
39 class ModelHighAPI_Reference;
40 class ModelHighAPI_Selection;
41 class SketchAPI_Arc;
42 class SketchAPI_MacroArc;
43 class SketchAPI_Circle;
44 class SketchAPI_MacroCircle;
45 class SketchAPI_IntersectionPoint;
46 class SketchAPI_Line;
47 class SketchAPI_Mirror;
48 class SketchAPI_Point;
49 class SketchAPI_Projection;
50 class SketchAPI_Rectangle;
51 class SketchAPI_Rotation;
52 class SketchAPI_Translation;
53 //--------------------------------------------------------------------------------------
54 /**\class SketchAPI_Sketch
55  * \ingroup CPPHighAPI
56  * \brief Interface for Sketch feature
57  */
58 class SketchAPI_Sketch : public ModelHighAPI_Interface
59 {
60 public:
61   /// Constructor without values
62   SKETCHAPI_EXPORT
63   explicit SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature);
64   /// Constructor with values
65   SKETCHAPI_EXPORT
66   SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
67                    const std::shared_ptr<GeomAPI_Ax3> & thePlane);
68   /// Constructor with values
69   SKETCHAPI_EXPORT
70   SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
71                    const ModelHighAPI_Selection & theExternal);
72   /// Constructor with values
73   SKETCHAPI_EXPORT
74   SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
75                    std::shared_ptr<ModelAPI_Object> thePlaneObject);
76   /// Destructor
77   SKETCHAPI_EXPORT
78   virtual ~SketchAPI_Sketch();
79
80   INTERFACE_7(SketchPlugin_Sketch::ID(),
81               origin, SketchPlugin_Sketch::ORIGIN_ID(),
82               GeomDataAPI_Point, /** Origin point */,
83               dirX, SketchPlugin_Sketch::DIRX_ID(),
84               GeomDataAPI_Dir, /** Direction of X */,
85               normal, SketchPlugin_Sketch::NORM_ID(),
86               GeomDataAPI_Dir, /** Normal */,
87               features, SketchPlugin_Sketch::FEATURES_ID(),
88               ModelAPI_AttributeRefList, /** Features */,
89               external, SketchPlugin_SketchEntity::EXTERNAL_ID(),
90               ModelAPI_AttributeSelection, /** External */,
91               solverError, SketchPlugin_Sketch::SOLVER_ERROR(),
92               ModelAPI_AttributeString, /** Solver error */,
93               solverDOF, SketchPlugin_Sketch::SOLVER_DOF(),
94               ModelAPI_AttributeString, /** Solver DOF */
95   )
96
97   /// Set plane
98   SKETCHAPI_EXPORT
99   void setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane);
100
101   /// Change sketch plane
102   SKETCHAPI_EXPORT
103   void setPlane(const ModelHighAPI_Selection & thePlane,
104                 bool theRemoveExternalDependency = false);
105
106   /// Set external
107   SKETCHAPI_EXPORT
108   void setExternal(const ModelHighAPI_Selection & theExternal);
109
110   /// Set external
111   SKETCHAPI_EXPORT
112   void setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject);
113
114   /// Change order of sketch results (faces)
115   SKETCHAPI_EXPORT
116   void changeFacesOrder(const std::list<std::list<ModelHighAPI_Selection> >& theFaces);
117
118   /// List points not connected by constraints with other sketch entitites
119   SKETCHAPI_EXPORT
120   std::list< std::shared_ptr<SketchAPI_Point> > getFreePoints();
121
122   /// Add point
123   SKETCHAPI_EXPORT
124   std::shared_ptr<SketchAPI_Point> addPoint(
125       double theX, double theY);
126   /// Add point
127   SKETCHAPI_EXPORT
128   std::shared_ptr<SketchAPI_Point> addPoint(
129       const std::shared_ptr<GeomAPI_Pnt2d> & thePoint);
130   /// Add point
131   SKETCHAPI_EXPORT
132   std::shared_ptr<SketchAPI_Point> addPoint(const ModelHighAPI_Selection & theExternal);
133   /// Add point
134   SKETCHAPI_EXPORT
135   std::shared_ptr<SketchAPI_Point> addPoint(const std::string & theExternalName);
136
137   /// Add intersection point
138   SKETCHAPI_EXPORT
139   std::shared_ptr<SketchAPI_IntersectionPoint>
140     addIntersectionPoint(const ModelHighAPI_Selection & theExternal,
141                          bool theKeepResult = false);
142   /// Add point
143   SKETCHAPI_EXPORT
144   std::shared_ptr<SketchAPI_IntersectionPoint>
145     addIntersectionPoint(const std::string & theExternalName,
146                          bool theKeepResult = false);
147
148   /// Add line
149   SKETCHAPI_EXPORT
150   std::shared_ptr<SketchAPI_Line> addLine(
151       double theX1, double theY1, double theX2, double theY2);
152   /// Add line
153   SKETCHAPI_EXPORT
154   std::shared_ptr<SketchAPI_Line> addLine(
155       const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
156       const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
157   /// Add line
158   SKETCHAPI_EXPORT
159   std::shared_ptr<SketchAPI_Line> addLine(const ModelHighAPI_Selection & theExternal);
160   /// Add line
161   SKETCHAPI_EXPORT
162   std::shared_ptr<SketchAPI_Line> addLine(const std::string & theExternalName);
163
164   /// Add rectangle
165   SKETCHAPI_EXPORT
166   std::shared_ptr<SketchAPI_Rectangle> addRectangle(
167       double theX1, double theY1, double theX2, double theY2);
168   /// Add rectangle
169   SKETCHAPI_EXPORT
170   std::shared_ptr<SketchAPI_Rectangle> addRectangle(
171       const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
172       const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
173
174   /// Add circle
175   SKETCHAPI_EXPORT
176   std::shared_ptr<SketchAPI_Circle> addCircle(
177       double theCenterX, double theCenterY,
178       double theRadius);
179   /// Add circle
180   SKETCHAPI_EXPORT
181   std::shared_ptr<SketchAPI_Circle> addCircle(
182       const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
183       double theRadius);
184   /// Add circle
185   SKETCHAPI_EXPORT
186   std::shared_ptr<SketchAPI_MacroCircle> addCircle(
187       double theCenterX, double theCenterY,
188       double thePassedX, double thePassedY);
189   /// Add circle
190   SKETCHAPI_EXPORT
191   std::shared_ptr<SketchAPI_MacroCircle> addCircle(
192       const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
193       const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
194   /// Add circle
195   SKETCHAPI_EXPORT
196   std::shared_ptr<SketchAPI_MacroCircle> addCircle(
197       double theX1, double theY1,
198       double theX2, double theY2,
199       double theX3, double theY3);
200   /// Add circle
201   SKETCHAPI_EXPORT
202   std::shared_ptr<SketchAPI_MacroCircle> addCircle(
203       const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
204       const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
205       const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
206   /// Add circle
207   SKETCHAPI_EXPORT
208   std::shared_ptr<SketchAPI_Circle> addCircle(const ModelHighAPI_Selection & theExternal);
209   /// Add circle
210   SKETCHAPI_EXPORT
211   std::shared_ptr<SketchAPI_Circle> addCircle(const std::string & theExternalName);
212
213   /// Add arc
214   SKETCHAPI_EXPORT
215   std::shared_ptr<SketchAPI_Arc> addArc(
216       double theCenterX, double theCenterY,
217       double theStartX, double theStartY,
218       double theEndX, double theEndY,
219       bool theInversed);
220
221   /// Add arc
222   SKETCHAPI_EXPORT
223   std::shared_ptr<SketchAPI_Arc> addArc(
224       const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
225       const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
226       const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
227       bool theInversed);
228
229   /// Add arc
230   SKETCHAPI_EXPORT
231   std::shared_ptr<SketchAPI_MacroArc> addArc(
232       double theStartX, double theStartY,
233       double theEndX, double theEndY,
234       double thePassedX, double thePassedY);
235
236   /// Add arc
237   SKETCHAPI_EXPORT
238   std::shared_ptr<SketchAPI_MacroArc> addArc(
239       const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
240       const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
241       const std::shared_ptr<GeomAPI_Pnt2d>& thePassed);
242
243   /// Add arc
244   SKETCHAPI_EXPORT
245   std::shared_ptr<SketchAPI_MacroArc> addArc(
246       const ModelHighAPI_RefAttr& theTangentPoint,
247       double theEndX, double theEndY,
248       bool theInversed);
249
250   /// Add arc
251   SKETCHAPI_EXPORT
252   std::shared_ptr<SketchAPI_MacroArc> addArc(
253       const ModelHighAPI_RefAttr& theTangentPoint,
254       const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
255       bool theInversed);
256
257   /// Add arc
258   SKETCHAPI_EXPORT
259   std::shared_ptr<SketchAPI_Arc> addArc(const ModelHighAPI_Selection & theExternal);
260
261   /// Add arc
262   SKETCHAPI_EXPORT
263   std::shared_ptr<SketchAPI_Arc> addArc(const std::string & theExternalName);
264
265   /// Add projection
266   SKETCHAPI_EXPORT
267   std::shared_ptr<SketchAPI_Projection> addProjection(
268       const ModelHighAPI_Selection & theExternalFeature,
269       bool theKeepResult = false);
270
271   /// Add projection
272   SKETCHAPI_EXPORT
273   std::shared_ptr<SketchAPI_Projection> addProjection(const std::string & theExternalName,
274                                                       bool theKeepResult = false);
275
276   /// Add mirror
277   SKETCHAPI_EXPORT
278   std::shared_ptr<SketchAPI_Mirror> addMirror(
279       const ModelHighAPI_RefAttr & theMirrorLine,
280       const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects);
281
282   /// Add translation
283   SKETCHAPI_EXPORT
284   std::shared_ptr<SketchAPI_Translation> addTranslation(
285       const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
286       const ModelHighAPI_RefAttr & thePoint1,
287       const ModelHighAPI_RefAttr & thePoint2,
288       const ModelHighAPI_Integer & theNumberOfObjects,
289       bool theFullValue = false);
290
291   /// Add rotation
292   SKETCHAPI_EXPORT
293   std::shared_ptr<SketchAPI_Rotation> addRotation(
294       const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
295       const ModelHighAPI_RefAttr & theCenter,
296       const ModelHighAPI_Double & theAngle,
297       const ModelHighAPI_Integer & theNumberOfObjects,
298       bool theFullValue = false,
299       bool theReversed  = false);
300
301   /// Add split
302   SKETCHAPI_EXPORT
303   std::shared_ptr<ModelHighAPI_Interface> addSplit(
304       const ModelHighAPI_Reference& theFeature,
305       const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
306
307   /// Add trim
308   SKETCHAPI_EXPORT
309   std::shared_ptr<ModelHighAPI_Interface> addTrim(
310       const ModelHighAPI_Reference& theFeature,
311       const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
312
313   /// Set angle
314   SKETCHAPI_EXPORT
315   std::shared_ptr<ModelHighAPI_Interface> setAngle(
316       const ModelHighAPI_RefAttr & theLine1,
317       const ModelHighAPI_RefAttr & theLine2,
318       const ModelHighAPI_Double & theValue);
319
320   /// Set complementary angle
321   SKETCHAPI_EXPORT
322   std::shared_ptr<ModelHighAPI_Interface> setAngleComplementary(
323       const ModelHighAPI_RefAttr & theLine1,
324       const ModelHighAPI_RefAttr & theLine2,
325       const ModelHighAPI_Double & theValue);
326
327   /// Set backward angle (= 360 - angle)
328   SKETCHAPI_EXPORT
329   std::shared_ptr<ModelHighAPI_Interface> setAngleBackward(
330       const ModelHighAPI_RefAttr & theLine1,
331       const ModelHighAPI_RefAttr & theLine2,
332       const ModelHighAPI_Double & theValue);
333
334   /// Set coincident
335   SKETCHAPI_EXPORT
336   std::shared_ptr<ModelHighAPI_Interface> setCoincident(
337       const ModelHighAPI_RefAttr & thePoint1,
338       const ModelHighAPI_RefAttr & thePoint2);
339
340   /// Set collinear
341   SKETCHAPI_EXPORT
342   std::shared_ptr<ModelHighAPI_Interface> setCollinear(
343       const ModelHighAPI_RefAttr & theLine1,
344       const ModelHighAPI_RefAttr & theLine2);
345
346   /// Set distance
347   SKETCHAPI_EXPORT
348   std::shared_ptr<ModelHighAPI_Interface> setDistance(
349       const ModelHighAPI_RefAttr & thePoint,
350       const ModelHighAPI_RefAttr & thePointOrLine,
351       const ModelHighAPI_Double & theValue,
352       bool isSigned = false);
353
354   /// Set signed distance
355   SKETCHAPI_EXPORT
356   std::shared_ptr<ModelHighAPI_Interface> setSignedDistance(
357       const ModelHighAPI_RefAttr & thePoint,
358       const ModelHighAPI_RefAttr & thePointOrLine,
359       const ModelHighAPI_Double & theValue);
360
361   /// Set unsigned distance
362   SKETCHAPI_EXPORT
363   std::shared_ptr<ModelHighAPI_Interface> setUnsignedDistance(
364       const ModelHighAPI_RefAttr & thePoint,
365       const ModelHighAPI_RefAttr & thePointOrLine,
366       const ModelHighAPI_Double & theValue);
367
368   /// Set horizontal distance
369   SKETCHAPI_EXPORT
370   std::shared_ptr<ModelHighAPI_Interface> setHorizontalDistance(
371       const ModelHighAPI_RefAttr & thePoint1,
372       const ModelHighAPI_RefAttr & thePoint2,
373       const ModelHighAPI_Double & theValue);
374
375   /// Set vertical distance
376   SKETCHAPI_EXPORT
377   std::shared_ptr<ModelHighAPI_Interface> setVerticalDistance(
378       const ModelHighAPI_RefAttr & thePoint1,
379       const ModelHighAPI_RefAttr & thePoint2,
380       const ModelHighAPI_Double & theValue);
381
382   /// Set equal
383   SKETCHAPI_EXPORT
384   std::shared_ptr<ModelHighAPI_Interface> setEqual(
385       const ModelHighAPI_RefAttr & theObject1,
386       const ModelHighAPI_RefAttr & theObject2);
387
388   /// Set fillet
389   SKETCHAPI_EXPORT
390   std::shared_ptr<ModelHighAPI_Interface> setFillet(
391       const ModelHighAPI_RefAttr & thePoint);
392
393   /// Set fillet with additional radius constraint
394   SKETCHAPI_EXPORT
395   std::shared_ptr<ModelHighAPI_Interface> setFilletWithRadius(
396       const ModelHighAPI_RefAttr & thePoint,
397       const ModelHighAPI_Double & theRadius);
398
399   /// Set fixed
400   SKETCHAPI_EXPORT
401   std::shared_ptr<ModelHighAPI_Interface> setFixed(
402       const ModelHighAPI_RefAttr & theObject);
403
404   /// Set horizontal
405   SKETCHAPI_EXPORT
406   std::shared_ptr<ModelHighAPI_Interface> setHorizontal(
407       const ModelHighAPI_RefAttr & theLine);
408
409   /// Set length
410   SKETCHAPI_EXPORT
411   std::shared_ptr<ModelHighAPI_Interface> setLength(
412       const ModelHighAPI_RefAttr & theLine,
413       const ModelHighAPI_Double & theValue);
414
415   /// Set middle
416   SKETCHAPI_EXPORT
417   std::shared_ptr<ModelHighAPI_Interface> setMiddlePoint(
418       const ModelHighAPI_RefAttr & thePoint,
419       const ModelHighAPI_RefAttr & theLine);
420
421   /// Set parallel
422   SKETCHAPI_EXPORT
423   std::shared_ptr<ModelHighAPI_Interface> setParallel(
424       const ModelHighAPI_RefAttr & theLine1,
425       const ModelHighAPI_RefAttr & theLine2);
426
427   /// Set perpendicular
428   SKETCHAPI_EXPORT
429   std::shared_ptr<ModelHighAPI_Interface> setPerpendicular(
430       const ModelHighAPI_RefAttr & theLine1,
431       const ModelHighAPI_RefAttr & theLine2);
432
433   /// Set radius
434   SKETCHAPI_EXPORT
435   std::shared_ptr<ModelHighAPI_Interface> setRadius(
436       const ModelHighAPI_RefAttr & theCircleOrArc,
437       const ModelHighAPI_Double & theValue);
438
439   /// Set tangent
440   SKETCHAPI_EXPORT
441   std::shared_ptr<ModelHighAPI_Interface> setTangent(
442       const ModelHighAPI_RefAttr & theLine,
443       const ModelHighAPI_RefAttr & theCircle);
444
445   /// Set vertical
446   SKETCHAPI_EXPORT
447   std::shared_ptr<ModelHighAPI_Interface> setVertical(
448       const ModelHighAPI_RefAttr & theLine);
449
450   /// Set constraint value
451   SKETCHAPI_EXPORT
452   void setValue(
453       const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
454       const ModelHighAPI_Double & theValue);
455
456   /// Move point or sketch feature
457   SKETCHAPI_EXPORT
458   void move(const ModelHighAPI_RefAttr& theMovedEntity,
459             const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint);
460
461   /// Move point or sketch feature
462   SKETCHAPI_EXPORT
463   void move(const ModelHighAPI_RefAttr& theMovedEntity,
464             double theTargetX, double theTargetY);
465
466   SKETCHAPI_EXPORT
467   std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
468
469   // TODO(spo): rename to selectFaces() or faces() (or add faces() -> list to SWIG)
470   /// Select face
471   SKETCHAPI_EXPORT
472   std::list<ModelHighAPI_Selection> selectFace() const;
473
474   /// Dump wrapped feature
475   SKETCHAPI_EXPORT
476   virtual void dump(ModelHighAPI_Dumper& theDumper) const;
477
478 protected:
479   std::shared_ptr<ModelAPI_CompositeFeature> compositeFeature() const;
480
481 };
482
483 //! Pointer on Sketch object
484 typedef std::shared_ptr<SketchAPI_Sketch> SketchPtr;
485
486 /**\ingroup CPPHighAPI
487  * \brief Create Sketch feature
488  */
489 SKETCHAPI_EXPORT
490 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
491                     const std::shared_ptr<GeomAPI_Ax3> & thePlane);
492
493 /**\ingroup CPPHighAPI
494  * \brief Create Sketch feature
495  */
496 SKETCHAPI_EXPORT
497 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
498                     const ModelHighAPI_Selection & theExternal);
499
500 /**\ingroup CPPHighAPI
501  * \brief Create Sketch feature
502  */
503 SKETCHAPI_EXPORT
504 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
505                     const std::string & theExternalName);
506
507 /**\ingroup CPPHighAPI
508  * \brief Create Sketch feature
509  */
510 SKETCHAPI_EXPORT
511 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
512                     std::shared_ptr<ModelAPI_Object> thePlaneObject);
513
514 //--------------------------------------------------------------------------------------
515 //--------------------------------------------------------------------------------------
516 #endif /* SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_ */