Salome HOME
Ceration of objects from popup menu of main partitions.
[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
48   //AIS_Shape::Compute( thePM, thePrs, theMode );
49
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 )
56     {
57
58       /*int iPoint = 0; 
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 );
64       }
65       if( aSectSize != 0 ){
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 );
71         }
72       }
73       */
74     }
75     //else if( aSectType == CurveCreator::Spline )
76     {
77       std::vector<double> aPoints;
78       for( int iPoint = 0; iPoint < aSectSize; iPoint++ )
79       {
80         /*Handle_AIS_Point anAISPnt = getAISPoint( theISection, iPoint );
81         aSectionRepresentation.push_back( anAISPnt );
82         */
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 );
89       }
90       if( aSectSize > 1 )
91       {
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);
100           aListIter++;
101           aPnt.SetY(*aListIter);
102           aListIter++;
103           aPnt.SetZ(0);
104           aHCurvePoints->SetValue(ind, aPnt);
105         }
106         // compute BSpline
107         GeomAPI_Interpolate aGBC(aHCurvePoints, aSectIsClosed, gp::Resolution());
108         aGBC.Perform();
109         if (aGBC.IsDone()) {
110           aBSplineCurve = aGBC.Curve();
111         }
112         TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSplineCurve ).Edge();
113
114         TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire();
115
116         Set( aWire );
117         AIS_Shape::Compute( thePM, thePrs, theMode );
118       }
119     }
120   }
121 }
122
123 void CurveCreator_AISCurve::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
124                                               const Standard_Integer theMode )
125 {
126   AIS_Shape::ComputeSelection( theSelection, theMode );
127 }