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>
8 #include <PartSet_OperationFeatureEditMulti.h>
10 #include <SketchPlugin_Constraint.h>
12 #include <ModuleBase_OperationDescription.h>
13 #include <ModuleBase_WidgetEditor.h>
14 #include <ModuleBase_ViewerPrs.h>
15 #include <ModuleBase_IPropertyPanel.h>
16 #include <ModuleBase_ISelection.h>
17 #include <ModuleBase_IViewer.h>
19 #include <ModelAPI_Events.h>
21 #include <SketchPlugin_Feature.h>
22 #include <GeomDataAPI_Point2D.h>
24 #include <ModelAPI_Data.h>
25 #include <ModelAPI_Document.h>
26 #include <ModelAPI_Events.h>
28 #include <Events_Loop.h>
30 #include <SketchPlugin_Line.h>
32 #include <V3d_View.hxx>
33 #include <AIS_DimensionOwner.hxx>
34 #include <AIS_DimensionSelectionMode.hxx>
40 #include <QMouseEvent>
44 PartSet_OperationFeatureEdit::PartSet_OperationFeatureEdit(const QString& theId,
46 CompositeFeaturePtr theFeature)
47 : PartSet_OperationFeatureBase(theId, theParent, theFeature),
48 myIsBlockedSelection(false)
53 PartSet_OperationFeatureEdit::~PartSet_OperationFeatureEdit()
58 void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection)
60 ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
61 if(aActiveWgt && aActiveWgt->isViewerSelector()) {
62 // Almost do nothing, all stuff in on PartSet_OperationFeatureBase::mouseReleased
63 PartSet_OperationFeatureBase::mousePressed(theEvent, theViewer, theSelection);
66 QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
67 QList<ModuleBase_ViewerPrs> aHighlighted = theSelection->getHighlighted();
68 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
69 if (aHasShift && !aHighlighted.empty()) {
70 foreach (ModuleBase_ViewerPrs aPrs, aHighlighted) {
71 aSelected.append(aPrs);
75 if (!aSelected.empty()) {
76 aObject = aSelected.first().object();
78 if (!aHighlighted.empty())
79 aObject = aHighlighted.first().object();
81 //if (!theHighlighted.empty())
82 // aObject = theHighlighted.front().object();
83 //if (!aObject && !theSelected.empty()) // changed for a constrain
84 // aObject = theSelected.front().object();
86 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
87 if (!aFeature || aFeature != feature() || (aSelected.size() > 1)) {
89 emit featureConstructed(feature(), FM_Deactivation);
91 // If we have selection and prehilighting with shift pressed
92 // Then we have to select all these objects and restart as multi edit operfation
93 //bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
94 //if (aHasShift && !theHighlighted.empty()) {
95 // QList<ObjectPtr> aSelected;
96 // std::list<ModuleBase_ViewerPrs>::const_iterator aIt;
97 // for (aIt = theSelected.cbegin(); aIt != theSelected.cend(); ++aIt)
98 // aSelected.append((*aIt).object());
100 // for (aIt = theHighlighted.cbegin(); aIt != theHighlighted.cend(); ++aIt) {
101 // if (!aSelected.contains((*aIt).object()))
102 // aSelected.append((*aIt).object());
104 // emit setSelection(aSelected);
107 std::string anOperationType =
108 (aSelected.size() > 1) ?
109 PartSet_OperationFeatureEditMulti::Type() : PartSet_OperationFeatureEdit::Type();
110 restartOperation(anOperationType, aFeature);
117 void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer)
119 if (!(theEvent->buttons() & Qt::LeftButton))
121 Handle(V3d_View) aView = theViewer->activeView();
122 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
124 if (theViewer->isSelectionEnabled())
125 theViewer->enableSelection(false);
127 //blockSelection(true);
128 if (myCurPoint.myIsInitialized) {
130 PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), aView, aCurX, aCurY);
133 PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
135 double aDeltaX = aX - aCurX;
136 double aDeltaY = anY - aCurY;
138 boost::shared_ptr<SketchPlugin_Feature> aSketchFeature = boost::dynamic_pointer_cast<
139 SketchPlugin_Feature>(feature());
140 // MPV: added condition because it could be external edge of some object, not sketch
141 if (aSketchFeature && aSketchFeature->sketch() == sketch().get()) {
142 aSketchFeature->move(aDeltaX, aDeltaY);
143 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
144 ModelAPI_EventCreator::get()->sendUpdated(feature(), anEvent);
149 myCurPoint.setPoint(aPoint);
152 void PartSet_OperationFeatureEdit::mouseReleased(
153 QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
154 ModuleBase_ISelection* theSelection)
156 ModuleBase_ModelWidget* aActiveWgt = 0;
158 aActiveWgt = myPropertyPanel->activeWidget();
159 if(aActiveWgt && aActiveWgt->isViewerSelector()) {
160 // Almost do nothing, all stuff in on PartSet_OperationFeatureBase::mouseReleased
161 PartSet_OperationFeatureBase::mouseReleased(theEvent, theViewer, theSelection);
163 //blockSelection(false);
165 if (!theViewer->isSelectionEnabled())
166 theViewer->enableSelection(true);
169 void PartSet_OperationFeatureEdit::mouseDoubleClick(
170 QMouseEvent* theEvent, Handle_V3d_View theView,
171 ModuleBase_ISelection* theSelection)
173 // TODO the functionality is important only for constraint feature. Should be moved in another place
174 QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
175 if (!aSelected.empty()) {
176 ModuleBase_ViewerPrs aFeaturePrs = aSelected.first();
177 if (!aFeaturePrs.owner().IsNull()) {
178 Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast(
179 aFeaturePrs.owner());
180 if (!anOwner.IsNull() && anOwner->SelectionMode() == AIS_DSM_Text) {
182 double aValue = PartSet_Tools::featureValue(feature(), SketchPlugin_Constraint::VALUE(),
185 ModuleBase_WidgetEditor::editFeatureValue(feature(), SketchPlugin_Constraint::VALUE());
193 void PartSet_OperationFeatureEdit::startOperation()
195 PartSet_OperationSketchBase::startOperation();
196 //emit multiSelectionEnabled(false);
201 void PartSet_OperationFeatureEdit::stopOperation()
203 //emit multiSelectionEnabled(true);
205 //blockSelection(false, false);
208 //void PartSet_OperationFeatureEdit::blockSelection(bool isBlocked, const bool isRestoreSelection)
210 // if (myIsBlockedSelection == isBlocked)
213 // myIsBlockedSelection = isBlocked;
214 // QList<ObjectPtr> aFeatureList;
215 // aFeatureList.append(feature());
217 // //if (isBlocked) {
218 // // emit setSelection(QList<ObjectPtr>());
219 // // emit stopSelection(aFeatureList, true);
221 // // emit stopSelection(aFeatureList, false);
222 // // if (isRestoreSelection)
223 // // emit setSelection(aFeatureList);
227 FeaturePtr PartSet_OperationFeatureEdit::createFeature(const bool theFlushMessage,
228 CompositeFeaturePtr theCompositeFeature)
230 // do nothing in order to do not create a new feature
234 void PartSet_OperationFeatureEdit::sendFeatures()
236 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
238 FeaturePtr aFeature = feature();
239 ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
241 Events_Loop::loop()->flush(anEvent);