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