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)
47 ObjectPtr aSelectedObject = PartSet_Tools::findFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
48 theSelectedObject, theSketch);
49 if (!aSelectedObject.get()) {
50 // Processing of external (non-sketch) object
51 aSelectedObject = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
52 theSelectedObject, theSketch);
53 if (aSelectedObject.get())
54 myExternalObjects.append(aSelectedObject);
56 return aSelectedObject;
59 //********************************************************************
60 ObjectPtr PartSet_ExternalObjectsMgr::externalObjectValidated(const ObjectPtr& theSelectedObject,
61 const GeomShapePtr& theShape,
62 const CompositeFeaturePtr& theSketch)
64 // TODO(nds): unite with externalObject()
65 ObjectPtr aSelectedObject = PartSet_Tools::findFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
66 theSelectedObject, theSketch);
67 if (!aSelectedObject.get()) {
68 // Processing of external (non-sketch) object
69 aSelectedObject = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
70 theSelectedObject, theSketch);
71 if (aSelectedObject.get())
72 myExternalObjectValidated = aSelectedObject;
74 return aSelectedObject;
77 //********************************************************************
78 void PartSet_ExternalObjectsMgr::removeExternal(const CompositeFeaturePtr& theSketch,
79 const FeaturePtr& theFeature,
80 ModuleBase_IWorkshop* theWorkshop)
82 QObjectPtrList::const_iterator anIt = myExternalObjects.begin(), aLast = myExternalObjects.end();
83 for (; anIt != aLast; anIt++) {
84 ObjectPtr anObject = *anIt;
86 DocumentPtr aDoc = anObject->document();
87 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
88 if (aFeature.get() != NULL) {
89 QObjectPtrList anObjects;
90 anObjects.append(aFeature);
91 // the external feature should be removed with all references, sketch feature should be ignored
92 std::set<FeaturePtr> anIgnoredFeatures;
93 // the current feature should be ignored, because it can use the external feature in the
94 // attributes and, therefore have a references to it. So, the delete functionality tries
95 // to delete this feature. Test case is creation of a constraint on external point,
96 // use in this control after an external point, the point of the sketch.
97 anIgnoredFeatures.insert(theFeature);
98 workshop(theWorkshop)->deleteFeatures(anObjects, anIgnoredFeatures);
101 //removeExternalObject(anObject, theSketch, theFeature);
103 myExternalObjects.clear();
106 //********************************************************************
107 void PartSet_ExternalObjectsMgr::removeUnusedExternalObjects(const QObjectPtrList& theIgnoreObjects,
108 const CompositeFeaturePtr& theSketch,
109 const FeaturePtr& theFeature)
112 // TODO(nds): unite with removeExternal(), remove parameters
113 QObjectPtrList aUsedExternalObjects;
115 QObjectPtrList::const_iterator anIt = myExternalObjects.begin(), aLast = myExternalObjects.end();
116 for (; anIt != aLast; anIt++) {
117 ObjectPtr anObject = *anIt;
118 if (theIgnoreObjects.contains(anObject))
119 aUsedExternalObjects.append(anObject);
121 removeExternalObject(anObject, theSketch, theFeature);
123 myExternalObjects.clear();
124 //if (!aUsedExternalObjects.empty())
125 // myExternalObjects = aUsedExternalObjects;
128 //********************************************************************
129 void PartSet_ExternalObjectsMgr::removeExternalValidated(const CompositeFeaturePtr& theSketch,
130 const FeaturePtr& theFeature,
131 ModuleBase_IWorkshop* theWorkshop)
133 // TODO(nds): unite with removeExternal(), remove parameters
134 removeExternalObject(myExternalObjectValidated, theSketch, theFeature, theWorkshop);
135 myExternalObjectValidated = ObjectPtr();
138 void PartSet_ExternalObjectsMgr::removeExternalObject(const ObjectPtr& theObject,
139 const CompositeFeaturePtr& theSketch,
140 const FeaturePtr& theFeature,
141 ModuleBase_IWorkshop* theWorkshop)
143 if (theObject.get()) {
144 DocumentPtr aDoc = theObject->document();
145 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
146 if (aFeature.get() != NULL) {
147 QObjectPtrList anObjects;
148 anObjects.append(aFeature);
149 // the external feature should be removed with all references, sketch feature should be ignored
150 std::set<FeaturePtr> anIgnoredFeatures;
151 // the current feature should be ignored, because it can use the external feature in the
152 // attributes and, therefore have a references to it. So, the delete functionality tries
153 // to delete this feature. Test case is creation of a constraint on external point,
154 // use in this control after an external point, the point of the sketch.
155 anIgnoredFeatures.insert(theFeature);
156 workshop(theWorkshop)->deleteFeatures(anObjects, anIgnoredFeatures);
161 XGUI_Workshop* PartSet_ExternalObjectsMgr::workshop(ModuleBase_IWorkshop* theWorkshop)
163 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
164 return aConnector->workshop();