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);
57 std::deque<float> aPoint = myCurve->getPoint( theSectionId, thePointId );
61 thePoint = gp_Pnt( anX, anY, aZ);*/
64 #define MAKE_BUILDER_USE
65 void CurveCreator_AISCurve::Compute( const Handle(PrsMgr_PresentationManager3d)& thePM,
66 const Handle(Prs3d_Presentation)& thePrs,
67 const Standard_Integer theMode )
71 for( int iSection = 0 ; iSection < myCurve->getNbSections() ; iSection++ ) {
72 CurveCreator::SectionType aSectType = myCurve->getSectionType( iSection );
73 int aPointSize = myCurve->getNbPoints( iSection );
74 bool aSectIsClosed = myCurve->isClosed( iSection );
75 if( aSectType == CurveCreator::Polyline )
78 gp_Pnt aPrevPoint, aPoint;
79 if ( aPointSize == 1 ) {
80 getPoint( iSection, iPoint, aPrevPoint );
81 TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex( aPrevPoint ).Vertex();
84 else if ( aPointSize > 1 ) {
85 #ifdef MAKE_BUILDER_USE
86 TopoDS_Edge aPointEdge;
87 BRepBuilderAPI_MakeWire aMakeWire;
88 getPoint( iSection, iPoint, aPrevPoint );
90 for( ; iPoint < aPointSize; iPoint++ ) {
91 getPoint( iSection, iPoint, aPoint );
92 aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge();
93 aMakeWire.Add( BRepBuilderAPI_MakeWire( aPointEdge ) );
96 if( myCurve->isClosed( iSection ) && ( aPointSize > 2 ) ) {
97 getPoint( iSection, 0, aPoint );
98 aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge();
99 aMakeWire.Add( BRepBuilderAPI_MakeWire( aPointEdge ) );
102 TopoDS_Wire aLineWire = aMakeWire.Wire();
104 AIS_Shape::Compute( thePM, thePrs, theMode );
107 bool isClosed = myCurve->isClosed( iSection ) && ( aPointSize > 2 );
108 Handle(Graphic3d_ArrayOfPolylines) anArray = new Graphic3d_ArrayOfPolylines
109 ( !isClosed ? aPointSize : aPointSize+1 );
110 for( ; iPoint < aPointSize; iPoint++ ) {
111 getPoint( iSection, iPoint, aPoint );
112 anArray->AddVertex(aPoint.X(), aPoint.Y(), aPoint.Z());
115 if( myCurve->isClosed( iSection ) && ( aPointSize > 2 ) ) {
116 getPoint( iSection, 0, aPoint );
117 anArray->AddVertex(aPoint.X(), aPoint.Y(), aPoint.Z());
119 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( thePrs );
120 aGroup->AddPrimitiveArray(anArray);
123 else if( aSectType == CurveCreator::Spline )
125 std::vector<double> aPoints;
126 for( int iPoint = 0; iPoint < aPointSize; iPoint++ )
128 CurveCreator::Coordinates aCoords = myCurve->getPoint( iSection, iPoint );
129 double aX = aCoords[0];
130 double aY = aCoords[1];
131 double aZ = aCoords[2];
132 aPoints.push_back( aX );
133 aPoints.push_back( aY );
137 Handle(Geom_BSplineCurve) aBSplineCurve;
138 Handle(Geom_Curve) aGeomCurve;
139 // fill array for algorithm by the received coordinates
140 int aLen = aPoints.size() / 2;
141 Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt (1, aLen);
142 std::vector<double>::const_iterator aListIter = aPoints.begin();
143 for (int ind = 1; ind <= aLen; ind++) {
144 gp_Pnt aPnt(gp::Origin());
145 aPnt.SetX(*aListIter);
147 aPnt.SetY(*aListIter);
150 aHCurvePoints->SetValue(ind, aPnt);
153 GeomAPI_Interpolate aGBC(aHCurvePoints, aSectIsClosed, gp::Resolution());
156 aBSplineCurve = aGBC.Curve();
158 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSplineCurve ).Edge();
160 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire();
163 AIS_Shape::Compute( thePM, thePrs, theMode );
169 void CurveCreator_AISCurve::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
170 const Standard_Integer theMode )
172 AIS_Shape::ComputeSelection( theSelection, theMode );