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 <PartSet_ConstraintRadiusPrs.h>
12 #include <SketchPlugin_Constraint.h>
14 #include <ModuleBase_OperationDescription.h>
15 #include <Model_Events.h>
17 #include <XGUI_ViewerPrs.h>
19 #include <SketchPlugin_Feature.h>
20 #include <GeomDataAPI_Point2D.h>
21 #include <ModelAPI_Data.h>
22 #include <ModelAPI_Document.h>
24 #include <Model_Events.h>
26 #include <Events_Loop.h>
28 #include <SketchPlugin_Line.h>
30 #include <V3d_View.hxx>
31 #include <AIS_LengthDimension.hxx>
37 #include <QMouseEvent>
41 PartSet_OperationEditConstraint::PartSet_OperationEditConstraint(const QString& theId,
42 const std::string& theFeatureKind,
44 FeaturePtr theFeature)
45 : PartSet_OperationSketchBase(theId, theParent), myIsBlockedSelection(false)
47 myFeaturePrs = PartSet_Tools::createFeaturePrs(theFeatureKind, theFeature);
50 myEditor = new PartSet_EditLine(0);
51 connect(myEditor, SIGNAL(stopped(double)), this, SLOT(onEditStopped(double)));
54 PartSet_OperationEditConstraint::~PartSet_OperationEditConstraint()
58 bool PartSet_OperationEditConstraint::isGranted(ModuleBase_IOperation* theOperation) const
60 return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
63 std::list<int> PartSet_OperationEditConstraint::getSelectionModes(FeaturePtr theFeature) const
65 return PartSet_OperationSketchBase::getSelectionModes(theFeature);
68 void PartSet_OperationEditConstraint::init(FeaturePtr theFeature,
69 const std::list<XGUI_ViewerPrs>& theSelected,
70 const std::list<XGUI_ViewerPrs>& theHighlighted)
72 setEditingFeature(theFeature);
73 myFeaturePrs->init(theFeature);
76 if (!theHighlighted.empty()) {
77 // if there is highlighted object, we check whether it is in the list of selected objects
78 // in that case this object is a handle of the moved lines. If there no such object in the selection,
79 // the hightlighted object should moved and the selection is skipped. The skipped selection will be
80 // deselected in the viewer by blockSelection signal in the startOperation method.
81 bool isSelected = false;
82 std::list<XGUI_ViewerPrs>::const_iterator anIt = theSelected.begin(), aLast = theSelected.end();
83 for (; anIt != aLast && !isSelected; anIt++) {
84 isSelected = (*anIt).feature() == feature();
87 myFeatures = theHighlighted;
89 myFeatures = theSelected;
92 myFeatures = theSelected;*/
95 FeaturePtr PartSet_OperationEditConstraint::sketch() const
97 return myFeaturePrs->sketch();
100 void PartSet_OperationEditConstraint::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView,
101 const std::list<XGUI_ViewerPrs>& theSelected,
102 const std::list<XGUI_ViewerPrs>& theHighlighted)
104 //if (myFeatures.size() == 1)
107 if (!theHighlighted.empty())
108 aFeature = theHighlighted.front().feature();
109 if (!aFeature && !theSelected.empty()) // changed
110 aFeature = theSelected.front().feature();
112 if (aFeature && aFeature == feature()) { // continue the feature edit
115 //XGUI_ViewerPrs aFeaturePrs = myFeatures.front();
117 emit featureConstructed(feature(), FM_Deactivation);
119 /*bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
120 if(aHasShift && !theHighlighted.empty()) {
121 std::list<XGUI_ViewerPrs> aSelected;
122 aSelected.push_back(aFeaturePrs);
123 aSelected.push_back(theHighlighted.front());
124 emit setSelection(aSelected);
127 restartOperation(PartSet_OperationEditConstraint::Type(), aFeature);
133 void PartSet_OperationEditConstraint::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
135 if (!(theEvent->buttons() & Qt::LeftButton))
138 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
140 blockSelection(true);
141 if (myCurPoint.myIsInitialized) {
143 PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
146 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
149 if (feature()->getKind() == PartSet_ConstraintRadiusPrs::getKind()) {
150 boost::shared_ptr<PartSet_ConstraintRadiusPrs> anArcPrs =
151 boost::dynamic_pointer_cast<PartSet_ConstraintRadiusPrs>(myFeaturePrs);
153 anArcPrs->projectPointOnFeature(feature(), sketch(), aPoint, theView, aX, anY);
156 myFeaturePrs->setPoint(aX, anY, SM_LastPoint);
160 myCurPoint.setPoint(aPoint);
163 void PartSet_OperationEditConstraint::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
164 const std::list<XGUI_ViewerPrs>& /*theSelected*/,
165 const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
167 //std::list<XGUI_ViewerPrs> aFeatures = myFeatures;
168 //if (myFeatures.size() == 1) {
169 blockSelection(false);
173 std::list<XGUI_ViewerPrs>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
174 for (; anIt != aLast; anIt++) {
175 FeaturePtr aFeature = (*anIt).feature();
177 emit featureConstructed(aFeature, FM_Deactivation);
182 void PartSet_OperationEditConstraint::mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView,
183 const std::list<XGUI_ViewerPrs>& theSelected,
184 const std::list<XGUI_ViewerPrs>& theHighlighted)
187 if (!theSelected.empty()) {
189 double aValue = PartSet_Tools::featureValue(feature(), CONSTRAINT_ATTR_VALUE, isValid);
191 QPoint aPos = theEvent->globalPos();
192 myEditor->start(aPos, aValue);
197 void PartSet_OperationEditConstraint::startOperation()
199 PartSet_OperationSketchBase::startOperation();
200 emit multiSelectionEnabled(false);
202 //if (myFeatures.size() > 1)
203 // blockSelection(true);
208 void PartSet_OperationEditConstraint::stopOperation()
210 emit multiSelectionEnabled(true);
212 //blockSelection(false, myFeatures.size() > 1);
214 //myFeatures.clear();
217 void PartSet_OperationEditConstraint::blockSelection(bool isBlocked, const bool isRestoreSelection)
219 if (myIsBlockedSelection == isBlocked)
222 myIsBlockedSelection = isBlocked;
224 emit setSelection(std::list<XGUI_ViewerPrs>());
225 //emit stopSelection(myFeatures, true);
228 //emit stopSelection(myFeatures, false);
229 //if (isRestoreSelection)
230 // emit setSelection(myFeatures);
234 FeaturePtr PartSet_OperationEditConstraint::createFeature(const bool /*theFlushMessage*/)
236 // do nothing in order to do not create a new feature
240 void PartSet_OperationEditConstraint::sendFeatures()
242 static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_MOVED);
244 std::list<FeaturePtr> aFeatures;
245 aFeatures.push_back(feature());
246 std::list<FeaturePtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
247 //std::list<XGUI_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();
248 for (; anIt != aLast; anIt++) {
249 FeaturePtr aFeature = (*anIt);//.feature();
253 Model_FeatureUpdatedMessage aMessage(aFeature, anEvent);
254 Events_Loop::loop()->send(aMessage);
256 Events_Loop::loop()->flush(anEvent);
260 void PartSet_OperationEditConstraint::onEditStopped(double theValue)
262 PartSet_Tools::setFeatureValue(feature(), theValue, CONSTRAINT_ATTR_VALUE);
266 emit featureConstructed(feature(), FM_Deactivation);
267 //restartOperation(feature()->getKind(), FeaturePtr());