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 <XGUI_ViewerPrs.h>
10 #include <SketchPlugin_Feature.h>
11 #include <GeomDataAPI_Point2D.h>
12 #include <ModelAPI_Data.h>
13 #include <ModelAPI_Document.h>
15 #include <SketchPlugin_Line.h>
17 #include <V3d_View.hxx>
23 #include <QMouseEvent>
27 PartSet_OperationEditLine::PartSet_OperationEditLine(const QString& theId,
29 boost::shared_ptr<ModelAPI_Feature> theFeature)
30 : PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature)
34 PartSet_OperationEditLine::~PartSet_OperationEditLine()
38 bool PartSet_OperationEditLine::isGranted() const
43 std::list<int> PartSet_OperationEditLine::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
45 std::list<int> aModes;
46 aModes.push_back(TopAbs_VERTEX);
47 aModes.push_back(TopAbs_EDGE);
51 void PartSet_OperationEditLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature)
53 setFeature(theFeature);
56 void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView)
58 if (!(theEvent->buttons() & Qt::LeftButton))
60 gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
61 myCurPoint.setPoint(aPoint);
64 void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView,
65 const std::list<XGUI_ViewerPrs>& theSelected)
67 if (!(theEvent->buttons() & Qt::LeftButton))
69 gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
71 if (myCurPoint.myIsInitialized) {
73 PartSet_Tools::ConvertTo2D(myCurPoint.myPoint, mySketch, theView, aCurX, aCurY);
76 PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY);
78 double aDeltaX = aX - aCurX;
79 double aDeltaY = anY - aCurY;
81 moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_START);
82 moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_END);
84 /*std::list<XGUI_ViewerPrs>::const_iterator anIt = theSelected.begin(), aLast = theSelected.end();
85 for (; anIt != aLast; anIt++) {
86 boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).feature();
89 moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_START);
90 moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_END);
93 myCurPoint.setPoint(aPoint);
96 void PartSet_OperationEditLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
97 const std::list<XGUI_ViewerPrs>& theSelected)
99 boost::shared_ptr<ModelAPI_Feature> aFeature;
100 if (!theSelected.empty())
101 aFeature = theSelected.front().feature();
103 if (aFeature == feature())
108 emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
111 void PartSet_OperationEditLine::startOperation()
113 // do nothing in order to do not create a new feature
114 emit selectionEnabled(false);
118 void PartSet_OperationEditLine::stopOperation()
120 emit selectionEnabled(true);
123 boost::shared_ptr<ModelAPI_Feature> PartSet_OperationEditLine::createFeature()
125 // do nothing in order to do not create a new feature
126 return boost::shared_ptr<ModelAPI_Feature>();
129 void PartSet_OperationEditLine::moveLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
130 double theDeltaX, double theDeltaY,
131 const std::string& theAttribute)
136 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
137 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
138 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
140 aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY);