Salome HOME
Creat\Edit stream operation.
[modules/hydro.git] / src / HYDROCurveCreator / CurveCreator_AISCurve.cxx
1 // Copyright (C) 2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "CurveCreator_AISCurve.hxx"
21 #include "CurveCreator_ICurve.hxx"
22
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>
33
34 IMPLEMENT_STANDARD_HANDLE(CurveCreator_AISCurve, AIS_Shape)
35 IMPLEMENT_STANDARD_RTTIEXT(CurveCreator_AISCurve, AIS_Shape)
36
37 CurveCreator_AISCurve::CurveCreator_AISCurve( CurveCreator_ICurve* theCurve )
38 : AIS_Shape( TopoDS_Shape() ), myCurve( theCurve )
39 {
40 }
41
42 void CurveCreator_AISCurve::Compute( const Handle(PrsMgr_PresentationManager3d)& thePM,
43                                      const Handle(Prs3d_Presentation)& thePrs,
44                                      const Standard_Integer theMode )
45 {
46   thePrs->Clear();
47   //AIS_Shape::Compute( thePM, thePrs, theMode );
48
49   for( int iSection = 0 ; iSection < myCurve->getNbSections() ; iSection++ ) {
50     //TopoDS_Shape aShape;
51
52     CurveCreator::SectionType aSectType = myCurve->getSectionType( iSection );
53     int aSectSize = myCurve->getNbPoints( iSection );
54     bool aSectIsClosed = myCurve->isClosed( iSection );
55     /*if( aSectType == CurveCreator::Polyline )
56     {
57       int iPoint = 0; 
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 );
63       }
64       if( aSectSize != 0 ){
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 );
70         }
71       }
72     }*/
73     //else if( aSectType == CurveCreator::Spline )
74     {
75       std::vector<double> aPoints;
76       for( int iPoint = 0; iPoint < aSectSize; iPoint++ )
77       {
78         /*Handle_AIS_Point anAISPnt = getAISPoint( theISection, iPoint );
79         aSectionRepresentation.push_back( anAISPnt );
80         */
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 );
87       }
88       if( aSectSize > 1 )
89       {
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);
98           aListIter++;
99           aPnt.SetY(*aListIter);
100           aListIter++;
101           aPnt.SetZ(0);
102           aHCurvePoints->SetValue(ind, aPnt);
103         }
104         // compute BSpline
105         GeomAPI_Interpolate aGBC(aHCurvePoints, aSectIsClosed, gp::Resolution());
106         aGBC.Perform();
107         if (aGBC.IsDone()) {
108           aBSplineCurve = aGBC.Curve();
109         }
110         TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSplineCurve ).Edge();
111
112         TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire();
113
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 );
118         //SetColor(aColor);
119       }
120     }
121     //StdPrs_WFDeflectionShape::Add( thePrs, aShape, myDrawer );
122   }
123 }
124
125 void CurveCreator_AISCurve::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
126                                               const Standard_Integer theMode )
127 {
128   AIS_Shape::ComputeSelection( theSelection, theMode );
129 }