]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_OperationSketchLine.cpp
Salome HOME
refs #30 - Sketch base GUI: create, draw lines
[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::setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList,
42                                                     const gp_Pnt& thePoint)
43 {
44   if (theList.IsEmpty())
45     return;
46
47   switch (myPointSelectionMode)
48   {
49     case SM_FirstPoint: {
50       setLinePoint(thePoint, LINE_ATTR_START);
51       myPointSelectionMode = SM_SecondPoint;
52     }
53     break;
54     case SM_SecondPoint: {
55       setLinePoint(thePoint, LINE_ATTR_END);
56       commit();
57     }
58     break;
59     case SM_None: {
60
61     }
62     break;
63     default:
64       break;
65   }
66 }
67
68 void PartSet_OperationSketchLine::setMouseMovePoint(const gp_Pnt& thePoint)
69 {
70   if (myPointSelectionMode == SM_SecondPoint)
71     setLinePoint(thePoint, LINE_ATTR_END);
72 }
73
74 void PartSet_OperationSketchLine::startOperation()
75 {
76   PartSet_OperationSketchBase::startOperation();
77
78   if (mySketch) {
79     boost::shared_ptr<SketchPlugin_Feature> aFeature = 
80                            boost::dynamic_pointer_cast<SketchPlugin_Feature>(mySketch);
81
82     aFeature->addSub(feature());
83   }
84   myPointSelectionMode = SM_FirstPoint;
85 }
86
87 void PartSet_OperationSketchLine::stopOperation()
88 {
89   PartSet_OperationSketchBase::stopOperation();
90
91   myPointSelectionMode = SM_None;
92 }
93
94 void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint,
95                                                const std::string& theAttribute)
96 {
97   boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
98   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
99         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
100   double aX = thePoint.X(), anY = thePoint.Y();
101   aPoint->setValue(aX, anY);
102 }
103