1 #include "HYDROGUI_AISCurve.h"
3 #include <HYDROData_BSplineOperation.h>
5 #include <CurveCreator.hxx>
6 #include <CurveCreator_Curve.hxx>
8 #include <AIS_Point.hxx>
9 #include <AIS_Line.hxx>
10 #include <AIS_Shape.hxx>
11 #include <BRepBuilderAPI_MakeEdge.hxx>
12 #include <BRepBuilderAPI_MakeWire.hxx>
13 #include <Geom_CartesianPoint.hxx>
16 #include <TopoDS_Edge.hxx>
17 #include <TopoDS_Face.hxx>
18 #include <TopoDS_Wire.hxx>
20 HYDROGUI_AISCurveSection::HYDROGUI_AISCurveSection( Handle_AIS_InteractiveContext theContext,
21 CurveCreator_Curve* theCurve, int theSection) :
22 myCurve(theCurve), mySection(theSection), myContext(theContext), myIsHL(false)
27 HYDROGUI_AISCurveSection::~HYDROGUI_AISCurveSection()
30 for( int i = 0 ; i < myObjects.size() ; i++ ){
31 myObjects[i].Nullify();
36 Quantity_Color HYDROGUI_AISCurveSection::getActiveColor()
39 return Quantity_Color( 1., 0., 0., Quantity_TOC_RGB );
41 return Quantity_Color( 0., 1., 0., Quantity_TOC_RGB );
44 void HYDROGUI_AISCurveSection::highlight( bool isHL )
47 Quantity_Color aColor = getActiveColor();
48 for( int i = 0 ; i < myObjects.size() ; i++ ){
49 myObjects[i]->SetColor(aColor);
50 myContext->Display(myObjects[i], Standard_False);
52 myContext->UpdateCurrentViewer();
55 void HYDROGUI_AISCurveSection::Display()
57 for( int i = 0 ; i < myObjects.size() ; i++ ){
58 myContext->Display(myObjects[i], Standard_False);
60 myContext->UpdateCurrentViewer();
63 void HYDROGUI_AISCurveSection::Erase()
65 for( int i = 0 ; i < myObjects.size() ; i++ ){
66 myContext->Erase(myObjects[i], Standard_False);
68 myContext->UpdateCurrentViewer();
71 void HYDROGUI_AISCurveSection::buildSection()
73 CurveCreator::SectionType aSectType = myCurve->getSectionType( mySection );
74 int aSectSize = myCurve->getNbPoints( mySection );
75 bool aSectIsClosed = myCurve->isClosed( mySection );
77 if( aSectType == CurveCreator::Polyline )
80 for( ; i < ( aSectSize - 1 ) ; i++ ){
81 Handle_AIS_Point anAISPnt = getAISPoint(i);
82 myObjects.push_back( anAISPnt );
83 Handle_AIS_Line aLine = getAISLine( i, i+1 );
84 myObjects.push_back( aLine );
87 Handle_AIS_Point anAISPnt = getAISPoint(i);
88 myObjects.push_back( anAISPnt );
89 if( myCurve->isClosed(mySection) && ( aSectSize > 1 ) ){
90 Handle_AIS_Line aLine = getAISLine( i, 0 );
91 myObjects.push_back( aLine );
95 else if( aSectType == CurveCreator::Spline )
97 QList<double> aPoints;
98 for( int i = 0; i < aSectSize; i++ )
100 Handle_AIS_Point anAISPnt = getAISPoint( i );
101 myObjects.push_back( anAISPnt );
103 double aX = 0, aY = 0, aZ = 0;
104 getPoint( i, aX, aY, aZ );
110 HYDROData_BSplineOperation aBSpline( aPoints, 0, aSectIsClosed );
111 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge();
113 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire();
115 Handle(AIS_Shape) aShape = new AIS_Shape( aWire );
116 myObjects.push_back( aShape );
121 Handle_AIS_Point HYDROGUI_AISCurveSection::getAISPoint( int theIndx )
126 getPoint( theIndx, anX, anY, aZ );
127 gp_Pnt aPoint( anX, anY, aZ);
129 AIS_Point* aPnt = new AIS_Point( new Geom_CartesianPoint(aPoint));
133 Handle_AIS_Line HYDROGUI_AISCurveSection::getAISLine( int theIndx1, int theIndx2 )
138 getPoint( theIndx1, anX, anY, aZ );
139 gp_Pnt aPoint1( anX, anY, aZ);
144 getPoint( theIndx2, anX2, anY2, aZ2 );
145 //MTN to avoid crash during line construction
146 if( ( anX == anX2 ) && ( anY == anY2 ) && (aZ == aZ2 ) ){
150 gp_Pnt aPoint2( anX2, anY2, aZ2 );
152 AIS_Line* aLine = new AIS_Line( new Geom_CartesianPoint(aPoint1), new Geom_CartesianPoint(aPoint2) );
156 void HYDROGUI_AISCurveSection::getPoint( int theIndx, double& theX, double& theY, double& theZ )
158 CurveCreator::Dimension aDim = myCurve->getDimension();
159 const CurveCreator::Coordinates aCoords = myCurve->getPoint( mySection, theIndx );
163 if( aDim == CurveCreator::Dim3d ){
168 /******************************* HYDROGUI_AISCurve ********************************************/
169 HYDROGUI_AISCurve::HYDROGUI_AISCurve( CurveCreator_Curve* theCurve, Handle_AIS_InteractiveContext theContext ) :
170 CurveCreator_Listener(), myCurve(theCurve), myContext( theContext )
172 myCurve->setListener(this);
176 HYDROGUI_AISCurve::~HYDROGUI_AISCurve(void)
178 myCurve->removeListener();
181 void HYDROGUI_AISCurve::setCurve( CurveCreator_Curve* theCurve )
187 void HYDROGUI_AISCurve::Display()
189 for( int i = 0 ; i < myCurveRepresentation.size() ; i++ ){
190 myCurveRepresentation[i]->Display();
194 void HYDROGUI_AISCurve::Erase()
196 for( int i = 0 ; i < myCurveRepresentation.size() ; i++ ){
197 myCurveRepresentation[i]->Erase();
201 void HYDROGUI_AISCurve::buildCurve()
203 for( int i = 0 ; i < myCurveRepresentation.size() ; i++ ){
204 myCurveRepresentation[i]->Erase();
205 delete myCurveRepresentation[i];
207 myCurveRepresentation.clear();
209 for( int i = 0 ; i < myCurve->getNbSections() ; i++ ){
210 HYDROGUI_AISCurveSection* aSection = new HYDROGUI_AISCurveSection( myContext, myCurve, i);
211 myCurveRepresentation.push_back( aSection );
212 myCurveRepresentation[i]->Display();
216 void HYDROGUI_AISCurve::pointChanged( int theSection, int thePoint )
221 void HYDROGUI_AISCurve::pointInserted( int theSection, int theIndx )
226 void HYDROGUI_AISCurve::highlightSection( int theSection, bool isHL )
228 if( theSection >= myCurveRepresentation.size() )
230 myCurveRepresentation[theSection]->highlight(isHL);