Salome HOME
Merge branch 'task_5_2_4' 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   /// List points not connected by constraints with other sketch entitites
115   SKETCHAPI_EXPORT
116   std::list< std::shared_ptr<SketchAPI_Point> > getFreePoints();
117
118   /// Add point
119   SKETCHAPI_EXPORT
120   std::shared_ptr<SketchAPI_Point> addPoint(
121       double theX, double theY);
122   /// Add point
123   SKETCHAPI_EXPORT
124   std::shared_ptr<SketchAPI_Point> addPoint(
125       const std::shared_ptr<GeomAPI_Pnt2d> & thePoint);
126   /// Add point
127   SKETCHAPI_EXPORT
128   std::shared_ptr<SketchAPI_Point> addPoint(const ModelHighAPI_Selection & theExternal);
129   /// Add point
130   SKETCHAPI_EXPORT
131   std::shared_ptr<SketchAPI_Point> addPoint(const std::string & theExternalName);
132
133   /// Add intersection point
134   SKETCHAPI_EXPORT
135   std::shared_ptr<SketchAPI_IntersectionPoint>
136     addIntersectionPoint(const ModelHighAPI_Selection & theExternal,
137                          bool theKeepResult = false);
138   /// Add point
139   SKETCHAPI_EXPORT
140   std::shared_ptr<SketchAPI_IntersectionPoint>
141     addIntersectionPoint(const std::string & theExternalName,
142                          bool theKeepResult = false);
143
144   /// Add line
145   SKETCHAPI_EXPORT
146   std::shared_ptr<SketchAPI_Line> addLine(
147       double theX1, double theY1, double theX2, double theY2);
148   /// Add line
149   SKETCHAPI_EXPORT
150   std::shared_ptr<SketchAPI_Line> addLine(
151       const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
152       const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
153   /// Add line
154   SKETCHAPI_EXPORT
155   std::shared_ptr<SketchAPI_Line> addLine(const ModelHighAPI_Selection & theExternal);
156   /// Add line
157   SKETCHAPI_EXPORT
158   std::shared_ptr<SketchAPI_Line> addLine(const std::string & theExternalName);
159
160   /// Add rectangle
161   SKETCHAPI_EXPORT
162   std::shared_ptr<SketchAPI_Rectangle> addRectangle(
163       double theX1, double theY1, double theX2, double theY2);
164   /// Add rectangle
165   SKETCHAPI_EXPORT
166   std::shared_ptr<SketchAPI_Rectangle> addRectangle(
167       const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
168       const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
169
170   /// Add circle
171   SKETCHAPI_EXPORT
172   std::shared_ptr<SketchAPI_Circle> addCircle(
173       double theCenterX, double theCenterY,
174       double theRadius);
175   /// Add circle
176   SKETCHAPI_EXPORT
177   std::shared_ptr<SketchAPI_Circle> addCircle(
178       const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
179       double theRadius);
180   /// Add circle
181   SKETCHAPI_EXPORT
182   std::shared_ptr<SketchAPI_MacroCircle> addCircle(
183       double theCenterX, double theCenterY,
184       double thePassedX, double thePassedY);
185   /// Add circle
186   SKETCHAPI_EXPORT
187   std::shared_ptr<SketchAPI_MacroCircle> addCircle(
188       const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
189       const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
190   /// Add circle
191   SKETCHAPI_EXPORT
192   std::shared_ptr<SketchAPI_MacroCircle> addCircle(
193       double theX1, double theY1,
194       double theX2, double theY2,
195       double theX3, double theY3);
196   /// Add circle
197   SKETCHAPI_EXPORT
198   std::shared_ptr<SketchAPI_MacroCircle> addCircle(
199       const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
200       const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
201       const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
202   /// Add circle
203   SKETCHAPI_EXPORT
204   std::shared_ptr<SketchAPI_Circle> addCircle(const ModelHighAPI_Selection & theExternal);
205   /// Add circle
206   SKETCHAPI_EXPORT
207   std::shared_ptr<SketchAPI_Circle> addCircle(const std::string & theExternalName);
208
209   /// Add arc
210   SKETCHAPI_EXPORT
211   std::shared_ptr<SketchAPI_Arc> addArc(
212       double theCenterX, double theCenterY,
213       double theStartX, double theStartY,
214       double theEndX, double theEndY,
215       bool theInversed);
216
217   /// Add arc
218   SKETCHAPI_EXPORT
219   std::shared_ptr<SketchAPI_Arc> addArc(
220       const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
221       const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
222       const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
223       bool theInversed);
224
225   /// Add arc
226   SKETCHAPI_EXPORT
227   std::shared_ptr<SketchAPI_MacroArc> addArc(
228       double theStartX, double theStartY,
229       double theEndX, double theEndY,
230       double thePassedX, double thePassedY);
231
232   /// Add arc
233   SKETCHAPI_EXPORT
234   std::shared_ptr<SketchAPI_MacroArc> addArc(
235       const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
236       const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
237       const std::shared_ptr<GeomAPI_Pnt2d>& thePassed);
238
239   /// Add transversal/tangent arc
240   SKETCHAPI_EXPORT
241   std::shared_ptr<SketchAPI_MacroArc> addArc(
242       const ModelHighAPI_RefAttr& theConnectedPoint,
243       double theEndX, double theEndY,
244       bool theInversed,
245       bool theTransversal = false);
246
247   /// Add transversal/tangent arc
248   SKETCHAPI_EXPORT
249   std::shared_ptr<SketchAPI_MacroArc> addArc(
250       const ModelHighAPI_RefAttr& theConnectedPoint,
251       const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
252       bool theInversed,
253       bool theTransversal = false);
254
255   /// Add arc
256   SKETCHAPI_EXPORT
257   std::shared_ptr<SketchAPI_Arc> addArc(const ModelHighAPI_Selection & theExternal);
258
259   /// Add arc
260   SKETCHAPI_EXPORT
261   std::shared_ptr<SketchAPI_Arc> addArc(const std::string & theExternalName);
262
263   /// Add projection
264   SKETCHAPI_EXPORT
265   std::shared_ptr<SketchAPI_Projection> addProjection(
266       const ModelHighAPI_Selection & theExternalFeature,
267       bool theKeepResult = false);
268
269   /// Add projection
270   SKETCHAPI_EXPORT
271   std::shared_ptr<SketchAPI_Projection> addProjection(const std::string & theExternalName,
272                                                       bool theKeepResult = false);
273
274   /// Add mirror
275   SKETCHAPI_EXPORT
276   std::shared_ptr<SketchAPI_Mirror> addMirror(
277       const ModelHighAPI_RefAttr & theMirrorLine,
278       const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects);
279
280   /// Add translation
281   SKETCHAPI_EXPORT
282   std::shared_ptr<SketchAPI_Translation> addTranslation(
283       const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
284       const ModelHighAPI_RefAttr & thePoint1,
285       const ModelHighAPI_RefAttr & thePoint2,
286       const ModelHighAPI_Integer & theNumberOfObjects,
287       bool theFullValue = false);
288
289   /// Add rotation
290   SKETCHAPI_EXPORT
291   std::shared_ptr<SketchAPI_Rotation> addRotation(
292       const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
293       const ModelHighAPI_RefAttr & theCenter,
294       const ModelHighAPI_Double & theAngle,
295       const ModelHighAPI_Integer & theNumberOfObjects,
296       bool theFullValue = false,
297       bool theReversed  = false);
298
299   /// Add split
300   SKETCHAPI_EXPORT
301   std::shared_ptr<ModelHighAPI_Interface> addSplit(
302       const ModelHighAPI_Reference& theFeature,
303       const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
304
305   /// Add trim
306   SKETCHAPI_EXPORT
307   std::shared_ptr<ModelHighAPI_Interface> addTrim(
308       const ModelHighAPI_Reference& theFeature,
309       const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
310
311   /// Set angle
312   SKETCHAPI_EXPORT
313   std::shared_ptr<ModelHighAPI_Interface> setAngle(
314       const ModelHighAPI_RefAttr & theLine1,
315       const ModelHighAPI_RefAttr & theLine2,
316       const ModelHighAPI_Double & theValue);
317
318   /// Set complementary angle
319   SKETCHAPI_EXPORT
320   std::shared_ptr<ModelHighAPI_Interface> setAngleComplementary(
321       const ModelHighAPI_RefAttr & theLine1,
322       const ModelHighAPI_RefAttr & theLine2,
323       const ModelHighAPI_Double & theValue);
324
325   /// Set backward angle (= 360 - angle)
326   SKETCHAPI_EXPORT
327   std::shared_ptr<ModelHighAPI_Interface> setAngleBackward(
328       const ModelHighAPI_RefAttr & theLine1,
329       const ModelHighAPI_RefAttr & theLine2,
330       const ModelHighAPI_Double & theValue);
331
332   /// Set coincident
333   SKETCHAPI_EXPORT
334   std::shared_ptr<ModelHighAPI_Interface> setCoincident(
335       const ModelHighAPI_RefAttr & thePoint1,
336       const ModelHighAPI_RefAttr & thePoint2);
337
338   /// Set collinear
339   SKETCHAPI_EXPORT
340   std::shared_ptr<ModelHighAPI_Interface> setCollinear(
341       const ModelHighAPI_RefAttr & theLine1,
342       const ModelHighAPI_RefAttr & theLine2);
343
344   /// Set distance
345   SKETCHAPI_EXPORT
346   std::shared_ptr<ModelHighAPI_Interface> setDistance(
347       const ModelHighAPI_RefAttr & thePoint,
348       const ModelHighAPI_RefAttr & thePointOrLine,
349       const ModelHighAPI_Double & theValue,
350       bool isSigned = false);
351
352   /// Set signed distance
353   SKETCHAPI_EXPORT
354   std::shared_ptr<ModelHighAPI_Interface> setSignedDistance(
355       const ModelHighAPI_RefAttr & thePoint,
356       const ModelHighAPI_RefAttr & thePointOrLine,
357       const ModelHighAPI_Double & theValue);
358
359   /// Set unsigned distance
360   SKETCHAPI_EXPORT
361   std::shared_ptr<ModelHighAPI_Interface> setUnsignedDistance(
362       const ModelHighAPI_RefAttr & thePoint,
363       const ModelHighAPI_RefAttr & thePointOrLine,
364       const ModelHighAPI_Double & theValue);
365
366   /// Set horizontal distance
367   SKETCHAPI_EXPORT
368   std::shared_ptr<ModelHighAPI_Interface> setHorizontalDistance(
369       const ModelHighAPI_RefAttr & thePoint1,
370       const ModelHighAPI_RefAttr & thePoint2,
371       const ModelHighAPI_Double & theValue);
372
373   /// Set vertical distance
374   SKETCHAPI_EXPORT
375   std::shared_ptr<ModelHighAPI_Interface> setVerticalDistance(
376       const ModelHighAPI_RefAttr & thePoint1,
377       const ModelHighAPI_RefAttr & thePoint2,
378       const ModelHighAPI_Double & theValue);
379
380   /// Set equal
381   SKETCHAPI_EXPORT
382   std::shared_ptr<ModelHighAPI_Interface> setEqual(
383       const ModelHighAPI_RefAttr & theObject1,
384       const ModelHighAPI_RefAttr & theObject2);
385
386   /// Set fillet
387   SKETCHAPI_EXPORT
388   std::shared_ptr<ModelHighAPI_Interface> setFillet(
389       const ModelHighAPI_RefAttr & thePoint);
390
391   /// Set fillet with additional radius constraint
392   SKETCHAPI_EXPORT
393   std::shared_ptr<ModelHighAPI_Interface> setFilletWithRadius(
394       const ModelHighAPI_RefAttr & thePoint,
395       const ModelHighAPI_Double & theRadius);
396
397   /// Set fixed
398   SKETCHAPI_EXPORT
399   std::shared_ptr<ModelHighAPI_Interface> setFixed(
400       const ModelHighAPI_RefAttr & theObject);
401
402   /// Set horizontal
403   SKETCHAPI_EXPORT
404   std::shared_ptr<ModelHighAPI_Interface> setHorizontal(
405       const ModelHighAPI_RefAttr & theLine);
406
407   /// Set length
408   SKETCHAPI_EXPORT
409   std::shared_ptr<ModelHighAPI_Interface> setLength(
410       const ModelHighAPI_RefAttr & theLine,
411       const ModelHighAPI_Double & theValue);
412
413   /// Set middle
414   SKETCHAPI_EXPORT
415   std::shared_ptr<ModelHighAPI_Interface> setMiddlePoint(
416       const ModelHighAPI_RefAttr & thePoint,
417       const ModelHighAPI_RefAttr & theLine);
418
419   /// Set parallel
420   SKETCHAPI_EXPORT
421   std::shared_ptr<ModelHighAPI_Interface> setParallel(
422       const ModelHighAPI_RefAttr & theLine1,
423       const ModelHighAPI_RefAttr & theLine2);
424
425   /// Set perpendicular
426   SKETCHAPI_EXPORT
427   std::shared_ptr<ModelHighAPI_Interface> setPerpendicular(
428       const ModelHighAPI_RefAttr & theLine1,
429       const ModelHighAPI_RefAttr & theLine2);
430
431   /// Set radius
432   SKETCHAPI_EXPORT
433   std::shared_ptr<ModelHighAPI_Interface> setRadius(
434       const ModelHighAPI_RefAttr & theCircleOrArc,
435       const ModelHighAPI_Double & theValue);
436
437   /// Set tangent
438   SKETCHAPI_EXPORT
439   std::shared_ptr<ModelHighAPI_Interface> setTangent(
440       const ModelHighAPI_RefAttr & theLine,
441       const ModelHighAPI_RefAttr & theCircle);
442
443   /// Set vertical
444   SKETCHAPI_EXPORT
445   std::shared_ptr<ModelHighAPI_Interface> setVertical(
446       const ModelHighAPI_RefAttr & theLine);
447
448   /// Set constraint value
449   SKETCHAPI_EXPORT
450   void setValue(
451       const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
452       const ModelHighAPI_Double & theValue);
453
454   /// Move point or sketch feature
455   SKETCHAPI_EXPORT
456   void move(const ModelHighAPI_RefAttr& theMovedEntity,
457             const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint);
458
459   /// Move point or sketch feature
460   SKETCHAPI_EXPORT
461   void move(const ModelHighAPI_RefAttr& theMovedEntity,
462             double theTargetX, double theTargetY);
463
464   SKETCHAPI_EXPORT
465   std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
466
467   // TODO(spo): rename to selectFaces() or faces() (or add faces() -> list to SWIG)
468   /// Select face
469   SKETCHAPI_EXPORT
470   std::list<ModelHighAPI_Selection> selectFace() const;
471
472   /// Dump wrapped feature
473   SKETCHAPI_EXPORT
474   virtual void dump(ModelHighAPI_Dumper& theDumper) const;
475
476 protected:
477   std::shared_ptr<ModelAPI_CompositeFeature> compositeFeature() const;
478
479 };
480
481 //! Pointer on Sketch object
482 typedef std::shared_ptr<SketchAPI_Sketch> SketchPtr;
483
484 /**\ingroup CPPHighAPI
485  * \brief Create Sketch feature
486  */
487 SKETCHAPI_EXPORT
488 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
489                     const std::shared_ptr<GeomAPI_Ax3> & thePlane);
490
491 /**\ingroup CPPHighAPI
492  * \brief Create Sketch feature
493  */
494 SKETCHAPI_EXPORT
495 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
496                     const ModelHighAPI_Selection & theExternal);
497
498 /**\ingroup CPPHighAPI
499  * \brief Create Sketch feature
500  */
501 SKETCHAPI_EXPORT
502 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
503                     const std::string & theExternalName);
504
505 /**\ingroup CPPHighAPI
506  * \brief Create Sketch feature
507  */
508 SKETCHAPI_EXPORT
509 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
510                     std::shared_ptr<ModelAPI_Object> thePlaneObject);
511
512 //--------------------------------------------------------------------------------------
513 //--------------------------------------------------------------------------------------
514 #endif /* SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_ */