Salome HOME
45121e28572def4a10d6d9e359799b8ca74d58f5
[modules/shaper.git] / src / PartSet / PartSet_OperationSketchLine.cpp
1 // File:        PartSet_OperationSketchLine.h
2 // Created:     20 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #include <PartSet_OperationSketchLine.h>
6
7 #include <SketchPlugin_Feature.h>
8 #include <GeomDataAPI_Point2D.h>
9 #include <ModelAPI_Data.h>
10
11 #include <SketchPlugin_Line.h>
12
13 #ifdef _DEBUG
14 #include <QDebug>
15 #endif
16
17 using namespace std;
18
19 PartSet_OperationSketchLine::PartSet_OperationSketchLine(const QString& theId,
20                                                   QObject* theParent,
21                                               boost::shared_ptr<ModelAPI_Feature> theFeature)
22 : PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature),
23   myPointSelectionMode(SM_FirstPoint)
24 {
25 }
26
27 PartSet_OperationSketchLine::~PartSet_OperationSketchLine()
28 {
29 }
30
31 bool PartSet_OperationSketchLine::isGranted() const
32 {
33   return true;
34 }
35
36 int PartSet_OperationSketchLine::getSelectionMode() const
37 {
38   return 0;//TopAbs_FACE;
39 }
40
41 void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint)
42 {
43   switch (myPointSelectionMode)
44   {
45     case SM_FirstPoint: {
46       setLinePoint(thePoint, LINE_ATTR_START);
47       myPointSelectionMode = SM_SecondPoint;
48     }
49     break;
50     case SM_SecondPoint: {
51       setLinePoint(thePoint, LINE_ATTR_END);
52       myPointSelectionMode = SM_None;
53     }
54     break;
55     case SM_None: {
56
57     }
58     break;
59     default:
60       break;
61   }
62 }
63
64 void PartSet_OperationSketchLine::mouseMoved(const gp_Pnt& thePoint)
65 {
66   if (myPointSelectionMode == SM_SecondPoint)
67     setLinePoint(thePoint, LINE_ATTR_END);
68 }
69
70 void PartSet_OperationSketchLine::startOperation()
71 {
72   PartSet_OperationSketchBase::startOperation();
73
74   if (mySketch) {
75     boost::shared_ptr<SketchPlugin_Feature> aFeature = 
76                            boost::dynamic_pointer_cast<SketchPlugin_Feature>(mySketch);
77
78     aFeature->addSub(feature());
79   }
80   myPointSelectionMode = SM_FirstPoint;
81 }
82
83 void PartSet_OperationSketchLine::stopOperation()
84 {
85   PartSet_OperationSketchBase::stopOperation();
86   myPointSelectionMode = SM_None;
87 }
88
89 void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint,
90                                                const std::string& theAttribute)
91 {
92   boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
93   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
94         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
95   double aX = thePoint.X(), anY = thePoint.Y();
96   aPoint->setValue(aX, anY);
97 }
98