From: asl Date: Thu, 21 Sep 2017 08:49:57 +0000 (+0300) Subject: refs #1330: type/size support for polyline arrow X-Git-Tag: v2.1~66^2~13^2~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=09f5eb100ec5e364736e10b8b1385a2bc9d88df9;p=modules%2Fhydro.git refs #1330: type/size support for polyline arrow --- diff --git a/src/HYDROGUI/HYDROGUI_Polyline.cxx b/src/HYDROGUI/HYDROGUI_Polyline.cxx index e640f9a7..b7d58e01 100644 --- a/src/HYDROGUI/HYDROGUI_Polyline.cxx +++ b/src/HYDROGUI/HYDROGUI_Polyline.cxx @@ -101,25 +101,47 @@ void HYDROGUI_Polyline::Compute(const Handle(PrsMgr_PresentationManager3d)& aPre } } -QList HYDROGUI_Polyline::createPresentations( const TopoDS_Shape& shape ) +QList HYDROGUI_Polyline::createPresentations + ( const TopoDS_Shape& theShape, int theType, int theSize ) { QList shapes; // 1. Main shape - shapes.append( new HYDROGUI_Polyline( shape ) ); + shapes.append( new HYDROGUI_Polyline( theShape ) ); // 2. Shapes for direction arrows on edges - TopExp_Explorer Exp ( shape, TopAbs_EDGE ); + TopExp_Explorer Exp ( theShape, TopAbs_EDGE ); for ( ; Exp.More(); Exp.Next() ) { TopoDS_Edge anEdge = TopoDS::Edge(Exp.Current()); if ( !anEdge.IsNull() ) - shapes.append( new HYDROGUI_Arrow( anEdge ) ); + { + Handle(HYDROGUI_Arrow) arrow = new HYDROGUI_Arrow( anEdge ); + if( theType>=0 ) + arrow->SetType( (HYDROGUI_Arrow::Type)theType ); + if( theSize>=0 ) + arrow->SetSize( theSize ); + shapes.append( arrow ); + } } return shapes; } +void HYDROGUI_Polyline::update( const QList& theObjects, int theType, int theSize ) +{ + foreach( Handle(AIS_InteractiveObject) obj, theObjects ) + { + Handle(HYDROGUI_Arrow) arrow = Handle(HYDROGUI_Arrow)::DownCast( obj ); + if( !arrow.IsNull() ) + { + if( theType>=0 ) + arrow->SetType( (HYDROGUI_Arrow::Type)theType ); + if( theSize>=0 ) + arrow->SetSize( theSize ); + } + } +} @@ -128,7 +150,7 @@ IMPLEMENT_STANDARD_RTTIEXT(HYDROGUI_Arrow, AIS_Shape) HYDROGUI_Arrow::HYDROGUI_Arrow( const TopoDS_Edge& edge ) - : AIS_Shape( edge ) + : AIS_Shape( edge ), myType( Cone ), mySize( 35 ) { } @@ -136,31 +158,67 @@ HYDROGUI_Arrow::~HYDROGUI_Arrow() { } +HYDROGUI_Arrow::Type HYDROGUI_Arrow::GetType() const +{ + return myType; +} + +void HYDROGUI_Arrow::SetType( HYDROGUI_Arrow::Type theType ) +{ + myType = theType; +} + +int HYDROGUI_Arrow::GetSize() const +{ + return mySize; +} + +void HYDROGUI_Arrow::SetSize( int theSize ) +{ + mySize = qMax( theSize, 0 ); +} + void HYDROGUI_Arrow::Compute( const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, const Handle(Prs3d_Presentation)& aPrs, const Standard_Integer aMode ) { aPrs->Clear(); - + if( myType==None ) + return; + TopoDS_Edge anEdge = TopoDS::Edge( myshape ); if( anEdge.IsNull() ) return; BRepAdaptor_Curve anAdaptor( anEdge ); double curveLen = GCPnts_AbscissaPoint::Length( anAdaptor, anAdaptor.FirstParameter(), anAdaptor.LastParameter() ); - double arrowLen = qMin( curveLen/10, 35.0 ); + double arrowLen; + if( mySize==0 ) + // if size==0, then the arrow length is proportional to curve length + arrowLen = curveLen/10; + else + arrowLen = qMin( curveLen/10, (double)mySize ); double t = ( anAdaptor.FirstParameter() + anAdaptor.LastParameter() ) / 2; - gp_Pnt P; + gp_Pnt P, P1; gp_Vec V; anAdaptor.D1( t, P, V ); - gp_Trsf tr; - tr.SetTranslation( -gp_Vec( gp_Pnt(), P ) ); - aPrs->SetTransformation( new Geom_Transformation( tr ) ); + bool isFixed = mySize>0; + + if( isFixed ) + { + gp_Trsf tr; + tr.SetTranslation( -gp_Vec( gp_Pnt(), P ) ); + aPrs->SetTransformation( new Geom_Transformation( tr ) ); - Handle(Graphic3d_TransformPers) tp = new Graphic3d_TransformPers( Graphic3d_TMF_ZoomPers, P ); - SetTransformPersistence( tp ); + Handle(Graphic3d_TransformPers) tp = new Graphic3d_TransformPers( Graphic3d_TMF_ZoomPers, P ); + SetTransformPersistence( tp ); + + P1 = gp_Pnt(); + } + else + P1 = P; Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aPrs ); Quantity_Color aColor; @@ -168,7 +226,34 @@ void HYDROGUI_Arrow::Compute( const Handle(PrsMgr_PresentationManager3d)& aPrese Standard_Real anWidth; Attributes()->LineAspect()->Aspect()->Values( aColor, aType, anWidth ); anWidth = 1; - Handle(Graphic3d_AspectLine3d) anAspect = new Graphic3d_AspectLine3d( aColor, aType, anWidth ); - aGroup->SetPrimitivesAspect( anAspect ); - Prs3d_Arrow::Draw( aGroup, gp_Pnt(), V, M_PI/180.*12., arrowLen ); + + if( myType==Cone ) + { + Handle(Graphic3d_AspectLine3d) anAspect = new Graphic3d_AspectLine3d( aColor, aType, anWidth ); + aGroup->SetPrimitivesAspect( anAspect ); + + Prs3d_Arrow::Draw( aGroup, P1, V, M_PI/180.*12., arrowLen ); + } + else + { + Graphic3d_MaterialAspect m( Graphic3d_NOM_PLASTIC ); + Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d + ( Aspect_IS_SOLID, aColor, aColor, Aspect_TOL_SOLID, 1, m, m ); + aGroup->SetPrimitivesAspect( anAspect ); + + gp_Vec d = -V.Normalized() * arrowLen; + const double k = 5.0; + gp_Vec n( -d.Y()/k, d.X()/k, 0 ); + + gp_Pnt Pa = P1.Translated( d ); + gp_Pnt P2 = Pa.Translated( n ); + gp_Pnt P3 = Pa.Translated( -n ); + + Handle(Graphic3d_ArrayOfTriangles) prim = new Graphic3d_ArrayOfTriangles(3); + prim->AddVertex( P1 ); + prim->AddVertex( P2 ); + prim->AddVertex( P3 ); + + aGroup->AddPrimitiveArray( prim ); + } } diff --git a/src/HYDROGUI/HYDROGUI_Polyline.h b/src/HYDROGUI/HYDROGUI_Polyline.h index 18aa9ecb..ca41ae7c 100644 --- a/src/HYDROGUI/HYDROGUI_Polyline.h +++ b/src/HYDROGUI/HYDROGUI_Polyline.h @@ -35,7 +35,9 @@ public: const Handle(Prs3d_Presentation)& aPresentation, const Standard_Integer aMode = 0); - static QList createPresentations( const TopoDS_Shape& shape ); + static QList createPresentations + ( const TopoDS_Shape& theShape, int theType, int theSize ); + static void update( const QList&, int theType, int theSize ); public: DEFINE_STANDARD_RTTIEXT(HYDROGUI_Polyline, AIS_Shape);