1 // Copyright (C) 2014-2022 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_
21 #define SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_
23 //--------------------------------------------------------------------------------------
24 #include "SketchAPI.h"
28 #include <SketchPlugin_Sketch.h>
29 #include <SketchPlugin_SketchEntity.h>
30 #include <SketchPlugin_Offset.h>
32 #include <ModelHighAPI_Double.h>
33 #include <ModelHighAPI_Interface.h>
34 #include <ModelHighAPI_Macro.h>
35 #include <ModelHighAPI_Selection.h>
36 //--------------------------------------------------------------------------------------
37 class ModelAPI_CompositeFeature;
38 class ModelAPI_Object;
39 class ModelHighAPI_Integer;
40 class ModelHighAPI_RefAttr;
41 class ModelHighAPI_Reference;
43 class SketchAPI_MacroArc;
44 class SketchAPI_Circle;
45 class SketchAPI_MacroCircle;
46 class SketchAPI_Ellipse;
47 class SketchAPI_MacroEllipse;
48 class SketchAPI_EllipticArc;
49 class SketchAPI_MacroEllipticArc;
50 class SketchAPI_BSpline;
51 class SketchAPI_IntersectionPoint;
53 class SketchAPI_Mirror;
54 class SketchAPI_Offset;
55 class SketchAPI_Point;
56 class SketchAPI_Projection;
57 class SketchAPI_Rectangle;
58 class SketchAPI_Rotation;
59 class SketchAPI_Translation;
61 //--------------------------------------------------------------------------------------
62 typedef std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> PointOrReference;
63 //--------------------------------------------------------------------------------------
64 /**\class SketchAPI_Sketch
66 * \brief Interface for Sketch feature
68 class SketchAPI_Sketch : public ModelHighAPI_Interface
71 /// Constructor without values
73 explicit SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature);
74 /// Constructor with values
76 SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
77 const std::shared_ptr<GeomAPI_Ax3> & thePlane);
78 /// Constructor with values
80 SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
81 const ModelHighAPI_Selection & theExternal);
82 /// Constructor with values
84 SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
85 std::shared_ptr<ModelAPI_Object> thePlaneObject);
88 virtual ~SketchAPI_Sketch();
90 INTERFACE_7(SketchPlugin_Sketch::ID(),
91 origin, SketchPlugin_Sketch::ORIGIN_ID(),
92 GeomDataAPI_Point, /** Origin point */,
93 dirX, SketchPlugin_Sketch::DIRX_ID(),
94 GeomDataAPI_Dir, /** Direction of X */,
95 normal, SketchPlugin_Sketch::NORM_ID(),
96 GeomDataAPI_Dir, /** Normal */,
97 features, SketchPlugin_Sketch::FEATURES_ID(),
98 ModelAPI_AttributeRefList, /** Features */,
99 external, SketchPlugin_SketchEntity::EXTERNAL_ID(),
100 ModelAPI_AttributeSelection, /** External */,
101 solverError, SketchPlugin_Sketch::SOLVER_ERROR(),
102 ModelAPI_AttributeString, /** Solver error */,
103 solverDOF, SketchPlugin_Sketch::SOLVER_DOF(),
104 ModelAPI_AttributeString, /** Solver DOF */
109 void setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane);
111 /// Change sketch plane
113 void setPlane(const ModelHighAPI_Selection & thePlane,
114 bool theRemoveExternalDependency = false);
118 void setExternal(const ModelHighAPI_Selection & theExternal);
122 void setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject);
124 /// Change order of sketch results (faces)
126 void changeFacesOrder(const std::list<std::list<ModelHighAPI_Selection> >& theFaces);
128 /// List points not connected by constraints with other sketch entitites
130 std::list< std::shared_ptr<SketchAPI_Point> > getFreePoints();
134 std::shared_ptr<SketchAPI_Point> addPoint(
135 double theX, double theY);
138 std::shared_ptr<SketchAPI_Point> addPoint(
139 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint);
142 std::shared_ptr<SketchAPI_Point> addPoint(const ModelHighAPI_Selection & theExternal);
145 std::shared_ptr<SketchAPI_Point> addPoint(const std::wstring & theExternalName);
147 /// Add intersection point
149 std::shared_ptr<SketchAPI_IntersectionPoint>
150 addIntersectionPoint(const ModelHighAPI_Selection & theExternal,
151 bool theKeepResult = false);
154 std::shared_ptr<SketchAPI_IntersectionPoint>
155 addIntersectionPoint(const std::wstring & theExternalName,
156 bool theKeepResult = false);
160 std::shared_ptr<SketchAPI_Line> addLine(
161 double theX1, double theY1, double theX2, double theY2);
164 std::shared_ptr<SketchAPI_Line> addLine(
165 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
166 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
169 std::shared_ptr<SketchAPI_Line> addLine(const ModelHighAPI_Selection & theExternal);
172 std::shared_ptr<SketchAPI_Line> addLine(const std::wstring & theExternalName);
176 std::shared_ptr<SketchAPI_Rectangle> addRectangle(
177 double theX1, double theY1, double theX2, double theY2);
180 std::shared_ptr<SketchAPI_Rectangle> addRectangle(
181 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
182 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
185 std::shared_ptr<SketchAPI_Rectangle> addRectangleCentered(
186 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theCenter,
187 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theCorner);
191 std::shared_ptr<SketchAPI_Circle> addCircle(
192 double theCenterX, double theCenterY,
196 std::shared_ptr<SketchAPI_Circle> addCircle(
197 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
201 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
202 double theCenterX, double theCenterY,
203 double thePassedX, double thePassedY);
206 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
207 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
208 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
211 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
212 double theX1, double theY1,
213 double theX2, double theY2,
214 double theX3, double theY3);
217 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
218 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
219 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
220 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
223 std::shared_ptr<SketchAPI_Circle> addCircle(const ModelHighAPI_Selection & theExternal);
226 std::shared_ptr<SketchAPI_Circle> addCircle(const std::wstring & theExternalName);
230 std::shared_ptr<SketchAPI_Arc> addArc(
231 double theCenterX, double theCenterY,
232 double theStartX, double theStartY,
233 double theEndX, double theEndY,
238 std::shared_ptr<SketchAPI_Arc> addArc(
239 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
240 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
241 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
246 std::shared_ptr<SketchAPI_MacroArc> addArc(
247 double theStartX, double theStartY,
248 double theEndX, double theEndY,
249 double thePassedX, double thePassedY);
253 std::shared_ptr<SketchAPI_MacroArc> addArc(
254 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
255 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
256 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed);
258 /// Add transversal/tangent arc
260 std::shared_ptr<SketchAPI_MacroArc> addArc(
261 const ModelHighAPI_RefAttr& theConnectedPoint,
262 double theEndX, double theEndY,
264 bool theTransversal = false);
266 /// Add transversal/tangent arc
268 std::shared_ptr<SketchAPI_MacroArc> addArc(
269 const ModelHighAPI_RefAttr& theConnectedPoint,
270 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
272 bool theTransversal = false);
276 std::shared_ptr<SketchAPI_Arc> addArc(const ModelHighAPI_Selection & theExternal);
280 std::shared_ptr<SketchAPI_Arc> addArc(const std::wstring & theExternalName);
284 std::shared_ptr<SketchAPI_Ellipse> addEllipse(
285 double theCenterX, double theCenterY,
286 double theFocusX, double theFocusY,
287 double theMinorRadius);
290 std::shared_ptr<SketchAPI_Ellipse> addEllipse(
291 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
292 const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
296 std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
297 double thePoint1X, double thePoint1Y,
298 double thePoint2X, double thePoint2Y,
299 double thePassedX, double thePassedY,
300 bool isPoint1Center = true);
303 std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
304 const PointOrReference& thePoint1,
305 const PointOrReference& thePoint2,
306 const PointOrReference& thePassedPoint,
307 bool isPoint1Center = true);
310 std::shared_ptr<SketchAPI_Ellipse> addEllipse(const ModelHighAPI_Selection & theExternal);
313 std::shared_ptr<SketchAPI_Ellipse> addEllipse(const std::wstring & theExternalName);
317 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(
318 double theCenterX, double theCenterY,
319 double theFocusX, double theFocusY,
320 double theStartX, double theStartY,
321 double theEndX, double theEndY,
322 bool theInversed = false);
325 std::shared_ptr<SketchAPI_MacroEllipticArc> addEllipticArc(
326 const PointOrReference& theCenter,
327 const PointOrReference& theMajorAxisPoint,
328 const PointOrReference& theStartPoint,
329 const PointOrReference& theEndPoint,
330 bool theInversed = false);
333 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(const ModelHighAPI_Selection & theExternal);
336 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(const std::wstring & theExternalName);
340 std::shared_ptr<SketchAPI_BSpline> addSpline(
341 const ModelHighAPI_Selection & external = ModelHighAPI_Selection(),
342 const int degree = -1,
343 const std::list<PointOrReference>& poles = std::list<PointOrReference>(),
344 const std::list<ModelHighAPI_Double>& weights = std::list<ModelHighAPI_Double>(),
345 const std::list<ModelHighAPI_Double>& knots = std::list<ModelHighAPI_Double>(),
346 const std::list<ModelHighAPI_Integer>& multiplicities = std::list<ModelHighAPI_Integer>(),
347 const bool periodic = false);
349 /// Add interpolation feature
351 std::shared_ptr<SketchAPI_BSpline> addInterpolation(
352 const std::list<ModelHighAPI_RefAttr>& points,
353 const bool periodic = false,
354 const bool closed = false);
356 /// Add approximation feature
358 std::shared_ptr<SketchAPI_BSpline> addApproximation(
359 const std::list<ModelHighAPI_RefAttr>& points,
360 const ModelHighAPI_Double& precision = ModelHighAPI_Double(1.e-3),
361 const bool periodic = false,
362 const bool closed = false);
366 std::shared_ptr<SketchAPI_Projection> addProjection(
367 const ModelHighAPI_Selection & theExternalFeature,
368 bool keepResult = false,
369 bool keepRefToOriginal = true);
373 std::shared_ptr<SketchAPI_Mirror> addMirror(
374 const ModelHighAPI_RefAttr & theMirrorLine,
375 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects);
379 std::shared_ptr<SketchAPI_Offset> addOffset(
380 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
381 const ModelHighAPI_Double & theValue,
382 const bool theReversed = false,
383 const std::string & theJointType = SketchPlugin_Offset::JOINT_KEEP_DISTANCE());
387 std::shared_ptr<SketchAPI_Translation> addTranslation(
388 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
389 const ModelHighAPI_RefAttr & thePoint1,
390 const ModelHighAPI_RefAttr & thePoint2,
391 const ModelHighAPI_Integer & theNumberOfObjects,
392 bool theFullValue = false);
396 std::shared_ptr<SketchAPI_Rotation> addRotation(
397 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
398 const ModelHighAPI_RefAttr & theCenter,
399 const ModelHighAPI_Double & theAngle,
400 const ModelHighAPI_Integer & theNumberOfObjects,
401 bool theFullValue = false,
402 bool theReversed = false);
406 std::shared_ptr<ModelHighAPI_Interface> addSplit(
407 const ModelHighAPI_Reference& theFeature,
408 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
412 std::shared_ptr<ModelHighAPI_Interface> addTrim(
413 const ModelHighAPI_Reference& theFeature,
414 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
418 std::shared_ptr<ModelHighAPI_Interface> setAngle(
419 const ModelHighAPI_RefAttr & theLine1,
420 const ModelHighAPI_RefAttr & theLine2,
421 const ModelHighAPI_Double & theValue,
422 const std::string& type = std::string());
424 /// Set complementary angle
426 std::shared_ptr<ModelHighAPI_Interface> setAngleComplementary(
427 const ModelHighAPI_RefAttr & theLine1,
428 const ModelHighAPI_RefAttr & theLine2,
429 const ModelHighAPI_Double & theValue);
431 /// Set backward angle (= 360 - angle)
433 std::shared_ptr<ModelHighAPI_Interface> setAngleBackward(
434 const ModelHighAPI_RefAttr & theLine1,
435 const ModelHighAPI_RefAttr & theLine2,
436 const ModelHighAPI_Double & theValue);
440 std::shared_ptr<ModelHighAPI_Interface> setCoincident(
441 const ModelHighAPI_RefAttr & thePoint1,
442 const ModelHighAPI_RefAttr & thePoint2);
446 std::shared_ptr<ModelHighAPI_Interface> setCollinear(
447 const ModelHighAPI_RefAttr & theLine1,
448 const ModelHighAPI_RefAttr & theLine2);
452 std::shared_ptr<ModelHighAPI_Interface> setDistance(
453 const ModelHighAPI_RefAttr & thePoint,
454 const ModelHighAPI_RefAttr & thePointOrLine,
455 const ModelHighAPI_Double & theValue,
456 bool isSigned = false);
458 /// Set signed distance
460 std::shared_ptr<ModelHighAPI_Interface> setSignedDistance(
461 const ModelHighAPI_RefAttr & thePoint,
462 const ModelHighAPI_RefAttr & thePointOrLine,
463 const ModelHighAPI_Double & theValue);
465 /// Set unsigned distance
467 std::shared_ptr<ModelHighAPI_Interface> setUnsignedDistance(
468 const ModelHighAPI_RefAttr & thePoint,
469 const ModelHighAPI_RefAttr & thePointOrLine,
470 const ModelHighAPI_Double & theValue);
472 /// Set horizontal distance
474 std::shared_ptr<ModelHighAPI_Interface> setHorizontalDistance(
475 const ModelHighAPI_RefAttr & thePoint1,
476 const ModelHighAPI_RefAttr & thePoint2,
477 const ModelHighAPI_Double & theValue);
479 /// Set vertical distance
481 std::shared_ptr<ModelHighAPI_Interface> setVerticalDistance(
482 const ModelHighAPI_RefAttr & thePoint1,
483 const ModelHighAPI_RefAttr & thePoint2,
484 const ModelHighAPI_Double & theValue);
488 std::shared_ptr<ModelHighAPI_Interface> setEqual(
489 const ModelHighAPI_RefAttr & theObject1,
490 const ModelHighAPI_RefAttr & theObject2);
494 std::shared_ptr<ModelHighAPI_Interface> setFillet(
495 const ModelHighAPI_RefAttr & thePoint);
497 /// Set fillet with additional radius constraint
499 std::shared_ptr<ModelHighAPI_Interface> setFilletWithRadius(
500 const ModelHighAPI_RefAttr & thePoint,
501 const ModelHighAPI_Double & theRadius);
505 std::shared_ptr<ModelHighAPI_Interface> setFixed(
506 const ModelHighAPI_RefAttr & theObject);
510 std::shared_ptr<ModelHighAPI_Interface> setHorizontal(
511 const ModelHighAPI_RefAttr & theLine);
515 std::shared_ptr<ModelHighAPI_Interface> setLength(
516 const ModelHighAPI_RefAttr & theLine,
517 const ModelHighAPI_Double & theValue);
521 std::shared_ptr<ModelHighAPI_Interface> setMiddlePoint(
522 const ModelHighAPI_RefAttr & thePoint,
523 const ModelHighAPI_RefAttr & theLine);
527 std::shared_ptr<ModelHighAPI_Interface> setParallel(
528 const ModelHighAPI_RefAttr & theLine1,
529 const ModelHighAPI_RefAttr & theLine2);
531 /// Set perpendicular
533 std::shared_ptr<ModelHighAPI_Interface> setPerpendicular(
534 const ModelHighAPI_RefAttr & theLine1,
535 const ModelHighAPI_RefAttr & theLine2);
539 std::shared_ptr<ModelHighAPI_Interface> setRadius(
540 const ModelHighAPI_RefAttr & theCircleOrArc,
541 const ModelHighAPI_Double & theValue);
545 std::shared_ptr<ModelHighAPI_Interface> setTangent(
546 const ModelHighAPI_RefAttr & theLine,
547 const ModelHighAPI_RefAttr & theCircle);
551 std::shared_ptr<ModelHighAPI_Interface> setVertical(
552 const ModelHighAPI_RefAttr & theLine);
554 /// Set constraint value
557 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
558 const ModelHighAPI_Double & theValue);
560 /// Move point or sketch feature
562 void move(const ModelHighAPI_RefAttr& theMovedEntity,
563 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint);
565 /// Move point or sketch feature
567 void move(const ModelHighAPI_RefAttr& theMovedEntity,
568 double theTargetX, double theTargetY);
571 std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
573 // TODO(spo): rename to selectFaces() or faces() (or add faces() -> list to SWIG)
576 std::list<ModelHighAPI_Selection> selectFace() const;
578 /// Dump wrapped feature
580 virtual void dump(ModelHighAPI_Dumper& theDumper) const;
583 std::shared_ptr<ModelAPI_CompositeFeature> compositeFeature() const;
587 //! Pointer on Sketch object
588 typedef std::shared_ptr<SketchAPI_Sketch> SketchPtr;
590 //--------------------------------------------------------------------------------------
592 /**\ingroup CPPHighAPI
593 * \brief Create Sketch feature
596 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
597 const std::shared_ptr<GeomAPI_Ax3> & thePlane);
599 /**\ingroup CPPHighAPI
600 * \brief Create Sketch feature
603 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
604 const ModelHighAPI_Selection & theExternal);
606 /**\ingroup CPPHighAPI
607 * \brief Create Sketch feature
610 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
611 const std::wstring & theExternalName);
613 /**\ingroup CPPHighAPI
614 * \brief Create Sketch feature
617 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
618 std::shared_ptr<ModelAPI_Object> thePlaneObject);
620 //--------------------------------------------------------------------------------------
622 /** \ingroup CPPHighAPI
623 * \brief Copy sketch with all its sub-features
626 SketchPtr copySketch(const std::shared_ptr<ModelAPI_Document> & thePart,
627 const SketchPtr & theSketch);
629 //--------------------------------------------------------------------------------------
630 #endif /* SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_ */