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 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);
343 std::shared_ptr<SketchAPI_Projection> addProjection(
344 const ModelHighAPI_Selection & theExternalFeature,
345 bool theKeepResult = false);
349 std::shared_ptr<SketchAPI_Projection> addProjection(const std::string & theExternalName,
350 bool theKeepResult = false);
354 std::shared_ptr<SketchAPI_Mirror> addMirror(
355 const ModelHighAPI_RefAttr & theMirrorLine,
356 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects);
360 std::shared_ptr<SketchAPI_Translation> addTranslation(
361 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
362 const ModelHighAPI_RefAttr & thePoint1,
363 const ModelHighAPI_RefAttr & thePoint2,
364 const ModelHighAPI_Integer & theNumberOfObjects,
365 bool theFullValue = false);
369 std::shared_ptr<SketchAPI_Rotation> addRotation(
370 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
371 const ModelHighAPI_RefAttr & theCenter,
372 const ModelHighAPI_Double & theAngle,
373 const ModelHighAPI_Integer & theNumberOfObjects,
374 bool theFullValue = false,
375 bool theReversed = false);
379 std::shared_ptr<ModelHighAPI_Interface> addSplit(
380 const ModelHighAPI_Reference& theFeature,
381 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
385 std::shared_ptr<ModelHighAPI_Interface> addTrim(
386 const ModelHighAPI_Reference& theFeature,
387 const std::shared_ptr<GeomAPI_Pnt2d>& thePositionPoint);
391 std::shared_ptr<ModelHighAPI_Interface> setAngle(
392 const ModelHighAPI_RefAttr & theLine1,
393 const ModelHighAPI_RefAttr & theLine2,
394 const ModelHighAPI_Double & theValue,
395 const std::string& type = std::string());
397 /// Set complementary angle
399 std::shared_ptr<ModelHighAPI_Interface> setAngleComplementary(
400 const ModelHighAPI_RefAttr & theLine1,
401 const ModelHighAPI_RefAttr & theLine2,
402 const ModelHighAPI_Double & theValue);
404 /// Set backward angle (= 360 - angle)
406 std::shared_ptr<ModelHighAPI_Interface> setAngleBackward(
407 const ModelHighAPI_RefAttr & theLine1,
408 const ModelHighAPI_RefAttr & theLine2,
409 const ModelHighAPI_Double & theValue);
413 std::shared_ptr<ModelHighAPI_Interface> setCoincident(
414 const ModelHighAPI_RefAttr & thePoint1,
415 const ModelHighAPI_RefAttr & thePoint2);
419 std::shared_ptr<ModelHighAPI_Interface> setCollinear(
420 const ModelHighAPI_RefAttr & theLine1,
421 const ModelHighAPI_RefAttr & theLine2);
425 std::shared_ptr<ModelHighAPI_Interface> setDistance(
426 const ModelHighAPI_RefAttr & thePoint,
427 const ModelHighAPI_RefAttr & thePointOrLine,
428 const ModelHighAPI_Double & theValue,
429 bool isSigned = false);
431 /// Set signed distance
433 std::shared_ptr<ModelHighAPI_Interface> setSignedDistance(
434 const ModelHighAPI_RefAttr & thePoint,
435 const ModelHighAPI_RefAttr & thePointOrLine,
436 const ModelHighAPI_Double & theValue);
438 /// Set unsigned distance
440 std::shared_ptr<ModelHighAPI_Interface> setUnsignedDistance(
441 const ModelHighAPI_RefAttr & thePoint,
442 const ModelHighAPI_RefAttr & thePointOrLine,
443 const ModelHighAPI_Double & theValue);
445 /// Set horizontal distance
447 std::shared_ptr<ModelHighAPI_Interface> setHorizontalDistance(
448 const ModelHighAPI_RefAttr & thePoint1,
449 const ModelHighAPI_RefAttr & thePoint2,
450 const ModelHighAPI_Double & theValue);
452 /// Set vertical distance
454 std::shared_ptr<ModelHighAPI_Interface> setVerticalDistance(
455 const ModelHighAPI_RefAttr & thePoint1,
456 const ModelHighAPI_RefAttr & thePoint2,
457 const ModelHighAPI_Double & theValue);
461 std::shared_ptr<ModelHighAPI_Interface> setEqual(
462 const ModelHighAPI_RefAttr & theObject1,
463 const ModelHighAPI_RefAttr & theObject2);
467 std::shared_ptr<ModelHighAPI_Interface> setFillet(
468 const ModelHighAPI_RefAttr & thePoint);
470 /// Set fillet with additional radius constraint
472 std::shared_ptr<ModelHighAPI_Interface> setFilletWithRadius(
473 const ModelHighAPI_RefAttr & thePoint,
474 const ModelHighAPI_Double & theRadius);
478 std::shared_ptr<ModelHighAPI_Interface> setFixed(
479 const ModelHighAPI_RefAttr & theObject);
483 std::shared_ptr<ModelHighAPI_Interface> setHorizontal(
484 const ModelHighAPI_RefAttr & theLine);
488 std::shared_ptr<ModelHighAPI_Interface> setLength(
489 const ModelHighAPI_RefAttr & theLine,
490 const ModelHighAPI_Double & theValue);
494 std::shared_ptr<ModelHighAPI_Interface> setMiddlePoint(
495 const ModelHighAPI_RefAttr & thePoint,
496 const ModelHighAPI_RefAttr & theLine);
500 std::shared_ptr<ModelHighAPI_Interface> setParallel(
501 const ModelHighAPI_RefAttr & theLine1,
502 const ModelHighAPI_RefAttr & theLine2);
504 /// Set perpendicular
506 std::shared_ptr<ModelHighAPI_Interface> setPerpendicular(
507 const ModelHighAPI_RefAttr & theLine1,
508 const ModelHighAPI_RefAttr & theLine2);
512 std::shared_ptr<ModelHighAPI_Interface> setRadius(
513 const ModelHighAPI_RefAttr & theCircleOrArc,
514 const ModelHighAPI_Double & theValue);
518 std::shared_ptr<ModelHighAPI_Interface> setTangent(
519 const ModelHighAPI_RefAttr & theLine,
520 const ModelHighAPI_RefAttr & theCircle);
524 std::shared_ptr<ModelHighAPI_Interface> setVertical(
525 const ModelHighAPI_RefAttr & theLine);
527 /// Set constraint value
530 const std::shared_ptr<ModelHighAPI_Interface> & theConstraint,
531 const ModelHighAPI_Double & theValue);
533 /// Move point or sketch feature
535 void move(const ModelHighAPI_RefAttr& theMovedEntity,
536 const std::shared_ptr<GeomAPI_Pnt2d>& theTargetPoint);
538 /// Move point or sketch feature
540 void move(const ModelHighAPI_RefAttr& theMovedEntity,
541 double theTargetX, double theTargetY);
544 std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
546 // TODO(spo): rename to selectFaces() or faces() (or add faces() -> list to SWIG)
549 std::list<ModelHighAPI_Selection> selectFace() const;
551 /// Dump wrapped feature
553 virtual void dump(ModelHighAPI_Dumper& theDumper) const;
556 std::shared_ptr<ModelAPI_CompositeFeature> compositeFeature() const;
560 //! Pointer on Sketch object
561 typedef std::shared_ptr<SketchAPI_Sketch> SketchPtr;
563 /**\ingroup CPPHighAPI
564 * \brief Create Sketch feature
567 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
568 const std::shared_ptr<GeomAPI_Ax3> & thePlane);
570 /**\ingroup CPPHighAPI
571 * \brief Create Sketch feature
574 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
575 const ModelHighAPI_Selection & theExternal);
577 /**\ingroup CPPHighAPI
578 * \brief Create Sketch feature
581 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
582 const std::string & theExternalName);
584 /**\ingroup CPPHighAPI
585 * \brief Create Sketch feature
588 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
589 std::shared_ptr<ModelAPI_Object> thePlaneObject);
591 //--------------------------------------------------------------------------------------
592 //--------------------------------------------------------------------------------------
593 #endif /* SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_ */