1 // Copyright (C) 2014-2024 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"
29 #include <SketchPlugin_Sketch.h>
30 #include <SketchPlugin_SketchEntity.h>
31 #include <SketchPlugin_Offset.h>
33 #include <ModelHighAPI_Double.h>
34 #include <ModelHighAPI_Interface.h>
35 #include <ModelHighAPI_Macro.h>
36 #include <ModelHighAPI_Selection.h>
37 //--------------------------------------------------------------------------------------
38 class ModelAPI_CompositeFeature;
39 class ModelAPI_Object;
40 class ModelHighAPI_Integer;
41 class ModelHighAPI_RefAttr;
42 class ModelHighAPI_Reference;
44 class SketchAPI_MacroArc;
45 class SketchAPI_Circle;
46 class SketchAPI_MacroCircle;
47 class SketchAPI_Ellipse;
48 class SketchAPI_MacroEllipse;
49 class SketchAPI_EllipticArc;
50 class SketchAPI_MacroEllipticArc;
51 class SketchAPI_BSpline;
52 class SketchAPI_IntersectionPoint;
54 class SketchAPI_Mirror;
55 class SketchAPI_Offset;
56 class SketchAPI_Point;
57 class SketchAPI_Projection;
58 class SketchAPI_Rectangle;
59 class SketchAPI_Rotation;
60 class SketchAPI_Translation;
61 class SketchAPI_MacroMiddlePoint;
63 //--------------------------------------------------------------------------------------
64 typedef std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> PointOrReference;
65 //--------------------------------------------------------------------------------------
66 /**\class SketchAPI_Sketch
68 * \brief Interface for Sketch feature
70 class SketchAPI_Sketch : public ModelHighAPI_Interface
73 /// Constructor without values
75 explicit SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature);
76 /// Constructor with values
78 SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
79 const std::shared_ptr<GeomAPI_Ax3> & thePlane);
80 /// Constructor with values
82 SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
83 const ModelHighAPI_Selection & theExternal);
84 /// Constructor with values
86 SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
87 std::shared_ptr<ModelAPI_Object> thePlaneObject);
90 virtual ~SketchAPI_Sketch();
92 INTERFACE_7(SketchPlugin_Sketch::ID(),
93 origin, SketchPlugin_Sketch::ORIGIN_ID(),
94 GeomDataAPI_Point, /** Origin point */,
95 dirX, SketchPlugin_Sketch::DIRX_ID(),
96 GeomDataAPI_Dir, /** Direction of X */,
97 normal, SketchPlugin_Sketch::NORM_ID(),
98 GeomDataAPI_Dir, /** Normal */,
99 features, SketchPlugin_Sketch::FEATURES_ID(),
100 ModelAPI_AttributeRefList, /** Features */,
101 external, SketchPlugin_SketchEntity::EXTERNAL_ID(),
102 ModelAPI_AttributeSelection, /** External */,
103 solverError, SketchPlugin_Sketch::SOLVER_ERROR(),
104 ModelAPI_AttributeString, /** Solver error */,
105 solverDOF, SketchPlugin_Sketch::SOLVER_DOF(),
106 ModelAPI_AttributeString, /** Solver DOF */
111 void setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane);
113 /// Change sketch plane
115 void setPlane(const ModelHighAPI_Selection & thePlane,
116 bool theRemoveExternalDependency = false);
120 void setExternal(const ModelHighAPI_Selection & theExternal);
124 void setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject);
126 /// Change order of sketch results (faces)
128 void changeFacesOrder(const std::list<std::list<ModelHighAPI_Selection> >& theFaces);
130 /// List points not connected by constraints with other sketch entitites
132 std::list< std::shared_ptr<SketchAPI_Point> > getFreePoints();
136 std::shared_ptr<SketchAPI_Point> addPoint(
137 double theX, double theY);
140 std::shared_ptr<SketchAPI_Point> addPoint(
141 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint);
144 std::shared_ptr<SketchAPI_Point> addPoint(const ModelHighAPI_Selection & theExternal);
147 std::shared_ptr<SketchAPI_Point> addPoint(const std::wstring & theExternalName);
149 /// Add intersection point
151 std::shared_ptr<SketchAPI_IntersectionPoint>
152 addIntersectionPoint(const ModelHighAPI_Selection & theExternal,
153 bool theKeepResult = false);
156 std::shared_ptr<SketchAPI_IntersectionPoint>
157 addIntersectionPoint(const std::wstring & theExternalName,
158 bool theKeepResult = false);
162 std::shared_ptr<SketchAPI_Line> addLine(
163 double theX1, double theY1, double theX2, double theY2);
166 std::shared_ptr<SketchAPI_Line> addLine(
167 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
168 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
171 std::shared_ptr<SketchAPI_Line> addLine(const ModelHighAPI_Selection & theExternal);
174 std::shared_ptr<SketchAPI_Line> addLine(const std::wstring & theExternalName);
178 std::shared_ptr<SketchAPI_Rectangle> addRectangle(
179 double theX1, double theY1, double theX2, double theY2);
182 std::shared_ptr<SketchAPI_Rectangle> addRectangle(
183 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theStartPoint,
184 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theEndPoint);
187 std::pair<std::shared_ptr<SketchAPI_Rectangle>, std::shared_ptr<SketchAPI_Point>> addRectangleCentered(
188 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theCenter,
189 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theCorner);
192 std::pair<std::shared_ptr<SketchAPI_Rectangle>, std::shared_ptr<SketchAPI_Point>> addRectangleCentered(
193 double theCenterX, double theCenterY,
194 double theCornerX, double theCornerY
199 std::shared_ptr<SketchAPI_Circle> addCircle(
200 double theCenterX, double theCenterY,
204 std::shared_ptr<SketchAPI_Circle> addCircle(
205 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
209 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
210 double theCenterX, double theCenterY,
211 double thePassedX, double thePassedY);
214 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
215 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
216 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
219 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
220 double theX1, double theY1,
221 double theX2, double theY2,
222 double theX3, double theY3);
225 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
226 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
227 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
228 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
231 std::shared_ptr<SketchAPI_Circle> addCircle(const ModelHighAPI_Selection & theExternal);
234 std::shared_ptr<SketchAPI_Circle> addCircle(const std::wstring & theExternalName);
238 std::shared_ptr<SketchAPI_Arc> addArc(
239 double theCenterX, double theCenterY,
240 double theStartX, double theStartY,
241 double theEndX, double theEndY,
246 std::shared_ptr<SketchAPI_Arc> addArc(
247 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
248 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
249 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
254 std::shared_ptr<SketchAPI_MacroArc> addArc(
255 double theStartX, double theStartY,
256 double theEndX, double theEndY,
257 double thePassedX, double thePassedY);
261 std::shared_ptr<SketchAPI_MacroArc> addArc(
262 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
263 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
264 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed);
266 /// Add transversal/tangent arc
268 std::shared_ptr<SketchAPI_MacroArc> addArc(
269 const ModelHighAPI_RefAttr& theConnectedPoint,
270 double theEndX, double theEndY,
272 bool theTransversal = false);
274 /// Add transversal/tangent arc
276 std::shared_ptr<SketchAPI_MacroArc> addArc(
277 const ModelHighAPI_RefAttr& theConnectedPoint,
278 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
280 bool theTransversal = false);
284 std::shared_ptr<SketchAPI_Arc> addArc(const ModelHighAPI_Selection & theExternal);
288 std::shared_ptr<SketchAPI_Arc> addArc(const std::wstring & theExternalName);
292 std::shared_ptr<SketchAPI_Ellipse> addEllipse(
293 double theCenterX, double theCenterY,
294 double theFocusX, double theFocusY,
295 double theMinorRadius);
298 std::shared_ptr<SketchAPI_Ellipse> addEllipse(
299 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
300 const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
304 std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
305 double thePoint1X, double thePoint1Y,
306 double thePoint2X, double thePoint2Y,
307 double thePassedX, double thePassedY,
308 bool isPoint1Center = true);
311 std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
312 const PointOrReference& thePoint1,
313 const PointOrReference& thePoint2,
314 const PointOrReference& thePassedPoint,
315 bool isPoint1Center = true);
318 std::shared_ptr<SketchAPI_Ellipse> addEllipse(const ModelHighAPI_Selection & theExternal);
321 std::shared_ptr<SketchAPI_Ellipse> addEllipse(const std::wstring & theExternalName);
325 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(
326 double theCenterX, double theCenterY,
327 double theFocusX, double theFocusY,
328 double theStartX, double theStartY,
329 double theEndX, double theEndY,
330 bool theInversed = false);
333 std::shared_ptr<SketchAPI_MacroEllipticArc> addEllipticArc(
334 const PointOrReference& theCenter,
335 const PointOrReference& theMajorAxisPoint,
336 const PointOrReference& theStartPoint,
337 const PointOrReference& theEndPoint,
338 bool theInversed = false);
341 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(const ModelHighAPI_Selection & theExternal);
344 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(const std::wstring & theExternalName);
348 std::shared_ptr<SketchAPI_BSpline> addSpline(
349 const ModelHighAPI_Selection & external = ModelHighAPI_Selection(),
350 const int degree = -1,
351 const std::list<PointOrReference>& poles = std::list<PointOrReference>(),
352 const std::list<ModelHighAPI_Double>& weights = std::list<ModelHighAPI_Double>(),
353 const std::list<ModelHighAPI_Double>& knots = std::list<ModelHighAPI_Double>(),
354 const std::list<ModelHighAPI_Integer>& multiplicities = std::list<ModelHighAPI_Integer>(),
355 const bool periodic = false);
357 /// Add interpolation feature
359 std::shared_ptr<SketchAPI_BSpline> addInterpolation(
360 const std::list<ModelHighAPI_RefAttr>& points,
361 const bool periodic = false,
362 const bool closed = false);
364 /// Add approximation feature
366 std::shared_ptr<SketchAPI_BSpline> addApproximation(
367 const std::list<ModelHighAPI_RefAttr>& points,
368 const ModelHighAPI_Double& precision = ModelHighAPI_Double(1.e-3),
369 const bool periodic = false,
370 const bool closed = false);
374 std::shared_ptr<SketchAPI_Projection> addProjection(
375 const ModelHighAPI_Selection & theExternalFeature,
376 bool keepResult = false,
377 bool keepRefToOriginal = true);
381 std::shared_ptr<SketchAPI_Mirror> addMirror(
382 const ModelHighAPI_RefAttr & theMirrorLine,
383 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects);
387 std::shared_ptr<SketchAPI_Offset> addOffset(
388 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
389 const ModelHighAPI_Double & theValue,
390 const bool theReversed = false,
391 const std::string & theJointType = SketchPlugin_Offset::JOINT_KEEP_DISTANCE(),
392 const bool theApprox = false);
396 std::shared_ptr<SketchAPI_Translation> addTranslation(
397 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
398 const ModelHighAPI_RefAttr & thePoint1,
399 const ModelHighAPI_RefAttr & thePoint2,
400 const ModelHighAPI_Integer & theNumberOfObjects,
401 bool theFullValue = false);
405 std::shared_ptr<SketchAPI_Rotation> addRotation(
406 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
407 const ModelHighAPI_RefAttr & theCenter,
408 const ModelHighAPI_Double & theAngle,
409 const ModelHighAPI_Integer & theNumberOfObjects,
410 bool theFullValue = false,
411 bool theReversed = false);
415 std::shared_ptr<ModelHighAPI_Interface> addSplit(
416 const ModelHighAPI_Reference& theFeature,
417 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
421 std::shared_ptr<ModelHighAPI_Interface> addTrim(
422 const ModelHighAPI_Reference& theFeature,
423 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
427 std::shared_ptr<ModelHighAPI_Interface> setAngle(
428 const ModelHighAPI_RefAttr & theLine1,
429 const ModelHighAPI_RefAttr & theLine2,
430 const ModelHighAPI_Double & theValue,
431 const std::string& type = std::string());
433 /// Set complementary angle
435 std::shared_ptr<ModelHighAPI_Interface> setAngleComplementary(
436 const ModelHighAPI_RefAttr & theLine1,
437 const ModelHighAPI_RefAttr & theLine2,
438 const ModelHighAPI_Double & theValue);
440 /// Set backward angle (= 360 - angle)
442 std::shared_ptr<ModelHighAPI_Interface> setAngleBackward(
443 const ModelHighAPI_RefAttr & theLine1,
444 const ModelHighAPI_RefAttr & theLine2,
445 const ModelHighAPI_Double & theValue);
449 std::shared_ptr<ModelHighAPI_Interface> setCoincident(
450 const ModelHighAPI_RefAttr & thePoint1,
451 const ModelHighAPI_RefAttr & thePoint2);
455 std::shared_ptr<ModelHighAPI_Interface> setCollinear(
456 const ModelHighAPI_RefAttr & theLine1,
457 const ModelHighAPI_RefAttr & theLine2);
461 std::shared_ptr<ModelHighAPI_Interface> setDistance(
462 const ModelHighAPI_RefAttr & thePoint,
463 const ModelHighAPI_RefAttr & thePointOrLine,
464 const ModelHighAPI_Double & theValue,
465 bool isSigned = false);
467 /// Set signed distance
469 std::shared_ptr<ModelHighAPI_Interface> setSignedDistance(
470 const ModelHighAPI_RefAttr & thePoint,
471 const ModelHighAPI_RefAttr & thePointOrLine,
472 const ModelHighAPI_Double & theValue);
474 /// Set unsigned distance
476 std::shared_ptr<ModelHighAPI_Interface> setUnsignedDistance(
477 const ModelHighAPI_RefAttr & thePoint,
478 const ModelHighAPI_RefAttr & thePointOrLine,
479 const ModelHighAPI_Double & theValue);
481 /// Set horizontal distance
483 std::shared_ptr<ModelHighAPI_Interface> setHorizontalDistance(
484 const ModelHighAPI_RefAttr & thePoint1,
485 const ModelHighAPI_RefAttr & thePoint2,
486 const ModelHighAPI_Double & theValue);
488 /// Set vertical distance
490 std::shared_ptr<ModelHighAPI_Interface> setVerticalDistance(
491 const ModelHighAPI_RefAttr & thePoint1,
492 const ModelHighAPI_RefAttr & thePoint2,
493 const ModelHighAPI_Double & theValue);
497 std::shared_ptr<ModelHighAPI_Interface> setEqual(
498 const ModelHighAPI_RefAttr & theObject1,
499 const ModelHighAPI_RefAttr & theObject2);
503 std::shared_ptr<ModelHighAPI_Interface> setFillet(
504 const ModelHighAPI_RefAttr & thePoint);
506 /// Set fillet with additional radius constraint
508 std::shared_ptr<ModelHighAPI_Interface> setFilletWithRadius(
509 const ModelHighAPI_RefAttr & thePoint,
510 const ModelHighAPI_Double & theRadius);
514 std::shared_ptr<ModelHighAPI_Interface> setFixed(
515 const ModelHighAPI_RefAttr & theObject);
519 std::shared_ptr<ModelHighAPI_Interface> setHorizontal(
520 const ModelHighAPI_RefAttr & theLine);
524 std::shared_ptr<ModelHighAPI_Interface> setLength(
525 const ModelHighAPI_RefAttr & theLine,
526 const ModelHighAPI_Double & theValue);
530 std::shared_ptr<ModelHighAPI_Interface> setMiddlePoint(
531 const ModelHighAPI_RefAttr & thePoint,
532 const ModelHighAPI_RefAttr & theLine);
536 std::shared_ptr<SketchAPI_MacroMiddlePoint> setMiddlePoint(
537 const ModelHighAPI_RefAttr& theLine);
541 std::shared_ptr<ModelHighAPI_Interface> setParallel(
542 const ModelHighAPI_RefAttr & theLine1,
543 const ModelHighAPI_RefAttr & theLine2);
545 /// Set perpendicular
547 std::shared_ptr<ModelHighAPI_Interface> setPerpendicular(
548 const ModelHighAPI_RefAttr & theLine1,
549 const ModelHighAPI_RefAttr & theLine2);
553 std::shared_ptr<ModelHighAPI_Interface> setRadius(
554 const ModelHighAPI_RefAttr & theCircleOrArc,
555 const ModelHighAPI_Double & theValue);
559 std::shared_ptr<ModelHighAPI_Interface> setTangent(
560 const ModelHighAPI_RefAttr & theLine,
561 const ModelHighAPI_RefAttr & theCircle);
565 std::shared_ptr<ModelHighAPI_Interface> setVertical(
566 const ModelHighAPI_RefAttr & theLine);
568 /// Set constraint value
571 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
572 const ModelHighAPI_Double & theValue);
574 /// Move point or sketch feature
576 void move(const ModelHighAPI_RefAttr& theMovedEntity,
577 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint);
579 /// Move point or sketch feature
581 void move(const ModelHighAPI_RefAttr& theMovedEntity,
582 double theTargetX, double theTargetY);
585 std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
587 // TODO(spo): rename to selectFaces() or faces() (or add faces() -> list to SWIG)
590 std::list<ModelHighAPI_Selection> selectFace() const;
592 /// Dump wrapped feature
594 virtual void dump(ModelHighAPI_Dumper& theDumper) const;
597 std::shared_ptr<ModelAPI_CompositeFeature> compositeFeature() const;
601 //! Pointer on Sketch object
602 typedef std::shared_ptr<SketchAPI_Sketch> SketchPtr;
604 //--------------------------------------------------------------------------------------
606 /**\ingroup CPPHighAPI
607 * \brief Create Sketch feature
610 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
611 const std::shared_ptr<GeomAPI_Ax3> & thePlane);
613 /**\ingroup CPPHighAPI
614 * \brief Create Sketch feature
617 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
618 const ModelHighAPI_Selection & theExternal);
620 /**\ingroup CPPHighAPI
621 * \brief Create Sketch feature
624 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
625 const std::wstring & theExternalName);
627 /**\ingroup CPPHighAPI
628 * \brief Create Sketch feature
631 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
632 std::shared_ptr<ModelAPI_Object> thePlaneObject);
634 //--------------------------------------------------------------------------------------
636 /** \ingroup CPPHighAPI
637 * \brief Copy sketch with all its sub-features
640 SketchPtr copySketch(const std::shared_ptr<ModelAPI_Document> & thePart,
641 const SketchPtr & theSketch);
643 //--------------------------------------------------------------------------------------
644 #endif /* SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_ */