1 #include "HYDROGUI_AISCurve.h"
3 #include <HYDROData_BSplineOperation.h>
5 #include <CurveCreator_Curve.hxx>
7 #include <AIS_Point.hxx>
8 #include <AIS_Line.hxx>
9 #include <AIS_Shape.hxx>
10 #include <BRepBuilderAPI_MakeEdge.hxx>
11 #include <BRepBuilderAPI_MakeWire.hxx>
12 #include <Geom_CartesianPoint.hxx>
15 #include <TopoDS_Edge.hxx>
16 #include <TopoDS_Face.hxx>
17 #include <TopoDS_Wire.hxx>
19 HYDROGUI_AISCurveSection::HYDROGUI_AISCurveSection( Handle_AIS_InteractiveContext theContext,
20 CurveCreator_Curve* theCurve, int theSection) :
21 myCurve(theCurve), mySection(theSection), myContext(theContext), myIsHL(false)
26 HYDROGUI_AISCurveSection::~HYDROGUI_AISCurveSection()
29 for( int i = 0 ; i < myObjects.size() ; i++ ){
30 myObjects[i].Nullify();
35 Quantity_Color HYDROGUI_AISCurveSection::getActiveColor()
38 return Quantity_Color( 1., 0., 0., Quantity_TOC_RGB );
40 return Quantity_Color( 0., 1., 0., Quantity_TOC_RGB );
43 void HYDROGUI_AISCurveSection::highlight( bool isHL )
46 Quantity_Color aColor = getActiveColor();
47 for( int i = 0 ; i < myObjects.size() ; i++ ){
48 myObjects[i]->SetColor(aColor);
49 myContext->Display(myObjects[i], Standard_False);
51 myContext->UpdateCurrentViewer();
54 void HYDROGUI_AISCurveSection::Display()
56 for( int i = 0 ; i < myObjects.size() ; i++ ){
57 myContext->Display(myObjects[i], Standard_False);
59 myContext->UpdateCurrentViewer();
62 void HYDROGUI_AISCurveSection::Erase()
64 for( int i = 0 ; i < myObjects.size() ; i++ ){
65 myContext->Erase(myObjects[i], Standard_False);
67 myContext->UpdateCurrentViewer();
70 void HYDROGUI_AISCurveSection::buildSection()
72 CurveCreator::Type aSectType = myCurve->getType( mySection );
73 int aSectSize = myCurve->getNbPoints( mySection );
74 bool aSectIsClosed = myCurve->isClosed( mySection );
76 if( aSectType == CurveCreator::Polyline )
79 for( ; i < ( aSectSize - 1 ) ; i++ ){
80 Handle_AIS_Point anAISPnt = getAISPoint(i);
81 myObjects.push_back( anAISPnt );
82 Handle_AIS_Line aLine = getAISLine( i, i+1 );
83 myObjects.push_back( aLine );
86 Handle_AIS_Point anAISPnt = getAISPoint(i);
87 myObjects.push_back( anAISPnt );
88 if( myCurve->isClosed(mySection) && ( aSectSize > 1 ) ){
89 Handle_AIS_Line aLine = getAISLine( i, 0 );
90 myObjects.push_back( aLine );
94 else if( aSectType == CurveCreator::BSpline )
96 QList<double> aPoints;
97 for( int i = 0; i < aSectSize; i++ )
99 Handle_AIS_Point anAISPnt = getAISPoint( i );
100 myObjects.push_back( anAISPnt );
102 double aX = 0, aY = 0, aZ = 0;
103 getPoint( i, aX, aY, aZ );
109 HYDROData_BSplineOperation aBSpline( aPoints, 0, aSectIsClosed );
110 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge();
112 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire();
114 Handle(AIS_Shape) aShape = new AIS_Shape( aWire );
115 myObjects.push_back( aShape );
120 Handle_AIS_Point HYDROGUI_AISCurveSection::getAISPoint( int theIndx )
125 getPoint( theIndx, anX, anY, aZ );
126 gp_Pnt aPoint( anX, anY, aZ);
128 AIS_Point* aPnt = new AIS_Point( new Geom_CartesianPoint(aPoint));
132 Handle_AIS_Line HYDROGUI_AISCurveSection::getAISLine( int theIndx1, int theIndx2 )
137 getPoint( theIndx1, anX, anY, aZ );
138 gp_Pnt aPoint1( anX, anY, aZ);
143 getPoint( theIndx2, anX2, anY2, aZ2 );
144 //MTN to avoid crash during line construction
145 if( ( anX == anX2 ) && ( anY == anY2 ) && (aZ == aZ2 ) ){
149 gp_Pnt aPoint2( anX2, anY2, aZ2 );
151 AIS_Line* aLine = new AIS_Line( new Geom_CartesianPoint(aPoint1), new Geom_CartesianPoint(aPoint2) );
155 void HYDROGUI_AISCurveSection::getPoint( int theIndx, double& theX, double& theY, double& theZ )
157 CurveCreator::Dimension aDim = myCurve->getDimension();
158 CurveCreator::Coordinates aCoords = myCurve->getCoordinates( mySection, theIndx );
162 if( aDim == CurveCreator::Dim3d ){
167 /******************************* HYDROGUI_AISCurve ********************************************/
168 HYDROGUI_AISCurve::HYDROGUI_AISCurve( CurveCreator_Curve* theCurve, Handle_AIS_InteractiveContext theContext ) :
169 CurveCreator_Listener(), myCurve(theCurve), myContext( theContext )
171 myCurve->setListener(this);
175 HYDROGUI_AISCurve::~HYDROGUI_AISCurve(void)
177 myCurve->removeListener();
180 void HYDROGUI_AISCurve::setCurve( CurveCreator_Curve* theCurve )
186 void HYDROGUI_AISCurve::Display()
188 for( int i = 0 ; i < myCurveRepresentation.size() ; i++ ){
189 myCurveRepresentation[i]->Display();
193 void HYDROGUI_AISCurve::Erase()
195 for( int i = 0 ; i < myCurveRepresentation.size() ; i++ ){
196 myCurveRepresentation[i]->Erase();
200 void HYDROGUI_AISCurve::buildCurve()
202 for( int i = 0 ; i < myCurveRepresentation.size() ; i++ ){
203 myCurveRepresentation[i]->Erase();
204 delete myCurveRepresentation[i];
206 myCurveRepresentation.clear();
208 for( int i = 0 ; i < myCurve->getNbSections() ; i++ ){
209 HYDROGUI_AISCurveSection* aSection = new HYDROGUI_AISCurveSection( myContext, myCurve, i);
210 myCurveRepresentation.push_back( aSection );
211 myCurveRepresentation[i]->Display();
215 void HYDROGUI_AISCurve::pointInserted( int theSection, int theIndx )
220 void HYDROGUI_AISCurve::highlightSection( int theSection, bool isHL )
222 if( theSection >= myCurveRepresentation.size() )
224 myCurveRepresentation[theSection]->highlight(isHL);