1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <HYDROGUI_Polyline.h>
20 #include <BRepAdaptor_Curve.hxx>
21 #include <BRepBndLib.hxx>
22 #include <BRep_Tool.hxx>
23 #include <GCPnts_AbscissaPoint.hxx>
24 #include <GCPnts_QuasiUniformDeflection.hxx>
25 #include <Graphic3d_ArrayOfPolylines.hxx>
26 #include <Prs3d_Arrow.hxx>
27 #include <Prs3d_LineAspect.hxx>
28 #include <Prs3d_Point.hxx>
29 #include <Prs3d_Root.hxx>
31 #include <TopExp_Explorer.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS_Vertex.hxx>
36 IMPLEMENT_STANDARD_RTTIEXT(HYDROGUI_Polyline, AIS_Shape)
39 HYDROGUI_Polyline::HYDROGUI_Polyline(const TopoDS_Shape& shape)
44 HYDROGUI_Polyline::~HYDROGUI_Polyline()
48 Handle( Graphic3d_ArrayOfPolylines ) BuildEdgePresentation( const TopoDS_Edge& theEdge, double theDeviation )
50 BRepAdaptor_Curve aCurveAdaptor( theEdge );
51 GCPnts_QuasiUniformDeflection aPnts( aCurveAdaptor, theDeviation );
53 Handle( Graphic3d_ArrayOfPolylines ) anArray;
57 int n = aPnts.NbPoints();
58 anArray = new Graphic3d_ArrayOfPolylines( n );
59 for( int i=1; i<=n; i++ )
60 anArray->AddVertex( aPnts.Value( i ) );
65 void HYDROGUI_Polyline::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
66 const Handle(Prs3d_Presentation)& aPrs,
67 const Standard_Integer aMode)
69 //AIS_Shape::Compute(aPresentationManager, aPrs, aMode);
73 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aPrs );
74 Quantity_Color aColor;
75 Aspect_TypeOfLine aType;
76 Standard_Real anWidth;
77 Attributes()->LineAspect()->Aspect()->Values( aColor, aType, anWidth );
79 Handle(Graphic3d_AspectLine3d) anAspect = new Graphic3d_AspectLine3d( aColor, aType, anWidth );
81 TopExp_Explorer Exp1 ( myshape, TopAbs_EDGE );
83 BRepBndLib::AddClose(myshape, BB);
84 double xmin, xmax, ymin, ymax, zmin, zmax;
85 double devCoeff = 0.05;
88 BB.Get(xmin, ymin, zmin, xmax, ymax, zmax); //ignore Z coord
89 double minSide = Min(Abs(xmax - xmin), Abs(ymax - ymin));
90 devCoeff = minSide > 50 ? 0.05 : minSide / 3000;
92 for ( ; Exp1.More(); Exp1.Next() )
94 TopoDS_Edge anEdge = TopoDS::Edge( Exp1.Current() );
95 Handle( Graphic3d_ArrayOfPolylines ) anArray = BuildEdgePresentation( anEdge, devCoeff );
96 if( !anArray.IsNull() )
98 aGroup->SetPrimitivesAspect( anAspect );
99 aGroup->AddPrimitiveArray( anArray );
104 QList<Handle(AIS_InteractiveObject)> HYDROGUI_Polyline::createPresentations( const TopoDS_Shape& shape )
106 QList<Handle(AIS_InteractiveObject)> shapes;
109 shapes.append( new HYDROGUI_Polyline( shape ) );
111 // 2. Shapes for direction arrows on edges
112 TopExp_Explorer Exp ( shape, TopAbs_EDGE );
113 for ( ; Exp.More(); Exp.Next() )
115 TopoDS_Edge anEdge = TopoDS::Edge(Exp.Current());
116 if ( !anEdge.IsNull() )
117 shapes.append( new HYDROGUI_Arrow( anEdge ) );
127 IMPLEMENT_STANDARD_RTTIEXT(HYDROGUI_Arrow, AIS_Shape)
130 HYDROGUI_Arrow::HYDROGUI_Arrow( const TopoDS_Edge& edge )
135 HYDROGUI_Arrow::~HYDROGUI_Arrow()
139 void HYDROGUI_Arrow::Compute( const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
140 const Handle(Prs3d_Presentation)& aPrs,
141 const Standard_Integer aMode )
145 TopoDS_Edge anEdge = TopoDS::Edge( myshape );
146 if( anEdge.IsNull() )
149 BRepAdaptor_Curve anAdaptor( anEdge );
150 double curveLen = GCPnts_AbscissaPoint::Length( anAdaptor, anAdaptor.FirstParameter(), anAdaptor.LastParameter() );
151 double arrowLen = qMin( curveLen/10, 35.0 );
153 double t = ( anAdaptor.FirstParameter() + anAdaptor.LastParameter() ) / 2;
156 anAdaptor.D1( t, P, V );
159 tr.SetTranslation( -gp_Vec( gp_Pnt(), P ) );
160 aPrs->SetTransformation( new Geom_Transformation( tr ) );
162 Handle(Graphic3d_TransformPers) tp = new Graphic3d_TransformPers( Graphic3d_TMF_ZoomPers, P );
163 SetTransformPersistence( tp );
165 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aPrs );
166 Quantity_Color aColor;
167 Aspect_TypeOfLine aType;
168 Standard_Real anWidth;
169 Attributes()->LineAspect()->Aspect()->Values( aColor, aType, anWidth );
171 Handle(Graphic3d_AspectLine3d) anAspect = new Graphic3d_AspectLine3d( aColor, aType, anWidth );
172 aGroup->SetPrimitivesAspect( anAspect );
173 Prs3d_Arrow::Draw( aGroup, gp_Pnt(), V, M_PI/180.*12., arrowLen );