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>
14 #include <ModuleBase_IPropertyPanel.h>
16 #include <ModelAPI_Events.h>
18 #include <SketchPlugin_Feature.h>
19 #include <GeomDataAPI_Point2D.h>
21 #include <ModelAPI_Data.h>
22 #include <ModelAPI_Document.h>
23 #include <ModelAPI_Events.h>
25 #include <Events_Loop.h>
27 #include <SketchPlugin_Line.h>
29 #include <V3d_View.hxx>
30 #include <AIS_DimensionOwner.hxx>
31 #include <AIS_DimensionSelectionMode.hxx>
37 #include <QMouseEvent>
41 PartSet_OperationFeatureEdit::PartSet_OperationFeatureEdit(const QString& theId,
43 FeaturePtr theFeature)
44 : PartSet_OperationFeatureBase(theId, theParent, theFeature),
45 myIsBlockedSelection(false)
50 PartSet_OperationFeatureEdit::~PartSet_OperationFeatureEdit()
55 void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView,
56 const std::list<ModuleBase_ViewerPrs>& theSelected,
57 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
59 ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
60 if(aActiveWgt && aActiveWgt->isViewerSelector()) {
61 // Almost do nothing, all stuff in on PartSet_OperationFeatureBase::mouseReleased
62 PartSet_OperationFeatureBase::mousePressed(theEvent, theView, theSelected, theHighlighted);
66 if (!theHighlighted.empty())
67 aObject = theHighlighted.front().object();
68 if (!aObject && !theSelected.empty()) // changed for a constrain
69 aObject = theSelected.front().object();
71 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
72 if (!aFeature || aFeature != feature()) {
74 emit featureConstructed(feature(), FM_Deactivation);
76 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
77 if (aHasShift && !theHighlighted.empty()) {
78 QList<ObjectPtr> aSelected;
79 std::list<ModuleBase_ViewerPrs>::const_iterator aIt;
80 for (aIt = theSelected.cbegin(); aIt != theSelected.cend(); ++aIt)
81 aSelected.append((*aIt).object());
82 /*for (aIt = theHighlighted.cbegin(); aIt != theHighlighted.cend(); ++aIt) {
83 if (!aSelected.contains((*aIt).object()))
84 aSelected.append((*aIt).object());
86 //aSelected.push_back(feature());
87 //aSelected.push_back(theHighlighted.front().object());
88 emit setSelection(aSelected);
89 } else if (aFeature) {
90 restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature);
96 void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
98 if (!(theEvent->buttons() & Qt::LeftButton))
101 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
103 blockSelection(true);
104 if (myCurPoint.myIsInitialized) {
106 PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
109 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
111 double aDeltaX = aX - aCurX;
112 double aDeltaY = anY - aCurY;
114 boost::shared_ptr<SketchPlugin_Feature> aSketchFeature = boost::dynamic_pointer_cast<
115 SketchPlugin_Feature>(feature());
116 aSketchFeature->move(aDeltaX, aDeltaY);
117 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
118 ModelAPI_EventCreator::get()->sendUpdated(feature(), anEvent);
122 myCurPoint.setPoint(aPoint);
125 void PartSet_OperationFeatureEdit::mouseReleased(
126 QMouseEvent* theEvent, Handle(V3d_View) theView,
127 const std::list<ModuleBase_ViewerPrs>& theSelected,
128 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
130 ModuleBase_ModelWidget* aActiveWgt = 0;
132 aActiveWgt = myPropertyPanel->activeWidget();
133 if(aActiveWgt && aActiveWgt->isViewerSelector()) {
134 // Almost do nothing, all stuff in on PartSet_OperationFeatureBase::mouseReleased
135 PartSet_OperationFeatureBase::mouseReleased(theEvent, theView, theSelected, theHighlighted);
137 blockSelection(false);
141 void PartSet_OperationFeatureEdit::mouseDoubleClick(
142 QMouseEvent* theEvent, Handle_V3d_View theView,
143 const std::list<ModuleBase_ViewerPrs>& theSelected,
144 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
146 // TODO the functionality is important only for constraint feature. Should be moved in another place
147 if (!theSelected.empty()) {
148 ModuleBase_ViewerPrs aFeaturePrs = theSelected.front();
149 if (!aFeaturePrs.owner().IsNull()) {
150 Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast(
151 aFeaturePrs.owner());
152 if (!anOwner.IsNull() && anOwner->SelectionMode() == AIS_DSM_Text) {
154 double aValue = PartSet_Tools::featureValue(feature(), SketchPlugin_Constraint::VALUE(),
157 ModuleBase_WidgetEditor::editFeatureValue(feature(), SketchPlugin_Constraint::VALUE());
165 void PartSet_OperationFeatureEdit::startOperation()
167 PartSet_OperationSketchBase::startOperation();
168 emit multiSelectionEnabled(false);
173 void PartSet_OperationFeatureEdit::stopOperation()
175 emit multiSelectionEnabled(true);
177 blockSelection(false, false);
180 void PartSet_OperationFeatureEdit::blockSelection(bool isBlocked, const bool isRestoreSelection)
182 if (myIsBlockedSelection == isBlocked)
185 myIsBlockedSelection = isBlocked;
186 QList<ObjectPtr> aFeatureList;
187 aFeatureList.append(feature());
190 emit setSelection(QList<ObjectPtr>());
191 emit stopSelection(aFeatureList, true);
193 emit stopSelection(aFeatureList, false);
194 if (isRestoreSelection)
195 emit setSelection(aFeatureList);
199 FeaturePtr PartSet_OperationFeatureEdit::createFeature(const bool /*theFlushMessage*/)
201 // do nothing in order to do not create a new feature
205 void PartSet_OperationFeatureEdit::sendFeatures()
207 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
209 FeaturePtr aFeature = feature();
210 ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
212 Events_Loop::loop()->flush(anEvent);