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>
29 #include <AIS_DimensionOwner.hxx>
30 #include <AIS_DimensionSelectionMode.hxx>
36 #include <QMouseEvent>
40 PartSet_OperationFeatureEdit::PartSet_OperationFeatureEdit(const QString& theId,
42 FeaturePtr theFeature)
43 : PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature), myIsBlockedSelection(false)
47 PartSet_OperationFeatureEdit::~PartSet_OperationFeatureEdit()
51 bool PartSet_OperationFeatureEdit::isGranted(ModuleBase_IOperation* theOperation) const
53 return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
56 std::list<int> PartSet_OperationFeatureEdit::getSelectionModes(FeaturePtr theFeature) const
58 return PartSet_OperationSketchBase::getSelectionModes(theFeature);
61 void PartSet_OperationFeatureEdit::initFeature(FeaturePtr theFeature)
63 setEditingFeature(theFeature);
67 FeaturePtr PartSet_OperationFeatureEdit::sketch() const
72 void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView,
73 const std::list<XGUI_ViewerPrs>& theSelected,
74 const std::list<XGUI_ViewerPrs>& theHighlighted)
77 if (!theHighlighted.empty())
78 aFeature = theHighlighted.front().feature();
79 if (!aFeature && !theSelected.empty()) // changed for a constrain
80 aFeature = theSelected.front().feature();
82 if (!aFeature || aFeature != feature())
85 emit featureConstructed(feature(), FM_Deactivation);
87 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
88 if(aHasShift && !theHighlighted.empty()) {
89 QFeatureList aSelected;
90 aSelected.push_back(feature());
91 aSelected.push_back(theHighlighted.front().feature());
92 emit setSelection(aSelected);
95 restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature);
100 void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
102 if (!(theEvent->buttons() & Qt::LeftButton))
105 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
107 blockSelection(true);
108 if (myCurPoint.myIsInitialized) {
110 PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
113 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
115 double aDeltaX = aX - aCurX;
116 double aDeltaY = anY - aCurY;
118 boost::shared_ptr<SketchPlugin_Feature> aSketchFeature =
119 boost::dynamic_pointer_cast<SketchPlugin_Feature>(feature());
120 aSketchFeature->move(aDeltaX, aDeltaY);
124 myCurPoint.setPoint(aPoint);
127 void PartSet_OperationFeatureEdit::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
128 const std::list<XGUI_ViewerPrs>& /*theSelected*/,
129 const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
131 blockSelection(false);
134 void PartSet_OperationFeatureEdit::mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView,
135 const std::list<XGUI_ViewerPrs>& theSelected,
136 const std::list<XGUI_ViewerPrs>& theHighlighted)
138 // TODO the functionality is important only for constraint feature. Should be moved in another place
139 if (!theSelected.empty()) {
140 XGUI_ViewerPrs aFeaturePrs = theSelected.front();
141 if (!aFeaturePrs.owner().IsNull()) {
142 Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast(aFeaturePrs.owner());
143 if (!anOwner.IsNull() && anOwner->SelectionMode() == AIS_DSM_Text) {
145 double aValue = PartSet_Tools::featureValue(feature(), CONSTRAINT_ATTR_VALUE, isValid);
147 ModuleBase_WidgetEditor::editFeatureValue(feature(), CONSTRAINT_ATTR_VALUE);
155 void PartSet_OperationFeatureEdit::startOperation()
157 PartSet_OperationSketchBase::startOperation();
158 emit multiSelectionEnabled(false);
163 void PartSet_OperationFeatureEdit::stopOperation()
165 emit multiSelectionEnabled(true);
167 blockSelection(false, false);
170 void PartSet_OperationFeatureEdit::blockSelection(bool isBlocked, const bool isRestoreSelection)
172 if (myIsBlockedSelection == isBlocked)
175 myIsBlockedSelection = isBlocked;
176 QFeatureList aFeatureList;
177 aFeatureList.append(feature());
180 emit setSelection(QFeatureList());
181 emit stopSelection(aFeatureList, true);
184 emit stopSelection(aFeatureList, false);
185 if (isRestoreSelection)
186 emit setSelection(aFeatureList);
190 FeaturePtr PartSet_OperationFeatureEdit::createFeature(const bool /*theFlushMessage*/)
192 // do nothing in order to do not create a new feature
196 void PartSet_OperationFeatureEdit::sendFeatures()
198 static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_MOVED);
200 FeaturePtr aFeature = feature();
202 Model_FeatureUpdatedMessage aMessage(aFeature, anEvent);
203 Events_Loop::loop()->send(aMessage);
205 Events_Loop::loop()->flush(anEvent);