From 047d8bf632f19f16e097ef80fba5f6345ccf0b0d Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 26 May 2015 13:56:05 +0300 Subject: [PATCH 01/11] Remove redundant code --- src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx b/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx index 8a35f1681..00b35eaec 100644 --- a/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx +++ b/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx @@ -400,7 +400,6 @@ void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument() // TODO supprimer les lignes qui ne servent à rien le cas échéant SUIT_ViewWindow* theViewWindow = getDesktop()->activeWindow(); - std::map< std::string , std::vector >::iterator AISit; SOCC_Viewer* soccViewer = (SOCC_Viewer*)(theViewWindow->getViewManager()->getViewModel()); if (!myEditCurrentArgument->isEnabled()) @@ -434,17 +433,6 @@ void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument() if ( myEditCurrentArgument == mySelectionGroup->LineEdit1 ) { myFace = aSelectedObject; - AISit = soccViewer->entry2aisobjects.find(myFaceEntry.toStdString()); - if (AISit == soccViewer->entry2aisobjects.end()) - return; - - Handle(AIS_InteractiveObject) myAIS = (*AISit).second[0]; - Handle(GEOM_AISShape) myAISShape; - if( myAIS->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) { - myAISShape = Handle(GEOM_AISShape)::DownCast( myAIS ); - } - else - return ; SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); if ( !study ) return; @@ -455,7 +443,7 @@ void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument() PropMap propMap = study->getObjectProperties( vm->getGlobalId(), myFaceEntry ); QString theImgFileName = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString(); if ( theImgFileName.isEmpty() ) - return ; + return; // Setting the image caracteristics myDetector->SetPath( theImgFileName.toStdString() ); From c3778fc96ed24ce5cf1ef7f3fca152390c6c279f Mon Sep 17 00:00:00 2001 From: abk Date: Wed, 24 Jun 2015 21:20:39 +0300 Subject: [PATCH 02/11] Methods 'CurveCreator_Utils::constructShape' and 'Sketcher_Utils::MakeInterpolation' were changed to interpolate each spline section by the cubic B-spline passing through the control points that the tangent vector in each control point P is calculated by the following way: - if point P is preceded by a control point A and is followed by a control point B then the tangent vector is equal to (P - A) / |P - A| + (B - P) / |B - P|; - if point P is preceded by a control point A but is not followed by any control point then the tangent vector is equal to P - A; - if point P is followed by a control point B but is not preceded by any control point then the tangent vector is equal to B - P. --- src/CurveCreator/CurveCreator_Utils.cxx | 246 ++++++++++++++---------- src/SKETCHER/Sketcher_Utils.cxx | 161 ++++++++++++---- 2 files changed, 269 insertions(+), 138 deletions(-) diff --git a/src/CurveCreator/CurveCreator_Utils.cxx b/src/CurveCreator/CurveCreator_Utils.cxx index 7b6075c2b..52fab0c1c 100644 --- a/src/CurveCreator/CurveCreator_Utils.cxx +++ b/src/CurveCreator/CurveCreator_Utils.cxx @@ -183,116 +183,168 @@ gp_Pnt CurveCreator_Utils::ConvertClickToPoint( int x, int y, Handle(V3d_View) a return ResultPoint; } -void CurveCreator_Utils::constructShape( const CurveCreator_ICurve* theCurve, - TopoDS_Shape& theShape ) +//======================================================================= +// function : constructBSpline +// purpose : +// The algorithm builds the cubic B-spline passing through the points that the +// tangent vector in each given point P is calculated by the following way: +// if point P is preceded by a point A and is followed by a point B then +// the tangent vector is equal to (P - A) / |P - A| + (B - P) / |B - P|; +// if point P is preceded by a point A but is not followed by any point then +// the tangent vector is equal to P - A; +// if point P is followed by a point B but is not preceded by any point then +// the tangent vector is equal to B - P. +//======================================================================= +static bool constructBSpline( + const Handle(TColgp_HArray1OfPnt)& thePoints, + const Standard_Boolean theIsClosed, + Handle(Geom_BSplineCurve)& theBSpline) +{ + const int aPointCount = thePoints->Length(); + if (aPointCount <= 1) + { + return false; + } + + // Calculate the tangents. + TColgp_Array1OfVec aTangents(1, aPointCount); + Handle(TColStd_HArray1OfBoolean) aTangentFlags = + new TColStd_HArray1OfBoolean(1, aPointCount); + GeomAPI_Interpolate aInterpolator(thePoints, theIsClosed, 0); + if (aPointCount == 2) + { + aTangentFlags->SetValue(1, Standard_False); + aTangentFlags->SetValue(2, Standard_False); + } + else + { + for (Standard_Integer aPN = 1; aPN <= aPointCount; ++aPN) + { + gp_Vec aTangent; + if (aPN != 1 || theIsClosed) + { + const Standard_Integer aPN1 = (aPN != 1) ? (aPN - 1) : aPointCount; + aTangent = gp_Vec(thePoints->Value(aPN1), + thePoints->Value(aPN)).Normalized(); + } + if (aPN < aPointCount || theIsClosed) + { + const Standard_Integer aPN2 = (aPN != aPointCount) ? (aPN + 1) : 1; + const gp_Vec aTangent2 = aTangent + + gp_Vec(thePoints->Value(aPN), thePoints->Value(aPN2)).Normalized(); + if (aTangent2.SquareMagnitude() >= Precision::SquareConfusion()) + { + aTangent = aTangent2.Normalized(); + } + else + { + aTangent = -aTangent; + } + } + aTangents.SetValue(aPN, aTangent); + aTangentFlags->SetValue(aPN, Standard_True); + } + } + + // Interpolate. + aInterpolator.Load(aTangents, aTangentFlags, Standard_False); + aInterpolator.Perform(); + const bool aResult = (aInterpolator.IsDone() == Standard_True); + if (aResult) + { + theBSpline = aInterpolator.Curve(); + } + return aResult; +} + +//======================================================================= +// function : constructShape +// purpose : +//======================================================================= +void CurveCreator_Utils::constructShape( + const CurveCreator_ICurve* theCurve, TopoDS_Shape& theShape) { BRep_Builder aBuilder; - TopoDS_Compound aComp; - aBuilder.MakeCompound( aComp ); - for( int iSection = 0 ; iSection < theCurve->getNbSections() ; iSection++ ) + TopoDS_Compound aShape; + aBuilder.MakeCompound(aShape); + const int aSectionCount = theCurve->getNbSections(); + for (int aSectionI = 0; aSectionI < aSectionCount; ++aSectionI) { - int theISection = iSection; - - CurveCreator::SectionType aSectType = theCurve->getSectionType( theISection ); - int aPointSize = theCurve->getNbPoints( theISection ); - if ( aPointSize == 0 ) + const int aTmpPointCount = theCurve->getNbPoints(aSectionI); + if (aTmpPointCount == 0) + { continue; - - bool aSectIsClosed = theCurve->isClosed( theISection ); - bool isPolyline = aSectType == CurveCreator::Polyline; - - int iPoint = 0; - gp_Pnt aPrevPoint, aPoint; - // filters the curve points to skip equal points - std::vector aPoints; - CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPoint ); - aPoints.push_back( aPoint ); - aPrevPoint = aPoint; - iPoint++; - for( ; iPoint < aPointSize; iPoint++ ) { - CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPoint ); - if ( !isEqualPoints( aPrevPoint, aPoint ) ) - aPoints.push_back( aPoint ); - aPrevPoint = aPoint; } - int aNbPoints = aPoints.size(); - if ( aNbPoints == 1 ) { - aPoint = aPoints.front(); - TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex(); - aBuilder.Add( aComp, aVertex ); + // Get the different points. + std::vector aTmpPoints; + gp_Pnt aFirstPoint; + CurveCreator_UtilsICurve::getPoint(theCurve, aSectionI, 0, aFirstPoint); + gp_Pnt aPoint = aFirstPoint; + aTmpPoints.push_back(aPoint); + for (int aPI = 1; aPI < aTmpPointCount; ++aPI) + { + gp_Pnt aPoint2; + CurveCreator_UtilsICurve::getPoint(theCurve, aSectionI, aPI, aPoint2); + if (!isEqualPoints(aPoint, aPoint2)) + { + aPoint = aPoint2; + aTmpPoints.push_back(aPoint); + } } - else if ( aNbPoints > 1 ) { - Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt(1, aNbPoints); - TColgp_Array1OfVec aTangents(1, aNbPoints); - Handle(TColStd_HArray1OfBoolean) aTangentFlags = new TColStd_HArray1OfBoolean(1, aNbPoints); - gp_Vec aNullVec(0, 0, 0); - - TopoDS_Edge aPointEdge; - TopoDS_Vertex aVertex; - - std::vector::const_iterator aPointIt = aPoints.begin(), aPointLast = aPoints.end(); - aPoint = *aPointIt; - - int aHIndex = 1; - aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex(); - aBuilder.Add( aComp, aVertex ); - if ( !isPolyline ) { - aHCurvePoints->SetValue( aHIndex, aPoint ); - aTangents.SetValue( aHIndex, aNullVec ); - aTangentFlags->SetValue( aHIndex, Standard_False ); - aHIndex++; + const bool isClosed = theCurve->isClosed(aSectionI); + int aPointCount = aTmpPoints.size(); + if (isClosed) + { + while (aPointCount > 1 && + isEqualPoints(aFirstPoint, aTmpPoints[aPointCount - 1])) + { + --aPointCount; } + } - aPrevPoint = aPoint; - aPointIt++; - for( ; aPointIt != aPointLast; aPointIt++ ) { - aPoint = *aPointIt; - aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex(); - aBuilder.Add( aComp, aVertex ); - if ( isPolyline ) { - TopoDS_Edge aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge(); - aBuilder.Add( aComp, aPointEdge ); - } - else { - aHCurvePoints->SetValue( aHIndex, aPoint ); - aTangents.SetValue( aHIndex, aNullVec ); - aTangentFlags->SetValue( aHIndex, Standard_False ); - aHIndex++; - } - aPrevPoint = aPoint; - } - if( aSectIsClosed && ( aNbPoints > 2 ) ) { - aPoint = aPoints.front(); - aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex(); - aBuilder.Add( aComp, aVertex ); - if ( isPolyline ) { - aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge(); - aBuilder.Add( aComp, aPointEdge ); - } - } - if( !isPolyline ) { - // compute BSpline - Handle(Geom_BSplineCurve) aBSplineCurve; - GeomAPI_Interpolate aGBC(aHCurvePoints, aSectIsClosed, gp::Resolution()); - // correct the spline degree to be as 3 for non-periodic spline if number of points - // less than 3. It is need to have a knot in each spline point. This knots are used - // to found a neighbour points when a new point is inserted between two existing. - if (!aSectIsClosed ) { - if (aHCurvePoints->Length() == 3) - aGBC.Load(aTangents, aTangentFlags); - } + // Add the vertices to the shape. + Handle(TColgp_HArray1OfPnt) aPoints = + new TColgp_HArray1OfPnt(1, aPointCount); + for (Standard_Integer aPI = 0; aPI < aPointCount; ++aPI) + { + aPoints->SetValue(aPI + 1, aTmpPoints[aPI]); + aBuilder.Add(aShape, BRepBuilderAPI_MakeVertex(aTmpPoints[aPI])); + } + if (aPointCount == 1) + { + continue; + } - aGBC.Perform(); - if ( aGBC.IsDone() ) - aBSplineCurve = aGBC.Curve(); - TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSplineCurve ).Edge(); - TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire(); - aBuilder.Add( aComp, aWire ); + // Add the edges to the shape. + const bool isPolyline = + (theCurve->getSectionType(aSectionI) == CurveCreator::Polyline); + if (isPolyline) + { + for (Standard_Integer aPN = 1; aPN < aPointCount; ++aPN) + { + aBuilder.Add(aShape, BRepBuilderAPI_MakeEdge( + BRepBuilderAPI_MakeVertex(aPoints->Value(aPN)), + BRepBuilderAPI_MakeVertex(aPoints->Value(aPN + 1)))); + } + if (isClosed) + { + aBuilder.Add(aShape, BRepBuilderAPI_MakeEdge( + BRepBuilderAPI_MakeVertex(aPoints->Value(aPointCount)), + BRepBuilderAPI_MakeVertex(aPoints->Value(1)))); + } + } + else + { + Handle(Geom_BSplineCurve) aBSpline; + if (constructBSpline(aPoints, isClosed, aBSpline)) + { + aBuilder.Add(aShape, + BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(aBSpline))); } } } - theShape = aComp; + theShape = aShape; } /** diff --git a/src/SKETCHER/Sketcher_Utils.cxx b/src/SKETCHER/Sketcher_Utils.cxx index d707546fa..aeb4d9f1e 100644 --- a/src/SKETCHER/Sketcher_Utils.cxx +++ b/src/SKETCHER/Sketcher_Utils.cxx @@ -32,7 +32,9 @@ #include #include #include +#include #include +#include #include const double POINT_CONFUSION_TOLERANCE = 0.0001; @@ -97,58 +99,135 @@ TopoDS_Shape Sketcher_Utils::MakePolyline return aResult; } +//======================================================================= +// function : constructBSpline +// purpose : See function 'constructBSpline' in file 'CurveCreator_Utils.cxx'. +//======================================================================= +static bool constructBSpline( + const Handle(TColgp_HArray1OfPnt)& thePoints, + const Standard_Boolean theIsClosed, + Handle(Geom_BSplineCurve)& theBSpline) +{ + const int aPointCount = thePoints->Length(); + if (aPointCount <= 1) + { + return false; + } + + // Calculate the tangents. + TColgp_Array1OfVec aTangents(1, aPointCount); + Handle(TColStd_HArray1OfBoolean) aTangentFlags = + new TColStd_HArray1OfBoolean(1, aPointCount); + GeomAPI_Interpolate aInterpolator(thePoints, theIsClosed, 0); + if (aPointCount == 2) + { + aTangentFlags->SetValue(1, Standard_False); + aTangentFlags->SetValue(2, Standard_False); + } + else + { + for (Standard_Integer aPN = 1; aPN <= aPointCount; ++aPN) + { + gp_Vec aTangent; + if (aPN != 1 || theIsClosed) + { + const Standard_Integer aPN1 = (aPN != 1) ? (aPN - 1) : aPointCount; + aTangent = gp_Vec(thePoints->Value(aPN1), + thePoints->Value(aPN)).Normalized(); + } + if (aPN < aPointCount || theIsClosed) + { + const Standard_Integer aPN2 = (aPN != aPointCount) ? (aPN + 1) : 1; + const gp_Vec aTangent2 = aTangent + + gp_Vec(thePoints->Value(aPN), thePoints->Value(aPN2)).Normalized(); + if (aTangent2.SquareMagnitude() >= Precision::SquareConfusion()) + { + aTangent = aTangent2.Normalized(); + } + else + { + aTangent = -aTangent; + } + } + aTangents.SetValue(aPN, aTangent); + aTangentFlags->SetValue(aPN, Standard_True); + } + } + + // Interpolate. + aInterpolator.Load(aTangents, aTangentFlags, Standard_False); + aInterpolator.Perform(); + const bool aResult = (aInterpolator.IsDone() == Standard_True); + if (aResult) + { + theBSpline = aInterpolator.Curve(); + } + return aResult; +} + //======================================================================= // function : MakeInterpolation // purpose : //======================================================================= -TopoDS_Shape Sketcher_Utils::MakeInterpolation - (const std::list &theCoords2D, - const Standard_Boolean IsClosed, - const gp_Ax3 &thePlane) +TopoDS_Shape Sketcher_Utils::MakeInterpolation( + const std::list& theCoords2D, + const Standard_Boolean theIsClosed, + const gp_Ax3& thePlane) { - std::list aPoints; - TopoDS_Shape aResult; + if (theCoords2D.size() == 0) + { + return TopoDS_Shape(); + } - To3D(theCoords2D, thePlane, aPoints); - - Standard_Integer aNbPnts = aPoints.size(); - - if (aNbPnts > 1) { - if (IsClosed && - aPoints.front().IsEqual(aPoints.back(), POINT_CONFUSION_TOLERANCE)) { - // The polyline should be closed, first and last points are confused. - // Remove the last point. - aPoints.pop_back(); - --aNbPnts; + // Get the different points. + std::list aTmpPoints; + To3D(theCoords2D, thePlane, aTmpPoints); + gp_Pnt aFirstPoint = aTmpPoints.front(); + gp_Pnt aPoint = aFirstPoint; + std::list::iterator aPIt = aTmpPoints.begin(); + for (++aPIt; aPIt != aTmpPoints.cend();) + { + const gp_Pnt aPoint2 = *aPIt; + if (!aPoint.IsEqual(aPoint2, POINT_CONFUSION_TOLERANCE)) + { + aPoint = aPoint2; + ++aPIt; + } + else + { + aTmpPoints.erase(aPIt); + } + } + if (theIsClosed) + { + while (--aPIt != aTmpPoints.cbegin() && + aFirstPoint.IsEqual(*aPIt, POINT_CONFUSION_TOLERANCE)) + { + aTmpPoints.erase(aPIt); } } - if (aNbPnts == 1) { - // The result is vertex. - aResult = BRepBuilderAPI_MakeVertex(aPoints.front()).Vertex(); - } else if (aNbPnts > 1) { - std::list ::const_iterator anIter = aPoints.begin(); - Handle(TColgp_HArray1OfPnt) aHCurvePoints = - new TColgp_HArray1OfPnt(1, aNbPnts); - Standard_Integer i; - - for (i = 1; anIter != aPoints.end(); ++anIter, ++i) { - aHCurvePoints->SetValue(i, *anIter); - } - - // Compute BSpline - Standard_Real aTol = Precision::Confusion(); - GeomAPI_Interpolate aGBC(aHCurvePoints, IsClosed, aTol); - - aGBC.Perform(); - - if (aGBC.IsDone()) { - TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(aGBC.Curve()).Edge(); - aResult = BRepBuilderAPI_MakeWire(anEdge).Wire(); - } + // Process the single point case. + const int aPointCount = aTmpPoints.size(); + if (aPointCount == 1) + { + return BRepBuilderAPI_MakeVertex(aTmpPoints.front()); } - return aResult; + // Process the other cases. + Handle(TColgp_HArray1OfPnt) aPoints = + new TColgp_HArray1OfPnt(1, aPointCount); + aPIt = aTmpPoints.begin(); + for (Standard_Integer aPN = 1; aPIt != aTmpPoints.cend(); ++aPIt, ++aPN) + { + aPoints->SetValue(aPN, *aPIt); + } + Handle(Geom_BSplineCurve) aBSpline; + if (constructBSpline(aPoints, theIsClosed, aBSpline)) + { + return BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(aBSpline)); + } + return TopoDS_Shape(); } //======================================================================= From 34c4dd8f29522c302d80dd3d35537eee9320e047 Mon Sep 17 00:00:00 2001 From: asl Date: Thu, 25 Jun 2015 09:20:44 +0300 Subject: [PATCH 03/11] refs #589: integration of new interpolation algo to HYDRO --- src/CurveCreator/CurveCreator_Utils.cxx | 2 +- src/CurveCreator/CurveCreator_Utils.hxx | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/CurveCreator/CurveCreator_Utils.cxx b/src/CurveCreator/CurveCreator_Utils.cxx index 52fab0c1c..4f8ca6fb8 100644 --- a/src/CurveCreator/CurveCreator_Utils.cxx +++ b/src/CurveCreator/CurveCreator_Utils.cxx @@ -195,7 +195,7 @@ gp_Pnt CurveCreator_Utils::ConvertClickToPoint( int x, int y, Handle(V3d_View) a // if point P is followed by a point B but is not preceded by any point then // the tangent vector is equal to B - P. //======================================================================= -static bool constructBSpline( +bool CurveCreator_Utils::constructBSpline( const Handle(TColgp_HArray1OfPnt)& thePoints, const Standard_Boolean theIsClosed, Handle(Geom_BSplineCurve)& theBSpline) diff --git a/src/CurveCreator/CurveCreator_Utils.hxx b/src/CurveCreator/CurveCreator_Utils.hxx index 78be98b00..0494fceef 100644 --- a/src/CurveCreator/CurveCreator_Utils.hxx +++ b/src/CurveCreator/CurveCreator_Utils.hxx @@ -30,6 +30,7 @@ #include #include #include +#include #include #include // TODO: remove @@ -132,6 +133,10 @@ public: gp_Pnt& thePoint, gp_Pnt& thePoint1, gp_Pnt& thePoint2 ); + CURVECREATOR_EXPORT static bool constructBSpline( const Handle(TColgp_HArray1OfPnt)& thePoints, + const Standard_Boolean theIsClosed, + Handle(Geom_BSplineCurve)& theBSpline ); + protected: /* * Returns whether the clicked point belong to the curve or has a very near projection From 3f406f6a6e1587156887937c626f774a59bc671f Mon Sep 17 00:00:00 2001 From: asl Date: Thu, 25 Jun 2015 09:26:30 +0300 Subject: [PATCH 04/11] patch for correct compilation on Linux --- src/SKETCHER/Sketcher_Utils.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SKETCHER/Sketcher_Utils.cxx b/src/SKETCHER/Sketcher_Utils.cxx index aeb4d9f1e..351de0b98 100644 --- a/src/SKETCHER/Sketcher_Utils.cxx +++ b/src/SKETCHER/Sketcher_Utils.cxx @@ -185,7 +185,7 @@ TopoDS_Shape Sketcher_Utils::MakeInterpolation( gp_Pnt aFirstPoint = aTmpPoints.front(); gp_Pnt aPoint = aFirstPoint; std::list::iterator aPIt = aTmpPoints.begin(); - for (++aPIt; aPIt != aTmpPoints.cend();) + for (++aPIt; aPIt != aTmpPoints.end();) { const gp_Pnt aPoint2 = *aPIt; if (!aPoint.IsEqual(aPoint2, POINT_CONFUSION_TOLERANCE)) @@ -200,7 +200,7 @@ TopoDS_Shape Sketcher_Utils::MakeInterpolation( } if (theIsClosed) { - while (--aPIt != aTmpPoints.cbegin() && + while (--aPIt != aTmpPoints.begin() && aFirstPoint.IsEqual(*aPIt, POINT_CONFUSION_TOLERANCE)) { aTmpPoints.erase(aPIt); @@ -218,7 +218,7 @@ TopoDS_Shape Sketcher_Utils::MakeInterpolation( Handle(TColgp_HArray1OfPnt) aPoints = new TColgp_HArray1OfPnt(1, aPointCount); aPIt = aTmpPoints.begin(); - for (Standard_Integer aPN = 1; aPIt != aTmpPoints.cend(); ++aPIt, ++aPN) + for (Standard_Integer aPN = 1; aPIt != aTmpPoints.end(); ++aPIt, ++aPN) { aPoints->SetValue(aPN, *aPIt); } From 44f924fa670420fc1bd7deefe2c6c3d595bc552c Mon Sep 17 00:00:00 2001 From: abk Date: Mon, 29 Jun 2015 15:21:11 +0300 Subject: [PATCH 05/11] Initial version of interface 'CurveCreator_ISection' was created for the curve sections. Type 'CurveCreator_Section' was inherited from the interface and extended to implement the interface. Method 'CurveCreator_Curve::getSection' was modified for the interface. Method 'CurveCreator_Utils::ConstructWire' was created to construct the wire corresponding to each polyline or spline section. --- src/CurveCreator/CMakeLists.txt | 1 + src/CurveCreator/CurveCreator_Curve.cxx | 51 ++++------ src/CurveCreator/CurveCreator_Curve.hxx | 21 ++-- src/CurveCreator/CurveCreator_ICurve.hxx | 24 +++++ src/CurveCreator/CurveCreator_Section.cxx | 70 +++++++++++++ src/CurveCreator/CurveCreator_Section.hxx | 6 +- src/CurveCreator/CurveCreator_Utils.cxx | 116 ++++++++++------------ src/CurveCreator/CurveCreator_Utils.hxx | 19 ++++ 8 files changed, 208 insertions(+), 100 deletions(-) create mode 100644 src/CurveCreator/CurveCreator_Section.cxx diff --git a/src/CurveCreator/CMakeLists.txt b/src/CurveCreator/CMakeLists.txt index e17655aa6..c085fc69f 100644 --- a/src/CurveCreator/CMakeLists.txt +++ b/src/CurveCreator/CMakeLists.txt @@ -94,6 +94,7 @@ SET(_other_SOURCES CurveCreator_Diff.cxx CurveCreator_Displayer.cxx CurveCreator_Operation.cxx + CurveCreator_Section.cxx CurveCreator_Utils.cxx CurveCreator_UtilsICurve.cxx ) diff --git a/src/CurveCreator/CurveCreator_Curve.cxx b/src/CurveCreator/CurveCreator_Curve.cxx index fb59efdd0..0185e6cf4 100644 --- a/src/CurveCreator/CurveCreator_Curve.cxx +++ b/src/CurveCreator/CurveCreator_Curve.cxx @@ -88,7 +88,7 @@ std::string CurveCreator_Curve::getUniqSectionName() const std::string aName(aBuffer); int j; for( j = 0 ; j < mySections.size() ; j++ ){ - aSection = getSection( j ); + aSection = (CurveCreator_Section*)getSection( j ); if ( aSection && aSection->myName == aName ) break; } @@ -263,7 +263,7 @@ bool CurveCreator_Curve::moveSectionInternal(const int theISection, int aMovedSectionId = theISection >= 0 ? theISection : mySections.size()-1; if (aMovedSectionId != theNewIndex) { - CurveCreator_Section* aSection = getSection( aMovedSectionId ); + CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( aMovedSectionId ); // Remove section CurveCreator::Sections::iterator anIter = mySections.begin() + aMovedSectionId; @@ -362,7 +362,7 @@ bool CurveCreator_Curve::clearInternal() CurveCreator_Section* aSection; for (; i < aNbSections; i++) { - aSection = getSection( i ); + aSection = (CurveCreator_Section*)getSection( i ); if ( aSection ) delete aSection; } @@ -397,7 +397,8 @@ bool CurveCreator_Curve::joinInternal( const std::list& theSections ) return res; int anISectionMain = theSections.front(); - CurveCreator_Section* aSectionMain = getSection( anISectionMain ); + CurveCreator_Section* aSectionMain = + (CurveCreator_Section*)getSection( anISectionMain ); std::list aSectionsToJoin = theSections; aSectionsToJoin.erase( aSectionsToJoin.begin() ); // skip the main section @@ -408,7 +409,7 @@ bool CurveCreator_Curve::joinInternal( const std::list& theSections ) std::list::const_iterator anIt = aSectionsToJoin.begin(), aLast = aSectionsToJoin.end(); CurveCreator_Section* aSection; for (; anIt != aLast; anIt++) { - aSection = getSection( *anIt ); + aSection = (CurveCreator_Section*)getSection( *anIt ); aSectionMain->myPoints.insert(aSectionMain->myPoints.end(), aSection->myPoints.begin(), aSection->myPoints.end()); res = removeSectionInternal(*anIt); @@ -552,12 +553,12 @@ int CurveCreator_Curve::getNbPoints( const int theISection ) const const int aNbSections = getNbSections(); for (; i < aNbSections; i++) { - aSection = getSection( i ); + aSection = (CurveCreator_Section*)getSection( i ); if ( aSection ) aNbCoords += aSection->myPoints.size(); } } else { - aSection = getSection( theISection ); + aSection = (CurveCreator_Section*)getSection( theISection ); if ( aSection ) aNbCoords = aSection->myPoints.size(); } @@ -592,7 +593,8 @@ void CurveCreator_Curve::saveCoordDiff( const SectionToPointCoordsList &theOldCo //! Get "closed" flag of the specified section bool CurveCreator_Curve::isClosed( const int theISection ) const { - CurveCreator_Section* aSection = getSection( theISection ); + const CurveCreator_Section* aSection = + (CurveCreator_Section*)getSection( theISection ); return aSection ? aSection->myIsClosed : false; } @@ -606,14 +608,14 @@ bool CurveCreator_Curve::setClosedInternal( const int theISection, int i; for (i = 0; i < aSize; i++) { - aSection = getSection( i ); + aSection = (CurveCreator_Section*)getSection( i ); if( aSection ) { aSection->myIsClosed = theIsClosed; redisplayCurve(); } } } else { - aSection = getSection( theISection ); + aSection = (CurveCreator_Section*)getSection( theISection ); if ( aSection ) { aSection->myIsClosed = theIsClosed; redisplayCurve(); @@ -644,7 +646,7 @@ bool CurveCreator_Curve::setClosed( const int theISection, //! Returns specified section name std::string CurveCreator_Curve::getSectionName( const int theISection ) const { - CurveCreator_Section* aSection = getSection( theISection ); + CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection ); return aSection ? aSection->myName : ""; } @@ -653,7 +655,7 @@ bool CurveCreator_Curve::setSectionNameInternal( const int theISection, const std::string& theName ) { bool res = false; - CurveCreator_Section* aSection = getSection( theISection ); + CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection ); if( aSection ) { aSection->myName = theName; res = true; @@ -681,7 +683,7 @@ bool CurveCreator_Curve::setSectionName( const int theISection, CurveCreator::SectionType CurveCreator_Curve::getSectionType ( const int theISection ) const { - CurveCreator_Section* aSection = getSection( theISection ); + CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection ); return aSection ? aSection->myType : CurveCreator::Polyline; } @@ -695,13 +697,13 @@ bool CurveCreator_Curve::setSectionTypeInternal( const int theISection, const int aNbSections = getNbSections(); for (; i < aNbSections; i++) { - aSection = getSection( i ); + aSection = (CurveCreator_Section*)getSection( i ); if ( aSection ) aSection->myType = theType; } redisplayCurve(); } else { - aSection = getSection( theISection ); + aSection = (CurveCreator_Section*)getSection( theISection ); if ( aSection && aSection->myType != theType ){ aSection->myType = theType; redisplayCurve(); @@ -744,7 +746,7 @@ bool CurveCreator_Curve::addPointsInternal( const CurveCreator::SectionsMap &the CurveCreator_Section *aSection = 0; for ( ; anIt != theSectionsMap.end(); anIt++ ) { int anISection = anIt->first; - aSection = getSection( anISection ); + aSection = (CurveCreator_Section*)getSection( anISection ); if( aSection ) { CurveCreator::PosPointsList aSectionPoints = anIt->second; CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin(); @@ -808,7 +810,7 @@ bool CurveCreator_Curve::setPointInternal( const CurveCreator::SectionsMap &theS CurveCreator_Section *aSection = 0; for ( ; anIt != theSectionsMap.end(); anIt++ ) { int anISection = anIt->first; - aSection = getSection( anISection ); + aSection = (CurveCreator_Section*)getSection( anISection ); if( aSection ) { CurveCreator::PosPointsList aSectionPoints = anIt->second; CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin(); @@ -948,7 +950,7 @@ bool CurveCreator_Curve::removeSeveralPoints( const SectionToPointList &theSecti CurveCreator::Coordinates CurveCreator_Curve::getPoint( const int theISection, const int theIPnt) const { - CurveCreator_Section* aSection = getSection( theISection ); + CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection ); CurveCreator::Coordinates::const_iterator anIter = aSection->myPoints.begin() + toICoord(theIPnt); CurveCreator::Coordinates aResult(anIter, anIter + myDimension); @@ -962,7 +964,7 @@ CurveCreator::Coordinates CurveCreator_Curve::getPoint( const int theISection, //======================================================================= CurveCreator::Coordinates CurveCreator_Curve::getPoints( const int theISection ) const { - CurveCreator_Section* aSection = getSection( theISection ); + CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection ); return aSection ? aSection->myPoints : CurveCreator::Coordinates(); } @@ -974,15 +976,6 @@ void CurveCreator_Curve::constructAISObject() myAISShape = new AIS_Shape( aShape ); } -CurveCreator_Section* CurveCreator_Curve::getSection( const int theSectionId ) const -{ - CurveCreator_Section *aSection = 0; - if ( theSectionId >= 0 && theSectionId < mySections.size() ) - aSection = mySections.at( theSectionId ); - - return aSection; -} - Handle(AIS_InteractiveObject) CurveCreator_Curve::getAISObject( const bool theNeedToBuild ) const { if ( !myAISShape && theNeedToBuild ) { @@ -997,7 +990,7 @@ bool CurveCreator_Curve::removeSectionPoints( const int theSectionId, { bool aRes = false; - CurveCreator_Section* aSection = getSection( theSectionId ); + CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theSectionId ); if ( !aSection ) return aRes; diff --git a/src/CurveCreator/CurveCreator_Curve.hxx b/src/CurveCreator/CurveCreator_Curve.hxx index 0c9cd27e9..2443eb87e 100644 --- a/src/CurveCreator/CurveCreator_Curve.hxx +++ b/src/CurveCreator/CurveCreator_Curve.hxx @@ -205,6 +205,21 @@ public: virtual bool setSectionType( const int theISection, const CurveCreator::SectionType theType ); + //! A virtual method. + const CurveCreator_ISection* getSection(const int theSectionIndex) const + { + if (theSectionIndex >= 0 && theSectionIndex < mySections.size()) + { + return (CurveCreator_ISection*)mySections[theSectionIndex]; + } + return NULL; + } + + //! A virtual method. + CurveCreator_ISection* getSection(const int theSectionIndex) + { + return (CurveCreator_ISection*)mySections[theSectionIndex]; + } /***********************************************/ /*** Point methods ***/ @@ -298,12 +313,6 @@ protected: protected: virtual void constructAISObject(); - /** - * Returns the section by the section index or NULL if the index is out of the section - * list range - * \param theSectionId the section index - */ - CurveCreator_Section* getSection( const int theSectionId ) const; protected: bool mySkipSorting; diff --git a/src/CurveCreator/CurveCreator_ICurve.hxx b/src/CurveCreator/CurveCreator_ICurve.hxx index b6429cb97..5b5d5eae3 100644 --- a/src/CurveCreator/CurveCreator_ICurve.hxx +++ b/src/CurveCreator/CurveCreator_ICurve.hxx @@ -24,6 +24,9 @@ #define _CurveCreator_ICurve_HeaderFile #include "CurveCreator_Macro.hxx" + +#include + #include #include #include @@ -49,6 +52,17 @@ namespace CurveCreator }; +//! The type represents the interface to the curve section. +struct CURVECREATOR_EXPORT CurveCreator_ISection +{ + //! The destructor. + virtual ~CurveCreator_ISection() {} + + //! Calculates the different points of the section. + virtual void GetDifferentPoints( + const int theDimension, Handle(TColgp_HArray1OfPnt)& thePoints) const = 0; +}; + /** * The CurveCreator_ICurve object is represented as one or more sets of * connected points; thus CurveCreator_ICurve object can contain several @@ -69,6 +83,9 @@ public: /*** Undo/Redo methods ***/ /***********************************************/ + //! The destructor. + virtual ~CurveCreator_ICurve() {} + //! Get number of available undo operations virtual int getNbUndo() const = 0; @@ -131,6 +148,13 @@ public: virtual bool setSectionType( const int theISection, const CurveCreator::SectionType theType ) = 0; + //! Returns the curve section with the index. + virtual const CurveCreator_ISection* getSection( + const int theSectionIndex) const = 0; + + //! Returns the curve section with the index. + virtual CurveCreator_ISection* getSection(const int theSectionIndex) = 0; + /***********************************************/ /*** Point methods ***/ diff --git a/src/CurveCreator/CurveCreator_Section.cxx b/src/CurveCreator/CurveCreator_Section.cxx new file mode 100644 index 000000000..c798950ac --- /dev/null +++ b/src/CurveCreator/CurveCreator_Section.cxx @@ -0,0 +1,70 @@ +// Copyright (C) 2013-2015 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: CurveCreator_Section.cxx +// Author: Aleksandr BOBKOV + +#include "CurveCreator_Section.hxx" + +#include + +const double POINT_CONFUSION = 1e-4; + +//======================================================================= +// function: GetDifferentPoints +// purpose: +//======================================================================= +void CurveCreator_Section::GetDifferentPoints( + const int theDimension, Handle(TColgp_HArray1OfPnt)& thePoints) const +{ + std::vector aTmpPoints; + CurveCreator::Coordinates::const_iterator aPIt = myPoints.begin(); + CurveCreator::Coordinates::const_iterator aPItLast = myPoints.end(); + const gp_Pnt aFirstPoint( + *aPIt, *(aPIt + 1), (theDimension == 2) ? 0 : *(aPIt + 2)); + gp_Pnt aPoint = aFirstPoint; + aTmpPoints.push_back(aPoint); + + for (; aPIt != aPItLast; aPIt += theDimension) + { + const gp_Pnt aPoint2( + *aPIt, *(aPIt + 1), (theDimension == 2) ? 0 : *(aPIt + 2)); + if (!aPoint.IsEqual(aPoint2, POINT_CONFUSION)) + { + aPoint = aPoint2; + aTmpPoints.push_back(aPoint); + } + } + + int aPointCount = aTmpPoints.size(); + if (myIsClosed) + { + while (aPointCount > 1 && + aFirstPoint.IsEqual(aTmpPoints[aPointCount - 1], POINT_CONFUSION)) + { + --aPointCount; + } + } + + thePoints = new TColgp_HArray1OfPnt(1, aPointCount); + for (int aPI = 0; aPI < aPointCount; ++aPI) + { + thePoints->SetValue(aPI + 1, aTmpPoints[aPI]); + } +} diff --git a/src/CurveCreator/CurveCreator_Section.hxx b/src/CurveCreator/CurveCreator_Section.hxx index 241615c26..076dc7809 100644 --- a/src/CurveCreator/CurveCreator_Section.hxx +++ b/src/CurveCreator/CurveCreator_Section.hxx @@ -24,11 +24,13 @@ #define _CurveCreator_Section_HeaderFile #include "CurveCreator.hxx" +#include "CurveCreator_ICurve.hxx" #include //! Structure to store sections representing the CurveCreator_Curve object -struct CurveCreator_Section +struct CURVECREATOR_EXPORT CurveCreator_Section : + public CurveCreator_ISection { //! Constructor. Initializes object with default values. CurveCreator_Section() : myName("Section"),myType(CurveCreator::Polyline), myIsClosed(false) @@ -39,6 +41,8 @@ struct CurveCreator_Section CurveCreator::SectionType myType; //!< type of the section bool myIsClosed; //!< closed or not + //! A virtual method. + void GetDifferentPoints(const int theDimension, Handle(TColgp_HArray1OfPnt)& thePoints) const; }; #endif diff --git a/src/CurveCreator/CurveCreator_Utils.cxx b/src/CurveCreator/CurveCreator_Utils.cxx index 4f8ca6fb8..52ed6f0e2 100644 --- a/src/CurveCreator/CurveCreator_Utils.cxx +++ b/src/CurveCreator/CurveCreator_Utils.cxx @@ -20,6 +20,7 @@ #include "CurveCreator_Utils.hxx" #include "CurveCreator.hxx" #include "CurveCreator_Curve.hxx" +#include "CurveCreator_Section.hxx" #include "CurveCreator_UtilsICurve.hxx" #include @@ -186,14 +187,6 @@ gp_Pnt CurveCreator_Utils::ConvertClickToPoint( int x, int y, Handle(V3d_View) a //======================================================================= // function : constructBSpline // purpose : -// The algorithm builds the cubic B-spline passing through the points that the -// tangent vector in each given point P is calculated by the following way: -// if point P is preceded by a point A and is followed by a point B then -// the tangent vector is equal to (P - A) / |P - A| + (B - P) / |B - P|; -// if point P is preceded by a point A but is not followed by any point then -// the tangent vector is equal to P - A; -// if point P is followed by a point B but is not preceded by any point then -// the tangent vector is equal to B - P. //======================================================================= bool CurveCreator_Utils::constructBSpline( const Handle(TColgp_HArray1OfPnt)& thePoints, @@ -257,6 +250,47 @@ bool CurveCreator_Utils::constructBSpline( return aResult; } +//======================================================================= +// function : constructWire +// purpose : +//======================================================================= +TopoDS_Wire CurveCreator_Utils::ConstructWire( + Handle(TColgp_HArray1OfPnt) thePoints, + const bool theIsPolyline, + const bool theIsClosed) +{ + TopoDS_Wire aWire; + BRep_Builder aBuilder; + aBuilder.MakeWire(aWire); + const int aPointCount = thePoints->Length(); + if (theIsPolyline) + { + const TopoDS_Vertex aFirstVertex = + BRepBuilderAPI_MakeVertex(thePoints->Value(1)); + TopoDS_Vertex aVertex = aFirstVertex; + for (Standard_Integer aPN = 1; aPN < aPointCount; ++aPN) + { + const TopoDS_Vertex aVertex2 = + BRepBuilderAPI_MakeVertex(thePoints->Value(aPN + 1)); + aBuilder.Add(aWire, BRepBuilderAPI_MakeEdge(aVertex, aVertex2)); + aVertex = aVertex2; + } + if (theIsClosed && aPointCount > 1) + { + aBuilder.Add(aWire, BRepBuilderAPI_MakeEdge(aVertex, aFirstVertex)); + } + } + else + { + Handle(Geom_BSplineCurve) aBSpline; + if (constructBSpline(thePoints, theIsClosed, aBSpline)) + { + aBuilder.Add(aWire, BRepBuilderAPI_MakeEdge(aBSpline)); + } + } + return aWire; +} + //======================================================================= // function : constructShape // purpose : @@ -277,71 +311,25 @@ void CurveCreator_Utils::constructShape( } // Get the different points. - std::vector aTmpPoints; - gp_Pnt aFirstPoint; - CurveCreator_UtilsICurve::getPoint(theCurve, aSectionI, 0, aFirstPoint); - gp_Pnt aPoint = aFirstPoint; - aTmpPoints.push_back(aPoint); - for (int aPI = 1; aPI < aTmpPointCount; ++aPI) - { - gp_Pnt aPoint2; - CurveCreator_UtilsICurve::getPoint(theCurve, aSectionI, aPI, aPoint2); - if (!isEqualPoints(aPoint, aPoint2)) - { - aPoint = aPoint2; - aTmpPoints.push_back(aPoint); - } - } + const CurveCreator_ISection* aSection = theCurve->getSection(aSectionI); + Handle(TColgp_HArray1OfPnt) aPoints; + aSection->GetDifferentPoints(theCurve->getDimension(), aPoints); + const int aPointCount = aPoints->Length(); const bool isClosed = theCurve->isClosed(aSectionI); - int aPointCount = aTmpPoints.size(); - if (isClosed) - { - while (aPointCount > 1 && - isEqualPoints(aFirstPoint, aTmpPoints[aPointCount - 1])) - { - --aPointCount; - } - } // Add the vertices to the shape. - Handle(TColgp_HArray1OfPnt) aPoints = - new TColgp_HArray1OfPnt(1, aPointCount); - for (Standard_Integer aPI = 0; aPI < aPointCount; ++aPI) + for (Standard_Integer aPN = 1; aPN <= aPointCount; ++aPN) { - aPoints->SetValue(aPI + 1, aTmpPoints[aPI]); - aBuilder.Add(aShape, BRepBuilderAPI_MakeVertex(aTmpPoints[aPI])); - } - if (aPointCount == 1) - { - continue; + aBuilder.Add(aShape, BRepBuilderAPI_MakeVertex(aPoints->Value(aPN))); } - // Add the edges to the shape. + // Add the wire to the shape. const bool isPolyline = (theCurve->getSectionType(aSectionI) == CurveCreator::Polyline); - if (isPolyline) + const TopoDS_Wire aWire = ConstructWire(aPoints, isPolyline, isClosed); + if (!aWire.IsNull()) { - for (Standard_Integer aPN = 1; aPN < aPointCount; ++aPN) - { - aBuilder.Add(aShape, BRepBuilderAPI_MakeEdge( - BRepBuilderAPI_MakeVertex(aPoints->Value(aPN)), - BRepBuilderAPI_MakeVertex(aPoints->Value(aPN + 1)))); - } - if (isClosed) - { - aBuilder.Add(aShape, BRepBuilderAPI_MakeEdge( - BRepBuilderAPI_MakeVertex(aPoints->Value(aPointCount)), - BRepBuilderAPI_MakeVertex(aPoints->Value(1)))); - } - } - else - { - Handle(Geom_BSplineCurve) aBSpline; - if (constructBSpline(aPoints, isClosed, aBSpline)) - { - aBuilder.Add(aShape, - BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(aBSpline))); - } + aBuilder.Add(aShape, aWire); } } theShape = aShape; diff --git a/src/CurveCreator/CurveCreator_Utils.hxx b/src/CurveCreator/CurveCreator_Utils.hxx index 0494fceef..29393fa3f 100644 --- a/src/CurveCreator/CurveCreator_Utils.hxx +++ b/src/CurveCreator/CurveCreator_Utils.hxx @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -133,10 +134,28 @@ public: gp_Pnt& thePoint, gp_Pnt& thePoint1, gp_Pnt& thePoint2 ); + /** + * The algorithm builds the cubic B-spline passing through the points that the + * tangent vector in each given point P is calculated by the following way: + * if point P is preceded by a point A and is followed by a point B then + * the tangent vector is equal to (P - A) / |P - A| + (B - P) / |B - P|; + * if point P is preceded by a point A but is not followed by any point then + * the tangent vector is equal to P - A; + * if point P is followed by a point B but is not preceded by any point then + * the tangent vector is equal to B - P. + */ CURVECREATOR_EXPORT static bool constructBSpline( const Handle(TColgp_HArray1OfPnt)& thePoints, const Standard_Boolean theIsClosed, Handle(Geom_BSplineCurve)& theBSpline ); + /** + * Constructs the wire corresponding to the section. + */ + CURVECREATOR_EXPORT static TopoDS_Wire ConstructWire( + Handle(TColgp_HArray1OfPnt) thePoints, + const bool theIsPolyline, + const bool theIsClosed); + protected: /* * Returns whether the clicked point belong to the curve or has a very near projection From 21a4549eddab46fed5cceff05426fc6df373246a Mon Sep 17 00:00:00 2001 From: asl Date: Thu, 8 Oct 2015 10:53:32 +0300 Subject: [PATCH 06/11] refs #587: sorting the point table by click on header --- src/CurveCreator/CurveCreator_TableView.cxx | 10 +++++++++- src/CurveCreator/CurveCreator_TableView.h | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/CurveCreator/CurveCreator_TableView.cxx b/src/CurveCreator/CurveCreator_TableView.cxx index b8fd0bf6e..fe4c2dd69 100644 --- a/src/CurveCreator/CurveCreator_TableView.cxx +++ b/src/CurveCreator/CurveCreator_TableView.cxx @@ -24,6 +24,7 @@ #include #include +#include #include @@ -109,6 +110,8 @@ CurveCreator_TableView::CurveCreator_TableView( CurveCreator_ICurve* theCurve, //aLabels << tr( "SECTION_LABEL" ) << tr( "IDENTIFIER_LABEL" ) << aCoord1 << aCoord2; aLabels << tr( "TABLE_SECTION" ) << tr("TABLE_INDEX") << aCoord1 << aCoord2; setHorizontalHeaderLabels( aLabels ); + + connect( horizontalHeader(), SIGNAL( sectionClicked( int ) ), this, SLOT( OnHeaderClick( int ) ) ); } void CurveCreator_TableView::setCurve( CurveCreator_ICurve* theCurve ) @@ -131,7 +134,7 @@ void CurveCreator_TableView::setLocalPointsToTable( QTableWidgetItem* anItem; anItem = new QTableWidgetItem( myCurve->getSectionName( anISection ).c_str() ); - anItem->setFlags( anItem->flags() & ~Qt::ItemIsEnabled ); + anItem->setFlags( anItem->flags() & ~Qt::ItemIsEditable ); anItem->setData( Qt::UserRole, anISection ); setItem( aRowId, 0, anItem ); @@ -176,3 +179,8 @@ int CurveCreator_TableView::getPointId( const int theRowId ) const { return item( theRowId, 1 )->data( Qt::UserRole ).toInt(); } + +void CurveCreator_TableView::OnHeaderClick( int theLogicalId ) +{ + sortByColumn( theLogicalId, Qt::AscendingOrder ); +} diff --git a/src/CurveCreator/CurveCreator_TableView.h b/src/CurveCreator/CurveCreator_TableView.h index e6e8d1cd6..6028e04dd 100644 --- a/src/CurveCreator/CurveCreator_TableView.h +++ b/src/CurveCreator/CurveCreator_TableView.h @@ -63,6 +63,9 @@ public: */ int getPointId( const int theRowId ) const; +private slots: + void OnHeaderClick( int ); + private: CurveCreator_ICurve* myCurve; From bf8682daf1506c4d974f3b68c41678b60bdbf3b2 Mon Sep 17 00:00:00 2001 From: asl Date: Mon, 12 Oct 2015 11:41:03 +0300 Subject: [PATCH 07/11] refs #527, #577: using double for coordinates --- src/CurveCreator/CurveCreator.hxx | 2 +- src/CurveCreator/CurveCreator_ICurve.hxx | 11 ++++++----- src/CurveCreator/CurveCreator_Widget.cxx | 8 ++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/CurveCreator/CurveCreator.hxx b/src/CurveCreator/CurveCreator.hxx index f7e8d33ee..e95749664 100644 --- a/src/CurveCreator/CurveCreator.hxx +++ b/src/CurveCreator/CurveCreator.hxx @@ -33,7 +33,7 @@ struct CurveCreator_PosPoint; namespace CurveCreator { //! Points coordinates - typedef float TypeCoord; + typedef double TypeCoord; /** List of coordinates in format depends on section dimension: * 2D: [x1, y1, x2, y2, x3, y3, ..] diff --git a/src/CurveCreator/CurveCreator_ICurve.hxx b/src/CurveCreator/CurveCreator_ICurve.hxx index 5b5d5eae3..20f8508e8 100644 --- a/src/CurveCreator/CurveCreator_ICurve.hxx +++ b/src/CurveCreator/CurveCreator_ICurve.hxx @@ -23,6 +23,7 @@ #ifndef _CurveCreator_ICurve_HeaderFile #define _CurveCreator_ICurve_HeaderFile +#include "CurveCreator.hxx" #include "CurveCreator_Macro.hxx" #include @@ -76,7 +77,7 @@ public: typedef std::pair SectionToPoint; typedef std::deque SectionToPointList; - typedef std::deque< std::pair< SectionToPoint,std::deque< float > > > SectionToPointCoordsList; + typedef std::deque< std::pair< SectionToPoint, CurveCreator::Coordinates > > SectionToPointCoordsList; public: /***********************************************/ @@ -167,14 +168,14 @@ public: * Insert one or several points to the specified section starting from the given theIPnt index * (or add these at the end of section points if \a theIPnt is -1). */ - virtual bool addPoints( const std::deque& theCoords, + virtual bool addPoints( const CurveCreator::Coordinates& theCoords, const int theISection, const int theIPnt = -1 ) = 0; //! Set coordinates of specified point virtual bool setPoint( const int theISection, const int theIPnt, - const std::deque& theNewCoords ) = 0; + const CurveCreator::Coordinates& theNewCoords ) = 0; //! Set coordinates of specified points from different sections virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords, @@ -186,13 +187,13 @@ public: virtual bool removeSeveralPoints( const SectionToPointList &theSectionToPntIDs) = 0; //! Get coordinates of specified point - virtual std::deque getPoint( const int theISection, + virtual CurveCreator::Coordinates getPoint( const int theISection, const int theIPnt ) const = 0; /** * Get points of a section (the total points in Curve if theISection is equal to -1).. */ - virtual std::deque getPoints( const int theISection = -1 ) const = 0; + virtual CurveCreator::Coordinates getPoints( const int theISection = -1 ) const = 0; /** * Get number of points in specified section or (the total number of points diff --git a/src/CurveCreator/CurveCreator_Widget.cxx b/src/CurveCreator/CurveCreator_Widget.cxx index 393fa49dc..df9c6b710 100644 --- a/src/CurveCreator/CurveCreator_Widget.cxx +++ b/src/CurveCreator/CurveCreator_Widget.cxx @@ -1059,7 +1059,7 @@ void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow* theWindow, QMouseEven if ( myDragStarted ) { bool isDragged = myDragged; CurveCreator_ICurve::SectionToPointList aDraggedPoints; - QMap > anInitialDragPointsCoords; + QMap anInitialDragPointsCoords; if ( myDragged ) { aDraggedPoints = myDragPoints; anInitialDragPointsCoords = myInitialDragPointsCoords; @@ -1105,7 +1105,7 @@ void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow* theWindow, QMouseEven for ( ; anIt != aLast; anIt++ ) { int aSectionId = anIt->first; int aPointId = anIt->second; - std::deque aPos = myCurve->getPoint( aSectionId, aPointId ); + CurveCreator::Coordinates aPos = myCurve->getPoint( aSectionId, aPointId ); aCoordList.push_back( std::make_pair( std::make_pair( aSectionId, aPointId ), aPos ) ); @@ -1195,7 +1195,7 @@ void CurveCreator_Widget::onCellChanged( int theRow, int theColumn ) double aX = myLocalPointView->item( theRow, 2 )->data( Qt::UserRole ).toDouble(); double anY = myLocalPointView->item( theRow, 3 )->data( Qt::UserRole ).toDouble(); - std::deque aChangedPos; + CurveCreator::Coordinates aChangedPos; aChangedPos.push_back( aX ); aChangedPos.push_back( anY ); myCurve->setPoint( aCurrSect, aPntIndex, aChangedPos ); @@ -1338,7 +1338,7 @@ void CurveCreator_Widget::moveSelectedPoints( const int theXPosition, double anYDelta = aStartPnt.Y() - anEndPnt.Y(); CurveCreator_ICurve::SectionToPointCoordsList aCoordList; - std::deque aChangedPos; + CurveCreator::Coordinates aChangedPos; CurveCreator_ICurve::SectionToPointList::const_iterator anIt = myDragPoints.begin(), aLast = myDragPoints.end(); for ( ; anIt != aLast; anIt++ ) { From 643db5d3ff7de94ac5f63883a7bd1bf80c7e161a Mon Sep 17 00:00:00 2001 From: asl Date: Thu, 29 Oct 2015 08:57:58 +0300 Subject: [PATCH 08/11] refs #674: correct using of doubles coordinates --- src/CurveCreator/CurveCreator_Utils.cxx | 2 +- src/CurveCreator/CurveCreator_UtilsICurve.cxx | 2 +- src/CurveCreator/CurveCreator_UtilsICurve.hxx | 2 +- src/CurveCreator/CurveCreator_Widget.cxx | 2 +- src/CurveCreator/CurveCreator_Widget.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/CurveCreator/CurveCreator_Utils.cxx b/src/CurveCreator/CurveCreator_Utils.cxx index 52ed6f0e2..863432b4c 100644 --- a/src/CurveCreator/CurveCreator_Utils.cxx +++ b/src/CurveCreator/CurveCreator_Utils.cxx @@ -556,7 +556,7 @@ void CurveCreator_Utils::getSelectedPoints( Handle(AIS_InteractiveContext) theCo { thePoints.clear(); - std::list aSelectedPoints; + std::list aSelectedPoints; gp_Pnt aPnt; std::map aPointsMap; diff --git a/src/CurveCreator/CurveCreator_UtilsICurve.cxx b/src/CurveCreator/CurveCreator_UtilsICurve.cxx index a0bd400a9..cf6dc203d 100644 --- a/src/CurveCreator/CurveCreator_UtilsICurve.cxx +++ b/src/CurveCreator/CurveCreator_UtilsICurve.cxx @@ -25,7 +25,7 @@ const double LOCAL_SELECTION_TOLERANCE = 0.0001; int CurveCreator_UtilsICurve::findLocalPointIndex( const CurveCreator_ICurve* theCurve, - int theSectionId, float theX, float theY ) + int theSectionId, double theX, double theY ) { int aPntIndex = -1; if ( !theCurve ) diff --git a/src/CurveCreator/CurveCreator_UtilsICurve.hxx b/src/CurveCreator/CurveCreator_UtilsICurve.hxx index 89ff253f5..39c73b537 100644 --- a/src/CurveCreator/CurveCreator_UtilsICurve.hxx +++ b/src/CurveCreator/CurveCreator_UtilsICurve.hxx @@ -39,7 +39,7 @@ public: * \param theY the Y coordinate of the point */ CURVECREATOR_EXPORT static int findLocalPointIndex( const CurveCreator_ICurve* theCurve, - int theSectionId, float theX, float theY ); + int theSectionId, double theX, double theY ); CURVECREATOR_EXPORT static void findSectionsToPoints( const CurveCreator_ICurve* theCurve, const double theX, const double theY, diff --git a/src/CurveCreator/CurveCreator_Widget.cxx b/src/CurveCreator/CurveCreator_Widget.cxx index df9c6b710..54cf166bb 100644 --- a/src/CurveCreator/CurveCreator_Widget.cxx +++ b/src/CurveCreator/CurveCreator_Widget.cxx @@ -1490,7 +1490,7 @@ void CurveCreator_Widget::finishCurveModification( * \param theX the X coordinate of the point * \param theY the Y coordinate of the point */ -int CurveCreator_Widget::findLocalPointIndex( int theSectionId, float theX, float theY ) +int CurveCreator_Widget::findLocalPointIndex( int theSectionId, double theX, double theY ) { return CurveCreator_UtilsICurve::findLocalPointIndex( myCurve, theSectionId, theX, theY ); } diff --git a/src/CurveCreator/CurveCreator_Widget.h b/src/CurveCreator/CurveCreator_Widget.h index 1fa317f56..87433c553 100644 --- a/src/CurveCreator/CurveCreator_Widget.h +++ b/src/CurveCreator/CurveCreator_Widget.h @@ -195,7 +195,7 @@ private: CurveCreator_ICurve::SectionToPointList() ); // curve algorithm - int findLocalPointIndex( int theSectionId, float theX, float theY ); + int findLocalPointIndex( int theSectionId, double theX, double theY ); void findSectionsToPoints( const double theX, const double theY, CurveCreator_ICurve::SectionToPointList& thePoints ); void convert( const CurveCreator_ICurve::SectionToPointList& thePoints, From 40d157643739ac8b0636516f1ec1ca848992d455 Mon Sep 17 00:00:00 2001 From: mkr Date: Tue, 24 Nov 2015 18:38:51 +0300 Subject: [PATCH 09/11] refs #739: correct sorting of numerical data for columns in the table of local points. --- src/CurveCreator/CurveCreator_TableView.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/CurveCreator/CurveCreator_TableView.cxx b/src/CurveCreator/CurveCreator_TableView.cxx index fe4c2dd69..31bbb5c4d 100644 --- a/src/CurveCreator/CurveCreator_TableView.cxx +++ b/src/CurveCreator/CurveCreator_TableView.cxx @@ -141,6 +141,7 @@ void CurveCreator_TableView::setLocalPointsToTable( anItem = new QTableWidgetItem( QString::number( anIPoint + 1 ) ); anItem->setFlags( anItem->flags() & ~Qt::ItemIsEnabled ); anItem->setData( Qt::UserRole, anIPoint ); + anItem->setData( Qt::DisplayRole, anIPoint ); setItem( aRowId, 1, anItem ); gp_Pnt aPoint; @@ -152,7 +153,7 @@ void CurveCreator_TableView::setLocalPointsToTable( setItem( aRowId, 2, anItem ); } anItem->setData( Qt::UserRole, aPoint.X() ); - anItem->setData( Qt::DisplayRole, QString::number( aPoint.X(), 'f', 2 ) ); + anItem->setData( Qt::DisplayRole, QString::number( aPoint.X(), 'f', 2 ).toDouble() ); anItem = item( aRowId, 3 ); if ( !anItem ) { @@ -160,7 +161,7 @@ void CurveCreator_TableView::setLocalPointsToTable( setItem( aRowId, 3, anItem ); } anItem->setData( Qt::UserRole, aPoint.Y() ); - anItem->setData( Qt::DisplayRole, QString::number( aPoint.Y(), 'f', 2 ) ); + anItem->setData( Qt::DisplayRole, QString::number( aPoint.Y(), 'f', 2 ).toDouble() ); aRowId++; } From 610bd3aff0e4c4838056a342f50f220bb62f8c61 Mon Sep 17 00:00:00 2001 From: mkr Date: Wed, 25 Nov 2015 15:02:52 +0300 Subject: [PATCH 10/11] refs #731: fix hanging of application after Undo operation during profile/polyline creation. --- src/CurveCreator/CurveCreator_Operation.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CurveCreator/CurveCreator_Operation.cxx b/src/CurveCreator/CurveCreator_Operation.cxx index 32d29697e..17c278a97 100644 --- a/src/CurveCreator/CurveCreator_Operation.cxx +++ b/src/CurveCreator/CurveCreator_Operation.cxx @@ -341,7 +341,7 @@ void CurveCreator_Operation::apply(CurveCreator_Curve *theCurve) int nbPoints = pInt[0]; int nbCoords = pInt[1]; - int nbParams = 3+nbCoords; + int nbParams = 3+nbCoords*sizeof(double)/sizeof(int); for (int i = 0; i < nbPoints*nbParams; i=i+nbParams) { aCoords.clear(); aPoints.clear(); From 5488595c4524089e729eabd422c65185b4b0ad14 Mon Sep 17 00:00:00 2001 From: mkr Date: Wed, 25 Nov 2015 18:43:47 +0300 Subject: [PATCH 11/11] refs #736: fix displaying of ghost of polyline section in addition mode. --- src/CurveCreator/CurveCreator_Widget.cxx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/CurveCreator/CurveCreator_Widget.cxx b/src/CurveCreator/CurveCreator_Widget.cxx index 54cf166bb..0bbccc6a1 100644 --- a/src/CurveCreator/CurveCreator_Widget.cxx +++ b/src/CurveCreator/CurveCreator_Widget.cxx @@ -1005,10 +1005,18 @@ void CurveCreator_Widget::onMousePress( SUIT_ViewWindow*, QMouseEvent* theEvent */ void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow* theWindow, QMouseEvent* theEvent ) { - if ( getActionMode() != ModificationMode ) + ActionMode aMode = getActionMode(); + if ( aMode != ModificationMode ) { // Emit selectionChanged() signal getOCCViewer()->performSelectionChanged(); + + if ( aMode == AdditionMode ) + { + Handle(AIS_InteractiveContext) aCtx = getAISContext(); + if ( !aCtx.IsNull() ) + aCtx->ClearSelected(); + } return; } if (theEvent->button() != Qt::LeftButton) return;