From: pkv Date: Thu, 6 Oct 2005 12:38:47 +0000 (+0000) Subject: Add transparent frame around the annotation text X-Git-Tag: BR-D5-38-2003_D2005-12-10~42 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a67ffc31614c64e2bfa19489d452ce60f53e5b47;p=modules%2Fvisu.git Add transparent frame around the annotation text --- diff --git a/src/OBJECT/VISU_GaussPtsAct.cxx b/src/OBJECT/VISU_GaussPtsAct.cxx index dcf909df..a37e9389 100644 --- a/src/OBJECT/VISU_GaussPtsAct.cxx +++ b/src/OBJECT/VISU_GaussPtsAct.cxx @@ -96,8 +96,7 @@ VISU_GaussPtsAct myWidget(NULL), myGaussPointsPL(NULL), myLastObjPointID(-1), - myTextMapper(vtkTextMapper::New()), - myTextActor(VISU_GPTextActor::New()), + myTextActor(VISU_FramedTextActor::New()), mySphereSource(vtkSphereSource::New()), mySphereMapper(vtkPolyDataMapper::New()), mySphereActor(vtkActor::New()), @@ -115,8 +114,6 @@ VISU_GaussPtsAct myEventCallbackCommand->Delete(); myDeviceActor->Delete(); - - myTextMapper->Delete(); myTextActor->Delete(); mySphereSource->Delete(); @@ -138,11 +135,6 @@ VISU_GaussPtsAct myDeviceActor->SetVisibility(true); myDeviceActor->SetPickable(false); - vtkTextProperty* aTextProperty = myTextMapper->GetTextProperty(); - aTextProperty->SetVerticalJustification(VTK_TEXT_BOTTOM); - aTextProperty->SetJustification(VTK_TEXT_LEFT); - - myTextActor->SetMapper(myTextMapper.GetPointer()); myTextActor->SetVisibility(false); myTextActor->SetPickable(false); @@ -535,6 +527,7 @@ VISU_GaussPtsAct // To calculate display (2D) position of the annotation float aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.0}; myTextActor->SetModePosition(myPickingSettings->GetInfoWindowPosition()); + myTextActor->SetTransparency(myPickingSettings->GetInfoWindowTransparency()); myTextActor->SetWorldPoint(aWorldCoord); // // To prepare the annotation text @@ -583,8 +576,7 @@ VISU_GaussPtsAct } std::string aString = aStr.str(); - myTextMapper->SetInput(aString.c_str()); - + myTextActor->SetText(aString.c_str()); myLastObjPointID = anObjId; } diff --git a/src/OBJECT/VISU_GaussPtsAct.h b/src/OBJECT/VISU_GaussPtsAct.h index ff0e7bff..23e65a98 100644 --- a/src/OBJECT/VISU_GaussPtsAct.h +++ b/src/OBJECT/VISU_GaussPtsAct.h @@ -50,7 +50,7 @@ class vtkInteractorStyle; class VISU_GaussPtsDeviceActor; class VISU_CursorPyramid; -class VISU_GPTextActor; +class VISU_FramedTextActor; class vtkUnstructuredGrid; class vtkDataSetMapper; @@ -221,9 +221,9 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_Actor vtkSmartPointer myGaussPointsPL; vtkIdType myLastObjPointID; - vtkSmartPointer myTextMapper; - vtkSmartPointer myTextActor; + vtkSmartPointer myTextActor; + vtkSmartPointer mySphereSource; vtkSmartPointer mySphereMapper; vtkSmartPointer mySphereActor; diff --git a/src/OBJECT/VISU_GaussPtsDeviceActor.cxx b/src/OBJECT/VISU_GaussPtsDeviceActor.cxx index 7d6038c5..22667349 100644 --- a/src/OBJECT/VISU_GaussPtsDeviceActor.cxx +++ b/src/OBJECT/VISU_GaussPtsDeviceActor.cxx @@ -266,53 +266,165 @@ VISU_CursorPyramid myActors[5]->SetOrientation(180., 0. ,0.); } +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include //================================================================== -vtkStandardNewMacro(VISU_GPTextActor); +vtkCxxRevisionMacro(VISU_FramedTextActor, "$Revision$"); +vtkStandardNewMacro(VISU_FramedTextActor); + //================================================================== -// function : +// function : VISU_FramedTextActor // purpose : //================================================================== -VISU_GPTextActor::VISU_GPTextActor() +VISU_FramedTextActor::VISU_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("some text"); + myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty); + myTextActor=vtkActor2D::New(); + myTextActor->SetMapper(myTextMapper); + // + myBarActor->SetVisibility(1); + myTextActor->SetVisibility(1); + myBarActor->SetPickable(0); + myTextActor->SetPickable(0); + //---------------------------------------------------------- myModePosition=0;// 0 -centered below the point - // 1 -top left corner of the 3D view window + // 1 -top left corner of the 3D view window // for(int i=0; i<4; i++) { myWorldPoint[i] = 0.; } myDistance=10.; - GetTextProperty()->SetFontSize(12); - GetTextProperty()->ShadowOn(); + // } //================================================================== -// function : SetDistance +// function : ~ // purpose : //================================================================== -void VISU_GPTextActor::SetDistance(const float theDistance) +VISU_FramedTextActor::~VISU_FramedTextActor() { - myDistance=theDistance; + myTextActor->Delete(); + myTextMapper->Delete(); + myTextProperty->Delete(); + myBarActor->Delete(); + myBarMapper->Delete(); + myBar->Delete(); } //================================================================== -// function : GetDistance +// function : SetVisibility // purpose : //================================================================== -float VISU_GPTextActor::GetDistance()const +void VISU_FramedTextActor::SetVisibility (int theVisibility) { - return myDistance; + myBarActor->SetVisibility(theVisibility); + myTextActor->SetVisibility(theVisibility); +} +//================================================================== +// function : GetVisibility +// purpose : +//================================================================== +int VISU_FramedTextActor::GetVisibility() +{ + return myBarActor->GetVisibility(); +} +//================================================================== +// function : SetPickable +// purpose : +//================================================================== +void VISU_FramedTextActor::SetPickable (int thePickability) +{ + myBarActor->SetPickable(thePickability); + myTextActor->SetPickable(thePickability); +} +//================================================================== +// function : GetPickable +// purpose : +//================================================================== +int VISU_FramedTextActor::GetPickable() +{ + return myBarActor->GetPickable(); +} +//================================================================== +// function : SetTransparency +// purpose : +//================================================================== +void VISU_FramedTextActor::SetTransparency(const float theTransparency) +{ + if (theTransparency>=0. && theTransparency<=1.){ + myTransparency=theTransparency; + myBarActor->GetProperty()->SetOpacity(1.-myTransparency); + Modified(); + } +} +//================================================================== +// function : GetTransparency +// purpose : +//================================================================== +float VISU_FramedTextActor::GetTransparency()const +{ + return myTransparency; +} +//================================================================== +// function : SetText +// purpose : +//================================================================== +void VISU_FramedTextActor::SetText(const char* theText) +{ + myTextMapper->SetInput(theText); + Modified(); +} +//================================================================== +// function : GetText +// purpose : +//================================================================== +char* VISU_FramedTextActor::GetText() +{ + return myTextMapper->GetInput(); } //================================================================== // function : SetModePosition // purpose : //================================================================== -void VISU_GPTextActor::SetModePosition(const int theMode) +void VISU_FramedTextActor::SetModePosition(const int theMode) { myModePosition=theMode; + Modified(); } //================================================================== // function : GetModePosition // purpose : //================================================================== -int VISU_GPTextActor::GetModePosition()const +int VISU_FramedTextActor::GetModePosition()const { return myModePosition; } @@ -320,55 +432,124 @@ int VISU_GPTextActor::GetModePosition()const // function : SetWorldPoint // purpose : //================================================================== -void VISU_GPTextActor::SetWorldPoint(const float theWorldPoint[4]) +void VISU_FramedTextActor::SetWorldPoint(const float theWorldPoint[4]) { - for(int i = 0; i < 4; i++) { + for(int i = 0; i<4; ++i) { myWorldPoint[i] = theWorldPoint[i]; - } + } + Modified(); } //================================================================== // function : GetWorldPoint // purpose : //================================================================== -const float* VISU_GPTextActor::GetWorldPoint()const +const float* VISU_FramedTextActor::GetWorldPoint()const { return myWorldPoint; } //================================================================== +// function : SetDistance +// purpose : +//================================================================== +void VISU_FramedTextActor::SetDistance(const float theDistance) +{ + myDistance=theDistance; +} +//================================================================== +// function : GetDistance +// purpose : +//================================================================== +float VISU_FramedTextActor::GetDistance()const +{ + return myDistance; +} +//================================================================== +// function : ReleaseGraphicsResources +// purpose : +//================================================================== +void VISU_FramedTextActor::ReleaseGraphicsResources(vtkWindow *win) +{ + myTextActor->ReleaseGraphicsResources(win); + myBarActor->ReleaseGraphicsResources(win); +} +//================================================================== +// function : RenderOverlay +// purpose : +//================================================================== +int VISU_FramedTextActor::RenderOverlay(vtkViewport *viewport) +{ + int renderedSomething = 0; + myBarActor->RenderOverlay(viewport); + renderedSomething +=myTextActor->RenderOverlay(viewport); + return renderedSomething; +} +//================================================================== // function : RenderOpaqueGeometry // purpose : //================================================================== -int VISU_GPTextActor::RenderOpaqueGeometry(vtkViewport *theViewport) +int VISU_FramedTextActor::RenderOpaqueGeometry(vtkViewport *viewport) { - int iScaledText=GetScaledText(); - int iAlignmentPoint=GetAlignmentPoint(); - float * pPosition2=GetPosition2(); - vtkTextProperty *pTextProperty=GetTextProperty(); + int renderedSomething=0; + int size[2]; + int aTextSize[2], barWidth, barHeight; + float x[3]={0.,0.,0.}; + // + int numPts=4; + vtkPoints *pts = vtkPoints::New(); + pts->SetNumberOfPoints(numPts); + vtkCellArray *polys = vtkCellArray::New(); + polys->Allocate(polys->EstimateSize(1,4)); // - if (myModePosition==0){ - float aSelectionPoint[3]; - // - theViewport->SetWorldPoint(myWorldPoint); - theViewport->WorldToDisplay(); - theViewport->GetDisplayPoint(aSelectionPoint); + myBar->Initialize(); + myBar->SetPoints(pts); + myBar->SetPolys(polys); + pts->Delete(); polys->Delete(); + // + myTextMapper->GetSize(viewport, aTextSize); + // + barWidth =aTextSize[0]; + barHeight=aTextSize[1]; + // + if (myModePosition==0) { - aSelectionPoint[1] -= myDistance; - pTextProperty->SetJustificationToCentered(); - pTextProperty->SetVerticalJustificationToTop(); - SetAlignmentPoint(-1);/// - SetPosition(aSelectionPoint); + float aSelectionPoint[3], u, v; + // + viewport->SetWorldPoint(myWorldPoint); + viewport->WorldToDisplay(); + viewport->GetDisplayPoint(aSelectionPoint); + u=aSelectionPoint[0]; + v=aSelectionPoint[1]-myDistance; + viewport->ViewportToNormalizedViewport(u, v); + // + PositionCoordinate->SetValue(u, v); + // + myTextProperty->SetJustificationToCentered (); + myTextProperty->SetVerticalJustificationToTop(); + // + x[0]=-barWidth/2. ; x[1]=0. ; pts->SetPoint(0,x); + x[0]=-barWidth/2. ; x[1]=-barHeight ; pts->SetPoint(1,x); + x[0]= barWidth/2 ; x[1]=0. ; pts->SetPoint(2,x); + x[0]= barWidth/2 ; x[1]=-barHeight ; pts->SetPoint(3,x); } - else if (myModePosition==1) { - pTextProperty->SetJustificationToLeft(); - pTextProperty->SetVerticalJustificationToTop(); - ScaledTextOff (); - SetPosition2 (1., 1.); - SetAlignmentPoint(6); - SetPosition(0., 0.); - } - Superclass::RenderOpaqueGeometry(theViewport); + else {//if (myModePosition==1) { + PositionCoordinate->SetValue(0., 1.); + myTextProperty->SetJustificationToLeft(); + myTextProperty->SetVerticalJustificationToTop(); + // + x[0]=0. ; x[1]=0. ; pts->SetPoint(0,x); + x[0]=0. ; x[1]=-barHeight ; pts->SetPoint(1,x); + x[0]= barWidth ; x[1]=0. ; pts->SetPoint(2,x); + x[0]= barWidth ; x[1]=-barHeight ; pts->SetPoint(3,x); + } + // + myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty); + myBarActor ->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate); + myTextActor->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate); + // + vtkIdType ptIds[4]={0,1,3,2}; + polys->InsertNextCell(4,ptIds); + // + myBuildTime.Modified(); // - SetAlignmentPoint(iAlignmentPoint); - SetPosition2(pPosition2); - SetScaledText(iScaledText); + return renderedSomething; } diff --git a/src/OBJECT/VISU_GaussPtsDeviceActor.h b/src/OBJECT/VISU_GaussPtsDeviceActor.h index 33ace523..2dd699fa 100644 --- a/src/OBJECT/VISU_GaussPtsDeviceActor.h +++ b/src/OBJECT/VISU_GaussPtsDeviceActor.h @@ -137,38 +137,76 @@ protected: vtkSmartPointer myMappers[6]; vtkSmartPointer myActors[6]; }; - -//============================================================================ -#include - -class VISU_GPTextActor : public vtkTextActor +//================================================================== +// class VISU_FramedTextActor +// +#include +// +class vtkViewport; +class vtkProp; +class vtkWindow; +class vtkPolyData; +class vtkPolyDataMapper2D; +class vtkActor2D; +class vtkTimeStamp; +class vtkTextProperty; +class vtkTextMapper; + +class VISU_FramedTextActor : public vtkActor2D { public: - vtkTypeMacro(VISU_GPTextActor,vtkTextActor); - - static VISU_GPTextActor* New(); - - void SetWorldPoint(const float theWorldPoint[4]); - - const float* GetWorldPoint()const; - + // vtks + vtkTypeRevisionMacro(VISU_FramedTextActor,vtkActor2D); + static VISU_FramedTextActor *New(); + // + virtual int RenderOpaqueGeometry(vtkViewport* viewport); + virtual int RenderTranslucentGeometry(vtkViewport*) { return 0; }; + virtual int RenderOverlay(vtkViewport* viewport); + virtual void ReleaseGraphicsResources(vtkWindow *); + virtual void SetVisibility (int ); + virtual int GetVisibility() ; + virtual void SetPickable (int ) ; + virtual int GetPickable(); + // + // selectors + void SetText(const char* theText); + char* GetText(); + // void SetModePosition(const int theMode); - int GetModePosition()const; - + // + void SetWorldPoint(const float theWorldPoint[4]); + const float* GetWorldPoint()const; + // void SetDistance(const float theDistance); - float GetDistance()const; - - virtual int RenderOpaqueGeometry(vtkViewport *theViewport); - + // + void SetTransparency(const float theTransparency); + float GetTransparency()const; + // protected: - VISU_GPTextActor(); + VISU_FramedTextActor(); + ~VISU_FramedTextActor(); protected: + vtkPolyData *myBar; + vtkPolyDataMapper2D *myBarMapper; + vtkActor2D *myBarActor; + // + vtkTextProperty *myTextProperty; + vtkTextMapper *myTextMapper; + vtkActor2D *myTextActor; + // + vtkTimeStamp myBuildTime; + // int myModePosition; float myWorldPoint[4]; float myDistance; + float myTransparency; + +private: + VISU_FramedTextActor(const VISU_FramedTextActor&); // Not implemented. + void operator=(const VISU_FramedTextActor&); // Not implemented. }; #endif //VISU_GAUSS_PTS_DEVICE_ACTOR_H