From: nds Date: Mon, 12 Oct 2015 05:33:04 +0000 (+0300) Subject: Equal points should not be used in the operation preselection. X-Git-Tag: V_1.4.0_demo2~13 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9af20d7ec247473224142e202f5f8bcbc8733f65;p=modules%2Fshaper.git Equal points should not be used in the operation preselection. --- diff --git a/src/GeomAPI/GeomAPI_Pnt.cpp b/src/GeomAPI/GeomAPI_Pnt.cpp index 0cf67c2ad..9138365cc 100644 --- a/src/GeomAPI/GeomAPI_Pnt.cpp +++ b/src/GeomAPI/GeomAPI_Pnt.cpp @@ -66,6 +66,11 @@ double GeomAPI_Pnt::distance(const std::shared_ptr& theOther) const return MY_PNT->Distance(theOther->impl()); } +bool GeomAPI_Pnt::isEqual(const std::shared_ptr& theOther) const +{ + return distance(theOther) < Precision::Confusion(); +} + std::shared_ptr GeomAPI_Pnt::to2D(const std::shared_ptr& theOrigin, const std::shared_ptr& theDirX, const std::shared_ptr& theDirY) { diff --git a/src/GeomAPI/GeomAPI_Pnt.h b/src/GeomAPI/GeomAPI_Pnt.h index a3016b943..17c2c0db8 100644 --- a/src/GeomAPI/GeomAPI_Pnt.h +++ b/src/GeomAPI/GeomAPI_Pnt.h @@ -58,6 +58,10 @@ class GeomAPI_Pnt : public GeomAPI_Interface GEOMAPI_EXPORT double distance(const std::shared_ptr& theOther) const; + /// Returns whether the distance between two points is less then precision confusion + GEOMAPI_EXPORT + bool isEqual(const std::shared_ptr& theOther) const; + /// Projects a point to the plane defined by the origin and 2 axes vectors in this plane GEOMAPI_EXPORT std::shared_ptr to2D(const std::shared_ptr& theOrigin, diff --git a/src/ModuleBase/ModuleBase_ISelection.cpp b/src/ModuleBase/ModuleBase_ISelection.cpp index cff9fa134..9eaf186dc 100644 --- a/src/ModuleBase/ModuleBase_ISelection.cpp +++ b/src/ModuleBase/ModuleBase_ISelection.cpp @@ -2,6 +2,12 @@ #include "ModuleBase_ISelection.h" +#include +#include +#include +#include +#include + //******************************************************************** void ModuleBase_ISelection::appendSelected(const QList theValues, QList& theValuesTo) @@ -76,3 +82,60 @@ QList ModuleBase_ISelection::getViewerPrs(const QObjectPtr } return aSelectedPrs; } + +//******************************************************************** +void ModuleBase_ISelection::filterPreselectionOnEqualPoints + (QList& theSelected) +{ + QList aCandidatesToRemove; + QList::const_iterator anIt = theSelected.begin(), + aLast = theSelected.end(); + QList::const_iterator aSubIt; + for (; anIt != aLast; anIt++) { + aSubIt = anIt; + aSubIt++; + for (; aSubIt != aLast; aSubIt++) { + if (isEqualVertices(*anIt, *aSubIt)) { + aCandidatesToRemove.append(*aSubIt); + break; + } + } + } + QList::const_iterator aRemIt = aCandidatesToRemove.begin(), + aRemLast = aCandidatesToRemove.end(); + for (; aRemIt != aRemLast; aRemIt++) { + theSelected.removeAll(*aRemIt); + } +} + +bool ModuleBase_ISelection::isEqualVertices(const ModuleBase_ViewerPrs thePrs1, + const ModuleBase_ViewerPrs thePrs2) +{ + bool isEqual = false; + Handle(StdSelect_BRepOwner) anOwner1 = Handle(StdSelect_BRepOwner)::DownCast(thePrs1.owner()); + Handle(StdSelect_BRepOwner) anOwner2 = Handle(StdSelect_BRepOwner)::DownCast(thePrs2.owner()); + + if (!anOwner1.IsNull() && anOwner1->HasShape() && + !anOwner2.IsNull() && anOwner2->HasShape()) { + const TopoDS_Shape& aShape1 = anOwner1->Shape(); + const TopoDS_Shape& aShape2 = anOwner2->Shape(); + //TopAbs_ShapeEnum aShapeType = aShape.ShapeType(); + if (aShape1.ShapeType() == TopAbs_VERTEX && + aShape2.ShapeType() == TopAbs_VERTEX) { + const TopoDS_Vertex& aVertex1 = TopoDS::Vertex(aShape1); + const TopoDS_Vertex& aVertex2 = TopoDS::Vertex(aShape2); + if (!aVertex1.IsNull() && !aVertex2.IsNull()) { + gp_Pnt aPoint1 = BRep_Tool::Pnt(aVertex1); + gp_Pnt aPoint2 = BRep_Tool::Pnt(aVertex2); + + 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())); + isEqual = aPnt1->isEqual(aPnt2); + } + } + } + + return isEqual; +} diff --git a/src/ModuleBase/ModuleBase_ISelection.h b/src/ModuleBase/ModuleBase_ISelection.h index 2c60a76ac..f7289bab7 100644 --- a/src/ModuleBase/ModuleBase_ISelection.h +++ b/src/ModuleBase/ModuleBase_ISelection.h @@ -107,6 +107,17 @@ class ModuleBase_ISelection //! \return a list of prs, where only object is not empty static MODULEBASE_EXPORT QList getViewerPrs( const QObjectPtrList& theObjects); + + /// Removes selection items where owners have equal vertices. The first + /// owner with the qual vertex stays in the list. + static MODULEBASE_EXPORT void filterPreselectionOnEqualPoints + (QList& theSelected); +private: + /// Returns true if the presentations have an owner with a vertex and these vertices are equal. + /// \param thePrs1 the first viewer selected presentation + /// \param thePrs2 the second viewer selected presentation + static bool isEqualVertices(const ModuleBase_ViewerPrs thePrs1, + const ModuleBase_ViewerPrs thePrs2); }; #endif diff --git a/src/ModuleBase/ModuleBase_OperationFeature.cpp b/src/ModuleBase/ModuleBase_OperationFeature.cpp index b3540002f..7458ae9fd 100755 --- a/src/ModuleBase/ModuleBase_OperationFeature.cpp +++ b/src/ModuleBase/ModuleBase_OperationFeature.cpp @@ -299,6 +299,8 @@ void ModuleBase_OperationFeature::activateByPreselection() if (myPreSelection.empty()) return; + ModuleBase_ISelection::filterPreselectionOnEqualPoints(myPreSelection); + ModuleBase_ModelWidget* aFilledWgt = 0; ModuleBase_IPropertyPanel* aPropertyPanel = propertyPanel(); if (aPropertyPanel) { diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp index 02683b355..99468bcf0 100755 --- a/src/PartSet/PartSet_Validators.cpp +++ b/src/PartSet/PartSet_Validators.cpp @@ -39,6 +39,8 @@ int shapesNbPoints(const ModuleBase_ISelection* theSelection) { QList aList = theSelection->getSelected(ModuleBase_ISelection::Viewer); + ModuleBase_ISelection::filterPreselectionOnEqualPoints(aList); + int aCount = 0; foreach (ModuleBase_ViewerPrs aPrs, aList) { const TopoDS_Shape& aShape = aPrs.shape();