X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_WidgetShapeSelector.cpp;h=82c0479bd67ced814630e957d64583b71d6212e5;hb=368eb86f8835d384a102ad84410a6c825c597a8c;hp=98c25d47b1dc4eda49d7e3e2af954673bc2ad324;hpb=a24b7e6f4d112d5e7889fd76f030298fc428cd01;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index 98c25d47b..82c0479bd 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -10,13 +10,22 @@ #include #include +#include + #include #include -#include -#include +#include + #include -#include + +PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent, + ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData, + const std::string& theParentId) +: ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId) +{ +} bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) { @@ -76,30 +85,11 @@ bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomSha return ModuleBase_WidgetShapeSelector::setObject(aSelectedObject, aShape); } -//******************************************************************** -void PartSet_WidgetShapeSelector::storeAttributeValue() -{ - /// this is a temporary code, will be removed when master is merged to this branch - /*XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); - XGUI_Workshop* aWorkshop = aConnector->workshop(); - aWorkshop->displayer()->enableUpdateViewer(false); - */ - ModuleBase_WidgetShapeSelector::storeAttributeValue(); -} - //******************************************************************** void PartSet_WidgetShapeSelector::restoreAttributeValue(const bool theValid) { ModuleBase_WidgetShapeSelector::restoreAttributeValue(theValid); - /// this is a temporary code, will be removed when master is merged to this branch - /// after merge, the external edge should be removed always, without flag checking - if (!theValid) - removeExternal(); - /* - XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); - XGUI_Workshop* aWorkshop = aConnector->workshop(); - aWorkshop->displayer()->enableUpdateViewer(false);//->erase(myExternalObject); - aWorkshop->displayer()->enableUpdateViewer(true);*/ + removeExternal(); } //******************************************************************** @@ -111,40 +101,6 @@ void PartSet_WidgetShapeSelector::createExternal(ObjectPtr theSelectedObject, if (aObj != myExternalObject) { removeExternal(); myExternalObject = aObj; -// TODO(nds) v1.0.2 master -// // Check the acceptability of the object and shape as validator attribute -// AttributePtr aPntAttr; -// DataPtr aData = myFeature->data(); -// if (theShape.get() != NULL) { -// AttributePtr aAttr = aData->attribute(attributeID()); -// AttributeRefAttrPtr aRefAttr = -// std::dynamic_pointer_cast(aAttr); -// if (aRefAttr) { -// TopoDS_Shape aShape = theShape->impl(); -// aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theObj, aShape, mySketch); -// } -// } -// // Check the acceptability of the object as attribute -// aValidator = aValidators.begin(); -// std::list >::iterator aArgs = anArguments.begin(); -// for (; aValidator != aValidators.end(); aValidator++, aArgs++) { -// const ModelAPI_RefAttrValidator* aAttrValidator = -// dynamic_cast(*aValidator); -// if (aAttrValidator) { -// if (aPntAttr.get() != NULL) -// { -// if (!aAttrValidator->isValid(myFeature, *aArgs, aPntAttr)) { -// return false; -// } -// } -// else -// { -// if (!aAttrValidator->isValid(myFeature, *aArgs, theObj, theShape)) { -// return false; -// } -// } -// } -// ======= end of todo } } @@ -155,8 +111,31 @@ void PartSet_WidgetShapeSelector::removeExternal() DocumentPtr aDoc = myExternalObject->document(); FeaturePtr aFeature = ModelAPI_Feature::feature(myExternalObject); if (aFeature.get() != NULL) { - aDoc->removeFeature(aFeature); + // 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 + std::set anIgnoredFeatures; + anIgnoredFeatures.insert(sketch()); + XGUI_Workshop::deleteFeatures(anObjects, anIgnoredFeatures); } - myExternalObject = NULL; + myExternalObject = ObjectPtr(); } }