1 // File: PartSet_OperationEditLine.h
2 // Created: 05 May 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_OperationEditLine.h>
6 #include <PartSet_Tools.h>
8 #include <SketchPlugin_Feature.h>
9 #include <GeomDataAPI_Point2D.h>
10 #include <ModelAPI_Data.h>
11 #include <ModelAPI_Document.h>
13 #include <SketchPlugin_Line.h>
15 #include <V3d_View.hxx>
21 #include <QMouseEvent>
25 PartSet_OperationEditLine::PartSet_OperationEditLine(const QString& theId,
27 boost::shared_ptr<ModelAPI_Feature> theFeature)
28 : PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature)
32 PartSet_OperationEditLine::~PartSet_OperationEditLine()
36 bool PartSet_OperationEditLine::isGranted() const
41 std::list<int> PartSet_OperationEditLine::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
43 std::list<int> aModes;
44 aModes.push_back(TopAbs_VERTEX);
45 aModes.push_back(TopAbs_EDGE);
49 void PartSet_OperationEditLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature)
51 setFeature(theFeature);
54 void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView)
56 if (!(theEvent->buttons() & Qt::LeftButton))
58 gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
59 myCurPressed = aPoint;
62 void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
64 if (!(theEvent->buttons() & Qt::LeftButton))
68 PartSet_Tools::ConvertTo2D(myCurPressed, mySketch, aCurX, aCurY);
71 gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
72 PartSet_Tools::ConvertTo2D(aPoint, mySketch, aX, anY);
74 double aDeltaX = aX - aCurX;
75 double aDeltaY = anY - aCurY;
77 moveLinePoint(aDeltaX, aDeltaY, LINE_ATTR_START);
78 moveLinePoint(aDeltaX, aDeltaY, LINE_ATTR_END);
79 myCurPressed = aPoint;
82 void PartSet_OperationEditLine::setSelected(boost::shared_ptr<ModelAPI_Feature> theFeature,
83 const TopoDS_Shape& theShape)
85 if (theFeature == feature())
91 emit launchOperation(PartSet_OperationEditLine::Type(), theFeature);
94 void PartSet_OperationEditLine::startOperation()
96 // do nothing in order to do not create a new feature
99 boost::shared_ptr<ModelAPI_Feature> PartSet_OperationEditLine::createFeature()
101 // do nothing in order to do not create a new feature
102 return boost::shared_ptr<ModelAPI_Feature>();
105 void PartSet_OperationEditLine::moveLinePoint(double theDeltaX, double theDeltaY,
106 const std::string& theAttribute)
108 boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
109 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
110 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
112 aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY);