X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_WidgetShapeSelector.cpp;h=089bd98a6ccf1cc1794b3d8cd0da43b06a6d416b;hb=c55b14977783111c8b418b416c7f6c2fa545c5e5;hp=82c0479bd67ced814630e957d64583b71d6212e5;hpb=368eb86f8835d384a102ad84410a6c825c597a8c;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index 82c0479bd..089bd98a6 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -23,8 +24,13 @@ PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, const std::string& theParentId) -: ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId) +: ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId), myUseExternal(true) { + QString aIsExternal(theData->getProperty("use_external").c_str()); + if (!aIsExternal.isEmpty()) { + QString aStr = aIsExternal.toUpper(); + myUseExternal = (aStr == "TRUE") || (aStr == "YES"); + } } bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) @@ -35,15 +41,24 @@ bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomSha FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aSelectedObject); if (aSelectedFeature == myFeature) // In order to avoid selection of the same object return false; + // Do check using of external feature 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; + + // Do check that we can use external feature + if ((aSPFeature.get() != NULL) && aSPFeature->isExternal() && (!myUseExternal)) + return false; + + if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull() && myUseExternal) { + 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 +107,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 +114,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