1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include "ModuleBase_ISelection.h"
5 //********************************************************************
6 void ModuleBase_ISelection::appendSelected(const QList<ModuleBase_ViewerPrs> theValues,
7 QList<ModuleBase_ViewerPrs>& theValuesTo)
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());
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));
30 //********************************************************************
31 ResultPtr ModuleBase_ISelection::getResult(const ModuleBase_ViewerPrs& thePrs)
35 if (!thePrs.owner().IsNull()) {
36 ObjectPtr anObject = getSelectableObject(thePrs.owner());
37 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
40 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(thePrs.object());
46 //********************************************************************
47 GeomShapePtr ModuleBase_ISelection::getShape(const ModuleBase_ViewerPrs& thePrs)
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()) {
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();
66 //********************************************************************
67 QList<ModuleBase_ViewerPrs> ModuleBase_ISelection::getViewerPrs(const QObjectPtrList& theObjects)
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));