1 // Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "CurveCreator_AISCurve.hxx"
21 #include "CurveCreator_Curve.hxx"
23 #include <Quantity_Color.hxx>
24 #include <Prs3d_Presentation.hxx>
25 #include <StdPrs_WFDeflectionShape.hxx>
26 #include <Geom_BSplineCurve.hxx>
27 #include <TColgp_HArray1OfPnt.hxx>
28 #include <GeomAPI_Interpolate.hxx>
29 #include <BRepBuilderAPI_MakeEdge.hxx>
30 #include <BRepBuilderAPI_MakeWire.hxx>
31 #include <BRepBuilderAPI_MakeVertex.hxx>
32 #include <TopoDS_Edge.hxx>
33 #include <TopoDS_Wire.hxx>
35 #include <Graphic3d_Array1OfVertex.hxx>
36 #include <Graphic3d_Group.hxx>
37 #include <Graphic3d_ArrayOfSegments.hxx>
38 #include <Prs3d_Root.hxx>
40 IMPLEMENT_STANDARD_HANDLE(CurveCreator_AISCurve, AIS_Shape)
41 IMPLEMENT_STANDARD_RTTIEXT(CurveCreator_AISCurve, AIS_Shape)
43 CurveCreator_AISCurve::CurveCreator_AISCurve( CurveCreator_Curve* theCurve )
44 : AIS_Shape( TopoDS_Shape() ), myCurve( theCurve )
48 void CurveCreator_AISCurve::getPoint( const int theISection, const int theIPoint,
52 myCurve->getCoordinates( theISection, theIPoint, anX, anY, aZ );
53 thePoint = gp_Pnt( anX, anY, aZ);
56 #define MAKE_BUILDER_USE
57 void CurveCreator_AISCurve::Compute( const Handle(PrsMgr_PresentationManager3d)& thePM,
58 const Handle(Prs3d_Presentation)& thePrs,
59 const Standard_Integer theMode )
63 for( int iSection = 0 ; iSection < myCurve->getNbSections() ; iSection++ ) {
64 CurveCreator::SectionType aSectType = myCurve->getSectionType( iSection );
65 int aPointSize = myCurve->getNbPoints( iSection );
66 bool aSectIsClosed = myCurve->isClosed( iSection );
67 if( aSectType == CurveCreator::Polyline )
70 gp_Pnt aPrevPoint, aPoint;
71 if ( aPointSize == 1 ) {
72 getPoint( iSection, iPoint, aPrevPoint );
73 TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex( aPrevPoint ).Vertex();
76 else if ( aPointSize > 1 ) {
77 #ifdef MAKE_BUILDER_USE
78 TopoDS_Edge aPointEdge;
79 BRepBuilderAPI_MakeWire aMakeWire;
80 getPoint( iSection, iPoint, aPrevPoint );
82 for( ; iPoint < aPointSize; iPoint++ ) {
83 getPoint( iSection, iPoint, aPoint );
84 aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge();
85 aMakeWire.Add( BRepBuilderAPI_MakeWire( aPointEdge ) );
88 if( myCurve->isClosed( iSection ) && ( aPointSize > 2 ) ) {
89 getPoint( iSection, 0, aPoint );
90 aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge();
91 aMakeWire.Add( BRepBuilderAPI_MakeWire( aPointEdge ) );
94 TopoDS_Wire aLineWire = aMakeWire.Wire();
96 AIS_Shape::Compute( thePM, thePrs, theMode );
99 bool isClosed = myCurve->isClosed( iSection ) && ( aPointSize > 2 );
100 Handle(Graphic3d_ArrayOfPolylines) anArray = new Graphic3d_ArrayOfPolylines
101 ( !isClosed ? aPointSize : aPointSize+1 );
102 for( ; iPoint < aPointSize; iPoint++ ) {
103 getPoint( iSection, iPoint, aPoint );
104 anArray->AddVertex(aPoint.X(), aPoint.Y(), aPoint.Z());
107 if( myCurve->isClosed( iSection ) && ( aPointSize > 2 ) ) {
108 getPoint( iSection, 0, aPoint );
109 anArray->AddVertex(aPoint.X(), aPoint.Y(), aPoint.Z());
111 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( thePrs );
112 aGroup->AddPrimitiveArray(anArray);
115 else if( aSectType == CurveCreator::Spline )
117 std::vector<double> aPoints;
118 for( int iPoint = 0; iPoint < aPointSize; iPoint++ )
120 CurveCreator::Coordinates aCoords = myCurve->getPoint( iSection, iPoint );
121 double aX = aCoords[0];
122 double aY = aCoords[1];
123 double aZ = aCoords[2];
124 aPoints.push_back( aX );
125 aPoints.push_back( aY );
129 Handle(Geom_BSplineCurve) aBSplineCurve;
130 Handle(Geom_Curve) aGeomCurve;
131 // fill array for algorithm by the received coordinates
132 int aLen = aPoints.size() / 2;
133 Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt (1, aLen);
134 std::vector<double>::const_iterator aListIter = aPoints.begin();
135 for (int ind = 1; ind <= aLen; ind++) {
136 gp_Pnt aPnt(gp::Origin());
137 aPnt.SetX(*aListIter);
139 aPnt.SetY(*aListIter);
142 aHCurvePoints->SetValue(ind, aPnt);
145 GeomAPI_Interpolate aGBC(aHCurvePoints, aSectIsClosed, gp::Resolution());
148 aBSplineCurve = aGBC.Curve();
150 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSplineCurve ).Edge();
152 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire();
155 AIS_Shape::Compute( thePM, thePrs, theMode );
161 void CurveCreator_AISCurve::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
162 const Standard_Integer theMode )
164 AIS_Shape::ComputeSelection( theSelection, theMode );