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)
44 PartSet_OperationFeatureEditMulti::~PartSet_OperationFeatureEditMulti()
48 bool PartSet_OperationFeatureEditMulti::isGranted(ModuleBase_IOperation* theOperation) const
50 return theOperation->getDescription()->operationId().toStdString()
51 == PartSet_OperationSketch::Type();
54 void PartSet_OperationFeatureEditMulti::initSelection(
55 const std::list<ModuleBase_ViewerPrs>& theSelected,
56 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
58 if (!theHighlighted.empty()) {
59 // if there is highlighted object, we check whether it is in the list of selected objects
60 // in that case this object is a handle of the moved lines. If there no such object in the selection,
61 // the hightlighted object should moved and the selection is skipped. The skipped selection will be
62 // deselected in the viewer by blockSelection signal in the startOperation method.
63 bool isSelected = false;
64 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = theSelected.begin(), aLast = theSelected
66 for (; anIt != aLast && !isSelected; anIt++) {
67 isSelected = ModelAPI_Feature::feature((*anIt).object()) == feature();
70 myFeatures = theHighlighted;
72 myFeatures = theSelected;
74 myFeatures = theSelected;
77 void PartSet_OperationFeatureEditMulti::initFeature(FeaturePtr theFeature)
79 setEditingFeature(theFeature);
82 FeaturePtr PartSet_OperationFeatureEditMulti::sketch() const
87 void PartSet_OperationFeatureEditMulti::mousePressed(
88 QMouseEvent* theEvent, Handle(V3d_View) theView,
89 const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
90 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
94 void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
96 if (!(theEvent->buttons() & Qt::LeftButton))
99 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
101 blockSelection(true);
102 if (myCurPoint.myIsInitialized) {
104 PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
107 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
109 double aDeltaX = aX - aCurX;
110 double aDeltaY = anY - aCurY;
112 boost::shared_ptr<SketchPlugin_Feature> aSketchFeature = boost::dynamic_pointer_cast<
113 SketchPlugin_Feature>(feature());
114 aSketchFeature->move(aDeltaX, aDeltaY);
116 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures
118 for (; anIt != aLast; anIt++) {
119 ObjectPtr aObject = (*anIt).object();
120 if (!aObject || aObject == feature())
122 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
124 aSketchFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
126 aSketchFeature->move(aDeltaX, aDeltaY);
132 myCurPoint.setPoint(aPoint);
135 void PartSet_OperationFeatureEditMulti::mouseReleased(
136 QMouseEvent* theEvent, Handle(V3d_View) theView,
137 const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
138 const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
141 std::list<ModuleBase_ViewerPrs> aFeatures = myFeatures;
142 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = aFeatures.begin(), aLast =
144 for (; anIt != aLast; anIt++) {
145 ObjectPtr aFeature = (*anIt).object();
147 emit featureConstructed(aFeature, FM_Deactivation);
153 void PartSet_OperationFeatureEditMulti::startOperation()
155 PartSet_OperationSketchBase::startOperation();
156 emit multiSelectionEnabled(false);
158 blockSelection(true);
163 void PartSet_OperationFeatureEditMulti::stopOperation()
165 emit multiSelectionEnabled(true);
167 blockSelection(false, true);
172 void PartSet_OperationFeatureEditMulti::blockSelection(bool isBlocked,
173 const bool isRestoreSelection)
175 if (myIsBlockedSelection == isBlocked)
178 myIsBlockedSelection = isBlocked;
179 QList<ObjectPtr> aFeatureList;
180 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast =
182 /*for(; anIt != aLast; anIt++)
183 aFeatureList.append((*anIt).feature());*/
185 emit setSelection(QList<ObjectPtr>());
186 emit stopSelection(aFeatureList, true);
188 emit stopSelection(aFeatureList, false);
189 if (isRestoreSelection) {
190 emit setSelection(aFeatureList);
195 void PartSet_OperationFeatureEditMulti::sendFeatures()
197 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
199 std::list<FeaturePtr> aFeatures;
200 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast =
202 for (; anIt != aLast; anIt++) {
203 ObjectPtr aFeature = (*anIt).object();
207 ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
209 Events_Loop::loop()->flush(anEvent);