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