#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
+#include <ModuleBase_Definitions.h>
+
#include <PartSet_Tools.h>
#include <SketchPlugin_Feature.h>
-#include <ModuleBase_IWorkshop.h>
-#include <XGUI_ModuleConnector.h>
+#include <SketchPlugin_ConstraintRigid.h>
+
#include <XGUI_Workshop.h>
-#include <XGUI_Displayer.h>
-bool PartSet_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape)
+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)
{
ObjectPtr aSelectedObject = theSelectedObject;
GeomShapePtr aShape = theShape;
}
}
}
- return ModuleBase_WidgetShapeSelector::storeAttributeValues(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<XGUI_ModuleConnector*>(myWorkshop);
- XGUI_Workshop* aWorkshop = aConnector->workshop();
- aWorkshop->displayer()->enableUpdateViewer(false);
- */
- ModuleBase_WidgetShapeSelector::storeAttributeValue();
+ return ModuleBase_WidgetShapeSelector::setObject(aSelectedObject, aShape);
}
//********************************************************************
void PartSet_WidgetShapeSelector::restoreAttributeValue(const bool theValid)
{
ModuleBase_WidgetShapeSelector::restoreAttributeValue(theValid);
- //if (!theValid)
removeExternal();
- /*
- XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
- XGUI_Workshop* aWorkshop = aConnector->workshop();
- aWorkshop->displayer()->enableUpdateViewer(false);//->erase(myExternalObject);
- aWorkshop->displayer()->enableUpdateViewer(true);*/
}
//********************************************************************
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<FeaturePtr> aRefFeatures;
+ aFeature->document()->refsToFeature(aFeature, aRefFeatures, false);
+ std::set<FeaturePtr>::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<FeaturePtr> anIgnoredFeatures;
+ anIgnoredFeatures.insert(sketch());
+ XGUI_Workshop::deleteFeatures(anObjects, anIgnoredFeatures);
}
- myExternalObject = NULL;
+ myExternalObject = ObjectPtr();
}
}