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 #include "SketchAPI_MacroEllipse.h"
22 #include <GeomAPI_Pnt2d.h>
24 #include <ModelHighAPI_RefAttr.h>
25 #include <ModelHighAPI_Tools.h>
27 SketchAPI_MacroEllipse::SketchAPI_MacroEllipse(const std::shared_ptr<ModelAPI_Feature>& theFeature)
28 : SketchAPI_SketchEntity(theFeature)
33 SketchAPI_MacroEllipse::SketchAPI_MacroEllipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
34 double theX1, double theY1,
35 double theX2, double theY2,
36 double theX3, double theY3,
38 : SketchAPI_SketchEntity(theFeature)
42 setByCenterAndPassedPoints();
44 setByMajorAxisAndPassedPoint();
46 initializePoints(theX1, theY1, theX2, theY2, theX3, theY3);
50 SketchAPI_MacroEllipse::SketchAPI_MacroEllipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
51 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
52 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
53 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3,
55 : SketchAPI_SketchEntity(theFeature)
59 setByCenterAndPassedPoints();
61 setByMajorAxisAndPassedPoint();
63 initializePoints(thePoint1, thePoint2, thePoint3);
67 SketchAPI_MacroEllipse::SketchAPI_MacroEllipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
68 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
69 const ModelHighAPI_RefAttr& thePoint1Ref,
70 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
71 const ModelHighAPI_RefAttr& thePoint2Ref,
72 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3,
73 const ModelHighAPI_RefAttr& thePoint3Ref,
75 : SketchAPI_SketchEntity(theFeature)
79 setByCenterAndPassedPoints();
81 setByMajorAxisAndPassedPoint();
83 initializePoints(thePoint1, thePoint1Ref, thePoint2, thePoint2Ref, thePoint3, thePoint3Ref);
87 SketchAPI_MacroEllipse::~SketchAPI_MacroEllipse()
91 void SketchAPI_MacroEllipse::setByCenterAndPassedPoints()
93 fillAttribute(SketchPlugin_MacroEllipse::ELLIPSE_TYPE_BY_CENTER_AXIS_POINT(), myellipseType);
96 void SketchAPI_MacroEllipse::setByMajorAxisAndPassedPoint()
98 fillAttribute(SketchPlugin_MacroEllipse::ELLIPSE_TYPE_BY_AXIS_AND_POINT(), myellipseType);
101 void SketchAPI_MacroEllipse::initializePoints(double theX1, double theY1,
102 double theX2, double theY2,
103 double theX3, double theY3)
105 fillAttribute(majorAxisNegativePoint(), theX1, theY1);
106 fillAttribute(majorAxisPositivePoint(), theX2, theY2);
107 fillAttribute(passedPoint(), theX3, theY3);
112 void SketchAPI_MacroEllipse::initializePoints(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
113 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
114 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
116 fillAttribute(thePoint1, mymajorAxisNegativePoint);
117 fillAttribute(thePoint2, mymajorAxisPositivePoint);
118 fillAttribute(thePoint3, mypassedPoint);
123 static void fillAttribute(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint,
124 const ModelHighAPI_RefAttr& thePointRef,
125 std::shared_ptr<GeomDataAPI_Point2D> thePointAttr,
126 AttributeRefAttrPtr thePointRefAttr)
128 GeomPnt2dPtr aPoint = thePoint;
129 if (!thePointRef.isEmpty()) {
130 fillAttribute(thePointRef, thePointRefAttr);
131 std::shared_ptr<GeomDataAPI_Point2D> anAttrPnt =
132 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(thePointRefAttr->attr());
134 aPoint = anAttrPnt->pnt();
136 fillAttribute(aPoint, thePointAttr);
139 void SketchAPI_MacroEllipse::initializePoints(
140 const std::shared_ptr<GeomAPI_Pnt2d>& theMajorAxisPoint1,
141 const ModelHighAPI_RefAttr& theMajorAxisPoint1Ref,
142 const std::shared_ptr<GeomAPI_Pnt2d>& theMajorAxisPoint2,
143 const ModelHighAPI_RefAttr& theMajorAxisPoint2Ref,
144 const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint,
145 const ModelHighAPI_RefAttr& thePassedPointRef)
147 fillAttribute(theMajorAxisPoint1, theMajorAxisPoint1Ref,
148 mymajorAxisNegativePoint, mymajorAxisNegativePointRef);
149 fillAttribute(theMajorAxisPoint2, theMajorAxisPoint2Ref,
150 mymajorAxisPositivePoint, mymajorAxisPositivePointRef);
151 fillAttribute(thePassedPoint, thePassedPointRef, mypassedPoint, mypassedPointRef);