1 // File: PartSet_OperationFeatureEdit.h
2 // Created: 05 May 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_OperationFeatureEdit.h>
6 #include <PartSet_Tools.h>
7 #include <PartSet_OperationSketch.h>
9 #include <SketchPlugin_Constraint.h>
11 #include <ModuleBase_OperationDescription.h>
12 #include <ModuleBase_WidgetEditor.h>
13 #include <Model_Events.h>
15 #include <XGUI_ViewerPrs.h>
17 #include <SketchPlugin_Feature.h>
18 #include <GeomDataAPI_Point2D.h>
19 #include <ModelAPI_Data.h>
20 #include <ModelAPI_Document.h>
22 #include <Model_Events.h>
24 #include <Events_Loop.h>
26 #include <SketchPlugin_Line.h>
28 #include <V3d_View.hxx>
34 #include <QMouseEvent>
38 PartSet_OperationFeatureEdit::PartSet_OperationFeatureEdit(const QString& theId,
40 FeaturePtr theFeature)
41 : PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature), myIsBlockedSelection(false)
45 PartSet_OperationFeatureEdit::~PartSet_OperationFeatureEdit()
49 bool PartSet_OperationFeatureEdit::isGranted(ModuleBase_IOperation* theOperation) const
51 return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
54 std::list<int> PartSet_OperationFeatureEdit::getSelectionModes(FeaturePtr theFeature) const
56 return PartSet_OperationSketchBase::getSelectionModes(theFeature);
59 void PartSet_OperationFeatureEdit::init(FeaturePtr theFeature,
60 const std::list<XGUI_ViewerPrs>& theSelected,
61 const std::list<XGUI_ViewerPrs>& theHighlighted)
63 setEditingFeature(theFeature);
66 FeaturePtr PartSet_OperationFeatureEdit::sketch() const
71 void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView,
72 const std::list<XGUI_ViewerPrs>& theSelected,
73 const std::list<XGUI_ViewerPrs>& theHighlighted)
76 if (!theHighlighted.empty())
77 aFeature = theHighlighted.front().feature();
78 if (!aFeature && !theSelected.empty()) // changed for a constrain
79 aFeature = theSelected.front().feature();
81 if (!aFeature || aFeature != feature())
84 emit featureConstructed(feature(), FM_Deactivation);
86 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
87 if(aHasShift && !theHighlighted.empty()) {
88 QFeatureList aSelected;
89 aSelected.push_back(feature());
90 aSelected.push_back(theHighlighted.front().feature());
91 emit setSelection(aSelected);
94 restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature);
99 void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
101 if (!(theEvent->buttons() & Qt::LeftButton))
104 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
106 blockSelection(true);
107 if (myCurPoint.myIsInitialized) {
109 PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
112 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
114 double aDeltaX = aX - aCurX;
115 double aDeltaY = anY - aCurY;
117 boost::shared_ptr<SketchPlugin_Feature> aSketchFeature =
118 boost::dynamic_pointer_cast<SketchPlugin_Feature>(feature());
119 aSketchFeature->move(aDeltaX, aDeltaY);
123 myCurPoint.setPoint(aPoint);
126 void PartSet_OperationFeatureEdit::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
127 const std::list<XGUI_ViewerPrs>& /*theSelected*/,
128 const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
130 blockSelection(false);
133 void PartSet_OperationFeatureEdit::mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView,
134 const std::list<XGUI_ViewerPrs>& theSelected,
135 const std::list<XGUI_ViewerPrs>& theHighlighted)
138 if (!theSelected.empty()) {
140 double aValue = PartSet_Tools::featureValue(feature(), CONSTRAINT_ATTR_VALUE, isValid);
142 ModuleBase_WidgetEditor::editFeatureValue(feature(), CONSTRAINT_ATTR_VALUE);
144 //QPoint aPos = theEvent->globalPos();
145 //myEditor->start(aPos, aValue);
150 void PartSet_OperationFeatureEdit::startOperation()
152 PartSet_OperationSketchBase::startOperation();
153 emit multiSelectionEnabled(false);
158 void PartSet_OperationFeatureEdit::stopOperation()
160 emit multiSelectionEnabled(true);
162 blockSelection(false, false);
165 void PartSet_OperationFeatureEdit::blockSelection(bool isBlocked, const bool isRestoreSelection)
167 if (myIsBlockedSelection == isBlocked)
170 myIsBlockedSelection = isBlocked;
171 QFeatureList aFeatureList;
172 aFeatureList.append(feature());
175 emit setSelection(QFeatureList());
176 emit stopSelection(aFeatureList, true);
179 emit stopSelection(aFeatureList, false);
180 if (isRestoreSelection)
181 emit setSelection(aFeatureList);
185 FeaturePtr PartSet_OperationFeatureEdit::createFeature(const bool /*theFlushMessage*/)
187 // do nothing in order to do not create a new feature
191 void PartSet_OperationFeatureEdit::sendFeatures()
193 static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_MOVED);
195 FeaturePtr aFeature = feature();
197 Model_FeatureUpdatedMessage aMessage(aFeature, anEvent);
198 Events_Loop::loop()->send(aMessage);
200 Events_Loop::loop()->flush(anEvent);