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>
27 #include <QMouseEvent>
32 //using namespace std;
34 PartSet_OperationFeatureEditMulti::PartSet_OperationFeatureEditMulti(const QString& theId,
36 CompositeFeaturePtr theFeature)
37 : PartSet_OperationSketchBase(theId, theParent),
39 myIsBlockedSelection(false)
44 PartSet_OperationFeatureEditMulti::~PartSet_OperationFeatureEditMulti()
49 bool isContains(const std::list<ModuleBase_ViewerPrs>& theSelected, const ModuleBase_ViewerPrs& thePrs)
51 std::list<ModuleBase_ViewerPrs>::const_iterator anIt;
52 for (anIt = theSelected.cbegin(); anIt != theSelected.cend(); ++anIt) {
53 if ((*anIt).object() == thePrs.object())
60 void PartSet_OperationFeatureEditMulti::initSelection(
61 const std::list<ModuleBase_ViewerPrs>& theSelected,
62 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
64 //if (!theHighlighted.empty()) {
65 // // if there is highlighted object, we check whether it is in the list of selected objects
66 // // in that case this object is a handle of the moved lines. If there no such object in the selection,
67 // // the hightlighted object should moved and the selection is skipped. The skipped selection will be
68 // // deselected in the viewer by blockSelection signal in the startOperation method.
69 // bool isSelected = false;
70 // std::list<ModuleBase_ViewerPrs>::const_iterator anIt = theSelected.begin(),
71 // aLast = theSelected.end();
72 // for (; anIt != aLast && !isSelected; anIt++) {
73 // isSelected = ModelAPI_Feature::feature((*anIt).object()) == feature();
76 // myFeatures = theHighlighted;
78 // myFeatures = theSelected;
80 myFeatures = theSelected;
81 // add highlighted elements if they are not selected
82 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = theHighlighted.cbegin();
83 for ( ; anIt != theHighlighted.cend(); ++anIt) {
84 if (!isContains(myFeatures, (*anIt)))
85 myFeatures.push_back(*anIt);
87 // Remove current feature if it is in the list (it will be moved as main feature)
88 std::list<ModuleBase_ViewerPrs>::iterator anEraseIt = myFeatures.begin();
89 for ( ; anEraseIt != myFeatures.end(); ++anEraseIt) {
90 if (ModelAPI_Feature::feature((*anEraseIt).object()) == feature()) {
91 myFeatures.erase(anEraseIt);
97 CompositeFeaturePtr PartSet_OperationFeatureEditMulti::sketch() const
102 void PartSet_OperationFeatureEditMulti::mousePressed(
103 QMouseEvent* theEvent, Handle(V3d_View) theView,
104 const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
105 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
109 void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
111 if (!(theEvent->buttons() & Qt::LeftButton))
114 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
116 blockSelection(true);
117 if (myCurPoint.myIsInitialized) {
119 PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
122 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, 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 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(),
132 aLast = myFeatures.end();
133 for (; anIt != aLast; anIt++) {
134 ObjectPtr aObject = (*anIt).object();
135 if (!aObject || aObject == feature())
137 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
139 aSketchFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
141 aSketchFeature->move(aDeltaX, aDeltaY);
147 myCurPoint.setPoint(aPoint);
150 void PartSet_OperationFeatureEditMulti::mouseReleased(
151 QMouseEvent* theEvent, Handle(V3d_View) theView,
152 const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
153 const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
156 std::list<ModuleBase_ViewerPrs> aFeatures = myFeatures;
157 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = aFeatures.begin(), aLast =
159 for (; anIt != aLast; anIt++) {
160 ObjectPtr aFeature = (*anIt).object();
162 emit featureConstructed(aFeature, FM_Deactivation);
168 void PartSet_OperationFeatureEditMulti::startOperation()
170 PartSet_OperationSketchBase::startOperation();
171 emit multiSelectionEnabled(false);
173 blockSelection(true);
178 void PartSet_OperationFeatureEditMulti::stopOperation()
180 emit multiSelectionEnabled(true);
182 blockSelection(false, true);
187 void PartSet_OperationFeatureEditMulti::blockSelection(bool isBlocked,
188 const bool isRestoreSelection)
190 if (myIsBlockedSelection == isBlocked)
193 myIsBlockedSelection = isBlocked;
194 QList<ObjectPtr> aFeatureList;
195 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast =
197 /*for(; anIt != aLast; anIt++)
198 aFeatureList.append((*anIt).feature());*/
200 emit setSelection(QList<ObjectPtr>());
201 emit stopSelection(aFeatureList, true);
203 emit stopSelection(aFeatureList, false);
204 if (isRestoreSelection) {
205 emit setSelection(aFeatureList);
210 void PartSet_OperationFeatureEditMulti::sendFeatures()
212 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
214 std::list<FeaturePtr> aFeatures;
215 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast =
217 for (; anIt != aLast; anIt++) {
218 ObjectPtr aFeature = (*anIt).object();
222 ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
224 Events_Loop::loop()->flush(anEvent);