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