1 // File: PartSet_FeaturePrs.h
2 // Created: 04 Jun 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_FeatureArcPrs.h>
6 #include <PartSet_Tools.h>
8 #include <SketchPlugin_Feature.h>
9 #include <SketchPlugin_Sketch.h>
10 #include <SketchPlugin_Arc.h>
12 #include <GeomDataAPI_Point2D.h>
13 #include <GeomAPI_Pnt2d.h>
14 #include <GeomAPI_Circ2d.h>
16 #include <ModelAPI_Data.h>
17 #include <ModelAPI_Document.h>
18 #include <ModelAPI_AttributeRefAttr.h>
19 #include <ModelAPI_AttributeRefList.h>
21 #include <V3d_View.hxx>
23 #include <Precision.hxx>
27 PartSet_FeatureArcPrs::PartSet_FeatureArcPrs(FeaturePtr theSketch)
28 : PartSet_FeaturePrs(theSketch)
32 std::string PartSet_FeatureArcPrs::getKind()
34 return SKETCH_ARC_KIND;
37 PartSet_SelectionMode PartSet_FeatureArcPrs::setPoint(double theX, double theY,
38 const PartSet_SelectionMode& theMode)
40 PartSet_SelectionMode aMode = theMode;
44 PartSet_Tools::setFeaturePoint(feature(), theX, theY, ARC_ATTR_CENTER);
45 aMode = SM_SecondPoint;
48 case SM_SecondPoint: {
49 PartSet_Tools::setFeaturePoint(feature(), theX, theY, ARC_ATTR_START);
50 aMode = SM_ThirdPoint;
54 PartSet_Tools::setFeaturePoint(feature(), theX, theY, ARC_ATTR_END);
64 std::string PartSet_FeatureArcPrs::getAttribute(const PartSet_SelectionMode& theMode) const
66 std::string aAttribute;
70 aAttribute = ARC_ATTR_CENTER;
73 aAttribute = ARC_ATTR_START;
76 aAttribute = ARC_ATTR_END;
84 PartSet_SelectionMode PartSet_FeatureArcPrs::getNextMode(const std::string& theAttribute) const
86 PartSet_SelectionMode aMode;
88 if (theAttribute == ARC_ATTR_CENTER)
89 aMode = SM_SecondPoint;
90 else if (theAttribute == ARC_ATTR_START)
91 aMode = SM_ThirdPoint;
92 else if (theAttribute == ARC_ATTR_END)
97 void PartSet_FeatureArcPrs::move(double theDeltaX, double theDeltaY)
99 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
100 if (!aData->isValid())
103 boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
104 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_CENTER));
105 aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
107 boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
108 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_START));
109 aPoint2->setValue(aPoint2->x() + theDeltaX, aPoint2->y() + theDeltaY);
111 boost::shared_ptr<GeomDataAPI_Point2D> aPoint3 =
112 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_END));
113 aPoint3->setValue(aPoint3->x() + theDeltaX, aPoint3->y() + theDeltaY);
116 double PartSet_FeatureArcPrs::distanceToPoint(FeaturePtr theFeature,
117 double theX, double theY)
120 if (!theFeature || theFeature->getKind() != getKind())
122 boost::shared_ptr<GeomAPI_Pnt2d> aPoint2d(new GeomAPI_Pnt2d(theX, theY));
125 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
127 boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
128 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_CENTER));
129 aDelta = aPoint1->pnt()->distance(aPoint2d);
131 boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
132 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_START));
133 aDelta = qMin(aDelta, aPoint2->pnt()->distance(aPoint2d));
135 boost::shared_ptr<GeomDataAPI_Point2D> aPoint3 =
136 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_END));
137 aDelta = qMin(aDelta, aPoint3->pnt()->distance(aPoint2d));
142 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureArcPrs::findPoint(FeaturePtr theFeature,
143 double theX, double theY)
145 boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
146 if (!theFeature || theFeature->getKind() != getKind())
149 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
150 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
151 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_CENTER));
152 if (fabs(aPoint->x() - theX) < Precision::Confusion() &&
153 fabs(aPoint->y() - theY) < Precision::Confusion()) {
157 aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_START));
158 if (fabs(aPoint->x() - theX) < Precision::Confusion() &&
159 fabs(aPoint->y() - theY) < Precision::Confusion())
163 aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_END));
164 if (fabs(aPoint->x() - theX) < Precision::Confusion() &&
165 fabs(aPoint->y() - theY) < Precision::Confusion())
171 void PartSet_FeatureArcPrs::projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch,
172 gp_Pnt& thePoint, Handle(V3d_View) theView,
173 double& theX, double& theY)
175 FeaturePtr aSketch = theSketch;
178 PartSet_Tools::convertTo2D(thePoint, aSketch, theView, aX, anY);
180 // circle origin point and radius
181 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
182 boost::shared_ptr<GeomDataAPI_Point2D> aCenter = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
183 (aData->attribute(ARC_ATTR_CENTER));
184 boost::shared_ptr<GeomDataAPI_Point2D> aStart = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
185 (aData->attribute(ARC_ATTR_START));
187 boost::shared_ptr<GeomAPI_Circ2d> aCirc(new GeomAPI_Circ2d(aCenter->pnt(), aStart->pnt()));
188 boost::shared_ptr<GeomAPI_Pnt2d> aGeomPoint2d(new GeomAPI_Pnt2d(aX, anY));
189 boost::shared_ptr<GeomAPI_Pnt2d> aPnt2d = aCirc->project(aGeomPoint2d);
197 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureArcPrs::featurePoint
198 (const PartSet_SelectionMode& theMode)
200 std::string aPointArg;
204 aPointArg = ARC_ATTR_CENTER;
207 aPointArg = ARC_ATTR_START;
210 aPointArg = ARC_ATTR_END;
215 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
216 boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
217 (aData->attribute(aPointArg));
221 double PartSet_FeatureArcPrs::radius(FeaturePtr theFeature)
226 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
228 boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr =
229 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_CENTER));
230 boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr =
231 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_START));
233 return aCenterAttr->pnt()->distance(aStartAttr->pnt());