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_ICurve.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 <TopoDS_Edge.hxx>
32 #include <TopoDS_Wire.hxx>
34 IMPLEMENT_STANDARD_HANDLE(CurveCreator_AISCurve, AIS_Shape)
35 IMPLEMENT_STANDARD_RTTIEXT(CurveCreator_AISCurve, AIS_Shape)
37 CurveCreator_AISCurve::CurveCreator_AISCurve( CurveCreator_ICurve* theCurve )
38 : AIS_Shape( TopoDS_Shape() ), myCurve( theCurve )
42 void CurveCreator_AISCurve::Compute( const Handle(PrsMgr_PresentationManager3d)& thePM,
43 const Handle(Prs3d_Presentation)& thePrs,
44 const Standard_Integer theMode )
47 //AIS_Shape::Compute( thePM, thePrs, theMode );
49 for( int iSection = 0 ; iSection < myCurve->getNbSections() ; iSection++ ) {
50 //TopoDS_Shape aShape;
52 CurveCreator::SectionType aSectType = myCurve->getSectionType( iSection );
53 int aSectSize = myCurve->getNbPoints( iSection );
54 bool aSectIsClosed = myCurve->isClosed( iSection );
55 /*if( aSectType == CurveCreator::Polyline )
58 for( ; iPoint < ( aSectSize - 1 ) ; iPoint++ ){
59 Handle_AIS_Point anAISPnt = getAISPoint(theISection, iPoint);
60 aSectionRepresentation.push_back( anAISPnt );
61 Handle_AIS_Line aLine = getAISLine( theISection, iPoint, iPoint+1 );
62 aSectionRepresentation.push_back( aLine );
65 Handle_AIS_Point anAISPnt = getAISPoint(theISection, iPoint);
66 aSectionRepresentation.push_back( anAISPnt );
67 if( isClosed(theISection) && ( aSectSize > 1 ) ){
68 Handle_AIS_Line aLine = getAISLine( theISection, iPoint, 0 );
69 aSectionRepresentation.push_back( aLine );
73 //else if( aSectType == CurveCreator::Spline )
75 std::vector<double> aPoints;
76 for( int iPoint = 0; iPoint < aSectSize; iPoint++ )
78 /*Handle_AIS_Point anAISPnt = getAISPoint( theISection, iPoint );
79 aSectionRepresentation.push_back( anAISPnt );
81 CurveCreator::Coordinates aCoords = myCurve->getPoint( iSection, iPoint );
82 double aX = aCoords[0];
83 double aY = aCoords[1];
84 double aZ = aCoords[2];
85 aPoints.push_back( aX );
86 aPoints.push_back( aY );
90 Handle(Geom_BSplineCurve) aBSplineCurve;
91 // fill array for algorithm by the received coordinates
92 int aLen = aPoints.size() / 2;
93 Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt (1, aLen);
94 std::vector<double>::const_iterator aListIter = aPoints.begin();
95 for (int ind = 1; ind <= aLen; ind++) {
96 gp_Pnt aPnt(gp::Origin());
97 aPnt.SetX(*aListIter);
99 aPnt.SetY(*aListIter);
102 aHCurvePoints->SetValue(ind, aPnt);
105 GeomAPI_Interpolate aGBC(aHCurvePoints, aSectIsClosed, gp::Resolution());
108 aBSplineCurve = aGBC.Curve();
110 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSplineCurve ).Edge();
112 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire();
114 //Handle(AIS_Shape) aShape = new AIS_Shape( aWire );
115 //aSectionRepresentation.push_back( aShape );
116 StdPrs_WFDeflectionShape::Add( thePrs, aWire/*aShape*/, myDrawer );
117 //Quantity_Color aColor( 200, 200, 100, Quantity_TOC_RGB );
121 //StdPrs_WFDeflectionShape::Add( thePrs, aShape, myDrawer );
125 void CurveCreator_AISCurve::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
126 const Standard_Integer theMode )
128 AIS_Shape::ComputeSelection( theSelection, theMode );