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,
18 const std::string& theCanCreateExternal,
19 const bool theDefaultValue)
20 : myUseExternal(theDefaultValue), myCanCreateExternal(true)
22 QString aIsExternal(theExternal.c_str());
23 if (!aIsExternal.isEmpty()) {
24 QString aStr = aIsExternal.toUpper();
25 myUseExternal = (aStr == "TRUE") || (aStr == "YES");
28 QString aCanCreateExternal(theCanCreateExternal.c_str());
29 if (!aCanCreateExternal.isEmpty()) {
30 QString aStr = aCanCreateExternal.toUpper();
31 myCanCreateExternal = (aStr == "TRUE") || (aStr == "YES");
35 bool PartSet_ExternalObjectsMgr::isValidObject(const ObjectPtr& theObject)
38 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
39 // Do check using of external feature
40 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
41 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
43 // Do check that we can use external feature
44 if (aSPFeature.get() != NULL && aSPFeature->isExternal() && !useExternal()) {
51 ObjectPtr PartSet_ExternalObjectsMgr::externalObject(const ObjectPtr& theSelectedObject,
52 const GeomShapePtr& theShape,
53 const CompositeFeaturePtr& theSketch,
54 const bool theTemporary)
56 ObjectPtr aSelectedObject = PartSet_Tools::findFixedObjectByExternal(
57 theShape->impl<TopoDS_Shape>(), theSelectedObject, theSketch);
58 FeaturePtr aFeature = ModelAPI_Feature::feature(aSelectedObject);
60 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
61 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
62 /// some sketch entities should be never shown, e.g. projection feature
63 /// such external features should not be used in selection
64 if (aSketchFeature.get() && !aSketchFeature->canBeDisplayed())
68 if (!aSelectedObject.get()) {
69 // Processing of external (non-sketch) object
70 aSelectedObject = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
71 theSelectedObject, theSketch, theTemporary);
72 if (aSelectedObject.get() && theTemporary)
73 myExternalObjectValidated = aSelectedObject;
75 return aSelectedObject;
78 //********************************************************************
79 void PartSet_ExternalObjectsMgr::removeExternal(const CompositeFeaturePtr& theSketch,
80 const FeaturePtr& theFeature,
81 ModuleBase_IWorkshop* theWorkshop,
82 const bool theTemporary)
85 removeExternalObject(myExternalObjectValidated, theSketch, theFeature, theWorkshop);
88 void PartSet_ExternalObjectsMgr::removeExternalObject(const ObjectPtr& theObject,
89 const CompositeFeaturePtr& /*theSketch*/,
90 const FeaturePtr& theFeature,
91 ModuleBase_IWorkshop* theWorkshop)
93 if (theObject.get()) {
94 DocumentPtr aDoc = theObject->document();
95 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
96 if (aFeature.get() != NULL) {
97 QObjectPtrList anObjects;
98 anObjects.append(aFeature);
99 // the external feature should be removed with all references,
100 // composite sketch feature will be ignored
101 workshop(theWorkshop)->deleteFeatures(anObjects);
106 XGUI_Workshop* PartSet_ExternalObjectsMgr::workshop(ModuleBase_IWorkshop* theWorkshop)
108 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
109 return aConnector->workshop();