1 // Copyright (C) 2014-2020 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_Point;
54 class SketchAPI_Projection;
55 class SketchAPI_Rectangle;
56 class SketchAPI_Rotation;
57 class SketchAPI_Translation;
58 //--------------------------------------------------------------------------------------
59 typedef std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> PointOrReference;
60 //--------------------------------------------------------------------------------------
61 /**\class SketchAPI_Sketch
63 * \brief Interface for Sketch feature
65 class SketchAPI_Sketch : public ModelHighAPI_Interface
68 /// Constructor without values
70 explicit SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature);
71 /// Constructor with values
73 SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
74 const std::shared_ptr<GeomAPI_Ax3> & thePlane);
75 /// Constructor with values
77 SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
78 const ModelHighAPI_Selection & theExternal);
79 /// Constructor with values
81 SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
82 std::shared_ptr<ModelAPI_Object> thePlaneObject);
85 virtual ~SketchAPI_Sketch();
87 INTERFACE_7(SketchPlugin_Sketch::ID(),
88 origin, SketchPlugin_Sketch::ORIGIN_ID(),
89 GeomDataAPI_Point, /** Origin point */,
90 dirX, SketchPlugin_Sketch::DIRX_ID(),
91 GeomDataAPI_Dir, /** Direction of X */,
92 normal, SketchPlugin_Sketch::NORM_ID(),
93 GeomDataAPI_Dir, /** Normal */,
94 features, SketchPlugin_Sketch::FEATURES_ID(),
95 ModelAPI_AttributeRefList, /** Features */,
96 external, SketchPlugin_SketchEntity::EXTERNAL_ID(),
97 ModelAPI_AttributeSelection, /** External */,
98 solverError, SketchPlugin_Sketch::SOLVER_ERROR(),
99 ModelAPI_AttributeString, /** Solver error */,
100 solverDOF, SketchPlugin_Sketch::SOLVER_DOF(),
101 ModelAPI_AttributeString, /** Solver DOF */
106 void setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane);
108 /// Change sketch plane
110 void setPlane(const ModelHighAPI_Selection & thePlane,
111 bool theRemoveExternalDependency = false);
115 void setExternal(const ModelHighAPI_Selection & theExternal);
119 void setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject);
121 /// Change order of sketch results (faces)
123 void changeFacesOrder(const std::list<std::list<ModelHighAPI_Selection> >& theFaces);
125 /// List points not connected by constraints with other sketch entitites
127 std::list< std::shared_ptr<SketchAPI_Point> > getFreePoints();
131 std::shared_ptr<SketchAPI_Point> addPoint(
132 double theX, double theY);
135 std::shared_ptr<SketchAPI_Point> addPoint(
136 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint);
139 std::shared_ptr<SketchAPI_Point> addPoint(const ModelHighAPI_Selection & theExternal);
142 std::shared_ptr<SketchAPI_Point> addPoint(const std::string & theExternalName);
144 /// Add intersection point
146 std::shared_ptr<SketchAPI_IntersectionPoint>
147 addIntersectionPoint(const ModelHighAPI_Selection & theExternal,
148 bool theKeepResult = false);
151 std::shared_ptr<SketchAPI_IntersectionPoint>
152 addIntersectionPoint(const std::string & theExternalName,
153 bool theKeepResult = false);
157 std::shared_ptr<SketchAPI_Line> addLine(
158 double theX1, double theY1, double theX2, double theY2);
161 std::shared_ptr<SketchAPI_Line> addLine(
162 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
163 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
166 std::shared_ptr<SketchAPI_Line> addLine(const ModelHighAPI_Selection & theExternal);
169 std::shared_ptr<SketchAPI_Line> addLine(const std::string & theExternalName);
173 std::shared_ptr<SketchAPI_Rectangle> addRectangle(
174 double theX1, double theY1, double theX2, double theY2);
177 std::shared_ptr<SketchAPI_Rectangle> addRectangle(
178 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
179 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
183 std::shared_ptr<SketchAPI_Circle> addCircle(
184 double theCenterX, double theCenterY,
188 std::shared_ptr<SketchAPI_Circle> addCircle(
189 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
193 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
194 double theCenterX, double theCenterY,
195 double thePassedX, double thePassedY);
198 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
199 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
200 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
203 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
204 double theX1, double theY1,
205 double theX2, double theY2,
206 double theX3, double theY3);
209 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
210 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
211 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
212 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
215 std::shared_ptr<SketchAPI_Circle> addCircle(const ModelHighAPI_Selection & theExternal);
218 std::shared_ptr<SketchAPI_Circle> addCircle(const std::string & theExternalName);
222 std::shared_ptr<SketchAPI_Arc> addArc(
223 double theCenterX, double theCenterY,
224 double theStartX, double theStartY,
225 double theEndX, double theEndY,
230 std::shared_ptr<SketchAPI_Arc> addArc(
231 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
232 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
233 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
238 std::shared_ptr<SketchAPI_MacroArc> addArc(
239 double theStartX, double theStartY,
240 double theEndX, double theEndY,
241 double thePassedX, double thePassedY);
245 std::shared_ptr<SketchAPI_MacroArc> addArc(
246 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
247 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
248 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed);
250 /// Add transversal/tangent arc
252 std::shared_ptr<SketchAPI_MacroArc> addArc(
253 const ModelHighAPI_RefAttr& theConnectedPoint,
254 double theEndX, double theEndY,
256 bool theTransversal = false);
258 /// Add transversal/tangent arc
260 std::shared_ptr<SketchAPI_MacroArc> addArc(
261 const ModelHighAPI_RefAttr& theConnectedPoint,
262 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
264 bool theTransversal = false);
268 std::shared_ptr<SketchAPI_Arc> addArc(const ModelHighAPI_Selection & theExternal);
272 std::shared_ptr<SketchAPI_Arc> addArc(const std::string & theExternalName);
276 std::shared_ptr<SketchAPI_Ellipse> addEllipse(
277 double theCenterX, double theCenterY,
278 double theFocusX, double theFocusY,
279 double theMinorRadius);
282 std::shared_ptr<SketchAPI_Ellipse> addEllipse(
283 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
284 const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
288 std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
289 double thePoint1X, double thePoint1Y,
290 double thePoint2X, double thePoint2Y,
291 double thePassedX, double thePassedY,
292 bool isPoint1Center = true);
295 std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
296 const PointOrReference& thePoint1,
297 const PointOrReference& thePoint2,
298 const PointOrReference& thePassedPoint,
299 bool isPoint1Center = true);
302 std::shared_ptr<SketchAPI_Ellipse> addEllipse(const ModelHighAPI_Selection & theExternal);
305 std::shared_ptr<SketchAPI_Ellipse> addEllipse(const std::string & theExternalName);
309 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(
310 double theCenterX, double theCenterY,
311 double theFocusX, double theFocusY,
312 double theStartX, double theStartY,
313 double theEndX, double theEndY,
314 bool theInversed = false);
317 std::shared_ptr<SketchAPI_MacroEllipticArc> addEllipticArc(
318 const PointOrReference& theCenter,
319 const PointOrReference& theMajorAxisPoint,
320 const PointOrReference& theStartPoint,
321 const PointOrReference& theEndPoint,
322 bool theInversed = false);
325 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(const ModelHighAPI_Selection & theExternal);
328 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(const std::string & theExternalName);
332 std::shared_ptr<SketchAPI_BSpline> addSpline(
333 const ModelHighAPI_Selection & external = ModelHighAPI_Selection(),
334 const int degree = -1,
335 const std::list<PointOrReference>& poles = std::list<PointOrReference>(),
336 const std::list<ModelHighAPI_Double>& weights = std::list<ModelHighAPI_Double>(),
337 const std::list<ModelHighAPI_Double>& knots = std::list<ModelHighAPI_Double>(),
338 const std::list<ModelHighAPI_Integer>& multiplicities = std::list<ModelHighAPI_Integer>(),
339 const bool periodic = false);
341 /// Add interpolation feature
343 std::shared_ptr<SketchAPI_BSpline> addInterpolation(
344 const std::list<ModelHighAPI_RefAttr>& points,
345 const bool periodic = false,
346 const bool closed = false);
348 /// Add approximation feature
350 std::shared_ptr<SketchAPI_BSpline> addApproximation(
351 const std::list<ModelHighAPI_RefAttr>& points,
352 const ModelHighAPI_Double& precision = ModelHighAPI_Double(1.e-3),
353 const bool periodic = false,
354 const bool closed = false);
358 std::shared_ptr<SketchAPI_Projection> addProjection(
359 const ModelHighAPI_Selection & theExternalFeature,
360 bool theKeepResult = false);
364 std::shared_ptr<SketchAPI_Projection> addProjection(const std::string & theExternalName,
365 bool theKeepResult = false);
369 std::shared_ptr<SketchAPI_Mirror> addMirror(
370 const ModelHighAPI_RefAttr & theMirrorLine,
371 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects);
375 std::shared_ptr<SketchAPI_Translation> addTranslation(
376 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
377 const ModelHighAPI_RefAttr & thePoint1,
378 const ModelHighAPI_RefAttr & thePoint2,
379 const ModelHighAPI_Integer & theNumberOfObjects,
380 bool theFullValue = false);
384 std::shared_ptr<SketchAPI_Rotation> addRotation(
385 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
386 const ModelHighAPI_RefAttr & theCenter,
387 const ModelHighAPI_Double & theAngle,
388 const ModelHighAPI_Integer & theNumberOfObjects,
389 bool theFullValue = false,
390 bool theReversed = false);
394 std::shared_ptr<ModelHighAPI_Interface> addSplit(
395 const ModelHighAPI_Reference& theFeature,
396 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
400 std::shared_ptr<ModelHighAPI_Interface> addTrim(
401 const ModelHighAPI_Reference& theFeature,
402 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
406 std::shared_ptr<ModelHighAPI_Interface> setAngle(
407 const ModelHighAPI_RefAttr & theLine1,
408 const ModelHighAPI_RefAttr & theLine2,
409 const ModelHighAPI_Double & theValue,
410 const std::string& type = std::string());
412 /// Set complementary angle
414 std::shared_ptr<ModelHighAPI_Interface> setAngleComplementary(
415 const ModelHighAPI_RefAttr & theLine1,
416 const ModelHighAPI_RefAttr & theLine2,
417 const ModelHighAPI_Double & theValue);
419 /// Set backward angle (= 360 - angle)
421 std::shared_ptr<ModelHighAPI_Interface> setAngleBackward(
422 const ModelHighAPI_RefAttr & theLine1,
423 const ModelHighAPI_RefAttr & theLine2,
424 const ModelHighAPI_Double & theValue);
428 std::shared_ptr<ModelHighAPI_Interface> setCoincident(
429 const ModelHighAPI_RefAttr & thePoint1,
430 const ModelHighAPI_RefAttr & thePoint2);
434 std::shared_ptr<ModelHighAPI_Interface> setCollinear(
435 const ModelHighAPI_RefAttr & theLine1,
436 const ModelHighAPI_RefAttr & theLine2);
440 std::shared_ptr<ModelHighAPI_Interface> setDistance(
441 const ModelHighAPI_RefAttr & thePoint,
442 const ModelHighAPI_RefAttr & thePointOrLine,
443 const ModelHighAPI_Double & theValue,
444 bool isSigned = false);
446 /// Set signed distance
448 std::shared_ptr<ModelHighAPI_Interface> setSignedDistance(
449 const ModelHighAPI_RefAttr & thePoint,
450 const ModelHighAPI_RefAttr & thePointOrLine,
451 const ModelHighAPI_Double & theValue);
453 /// Set unsigned distance
455 std::shared_ptr<ModelHighAPI_Interface> setUnsignedDistance(
456 const ModelHighAPI_RefAttr & thePoint,
457 const ModelHighAPI_RefAttr & thePointOrLine,
458 const ModelHighAPI_Double & theValue);
460 /// Set horizontal distance
462 std::shared_ptr<ModelHighAPI_Interface> setHorizontalDistance(
463 const ModelHighAPI_RefAttr & thePoint1,
464 const ModelHighAPI_RefAttr & thePoint2,
465 const ModelHighAPI_Double & theValue);
467 /// Set vertical distance
469 std::shared_ptr<ModelHighAPI_Interface> setVerticalDistance(
470 const ModelHighAPI_RefAttr & thePoint1,
471 const ModelHighAPI_RefAttr & thePoint2,
472 const ModelHighAPI_Double & theValue);
476 std::shared_ptr<ModelHighAPI_Interface> setEqual(
477 const ModelHighAPI_RefAttr & theObject1,
478 const ModelHighAPI_RefAttr & theObject2);
482 std::shared_ptr<ModelHighAPI_Interface> setFillet(
483 const ModelHighAPI_RefAttr & thePoint);
485 /// Set fillet with additional radius constraint
487 std::shared_ptr<ModelHighAPI_Interface> setFilletWithRadius(
488 const ModelHighAPI_RefAttr & thePoint,
489 const ModelHighAPI_Double & theRadius);
493 std::shared_ptr<ModelHighAPI_Interface> setFixed(
494 const ModelHighAPI_RefAttr & theObject);
498 std::shared_ptr<ModelHighAPI_Interface> setHorizontal(
499 const ModelHighAPI_RefAttr & theLine);
503 std::shared_ptr<ModelHighAPI_Interface> setLength(
504 const ModelHighAPI_RefAttr & theLine,
505 const ModelHighAPI_Double & theValue);
509 std::shared_ptr<ModelHighAPI_Interface> setMiddlePoint(
510 const ModelHighAPI_RefAttr & thePoint,
511 const ModelHighAPI_RefAttr & theLine);
515 std::shared_ptr<ModelHighAPI_Interface> setParallel(
516 const ModelHighAPI_RefAttr & theLine1,
517 const ModelHighAPI_RefAttr & theLine2);
519 /// Set perpendicular
521 std::shared_ptr<ModelHighAPI_Interface> setPerpendicular(
522 const ModelHighAPI_RefAttr & theLine1,
523 const ModelHighAPI_RefAttr & theLine2);
527 std::shared_ptr<ModelHighAPI_Interface> setRadius(
528 const ModelHighAPI_RefAttr & theCircleOrArc,
529 const ModelHighAPI_Double & theValue);
533 std::shared_ptr<ModelHighAPI_Interface> setTangent(
534 const ModelHighAPI_RefAttr & theLine,
535 const ModelHighAPI_RefAttr & theCircle);
539 std::shared_ptr<ModelHighAPI_Interface> setVertical(
540 const ModelHighAPI_RefAttr & theLine);
542 /// Set constraint value
545 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
546 const ModelHighAPI_Double & theValue);
548 /// Move point or sketch feature
550 void move(const ModelHighAPI_RefAttr& theMovedEntity,
551 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint);
553 /// Move point or sketch feature
555 void move(const ModelHighAPI_RefAttr& theMovedEntity,
556 double theTargetX, double theTargetY);
559 std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
561 // TODO(spo): rename to selectFaces() or faces() (or add faces() -> list to SWIG)
564 std::list<ModelHighAPI_Selection> selectFace() const;
566 /// Dump wrapped feature
568 virtual void dump(ModelHighAPI_Dumper& theDumper) const;
571 std::shared_ptr<ModelAPI_CompositeFeature> compositeFeature() const;
575 //! Pointer on Sketch object
576 typedef std::shared_ptr<SketchAPI_Sketch> SketchPtr;
578 //--------------------------------------------------------------------------------------
580 /**\ingroup CPPHighAPI
581 * \brief Create Sketch feature
584 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
585 const std::shared_ptr<GeomAPI_Ax3> & thePlane);
587 /**\ingroup CPPHighAPI
588 * \brief Create Sketch feature
591 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
592 const ModelHighAPI_Selection & theExternal);
594 /**\ingroup CPPHighAPI
595 * \brief Create Sketch feature
598 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
599 const std::string & theExternalName);
601 /**\ingroup CPPHighAPI
602 * \brief Create Sketch feature
605 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
606 std::shared_ptr<ModelAPI_Object> thePlaneObject);
608 //--------------------------------------------------------------------------------------
610 /** \ingroup CPPHighAPI
611 * \brief Copy sketch with all its sub-features
614 SketchPtr copySketch(const std::shared_ptr<ModelAPI_Document> & thePart,
615 const SketchPtr & theSketch);
617 //--------------------------------------------------------------------------------------
618 #endif /* SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_ */