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), mySketch(theFeature), myIsBlockedSelection(false)
42 PartSet_OperationFeatureEditMulti::~PartSet_OperationFeatureEditMulti()
46 bool PartSet_OperationFeatureEditMulti::isGranted(ModuleBase_IOperation* theOperation) const
48 return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
51 void PartSet_OperationFeatureEditMulti::initSelection(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.end();
62 /*for (; anIt != aLast && !isSelected; anIt++) {
63 isSelected = (*anIt).feature() == feature();
66 myFeatures = theHighlighted;
68 myFeatures = theSelected;
71 myFeatures = theSelected;
74 void PartSet_OperationFeatureEditMulti::initFeature(FeaturePtr theFeature)
76 setEditingFeature(theFeature);
79 FeaturePtr PartSet_OperationFeatureEditMulti::sketch() const
84 void PartSet_OperationFeatureEditMulti::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView,
85 const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
86 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
90 void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
92 if (!(theEvent->buttons() & Qt::LeftButton))
95 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
98 if (myCurPoint.myIsInitialized) {
100 PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
103 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
105 double aDeltaX = aX - aCurX;
106 double aDeltaY = anY - aCurY;
108 boost::shared_ptr<SketchPlugin_Feature> aSketchFeature =
109 boost::dynamic_pointer_cast<SketchPlugin_Feature>(feature());
110 aSketchFeature->move(aDeltaX, aDeltaY);
112 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();
114 /*for (; anIt != aLast; anIt++) {
115 FeaturePtr aFeature = (*anIt).feature();
116 if (!aFeature || aFeature == feature())
118 aSketchFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
119 aSketchFeature->move(aDeltaX, aDeltaY);
124 myCurPoint.setPoint(aPoint);
127 void PartSet_OperationFeatureEditMulti::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
128 const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
129 const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
131 std::list<ModuleBase_ViewerPrs> aFeatures = myFeatures;
133 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
135 /*for (; anIt != aLast; anIt++) {
136 FeaturePtr aFeature = (*anIt).feature();
138 emit featureConstructed(aFeature, FM_Deactivation);
143 void PartSet_OperationFeatureEditMulti::startOperation()
145 PartSet_OperationSketchBase::startOperation();
146 emit multiSelectionEnabled(false);
148 blockSelection(true);
153 void PartSet_OperationFeatureEditMulti::stopOperation()
155 emit multiSelectionEnabled(true);
157 blockSelection(false, true);
162 void PartSet_OperationFeatureEditMulti::blockSelection(bool isBlocked, const bool isRestoreSelection)
164 if (myIsBlockedSelection == isBlocked)
167 myIsBlockedSelection = isBlocked;
168 QFeatureList aFeatureList;
169 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(),
170 aLast = myFeatures.end();
171 /*for(; anIt != aLast; anIt++)
172 aFeatureList.append((*anIt).feature());*/
174 emit setSelection(QFeatureList());
175 emit stopSelection(aFeatureList, true);
178 emit stopSelection(aFeatureList, false);
179 if (isRestoreSelection) {
180 emit setSelection(aFeatureList);
185 void PartSet_OperationFeatureEditMulti::sendFeatures()
187 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
189 std::list<FeaturePtr > aFeatures;
190 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();
192 /*for (; anIt != aLast; anIt++) {
193 FeaturePtr aFeature = (*anIt).feature();
197 ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
199 Events_Loop::loop()->flush(anEvent);