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 <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_OperationFeatureEdit::PartSet_OperationFeatureEdit(const QString& theId,
37 FeaturePtr theFeature)
38 : PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature), myIsBlockedSelection(false)
42 PartSet_OperationFeatureEdit::~PartSet_OperationFeatureEdit()
46 bool PartSet_OperationFeatureEdit::isGranted(ModuleBase_IOperation* theOperation) const
48 return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
51 std::list<int> PartSet_OperationFeatureEdit::getSelectionModes(FeaturePtr theFeature) const
53 return PartSet_OperationSketchBase::getSelectionModes(theFeature);
56 void PartSet_OperationFeatureEdit::init(FeaturePtr theFeature,
57 const std::list<XGUI_ViewerPrs>& theSelected,
58 const std::list<XGUI_ViewerPrs>& theHighlighted)
60 setEditingFeature(theFeature);
63 FeaturePtr PartSet_OperationFeatureEdit::sketch() const
68 void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView,
69 const std::list<XGUI_ViewerPrs>& /*theSelected*/,
70 const std::list<XGUI_ViewerPrs>& theHighlighted)
73 if (!theHighlighted.empty())
74 aFeature = theHighlighted.front().feature();
76 if (!aFeature || aFeature != feature())
79 emit featureConstructed(feature(), FM_Deactivation);
81 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
82 if(aHasShift && !theHighlighted.empty()) {
83 QFeatureList aSelected;
84 aSelected.push_back(feature());
85 aSelected.push_back(theHighlighted.front().feature());
86 emit setSelection(aSelected);
89 restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature);
94 void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
96 if (!(theEvent->buttons() & Qt::LeftButton))
99 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
101 blockSelection(true);
102 if (myCurPoint.myIsInitialized) {
104 PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
107 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
109 double aDeltaX = aX - aCurX;
110 double aDeltaY = anY - aCurY;
112 boost::shared_ptr<SketchPlugin_Feature> aSketchFeature =
113 boost::dynamic_pointer_cast<SketchPlugin_Feature>(feature());
114 aSketchFeature->move(aDeltaX, aDeltaY);
118 myCurPoint.setPoint(aPoint);
121 void PartSet_OperationFeatureEdit::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
122 const std::list<XGUI_ViewerPrs>& /*theSelected*/,
123 const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
125 blockSelection(false);
128 void PartSet_OperationFeatureEdit::startOperation()
130 PartSet_OperationSketchBase::startOperation();
131 emit multiSelectionEnabled(false);
136 void PartSet_OperationFeatureEdit::stopOperation()
138 emit multiSelectionEnabled(true);
140 blockSelection(false, false);
143 void PartSet_OperationFeatureEdit::blockSelection(bool isBlocked, const bool isRestoreSelection)
145 if (myIsBlockedSelection == isBlocked)
148 myIsBlockedSelection = isBlocked;
149 QFeatureList aFeatureList;
150 aFeatureList.append(feature());
153 emit setSelection(QFeatureList());
154 emit stopSelection(aFeatureList, true);
157 emit stopSelection(aFeatureList, false);
158 if (isRestoreSelection)
159 emit setSelection(aFeatureList);
163 FeaturePtr PartSet_OperationFeatureEdit::createFeature(const bool /*theFlushMessage*/)
165 // do nothing in order to do not create a new feature
169 void PartSet_OperationFeatureEdit::sendFeatures()
171 static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_MOVED);
173 FeaturePtr aFeature = feature();
175 Model_FeatureUpdatedMessage aMessage(aFeature, anEvent);
176 Events_Loop::loop()->send(aMessage);
178 Events_Loop::loop()->flush(anEvent);