Salome HOME
Shape plane filter should process shapes of objects selected in object browser.
[modules/shaper.git] / src / ModuleBase / ModuleBase_ISelection.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 #include "ModuleBase_ISelection.h"
4
5 //********************************************************************
6 void ModuleBase_ISelection::appendSelected(const QList<ModuleBase_ViewerPrs> theValues,
7                                            QList<ModuleBase_ViewerPrs>& theValuesTo)
8 {
9   // collect the objects from the viewer
10   QObjectPtrList anExistedObjects;
11   QList<ModuleBase_ViewerPrs>::const_iterator aPrsIt = theValuesTo.begin(),
12                                               aPrsLast = theValuesTo.end();
13   for (; aPrsIt != aPrsLast; aPrsIt++) {
14     if ((*aPrsIt).owner() && (*aPrsIt).object())
15       anExistedObjects.push_back((*aPrsIt).object());
16   }
17
18
19   QList<ModuleBase_ViewerPrs>::const_iterator anIt = theValues.begin(),
20                                               aLast = theValues.end();
21   for (; anIt != aLast; anIt++) {
22     ObjectPtr anObject = (*anIt).object();
23     if (anObject.get() != NULL && !anExistedObjects.contains(anObject)) {
24       theValuesTo.append(ModuleBase_ViewerPrs(anObject, TopoDS_Shape(), NULL));
25     }
26   }
27
28 }
29
30 //********************************************************************
31 ResultPtr ModuleBase_ISelection::getResult(const ModuleBase_ViewerPrs& thePrs)
32 {
33   ResultPtr aResult;
34
35   if (!thePrs.owner().IsNull()) {
36     ObjectPtr anObject = getSelectableObject(thePrs.owner());
37     aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
38   }
39   else {
40     aResult = std::dynamic_pointer_cast<ModelAPI_Result>(thePrs.object());
41   }
42
43   return aResult;
44 }
45
46 //********************************************************************
47 GeomShapePtr ModuleBase_ISelection::getShape(const ModuleBase_ViewerPrs& thePrs)
48 {
49   GeomShapePtr aShape;
50
51   const TopoDS_Shape& aTDSShape = thePrs.shape();
52   // if only result is selected, an empty shape is set to the model
53   if (aTDSShape.IsNull()) {
54   }
55   else {
56     aShape = GeomShapePtr(new GeomAPI_Shape());
57     aShape->setImpl(new TopoDS_Shape(aTDSShape));
58     // If the result object is built on the same shape, the result shape here is empty one
59     ResultPtr aResult = getResult(thePrs);
60     if (aResult.get() && aShape->isEqual(aResult->shape()))
61       aShape = GeomShapePtr();
62   }
63   return aShape;
64 }
65
66 //********************************************************************
67 QList<ModuleBase_ViewerPrs> ModuleBase_ISelection::getViewerPrs(const QObjectPtrList& theObjects)
68 {
69   QList<ModuleBase_ViewerPrs> aSelectedPrs;
70   QObjectPtrList::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
71   for (; anIt != aLast; anIt++) {
72     ObjectPtr anObject = *anIt;
73     if (anObject.get() != NULL) {
74       aSelectedPrs.append(ModuleBase_ViewerPrs(anObject, TopoDS_Shape(), NULL));
75     }
76   }
77   return aSelectedPrs;
78 }