From: nds Date: Thu, 7 Dec 2017 08:57:59 +0000 (+0300) Subject: Issue #2325 impossible to select center of cylinder in sketch X-Git-Tag: V_2.10.0RC~85 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4d28b860188b4ad9550d6ccbd3fbf9f9f6c1d5ff;p=modules%2Fshaper.git Issue #2325 impossible to select center of cylinder in sketch --- diff --git a/src/PartSet/PartSet_ExternalObjectsMgr.cpp b/src/PartSet/PartSet_ExternalObjectsMgr.cpp index 793940cca..d2df7c96d 100755 --- a/src/PartSet/PartSet_ExternalObjectsMgr.cpp +++ b/src/PartSet/PartSet_ExternalObjectsMgr.cpp @@ -19,6 +19,8 @@ // #include "PartSet_ExternalObjectsMgr.h" + +#include "PartSet_CenterPrs.h" #include "PartSet_Tools.h" #include @@ -83,12 +85,40 @@ ObjectPtr PartSet_ExternalObjectsMgr::externalObject(const ObjectPtr& theSelecte return aSelectedObject; } +ObjectPtr PartSet_ExternalObjectsMgr::externalCenterObject(const ModuleBase_ViewerPrsPtr& thePrs, + const CompositeFeaturePtr& theSketch, + const bool theTemporary) +{ + if (!thePrs.get() || thePrs->interactive().IsNull()) + return ObjectPtr(); + + Handle(PartSet_CenterPrs) aAIS = Handle(PartSet_CenterPrs)::DownCast(thePrs->interactive()); + if (aAIS.IsNull()) + return ObjectPtr(); + + gp_Pnt aPntComp = aAIS->Component()->Pnt(); + GeomVertexPtr aVertPtr(new GeomAPI_Vertex(aPntComp.X(), aPntComp.Y(), aPntComp.Z())); + TopoDS_Shape aShape = aVertPtr->impl(); + + ResultPtr aSelectedObject = + PartSet_Tools::findFixedObjectByExternal(aShape, aAIS->object(), theSketch); + if (!aSelectedObject.get()) + { + FeaturePtr aCreatedFeature; + aSelectedObject = PartSet_Tools::createFixedByExternalCenter(aAIS->object(), aAIS->edge(), + aAIS->centerType(), theSketch, theTemporary, aCreatedFeature); + if (aCreatedFeature.get() && theTemporary) + myExternalObjectValidated = aCreatedFeature; + } + return aSelectedObject; +} + void PartSet_ExternalObjectsMgr::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs, - ObjectPtr& theObject, - GeomShapePtr& theShape, - ModuleBase_IWorkshop* theWorkshop, - const CompositeFeaturePtr& theSketch, - const bool isInValidate) + ObjectPtr& theObject, + GeomShapePtr& theShape, + ModuleBase_IWorkshop* theWorkshop, + const CompositeFeaturePtr& theSketch, + const bool isInValidate) { FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject); std::shared_ptr aSPFeature = @@ -110,6 +140,9 @@ void PartSet_ExternalObjectsMgr::getGeomSelection(const ModuleBase_ViewerPrsPtr& if (aShape.get() != NULL && !aShape->isNull()) anExternalObject = externalObject(theObject, aShape, theSketch, isInValidate); + if (!anExternalObject.get()) { + anExternalObject = externalCenterObject(thePrs, theSketch, isInValidate); + } } else { /// use objects of found selection anExternalObject = theObject; diff --git a/src/PartSet/PartSet_ExternalObjectsMgr.h b/src/PartSet/PartSet_ExternalObjectsMgr.h index d506047e7..59d014158 100755 --- a/src/PartSet/PartSet_ExternalObjectsMgr.h +++ b/src/PartSet/PartSet_ExternalObjectsMgr.h @@ -74,6 +74,15 @@ class PARTSET_EXPORT PartSet_ExternalObjectsMgr ObjectPtr externalObject(const ObjectPtr& theSelectedObject, const GeomShapePtr& theShape, const CompositeFeaturePtr& theSketch, const bool theTemporary = false); + /// Finds or create and external object by selected circle center (PartSet_CenterPrs) + /// \param thePrs a selection + /// \param theSketch a current sketch + /// \param theTemporary the created external object is temporary, execute is not performed for it + /// \return the object + ObjectPtr externalCenterObject(const std::shared_ptr& thePrs, + const CompositeFeaturePtr& theSketch, + const bool theTemporary); + // Removes the external presentation from the model /// \param theSketch a current sketch /// \param theFeature a current feature diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index dac76b8e9..2d32f553e 100755 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -686,13 +686,15 @@ ResultPtr PartSet_Tools::createFixedByExternalCenter( const std::shared_ptr& theEdge, ModelAPI_AttributeSelection::CenterType theType, const CompositeFeaturePtr& theSketch, - bool theTemporary) + bool theTemporary, + FeaturePtr& theCreatedFeature) { ResultPtr aResult = std::dynamic_pointer_cast(theObject); if (!aResult.get()) return ResultPtr(); FeaturePtr aProjectionFeature = theSketch->addFeature(SketchPlugin_Projection::ID()); + theCreatedFeature = aProjectionFeature; AttributeSelectionPtr anExternalAttr = std::dynamic_pointer_cast( aProjectionFeature->attribute(SketchPlugin_Projection::EXTERNAL_FEATURE_ID())); anExternalAttr->setValueCenter(aResult, theEdge, theType, theTemporary); diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 1a8beb670..1f5bf51b1 100755 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -283,7 +283,8 @@ public: const std::shared_ptr& theEdge, ModelAPI_AttributeSelection::CenterType theType, const CompositeFeaturePtr& theSketch, - bool theTemporary = false); + bool theTemporary, + FeaturePtr& theCreatedFeature); }; diff --git a/src/PartSet/PartSet_WidgetMultiSelector.cpp b/src/PartSet/PartSet_WidgetMultiSelector.cpp index a85835734..b552e9376 100755 --- a/src/PartSet/PartSet_WidgetMultiSelector.cpp +++ b/src/PartSet/PartSet_WidgetMultiSelector.cpp @@ -34,6 +34,7 @@ #include +#include #include #include #include @@ -61,7 +62,12 @@ PartSet_WidgetMultiSelector::~PartSet_WidgetMultiSelector() //******************************************************************** bool PartSet_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs) { - bool aValid = ModuleBase_WidgetMultiSelector::isValidSelectionCustom(thePrs); + bool aValid = false; + if (thePrs.get() && thePrs->interactive()->IsKind(STANDARD_TYPE(PartSet_CenterPrs))) + aValid = true; // we should not check acceptSubShape for such presentation + else + aValid = ModuleBase_WidgetMultiSelector::isValidSelectionCustom(thePrs); + if (aValid) { ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs); aValid = myExternalObjectMgr->isValidObject(anObject); diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 37d9fb015..0514fe7bb 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -726,8 +726,11 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo ResultPtr aFixedObject = PartSet_Tools::findFixedObjectByExternal(aShape, aAIS->object(), mySketch); if (!aFixedObject.get()) + { + FeaturePtr aCreatedFeature; aFixedObject = PartSet_Tools::createFixedByExternalCenter(aAIS->object(), aAIS->edge(), - aAIS->centerType(), mySketch); + aAIS->centerType(), mySketch, false, aCreatedFeature); + } if (aFixedObject.get()) setConstraintToObject(aFixedObject); // fignal updated should be flushed in order to visualize possible created diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index ead2a719a..056ca9dd6 100755 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -19,6 +19,8 @@ // #include "PartSet_WidgetShapeSelector.h" + +#include "PartSet_CenterPrs.h" #include "PartSet_Module.h" #include "PartSet_SketcherMgr.h" @@ -74,7 +76,12 @@ bool PartSet_WidgetShapeSelector::activateSelectionAndFilters(bool toActivate) //******************************************************************** bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs) { - bool aValid = ModuleBase_WidgetShapeSelector::isValidSelectionCustom(thePrs); + bool aValid = false; + if (thePrs.get() && thePrs->interactive()->IsKind(STANDARD_TYPE(PartSet_CenterPrs))) + aValid = true; // we should not check acceptSubShape for such presentation + else + aValid = ModuleBase_WidgetShapeSelector::isValidSelectionCustom(thePrs); + if (aValid) { ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs); aValid = myExternalObjectMgr->isValidObject(anObject);