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>
12 #include <SketchPlugin_Feature.h>
16 PartSet_ExternalObjectsMgr::PartSet_ExternalObjectsMgr(const std::string& theExternal, const bool theDefaultValue)
17 : myUseExternal(theDefaultValue)
19 QString aIsExternal(theExternal.c_str());
20 if (!aIsExternal.isEmpty()) {
21 QString aStr = aIsExternal.toUpper();
22 myUseExternal = (aStr == "TRUE") || (aStr == "YES");
26 bool PartSet_ExternalObjectsMgr::isValidObject(const ObjectPtr& theObject)
29 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
30 // Do check using of external feature
31 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
32 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
34 // Do check that we can use external feature
35 if (aSPFeature.get() != NULL && aSPFeature->isExternal() && !useExternal()) {
42 ObjectPtr PartSet_ExternalObjectsMgr::externalObject(const ObjectPtr& theSelectedObject,
43 const GeomShapePtr& theShape,
44 const CompositeFeaturePtr& theSketch)
46 ObjectPtr aSelectedObject = PartSet_Tools::findFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
47 theSelectedObject, theSketch);
48 if (!aSelectedObject.get()) {
49 // Processing of external (non-sketch) object
50 aSelectedObject = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
51 theSelectedObject, theSketch);
52 if (aSelectedObject.get())
53 myExternalObjects.append(aSelectedObject);
55 return aSelectedObject;
58 //********************************************************************
59 ObjectPtr PartSet_ExternalObjectsMgr::externalObjectValidated(const ObjectPtr& theSelectedObject,
60 const GeomShapePtr& theShape,
61 const CompositeFeaturePtr& theSketch)
63 // TODO(nds): unite with externalObject()
64 ObjectPtr aSelectedObject = PartSet_Tools::findFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
65 theSelectedObject, theSketch);
66 if (!aSelectedObject.get()) {
67 // Processing of external (non-sketch) object
68 aSelectedObject = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
69 theSelectedObject, theSketch);
70 if (aSelectedObject.get())
71 myExternalObjectValidated = aSelectedObject;
73 return aSelectedObject;
76 //********************************************************************
77 void PartSet_ExternalObjectsMgr::removeExternal(const CompositeFeaturePtr& theSketch,
78 const FeaturePtr& theFeature)
80 QObjectPtrList::const_iterator anIt = myExternalObjects.begin(), aLast = myExternalObjects.end();
81 for (; anIt != aLast; anIt++) {
82 ObjectPtr anObject = *anIt;
84 DocumentPtr aDoc = anObject->document();
85 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
86 if (aFeature.get() != NULL) {
87 QObjectPtrList anObjects;
88 anObjects.append(aFeature);
89 // the external feature should be removed with all references, sketch feature should be ignored
90 std::set<FeaturePtr> anIgnoredFeatures;
91 anIgnoredFeatures.insert(theSketch);
92 // the current feature should be ignored, because it can use the external feature in the
93 // attributes and, therefore have a references to it. So, the delete functionality tries
94 // to delete this feature. Test case is creation of a constraint on external point,
95 // use in this control after an external point, the point of the sketch.
96 anIgnoredFeatures.insert(theFeature);
97 XGUI_Workshop::deleteFeatures(anObjects, anIgnoredFeatures);
100 //removeExternalObject(anObject, theSketch, theFeature);
102 myExternalObjects.clear();
105 //********************************************************************
106 void PartSet_ExternalObjectsMgr::removeUnusedExternalObjects(const QObjectPtrList& theIgnoreObjects,
107 const CompositeFeaturePtr& theSketch,
108 const FeaturePtr& theFeature)
111 // TODO(nds): unite with removeExternal(), remove parameters
112 QObjectPtrList aUsedExternalObjects;
114 QObjectPtrList::const_iterator anIt = myExternalObjects.begin(), aLast = myExternalObjects.end();
115 for (; anIt != aLast; anIt++) {
116 ObjectPtr anObject = *anIt;
117 if (theIgnoreObjects.contains(anObject))
118 aUsedExternalObjects.append(anObject);
120 removeExternalObject(anObject, theSketch, theFeature);
122 myExternalObjects.clear();
123 //if (!aUsedExternalObjects.empty())
124 // myExternalObjects = aUsedExternalObjects;
127 //********************************************************************
128 void PartSet_ExternalObjectsMgr::removeExternalValidated(const CompositeFeaturePtr& theSketch,
129 const FeaturePtr& theFeature)
131 // TODO(nds): unite with removeExternal(), remove parameters
132 removeExternalObject(myExternalObjectValidated, theSketch, theFeature);
133 myExternalObjectValidated = ObjectPtr();
136 void PartSet_ExternalObjectsMgr::removeExternalObject(const ObjectPtr& theObject,
137 const CompositeFeaturePtr& theSketch,
138 const FeaturePtr& theFeature)
140 if (theObject.get()) {
141 DocumentPtr aDoc = theObject->document();
142 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
143 if (aFeature.get() != NULL) {
144 QObjectPtrList anObjects;
145 anObjects.append(aFeature);
146 // the external feature should be removed with all references, sketch feature should be ignored
147 std::set<FeaturePtr> anIgnoredFeatures;
148 anIgnoredFeatures.insert(theSketch);
149 // the current feature should be ignored, because it can use the external feature in the
150 // attributes and, therefore have a references to it. So, the delete functionality tries
151 // to delete this feature. Test case is creation of a constraint on external point,
152 // use in this control after an external point, the point of the sketch.
153 anIgnoredFeatures.insert(theFeature);
154 XGUI_Workshop::deleteFeatures(anObjects, anIgnoredFeatures);