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>
24 #include <Config_Keywords.h>
25 #include <Config_WidgetAPI.h>
27 #include <Events_Loop.h>
28 #include <ModelAPI_Events.h>
29 #include <ModelAPI_AttributeBoolean.h>
31 #include <ModelAPI_Feature.h>
32 #include <ModelAPI_Data.h>
33 #include <ModelAPI_Object.h>
34 #include <GeomDataAPI_Point2D.h>
35 #include <GeomAPI_Pnt2d.h>
37 #include <GeomAPI_ShapeExplorer.h>
38 #include <GeomAPI_Vertex.h>
40 #include <SketchPlugin_Feature.h>
41 #include <SketchPlugin_ConstraintCoincidence.h>
42 #include <SketchPlugin_Line.h>
43 #include <SketchPlugin_Arc.h>
44 #include <SketchPlugin_Circle.h>
45 #include <SketchPlugin_Point.h>
48 #include <QGridLayout>
51 #include <QMouseEvent>
52 #include <QApplication>
55 #include <TopoDS_Vertex.hxx>
56 #include <BRep_Tool.hxx>
61 const double MaxCoordinate = 1e12;
63 static QStringList MyFeaturesForCoincedence;
65 PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent,
66 ModuleBase_IWorkshop* theWorkshop,
67 const Config_WidgetAPI* theData)
68 : ModuleBase_ModelWidget(theParent, theData), myWorkshop(theWorkshop),
69 myValueIsCashed(false), myIsFeatureVisibleInCash(true),
70 myXValueInCash(0), myYValueInCash(0)
72 if (MyFeaturesForCoincedence.isEmpty()) {
73 MyFeaturesForCoincedence << SketchPlugin_Line::ID().c_str()
74 << SketchPlugin_Arc::ID().c_str()
75 << SketchPlugin_Point::ID().c_str()
76 << SketchPlugin_Circle::ID().c_str();
79 // the control should accept the focus, so the boolean flag is corrected to be true
80 myIsObligatory = true;
81 QString aPageName = QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME));
82 myGroupBox = new QGroupBox(aPageName, theParent);
83 myGroupBox->setFlat(false);
85 bool aAcceptVariables = theData->getBooleanAttribute(DOUBLE_WDG_ACCEPT_EXPRESSIONS, true);
87 QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
88 ModuleBase_Tools::adjustMargins(aGroupLay);
89 aGroupLay->setSpacing(2);
90 aGroupLay->setColumnStretch(1, 1);
92 QLabel* aLabel = new QLabel(myGroupBox);
93 aLabel->setText(tr("X "));
94 aGroupLay->addWidget(aLabel, 0, 0);
96 myXSpin = new 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(valueChanged(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_ParamSpinBox(myGroupBox);
112 myYSpin->setAcceptVariables(aAcceptVariables);
113 myYSpin->setMinimum(-DBL_MAX);
114 myYSpin->setMaximum(DBL_MAX);
115 myYSpin->setToolTip(tr("Y"));
116 aGroupLay->addWidget(myYSpin, 1, 1);
118 connect(myYSpin, SIGNAL(valueChanged(const QString&)), this, SIGNAL(valuesModified()));
119 myYSpin->setValueEnabled(isValueEnabled());
121 QVBoxLayout* aLayout = new QVBoxLayout(this);
122 ModuleBase_Tools::zeroMargins(aLayout);
123 aLayout->addWidget(myGroupBox);
126 myWidgetValidator = new ModuleBase_WidgetValidator(this, myWorkshop);
129 bool PartSet_WidgetPoint2D::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& theValue)
133 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
134 if (aModule->sketchReentranceMgr()->isInternalEditActive())
135 return true; /// when internal edit is started a new feature is created. I has not results, AIS
137 /// the selection is not possible if the current feature has no presentation for the current
138 /// attribute not in AIS not in results. If so, no object in current feature where make
139 /// coincidence, so selection is not necessary
140 std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
141 std::shared_ptr<GeomDataAPI_Point2D> aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
142 aData->attribute(attributeID()));
143 std::shared_ptr<GeomAPI_Pnt2d> aPoint = aPointAttr->pnt();
145 bool aFoundPoint = false;
146 GeomShapePtr anAISShape;
147 GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(myFeature);
150 anAIS = aPrs->getAISObject(anAIS);
152 anAISShape = anAIS->getShape();
155 const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = myFeature->results();
156 if (!anAISShape.get() && aResults.empty())
160 if (anAISShape.get())
161 aFoundPoint = shapeContainsPoint(anAISShape, aPoint, mySketch);
163 /// analysis of results
164 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.cbegin();
165 for (; aRIter != aResults.cend() && !aFoundPoint; aRIter++) {
166 ResultPtr aResult = *aRIter;
167 if (aResult.get() && aResult->shape().get()) {
168 GeomShapePtr aShape = aResult->shape();
169 aFoundPoint = shapeContainsPoint(aShape, aPoint, mySketch);
175 bool PartSet_WidgetPoint2D::resetCustom()
178 if (!isUseReset() || isComputedDefault() || myXSpin->hasVariable() || myYSpin->hasVariable()) {
182 if (myValueIsCashed) {
183 // if the restored value should be hidden, aDone = true to set
184 // reset state for the widget in the parent
185 aDone = restoreCurentValue();
186 emit objectUpdated();
190 double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
191 // it is important to block the spin box control in order to do not through out the
192 // locking of the validating state.
193 ModuleBase_Tools::setSpinValue(myXSpin, isOk ? aDefValue : 0.0);
194 ModuleBase_Tools::setSpinValue(myYSpin, isOk ? aDefValue : 0.0);
202 PartSet_WidgetPoint2D::~PartSet_WidgetPoint2D()
206 bool PartSet_WidgetPoint2D::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,
207 const bool theToValidate)
210 if (theValues.empty())
213 ModuleBase_ViewerPrsPtr aValue = theValues.takeFirst();
214 GeomShapePtr aShape = aValue->shape();
215 if (aShape.get() && !aShape->isNull()) {
216 Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
218 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
219 if (getPoint2d(aView, aTDShape, aX, aY)) {
220 isDone = setPoint(aX, aY);
221 PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aX, aY);
227 void PartSet_WidgetPoint2D::selectContent()
229 myXSpin->selectAll();
232 bool PartSet_WidgetPoint2D::setPoint(double theX, double theY)
234 if (fabs(theX) >= MaxCoordinate)
236 if (fabs(theY) >= MaxCoordinate)
239 ModuleBase_Tools::setSpinValue(myXSpin, theX);
240 ModuleBase_Tools::setSpinValue(myYSpin, theY);
246 bool PartSet_WidgetPoint2D::storeValueCustom()
248 std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
249 if (!aData) // can be on abort of sketcher element
251 std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
252 aData->attribute(attributeID()));
254 PartSet_WidgetPoint2D* that = (PartSet_WidgetPoint2D*) this;
255 bool isBlocked = that->blockSignals(true);
256 bool isImmutable = aPoint->setImmutable(true);
258 // if text is not empty then setValue will be ignored
259 // so we should set the text at first
260 aPoint->setText(myXSpin->hasVariable() ? myXSpin->text().toStdString() : "",
261 myYSpin->hasVariable() ? myYSpin->text().toStdString() : "");
262 aPoint->setValue(!myXSpin->hasVariable() ? myXSpin->value() : aPoint->x(),
263 !myYSpin->hasVariable() ? myYSpin->value() : aPoint->y());
265 // after movement the solver will call the update event: optimization
266 moveObject(myFeature);
267 aPoint->setImmutable(isImmutable);
268 that->blockSignals(isBlocked);
273 bool PartSet_WidgetPoint2D::restoreValueCustom()
275 std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
276 std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
277 aData->attribute(attributeID()));
278 QString aTextX = QString::fromStdString(aPoint->textX());
279 QString aTextY = QString::fromStdString(aPoint->textY());
281 bool isDouble = false;
283 if (aTextX.isEmpty()) {
284 ModuleBase_Tools::setSpinValue(myXSpin, aPoint->x());
286 aVal = aTextX.toDouble(&isDouble);
288 ModuleBase_Tools::setSpinValue(myXSpin, aVal);
290 ModuleBase_Tools::setSpinText(myXSpin, aTextX);
292 if (aTextY.isEmpty()) {
293 ModuleBase_Tools::setSpinValue(myYSpin, aPoint->y());
295 aVal = aTextY.toDouble(&isDouble);
297 ModuleBase_Tools::setSpinValue(myYSpin, aVal);
299 ModuleBase_Tools::setSpinText(myYSpin, aTextY);
301 //if (aTextX.empty() || aTextY.empty()) {
302 // ModuleBase_Tools::setSpinValue(myXSpin, aPoint->x());
303 // ModuleBase_Tools::setSpinValue(myYSpin, aPoint->y());
305 // ModuleBase_Tools::setSpinText(myXSpin, QString::fromStdString(aTextX));
306 // ModuleBase_Tools::setSpinText(myYSpin, QString::fromStdString(aTextY));
311 void PartSet_WidgetPoint2D::storeCurentValue()
313 // do not use cash if a variable is used
314 if (myXSpin->hasVariable() || myYSpin->hasVariable())
317 myValueIsCashed = true;
318 myIsFeatureVisibleInCash = XGUI_Displayer::isVisible(
319 XGUI_Tools::workshop(myWorkshop)->displayer(), myFeature);
320 myXValueInCash = myXSpin->value();
321 myYValueInCash = myYSpin->value();
324 bool PartSet_WidgetPoint2D::restoreCurentValue()
326 bool aRestoredAndHidden = true;
328 bool isVisible = myIsFeatureVisibleInCash;
329 // fill the control widgets by the cashed value
331 myValueIsCashed = false;
332 myIsFeatureVisibleInCash = true;
333 ModuleBase_Tools::setSpinValue(myXSpin, myXValueInCash);
334 ModuleBase_Tools::setSpinValue(myYSpin, myYValueInCash);
336 // store value to the model
339 setValueState(Stored);
340 aRestoredAndHidden = false;
343 aRestoredAndHidden = true;
345 return aRestoredAndHidden;
348 QList<QWidget*> PartSet_WidgetPoint2D::getControls() const
350 QList<QWidget*> aControls;
351 aControls.append(myXSpin);
352 aControls.append(myYSpin);
357 void PartSet_WidgetPoint2D::activateCustom()
360 aModes << TopAbs_VERTEX;
361 aModes << TopAbs_EDGE;
362 myWorkshop->activateSubShapesSelection(aModes);
364 if (!isEditingMode()) {
365 FeaturePtr aFeature = feature();
366 if (aFeature.get() && aFeature->getKind() == SketchPlugin_Point::ID())
371 void PartSet_WidgetPoint2D::deactivate()
373 // the value of the control should be stored to model if it was not
374 // initialized yet. It is important when we leave this control by Tab key.
375 // It should not be performed by the widget activation as the preview
376 // is visualized with default value. Line point is moved to origin.
377 AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
378 if (anAttribute && !anAttribute->isInitialized())
381 ModuleBase_ModelWidget::deactivate();
382 myWorkshop->deactivateSubShapesSelection();
385 bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView,
386 const TopoDS_Shape& theShape,
387 double& theX, double& theY) const
389 if (!theShape.IsNull()) {
390 if (theShape.ShapeType() == TopAbs_VERTEX) {
391 const TopoDS_Vertex& aVertex = TopoDS::Vertex(theShape);
392 if (!aVertex.IsNull()) {
393 // A case when point is taken from existing vertex
394 gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
395 PartSet_Tools::convertTo2D(aPoint, mySketch, theView, theX, theY);
403 bool PartSet_WidgetPoint2D::setConstraintWith(const ObjectPtr& theObject)
405 std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint;
406 if (feature()->isMacro()) {
407 AttributePtr aThisAttr = feature()->data()->attribute(attributeID());
408 std::shared_ptr<GeomDataAPI_Point2D> anAttrPoint =
409 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aThisAttr);
410 if (anAttrPoint.get()) {
411 // the macro feature will be removed after the operation is stopped, so we need to build
412 // coicidence to possible sub-features
413 aFeaturePoint = PartSet_Tools::findFirstEqualPointInArgumentFeatures(feature(),
418 AttributePtr aThisAttr = feature()->data()->attribute(attributeID());
419 aFeaturePoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aThisAttr);
421 if (!aFeaturePoint.get())
424 // Create point-edge coincedence
425 FeaturePtr aFeature = mySketch->addFeature(SketchPlugin_ConstraintCoincidence::ID());
426 std::shared_ptr<ModelAPI_Data> aData = aFeature->data();
428 std::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 = std::dynamic_pointer_cast<
429 ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
431 aRef1->setAttr(aFeaturePoint);
433 std::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 = std::dynamic_pointer_cast<
434 ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
435 aRef2->setObject(theObject);
437 // we need to flush created signal in order to coincidence is processed by solver
438 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
443 void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent)
445 // the contex menu release by the right button should not be processed by this widget
446 if (theEvent->button() != Qt::LeftButton)
449 ModuleBase_ISelection* aSelection = myWorkshop->selection();
450 Handle(V3d_View) aView = theWindow->v3dView();
452 QList<ModuleBase_ViewerPrsPtr> aList = aSelection->getSelected(ModuleBase_ISelection::Viewer);
453 ModuleBase_ViewerPrsPtr aFirstValue = aList.size() > 0 ? aList.first() : ModuleBase_ViewerPrsPtr();
454 // if we have selection and use it
455 if (aFirstValue.get() && isValidSelectionCustom(aFirstValue)) {
456 GeomShapePtr aGeomShape = aFirstValue->shape();
457 TopoDS_Shape aShape = aGeomShape->impl<TopoDS_Shape>();
458 ObjectPtr aObject = aFirstValue->object();
460 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aObject);
461 bool anExternal = false;
462 std::shared_ptr<SketchPlugin_Feature> aSPFeature;
463 if (aSelectedFeature.get() != NULL)
464 aSPFeature = std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
465 if ((!aSPFeature && !aShape.IsNull()) ||
466 (aSPFeature.get() && aSPFeature->isExternal())) {
467 ResultPtr aFixedObject;
469 aFixedObject = PartSet_Tools::findFixedObjectByExternal(aShape, aObject, mySketch);
470 if (!aFixedObject.get())
471 aFixedObject = PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch);
473 if (getPoint2d(aView, aShape, aX, aY) && isFeatureContainsPoint(myFeature, aX, aY)) {
474 // do not create a constraint to the point, which already used by the feature
475 // if the feature contains the point, focus is not switched
479 if (getPoint2d(aView, aShape, aX, aY))
482 setValueState(Stored); // in case of edge selection, Apply state should also be updated
483 bool anOrphanPoint = aShape.ShapeType() == TopAbs_VERTEX ||
484 isOrphanPoint(aSelectedFeature, mySketch, aX, aY);
486 anOrphanPoint = true; // we should not stop reentrant operation on external objects because
487 // they are not participate in the contour creation excepting external vertices
488 if (aShape.ShapeType() == TopAbs_VERTEX) {
489 FeaturePtr aFixedFeature = ModelAPI_Feature::feature(aFixedObject);
490 if (aFixedFeature.get() && aFixedFeature->getKind() == SketchPlugin_Point::ID()) {
491 anOrphanPoint = isOrphanPoint(aFixedFeature, mySketch, aX, aY);
495 // point is taken from mouse event and set in attribute. It should be done before setting
496 // coinident constraint to the external line. If a point is created, it should be in the mouse
498 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView());
500 PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, anY);
504 if (aFixedObject.get())
505 setConstraintWith(aFixedObject);
506 // fignal updated should be flushed in order to visualize possible created external objects
507 // e.g. selection of trihedron axis when input end arc point
508 updateObject(feature());
511 emit vertexSelected(); // it stops the reentrant operation
513 emit focusOutWidget(this);
518 bool isProcessed = false;
519 if (getPoint2d(aView, aShape, aX, aY) && isFeatureContainsPoint(myFeature, aX, aY)) {
520 // when the point is selected, the coordinates of the point should be set into the attribute
521 // if the feature contains the point, focus is not switched
525 bool anOrphanPoint = isOrphanPoint(aSelectedFeature, mySketch, aX, aY);
526 // do not set a coincidence constraint in the attribute if the feature contains a point
527 // with the same coordinates. It is important for line creation in order to do not set
528 // the same constraints for the same points, oterwise the result line has zero length.
529 bool isAuxiliaryFeature = false;
530 if (getPoint2d(aView, aShape, aX, aY)) {
532 feature()->execute();
533 PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aX, aY);
535 else if (aShape.ShapeType() == TopAbs_EDGE) {
536 // point is taken from mouse event and set in attribute. It should be done before setting
537 // coinident constraint to the external line. If a point is created, it should be in the mouse
539 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView());
540 PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, aY);
542 setConstraintWith(aObject);
543 setValueState(Stored); // in case of edge selection, Apply state should also be updated
544 isAuxiliaryFeature = PartSet_Tools::isAuxiliarySketchEntity(aObject);
546 // it is important to perform updateObject() in order to the current value is
547 // processed by Sketch Solver. Test case: line is created from a previous point
548 // to some distance, but in the area of the highlighting of the point. Constraint
549 // coincidence is created, after the solver is performed, the distance between the
550 // points of the line becomes less than the tolerance. Validator of the line returns
551 // false, the line will be aborted, but sketch stays valid.
552 updateObject(feature());
553 if (!anOrphanPoint && !anExternal && !isAuxiliaryFeature)
554 emit vertexSelected();
555 emit focusOutWidget(this);
559 // End of Bug dependent fragment
561 // A case when point is taken from mouse event
562 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView());
564 PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, anY);
566 // if the feature contains the point, focus is not switched
567 if (!setPoint(aX, anY) || isFeatureContainsPoint(myFeature, aX, anY))
570 /// Start alternative code
571 //std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint = std::dynamic_pointer_cast<
572 // GeomDataAPI_Point2D>(feature()->data()->attribute(attributeID()));
573 //QList<FeaturePtr> aIgnore;
574 //aIgnore.append(feature());
576 //double aTolerance = aView->Convert(7);
577 //std::shared_ptr<GeomDataAPI_Point2D> aAttrPnt =
578 // PartSet_Tools::findAttributePoint(mySketch, aX, anY, aTolerance, aIgnore);
579 //if (aAttrPnt.get() != NULL) {
580 // aFeaturePoint->setValue(aAttrPnt->pnt());
581 // PartSet_Tools::createConstraint(mySketch, aAttrPnt, aFeaturePoint);
582 // emit vertexSelected();
584 /// End alternative code
585 emit focusOutWidget(this);
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()
659 bool isModified = getValueState() == ModifiedInPP;
661 bool isXModified = myXSpin->hasFocus();
662 emit valuesChanged();
664 myXSpin->selectAll();
666 myYSpin->selectAll();
671 bool PartSet_WidgetPoint2D::useSelectedShapes() const
676 bool PartSet_WidgetPoint2D::isOrphanPoint(const FeaturePtr& theFeature,
677 const CompositeFeaturePtr& theSketch,
678 double theX, double theY)
680 bool anOrphanPoint = false;
681 if (theFeature.get()) {
682 std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
683 std::string aFeatureKind = theFeature->getKind();
684 if (aFeatureKind == SketchPlugin_Point::ID())
685 aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
686 theFeature->attribute(SketchPlugin_Point::COORD_ID()));
687 else if (aFeatureKind == SketchPlugin_Circle::ID())
688 aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
689 theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
691 else if (aFeatureKind == SketchPlugin_Arc::ID())
692 aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
693 theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
695 /// check that the geometry point with the given coordinates is the checked point
696 /// e.g. in arc the (x,y) point can not coicide to the center point and it automatically
697 /// means that this point is not an orphant one.
698 if (aPointAttr.get()) {
699 std::shared_ptr<GeomAPI_Pnt2d> aCheckedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
700 new GeomAPI_Pnt2d(theX, theY));
701 if (!aCheckedPoint->isEqual(aPointAttr->pnt()))
702 return anOrphanPoint;
705 if (aPointAttr.get()) {
706 std::shared_ptr<GeomAPI_Pnt2d> aPoint = aPointAttr->pnt();
707 // we need to find coincidence features in results also, because external object(point)
708 // uses refs to me in another feature.
709 FeaturePtr aCoincidence = PartSet_Tools::findFirstCoincidence(theFeature, aPoint);
710 anOrphanPoint = true;
711 // if there is at least one concident line to the point, the point is not an orphant
712 if (aCoincidence.get()) {
713 QList<FeaturePtr> aCoinsideLines;
714 QList<FeaturePtr> aCoins;
715 PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines, aCoins,
716 SketchPlugin_ConstraintCoincidence::ENTITY_A());
717 PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines, aCoins,
718 SketchPlugin_ConstraintCoincidence::ENTITY_B());
719 QList<FeaturePtr>::const_iterator anIt = aCoinsideLines.begin(),
720 aLast = aCoinsideLines.end();
721 for (; anIt != aLast && anOrphanPoint; anIt++) {
722 anOrphanPoint = (*anIt)->getKind() != SketchPlugin_Line::ID();
727 return anOrphanPoint;
730 bool PartSet_WidgetPoint2D::shapeContainsPoint(const GeomShapePtr& theShape,
731 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint,
732 const CompositeFeaturePtr& theSketch)
734 std::shared_ptr<GeomAPI_Pnt> aPoint = PartSet_Tools::point3D(thePoint, theSketch);
736 bool aContainPoint = false;
737 GeomAPI_ShapeExplorer anExp(theShape, GeomAPI_Shape::VERTEX);
738 for(; anExp.more() && !aContainPoint; anExp.next()) {
739 std::shared_ptr<GeomAPI_Shape> aVertexInCompSolid = anExp.current();
740 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aVertexInCompSolid));
742 aContainPoint = aPoint->isEqual(aVertex->point());
744 return aContainPoint;