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(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<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();
82 /*if (!aFeature || aFeature != feature())
85 emit featureConstructed(feature(), FM_Deactivation);
87 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
88 if(aHasShift && !theHighlighted.empty()) {
89 QResultList aSelected;
91 aSelected.push_back(feature());
92 aSelected.push_back(theHighlighted.front().result());
93 emit setSelection(aSelected);
97 restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature);
102 void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
104 if (!(theEvent->buttons() & Qt::LeftButton))
107 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
109 blockSelection(true);
110 if (myCurPoint.myIsInitialized) {
112 PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
115 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
117 double aDeltaX = aX - aCurX;
118 double aDeltaY = anY - aCurY;
120 boost::shared_ptr<SketchPlugin_Feature> aSketchFeature =
121 boost::dynamic_pointer_cast<SketchPlugin_Feature>(feature());
122 aSketchFeature->move(aDeltaX, aDeltaY);
126 myCurPoint.setPoint(aPoint);
129 void PartSet_OperationFeatureEdit::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
130 const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
131 const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
133 blockSelection(false);
136 void PartSet_OperationFeatureEdit::mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView,
137 const std::list<ModuleBase_ViewerPrs>& theSelected,
138 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
140 // TODO the functionality is important only for constraint feature. Should be moved in another place
141 if (!theSelected.empty()) {
142 ModuleBase_ViewerPrs aFeaturePrs = theSelected.front();
143 if (!aFeaturePrs.owner().IsNull()) {
144 Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast(aFeaturePrs.owner());
145 if (!anOwner.IsNull() && anOwner->SelectionMode() == AIS_DSM_Text) {
147 double aValue = PartSet_Tools::featureValue(feature(), SketchPlugin_Constraint::VALUE(), isValid);
149 ModuleBase_WidgetEditor::editFeatureValue(feature(), SketchPlugin_Constraint::VALUE());
157 void PartSet_OperationFeatureEdit::startOperation()
159 PartSet_OperationSketchBase::startOperation();
160 emit multiSelectionEnabled(false);
165 void PartSet_OperationFeatureEdit::stopOperation()
167 emit multiSelectionEnabled(true);
169 blockSelection(false, false);
172 void PartSet_OperationFeatureEdit::blockSelection(bool isBlocked, const bool isRestoreSelection)
174 if (myIsBlockedSelection == isBlocked)
177 myIsBlockedSelection = isBlocked;
178 QFeatureList aFeatureList;
179 aFeatureList.append(feature());
182 emit setSelection(QFeatureList());
183 emit stopSelection(aFeatureList, true);
186 emit stopSelection(aFeatureList, false);
187 if (isRestoreSelection)
188 emit setSelection(aFeatureList);
192 FeaturePtr PartSet_OperationFeatureEdit::createFeature(const bool /*theFlushMessage*/)
194 // do nothing in order to do not create a new feature
198 void PartSet_OperationFeatureEdit::sendFeatures()
200 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
202 FeaturePtr aFeature = feature();
203 ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
205 Events_Loop::loop()->flush(anEvent);