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()
49 void PartSet_OperationFeatureEditMulti::initSelection(
50 const std::list<ModuleBase_ViewerPrs>& theSelected,
51 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
53 if (!theHighlighted.empty()) {
54 // if there is highlighted object, we check whether it is in the list of selected objects
55 // in that case this object is a handle of the moved lines. If there no such object in the selection,
56 // the hightlighted object should moved and the selection is skipped. The skipped selection will be
57 // deselected in the viewer by blockSelection signal in the startOperation method.
58 bool isSelected = false;
59 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = theSelected.begin(), aLast = theSelected
61 for (; anIt != aLast && !isSelected; anIt++) {
62 isSelected = ModelAPI_Feature::feature((*anIt).object()) == feature();
65 myFeatures = theHighlighted;
67 myFeatures = theSelected;
69 myFeatures = theSelected;
72 void PartSet_OperationFeatureEditMulti::initFeature(FeaturePtr theFeature)
74 setEditingFeature(theFeature);
77 FeaturePtr PartSet_OperationFeatureEditMulti::sketch() const
82 void PartSet_OperationFeatureEditMulti::mousePressed(
83 QMouseEvent* theEvent, Handle(V3d_View) theView,
84 const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
85 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
89 void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
91 if (!(theEvent->buttons() & Qt::LeftButton))
94 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
97 if (myCurPoint.myIsInitialized) {
99 PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
102 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
104 double aDeltaX = aX - aCurX;
105 double aDeltaY = anY - aCurY;
107 boost::shared_ptr<SketchPlugin_Feature> aSketchFeature = boost::dynamic_pointer_cast<
108 SketchPlugin_Feature>(feature());
109 aSketchFeature->move(aDeltaX, aDeltaY);
111 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures
113 for (; anIt != aLast; anIt++) {
114 ObjectPtr aObject = (*anIt).object();
115 if (!aObject || aObject == feature())
117 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
119 aSketchFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
121 aSketchFeature->move(aDeltaX, aDeltaY);
127 myCurPoint.setPoint(aPoint);
130 void PartSet_OperationFeatureEditMulti::mouseReleased(
131 QMouseEvent* theEvent, Handle(V3d_View) theView,
132 const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
133 const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
136 std::list<ModuleBase_ViewerPrs> aFeatures = myFeatures;
137 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = aFeatures.begin(), aLast =
139 for (; anIt != aLast; anIt++) {
140 ObjectPtr aFeature = (*anIt).object();
142 emit featureConstructed(aFeature, FM_Deactivation);
148 void PartSet_OperationFeatureEditMulti::startOperation()
150 PartSet_OperationSketchBase::startOperation();
151 emit multiSelectionEnabled(false);
153 blockSelection(true);
158 void PartSet_OperationFeatureEditMulti::stopOperation()
160 emit multiSelectionEnabled(true);
162 blockSelection(false, true);
167 void PartSet_OperationFeatureEditMulti::blockSelection(bool isBlocked,
168 const bool isRestoreSelection)
170 if (myIsBlockedSelection == isBlocked)
173 myIsBlockedSelection = isBlocked;
174 QList<ObjectPtr> aFeatureList;
175 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast =
177 /*for(; anIt != aLast; anIt++)
178 aFeatureList.append((*anIt).feature());*/
180 emit setSelection(QList<ObjectPtr>());
181 emit stopSelection(aFeatureList, true);
183 emit stopSelection(aFeatureList, false);
184 if (isRestoreSelection) {
185 emit setSelection(aFeatureList);
190 void PartSet_OperationFeatureEditMulti::sendFeatures()
192 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
194 std::list<FeaturePtr> aFeatures;
195 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast =
197 for (; anIt != aLast; anIt++) {
198 ObjectPtr aFeature = (*anIt).object();
202 ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
204 Events_Loop::loop()->flush(anEvent);