From 801c46619b557764c571495e7c117d7247932e73 Mon Sep 17 00:00:00 2001 From: sln Date: Mon, 3 Feb 2014 11:11:39 +0000 Subject: [PATCH] Merging with PLEX actor --- src/SUIT/SUIT_TreeModel.cxx | 10 ++ src/SUIT/SUIT_TreeModel.h | 4 +- src/SVTK/Makefile.am | 2 + src/SVTK/Plot3d_Actor.cxx | 317 +++++++++++++++++++++++++++++++++++ src/SVTK/Plot3d_Actor.h | 88 ++++++++++ src/SVTK/SVTK_ViewWindow.cxx | 23 ++- 6 files changed, 436 insertions(+), 8 deletions(-) create mode 100644 src/SVTK/Plot3d_Actor.cxx create mode 100644 src/SVTK/Plot3d_Actor.h diff --git a/src/SUIT/SUIT_TreeModel.cxx b/src/SUIT/SUIT_TreeModel.cxx index 95ccb9e6b..e8e38e179 100755 --- a/src/SUIT/SUIT_TreeModel.cxx +++ b/src/SUIT/SUIT_TreeModel.cxx @@ -1230,6 +1230,16 @@ void SUIT_TreeModel::updateItem( SUIT_TreeModel::TreeItem* item ) emit dataChanged( firstIdx, lastIdx ); } +void SUIT_TreeModel::updateItem( SUIT_DataObject* obj) +{ + if(obj) + { + QModelIndex firstIdx = index( obj, 0 ); + QModelIndex lastIdx = index( obj, columnCount() - 1 ); + emit dataChanged( firstIdx, lastIdx ); + } +} + /*! \brief Remove tree item (recursively). \param item tree item to be removed diff --git a/src/SUIT/SUIT_TreeModel.h b/src/SUIT/SUIT_TreeModel.h index 9d1d7a0cb..94d336091 100755 --- a/src/SUIT/SUIT_TreeModel.h +++ b/src/SUIT/SUIT_TreeModel.h @@ -151,7 +151,9 @@ public: int row, int column, const QModelIndex& parent ); bool getObjects( const QMimeData* data, QList& ) const; void setDropAccepted( const bool ); - + + void updateItem( SUIT_DataObject* object); + public slots: virtual void updateTree( const QModelIndex& ); virtual void updateTree( SUIT_DataObject* = 0 ); diff --git a/src/SVTK/Makefile.am b/src/SVTK/Makefile.am index 52bfe84e6..4578083b3 100755 --- a/src/SVTK/Makefile.am +++ b/src/SVTK/Makefile.am @@ -61,6 +61,7 @@ salomeinclude_HEADERS= \ SVTK_ImageWriterMgr.h \ SVTK_FrameBuffer.h\ SVTK_DoubleSpinBox.h \ + Plot3d_Actor.h \ Plot3d_ViewManager.h \ Plot3d_ViewModel.h @@ -98,6 +99,7 @@ dist_libSVTK_la_SOURCES= \ SVTK_ImageWriterMgr.cxx \ SVTK_FrameBuffer.cxx \ SVTK_DoubleSpinBox.cxx \ + Plot3d_Actor.cxx \ Plot3d_ViewManager.cxx \ Plot3d_ViewModel.cxx diff --git a/src/SVTK/Plot3d_Actor.cxx b/src/SVTK/Plot3d_Actor.cxx new file mode 100644 index 000000000..f09f1e840 --- /dev/null +++ b/src/SVTK/Plot3d_Actor.cxx @@ -0,0 +1,317 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 "Plot3d_Actor.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +vtkStandardNewMacro(Plot3d_Actor); + +//============================================================================= +// Function : Plot3d_Actor +// Purpose : Constructor +//============================================================================= +Plot3d_Actor::Plot3d_Actor() +{ + myIsDistance = false; + + myStartPoint = 0; + myEndPoint = 0; + + // Scalar bar + myToDisplayScalarBar = false; + + myScalarBarActor = vtkScalarBarActor::New(); + myScalarBarActor->SetVisibility( false ); + + // Title props + QColor aTextColor = Qt::white; + + vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New(); + aScalarBarTitleProp->SetColor( aTextColor.redF(), aTextColor.greenF(), aTextColor.blueF() ); + aScalarBarTitleProp->SetFontFamilyToArial(); + int aSize = 24; + aScalarBarTitleProp->SetFontSize( aSize ); + myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp ); + aScalarBarTitleProp->Delete(); + + // Label props + vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New(); + aScalarBarLabelProp->SetColor( aTextColor.redF(), aTextColor.greenF(), aTextColor.blueF() ); + aScalarBarLabelProp->SetFontFamilyToArial(); + myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp ); + aScalarBarLabelProp->Delete(); + + // Position + double aXPos = 0.01, aYPos = 0.1; + myScalarBarActor->SetPosition( aXPos, aYPos ); + + // Width + double aWidth = 0.10, aHeight = 0.80; + myScalarBarActor->SetWidth( aWidth ); + myScalarBarActor->SetHeight( aHeight ); + + // Number of labels and Maximum number of colors + myScalarBarActor->SetNumberOfLabels( 5 ); + myScalarBarActor->SetMaximumNumberOfColors( 99 ); + + // ScalarBar widget + myScalarBarWg = vtkScalarBarWidget::New(); + myScalarBarWg->SetScalarBarActor( myScalarBarActor.GetPointer() ); + + // Property + this->GetProperty()->ShadingOff(); + this->GetProperty()->LightingOff(); +} + +//============================================================================= +// Function : ~Plot3d_Actor +// Purpose : Destructor +//============================================================================= +Plot3d_Actor::~Plot3d_Actor() +{ +} + +//============================================================================= +// Function : SetVisibility +// Purpose : +//============================================================================= +void Plot3d_Actor::SetVisibility( int theVisibility ) +{ + Superclass::SetVisibility( theVisibility ); + + myScalarBarActor->SetVisibility( GetVisibility() && myToDisplayScalarBar ); + + if ( !theVisibility || !myScalarBarActor->GetLookupTable() || !myToDisplayScalarBar ) + myScalarBarWg->EnabledOff(); + else + myScalarBarWg->EnabledOn(); +} + +//============================================================================= +// Function : SetMapper +// Purpose : +//============================================================================= +void Plot3d_Actor::SetMapper( vtkMapper* theMapper ) +{ + Superclass::SetMapper(theMapper); +} + +//============================================================================= +// Function : AddToRender +// Purpose : +//============================================================================= +void Plot3d_Actor::AddToRender( vtkRenderer* theRenderer ) +{ + Superclass::AddToRender( theRenderer ); + + if ( vtkRenderWindow *win = theRenderer->GetRenderWindow() ) + { + if ( vtkRenderWindowInteractor *interactor = win->GetInteractor() ) + { + myScalarBarWg->SetInteractor( interactor ); + if ( myToDisplayScalarBar ) + myScalarBarWg->EnabledOn(); + } + } + + theRenderer->AddActor( myScalarBarActor.GetPointer() ); +} + +//============================================================================= +// Function : RemoveFromRender +// Purpose : +//============================================================================= +void Plot3d_Actor::RemoveFromRender( vtkRenderer* theRenderer ) +{ + myScalarBarWg->EnabledOff(); + theRenderer->RemoveActor( myScalarBarActor.GetPointer() ); + + Superclass::RemoveFromRender( theRenderer ); +} + +//============================================================================= +// Function : GetScalarBarActor +// Purpose : +//============================================================================= +vtkSmartPointer Plot3d_Actor::GetScalarBarActor() const +{ + return myScalarBarActor; +} + +//============================================================================= +// Function : DisplayScalarBar +// Purpose : +//============================================================================= +void Plot3d_Actor::DisplayScalarBar( const bool theToDisplay ) +{ + myToDisplayScalarBar = theToDisplay; + myScalarBarActor->SetVisibility( GetVisibility() && theToDisplay ); + myScalarBarWg->SetEnabled( GetVisibility() && theToDisplay ? 1 : 0 ); +} + +//============================================================================= +// Function : Build +// Purpose : +//============================================================================= +void Plot3d_Actor::Build( const int theNX, + const int theNY, + const QList& thePntList, + const QList& theValueList, + const double theMinValue, + const double theMaxValue ) +{ + vtkPolyData* aPointSet = vtkPolyData::New(); + aPointSet->Allocate( ( theNX - 1 ) * ( theNY - 1 ) ); + + vtkPoints* aPoints = vtkPoints::New(); + QListIterator aPntIter( thePntList ); + while( aPntIter.hasNext() ) + { + const QPointF& aPnt = aPntIter.next(); + aPoints->InsertNextPoint( aPnt.x(), aPnt.y(), 0 ); + } + aPointSet->SetPoints( aPoints ); + + vtkIdType pts[ 4 ]; + for( int i = 0; i < theNX - 1; i++ ) + { + for( int j = 0; j < theNY - 1; j++ ) + { + pts[0] = j + theNY * i; + pts[1] = j + theNY * i + 1; + pts[2] = j + theNY * ( i + 1 ) + 1; + pts[3] = j + theNY * ( i + 1 ); + aPointSet->InsertNextCell( VTK_QUAD, 4, pts ); + } + } + + vtkFloatArray* aFloatArray = vtkFloatArray::New(); + QListIterator aValueIter( theValueList ); + while( aValueIter.hasNext() ) + { + const double aValue = aValueIter.next(); + aFloatArray->InsertNextTuple1( aValue ); + } + + vtkPointData* aPointData = aPointSet->GetPointData(); + aPointData->SetScalars( aFloatArray ); + + vtkWarpScalar* aWarpScalar = vtkWarpScalar::New(); + aWarpScalar->SetInput( aPointSet ); + aWarpScalar->SetScaleFactor( 1 ); + + vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New(); + aMapper->SetInput( aWarpScalar->GetPolyDataOutput() ); + aMapper->SetScalarRange( theMinValue, theMaxValue ); + + SetMapper( aMapper ); + + vtkLookupTable* aLookupTable = vtkLookupTable::New(); + aLookupTable->SetHueRange( 0.66667, 0.0 ); + + aMapper->SetLookupTable( aLookupTable ); + myScalarBarActor->SetLookupTable( aLookupTable ); + + aPoints->Delete(); + aFloatArray->Delete(); + aPointSet->Delete(); +} + +//============================================================================= +// Function : SetUnits +// Purpose : +//============================================================================= +void Plot3d_Actor::SetUnits( const QString& theUnits ) +{ + myUnits = theUnits; +} + +//============================================================================= +// Function : GetUnits +// Purpose : +//============================================================================= +QString Plot3d_Actor::GetUnits() const +{ + return myUnits; +} + +//============================================================================= +// Function : SetIsDistance +// Purpose : +//============================================================================= +void Plot3d_Actor::SetIsDistance( const bool theIsDistance ) +{ + myIsDistance = theIsDistance; +} + +//============================================================================= +// Function : GetIsDistance +// Purpose : +//============================================================================= +bool Plot3d_Actor::GetIsDistance() const +{ + return myIsDistance; +} + +//============================================================================= +// Function : SetBoundaryPoints +// Purpose : +//============================================================================= +void Plot3d_Actor::SetBoundaryPoints( const int theStartPoint, + const int theEndPoint ) +{ + myStartPoint = theStartPoint; + myEndPoint = theEndPoint; +} + +//============================================================================= +// Function : GetBoundaryPoints +// Purpose : +//============================================================================= +void Plot3d_Actor::GetBoundaryPoints( int& theStartPoint, + int& theEndPoint ) +{ + theStartPoint = myStartPoint; + theEndPoint = myEndPoint; +} + +//============================================================================= +// Function : SetTextColor +// Purpose : +//============================================================================= +void Plot3d_Actor::SetTextColor( const QColor& theColor ) +{ + vtkTextProperty* aScalarBarTitleProp = myScalarBarActor->GetTitleTextProperty(); + aScalarBarTitleProp->SetColor( theColor.redF(), theColor.greenF(), theColor.blueF() ); + + vtkTextProperty* aScalarBarLabelProp = myScalarBarActor->GetLabelTextProperty(); + aScalarBarLabelProp->SetColor( theColor.redF(), theColor.greenF(), theColor.blueF() ); +} diff --git a/src/SVTK/Plot3d_Actor.h b/src/SVTK/Plot3d_Actor.h new file mode 100644 index 000000000..dfc98ea8a --- /dev/null +++ b/src/SVTK/Plot3d_Actor.h @@ -0,0 +1,88 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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 PLOT3D_VIEWMODEL_H +#define PLOT3D_VIEWMODEL_H + +#include "SVTK.h" + +#include "SALOME_Actor.h" + +#include +#include +#include +#include + +class vtkScalarBarActor; +class vtkScalarBarWidget; + +/* + Class : Plot3d_Actor + Descrtiption : Class for presentation of the Plot3d graph +*/ + +class SVTK_EXPORT Plot3d_Actor : public SALOME_Actor +{ +public: + static Plot3d_Actor* New(); + vtkTypeMacro( Plot3d_Actor, SALOME_Actor ); + + Plot3d_Actor(); + virtual ~Plot3d_Actor(); + + virtual void AddToRender( vtkRenderer* theRender ); + virtual void RemoveFromRender(vtkRenderer* theRendere); + + virtual void SetVisibility( int ); + + virtual void SetMapper( vtkMapper* theMapper ); + + vtkSmartPointer GetScalarBarActor() const; + void DisplayScalarBar( const bool ); + + void Build( const int theNX, + const int theNY, + const QList& thePntList, + const QList& theValueList, + const double theMinValue, + const double theMaxValue ); + + void SetUnits( const QString& ); + QString GetUnits() const; + + void SetIsDistance( const bool ); + bool GetIsDistance() const; + + void SetBoundaryPoints( const int, const int ); + void GetBoundaryPoints( int&, int& ); + + void SetTextColor( const QColor& theColor ); + +protected: + vtkSmartPointer myScalarBarActor; + vtkSmartPointer myScalarBarWg; + bool myToDisplayScalarBar; + + QString myUnits; + bool myIsDistance; + + int myStartPoint; + int myEndPoint; +}; + +#endif diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 30ecde209..b029798e7 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -116,6 +116,7 @@ SVTK_ViewWindow::SVTK_ViewWindow(SUIT_Desktop* theDesktop): myDumpImage(QImage()), myStandardInteractorStyle(SVTK_InteractorStyle::New()), myKeyFreeInteractorStyle(SVTK_KeyFreeInteractorStyle::New()), + myViewsAction( NULL ), myMode2D( false ) { setWindowFlags( windowFlags() & ~Qt::Window ); @@ -155,8 +156,11 @@ void SVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel) myToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_LABEL"), -1, this ); myRecordingToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_RECORD_LABEL"), -1, this ); - createActions( SUIT_Session::session()->activeApplication()->resourceMgr() ); - createToolBar(); + if( SUIT_Session* aSession = SUIT_Session::session() ) + { + createActions( aSession->activeApplication()->resourceMgr() ); + createToolBar(); + } SetEventDispatcher(myInteractor->GetDevice()); myInteractor->setBackgroundRole( QPalette::NoRole );//NoBackground @@ -727,11 +731,16 @@ void SVTK_ViewWindow::onMode2D( bool theOn ) { myMode2D = theOn; - getAction( ViewTrihedronId )->setVisible( !theOn ); - getAction( ChangeRotationPointId )->setVisible( !theOn ); - getAction( RotationId )->setVisible( !theOn ); - myViewsAction->setVisible( !theOn ); - getAction( ResetId )->setVisible( !theOn ); + if( getAction( ViewTrihedronId ) ) + getAction( ViewTrihedronId )->setVisible( !theOn ); + if( getAction( ViewTrihedronId ) ) + getAction( ViewTrihedronId )->setVisible( !theOn ); + if( getAction( ChangeRotationPointId ) ) + getAction( ChangeRotationPointId )->setVisible( !theOn ); + if( myViewsAction ) + myViewsAction->setVisible( !theOn ); + if( getAction( ViewTrihedronId ) ) + getAction( ViewTrihedronId )->setVisible( !theOn ); SVTK_ComboAction* a = ::qobject_cast( toolMgr()->action( ProjectionModeId ) ); if( a ) -- 2.39.2