X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROCurveCreator%2FCurveCreator_Utils.cxx;h=f4e49253ac69e7ff38c073248b656cbf1622a1b5;hb=8edd427af3997521bda72ca3c416cc1d490565d5;hp=1fa61b3378265aaa96134014f620f2de147b8980;hpb=c3f79a88a881487ffae38af1a869ea7f91f08fa5;p=modules%2Fhydro.git diff --git a/src/HYDROCurveCreator/CurveCreator_Utils.cxx b/src/HYDROCurveCreator/CurveCreator_Utils.cxx index 1fa61b33..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,14 +84,191 @@ 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; + + gp_Pnt aPnt; + for ( theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected() ) { + TopoDS_Vertex aVertex; + TopoDS_Shape aShape = theContext->SelectedShape(); + if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) + aVertex = TopoDS::Vertex( theContext->SelectedShape() ); + else { + Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner(); + if ( !anOwner.IsNull() ) { + Handle(AIS_InteractiveObject) anAIS = Handle(AIS_InteractiveObject)::DownCast( anOwner->Selectable() ); + if ( !anAIS.IsNull() ) { + Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast( anAIS); + if ( !aPoint.IsNull() ) + aVertex = TopoDS::Vertex( aPoint->Vertex() ); + } + if ( aVertex.IsNull() ) { + // the following happens if there are no points in the current curve, there is only a shape + /*Handle(StdSelect_BRepOwner) aBrepOwner = Handle(StdSelect_BRepOwner)::DownCast(anOwner); + if ( aBrepOwner.IsNull() ) + continue; + if ( aBrepOwner->HasShape() ) { + const TopoDS_Shape& aShape = aBrepOwner->Shape(); + if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) + { + aVertex = TopoDS::Vertex( aShape ); + } + }*/ + } + } + } + if ( aVertex.IsNull() ) + continue; + aPnt = BRep_Tool::Pnt( aVertex ); + aSelectedPoints.push_back( aPnt.X() ); + aSelectedPoints.push_back( aPnt.Y() ); + aSelectedPoints.push_back( aPnt.Z() ); + } + + return aSelectedPoints; +} //======================================================================= // function : setLocalPointContext // purpose : Open/close the viewer local context //======================================================================= +//#define USE_GLOBAL_SELECTION void CurveCreator_Utils::setLocalPointContext( Handle(AIS_InteractiveContext) theContext, const bool theOpen ) { +#ifdef USE_GLOBAL_SELECTION + return; +#endif if ( !theContext ) return; @@ -102,8 +292,8 @@ void CurveCreator_Utils::setLocalPointContext( if ( anAIS->IsKind( STANDARD_TYPE( AIS_Shape ) ) ) { theContext->Load( anAIS, -1/*selection mode*/, true/*allow decomposition*/ ); - theContext->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)TopAbs_WIRE ) ); - //theContext->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)TopAbs_VERTEX ) ); + //theContext->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)TopAbs_WIRE ) ); + theContext->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)TopAbs_VERTEX ) ); } else if ( anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron) ) {