From: nds Date: Wed, 12 Apr 2017 10:03:42 +0000 (+0300) Subject: Issue #2120 - Crash when creating an arc passing through the arc connected to both... X-Git-Tag: V_2.7.0~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8ac575427c615811d8188e80b5a8dc9a3855da1c;p=modules%2Fshaper.git Issue #2120 - Crash when creating an arc passing through the arc connected to both ends --- diff --git a/src/PartSet/PartSet_ExternalObjectsMgr.cpp b/src/PartSet/PartSet_ExternalObjectsMgr.cpp index 2c8ac1d08..bc0412047 100755 --- a/src/PartSet/PartSet_ExternalObjectsMgr.cpp +++ b/src/PartSet/PartSet_ExternalObjectsMgr.cpp @@ -10,6 +10,9 @@ #include #include +#include +#include + #include #include @@ -75,6 +78,46 @@ ObjectPtr PartSet_ExternalObjectsMgr::externalObject(const ObjectPtr& theSelecte return aSelectedObject; } +void PartSet_ExternalObjectsMgr::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs, + ObjectPtr& theObject, + GeomShapePtr& theShape, + ModuleBase_IWorkshop* theWorkshop, + const CompositeFeaturePtr& theSketch, + const bool isInValidate) +{ + FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject); + std::shared_ptr aSPFeature = + std::dynamic_pointer_cast(aSelectedFeature); + // there is no a sketch feature is selected, but the shape exists, + // try to create an exernal object + // TODO: unite with the same functionality in PartSet_WidgetShapeSelector + if (aSPFeature.get() == NULL) { + ObjectPtr anExternalObject = ObjectPtr(); + GeomShapePtr anExternalShape = GeomShapePtr(); + if (useExternal()) { + if (canCreateExternal()) { + GeomShapePtr aShape = theShape; + if (!aShape.get()) { + ResultPtr aResult = theWorkshop->selection()->getResult(thePrs); + if (aResult.get()) + aShape = aResult->shape(); + } + if (aShape.get() != NULL && !aShape->isNull()) + anExternalObject = + externalObject(theObject, aShape, theSketch, isInValidate); + } + else { /// use objects of found selection + anExternalObject = theObject; + anExternalShape = theShape; + } + } + /// the object is null if the selected feature is "external"(not sketch entity feature of the + /// current sketch) and it is not created by object manager + theObject = anExternalObject; + theShape = anExternalShape; + } +} + //******************************************************************** void PartSet_ExternalObjectsMgr::removeExternal(const CompositeFeaturePtr& theSketch, const FeaturePtr& theFeature, diff --git a/src/PartSet/PartSet_ExternalObjectsMgr.h b/src/PartSet/PartSet_ExternalObjectsMgr.h index 4cc3696da..f403f88a4 100755 --- a/src/PartSet/PartSet_ExternalObjectsMgr.h +++ b/src/PartSet/PartSet_ExternalObjectsMgr.h @@ -19,6 +19,7 @@ #include class ModuleBase_IWorkshop; +class ModuleBase_ViewerPrs; class XGUI_Workshop; /** @@ -70,6 +71,17 @@ class PARTSET_EXPORT PartSet_ExternalObjectsMgr ModuleBase_IWorkshop* theWorkshop, const bool theTemporary); + /// Return an object and geom shape by the viewer presentation + /// \param thePrs a selection + /// \param theObject an output object + /// \param theShape a shape of the selection + virtual void getGeomSelection(const std::shared_ptr& thePrs, + ObjectPtr& theObject, + GeomShapePtr& theShape, + ModuleBase_IWorkshop* theWorkshop, + const CompositeFeaturePtr& theSketch, + const bool isInValidate); + protected: /// Delete from the document the feature of the object. It deletes all objects, which refers to /// the deleted one. The parameter feature is ignored even it refer to the deleted object. diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index c81d84b96..ceb12eff0 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -133,6 +134,8 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, setLayout(aLayout); myWidgetValidator = new ModuleBase_WidgetValidator(this, myWorkshop); + myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"), + theData->getProperty("can_create_external"), true); } bool PartSet_WidgetPoint2D::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& theValue) @@ -212,6 +215,7 @@ bool PartSet_WidgetPoint2D::isValidSelectionForAttribute_( // restores the current values of the widget attribute myWidgetValidator->restoreAttributeValue(aRefAttr, aValid); + myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true); ModuleBase_WidgetValidated::blockFeatureAttribute(aRefAttr, myFeature, false, isFlushesActived, isAttributeSetInitializedBlocked, isAttributeSendUpdatedBlocked); @@ -227,11 +231,11 @@ bool PartSet_WidgetPoint2D::setSelectionCustom(const ModuleBase_ViewerPrsPtr& th double aX, aY; const TopoDS_Shape& aTDShape = aShape->impl(); if (getPoint2d(aView, aTDShape, aX, aY)) { - fillRefAttribute(aX, aY); + fillRefAttribute(aX, aY, theValue); isDone = true; } else if (aTDShape.ShapeType() == TopAbs_EDGE) { - fillRefAttribute(theValue->object()); + fillRefAttribute(theValue); isDone = true; } } @@ -271,6 +275,7 @@ bool PartSet_WidgetPoint2D::resetCustom() PartSet_WidgetPoint2D::~PartSet_WidgetPoint2D() { + delete myExternalObjectMgr; } bool PartSet_WidgetPoint2D::setSelection(QList& theValues, @@ -290,7 +295,7 @@ bool PartSet_WidgetPoint2D::setSelection(QList& theValu const TopoDS_Shape& aTDShape = aShape->impl(); if (getPoint2d(aView, aTDShape, aX, aY)) { isDone = setPoint(aX, aY); - setConstraintToPoint(aX, aY); + setConstraintToPoint(aX, aY, aValue); } } } @@ -458,11 +463,12 @@ bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView, return false; } -bool PartSet_WidgetPoint2D::setConstraintToPoint(double theClickedX, double theClickedY) +bool PartSet_WidgetPoint2D::setConstraintToPoint(double theClickedX, double theClickedY, + const std::shared_ptr& theValue) { AttributeRefAttrPtr aRefAttr = attributeRefAttr(); if (aRefAttr.get()) - fillRefAttribute(theClickedX, theClickedY); + fillRefAttribute(theClickedX, theClickedY, theValue); else { FeaturePtr aFeature = feature(); std::string anAttribute = attributeID(); @@ -647,7 +653,7 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo bool isAuxiliaryFeature = false; if (getPoint2d(aView, aShape, aX, aY)) { setPoint(aX, aY); - setConstraintToPoint(aX, aY); + setConstraintToPoint(aX, aY, aFirstValue); } else if (aShape.ShapeType() == TopAbs_EDGE) { // point is taken from mouse event and set in attribute. It should be done before setting @@ -869,7 +875,8 @@ AttributeRefAttrPtr PartSet_WidgetPoint2D::attributeRefAttr() const return std::dynamic_pointer_cast(anAttributeRef); } -void PartSet_WidgetPoint2D::fillRefAttribute(double theClickedX, double theClickedY) +void PartSet_WidgetPoint2D::fillRefAttribute(double theClickedX, double theClickedY, + const std::shared_ptr& theValue) { AttributeRefAttrPtr aRefAttr = attributeRefAttr(); if (!aRefAttr.get()) @@ -885,9 +892,19 @@ void PartSet_WidgetPoint2D::fillRefAttribute(double theClickedX, double theClick aFeature, aClickedPoint); if (aClickedFeaturePoint.get()) aRefAttr->setAttr(aClickedFeaturePoint); + else { + ObjectPtr anObject = getGeomSelection(theValue); + if (anObject.get()) + aRefAttr->setObject(anObject); + } } } +void PartSet_WidgetPoint2D::fillRefAttribute(const ModuleBase_ViewerPrsPtr& theValue) +{ + fillRefAttribute(getGeomSelection(theValue)); +} + void PartSet_WidgetPoint2D::fillRefAttribute(const ObjectPtr& theObject) { AttributeRefAttrPtr aRefAttr = attributeRefAttr(); @@ -972,3 +989,15 @@ std::shared_ptr PartSet_WidgetPoint2D::findFirstEqualPointI } return aFPoint; } + +ObjectPtr PartSet_WidgetPoint2D::getGeomSelection(const ModuleBase_ViewerPrsPtr& theValue) +{ + ObjectPtr anObject; + GeomShapePtr aShape; + ModuleBase_ISelection* aSelection = myWorkshop->selection(); + anObject = aSelection->getResult(theValue); + aShape = aSelection->getShape(theValue); + myExternalObjectMgr->getGeomSelection(theValue, anObject, aShape, myWorkshop, sketch(), true); + + return anObject; +} diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index 45841941a..06b8e4a37 100755 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -25,6 +25,7 @@ class ModuleBase_IWorkshop; class ModuleBase_ParamSpinBox; class ModuleBase_IViewWindow; class ModuleBase_LabelValue; +class PartSet_ExternalObjectsMgr; class GeomAPI_Pnt2d; class ModuleBase_IWorkshop; @@ -191,7 +192,8 @@ protected: /// Creates constrains of the clicked point /// \param theClickedX the horizontal coordnate of the point /// \param theClickedY the vertical coordnate of the point - bool setConstraintToPoint(double theClickedX, double theClickedY); + bool setConstraintToPoint(double theClickedX, double theClickedY, + const std::shared_ptr& theValue); /// Create a coincidence constraint between the attribute and the parameter object /// \theObject a result object @@ -249,9 +251,13 @@ protected: /// Finds first equal point attribute in sketch and set it to reference attribute /// \param theClickedX the horizontal coordnate of the point /// \param theClickedY the vertical coordnate of the point - void fillRefAttribute(double theClickedX, double theClickedY); + void fillRefAttribute(const std::shared_ptr& theValue); + void fillRefAttribute(double theClickedX, double theClickedY, + const std::shared_ptr& theValue); void fillRefAttribute(const ObjectPtr& theObject); + ObjectPtr getGeomSelection(const std::shared_ptr& theValue); + protected: ModuleBase_IWorkshop* myWorkshop; ///< workshop @@ -261,6 +267,7 @@ private: //ModuleBase_ParamSpinBox* myYSpin; ///< the spin box for the Y coordinate ModuleBase_LabelValue* myXSpin; ///< the label for the X coordinate ModuleBase_LabelValue* myYSpin; ///< the label for the Y coordinate + PartSet_ExternalObjectsMgr* myExternalObjectMgr; ///< reference to external objects manager /// value used as selection in mouse release method std::shared_ptr myPreSelected; diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index 472b122e8..14444e9da 100755 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -74,6 +74,9 @@ void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr { ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape); + myExternalObjectMgr->getGeomSelection(thePrs, theObject, theShape, + myWorkshop, sketch(), myIsInValidate); + /* FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject); std::shared_ptr aSPFeature = std::dynamic_pointer_cast(aSelectedFeature); @@ -104,7 +107,7 @@ void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr /// current sketch) and it is not created by object manager theObject = anExternalObject; theShape = anExternalShape; - } + }*/ } //********************************************************************