+
+//********************************************************************
+void ModuleBase_ISelection::filterSelectionOnEqualPoints
+ (QList<ModuleBase_ViewerPrsPtr>& theSelected)
+{
+ QList<ModuleBase_ViewerPrsPtr> aCandidatesToRemove;
+ QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theSelected.begin(),
+ aLast = theSelected.end();
+ QList<ModuleBase_ViewerPrsPtr>::const_iterator aSubIt;
+
+ std::set<std::shared_ptr<GeomAPI_Vertex> > aVerticesMap;
+ for (; anIt != aLast; anIt++) {
+ ModuleBase_ViewerPrsPtr aPrs = *anIt;
+ std::shared_ptr<GeomAPI_Vertex> aGeomPrsVertex = getPresentationVertex(aPrs);
+ if (aGeomPrsVertex.get()) {
+ const TopoDS_Vertex& aPrsVertex = aGeomPrsVertex->impl<TopoDS_Vertex>();
+ std::set<std::shared_ptr<GeomAPI_Vertex> >::const_iterator anIt = aVerticesMap.begin(),
+ aLast = aVerticesMap.end();
+ bool aFound = false;
+ for (; anIt != aLast && !aFound; anIt++) {
+ std::shared_ptr<GeomAPI_Vertex> aGeomVertex = *anIt;
+ const TopoDS_Vertex& aVertex = aGeomVertex->impl<TopoDS_Vertex>();
+ gp_Pnt aPoint1 = BRep_Tool::Pnt(aVertex);
+ gp_Pnt aPoint2 = BRep_Tool::Pnt(aPrsVertex);
+
+ std::shared_ptr<GeomAPI_Pnt> aPnt1 = std::shared_ptr<GeomAPI_Pnt>
+ (new GeomAPI_Pnt(aPoint1.X(), aPoint1.Y(), aPoint1.Z()));
+ std::shared_ptr<GeomAPI_Pnt> aPnt2 = std::shared_ptr<GeomAPI_Pnt>
+ (new GeomAPI_Pnt(aPoint2.X(), aPoint2.Y(), aPoint2.Z()));
+ aFound = aPnt1->isEqual(aPnt2);
+ }
+ if (aFound) {
+ aCandidatesToRemove.append(aPrs);
+ continue;
+ }
+ aVerticesMap.insert(aGeomPrsVertex);
+ }
+ }
+ QList<ModuleBase_ViewerPrsPtr>::const_iterator aRemIt = aCandidatesToRemove.begin(),
+ aRemLast = aCandidatesToRemove.end();
+ for (; aRemIt != aRemLast; aRemIt++) {
+ theSelected.removeAll(*aRemIt);
+ }
+}
+
+std::shared_ptr<GeomAPI_Vertex> ModuleBase_ISelection::getPresentationVertex(
+ const ModuleBase_ViewerPrsPtr& thePrs)
+{
+ std::shared_ptr<GeomAPI_Vertex> 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<GeomAPI_Vertex>(new GeomAPI_Vertex(aPoint.X(), aPoint.Y(),
+ aPoint.Z()));
+ }
+ }
+ }
+ return aGeomVertex;
+}
+