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);
194 std::shared_ptr<SketchAPI_Circle> addCircle(
195 double theCenterX, double theCenterY,
199 std::shared_ptr<SketchAPI_Circle> addCircle(
200 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
204 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
205 double theCenterX, double theCenterY,
206 double thePassedX, double thePassedY);
209 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
210 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
211 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
214 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
215 double theX1, double theY1,
216 double theX2, double theY2,
217 double theX3, double theY3);
220 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
221 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
222 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
223 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
226 std::shared_ptr<SketchAPI_Circle> addCircle(const ModelHighAPI_Selection & theExternal);
229 std::shared_ptr<SketchAPI_Circle> addCircle(const std::wstring & theExternalName);
233 std::shared_ptr<SketchAPI_Arc> addArc(
234 double theCenterX, double theCenterY,
235 double theStartX, double theStartY,
236 double theEndX, double theEndY,
241 std::shared_ptr<SketchAPI_Arc> addArc(
242 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
243 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
244 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
249 std::shared_ptr<SketchAPI_MacroArc> addArc(
250 double theStartX, double theStartY,
251 double theEndX, double theEndY,
252 double thePassedX, double thePassedY);
256 std::shared_ptr<SketchAPI_MacroArc> addArc(
257 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
258 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
259 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed);
261 /// Add transversal/tangent arc
263 std::shared_ptr<SketchAPI_MacroArc> addArc(
264 const ModelHighAPI_RefAttr& theConnectedPoint,
265 double theEndX, double theEndY,
267 bool theTransversal = false);
269 /// Add transversal/tangent arc
271 std::shared_ptr<SketchAPI_MacroArc> addArc(
272 const ModelHighAPI_RefAttr& theConnectedPoint,
273 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
275 bool theTransversal = false);
279 std::shared_ptr<SketchAPI_Arc> addArc(const ModelHighAPI_Selection & theExternal);
283 std::shared_ptr<SketchAPI_Arc> addArc(const std::wstring & theExternalName);
287 std::shared_ptr<SketchAPI_Ellipse> addEllipse(
288 double theCenterX, double theCenterY,
289 double theFocusX, double theFocusY,
290 double theMinorRadius);
293 std::shared_ptr<SketchAPI_Ellipse> addEllipse(
294 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
295 const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
299 std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
300 double thePoint1X, double thePoint1Y,
301 double thePoint2X, double thePoint2Y,
302 double thePassedX, double thePassedY,
303 bool isPoint1Center = true);
306 std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
307 const PointOrReference& thePoint1,
308 const PointOrReference& thePoint2,
309 const PointOrReference& thePassedPoint,
310 bool isPoint1Center = true);
313 std::shared_ptr<SketchAPI_Ellipse> addEllipse(const ModelHighAPI_Selection & theExternal);
316 std::shared_ptr<SketchAPI_Ellipse> addEllipse(const std::wstring & theExternalName);
320 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(
321 double theCenterX, double theCenterY,
322 double theFocusX, double theFocusY,
323 double theStartX, double theStartY,
324 double theEndX, double theEndY,
325 bool theInversed = false);
328 std::shared_ptr<SketchAPI_MacroEllipticArc> addEllipticArc(
329 const PointOrReference& theCenter,
330 const PointOrReference& theMajorAxisPoint,
331 const PointOrReference& theStartPoint,
332 const PointOrReference& theEndPoint,
333 bool theInversed = false);
336 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(const ModelHighAPI_Selection & theExternal);
339 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(const std::wstring & theExternalName);
343 std::shared_ptr<SketchAPI_BSpline> addSpline(
344 const ModelHighAPI_Selection & external = ModelHighAPI_Selection(),
345 const int degree = -1,
346 const std::list<PointOrReference>& poles = std::list<PointOrReference>(),
347 const std::list<ModelHighAPI_Double>& weights = std::list<ModelHighAPI_Double>(),
348 const std::list<ModelHighAPI_Double>& knots = std::list<ModelHighAPI_Double>(),
349 const std::list<ModelHighAPI_Integer>& multiplicities = std::list<ModelHighAPI_Integer>(),
350 const bool periodic = false);
352 /// Add interpolation feature
354 std::shared_ptr<SketchAPI_BSpline> addInterpolation(
355 const std::list<ModelHighAPI_RefAttr>& points,
356 const bool periodic = false,
357 const bool closed = false);
359 /// Add approximation feature
361 std::shared_ptr<SketchAPI_BSpline> addApproximation(
362 const std::list<ModelHighAPI_RefAttr>& points,
363 const ModelHighAPI_Double& precision = ModelHighAPI_Double(1.e-3),
364 const bool periodic = false,
365 const bool closed = false);
369 std::shared_ptr<SketchAPI_Projection> addProjection(
370 const ModelHighAPI_Selection & theExternalFeature,
371 bool keepResult = false,
372 bool keepRefToOriginal = true);
376 std::shared_ptr<SketchAPI_Mirror> addMirror(
377 const ModelHighAPI_RefAttr & theMirrorLine,
378 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects);
382 std::shared_ptr<SketchAPI_Offset> addOffset(
383 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
384 const ModelHighAPI_Double & theValue,
385 const bool theReversed);
389 std::shared_ptr<SketchAPI_Translation> addTranslation(
390 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
391 const ModelHighAPI_RefAttr & thePoint1,
392 const ModelHighAPI_RefAttr & thePoint2,
393 const ModelHighAPI_Integer & theNumberOfObjects,
394 bool theFullValue = false);
398 std::shared_ptr<SketchAPI_Rotation> addRotation(
399 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
400 const ModelHighAPI_RefAttr & theCenter,
401 const ModelHighAPI_Double & theAngle,
402 const ModelHighAPI_Integer & theNumberOfObjects,
403 bool theFullValue = false,
404 bool theReversed = false);
408 std::shared_ptr<ModelHighAPI_Interface> addSplit(
409 const ModelHighAPI_Reference& theFeature,
410 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
414 std::shared_ptr<ModelHighAPI_Interface> addTrim(
415 const ModelHighAPI_Reference& theFeature,
416 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
420 std::shared_ptr<ModelHighAPI_Interface> setAngle(
421 const ModelHighAPI_RefAttr & theLine1,
422 const ModelHighAPI_RefAttr & theLine2,
423 const ModelHighAPI_Double & theValue,
424 const std::string& type = std::string());
426 /// Set complementary angle
428 std::shared_ptr<ModelHighAPI_Interface> setAngleComplementary(
429 const ModelHighAPI_RefAttr & theLine1,
430 const ModelHighAPI_RefAttr & theLine2,
431 const ModelHighAPI_Double & theValue);
433 /// Set backward angle (= 360 - angle)
435 std::shared_ptr<ModelHighAPI_Interface> setAngleBackward(
436 const ModelHighAPI_RefAttr & theLine1,
437 const ModelHighAPI_RefAttr & theLine2,
438 const ModelHighAPI_Double & theValue);
442 std::shared_ptr<ModelHighAPI_Interface> setCoincident(
443 const ModelHighAPI_RefAttr & thePoint1,
444 const ModelHighAPI_RefAttr & thePoint2);
448 std::shared_ptr<ModelHighAPI_Interface> setCollinear(
449 const ModelHighAPI_RefAttr & theLine1,
450 const ModelHighAPI_RefAttr & theLine2);
454 std::shared_ptr<ModelHighAPI_Interface> setDistance(
455 const ModelHighAPI_RefAttr & thePoint,
456 const ModelHighAPI_RefAttr & thePointOrLine,
457 const ModelHighAPI_Double & theValue,
458 bool isSigned = false);
460 /// Set signed distance
462 std::shared_ptr<ModelHighAPI_Interface> setSignedDistance(
463 const ModelHighAPI_RefAttr & thePoint,
464 const ModelHighAPI_RefAttr & thePointOrLine,
465 const ModelHighAPI_Double & theValue);
467 /// Set unsigned distance
469 std::shared_ptr<ModelHighAPI_Interface> setUnsignedDistance(
470 const ModelHighAPI_RefAttr & thePoint,
471 const ModelHighAPI_RefAttr & thePointOrLine,
472 const ModelHighAPI_Double & theValue);
474 /// Set horizontal distance
476 std::shared_ptr<ModelHighAPI_Interface> setHorizontalDistance(
477 const ModelHighAPI_RefAttr & thePoint1,
478 const ModelHighAPI_RefAttr & thePoint2,
479 const ModelHighAPI_Double & theValue);
481 /// Set vertical distance
483 std::shared_ptr<ModelHighAPI_Interface> setVerticalDistance(
484 const ModelHighAPI_RefAttr & thePoint1,
485 const ModelHighAPI_RefAttr & thePoint2,
486 const ModelHighAPI_Double & theValue);
490 std::shared_ptr<ModelHighAPI_Interface> setEqual(
491 const ModelHighAPI_RefAttr & theObject1,
492 const ModelHighAPI_RefAttr & theObject2);
496 std::shared_ptr<ModelHighAPI_Interface> setFillet(
497 const ModelHighAPI_RefAttr & thePoint);
499 /// Set fillet with additional radius constraint
501 std::shared_ptr<ModelHighAPI_Interface> setFilletWithRadius(
502 const ModelHighAPI_RefAttr & thePoint,
503 const ModelHighAPI_Double & theRadius);
507 std::shared_ptr<ModelHighAPI_Interface> setFixed(
508 const ModelHighAPI_RefAttr & theObject);
512 std::shared_ptr<ModelHighAPI_Interface> setHorizontal(
513 const ModelHighAPI_RefAttr & theLine);
517 std::shared_ptr<ModelHighAPI_Interface> setLength(
518 const ModelHighAPI_RefAttr & theLine,
519 const ModelHighAPI_Double & theValue);
523 std::shared_ptr<ModelHighAPI_Interface> setMiddlePoint(
524 const ModelHighAPI_RefAttr & thePoint,
525 const ModelHighAPI_RefAttr & theLine);
529 std::shared_ptr<ModelHighAPI_Interface> setParallel(
530 const ModelHighAPI_RefAttr & theLine1,
531 const ModelHighAPI_RefAttr & theLine2);
533 /// Set perpendicular
535 std::shared_ptr<ModelHighAPI_Interface> setPerpendicular(
536 const ModelHighAPI_RefAttr & theLine1,
537 const ModelHighAPI_RefAttr & theLine2);
541 std::shared_ptr<ModelHighAPI_Interface> setRadius(
542 const ModelHighAPI_RefAttr & theCircleOrArc,
543 const ModelHighAPI_Double & theValue);
547 std::shared_ptr<ModelHighAPI_Interface> setTangent(
548 const ModelHighAPI_RefAttr & theLine,
549 const ModelHighAPI_RefAttr & theCircle);
553 std::shared_ptr<ModelHighAPI_Interface> setVertical(
554 const ModelHighAPI_RefAttr & theLine);
556 /// Set constraint value
559 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
560 const ModelHighAPI_Double & theValue);
562 /// Move point or sketch feature
564 void move(const ModelHighAPI_RefAttr& theMovedEntity,
565 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint);
567 /// Move point or sketch feature
569 void move(const ModelHighAPI_RefAttr& theMovedEntity,
570 double theTargetX, double theTargetY);
573 std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
575 // TODO(spo): rename to selectFaces() or faces() (or add faces() -> list to SWIG)
578 std::list<ModelHighAPI_Selection> selectFace() const;
580 /// Dump wrapped feature
582 virtual void dump(ModelHighAPI_Dumper& theDumper) const;
585 std::shared_ptr<ModelAPI_CompositeFeature> compositeFeature() const;
589 //! Pointer on Sketch object
590 typedef std::shared_ptr<SketchAPI_Sketch> SketchPtr;
592 //--------------------------------------------------------------------------------------
594 /**\ingroup CPPHighAPI
595 * \brief Create Sketch feature
598 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
599 const std::shared_ptr<GeomAPI_Ax3> & thePlane);
601 /**\ingroup CPPHighAPI
602 * \brief Create Sketch feature
605 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
606 const ModelHighAPI_Selection & theExternal);
608 /**\ingroup CPPHighAPI
609 * \brief Create Sketch feature
612 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
613 const std::wstring & theExternalName);
615 /**\ingroup CPPHighAPI
616 * \brief Create Sketch feature
619 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
620 std::shared_ptr<ModelAPI_Object> thePlaneObject);
622 //--------------------------------------------------------------------------------------
624 /** \ingroup CPPHighAPI
625 * \brief Copy sketch with all its sub-features
628 SketchPtr copySketch(const std::shared_ptr<ModelAPI_Document> & thePart,
629 const SketchPtr & theSketch);
631 //--------------------------------------------------------------------------------------
632 #endif /* SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_ */