1 // File: PartSet_OperationEditConstraint.h
2 // Created: 05 May 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_OperationEditConstraint.h>
6 #include <PartSet_Tools.h>
7 #include <PartSet_OperationSketch.h>
8 #include <PartSet_EditLine.h>
9 #include <PartSet_FeaturePrs.h>
10 #include <SketchPlugin_ConstraintLength.h>
12 #include <ModuleBase_OperationDescription.h>
13 #include <Model_Events.h>
15 #include <XGUI_ViewerPrs.h>
17 #include <SketchPlugin_Feature.h>
18 #include <GeomDataAPI_Point2D.h>
19 #include <ModelAPI_Data.h>
20 #include <ModelAPI_Document.h>
22 #include <Model_Events.h>
24 #include <Events_Loop.h>
26 #include <SketchPlugin_Line.h>
28 #include <V3d_View.hxx>
29 #include <AIS_LengthDimension.hxx>
35 #include <QMouseEvent>
39 PartSet_OperationEditConstraint::PartSet_OperationEditConstraint(const QString& theId,
40 const std::string& theFeatureKind,
42 FeaturePtr theFeature)
43 : PartSet_OperationSketchBase(theId, theParent), myIsBlockedSelection(false)
45 myFeaturePrs = PartSet_Tools::createFeaturePrs(theFeatureKind, theFeature);
48 myEditor = new PartSet_EditLine(0);
49 connect(myEditor, SIGNAL(stopped(double)), this, SLOT(onEditStopped(double)));
52 PartSet_OperationEditConstraint::~PartSet_OperationEditConstraint()
56 bool PartSet_OperationEditConstraint::isGranted(ModuleBase_IOperation* theOperation) const
58 return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
61 std::list<int> PartSet_OperationEditConstraint::getSelectionModes(FeaturePtr theFeature) const
63 return PartSet_OperationSketchBase::getSelectionModes(theFeature);
66 void PartSet_OperationEditConstraint::init(FeaturePtr theFeature,
67 const std::list<XGUI_ViewerPrs>& theSelected,
68 const std::list<XGUI_ViewerPrs>& theHighlighted)
70 setFeature(theFeature);
71 myFeaturePrs->init(theFeature);
74 if (!theHighlighted.empty()) {
75 // if there is highlighted object, we check whether it is in the list of selected objects
76 // in that case this object is a handle of the moved lines. If there no such object in the selection,
77 // the hightlighted object should moved and the selection is skipped. The skipped selection will be
78 // deselected in the viewer by blockSelection signal in the startOperation method.
79 bool isSelected = false;
80 std::list<XGUI_ViewerPrs>::const_iterator anIt = theSelected.begin(), aLast = theSelected.end();
81 for (; anIt != aLast && !isSelected; anIt++) {
82 isSelected = (*anIt).feature() == feature();
85 myFeatures = theHighlighted;
87 myFeatures = theSelected;
90 myFeatures = theSelected;*/
93 FeaturePtr PartSet_OperationEditConstraint::sketch() const
95 return myFeaturePrs->sketch();
98 void PartSet_OperationEditConstraint::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView,
99 const std::list<XGUI_ViewerPrs>& theSelected,
100 const std::list<XGUI_ViewerPrs>& theHighlighted)
102 //if (myFeatures.size() == 1)
105 if (!theHighlighted.empty())
106 aFeature = theHighlighted.front().feature();
107 if (!aFeature && !theSelected.empty()) // changed
108 aFeature = theSelected.front().feature();
110 if (aFeature && aFeature == feature()) { // continue the feature edit
113 //XGUI_ViewerPrs aFeaturePrs = myFeatures.front();
115 emit featureConstructed(feature(), FM_Deactivation);
117 /*bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
118 if(aHasShift && !theHighlighted.empty()) {
119 std::list<XGUI_ViewerPrs> aSelected;
120 aSelected.push_back(aFeaturePrs);
121 aSelected.push_back(theHighlighted.front());
122 emit setSelection(aSelected);
125 restartOperation(PartSet_OperationEditConstraint::Type(), aFeature);
131 void PartSet_OperationEditConstraint::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
133 if (!(theEvent->buttons() & Qt::LeftButton))
136 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
138 blockSelection(true);
139 if (myCurPoint.myIsInitialized) {
141 PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
144 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
146 /*double aDeltaX = aX - aCurX;
147 double aDeltaY = anY - aCurY;
149 PartSet_Tools::moveFeature(feature(), aDeltaX, aDeltaY);*/
150 myFeaturePrs->setPoint(aX, anY, SM_SecondPoint);
153 /*std::list<XGUI_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();
154 for (; anIt != aLast; anIt++) {
155 FeaturePtr aFeature = (*anIt).feature();
156 if (!aFeature || aFeature == feature())
158 PartSet_Tools::moveFeature(aFeature, aDeltaX, aDeltaY);
163 myCurPoint.setPoint(aPoint);
166 void PartSet_OperationEditConstraint::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
167 const std::list<XGUI_ViewerPrs>& /*theSelected*/,
168 const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
170 //std::list<XGUI_ViewerPrs> aFeatures = myFeatures;
171 //if (myFeatures.size() == 1) {
172 blockSelection(false);
176 std::list<XGUI_ViewerPrs>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
177 for (; anIt != aLast; anIt++) {
178 FeaturePtr aFeature = (*anIt).feature();
180 emit featureConstructed(aFeature, FM_Deactivation);
185 void PartSet_OperationEditConstraint::mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView,
186 const std::list<XGUI_ViewerPrs>& theSelected,
187 const std::list<XGUI_ViewerPrs>& theHighlighted)
190 if (!theSelected.empty()) {
192 double aValue = PartSet_Tools::featureValue(feature(), CONSTRAINT_ATTR_VALUE, isValid);
194 QPoint aPos = theEvent->globalPos();
195 myEditor->start(aPos, aValue);
200 void PartSet_OperationEditConstraint::startOperation()
202 // do nothing in order to do not create a new feature
203 emit multiSelectionEnabled(false);
205 //if (myFeatures.size() > 1)
206 // blockSelection(true);
211 void PartSet_OperationEditConstraint::stopOperation()
213 emit multiSelectionEnabled(true);
215 //blockSelection(false, myFeatures.size() > 1);
217 //myFeatures.clear();
220 void PartSet_OperationEditConstraint::blockSelection(bool isBlocked, const bool isRestoreSelection)
222 if (myIsBlockedSelection == isBlocked)
225 myIsBlockedSelection = isBlocked;
227 emit setSelection(std::list<XGUI_ViewerPrs>());
228 //emit stopSelection(myFeatures, true);
231 //emit stopSelection(myFeatures, false);
232 //if (isRestoreSelection)
233 // emit setSelection(myFeatures);
237 FeaturePtr PartSet_OperationEditConstraint::createFeature(const bool /*theFlushMessage*/)
239 // do nothing in order to do not create a new feature
243 void PartSet_OperationEditConstraint::sendFeatures()
245 static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_MOVED);
247 std::list<FeaturePtr> aFeatures;
248 aFeatures.push_back(feature());
249 std::list<FeaturePtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
250 //std::list<XGUI_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();
251 for (; anIt != aLast; anIt++) {
252 FeaturePtr aFeature = (*anIt);//.feature();
256 Model_FeatureUpdatedMessage aMessage(aFeature, anEvent);
257 Events_Loop::loop()->send(aMessage);
259 Events_Loop::loop()->flush(anEvent);
263 void PartSet_OperationEditConstraint::onEditStopped(double theValue)
265 PartSet_Tools::setFeatureValue(feature(), theValue, CONSTRAINT_ATTR_VALUE);
269 emit featureConstructed(feature(), FM_Deactivation);
270 //restartOperation(feature()->getKind(), FeaturePtr());