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 theViewer->enableSelection(true);
90 emit featureConstructed(feature(), FM_Deactivation);
92 // If we have selection and prehilighting with shift pressed
93 // Then we have to select all these objects and restart as multi edit operfation
94 //bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
95 //if (aHasShift && !theHighlighted.empty()) {
96 // QList<ObjectPtr> aSelected;
97 // std::list<ModuleBase_ViewerPrs>::const_iterator aIt;
98 // for (aIt = theSelected.cbegin(); aIt != theSelected.cend(); ++aIt)
99 // aSelected.append((*aIt).object());
101 // for (aIt = theHighlighted.cbegin(); aIt != theHighlighted.cend(); ++aIt) {
102 // if (!aSelected.contains((*aIt).object()))
103 // aSelected.append((*aIt).object());
105 // emit setSelection(aSelected);
108 std::string anOperationType =
109 (aSelected.size() > 1) ?
110 PartSet_OperationFeatureEditMulti::Type() : PartSet_OperationFeatureEdit::Type();
111 restartOperation(anOperationType, aFeature);
118 void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer)
120 if (!(theEvent->buttons() & Qt::LeftButton))
122 Handle(V3d_View) aView = theViewer->activeView();
123 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
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 theViewer->enableSelection(true);
157 ModuleBase_ModelWidget* aActiveWgt = 0;
159 aActiveWgt = myPropertyPanel->activeWidget();
160 if(aActiveWgt && aActiveWgt->isViewerSelector()) {
161 // Almost do nothing, all stuff in on PartSet_OperationFeatureBase::mouseReleased
162 PartSet_OperationFeatureBase::mouseReleased(theEvent, theViewer, theSelection);
164 //blockSelection(false);
168 void PartSet_OperationFeatureEdit::mouseDoubleClick(
169 QMouseEvent* theEvent, Handle_V3d_View theView,
170 ModuleBase_ISelection* theSelection)
172 // TODO the functionality is important only for constraint feature. Should be moved in another place
173 QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
174 if (!aSelected.empty()) {
175 ModuleBase_ViewerPrs aFeaturePrs = aSelected.first();
176 if (!aFeaturePrs.owner().IsNull()) {
177 Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast(
178 aFeaturePrs.owner());
179 if (!anOwner.IsNull() && anOwner->SelectionMode() == AIS_DSM_Text) {
181 double aValue = PartSet_Tools::featureValue(feature(), SketchPlugin_Constraint::VALUE(),
184 ModuleBase_WidgetEditor::editFeatureValue(feature(), SketchPlugin_Constraint::VALUE());
192 void PartSet_OperationFeatureEdit::startOperation()
194 PartSet_OperationSketchBase::startOperation();
195 //emit multiSelectionEnabled(false);
200 void PartSet_OperationFeatureEdit::stopOperation()
202 //emit multiSelectionEnabled(true);
204 //blockSelection(false, false);
207 //void PartSet_OperationFeatureEdit::blockSelection(bool isBlocked, const bool isRestoreSelection)
209 // if (myIsBlockedSelection == isBlocked)
212 // myIsBlockedSelection = isBlocked;
213 // QList<ObjectPtr> aFeatureList;
214 // aFeatureList.append(feature());
216 // //if (isBlocked) {
217 // // emit setSelection(QList<ObjectPtr>());
218 // // emit stopSelection(aFeatureList, true);
220 // // emit stopSelection(aFeatureList, false);
221 // // if (isRestoreSelection)
222 // // emit setSelection(aFeatureList);
226 FeaturePtr PartSet_OperationFeatureEdit::createFeature(const bool theFlushMessage,
227 CompositeFeaturePtr theCompositeFeature)
229 // do nothing in order to do not create a new feature
233 void PartSet_OperationFeatureEdit::sendFeatures()
235 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
237 FeaturePtr aFeature = feature();
238 ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
240 Events_Loop::loop()->flush(anEvent);