From: nds Date: Wed, 13 Feb 2008 13:35:32 +0000 (+0000) Subject: Create TextZone in the VTK Viewer. X-Git-Tag: TG_Saint_Valentine-Day~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=feefa83a5cef10f2271dd95ba0a507a7b27a576e;p=modules%2Fgui.git Create TextZone in the VTK Viewer. --- diff --git a/src/SVTK/SVTK.pro b/src/SVTK/SVTK.pro index b7e5eb2d1..86028467b 100644 --- a/src/SVTK/SVTK.pro +++ b/src/SVTK/SVTK.pro @@ -26,7 +26,10 @@ HEADERS += SVTK_Actor.h HEADERS += SALOME_Actor.h HEADERS += SVTK_RectPicker.h HEADERS += SVTK_DeviceActor.h +HEADERS += SVTK_Actor2DWidget.h +HEADERS += SVTK_CaptionActor2DWidget.h HEADERS += SVTK_NonIsometricDlg.h +HEADERS += SVTK_TextRegionDlg.h HEADERS += SVTK_UpdateRateDlg.h HEADERS += SVTK_CubeAxesDlg.h @@ -57,9 +60,12 @@ SOURCES += SVTK_Actor.cxx SOURCES += SALOME_Actor.cxx SOURCES += SVTK_RectPicker.cxx SOURCES += SVTK_DeviceActor.cxx +SOURCES += SVTK_Actor2DWidget.cxx +SOURCES += SVTK_CaptionActor2DWidget.cxx SOURCES += SVTK_CubeAxesActor2D.cxx SOURCES += SVTK_NonIsometricDlg.cxx SOURCES += SVTK_UpdateRateDlg.cxx +SOURCES += SVTK_TextRegionDlg.cxx SOURCES += SVTK_CubeAxesDlg.cxx SOURCES += SVTK_DialogBase.cxx SOURCES += SVTK_FontWidget.cxx diff --git a/src/SVTK/SVTK_Actor2DWidget.cxx b/src/SVTK/SVTK_Actor2DWidget.cxx new file mode 100644 index 000000000..9617c77b1 --- /dev/null +++ b/src/SVTK/SVTK_Actor2DWidget.cxx @@ -0,0 +1,479 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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 +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#include "SVTK_Actor2DWidget.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(SVTK_Actor2DWidget); +vtkCxxSetObjectMacro(SVTK_Actor2DWidget, Actor2D, vtkActor2D); + +SVTK_Actor2DWidget::SVTK_Actor2DWidget() +{ + this->Actor2D = NULL; + this->EventCallbackCommand->SetCallback(SVTK_Actor2DWidget::ProcessEvents); + this->State = SVTK_Actor2DWidget::Outside; + this->LeftButtonDown = 0; + this->RightButtonDown = 0; + this->Priority = 0.55; +} + +SVTK_Actor2DWidget::~SVTK_Actor2DWidget() +{ + this->SetActor2D(0); +} + +void SVTK_Actor2DWidget::SetEnabled(int enabling) +{ + if ( ! this->Interactor ) + { + vtkErrorMacro(<<"The interactor must be set prior to enabling/disabling widget"); + return; + } + + if ( enabling ) + { + vtkDebugMacro(<<"Enabling line widget"); + if ( this->Enabled ) //already enabled, just return + { + return; + } + + if ( ! this->CurrentRenderer ) + { + this->SetCurrentRenderer(this->Interactor->FindPokedRenderer( + this->Interactor->GetLastEventPosition()[0], + this->Interactor->GetLastEventPosition()[1])); + if (this->CurrentRenderer == NULL) + { + return; + } + } + + this->Enabled = 1; + + // listen for the following events + vtkRenderWindowInteractor *i = this->Interactor; + i->AddObserver(vtkCommand::MouseMoveEvent, + this->EventCallbackCommand, this->Priority); + i->AddObserver(vtkCommand::LeftButtonPressEvent, + this->EventCallbackCommand, this->Priority); + i->AddObserver(vtkCommand::LeftButtonReleaseEvent, + this->EventCallbackCommand, this->Priority); + i->AddObserver(vtkCommand::RightButtonPressEvent, + this->EventCallbackCommand, this->Priority); + i->AddObserver(vtkCommand::RightButtonReleaseEvent, + this->EventCallbackCommand, this->Priority); + + // Add the scalar bar + this->CurrentRenderer->AddViewProp(this->Actor2D); + this->InvokeEvent(vtkCommand::EnableEvent,NULL); + } + else //disabling------------------------------------------ + { + vtkDebugMacro(<<"Disabling line widget"); + if ( ! this->Enabled ) //already disabled, just return + { + return; + } + this->Enabled = 0; + + // don't listen for events any more + this->Interactor->RemoveObserver(this->EventCallbackCommand); + + // turn off the line + this->CurrentRenderer->RemoveActor(this->Actor2D); + this->InvokeEvent(vtkCommand::DisableEvent,NULL); + this->SetCurrentRenderer(NULL); + } + + this->Interactor->Render(); +} + +void SVTK_Actor2DWidget::ProcessEvents(vtkObject* vtkNotUsed(object), + unsigned long event, + void* clientdata, + void* vtkNotUsed(calldata)) +{ + SVTK_Actor2DWidget* self = reinterpret_cast( clientdata ); + + //okay, let's do the right thing + switch(event) + { + case vtkCommand::LeftButtonPressEvent: + self->OnLeftButtonDown(); + break; + case vtkCommand::LeftButtonReleaseEvent: + self->OnLeftButtonUp(); + break; + case vtkCommand::RightButtonPressEvent: + self->OnRightButtonDown(); + break; + case vtkCommand::RightButtonReleaseEvent: + self->OnRightButtonUp(); + break; + case vtkCommand::MouseMoveEvent: + self->OnMouseMove(); + break; + } +} + + +int SVTK_Actor2DWidget::ComputeStateBasedOnPosition(int X, int Y, + int *pos1, int *pos2) +{ + int Result; + + // what are we modifying? The position, or size? + // if size what piece? + // if we are within 7 pixels of an edge... + int e1 = 0; + int e2 = 0; + int e3 = 0; + int e4 = 0; + if (X - pos1[0] < 7) + { + e1 = 1; + } + if (pos2[0] - X < 7) + { + e3 = 1; + } + if (Y - pos1[1] < 7) + { + e2 = 1; + } + if (pos2[1] - Y < 7) + { + e4 = 1; + } + + // assume we are moving + Result = SVTK_Actor2DWidget::Moving; + // unless we are on a corner or edges + if (e2) + { + Result = SVTK_Actor2DWidget::AdjustingE2; + } + if (e4) + { + Result = SVTK_Actor2DWidget::AdjustingE4; + } + if (e1) + { + Result = SVTK_Actor2DWidget::AdjustingE1; + if (e2) + { + Result = SVTK_Actor2DWidget::AdjustingP1; + } + if (e4) + { + Result = SVTK_Actor2DWidget::AdjustingP4; + } + } + if (e3) + { + Result = SVTK_Actor2DWidget::AdjustingE3; + if (e2) + { + Result = SVTK_Actor2DWidget::AdjustingP2; + } + if (e4) + { + Result = SVTK_Actor2DWidget::AdjustingP3; + } + } + + return Result; +} + +void SVTK_Actor2DWidget::SetCursor(int cState) +{ + switch (cState) + { + case SVTK_Actor2DWidget::AdjustingP1: + this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZESW); + break; + case SVTK_Actor2DWidget::AdjustingP3: + this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZENE); + break; + case SVTK_Actor2DWidget::AdjustingP2: + this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZESE); + break; + case SVTK_Actor2DWidget::AdjustingP4: + this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZENW); + break; + case SVTK_Actor2DWidget::AdjustingE1: + case SVTK_Actor2DWidget::AdjustingE3: + this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZEWE); + break; + case SVTK_Actor2DWidget::AdjustingE2: + case SVTK_Actor2DWidget::AdjustingE4: + this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZENS); + break; + case SVTK_Actor2DWidget::Moving: + this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZEALL); + break; + } +} + + +void SVTK_Actor2DWidget::OnLeftButtonDown() +{ + if(!this->Actor2D) + return; + + // We're only here is we are enabled + int X = this->Interactor->GetEventPosition()[0]; + int Y = this->Interactor->GetEventPosition()[1]; + + // are we over the widget? + //this->Interactor->FindPokedRenderer(X,Y); + int *pos1 = this->Actor2D->GetPositionCoordinate() + ->GetComputedDisplayValue(this->CurrentRenderer); + int *pos2 = this->Actor2D->GetPosition2Coordinate() + ->GetComputedDisplayValue(this->CurrentRenderer); + + // are we not over the scalar bar, ignore + if (X < pos1[0] || X > pos2[0] || Y < pos1[1] || Y > pos2[1]) + { + return; + } + + if(this->Interactor->GetRepeatCount() > 1){ + this->InvokeEvent(SVTK_Actor2DWidget::EditEvent, NULL); + return; + } + + // start a drag, store the normalized view coords + double X2 = X; + double Y2 = Y; + // convert to normalized viewport coordinates + this->CurrentRenderer->DisplayToNormalizedDisplay(X2,Y2); + this->CurrentRenderer->NormalizedDisplayToViewport(X2,Y2); + this->CurrentRenderer->ViewportToNormalizedViewport(X2,Y2); + this->StartPosition[0] = X2; + this->StartPosition[1] = Y2; + + this->State = this->ComputeStateBasedOnPosition(X, Y, pos1, pos2); + this->SetCursor(this->State); + + this->EventCallbackCommand->SetAbortFlag(1); + this->StartInteraction(); + this->InvokeEvent(vtkCommand::StartInteractionEvent,NULL); + this->LeftButtonDown = 1; +} + +void SVTK_Actor2DWidget::OnMouseMove() +{ + if(!this->Actor2D) + return; + + // compute some info we need for all cases + int X = this->Interactor->GetEventPosition()[0]; + int Y = this->Interactor->GetEventPosition()[1]; + + + // compute the display bounds of the scalar bar if we are inside or outside + int *pos1, *pos2; + if (this->State == SVTK_Actor2DWidget::Outside || + this->State == SVTK_Actor2DWidget::Inside) + { + pos1 = this->Actor2D->GetPositionCoordinate() + ->GetComputedDisplayValue(this->CurrentRenderer); + pos2 = this->Actor2D->GetPosition2Coordinate() + ->GetComputedDisplayValue(this->CurrentRenderer); + + if (this->State == SVTK_Actor2DWidget::Outside) + { + // if we are not over the scalar bar, ignore + if (X < pos1[0] || X > pos2[0] || + Y < pos1[1] || Y > pos2[1]) + { + return; + } + // otherwise change our state to inside + this->State = SVTK_Actor2DWidget::Inside; + } + + // if inside, set the cursor to the correct shape + if (this->State == SVTK_Actor2DWidget::Inside) + { + // if we have left then change cursor back to default + if (X < pos1[0] || X > pos2[0] || + Y < pos1[1] || Y > pos2[1]) + { + this->State = SVTK_Actor2DWidget::Outside; + this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_DEFAULT); + return; + } + // adjust the cursor based on our position + this->SetCursor(this->ComputeStateBasedOnPosition(X,Y,pos1,pos2)); + return; + } + } + + double XF = X; + double YF = Y; + // convert to normalized viewport coordinates + this->CurrentRenderer->DisplayToNormalizedDisplay(XF,YF); + this->CurrentRenderer->NormalizedDisplayToViewport(XF,YF); + this->CurrentRenderer->ViewportToNormalizedViewport(XF,YF); + + // there are four parameters that can be adjusted + double *fpos1 = this->Actor2D->GetPositionCoordinate()->GetValue(); + double *fpos2 = this->Actor2D->GetPosition2Coordinate()->GetValue(); + double par1[2]; + double par2[2]; + par1[0] = fpos1[0]; + par1[1] = fpos1[1]; + par2[0] = fpos1[0] + fpos2[0]; + par2[1] = fpos1[1] + fpos2[1]; + + // based on the state, adjust the ScalarBar parameters + switch (this->State) + { + case SVTK_Actor2DWidget::AdjustingP1: + par1[0] = par1[0] + XF - this->StartPosition[0]; + par1[1] = par1[1] + YF - this->StartPosition[1]; + break; + case SVTK_Actor2DWidget::AdjustingP2: + par2[0] = par2[0] + XF - this->StartPosition[0]; + par1[1] = par1[1] + YF - this->StartPosition[1]; + break; + case SVTK_Actor2DWidget::AdjustingP3: + par2[0] = par2[0] + XF - this->StartPosition[0]; + par2[1] = par2[1] + YF - this->StartPosition[1]; + break; + case SVTK_Actor2DWidget::AdjustingP4: + par1[0] = par1[0] + XF - this->StartPosition[0]; + par2[1] = par2[1] + YF - this->StartPosition[1]; + break; + case SVTK_Actor2DWidget::AdjustingE1: + par1[0] = par1[0] + XF - this->StartPosition[0]; + break; + case SVTK_Actor2DWidget::AdjustingE2: + par1[1] = par1[1] + YF - this->StartPosition[1]; + break; + case SVTK_Actor2DWidget::AdjustingE3: + par2[0] = par2[0] + XF - this->StartPosition[0]; + break; + case SVTK_Actor2DWidget::AdjustingE4: + par2[1] = par2[1] + YF - this->StartPosition[1]; + break; + case SVTK_Actor2DWidget::Moving: + // first apply the move + par1[0] = par1[0] + XF - this->StartPosition[0]; + par1[1] = par1[1] + YF - this->StartPosition[1]; + par2[0] = par2[0] + XF - this->StartPosition[0]; + par2[1] = par2[1] + YF - this->StartPosition[1]; + break; + } + + // push the change out to the scalar bar + // make sure the scalar bar doesn't shrink to nothing + if (par2[0] > par1[0] && par2[1] > par1[1]) + { + this->Actor2D->GetPositionCoordinate()->SetValue(par1[0],par1[1]); + this->Actor2D->GetPosition2Coordinate()-> + SetValue(par2[0] - par1[0], par2[1] - par1[1]); + this->StartPosition[0] = XF; + this->StartPosition[1] = YF; + } + + // start a drag + this->EventCallbackCommand->SetAbortFlag(1); + this->InvokeEvent(vtkCommand::InteractionEvent,NULL); + this->Interactor->Render(); +} + +void SVTK_Actor2DWidget::OnLeftButtonUp() +{ + if (this->State == SVTK_Actor2DWidget::Outside || this->LeftButtonDown == 0) + { + return; + } + + // stop adjusting + this->State = SVTK_Actor2DWidget::Outside; + this->EventCallbackCommand->SetAbortFlag(1); + this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_DEFAULT); + this->EndInteraction(); + this->InvokeEvent(vtkCommand::EndInteractionEvent,NULL); + this->LeftButtonDown = 0; +} + +void SVTK_Actor2DWidget::OnRightButtonDown() +{ + + // are we not over the scalar bar, ignore + if (this->State == SVTK_Actor2DWidget::Outside) + { + return; + } + + if (this->HasObserver(vtkCommand::RightButtonPressEvent) ) + { + this->EventCallbackCommand->SetAbortFlag(1); + this->InvokeEvent(vtkCommand::RightButtonPressEvent,NULL); + } + RightButtonDown = 1; +} + +void SVTK_Actor2DWidget::OnRightButtonUp() +{ + if (RightButtonDown == 0) { + return; + } + + if (this->HasObserver(vtkCommand::RightButtonReleaseEvent)) + { + this->EventCallbackCommand->SetAbortFlag(1); + this->InvokeEvent(vtkCommand::RightButtonReleaseEvent,NULL); + } + this->RightButtonDown = 0; +} + +void SVTK_Actor2DWidget::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os,indent); + + os << indent << "Actor2D: " << this->Actor2D << "\n"; +} diff --git a/src/SVTK/SVTK_Actor2DWidget.h b/src/SVTK/SVTK_Actor2DWidget.h new file mode 100644 index 000000000..0b3f8c2ed --- /dev/null +++ b/src/SVTK/SVTK_Actor2DWidget.h @@ -0,0 +1,127 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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 +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#ifndef __SVTK_ACTOR2D_WIDGET__ +#define __SVTK_ACTOR2D_WIDGET__ + +#include "SVTK.h" + +#ifdef WIN32 +#pragma warning( disable:4251 ) +#endif + +#include +#include + +class vtkActor2D; +class vtkRenderer; + + +//---------------------------------------------------------------------------- +class SVTK_EXPORT SVTK_Actor2DWidget : public vtkInteractorObserver +{ +public: + static SVTK_Actor2DWidget *New(); + vtkTypeMacro(SVTK_Actor2DWidget, vtkInteractorObserver); + void PrintSelf(ostream& os, vtkIndent indent); + + void SetActor2D(vtkActor2D *theActor2D); + vtkGetObjectMacro(Actor2D, vtkActor2D); + + // Description: + // Methods for turning the interactor observer on and off. + virtual void SetEnabled(int); + + //! connect to this event to process editing + enum Event + { + EditEvent = vtkCommand::UserEvent + 1000 + }; + +protected: + SVTK_Actor2DWidget(); + ~SVTK_Actor2DWidget(); + + // the actor that is used + vtkActor2D *Actor2D; + + //! handles the events + static void ProcessEvents(vtkObject* object, + unsigned long event, + void* clientdata, + void* calldata); + + //! ProcessEvents() dispatches to these methods. + void OnLeftButtonDown(); + void OnLeftButtonUp(); + void OnRightButtonDown(); + void OnRightButtonUp(); + void OnMouseMove(); + + //! used to compute relative movements + double StartPosition[2]; + + //! manage the state of the widget + int State; + + //! use this to track whether left/right button was pressed to gate action on button up event. + int LeftButtonDown; + int RightButtonDown; + enum WidgetState + { + Moving=0, + AdjustingP1, + AdjustingP2, + AdjustingP3, + AdjustingP4, + AdjustingE1, + AdjustingE2, + AdjustingE3, + AdjustingE4, + Inside, + Outside + }; + + // use to determine what state the mouse is over, edge1 p1, etc. + // returns a state from the WidgetState enum above + int ComputeStateBasedOnPosition(int X, int Y, int *pos1, int *pos2); + + // set the cursor to the correct shape based on State argument + void SetCursor(int State); + +private: + SVTK_Actor2DWidget(const SVTK_Actor2DWidget&); //Not implemented + void operator=(const SVTK_Actor2DWidget&); //Not implemented +}; + + +#ifdef WIN32 +#pragma warning( default:4251 ) +#endif + +#endif // __SVTK_ACTOR2D_WIDGET__ diff --git a/src/SVTK/SVTK_CaptionActor2DWidget.cxx b/src/SVTK/SVTK_CaptionActor2DWidget.cxx new file mode 100644 index 000000000..91b2fcd36 --- /dev/null +++ b/src/SVTK/SVTK_CaptionActor2DWidget.cxx @@ -0,0 +1,93 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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 +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#include "SVTK_CaptionActor2DWidget.h" + +#include + +#include +#include +#include + + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(SVTK_CaptionActor2DWidget); + +SVTK_CaptionActor2DWidget::SVTK_CaptionActor2DWidget() +{ + this->CaptionActor2D = NULL; +} + +SVTK_CaptionActor2DWidget::~SVTK_CaptionActor2DWidget() +{ + this->SetCaptionActor2D(0); +} + +void +SVTK_CaptionActor2DWidget +::SetCaptionActor2D(vtkCaptionActor2D *theCaptionActor2D) +{ + this->SetActor2D(theCaptionActor2D); + CaptionActor2D = theCaptionActor2D; +} + +//---------------------------------------------------------------------------- +namespace SVTK +{ + SVTK_CaptionActor2DWidget* + PublishCaptionActor2D(vtkRenderWindowInteractor* theInteractor) + { + vtkCaptionActor2D* aCaptionActor2D = vtkCaptionActor2D::New(); + aCaptionActor2D->SetPickable(true); + aCaptionActor2D->SetBorder(true); + aCaptionActor2D->SetLeader(false); + aCaptionActor2D->SetCaption(""); + + vtkCoordinate* aCoordinate = aCaptionActor2D->GetPositionCoordinate(); + aCoordinate->SetCoordinateSystemToNormalizedViewport(); + aCoordinate->SetReferenceCoordinate(NULL); + aCoordinate->SetCoordinateSystemToNormalizedViewport(); + aCoordinate->SetValue(0.05, 0.05); + aCaptionActor2D->SetWidth(0.25); + aCaptionActor2D->SetHeight(0.15); + + vtkTextProperty *aTextProperty = vtkTextProperty::New(); + aCaptionActor2D->SetCaptionTextProperty(aTextProperty); + aTextProperty->SetJustificationToCentered(); + aTextProperty->SetVerticalJustificationToCentered(); + aTextProperty->SetFontSize(10); + aTextProperty->Delete(); + + SVTK_CaptionActor2DWidget* aWidget = SVTK_CaptionActor2DWidget::New(); + aWidget->SetCaptionActor2D(aCaptionActor2D); + aWidget->SetInteractor(theInteractor); + aWidget->SetEnabled(1); + + return aWidget; + } +} diff --git a/src/SVTK/SVTK_CaptionActor2DWidget.h b/src/SVTK/SVTK_CaptionActor2DWidget.h new file mode 100644 index 000000000..6b3427b01 --- /dev/null +++ b/src/SVTK/SVTK_CaptionActor2DWidget.h @@ -0,0 +1,79 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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 +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#ifndef __SVTK_CAPTION_ACTOR2D_WIDGET__ +#define __SVTK_CAPTION_ACTOR2D_WIDGET__ + +#include "SVTK.h" + +#ifdef WIN32 +#pragma warning( disable:4251 ) +#endif + +#include "SVTK_Actor2DWidget.h" + +class vtkCaptionActor2D; + + +//---------------------------------------------------------------------------- +class SVTK_EXPORT SVTK_CaptionActor2DWidget : public SVTK_Actor2DWidget +{ +public: + static SVTK_CaptionActor2DWidget *New(); + vtkTypeMacro(SVTK_CaptionActor2DWidget, SVTK_Actor2DWidget); + + void SetCaptionActor2D(vtkCaptionActor2D *theCaptionActor2D); + vtkGetObjectMacro(CaptionActor2D, vtkCaptionActor2D); + +protected: + SVTK_CaptionActor2DWidget(); + ~SVTK_CaptionActor2DWidget(); + + // the actor that is used + vtkCaptionActor2D *CaptionActor2D; + +private: + SVTK_CaptionActor2DWidget(const SVTK_CaptionActor2DWidget&); //Not implemented + void operator=(const SVTK_CaptionActor2DWidget&); //Not implemented +}; + + +//---------------------------------------------------------------------------- +namespace SVTK +{ + SVTK_CaptionActor2DWidget* + PublishCaptionActor2D(vtkRenderWindowInteractor* theInteractor); +} + + +//---------------------------------------------------------------------------- +#ifdef WIN32 +#pragma warning( default:4251 ) +#endif + +#endif // __SVTK_CAPTION_ACTOR2D_WIDGET__ diff --git a/src/SVTK/SVTK_MainWindow.cxx b/src/SVTK/SVTK_MainWindow.cxx index 2d50a0606..276760378 100644 --- a/src/SVTK/SVTK_MainWindow.cxx +++ b/src/SVTK/SVTK_MainWindow.cxx @@ -34,9 +34,6 @@ #include #include -#include -#include - #include #include #include @@ -50,6 +47,9 @@ #include "SVTK_UpdateRateDlg.h" #include "SVTK_CubeAxesDlg.h" #include "SVTK_SetRotationPointDlg.h" + +#include "SVTK_TextRegionDlg.h" + #include "SVTK_MainWindow.h" #include "SVTK_Event.h" #include "SVTK_Renderer.h" @@ -57,6 +57,9 @@ #include "SVTK_InteractorStyle.h" #include "SVTK_Selector.h" +#include +#include + /*! Constructor */ @@ -94,10 +97,12 @@ SVTK_MainWindow myInteractor->setFocus(); setFocusProxy(myInteractor); - myUpdateRateDlg = new SVTK_UpdateRateDlg(myActionsMap[UpdateRate],this,"SVTK_UpdateRateDlg"); - myNonIsometricDlg = new SVTK_NonIsometricDlg(myActionsMap[NonIsometric],this,"SVTK_NonIsometricDlg"); - myCubeAxesDlg = new SVTK_CubeAxesDlg(myActionsMap[GraduatedAxes],this,"SVTK_CubeAxesDlg"); - mySetRotationPointDlg = new SVTK_SetRotationPointDlg(myActionsMap[ChangeRotationPointId],this,"SVTK_SetRotationPointDlg"); + myUpdateRateDlg = new SVTK_UpdateRateDlg(myActionsMap[UpdateRate], this, "SVTK_UpdateRateDlg"); + myNonIsometricDlg = new SVTK_NonIsometricDlg(myActionsMap[NonIsometric], this," SVTK_NonIsometricDlg"); + myCubeAxesDlg = new SVTK_CubeAxesDlg(myActionsMap[GraduatedAxes], this, "SVTK_CubeAxesDlg"); + mySetRotationPointDlg = new SVTK_SetRotationPointDlg(myActionsMap[ChangeRotationPointId], this, "SVTK_SetRotationPointDlg"); + myTextRegionDlg = new SVTK_TextRegionDlg(myActionsMap[TextRegion], this, "SVTK_TextRegionDlg"); + } /*! @@ -576,6 +581,14 @@ SVTK_MainWindow connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onUpdateRate(bool))); myActionsMap[ UpdateRate ] = anAction; + // onTextRegion: Create Text Region + anAction = new QtxAction(tr("MNU_SVTK_TEXT_REGION"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_TEXT_REGION" ) ), + tr( "MNU_SVTK_TEXT_REGION" ), 0, this); + anAction->setStatusTip(tr("DSC_SVTK_TEXT_REGION")); + connect(anAction, SIGNAL(activated()), this, SLOT(onTextRegion())); + myActionsMap[ TextRegion ] = anAction; + // print view anAction = new QtxAction(tr("MNU_PRINT_VIEW"), theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_PRINT_VIEW" ) ), @@ -628,6 +641,7 @@ SVTK_MainWindow myToolBar->addAction( myActionsMap[UpdateRate] ); myToolBar->addAction( myActionsMap[NonIsometric] ); myToolBar->addAction( myActionsMap[GraduatedAxes] ); + myToolBar->addAction( myActionsMap[TextRegion] ); myToolBar->addAction( myActionsMap[PrintId] ); } @@ -857,6 +871,13 @@ SVTK_MainWindow Repaint(); } +void +SVTK_MainWindow +::onTextRegion() +{ + myTextRegionDlg->PublishNew(GetInteractor()); +} + void SVTK_MainWindow ::onUpdateRate(bool theIsActivate) diff --git a/src/SVTK/SVTK_MainWindow.h b/src/SVTK/SVTK_MainWindow.h index 57d9de915..95503a88e 100644 --- a/src/SVTK/SVTK_MainWindow.h +++ b/src/SVTK/SVTK_MainWindow.h @@ -48,6 +48,7 @@ class SVTK_UpdateRateDlg; class SVTK_CubeAxesActor2D; class SVTK_CubeAxesDlg; class SVTK_SetRotationPointDlg; +class SVTK_TextRegionDlg; class VTKViewer_Trihedron; class VTKViewer_Actor; @@ -231,6 +232,8 @@ public: void onNonIsometric(bool theIsActivate); void onGraduatedAxes(bool theIsActivate); + void onTextRegion(); + void onAdjustTrihedron(); void onAdjustCubeAxes(); @@ -252,7 +255,8 @@ public: enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, ChangeRotationPointId, RotationId, FrontId, BackId, TopId, BottomId, LeftId, RightId, ResetId, - ViewTrihedronId, NonIsometric, GraduatedAxes, UpdateRate, PrintId }; + ViewTrihedronId, NonIsometric, GraduatedAxes, UpdateRate, + TextRegion, PrintId }; typedef QMap TActionsMap; SUIT_ViewWindow* myViewWindow; @@ -261,6 +265,7 @@ public: SVTK_UpdateRateDlg* myUpdateRateDlg; SVTK_CubeAxesDlg* myCubeAxesDlg; SVTK_SetRotationPointDlg* mySetRotationPointDlg; + SVTK_TextRegionDlg* myTextRegionDlg; vtkSmartPointer myEventDispatcher; TActionsMap myActionsMap; diff --git a/src/SVTK/SVTK_TextRegionDlg.cxx b/src/SVTK/SVTK_TextRegionDlg.cxx new file mode 100644 index 000000000..45766d8db --- /dev/null +++ b/src/SVTK/SVTK_TextRegionDlg.cxx @@ -0,0 +1,321 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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 +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#include "SVTK_TextRegionDlg.h" + +#include "SVTK_CaptionActor2DWidget.h" +#include "SVTK_RenderWindowInteractor.h" + +#include "SVTK_MainWindow.h" +#include "SVTK_FontWidget.h" + +#include "QtxAction.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + + +/*! + Constructor +*/ +SVTK_TextRegionDlg +::SVTK_TextRegionDlg(QtxAction* theAction, + SVTK_MainWindow* theParent, + const char* theName): + SVTK_DialogBase(theAction, + theParent, + theName), + myMainWindow( theParent ), + myPriority(0.0), + myEventCallbackCommand(vtkCallbackCommand::New()) +{ + myEventCallbackCommand->Delete(); + myEventCallbackCommand->SetClientData(this); + myEventCallbackCommand->SetCallback(SVTK_TextRegionDlg::ProcessEvents); + + setWindowTitle(tr("DLG_TITLE")); + + QVBoxLayout* aFormLayout = new QVBoxLayout( this ); + aFormLayout->setSpacing( 5 ); + aFormLayout->setMargin( 5 ); + { + QGroupBox* aGroupBox = new QGroupBox( this ); + aGroupBox->setTitle( tr( "TEXT_PROPERTIES" ) ); + + QVBoxLayout* aGrLayout = new QVBoxLayout( aGroupBox ); + aGrLayout->setSpacing( 6 ); + aGrLayout->setMargin( 11 ); + { + aGrLayout->setAlignment( Qt::AlignTop ); + + { + SVTK_FontWidget* aWidget = new SVTK_FontWidget(aGroupBox); + aGrLayout->addWidget( aWidget ); + connect(aWidget, SIGNAL(Modified()), SLOT(onAutoApply())); + myFontWidget = aWidget; + } + + { + QTextEdit* aTextEdit = new QTextEdit( aGroupBox ); + aTextEdit->setLineWrapMode( QTextEdit::WidgetWidth ); + aGrLayout->addWidget( aTextEdit ); + connect(aTextEdit, SIGNAL(textChanged()), SLOT(onAutoApply())); + myTextEdit = aTextEdit; + } + } + + aFormLayout->addWidget( aGroupBox ); + } + { + QGroupBox* aGroupBox = new QGroupBox( this ); + QVBoxLayout* aGrLayout = new QVBoxLayout( aGroupBox ); + aGrLayout->setSpacing( 6 ); + aGrLayout->setMargin( 11 ); + + { + aGrLayout->setAlignment( Qt::AlignTop ); + { + QCheckBox* aCheckBox = new QCheckBox( aGroupBox ); + aCheckBox->setText( tr( "AUTO_APPLY" ) ); + aCheckBox->setChecked( TRUE ); + aGrLayout->addWidget( aCheckBox ); + myAutoApplyCheckBox = aCheckBox; + } + } + + aFormLayout->addWidget( aGroupBox ); + } + { + QGroupBox* aGroupBox = new QGroupBox( this ); + QVBoxLayout* aGrLayout = new QVBoxLayout( aGroupBox ); + aGrLayout->setSpacing( 6 ); + aGrLayout->setMargin( 11 ); + + { + aGrLayout->setAlignment( Qt::AlignTop ); + + { + QPushButton* aPushButton = new QPushButton( aGroupBox ); + aPushButton->setText( tr( "OK" ) ); + aGrLayout->addWidget( aPushButton ); + connect(aPushButton, SIGNAL(clicked()), SLOT(onOk())); + } + { + QPushButton* aPushButton = new QPushButton( aGroupBox ); + aPushButton->setText( tr( "APPLY" ) ); + aGrLayout->addWidget( aPushButton ); + connect(aPushButton, SIGNAL(clicked()), SLOT(onApply())); + } + { + QSpacerItem* aSpacer = new QSpacerItem( 157, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); + aGrLayout->addItem( aSpacer ); + } + { + QPushButton* aPushButton = new QPushButton( aGroupBox ); + aPushButton->setText( tr( "CLOSE" ) ); + aGrLayout->addWidget( aPushButton ); + connect(aPushButton, SIGNAL(clicked()), SLOT(onClose())); + } + } + + aFormLayout->addWidget( aGroupBox ); + } +} + +/*! + Destroys the object and frees any allocated resources + */ +SVTK_TextRegionDlg +::~SVTK_TextRegionDlg() +{ + // no need to delete child widgets, Qt does it all for us +} + +/*! + Processes events +*/ +void +SVTK_TextRegionDlg +::ProcessEvents(vtkObject* theObject, + unsigned long theEvent, + void* theClientData, + void* vtkNotUsed(theCallData)) +{ + SVTK_TextRegionDlg* self = reinterpret_cast(theClientData); + + if(theEvent == SVTK_Actor2DWidget::EditEvent){ + SVTK_CaptionActor2DWidget* aWidget = dynamic_cast(theObject); + self->Update( aWidget ); + } +} + +/*! + Update +*/ +void +SVTK_TextRegionDlg +::Update(SVTK_CaptionActor2DWidget* theWidget) +{ + if(!theWidget) + return; + + vtkCaptionActor2D* aCaptionActor2D = theWidget->GetCaptionActor2D(); + if(!aCaptionActor2D) + return; + + myWidget = NULL; // To avoid call of onApply function + + //myFontWidget->SetData(aCaptionActor2D->GetCaptionTextProperty()); + QColor aTitleColor(255, 255, 255); + int aTitleFontFamily = VTK_ARIAL; + bool isTitleBold = false; + bool isTitleItalic = false; + bool isTitleShadow = false; + + vtkTextProperty* aTitleProp = aCaptionActor2D->GetCaptionTextProperty(); + if (aTitleProp !=0) + { + vtkFloatingPointType c[ 3 ]; + aTitleProp->GetColor(c); + aTitleColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255)); + aTitleFontFamily = aTitleProp->GetFontFamily(); + isTitleBold = aTitleProp->GetBold() ? true : false; + isTitleItalic = aTitleProp->GetItalic() ? true : false; + isTitleShadow = aTitleProp->GetShadow() ? true : false; + } + myFontWidget->SetData(aTitleColor, aTitleFontFamily, isTitleBold, + isTitleItalic, isTitleShadow); + + myTextEdit->setText(aCaptionActor2D->GetCaption()); + + myWidget = theWidget; + + show(); +} + +/*! + PublishNew +*/ +void +SVTK_TextRegionDlg +::PublishNew(SVTK_RenderWindowInteractor* theInteractor) +{ + SVTK_CaptionActor2DWidget* aWidget = SVTK::PublishCaptionActor2D(theInteractor->GetDevice()); + + aWidget->AddObserver( SVTK_Actor2DWidget::EditEvent, + myEventCallbackCommand.GetPointer(), + myPriority ); + + Update(aWidget); +} + +/*! + Verify validity of entry data +*/ +bool +SVTK_TextRegionDlg +::onApply() +{ + if(!myWidget) + return false; + + vtkCaptionActor2D* aCaptionActor2D = myWidget->GetCaptionActor2D(); + if(!aCaptionActor2D) + return false; + + QColor aTitleColor(255, 255, 255); + int aTitleFontFamily = VTK_ARIAL; + bool isTitleBold = false; + bool isTitleItalic = false; + bool isTitleShadow = false; + + //myFontWidget->GetData(aCaptionActor2D->GetCaptionTextProperty()); + vtkTextProperty* aCaptionProp = aCaptionActor2D->GetCaptionTextProperty(); + myFontWidget->GetData( aTitleColor, aTitleFontFamily, isTitleBold, + isTitleItalic, isTitleShadow ); + if ( aCaptionProp ) { + aCaptionProp->SetColor(aTitleColor.red() / 255., + aTitleColor.green() / 255., + aTitleColor.blue() / 255.); + aCaptionProp->SetFontFamily(aTitleFontFamily); + aCaptionProp->SetBold(isTitleBold ? 1 : 0); + aCaptionProp->SetItalic(isTitleItalic ? 1 : 0); + aCaptionProp->SetShadow(isTitleShadow ? 1 : 0); + + aCaptionActor2D->SetCaptionTextProperty(aCaptionProp); + } + + aCaptionActor2D->SetCaption(myTextEdit->toPlainText().toLatin1()); + + myMainWindow->Repaint(); + + return true; +} + +/*! + Verify validity of entry data +*/ +bool +SVTK_TextRegionDlg +::onAutoApply() +{ + if(!myAutoApplyCheckBox->isChecked()) + return false; + + return onApply(); +} + +/*! + SLOT called when "Ok" button pressed. +*/ +void +SVTK_TextRegionDlg +::onOk() +{ + done(onApply()); +} + +/*! + SLOT: called when "Close" button pressed. Close dialog +*/ +void +SVTK_TextRegionDlg +::onClose() +{ + reject(); +} diff --git a/src/SVTK/SVTK_TextRegionDlg.h b/src/SVTK/SVTK_TextRegionDlg.h new file mode 100644 index 000000000..dae423a60 --- /dev/null +++ b/src/SVTK/SVTK_TextRegionDlg.h @@ -0,0 +1,98 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 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 +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#ifndef SVTK_TEXT_REGION_DLG_H +#define SVTK_TEXT_REGION_DLG_H + +#include "SVTK_DialogBase.h" + +#include + +class SVTK_MainWindow; +class SVTK_RenderWindowInteractor; + +class SVTK_FontWidget; +class SVTK_CaptionActor2DWidget; + +class QTextEdit; +class QCheckBox; + +class vtkCallbackCommand; +class vtkObject; + + +//---------------------------------------------------------------------------- +class SVTK_TextRegionDlg : public SVTK_DialogBase +{ + Q_OBJECT; + +public: + SVTK_TextRegionDlg(QtxAction* theAction, + SVTK_MainWindow* theParent, + const char* theName); + + ~SVTK_TextRegionDlg(); + + void PublishNew(SVTK_RenderWindowInteractor* theInteractor); + +private slots: + void onOk(); + bool onApply(); + bool onAutoApply(); + void onClose(); + + private: + //---------------------------------------------------------------------------- + SVTK_MainWindow *myMainWindow; + + // Priority at which events are processed + vtkFloatingPointType myPriority; + + // Used to process events + vtkSmartPointer myEventCallbackCommand; + + // Description: + // Main process event method + static + void + ProcessEvents(vtkObject* object, + unsigned long event, + void* clientdata, + void* calldata); + + void Update(SVTK_CaptionActor2DWidget* theWidget); + + SVTK_CaptionActor2DWidget* myWidget; + SVTK_FontWidget* myFontWidget; + QCheckBox* myAutoApplyCheckBox; + QTextEdit* myTextEdit; + +}; + + +#endif // SVTK_TEXT_REGION_DLG_H diff --git a/src/SVTK/resources/SVTK_images.ts b/src/SVTK/resources/SVTK_images.ts index 6e4a9d1d7..6330af349 100644 --- a/src/SVTK/resources/SVTK_images.ts +++ b/src/SVTK/resources/SVTK_images.ts @@ -13,6 +13,10 @@ ICON_UPDATE_RATE view_update_rate.png + + ICON_TEXT_REGION + view_text.png + ICON_PRINT_VIEW view_print.png diff --git a/src/SVTK/resources/SVTK_msg_en.ts b/src/SVTK/resources/SVTK_msg_en.ts index 49b65d933..e48e72b8f 100644 --- a/src/SVTK/resources/SVTK_msg_en.ts +++ b/src/SVTK/resources/SVTK_msg_en.ts @@ -265,6 +265,14 @@ MNU_SVTK_UPDATE_RATE Update rate + + MNU_SVTK_TEXT_REGION + Text Zone + + + DSC_SVTK_TEXT_REGION + Text Zone + MNU_PRINT_VIEW Print view @@ -344,6 +352,33 @@ Set Rotation Point + + SVTK_TextRegionDlg + + DLG_TITLE + Text Zone + + + TEXT_PROPERTIES + Properties + + + AUTO_APPLY + Auto Apply + + + OK + OK + + + APPLY + Apply + + + CLOSE + Close + + SVTK_UpdateRateDlg