X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_ISelection.cpp;h=0025283060036b8ad61910cd0c0baa0db9c1b471;hb=9aeb69897970e21212d6f8926ec33d2eb696f18d;hp=cff9fa134ae48aa270437c0f5992c18fbc3f07b6;hpb=dfb689721a73f8b65b0f61b593ef6421409bbf7b;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_ISelection.cpp b/src/ModuleBase/ModuleBase_ISelection.cpp index cff9fa134..002528306 100644 --- a/src/ModuleBase/ModuleBase_ISelection.cpp +++ b/src/ModuleBase/ModuleBase_ISelection.cpp @@ -2,59 +2,66 @@ #include "ModuleBase_ISelection.h" +#include "ModuleBase_ViewerPrs.h" + +#include +#include +#include +#include +#include + //******************************************************************** -void ModuleBase_ISelection::appendSelected(const QList theValues, - QList& theValuesTo) +void ModuleBase_ISelection::appendSelected(const QList theValues, + QList& theValuesTo) { // collect the objects from the viewer QObjectPtrList anExistedObjects; - QList::const_iterator aPrsIt = theValuesTo.begin(), + QList::const_iterator aPrsIt = theValuesTo.begin(), aPrsLast = theValuesTo.end(); for (; aPrsIt != aPrsLast; aPrsIt++) { - if ((*aPrsIt).owner() && (*aPrsIt).object()) - anExistedObjects.push_back((*aPrsIt).object()); + if ((*aPrsIt)->owner() && (*aPrsIt)->object()) + anExistedObjects.push_back((*aPrsIt)->object()); } - QList::const_iterator anIt = theValues.begin(), + QList::const_iterator anIt = theValues.begin(), aLast = theValues.end(); for (; anIt != aLast; anIt++) { - ObjectPtr anObject = (*anIt).object(); + ObjectPtr anObject = (*anIt)->object(); if (anObject.get() != NULL && !anExistedObjects.contains(anObject)) { - theValuesTo.append(ModuleBase_ViewerPrs(anObject, TopoDS_Shape(), NULL)); + theValuesTo.append(std::shared_ptr( + new ModuleBase_ViewerPrs(anObject, GeomShapePtr(), NULL))); } } } //******************************************************************** -ResultPtr ModuleBase_ISelection::getResult(const ModuleBase_ViewerPrs& thePrs) +ResultPtr ModuleBase_ISelection::getResult(const ModuleBase_ViewerPrsPtr& thePrs) { ResultPtr aResult; - if (!thePrs.owner().IsNull()) { - ObjectPtr anObject = getSelectableObject(thePrs.owner()); + if (thePrs->object().get()) + aResult = std::dynamic_pointer_cast(thePrs->object()); + else if (!thePrs->owner().IsNull()) { + ObjectPtr anObject = getSelectableObject(thePrs->owner()); aResult = std::dynamic_pointer_cast(anObject); } - else { - aResult = std::dynamic_pointer_cast(thePrs.object()); - } return aResult; } //******************************************************************** -GeomShapePtr ModuleBase_ISelection::getShape(const ModuleBase_ViewerPrs& thePrs) +GeomShapePtr ModuleBase_ISelection::getShape(const ModuleBase_ViewerPrsPtr& thePrs) { GeomShapePtr aShape; - const TopoDS_Shape& aTDSShape = thePrs.shape(); + const GeomShapePtr& aPrsShape = thePrs->shape(); // if only result is selected, an empty shape is set to the model - if (aTDSShape.IsNull()) { + if (!aPrsShape.get() || aPrsShape->isNull()) { } else { - aShape = GeomShapePtr(new GeomAPI_Shape()); - aShape->setImpl(new TopoDS_Shape(aTDSShape)); + aShape = aPrsShape; // If the result object is built on the same shape, the result shape here is empty one ResultPtr aResult = getResult(thePrs); if (aResult.get() && aShape->isEqual(aResult->shape())) @@ -64,15 +71,81 @@ GeomShapePtr ModuleBase_ISelection::getShape(const ModuleBase_ViewerPrs& thePrs) } //******************************************************************** -QList ModuleBase_ISelection::getViewerPrs(const QObjectPtrList& theObjects) +QList ModuleBase_ISelection::getViewerPrs(const QObjectPtrList& theObjects) { - QList aSelectedPrs; + QList aSelectedPrs; QObjectPtrList::const_iterator anIt = theObjects.begin(), aLast = theObjects.end(); for (; anIt != aLast; anIt++) { ObjectPtr anObject = *anIt; if (anObject.get() != NULL) { - aSelectedPrs.append(ModuleBase_ViewerPrs(anObject, TopoDS_Shape(), NULL)); + aSelectedPrs.append(std::shared_ptr( + new ModuleBase_ViewerPrs(anObject, GeomShapePtr(), NULL))); } } return aSelectedPrs; } + +//******************************************************************** +void ModuleBase_ISelection::filterSelectionOnEqualPoints + (QList& theSelected) +{ + QList aCandidatesToRemove; + QList::const_iterator anIt = theSelected.begin(), + aLast = theSelected.end(); + QList::const_iterator aSubIt; + + std::set > aVerticesMap; + for (; anIt != aLast; anIt++) { + ModuleBase_ViewerPrsPtr aPrs = *anIt; + std::shared_ptr aGeomPrsVertex = getPresentationVertex(aPrs); + if (aGeomPrsVertex.get()) { + const TopoDS_Vertex& aPrsVertex = aGeomPrsVertex->impl(); + std::set >::const_iterator anIt = aVerticesMap.begin(), + aLast = aVerticesMap.end(); + bool aFound = false; + for (; anIt != aLast && !aFound; anIt++) { + std::shared_ptr aGeomVertex = *anIt; + const TopoDS_Vertex& aVertex = aGeomVertex->impl(); + gp_Pnt aPoint1 = BRep_Tool::Pnt(aVertex); + gp_Pnt aPoint2 = BRep_Tool::Pnt(aPrsVertex); + + std::shared_ptr aPnt1 = std::shared_ptr + (new GeomAPI_Pnt(aPoint1.X(), aPoint1.Y(), aPoint1.Z())); + std::shared_ptr aPnt2 = std::shared_ptr + (new GeomAPI_Pnt(aPoint2.X(), aPoint2.Y(), aPoint2.Z())); + aFound = aPnt1->isEqual(aPnt2); + } + if (aFound) { + aCandidatesToRemove.append(aPrs); + continue; + } + aVerticesMap.insert(aGeomPrsVertex); + } + } + QList::const_iterator aRemIt = aCandidatesToRemove.begin(), + aRemLast = aCandidatesToRemove.end(); + for (; aRemIt != aRemLast; aRemIt++) { + theSelected.removeAll(*aRemIt); + } +} + +std::shared_ptr ModuleBase_ISelection::getPresentationVertex( + const ModuleBase_ViewerPrsPtr& thePrs) +{ + std::shared_ptr aGeomVertex; + Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(thePrs->owner()); + + if (!anOwner.IsNull() && anOwner->HasShape()) { + const TopoDS_Shape& aShape = anOwner->Shape(); + if (aShape.ShapeType() == TopAbs_VERTEX) { + const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape); + if (!aVertex.IsNull()) { + gp_Pnt aPoint = BRep_Tool::Pnt(aVertex); + aGeomVertex = std::shared_ptr(new GeomAPI_Vertex(aPoint.X(), aPoint.Y(), + aPoint.Z())); + } + } + } + return aGeomVertex; +} +