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>
11 #include <XGUI_ModuleConnector.h>
13 #include <SketchPlugin_Feature.h>
17 PartSet_ExternalObjectsMgr::PartSet_ExternalObjectsMgr(const std::string& theExternal, const bool theDefaultValue)
18 : myUseExternal(theDefaultValue)
20 QString aIsExternal(theExternal.c_str());
21 if (!aIsExternal.isEmpty()) {
22 QString aStr = aIsExternal.toUpper();
23 myUseExternal = (aStr == "TRUE") || (aStr == "YES");
27 bool PartSet_ExternalObjectsMgr::isValidObject(const ObjectPtr& theObject)
30 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
31 // Do check using of external feature
32 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
33 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
35 // Do check that we can use external feature
36 if (aSPFeature.get() != NULL && aSPFeature->isExternal() && !useExternal()) {
43 ObjectPtr PartSet_ExternalObjectsMgr::externalObject(const ObjectPtr& theSelectedObject,
44 const GeomShapePtr& theShape,
45 const CompositeFeaturePtr& theSketch,
46 const bool theTemporary)
48 ObjectPtr aSelectedObject = PartSet_Tools::findFixedObjectByExternal(
49 theShape->impl<TopoDS_Shape>(), theSelectedObject, theSketch);
50 if (!aSelectedObject.get()) {
51 // Processing of external (non-sketch) object
52 aSelectedObject = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
53 theSelectedObject, theSketch, theTemporary);
54 if (aSelectedObject.get() && theTemporary)
55 myExternalObjectValidated = aSelectedObject;
57 return aSelectedObject;
60 //********************************************************************
61 void PartSet_ExternalObjectsMgr::removeExternal(const CompositeFeaturePtr& theSketch,
62 const FeaturePtr& theFeature,
63 ModuleBase_IWorkshop* theWorkshop,
64 const bool theTemporary)
67 removeExternalObject(myExternalObjectValidated, theSketch, theFeature, theWorkshop);
70 void PartSet_ExternalObjectsMgr::removeExternalObject(const ObjectPtr& theObject,
71 const CompositeFeaturePtr& /*theSketch*/,
72 const FeaturePtr& theFeature,
73 ModuleBase_IWorkshop* theWorkshop)
75 if (theObject.get()) {
76 DocumentPtr aDoc = theObject->document();
77 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
78 if (aFeature.get() != NULL) {
79 QObjectPtrList anObjects;
80 anObjects.append(aFeature);
81 // the external feature should be removed with all references, sketch feature should be ignored
82 std::set<FeaturePtr> anIgnoredFeatures;
83 // the current feature should be ignored, because it can use the external feature in the
84 // attributes and, therefore have a references to it. So, the delete functionality tries
85 // to delete this feature. Test case is creation of a constraint on external point,
86 // use in this control after an external point, the point of the sketch.
87 anIgnoredFeatures.insert(theFeature);
88 workshop(theWorkshop)->deleteFeatures(anObjects, anIgnoredFeatures);
93 XGUI_Workshop* PartSet_ExternalObjectsMgr::workshop(ModuleBase_IWorkshop* theWorkshop)
95 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
96 return aConnector->workshop();