From: nds Date: Thu, 2 Apr 2015 08:48:18 +0000 (+0300) Subject: The external edge should be removed only if it was created by the widget. So, the... X-Git-Tag: V_1.1.0~62 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=04f3d16c5347e2dd849add526fa1997d09d2f7e5;p=modules%2Fshaper.git The external edge should be removed only if it was created by the widget. So, the functionality of an external object creation is separated into two - find and creation. --- diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index a92364d05..82675355b 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -431,19 +431,30 @@ std::shared_ptr PartSet_Tools::point3D(std::shared_ptrto3D(aC->pnt(), aX->dir(), aY); } -ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShape, - const ObjectPtr& theObject, - CompositeFeaturePtr theSketch) +ResultPtr PartSet_Tools::findFixedObjectByExternal(const TopoDS_Shape& theShape, + const ObjectPtr& theObject, + CompositeFeaturePtr theSketch) { + ResultPtr aResult; if (theShape.ShapeType() == TopAbs_EDGE) { // Check that we already have such external edge std::shared_ptr aInEdge = std::shared_ptr(new GeomAPI_Edge()); aInEdge->setImpl(new TopoDS_Shape(theShape)); - ResultPtr aResult = findExternalEdge(theSketch, aInEdge); - if (aResult) - return aResult; + aResult = findExternalEdge(theSketch, aInEdge); + } + if (theShape.ShapeType() == TopAbs_VERTEX) { + std::shared_ptr aInVert = std::shared_ptr(new GeomAPI_Vertex()); + aInVert->setImpl(new TopoDS_Shape(theShape)); + aResult = findExternalVertex(theSketch, aInVert); + } + return aResult; +} - // If not found then we have to create new +ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShape, + const ObjectPtr& theObject, + CompositeFeaturePtr theSketch) +{ + if (theShape.ShapeType() == TopAbs_EDGE) { Standard_Real aStart, aEnd; Handle(V3d_View) aNullView; FeaturePtr aMyFeature; @@ -487,12 +498,6 @@ ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShap } } if (theShape.ShapeType() == TopAbs_VERTEX) { - std::shared_ptr aInVert = std::shared_ptr(new GeomAPI_Vertex()); - aInVert->setImpl(new TopoDS_Shape(theShape)); - ResultPtr aResult = findExternalVertex(theSketch, aInVert); - if (aResult) - return aResult; - FeaturePtr aMyFeature = theSketch->addFeature(SketchPlugin_Point::ID()); if (aMyFeature) { diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 854dd3b0e..e614074a8 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -145,6 +145,15 @@ class PARTSET_EXPORT PartSet_Tools static std::shared_ptr point3D(std::shared_ptr thePoint2D, CompositeFeaturePtr theSketch); + /// Finds a line (arc or circle) by given edge + /// \param theShape an edge + /// \param theObject a selected result object + /// \param theSketch a sketch feature + /// \return result of found feature or NULL + static ResultPtr findFixedObjectByExternal(const TopoDS_Shape& theShape, + const ObjectPtr& theObject, + CompositeFeaturePtr theSketch); + /// Creates a line (arc or circle) by given edge /// Created line will have fixed constraint /// \param theShape an edge diff --git a/src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp b/src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp index 5c5700b99..f3799357c 100644 --- a/src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp @@ -14,7 +14,11 @@ bool PartSet_WidgetConstraintShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) { - ObjectPtr aSelectedObject = theSelectedObject; + // initially the method is wrote to create an external object. Since the parent widget creates it, + // the redefinition is not necessary anymore. + // TODO: remove the widget and use the parent one insted of it + return PartSet_WidgetShapeSelector::setObject(theSelectedObject, theShape); + /*ObjectPtr aSelectedObject = theSelectedObject; FeaturePtr aFeature = ModelAPI_Feature::feature(aSelectedObject); if (aFeature) { @@ -29,5 +33,5 @@ bool PartSet_WidgetConstraintShapeSelector::setObject(ObjectPtr theSelectedObjec return false; } } - return ModuleBase_WidgetShapeSelector::setObject(aSelectedObject, theShape); + return ModuleBase_WidgetShapeSelector::setObject(aSelectedObject, theShape);*/ } diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 4104331df..10f6de95f 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -262,8 +262,11 @@ void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMous if (aSelectedFeature.get() != NULL) { std::shared_ptr aSPFeature = std::dynamic_pointer_cast(aSelectedFeature); - if ((!aSPFeature) && (!aShape.IsNull())) - PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch); + if ((!aSPFeature) && (!aShape.IsNull())) { + ResultPtr aFixedObject = PartSet_Tools::findFixedObjectByExternal(aShape, aObject, mySketch); + if (!aFixedObject.get()) + aFixedObject = PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch); + } } double aX, aY; if (getPoint2d(aView, aShape, aX, aY)) { diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index 82c0479bd..cd659c04d 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -38,12 +38,15 @@ bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomSha std::shared_ptr aSPFeature = std::dynamic_pointer_cast(aSelectedFeature); if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull()) { - // Processing of external (non-sketch) object - createExternal(theSelectedObject, theShape); - if (myExternalObject) - aSelectedObject = myExternalObject; - else - return false; + aSelectedObject = PartSet_Tools::findFixedObjectByExternal(theShape->impl(), + theSelectedObject, mySketch); + if (!aSelectedObject.get()) { + // Processing of external (non-sketch) object + aSelectedObject = PartSet_Tools::createFixedObjectByExternal(theShape->impl(), + theSelectedObject, mySketch); + if (aSelectedObject.get()) + myExternalObject = aSelectedObject; + } } else { // Processing of sketch object DataPtr aData = myFeature->data(); @@ -92,18 +95,6 @@ void PartSet_WidgetShapeSelector::restoreAttributeValue(const bool theValid) removeExternal(); } -//******************************************************************** -void PartSet_WidgetShapeSelector::createExternal(ObjectPtr theSelectedObject, - GeomShapePtr theShape) -{ - ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(theShape->impl(), - theSelectedObject, mySketch); - if (aObj != myExternalObject) { - removeExternal(); - myExternalObject = aObj; - } -} - //******************************************************************** void PartSet_WidgetShapeSelector::removeExternal() { @@ -111,24 +102,6 @@ void PartSet_WidgetShapeSelector::removeExternal() DocumentPtr aDoc = myExternalObject->document(); FeaturePtr aFeature = ModelAPI_Feature::feature(myExternalObject); if (aFeature.get() != NULL) { - // 1. check whether the external object can be deleted - // It should not be deleted if there are references to the object from other features, - // which are not the sketch or a rigid constraints. - std::set aRefFeatures; - aFeature->document()->refsToFeature(aFeature, aRefFeatures, false); - std::set::const_iterator anIt = aRefFeatures.begin(), - aLast = aRefFeatures.end(); - bool aReferenceExist = false; - CompositeFeaturePtr aSketch = sketch(); - for (; anIt != aLast && !aReferenceExist; anIt++) { - FeaturePtr aFeature = (*anIt); - aReferenceExist = aFeature != aSketch && - aFeature->getKind() != SketchPlugin_ConstraintRigid::ID(); - } - if (aReferenceExist) - return; - - // 2. delete external object QObjectPtrList anObjects; anObjects.append(aFeature); // the external feature should be removed with all references, sketch feature should be ignored diff --git a/src/PartSet/PartSet_WidgetShapeSelector.h b/src/PartSet/PartSet_WidgetShapeSelector.h index e529e33ec..fb32bff9c 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.h +++ b/src/PartSet/PartSet_WidgetShapeSelector.h @@ -54,11 +54,6 @@ protected: /// \param theValid a boolean flag, if restore happens for valid parameters void restoreAttributeValue(const bool theValid); - // Removes the external presentation from the model - /// \param theSelectedObject an object - /// \param theShape a selected shape, which is used in the selection attribute - void createExternal(ObjectPtr theSelectedObject, GeomShapePtr theShape); - // Removes the external presentation from the model void removeExternal();