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 <ModuleBase_ViewerPrs.h>
15 #include <ModelAPI_Events.h>
17 #include <SketchPlugin_Feature.h>
18 #include <GeomDataAPI_Point2D.h>
19 #include <ModelAPI_Data.h>
20 #include <ModelAPI_Document.h>
22 #include <ModelAPI_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(ObjectPtr 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<ModuleBase_ViewerPrs>& theSelected,
74 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
77 if (!theHighlighted.empty())
78 aFeature = theHighlighted.front().object();
79 if (!aFeature && !theSelected.empty()) // changed for a constrain
80 aFeature = theSelected.front().object();
81 if (!aFeature || aFeature != feature()) {
83 emit featureConstructed(feature(), FM_Deactivation);
85 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
86 if(aHasShift && !theHighlighted.empty()) {
87 QList<ObjectPtr> aSelected;
88 aSelected.push_back(feature());
89 aSelected.push_back(theHighlighted.front().object());
90 emit setSelection(aSelected);
93 restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature);
98 void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
100 if (!(theEvent->buttons() & Qt::LeftButton))
103 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
105 blockSelection(true);
106 if (myCurPoint.myIsInitialized) {
108 PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
111 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
113 double aDeltaX = aX - aCurX;
114 double aDeltaY = anY - aCurY;
116 boost::shared_ptr<SketchPlugin_Feature> aSketchFeature =
117 boost::dynamic_pointer_cast<SketchPlugin_Feature>(feature());
118 aSketchFeature->move(aDeltaX, aDeltaY);
122 myCurPoint.setPoint(aPoint);
125 void PartSet_OperationFeatureEdit::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
126 const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
127 const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
129 blockSelection(false);
132 void PartSet_OperationFeatureEdit::mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView,
133 const std::list<ModuleBase_ViewerPrs>& theSelected,
134 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
136 // TODO the functionality is important only for constraint feature. Should be moved in another place
137 if (!theSelected.empty()) {
138 ModuleBase_ViewerPrs aFeaturePrs = theSelected.front();
139 if (!aFeaturePrs.owner().IsNull()) {
140 Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast(aFeaturePrs.owner());
141 if (!anOwner.IsNull() && anOwner->SelectionMode() == AIS_DSM_Text) {
143 double aValue = PartSet_Tools::featureValue(feature(), SketchPlugin_Constraint::VALUE(), isValid);
145 ModuleBase_WidgetEditor::editFeatureValue(feature(), SketchPlugin_Constraint::VALUE());
153 void PartSet_OperationFeatureEdit::startOperation()
155 PartSet_OperationSketchBase::startOperation();
156 emit multiSelectionEnabled(false);
161 void PartSet_OperationFeatureEdit::stopOperation()
163 emit multiSelectionEnabled(true);
165 blockSelection(false, false);
168 void PartSet_OperationFeatureEdit::blockSelection(bool isBlocked, const bool isRestoreSelection)
170 if (myIsBlockedSelection == isBlocked)
173 myIsBlockedSelection = isBlocked;
174 QList<ObjectPtr> aFeatureList;
175 aFeatureList.append(feature());
178 emit setSelection(QList<ObjectPtr>());
179 emit stopSelection(aFeatureList, true);
182 emit stopSelection(aFeatureList, false);
183 if (isRestoreSelection)
184 emit setSelection(aFeatureList);
188 FeaturePtr PartSet_OperationFeatureEdit::createFeature(const bool /*theFlushMessage*/)
190 // do nothing in order to do not create a new feature
194 void PartSet_OperationFeatureEdit::sendFeatures()
196 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
198 FeaturePtr aFeature = feature();
199 ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
201 Events_Loop::loop()->flush(anEvent);