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_Interface.h>
32 #include <ModelHighAPI_Macro.h>
33 #include <ModelHighAPI_Selection.h>
34 //--------------------------------------------------------------------------------------
35 class ModelAPI_CompositeFeature;
36 class ModelAPI_Object;
37 class ModelHighAPI_Double;
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 /**\class SketchAPI_Sketch
61 * \brief Interface for Sketch feature
63 class SketchAPI_Sketch : public ModelHighAPI_Interface
66 /// Constructor without values
68 explicit SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature);
69 /// Constructor with values
71 SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
72 const std::shared_ptr<GeomAPI_Ax3> & thePlane);
73 /// Constructor with values
75 SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
76 const ModelHighAPI_Selection & theExternal);
77 /// Constructor with values
79 SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
80 std::shared_ptr<ModelAPI_Object> thePlaneObject);
83 virtual ~SketchAPI_Sketch();
85 INTERFACE_7(SketchPlugin_Sketch::ID(),
86 origin, SketchPlugin_Sketch::ORIGIN_ID(),
87 GeomDataAPI_Point, /** Origin point */,
88 dirX, SketchPlugin_Sketch::DIRX_ID(),
89 GeomDataAPI_Dir, /** Direction of X */,
90 normal, SketchPlugin_Sketch::NORM_ID(),
91 GeomDataAPI_Dir, /** Normal */,
92 features, SketchPlugin_Sketch::FEATURES_ID(),
93 ModelAPI_AttributeRefList, /** Features */,
94 external, SketchPlugin_SketchEntity::EXTERNAL_ID(),
95 ModelAPI_AttributeSelection, /** External */,
96 solverError, SketchPlugin_Sketch::SOLVER_ERROR(),
97 ModelAPI_AttributeString, /** Solver error */,
98 solverDOF, SketchPlugin_Sketch::SOLVER_DOF(),
99 ModelAPI_AttributeString, /** Solver DOF */
104 void setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane);
106 /// Change sketch plane
108 void setPlane(const ModelHighAPI_Selection & thePlane,
109 bool theRemoveExternalDependency = false);
113 void setExternal(const ModelHighAPI_Selection & theExternal);
117 void setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject);
119 /// Change order of sketch results (faces)
121 void changeFacesOrder(const std::list<std::list<ModelHighAPI_Selection> >& theFaces);
123 /// List points not connected by constraints with other sketch entitites
125 std::list< std::shared_ptr<SketchAPI_Point> > getFreePoints();
129 std::shared_ptr<SketchAPI_Point> addPoint(
130 double theX, double theY);
133 std::shared_ptr<SketchAPI_Point> addPoint(
134 const std::shared_ptr<GeomAPI_Pnt2d> & thePoint);
137 std::shared_ptr<SketchAPI_Point> addPoint(const ModelHighAPI_Selection & theExternal);
140 std::shared_ptr<SketchAPI_Point> addPoint(const std::string & theExternalName);
142 /// Add intersection point
144 std::shared_ptr<SketchAPI_IntersectionPoint>
145 addIntersectionPoint(const ModelHighAPI_Selection & theExternal,
146 bool theKeepResult = false);
149 std::shared_ptr<SketchAPI_IntersectionPoint>
150 addIntersectionPoint(const std::string & theExternalName,
151 bool theKeepResult = false);
155 std::shared_ptr<SketchAPI_Line> addLine(
156 double theX1, double theY1, double theX2, double theY2);
159 std::shared_ptr<SketchAPI_Line> addLine(
160 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
161 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
164 std::shared_ptr<SketchAPI_Line> addLine(const ModelHighAPI_Selection & theExternal);
167 std::shared_ptr<SketchAPI_Line> addLine(const std::string & theExternalName);
171 std::shared_ptr<SketchAPI_Rectangle> addRectangle(
172 double theX1, double theY1, double theX2, double theY2);
175 std::shared_ptr<SketchAPI_Rectangle> addRectangle(
176 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
177 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
181 std::shared_ptr<SketchAPI_Circle> addCircle(
182 double theCenterX, double theCenterY,
186 std::shared_ptr<SketchAPI_Circle> addCircle(
187 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
191 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
192 double theCenterX, double theCenterY,
193 double thePassedX, double thePassedY);
196 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
197 const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
198 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
201 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
202 double theX1, double theY1,
203 double theX2, double theY2,
204 double theX3, double theY3);
207 std::shared_ptr<SketchAPI_MacroCircle> addCircle(
208 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
209 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
210 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
213 std::shared_ptr<SketchAPI_Circle> addCircle(const ModelHighAPI_Selection & theExternal);
216 std::shared_ptr<SketchAPI_Circle> addCircle(const std::string & theExternalName);
220 std::shared_ptr<SketchAPI_Arc> addArc(
221 double theCenterX, double theCenterY,
222 double theStartX, double theStartY,
223 double theEndX, double theEndY,
228 std::shared_ptr<SketchAPI_Arc> addArc(
229 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
230 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
231 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
236 std::shared_ptr<SketchAPI_MacroArc> addArc(
237 double theStartX, double theStartY,
238 double theEndX, double theEndY,
239 double thePassedX, double thePassedY);
243 std::shared_ptr<SketchAPI_MacroArc> addArc(
244 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
245 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
246 const std::shared_ptr<GeomAPI_Pnt2d>& thePassed);
248 /// Add transversal/tangent arc
250 std::shared_ptr<SketchAPI_MacroArc> addArc(
251 const ModelHighAPI_RefAttr& theConnectedPoint,
252 double theEndX, double theEndY,
254 bool theTransversal = false);
256 /// Add transversal/tangent arc
258 std::shared_ptr<SketchAPI_MacroArc> addArc(
259 const ModelHighAPI_RefAttr& theConnectedPoint,
260 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
262 bool theTransversal = false);
266 std::shared_ptr<SketchAPI_Arc> addArc(const ModelHighAPI_Selection & theExternal);
270 std::shared_ptr<SketchAPI_Arc> addArc(const std::string & theExternalName);
274 std::shared_ptr<SketchAPI_Ellipse> addEllipse(
275 double theCenterX, double theCenterY,
276 double theFocusX, double theFocusY,
277 double theMinorRadius);
280 std::shared_ptr<SketchAPI_Ellipse> addEllipse(
281 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
282 const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
286 std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
287 double thePoint1X, double thePoint1Y,
288 double thePoint2X, double thePoint2Y,
289 double thePassedX, double thePassedY,
290 bool isPoint1Center = true);
293 std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
294 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& thePoint1,
295 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& thePoint2,
296 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& thePassedPoint,
297 bool isPoint1Center = true);
300 std::shared_ptr<SketchAPI_Ellipse> addEllipse(const ModelHighAPI_Selection & theExternal);
303 std::shared_ptr<SketchAPI_Ellipse> addEllipse(const std::string & theExternalName);
307 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(
308 double theCenterX, double theCenterY,
309 double theFocusX, double theFocusY,
310 double theStartX, double theStartY,
311 double theEndX, double theEndY,
312 bool theInversed = false);
315 std::shared_ptr<SketchAPI_MacroEllipticArc> addEllipticArc(
316 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& theCenter,
317 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& theMajorAxisPoint,
318 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& theStartPoint,
319 const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& theEndPoint,
320 bool theInversed = false);
323 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(const ModelHighAPI_Selection & theExternal);
326 std::shared_ptr<SketchAPI_EllipticArc> addEllipticArc(const std::string & theExternalName);
330 std::shared_ptr<SketchAPI_BSpline> addSpline(
331 const ModelHighAPI_Selection & external = ModelHighAPI_Selection(),
332 const int degree = -1,
333 const std::list<std::shared_ptr<GeomAPI_Pnt2d> >& poles =
334 std::list<std::shared_ptr<GeomAPI_Pnt2d> >(),
335 const std::list<ModelHighAPI_Double>& weights = std::list<ModelHighAPI_Double>(),
336 const std::list<ModelHighAPI_Double>& knots = std::list<ModelHighAPI_Double>(),
337 const std::list<ModelHighAPI_Integer>& multiplicities = std::list<ModelHighAPI_Integer>(),
338 const bool periodic = false);
342 std::shared_ptr<SketchAPI_Projection> addProjection(
343 const ModelHighAPI_Selection & theExternalFeature,
344 bool theKeepResult = false);
348 std::shared_ptr<SketchAPI_Projection> addProjection(const std::string & theExternalName,
349 bool theKeepResult = false);
353 std::shared_ptr<SketchAPI_Mirror> addMirror(
354 const ModelHighAPI_RefAttr & theMirrorLine,
355 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects);
359 std::shared_ptr<SketchAPI_Translation> addTranslation(
360 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
361 const ModelHighAPI_RefAttr & thePoint1,
362 const ModelHighAPI_RefAttr & thePoint2,
363 const ModelHighAPI_Integer & theNumberOfObjects,
364 bool theFullValue = false);
368 std::shared_ptr<SketchAPI_Rotation> addRotation(
369 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
370 const ModelHighAPI_RefAttr & theCenter,
371 const ModelHighAPI_Double & theAngle,
372 const ModelHighAPI_Integer & theNumberOfObjects,
373 bool theFullValue = false,
374 bool theReversed = false);
378 std::shared_ptr<ModelHighAPI_Interface> addSplit(
379 const ModelHighAPI_Reference& theFeature,
380 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
384 std::shared_ptr<ModelHighAPI_Interface> addTrim(
385 const ModelHighAPI_Reference& theFeature,
386 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
390 std::shared_ptr<ModelHighAPI_Interface> setAngle(
391 const ModelHighAPI_RefAttr & theLine1,
392 const ModelHighAPI_RefAttr & theLine2,
393 const ModelHighAPI_Double & theValue,
394 const std::string& type = std::string());
396 /// Set complementary angle
398 std::shared_ptr<ModelHighAPI_Interface> setAngleComplementary(
399 const ModelHighAPI_RefAttr & theLine1,
400 const ModelHighAPI_RefAttr & theLine2,
401 const ModelHighAPI_Double & theValue);
403 /// Set backward angle (= 360 - angle)
405 std::shared_ptr<ModelHighAPI_Interface> setAngleBackward(
406 const ModelHighAPI_RefAttr & theLine1,
407 const ModelHighAPI_RefAttr & theLine2,
408 const ModelHighAPI_Double & theValue);
412 std::shared_ptr<ModelHighAPI_Interface> setCoincident(
413 const ModelHighAPI_RefAttr & thePoint1,
414 const ModelHighAPI_RefAttr & thePoint2);
418 std::shared_ptr<ModelHighAPI_Interface> setCollinear(
419 const ModelHighAPI_RefAttr & theLine1,
420 const ModelHighAPI_RefAttr & theLine2);
424 std::shared_ptr<ModelHighAPI_Interface> setDistance(
425 const ModelHighAPI_RefAttr & thePoint,
426 const ModelHighAPI_RefAttr & thePointOrLine,
427 const ModelHighAPI_Double & theValue,
428 bool isSigned = false);
430 /// Set signed distance
432 std::shared_ptr<ModelHighAPI_Interface> setSignedDistance(
433 const ModelHighAPI_RefAttr & thePoint,
434 const ModelHighAPI_RefAttr & thePointOrLine,
435 const ModelHighAPI_Double & theValue);
437 /// Set unsigned distance
439 std::shared_ptr<ModelHighAPI_Interface> setUnsignedDistance(
440 const ModelHighAPI_RefAttr & thePoint,
441 const ModelHighAPI_RefAttr & thePointOrLine,
442 const ModelHighAPI_Double & theValue);
444 /// Set horizontal distance
446 std::shared_ptr<ModelHighAPI_Interface> setHorizontalDistance(
447 const ModelHighAPI_RefAttr & thePoint1,
448 const ModelHighAPI_RefAttr & thePoint2,
449 const ModelHighAPI_Double & theValue);
451 /// Set vertical distance
453 std::shared_ptr<ModelHighAPI_Interface> setVerticalDistance(
454 const ModelHighAPI_RefAttr & thePoint1,
455 const ModelHighAPI_RefAttr & thePoint2,
456 const ModelHighAPI_Double & theValue);
460 std::shared_ptr<ModelHighAPI_Interface> setEqual(
461 const ModelHighAPI_RefAttr & theObject1,
462 const ModelHighAPI_RefAttr & theObject2);
466 std::shared_ptr<ModelHighAPI_Interface> setFillet(
467 const ModelHighAPI_RefAttr & thePoint);
469 /// Set fillet with additional radius constraint
471 std::shared_ptr<ModelHighAPI_Interface> setFilletWithRadius(
472 const ModelHighAPI_RefAttr & thePoint,
473 const ModelHighAPI_Double & theRadius);
477 std::shared_ptr<ModelHighAPI_Interface> setFixed(
478 const ModelHighAPI_RefAttr & theObject);
482 std::shared_ptr<ModelHighAPI_Interface> setHorizontal(
483 const ModelHighAPI_RefAttr & theLine);
487 std::shared_ptr<ModelHighAPI_Interface> setLength(
488 const ModelHighAPI_RefAttr & theLine,
489 const ModelHighAPI_Double & theValue);
493 std::shared_ptr<ModelHighAPI_Interface> setMiddlePoint(
494 const ModelHighAPI_RefAttr & thePoint,
495 const ModelHighAPI_RefAttr & theLine);
499 std::shared_ptr<ModelHighAPI_Interface> setParallel(
500 const ModelHighAPI_RefAttr & theLine1,
501 const ModelHighAPI_RefAttr & theLine2);
503 /// Set perpendicular
505 std::shared_ptr<ModelHighAPI_Interface> setPerpendicular(
506 const ModelHighAPI_RefAttr & theLine1,
507 const ModelHighAPI_RefAttr & theLine2);
511 std::shared_ptr<ModelHighAPI_Interface> setRadius(
512 const ModelHighAPI_RefAttr & theCircleOrArc,
513 const ModelHighAPI_Double & theValue);
517 std::shared_ptr<ModelHighAPI_Interface> setTangent(
518 const ModelHighAPI_RefAttr & theLine,
519 const ModelHighAPI_RefAttr & theCircle);
523 std::shared_ptr<ModelHighAPI_Interface> setVertical(
524 const ModelHighAPI_RefAttr & theLine);
526 /// Set constraint value
529 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
530 const ModelHighAPI_Double & theValue);
532 /// Move point or sketch feature
534 void move(const ModelHighAPI_RefAttr& theMovedEntity,
535 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint);
537 /// Move point or sketch feature
539 void move(const ModelHighAPI_RefAttr& theMovedEntity,
540 double theTargetX, double theTargetY);
543 std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
545 // TODO(spo): rename to selectFaces() or faces() (or add faces() -> list to SWIG)
548 std::list<ModelHighAPI_Selection> selectFace() const;
550 /// Dump wrapped feature
552 virtual void dump(ModelHighAPI_Dumper& theDumper) const;
555 std::shared_ptr<ModelAPI_CompositeFeature> compositeFeature() const;
559 //! Pointer on Sketch object
560 typedef std::shared_ptr<SketchAPI_Sketch> SketchPtr;
562 /**\ingroup CPPHighAPI
563 * \brief Create Sketch feature
566 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
567 const std::shared_ptr<GeomAPI_Ax3> & thePlane);
569 /**\ingroup CPPHighAPI
570 * \brief Create Sketch feature
573 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
574 const ModelHighAPI_Selection & theExternal);
576 /**\ingroup CPPHighAPI
577 * \brief Create Sketch feature
580 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
581 const std::string & theExternalName);
583 /**\ingroup CPPHighAPI
584 * \brief Create Sketch feature
587 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
588 std::shared_ptr<ModelAPI_Object> thePlaneObject);
590 //--------------------------------------------------------------------------------------
591 //--------------------------------------------------------------------------------------
592 #endif /* SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_ */