1 // Copyright (C) 2014-2019 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;
59 //--------------------------------------------------------------------------------------
60 typedef std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> PointOrReference;
61 //--------------------------------------------------------------------------------------
62 /**\class SketchAPI_Sketch
64 * \brief Interface for Sketch feature
66 class SketchAPI_Sketch : public ModelHighAPI_Interface
69 /// Constructor without values
71 explicit SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature);
72 /// Constructor with values
74 SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
75 const std::shared_ptr<GeomAPI_Ax3> & thePlane);
76 /// Constructor with values
78 SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
79 const ModelHighAPI_Selection & theExternal);
80 /// Constructor with values
82 SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
83 std::shared_ptr<ModelAPI_Object> thePlaneObject);
86 virtual ~SketchAPI_Sketch();
88 INTERFACE_7(SketchPlugin_Sketch::ID(),
89 origin, SketchPlugin_Sketch::ORIGIN_ID(),
90 GeomDataAPI_Point, /** Origin point */,
91 dirX, SketchPlugin_Sketch::DIRX_ID(),
92 GeomDataAPI_Dir, /** Direction of X */,
93 normal, SketchPlugin_Sketch::NORM_ID(),
94 GeomDataAPI_Dir, /** Normal */,
95 features, SketchPlugin_Sketch::FEATURES_ID(),
96 ModelAPI_AttributeRefList, /** Features */,
97 external, SketchPlugin_SketchEntity::EXTERNAL_ID(),
98 ModelAPI_AttributeSelection, /** External */,
99 solverError, SketchPlugin_Sketch::SOLVER_ERROR(),
100 ModelAPI_AttributeString, /** Solver error */,
101 solverDOF, SketchPlugin_Sketch::SOLVER_DOF(),
102 ModelAPI_AttributeString, /** Solver DOF */
107 void setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane);
109 /// Change sketch plane
111 void setPlane(const ModelHighAPI_Selection & thePlane,
112 bool theRemoveExternalDependency = false);
116 void setExternal(const ModelHighAPI_Selection & theExternal);
120 void setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject);
122 /// Change order of sketch results (faces)
124 void changeFacesOrder(const std::list<std::list<ModelHighAPI_Selection> >& theFaces);
126 /// List points not connected by constraints with other sketch entitites
128 std::list< std::shared_ptr<SketchAPI_Point> > getFreePoints();
132 std::shared_ptr<SketchAPI_Point> addPoint(
133 double theX, double theY);
136 std::shared_ptr<SketchAPI_Point> addPoint(
137 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint);
140 std::shared_ptr<SketchAPI_Point> addPoint(const ModelHighAPI_Selection & theExternal);
143 std::shared_ptr<SketchAPI_Point> addPoint(const std::wstring & theExternalName);
145 /// Add intersection point
147 std::shared_ptr<SketchAPI_IntersectionPoint>
148 addIntersectionPoint(const ModelHighAPI_Selection & theExternal,
149 bool theKeepResult = false);
152 std::shared_ptr<SketchAPI_IntersectionPoint>
153 addIntersectionPoint(const std::wstring & theExternalName,
154 bool theKeepResult = false);
158 std::shared_ptr<SketchAPI_Line> addLine(
159 double theX1, double theY1, double theX2, double theY2);
162 std::shared_ptr<SketchAPI_Line> addLine(
163 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
164 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
167 std::shared_ptr<SketchAPI_Line> addLine(const ModelHighAPI_Selection & theExternal);
170 std::shared_ptr<SketchAPI_Line> addLine(const std::wstring & theExternalName);
174 std::shared_ptr<SketchAPI_Rectangle> addRectangle(
175 double theX1, double theY1, double theX2, double theY2);
178 std::shared_ptr<SketchAPI_Rectangle> addRectangle(
179 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
180 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
184 std::shared_ptr<SketchAPI_Circle> addCircle(
185 double theCenterX, double theCenterY,
189 std::shared_ptr<SketchAPI_Circle> addCircle(
190 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
194 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
195 double theCenterX, double theCenterY,
196 double thePassedX, double thePassedY);
199 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
200 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
201 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
204 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
205 double theX1, double theY1,
206 double theX2, double theY2,
207 double theX3, double theY3);
210 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
211 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
212 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
213 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
216 std::shared_ptr<SketchAPI_Circle> addCircle(const ModelHighAPI_Selection & theExternal);
219 std::shared_ptr<SketchAPI_Circle> addCircle(const std::wstring & theExternalName);
223 std::shared_ptr<SketchAPI_Arc> addArc(
224 double theCenterX, double theCenterY,
225 double theStartX, double theStartY,
226 double theEndX, double theEndY,
231 std::shared_ptr<SketchAPI_Arc> addArc(
232 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
233 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
234 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
239 std::shared_ptr<SketchAPI_MacroArc> addArc(
240 double theStartX, double theStartY,
241 double theEndX, double theEndY,
242 double thePassedX, double thePassedY);
246 std::shared_ptr<SketchAPI_MacroArc> addArc(
247 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
248 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
249 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed);
251 /// Add transversal/tangent arc
253 std::shared_ptr<SketchAPI_MacroArc> addArc(
254 const ModelHighAPI_RefAttr& theConnectedPoint,
255 double theEndX, double theEndY,
257 bool theTransversal = false);
259 /// Add transversal/tangent arc
261 std::shared_ptr<SketchAPI_MacroArc> addArc(
262 const ModelHighAPI_RefAttr& theConnectedPoint,
263 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
265 bool theTransversal = false);
269 std::shared_ptr<SketchAPI_Arc> addArc(const ModelHighAPI_Selection & theExternal);
273 std::shared_ptr<SketchAPI_Arc> addArc(const std::wstring & theExternalName);
277 std::shared_ptr<SketchAPI_Ellipse> addEllipse(
278 double theCenterX, double theCenterY,
279 double theFocusX, double theFocusY,
280 double theMinorRadius);
283 std::shared_ptr<SketchAPI_Ellipse> addEllipse(
284 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
285 const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
289 std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
290 double thePoint1X, double thePoint1Y,
291 double thePoint2X, double thePoint2Y,
292 double thePassedX, double thePassedY,
293 bool isPoint1Center = true);
296 std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
297 const PointOrReference& thePoint1,
298 const PointOrReference& thePoint2,
299 const PointOrReference& thePassedPoint,
300 bool isPoint1Center = true);
303 std::shared_ptr<SketchAPI_Ellipse> addEllipse(const ModelHighAPI_Selection & theExternal);
306 std::shared_ptr<SketchAPI_Ellipse> addEllipse(const std::wstring & theExternalName);
310 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(
311 double theCenterX, double theCenterY,
312 double theFocusX, double theFocusY,
313 double theStartX, double theStartY,
314 double theEndX, double theEndY,
315 bool theInversed = false);
318 std::shared_ptr<SketchAPI_MacroEllipticArc> addEllipticArc(
319 const PointOrReference& theCenter,
320 const PointOrReference& theMajorAxisPoint,
321 const PointOrReference& theStartPoint,
322 const PointOrReference& theEndPoint,
323 bool theInversed = false);
326 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(const ModelHighAPI_Selection & theExternal);
329 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(const std::wstring & theExternalName);
333 std::shared_ptr<SketchAPI_BSpline> addSpline(
334 const ModelHighAPI_Selection & external = ModelHighAPI_Selection(),
335 const int degree = -1,
336 const std::list<PointOrReference>& poles = std::list<PointOrReference>(),
337 const std::list<ModelHighAPI_Double>& weights = std::list<ModelHighAPI_Double>(),
338 const std::list<ModelHighAPI_Double>& knots = std::list<ModelHighAPI_Double>(),
339 const std::list<ModelHighAPI_Integer>& multiplicities = std::list<ModelHighAPI_Integer>(),
340 const bool periodic = false);
342 /// Add interpolation feature
344 std::shared_ptr<SketchAPI_BSpline> addInterpolation(
345 const std::list<ModelHighAPI_RefAttr>& points,
346 const bool periodic = false,
347 const bool closed = false);
349 /// Add approximation feature
351 std::shared_ptr<SketchAPI_BSpline> addApproximation(
352 const std::list<ModelHighAPI_RefAttr>& points,
353 const ModelHighAPI_Double& precision = ModelHighAPI_Double(1.e-3),
354 const bool periodic = false,
355 const bool closed = false);
359 std::shared_ptr<SketchAPI_Projection> addProjection(
360 const ModelHighAPI_Selection & theExternalFeature,
361 bool theKeepResult = false);
365 std::shared_ptr<SketchAPI_Projection> addProjection(const std::wstring & theExternalName,
366 bool theKeepResult = false);
370 std::shared_ptr<SketchAPI_Mirror> addMirror(
371 const ModelHighAPI_RefAttr & theMirrorLine,
372 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects);
376 std::shared_ptr<SketchAPI_Offset> addOffset(
377 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
378 const ModelHighAPI_Double & theValue,
379 const bool theReversed);
383 std::shared_ptr<SketchAPI_Translation> addTranslation(
384 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
385 const ModelHighAPI_RefAttr & thePoint1,
386 const ModelHighAPI_RefAttr & thePoint2,
387 const ModelHighAPI_Integer & theNumberOfObjects,
388 bool theFullValue = false);
392 std::shared_ptr<SketchAPI_Rotation> addRotation(
393 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
394 const ModelHighAPI_RefAttr & theCenter,
395 const ModelHighAPI_Double & theAngle,
396 const ModelHighAPI_Integer & theNumberOfObjects,
397 bool theFullValue = false,
398 bool theReversed = false);
402 std::shared_ptr<ModelHighAPI_Interface> addSplit(
403 const ModelHighAPI_Reference& theFeature,
404 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
408 std::shared_ptr<ModelHighAPI_Interface> addTrim(
409 const ModelHighAPI_Reference& theFeature,
410 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
414 std::shared_ptr<ModelHighAPI_Interface> setAngle(
415 const ModelHighAPI_RefAttr & theLine1,
416 const ModelHighAPI_RefAttr & theLine2,
417 const ModelHighAPI_Double & theValue,
418 const std::string& type = std::string());
420 /// Set complementary angle
422 std::shared_ptr<ModelHighAPI_Interface> setAngleComplementary(
423 const ModelHighAPI_RefAttr & theLine1,
424 const ModelHighAPI_RefAttr & theLine2,
425 const ModelHighAPI_Double & theValue);
427 /// Set backward angle (= 360 - angle)
429 std::shared_ptr<ModelHighAPI_Interface> setAngleBackward(
430 const ModelHighAPI_RefAttr & theLine1,
431 const ModelHighAPI_RefAttr & theLine2,
432 const ModelHighAPI_Double & theValue);
436 std::shared_ptr<ModelHighAPI_Interface> setCoincident(
437 const ModelHighAPI_RefAttr & thePoint1,
438 const ModelHighAPI_RefAttr & thePoint2);
442 std::shared_ptr<ModelHighAPI_Interface> setCollinear(
443 const ModelHighAPI_RefAttr & theLine1,
444 const ModelHighAPI_RefAttr & theLine2);
448 std::shared_ptr<ModelHighAPI_Interface> setDistance(
449 const ModelHighAPI_RefAttr & thePoint,
450 const ModelHighAPI_RefAttr & thePointOrLine,
451 const ModelHighAPI_Double & theValue,
452 bool isSigned = false);
454 /// Set signed distance
456 std::shared_ptr<ModelHighAPI_Interface> setSignedDistance(
457 const ModelHighAPI_RefAttr & thePoint,
458 const ModelHighAPI_RefAttr & thePointOrLine,
459 const ModelHighAPI_Double & theValue);
461 /// Set unsigned distance
463 std::shared_ptr<ModelHighAPI_Interface> setUnsignedDistance(
464 const ModelHighAPI_RefAttr & thePoint,
465 const ModelHighAPI_RefAttr & thePointOrLine,
466 const ModelHighAPI_Double & theValue);
468 /// Set horizontal distance
470 std::shared_ptr<ModelHighAPI_Interface> setHorizontalDistance(
471 const ModelHighAPI_RefAttr & thePoint1,
472 const ModelHighAPI_RefAttr & thePoint2,
473 const ModelHighAPI_Double & theValue);
475 /// Set vertical distance
477 std::shared_ptr<ModelHighAPI_Interface> setVerticalDistance(
478 const ModelHighAPI_RefAttr & thePoint1,
479 const ModelHighAPI_RefAttr & thePoint2,
480 const ModelHighAPI_Double & theValue);
484 std::shared_ptr<ModelHighAPI_Interface> setEqual(
485 const ModelHighAPI_RefAttr & theObject1,
486 const ModelHighAPI_RefAttr & theObject2);
490 std::shared_ptr<ModelHighAPI_Interface> setFillet(
491 const ModelHighAPI_RefAttr & thePoint);
493 /// Set fillet with additional radius constraint
495 std::shared_ptr<ModelHighAPI_Interface> setFilletWithRadius(
496 const ModelHighAPI_RefAttr & thePoint,
497 const ModelHighAPI_Double & theRadius);
501 std::shared_ptr<ModelHighAPI_Interface> setFixed(
502 const ModelHighAPI_RefAttr & theObject);
506 std::shared_ptr<ModelHighAPI_Interface> setHorizontal(
507 const ModelHighAPI_RefAttr & theLine);
511 std::shared_ptr<ModelHighAPI_Interface> setLength(
512 const ModelHighAPI_RefAttr & theLine,
513 const ModelHighAPI_Double & theValue);
517 std::shared_ptr<ModelHighAPI_Interface> setMiddlePoint(
518 const ModelHighAPI_RefAttr & thePoint,
519 const ModelHighAPI_RefAttr & theLine);
523 std::shared_ptr<ModelHighAPI_Interface> setParallel(
524 const ModelHighAPI_RefAttr & theLine1,
525 const ModelHighAPI_RefAttr & theLine2);
527 /// Set perpendicular
529 std::shared_ptr<ModelHighAPI_Interface> setPerpendicular(
530 const ModelHighAPI_RefAttr & theLine1,
531 const ModelHighAPI_RefAttr & theLine2);
535 std::shared_ptr<ModelHighAPI_Interface> setRadius(
536 const ModelHighAPI_RefAttr & theCircleOrArc,
537 const ModelHighAPI_Double & theValue);
541 std::shared_ptr<ModelHighAPI_Interface> setTangent(
542 const ModelHighAPI_RefAttr & theLine,
543 const ModelHighAPI_RefAttr & theCircle);
547 std::shared_ptr<ModelHighAPI_Interface> setVertical(
548 const ModelHighAPI_RefAttr & theLine);
550 /// Set constraint value
553 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
554 const ModelHighAPI_Double & theValue);
556 /// Move point or sketch feature
558 void move(const ModelHighAPI_RefAttr& theMovedEntity,
559 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint);
561 /// Move point or sketch feature
563 void move(const ModelHighAPI_RefAttr& theMovedEntity,
564 double theTargetX, double theTargetY);
567 std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
569 // TODO(spo): rename to selectFaces() or faces() (or add faces() -> list to SWIG)
572 std::list<ModelHighAPI_Selection> selectFace() const;
574 /// Dump wrapped feature
576 virtual void dump(ModelHighAPI_Dumper& theDumper) const;
579 std::shared_ptr<ModelAPI_CompositeFeature> compositeFeature() const;
583 //! Pointer on Sketch object
584 typedef std::shared_ptr<SketchAPI_Sketch> SketchPtr;
586 //--------------------------------------------------------------------------------------
588 /**\ingroup CPPHighAPI
589 * \brief Create Sketch feature
592 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
593 const std::shared_ptr<GeomAPI_Ax3> & thePlane);
595 /**\ingroup CPPHighAPI
596 * \brief Create Sketch feature
599 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
600 const ModelHighAPI_Selection & theExternal);
602 /**\ingroup CPPHighAPI
603 * \brief Create Sketch feature
606 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
607 const std::wstring & theExternalName);
609 /**\ingroup CPPHighAPI
610 * \brief Create Sketch feature
613 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
614 std::shared_ptr<ModelAPI_Object> thePlaneObject);
616 //--------------------------------------------------------------------------------------
618 /** \ingroup CPPHighAPI
619 * \brief Copy sketch with all its sub-features
622 SketchPtr copySketch(const std::shared_ptr<ModelAPI_Document> & thePart,
623 const SketchPtr & theSketch);
625 //--------------------------------------------------------------------------------------
626 #endif /* SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_ */