1 // File: PartSet_OperationFeatureEditMulti.h
2 // Created: 05 May 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_OperationFeatureEditMulti.h>
6 #include <PartSet_Tools.h>
7 #include <PartSet_OperationSketch.h>
9 #include <ModuleBase_OperationDescription.h>
10 #include <ModuleBase_ViewerPrs.h>
11 #include <ModuleBase_IViewer.h>
12 #include <ModuleBase_ISelection.h>
14 #include <ModelAPI_Events.h>
16 #include <SketchPlugin_Feature.h>
17 #include <GeomDataAPI_Point2D.h>
18 #include <ModelAPI_Data.h>
19 #include <ModelAPI_Document.h>
21 #include <ModelAPI_Events.h>
23 #include <Events_Loop.h>
25 #include <SketchPlugin_Line.h>
27 #include <V3d_View.hxx>
29 #include <QMouseEvent>
34 //using namespace std;
36 PartSet_OperationFeatureEditMulti::PartSet_OperationFeatureEditMulti(const QString& theId,
38 CompositeFeaturePtr theFeature)
39 : PartSet_OperationSketchBase(theId, theParent),
41 myIsBlockedSelection(false)
46 PartSet_OperationFeatureEditMulti::~PartSet_OperationFeatureEditMulti()
51 bool isContains(const QList<ModuleBase_ViewerPrs>& theSelected, const ModuleBase_ViewerPrs& thePrs)
53 foreach (ModuleBase_ViewerPrs aPrs, theSelected) {
54 if (aPrs.object() == thePrs.object())
61 void PartSet_OperationFeatureEditMulti::initSelection(ModuleBase_ISelection* theSelection)
63 //if (!theHighlighted.empty()) {
64 // // if there is highlighted object, we check whether it is in the list of selected objects
65 // // in that case this object is a handle of the moved lines. If there no such object in the selection,
66 // // the hightlighted object should moved and the selection is skipped. The skipped selection will be
67 // // deselected in the viewer by blockSelection signal in the startOperation method.
68 // bool isSelected = false;
69 // std::list<ModuleBase_ViewerPrs>::const_iterator anIt = theSelected.begin(),
70 // aLast = theSelected.end();
71 // for (; anIt != aLast && !isSelected; anIt++) {
72 // isSelected = ModelAPI_Feature::feature((*anIt).object()) == feature();
75 // myFeatures = theHighlighted;
77 // myFeatures = theSelected;
79 myFeatures = theSelection->getSelected();
80 QList<ModuleBase_ViewerPrs> aHighlighted = theSelection->getHighlighted();
81 // add highlighted elements if they are not selected
82 foreach (ModuleBase_ViewerPrs aPrs, aHighlighted) {
83 if (!isContains(myFeatures, aPrs))
84 myFeatures.append(aPrs);
86 // Remove current feature if it is in the list (it will be moved as main feature)
87 foreach (ModuleBase_ViewerPrs aPrs, myFeatures) {
88 FeaturePtr aF = ModelAPI_Feature::feature(aPrs.object());
89 if (ModelAPI_Feature::feature(aPrs.object()) == feature()) {
90 myFeatures.removeOne(aPrs);
96 CompositeFeaturePtr PartSet_OperationFeatureEditMulti::sketch() const
101 //void PartSet_OperationFeatureEditMulti::mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection)
105 void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer)
107 if (!(theEvent->buttons() & Qt::LeftButton))
110 if (theViewer->isSelectionEnabled())
111 theViewer->enableSelection(false);
113 Handle(V3d_View) aView = theViewer->activeView();
114 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
116 //blockSelection(true);
117 if (myCurPoint.myIsInitialized) {
119 PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), aView, aCurX, aCurY);
122 PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
124 double aDeltaX = aX - aCurX;
125 double aDeltaY = anY - aCurY;
127 boost::shared_ptr<SketchPlugin_Feature> aSketchFeature = boost::dynamic_pointer_cast<
128 SketchPlugin_Feature>(feature());
129 aSketchFeature->move(aDeltaX, aDeltaY);
131 foreach (ModuleBase_ViewerPrs aPrs, myFeatures) {
132 ObjectPtr aObject = aPrs.object();
133 if (!aObject || aObject == feature())
135 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
137 aSketchFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
139 aSketchFeature->move(aDeltaX, aDeltaY);
145 myCurPoint.setPoint(aPoint);
148 void PartSet_OperationFeatureEditMulti::mouseReleased(
149 QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
150 ModuleBase_ISelection* theSelection)
152 theViewer->enableSelection(true);
154 foreach (ModuleBase_ViewerPrs aPrs, myFeatures) {
155 ObjectPtr aFeature = aPrs.object();
157 emit featureConstructed(aFeature, FM_Deactivation);
163 void PartSet_OperationFeatureEditMulti::startOperation()
165 PartSet_OperationSketchBase::startOperation();
166 //emit multiSelectionEnabled(false);
168 //blockSelection(true);
173 void PartSet_OperationFeatureEditMulti::stopOperation()
175 //emit multiSelectionEnabled(true);
177 //blockSelection(false, true);
182 //void PartSet_OperationFeatureEditMulti::blockSelection(bool isBlocked,
183 // const bool isRestoreSelection)
185 // if (myIsBlockedSelection == isBlocked)
188 // myIsBlockedSelection = isBlocked;
189 // QList<ObjectPtr> aFeatureList;
190 //// std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast =
191 //// myFeatures.end();
192 // /*for(; anIt != aLast; anIt++)
193 // aFeatureList.append((*anIt).feature());*/
194 // //if (isBlocked) {
195 // // emit setSelection(QList<ObjectPtr>());
196 // // emit stopSelection(aFeatureList, true);
198 // // emit stopSelection(aFeatureList, false);
199 // // if (isRestoreSelection) {
200 // // emit setSelection(aFeatureList);
205 void PartSet_OperationFeatureEditMulti::sendFeatures()
207 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
209 foreach (ModuleBase_ViewerPrs aPrs, myFeatures) {
210 ObjectPtr aFeature = aPrs.object();
214 ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
216 Events_Loop::loop()->flush(anEvent);