Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchAPI / SketchAPI_MacroEllipticArc.cpp
1 // Copyright (C) 2014-2023  CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "SketchAPI_MacroEllipticArc.h"
21
22 #include <GeomAPI_Pnt2d.h>
23
24 #include <ModelHighAPI_RefAttr.h>
25 #include <ModelHighAPI_Tools.h>
26
27 #include <SketchPlugin_MacroEllipticArc.h>
28
29 #define CENTER_POINT (std::dynamic_pointer_cast<GeomDataAPI_Point2D>( \
30                       feature()->attribute(SketchPlugin_MacroEllipticArc::CENTER_ID())))
31 #define MAJOR_AXIS_POSITIVE (std::dynamic_pointer_cast<GeomDataAPI_Point2D>( \
32                       feature()->attribute(SketchPlugin_MacroEllipticArc::MAJOR_AXIS_POINT_ID())))
33 #define START_POINT (std::dynamic_pointer_cast<GeomDataAPI_Point2D>( \
34                      feature()->attribute(SketchPlugin_MacroEllipticArc::START_POINT_ID())))
35 #define END_POINT (std::dynamic_pointer_cast<GeomDataAPI_Point2D>( \
36                    feature()->attribute(SketchPlugin_MacroEllipticArc::END_POINT_ID())))
37
38 #define CENTER_POINT_REF (feature()->refattr(SketchPlugin_MacroEllipticArc::CENTER_REF_ID()))
39 #define MAJOR_AXIS_POSITIVE_REF (feature()->refattr( \
40                                  SketchPlugin_MacroEllipticArc::MAJOR_AXIS_POINT_REF_ID()))
41 #define START_POINT_REF (feature()->refattr(SketchPlugin_MacroEllipticArc::START_POINT_REF_ID()))
42 #define END_POINT_REF (feature()->refattr(SketchPlugin_MacroEllipticArc::END_POINT_REF_ID()))
43
44
45 static void fillAttribute(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint,
46                           const ModelHighAPI_RefAttr& thePointRef,
47                           std::shared_ptr<GeomDataAPI_Point2D> thePointAttr,
48                           AttributeRefAttrPtr thePointRefAttr)
49 {
50   GeomPnt2dPtr aPoint = thePoint;
51   if (!thePointRef.isEmpty()) {
52     fillAttribute(thePointRef, thePointRefAttr);
53     std::shared_ptr<GeomDataAPI_Point2D> anAttrPnt =
54         std::dynamic_pointer_cast<GeomDataAPI_Point2D>(thePointRefAttr->attr());
55     if (anAttrPnt)
56       aPoint = anAttrPnt->pnt();
57   }
58   fillAttribute(aPoint, thePointAttr);
59 }
60
61 SketchAPI_MacroEllipticArc::SketchAPI_MacroEllipticArc(const FeaturePtr& theFeature)
62   : SketchAPI_MacroEllipse(theFeature, false)
63 {
64 }
65
66 SketchAPI_MacroEllipticArc::SketchAPI_MacroEllipticArc(
67     const std::shared_ptr<ModelAPI_Feature>& theFeature,
68     const std::shared_ptr<GeomAPI_Pnt2d>&    theCenter,
69     const ModelHighAPI_RefAttr&              theCenterRef,
70     const std::shared_ptr<GeomAPI_Pnt2d>&    theMajorAxisPoint,
71     const ModelHighAPI_RefAttr&              theMajorAxisPointRef,
72     const std::shared_ptr<GeomAPI_Pnt2d>&    theArcStart,
73     const ModelHighAPI_RefAttr&              theArcStartRef,
74     const std::shared_ptr<GeomAPI_Pnt2d>&    theArcEnd,
75     const ModelHighAPI_RefAttr&              theArcEndRef,
76     const bool                               theReversed)
77   : SketchAPI_MacroEllipse(theFeature, false)
78 {
79   if (initialize()) {
80     fillAttribute(theCenter, theCenterRef,
81                   CENTER_POINT, CENTER_POINT_REF);
82     fillAttribute(theMajorAxisPoint, theMajorAxisPointRef,
83                   MAJOR_AXIS_POSITIVE, MAJOR_AXIS_POSITIVE_REF);
84     fillAttribute(theArcStart, theArcStartRef, START_POINT, START_POINT_REF);
85     fillAttribute(theArcEnd, theArcEndRef, END_POINT, END_POINT_REF);
86
87     fillAttribute(theReversed, reversed());
88
89     storeSketch(theFeature);
90     execute();
91   }
92 }
93
94 SketchAPI_MacroEllipticArc::~SketchAPI_MacroEllipticArc()
95 {
96 }