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;
48 //return PartSet_OperationSketchBase::getSelectionModes(theFeature);
51 void PartSet_OperationEditLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature,
52 const std::list<XGUI_ViewerPrs>& thePresentations)
54 setFeature(theFeature);
55 myFeatures = thePresentations;
58 void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView)
60 if (!(theEvent->buttons() & Qt::LeftButton))
62 gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
63 myCurPoint.setPoint(aPoint);
66 void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
68 if (!(theEvent->buttons() & Qt::LeftButton))
71 gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
73 if (myCurPoint.myIsInitialized) {
75 PartSet_Tools::ConvertTo2D(myCurPoint.myPoint, mySketch, theView, aCurX, aCurY);
78 PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY);
80 double aDeltaX = aX - aCurX;
81 double aDeltaY = anY - aCurY;
83 moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_START);
84 moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_END);
86 std::list<XGUI_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();
87 for (; anIt != aLast; anIt++) {
88 boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).feature();
89 if (!aFeature || aFeature == feature())
91 moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_START);
92 moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_END);
95 myCurPoint.setPoint(aPoint);
98 void PartSet_OperationEditLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
99 const std::list<XGUI_ViewerPrs>& theSelected)
101 std::list<XGUI_ViewerPrs> aFeatures = myFeatures;
102 if (myFeatures.size() == 1) {
103 boost::shared_ptr<ModelAPI_Feature> aFeature;
104 if (!theSelected.empty())
105 aFeature = theSelected.front().feature();
107 if (aFeature == feature())
112 emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
116 std::list<XGUI_ViewerPrs>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
117 for (; anIt != aLast; anIt++) {
118 boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).feature();
120 emit featureConstructed(aFeature, FM_Deactivation);
125 void PartSet_OperationEditLine::startOperation()
127 // do nothing in order to do not create a new feature
128 emit multiSelectionEnabled(false);
129 emit stopSelection(myFeatures, true);
133 void PartSet_OperationEditLine::stopOperation()
135 emit multiSelectionEnabled(true);
136 emit stopSelection(myFeatures, false);
140 boost::shared_ptr<ModelAPI_Feature> PartSet_OperationEditLine::createFeature()
142 // do nothing in order to do not create a new feature
143 return boost::shared_ptr<ModelAPI_Feature>();
146 void PartSet_OperationEditLine::moveLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
147 double theDeltaX, double theDeltaY,
148 const std::string& theAttribute)
150 if (!theFeature || theFeature->getKind() != "SketchLine")
153 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
154 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
155 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
157 aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY);