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>
11 #include <ModuleBase_Tools.h>
13 #include <ModelAPI_Events.h>
15 #include <SketchPlugin_Feature.h>
16 #include <GeomDataAPI_Point2D.h>
17 #include <ModelAPI_Data.h>
18 #include <ModelAPI_Document.h>
20 #include <ModelAPI_Events.h>
22 #include <Events_Loop.h>
24 #include <SketchPlugin_Line.h>
26 #include <V3d_View.hxx>
32 #include <QMouseEvent>
36 PartSet_OperationFeatureEditMulti::PartSet_OperationFeatureEditMulti(const QString& theId,
38 FeaturePtr theFeature)
39 : PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature), myIsBlockedSelection(false)
43 PartSet_OperationFeatureEditMulti::~PartSet_OperationFeatureEditMulti()
47 bool PartSet_OperationFeatureEditMulti::isGranted(ModuleBase_IOperation* theOperation) const
49 return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
52 void PartSet_OperationFeatureEditMulti::initSelection(const std::list<ModuleBase_ViewerPrs>& theSelected,
53 const std::list<ModuleBase_ViewerPrs>& theHighlighted)
55 if (!theHighlighted.empty()) {
56 // if there is highlighted object, we check whether it is in the list of selected objects
57 // in that case this object is a handle of the moved lines. If there no such object in the selection,
58 // the hightlighted object should moved and the selection is skipped. The skipped selection will be
59 // deselected in the viewer by blockSelection signal in the startOperation method.
60 bool isSelected = false;
61 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = theSelected.begin(), aLast = theSelected.end();
62 for (; anIt != aLast && !isSelected; anIt++) {
63 isSelected = ModuleBase_Tools::feature((*anIt).object()) == 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();
113 for (; anIt != aLast; anIt++) {
114 ObjectPtr aObject = (*anIt).object();
115 if (!aObject || aObject == feature())
117 FeaturePtr aFeature = ModuleBase_Tools::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(QMouseEvent* theEvent, Handle(V3d_View) theView,
131 const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
132 const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
134 std::list<ModuleBase_ViewerPrs> aFeatures = myFeatures;
136 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
137 for (; anIt != aLast; anIt++) {
138 ObjectPtr aFeature = (*anIt).object();
140 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, const bool isRestoreSelection)
166 if (myIsBlockedSelection == isBlocked)
169 myIsBlockedSelection = isBlocked;
170 QList<ObjectPtr> aFeatureList;
171 std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(),
172 aLast = myFeatures.end();
173 /*for(; anIt != aLast; anIt++)
174 aFeatureList.append((*anIt).feature());*/
176 emit setSelection(QList<ObjectPtr>());
177 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 = myFeatures.end();
193 for (; anIt != aLast; anIt++) {
194 ObjectPtr aFeature = (*anIt).object();
198 ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
200 Events_Loop::loop()->flush(anEvent);