]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_ExternalObjectsMgr.cpp
Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
[modules/shaper.git] / src / PartSet / PartSet_ExternalObjectsMgr.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_ExternalObjectsMgr.cpp
4 // Created:     15 Apr 2015
5 // Author:      Natalia Ermolaeva
6
7 #include "PartSet_ExternalObjectsMgr.h"
8 #include "PartSet_Tools.h"
9
10 #include <XGUI_Workshop.h>
11
12 #include <QString>
13
14 PartSet_ExternalObjectsMgr::PartSet_ExternalObjectsMgr(const std::string& theExternal, const bool theDefaultValue)
15 : myUseExternal(theDefaultValue)
16 {
17   QString aIsExternal(theExternal.c_str());
18   if (!aIsExternal.isEmpty()) {
19     QString aStr = aIsExternal.toUpper();
20     myUseExternal = (aStr == "TRUE") || (aStr == "YES"); 
21   }
22 }
23
24 ObjectPtr PartSet_ExternalObjectsMgr::externalObject(const ObjectPtr& theSelectedObject,
25                                                      const GeomShapePtr& theShape,
26                                                      const CompositeFeaturePtr& theSketch)
27 {
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);
36   }
37   return aSelectedObject;
38 }
39
40 //********************************************************************
41 void PartSet_ExternalObjectsMgr::removeExternal(const CompositeFeaturePtr& theSketch,
42                                                 const FeaturePtr& theFeature)
43 {
44   QObjectPtrList::const_iterator anIt = myExternalObjects.begin(), aLast = myExternalObjects.end();
45   for (; anIt != aLast; anIt++) {
46     ObjectPtr anObject = *anIt;
47     if (anObject.get()) {
48       DocumentPtr aDoc = anObject->document();
49       FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
50       if (aFeature.get() != NULL) {
51         QObjectPtrList anObjects;
52         anObjects.append(aFeature);
53         // the external feature should be removed with all references, sketch feature should be ignored
54         std::set<FeaturePtr> anIgnoredFeatures;
55         anIgnoredFeatures.insert(theSketch);
56         // the current feature should be ignored, because it can use the external feature in the
57         // attributes and, therefore have a references to it. So, the delete functionality tries
58         // to delete this feature. Test case is creation of a constraint on external point,
59         // use in this control after an external point, the point of the sketch.
60         anIgnoredFeatures.insert(theFeature);
61         XGUI_Workshop::deleteFeatures(anObjects, anIgnoredFeatures);
62       }
63     }
64   }
65   myExternalObjects.clear();
66 }