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