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>
12 #include <ModelAPI_Events.h>
14 #include <SketchPlugin_Feature.h>
15 #include <GeomDataAPI_Point2D.h>
16 #include <ModelAPI_Data.h>
17 #include <ModelAPI_Document.h>
19 #include <ModelAPI_Events.h>
21 #include <Events_Loop.h>
23 #include <SketchPlugin_Line.h>
25 #include <V3d_View.hxx>
31 #include <QMouseEvent>
35 PartSet_OperationFeatureEditMulti::PartSet_OperationFeatureEditMulti(const QString& theId,
37 FeaturePtr theFeature)
38 : PartSet_OperationSketchBase(theId, theParent),
40 myIsBlockedSelection(false)
45 PartSet_OperationFeatureEditMulti::~PartSet_OperationFeatureEditMulti()
50 bool isContains(const std::list<ModuleBase_ViewerPrs>& theSelected, const ModuleBase_ViewerPrs& thePrs)
52 std::list<ModuleBase_ViewerPrs>::const_iterator anIt;
53 for (anIt = theSelected.cbegin(); anIt != theSelected.cend(); ++anIt) {
54 if ((*anIt).object() == thePrs.object())
61 void PartSet_OperationFeatureEditMulti::initSelection(
62 const std::list<ModuleBase_ViewerPrs>& theSelected,
63 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
65 //if (!theHighlighted.empty()) {
66 // // if there is highlighted object, we check whether it is in the list of selected objects
67 // // in that case this object is a handle of the moved lines. If there no such object in the selection,
68 // // the hightlighted object should moved and the selection is skipped. The skipped selection will be
69 // // deselected in the viewer by blockSelection signal in the startOperation method.
70 // bool isSelected = false;
71 // std::list<ModuleBase_ViewerPrs>::const_iterator anIt = theSelected.begin(),
72 // aLast = theSelected.end();
73 // for (; anIt != aLast && !isSelected; anIt++) {
74 // isSelected = ModelAPI_Feature::feature((*anIt).object()) == feature();
77 // myFeatures = theHighlighted;
79 // myFeatures = theSelected;
81 myFeatures = theSelected;
82 // add highlighted elements if they are not selected
83 std::list<ModuleBase_ViewerPrs>::const_iterator anIt;
84 for (anIt = theHighlighted.cbegin(); anIt != theHighlighted.cend(); ++anIt) {
85 if (!isContains(myFeatures, (*anIt)))
86 myFeatures.push_back(*anIt);
88 // Remove current feature if it is in the list (it will be moved as main feature)
89 FeaturePtr aFea = feature();
90 for (anIt = myFeatures.cbegin(); anIt != myFeatures.cend(); ++anIt) {
91 FeaturePtr aF = ModelAPI_Feature::feature((*anIt).object());
92 if (ModelAPI_Feature::feature((*anIt).object()) == feature()) {
93 myFeatures.erase(anIt);
99 FeaturePtr PartSet_OperationFeatureEditMulti::sketch() const
104 void PartSet_OperationFeatureEditMulti::mousePressed(
105 QMouseEvent* theEvent, Handle(V3d_View) theView,
106 const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
107 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
111 void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
113 if (!(theEvent->buttons() & Qt::LeftButton))
116 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
118 blockSelection(true);
119 if (myCurPoint.myIsInitialized) {
121 PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
124 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
126 double aDeltaX = aX - aCurX;
127 double aDeltaY = anY - aCurY;
129 boost::shared_ptr<SketchPlugin_Feature> aSketchFeature = boost::dynamic_pointer_cast<
130 SketchPlugin_Feature>(feature());
131 aSketchFeature->move(aDeltaX, aDeltaY);
133 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(),
134 aLast = myFeatures.end();
135 for (; anIt != aLast; anIt++) {
136 ObjectPtr aObject = (*anIt).object();
137 if (!aObject || aObject == feature())
139 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
141 aSketchFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
143 aSketchFeature->move(aDeltaX, aDeltaY);
149 myCurPoint.setPoint(aPoint);
152 void PartSet_OperationFeatureEditMulti::mouseReleased(
153 QMouseEvent* theEvent, Handle(V3d_View) theView,
154 const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
155 const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
158 std::list<ModuleBase_ViewerPrs> aFeatures = myFeatures;
159 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = aFeatures.begin(), aLast =
161 for (; anIt != aLast; anIt++) {
162 ObjectPtr aFeature = (*anIt).object();
164 emit featureConstructed(aFeature, FM_Deactivation);
170 void PartSet_OperationFeatureEditMulti::startOperation()
172 PartSet_OperationSketchBase::startOperation();
173 emit multiSelectionEnabled(false);
175 blockSelection(true);
180 void PartSet_OperationFeatureEditMulti::stopOperation()
182 emit multiSelectionEnabled(true);
184 blockSelection(false, true);
189 void PartSet_OperationFeatureEditMulti::blockSelection(bool isBlocked,
190 const bool isRestoreSelection)
192 if (myIsBlockedSelection == isBlocked)
195 myIsBlockedSelection = isBlocked;
196 QList<ObjectPtr> aFeatureList;
197 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast =
199 /*for(; anIt != aLast; anIt++)
200 aFeatureList.append((*anIt).feature());*/
202 emit setSelection(QList<ObjectPtr>());
203 emit stopSelection(aFeatureList, true);
205 emit stopSelection(aFeatureList, false);
206 if (isRestoreSelection) {
207 emit setSelection(aFeatureList);
212 void PartSet_OperationFeatureEditMulti::sendFeatures()
214 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
216 std::list<FeaturePtr> aFeatures;
217 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast =
219 for (; anIt != aLast; anIt++) {
220 ObjectPtr aFeature = (*anIt).object();
224 ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
226 Events_Loop::loop()->flush(anEvent);