1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_ExternalObjectsMgr.cpp
4 // Created: 15 Apr 2015
5 // Author: Natalia Ermolaeva
7 #include "PartSet_ExternalObjectsMgr.h"
8 #include "PartSet_Tools.h"
10 #include <XGUI_Workshop.h>
14 PartSet_ExternalObjectsMgr::PartSet_ExternalObjectsMgr(const std::string& theExternal, const bool theDefaultValue)
15 : myUseExternal(theDefaultValue)
17 QString aIsExternal(theExternal.c_str());
18 if (!aIsExternal.isEmpty()) {
19 QString aStr = aIsExternal.toUpper();
20 myUseExternal = (aStr == "TRUE") || (aStr == "YES");
24 ObjectPtr PartSet_ExternalObjectsMgr::externalObject(const ObjectPtr& theSelectedObject,
25 const GeomShapePtr& theShape,
26 const CompositeFeaturePtr& theSketch)
28 ObjectPtr aSelectedObject = PartSet_Tools::findFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
29 theSelectedObject, theSketch);
30 if (!aSelectedObject.get()) {
31 // Processing of external (non-sketch) object
32 aSelectedObject = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
33 theSelectedObject, theSketch);
34 if (aSelectedObject.get())
35 myExternalObjects.append(aSelectedObject);
37 return aSelectedObject;
40 //********************************************************************
41 void PartSet_ExternalObjectsMgr::removeExternal(const CompositeFeaturePtr& theSketch,
42 const FeaturePtr& theFeature)
44 QObjectPtrList::const_iterator anIt = myExternalObjects.begin(), aLast = myExternalObjects.end();
45 for (; anIt != aLast; anIt++) {
46 ObjectPtr anObject = *anIt;
48 DocumentPtr aDoc = anObject->document();
49 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
50 if (aFeature.get() != NULL) {
51 QObjectPtrList anObjects;
52 anObjects.append(aFeature);
53 // the external feature should be removed with all references, sketch feature should be ignored
54 std::set<FeaturePtr> anIgnoredFeatures;
55 anIgnoredFeatures.insert(theSketch);
56 // the current feature should be ignored, because it can use the external feature in the
57 // attributes and, therefore have a references to it. So, the delete functionality tries
58 // to delete this feature. Test case is creation of a constraint on external point,
59 // use in this control after an external point, the point of the sketch.
60 anIgnoredFeatures.insert(theFeature);
61 XGUI_Workshop::deleteFeatures(anObjects, anIgnoredFeatures);
65 myExternalObjects.clear();