]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_FeatureArcPrs.cpp
Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / PartSet / PartSet_FeatureArcPrs.cpp
1 // File:        PartSet_FeaturePrs.h
2 // Created:     04 Jun 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #include <PartSet_FeatureArcPrs.h>
6 #include <PartSet_Tools.h>
7
8 #include <SketchPlugin_Feature.h>
9 #include <SketchPlugin_Sketch.h>
10 #include <SketchPlugin_Arc.h>
11
12 #include <GeomDataAPI_Point2D.h>
13 #include <GeomAPI_Pnt2d.h>
14 #include <GeomAPI_Circ2d.h>
15
16 #include <ModelAPI_Data.h>
17 #include <ModelAPI_Document.h>
18 #include <ModelAPI_AttributeRefAttr.h>
19 #include <ModelAPI_AttributeRefList.h>
20
21 #include <V3d_View.hxx>
22
23 #include <Precision.hxx>
24
25 using namespace std;
26
27 PartSet_FeatureArcPrs::PartSet_FeatureArcPrs(FeaturePtr theSketch)
28 : PartSet_FeaturePrs(theSketch)
29 {
30 }
31
32 PartSet_SelectionMode PartSet_FeatureArcPrs::setPoint(double theX, double theY,
33                                                        const PartSet_SelectionMode& theMode)
34 {
35   PartSet_SelectionMode aMode = theMode;
36   switch (theMode)
37   {
38     case SM_FirstPoint: {
39       PartSet_Tools::setFeaturePoint(feature(), theX, theY, ARC_ATTR_CENTER);
40       aMode = SM_SecondPoint;
41     }
42     break;
43     case SM_SecondPoint: {
44       PartSet_Tools::setFeaturePoint(feature(), theX, theY, ARC_ATTR_START);
45       aMode = SM_ThirdPoint;
46    }
47    break;
48    case SM_ThirdPoint: {
49      PartSet_Tools::setFeaturePoint(feature(), theX, theY, ARC_ATTR_END);
50      aMode = SM_DonePoint;
51    }
52     break;
53     default:
54       break;
55   }
56   return aMode;
57 }
58
59 std::string PartSet_FeatureArcPrs::getAttribute(const PartSet_SelectionMode& theMode) const
60 {
61   std::string aAttribute;
62   switch (theMode)
63   {
64     case SM_FirstPoint:
65       aAttribute = ARC_ATTR_CENTER;
66     break;
67     case SM_SecondPoint:
68       aAttribute = ARC_ATTR_START;
69     break;
70     case SM_ThirdPoint:
71       aAttribute = ARC_ATTR_END;
72     break;
73     default:
74     break;
75   }
76   return aAttribute;
77 }
78
79 PartSet_SelectionMode PartSet_FeatureArcPrs::getNextMode(const std::string& theAttribute) const
80 {
81   PartSet_SelectionMode aMode;
82
83   if (theAttribute == ARC_ATTR_CENTER)
84     aMode = SM_SecondPoint;
85   else if (theAttribute == ARC_ATTR_START)
86     aMode = SM_ThirdPoint;
87   else if (theAttribute == ARC_ATTR_END)
88     aMode = SM_DonePoint;
89   return aMode;
90 }
91
92 void PartSet_FeatureArcPrs::projectPointOnArc(gp_Pnt& thePoint, Handle(V3d_View) theView,
93                                               double& theX, double& theY)
94 {
95   FeaturePtr aSketch = sketch();
96   if (aSketch) {
97     double aX, anY;
98     PartSet_Tools::convertTo2D(thePoint, aSketch, theView, aX, anY);
99
100     // circle origin point and radius
101     boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
102     boost::shared_ptr<GeomDataAPI_Point2D> aCenter = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
103                                                               (aData->attribute(ARC_ATTR_CENTER));
104     boost::shared_ptr<GeomDataAPI_Point2D> aStart = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
105                                                               (aData->attribute(ARC_ATTR_START));
106
107     boost::shared_ptr<GeomAPI_Circ2d> aCirc(new GeomAPI_Circ2d(aCenter->pnt(), aStart->pnt()));
108     boost::shared_ptr<GeomAPI_Pnt2d> aGeomPoint2d(new GeomAPI_Pnt2d(aX, anY));
109     boost::shared_ptr<GeomAPI_Pnt2d> aPnt2d = aCirc->project(aGeomPoint2d);
110     if (aPnt2d) {
111       theX = aPnt2d->x();
112       theY = aPnt2d->y();
113     }
114   }
115 }
116
117 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureArcPrs::featurePoint
118                                                      (const PartSet_SelectionMode& theMode)
119 {
120   std::string aPointArg;
121   switch (theMode)
122   {
123     case SM_FirstPoint:
124       aPointArg = ARC_ATTR_CENTER;
125       break;
126     case SM_SecondPoint:
127       aPointArg = ARC_ATTR_START;
128       break;
129     case SM_ThirdPoint:
130       aPointArg = ARC_ATTR_END;
131       break;
132     default:
133       break;
134   }
135   boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
136   boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
137                                                               (aData->attribute(aPointArg));
138   return aPoint;
139 }