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>
21 #include <Config_Keywords.h>
22 #include <Config_WidgetAPI.h>
24 #include <Events_Loop.h>
25 #include <ModelAPI_Events.h>
26 #include <ModelAPI_AttributeBoolean.h>
28 #include <ModelAPI_Feature.h>
29 #include <ModelAPI_Data.h>
30 #include <ModelAPI_Object.h>
31 #include <GeomDataAPI_Point2D.h>
32 #include <GeomAPI_Pnt2d.h>
34 #include <SketchPlugin_Feature.h>
35 #include <SketchPlugin_ConstraintCoincidence.h>
36 #include <SketchPlugin_Line.h>
37 #include <SketchPlugin_Arc.h>
38 #include <SketchPlugin_Circle.h>
39 #include <SketchPlugin_Point.h>
42 #include <QGridLayout>
45 #include <QMouseEvent>
46 #include <QApplication>
49 #include <TopoDS_Vertex.hxx>
50 #include <BRep_Tool.hxx>
55 const double MaxCoordinate = 1e12;
57 static QStringList MyFeaturesForCoincedence;
59 PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent,
60 ModuleBase_IWorkshop* theWorkshop,
61 const Config_WidgetAPI* theData,
62 const std::string& theParentId)
63 : ModuleBase_ModelWidget(theParent, theData, theParentId), 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_ViewerPrs>& theValues,
152 const bool theToValidate)
155 if (theValues.empty())
158 ModuleBase_ViewerPrs aValue = theValues.takeFirst();
159 TopoDS_Shape aShape = aValue.shape();
160 if (!aShape.IsNull()) {
161 Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
163 if (getPoint2d(aView, aShape, aX, aY)) {
164 isDone = setPoint(aX, aY);
165 PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aX, aY);
168 else if (canBeActivatedByMove()) {
169 if (feature()->getKind() == SketchPlugin_Line::ID()) {
170 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aValue.object());
171 // Initialize new line with first point equal to end of previous
172 if (aFeature.get()) {
173 std::shared_ptr<ModelAPI_Data> aData = aFeature->data();
174 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
175 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
176 aData->attribute(SketchPlugin_Line::END_ID()));
178 setPoint(aPoint->x(), aPoint->y());
179 PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aPoint->x(),
189 void PartSet_WidgetPoint2D::selectContent()
191 myXSpin->selectAll();
194 bool PartSet_WidgetPoint2D::setPoint(double theX, double theY)
196 if (fabs(theX) >= MaxCoordinate)
198 if (fabs(theY) >= MaxCoordinate)
201 ModuleBase_Tools::setSpinValue(myXSpin, theX);
202 ModuleBase_Tools::setSpinValue(myYSpin, theY);
208 bool PartSet_WidgetPoint2D::storeValueCustom() const
210 std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
211 if (!aData) // can be on abort of sketcher element
213 std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
214 aData->attribute(attributeID()));
216 PartSet_WidgetPoint2D* that = (PartSet_WidgetPoint2D*) this;
217 bool isBlocked = that->blockSignals(true);
218 bool isImmutable = aPoint->setImmutable(true);
220 // if text is not empty then setValue will be ignored
221 // so we should set the text at first
222 aPoint->setText(myXSpin->hasVariable() ? myXSpin->text().toStdString() : "",
223 myYSpin->hasVariable() ? myYSpin->text().toStdString() : "");
224 aPoint->setValue(!myXSpin->hasVariable() ? myXSpin->value() : aPoint->x(),
225 !myYSpin->hasVariable() ? myYSpin->value() : aPoint->y());
227 // after movement the solver will call the update event: optimization
228 moveObject(myFeature);
229 aPoint->setImmutable(isImmutable);
230 that->blockSignals(isBlocked);
235 bool PartSet_WidgetPoint2D::restoreValueCustom()
237 std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
238 std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
239 aData->attribute(attributeID()));
240 QString aTextX = QString::fromStdString(aPoint->textX());
241 QString aTextY = QString::fromStdString(aPoint->textY());
243 bool isDouble = false;
245 if (aTextX.isEmpty()) {
246 ModuleBase_Tools::setSpinValue(myXSpin, aPoint->x());
248 aVal = aTextX.toDouble(&isDouble);
250 ModuleBase_Tools::setSpinValue(myXSpin, aVal);
252 ModuleBase_Tools::setSpinText(myXSpin, aTextX);
254 if (aTextY.isEmpty()) {
255 ModuleBase_Tools::setSpinValue(myYSpin, aPoint->y());
257 aVal = aTextY.toDouble(&isDouble);
259 ModuleBase_Tools::setSpinValue(myYSpin, aVal);
261 ModuleBase_Tools::setSpinText(myYSpin, aTextY);
263 //if (aTextX.empty() || aTextY.empty()) {
264 // ModuleBase_Tools::setSpinValue(myXSpin, aPoint->x());
265 // ModuleBase_Tools::setSpinValue(myYSpin, aPoint->y());
267 // ModuleBase_Tools::setSpinText(myXSpin, QString::fromStdString(aTextX));
268 // ModuleBase_Tools::setSpinText(myYSpin, QString::fromStdString(aTextY));
273 void PartSet_WidgetPoint2D::storeCurentValue()
275 // do not use cash if a variable is used
276 if (myXSpin->hasVariable() || myYSpin->hasVariable())
279 myValueIsCashed = true;
280 myIsFeatureVisibleInCash = XGUI_Displayer::isVisible(
281 XGUI_Tools::workshop(myWorkshop)->displayer(), myFeature);
282 myXValueInCash = myXSpin->value();
283 myYValueInCash = myYSpin->value();
286 bool PartSet_WidgetPoint2D::restoreCurentValue()
288 bool aRestoredAndHidden = true;
290 bool isVisible = myIsFeatureVisibleInCash;
291 // fill the control widgets by the cashed value
293 myValueIsCashed = false;
294 myIsFeatureVisibleInCash = true;
295 ModuleBase_Tools::setSpinValue(myXSpin, myXValueInCash);
296 ModuleBase_Tools::setSpinValue(myYSpin, myYValueInCash);
298 // store value to the model
301 setValueState(Stored);
302 aRestoredAndHidden = false;
305 aRestoredAndHidden = true;
307 return aRestoredAndHidden;
310 QList<QWidget*> PartSet_WidgetPoint2D::getControls() const
312 QList<QWidget*> aControls;
313 aControls.append(myXSpin);
314 aControls.append(myYSpin);
319 void PartSet_WidgetPoint2D::activateCustom()
321 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
322 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
323 this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
324 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
325 this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
328 aModes << TopAbs_VERTEX;
329 aModes << TopAbs_EDGE;
330 myWorkshop->activateSubShapesSelection(aModes);
332 if (!isEditingMode()) {
333 FeaturePtr aFeature = feature();
334 if (aFeature.get() && aFeature->getKind() == SketchPlugin_Point::ID())
339 bool PartSet_WidgetPoint2D::canBeActivatedByMove()
341 bool aCanBeActivated = false;
342 if (feature()->getKind() == SketchPlugin_Line::ID() &&
343 attributeID() == SketchPlugin_Line::START_ID())
344 aCanBeActivated = true;
346 return aCanBeActivated;
349 void PartSet_WidgetPoint2D::deactivate()
351 // the value of the control should be stored to model if it was not
352 // initialized yet. It is important when we leave this control by Tab key.
353 // It should not be performed by the widget activation as the preview
354 // is visualized with default value. Line point is moved to origin.
355 AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
356 if (anAttribute && !anAttribute->isInitialized())
359 ModuleBase_ModelWidget::deactivate();
360 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
361 disconnect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
362 this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
363 disconnect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
364 this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
366 myWorkshop->deactivateSubShapesSelection();
369 bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView,
370 const TopoDS_Shape& theShape,
371 double& theX, double& theY) const
373 if (!theShape.IsNull()) {
374 if (theShape.ShapeType() == TopAbs_VERTEX) {
375 const TopoDS_Vertex& aVertex = TopoDS::Vertex(theShape);
376 if (!aVertex.IsNull()) {
377 // A case when point is taken from existing vertex
378 gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
379 PartSet_Tools::convertTo2D(aPoint, mySketch, theView, theX, theY);
387 void PartSet_WidgetPoint2D::setConstraintWith(const ObjectPtr& theObject)
389 // Create point-edge coincedence
390 FeaturePtr aFeature = mySketch->addFeature(SketchPlugin_ConstraintCoincidence::ID());
391 std::shared_ptr<ModelAPI_Data> aData = aFeature->data();
393 std::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 = std::dynamic_pointer_cast<
394 ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
395 AttributePtr aThisAttr = feature()->data()->attribute(attributeID());
396 std::shared_ptr<GeomDataAPI_Point2D> aThisPoint =
397 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aThisAttr);
398 aRef1->setAttr(aThisPoint);
400 std::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 = std::dynamic_pointer_cast<
401 ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
402 aRef2->setObject(theObject);
407 void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
409 // the contex menu release by the right button should not be processed by this widget
410 if (theEvent->button() != Qt::LeftButton)
413 ModuleBase_ISelection* aSelection = myWorkshop->selection();
414 Handle(V3d_View) aView = theWnd->v3dView();
415 // TODO: This fragment doesn't work because bug in OCC Viewer. It can be used after fixing.
416 NCollection_List<TopoDS_Shape> aShapes;
417 std::list<ObjectPtr> aObjects;
418 aSelection->selectedShapes(aShapes, aObjects);
419 // if we have selection and use it
420 if (aShapes.Extent() > 0 && useSelectedShapes()) {
421 TopoDS_Shape aShape = aShapes.First();
422 ObjectPtr aObject = aObjects.front();
423 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aObject);
424 bool anExternal = false;
425 std::shared_ptr<SketchPlugin_Feature> aSPFeature;
426 if (aSelectedFeature.get() != NULL)
427 aSPFeature = std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
428 if ((!aSPFeature && !aShape.IsNull()) ||
429 (aSPFeature.get() && aSPFeature->isExternal())) {
431 ResultPtr aFixedObject = PartSet_Tools::findFixedObjectByExternal(aShape, aObject, mySketch);
432 if (!aFixedObject.get())
433 aFixedObject = PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch);
436 if (getPoint2d(aView, aShape, aX, aY) && isFeatureContainsPoint(myFeature, aX, aY)) {
437 // do not create a constraint to the point, which already used by the feature
438 // if the feature contains the point, focus is not switched
442 if (getPoint2d(aView, aShape, aX, aY))
445 setValueState(Stored); // in case of edge selection, Apply state should also be updated
446 bool anOrphanPoint = aShape.ShapeType() == TopAbs_VERTEX ||
447 isOrphanPoint(aSelectedFeature, mySketch, aX, aY);
449 anOrphanPoint = true; // we should not stop reentrant operation on external objects because
450 // they are not participate in the contour creation excepting external vertices
451 if (aShape.ShapeType() == TopAbs_VERTEX) {
452 FeaturePtr aFixedFeature = ModelAPI_Feature::feature(aFixedObject);
453 if (aFixedFeature.get() && aFixedFeature->getKind() == SketchPlugin_Point::ID()) {
454 anOrphanPoint = isOrphanPoint(aFixedFeature, mySketch, aX, aY, true);
459 setConstraintWith(aFixedObject);
460 // fignal updated should be flushed in order to visualize possible created external objects
461 // e.g. selection of trihedron axis when input end arc point
462 updateObject(feature());
465 emit vertexSelected(); // it stops the reentrant operation
467 emit focusOutWidget(this);
472 bool isProcessed = false;
473 if (getPoint2d(aView, aShape, aX, aY) && isFeatureContainsPoint(myFeature, aX, aY)) {
474 // when the point is selected, the coordinates of the point should be set into the attribute
475 // if the feature contains the point, focus is not switched
479 bool anOrphanPoint = isOrphanPoint(aSelectedFeature, mySketch, aX, aY);
480 // do not set a coincidence constraint in the attribute if the feature contains a point
481 // with the same coordinates. It is important for line creation in order to do not set
482 // the same constraints for the same points, oterwise the result line has zero length.
483 bool isAuxiliaryFeature = false;
484 if (getPoint2d(aView, aShape, aX, aY)) {
486 PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aX, aY);
488 else if (aShape.ShapeType() == TopAbs_EDGE) {
489 if (MyFeaturesForCoincedence.contains(myFeature->getKind().c_str())) {
490 setConstraintWith(aObject);
491 setValueState(Stored); // in case of edge selection, Apply state should also be updated
493 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(aObject);
494 std::string anAuxiliaryAttribute = SketchPlugin_SketchEntity::AUXILIARY_ID();
495 AttributeBooleanPtr anAuxiliaryAttr = std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(
496 anObjectFeature->data()->attribute(anAuxiliaryAttribute));
497 if (anAuxiliaryAttr.get())
498 isAuxiliaryFeature = anAuxiliaryAttr->value();
501 // it is important to perform updateObject() in order to the current value is
502 // processed by Sketch Solver. Test case: line is created from a previous point
503 // to some distance, but in the area of the highlighting of the point. Constraint
504 // coincidence is created, after the solver is performed, the distance between the
505 // points of the line becomes less than the tolerance. Validator of the line returns
506 // false, the line will be aborted, but sketch stays valid.
507 updateObject(feature());
508 if (!anOrphanPoint && !anExternal && !isAuxiliaryFeature)
509 emit vertexSelected();
510 emit focusOutWidget(this);
514 // End of Bug dependent fragment
516 // A case when point is taken from mouse event
517 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
519 PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, anY);
521 // if the feature contains the point, focus is not switched
522 if (!setPoint(aX, anY) || isFeatureContainsPoint(myFeature, aX, anY))
525 /// Start alternative code
526 //std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint = std::dynamic_pointer_cast<
527 // GeomDataAPI_Point2D>(feature()->data()->attribute(attributeID()));
528 //QList<FeaturePtr> aIgnore;
529 //aIgnore.append(feature());
531 //double aTolerance = aView->Convert(7);
532 //std::shared_ptr<GeomDataAPI_Point2D> aAttrPnt =
533 // PartSet_Tools::findAttributePoint(mySketch, aX, anY, aTolerance, aIgnore);
534 //if (aAttrPnt.get() != NULL) {
535 // aFeaturePoint->setValue(aAttrPnt->pnt());
536 // PartSet_Tools::createConstraint(mySketch, aAttrPnt, aFeaturePoint);
537 // emit vertexSelected();
539 /// End alternative code
540 emit focusOutWidget(this);
545 void PartSet_WidgetPoint2D::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
550 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
553 PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, anY);
554 if (myState != ModifiedInViewer)
556 // we need to block the value state change
557 bool isBlocked = blockValueState(true);
559 blockValueState(isBlocked);
560 setValueState(ModifiedInViewer);
563 double PartSet_WidgetPoint2D::x() const
565 return myXSpin->value();
568 double PartSet_WidgetPoint2D::y() const
570 return myYSpin->value();
574 bool PartSet_WidgetPoint2D::isFeatureContainsPoint(const FeaturePtr& theFeature,
575 double theX, double theY)
577 bool aPointIsFound = false;
579 if (feature()->getKind() != SketchPlugin_Line::ID())
580 return aPointIsFound;
582 AttributePtr aWidgetAttribute = myFeature->attribute(attributeID());
584 std::shared_ptr<GeomAPI_Pnt2d> aPnt2d =
585 std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY));
586 std::list<AttributePtr> anAttributes =
587 myFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
588 std::list<AttributePtr>::iterator anIter = anAttributes.begin();
589 for(; anIter != anAttributes.end() && !aPointIsFound; anIter++) {
590 AttributePoint2DPtr aPoint2DAttribute =
591 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIter);
592 if (aPoint2DAttribute == aWidgetAttribute)
594 if (aPoint2DAttribute.get() && aPoint2DAttribute->isInitialized()) {
595 aPointIsFound = aPoint2DAttribute->pnt()->isEqual(aPnt2d);
598 return aPointIsFound;
601 void PartSet_WidgetPoint2D::initializeValueByActivate()
605 /*void PartSet_WidgetPoint2D::onValuesChanged()
607 emit valuesChanged();
610 bool PartSet_WidgetPoint2D::processEnter()
612 bool isModified = getValueState() == ModifiedInPP;
614 bool isXModified = myXSpin->hasFocus();
615 emit valuesChanged();
617 myXSpin->selectAll();
619 myYSpin->selectAll();
624 bool PartSet_WidgetPoint2D::useSelectedShapes() const
629 bool PartSet_WidgetPoint2D::isOrphanPoint(const FeaturePtr& theFeature,
630 const CompositeFeaturePtr& theSketch,
631 double theX, double theY, const bool theSearchInResults)
633 bool anOrphanPoint = false;
634 if (theFeature.get()) {
635 std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
636 std::string aFeatureKind = theFeature->getKind();
637 if (aFeatureKind == SketchPlugin_Point::ID())
638 aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
639 theFeature->attribute(SketchPlugin_Point::COORD_ID()));
640 else if (aFeatureKind == SketchPlugin_Circle::ID())
641 aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
642 theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
644 else if (aFeatureKind == SketchPlugin_Arc::ID())
645 aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
646 theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
648 /// check that the geometry point with the given coordinates is the checked point
649 /// e.g. in arc the (x,y) point can not coicide to the center point and it automatically
650 /// means that this point is not an orphant one.
651 if (aPointAttr.get()) {
652 std::shared_ptr<GeomAPI_Pnt2d> aCheckedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
653 new GeomAPI_Pnt2d(theX, theY));
654 if (!aCheckedPoint->isEqual(aPointAttr->pnt()))
655 return anOrphanPoint;
658 if (aPointAttr.get()) {
659 std::shared_ptr<GeomAPI_Pnt2d> aPoint = aPointAttr->pnt();
660 // we need to find coincidence features in results also, because external object(point)
661 // uses refs to me in another feature.
662 FeaturePtr aCoincidence = PartSet_Tools::findFirstCoincidence(theFeature, aPoint, theSearchInResults);
663 anOrphanPoint = true;
664 // if there is at least one concident line to the point, the point is not an orphant
665 if (aCoincidence.get()) {
666 QList<FeaturePtr> aCoinsideLines;
667 PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines,
668 SketchPlugin_ConstraintCoincidence::ENTITY_A());
669 PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines,
670 SketchPlugin_ConstraintCoincidence::ENTITY_B());
671 QList<FeaturePtr>::const_iterator anIt = aCoinsideLines.begin(),
672 aLast = aCoinsideLines.end();
673 for (; anIt != aLast && anOrphanPoint; anIt++) {
674 anOrphanPoint = (*anIt)->getKind() != SketchPlugin_Line::ID();
679 return anOrphanPoint;