1 #include "HYDROGUI_AISCurve.h"
3 #include "CurveCreator_Curve.hxx"
5 #include <AIS_Point.hxx>
6 #include <AIS_Line.hxx>
11 #include <Geom_CartesianPoint.hxx>
13 HYDROGUI_AISCurveSection::HYDROGUI_AISCurveSection( Handle_AIS_InteractiveContext theContext,
14 CurveCreator_Curve* theCurve, int theSection) :
15 myCurve(theCurve), mySection(theSection), myContext(theContext), myIsHL(false)
20 HYDROGUI_AISCurveSection::~HYDROGUI_AISCurveSection()
23 for( int i = 0 ; i < myObjects.size() ; i++ ){
24 myObjects[i].Nullify();
29 Quantity_Color HYDROGUI_AISCurveSection::getActiveColor()
32 return Quantity_Color( 1., 0., 0., Quantity_TOC_RGB );
34 return Quantity_Color( 0., 1., 0., Quantity_TOC_RGB );
37 void HYDROGUI_AISCurveSection::highlight( bool isHL )
40 Quantity_Color aColor = getActiveColor();
41 for( int i = 0 ; i < myObjects.size() ; i++ ){
42 myObjects[i]->SetColor(aColor);
43 myContext->Display(myObjects[i]);
47 void HYDROGUI_AISCurveSection::Display()
49 for( int i = 0 ; i < myObjects.size() ; i++ ){
50 myContext->Display(myObjects[i]);
54 void HYDROGUI_AISCurveSection::Erase()
56 for( int i = 0 ; i < myObjects.size() ; i++ ){
57 myContext->Erase(myObjects[i]);
61 void HYDROGUI_AISCurveSection::buildSection()
63 int aSectSize = myCurve->getNbPoints( mySection );
68 for( ; i < ( aSectSize - 1 ) ; i++ ){
69 Handle_AIS_Point anAISPnt = getAISPoint(i);
70 myObjects.push_back( anAISPnt );
71 Handle_AIS_Line aLine = getAISLine( i, i+1 );
72 myObjects.push_back( aLine );
75 Handle_AIS_Point anAISPnt = getAISPoint(i);
76 myObjects.push_back( anAISPnt );
77 if( myCurve->isClosed(mySection) && ( aSectSize > 1 ) ){
78 Handle_AIS_Line aLine = getAISLine( i, 0 );
79 myObjects.push_back( aLine );
84 Handle_AIS_Point HYDROGUI_AISCurveSection::getAISPoint( int theIndx )
89 getPoint( theIndx, anX, anY, aZ );
90 gp_Pnt aPoint( anX, anY, aZ);
92 AIS_Point* aPnt = new AIS_Point( new Geom_CartesianPoint(aPoint));
96 Handle_AIS_Line HYDROGUI_AISCurveSection::getAISLine( int theIndx1, int theIndx2 )
101 getPoint( theIndx1, anX, anY, aZ );
102 gp_Pnt aPoint1( anX, anY, aZ);
107 getPoint( theIndx2, anX2, anY2, aZ2 );
108 //MTN to avoid crash during line construction
109 if( ( anX == anX2 ) && ( anY == anY2 ) && (aZ == aZ2 ) ){
113 gp_Pnt aPoint2( anX2, anY2, aZ2 );
115 AIS_Line* aLine = new AIS_Line( new Geom_CartesianPoint(aPoint1), new Geom_CartesianPoint(aPoint2) );
119 void HYDROGUI_AISCurveSection::getPoint( int theIndx, double& theX, double& theY, double& theZ )
121 CurveCreator::Dimension aDim = myCurve->getDimension();
122 CurveCreator::Coordinates aCoords = myCurve->getCoordinates( mySection, theIndx );
126 if( aDim == CurveCreator::Dim3d ){
131 /******************************* HYDROGUI_AISCurve ********************************************/
132 HYDROGUI_AISCurve::HYDROGUI_AISCurve( CurveCreator_Curve* theCurve, Handle_AIS_InteractiveContext theContext ) :
133 CurveCreator_Listener(), myCurve(theCurve), myContext( theContext )
135 myCurve->setListener(this);
139 HYDROGUI_AISCurve::~HYDROGUI_AISCurve(void)
143 void HYDROGUI_AISCurve::setCurve( CurveCreator_Curve* theCurve )
149 void HYDROGUI_AISCurve::Display()
151 for( int i = 0 ; i < myCurveRepresentation.size() ; i++ ){
152 myCurveRepresentation[i]->Display();
156 void HYDROGUI_AISCurve::buildCurve()
158 for( int i = 0 ; i < myCurveRepresentation.size() ; i++ ){
159 myCurveRepresentation[i]->Erase();
160 delete myCurveRepresentation[i];
162 myCurveRepresentation.clear();
164 for( int i = 0 ; i < myCurve->getNbSections() ; i++ ){
165 HYDROGUI_AISCurveSection* aSection = new HYDROGUI_AISCurveSection( myContext, myCurve, i);
166 myCurveRepresentation.push_back( aSection );
167 myCurveRepresentation[i]->Display();
171 void HYDROGUI_AISCurve::pointInserted( int theSection, int theIndx )
176 void HYDROGUI_AISCurve::highlightSection( int theSection, bool isHL )
178 if( theSection >= myCurveRepresentation.size() )
180 myCurveRepresentation[theSection]->highlight(isHL);