1 // Copyright (C) 2014-2021 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>
31 #include <ModelHighAPI_Double.h>
32 #include <ModelHighAPI_Interface.h>
33 #include <ModelHighAPI_Macro.h>
34 #include <ModelHighAPI_Selection.h>
35 //--------------------------------------------------------------------------------------
36 class ModelAPI_CompositeFeature;
37 class ModelAPI_Object;
38 class ModelHighAPI_Integer;
39 class ModelHighAPI_RefAttr;
40 class ModelHighAPI_Reference;
42 class SketchAPI_MacroArc;
43 class SketchAPI_Circle;
44 class SketchAPI_MacroCircle;
45 class SketchAPI_Ellipse;
46 class SketchAPI_MacroEllipse;
47 class SketchAPI_EllipticArc;
48 class SketchAPI_MacroEllipticArc;
49 class SketchAPI_BSpline;
50 class SketchAPI_IntersectionPoint;
52 class SketchAPI_Mirror;
53 class SketchAPI_Offset;
54 class SketchAPI_Point;
55 class SketchAPI_Projection;
56 class SketchAPI_Rectangle;
57 class SketchAPI_Rotation;
58 class SketchAPI_Translation;
60 //--------------------------------------------------------------------------------------
61 typedef std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> PointOrReference;
62 //--------------------------------------------------------------------------------------
63 /**\class SketchAPI_Sketch
65 * \brief Interface for Sketch feature
67 class SketchAPI_Sketch : public ModelHighAPI_Interface
70 /// Constructor without values
72 explicit SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature);
73 /// Constructor with values
75 SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
76 const std::shared_ptr<GeomAPI_Ax3> & thePlane);
77 /// Constructor with values
79 SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
80 const ModelHighAPI_Selection & theExternal);
81 /// Constructor with values
83 SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
84 std::shared_ptr<ModelAPI_Object> thePlaneObject);
87 virtual ~SketchAPI_Sketch();
89 INTERFACE_7(SketchPlugin_Sketch::ID(),
90 origin, SketchPlugin_Sketch::ORIGIN_ID(),
91 GeomDataAPI_Point, /** Origin point */,
92 dirX, SketchPlugin_Sketch::DIRX_ID(),
93 GeomDataAPI_Dir, /** Direction of X */,
94 normal, SketchPlugin_Sketch::NORM_ID(),
95 GeomDataAPI_Dir, /** Normal */,
96 features, SketchPlugin_Sketch::FEATURES_ID(),
97 ModelAPI_AttributeRefList, /** Features */,
98 external, SketchPlugin_SketchEntity::EXTERNAL_ID(),
99 ModelAPI_AttributeSelection, /** External */,
100 solverError, SketchPlugin_Sketch::SOLVER_ERROR(),
101 ModelAPI_AttributeString, /** Solver error */,
102 solverDOF, SketchPlugin_Sketch::SOLVER_DOF(),
103 ModelAPI_AttributeString, /** Solver DOF */
108 void setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane);
110 /// Change sketch plane
112 void setPlane(const ModelHighAPI_Selection & thePlane,
113 bool theRemoveExternalDependency = false);
117 void setExternal(const ModelHighAPI_Selection & theExternal);
121 void setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject);
123 /// Change order of sketch results (faces)
125 void changeFacesOrder(const std::list<std::list<ModelHighAPI_Selection> >& theFaces);
127 /// List points not connected by constraints with other sketch entitites
129 std::list< std::shared_ptr<SketchAPI_Point> > getFreePoints();
133 std::shared_ptr<SketchAPI_Point> addPoint(
134 double theX, double theY);
137 std::shared_ptr<SketchAPI_Point> addPoint(
138 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint);
141 std::shared_ptr<SketchAPI_Point> addPoint(const ModelHighAPI_Selection & theExternal);
144 std::shared_ptr<SketchAPI_Point> addPoint(const std::wstring & theExternalName);
146 /// Add intersection point
148 std::shared_ptr<SketchAPI_IntersectionPoint>
149 addIntersectionPoint(const ModelHighAPI_Selection & theExternal,
150 bool theKeepResult = false);
153 std::shared_ptr<SketchAPI_IntersectionPoint>
154 addIntersectionPoint(const std::wstring & theExternalName,
155 bool theKeepResult = false);
159 std::shared_ptr<SketchAPI_Line> addLine(
160 double theX1, double theY1, double theX2, double theY2);
163 std::shared_ptr<SketchAPI_Line> addLine(
164 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
165 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
168 std::shared_ptr<SketchAPI_Line> addLine(const ModelHighAPI_Selection & theExternal);
171 std::shared_ptr<SketchAPI_Line> addLine(const std::wstring & theExternalName);
175 std::shared_ptr<SketchAPI_Rectangle> addRectangle(
176 double theX1, double theY1, double theX2, double theY2);
179 std::shared_ptr<SketchAPI_Rectangle> addRectangle(
180 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
181 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
184 std::shared_ptr<SketchAPI_Rectangle> addRectangleCentered(
185 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theCenter,
186 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theCorner);
190 std::shared_ptr<SketchAPI_Circle> addCircle(
191 double theCenterX, double theCenterY,
195 std::shared_ptr<SketchAPI_Circle> addCircle(
196 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
200 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
201 double theCenterX, double theCenterY,
202 double thePassedX, double thePassedY);
205 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
206 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
207 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
210 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
211 double theX1, double theY1,
212 double theX2, double theY2,
213 double theX3, double theY3);
216 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
217 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
218 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
219 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
222 std::shared_ptr<SketchAPI_Circle> addCircle(const ModelHighAPI_Selection & theExternal);
225 std::shared_ptr<SketchAPI_Circle> addCircle(const std::wstring & theExternalName);
229 std::shared_ptr<SketchAPI_Arc> addArc(
230 double theCenterX, double theCenterY,
231 double theStartX, double theStartY,
232 double theEndX, double theEndY,
237 std::shared_ptr<SketchAPI_Arc> addArc(
238 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
239 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
240 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
245 std::shared_ptr<SketchAPI_MacroArc> addArc(
246 double theStartX, double theStartY,
247 double theEndX, double theEndY,
248 double thePassedX, double thePassedY);
252 std::shared_ptr<SketchAPI_MacroArc> addArc(
253 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
254 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
255 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed);
257 /// Add transversal/tangent arc
259 std::shared_ptr<SketchAPI_MacroArc> addArc(
260 const ModelHighAPI_RefAttr& theConnectedPoint,
261 double theEndX, double theEndY,
263 bool theTransversal = false);
265 /// Add transversal/tangent arc
267 std::shared_ptr<SketchAPI_MacroArc> addArc(
268 const ModelHighAPI_RefAttr& theConnectedPoint,
269 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
271 bool theTransversal = false);
275 std::shared_ptr<SketchAPI_Arc> addArc(const ModelHighAPI_Selection & theExternal);
279 std::shared_ptr<SketchAPI_Arc> addArc(const std::wstring & theExternalName);
283 std::shared_ptr<SketchAPI_Ellipse> addEllipse(
284 double theCenterX, double theCenterY,
285 double theFocusX, double theFocusY,
286 double theMinorRadius);
289 std::shared_ptr<SketchAPI_Ellipse> addEllipse(
290 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
291 const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
295 std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
296 double thePoint1X, double thePoint1Y,
297 double thePoint2X, double thePoint2Y,
298 double thePassedX, double thePassedY,
299 bool isPoint1Center = true);
302 std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
303 const PointOrReference& thePoint1,
304 const PointOrReference& thePoint2,
305 const PointOrReference& thePassedPoint,
306 bool isPoint1Center = true);
309 std::shared_ptr<SketchAPI_Ellipse> addEllipse(const ModelHighAPI_Selection & theExternal);
312 std::shared_ptr<SketchAPI_Ellipse> addEllipse(const std::wstring & theExternalName);
316 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(
317 double theCenterX, double theCenterY,
318 double theFocusX, double theFocusY,
319 double theStartX, double theStartY,
320 double theEndX, double theEndY,
321 bool theInversed = false);
324 std::shared_ptr<SketchAPI_MacroEllipticArc> addEllipticArc(
325 const PointOrReference& theCenter,
326 const PointOrReference& theMajorAxisPoint,
327 const PointOrReference& theStartPoint,
328 const PointOrReference& theEndPoint,
329 bool theInversed = false);
332 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(const ModelHighAPI_Selection & theExternal);
335 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(const std::wstring & theExternalName);
339 std::shared_ptr<SketchAPI_BSpline> addSpline(
340 const ModelHighAPI_Selection & external = ModelHighAPI_Selection(),
341 const int degree = -1,
342 const std::list<PointOrReference>& poles = std::list<PointOrReference>(),
343 const std::list<ModelHighAPI_Double>& weights = std::list<ModelHighAPI_Double>(),
344 const std::list<ModelHighAPI_Double>& knots = std::list<ModelHighAPI_Double>(),
345 const std::list<ModelHighAPI_Integer>& multiplicities = std::list<ModelHighAPI_Integer>(),
346 const bool periodic = false);
348 /// Add interpolation feature
350 std::shared_ptr<SketchAPI_BSpline> addInterpolation(
351 const std::list<ModelHighAPI_RefAttr>& points,
352 const bool periodic = false,
353 const bool closed = false);
355 /// Add approximation feature
357 std::shared_ptr<SketchAPI_BSpline> addApproximation(
358 const std::list<ModelHighAPI_RefAttr>& points,
359 const ModelHighAPI_Double& precision = ModelHighAPI_Double(1.e-3),
360 const bool periodic = false,
361 const bool closed = false);
365 std::shared_ptr<SketchAPI_Projection> addProjection(
366 const ModelHighAPI_Selection & theExternalFeature,
367 bool keepResult = false,
368 bool keepRefToOriginal = true);
372 std::shared_ptr<SketchAPI_Mirror> addMirror(
373 const ModelHighAPI_RefAttr & theMirrorLine,
374 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects);
378 std::shared_ptr<SketchAPI_Offset> addOffset(
379 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
380 const ModelHighAPI_Double & theValue,
381 const bool theReversed);
385 std::shared_ptr<SketchAPI_Translation> addTranslation(
386 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
387 const ModelHighAPI_RefAttr & thePoint1,
388 const ModelHighAPI_RefAttr & thePoint2,
389 const ModelHighAPI_Integer & theNumberOfObjects,
390 bool theFullValue = false);
394 std::shared_ptr<SketchAPI_Rotation> addRotation(
395 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
396 const ModelHighAPI_RefAttr & theCenter,
397 const ModelHighAPI_Double & theAngle,
398 const ModelHighAPI_Integer & theNumberOfObjects,
399 bool theFullValue = false,
400 bool theReversed = false);
404 std::shared_ptr<ModelHighAPI_Interface> addSplit(
405 const ModelHighAPI_Reference& theFeature,
406 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
410 std::shared_ptr<ModelHighAPI_Interface> addTrim(
411 const ModelHighAPI_Reference& theFeature,
412 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
416 std::shared_ptr<ModelHighAPI_Interface> setAngle(
417 const ModelHighAPI_RefAttr & theLine1,
418 const ModelHighAPI_RefAttr & theLine2,
419 const ModelHighAPI_Double & theValue,
420 const std::string& type = std::string());
422 /// Set complementary angle
424 std::shared_ptr<ModelHighAPI_Interface> setAngleComplementary(
425 const ModelHighAPI_RefAttr & theLine1,
426 const ModelHighAPI_RefAttr & theLine2,
427 const ModelHighAPI_Double & theValue);
429 /// Set backward angle (= 360 - angle)
431 std::shared_ptr<ModelHighAPI_Interface> setAngleBackward(
432 const ModelHighAPI_RefAttr & theLine1,
433 const ModelHighAPI_RefAttr & theLine2,
434 const ModelHighAPI_Double & theValue);
438 std::shared_ptr<ModelHighAPI_Interface> setCoincident(
439 const ModelHighAPI_RefAttr & thePoint1,
440 const ModelHighAPI_RefAttr & thePoint2);
444 std::shared_ptr<ModelHighAPI_Interface> setCollinear(
445 const ModelHighAPI_RefAttr & theLine1,
446 const ModelHighAPI_RefAttr & theLine2);
450 std::shared_ptr<ModelHighAPI_Interface> setDistance(
451 const ModelHighAPI_RefAttr & thePoint,
452 const ModelHighAPI_RefAttr & thePointOrLine,
453 const ModelHighAPI_Double & theValue,
454 bool isSigned = false);
456 /// Set signed distance
458 std::shared_ptr<ModelHighAPI_Interface> setSignedDistance(
459 const ModelHighAPI_RefAttr & thePoint,
460 const ModelHighAPI_RefAttr & thePointOrLine,
461 const ModelHighAPI_Double & theValue);
463 /// Set unsigned distance
465 std::shared_ptr<ModelHighAPI_Interface> setUnsignedDistance(
466 const ModelHighAPI_RefAttr & thePoint,
467 const ModelHighAPI_RefAttr & thePointOrLine,
468 const ModelHighAPI_Double & theValue);
470 /// Set horizontal distance
472 std::shared_ptr<ModelHighAPI_Interface> setHorizontalDistance(
473 const ModelHighAPI_RefAttr & thePoint1,
474 const ModelHighAPI_RefAttr & thePoint2,
475 const ModelHighAPI_Double & theValue);
477 /// Set vertical distance
479 std::shared_ptr<ModelHighAPI_Interface> setVerticalDistance(
480 const ModelHighAPI_RefAttr & thePoint1,
481 const ModelHighAPI_RefAttr & thePoint2,
482 const ModelHighAPI_Double & theValue);
486 std::shared_ptr<ModelHighAPI_Interface> setEqual(
487 const ModelHighAPI_RefAttr & theObject1,
488 const ModelHighAPI_RefAttr & theObject2);
492 std::shared_ptr<ModelHighAPI_Interface> setFillet(
493 const ModelHighAPI_RefAttr & thePoint);
495 /// Set fillet with additional radius constraint
497 std::shared_ptr<ModelHighAPI_Interface> setFilletWithRadius(
498 const ModelHighAPI_RefAttr & thePoint,
499 const ModelHighAPI_Double & theRadius);
503 std::shared_ptr<ModelHighAPI_Interface> setFixed(
504 const ModelHighAPI_RefAttr & theObject);
508 std::shared_ptr<ModelHighAPI_Interface> setHorizontal(
509 const ModelHighAPI_RefAttr & theLine);
513 std::shared_ptr<ModelHighAPI_Interface> setLength(
514 const ModelHighAPI_RefAttr & theLine,
515 const ModelHighAPI_Double & theValue);
519 std::shared_ptr<ModelHighAPI_Interface> setMiddlePoint(
520 const ModelHighAPI_RefAttr & thePoint,
521 const ModelHighAPI_RefAttr & theLine);
525 std::shared_ptr<ModelHighAPI_Interface> setParallel(
526 const ModelHighAPI_RefAttr & theLine1,
527 const ModelHighAPI_RefAttr & theLine2);
529 /// Set perpendicular
531 std::shared_ptr<ModelHighAPI_Interface> setPerpendicular(
532 const ModelHighAPI_RefAttr & theLine1,
533 const ModelHighAPI_RefAttr & theLine2);
537 std::shared_ptr<ModelHighAPI_Interface> setRadius(
538 const ModelHighAPI_RefAttr & theCircleOrArc,
539 const ModelHighAPI_Double & theValue);
543 std::shared_ptr<ModelHighAPI_Interface> setTangent(
544 const ModelHighAPI_RefAttr & theLine,
545 const ModelHighAPI_RefAttr & theCircle);
549 std::shared_ptr<ModelHighAPI_Interface> setVertical(
550 const ModelHighAPI_RefAttr & theLine);
552 /// Set constraint value
555 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
556 const ModelHighAPI_Double & theValue);
558 /// Move point or sketch feature
560 void move(const ModelHighAPI_RefAttr& theMovedEntity,
561 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint);
563 /// Move point or sketch feature
565 void move(const ModelHighAPI_RefAttr& theMovedEntity,
566 double theTargetX, double theTargetY);
569 std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
571 // TODO(spo): rename to selectFaces() or faces() (or add faces() -> list to SWIG)
574 std::list<ModelHighAPI_Selection> selectFace() const;
576 /// Dump wrapped feature
578 virtual void dump(ModelHighAPI_Dumper& theDumper) const;
581 std::shared_ptr<ModelAPI_CompositeFeature> compositeFeature() const;
585 //! Pointer on Sketch object
586 typedef std::shared_ptr<SketchAPI_Sketch> SketchPtr;
588 //--------------------------------------------------------------------------------------
590 /**\ingroup CPPHighAPI
591 * \brief Create Sketch feature
594 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
595 const std::shared_ptr<GeomAPI_Ax3> & thePlane);
597 /**\ingroup CPPHighAPI
598 * \brief Create Sketch feature
601 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
602 const ModelHighAPI_Selection & theExternal);
604 /**\ingroup CPPHighAPI
605 * \brief Create Sketch feature
608 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
609 const std::wstring & theExternalName);
611 /**\ingroup CPPHighAPI
612 * \brief Create Sketch feature
615 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
616 std::shared_ptr<ModelAPI_Object> thePlaneObject);
618 //--------------------------------------------------------------------------------------
620 /** \ingroup CPPHighAPI
621 * \brief Copy sketch with all its sub-features
624 SketchPtr copySketch(const std::shared_ptr<ModelAPI_Document> & thePart,
625 const SketchPtr & theSketch);
627 //--------------------------------------------------------------------------------------
628 #endif /* SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_ */