+ return isModified;*/
+}
+
+bool PartSet_WidgetPoint2D::useSelectedShapes() const
+{
+ return true;
+}
+
+bool PartSet_WidgetPoint2D::isOrphanPoint(const FeaturePtr& theFeature,
+ const CompositeFeaturePtr& theSketch,
+ double theX, double theY)
+{
+ bool anOrphanPoint = false;
+ if (theFeature.get()) {
+ AttributePoint2DPtr aPointAttr;
+ std::string aFeatureKind = theFeature->getKind();
+ if (aFeatureKind == SketchPlugin_Point::ID())
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ theFeature->attribute(SketchPlugin_Point::COORD_ID()));
+ else if (aFeatureKind == SketchPlugin_Circle::ID())
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
+
+ else if (aFeatureKind == SketchPlugin_Arc::ID())
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
+
+ /// check that the geometry point with the given coordinates is the checked point
+ /// e.g. in arc the (x,y) point can not coicide to the center point and it automatically
+ /// means that this point is not an orphant one.
+ if (aPointAttr.get()) {
+ std::shared_ptr<GeomAPI_Pnt2d> aCheckedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
+ new GeomAPI_Pnt2d(theX, theY));
+ if (!aCheckedPoint->isEqual(aPointAttr->pnt()))
+ return anOrphanPoint;
+ }
+
+ if (aPointAttr.get()) {
+ std::shared_ptr<GeomAPI_Pnt2d> aPoint = aPointAttr->pnt();
+ // we need to find coincidence features in results also, because external object(point)
+ // uses refs to me in another feature.
+ FeaturePtr aCoincidence = PartSet_Tools::findFirstCoincidence(theFeature, aPoint);
+ anOrphanPoint = true;
+ // if there is at least one concident line to the point, the point is not an orphant
+ if (aCoincidence.get()) {
+ QList<FeaturePtr> aCoinsideLines;
+ QList<FeaturePtr> aCoins;
+ PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines, aCoins,
+ SketchPlugin_ConstraintCoincidence::ENTITY_A());
+ PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines, aCoins,
+ SketchPlugin_ConstraintCoincidence::ENTITY_B());
+ QList<FeaturePtr>::const_iterator anIt = aCoinsideLines.begin(),
+ aLast = aCoinsideLines.end();
+ for (; anIt != aLast && anOrphanPoint; anIt++) {
+ anOrphanPoint = (*anIt)->getKind() != SketchPlugin_Line::ID();
+ }
+ }
+ }
+ }
+ return anOrphanPoint;
+}
+
+bool PartSet_WidgetPoint2D::shapeExploreHasVertex(const GeomShapePtr& theShape,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint,
+ const CompositeFeaturePtr& theSketch)
+{
+ std::shared_ptr<GeomAPI_Pnt> aPoint = PartSet_Tools::point3D(thePoint, theSketch);
+
+ bool aContainPoint = false;
+ GeomAPI_ShapeExplorer anExp(theShape, GeomAPI_Shape::VERTEX);
+ for(; anExp.more() && !aContainPoint; anExp.next()) {
+ std::shared_ptr<GeomAPI_Shape> aVertexInCompSolid = anExp.current();
+ std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aVertexInCompSolid));
+ if (aVertex.get())
+ aContainPoint = aPoint->isEqual(aVertex->point());
+ }
+ return aContainPoint;
+}
+
+AttributeRefAttrPtr PartSet_WidgetPoint2D::attributeRefAttr() const
+{
+ AttributeRefAttrPtr anAttribute;
+ if (myRefAttribute.empty())
+ return anAttribute;
+
+ AttributePtr anAttributeRef = feature()->attribute(myRefAttribute);
+ if (!anAttributeRef.get())
+ return anAttribute;
+
+ return std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttributeRef);
+}
+
+void PartSet_WidgetPoint2D::fillRefAttribute(double theClickedX, double theClickedY)
+{
+ AttributeRefAttrPtr aRefAttr = attributeRefAttr();
+ if (!aRefAttr.get())
+ return;
+
+ FeaturePtr aFeature = feature();
+ std::string anAttribute = attributeID();
+
+ if (aFeature.get()) {
+ std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
+ new GeomAPI_Pnt2d(theClickedX, theClickedY));
+ AttributePoint2DPtr aClickedFeaturePoint = findFirstEqualPointInSketch(mySketch,
+ aFeature, aClickedPoint);
+ if (aClickedFeaturePoint.get())
+ aRefAttr->setAttr(aClickedFeaturePoint);
+ }
+}
+
+void PartSet_WidgetPoint2D::fillRefAttribute(const ObjectPtr& theObject)
+{
+ AttributeRefAttrPtr aRefAttr = attributeRefAttr();
+ if (aRefAttr.get())
+ aRefAttr->setObject(theObject);
+}
+
+std::shared_ptr<GeomDataAPI_Point2D> PartSet_WidgetPoint2D::findFirstEqualPointInArgumentFeatures(
+ const FeaturePtr& theFeature, const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+ std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint;
+
+ // may be feature is not updated yet, execute is not performed and references features
+ // are not created. Case: rectangle macro feature
+ ModuleBase_Tools::flushUpdated(theFeature);
+
+ std::list<AttributePtr> anAttributes = theFeature->data()->attributes(
+ ModelAPI_AttributeRefList::typeId());
+ std::list<AttributePtr>::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end();
+ for (; anIt != aLast && !aFeaturePoint.get(); anIt++) {
+ std::shared_ptr<ModelAPI_AttributeRefList> aCurSelList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anIt);
+ for (int i = 0, aNb = aCurSelList->size(); i < aNb && !aFeaturePoint.get(); i++) {
+ ObjectPtr anObject = aCurSelList->object(i);
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
+ if (aFeature.get())
+ aFeaturePoint = findFirstEqualPoint(aFeature, thePoint);
+ }
+ }
+ return aFeaturePoint;
+}
+
+std::shared_ptr<GeomDataAPI_Point2D> PartSet_WidgetPoint2D::findFirstEqualPoint(
+ const FeaturePtr& theFeature,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+ std::shared_ptr<GeomDataAPI_Point2D> aFPoint;
+
+ // find the given point in the feature attributes
+ std::list<std::shared_ptr<ModelAPI_Attribute> > anAttiributes =
+ theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
+ std::list<std::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt = anAttiributes.begin(),
+ aLast = anAttiributes.end();
+ ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
+
+ for (; anIt != aLast && !aFPoint; anIt++) {
+ std::shared_ptr<GeomDataAPI_Point2D> aCurPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+ if (aCurPoint && aCurPoint->isInitialized() &&
+ aValidators->isCase(theFeature, aCurPoint->id()) &&
+ (aCurPoint->pnt()->distance(thePoint) < Precision::Confusion())) {
+ aFPoint = aCurPoint;
+ break;
+ }
+ }
+ return aFPoint;
+}
+
+std::shared_ptr<GeomDataAPI_Point2D> PartSet_WidgetPoint2D::findFirstEqualPointInSketch(
+ const CompositeFeaturePtr& theSketch,
+ const FeaturePtr& theSkipFeature,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+ // get all sketch features. If the point with the given coordinates belong to any sketch feature,
+ // the constraint is created between the feature point and the found sketch point
+ std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
+ std::shared_ptr<ModelAPI_AttributeRefList> aRefList = std::dynamic_pointer_cast<
+ ModelAPI_AttributeRefList>(aData->attribute(SketchPlugin_Sketch::FEATURES_ID()));
+
+ std::list<ObjectPtr> aFeatures = aRefList->list();
+ std::list<ObjectPtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
+ std::list<std::shared_ptr<ModelAPI_Attribute> > anAttiributes;
+
+ std::shared_ptr<GeomDataAPI_Point2D> aFPoint;
+ for (; anIt != aLast; anIt++) {
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
+ if (!aFeature.get() || (theSkipFeature.get() && theSkipFeature == aFeature))
+ continue;
+ aFPoint = PartSet_WidgetPoint2D::findFirstEqualPoint(aFeature, thePoint);
+ if (aFPoint.get())
+ break;
+ }
+ return aFPoint;