#include <ModelAPI_Validator.h>
#include <ModuleBase_Definitions.h>
+#include <Config_WidgetAPI.h>
#include <PartSet_Tools.h>
#include <SketchPlugin_Feature.h>
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)
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<SketchPlugin_Feature> aSPFeature =
std::dynamic_pointer_cast<SketchPlugin_Feature>(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<TopoDS_Shape>(),
+ theSelectedObject, mySketch);
+ if (!aSelectedObject.get()) {
+ // Processing of external (non-sketch) object
+ aSelectedObject = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
+ theSelectedObject, mySketch);
+ if (aSelectedObject.get())
+ myExternalObject = aSelectedObject;
+ }
} else {
// Processing of sketch object
DataPtr aData = myFeature->data();
removeExternal();
}
-//********************************************************************
-void PartSet_WidgetShapeSelector::createExternal(ObjectPtr theSelectedObject,
- GeomShapePtr theShape)
-{
- ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
- theSelectedObject, mySketch);
- if (aObj != myExternalObject) {
- removeExternal();
- myExternalObject = aObj;
- }
-}
-
//********************************************************************
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<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