1 // File: PartSet_OperationEditFeature.h
2 // Created: 05 May 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_OperationEditFeature.h>
6 #include <PartSet_Tools.h>
7 #include <PartSet_OperationSketch.h>
9 #include <ModuleBase_OperationDescription.h>
10 #include <Model_Events.h>
12 #include <XGUI_ViewerPrs.h>
14 #include <SketchPlugin_Feature.h>
15 #include <GeomDataAPI_Point2D.h>
16 #include <ModelAPI_Data.h>
17 #include <ModelAPI_Document.h>
19 #include <Model_Events.h>
21 #include <Events_Loop.h>
23 #include <SketchPlugin_Line.h>
25 #include <V3d_View.hxx>
31 #include <QMouseEvent>
35 PartSet_OperationEditFeature::PartSet_OperationEditFeature(const QString& theId,
37 FeaturePtr theFeature)
38 : PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature), myIsBlockedSelection(false)
42 PartSet_OperationEditFeature::~PartSet_OperationEditFeature()
46 bool PartSet_OperationEditFeature::isGranted(ModuleBase_IOperation* theOperation) const
48 return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
51 std::list<int> PartSet_OperationEditFeature::getSelectionModes(FeaturePtr theFeature) const
53 return PartSet_OperationSketchBase::getSelectionModes(theFeature);
56 void PartSet_OperationEditFeature::init(FeaturePtr theFeature,
57 const std::list<XGUI_ViewerPrs>& theSelected,
58 const std::list<XGUI_ViewerPrs>& theHighlighted)
60 setFeature(theFeature);
62 if (!theHighlighted.empty()) {
63 // if there is highlighted object, we check whether it is in the list of selected objects
64 // in that case this object is a handle of the moved lines. If there no such object in the selection,
65 // the hightlighted object should moved and the selection is skipped. The skipped selection will be
66 // deselected in the viewer by blockSelection signal in the startOperation method.
67 bool isSelected = false;
68 std::list<XGUI_ViewerPrs>::const_iterator anIt = theSelected.begin(), aLast = theSelected.end();
69 for (; anIt != aLast && !isSelected; anIt++) {
70 isSelected = (*anIt).feature() == feature();
73 myFeatures = theHighlighted;
75 myFeatures = theSelected;
78 myFeatures = theSelected;
81 FeaturePtr PartSet_OperationEditFeature::sketch() const
86 void PartSet_OperationEditFeature::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView,
87 const std::list<XGUI_ViewerPrs>& /*theSelected*/,
88 const std::list<XGUI_ViewerPrs>& theHighlighted)
90 if (myFeatures.size() == 1)
93 if (!theHighlighted.empty())
94 aFeature = theHighlighted.front().feature();
96 if (aFeature && aFeature == feature()) { // continue the feature edit
99 XGUI_ViewerPrs aFeaturePrs = myFeatures.front();
101 emit featureConstructed(feature(), FM_Deactivation);
103 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
104 if(aHasShift && !theHighlighted.empty()) {
105 std::list<XGUI_ViewerPrs> aSelected;
106 aSelected.push_back(aFeaturePrs);
107 aSelected.push_back(theHighlighted.front());
108 emit setSelection(aSelected);
111 restartOperation(PartSet_OperationEditFeature::Type(), aFeature);
117 void PartSet_OperationEditFeature::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
119 if (!(theEvent->buttons() & Qt::LeftButton))
122 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
124 blockSelection(true);
125 if (myCurPoint.myIsInitialized) {
127 PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
130 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
132 double aDeltaX = aX - aCurX;
133 double aDeltaY = anY - aCurY;
135 PartSet_Tools::moveFeature(feature(), aDeltaX, aDeltaY);
137 std::list<XGUI_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();
138 for (; anIt != aLast; anIt++) {
139 FeaturePtr aFeature = (*anIt).feature();
140 if (!aFeature || aFeature == feature())
142 PartSet_Tools::moveFeature(aFeature, aDeltaX, aDeltaY);
147 myCurPoint.setPoint(aPoint);
150 void PartSet_OperationEditFeature::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
151 const std::list<XGUI_ViewerPrs>& /*theSelected*/,
152 const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
154 std::list<XGUI_ViewerPrs> aFeatures = myFeatures;
155 if (myFeatures.size() == 1) {
156 blockSelection(false);
160 std::list<XGUI_ViewerPrs>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
161 for (; anIt != aLast; anIt++) {
162 FeaturePtr aFeature = (*anIt).feature();
164 emit featureConstructed(aFeature, FM_Deactivation);
169 void PartSet_OperationEditFeature::startOperation()
171 // do nothing in order to do not create a new feature
172 emit multiSelectionEnabled(false);
174 if (myFeatures.size() > 1)
175 blockSelection(true);
180 void PartSet_OperationEditFeature::stopOperation()
182 emit multiSelectionEnabled(true);
184 blockSelection(false, myFeatures.size() > 1);
189 void PartSet_OperationEditFeature::blockSelection(bool isBlocked, const bool isRestoreSelection)
191 if (myIsBlockedSelection == isBlocked)
194 myIsBlockedSelection = isBlocked;
196 emit setSelection(std::list<XGUI_ViewerPrs>());
197 emit stopSelection(myFeatures, true);
200 emit stopSelection(myFeatures, false);
201 if (isRestoreSelection)
202 emit setSelection(myFeatures);
206 FeaturePtr PartSet_OperationEditFeature::createFeature(const bool /*theFlushMessage*/)
208 // do nothing in order to do not create a new feature
212 void PartSet_OperationEditFeature::sendFeatures()
214 static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_MOVED);
216 std::list<FeaturePtr > aFeatures;
217 std::list<XGUI_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();
218 for (; anIt != aLast; anIt++) {
219 FeaturePtr aFeature = (*anIt).feature();
223 Model_FeatureUpdatedMessage aMessage(aFeature, anEvent);
224 Events_Loop::loop()->send(aMessage);
226 Events_Loop::loop()->flush(anEvent);