1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_WidgetPoint2D.cpp
4 // Created: 25 Apr 2014
5 // Author: Natalia ERMOLAEVA
7 #include "PartSet_WidgetPoint2d.h"
8 #include <PartSet_Tools.h>
9 #include <PartSet_Module.h>
11 #include <XGUI_Tools.h>
12 #include <XGUI_Workshop.h>
13 #include <XGUI_Displayer.h>
15 #include <ModuleBase_ParamSpinBox.h>
16 #include <ModuleBase_Tools.h>
17 #include <ModuleBase_IViewer.h>
18 #include <ModuleBase_IViewWindow.h>
19 #include <ModuleBase_ISelection.h>
20 #include <ModuleBase_ViewerPrs.h>
22 #include <Config_Keywords.h>
23 #include <Config_WidgetAPI.h>
25 #include <Events_Loop.h>
26 #include <ModelAPI_Events.h>
27 #include <ModelAPI_AttributeBoolean.h>
29 #include <ModelAPI_Feature.h>
30 #include <ModelAPI_Data.h>
31 #include <ModelAPI_Object.h>
32 #include <GeomDataAPI_Point2D.h>
33 #include <GeomAPI_Pnt2d.h>
35 #include <SketchPlugin_Feature.h>
36 #include <SketchPlugin_ConstraintCoincidence.h>
37 #include <SketchPlugin_Line.h>
38 #include <SketchPlugin_Arc.h>
39 #include <SketchPlugin_Circle.h>
40 #include <SketchPlugin_Point.h>
43 #include <QGridLayout>
46 #include <QMouseEvent>
47 #include <QApplication>
50 #include <TopoDS_Vertex.hxx>
51 #include <BRep_Tool.hxx>
56 const double MaxCoordinate = 1e12;
58 static QStringList MyFeaturesForCoincedence;
60 PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent,
61 ModuleBase_IWorkshop* theWorkshop,
62 const Config_WidgetAPI* theData)
63 : ModuleBase_ModelWidget(theParent, theData), myWorkshop(theWorkshop),
64 myValueIsCashed(false), myIsFeatureVisibleInCash(true),
65 myXValueInCash(0), myYValueInCash(0)
67 if (MyFeaturesForCoincedence.isEmpty()) {
68 MyFeaturesForCoincedence << SketchPlugin_Line::ID().c_str()
69 << SketchPlugin_Arc::ID().c_str()
70 << SketchPlugin_Point::ID().c_str()
71 << SketchPlugin_Circle::ID().c_str();
74 // the control should accept the focus, so the boolean flag is corrected to be true
75 myIsObligatory = true;
76 //myOptionParam = theData->getProperty(PREVIOUS_FEATURE_PARAM);
77 QString aPageName = QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME));
78 myGroupBox = new QGroupBox(aPageName, theParent);
79 myGroupBox->setFlat(false);
81 bool aAcceptVariables = theData->getBooleanAttribute(DOUBLE_WDG_ACCEPT_EXPRESSIONS, true);
83 QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
84 ModuleBase_Tools::adjustMargins(aGroupLay);
85 aGroupLay->setSpacing(2);
86 aGroupLay->setColumnStretch(1, 1);
88 QLabel* aLabel = new QLabel(myGroupBox);
89 aLabel->setText(tr("X "));
90 aGroupLay->addWidget(aLabel, 0, 0);
92 myXSpin = new ModuleBase_ParamSpinBox(myGroupBox);
93 myXSpin->setAcceptVariables(aAcceptVariables);
94 myXSpin->setMinimum(-DBL_MAX);
95 myXSpin->setMaximum(DBL_MAX);
96 myXSpin->setToolTip(tr("X"));
97 aGroupLay->addWidget(myXSpin, 0, 1);
99 connect(myXSpin, SIGNAL(valueChanged(const QString&)), this, SIGNAL(valuesModified()));
102 QLabel* aLabel = new QLabel(myGroupBox);
103 aLabel->setText(tr("Y "));
104 aGroupLay->addWidget(aLabel, 1, 0);
106 myYSpin = new ModuleBase_ParamSpinBox(myGroupBox);
107 myYSpin->setAcceptVariables(aAcceptVariables);
108 myYSpin->setMinimum(-DBL_MAX);
109 myYSpin->setMaximum(DBL_MAX);
110 myYSpin->setToolTip(tr("Y"));
111 aGroupLay->addWidget(myYSpin, 1, 1);
113 connect(myYSpin, SIGNAL(valueChanged(const QString&)), this, SIGNAL(valuesModified()));
115 QVBoxLayout* aLayout = new QVBoxLayout(this);
116 ModuleBase_Tools::zeroMargins(aLayout);
117 aLayout->addWidget(myGroupBox);
121 bool PartSet_WidgetPoint2D::resetCustom()
124 if (!isUseReset() || isComputedDefault() || myXSpin->hasVariable() || myYSpin->hasVariable()) {
128 if (myValueIsCashed) {
129 // if the restored value should be hidden, aDone = true to set
130 // reset state for the widget in the parent
131 aDone = restoreCurentValue();
135 double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
136 // it is important to block the spin box control in order to do not through out the
137 // locking of the validating state.
138 ModuleBase_Tools::setSpinValue(myXSpin, isOk ? aDefValue : 0.0);
139 ModuleBase_Tools::setSpinValue(myYSpin, isOk ? aDefValue : 0.0);
147 PartSet_WidgetPoint2D::~PartSet_WidgetPoint2D()
151 bool PartSet_WidgetPoint2D::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,
152 const bool theToValidate)
155 if (theValues.empty())
158 ModuleBase_ViewerPrsPtr aValue = theValues.takeFirst();
159 GeomShapePtr aShape = aValue->shape();
160 if (aShape.get() && !aShape->isNull()) {
161 Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
163 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
164 if (getPoint2d(aView, aTDShape, aX, aY)) {
165 isDone = setPoint(aX, aY);
166 PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aX, aY);
169 else if (canBeActivatedByMove()) {
170 if (feature()->getKind() == SketchPlugin_Line::ID()) {
171 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aValue->object());
172 // Initialize new line with first point equal to end of previous
173 if (aFeature.get()) {
174 std::shared_ptr<ModelAPI_Data> aData = aFeature->data();
175 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
176 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
177 aData->attribute(SketchPlugin_Line::END_ID()));
179 setPoint(aPoint->x(), aPoint->y());
180 PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aPoint->x(),
190 void PartSet_WidgetPoint2D::selectContent()
192 myXSpin->selectAll();
195 bool PartSet_WidgetPoint2D::setPoint(double theX, double theY)
197 if (fabs(theX) >= MaxCoordinate)
199 if (fabs(theY) >= MaxCoordinate)
202 ModuleBase_Tools::setSpinValue(myXSpin, theX);
203 ModuleBase_Tools::setSpinValue(myYSpin, theY);
209 bool PartSet_WidgetPoint2D::storeValueCustom() const
211 std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
212 if (!aData) // can be on abort of sketcher element
214 std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
215 aData->attribute(attributeID()));
217 PartSet_WidgetPoint2D* that = (PartSet_WidgetPoint2D*) this;
218 bool isBlocked = that->blockSignals(true);
219 bool isImmutable = aPoint->setImmutable(true);
221 // if text is not empty then setValue will be ignored
222 // so we should set the text at first
223 aPoint->setText(myXSpin->hasVariable() ? myXSpin->text().toStdString() : "",
224 myYSpin->hasVariable() ? myYSpin->text().toStdString() : "");
225 aPoint->setValue(!myXSpin->hasVariable() ? myXSpin->value() : aPoint->x(),
226 !myYSpin->hasVariable() ? myYSpin->value() : aPoint->y());
228 // after movement the solver will call the update event: optimization
229 moveObject(myFeature);
230 aPoint->setImmutable(isImmutable);
231 that->blockSignals(isBlocked);
236 bool PartSet_WidgetPoint2D::restoreValueCustom()
238 std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
239 std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
240 aData->attribute(attributeID()));
241 QString aTextX = QString::fromStdString(aPoint->textX());
242 QString aTextY = QString::fromStdString(aPoint->textY());
244 bool isDouble = false;
246 if (aTextX.isEmpty()) {
247 ModuleBase_Tools::setSpinValue(myXSpin, aPoint->x());
249 aVal = aTextX.toDouble(&isDouble);
251 ModuleBase_Tools::setSpinValue(myXSpin, aVal);
253 ModuleBase_Tools::setSpinText(myXSpin, aTextX);
255 if (aTextY.isEmpty()) {
256 ModuleBase_Tools::setSpinValue(myYSpin, aPoint->y());
258 aVal = aTextY.toDouble(&isDouble);
260 ModuleBase_Tools::setSpinValue(myYSpin, aVal);
262 ModuleBase_Tools::setSpinText(myYSpin, aTextY);
264 //if (aTextX.empty() || aTextY.empty()) {
265 // ModuleBase_Tools::setSpinValue(myXSpin, aPoint->x());
266 // ModuleBase_Tools::setSpinValue(myYSpin, aPoint->y());
268 // ModuleBase_Tools::setSpinText(myXSpin, QString::fromStdString(aTextX));
269 // ModuleBase_Tools::setSpinText(myYSpin, QString::fromStdString(aTextY));
274 void PartSet_WidgetPoint2D::storeCurentValue()
276 // do not use cash if a variable is used
277 if (myXSpin->hasVariable() || myYSpin->hasVariable())
280 myValueIsCashed = true;
281 myIsFeatureVisibleInCash = XGUI_Displayer::isVisible(
282 XGUI_Tools::workshop(myWorkshop)->displayer(), myFeature);
283 myXValueInCash = myXSpin->value();
284 myYValueInCash = myYSpin->value();
287 bool PartSet_WidgetPoint2D::restoreCurentValue()
289 bool aRestoredAndHidden = true;
291 bool isVisible = myIsFeatureVisibleInCash;
292 // fill the control widgets by the cashed value
294 myValueIsCashed = false;
295 myIsFeatureVisibleInCash = true;
296 ModuleBase_Tools::setSpinValue(myXSpin, myXValueInCash);
297 ModuleBase_Tools::setSpinValue(myYSpin, myYValueInCash);
299 // store value to the model
302 setValueState(Stored);
303 aRestoredAndHidden = false;
306 aRestoredAndHidden = true;
308 return aRestoredAndHidden;
311 QList<QWidget*> PartSet_WidgetPoint2D::getControls() const
313 QList<QWidget*> aControls;
314 aControls.append(myXSpin);
315 aControls.append(myYSpin);
320 void PartSet_WidgetPoint2D::activateCustom()
322 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
323 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
324 this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
325 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
326 this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
329 aModes << TopAbs_VERTEX;
330 aModes << TopAbs_EDGE;
331 myWorkshop->activateSubShapesSelection(aModes);
333 if (!isEditingMode()) {
334 FeaturePtr aFeature = feature();
335 if (aFeature.get() && aFeature->getKind() == SketchPlugin_Point::ID())
340 bool PartSet_WidgetPoint2D::canBeActivatedByMove()
342 bool aCanBeActivated = false;
343 if (feature()->getKind() == SketchPlugin_Line::ID() &&
344 attributeID() == SketchPlugin_Line::START_ID())
345 aCanBeActivated = true;
347 return aCanBeActivated;
350 void PartSet_WidgetPoint2D::deactivate()
352 // the value of the control should be stored to model if it was not
353 // initialized yet. It is important when we leave this control by Tab key.
354 // It should not be performed by the widget activation as the preview
355 // is visualized with default value. Line point is moved to origin.
356 AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
357 if (anAttribute && !anAttribute->isInitialized())
360 ModuleBase_ModelWidget::deactivate();
361 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
362 disconnect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
363 this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
364 disconnect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
365 this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
367 myWorkshop->deactivateSubShapesSelection();
370 bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView,
371 const TopoDS_Shape& theShape,
372 double& theX, double& theY) const
374 if (!theShape.IsNull()) {
375 if (theShape.ShapeType() == TopAbs_VERTEX) {
376 const TopoDS_Vertex& aVertex = TopoDS::Vertex(theShape);
377 if (!aVertex.IsNull()) {
378 // A case when point is taken from existing vertex
379 gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
380 PartSet_Tools::convertTo2D(aPoint, mySketch, theView, theX, theY);
388 bool PartSet_WidgetPoint2D::setConstraintWith(const ObjectPtr& theObject)
390 std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint;
391 if (feature()->isMacro()) {
392 AttributePtr aThisAttr = feature()->data()->attribute(attributeID());
393 std::shared_ptr<GeomDataAPI_Point2D> anAttrPoint =
394 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aThisAttr);
395 if (anAttrPoint.get()) {
396 // the macro feature will be removed after the operation is stopped, so we need to build
397 // coicidence to possible sub-features
398 aFeaturePoint = PartSet_Tools::findFirstEqualPointInArgumentFeatures(feature(),
403 AttributePtr aThisAttr = feature()->data()->attribute(attributeID());
404 aFeaturePoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aThisAttr);
406 if (!aFeaturePoint.get())
409 // Create point-edge coincedence
410 FeaturePtr aFeature = mySketch->addFeature(SketchPlugin_ConstraintCoincidence::ID());
411 std::shared_ptr<ModelAPI_Data> aData = aFeature->data();
413 std::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 = std::dynamic_pointer_cast<
414 ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
416 aRef1->setAttr(aFeaturePoint);
418 std::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 = std::dynamic_pointer_cast<
419 ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
420 aRef2->setObject(theObject);
422 // we need to flush created signal in order to coincidence is processed by solver
423 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
428 void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
430 // the contex menu release by the right button should not be processed by this widget
431 if (theEvent->button() != Qt::LeftButton)
434 ModuleBase_ISelection* aSelection = myWorkshop->selection();
435 Handle(V3d_View) aView = theWnd->v3dView();
436 // TODO: This fragment doesn't work because bug in OCC Viewer. It can be used after fixing.
437 NCollection_List<TopoDS_Shape> aShapes;
438 std::list<ObjectPtr> aObjects;
439 aSelection->selectedShapes(aShapes, aObjects);
440 // if we have selection and use it
441 if (aShapes.Extent() > 0 && useSelectedShapes()) {
442 TopoDS_Shape aShape = aShapes.First();
443 ObjectPtr aObject = aObjects.front();
444 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aObject);
445 bool anExternal = false;
446 std::shared_ptr<SketchPlugin_Feature> aSPFeature;
447 if (aSelectedFeature.get() != NULL)
448 aSPFeature = std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
449 if ((!aSPFeature && !aShape.IsNull()) ||
450 (aSPFeature.get() && aSPFeature->isExternal())) {
451 ResultPtr aFixedObject;
453 aFixedObject = PartSet_Tools::findFixedObjectByExternal(aShape, aObject, mySketch);
454 if (!aFixedObject.get())
455 aFixedObject = PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch);
457 if (getPoint2d(aView, aShape, aX, aY) && isFeatureContainsPoint(myFeature, aX, aY)) {
458 // do not create a constraint to the point, which already used by the feature
459 // if the feature contains the point, focus is not switched
463 if (getPoint2d(aView, aShape, aX, aY))
466 setValueState(Stored); // in case of edge selection, Apply state should also be updated
467 bool anOrphanPoint = aShape.ShapeType() == TopAbs_VERTEX ||
468 isOrphanPoint(aSelectedFeature, mySketch, aX, aY);
470 anOrphanPoint = true; // we should not stop reentrant operation on external objects because
471 // they are not participate in the contour creation excepting external vertices
472 if (aShape.ShapeType() == TopAbs_VERTEX) {
473 FeaturePtr aFixedFeature = ModelAPI_Feature::feature(aFixedObject);
474 if (aFixedFeature.get() && aFixedFeature->getKind() == SketchPlugin_Point::ID()) {
475 anOrphanPoint = isOrphanPoint(aFixedFeature, mySketch, aX, aY);
479 if (aFixedObject.get())
480 setConstraintWith(aFixedObject);
481 // fignal updated should be flushed in order to visualize possible created external objects
482 // e.g. selection of trihedron axis when input end arc point
483 updateObject(feature());
486 emit vertexSelected(); // it stops the reentrant operation
488 emit focusOutWidget(this);
493 bool isProcessed = false;
494 if (getPoint2d(aView, aShape, aX, aY) && isFeatureContainsPoint(myFeature, aX, aY)) {
495 // when the point is selected, the coordinates of the point should be set into the attribute
496 // if the feature contains the point, focus is not switched
500 bool anOrphanPoint = isOrphanPoint(aSelectedFeature, mySketch, aX, aY);
501 // do not set a coincidence constraint in the attribute if the feature contains a point
502 // with the same coordinates. It is important for line creation in order to do not set
503 // the same constraints for the same points, oterwise the result line has zero length.
504 bool isAuxiliaryFeature = false;
505 if (getPoint2d(aView, aShape, aX, aY)) {
507 feature()->execute();
508 PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aX, aY);
510 else if (aShape.ShapeType() == TopAbs_EDGE) {
511 if (!setConstraintWith(aObject)) {
512 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
513 PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, aY);
516 setValueState(Stored); // in case of edge selection, Apply state should also be updated
517 isAuxiliaryFeature = PartSet_Tools::isAuxiliarySketchEntity(aObject);
519 // it is important to perform updateObject() in order to the current value is
520 // processed by Sketch Solver. Test case: line is created from a previous point
521 // to some distance, but in the area of the highlighting of the point. Constraint
522 // coincidence is created, after the solver is performed, the distance between the
523 // points of the line becomes less than the tolerance. Validator of the line returns
524 // false, the line will be aborted, but sketch stays valid.
525 updateObject(feature());
526 if (!anOrphanPoint && !anExternal && !isAuxiliaryFeature)
527 emit vertexSelected();
528 emit focusOutWidget(this);
532 // End of Bug dependent fragment
534 // A case when point is taken from mouse event
535 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
537 PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, anY);
539 // if the feature contains the point, focus is not switched
540 if (!setPoint(aX, anY) || isFeatureContainsPoint(myFeature, aX, anY))
543 /// Start alternative code
544 //std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint = std::dynamic_pointer_cast<
545 // GeomDataAPI_Point2D>(feature()->data()->attribute(attributeID()));
546 //QList<FeaturePtr> aIgnore;
547 //aIgnore.append(feature());
549 //double aTolerance = aView->Convert(7);
550 //std::shared_ptr<GeomDataAPI_Point2D> aAttrPnt =
551 // PartSet_Tools::findAttributePoint(mySketch, aX, anY, aTolerance, aIgnore);
552 //if (aAttrPnt.get() != NULL) {
553 // aFeaturePoint->setValue(aAttrPnt->pnt());
554 // PartSet_Tools::createConstraint(mySketch, aAttrPnt, aFeaturePoint);
555 // emit vertexSelected();
557 /// End alternative code
558 emit focusOutWidget(this);
563 void PartSet_WidgetPoint2D::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
568 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
571 PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, anY);
572 if (myState != ModifiedInViewer)
574 // we need to block the value state change
575 bool isBlocked = blockValueState(true);
577 blockValueState(isBlocked);
578 setValueState(ModifiedInViewer);
581 double PartSet_WidgetPoint2D::x() const
583 return myXSpin->value();
586 double PartSet_WidgetPoint2D::y() const
588 return myYSpin->value();
592 bool PartSet_WidgetPoint2D::isFeatureContainsPoint(const FeaturePtr& theFeature,
593 double theX, double theY)
595 bool aPointIsFound = false;
597 if (feature()->getKind() != SketchPlugin_Line::ID())
598 return aPointIsFound;
600 AttributePtr aWidgetAttribute = myFeature->attribute(attributeID());
602 std::shared_ptr<GeomAPI_Pnt2d> aPnt2d =
603 std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY));
604 std::list<AttributePtr> anAttributes =
605 myFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
606 std::list<AttributePtr>::iterator anIter = anAttributes.begin();
607 for(; anIter != anAttributes.end() && !aPointIsFound; anIter++) {
608 AttributePoint2DPtr aPoint2DAttribute =
609 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIter);
610 if (aPoint2DAttribute == aWidgetAttribute)
612 if (aPoint2DAttribute.get() && aPoint2DAttribute->isInitialized()) {
613 aPointIsFound = aPoint2DAttribute->pnt()->isEqual(aPnt2d);
616 return aPointIsFound;
619 void PartSet_WidgetPoint2D::initializeValueByActivate()
623 /*void PartSet_WidgetPoint2D::onValuesChanged()
625 emit valuesChanged();
628 bool PartSet_WidgetPoint2D::processEnter()
630 bool isModified = getValueState() == ModifiedInPP;
632 bool isXModified = myXSpin->hasFocus();
633 emit valuesChanged();
635 myXSpin->selectAll();
637 myYSpin->selectAll();
642 bool PartSet_WidgetPoint2D::useSelectedShapes() const
647 bool PartSet_WidgetPoint2D::isOrphanPoint(const FeaturePtr& theFeature,
648 const CompositeFeaturePtr& theSketch,
649 double theX, double theY)
651 bool anOrphanPoint = false;
652 if (theFeature.get()) {
653 std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
654 std::string aFeatureKind = theFeature->getKind();
655 if (aFeatureKind == SketchPlugin_Point::ID())
656 aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
657 theFeature->attribute(SketchPlugin_Point::COORD_ID()));
658 else if (aFeatureKind == SketchPlugin_Circle::ID())
659 aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
660 theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
662 else if (aFeatureKind == SketchPlugin_Arc::ID())
663 aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
664 theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
666 /// check that the geometry point with the given coordinates is the checked point
667 /// e.g. in arc the (x,y) point can not coicide to the center point and it automatically
668 /// means that this point is not an orphant one.
669 if (aPointAttr.get()) {
670 std::shared_ptr<GeomAPI_Pnt2d> aCheckedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
671 new GeomAPI_Pnt2d(theX, theY));
672 if (!aCheckedPoint->isEqual(aPointAttr->pnt()))
673 return anOrphanPoint;
676 if (aPointAttr.get()) {
677 std::shared_ptr<GeomAPI_Pnt2d> aPoint = aPointAttr->pnt();
678 // we need to find coincidence features in results also, because external object(point)
679 // uses refs to me in another feature.
680 FeaturePtr aCoincidence = PartSet_Tools::findFirstCoincidence(theFeature, aPoint);
681 anOrphanPoint = true;
682 // if there is at least one concident line to the point, the point is not an orphant
683 if (aCoincidence.get()) {
684 QList<FeaturePtr> aCoinsideLines;
685 QList<FeaturePtr> aCoins;
686 PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines, aCoins,
687 SketchPlugin_ConstraintCoincidence::ENTITY_A());
688 PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines, aCoins,
689 SketchPlugin_ConstraintCoincidence::ENTITY_B());
690 QList<FeaturePtr>::const_iterator anIt = aCoinsideLines.begin(),
691 aLast = aCoinsideLines.end();
692 for (; anIt != aLast && anOrphanPoint; anIt++) {
693 anOrphanPoint = (*anIt)->getKind() != SketchPlugin_Line::ID();
698 return anOrphanPoint;