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 return PartSet_OperationSketchBase::getSelectionModes(theFeature);
48 void PartSet_OperationEditLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature,
49 const std::list<XGUI_ViewerPrs>& thePresentations)
51 setFeature(theFeature);
52 myFeatures = thePresentations;
55 void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView)
57 if (!(theEvent->buttons() & Qt::LeftButton))
59 gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
60 myCurPoint.setPoint(aPoint);
63 void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
65 if (!(theEvent->buttons() & Qt::LeftButton))
68 gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
70 if (myCurPoint.myIsInitialized) {
72 PartSet_Tools::ConvertTo2D(myCurPoint.myPoint, mySketch, theView, aCurX, aCurY);
75 PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY);
77 double aDeltaX = aX - aCurX;
78 double aDeltaY = anY - aCurY;
80 moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_START);
81 moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_END);
83 std::list<XGUI_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();
84 for (; anIt != aLast; anIt++) {
85 boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).feature();
86 if (!aFeature || aFeature == feature())
88 moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_START);
89 moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_END);
92 myCurPoint.setPoint(aPoint);
95 void PartSet_OperationEditLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
96 const std::list<XGUI_ViewerPrs>& theSelected)
98 std::list<XGUI_ViewerPrs> aFeatures = myFeatures;
99 if (myFeatures.size() == 1) {
100 if (theSelected.empty())
103 boost::shared_ptr<ModelAPI_Feature> aFeature = theSelected.front().feature();
105 emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
109 std::list<XGUI_ViewerPrs>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
110 for (; anIt != aLast; anIt++) {
111 boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).feature();
113 emit featureConstructed(aFeature, FM_Deactivation);
118 void PartSet_OperationEditLine::startOperation()
120 // do nothing in order to do not create a new feature
121 emit multiSelectionEnabled(false);
122 emit setSelection(std::list<XGUI_ViewerPrs>());
123 emit stopSelection(myFeatures, true);
127 void PartSet_OperationEditLine::stopOperation()
129 emit multiSelectionEnabled(true);
130 bool isSelectFeatures = myFeatures.size() > 1;
131 emit stopSelection(myFeatures, false);
132 if (isSelectFeatures)
133 emit setSelection(myFeatures);
138 boost::shared_ptr<ModelAPI_Feature> PartSet_OperationEditLine::createFeature()
140 // do nothing in order to do not create a new feature
141 return boost::shared_ptr<ModelAPI_Feature>();
144 void PartSet_OperationEditLine::moveLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
145 double theDeltaX, double theDeltaY,
146 const std::string& theAttribute)
148 if (!theFeature || theFeature->getKind() != "SketchLine")
151 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
152 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
153 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
155 aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY);