Salome HOME
Merge remote-tracking branch 'remotes/origin/master' into CEA_2019
[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 transversal/tangent arc
244   SKETCHAPI_EXPORT
245   std::shared_ptr<SketchAPI_MacroArc> addArc(
246       const ModelHighAPI_RefAttr& theConnectedPoint,
247       double theEndX, double theEndY,
248       bool theInversed,
249       bool theTransversal = false);
250
251   /// Add transversal/tangent arc
252   SKETCHAPI_EXPORT
253   std::shared_ptr<SketchAPI_MacroArc> addArc(
254       const ModelHighAPI_RefAttr& theConnectedPoint,
255       const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
256       bool theInversed,
257       bool theTransversal = false);
258
259   /// Add arc
260   SKETCHAPI_EXPORT
261   std::shared_ptr<SketchAPI_Arc> addArc(const ModelHighAPI_Selection & theExternal);
262
263   /// Add arc
264   SKETCHAPI_EXPORT
265   std::shared_ptr<SketchAPI_Arc> addArc(const std::string & theExternalName);
266
267   /// Add projection
268   SKETCHAPI_EXPORT
269   std::shared_ptr<SketchAPI_Projection> addProjection(
270       const ModelHighAPI_Selection & theExternalFeature,
271       bool theKeepResult = false);
272
273   /// Add projection
274   SKETCHAPI_EXPORT
275   std::shared_ptr<SketchAPI_Projection> addProjection(const std::string & theExternalName,
276                                                       bool theKeepResult = false);
277
278   /// Add mirror
279   SKETCHAPI_EXPORT
280   std::shared_ptr<SketchAPI_Mirror> addMirror(
281       const ModelHighAPI_RefAttr & theMirrorLine,
282       const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects);
283
284   /// Add translation
285   SKETCHAPI_EXPORT
286   std::shared_ptr<SketchAPI_Translation> addTranslation(
287       const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
288       const ModelHighAPI_RefAttr & thePoint1,
289       const ModelHighAPI_RefAttr & thePoint2,
290       const ModelHighAPI_Integer & theNumberOfObjects,
291       bool theFullValue = false);
292
293   /// Add rotation
294   SKETCHAPI_EXPORT
295   std::shared_ptr<SketchAPI_Rotation> addRotation(
296       const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
297       const ModelHighAPI_RefAttr & theCenter,
298       const ModelHighAPI_Double & theAngle,
299       const ModelHighAPI_Integer & theNumberOfObjects,
300       bool theFullValue = false,
301       bool theReversed  = false);
302
303   /// Add split
304   SKETCHAPI_EXPORT
305   std::shared_ptr<ModelHighAPI_Interface> addSplit(
306       const ModelHighAPI_Reference& theFeature,
307       const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
308
309   /// Add trim
310   SKETCHAPI_EXPORT
311   std::shared_ptr<ModelHighAPI_Interface> addTrim(
312       const ModelHighAPI_Reference& theFeature,
313       const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
314
315   /// Set angle
316   SKETCHAPI_EXPORT
317   std::shared_ptr<ModelHighAPI_Interface> setAngle(
318       const ModelHighAPI_RefAttr & theLine1,
319       const ModelHighAPI_RefAttr & theLine2,
320       const ModelHighAPI_Double & theValue);
321
322   /// Set complementary angle
323   SKETCHAPI_EXPORT
324   std::shared_ptr<ModelHighAPI_Interface> setAngleComplementary(
325       const ModelHighAPI_RefAttr & theLine1,
326       const ModelHighAPI_RefAttr & theLine2,
327       const ModelHighAPI_Double & theValue);
328
329   /// Set backward angle (= 360 - angle)
330   SKETCHAPI_EXPORT
331   std::shared_ptr<ModelHighAPI_Interface> setAngleBackward(
332       const ModelHighAPI_RefAttr & theLine1,
333       const ModelHighAPI_RefAttr & theLine2,
334       const ModelHighAPI_Double & theValue);
335
336   /// Set coincident
337   SKETCHAPI_EXPORT
338   std::shared_ptr<ModelHighAPI_Interface> setCoincident(
339       const ModelHighAPI_RefAttr & thePoint1,
340       const ModelHighAPI_RefAttr & thePoint2);
341
342   /// Set collinear
343   SKETCHAPI_EXPORT
344   std::shared_ptr<ModelHighAPI_Interface> setCollinear(
345       const ModelHighAPI_RefAttr & theLine1,
346       const ModelHighAPI_RefAttr & theLine2);
347
348   /// Set distance
349   SKETCHAPI_EXPORT
350   std::shared_ptr<ModelHighAPI_Interface> setDistance(
351       const ModelHighAPI_RefAttr & thePoint,
352       const ModelHighAPI_RefAttr & thePointOrLine,
353       const ModelHighAPI_Double & theValue,
354       bool isSigned = false);
355
356   /// Set signed distance
357   SKETCHAPI_EXPORT
358   std::shared_ptr<ModelHighAPI_Interface> setSignedDistance(
359       const ModelHighAPI_RefAttr & thePoint,
360       const ModelHighAPI_RefAttr & thePointOrLine,
361       const ModelHighAPI_Double & theValue);
362
363   /// Set unsigned distance
364   SKETCHAPI_EXPORT
365   std::shared_ptr<ModelHighAPI_Interface> setUnsignedDistance(
366       const ModelHighAPI_RefAttr & thePoint,
367       const ModelHighAPI_RefAttr & thePointOrLine,
368       const ModelHighAPI_Double & theValue);
369
370   /// Set horizontal distance
371   SKETCHAPI_EXPORT
372   std::shared_ptr<ModelHighAPI_Interface> setHorizontalDistance(
373       const ModelHighAPI_RefAttr & thePoint1,
374       const ModelHighAPI_RefAttr & thePoint2,
375       const ModelHighAPI_Double & theValue);
376
377   /// Set vertical distance
378   SKETCHAPI_EXPORT
379   std::shared_ptr<ModelHighAPI_Interface> setVerticalDistance(
380       const ModelHighAPI_RefAttr & thePoint1,
381       const ModelHighAPI_RefAttr & thePoint2,
382       const ModelHighAPI_Double & theValue);
383
384   /// Set equal
385   SKETCHAPI_EXPORT
386   std::shared_ptr<ModelHighAPI_Interface> setEqual(
387       const ModelHighAPI_RefAttr & theObject1,
388       const ModelHighAPI_RefAttr & theObject2);
389
390   /// Set fillet
391   SKETCHAPI_EXPORT
392   std::shared_ptr<ModelHighAPI_Interface> setFillet(
393       const ModelHighAPI_RefAttr & thePoint);
394
395   /// Set fillet with additional radius constraint
396   SKETCHAPI_EXPORT
397   std::shared_ptr<ModelHighAPI_Interface> setFilletWithRadius(
398       const ModelHighAPI_RefAttr & thePoint,
399       const ModelHighAPI_Double & theRadius);
400
401   /// Set fixed
402   SKETCHAPI_EXPORT
403   std::shared_ptr<ModelHighAPI_Interface> setFixed(
404       const ModelHighAPI_RefAttr & theObject);
405
406   /// Set horizontal
407   SKETCHAPI_EXPORT
408   std::shared_ptr<ModelHighAPI_Interface> setHorizontal(
409       const ModelHighAPI_RefAttr & theLine);
410
411   /// Set length
412   SKETCHAPI_EXPORT
413   std::shared_ptr<ModelHighAPI_Interface> setLength(
414       const ModelHighAPI_RefAttr & theLine,
415       const ModelHighAPI_Double & theValue);
416
417   /// Set middle
418   SKETCHAPI_EXPORT
419   std::shared_ptr<ModelHighAPI_Interface> setMiddlePoint(
420       const ModelHighAPI_RefAttr & thePoint,
421       const ModelHighAPI_RefAttr & theLine);
422
423   /// Set parallel
424   SKETCHAPI_EXPORT
425   std::shared_ptr<ModelHighAPI_Interface> setParallel(
426       const ModelHighAPI_RefAttr & theLine1,
427       const ModelHighAPI_RefAttr & theLine2);
428
429   /// Set perpendicular
430   SKETCHAPI_EXPORT
431   std::shared_ptr<ModelHighAPI_Interface> setPerpendicular(
432       const ModelHighAPI_RefAttr & theLine1,
433       const ModelHighAPI_RefAttr & theLine2);
434
435   /// Set radius
436   SKETCHAPI_EXPORT
437   std::shared_ptr<ModelHighAPI_Interface> setRadius(
438       const ModelHighAPI_RefAttr & theCircleOrArc,
439       const ModelHighAPI_Double & theValue);
440
441   /// Set tangent
442   SKETCHAPI_EXPORT
443   std::shared_ptr<ModelHighAPI_Interface> setTangent(
444       const ModelHighAPI_RefAttr & theLine,
445       const ModelHighAPI_RefAttr & theCircle);
446
447   /// Set vertical
448   SKETCHAPI_EXPORT
449   std::shared_ptr<ModelHighAPI_Interface> setVertical(
450       const ModelHighAPI_RefAttr & theLine);
451
452   /// Set constraint value
453   SKETCHAPI_EXPORT
454   void setValue(
455       const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
456       const ModelHighAPI_Double & theValue);
457
458   /// Move point or sketch feature
459   SKETCHAPI_EXPORT
460   void move(const ModelHighAPI_RefAttr& theMovedEntity,
461             const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint);
462
463   /// Move point or sketch feature
464   SKETCHAPI_EXPORT
465   void move(const ModelHighAPI_RefAttr& theMovedEntity,
466             double theTargetX, double theTargetY);
467
468   SKETCHAPI_EXPORT
469   std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
470
471   // TODO(spo): rename to selectFaces() or faces() (or add faces() -> list to SWIG)
472   /// Select face
473   SKETCHAPI_EXPORT
474   std::list<ModelHighAPI_Selection> selectFace() const;
475
476   /// Dump wrapped feature
477   SKETCHAPI_EXPORT
478   virtual void dump(ModelHighAPI_Dumper& theDumper) const;
479
480 protected:
481   std::shared_ptr<ModelAPI_CompositeFeature> compositeFeature() const;
482
483 };
484
485 //! Pointer on Sketch object
486 typedef std::shared_ptr<SketchAPI_Sketch> SketchPtr;
487
488 /**\ingroup CPPHighAPI
489  * \brief Create Sketch feature
490  */
491 SKETCHAPI_EXPORT
492 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
493                     const std::shared_ptr<GeomAPI_Ax3> & thePlane);
494
495 /**\ingroup CPPHighAPI
496  * \brief Create Sketch feature
497  */
498 SKETCHAPI_EXPORT
499 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
500                     const ModelHighAPI_Selection & theExternal);
501
502 /**\ingroup CPPHighAPI
503  * \brief Create Sketch feature
504  */
505 SKETCHAPI_EXPORT
506 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
507                     const std::string & theExternalName);
508
509 /**\ingroup CPPHighAPI
510  * \brief Create Sketch feature
511  */
512 SKETCHAPI_EXPORT
513 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
514                     std::shared_ptr<ModelAPI_Object> thePlaneObject);
515
516 //--------------------------------------------------------------------------------------
517 //--------------------------------------------------------------------------------------
518 #endif /* SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_ */