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>
14 #include <ModuleBase_Tools.h>
16 #include <ModelAPI_Events.h>
18 #include <SketchPlugin_Feature.h>
19 #include <GeomDataAPI_Point2D.h>
20 #include <ModelAPI_Data.h>
21 #include <ModelAPI_Document.h>
23 #include <ModelAPI_Events.h>
25 #include <Events_Loop.h>
27 #include <SketchPlugin_Line.h>
29 #include <V3d_View.hxx>
30 #include <AIS_DimensionOwner.hxx>
31 #include <AIS_DimensionSelectionMode.hxx>
37 #include <QMouseEvent>
41 PartSet_OperationFeatureEdit::PartSet_OperationFeatureEdit(const QString& theId,
43 FeaturePtr theFeature)
44 : PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature), myIsBlockedSelection(false)
48 PartSet_OperationFeatureEdit::~PartSet_OperationFeatureEdit()
52 bool PartSet_OperationFeatureEdit::isGranted(ModuleBase_IOperation* theOperation) const
54 return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
57 std::list<int> PartSet_OperationFeatureEdit::getSelectionModes(ObjectPtr theFeature) const
59 return PartSet_OperationSketchBase::getSelectionModes(theFeature);
62 void PartSet_OperationFeatureEdit::initFeature(FeaturePtr theFeature)
64 setEditingFeature(theFeature);
68 FeaturePtr PartSet_OperationFeatureEdit::sketch() const
73 void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView,
74 const std::list<ModuleBase_ViewerPrs>& theSelected,
75 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
78 if (!theHighlighted.empty())
79 aObject = theHighlighted.front().object();
80 if (!aObject && !theSelected.empty()) // changed for a constrain
81 aObject = theSelected.front().object();
83 FeaturePtr aFeature = ModuleBase_Tools::feature(aObject);
84 if (!aFeature || aFeature != feature()) {
86 emit featureConstructed(feature(), FM_Deactivation);
88 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
89 if(aHasShift && !theHighlighted.empty()) {
90 QList<ObjectPtr> aSelected;
91 std::list<ModuleBase_ViewerPrs>::const_iterator aIt;
92 for (aIt = theSelected.cbegin(); aIt != theSelected.cend(); ++aIt)
93 aSelected.append((*aIt).object());
94 /*for (aIt = theHighlighted.cbegin(); aIt != theHighlighted.cend(); ++aIt) {
95 if (!aSelected.contains((*aIt).object()))
96 aSelected.append((*aIt).object());
98 //aSelected.push_back(feature());
99 //aSelected.push_back(theHighlighted.front().object());
100 emit setSelection(aSelected);
103 restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature);
109 void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
111 if (!(theEvent->buttons() & Qt::LeftButton))
114 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
116 blockSelection(true);
117 if (myCurPoint.myIsInitialized) {
119 PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
122 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
124 double aDeltaX = aX - aCurX;
125 double aDeltaY = anY - aCurY;
127 boost::shared_ptr<SketchPlugin_Feature> aSketchFeature =
128 boost::dynamic_pointer_cast<SketchPlugin_Feature>(feature());
129 aSketchFeature->move(aDeltaX, aDeltaY);
130 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
131 ModelAPI_EventCreator::get()->sendUpdated(feature(), anEvent);
135 myCurPoint.setPoint(aPoint);
138 void PartSet_OperationFeatureEdit::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
139 const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
140 const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
142 blockSelection(false);
145 void PartSet_OperationFeatureEdit::mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView,
146 const std::list<ModuleBase_ViewerPrs>& theSelected,
147 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
149 // TODO the functionality is important only for constraint feature. Should be moved in another place
150 if (!theSelected.empty()) {
151 ModuleBase_ViewerPrs aFeaturePrs = theSelected.front();
152 if (!aFeaturePrs.owner().IsNull()) {
153 Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast(aFeaturePrs.owner());
154 if (!anOwner.IsNull() && anOwner->SelectionMode() == AIS_DSM_Text) {
156 double aValue = PartSet_Tools::featureValue(feature(), SketchPlugin_Constraint::VALUE(), isValid);
158 ModuleBase_WidgetEditor::editFeatureValue(feature(), SketchPlugin_Constraint::VALUE());
167 void PartSet_OperationFeatureEdit::keyReleased(const int theKey)
169 if (theKey == Qt::Key_Return) {
172 PartSet_OperationSketchBase::keyReleased(theKey);
175 void PartSet_OperationFeatureEdit::startOperation()
177 PartSet_OperationSketchBase::startOperation();
178 emit multiSelectionEnabled(false);
183 void PartSet_OperationFeatureEdit::stopOperation()
185 emit multiSelectionEnabled(true);
187 blockSelection(false, false);
190 void PartSet_OperationFeatureEdit::blockSelection(bool isBlocked, const bool isRestoreSelection)
192 if (myIsBlockedSelection == isBlocked)
195 myIsBlockedSelection = isBlocked;
196 QList<ObjectPtr> aFeatureList;
197 aFeatureList.append(feature());
200 emit setSelection(QList<ObjectPtr>());
201 emit stopSelection(aFeatureList, true);
204 emit stopSelection(aFeatureList, false);
205 if (isRestoreSelection)
206 emit setSelection(aFeatureList);
210 FeaturePtr PartSet_OperationFeatureEdit::createFeature(const bool /*theFlushMessage*/)
212 // do nothing in order to do not create a new feature
216 void PartSet_OperationFeatureEdit::sendFeatures()
218 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
220 FeaturePtr aFeature = feature();
221 ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
223 Events_Loop::loop()->flush(anEvent);