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 ObjectPtr PartSet_ExternalObjectsMgr::externalObjectValidated(const ObjectPtr& theSelectedObject,
42 const GeomShapePtr& theShape,
43 const CompositeFeaturePtr& theSketch)
45 // TODO(nds): unite with externalObject()
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 myExternalObjectValidated = aSelectedObject;
55 return aSelectedObject;
58 //********************************************************************
59 void PartSet_ExternalObjectsMgr::removeExternal(const CompositeFeaturePtr& theSketch,
60 const FeaturePtr& theFeature)
62 QObjectPtrList::const_iterator anIt = myExternalObjects.begin(), aLast = myExternalObjects.end();
63 for (; anIt != aLast; anIt++) {
64 ObjectPtr anObject = *anIt;
66 DocumentPtr aDoc = anObject->document();
67 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
68 if (aFeature.get() != NULL) {
69 QObjectPtrList anObjects;
70 anObjects.append(aFeature);
71 // the external feature should be removed with all references, sketch feature should be ignored
72 std::set<FeaturePtr> anIgnoredFeatures;
73 anIgnoredFeatures.insert(theSketch);
74 // the current feature should be ignored, because it can use the external feature in the
75 // attributes and, therefore have a references to it. So, the delete functionality tries
76 // to delete this feature. Test case is creation of a constraint on external point,
77 // use in this control after an external point, the point of the sketch.
78 anIgnoredFeatures.insert(theFeature);
79 XGUI_Workshop::deleteFeatures(anObjects, anIgnoredFeatures);
82 //removeExternalObject(anObject, theSketch, theFeature);
84 myExternalObjects.clear();
87 //********************************************************************
88 void PartSet_ExternalObjectsMgr::removeUnusedExternalObjects(const QObjectPtrList& theIgnoreObjects,
89 const CompositeFeaturePtr& theSketch,
90 const FeaturePtr& theFeature)
93 // TODO(nds): unite with removeExternal(), remove parameters
94 QObjectPtrList aUsedExternalObjects;
96 QObjectPtrList::const_iterator anIt = myExternalObjects.begin(), aLast = myExternalObjects.end();
97 for (; anIt != aLast; anIt++) {
98 ObjectPtr anObject = *anIt;
99 if (theIgnoreObjects.contains(anObject))
100 aUsedExternalObjects.append(anObject);
102 removeExternalObject(anObject, theSketch, theFeature);
104 myExternalObjects.clear();
105 //if (!aUsedExternalObjects.empty())
106 // myExternalObjects = aUsedExternalObjects;
109 //********************************************************************
110 void PartSet_ExternalObjectsMgr::removeExternalValidated(const CompositeFeaturePtr& theSketch,
111 const FeaturePtr& theFeature)
113 // TODO(nds): unite with removeExternal(), remove parameters
114 removeExternalObject(myExternalObjectValidated, theSketch, theFeature);
115 myExternalObjectValidated = ObjectPtr();
118 void PartSet_ExternalObjectsMgr::removeExternalObject(const ObjectPtr& theObject,
119 const CompositeFeaturePtr& theSketch,
120 const FeaturePtr& theFeature)
122 if (theObject.get()) {
123 DocumentPtr aDoc = theObject->document();
124 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
125 if (aFeature.get() != NULL) {
126 QObjectPtrList anObjects;
127 anObjects.append(aFeature);
128 // the external feature should be removed with all references, sketch feature should be ignored
129 std::set<FeaturePtr> anIgnoredFeatures;
130 anIgnoredFeatures.insert(theSketch);
131 // the current feature should be ignored, because it can use the external feature in the
132 // attributes and, therefore have a references to it. So, the delete functionality tries
133 // to delete this feature. Test case is creation of a constraint on external point,
134 // use in this control after an external point, the point of the sketch.
135 anIgnoredFeatures.insert(theFeature);
136 XGUI_Workshop::deleteFeatures(anObjects, anIgnoredFeatures);