From 823ae678db106bf2b4db03deadfaa34a34e8c16d Mon Sep 17 00:00:00 2001 From: ouv Date: Wed, 27 May 2009 07:21:08 +0000 Subject: [PATCH] Issue 0019818: EDF 703 SMESH VISU : Display Mesh Groups names in viewer (as a caption) --- src/LightApp/LightApp_Application.cxx | 13 + src/LightApp/resources/LightApp.xml | 3 + src/LightApp/resources/LightApp_msg_en.ts | 12 + src/SVTK/SALOME_Actor.cxx | 122 ++++- src/SVTK/SALOME_Actor.h | 36 ++ src/SVTK/SVTK_Renderer.cxx | 1 + src/SVTK/SVTK_ViewModel.cxx | 7 + src/SalomeApp/resources/SalomeApp.xml | 3 + src/VTKViewer/Makefile.am | 2 + src/VTKViewer/VTKViewer_FramedTextActor.cxx | 497 ++++++++++++++++++++ src/VTKViewer/VTKViewer_FramedTextActor.h | 129 +++++ 11 files changed, 824 insertions(+), 1 deletion(-) create mode 100644 src/VTKViewer/VTKViewer_FramedTextActor.cxx create mode 100644 src/VTKViewer/VTKViewer_FramedTextActor.h diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 5fd964157..5f5a86d73 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -1958,6 +1958,19 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) pref->addPreference( tr( "PREF_PROGRESSIVE" ), vtkRec, LightApp_Preferences::Bool, "VTKViewer", "recorder_progressive" ); + int vtkGN = pref->addPreference( tr( "PREF_FRAME_GROUP_NAMES" ), vtkGroup, + LightApp_Preferences::GroupBox, "VTKViewer", "show_group_names" ); + pref->setItemProperty( "columns", 2, vtkGN ); + + pref->addPreference( tr( "PREF_GROUP_NAMES_TEXT_COLOR" ), vtkGN, + LightApp_Preferences::Color, "VTKViewer", "group_names_text_color" ); + int transPref = pref->addPreference( tr( "PREF_GROUP_NAMES_TRANSPARENCY" ), vtkGN, + LightApp_Preferences::DblSpin, "VTKViewer", "group_names_transparency" ); + + pref->setItemProperty( "min", 0.0, transPref ); + pref->setItemProperty( "max", 1.0, transPref ); + pref->setItemProperty( "step", 0.1, transPref ); + // Plot2d pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup, LightApp_Preferences::Bool, "Plot2d", "ShowLegend" ); diff --git a/src/LightApp/resources/LightApp.xml b/src/LightApp/resources/LightApp.xml index 4178c9c07..0b7cc506b 100644 --- a/src/LightApp/resources/LightApp.xml +++ b/src/LightApp/resources/LightApp.xml @@ -130,6 +130,9 @@ + + +
diff --git a/src/LightApp/resources/LightApp_msg_en.ts b/src/LightApp/resources/LightApp_msg_en.ts index b91990d14..160c1410f 100644 --- a/src/LightApp/resources/LightApp_msg_en.ts +++ b/src/LightApp/resources/LightApp_msg_en.ts @@ -250,6 +250,18 @@ CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITASPREF_SKIPPED_FRAMES Recording at a given FPS + + PREF_FRAME_GROUP_NAMES + Names of groups + + + PREF_GROUP_NAMES_TEXT_COLOR + Text color + + + PREF_GROUP_NAMES_TRANSPARENCY + Transparency + PREF_BOTTOM Bottom diff --git a/src/SVTK/SALOME_Actor.cxx b/src/SVTK/SALOME_Actor.cxx index e4313ba14..cb64c5e63 100644 --- a/src/SVTK/SALOME_Actor.cxx +++ b/src/SVTK/SALOME_Actor.cxx @@ -36,10 +36,14 @@ #include "VTKViewer_Transform.h" #include "VTKViewer_TransformFilter.h" #include "VTKViewer_GeometryFilter.h" +#include "VTKViewer_FramedTextActor.h" #include "SVTK_RectPicker.h" #include "SVTK_Actor.h" +#include +#include + // VTK Includes #include #include @@ -156,7 +160,9 @@ SALOME_Actor myPreHighlightActor(SVTK_Actor::New()), myHighlightActor(SVTK_Actor::New()), myOutline(vtkOutlineSource::New()), - myOutlineActor(VTKViewer_Actor::New()) + myOutlineActor(VTKViewer_Actor::New()), + myIsDisplayNameActor(false), + myNameActor(VTKViewer_FramedTextActor::New()) { myPreHighlightActor->Delete(); myPreHighlightActor->Initialize(); @@ -183,6 +189,24 @@ SALOME_Actor myOutlineActor->GetProperty()->SetAmbient(1.0); myOutlineActor->GetProperty()->SetDiffuse(0.0); myOutlineActor->SetVisibility( false ); + + // Name actor + myNameActor->Delete(); + myNameActor->SetVisibility(false); + myNameActor->SetPickable(false); + myNameActor->SetModePosition(VTKViewer_FramedTextActor::TopRight); + myNameActor->SetLayoutType(VTKViewer_FramedTextActor::Vertical); + + SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr(); + + QColor aForegroundColor = aResourceMgr->colorValue( "VTKViewer", "group_names_text_color", Qt::white ); + myNameActor->SetForegroundColor(aForegroundColor.redF(), + aForegroundColor.greenF(), + aForegroundColor.blueF()); + + vtkFloatingPointType aGroupNamesTransparency = 0.5; + aGroupNamesTransparency = aResourceMgr->doubleValue( "VTKViewer", "group_names_transparency", aGroupNamesTransparency ); + myNameActor->SetTransparency(aGroupNamesTransparency); } /*! @@ -234,6 +258,7 @@ SALOME_Actor { if(hasIO()) myIO->setName(theName); + myNameActor->SetText(theName); Superclass::setName(theName); } @@ -252,6 +277,7 @@ SALOME_Actor theRenderer->AddActor( myPreHighlightActor.GetPointer() ); theRenderer->AddActor( myHighlightActor.GetPointer() ); theRenderer->AddActor( myOutlineActor.GetPointer() ); + theRenderer->AddActor( myNameActor.GetPointer() ); } /*! @@ -266,6 +292,7 @@ SALOME_Actor theRenderer->RemoveActor( myPreHighlightActor.GetPointer() ); theRenderer->RemoveActor( myHighlightActor.GetPointer() ); theRenderer->RemoveActor( myOutlineActor.GetPointer() ); + theRenderer->RemoveActor( myNameActor.GetPointer() ); } /*! @@ -360,6 +387,8 @@ SALOME_Actor myHighlightActor->SetVisibility( theVisibility && isHighlighted() && aHasIndex); } } + + UpdateNameActors(); } /*! @@ -789,6 +818,97 @@ SALOME_Actor return true; } +/*! + To get flag of displaying of name actor + \return flag to display or not to display name actor +*/ +bool +SALOME_Actor +::IsDisplayNameActor() const +{ + return myIsDisplayNameActor; +} + +/*! + To set flag of displaying of name actor + \param theIsDisplayNameActor flag to display or not to display name actor +*/ +void +SALOME_Actor +::SetIsDisplayNameActor(bool theIsDisplayNameActor) +{ + SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr(); + bool isShowGroupNames = aResourceMgr->booleanValue("VTKViewer", "show_group_names", false); + myIsDisplayNameActor = theIsDisplayNameActor && isShowGroupNames; + UpdateNameActors(); +} + +/*! + To set text of name actor + \param theText - text of name actor +*/ +void +SALOME_Actor +::SetNameActorText(const char* theText) +{ + myNameActor->SetText(theText); +} + +/*! + To set offset of name actor + \param theOffset - offset of name actor +*/ +void +SALOME_Actor +::SetNameActorOffset(int theOffset[2]) +{ + myNameActor->SetOffset(theOffset); +} + +/*! + To get size of name actor + \param theRenderer - renderer + \param theSize - size of name actor +*/ +void +SALOME_Actor +::GetNameActorSize(vtkRenderer* theRenderer, int theSize[2]) const +{ + myNameActor->GetSize(theRenderer, theSize); +} + +/*! + Update visibility of name actors +*/ +void +SALOME_Actor +::UpdateNameActors() +{ + if( vtkRenderer* aRenderer = GetRenderer() ) + { + int anOffset[2] = { 0, 0 }; + vtkActorCollection* aCollection = aRenderer->GetActors(); + for( int anIndex = 0, aNbItems = aCollection->GetNumberOfItems(); anIndex < aNbItems; anIndex++ ) + { + if( SALOME_Actor* anActor = dynamic_cast( aCollection->GetItemAsObject( anIndex ) ) ) + { + if( anActor->IsDisplayNameActor() ) + { + anActor->SetNameActorOffset( anOffset ); + if( anActor->GetVisibility() ) + { + int aSize[2]; + anActor->GetNameActorSize( aRenderer, aSize ); + anOffset[0] = anOffset[0] + aSize[0]; + anOffset[1] = anOffset[1] + aSize[1]; + } + } + } + } + } + myNameActor->SetVisibility( GetVisibility() && IsDisplayNameActor() ); +} + /*! To set up a picker for nodal selection (initialized by SVTK_Renderer::AddActor) \param thePointPicker - new picker diff --git a/src/SVTK/SALOME_Actor.h b/src/SVTK/SALOME_Actor.h index f859c499c..1f458732d 100644 --- a/src/SVTK/SALOME_Actor.h +++ b/src/SVTK/SALOME_Actor.h @@ -49,6 +49,8 @@ class vtkOutlineSource; class vtkInteractorStyle; class vtkRenderWindowInteractor; +class VTKViewer_FramedTextActor; + class SVTK_Actor; class SVTK_RectPicker; class SVTK_InteractorStyle; @@ -180,6 +182,37 @@ class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor SVTK_SelectionEvent* theSelectionEvent, bool theIsHighlight); + //---------------------------------------------------------------------------- + //! To get flag of displaying of name actor + virtual + bool + IsDisplayNameActor() const; + + //! To set flag of displaying of name actor + virtual + void + SetIsDisplayNameActor(bool theIsDisplayNameActor); + + //! To set text of name actor + virtual + void + SetNameActorText(const char* theText); + + //! To set offset of name actor + virtual + void + SetNameActorOffset(int theOffset[2]); + + //! To get size of name actor + virtual + void + GetNameActorSize(vtkRenderer* theRenderer, int theSize[2]) const; + + //! To update visibility of name actors + virtual + void + UpdateNameActors(); + //---------------------------------------------------------------------------- //! To set up a picker for nodal selection (initialized by #SVTK_Renderer::AddActor) void @@ -233,6 +266,9 @@ class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor vtkSmartPointer myOutlineActor; vtkSmartPointer myOutline; + + bool myIsDisplayNameActor; + vtkSmartPointer myNameActor; }; #ifdef WIN32 diff --git a/src/SVTK/SVTK_Renderer.cxx b/src/SVTK/SVTK_Renderer.cxx index 369520b1e..b29a61b21 100644 --- a/src/SVTK/SVTK_Renderer.cxx +++ b/src/SVTK/SVTK_Renderer.cxx @@ -247,6 +247,7 @@ SVTK_Renderer anActor->SetHighlightProperty(myHighlightProperty.GetPointer()); anActor->AddToRender(GetDevice()); + anActor->UpdateNameActors(); AdjustActors(); } } diff --git a/src/SVTK/SVTK_ViewModel.cxx b/src/SVTK/SVTK_ViewModel.cxx index 2c1e3c57a..a8151edcd 100644 --- a/src/SVTK/SVTK_ViewModel.cxx +++ b/src/SVTK/SVTK_ViewModel.cxx @@ -506,9 +506,16 @@ void SVTK_Viewer::EraseAll( const bool forced ) if(SVTK_View* aView = aViewWindow->getView()){ vtkRenderer* aRenderer = aView->getRenderer(); vtkActorCollection* anActorCollection = aRenderer->GetActors(); + // another way is used to cycle over the actor collection to avoid problems + // with the similar cycle inside SALOME_Actor::UpdateNameActors() called from + // SALOME_Actor::SetVisibility(...), which is called below + /* anActorCollection->InitTraversal(); while(vtkActor* anActor = anActorCollection->GetNextActor()){ if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){ + */ + for(int anIndex = 0, aNbItems = anActorCollection->GetNumberOfItems(); anIndex < aNbItems; anIndex++){ + if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActorCollection->GetItemAsObject(anIndex))){ // Set visibility flag // Temporarily commented to avoid awful dependecy on SALOMEDS // TODO: better mechanism of storing display/erse status in a study diff --git a/src/SalomeApp/resources/SalomeApp.xml b/src/SalomeApp/resources/SalomeApp.xml index b95d46a34..d4638708a 100644 --- a/src/SalomeApp/resources/SalomeApp.xml +++ b/src/SalomeApp/resources/SalomeApp.xml @@ -136,6 +136,9 @@ + + +
diff --git a/src/VTKViewer/Makefile.am b/src/VTKViewer/Makefile.am index 65a01c533..cb3e1078d 100755 --- a/src/VTKViewer/Makefile.am +++ b/src/VTKViewer/Makefile.am @@ -31,6 +31,7 @@ salomeinclude_HEADERS = \ VTKViewer.h \ VTKViewer_CellLocationsArray.h \ VTKViewer_Actor.h \ + VTKViewer_FramedTextActor.h \ VTKViewer_ExtractUnstructuredGrid.h \ VTKViewer_ConvexTool.h \ VTKViewer_Filter.h \ @@ -53,6 +54,7 @@ salomeinclude_HEADERS = \ dist_libVTKViewer_la_SOURCES = \ VTKViewer_CellLocationsArray.cxx \ VTKViewer_Actor.cxx \ + VTKViewer_FramedTextActor.cxx \ VTKViewer_ExtractUnstructuredGrid.cxx \ VTKViewer_Filter.cxx \ VTKViewer_GeometryFilter.cxx \ diff --git a/src/VTKViewer/VTKViewer_FramedTextActor.cxx b/src/VTKViewer/VTKViewer_FramedTextActor.cxx new file mode 100644 index 000000000..b0ab39849 --- /dev/null +++ b/src/VTKViewer/VTKViewer_FramedTextActor.cxx @@ -0,0 +1,497 @@ +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "VTKViewer_FramedTextActor.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define TEXT_MARGIN 4 +#define OFFSET_SPACING 2 + +//================================================================== +vtkCxxRevisionMacro(VTKViewer_FramedTextActor, "$Revision$"); +vtkStandardNewMacro(VTKViewer_FramedTextActor); + +//================================================================== +// function : VTKViewer_FramedTextActor +// purpose : +//================================================================== +VTKViewer_FramedTextActor::VTKViewer_FramedTextActor() +{ + PositionCoordinate->SetCoordinateSystemToNormalizedViewport(); + + myTransparency=0.; + myBar = vtkPolyData::New(); + myBarMapper = vtkPolyDataMapper2D::New(); + myBarMapper->SetInput(myBar); + myBarActor = vtkActor2D::New(); + myBarActor->SetMapper(myBarMapper); + myBarActor->GetProperty()->SetOpacity(1.-myTransparency); + myBarActor->GetProperty()->SetColor(.5, .5, .5); + + myTextProperty = vtkTextProperty::New(); + myTextProperty->SetFontSize(12); + myTextProperty->SetBold(0); + myTextProperty->SetItalic(0); + myTextProperty->SetShadow(1); + myTextProperty->SetFontFamilyToArial(); + + myTextMapper=vtkTextMapper::New(); + myTextMapper->SetInput(""); + myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty); + myTextActor=vtkActor2D::New(); + myTextActor->SetMapper(myTextMapper); + + myBarActor->SetVisibility(1); + myTextActor->SetVisibility(1); + myBarActor->SetPickable(0); + myTextActor->SetPickable(0); + + myModePosition = BelowPoint; + myLayoutType = Vertical; + + for(int i=0; i<4; i++) { + myWorldPoint[i] = 0.; + } + myDistance=10.; + + myTextMargin = TEXT_MARGIN; + + myHorizontalOffset = 0; + myVerticalOffset = 0; +} + +//================================================================== +// function : ~ +// purpose : +//================================================================== +VTKViewer_FramedTextActor::~VTKViewer_FramedTextActor() +{ + myTextActor->Delete(); + myTextMapper->Delete(); + myTextProperty->Delete(); + myBarActor->Delete(); + myBarMapper->Delete(); + myBar->Delete(); +} + +//================================================================== +// function : SetVisibility +// purpose : +//================================================================== +void VTKViewer_FramedTextActor::SetVisibility (int theVisibility) +{ + myBarActor->SetVisibility(theVisibility); + myTextActor->SetVisibility(theVisibility); +} + +//================================================================== +// function : GetVisibility +// purpose : +//================================================================== +int VTKViewer_FramedTextActor::GetVisibility() +{ + return myBarActor->GetVisibility(); +} + +//================================================================== +// function : SetPickable +// purpose : +//================================================================== +void VTKViewer_FramedTextActor::SetPickable (int thePickability) +{ + myBarActor->SetPickable(thePickability); + myTextActor->SetPickable(thePickability); +} + +//================================================================== +// function : GetPickable +// purpose : +//================================================================== +int VTKViewer_FramedTextActor::GetPickable() +{ + return myBarActor->GetPickable(); +} + +//================================================================== +// function : GetSize +// purpose : +//================================================================== +void VTKViewer_FramedTextActor::GetSize(vtkRenderer* theRenderer, int theSize[2]) const +{ + myTextMapper->GetSize(theRenderer, theSize); + theSize[0] = theSize[0] + 2 * GetTextMargin() + OFFSET_SPACING; + theSize[1] = theSize[1] + 2 * GetTextMargin() + OFFSET_SPACING; +} + +//================================================================== +// function : SetForegroundColor +// purpose : +//================================================================== +void VTKViewer_FramedTextActor::SetForegroundColor(const vtkFloatingPointType r, + const vtkFloatingPointType g, + const vtkFloatingPointType b) +{ + myTextProperty->SetColor(r, g, b); + myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty); + Modified(); +} + +//================================================================== +// function : GetForegroundColor +// purpose : +//================================================================== +void VTKViewer_FramedTextActor::GetForegroundColor(vtkFloatingPointType& r, + vtkFloatingPointType& g, + vtkFloatingPointType& b) +{ + vtkFloatingPointType aColor[3]; + myTextProperty->GetColor(aColor); + r = aColor[0]; + g = aColor[1]; + b = aColor[2]; +} + +//================================================================== +// function : SetBackgroundColor +// purpose : +//================================================================== +void VTKViewer_FramedTextActor::SetBackgroundColor(const vtkFloatingPointType r, + const vtkFloatingPointType g, + const vtkFloatingPointType b) +{ + myBarActor->GetProperty()->SetColor(r, g, b); + Modified(); +} + +//================================================================== +// function : GetBackgroundColor +// purpose : +//================================================================== +void VTKViewer_FramedTextActor::GetBackgroundColor(vtkFloatingPointType& r, + vtkFloatingPointType& g, + vtkFloatingPointType& b) +{ + vtkFloatingPointType aColor[3]; + myBarActor->GetProperty()->GetColor(aColor); + r = aColor[0]; + g = aColor[1]; + b = aColor[2]; +} + +//================================================================== +// function : SetTransparency +// purpose : +//================================================================== +void VTKViewer_FramedTextActor::SetTransparency(const vtkFloatingPointType theTransparency) +{ + if (theTransparency>=0. && theTransparency<=1.){ + myTransparency=theTransparency; + myBarActor->GetProperty()->SetOpacity(1.-myTransparency); + Modified(); + } +} + +//================================================================== +// function : GetTransparency +// purpose : +//================================================================== +vtkFloatingPointType VTKViewer_FramedTextActor::GetTransparency()const +{ + return myTransparency; +} + +//================================================================== +// function : SetTextMargin +// purpose : +//================================================================== +void VTKViewer_FramedTextActor::SetTextMargin(const int theMargin) +{ + if( theMargin >= 0 ) { + myTextMargin = theMargin; + Modified(); + } +} + +//================================================================== +// function : GetTextMargin +// purpose : +//================================================================== +int VTKViewer_FramedTextActor::GetTextMargin() const +{ + return myTextMargin; +} + +//================================================================== +// function : SetOffset +// purpose : +//================================================================== +void VTKViewer_FramedTextActor::SetOffset(const int theOffset[2]) +{ + myHorizontalOffset = theOffset[0]; + myVerticalOffset = theOffset[1]; + Modified(); +} + +//================================================================== +// function : SetText +// purpose : +//================================================================== +void VTKViewer_FramedTextActor::SetText(const char* theText) +{ + // remove whitespaces from from the start and the end + QString aString(theText); + myTextMapper->SetInput(aString.trimmed().toLatin1().constData()); + Modified(); +} + +//================================================================== +// function : GetText +// purpose : +//================================================================== +char* VTKViewer_FramedTextActor::GetText() +{ + return myTextMapper->GetInput(); +} + +//================================================================== +// function : SetModePosition +// purpose : +//================================================================== +void VTKViewer_FramedTextActor::SetModePosition(const int theMode) +{ + myModePosition = theMode; + Modified(); +} + +//================================================================== +// function : GetModePosition +// purpose : +//================================================================== +int VTKViewer_FramedTextActor::GetModePosition()const +{ + return myModePosition; +} + +//================================================================== +// function : SetLayoutType +// purpose : +//================================================================== +void VTKViewer_FramedTextActor::SetLayoutType(const int theType) +{ + myLayoutType = theType; + Modified(); +} + +//================================================================== +// function : GetLayoutType +// purpose : +//================================================================== +int VTKViewer_FramedTextActor::GetLayoutType() const +{ + return myLayoutType; +} + +//================================================================== +// function : SetWorldPoint +// purpose : +//================================================================== +void VTKViewer_FramedTextActor::SetWorldPoint(const vtkFloatingPointType theWorldPoint[4]) +{ + for(int i = 0; i<4; ++i) { + myWorldPoint[i] = theWorldPoint[i]; + } + Modified(); +} + +//================================================================== +// function : GetWorldPoint +// purpose : +//================================================================== +const vtkFloatingPointType* VTKViewer_FramedTextActor::GetWorldPoint()const +{ + return myWorldPoint; +} + +//================================================================== +// function : SetDistance +// purpose : +//================================================================== +void VTKViewer_FramedTextActor::SetDistance(const vtkFloatingPointType theDistance) +{ + myDistance=theDistance; +} + +//================================================================== +// function : GetDistance +// purpose : +//================================================================== +vtkFloatingPointType VTKViewer_FramedTextActor::GetDistance()const +{ + return myDistance; +} + +//================================================================== +// function : ReleaseGraphicsResources +// purpose : +//================================================================== +void VTKViewer_FramedTextActor::ReleaseGraphicsResources(vtkWindow *win) +{ + myTextActor->ReleaseGraphicsResources(win); + myBarActor->ReleaseGraphicsResources(win); +} + +//================================================================== +// function : RenderOverlay +// purpose : +//================================================================== +int VTKViewer_FramedTextActor::RenderOverlay(vtkViewport *viewport) +{ + int renderedSomething = 0; + myBarActor->RenderOverlay(viewport); + renderedSomething +=myTextActor->RenderOverlay(viewport); + return renderedSomething; +} + +//================================================================== +// function : RenderOpaqueGeometry +// purpose : +//================================================================== +int +VTKViewer_FramedTextActor +::RenderOpaqueGeometry(vtkViewport *theViewport) +{ + int anIsRenderedSomething = 0; + + int* aViewportSize = theViewport->GetSize(); + int aViewPortWidth = aViewportSize[0]; + int aViewPortHeight = aViewportSize[1]; + if(aViewPortWidth == 1 || aViewPortHeight == 1) + return anIsRenderedSomething; + + if(!myTextMapper->GetInput()) + return anIsRenderedSomething; + + myBar->Initialize(); + + int aNbPoints = 4; + vtkPoints *aPoints = vtkPoints::New(); + aPoints->SetNumberOfPoints(aNbPoints); + myBar->SetPoints(aPoints); + aPoints->Delete(); + + vtkCellArray *aPolys = vtkCellArray::New(); + aPolys->Allocate(aPolys->EstimateSize(1,4)); + vtkIdType aPointsIds[4] = {0, 1, 3, 2}; + aPolys->InsertNextCell(4,aPointsIds); + myBar->SetPolys(aPolys); + aPolys->Delete(); + + int aTextSize[2]; + myTextMapper->GetSize(theViewport, aTextSize); + int aBarWidth = aTextSize[0]; + int aBarHeight = aTextSize[1]; + + int aTextMargin = GetTextMargin(); + + vtkFloatingPointType xMin = 0.0; + vtkFloatingPointType xMax = 0.0; + vtkFloatingPointType yMin = -aBarHeight/2 - aTextMargin; + vtkFloatingPointType yMax = aBarHeight/2 + aTextMargin; + + int aHorizontalOffset = GetLayoutType() == Horizontal ? myHorizontalOffset : 0; + int aVerticalOffset = GetLayoutType() == Vertical ? myVerticalOffset : 0; + + if( myModePosition == BelowPoint ) + { + theViewport->SetWorldPoint(myWorldPoint); + theViewport->WorldToDisplay(); + + vtkFloatingPointType aSelectionPoint[3]; + theViewport->GetDisplayPoint(aSelectionPoint); + vtkFloatingPointType u = aSelectionPoint[0]; + vtkFloatingPointType v = aSelectionPoint[1] - myDistance; + theViewport->ViewportToNormalizedViewport(u, v); + PositionCoordinate->SetValue(u, v); + + myTextProperty->SetJustificationToCentered(); + + xMin = -aBarWidth/2 - aTextMargin; + xMax = aBarWidth/2 + aTextMargin; + } + else // except BelowPoint, only TopLeft and TopRight modes are supported at this moment + { + vtkFloatingPointType x = 0, xOffset = aHorizontalOffset + aTextMargin + OFFSET_SPACING; + vtkFloatingPointType y = 0, yOffset = aVerticalOffset + aTextMargin + OFFSET_SPACING; + + if( myModePosition == TopLeft ) + { + x = xOffset; + y = aViewPortHeight - yOffset - aBarHeight/2; + myTextProperty->SetJustificationToLeft(); + + xMin = - aTextMargin; + xMax = aBarWidth + aTextMargin; + } + else if( myModePosition == TopRight ) + { + x = aViewPortWidth - xOffset; + y = aViewPortHeight - yOffset - aBarHeight/2; + myTextProperty->SetJustificationToRight(); + + xMin = -aBarWidth - aTextMargin; + xMax = aTextMargin; + } + + PositionCoordinate->SetValue(x / (vtkFloatingPointType)aViewPortWidth, + y / (vtkFloatingPointType)aViewPortHeight); + } + + aPoints->SetPoint(0, xMin, yMax, 0.0); + aPoints->SetPoint(1, xMin, yMin, 0.0); + aPoints->SetPoint(2, xMax, yMax, 0.0); + aPoints->SetPoint(3, xMax, yMin, 0.0); + + myTextProperty->SetVerticalJustificationToCentered(); + + myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty); + myBarActor ->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate); + myTextActor->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate); + + myBuildTime.Modified(); + + return anIsRenderedSomething; +} diff --git a/src/VTKViewer/VTKViewer_FramedTextActor.h b/src/VTKViewer/VTKViewer_FramedTextActor.h new file mode 100644 index 000000000..71130ac40 --- /dev/null +++ b/src/VTKViewer/VTKViewer_FramedTextActor.h @@ -0,0 +1,129 @@ +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#ifndef VTKVIEWER_FRAMEDTEXTACTOR_H +#define VTKVIEWER_FRAMEDTEXTACTOR_H + +#include "VTKViewer.h" + +#include + +class vtkPolyData; +class vtkPolyDataMapper2D; +class vtkRenderer; +class vtkTimeStamp; +class vtkTextMapper; +class vtkTextProperty; +class vtkViewport; +class vtkWindow; + +class VTKVIEWER_EXPORT VTKViewer_FramedTextActor : public vtkActor2D +{ +public: + enum ModePosition { BelowPoint = 0, TopLeft, TopRight, BottomLeft, BottomRight }; + enum LayoutType { Vertical = 0, Horizontal }; + +public: + vtkTypeRevisionMacro(VTKViewer_FramedTextActor,vtkActor2D); + static VTKViewer_FramedTextActor *New(); + + virtual int RenderOpaqueGeometry(vtkViewport*); + virtual int RenderTranslucentGeometry(vtkViewport*) { return 0; } + virtual int RenderOverlay(vtkViewport*); + virtual void ReleaseGraphicsResources(vtkWindow*); + + virtual void SetVisibility(int); + virtual int GetVisibility(); + virtual void SetPickable(int); + virtual int GetPickable(); + + virtual void GetSize(vtkRenderer* theRenderer, int theSize[2]) const; + + void SetText(const char* theText); + char* GetText(); + + void SetModePosition(const int theMode); + int GetModePosition() const; + + void SetLayoutType(const int theType); + int GetLayoutType() const; + + void SetWorldPoint(const vtkFloatingPointType theWorldPoint[4]); + const vtkFloatingPointType* GetWorldPoint() const; + + void SetDistance(const vtkFloatingPointType theDistance); + vtkFloatingPointType GetDistance() const; + + void SetForegroundColor(const vtkFloatingPointType r, + const vtkFloatingPointType g, + const vtkFloatingPointType b); + void GetForegroundColor(vtkFloatingPointType& r, + vtkFloatingPointType& g, + vtkFloatingPointType& b); + + void SetBackgroundColor(const vtkFloatingPointType r, + const vtkFloatingPointType g, + const vtkFloatingPointType b); + void GetBackgroundColor(vtkFloatingPointType& r, + vtkFloatingPointType& g, + vtkFloatingPointType& b); + + void SetTransparency(const vtkFloatingPointType theTransparency); + vtkFloatingPointType GetTransparency() const; + + void SetTextMargin(const int theMargin); + int GetTextMargin() const; + + void SetOffset(const int theOffset[2]); + +protected: + VTKViewer_FramedTextActor(); + ~VTKViewer_FramedTextActor(); + +protected: + vtkPolyData* myBar; + vtkPolyDataMapper2D* myBarMapper; + vtkActor2D* myBarActor; + + vtkTextProperty* myTextProperty; + vtkTextMapper* myTextMapper; + vtkActor2D* myTextActor; + + vtkTimeStamp myBuildTime; + + int myModePosition; + int myLayoutType; + + vtkFloatingPointType myWorldPoint[4]; + vtkFloatingPointType myDistance; + vtkFloatingPointType myTransparency; + + int myTextMargin; + + int myHorizontalOffset; + int myVerticalOffset; + +private: + VTKViewer_FramedTextActor(const VTKViewer_FramedTextActor&); // Not implemented. + void operator=(const VTKViewer_FramedTextActor&); // Not implemented. +}; + +#endif -- 2.39.2