From 2e7629270ac6919a3421a0a562b8fc58bf3d7667 Mon Sep 17 00:00:00 2001 From: apl Date: Fri, 21 Oct 2016 12:52:30 +0300 Subject: [PATCH] Create annotation interaction and "hidden line" mode --- src/GEOMBase/GEOMBase_Helper.h | 5 +- src/GEOMGUI/GEOMGUI_AnnotationAttrs.cxx | 49 +++++--- src/GEOMGUI/GEOMGUI_AnnotationAttrs.h | 24 +++- src/GEOMGUI/GEOM_Displayer.cxx | 1 + src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx | 92 ++++++++++++--- src/MeasureGUI/MeasureGUI_AnnotationDlg.h | 5 + .../MeasureGUI_AnnotationInteractor.cxx | 10 +- .../MeasureGUI_AnnotationInteractor.h | 8 ++ src/OBJECT/GEOM_Annotation.cxx | 110 ++++++++++++++---- src/OBJECT/GEOM_Annotation.hxx | 44 +++++-- 10 files changed, 279 insertions(+), 69 deletions(-) mode change 100644 => 100755 src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx mode change 100644 => 100755 src/MeasureGUI/MeasureGUI_AnnotationInteractor.cxx mode change 100644 => 100755 src/MeasureGUI/MeasureGUI_AnnotationInteractor.h diff --git a/src/GEOMBase/GEOMBase_Helper.h b/src/GEOMBase/GEOMBase_Helper.h index 64d46f202..a62b2f129 100755 --- a/src/GEOMBase/GEOMBase_Helper.h +++ b/src/GEOMBase/GEOMBase_Helper.h @@ -65,6 +65,8 @@ public: static SUIT_ViewWindow* getActiveView(); protected: + typedef std::list PrsList; + static GEOM::GEOM_Gen_ptr getGeomEngine(); void display ( const ObjectList&, const bool = true ); @@ -97,6 +99,8 @@ protected: const bool = true ); void erasePreview ( const bool = true ); + const PrsList& getPreview() const { return myPreview; } + void localSelection( const ObjectList&, const std::list ); void localSelection( const ObjectList&, const int ); void localSelection( GEOM::GEOM_Object_ptr, const std::list ); @@ -210,7 +214,6 @@ private: void clearShapeBuffer( GEOM::GEOM_Object_ptr ); private: - typedef std::list PrsList; PrsList myPreview; GEOM_Displayer* myDisplayer; diff --git a/src/GEOMGUI/GEOMGUI_AnnotationAttrs.cxx b/src/GEOMGUI/GEOMGUI_AnnotationAttrs.cxx index ad6eddeb4..a5a656979 100755 --- a/src/GEOMGUI/GEOMGUI_AnnotationAttrs.cxx +++ b/src/GEOMGUI/GEOMGUI_AnnotationAttrs.cxx @@ -29,9 +29,6 @@ #include #include -// OCCT includes -#include - // STL includes #include #include @@ -353,10 +350,19 @@ void GEOMGUI_AnnotationAttrs::GetShapeSel( const int theIndex, int& theShapeType // purpose : //================================================================================= void GEOMGUI_AnnotationAttrs::Append( const Properties& theProps ) +{ + this->Append( theProps, gp_Ax3() ); +} + +//================================================================================= +// function : Append +// purpose : +//================================================================================= +void GEOMGUI_AnnotationAttrs::Append( const Properties& theProps, const gp_Ax3& theShapeLCS ) { const int aCount = this->GetNbAnnotation(); this->SetNbAnnotation( aCount + 1 ); - this->SetProperties( aCount, theProps ); + this->SetProperties( aCount, theProps, theShapeLCS ); } //================================================================================= @@ -365,13 +371,27 @@ void GEOMGUI_AnnotationAttrs::Append( const Properties& theProps ) //================================================================================= void GEOMGUI_AnnotationAttrs::SetProperties( const int theIndex, const Properties& theProps ) { + this->SetProperties( theIndex, theProps, gp_Ax3() ); +} + +//================================================================================= +// function : SetProperties +// purpose : +//================================================================================= +void GEOMGUI_AnnotationAttrs::SetProperties( const int theIndex, const Properties& theProps, + const gp_Ax3& theShapeLCS ) +{ + gp_Trsf aToShapeLCS; + aToShapeLCS.SetTransformation( gp_Ax3(), theShapeLCS ); + this->SetName( theIndex, theProps.Name ); this->SetText( theIndex, theProps.Text ); this->SetIsVisible( theIndex, theProps.IsVisible ); this->SetIsScreenFixed( theIndex, theProps.IsScreenFixed ); - this->SetPosition( theIndex, theProps.Position ); - this->SetAttach( theIndex, theProps.Attach ); this->SetShapeSel( theIndex, theProps.ShapeType, theProps.ShapeIndex ); + this->SetAttach( theIndex, theProps.Attach.Transformed( aToShapeLCS ) ); + this->SetPosition( theIndex, (theProps.IsScreenFixed) ? + theProps.Position : theProps.Position.Transformed( aToShapeLCS ) ); } //================================================================================= @@ -396,19 +416,20 @@ void GEOMGUI_AnnotationAttrs::GetProperties( const int theIndex, Properties& the //================================================================================= void GEOMGUI_AnnotationAttrs::SetupPresentation( const Handle(GEOM_Annotation)& thePresentation, const Properties& theProps, - const gp_Ax3& theLCS ) + const gp_Ax3& theShapeLCS ) { - gp_Trsf aToLCS; - aToLCS.SetTransformation( theLCS, gp_Ax3() ); + gp_Trsf aFromShapeLCS; + aFromShapeLCS.SetTransformation( theShapeLCS, gp_Ax3() ); TCollection_ExtendedString aText; for (int i = 0; i < (int)theProps.Text.length(); i++ ) aText.Insert( i + 1, theProps.Text[ i ].unicode() ); - // + thePresentation->SetText( aText ); thePresentation->SetScreenFixed( theProps.IsScreenFixed ); - thePresentation->SetPosition( theProps.Position ); - thePresentation->SetAttachPoint( theProps.Attach.Transformed( aToLCS ) ); + thePresentation->SetAttachPoint( theProps.Attach.Transformed( aFromShapeLCS ) ); + thePresentation->SetPosition( (theProps.IsScreenFixed) ? + theProps.Position : theProps.Position.Transformed( aFromShapeLCS ) ); } //================================================================================= @@ -417,9 +438,9 @@ void GEOMGUI_AnnotationAttrs::SetupPresentation( const Handle(GEOM_Annotation)& //================================================================================= void GEOMGUI_AnnotationAttrs::SetupPresentation( const Handle(GEOM_Annotation)& thePresentation, const int theIndex, - const gp_Ax3& theLCS ) + const gp_Ax3& theShapeLCS ) { Properties aProps; this->GetProperties( theIndex, aProps ); - this->SetupPresentation( thePresentation, aProps, theLCS ); + this->SetupPresentation( thePresentation, aProps, theShapeLCS ); } diff --git a/src/GEOMGUI/GEOMGUI_AnnotationAttrs.h b/src/GEOMGUI/GEOMGUI_AnnotationAttrs.h index 313fe623c..283af5064 100755 --- a/src/GEOMGUI/GEOMGUI_AnnotationAttrs.h +++ b/src/GEOMGUI/GEOMGUI_AnnotationAttrs.h @@ -32,6 +32,7 @@ #include // OCCT includes +#include #include #include @@ -80,18 +81,18 @@ public: //! Setup parameters of the annotation presentation with the properties given. //! @param thePresentation [in] the presentation to setup. //! @param theProps [in] the set of properties. - //! @param theLCS [in] the local coordinate system of the shape. + //! @param theShapeLCS [in] the local coordinate system of the shape. GEOMGUI_EXPORT static void SetupPresentation( const Handle(GEOM_Annotation)& thePresentation, const Properties& theProps, - const gp_Ax3& theLCS ); + const gp_Ax3& theShapeLCS ); //! Setup parameters of the annotation presentation with the properties of a definition. //! @param thePresentation [in] the presentation to setup. //! @param theIndex [in] the index of the annotation definition. - //! @param theLCS [in] the local coordinate system of the shape. + //! @param theShapeLCS [in] the local coordinate system of the shape. GEOMGUI_EXPORT void SetupPresentation( const Handle(GEOM_Annotation)& thePresentation, const int theIndex, - const gp_Ax3& theLCS ); + const gp_Ax3& theShapeLCS ); public: @@ -168,11 +169,26 @@ public: //! Appends new annotation definition with the given properties. GEOMGUI_EXPORT void Append( const Properties& theProps ); + //! Appends new annotation definition with the given properties and converts + //! position and attachment points to the given shape's local frame of reference. + //! @param theShapeLCS [in] the position of shape's local frame of reference with respect + //! to the world frame of reference. + GEOMGUI_EXPORT void Append( const Properties& theProps, const gp_Ax3& theShapeLCS ); + //! Sets complete properties of an annotation definition. //! @param theIndex [in] the index of the annotation definition. //! @param theProps [in] the structure containing the properties. GEOMGUI_EXPORT void SetProperties( const int theIndex, const Properties& theProps ); + //! Sets complete properties of an annotation definition with converting + //! position and attachment points to the given shape's local frame + //! of reference. + //! @param theIndex [in] the index of the annotation definition. + //! @param theProps [in] the structure containing the properties. + //! @param theShapeLCS [in] the position of shape's local frame of reference with respect + //! to the world frame of reference. + GEOMGUI_EXPORT void SetProperties( const int theIndex, const Properties& theProps, const gp_Ax3& theShapeLCS ); + //! Returns complete properties of an annotation definition. //! @param theIndex [in] the index of the annotation definition. //! @param theProps [out] the structure containing the properties. diff --git a/src/GEOMGUI/GEOM_Displayer.cxx b/src/GEOMGUI/GEOM_Displayer.cxx index de6d1bf2d..0280abd94 100755 --- a/src/GEOMGUI/GEOM_Displayer.cxx +++ b/src/GEOMGUI/GEOM_Displayer.cxx @@ -1444,6 +1444,7 @@ void GEOM_Displayer::updateShapeAnnotations( const Handle(SALOME_InteractiveObje aPresentation->SetLineWidth( aLineWidth ); aPresentation->SetLineStyle( static_cast( aLineStyle ) ); aPresentation->SetAutoHide( isAutoHide ? Standard_True : Standard_False ); + aPresentation->SetDepthCulling( Standard_True ); aListOfIO.Append( aPresentation ); } diff --git a/src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx b/src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx old mode 100644 new mode 100755 index 4a7042971..4e25192a5 --- a/src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx +++ b/src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx @@ -31,7 +31,6 @@ #include #include #include -#include #include #include @@ -210,6 +209,9 @@ MeasureGUI_AnnotationDlg::MeasureGUI_AnnotationDlg( GeometryGUI* theGeometryGUI, myInteractor = new MeasureGUI_AnnotationInteractor( theGeometryGUI, parent ); myInteractor->Enable(); + connect( myInteractor, SIGNAL( SignalInteractionFinished( Handle_GEOM_Annotation ) ), + this, SLOT( onDragged( Handle_GEOM_Annotation ) ) ); + Init(); } @@ -438,12 +440,19 @@ void MeasureGUI_AnnotationDlg::SelectionIntoArgument() activateSelection(); if ( !aNullShape ) { - if ( !getPickedPoint( anAttachPoint ) ) - { - TopoDS_Shape aShape; - GEOMBase::GetShape( myShape.get(), aShape ); + + TopoDS_Shape aShape; + GEOMBase::GetShape( myShape.get(), aShape ); + + if ( !getPickedPoint( anAttachPoint ) ) { + anAttachPoint = getAttachPoint( aShape ); } + + gp_Ax3 aShapeLCS = gp_Ax3().Transformed( aShape.Location().Transformation() ); + gp_Trsf aToShapeLCS; + aToShapeLCS.SetTransformation( gp_Ax3(), aShapeLCS ); + anAttachPoint.Transform( aToShapeLCS ); } } else if ( myEditCurrentArgument == mySubShapeName ) { if ( !myShape->_is_nil() ) { @@ -467,12 +476,20 @@ void MeasureGUI_AnnotationDlg::SelectionIntoArgument() aSubShapeIndex = aMainMap.FindIndex( aSubShape ); } - if ( !aSubShape.IsNull() ) - { - if ( !getPickedPoint( anAttachPoint ) ) - { + if ( !aSubShape.IsNull() ) { + + TopoDS_Shape aShape; + GEOMBase::GetShape( myShape.get(), aShape ); + + if ( !getPickedPoint( anAttachPoint ) ) { + anAttachPoint = getAttachPoint( aSubShape ); } + + gp_Ax3 aShapeLCS = gp_Ax3().Transformed( aShape.Location().Transformation() ); + gp_Trsf aToShapeLCS; + aToShapeLCS.SetTransformation( gp_Ax3(), aShapeLCS ); + anAttachPoint.Transform( aToShapeLCS ); } } } @@ -483,6 +500,18 @@ void MeasureGUI_AnnotationDlg::SelectionIntoArgument() redisplayPreview(); } +//======================================================================= +//function : closeEvent +//purpose : +//======================================================================= +void MeasureGUI_AnnotationDlg::closeEvent( QCloseEvent* theEv ) +{ + if ( myInteractor ) { + myInteractor->Disable(); + } + GEOMBase_Skeleton::closeEvent( theEv ); +} + //======================================================================= //function : onTextChange //purpose : change annotation text @@ -530,6 +559,42 @@ void MeasureGUI_AnnotationDlg::onSubShapeTypeChange() redisplayPreview(); } +//================================================================================= +// function : onDragged +// purpose : +//================================================================================= +void MeasureGUI_AnnotationDlg::onDragged( Handle_GEOM_Annotation theAnnotation ) +{ + const PrsList& aPreview = getPreview(); + PrsList::const_iterator anIt = aPreview.cbegin(); + for ( ; anIt != aPreview.cend(); ++anIt ) { + + AIS_ListOfInteractive aIObjects; + ((SOCC_Prs*)(*anIt))->GetObjects( aIObjects ); + AIS_ListOfInteractive::Iterator aIOIt( aIObjects ); + for ( ; aIOIt.More(); aIOIt.Next() ) { + + if ( aIOIt.Value() == theAnnotation ) { + + TopoDS_Shape aShape; + GEOMBase::GetShape( myShape.get(), aShape ); + gp_Ax3 aShapeLCS = gp_Ax3().Transformed( aShape.Location().Transformation() ); + gp_Trsf aToShapeLCS; + aToShapeLCS.SetTransformation( gp_Ax3(), aShapeLCS ); + + if ( !myAnnotationProperties.IsScreenFixed ) { + myAnnotationProperties.Position = theAnnotation->GetPosition().Transformed( aToShapeLCS ); + } + else { + myAnnotationProperties.Position = theAnnotation->GetPosition(); + } + + return; + } + } + } +} + #define RETURN_WITH_MSG( a, b ) \ if ( ( a ) ) { \ theMessage += ( b ); \ @@ -638,7 +703,8 @@ SALOME_Prs* MeasureGUI_AnnotationDlg::buildPrs() aPresentation->SetLineStyle( static_cast( aLineStyle ) ); aPresentation->SetAutoHide( isAutoHide ? Standard_True : Standard_False ); aPresentation->SetScreenFixed( myAnnotationProperties.IsScreenFixed ); - + aPresentation->SetDepthCulling( Standard_False ); + TopoDS_Shape aShape; GEOMBase::GetShape( myShape.get(), aShape ); gp_Ax3 aShapeLCS = gp_Ax3().Transformed( aShape.Location().Transformation() ); @@ -771,9 +837,9 @@ gp_Pnt MeasureGUI_AnnotationDlg::getAttachPoint( const TopoDS_Shape& theShape ) BRepBndLib::Add( aAttachShape, aBox ); const gp_Pnt aMin = aBox.CornerMin(); const gp_Pnt aMax = aBox.CornerMax(); - return gp_Pnt( aMin.X() + aMax.X() / 2.0, - aMin.Y() + aMax.Y() / 2.0, - aMin.Z() + aMax.Z() / 2.0 ); + return gp_Pnt( (aMin.X() + aMax.X()) / 2.0, + (aMin.Y() + aMax.Y()) / 2.0, + (aMin.Z() + aMax.Z()) / 2.0 ); } else if ( aAttachShape.ShapeType() == TopAbs_FACE ) { diff --git a/src/MeasureGUI/MeasureGUI_AnnotationDlg.h b/src/MeasureGUI/MeasureGUI_AnnotationDlg.h index df2a12283..9932520f1 100755 --- a/src/MeasureGUI/MeasureGUI_AnnotationDlg.h +++ b/src/MeasureGUI/MeasureGUI_AnnotationDlg.h @@ -28,6 +28,7 @@ #include +#include #include #include @@ -73,6 +74,8 @@ protected: void updateSubShapeEnableState(); void redisplayPreview(); + void closeEvent( QCloseEvent* theEv ); + private slots: void ClickOnOk(); bool ClickOnApply(); @@ -83,6 +86,8 @@ private slots: void onTypeChange(); void onSubShapeTypeChange(); + void onDragged( Handle_GEOM_Annotation theAnnotation ); + private: void Init(); diff --git a/src/MeasureGUI/MeasureGUI_AnnotationInteractor.cxx b/src/MeasureGUI/MeasureGUI_AnnotationInteractor.cxx old mode 100644 new mode 100755 index 504743406..6d1b635bc --- a/src/MeasureGUI/MeasureGUI_AnnotationInteractor.cxx +++ b/src/MeasureGUI/MeasureGUI_AnnotationInteractor.cxx @@ -137,7 +137,11 @@ void MeasureGUI_AnnotationInteractor::Disable() myActiveViewPort = NULL; } - myActiveIO.Nullify(); + if ( !myActiveIO.IsNull() ) + { + emit SignalInteractionFinished( myActiveIO ); + myActiveIO.Nullify(); + } } //================================================================================= @@ -245,6 +249,8 @@ bool MeasureGUI_AnnotationInteractor::eventFilter( QObject* theObject, QEvent* t myActiveIO = aAnnotation; myActiveIO->BeginDrag(); + emit SignalInteractionStarted( myActiveIO ); + return true; } @@ -304,6 +310,8 @@ bool MeasureGUI_AnnotationInteractor::eventFilter( QObject* theObject, QEvent* t anAISContext->UpdateCurrentViewer(); anAISContext->MoveTo( aMouseEv->pos().x(), aMouseEv->pos().y(), aView3d ); + emit SignalInteractionFinished( myActiveIO ); + mySelection.Clear(); myActiveIO.Nullify(); return (theEvent->type() == QEvent::MouseButtonRelease); diff --git a/src/MeasureGUI/MeasureGUI_AnnotationInteractor.h b/src/MeasureGUI/MeasureGUI_AnnotationInteractor.h old mode 100644 new mode 100755 index ed9bc0b5c..bf0061945 --- a/src/MeasureGUI/MeasureGUI_AnnotationInteractor.h +++ b/src/MeasureGUI/MeasureGUI_AnnotationInteractor.h @@ -78,6 +78,14 @@ protected: //! Disconnect interactor's event handler from the view window given. void DisconnectView( SUIT_ViewWindow* theWindow ); +signals: + + //! Emitted when interactor begins modification of the interactive object. + void SignalInteractionStarted( Handle_GEOM_Annotation theIO ); + + //! Emitted when interactor finished modification of the interactive object. + void SignalInteractionFinished( Handle_GEOM_Annotation theIO ); + protected slots: //! Handler for signal coming from GUI layer. diff --git a/src/OBJECT/GEOM_Annotation.cxx b/src/OBJECT/GEOM_Annotation.cxx index cb4d14fc3..4f79e508e 100755 --- a/src/OBJECT/GEOM_Annotation.cxx +++ b/src/OBJECT/GEOM_Annotation.cxx @@ -67,6 +67,7 @@ GEOM_Annotation::GEOM_Annotation() : AIS_InteractiveObject() SetAutoHide( Standard_True ); SetHilightMode( HighlightAll ); SetMutable( Standard_True ); + SetDepthCulling( Standard_True ); Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect(); aTextAspect->SetHeight( 20.0 ); @@ -77,6 +78,10 @@ GEOM_Annotation::GEOM_Annotation() : AIS_InteractiveObject() new Prs3d_LineAspect( Quantity_NOC_WHITE, Aspect_TOL_SOLID, 1.0 ); myDrawer->SetLineAspect( aLineAspect ); + Handle(Prs3d_LineAspect) aHiddenLineAspect = + new Prs3d_LineAspect( Quantity_NOC_WHITE, Aspect_TOL_DOT, 1.0 ); + myDrawer->SetHiddenLineAspect( aHiddenLineAspect ); + Handle(Prs3d_PointAspect) aPointAspect = new Prs3d_PointAspect( Aspect_TOM_POINT, Quantity_NOC_WHITE, 4.0 ); myDrawer->SetPointAspect( aPointAspect ); @@ -188,76 +193,106 @@ void GEOM_Annotation::SetTextColor( const Quantity_Color& theColor ) void GEOM_Annotation::SetLineColor( const Quantity_Color& theColor ) { myDrawer->LineAspect()->SetColor( theColor ); + myDrawer->HiddenLineAspect()->SetColor( theColor ); myDrawer->PointAspect()->SetColor( theColor ); SetToUpdate(); } // ======================================================================= -// function : SetTextHeight +// function : SetLineWidth // purpose : // ======================================================================= -void GEOM_Annotation::SetTextHeight( const Standard_Real theHeight ) +void GEOM_Annotation::SetLineWidth( const Standard_Real theLineWidth ) { - if (GetTextHeight() != theHeight) + if ( GetLineWidth() != theLineWidth ) { - myDrawer->TextAspect()->SetHeight( theHeight ); + myDrawer->LineAspect()->SetWidth( theLineWidth ); + myDrawer->HiddenLineAspect()->SetWidth( theLineWidth ); - SetToUpdate (); + SetToUpdate(); } } // ======================================================================= -// function : SetFontAspect +// function : SetLineStyle // purpose : // ======================================================================= -void GEOM_Annotation::SetFontAspect( const Font_FontAspect theFontAspect ) +void GEOM_Annotation::SetLineStyle( const Aspect_TypeOfLine theStyle ) { - if (GetFontAspect() != theFontAspect) + if ( GetLineStyle() != theStyle ) { - myDrawer->TextAspect()->Aspect()->SetTextFontAspect( theFontAspect ); + myDrawer->LineAspect()->SetTypeOfLine( theStyle ); SetToUpdate(); } } // ======================================================================= -// function : SetFont +// function : SetHiddenLineStyle // purpose : // ======================================================================= -void GEOM_Annotation::SetFont( const TCollection_AsciiString& theFont ) +void GEOM_Annotation::SetHiddenLineStyle( const Aspect_TypeOfLine theStyle ) { - if (GetFont() != theFont) + if ( GetHiddenLineStyle() != theStyle ) { - myDrawer->TextAspect()->Aspect()->SetFont( theFont ); + myDrawer->HiddenLineAspect()->SetTypeOfLine( theStyle ); SetToUpdate(); } } // ======================================================================= -// function : SetLineWidth +// function : SetTextHeight // purpose : // ======================================================================= -void GEOM_Annotation::SetLineWidth( const Standard_Real theLineWidth ) +void GEOM_Annotation::SetTextHeight( const Standard_Real theHeight ) { - if (GetLineWidth() != theLineWidth) + if ( GetTextHeight() != theHeight ) { - myDrawer->LineAspect()->SetWidth( theLineWidth ); + myDrawer->TextAspect()->SetHeight( theHeight ); SetToUpdate(); } } // ======================================================================= -// function : SetLineStyle +// function : SetFontAspect // purpose : // ======================================================================= -void GEOM_Annotation::SetLineStyle( const Aspect_TypeOfLine theStyle ) +void GEOM_Annotation::SetFontAspect( const Font_FontAspect theFontAspect ) { - if (GetLineStyle() != theStyle) + if ( GetFontAspect() != theFontAspect ) { - myDrawer->LineAspect()->SetTypeOfLine( theStyle ); + myDrawer->TextAspect()->Aspect()->SetTextFontAspect( theFontAspect ); + + SetToUpdate(); + } +} + +// ======================================================================= +// function : SetFont +// purpose : +// ======================================================================= +void GEOM_Annotation::SetFont( const TCollection_AsciiString& theFont ) +{ + if ( GetFont() != theFont ) + { + myDrawer->TextAspect()->Aspect()->SetFont( theFont ); + + SetToUpdate(); + } +} + +// ======================================================================= +// function : SetDepthCulling +// purpose : +// ======================================================================= +void GEOM_Annotation::SetDepthCulling( const Standard_Boolean theToEnable ) +{ + if ( GetDepthCulling() != theToEnable ) + { + myIsDepthCulling = theToEnable; SetToUpdate(); } @@ -289,10 +324,23 @@ void GEOM_Annotation::Compute( const Handle(PrsMgr_PresentationManager3d)& /*the OpenGl_Annotation* aAnnotationDraw = new OpenGl_Annotation( this, static_cast( anAsp->Height() ), aGroup->GlStruct()->GlDriver() ); - aGroup->AddElement( aAnnotationDraw ); + aAnnotationDraw->SetDepthMode( 0 ); aGroup->SetGroupPrimitivesAspect( myDrawer->TextAspect()->Aspect() ); aGroup->SetGroupPrimitivesAspect( myDrawer->LineAspect()->Aspect() ); aGroup->SetGroupPrimitivesAspect( myDrawer->PointAspect()->Aspect() ); + aGroup->AddElement( aAnnotationDraw ); + + if ( !myIsDepthCulling ) + { + OpenGl_Annotation* aAnnotationDraw = + new OpenGl_Annotation( this, static_cast( anAsp->Height() ), aGroup->GlStruct()->GlDriver() ); + + aAnnotationDraw->SetDepthMode( GL_GREATER ); + aGroup->SetPrimitivesAspect( myDrawer->TextAspect()->Aspect() ); + aGroup->SetPrimitivesAspect( myDrawer->HiddenLineAspect()->Aspect() ); + aGroup->SetPrimitivesAspect( myDrawer->PointAspect()->Aspect() ); + aGroup->AddElement( aAnnotationDraw ); + } Bnd_Box aBox = TextBoundingBox(); if ( myIsScreenFixed ) @@ -427,6 +475,7 @@ GEOM_Annotation::OpenGl_Annotation::OpenGl_Annotation( GEOM_Annotation* theAnnot const Standard_Integer theTextHeight, const OpenGl_GraphicDriver* theDriver ) : OpenGl_Element(), + myDepthMode( 0 ), myAISObject( theAnnotation ), myText( theAnnotation->myText.ToExtString() ), myTextLineY( 0.f ), @@ -566,6 +615,14 @@ void GEOM_Annotation::OpenGl_Annotation::Render( const Handle(OpenGl_Workspace)& theWorkspace->ApplyAspectLine(); } + GLint myOldDepthMode = 0; + + if ( myDepthMode ) + { + aContext->core11fwd->glGetIntegerv( GL_DEPTH_FUNC, &myOldDepthMode ); + aContext->core11fwd->glDepthFunc( myDepthMode ); + } + // ------------------------------------------------------------- // render text label in current persistence matrix and underline // ------------------------------------------------------------- @@ -658,14 +715,19 @@ void GEOM_Annotation::OpenGl_Annotation::Render( const Handle(OpenGl_Workspace)& aContext->ModelWorldState.Pop(); aContext->WorldViewState.Pop(); - if (myAISObject->myIsScreenFixed) + if ( myOldDepthMode ) + { + aContext->core11fwd->glDepthFunc( myOldDepthMode ); + } + + if ( myAISObject->myIsScreenFixed ) { aContext->WorldViewState.Pop(); } aContext->ApplyModelViewMatrix(); - if (toHighlight != theWorkspace->ToHighlight()) + if ( toHighlight != theWorkspace->ToHighlight() ) { theWorkspace->SetHighlight( toHighlight ); } diff --git a/src/OBJECT/GEOM_Annotation.hxx b/src/OBJECT/GEOM_Annotation.hxx index 98a9cc914..c98b2fda6 100755 --- a/src/OBJECT/GEOM_Annotation.hxx +++ b/src/OBJECT/GEOM_Annotation.hxx @@ -126,6 +126,24 @@ public: //! Returns color for the connection line. Quantity_Color GetLineColor() const { return myDrawer->LineAspect()->Aspect()->Color(); } + //! Sets line width to be used for drawing the annotation's extension line and underline. + Standard_EXPORT void SetLineWidth( const Standard_Real theLineWidth ); + + //! Returns line width for drawing the annotation's extension line and underline. + Standard_Real GetLineWidth() const { return myDrawer->LineAspect()->Aspect()->Width(); } + + //! Sets style of connection line. + Standard_EXPORT void SetLineStyle( const Aspect_TypeOfLine theStyle ); + + //! Retusn style of connection line. + Aspect_TypeOfLine GetLineStyle() const { return myDrawer->LineAspect()->Aspect()->Type(); } + + //! Sets style of hidden connection line. + Standard_EXPORT void SetHiddenLineStyle( const Aspect_TypeOfLine theStyle ); + + //! Retusn style of hidden connection line. + Aspect_TypeOfLine GetHiddenLineStyle() const { return myDrawer->HiddenLineAspect()->Aspect()->Type(); } + //! Sets text height in pixels. Standard_EXPORT void SetTextHeight( const Standard_Real theHeight ); @@ -144,18 +162,6 @@ public: //! Returns font used for drawing the label. TCollection_AsciiString GetFont() const { return myDrawer->TextAspect()->Aspect()->Font(); } - //! Sets line width to be used for drawing the annotation's extension line and underline. - Standard_EXPORT void SetLineWidth( const Standard_Real theLineWidth ); - - //! Returns line width for drawing the annotation's extension line and underline. - Standard_Real GetLineWidth() const { return myDrawer->LineAspect()->Aspect()->Width(); } - - //! Sets style of connection line. - Standard_EXPORT void SetLineStyle( const Aspect_TypeOfLine theStyle ); - - //! Retusn style of connection line. - Aspect_TypeOfLine GetLineStyle() const { return myDrawer->LineAspect()->Aspect()->Type(); } - //! Sets annotation auto-hiding option. //! \param theIsEnable [in] the option flag. If passed true, the annotation //! will be automatically hidden in the view if the attachment point @@ -172,6 +178,16 @@ public: //! Returns highlight mode HighlightMode GetHilightMode() const { return myHilightMode; } + //! Sets special flag that allows disabling depth testing when rendering + //! the graphical presentation. When disable the hidden parts such as + //! lines and text become visible and a rendered with another drawing + //! aspect. This mode should be explicitly used with setting top layer + //! for the presentation. Otherwise the behavior is undefined. + Standard_EXPORT void SetDepthCulling (const Standard_Boolean theToEnable); + + //! Returns depth culling state. + Standard_Boolean GetDepthCulling() const { return myIsDepthCulling; } + // Interactive dragging: public: @@ -216,6 +232,7 @@ private: gp_Pnt myStartPosition; //!< Position before starting dragging operation. Standard_Boolean myIsScreenFixed; //!< Flag indicating whether "screen fixed" positioning mode is turned on or off. Standard_Boolean myIsAutoHide; //!< Flag indicating whether "auto-hiding" option is turned on. + Standard_Boolean myIsDepthCulling; //!< Flag indiciating whether the "depth culling" is turned on. HighlightMode myHilightMode; //!< Highlight mode for presentation. TCollection_ExtendedString myText; //!< Text string of the label presentation. @@ -245,6 +262,8 @@ private: //! Renders the annotation graphical elements. virtual void Render( const Handle(OpenGl_Workspace)& theWorkspace ) const Standard_OVERRIDE; + void SetDepthMode( const int theMode ) { myDepthMode = theMode; } + private: struct TextSize { @@ -261,6 +280,7 @@ private: OpenGl_PrimitiveArray* myTextLineDraw; //!< Text underline draw element. OpenGl_PrimitiveArray* myExtLineDraw; //!< Extension line draw element. OpenGl_PrimitiveArray* myExtMarkerDraw; //!< Extension marker draw element. + int myDepthMode; //!< Depth mode for drawing hidden line presentation. mutable float myTextLineY; //!< Text's underlines relative position. mutable TextSize myTextSize; //!< Text's size parameters mutable Graphic3d_Vec2 myTextUnderline; //!< Text's underline position. -- 2.39.2