1 // File: PartSet_OperationEditLine.h
2 // Created: 05 May 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_OperationEditLine.h>
6 #include <PartSet_Tools.h>
7 #include <PartSet_OperationSketch.h>
9 #include <ModuleBase_OperationDescription.h>
11 #include <XGUI_ViewerPrs.h>
13 #include <SketchPlugin_Feature.h>
14 #include <GeomDataAPI_Point2D.h>
15 #include <ModelAPI_Data.h>
16 #include <ModelAPI_Document.h>
18 #include <SketchPlugin_Line.h>
20 #include <V3d_View.hxx>
26 #include <QMouseEvent>
30 PartSet_OperationEditLine::PartSet_OperationEditLine(const QString& theId,
32 boost::shared_ptr<ModelAPI_Feature> theFeature)
33 : PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature)
37 PartSet_OperationEditLine::~PartSet_OperationEditLine()
41 bool PartSet_OperationEditLine::isGranted(ModuleBase_IOperation* theOperation) const
43 return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
46 std::list<int> PartSet_OperationEditLine::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
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 boost::shared_ptr<ModelAPI_Feature> PartSet_OperationEditLine::sketch() const
63 void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView)
65 if (!(theEvent->buttons() & Qt::LeftButton))
67 gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
68 myCurPoint.setPoint(aPoint);
71 void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
73 if (!(theEvent->buttons() & Qt::LeftButton))
76 gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
78 if (myCurPoint.myIsInitialized) {
80 PartSet_Tools::ConvertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
83 PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
85 double aDeltaX = aX - aCurX;
86 double aDeltaY = anY - aCurY;
88 moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_START);
89 moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_END);
91 std::list<XGUI_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();
92 for (; anIt != aLast; anIt++) {
93 boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).feature();
94 if (!aFeature || aFeature == feature())
96 moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_START);
97 moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_END);
100 myCurPoint.setPoint(aPoint);
103 void PartSet_OperationEditLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
104 const std::list<XGUI_ViewerPrs>& theSelected)
106 std::list<XGUI_ViewerPrs> aFeatures = myFeatures;
107 if (myFeatures.size() == 1) {
108 if (theSelected.empty())
111 boost::shared_ptr<ModelAPI_Feature> aFeature = theSelected.front().feature();
113 emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
117 std::list<XGUI_ViewerPrs>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
118 for (; anIt != aLast; anIt++) {
119 boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).feature();
121 emit featureConstructed(aFeature, FM_Deactivation);
126 void PartSet_OperationEditLine::startOperation()
128 // do nothing in order to do not create a new feature
129 emit multiSelectionEnabled(false);
130 emit setSelection(std::list<XGUI_ViewerPrs>());
131 emit stopSelection(myFeatures, true);
135 void PartSet_OperationEditLine::stopOperation()
137 emit multiSelectionEnabled(true);
138 bool isSelectFeatures = myFeatures.size() > 1;
139 emit stopSelection(myFeatures, false);
140 if (isSelectFeatures)
141 emit setSelection(myFeatures);
146 boost::shared_ptr<ModelAPI_Feature> PartSet_OperationEditLine::createFeature()
148 // do nothing in order to do not create a new feature
149 return boost::shared_ptr<ModelAPI_Feature>();
152 void PartSet_OperationEditLine::moveLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
153 double theDeltaX, double theDeltaY,
154 const std::string& theAttribute)
156 if (!theFeature || theFeature->getKind() != "SketchLine")
159 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
160 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
161 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
163 aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY);