From 3c1624950a2ded5d420cd6931581c0692c3b8964 Mon Sep 17 00:00:00 2001 From: ski Date: Thu, 13 Oct 2016 13:40:12 +0300 Subject: [PATCH] 0027915: Foundation Classes - remove the class NCollection_QuickSort Class NCollection_QuickSort was removed. Direction of dimension lines was corrected. Updated porting notes. minor corrections in AIS --- dox/dev_guides/upgrade/upgrade.md | 7 ++ src/AIS/AIS_LengthDimension.cxx | 48 +++++--- .../BRepExtrema_DistShapeShape.cxx | 40 ++----- src/NCollection/FILES | 1 - src/NCollection/NCollection_QuickSort.hxx | 107 ------------------ tests/bugs/moddata_3/bug24896 | 4 +- tests/bugs/vis/bug26056 | 18 ++- 7 files changed, 61 insertions(+), 164 deletions(-) delete mode 100644 src/NCollection/NCollection_QuickSort.hxx diff --git a/dox/dev_guides/upgrade/upgrade.md b/dox/dev_guides/upgrade/upgrade.md index 834113253e..bed7f90947 100644 --- a/dox/dev_guides/upgrade/upgrade.md +++ b/dox/dev_guides/upgrade/upgrade.md @@ -1081,3 +1081,10 @@ The following obsolete features have been removed: @subsection upgrade_occt710_correction_of_TObj_Model Correction in TObj_Model class Methods *TObj_Model::SaveAs* and *TObj_Model::Load* receive *TCollection_ExtendedString* filename arguments instead of char*. This shows that the filename may be not-ASCII explicitly. Also it makes OCAF API related to this functionality more conform. + + +@subsection upgrade_occt710_sorttools Removal of NCollection_QuickSort class + +Class *NCollection_QuickSort* has been removed. +The code that used the tools provided by that class should be corrected manually. +The recommended approach is to use sorting algorithms provided by STL. diff --git a/src/AIS/AIS_LengthDimension.cxx b/src/AIS/AIS_LengthDimension.cxx index 7249c67ec7..cd35bf3175 100755 --- a/src/AIS/AIS_LengthDimension.cxx +++ b/src/AIS/AIS_LengthDimension.cxx @@ -435,32 +435,44 @@ Standard_Boolean AIS_LengthDimension::InitEdgeFaceLength (const TopoDS_Edge& the const TopoDS_Face& theFace, gp_Dir& theEdgeDir) { - // Compute edge direction - BRepAdaptor_Curve aCurveAdaptor (theEdge); - Handle(Geom_Curve) aCurve = Handle(Geom_Curve)::DownCast (aCurveAdaptor.Curve().Curve()->Transformed (aCurveAdaptor.Trsf())); - if (aCurve.IsNull()) + theEdgeDir = gp::DX(); + + // Find attachment points (closest distance between the edge and the face) + BRepExtrema_DistShapeShape aDistAdaptor (theEdge, theFace, Extrema_ExtFlag_MIN); + if (!aDistAdaptor.IsDone() || aDistAdaptor.NbSolution() <1) { return Standard_False; } - Standard_Real aFirst = aCurveAdaptor.FirstParameter(); - Standard_Real aLast = aCurveAdaptor.LastParameter(); - gp_Pnt aFirstPoint = !Precision::IsInfinite (aFirst) ? aCurve->Value (aFirst) : gp::Origin(); - gp_Pnt aSecondPoint = !Precision::IsInfinite (aLast) ? aCurve->Value (aLast) : gp::Origin(); - gce_MakeDir aMakeDir (aFirstPoint, aSecondPoint); - if (!aMakeDir.IsDone()) + myFirstPoint = aDistAdaptor.PointOnShape1 (1); + mySecondPoint = aDistAdaptor.PointOnShape2 (1); + + // Take direction for dimension line (will be orthogonalized later) parallel to edge + BRepAdaptor_Curve aCurveAdaptor (theEdge); + Standard_Real aParam; + if (aDistAdaptor.SupportOnShape1 (1).ShapeType() == TopAbs_EDGE) { - return Standard_False; + aDistAdaptor.ParOnEdgeS1 (1, aParam); + } + else + { + Standard_Real aD1 = aCurveAdaptor.Value(aCurveAdaptor.FirstParameter()).SquareDistance (myFirstPoint); + Standard_Real aD2 = aCurveAdaptor.Value(aCurveAdaptor.LastParameter()).SquareDistance (myFirstPoint); + aParam = (aD1 < aD2 ? aCurveAdaptor.FirstParameter() : aCurveAdaptor.LastParameter()); + } + gp_Pnt aP; + gp_Vec aV; + aCurveAdaptor.D1 (aParam, aP, aV); + if (aV.SquareMagnitude() > gp::Resolution()) + { + theEdgeDir = aV; } - theEdgeDir = aMakeDir.Value(); - // Find attachment points - BRepExtrema_DistShapeShape aDistAdaptor (theEdge, theFace, Extrema_ExtFlag_MIN); - if (!aDistAdaptor.IsDone()) + // reverse direction if parameter is close to the end of the curve, + // to reduce chances to have overlapping between dimension line and edge + if (Abs (aParam - aCurveAdaptor.FirstParameter()) < Abs (aParam - aCurveAdaptor.LastParameter())) { - return Standard_False; + theEdgeDir.Reverse(); } - myFirstPoint = aDistAdaptor.PointOnShape1 (1); - mySecondPoint = aDistAdaptor.PointOnShape2 (1); return IsValidPoints (myFirstPoint, mySecondPoint); } diff --git a/src/BRepExtrema/BRepExtrema_DistShapeShape.cxx b/src/BRepExtrema/BRepExtrema_DistShapeShape.cxx index 3c20114bc4..1d88441df7 100644 --- a/src/BRepExtrema/BRepExtrema_DistShapeShape.cxx +++ b/src/BRepExtrema/BRepExtrema_DistShapeShape.cxx @@ -36,10 +36,10 @@ #include #include #include -#include #include #include +#include namespace { @@ -91,38 +91,14 @@ namespace Index2 (theIndex2), Distance (theDistance) {} }; -} - -template<> -class NCollection_Comparator -{ -public: - - Standard_Boolean IsLower (const BRepExtrema_CheckPair& theLeft, const BRepExtrema_CheckPair& theRight) const - { - return theLeft.Distance < theRight.Distance; - } - - Standard_Boolean IsGreater (const BRepExtrema_CheckPair& theLeft, const BRepExtrema_CheckPair& theRight) const - { - return theLeft.Distance > theRight.Distance; - } - Standard_Boolean IsEqual (const BRepExtrema_CheckPair& theLeft, const BRepExtrema_CheckPair& theRight) const + // Used by std::sort function + static Standard_Boolean BRepExtrema_CheckPair_Comparator (const BRepExtrema_CheckPair& theLeft, + const BRepExtrema_CheckPair& theRight) { - return theLeft.Distance == theRight.Distance; + return (theLeft.Distance < theRight.Distance); } - - Standard_Boolean IsLowerEqual (const BRepExtrema_CheckPair& theLeft, const BRepExtrema_CheckPair& theRight) const - { - return theLeft.Distance <= theRight.Distance; - } - - Standard_Boolean IsGreaterEqual (const BRepExtrema_CheckPair& theLeft, const BRepExtrema_CheckPair& theRight) const - { - return theLeft.Distance >= theRight.Distance; - } -}; +} //======================================================================= //function : DistanceMapMap @@ -149,8 +125,8 @@ void BRepExtrema_DistShapeShape::DistanceMapMap (const TopTools_IndexedMapOfShap } } - NCollection_QuickSort, BRepExtrema_CheckPair>::Perform (aPairList, NCollection_Comparator(), - aPairList.Lower(), aPairList.Upper()); + std::stable_sort(aPairList.begin(), aPairList.end(), BRepExtrema_CheckPair_Comparator); + for (NCollection_Vector::Iterator aPairIter (aPairList); aPairIter.More(); aPairIter.Next()) { diff --git a/src/NCollection/FILES b/src/NCollection/FILES index 2d2def7b5e..32fe100f96 100755 --- a/src/NCollection/FILES +++ b/src/NCollection/FILES @@ -51,7 +51,6 @@ NCollection_ListNode.hxx NCollection_LocalArray.hxx NCollection_Map.hxx NCollection_Mat4.hxx -NCollection_QuickSort.hxx NCollection_Sequence.hxx NCollection_Shared.hxx NCollection_SparseArray.hxx diff --git a/src/NCollection/NCollection_QuickSort.hxx b/src/NCollection/NCollection_QuickSort.hxx deleted file mode 100644 index b83a4c50ce..0000000000 --- a/src/NCollection/NCollection_QuickSort.hxx +++ /dev/null @@ -1,107 +0,0 @@ -// Created on: 2011-01-27 -// Created by: KGV -// Copyright (c) 2011-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _NCollection_QuickSort_HeaderFile -#define _NCollection_QuickSort_HeaderFile - -#include -#include - -/** - * Perform sorting of enumerable collection with QuickSort algorithm. - * Enumerable collection should provide the random access to its values - * by index number with methods Value(theId) and ChangeValue(theId). - * Currently it supposed to be used with NCollection_Sequence and NCollection_Vector. - * - * Usage sample: - * // input sequence - * NCollection_Sequence aSequence; - * // perform sorting for the whole sequence. - * NCollection_QuickSort, Standard_Real> - * ::Perform (aSequence, NCollection_Comparator(), - * 1, aSequence.Size()); - */ -template -class NCollection_QuickSort -{ -public: - - //! Main entry call to perform sorting - static void Perform (TheCollType& theEnumColl, - const NCollection_Comparator& theComparator, - const Standard_Integer theLower, - const Standard_Integer theUpper) - { - if (theLower < theUpper) - { - Standard_Integer aPivotPosition = Partition (theEnumColl, theComparator, - theLower, theUpper); - if (theLower < aPivotPosition) - { - // recursive call - Perform (theEnumColl, theComparator, - theLower, aPivotPosition - 1); - } - // recursive call - Perform (theEnumColl, theComparator, - aPivotPosition + 1, theUpper); - } - } - -private: - - //! Auxiliary function - static void SwapValues (TheItemType& x, TheItemType& y) - { - TheItemType aCopy = x; - x = y; - y = aCopy; - } - - static Standard_Integer Partition (TheCollType& theEnumColl, - const NCollection_Comparator& theComparator, - const Standard_Integer theLower, - const Standard_Integer theUpper) - { - Standard_Integer anIdLeft (theLower), anIdRight (theUpper); - const TheItemType aPivot = theEnumColl.Value (theLower); - - while (anIdLeft < anIdRight) - { - while (theComparator.IsGreater (theEnumColl.Value (anIdRight), aPivot)) - { - --anIdRight; - } - while ((anIdLeft < anIdRight) && - theComparator.IsLowerEqual (theEnumColl.Value (anIdLeft), aPivot)) - { - ++anIdLeft; - } - - if (anIdLeft < anIdRight) - { - SwapValues (theEnumColl.ChangeValue (anIdLeft), - theEnumColl.ChangeValue (anIdRight)); - } - } - - theEnumColl.ChangeValue (theLower) = theEnumColl.Value (anIdRight); - theEnumColl.ChangeValue (anIdRight) = aPivot; - return anIdRight; - } - -}; - -#endif /*_NCollection_QuickSort_HeaderFile*/ diff --git a/tests/bugs/moddata_3/bug24896 b/tests/bugs/moddata_3/bug24896 index b36708054d..5fca32d7c8 100644 --- a/tests/bugs/moddata_3/bug24896 +++ b/tests/bugs/moddata_3/bug24896 @@ -22,7 +22,7 @@ if { [expr abs( ${dist} - ${good_dist} )] > ${toler} } { # 2 # Point 3D : 66.6, -11.8556887483839, 0.3 -regexp { +Point 3D : +([-0-9.+eE]+), +([-0-9.+eE]+), +([-0-9.+eE]+)} [ dump d ] full x1 y1 z1 +regexp { +Point 3D : +([-0-9.+eE]+), +([-0-9.+eE]+), +([-0-9.+eE]+)} [ dump d2 ] full x1 y1 z1 set good_x1 66.6 set good_y1 -11.8556887483839 set good_z1 0.3 @@ -39,7 +39,7 @@ if { [expr abs( ${z1} - ${good_z1} )] > ${toler} } { # 3 # Point 3D : 66.6, 11.8556887323157, 0.3 -regexp { +Point 3D : +([-0-9.+eE]+), +([-0-9.+eE]+), +([-0-9.+eE]+)} [ dump d2 ] full x2 y2 z2 +regexp { +Point 3D : +([-0-9.+eE]+), +([-0-9.+eE]+), +([-0-9.+eE]+)} [ dump d ] full x2 y2 z2 set good_x2 66.6 set good_y2 11.8556887323157 set good_z2 0.3 diff --git a/tests/bugs/vis/bug26056 b/tests/bugs/vis/bug26056 index 45be71c18f..a3f76458c0 100644 --- a/tests/bugs/vis/bug26056 +++ b/tests/bugs/vis/bug26056 @@ -4,22 +4,32 @@ puts "AIS_LengthDimension can not build dimension for face-edge or edge-face" puts "============" puts "" puts "Tests case of edge-face and face-edge input geometry for dimension" + pload MODELING VISUALIZATION -line aLine 0 -100 0 1 0 0 -mkedge anEdge aLine -100 100 plane aPlane 0 0 50 0 0 1 mkface aFace aPlane -100 100 -100 100 -line aLine2 0 0 100 1 1 0 +line aLine 0 -100 0 1 0 0 +mkedge anEdge aLine -100 100 + +line aLine2 0 0 100 1 1 0.1 mkedge anEdge2 aLine2 -150 150 +circle aCirc1 30 -30 100 0.3 -0.3 1 20. +mkedge anEdge3 aCirc1 + +circle aCirc2 -130 -30 100 0.3 -0.3 1 20. +mkedge anEdge4 aCirc2 30. 180. + vinit View1 vclear vaxo -vdisplay anEdge anEdge2 aFace +vdisplay anEdge anEdge2 anEdge3 anEdge4 aFace vdimension aDim1 -length -shapes anEdge aFace -text 15 3d sh vdimension aDim2 -length -shapes aFace anEdge2 -text 15 3d sh +vdimension aDim3 -length -shapes aFace anEdge3 -text 15 3d sh +vdimension aDim4 -length -shapes aFace anEdge4 -text 15 3d sh vfit checkview -screenshot -3d -path ${imagedir}/${test_image}.png -- 2.20.1