From d83e9cb83825e51b2259d33dbe50fe1494369420 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 17 Mar 2017 11:35:49 +0300 Subject: [PATCH] Issue #2024 - Redesign of circle and arc of circle: fill Reference Attribute --- src/PartSet/PartSet_Tools.cpp | 108 -------------- src/PartSet/PartSet_Tools.h | 19 --- src/PartSet/PartSet_WidgetPoint2d.cpp | 201 +++++++++++++++++--------- src/PartSet/PartSet_WidgetPoint2d.h | 33 ++++- 4 files changed, 162 insertions(+), 199 deletions(-) diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index e7e2458f5..2099f347c 100755 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -273,114 +273,6 @@ void PartSet_Tools::createConstraint(CompositeFeaturePtr theSketch, Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED)); } -/*std::shared_ptr PartSet_Tools:: - findAttributePoint(CompositeFeaturePtr theSketch, double theX, double theY, - double theTolerance, const QList& theIgnore) -{ - std::shared_ptr aClickedPoint = std::shared_ptr( - new GeomAPI_Pnt2d(theX, theY)); - - std::list > anAttiributes; - for (int i = 0; i < theSketch->numberOfSubs(); i++) { - FeaturePtr aFeature = theSketch->subFeature(i); - if (!theIgnore.contains(aFeature)) { - anAttiributes = aFeature->data()->attributes(GeomDataAPI_Point2D::typeId()); - - std::list >::const_iterator anIt; - for (anIt = anAttiributes.cbegin(); anIt != anAttiributes.cend(); ++anIt) { - std::shared_ptr aCurPoint = - std::dynamic_pointer_cast(*anIt); - double x = aCurPoint->x(); - double y = aCurPoint->y(); - if (aCurPoint && (aCurPoint->pnt()->distance(aClickedPoint) < theTolerance)) { - return aCurPoint; - } - } - } - } - return std::shared_ptr(); -}*/ - - -std::shared_ptr PartSet_Tools::findFirstEqualPointInArgumentFeatures( - const FeaturePtr& theFeature, const std::shared_ptr& thePoint) -{ - std::shared_ptr 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 anAttributes = theFeature->data()->attributes( - ModelAPI_AttributeRefList::typeId()); - std::list::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end(); - for (; anIt != aLast && !aFeaturePoint.get(); anIt++) { - std::shared_ptr aCurSelList = - std::dynamic_pointer_cast(*anIt); - for (int i = 0, aNb = aCurSelList->size(); i < aNb && !aFeaturePoint.get(); i++) { - ObjectPtr anObject = aCurSelList->object(i); - FeaturePtr aFeature = std::dynamic_pointer_cast(anObject); - if (aFeature.get()) - aFeaturePoint = PartSet_Tools::findFirstEqualPoint(aFeature, thePoint); - } - } - return aFeaturePoint; -} - -std::shared_ptr PartSet_Tools::findFirstEqualPoint( - const FeaturePtr& theFeature, - const std::shared_ptr& thePoint) -{ - std::shared_ptr aFPoint; - - // find the given point in the feature attributes - std::list > anAttiributes = - theFeature->data()->attributes(GeomDataAPI_Point2D::typeId()); - std::list >::const_iterator anIt = anAttiributes.begin(), - aLast = anAttiributes.end(); - ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators(); - - for (; anIt != aLast && !aFPoint; anIt++) { - std::shared_ptr aCurPoint = - std::dynamic_pointer_cast(*anIt); - if (aCurPoint && aCurPoint->isInitialized() && - aValidators->isCase(theFeature, aCurPoint->id()) && - (aCurPoint->pnt()->distance(thePoint) < Precision::Confusion())) { - aFPoint = aCurPoint; - break; - } - } - return aFPoint; -} - -std::shared_ptr PartSet_Tools::findFirstEqualPointInSketch( - const CompositeFeaturePtr& theSketch, - const std::shared_ptr& theFeaturePoint, - const std::shared_ptr& 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 aData = theSketch->data(); - std::shared_ptr aRefList = std::dynamic_pointer_cast< - ModelAPI_AttributeRefList>(aData->attribute(SketchPlugin_Sketch::FEATURES_ID())); - - std::list aFeatures = aRefList->list(); - std::list::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end(); - std::list > anAttiributes; - - FeaturePtr aFeatureOfPoint = ModelAPI_Feature::feature(theFeaturePoint->owner()); - std::shared_ptr aFPoint; - for (; anIt != aLast; anIt++) { - FeaturePtr aFeature = std::dynamic_pointer_cast(*anIt); - if (!aFeature.get() || aFeatureOfPoint == aFeature) - continue; - aFPoint = PartSet_Tools::findFirstEqualPoint(aFeature, thePoint); - if (aFPoint.get()) - break; - } - return aFPoint; -} - std::shared_ptr PartSet_Tools::sketchPlane(CompositeFeaturePtr theSketch) { std::shared_ptr aPlane; diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index ef4659704..1b9937dd1 100755 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -121,25 +121,6 @@ public: std::shared_ptr thePoint1, std::shared_ptr thePoint2); - /// Finds in the feature's sub-features first Point2D attribute with the given point coordinates - /// \param theFeature a feature with sub-feature attributes - /// \param thePoint a point to provided searched coordinates - /// \return found point or null - static std::shared_ptr findFirstEqualPointInArgumentFeatures( - const FeaturePtr& theFeature, const std::shared_ptr& thePoint); - - /// Finds in the feature first Point2D attribute with the given point coordinates - /// \param theFeature a feature with point attributes - /// \param thePoint a point to provided searched coordinates - /// \return found point or null - static std::shared_ptr findFirstEqualPoint(const FeaturePtr& theFeature, - const std::shared_ptr& thePoint); - - static std::shared_ptr findFirstEqualPointInSketch( - const CompositeFeaturePtr& theSketch, - const std::shared_ptr& theFeaturePoint, - const std::shared_ptr& thePoint); - /// Create a sketch plane instance /// \param theSketch a sketch feature /// \return API object of geom plane diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 2fef715df..03995e897 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -29,6 +29,9 @@ #include #include #include +#include +#include +#include #include #include @@ -157,7 +160,7 @@ bool PartSet_WidgetPoint2D::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr /// analysis of AIS std::shared_ptr aData = myFeature->data(); - std::shared_ptr aPointAttr = std::dynamic_pointer_cast( + AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast( aData->attribute(attributeID())); std::shared_ptr aPoint = aPointAttr->pnt(); if (anAISShape.get()) @@ -225,8 +228,7 @@ bool PartSet_WidgetPoint2D::setSelection(QList& theValu const TopoDS_Shape& aTDShape = aShape->impl(); if (getPoint2d(aView, aTDShape, aX, aY)) { isDone = setPoint(aX, aY); - setConstraintTo(aX, aY); - //PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aX, aY); + setConstraintToPoint(aX, aY); } } return isDone; @@ -259,7 +261,7 @@ bool PartSet_WidgetPoint2D::storeValueCustom() std::shared_ptr aData = myFeature->data(); if (!aData) // can be on abort of sketcher element return false; - std::shared_ptr aPoint = std::dynamic_pointer_cast( + AttributePoint2DPtr aPoint = std::dynamic_pointer_cast( aData->attribute(attributeID())); PartSet_WidgetPoint2D* that = (PartSet_WidgetPoint2D*) this; @@ -285,7 +287,7 @@ bool PartSet_WidgetPoint2D::storeValueCustom() bool PartSet_WidgetPoint2D::restoreValueCustom() { std::shared_ptr aData = myFeature->data(); - std::shared_ptr aPoint = std::dynamic_pointer_cast( + AttributePoint2DPtr aPoint = std::dynamic_pointer_cast( aData->attribute(attributeID())); double aValueX = aPoint->isInitialized() ? aPoint->x() : 0.; double aValueY = aPoint->isInitialized() ? aPoint->y() : 0.; @@ -393,7 +395,7 @@ bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView, return false; } -bool PartSet_WidgetPoint2D::setConstraintTo(double theClickedX, double theClickedY) +bool PartSet_WidgetPoint2D::setConstraintToPoint(double theClickedX, double theClickedY) { FeaturePtr aFeature = feature(); std::string anAttribute = attributeID(); @@ -403,61 +405,60 @@ bool PartSet_WidgetPoint2D::setConstraintTo(double theClickedX, double theClicke std::shared_ptr aClickedPoint = std::shared_ptr( new GeomAPI_Pnt2d(theClickedX, theClickedY)); - - // find a feature point by the selection mode - std::shared_ptr aFeaturePoint; - if (aFeature->isMacro()) { - // the macro feature will be removed after the operation is stopped, so we need to build - // coicidence to possible sub-features - aFeaturePoint = PartSet_Tools::findFirstEqualPointInArgumentFeatures(aFeature, aClickedPoint); - } - else { - aFeaturePoint = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(aFeature->data()->attribute(anAttribute)); - } - if (!aFeaturePoint.get()) - return false; - - std::shared_ptr aFPoint = PartSet_Tools::findFirstEqualPointInSketch( - mySketch, aFeaturePoint, aClickedPoint); - if (!aFPoint.get()) + AttributePoint2DPtr aClickedFeaturePoint = findFirstEqualPointInSketch(mySketch, + aFeature, aClickedPoint); + if (!aClickedFeaturePoint.get()) return false; AttributeRefAttrPtr aRefAttr = attributeRefAttr(); if (aRefAttr.get()) - aRefAttr->setAttr(aFPoint); - else - PartSet_Tools::createConstraint(mySketch, aFPoint, aFeaturePoint); - - return true; -} - -bool PartSet_WidgetPoint2D::setConstraintWith(const ObjectPtr& theObject) -{ - std::shared_ptr aFeaturePoint; - - if (feature()->isMacro()) { - AttributePtr aThisAttr = feature()->data()->attribute(attributeID()); - std::shared_ptr anAttrPoint = - std::dynamic_pointer_cast(aThisAttr); - if (anAttrPoint.get()) { + aRefAttr->setAttr(aClickedFeaturePoint); + else { + // find a feature point by the selection mode + AttributePoint2DPtr aFeaturePoint; + if (aFeature->isMacro()) { // the macro feature will be removed after the operation is stopped, so we need to build // coicidence to possible sub-features - aFeaturePoint = PartSet_Tools::findFirstEqualPointInArgumentFeatures(feature(), - anAttrPoint->pnt()); + aFeaturePoint = findFirstEqualPointInArgumentFeatures(aFeature, aClickedPoint); } + else { + aFeaturePoint = std::dynamic_pointer_cast< + GeomDataAPI_Point2D>(aFeature->data()->attribute(anAttribute)); + } + if (!aFeaturePoint.get()) + return false; + + PartSet_Tools::createConstraint(mySketch, aClickedFeaturePoint, aFeaturePoint); } - else { - AttributePtr aThisAttr = feature()->data()->attribute(attributeID()); - aFeaturePoint = std::dynamic_pointer_cast(aThisAttr); - } - if (!aFeaturePoint.get()) - return false; + return true; +} +bool PartSet_WidgetPoint2D::setConstraintToObject(const ObjectPtr& theObject) +{ AttributeRefAttrPtr aRefAttr = attributeRefAttr(); - if (aRefAttr.get()) + if (aRefAttr.get()) { aRefAttr->setObject(theObject); + } else { + AttributePoint2DPtr aFeaturePoint; + + if (feature()->isMacro()) { + AttributePtr aThisAttr = feature()->data()->attribute(attributeID()); + AttributePoint2DPtr anAttrPoint = std::dynamic_pointer_cast(aThisAttr); + if (anAttrPoint.get()) { + // the macro feature will be removed after the operation is stopped, so we need to build + // coicidence to possible sub-features + aFeaturePoint = findFirstEqualPointInArgumentFeatures(feature(), + anAttrPoint->pnt()); + } + } + else { + AttributePtr aThisAttr = feature()->data()->attribute(attributeID()); + aFeaturePoint = std::dynamic_pointer_cast(aThisAttr); + } + if (!aFeaturePoint.get()) + return false; + // Create point-edge coincedence FeaturePtr aFeature = mySketch->addFeature(SketchPlugin_ConstraintCoincidence::ID()); std::shared_ptr aData = aFeature->data(); @@ -544,7 +545,7 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo } } if (aFixedObject.get()) - setConstraintWith(aFixedObject); + setConstraintToObject(aFixedObject); // fignal updated should be flushed in order to visualize possible created // external objects e.g. selection of trihedron axis when input end arc point updateObject(feature()); @@ -573,8 +574,7 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo setPoint(aX, aY); feature()->execute(); - setConstraintTo(aX, aY); - //PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aX, aY); + setConstraintToPoint(aX, aY); } else if (aShape.ShapeType() == TopAbs_EDGE) { // point is taken from mouse event and set in attribute. It should be done before setting @@ -583,7 +583,7 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView()); PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, aY); setPoint(aX, aY); - setConstraintWith(aObject); + setConstraintToObject(aObject); setValueState(Stored); // in case of edge selection, Apply state should also be updated isAuxiliaryFeature = PartSet_Tools::isAuxiliarySketchEntity(aObject); } @@ -611,21 +611,6 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo if (!setPoint(aX, anY) || isFeatureContainsPoint(myFeature, aX, anY)) return; - /// Start alternative code - //std::shared_ptr aFeaturePoint = std::dynamic_pointer_cast< - // GeomDataAPI_Point2D>(feature()->data()->attribute(attributeID())); - //QList aIgnore; - //aIgnore.append(feature()); - - //double aTolerance = aView->Convert(7); - //std::shared_ptr aAttrPnt = - // PartSet_Tools::findAttributePoint(mySketch, aX, anY, aTolerance, aIgnore); - //if (aAttrPnt.get() != NULL) { - // aFeaturePoint->setValue(aAttrPnt->pnt()); - // PartSet_Tools::createConstraint(mySketch, aAttrPnt, aFeaturePoint); - // emit vertexSelected(); - //} - /// End alternative code emit focusOutWidget(this); } } @@ -733,7 +718,7 @@ bool PartSet_WidgetPoint2D::isOrphanPoint(const FeaturePtr& theFeature, { bool anOrphanPoint = false; if (theFeature.get()) { - std::shared_ptr aPointAttr; + AttributePoint2DPtr aPointAttr; std::string aFeatureKind = theFeature->getKind(); if (aFeatureKind == SketchPlugin_Point::ID()) aPointAttr = std::dynamic_pointer_cast( @@ -810,3 +795,81 @@ AttributeRefAttrPtr PartSet_WidgetPoint2D::attributeRefAttr() const return std::dynamic_pointer_cast(anAttributeRef); } + +std::shared_ptr PartSet_WidgetPoint2D::findFirstEqualPointInArgumentFeatures( + const FeaturePtr& theFeature, const std::shared_ptr& thePoint) +{ + std::shared_ptr 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 anAttributes = theFeature->data()->attributes( + ModelAPI_AttributeRefList::typeId()); + std::list::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end(); + for (; anIt != aLast && !aFeaturePoint.get(); anIt++) { + std::shared_ptr aCurSelList = + std::dynamic_pointer_cast(*anIt); + for (int i = 0, aNb = aCurSelList->size(); i < aNb && !aFeaturePoint.get(); i++) { + ObjectPtr anObject = aCurSelList->object(i); + FeaturePtr aFeature = std::dynamic_pointer_cast(anObject); + if (aFeature.get()) + aFeaturePoint = findFirstEqualPoint(aFeature, thePoint); + } + } + return aFeaturePoint; +} + +std::shared_ptr PartSet_WidgetPoint2D::findFirstEqualPoint( + const FeaturePtr& theFeature, + const std::shared_ptr& thePoint) +{ + std::shared_ptr aFPoint; + + // find the given point in the feature attributes + std::list > anAttiributes = + theFeature->data()->attributes(GeomDataAPI_Point2D::typeId()); + std::list >::const_iterator anIt = anAttiributes.begin(), + aLast = anAttiributes.end(); + ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators(); + + for (; anIt != aLast && !aFPoint; anIt++) { + std::shared_ptr aCurPoint = + std::dynamic_pointer_cast(*anIt); + if (aCurPoint && aCurPoint->isInitialized() && + aValidators->isCase(theFeature, aCurPoint->id()) && + (aCurPoint->pnt()->distance(thePoint) < Precision::Confusion())) { + aFPoint = aCurPoint; + break; + } + } + return aFPoint; +} + +std::shared_ptr PartSet_WidgetPoint2D::findFirstEqualPointInSketch( + const CompositeFeaturePtr& theSketch, + const FeaturePtr& theSkipFeature, + const std::shared_ptr& 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 aData = theSketch->data(); + std::shared_ptr aRefList = std::dynamic_pointer_cast< + ModelAPI_AttributeRefList>(aData->attribute(SketchPlugin_Sketch::FEATURES_ID())); + + std::list aFeatures = aRefList->list(); + std::list::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end(); + std::list > anAttiributes; + + std::shared_ptr aFPoint; + for (; anIt != aLast; anIt++) { + FeaturePtr aFeature = std::dynamic_pointer_cast(*anIt); + if (!aFeature.get() || (theSkipFeature.get() && theSkipFeature == aFeature)) + continue; + aFPoint = PartSet_WidgetPoint2D::findFirstEqualPoint(aFeature, thePoint); + if (aFPoint.get()) + break; + } + return aFPoint; +} diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index 2e17c1dd1..b54b76c0a 100755 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -20,6 +20,7 @@ class ModelAPI_Feature; class ModelAPI_AttributeRefAttr; +class GeomDataAPI_Point2D; class ModuleBase_IWorkshop; class ModuleBase_ParamSpinBox; class ModuleBase_IViewWindow; @@ -177,12 +178,12 @@ protected: /// Creates constrains of the clicked point /// \param theClickedX the horizontal coordnate of the point /// \param theClickedY the vertical coordnate of the point - bool setConstraintTo(double theClickedX, double theClickedY); + bool setConstraintToPoint(double theClickedX, double theClickedY); /// Create a coincidence constraint between the attribute and the parameter object /// \theObject a result object /// \return true if succed - bool setConstraintWith(const ObjectPtr& theObject); + bool setConstraintToObject(const ObjectPtr& theObject); /// Returns if the feature is an orphan point, circle or an arc. Returns true if it /// has no a coincident to other lines. It processes point, circle and arc features @@ -204,7 +205,33 @@ protected: const std::shared_ptr& thePoint, const CompositeFeaturePtr& theSketch); - std::shared_ptr attributeRefAttr() const; + /// Finds in the feature's sub-features first Point2D attribute with the given point coordinates + /// \param theFeature a feature with sub-feature attributes + /// \param thePoint a point to provided searched coordinates + /// \return found point or null + static std::shared_ptr findFirstEqualPointInArgumentFeatures( + const FeaturePtr& theFeature, const std::shared_ptr& thePoint); + + /// Finds in the feature first Point2D attribute with the given point coordinates + /// \param theFeature a feature with point attributes + /// \param thePoint a point to provided searched coordinates + /// \return found point or null + static std::shared_ptr findFirstEqualPoint(const FeaturePtr& theFeature, + const std::shared_ptr& thePoint); + + /// Finds in the sketch attribute point of any feature that is nearest to the given point + /// \param theSketch a sketch, that is a container of features + /// \param theSkipFeature a feature that do not participate in the search + /// \param thePoint a point to provided searched coordinates + /// \return found point or null + static std::shared_ptr findFirstEqualPointInSketch( + const CompositeFeaturePtr& theSketch, + const FeaturePtr& theSkipFeature, + const std::shared_ptr& thePoint); + + /// Returns attribute reference if the key is defined in XML definition of this control + /// \return found attribute or null + std::shared_ptr attributeRefAttr() const; protected: ModuleBase_IWorkshop* myWorkshop; ///< workshop -- 2.39.2