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 void PartSet_OperationFeatureEditMulti::initSelection(
51 const std::list<ModuleBase_ViewerPrs>& theSelected,
52 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
54 if (!theHighlighted.empty()) {
55 // if there is highlighted object, we check whether it is in the list of selected objects
56 // in that case this object is a handle of the moved lines. If there no such object in the selection,
57 // the hightlighted object should moved and the selection is skipped. The skipped selection will be
58 // deselected in the viewer by blockSelection signal in the startOperation method.
59 bool isSelected = false;
60 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = theSelected.begin(), aLast = theSelected
62 for (; anIt != aLast && !isSelected; anIt++) {
63 isSelected = ModelAPI_Feature::feature((*anIt).object()) == feature();
66 myFeatures = theHighlighted;
68 myFeatures = theSelected;
70 myFeatures = theSelected;
73 FeaturePtr PartSet_OperationFeatureEditMulti::sketch() const
78 void PartSet_OperationFeatureEditMulti::mousePressed(
79 QMouseEvent* theEvent, Handle(V3d_View) theView,
80 const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
81 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
85 void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
87 if (!(theEvent->buttons() & Qt::LeftButton))
90 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
92 /* blockSelection(true);
93 if (myCurPoint.myIsInitialized) {
95 PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
98 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
100 double aDeltaX = aX - aCurX;
101 double aDeltaY = anY - aCurY;
103 boost::shared_ptr<SketchPlugin_Feature> aSketchFeature = boost::dynamic_pointer_cast<
104 SketchPlugin_Feature>(sketch());
105 aSketchFeature->move(aDeltaX, aDeltaY);
107 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures
109 for (; anIt != aLast; anIt++) {
110 ObjectPtr aObject = (*anIt).object();
111 if (!aObject || aObject == feature())
113 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
115 aSketchFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
117 aSketchFeature->move(aDeltaX, aDeltaY);
123 myCurPoint.setPoint(aPoint);
127 void PartSet_OperationFeatureEditMulti::mouseReleased(
128 QMouseEvent* theEvent, Handle(V3d_View) theView,
129 const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
130 const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
133 std::list<ModuleBase_ViewerPrs> aFeatures = myFeatures;
134 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = aFeatures.begin(), aLast =
136 for (; anIt != aLast; anIt++) {
137 ObjectPtr aFeature = (*anIt).object();
139 emit featureConstructed(aFeature, FM_Deactivation);
145 void PartSet_OperationFeatureEditMulti::startOperation()
147 PartSet_OperationSketchBase::startOperation();
148 emit multiSelectionEnabled(false);
150 blockSelection(true);
155 void PartSet_OperationFeatureEditMulti::stopOperation()
157 emit multiSelectionEnabled(true);
159 blockSelection(false, true);
164 void PartSet_OperationFeatureEditMulti::blockSelection(bool isBlocked,
165 const bool isRestoreSelection)
167 if (myIsBlockedSelection == isBlocked)
170 myIsBlockedSelection = isBlocked;
171 QList<ObjectPtr> aFeatureList;
172 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast =
174 /*for(; anIt != aLast; anIt++)
175 aFeatureList.append((*anIt).feature());*/
177 emit setSelection(QList<ObjectPtr>());
178 emit stopSelection(aFeatureList, true);
180 emit stopSelection(aFeatureList, false);
181 if (isRestoreSelection) {
182 emit setSelection(aFeatureList);
187 void PartSet_OperationFeatureEditMulti::sendFeatures()
189 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
191 std::list<FeaturePtr> aFeatures;
192 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast =
194 for (; anIt != aLast; anIt++) {
195 ObjectPtr aFeature = (*anIt).object();
199 ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
201 Events_Loop::loop()->flush(anEvent);