X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_AISCurve.cxx;h=16364e6f8c2da028bc89eba840d4271d59555924;hb=5cae7e874afd2fc1b6f61023e8ebd33a933db3c7;hp=cfe51f303b27b7191845a55c92bdb48ec5dc152b;hpb=f96113cb7e3ebc96e9ce6230234c68afe9c7e34c;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_AISCurve.cxx b/src/HYDROGUI/HYDROGUI_AISCurve.cxx index cfe51f30..16364e6f 100755 --- a/src/HYDROGUI/HYDROGUI_AISCurve.cxx +++ b/src/HYDROGUI/HYDROGUI_AISCurve.cxx @@ -1,346 +1,225 @@ #include "HYDROGUI_AISCurve.h" -#include "CurveCreator_Curve.hxx" - +#include +#include #include - #include - +#include +#include +#include +#include #include - #include - -#include - - +#include +#include +#include HYDROGUI_AISCurveSection::HYDROGUI_AISCurveSection( Handle_AIS_InteractiveContext theContext, - CurveCreator_Curve* theCurve, int theSection) : - myCurve(theCurve), mySection(theSection), myContext(theContext), myIsHL(false) - { - buildSection(); - } - - HYDROGUI_AISCurveSection::~HYDROGUI_AISCurveSection() - { - Erase(); - for( int i = 0 ; i < myObjects.size() ; i++ ){ - myObjects[i].Nullify(); - } - myObjects.clear(); - } - - Quantity_Color HYDROGUI_AISCurveSection::getActiveColor() - { - if( myIsHL ){ - return Quantity_Color( 1., 0., 0., Quantity_TOC_RGB ); - } - return Quantity_Color( 0., 1., 0., Quantity_TOC_RGB ); - } - - void HYDROGUI_AISCurveSection::highlight( bool isHL ) - { - myIsHL = isHL; - Quantity_Color aColor = getActiveColor(); - for( int i = 0 ; i < myObjects.size() ; i++ ){ - myObjects[i]->SetColor(aColor); - - myContext->Display(myObjects[i]); - + myContext->Display(myObjects[i], Standard_False); } - + myContext->UpdateCurrentViewer(); } - - void HYDROGUI_AISCurveSection::Display() - { - for( int i = 0 ; i < myObjects.size() ; i++ ){ - - myContext->Display(myObjects[i]); - + myContext->Display(myObjects[i], Standard_False); } - + myContext->UpdateCurrentViewer(); } - - void HYDROGUI_AISCurveSection::Erase() - { - for( int i = 0 ; i < myObjects.size() ; i++ ){ - - myContext->Erase(myObjects[i]); - + myContext->Erase(myObjects[i], Standard_False); } - + myContext->UpdateCurrentViewer(); } - - void HYDROGUI_AISCurveSection::buildSection() - { - + CurveCreator::Type aSectType = myCurve->getType( mySection ); int aSectSize = myCurve->getNbPoints( mySection ); - - double anX; - - double anY; - - double aZ; - - int i = 0; - - for( ; i < ( aSectSize - 1 ) ; i++ ){ - - Handle_AIS_Point anAISPnt = getAISPoint(i); - - myObjects.push_back( anAISPnt ); - - Handle_AIS_Line aLine = getAISLine( i, i+1 ); - - myObjects.push_back( aLine ); - + bool aSectIsClosed = myCurve->isClosed( mySection ); + + if( aSectType == CurveCreator::Polyline ) + { + int i = 0; + for( ; i < ( aSectSize - 1 ) ; i++ ){ + Handle_AIS_Point anAISPnt = getAISPoint(i); + myObjects.push_back( anAISPnt ); + Handle_AIS_Line aLine = getAISLine( i, i+1 ); + myObjects.push_back( aLine ); + } + if( aSectSize != 0 ){ + Handle_AIS_Point anAISPnt = getAISPoint(i); + myObjects.push_back( anAISPnt ); + if( myCurve->isClosed(mySection) && ( aSectSize > 1 ) ){ + Handle_AIS_Line aLine = getAISLine( i, 0 ); + myObjects.push_back( aLine ); + } + } } + else if( aSectType == CurveCreator::BSpline ) + { + QList aPoints; + for( int i = 0; i < aSectSize; i++ ) + { + Handle_AIS_Point anAISPnt = getAISPoint( i ); + myObjects.push_back( anAISPnt ); + + double aX = 0, aY = 0, aZ = 0; + getPoint( i, aX, aY, aZ ); + aPoints << aX << aY; + } - if( aSectSize != 0 ){ - - Handle_AIS_Point anAISPnt = getAISPoint(i); - - myObjects.push_back( anAISPnt ); - - if( myCurve->isClosed(mySection) && ( aSectSize > 1 ) ){ - - Handle_AIS_Line aLine = getAISLine( i, 0 ); + if( aSectSize > 1 ) + { + HYDROData_BSplineOperation aBSpline( aPoints, 0, aSectIsClosed ); + TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge(); - myObjects.push_back( aLine ); + TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire(); + Handle(AIS_Shape) aShape = new AIS_Shape( aWire ); + myObjects.push_back( aShape ); } - } - } - - Handle_AIS_Point HYDROGUI_AISCurveSection::getAISPoint( int theIndx ) - { - double anX; - double anY; - double aZ; - getPoint( theIndx, anX, anY, aZ ); - gp_Pnt aPoint( anX, anY, aZ); AIS_Point* aPnt = new AIS_Point( new Geom_CartesianPoint(aPoint)); - return aPnt; - } - - Handle_AIS_Line HYDROGUI_AISCurveSection::getAISLine( int theIndx1, int theIndx2 ) - { - double anX; - double anY; - double aZ; - getPoint( theIndx1, anX, anY, aZ ); - gp_Pnt aPoint1( anX, anY, aZ); double anX2; - double anY2; - double aZ2; - getPoint( theIndx2, anX2, anY2, aZ2 ); - //MTN to avoid crash during line construction - if( ( anX == anX2 ) && ( anY == anY2 ) && (aZ == aZ2 ) ){ - aZ2 += 1e-7; - } gp_Pnt aPoint2( anX2, anY2, aZ2 ); AIS_Line* aLine = new AIS_Line( new Geom_CartesianPoint(aPoint1), new Geom_CartesianPoint(aPoint2) ); - return aLine; - } - - void HYDROGUI_AISCurveSection::getPoint( int theIndx, double& theX, double& theY, double& theZ ) - { - CurveCreator::Dimension aDim = myCurve->getDimension(); - CurveCreator::Coordinates aCoords = myCurve->getCoordinates( mySection, theIndx ); - theX = aCoords[0]; - theY = aCoords[1]; - theZ = 0.; - if( aDim == CurveCreator::Dim3d ){ - theZ = aCoords[2]; - } - } - - /******************************* HYDROGUI_AISCurve ********************************************/ - HYDROGUI_AISCurve::HYDROGUI_AISCurve( CurveCreator_Curve* theCurve, Handle_AIS_InteractiveContext theContext ) : - CurveCreator_Listener(), myCurve(theCurve), myContext( theContext ) - { - myCurve->setListener(this); - buildCurve(); - } - - HYDROGUI_AISCurve::~HYDROGUI_AISCurve(void) - { - + myCurve->removeListener(); } - - void HYDROGUI_AISCurve::setCurve( CurveCreator_Curve* theCurve ) - { - myCurve = theCurve; - buildCurve(); - } - - void HYDROGUI_AISCurve::Display() - { - for( int i = 0 ; i < myCurveRepresentation.size() ; i++ ){ - myCurveRepresentation[i]->Display(); - } - } - +void HYDROGUI_AISCurve::Erase() +{ + for( int i = 0 ; i < myCurveRepresentation.size() ; i++ ){ + myCurveRepresentation[i]->Erase(); + } +} void HYDROGUI_AISCurve::buildCurve() - { - for( int i = 0 ; i < myCurveRepresentation.size() ; i++ ){ - myCurveRepresentation[i]->Erase(); - delete myCurveRepresentation[i]; - } - myCurveRepresentation.clear(); for( int i = 0 ; i < myCurve->getNbSections() ; i++ ){ - HYDROGUI_AISCurveSection* aSection = new HYDROGUI_AISCurveSection( myContext, myCurve, i); - myCurveRepresentation.push_back( aSection ); - myCurveRepresentation[i]->Display(); - } - } - - void HYDROGUI_AISCurve::pointInserted( int theSection, int theIndx ) - { - buildCurve(); - } - - void HYDROGUI_AISCurve::highlightSection( int theSection, bool isHL ) - { - if( theSection >= myCurveRepresentation.size() ) - return; - myCurveRepresentation[theSection]->highlight(isHL); - } -