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>
20 #include <ModelAPI_Data.h>
21 #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, QObject* theParent,
41 FeaturePtr theFeature)
42 : PartSet_OperationSketchBase(theId, theParent),
44 myIsBlockedSelection(false)
48 PartSet_OperationFeatureEdit::~PartSet_OperationFeatureEdit()
52 std::list<int> PartSet_OperationFeatureEdit::getSelectionModes(ObjectPtr theFeature) const
54 return PartSet_OperationSketchBase::getSelectionModes(theFeature);
57 void PartSet_OperationFeatureEdit::initFeature(FeaturePtr theFeature)
59 setEditingFeature(theFeature);
62 FeaturePtr PartSet_OperationFeatureEdit::sketch() const
67 void PartSet_OperationFeatureEdit::mousePressed(
68 QMouseEvent* theEvent, Handle(V3d_View) theView,
69 const std::list<ModuleBase_ViewerPrs>& theSelected,
70 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
73 if (!theHighlighted.empty())
74 aObject = theHighlighted.front().object();
75 if (!aObject && !theSelected.empty()) // changed for a constrain
76 aObject = theSelected.front().object();
78 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
79 if (!aFeature || aFeature != feature()) {
81 emit featureConstructed(feature(), FM_Deactivation);
83 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
84 if (aHasShift && !theHighlighted.empty()) {
85 QList<ObjectPtr> aSelected;
86 std::list<ModuleBase_ViewerPrs>::const_iterator aIt;
87 for (aIt = theSelected.cbegin(); aIt != theSelected.cend(); ++aIt)
88 aSelected.append((*aIt).object());
89 /*for (aIt = theHighlighted.cbegin(); aIt != theHighlighted.cend(); ++aIt) {
90 if (!aSelected.contains((*aIt).object()))
91 aSelected.append((*aIt).object());
93 //aSelected.push_back(feature());
94 //aSelected.push_back(theHighlighted.front().object());
95 emit setSelection(aSelected);
96 } else if (aFeature) {
97 restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature);
103 void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
105 if (!(theEvent->buttons() & Qt::LeftButton))
108 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
110 blockSelection(true);
111 if (myCurPoint.myIsInitialized) {
113 PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
116 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
118 double aDeltaX = aX - aCurX;
119 double aDeltaY = anY - aCurY;
121 boost::shared_ptr<SketchPlugin_Feature> aSketchFeature = boost::dynamic_pointer_cast<
122 SketchPlugin_Feature>(feature());
123 aSketchFeature->move(aDeltaX, aDeltaY);
124 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
125 ModelAPI_EventCreator::get()->sendUpdated(feature(), anEvent);
129 myCurPoint.setPoint(aPoint);
132 void PartSet_OperationFeatureEdit::mouseReleased(
133 QMouseEvent* theEvent, Handle(V3d_View) theView,
134 const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
135 const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
137 blockSelection(false);
140 void PartSet_OperationFeatureEdit::mouseDoubleClick(
141 QMouseEvent* theEvent, Handle_V3d_View theView,
142 const std::list<ModuleBase_ViewerPrs>& theSelected,
143 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
145 // TODO the functionality is important only for constraint feature. Should be moved in another place
146 if (!theSelected.empty()) {
147 ModuleBase_ViewerPrs aFeaturePrs = theSelected.front();
148 if (!aFeaturePrs.owner().IsNull()) {
149 Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast(
150 aFeaturePrs.owner());
151 if (!anOwner.IsNull() && anOwner->SelectionMode() == AIS_DSM_Text) {
153 double aValue = PartSet_Tools::featureValue(feature(), SketchPlugin_Constraint::VALUE(),
156 ModuleBase_WidgetEditor::editFeatureValue(feature(), SketchPlugin_Constraint::VALUE());
164 void PartSet_OperationFeatureEdit::keyReleased(const int theKey)
166 if (theKey == Qt::Key_Return) {
169 PartSet_OperationSketchBase::keyReleased(theKey);
172 void PartSet_OperationFeatureEdit::startOperation()
174 PartSet_OperationSketchBase::startOperation();
175 emit multiSelectionEnabled(false);
180 void PartSet_OperationFeatureEdit::stopOperation()
182 emit multiSelectionEnabled(true);
184 blockSelection(false, false);
187 void PartSet_OperationFeatureEdit::blockSelection(bool isBlocked, const bool isRestoreSelection)
189 if (myIsBlockedSelection == isBlocked)
192 myIsBlockedSelection = isBlocked;
193 QList<ObjectPtr> aFeatureList;
194 aFeatureList.append(feature());
197 emit setSelection(QList<ObjectPtr>());
198 emit stopSelection(aFeatureList, true);
200 emit stopSelection(aFeatureList, false);
201 if (isRestoreSelection)
202 emit setSelection(aFeatureList);
206 FeaturePtr PartSet_OperationFeatureEdit::createFeature(const bool /*theFlushMessage*/)
208 // do nothing in order to do not create a new feature
212 void PartSet_OperationFeatureEdit::sendFeatures()
214 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
216 FeaturePtr aFeature = feature();
217 ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
219 Events_Loop::loop()->flush(anEvent);