1 // File: PartSet_OperationSketchLine.h
2 // Created: 20 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_OperationSketchLine.h>
7 #include <SketchPlugin_Feature.h>
8 #include <GeomDataAPI_Point2D.h>
9 #include <ModelAPI_Data.h>
11 #include <SketchPlugin_Line.h>
19 PartSet_OperationSketchLine::PartSet_OperationSketchLine(const QString& theId,
21 boost::shared_ptr<ModelAPI_Feature> theFeature)
22 : PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature),
23 myPointSelectionMode(SM_FirstPoint)
27 PartSet_OperationSketchLine::~PartSet_OperationSketchLine()
31 bool PartSet_OperationSketchLine::isGranted() const
36 int PartSet_OperationSketchLine::getSelectionMode() const
38 return 0;//TopAbs_FACE;
41 void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint)
43 switch (myPointSelectionMode)
46 setLinePoint(thePoint, LINE_ATTR_START);
47 myPointSelectionMode = SM_SecondPoint;
50 case SM_SecondPoint: {
51 setLinePoint(thePoint, LINE_ATTR_END);
52 myPointSelectionMode = SM_None;
64 void PartSet_OperationSketchLine::mouseMoved(const gp_Pnt& thePoint)
66 if (myPointSelectionMode == SM_SecondPoint)
67 setLinePoint(thePoint, LINE_ATTR_END);
70 void PartSet_OperationSketchLine::startOperation()
72 PartSet_OperationSketchBase::startOperation();
75 boost::shared_ptr<SketchPlugin_Feature> aFeature =
76 boost::dynamic_pointer_cast<SketchPlugin_Feature>(mySketch);
78 aFeature->addSub(feature());
80 myPointSelectionMode = SM_FirstPoint;
83 void PartSet_OperationSketchLine::stopOperation()
85 PartSet_OperationSketchBase::stopOperation();
86 myPointSelectionMode = SM_None;
89 void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint,
90 const std::string& theAttribute)
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);