1 // Copyright (C) 2014-2023 CEA, EDF
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;
60 class SketchAPI_MacroMiddlePoint;
62 //--------------------------------------------------------------------------------------
63 typedef std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> PointOrReference;
64 //--------------------------------------------------------------------------------------
65 /**\class SketchAPI_Sketch
67 * \brief Interface for Sketch feature
69 class SketchAPI_Sketch : public ModelHighAPI_Interface
72 /// Constructor without values
74 explicit SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature);
75 /// Constructor with values
77 SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
78 const std::shared_ptr<GeomAPI_Ax3> & thePlane);
79 /// Constructor with values
81 SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
82 const ModelHighAPI_Selection & theExternal);
83 /// Constructor with values
85 SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
86 std::shared_ptr<ModelAPI_Object> thePlaneObject);
89 virtual ~SketchAPI_Sketch();
91 INTERFACE_7(SketchPlugin_Sketch::ID(),
92 origin, SketchPlugin_Sketch::ORIGIN_ID(),
93 GeomDataAPI_Point, /** Origin point */,
94 dirX, SketchPlugin_Sketch::DIRX_ID(),
95 GeomDataAPI_Dir, /** Direction of X */,
96 normal, SketchPlugin_Sketch::NORM_ID(),
97 GeomDataAPI_Dir, /** Normal */,
98 features, SketchPlugin_Sketch::FEATURES_ID(),
99 ModelAPI_AttributeRefList, /** Features */,
100 external, SketchPlugin_SketchEntity::EXTERNAL_ID(),
101 ModelAPI_AttributeSelection, /** External */,
102 solverError, SketchPlugin_Sketch::SOLVER_ERROR(),
103 ModelAPI_AttributeString, /** Solver error */,
104 solverDOF, SketchPlugin_Sketch::SOLVER_DOF(),
105 ModelAPI_AttributeString, /** Solver DOF */
110 void setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane);
112 /// Change sketch plane
114 void setPlane(const ModelHighAPI_Selection & thePlane,
115 bool theRemoveExternalDependency = false);
119 void setExternal(const ModelHighAPI_Selection & theExternal);
123 void setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject);
125 /// Change order of sketch results (faces)
127 void changeFacesOrder(const std::list<std::list<ModelHighAPI_Selection> >& theFaces);
129 /// List points not connected by constraints with other sketch entitites
131 std::list< std::shared_ptr<SketchAPI_Point> > getFreePoints();
135 std::shared_ptr<SketchAPI_Point> addPoint(
136 double theX, double theY);
139 std::shared_ptr<SketchAPI_Point> addPoint(
140 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint);
143 std::shared_ptr<SketchAPI_Point> addPoint(const ModelHighAPI_Selection & theExternal);
146 std::shared_ptr<SketchAPI_Point> addPoint(const std::wstring & theExternalName);
148 /// Add intersection point
150 std::shared_ptr<SketchAPI_IntersectionPoint>
151 addIntersectionPoint(const ModelHighAPI_Selection & theExternal,
152 bool theKeepResult = false);
155 std::shared_ptr<SketchAPI_IntersectionPoint>
156 addIntersectionPoint(const std::wstring & theExternalName,
157 bool theKeepResult = false);
161 std::shared_ptr<SketchAPI_Line> addLine(
162 double theX1, double theY1, double theX2, double theY2);
165 std::shared_ptr<SketchAPI_Line> addLine(
166 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
167 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
170 std::shared_ptr<SketchAPI_Line> addLine(const ModelHighAPI_Selection & theExternal);
173 std::shared_ptr<SketchAPI_Line> addLine(const std::wstring & theExternalName);
177 std::shared_ptr<SketchAPI_Rectangle> addRectangle(
178 double theX1, double theY1, double theX2, double theY2);
181 std::shared_ptr<SketchAPI_Rectangle> addRectangle(
182 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
183 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
186 std::shared_ptr<SketchAPI_Rectangle> addRectangleCentered(
187 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theCenter,
188 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theCorner);
192 std::shared_ptr<SketchAPI_Circle> addCircle(
193 double theCenterX, double theCenterY,
197 std::shared_ptr<SketchAPI_Circle> addCircle(
198 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
202 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
203 double theCenterX, double theCenterY,
204 double thePassedX, double thePassedY);
207 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
208 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
209 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
212 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
213 double theX1, double theY1,
214 double theX2, double theY2,
215 double theX3, double theY3);
218 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
219 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
220 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
221 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
224 std::shared_ptr<SketchAPI_Circle> addCircle(const ModelHighAPI_Selection & theExternal);
227 std::shared_ptr<SketchAPI_Circle> addCircle(const std::wstring & theExternalName);
231 std::shared_ptr<SketchAPI_Arc> addArc(
232 double theCenterX, double theCenterY,
233 double theStartX, double theStartY,
234 double theEndX, double theEndY,
239 std::shared_ptr<SketchAPI_Arc> addArc(
240 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
241 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
242 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
247 std::shared_ptr<SketchAPI_MacroArc> addArc(
248 double theStartX, double theStartY,
249 double theEndX, double theEndY,
250 double thePassedX, double thePassedY);
254 std::shared_ptr<SketchAPI_MacroArc> addArc(
255 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
256 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
257 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed);
259 /// Add transversal/tangent arc
261 std::shared_ptr<SketchAPI_MacroArc> addArc(
262 const ModelHighAPI_RefAttr& theConnectedPoint,
263 double theEndX, double theEndY,
265 bool theTransversal = false);
267 /// Add transversal/tangent arc
269 std::shared_ptr<SketchAPI_MacroArc> addArc(
270 const ModelHighAPI_RefAttr& theConnectedPoint,
271 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
273 bool theTransversal = false);
277 std::shared_ptr<SketchAPI_Arc> addArc(const ModelHighAPI_Selection & theExternal);
281 std::shared_ptr<SketchAPI_Arc> addArc(const std::wstring & theExternalName);
285 std::shared_ptr<SketchAPI_Ellipse> addEllipse(
286 double theCenterX, double theCenterY,
287 double theFocusX, double theFocusY,
288 double theMinorRadius);
291 std::shared_ptr<SketchAPI_Ellipse> addEllipse(
292 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
293 const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
297 std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
298 double thePoint1X, double thePoint1Y,
299 double thePoint2X, double thePoint2Y,
300 double thePassedX, double thePassedY,
301 bool isPoint1Center = true);
304 std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
305 const PointOrReference& thePoint1,
306 const PointOrReference& thePoint2,
307 const PointOrReference& thePassedPoint,
308 bool isPoint1Center = true);
311 std::shared_ptr<SketchAPI_Ellipse> addEllipse(const ModelHighAPI_Selection & theExternal);
314 std::shared_ptr<SketchAPI_Ellipse> addEllipse(const std::wstring & theExternalName);
318 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(
319 double theCenterX, double theCenterY,
320 double theFocusX, double theFocusY,
321 double theStartX, double theStartY,
322 double theEndX, double theEndY,
323 bool theInversed = false);
326 std::shared_ptr<SketchAPI_MacroEllipticArc> addEllipticArc(
327 const PointOrReference& theCenter,
328 const PointOrReference& theMajorAxisPoint,
329 const PointOrReference& theStartPoint,
330 const PointOrReference& theEndPoint,
331 bool theInversed = false);
334 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(const ModelHighAPI_Selection & theExternal);
337 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(const std::wstring & theExternalName);
341 std::shared_ptr<SketchAPI_BSpline> addSpline(
342 const ModelHighAPI_Selection & external = ModelHighAPI_Selection(),
343 const int degree = -1,
344 const std::list<PointOrReference>& poles = std::list<PointOrReference>(),
345 const std::list<ModelHighAPI_Double>& weights = std::list<ModelHighAPI_Double>(),
346 const std::list<ModelHighAPI_Double>& knots = std::list<ModelHighAPI_Double>(),
347 const std::list<ModelHighAPI_Integer>& multiplicities = std::list<ModelHighAPI_Integer>(),
348 const bool periodic = false);
350 /// Add interpolation feature
352 std::shared_ptr<SketchAPI_BSpline> addInterpolation(
353 const std::list<ModelHighAPI_RefAttr>& points,
354 const bool periodic = false,
355 const bool closed = false);
357 /// Add approximation feature
359 std::shared_ptr<SketchAPI_BSpline> addApproximation(
360 const std::list<ModelHighAPI_RefAttr>& points,
361 const ModelHighAPI_Double& precision = ModelHighAPI_Double(1.e-3),
362 const bool periodic = false,
363 const bool closed = false);
367 std::shared_ptr<SketchAPI_Projection> addProjection(
368 const ModelHighAPI_Selection & theExternalFeature,
369 bool keepResult = false,
370 bool keepRefToOriginal = true);
374 std::shared_ptr<SketchAPI_Mirror> addMirror(
375 const ModelHighAPI_RefAttr & theMirrorLine,
376 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects);
380 std::shared_ptr<SketchAPI_Offset> addOffset(
381 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
382 const ModelHighAPI_Double & theValue,
383 const bool theReversed = false,
384 const std::string & theJointType = SketchPlugin_Offset::JOINT_KEEP_DISTANCE(),
385 const bool theApprox = false);
389 std::shared_ptr<SketchAPI_Translation> addTranslation(
390 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
391 const ModelHighAPI_RefAttr & thePoint1,
392 const ModelHighAPI_RefAttr & thePoint2,
393 const ModelHighAPI_Integer & theNumberOfObjects,
394 bool theFullValue = false);
398 std::shared_ptr<SketchAPI_Rotation> addRotation(
399 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
400 const ModelHighAPI_RefAttr & theCenter,
401 const ModelHighAPI_Double & theAngle,
402 const ModelHighAPI_Integer & theNumberOfObjects,
403 bool theFullValue = false,
404 bool theReversed = false);
408 std::shared_ptr<ModelHighAPI_Interface> addSplit(
409 const ModelHighAPI_Reference& theFeature,
410 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
414 std::shared_ptr<ModelHighAPI_Interface> addTrim(
415 const ModelHighAPI_Reference& theFeature,
416 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
420 std::shared_ptr<ModelHighAPI_Interface> setAngle(
421 const ModelHighAPI_RefAttr & theLine1,
422 const ModelHighAPI_RefAttr & theLine2,
423 const ModelHighAPI_Double & theValue,
424 const std::string& type = std::string());
426 /// Set complementary angle
428 std::shared_ptr<ModelHighAPI_Interface> setAngleComplementary(
429 const ModelHighAPI_RefAttr & theLine1,
430 const ModelHighAPI_RefAttr & theLine2,
431 const ModelHighAPI_Double & theValue);
433 /// Set backward angle (= 360 - angle)
435 std::shared_ptr<ModelHighAPI_Interface> setAngleBackward(
436 const ModelHighAPI_RefAttr & theLine1,
437 const ModelHighAPI_RefAttr & theLine2,
438 const ModelHighAPI_Double & theValue);
442 std::shared_ptr<ModelHighAPI_Interface> setCoincident(
443 const ModelHighAPI_RefAttr & thePoint1,
444 const ModelHighAPI_RefAttr & thePoint2);
448 std::shared_ptr<ModelHighAPI_Interface> setCollinear(
449 const ModelHighAPI_RefAttr & theLine1,
450 const ModelHighAPI_RefAttr & theLine2);
454 std::shared_ptr<ModelHighAPI_Interface> setDistance(
455 const ModelHighAPI_RefAttr & thePoint,
456 const ModelHighAPI_RefAttr & thePointOrLine,
457 const ModelHighAPI_Double & theValue,
458 bool isSigned = false);
460 /// Set signed distance
462 std::shared_ptr<ModelHighAPI_Interface> setSignedDistance(
463 const ModelHighAPI_RefAttr & thePoint,
464 const ModelHighAPI_RefAttr & thePointOrLine,
465 const ModelHighAPI_Double & theValue);
467 /// Set unsigned distance
469 std::shared_ptr<ModelHighAPI_Interface> setUnsignedDistance(
470 const ModelHighAPI_RefAttr & thePoint,
471 const ModelHighAPI_RefAttr & thePointOrLine,
472 const ModelHighAPI_Double & theValue);
474 /// Set horizontal distance
476 std::shared_ptr<ModelHighAPI_Interface> setHorizontalDistance(
477 const ModelHighAPI_RefAttr & thePoint1,
478 const ModelHighAPI_RefAttr & thePoint2,
479 const ModelHighAPI_Double & theValue);
481 /// Set vertical distance
483 std::shared_ptr<ModelHighAPI_Interface> setVerticalDistance(
484 const ModelHighAPI_RefAttr & thePoint1,
485 const ModelHighAPI_RefAttr & thePoint2,
486 const ModelHighAPI_Double & theValue);
490 std::shared_ptr<ModelHighAPI_Interface> setEqual(
491 const ModelHighAPI_RefAttr & theObject1,
492 const ModelHighAPI_RefAttr & theObject2);
496 std::shared_ptr<ModelHighAPI_Interface> setFillet(
497 const ModelHighAPI_RefAttr & thePoint);
499 /// Set fillet with additional radius constraint
501 std::shared_ptr<ModelHighAPI_Interface> setFilletWithRadius(
502 const ModelHighAPI_RefAttr & thePoint,
503 const ModelHighAPI_Double & theRadius);
507 std::shared_ptr<ModelHighAPI_Interface> setFixed(
508 const ModelHighAPI_RefAttr & theObject);
512 std::shared_ptr<ModelHighAPI_Interface> setHorizontal(
513 const ModelHighAPI_RefAttr & theLine);
517 std::shared_ptr<ModelHighAPI_Interface> setLength(
518 const ModelHighAPI_RefAttr & theLine,
519 const ModelHighAPI_Double & theValue);
523 std::shared_ptr<ModelHighAPI_Interface> setMiddlePoint(
524 const ModelHighAPI_RefAttr & thePoint,
525 const ModelHighAPI_RefAttr & theLine);
529 std::shared_ptr<SketchAPI_MacroMiddlePoint> setMiddlePoint(
530 const ModelHighAPI_RefAttr& theLine);
534 std::shared_ptr<ModelHighAPI_Interface> setParallel(
535 const ModelHighAPI_RefAttr & theLine1,
536 const ModelHighAPI_RefAttr & theLine2);
538 /// Set perpendicular
540 std::shared_ptr<ModelHighAPI_Interface> setPerpendicular(
541 const ModelHighAPI_RefAttr & theLine1,
542 const ModelHighAPI_RefAttr & theLine2);
546 std::shared_ptr<ModelHighAPI_Interface> setRadius(
547 const ModelHighAPI_RefAttr & theCircleOrArc,
548 const ModelHighAPI_Double & theValue);
552 std::shared_ptr<ModelHighAPI_Interface> setTangent(
553 const ModelHighAPI_RefAttr & theLine,
554 const ModelHighAPI_RefAttr & theCircle);
558 std::shared_ptr<ModelHighAPI_Interface> setVertical(
559 const ModelHighAPI_RefAttr & theLine);
561 /// Set constraint value
564 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
565 const ModelHighAPI_Double & theValue);
567 /// Move point or sketch feature
569 void move(const ModelHighAPI_RefAttr& theMovedEntity,
570 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint);
572 /// Move point or sketch feature
574 void move(const ModelHighAPI_RefAttr& theMovedEntity,
575 double theTargetX, double theTargetY);
578 std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
580 // TODO(spo): rename to selectFaces() or faces() (or add faces() -> list to SWIG)
583 std::list<ModelHighAPI_Selection> selectFace() const;
585 /// Dump wrapped feature
587 virtual void dump(ModelHighAPI_Dumper& theDumper) const;
590 std::shared_ptr<ModelAPI_CompositeFeature> compositeFeature() const;
594 //! Pointer on Sketch object
595 typedef std::shared_ptr<SketchAPI_Sketch> SketchPtr;
597 //--------------------------------------------------------------------------------------
599 /**\ingroup CPPHighAPI
600 * \brief Create Sketch feature
603 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
604 const std::shared_ptr<GeomAPI_Ax3> & thePlane);
606 /**\ingroup CPPHighAPI
607 * \brief Create Sketch feature
610 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
611 const ModelHighAPI_Selection & theExternal);
613 /**\ingroup CPPHighAPI
614 * \brief Create Sketch feature
617 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
618 const std::wstring & theExternalName);
620 /**\ingroup CPPHighAPI
621 * \brief Create Sketch feature
624 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
625 std::shared_ptr<ModelAPI_Object> thePlaneObject);
627 //--------------------------------------------------------------------------------------
629 /** \ingroup CPPHighAPI
630 * \brief Copy sketch with all its sub-features
633 SketchPtr copySketch(const std::shared_ptr<ModelAPI_Document> & thePart,
634 const SketchPtr & theSketch);
636 //--------------------------------------------------------------------------------------
637 #endif /* SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_ */