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;
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(),
384 const bool theApprox = false);
388 std::shared_ptr<SketchAPI_Translation> addTranslation(
389 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
390 const ModelHighAPI_RefAttr & thePoint1,
391 const ModelHighAPI_RefAttr & thePoint2,
392 const ModelHighAPI_Integer & theNumberOfObjects,
393 bool theFullValue = false);
397 std::shared_ptr<SketchAPI_Rotation> addRotation(
398 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
399 const ModelHighAPI_RefAttr & theCenter,
400 const ModelHighAPI_Double & theAngle,
401 const ModelHighAPI_Integer & theNumberOfObjects,
402 bool theFullValue = false,
403 bool theReversed = false);
407 std::shared_ptr<ModelHighAPI_Interface> addSplit(
408 const ModelHighAPI_Reference& theFeature,
409 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
413 std::shared_ptr<ModelHighAPI_Interface> addTrim(
414 const ModelHighAPI_Reference& theFeature,
415 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
419 std::shared_ptr<ModelHighAPI_Interface> setAngle(
420 const ModelHighAPI_RefAttr & theLine1,
421 const ModelHighAPI_RefAttr & theLine2,
422 const ModelHighAPI_Double & theValue,
423 const std::string& type = std::string());
425 /// Set complementary angle
427 std::shared_ptr<ModelHighAPI_Interface> setAngleComplementary(
428 const ModelHighAPI_RefAttr & theLine1,
429 const ModelHighAPI_RefAttr & theLine2,
430 const ModelHighAPI_Double & theValue);
432 /// Set backward angle (= 360 - angle)
434 std::shared_ptr<ModelHighAPI_Interface> setAngleBackward(
435 const ModelHighAPI_RefAttr & theLine1,
436 const ModelHighAPI_RefAttr & theLine2,
437 const ModelHighAPI_Double & theValue);
441 std::shared_ptr<ModelHighAPI_Interface> setCoincident(
442 const ModelHighAPI_RefAttr & thePoint1,
443 const ModelHighAPI_RefAttr & thePoint2);
447 std::shared_ptr<ModelHighAPI_Interface> setCollinear(
448 const ModelHighAPI_RefAttr & theLine1,
449 const ModelHighAPI_RefAttr & theLine2);
453 std::shared_ptr<ModelHighAPI_Interface> setDistance(
454 const ModelHighAPI_RefAttr & thePoint,
455 const ModelHighAPI_RefAttr & thePointOrLine,
456 const ModelHighAPI_Double & theValue,
457 bool isSigned = false);
459 /// Set signed distance
461 std::shared_ptr<ModelHighAPI_Interface> setSignedDistance(
462 const ModelHighAPI_RefAttr & thePoint,
463 const ModelHighAPI_RefAttr & thePointOrLine,
464 const ModelHighAPI_Double & theValue);
466 /// Set unsigned distance
468 std::shared_ptr<ModelHighAPI_Interface> setUnsignedDistance(
469 const ModelHighAPI_RefAttr & thePoint,
470 const ModelHighAPI_RefAttr & thePointOrLine,
471 const ModelHighAPI_Double & theValue);
473 /// Set horizontal distance
475 std::shared_ptr<ModelHighAPI_Interface> setHorizontalDistance(
476 const ModelHighAPI_RefAttr & thePoint1,
477 const ModelHighAPI_RefAttr & thePoint2,
478 const ModelHighAPI_Double & theValue);
480 /// Set vertical distance
482 std::shared_ptr<ModelHighAPI_Interface> setVerticalDistance(
483 const ModelHighAPI_RefAttr & thePoint1,
484 const ModelHighAPI_RefAttr & thePoint2,
485 const ModelHighAPI_Double & theValue);
489 std::shared_ptr<ModelHighAPI_Interface> setEqual(
490 const ModelHighAPI_RefAttr & theObject1,
491 const ModelHighAPI_RefAttr & theObject2);
495 std::shared_ptr<ModelHighAPI_Interface> setFillet(
496 const ModelHighAPI_RefAttr & thePoint);
498 /// Set fillet with additional radius constraint
500 std::shared_ptr<ModelHighAPI_Interface> setFilletWithRadius(
501 const ModelHighAPI_RefAttr & thePoint,
502 const ModelHighAPI_Double & theRadius);
506 std::shared_ptr<ModelHighAPI_Interface> setFixed(
507 const ModelHighAPI_RefAttr & theObject);
511 std::shared_ptr<ModelHighAPI_Interface> setHorizontal(
512 const ModelHighAPI_RefAttr & theLine);
516 std::shared_ptr<ModelHighAPI_Interface> setLength(
517 const ModelHighAPI_RefAttr & theLine,
518 const ModelHighAPI_Double & theValue);
522 std::shared_ptr<ModelHighAPI_Interface> setMiddlePoint(
523 const ModelHighAPI_RefAttr & thePoint,
524 const ModelHighAPI_RefAttr & theLine);
528 std::shared_ptr<ModelHighAPI_Interface> setParallel(
529 const ModelHighAPI_RefAttr & theLine1,
530 const ModelHighAPI_RefAttr & theLine2);
532 /// Set perpendicular
534 std::shared_ptr<ModelHighAPI_Interface> setPerpendicular(
535 const ModelHighAPI_RefAttr & theLine1,
536 const ModelHighAPI_RefAttr & theLine2);
540 std::shared_ptr<ModelHighAPI_Interface> setRadius(
541 const ModelHighAPI_RefAttr & theCircleOrArc,
542 const ModelHighAPI_Double & theValue);
546 std::shared_ptr<ModelHighAPI_Interface> setTangent(
547 const ModelHighAPI_RefAttr & theLine,
548 const ModelHighAPI_RefAttr & theCircle);
552 std::shared_ptr<ModelHighAPI_Interface> setVertical(
553 const ModelHighAPI_RefAttr & theLine);
555 /// Set constraint value
558 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
559 const ModelHighAPI_Double & theValue);
561 /// Move point or sketch feature
563 void move(const ModelHighAPI_RefAttr& theMovedEntity,
564 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint);
566 /// Move point or sketch feature
568 void move(const ModelHighAPI_RefAttr& theMovedEntity,
569 double theTargetX, double theTargetY);
572 std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
574 // TODO(spo): rename to selectFaces() or faces() (or add faces() -> list to SWIG)
577 std::list<ModelHighAPI_Selection> selectFace() const;
579 /// Dump wrapped feature
581 virtual void dump(ModelHighAPI_Dumper& theDumper) const;
584 std::shared_ptr<ModelAPI_CompositeFeature> compositeFeature() const;
588 //! Pointer on Sketch object
589 typedef std::shared_ptr<SketchAPI_Sketch> SketchPtr;
591 //--------------------------------------------------------------------------------------
593 /**\ingroup CPPHighAPI
594 * \brief Create Sketch feature
597 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
598 const std::shared_ptr<GeomAPI_Ax3> & thePlane);
600 /**\ingroup CPPHighAPI
601 * \brief Create Sketch feature
604 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
605 const ModelHighAPI_Selection & theExternal);
607 /**\ingroup CPPHighAPI
608 * \brief Create Sketch feature
611 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
612 const std::wstring & theExternalName);
614 /**\ingroup CPPHighAPI
615 * \brief Create Sketch feature
618 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
619 std::shared_ptr<ModelAPI_Object> thePlaneObject);
621 //--------------------------------------------------------------------------------------
623 /** \ingroup CPPHighAPI
624 * \brief Copy sketch with all its sub-features
627 SketchPtr copySketch(const std::shared_ptr<ModelAPI_Document> & thePart,
628 const SketchPtr & theSketch);
630 //--------------------------------------------------------------------------------------
631 #endif /* SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_ */