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 )
48 //AIS_Shape::Compute( thePM, thePrs, theMode );
50 for( int iSection = 0 ; iSection < myCurve->getNbSections() ; iSection++ ) {
51 //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 )
59 for( ; iPoint < ( aSectSize - 1 ) ; iPoint++ ){
60 Handle_AIS_Point anAISPnt = getAISPoint(theISection, iPoint);
61 aSectionRepresentation.push_back( anAISPnt );
62 Handle_AIS_Line aLine = getAISLine( theISection, iPoint, iPoint+1 );
63 aSectionRepresentation.push_back( aLine );
66 Handle_AIS_Point anAISPnt = getAISPoint(theISection, iPoint);
67 aSectionRepresentation.push_back( anAISPnt );
68 if( isClosed(theISection) && ( aSectSize > 1 ) ){
69 Handle_AIS_Line aLine = getAISLine( theISection, iPoint, 0 );
70 aSectionRepresentation.push_back( aLine );
75 //else if( aSectType == CurveCreator::Spline )
77 std::vector<double> aPoints;
78 for( int iPoint = 0; iPoint < aSectSize; iPoint++ )
80 /*Handle_AIS_Point anAISPnt = getAISPoint( theISection, iPoint );
81 aSectionRepresentation.push_back( anAISPnt );
83 CurveCreator::Coordinates aCoords = myCurve->getPoint( iSection, iPoint );
84 double aX = aCoords[0];
85 double aY = aCoords[1];
86 double aZ = aCoords[2];
87 aPoints.push_back( aX );
88 aPoints.push_back( aY );
92 Handle(Geom_BSplineCurve) aBSplineCurve;
93 // fill array for algorithm by the received coordinates
94 int aLen = aPoints.size() / 2;
95 Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt (1, aLen);
96 std::vector<double>::const_iterator aListIter = aPoints.begin();
97 for (int ind = 1; ind <= aLen; ind++) {
98 gp_Pnt aPnt(gp::Origin());
99 aPnt.SetX(*aListIter);
101 aPnt.SetY(*aListIter);
104 aHCurvePoints->SetValue(ind, aPnt);
107 GeomAPI_Interpolate aGBC(aHCurvePoints, aSectIsClosed, gp::Resolution());
110 aBSplineCurve = aGBC.Curve();
112 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSplineCurve ).Edge();
114 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire();
117 AIS_Shape::Compute( thePM, thePrs, theMode );
123 void CurveCreator_AISCurve::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
124 const Standard_Integer theMode )
126 AIS_Shape::ComputeSelection( theSelection, theMode );