X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROCurveCreator%2FCurveCreator_Utils.cxx;h=f4e49253ac69e7ff38c073248b656cbf1622a1b5;hb=8edd427af3997521bda72ca3c416cc1d490565d5;hp=12d7ee7d84cf92d6a17a80aef4630e1eaf760122;hpb=1e9be94cc5ff4ad886099c507462d5b70f6d71f9;p=modules%2Fhydro.git diff --git a/src/HYDROCurveCreator/CurveCreator_Utils.cxx b/src/HYDROCurveCreator/CurveCreator_Utils.cxx index 12d7ee7d..f4e49253 100644 --- a/src/HYDROCurveCreator/CurveCreator_Utils.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Utils.cxx @@ -18,6 +18,8 @@ // #include "CurveCreator_Utils.h" +#include "CurveCreator.hxx" +#include "CurveCreator_UtilsICurve.hxx" #include @@ -27,6 +29,7 @@ #include #include #include +#include #include #include @@ -40,13 +43,23 @@ #include #include -#include #include #include +#include +#include +#include +#include +#include + +#include +#include + #include #include +#include "CurveCreator_ICurve.hxx" + const double LOCAL_SELECTION_TOLERANCE = 0.0001; const int SCENE_PIXEL_TOLERANCE = 10; @@ -71,6 +84,135 @@ gp_Pnt CurveCreator_Utils::ConvertClickToPoint( int x, int y, Handle(V3d_View) a return GEOMUtils::ConvertClickToPoint( x, y, aView ); } + +//#define USE_COMPOUND +#include "CurveCreator_Curve.hxx" // TODO - remove +void CurveCreator_Utils::constructShape( const CurveCreator_ICurve* theCurve, + const int theISection, TopoDS_Shape& theShape, + std::vector& aSectionRepresentation ) +{ + CurveCreator::SectionType aSectType = theCurve->getSectionType( theISection ); + + + int aPointSize = theCurve->getNbPoints( theISection ); + bool aSectIsClosed = theCurve->isClosed( theISection ); + if( aSectType == CurveCreator::Polyline ) + { +#ifdef USE_COMPOUND + BRep_Builder aBuilder; + TopoDS_Compound aComp; + aBuilder.MakeCompound(aComp); + + int iPoint = 0; + gp_Pnt aPrevPoint, aPoint; + if ( aPointSize == 1 ) { + CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPrevPoint ); + TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex( aPrevPoint ).Vertex(); + aBuilder.Add( aComp, aVertex ); + } + else if ( aPointSize > 1 ) { + TopoDS_Edge aPointEdge; + TopoDS_Vertex aVertex; + CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPrevPoint ); + aVertex = BRepBuilderAPI_MakeVertex( aPrevPoint ).Vertex(); + aBuilder.Add( aComp, aVertex ); + iPoint++; + for( ; iPoint < aPointSize; iPoint++ ) { + CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPoint ); + aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex(); + aBuilder.Add( aComp, aVertex ); + aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge(); + aBuilder.Add( aComp, aPointEdge ); + aPrevPoint = aPoint; + } + if( aSectIsClosed && ( aPointSize > 2 ) ) { + CurveCreator_UtilsICurve::getPoint( theCurve, theISection, 0, aPoint ); + aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex(); + aBuilder.Add( aComp, aVertex ); + aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge(); + aBuilder.Add( aComp, aPointEdge ); + } + theShape = aComp; + } +#endif + } + else if( aSectType == CurveCreator::Spline ) + { + std::vector aPoints; + for( int iPoint = 0; iPoint < aPointSize; iPoint++ ) + { + CurveCreator::Coordinates aCoords = theCurve->getPoint( theISection, iPoint ); + double aX = aCoords[0]; + double aY = aCoords[1]; + double aZ = aCoords[2]; + aPoints.push_back( aX ); + aPoints.push_back( aY ); + } + + if( aPointSize > 1 ) + { + Handle(Geom_BSplineCurve) aBSplineCurve; + // fill array for algorithm by the received coordinates + int aLen = aPoints.size() / 2; + Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt (1, aLen); + std::vector::const_iterator aListIter = aPoints.begin(); + for (int ind = 1; ind <= aLen; ind++) { + gp_Pnt aPnt(gp::Origin()); + aPnt.SetX(*aListIter); + aListIter++; + aPnt.SetY(*aListIter); + aListIter++; + aPnt.SetZ(0); + aHCurvePoints->SetValue(ind, aPnt); + } + // compute BSpline + GeomAPI_Interpolate aGBC(aHCurvePoints, aSectIsClosed, gp::Resolution()); + aGBC.Perform(); + if (aGBC.IsDone()) { + aBSplineCurve = aGBC.Curve(); + } + TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSplineCurve ).Edge(); + + TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire(); + theShape = aWire; + } + } + + const CurveCreator_Curve* aCurve = dynamic_cast( theCurve ); + if ( !aCurve ) + return; + + if( aSectType == CurveCreator::Polyline ) + { +#ifndef USE_COMPOUND + int iPoint = 0; + for( ; iPoint < ( aPointSize - 1 ) ; iPoint++ ){ + Handle_AIS_Point anAISPnt = aCurve->getAISPoint(theISection, iPoint); + aSectionRepresentation.push_back( anAISPnt ); + Handle_AIS_Line aLine = aCurve->getAISLine( theISection, iPoint, iPoint+1 ); + aSectionRepresentation.push_back( aLine ); + } + if( aPointSize != 0 ){ + Handle_AIS_Point anAISPnt = aCurve->getAISPoint(theISection, iPoint); + aSectionRepresentation.push_back( anAISPnt ); + if( aSectIsClosed && ( aPointSize > 1 ) ){ + Handle_AIS_Line aLine = aCurve->getAISLine( theISection, iPoint, 0 ); + aSectionRepresentation.push_back( aLine ); + } + } +#endif + } + else if( aSectType == CurveCreator::Spline ) + { + std::vector aPoints; + for( int iPoint = 0; iPoint < aPointSize; iPoint++ ) + { + Handle_AIS_Point anAISPnt = aCurve->getAISPoint( theISection, iPoint ); + aSectionRepresentation.push_back( anAISPnt ); + } + } +} + std::list CurveCreator_Utils::getSelectedPoints( Handle(AIS_InteractiveContext) theContext ) { std::list aSelectedPoints; @@ -119,12 +261,12 @@ std::list CurveCreator_Utils::getSelectedPoints( Handle(AIS_InteractiveCo // function : setLocalPointContext // purpose : Open/close the viewer local context //======================================================================= -//#define USE_COMPOUND +//#define USE_GLOBAL_SELECTION void CurveCreator_Utils::setLocalPointContext( Handle(AIS_InteractiveContext) theContext, const bool theOpen ) { -#ifdef USE_COMPOUND +#ifdef USE_GLOBAL_SELECTION return; #endif if ( !theContext )