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_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> addRectangle(
185 double theX1, double theY1, double theX2, double theY2, bool isFirstPointCenter);
188 std::shared_ptr<SketchAPI_Rectangle> addRectangle(
189 const std::shared_ptr<GeomAPI_Pnt2d> & theFirstPoint,
190 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint, bool isFirstPointCenter);
193 std::shared_ptr<SketchAPI_Rectangle> addRectangleCentered(
194 double theX1, double theY1, double theX2, double theY2);
197 std::shared_ptr<SketchAPI_Rectangle> addRectangleCentered(
198 const std::shared_ptr<GeomAPI_Pnt2d> & theFirstPoint,
199 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
202 std::shared_ptr<SketchAPI_Circle> addCircle(
203 double theCenterX, double theCenterY,
207 std::shared_ptr<SketchAPI_Circle> addCircle(
208 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
212 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
213 double theCenterX, double theCenterY,
214 double thePassedX, double thePassedY);
217 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
218 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
219 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
222 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
223 double theX1, double theY1,
224 double theX2, double theY2,
225 double theX3, double theY3);
228 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
229 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
230 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
231 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
234 std::shared_ptr<SketchAPI_Circle> addCircle(const ModelHighAPI_Selection & theExternal);
237 std::shared_ptr<SketchAPI_Circle> addCircle(const std::wstring & theExternalName);
241 std::shared_ptr<SketchAPI_Arc> addArc(
242 double theCenterX, double theCenterY,
243 double theStartX, double theStartY,
244 double theEndX, double theEndY,
249 std::shared_ptr<SketchAPI_Arc> addArc(
250 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
251 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
252 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
257 std::shared_ptr<SketchAPI_MacroArc> addArc(
258 double theStartX, double theStartY,
259 double theEndX, double theEndY,
260 double thePassedX, double thePassedY);
264 std::shared_ptr<SketchAPI_MacroArc> addArc(
265 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
266 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
267 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed);
269 /// Add transversal/tangent arc
271 std::shared_ptr<SketchAPI_MacroArc> addArc(
272 const ModelHighAPI_RefAttr& theConnectedPoint,
273 double theEndX, double theEndY,
275 bool theTransversal = false);
277 /// Add transversal/tangent arc
279 std::shared_ptr<SketchAPI_MacroArc> addArc(
280 const ModelHighAPI_RefAttr& theConnectedPoint,
281 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
283 bool theTransversal = false);
287 std::shared_ptr<SketchAPI_Arc> addArc(const ModelHighAPI_Selection & theExternal);
291 std::shared_ptr<SketchAPI_Arc> addArc(const std::wstring & theExternalName);
295 std::shared_ptr<SketchAPI_Ellipse> addEllipse(
296 double theCenterX, double theCenterY,
297 double theFocusX, double theFocusY,
298 double theMinorRadius);
301 std::shared_ptr<SketchAPI_Ellipse> addEllipse(
302 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
303 const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
307 std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
308 double thePoint1X, double thePoint1Y,
309 double thePoint2X, double thePoint2Y,
310 double thePassedX, double thePassedY,
311 bool isPoint1Center = true);
314 std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
315 const PointOrReference& thePoint1,
316 const PointOrReference& thePoint2,
317 const PointOrReference& thePassedPoint,
318 bool isPoint1Center = true);
321 std::shared_ptr<SketchAPI_Ellipse> addEllipse(const ModelHighAPI_Selection & theExternal);
324 std::shared_ptr<SketchAPI_Ellipse> addEllipse(const std::wstring & theExternalName);
328 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(
329 double theCenterX, double theCenterY,
330 double theFocusX, double theFocusY,
331 double theStartX, double theStartY,
332 double theEndX, double theEndY,
333 bool theInversed = false);
336 std::shared_ptr<SketchAPI_MacroEllipticArc> addEllipticArc(
337 const PointOrReference& theCenter,
338 const PointOrReference& theMajorAxisPoint,
339 const PointOrReference& theStartPoint,
340 const PointOrReference& theEndPoint,
341 bool theInversed = false);
344 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(const ModelHighAPI_Selection & theExternal);
347 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(const std::wstring & theExternalName);
351 std::shared_ptr<SketchAPI_BSpline> addSpline(
352 const ModelHighAPI_Selection & external = ModelHighAPI_Selection(),
353 const int degree = -1,
354 const std::list<PointOrReference>& poles = std::list<PointOrReference>(),
355 const std::list<ModelHighAPI_Double>& weights = std::list<ModelHighAPI_Double>(),
356 const std::list<ModelHighAPI_Double>& knots = std::list<ModelHighAPI_Double>(),
357 const std::list<ModelHighAPI_Integer>& multiplicities = std::list<ModelHighAPI_Integer>(),
358 const bool periodic = false);
360 /// Add interpolation feature
362 std::shared_ptr<SketchAPI_BSpline> addInterpolation(
363 const std::list<ModelHighAPI_RefAttr>& points,
364 const bool periodic = false,
365 const bool closed = false);
367 /// Add approximation feature
369 std::shared_ptr<SketchAPI_BSpline> addApproximation(
370 const std::list<ModelHighAPI_RefAttr>& points,
371 const ModelHighAPI_Double& precision = ModelHighAPI_Double(1.e-3),
372 const bool periodic = false,
373 const bool closed = false);
377 std::shared_ptr<SketchAPI_Projection> addProjection(
378 const ModelHighAPI_Selection & theExternalFeature,
379 bool keepResult = false,
380 bool keepRefToOriginal = true);
384 std::shared_ptr<SketchAPI_Mirror> addMirror(
385 const ModelHighAPI_RefAttr & theMirrorLine,
386 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects);
390 std::shared_ptr<SketchAPI_Offset> addOffset(
391 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
392 const ModelHighAPI_Double & theValue,
393 const bool theReversed);
397 std::shared_ptr<SketchAPI_Translation> addTranslation(
398 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
399 const ModelHighAPI_RefAttr & thePoint1,
400 const ModelHighAPI_RefAttr & thePoint2,
401 const ModelHighAPI_Integer & theNumberOfObjects,
402 bool theFullValue = false);
406 std::shared_ptr<SketchAPI_Rotation> addRotation(
407 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
408 const ModelHighAPI_RefAttr & theCenter,
409 const ModelHighAPI_Double & theAngle,
410 const ModelHighAPI_Integer & theNumberOfObjects,
411 bool theFullValue = false,
412 bool theReversed = false);
416 std::shared_ptr<ModelHighAPI_Interface> addSplit(
417 const ModelHighAPI_Reference& theFeature,
418 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
422 std::shared_ptr<ModelHighAPI_Interface> addTrim(
423 const ModelHighAPI_Reference& theFeature,
424 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
428 std::shared_ptr<ModelHighAPI_Interface> setAngle(
429 const ModelHighAPI_RefAttr & theLine1,
430 const ModelHighAPI_RefAttr & theLine2,
431 const ModelHighAPI_Double & theValue,
432 const std::string& type = std::string());
434 /// Set complementary angle
436 std::shared_ptr<ModelHighAPI_Interface> setAngleComplementary(
437 const ModelHighAPI_RefAttr & theLine1,
438 const ModelHighAPI_RefAttr & theLine2,
439 const ModelHighAPI_Double & theValue);
441 /// Set backward angle (= 360 - angle)
443 std::shared_ptr<ModelHighAPI_Interface> setAngleBackward(
444 const ModelHighAPI_RefAttr & theLine1,
445 const ModelHighAPI_RefAttr & theLine2,
446 const ModelHighAPI_Double & theValue);
450 std::shared_ptr<ModelHighAPI_Interface> setCoincident(
451 const ModelHighAPI_RefAttr & thePoint1,
452 const ModelHighAPI_RefAttr & thePoint2);
456 std::shared_ptr<ModelHighAPI_Interface> setCollinear(
457 const ModelHighAPI_RefAttr & theLine1,
458 const ModelHighAPI_RefAttr & theLine2);
462 std::shared_ptr<ModelHighAPI_Interface> setDistance(
463 const ModelHighAPI_RefAttr & thePoint,
464 const ModelHighAPI_RefAttr & thePointOrLine,
465 const ModelHighAPI_Double & theValue,
466 bool isSigned = false);
468 /// Set signed distance
470 std::shared_ptr<ModelHighAPI_Interface> setSignedDistance(
471 const ModelHighAPI_RefAttr & thePoint,
472 const ModelHighAPI_RefAttr & thePointOrLine,
473 const ModelHighAPI_Double & theValue);
475 /// Set unsigned distance
477 std::shared_ptr<ModelHighAPI_Interface> setUnsignedDistance(
478 const ModelHighAPI_RefAttr & thePoint,
479 const ModelHighAPI_RefAttr & thePointOrLine,
480 const ModelHighAPI_Double & theValue);
482 /// Set horizontal distance
484 std::shared_ptr<ModelHighAPI_Interface> setHorizontalDistance(
485 const ModelHighAPI_RefAttr & thePoint1,
486 const ModelHighAPI_RefAttr & thePoint2,
487 const ModelHighAPI_Double & theValue);
489 /// Set vertical distance
491 std::shared_ptr<ModelHighAPI_Interface> setVerticalDistance(
492 const ModelHighAPI_RefAttr & thePoint1,
493 const ModelHighAPI_RefAttr & thePoint2,
494 const ModelHighAPI_Double & theValue);
498 std::shared_ptr<ModelHighAPI_Interface> setEqual(
499 const ModelHighAPI_RefAttr & theObject1,
500 const ModelHighAPI_RefAttr & theObject2);
504 std::shared_ptr<ModelHighAPI_Interface> setFillet(
505 const ModelHighAPI_RefAttr & thePoint);
507 /// Set fillet with additional radius constraint
509 std::shared_ptr<ModelHighAPI_Interface> setFilletWithRadius(
510 const ModelHighAPI_RefAttr & thePoint,
511 const ModelHighAPI_Double & theRadius);
515 std::shared_ptr<ModelHighAPI_Interface> setFixed(
516 const ModelHighAPI_RefAttr & theObject);
520 std::shared_ptr<ModelHighAPI_Interface> setHorizontal(
521 const ModelHighAPI_RefAttr & theLine);
525 std::shared_ptr<ModelHighAPI_Interface> setLength(
526 const ModelHighAPI_RefAttr & theLine,
527 const ModelHighAPI_Double & theValue);
531 std::shared_ptr<ModelHighAPI_Interface> setMiddlePoint(
532 const ModelHighAPI_RefAttr & thePoint,
533 const ModelHighAPI_RefAttr & theLine);
537 std::shared_ptr<ModelHighAPI_Interface> setParallel(
538 const ModelHighAPI_RefAttr & theLine1,
539 const ModelHighAPI_RefAttr & theLine2);
541 /// Set perpendicular
543 std::shared_ptr<ModelHighAPI_Interface> setPerpendicular(
544 const ModelHighAPI_RefAttr & theLine1,
545 const ModelHighAPI_RefAttr & theLine2);
549 std::shared_ptr<ModelHighAPI_Interface> setRadius(
550 const ModelHighAPI_RefAttr & theCircleOrArc,
551 const ModelHighAPI_Double & theValue);
555 std::shared_ptr<ModelHighAPI_Interface> setTangent(
556 const ModelHighAPI_RefAttr & theLine,
557 const ModelHighAPI_RefAttr & theCircle);
561 std::shared_ptr<ModelHighAPI_Interface> setVertical(
562 const ModelHighAPI_RefAttr & theLine);
564 /// Set constraint value
567 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
568 const ModelHighAPI_Double & theValue);
570 /// Move point or sketch feature
572 void move(const ModelHighAPI_RefAttr& theMovedEntity,
573 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint);
575 /// Move point or sketch feature
577 void move(const ModelHighAPI_RefAttr& theMovedEntity,
578 double theTargetX, double theTargetY);
581 std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
583 // TODO(spo): rename to selectFaces() or faces() (or add faces() -> list to SWIG)
586 std::list<ModelHighAPI_Selection> selectFace() const;
588 /// Dump wrapped feature
590 virtual void dump(ModelHighAPI_Dumper& theDumper) const;
593 std::shared_ptr<ModelAPI_CompositeFeature> compositeFeature() const;
597 //! Pointer on Sketch object
598 typedef std::shared_ptr<SketchAPI_Sketch> SketchPtr;
600 //--------------------------------------------------------------------------------------
602 /**\ingroup CPPHighAPI
603 * \brief Create Sketch feature
606 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
607 const std::shared_ptr<GeomAPI_Ax3> & thePlane);
609 /**\ingroup CPPHighAPI
610 * \brief Create Sketch feature
613 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
614 const ModelHighAPI_Selection & theExternal);
616 /**\ingroup CPPHighAPI
617 * \brief Create Sketch feature
620 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
621 const std::wstring & theExternalName);
623 /**\ingroup CPPHighAPI
624 * \brief Create Sketch feature
627 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
628 std::shared_ptr<ModelAPI_Object> thePlaneObject);
630 //--------------------------------------------------------------------------------------
632 /** \ingroup CPPHighAPI
633 * \brief Copy sketch with all its sub-features
636 SketchPtr copySketch(const std::shared_ptr<ModelAPI_Document> & thePart,
637 const SketchPtr & theSketch);
639 //--------------------------------------------------------------------------------------
640 #endif /* SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_ */