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,
42 FeaturePtr theFeature)
43 : PartSet_OperationFeatureBase(theId, theParent, theFeature),
44 myIsBlockedSelection(false)
48 PartSet_OperationFeatureEdit::~PartSet_OperationFeatureEdit()
52 void PartSet_OperationFeatureEdit::initFeature(FeaturePtr theFeature)
54 setEditingFeature(theFeature);
57 void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView,
58 const std::list<ModuleBase_ViewerPrs>& theSelected,
59 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
61 if(myActiveWidget && myActiveWidget->isViewerSelector()) {
62 // Almost do nothing, all stuff in on PartSet_OperationFeatureBase::mouseReleased
63 PartSet_OperationFeatureBase::mousePressed(theEvent, theView, theSelected, theHighlighted);
67 if (!theHighlighted.empty())
68 aObject = theHighlighted.front().object();
69 if (!aObject && !theSelected.empty()) // changed for a constrain
70 aObject = theSelected.front().object();
72 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
73 if (!aFeature || aFeature != feature()) {
75 emit featureConstructed(feature(), FM_Deactivation);
77 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
78 if (aHasShift && !theHighlighted.empty()) {
79 QList<ObjectPtr> aSelected;
80 std::list<ModuleBase_ViewerPrs>::const_iterator aIt;
81 for (aIt = theSelected.cbegin(); aIt != theSelected.cend(); ++aIt)
82 aSelected.append((*aIt).object());
83 /*for (aIt = theHighlighted.cbegin(); aIt != theHighlighted.cend(); ++aIt) {
84 if (!aSelected.contains((*aIt).object()))
85 aSelected.append((*aIt).object());
87 //aSelected.push_back(feature());
88 //aSelected.push_back(theHighlighted.front().object());
89 emit setSelection(aSelected);
90 } else if (aFeature) {
91 restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature);
97 void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
99 if (!(theEvent->buttons() & Qt::LeftButton))
102 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
104 blockSelection(true);
105 if (myCurPoint.myIsInitialized) {
107 PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
110 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
112 double aDeltaX = aX - aCurX;
113 double aDeltaY = anY - aCurY;
115 boost::shared_ptr<SketchPlugin_Feature> aSketchFeature = boost::dynamic_pointer_cast<
116 SketchPlugin_Feature>(feature());
117 aSketchFeature->move(aDeltaX, aDeltaY);
118 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
119 ModelAPI_EventCreator::get()->sendUpdated(feature(), anEvent);
123 myCurPoint.setPoint(aPoint);
126 void PartSet_OperationFeatureEdit::mouseReleased(
127 QMouseEvent* theEvent, Handle(V3d_View) theView,
128 const std::list<ModuleBase_ViewerPrs>& theSelected,
129 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
131 if(myActiveWidget && myActiveWidget->isViewerSelector()) {
132 // Almost do nothing, all stuff in on PartSet_OperationFeatureBase::mouseReleased
133 PartSet_OperationFeatureBase::mouseReleased(theEvent, theView, theSelected, theHighlighted);
135 blockSelection(false);
139 void PartSet_OperationFeatureEdit::mouseDoubleClick(
140 QMouseEvent* theEvent, Handle_V3d_View theView,
141 const std::list<ModuleBase_ViewerPrs>& theSelected,
142 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
144 // TODO the functionality is important only for constraint feature. Should be moved in another place
145 if (!theSelected.empty()) {
146 ModuleBase_ViewerPrs aFeaturePrs = theSelected.front();
147 if (!aFeaturePrs.owner().IsNull()) {
148 Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast(
149 aFeaturePrs.owner());
150 if (!anOwner.IsNull() && anOwner->SelectionMode() == AIS_DSM_Text) {
152 double aValue = PartSet_Tools::featureValue(feature(), SketchPlugin_Constraint::VALUE(),
155 ModuleBase_WidgetEditor::editFeatureValue(feature(), SketchPlugin_Constraint::VALUE());
163 void PartSet_OperationFeatureEdit::startOperation()
165 PartSet_OperationSketchBase::startOperation();
166 emit multiSelectionEnabled(false);
171 void PartSet_OperationFeatureEdit::stopOperation()
173 emit multiSelectionEnabled(true);
175 blockSelection(false, false);
178 void PartSet_OperationFeatureEdit::blockSelection(bool isBlocked, const bool isRestoreSelection)
180 if (myIsBlockedSelection == isBlocked)
183 myIsBlockedSelection = isBlocked;
184 QList<ObjectPtr> aFeatureList;
185 aFeatureList.append(feature());
188 emit setSelection(QList<ObjectPtr>());
189 emit stopSelection(aFeatureList, true);
191 emit stopSelection(aFeatureList, false);
192 if (isRestoreSelection)
193 emit setSelection(aFeatureList);
197 FeaturePtr PartSet_OperationFeatureEdit::createFeature(const bool /*theFlushMessage*/)
199 // do nothing in order to do not create a new feature
203 void PartSet_OperationFeatureEdit::sendFeatures()
205 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
207 FeaturePtr aFeature = feature();
208 ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
210 Events_Loop::loop()->flush(anEvent);