From f83c01fccd62b4e0baa3012ab0ad0291e0d92ea9 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 1 Dec 2005 10:06:01 +0000 Subject: [PATCH] This commit was generated by cvs2git to create branch 'BR-D5-38-2003'. Cherrypick from master 2005-12-01 10:05:59 UTC asl 'Improvement: now in rules you can use "canBeDisplayed" parameter. It is true, if current object can be displayed in active viewer. The result of this check is calculated by new virtual method LightApp_Displayer::canBeDisplayed. GEOM, SMESH, VISU overrides it in order to provide information, what object can be displayed in what viewer': src/VISUGUI/VisuGUI_Displayer.cxx src/VISUGUI/VisuGUI_Displayer.h --- src/VISUGUI/VisuGUI_Displayer.cxx | 241 ++++++++++++++++++++++++++++++ src/VISUGUI/VisuGUI_Displayer.h | 61 ++++++++ 2 files changed, 302 insertions(+) create mode 100644 src/VISUGUI/VisuGUI_Displayer.cxx create mode 100644 src/VISUGUI/VisuGUI_Displayer.h diff --git a/src/VISUGUI/VisuGUI_Displayer.cxx b/src/VISUGUI/VisuGUI_Displayer.cxx new file mode 100644 index 00000000..bcfffa77 --- /dev/null +++ b/src/VISUGUI/VisuGUI_Displayer.cxx @@ -0,0 +1,241 @@ +// VISU VISUGUI : Displayer for VISU module +// +// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VisuGUI_Displayer.cxx +// Author : Alexander SOLOVYOV +// Module : VISU +// $Header: /home/server/cvs/VISU/VISU_SRC/src/VISUGUI/VisuGUI_Displayer.cxx + +#include "VisuGUI_Displayer.h" +#include "VisuGUI_Tools.h" +#include "VISU_Actor.h" + +#include +#include + +#include +#include +#include + +#include +#include + +#include "VISU_ViewManager_i.hh" + +VisuGUI_Displayer::VisuGUI_Displayer( SalomeApp_Application* app ) +: LightApp_Displayer(), + myApp( app ) +{ +} + +VisuGUI_Displayer::~VisuGUI_Displayer() +{ +} + +SALOME_Prs* VisuGUI_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame ) +{ + SALOME_Prs* prs = 0; + + SALOME_View* aViewFrame = theViewFrame ? theViewFrame : GetActiveView(); + SalomeApp_Study* study = dynamic_cast( myApp->activeStudy() ); + + if ( study && aViewFrame ) + { + _PTR(SObject) obj = study->studyDS()->FindObjectID( entry.latin1() ); + CORBA::Object_var anObj = VISU::ClientSObjectToObject( obj ); + if( CORBA::is_nil( anObj ) ) + return 0; + + SVTK_Viewer* vtk_viewer = dynamic_cast( aViewFrame ); + if( vtk_viewer ) + { + SVTK_ViewWindow* wnd = dynamic_cast( vtk_viewer->getViewManager()->getActiveView() ); + if( wnd ) + { + VISU::Prs3d_i* thePrs = dynamic_cast( VISU::GetServant( anObj ).in() ); + if( thePrs ) + { + buildPrs3d( wnd, thePrs ); + prs = LightApp_Displayer::buildPresentation( entry, aViewFrame ); + } + } + } + + SPlot2d_Viewer* plot_viewer = dynamic_cast( aViewFrame ); + if( plot_viewer ) + { + Plot2d_ViewWindow* wnd = dynamic_cast( plot_viewer->getViewManager()->getActiveView() ); + if( !wnd ) + return 0; + + VISU::Curve_i* aCurve = dynamic_cast( VISU::GetServant( anObj ).in() ); + SPlot2d_Prs* iprs = 0; + if( aCurve ) + iprs = buildCurve( wnd, aCurve ); + + VISU::Container_i* aCont = dynamic_cast( VISU::GetServant( anObj ).in() ); + if( aCont ) + iprs = buildContainer( wnd, aCont ); + + VISU::Table_i* aTable = dynamic_cast(VISU::GetServant( anObj ).in() ); + if( aTable ) + iprs = buildTable( wnd, aTable ); + + if( iprs ) + prs = new SPlot2d_Prs( iprs ); + + if( prs ) + UpdatePrs( prs ); + } + } + return prs; +} + +void VisuGUI_Displayer::buildPrs3d( SVTK_ViewWindow* wnd, VISU::Prs3d_i* thePrs ) const +{ + VISU_Actor* newAct = VISU::FindActor( wnd, thePrs ); + if( !newAct ) + { + VISU_Actor* a = thePrs->CreateActor(); + if( a ) + newAct = a->GetParent(); + } + if( newAct && newAct ) + { + wnd->AddActor( newAct ); + wnd->Repaint(); + } +} + +bool VisuGUI_Displayer::addCurve( SPlot2d_Prs* prs, Plot2d_ViewWindow* wnd, VISU::Curve_i* c ) const +{ + if( !prs || !wnd || !c ) + return false; + + QString entry = c->GetSObject()->GetID(); + SPlot2d_Viewer* vv = dynamic_cast( wnd->getModel() ); + if( !vv ) + return false; + + SPlot2d_Curve* curve = vv->getCurveByIO( vv->FindIObject( entry.latin1() ) ); + if( !curve ) + { + curve = c->CreatePresentation(); + VISU::UpdateCurve( c, 0, curve, VISU::eDisplay ); + } + if( curve ) + prs->AddObject( curve ); + + return curve!=0; +} + +SPlot2d_Prs* VisuGUI_Displayer::buildCurve( Plot2d_ViewWindow* wnd, VISU::Curve_i* c ) const +{ + SPlot2d_Prs* prs = new SPlot2d_Prs(); + if( !addCurve( prs, wnd, c ) ) + { + delete prs; + prs = 0; + } + return prs; +} + +SPlot2d_Prs* VisuGUI_Displayer::buildContainer( Plot2d_ViewWindow* wnd, VISU::Container_i* c ) const +{ + SPlot2d_Prs* prs = new SPlot2d_Prs(); + + int nbCurves = c ? c->GetNbCurves() : 0; + for( int k=1; k<=nbCurves; k++ ) + { + VISU::Curve_i* theCurve = c->GetCurve( k ); + if( theCurve && theCurve->IsValid() ) + addCurve( prs, wnd, theCurve ); + } + if( prs->getCurves().count()==0 ) + { + delete prs; + prs = 0; + } + return prs; +} + +SPlot2d_Prs* VisuGUI_Displayer::buildTable( Plot2d_ViewWindow* wnd, VISU::Table_i* t ) const +{ + SPlot2d_Prs* prs = new SPlot2d_Prs(); + SalomeApp_Study* study = dynamic_cast( myApp->activeStudy() ); + if( !study ) + return prs; + + _PTR(SObject) TableSO = study->studyDS()->FindObjectID( t->GetEntry().latin1() ); + + if( !TableSO ) + return prs; + + _PTR(ChildIterator) Iter = study->studyDS()->NewChildIterator( TableSO ); + for( ; Iter->More(); Iter->Next() ) + { + CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() ); + if( !CORBA::is_nil( childObject ) ) + { + CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject ); + if( !CORBA::is_nil( aCurve ) ) + { + VISU::Curve_i* theCurve = dynamic_cast(VISU::GetServant(aCurve).in()); + addCurve( prs, wnd, theCurve ); + } + } + } + if( prs->getCurves().count()==0 ) + { + delete prs; + prs = 0; + } + return prs; +} + +bool VisuGUI_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const +{ + SalomeApp_Study* study = dynamic_cast( myApp->activeStudy() ); + if( !study ) + return false; + + _PTR(SObject) obj = study->studyDS()->FindObjectID( entry.latin1() ); + CORBA::Object_var anObj = VISU::ClientSObjectToObject( obj ); + if( CORBA::is_nil( anObj ) ) + return false; + + if( viewer_type==SVTK_Viewer::Type() ) + { + VISU::Prs3d_i* thePrs = dynamic_cast( VISU::GetServant( anObj ).in() ); + return thePrs; + } + else if( viewer_type==SPlot2d_Viewer::Type() ) + { + VISU::Curve_i* aCurve = dynamic_cast( VISU::GetServant( anObj ).in() ); + VISU::Container_i* aCont = dynamic_cast( VISU::GetServant( anObj ).in() ); + VISU::Table_i* aTable = dynamic_cast(VISU::GetServant( anObj ).in() ); + return aCurve || aCont || aTable; + } + else + return false; +} diff --git a/src/VISUGUI/VisuGUI_Displayer.h b/src/VISUGUI/VisuGUI_Displayer.h new file mode 100644 index 00000000..f762ba0a --- /dev/null +++ b/src/VISUGUI/VisuGUI_Displayer.h @@ -0,0 +1,61 @@ +// VISU VISUGUI : Displayer for VISU module +// +// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VisuGUI_Displayer.h +// Author : Alexander SOLOVYOV +// Module : VISU +// $Header: /home/server/cvs/VISU/VISU_SRC/src/VISUGUI/VisuGUI_Displayer.h + +#ifndef VISUGUI_DISPLAYER_HEADER +#define VISUGUI_DISPLAYER_HEADER + +#include +#include +#include + +class SalomeApp_Application; +class SVTK_ViewWindow; +class Plot2d_ViewWindow; +class SPlot2d_Prs; + +class VisuGUI_Displayer : public LightApp_Displayer +{ +public: + VisuGUI_Displayer( SalomeApp_Application* ); + ~VisuGUI_Displayer(); + + virtual SALOME_Prs* buildPresentation( const QString&, SALOME_View* = 0 ); + virtual bool canBeDisplayed( const QString& /*entry*/, const QString& /*viewer_type*/ ) const; + +protected: + bool addCurve ( SPlot2d_Prs*, Plot2d_ViewWindow*, VISU::Curve_i* ) const; + virtual void buildPrs3d ( SVTK_ViewWindow*, VISU::Prs3d_i* ) const; + virtual SPlot2d_Prs* buildCurve ( Plot2d_ViewWindow*, VISU::Curve_i* ) const; + virtual SPlot2d_Prs* buildContainer( Plot2d_ViewWindow*, VISU::Container_i* ) const; + virtual SPlot2d_Prs* buildTable ( Plot2d_ViewWindow*, VISU::Table_i* ) const; + +private: + SalomeApp_Application* myApp; +}; + +#endif -- 2.39.2