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>
10 #include <PartSet_SketcherReetntrantMgr.h>
12 #include <XGUI_Tools.h>
13 #include <XGUI_Workshop.h>
14 #include <XGUI_Displayer.h>
16 #include <ModuleBase_ParamSpinBox.h>
17 #include <ModuleBase_Tools.h>
18 #include <ModuleBase_IViewer.h>
19 #include <ModuleBase_IViewWindow.h>
20 #include <ModuleBase_ISelection.h>
21 #include <ModuleBase_ViewerPrs.h>
22 #include <ModuleBase_WidgetValidator.h>
23 #include <ModuleBase_LabelValue.h>
25 #include <Config_Keywords.h>
26 #include <Config_WidgetAPI.h>
28 #include <Events_Loop.h>
29 #include <ModelAPI_Events.h>
30 #include <ModelAPI_AttributeBoolean.h>
32 #include <ModelAPI_Feature.h>
33 #include <ModelAPI_Data.h>
34 #include <ModelAPI_Object.h>
35 #include <GeomDataAPI_Point2D.h>
36 #include <GeomAPI_Pnt2d.h>
38 #include <GeomAPI_ShapeExplorer.h>
39 #include <GeomAPI_Vertex.h>
41 #include <SketchPlugin_Feature.h>
42 #include <SketchPlugin_ConstraintCoincidence.h>
43 #include <SketchPlugin_Line.h>
44 #include <SketchPlugin_Arc.h>
45 #include <SketchPlugin_Circle.h>
46 #include <SketchPlugin_Point.h>
49 #include <QGridLayout>
52 #include <QMouseEvent>
53 #include <QApplication>
56 #include <TopoDS_Vertex.hxx>
57 #include <BRep_Tool.hxx>
62 const double MaxCoordinate = 1e12;
64 static QStringList MyFeaturesForCoincedence;
66 PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent,
67 ModuleBase_IWorkshop* theWorkshop,
68 const Config_WidgetAPI* theData)
69 : ModuleBase_ModelWidget(theParent, theData), myWorkshop(theWorkshop),
70 myValueIsCashed(false), myIsFeatureVisibleInCash(true),
71 myXValueInCash(0), myYValueInCash(0)
73 if (MyFeaturesForCoincedence.isEmpty()) {
74 MyFeaturesForCoincedence << SketchPlugin_Line::ID().c_str()
75 << SketchPlugin_Arc::ID().c_str()
76 << SketchPlugin_Point::ID().c_str()
77 << SketchPlugin_Circle::ID().c_str();
80 // the control should accept the focus, so the boolean flag is corrected to be true
81 myIsObligatory = true;
82 QString aPageName = QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME));
83 myGroupBox = new QGroupBox(aPageName, theParent);
84 myGroupBox->setFlat(false);
86 bool aAcceptVariables = theData->getBooleanAttribute(DOUBLE_WDG_ACCEPT_EXPRESSIONS, true);
88 QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
89 ModuleBase_Tools::adjustMargins(aGroupLay);
90 aGroupLay->setSpacing(2);
91 aGroupLay->setColumnStretch(1, 1);
93 QLabel* aLabel = new QLabel(myGroupBox);
95 myXSpin = new ModuleBase_LabelValue(myGroupBox, tr("X"));
96 //ModuleBase_ParamSpinBox(myGroupBox);
97 //myXSpin->setAcceptVariables(aAcceptVariables);
98 //myXSpin->setMinimum(-DBL_MAX);
99 //myXSpin->setMaximum(DBL_MAX);
100 //myXSpin->setToolTip(tr("X"));
101 aGroupLay->addWidget(myXSpin, 0, 1);
103 //connect(myXSpin, SIGNAL(textChanged(const QString&)), this, SIGNAL(valuesModified()));
104 //myXSpin->setValueEnabled(isValueEnabled());
107 //QLabel* aLabel = new QLabel(myGroupBox);
108 //aLabel->setText(tr("Y "));
109 //aGroupLay->addWidget(aLabel, 1, 0);
111 myYSpin = new ModuleBase_LabelValue(myGroupBox, tr("Y"));
112 //ModuleBase_ParamSpinBox(myGroupBox);
113 //myYSpin = new ModuleBase_ParamSpinBox(myGroupBox);
114 //myYSpin->setAcceptVariables(aAcceptVariables);
115 //myYSpin->setMinimum(-DBL_MAX);
116 //myYSpin->setMaximum(DBL_MAX);
117 //myYSpin->setToolTip(tr("Y"));
118 aGroupLay->addWidget(myYSpin, 1, 1);
120 //connect(myYSpin, SIGNAL(textChanged(const QString&)), this, SIGNAL(valuesModified()));
121 //myYSpin->setValueEnabled(isValueEnabled());
123 QVBoxLayout* aLayout = new QVBoxLayout(this);
124 ModuleBase_Tools::zeroMargins(aLayout);
125 aLayout->addWidget(myGroupBox);
128 myWidgetValidator = new ModuleBase_WidgetValidator(this, myWorkshop);
131 bool PartSet_WidgetPoint2D::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& theValue)
135 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
136 if (aModule->sketchReentranceMgr()->isInternalEditActive())
137 return true; /// when internal edit is started a new feature is created. I has not results, AIS
139 /// the selection is not possible if the current feature has no presentation for the current
140 /// attribute not in AIS not in results. If so, no object in current feature where make
141 /// coincidence, so selection is not necessary
142 bool aFoundPoint = false;
143 GeomShapePtr anAISShape;
144 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(myFeature);
147 anAIS = aPrs->getAISObject(anAIS);
149 anAISShape = anAIS->getShape();
152 const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = myFeature->results();
153 if (!anAISShape.get() && aResults.empty())
157 std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
158 std::shared_ptr<GeomDataAPI_Point2D> aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
159 aData->attribute(attributeID()));
160 std::shared_ptr<GeomAPI_Pnt2d> aPoint = aPointAttr->pnt();
161 if (anAISShape.get())
162 aFoundPoint = shapeContainsPoint(anAISShape, aPoint, mySketch);
164 /// analysis of results
165 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.cbegin();
166 for (; aRIter != aResults.cend() && !aFoundPoint; aRIter++) {
167 ResultPtr aResult = *aRIter;
168 if (aResult.get() && aResult->shape().get()) {
169 GeomShapePtr aShape = aResult->shape();
170 aFoundPoint = shapeContainsPoint(aShape, aPoint, mySketch);
176 bool PartSet_WidgetPoint2D::resetCustom()
179 if (!isUseReset() || isComputedDefault()
180 /*|| myXSpin->hasVariable() || myYSpin->hasVariable()*/) {
184 if (myValueIsCashed) {
185 // if the restored value should be hidden, aDone = true to set
186 // reset state for the widget in the parent
187 aDone = restoreCurentValue();
188 emit objectUpdated();
192 double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
193 // it is important to block the spin box control in order to do not through out the
194 // locking of the validating state.
195 myXSpin->setValue(isOk ? aDefValue : 0.0);
196 myYSpin->setValue(isOk ? aDefValue : 0.0);
198 //ModuleBase_Tools::setSpinValue(myXSpin, isOk ? aDefValue : 0.0);
199 //ModuleBase_Tools::setSpinValue(myYSpin, isOk ? aDefValue : 0.0);
207 PartSet_WidgetPoint2D::~PartSet_WidgetPoint2D()
211 bool PartSet_WidgetPoint2D::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,
212 const bool theToValidate)
215 if (theValues.empty())
218 ModuleBase_ViewerPrsPtr aValue = theValues.takeFirst();
219 GeomShapePtr aShape = aValue->shape();
220 if (aShape.get() && !aShape->isNull()) {
221 Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
223 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
224 if (getPoint2d(aView, aTDShape, aX, aY)) {
225 isDone = setPoint(aX, aY);
226 PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aX, aY);
232 void PartSet_WidgetPoint2D::selectContent()
234 // myXSpin->selectAll();
237 bool PartSet_WidgetPoint2D::setPoint(double theX, double theY)
239 if (fabs(theX) >= MaxCoordinate)
241 if (fabs(theY) >= MaxCoordinate)
244 myXSpin->setValue(theX);
245 myYSpin->setValue(theY);
247 //ModuleBase_Tools::setSpinValue(myXSpin, theX);
248 //ModuleBase_Tools::setSpinValue(myYSpin, theY);
254 bool PartSet_WidgetPoint2D::storeValueCustom()
256 std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
257 if (!aData) // can be on abort of sketcher element
259 std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
260 aData->attribute(attributeID()));
262 PartSet_WidgetPoint2D* that = (PartSet_WidgetPoint2D*) this;
263 bool isBlocked = that->blockSignals(true);
264 bool isImmutable = aPoint->setImmutable(true);
266 // if text is not empty then setValue will be ignored
267 // so we should set the text at first
268 //aPoint->setText(myXSpin->hasVariable() ? myXSpin->text().toStdString() : "",
269 // myYSpin->hasVariable() ? myYSpin->text().toStdString() : "");
270 //aPoint->setValue(!myXSpin->hasVariable() ? myXSpin->value() : aPoint->x(),
271 // !myYSpin->hasVariable() ? myYSpin->value() : aPoint->y());
272 aPoint->setValue(myXSpin->value(), myYSpin->value());
274 // after movement the solver will call the update event: optimization
275 moveObject(myFeature);
276 aPoint->setImmutable(isImmutable);
277 that->blockSignals(isBlocked);
282 bool PartSet_WidgetPoint2D::restoreValueCustom()
284 std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
285 std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
286 aData->attribute(attributeID()));
287 double aValueX = aPoint->isInitialized() ? aPoint->x() : 0.;
288 double aValueY = aPoint->isInitialized() ? aPoint->y() : 0.;
289 myXSpin->setValue(aValueX);
290 myYSpin->setValue(aValueY);
295 void PartSet_WidgetPoint2D::storeCurentValue()
297 // do not use cash if a variable is used
298 //if (myXSpin->hasVariable() || myYSpin->hasVariable())
301 myValueIsCashed = true;
302 myIsFeatureVisibleInCash = XGUI_Displayer::isVisible(
303 XGUI_Tools::workshop(myWorkshop)->displayer(), myFeature);
304 myXValueInCash = myXSpin->value();
305 myYValueInCash = myYSpin->value();
308 bool PartSet_WidgetPoint2D::restoreCurentValue()
310 bool aRestoredAndHidden = true;
312 bool isVisible = myIsFeatureVisibleInCash;
313 // fill the control widgets by the cashed value
315 myValueIsCashed = false;
316 myIsFeatureVisibleInCash = true;
317 myXSpin->setValue(myXValueInCash);
318 myYSpin->setValue(myYValueInCash);
319 //ModuleBase_Tools::setSpinValue(myXSpin, myXValueInCash);
320 //ModuleBase_Tools::setSpinValue(myYSpin, myYValueInCash);
322 // store value to the model
325 setValueState(Stored);
326 aRestoredAndHidden = false;
329 aRestoredAndHidden = true;
331 return aRestoredAndHidden;
334 QList<QWidget*> PartSet_WidgetPoint2D::getControls() const
336 QList<QWidget*> aControls;
337 aControls.append(myXSpin);
338 aControls.append(myYSpin);
343 void PartSet_WidgetPoint2D::activateCustom()
346 aModes << TopAbs_VERTEX;
347 aModes << TopAbs_EDGE;
348 myWorkshop->activateSubShapesSelection(aModes);
350 if (!isEditingMode()) {
351 FeaturePtr aFeature = feature();
352 if (aFeature.get() && aFeature->getKind() == SketchPlugin_Point::ID())
357 void PartSet_WidgetPoint2D::setHighlighted(bool isHighlighted)
361 void PartSet_WidgetPoint2D::deactivate()
363 // the value of the control should be stored to model if it was not
364 // initialized yet. It is important when we leave this control by Tab key.
365 // It should not be performed by the widget activation as the preview
366 // is visualized with default value. Line point is moved to origin.
367 AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
368 if (anAttribute && !anAttribute->isInitialized())
371 ModuleBase_ModelWidget::deactivate();
372 myWorkshop->deactivateSubShapesSelection();
375 bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView,
376 const TopoDS_Shape& theShape,
377 double& theX, double& theY) const
379 if (!theShape.IsNull()) {
380 if (theShape.ShapeType() == TopAbs_VERTEX) {
381 const TopoDS_Vertex& aVertex = TopoDS::Vertex(theShape);
382 if (!aVertex.IsNull()) {
383 // A case when point is taken from existing vertex
384 gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
385 PartSet_Tools::convertTo2D(aPoint, mySketch, theView, theX, theY);
393 bool PartSet_WidgetPoint2D::setConstraintWith(const ObjectPtr& theObject)
395 std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint;
396 if (feature()->isMacro()) {
397 AttributePtr aThisAttr = feature()->data()->attribute(attributeID());
398 std::shared_ptr<GeomDataAPI_Point2D> anAttrPoint =
399 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aThisAttr);
400 if (anAttrPoint.get()) {
401 // the macro feature will be removed after the operation is stopped, so we need to build
402 // coicidence to possible sub-features
403 aFeaturePoint = PartSet_Tools::findFirstEqualPointInArgumentFeatures(feature(),
408 AttributePtr aThisAttr = feature()->data()->attribute(attributeID());
409 aFeaturePoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aThisAttr);
411 if (!aFeaturePoint.get())
414 // Create point-edge coincedence
415 FeaturePtr aFeature = mySketch->addFeature(SketchPlugin_ConstraintCoincidence::ID());
416 std::shared_ptr<ModelAPI_Data> aData = aFeature->data();
418 std::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 = std::dynamic_pointer_cast<
419 ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
421 aRef1->setAttr(aFeaturePoint);
423 std::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 = std::dynamic_pointer_cast<
424 ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
425 aRef2->setObject(theObject);
427 // we need to flush created signal in order to coincidence is processed by solver
428 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
433 void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent)
435 // the contex menu release by the right button should not be processed by this widget
436 if (theEvent->button() != Qt::LeftButton)
439 ModuleBase_ISelection* aSelection = myWorkshop->selection();
440 Handle(V3d_View) aView = theWindow->v3dView();
442 QList<ModuleBase_ViewerPrsPtr> aList = aSelection->getSelected(ModuleBase_ISelection::Viewer);
443 ModuleBase_ViewerPrsPtr aFirstValue =
444 aList.size() > 0 ? aList.first() : ModuleBase_ViewerPrsPtr();
445 if (!aFirstValue.get() && myPreSelected.get()) {
446 aFirstValue = myPreSelected;
448 // if we have selection and use it
449 if (aFirstValue.get() && isValidSelectionCustom(aFirstValue) &&
450 aFirstValue->shape().get()) { /// Trihedron Axis may be selected, but shape is empty
451 GeomShapePtr aGeomShape = aFirstValue->shape();
452 TopoDS_Shape aShape = aGeomShape->impl<TopoDS_Shape>();
453 ObjectPtr aObject = aFirstValue->object();
455 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aObject);
456 bool anExternal = false;
457 std::shared_ptr<SketchPlugin_Feature> aSPFeature;
458 if (aSelectedFeature.get() != NULL)
459 aSPFeature = std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
461 ResultPtr aFixedObject;
462 bool aSketchExternalFeature = aSPFeature.get() && aSPFeature->isExternal();
463 if ((!aSPFeature && !aShape.IsNull()) || aSketchExternalFeature) {
464 aFixedObject = PartSet_Tools::findFixedObjectByExternal(aShape, aObject, mySketch);
465 if (aSketchExternalFeature && !aFixedObject.get()) {/// local selection on external feature
470 if (!aFixedObject.get())
471 aFixedObject = PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch);
476 if (getPoint2d(aView, aShape, aX, aY) && isFeatureContainsPoint(myFeature, aX, aY)) {
477 // do not create a constraint to the point, which already used by the feature
478 // if the feature contains the point, focus is not switched
482 if (getPoint2d(aView, aShape, aX, aY))
485 setValueState(Stored); // in case of edge selection, Apply state should also be updated
486 bool anOrphanPoint = aShape.ShapeType() == TopAbs_VERTEX ||
487 isOrphanPoint(aSelectedFeature, mySketch, aX, aY);
489 // we should not stop reentrant operation on external objects because
490 anOrphanPoint = true;
491 // they are not participate in the contour creation excepting external vertices
492 if (aShape.ShapeType() == TopAbs_VERTEX) {
493 FeaturePtr aFixedFeature = ModelAPI_Feature::feature(aFixedObject);
494 if (aFixedFeature.get() && aFixedFeature->getKind() == SketchPlugin_Point::ID()) {
495 anOrphanPoint = isOrphanPoint(aFixedFeature, mySketch, aX, aY);
499 if (aFixedObject.get())
500 setConstraintWith(aFixedObject);
501 // fignal updated should be flushed in order to visualize possible created
502 // external objects e.g. selection of trihedron axis when input end arc point
503 updateObject(feature());
506 emit vertexSelected(); // it stops the reentrant operation
508 emit focusOutWidget(this);
513 bool isProcessed = false;
514 if (getPoint2d(aView, aShape, aX, aY) && isFeatureContainsPoint(myFeature, aX, aY)) {
515 // when the point is selected, the coordinates of the point should be set into the attribute
516 // if the feature contains the point, focus is not switched
520 bool anOrphanPoint = isOrphanPoint(aSelectedFeature, mySketch, aX, aY);
521 // do not set a coincidence constraint in the attribute if the feature contains a point
522 // with the same coordinates. It is important for line creation in order to do not set
523 // the same constraints for the same points, oterwise the result line has zero length.
524 bool isAuxiliaryFeature = false;
525 if (getPoint2d(aView, aShape, aX, aY)) {
527 feature()->execute();
528 PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aX, aY);
530 else if (aShape.ShapeType() == TopAbs_EDGE) {
531 // point is taken from mouse event and set in attribute. It should be done before setting
532 // coinident constraint to the external line. If a point is created, it should be in
533 // the mouse clicked point
534 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView());
535 PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, aY);
537 setConstraintWith(aObject);
538 setValueState(Stored); // in case of edge selection, Apply state should also be updated
539 isAuxiliaryFeature = PartSet_Tools::isAuxiliarySketchEntity(aObject);
541 // it is important to perform updateObject() in order to the current value is
542 // processed by Sketch Solver. Test case: line is created from a previous point
543 // to some distance, but in the area of the highlighting of the point. Constraint
544 // coincidence is created, after the solver is performed, the distance between the
545 // points of the line becomes less than the tolerance. Validator of the line returns
546 // false, the line will be aborted, but sketch stays valid.
547 updateObject(feature());
548 if (!anOrphanPoint && !anExternal && !isAuxiliaryFeature)
549 emit vertexSelected();
550 emit focusOutWidget(this);
554 // End of Bug dependent fragment
556 // A case when point is taken from mouse event
557 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView());
559 PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, anY);
561 // if the feature contains the point, focus is not switched
562 if (!setPoint(aX, anY) || isFeatureContainsPoint(myFeature, aX, anY))
565 /// Start alternative code
566 //std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint = std::dynamic_pointer_cast<
567 // GeomDataAPI_Point2D>(feature()->data()->attribute(attributeID()));
568 //QList<FeaturePtr> aIgnore;
569 //aIgnore.append(feature());
571 //double aTolerance = aView->Convert(7);
572 //std::shared_ptr<GeomDataAPI_Point2D> aAttrPnt =
573 // PartSet_Tools::findAttributePoint(mySketch, aX, anY, aTolerance, aIgnore);
574 //if (aAttrPnt.get() != NULL) {
575 // aFeaturePoint->setValue(aAttrPnt->pnt());
576 // PartSet_Tools::createConstraint(mySketch, aAttrPnt, aFeaturePoint);
577 // emit vertexSelected();
579 /// End alternative code
580 emit focusOutWidget(this);
584 void PartSet_WidgetPoint2D::setPreSelection(
585 const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected)
587 myPreSelected = thePreSelected;
590 void PartSet_WidgetPoint2D::mouseMoved(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent)
592 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
594 if (isEditingMode() || aModule->sketchReentranceMgr()->isInternalEditStarted())
597 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView());
600 PartSet_Tools::convertTo2D(aPoint, mySketch, theWindow->v3dView(), aX, anY);
601 if (myState != ModifiedInViewer)
603 // we need to block the value state change
604 bool isBlocked = blockValueState(true);
606 blockValueState(isBlocked);
607 setValueState(ModifiedInViewer);
610 double PartSet_WidgetPoint2D::x() const
612 return myXSpin->value();
615 double PartSet_WidgetPoint2D::y() const
617 return myYSpin->value();
621 bool PartSet_WidgetPoint2D::isFeatureContainsPoint(const FeaturePtr& theFeature,
622 double theX, double theY)
624 bool aPointIsFound = false;
626 if (feature()->getKind() != SketchPlugin_Line::ID())
627 return aPointIsFound;
629 AttributePtr aWidgetAttribute = myFeature->attribute(attributeID());
631 std::shared_ptr<GeomAPI_Pnt2d> aPnt2d =
632 std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY));
633 std::list<AttributePtr> anAttributes =
634 myFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
635 std::list<AttributePtr>::iterator anIter = anAttributes.begin();
636 for(; anIter != anAttributes.end() && !aPointIsFound; anIter++) {
637 AttributePoint2DPtr aPoint2DAttribute =
638 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIter);
639 if (aPoint2DAttribute == aWidgetAttribute)
641 if (aPoint2DAttribute.get() && aPoint2DAttribute->isInitialized()) {
642 aPointIsFound = aPoint2DAttribute->pnt()->isEqual(aPnt2d);
645 return aPointIsFound;
648 void PartSet_WidgetPoint2D::initializeValueByActivate()
652 /*void PartSet_WidgetPoint2D::onValuesChanged()
654 emit valuesChanged();
657 bool PartSet_WidgetPoint2D::processEnter()
660 /*bool isModified = getValueState() == ModifiedInPP;
662 bool isXModified = myXSpin->hasFocus();
663 emit valuesChanged();
665 myXSpin->selectAll();
667 myYSpin->selectAll();
672 bool PartSet_WidgetPoint2D::useSelectedShapes() const
677 bool PartSet_WidgetPoint2D::isOrphanPoint(const FeaturePtr& theFeature,
678 const CompositeFeaturePtr& theSketch,
679 double theX, double theY)
681 bool anOrphanPoint = false;
682 if (theFeature.get()) {
683 std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
684 std::string aFeatureKind = theFeature->getKind();
685 if (aFeatureKind == SketchPlugin_Point::ID())
686 aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
687 theFeature->attribute(SketchPlugin_Point::COORD_ID()));
688 else if (aFeatureKind == SketchPlugin_Circle::ID())
689 aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
690 theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
692 else if (aFeatureKind == SketchPlugin_Arc::ID())
693 aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
694 theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
696 /// check that the geometry point with the given coordinates is the checked point
697 /// e.g. in arc the (x,y) point can not coicide to the center point and it automatically
698 /// means that this point is not an orphant one.
699 if (aPointAttr.get()) {
700 std::shared_ptr<GeomAPI_Pnt2d> aCheckedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
701 new GeomAPI_Pnt2d(theX, theY));
702 if (!aCheckedPoint->isEqual(aPointAttr->pnt()))
703 return anOrphanPoint;
706 if (aPointAttr.get()) {
707 std::shared_ptr<GeomAPI_Pnt2d> aPoint = aPointAttr->pnt();
708 // we need to find coincidence features in results also, because external object(point)
709 // uses refs to me in another feature.
710 FeaturePtr aCoincidence = PartSet_Tools::findFirstCoincidence(theFeature, aPoint);
711 anOrphanPoint = true;
712 // if there is at least one concident line to the point, the point is not an orphant
713 if (aCoincidence.get()) {
714 QList<FeaturePtr> aCoinsideLines;
715 QList<FeaturePtr> aCoins;
716 PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines, aCoins,
717 SketchPlugin_ConstraintCoincidence::ENTITY_A());
718 PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines, aCoins,
719 SketchPlugin_ConstraintCoincidence::ENTITY_B());
720 QList<FeaturePtr>::const_iterator anIt = aCoinsideLines.begin(),
721 aLast = aCoinsideLines.end();
722 for (; anIt != aLast && anOrphanPoint; anIt++) {
723 anOrphanPoint = (*anIt)->getKind() != SketchPlugin_Line::ID();
728 return anOrphanPoint;
731 bool PartSet_WidgetPoint2D::shapeContainsPoint(const GeomShapePtr& theShape,
732 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint,
733 const CompositeFeaturePtr& theSketch)
735 std::shared_ptr<GeomAPI_Pnt> aPoint = PartSet_Tools::point3D(thePoint, theSketch);
737 bool aContainPoint = false;
738 GeomAPI_ShapeExplorer anExp(theShape, GeomAPI_Shape::VERTEX);
739 for(; anExp.more() && !aContainPoint; anExp.next()) {
740 std::shared_ptr<GeomAPI_Shape> aVertexInCompSolid = anExp.current();
741 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aVertexInCompSolid));
743 aContainPoint = aPoint->isEqual(aVertex->point());
745 return aContainPoint;