From: smh Date: Mon, 12 Apr 2004 08:54:36 +0000 (+0000) Subject: VISU::ViewManager methods adapted for event posting X-Git-Tag: mergeto_Event_Server_20Apr04~14 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ca15acd57e7cb121017beb2eab051986717b8e04;p=modules%2Fvisu.git VISU::ViewManager methods adapted for event posting --- diff --git a/src/VISUGUI/VisuGUI.cxx b/src/VISUGUI/VisuGUI.cxx index 71087e39..6fd8031a 100644 --- a/src/VISUGUI/VisuGUI.cxx +++ b/src/VISUGUI/VisuGUI.cxx @@ -679,11 +679,17 @@ bool VisuGUI::ProcessEvent(SALOME_Event* se) VISU_Event* ve = dynamic_cast( se ); if ( ve ) { switch ( se->getType() ) { + case VISU_Event::Create3DView: + case VISU_Event::CreateTableView: + case VISU_Event::CreateXYPlot: + case VISU_Event::DestroyView: + OnViewEvent( ve ); + break; case VISU_Event::CreateTestViewEvent: - VisuGUI::CreateTestView(); + CreateTestView(); break; case VISU_Event::ShowTestObjectEvent: - VisuGUI::ShowTestObject(); + ShowTestObject(); break; } return true; @@ -4002,6 +4008,56 @@ void VisuGUI::SetActiveDialogBox(QDialog* aDlg) return ; } +// SAN - QT_EVENT prototype +// SALOME event handlers +//=========================================================== +/*! + * Function: VisuGUI::OnViewEvent + * Purpose: Handles events posted by VISU_ViewManager_i + */ +//=========================================================== +void VisuGUI::OnViewEvent( VISU_Event* e ) +{ + if ( !e ) + return; + + VISU_ViewEvent* ve = dynamic_cast( e ); + if ( !ve ) + return; + + VISU::ViewManager_i* aVmImpl = dynamic_cast( ve->sender()); + if ( !aVmImpl ) + return; + + switch( ve->getType() ) { + case VISU_Event::Create3DView: + { + VISU::View3D_ptr aView = aVmImpl->OnCreate3DView(); + ve->setView( aView ); + break; + } + case VISU_Event::CreateTableView: + { + VISU::Table_var aTable = VISU::Table::_narrow( ve->getArg() ); + VISU::TableView_ptr aView = aVmImpl->OnCreateTableView( aTable.in() ); + ve->setView( aView ); + break; + } + case VISU_Event::CreateXYPlot: + { + VISU::XYPlot_ptr aView = aVmImpl->OnCreateXYPlot(); + ve->setView( aView ); + break; + } + case VISU_Event::DestroyView: + aVmImpl->OnDestroy( ve->getView() ); + ve->setView( VISU::View::_nil() ); + break; + default: + break; + } +} + void VisuGUI::CreateTestView() { QAD_Desktop* desktop = VisuGUI::GetDesktop(); @@ -4057,3 +4113,4 @@ void VisuGUI::ShowTestObject() vf->getRenderer()->AddActor(sphere); vf->Repaint(); } +// SAN - QT_EVENT prototype diff --git a/src/VISUGUI/VisuGUI.h b/src/VISUGUI/VisuGUI.h index f9c7dec4..38ea0d11 100644 --- a/src/VISUGUI/VisuGUI.h +++ b/src/VISUGUI/VisuGUI.h @@ -42,6 +42,8 @@ class VTKViewer_ViewFrame; #include "VISUConfig.hh" +class VISU_Event; +class VISU_ViewEvent; class VISU_Actor; class VISU_MeshAct; class VISU_ScalarMapAct; @@ -95,8 +97,6 @@ class VisuGUI : public SALOMEGUI{ static SALOMEDS::Study_var GetStudyDocument(); static SALOMEDS::StudyBuilder_var NewBuilder(); static VISU::Storable::TRestoringMap getMapOfValue(SALOMEDS::SObject_var theSObject); - static void CreateTestView(); - static void ShowTestObject(); static VISU::Result_i* CreatePresent(SALOMEDS::SObject_var theField, VISU::Result_var& theResult); @@ -271,6 +271,15 @@ public slots: void SelectionInfo(); +private: + // SAN - QT_EVENT prototype + // SALOME event handlers + void OnViewEvent( VISU_Event* e ); + + void CreateTestView(); + void ShowTestObject(); + // SAN - QT_EVENT prototype + private : QDialog* myActiveDialogBox; int myState ; diff --git a/src/VISU_Event/Makefile.in b/src/VISU_Event/Makefile.in index e0d7b858..9a74fd18 100644 --- a/src/VISU_Event/Makefile.in +++ b/src/VISU_Event/Makefile.in @@ -42,6 +42,9 @@ LIB = libVISUEvent.la LIB_SRC = \ VISU_Event.cxx +LIB_CLIENT_IDL = SALOME_GenericObj.idl \ + VISU_Gen.idl + # additionnal information to compil and link file CPPFLAGS += $(QT_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome diff --git a/src/VISU_Event/VISU_Event.cxx b/src/VISU_Event/VISU_Event.cxx index d0df7c1d..3c656960 100644 --- a/src/VISU_Event/VISU_Event.cxx +++ b/src/VISU_Event/VISU_Event.cxx @@ -34,16 +34,86 @@ * Constructor */ //=========================================================== -VISU_Event::VISU_Event( int eventType, bool wait, bool autoRelease ) : SALOME_Event ( eventType, wait, autoRelease ) +VISU_Event::VISU_Event( int eventType, bool wait, VISU::Base_i* aSender, bool autoRelease ) +: SALOME_Event ( eventType, wait, autoRelease ), + mySender( aSender ) { } //=========================================================== /*! - * VISU_Event::VISU_Event + * VISU_Event::~VISU_Event * Destructor */ //=========================================================== VISU_Event::~VISU_Event() { } + +//=========================================================== +/*! + * VISU_ViewEvent::VISU_ViewEvent + * Constructor + */ +//=========================================================== +VISU_ViewEvent::VISU_ViewEvent( int eventType, bool wait, VISU::Base_i* aSender, bool autoRelease ) +: VISU_Event ( eventType, wait, aSender, autoRelease ) +{ + myArg = VISU::Base::_nil(); + myView = VISU::View::_nil(); +} + +//=========================================================== +/*! + * VISU_ViewEvent::~VISU_ViewEvent + * Destructor + */ +//=========================================================== +VISU_ViewEvent::~VISU_ViewEvent() +{ +} + +//=========================================================== +/*! + * Function: VISU_ViewEvent::SetArg + * Purpose: Sets argument of view creation + */ +//=========================================================== +void VISU_ViewEvent::setArg( VISU::Base_ptr theArg ) +{ + myArg = theArg; +} + +//=========================================================== +/*! + * Function: VISU_ViewEvent::GetArg + * Purpose: Returns argument of view creation + */ +//=========================================================== +VISU::Base_ptr VISU_ViewEvent::getArg() +{ + return myArg; +} + +//=========================================================== +/*! + * Function: VISU_ViewEvent::SetView + * Purpose: + */ +//=========================================================== +void VISU_ViewEvent::setView( VISU::View_ptr theView ) +{ + myView = theView; +} + +//=========================================================== +/*! + * Function: VISU_ViewEvent::GetView + * Purpose: + */ +//=========================================================== +VISU::View_ptr VISU_ViewEvent::getView() +{ + return myView; +} + diff --git a/src/VISU_Event/VISU_Event.h b/src/VISU_Event/VISU_Event.h index f535ef9c..5db95716 100644 --- a/src/VISU_Event/VISU_Event.h +++ b/src/VISU_Event/VISU_Event.h @@ -31,6 +31,8 @@ #include "SALOME_Event.hxx" +#include "VISUConfig.hh" + // VISU event types: 10000...10999 #define VISU_START_EVENT 10000 @@ -38,14 +40,39 @@ class VISU_Event : public SALOME_Event { public: enum { - CreateTestViewEvent = VISU_START_EVENT, + Create3DView = VISU_START_EVENT, + CreateTableView, + CreateXYPlot, + DestroyView, + // san - test events + CreateTestViewEvent, ShowTestObjectEvent, + // san - test events LastEvent = VISU_START_EVENT + 1000 }; - VISU_Event( int eventType, bool wait, bool autoRelease = false ); + VISU_Event( int eventType, bool wait, VISU::Base_i* sender = 0, bool autoRelease = false ); virtual ~VISU_Event(); - // Custom data can be added here... + VISU::Base_i* sender() { return mySender; } + +private: + VISU::Base_i* mySender; +}; + +class VISU_ViewEvent : public VISU_Event +{ +public: + VISU_ViewEvent( int eventType, bool wait, VISU::Base_i* sender = 0, bool autoRelease = false ); + virtual ~VISU_ViewEvent(); + + void setArg( VISU::Base_ptr ); + VISU::Base_ptr getArg(); + + void setView( VISU::View_ptr ); + VISU::View_ptr getView(); +private: + VISU::Base_ptr myArg; + VISU::View_ptr myView; }; #endif diff --git a/src/VISU_I/VISU_Gen_i.cc b/src/VISU_I/VISU_Gen_i.cc index e8a8f82d..39edd18e 100644 --- a/src/VISU_I/VISU_Gen_i.cc +++ b/src/VISU_I/VISU_Gen_i.cc @@ -894,7 +894,7 @@ namespace VISU{ */ void VISU_Gen_i::CreateTestView() { if(myMutex){ - VISU_Event* ve = new VISU_Event( VISU_Event::CreateTestViewEvent, true ); + VISU_Event* ve = new VISU_Event( VISU_Event::CreateTestViewEvent, true, this ); ve->process(); ve->release(); return; @@ -904,7 +904,7 @@ namespace VISU{ void VISU_Gen_i::ShowTestObject() { if(myMutex){ - VISU_Event* ve = new VISU_Event( VISU_Event::ShowTestObjectEvent, true ); + VISU_Event* ve = new VISU_Event( VISU_Event::ShowTestObjectEvent, true, this ); ve->process(); ve->release(); return; diff --git a/src/VISU_I/VISU_ViewManager_i.cc b/src/VISU_I/VISU_ViewManager_i.cc index 61da0aab..f50908a4 100644 --- a/src/VISU_I/VISU_ViewManager_i.cc +++ b/src/VISU_I/VISU_ViewManager_i.cc @@ -43,6 +43,8 @@ #include "VISU_ScalarBarActor.hxx" #include "VISU_Actor.h" +#include "VISU_Event.h" + #include "QAD_Application.h" #include "QAD_Desktop.h" #include "QAD_Tools.h" @@ -213,6 +215,23 @@ namespace VISU{ } } } + + QAD_Study* CheckStudy( SALOMEDS::Study_ptr theStudy ) { + QAD_Desktop* aDesktop = QAD_Application::getDesktop(); + QAD_Study* aStudy = aDesktop->findStudy(theStudy); + if(!aStudy){ + CORBA::String_var aName = theStudy->Name(); + aFileInfo.setFile(aName.in()); + if (aFileInfo.exists()) + aStudy = aDesktop->loadStudy(aFileInfo.baseName()); + else + aStudy = aDesktop->loadStudy(aName.in()); + if (!aStudy) { + MESSAGE("CheckStudy()::ERROR: Can't load study"); + } + } + return aStudy; + } //=========================================================================== /* #include @@ -239,27 +258,16 @@ namespace VISU{ myStudyDocument = SALOMEDS::Study::_duplicate(theStudy); //TViewManager* aTViewManager = new TViewManager(theStudy); //aTViewManager->start(); - QAD_Desktop* aDesktop = QAD_Application::getDesktop(); - QAD_Study* aStudy = aDesktop->findStudy(theStudy); - if(!aStudy){ - CORBA::String_var aName = theStudy->Name(); - aFileInfo.setFile(aName.in()); - if (aFileInfo.exists()) - aStudy = aDesktop->loadStudy(aFileInfo.baseName()); - else aStudy = aDesktop->loadStudy(aName.in()); - if (!aStudy) - MESSAGE("ViewManager_i::ERROR: Can't load study"); - } } VISU::View3D_ptr ViewManager_i::Create3DView(){ - Mutex mt(myMutex,qApp,MYDELAY); if(MYDEBUG) MESSAGE("ViewManager_i::Create3DView"); - VISU::View3D_i* pView = new View3D_i(myStudyDocument); - if(pView->Create(1) != NULL) - return VISU::View3D::_duplicate(pView->_this()); - return VISU::View3D::_nil(); + VISU_ViewEvent* ve = new VISU_ViewEvent( VISU_Event::Create3DView, true, this ); + ve->process(); + VISU::View3D_ptr aView = VISU::View3D::_narrow( ve->getView() ); + ve->release(); + return aView; } @@ -288,66 +296,92 @@ namespace VISU{ VISU::XYPlot_ptr ViewManager_i::CreateXYPlot(){ if(MYDEBUG) MESSAGE("ViewManager_i::CreateXYPlot"); - Mutex mt(myMutex,qApp,MYDELAY); - VISU::XYPlot_i* pView = new XYPlot_i(myStudyDocument); - if(pView->Create(1) != NULL) - return VISU::XYPlot::_duplicate(pView->_this()); - return VISU::XYPlot::_nil(); + VISU_ViewEvent* ve = new VISU_ViewEvent( VISU_Event::CreateXYPlot, true, this ); + ve->process(); + VISU::XYPlot_ptr aView = VISU::XYPlot::_narrow( ve->getView() ); + ve->release(); + return aView; } VISU::TableView_ptr ViewManager_i::CreateTableView(VISU::Table_ptr theTable){ if(MYDEBUG) MESSAGE("ViewManager_i::CreateTableView"); - Mutex mt(myMutex,qApp,MYDELAY); - VISU::TableView_i* pView = new TableView_i(myStudyDocument); - if(pView->Create(VISU::Table::_duplicate(theTable)) != NULL) - return VISU::TableView::_duplicate(pView->_this()); - return VISU::TableView::_nil(); + VISU_ViewEvent* ve = new VISU_ViewEvent( VISU_Event::CreateTableView, true, this ); + ve->setArg( theTable ); + ve->process(); + VISU::TableView_ptr aView = VISU::TableView::_narrow( ve->getView() ); + ve->release(); + return aView; } void ViewManager_i::Destroy(View_ptr theView){ if(MYDEBUG) MESSAGE("ViewManager_i::Destroy - "<_is_nil()); + VISU_ViewEvent* ve = new VISU_ViewEvent( VISU_Event::DestroyView, true, this ); + ve->setView( theView ); + ve->process(); + ve->release(); + } + + // SAN - QT_EVENT prototype + // SALOME event handlers + View3D_ptr ViewManager_i::OnCreate3DView() { + Mutex mt(myMutex,qApp,MYDELAY); + if(MYDEBUG) MESSAGE("ViewManager_i::OnCreate3DView"); + // Make sure that myStudyDocument is opened in the desktop + if ( CheckStudy( myStudyDocument ) ) { + VISU::View3D_i* pView = new View3D_i(myStudyDocument); + if(pView->Create(1) != NULL) + return VISU::View3D::_duplicate(pView->_this()); + } + return VISU::View3D::_nil(); + } + + VISU::TableView_ptr ViewManager_i::OnCreateTableView(VISU::Table_ptr theTable){ + if(MYDEBUG) MESSAGE("ViewManager_i::OnCreateTableView"); + Mutex mt(myMutex,qApp,MYDELAY); + if ( CheckStudy( myStudyDocument ) ) { + VISU::TableView_i* pView = new TableView_i(myStudyDocument); + if(pView->Create(VISU::Table::_duplicate(theTable)) != NULL) + return VISU::TableView::_duplicate(pView->_this()); + } + return VISU::TableView::_nil(); + } + + VISU::XYPlot_ptr ViewManager_i::OnCreateXYPlot(){ + if(MYDEBUG) MESSAGE("ViewManager_i::OnCreateXYPlot"); + Mutex mt(myMutex,qApp,MYDELAY); + if ( CheckStudy( myStudyDocument ) ) { + VISU::XYPlot_i* pView = new XYPlot_i(myStudyDocument); + if(pView->Create(1) != NULL) + return VISU::XYPlot::_duplicate(pView->_this()); + } + return VISU::XYPlot::_nil(); + } + + void ViewManager_i::OnDestroy(View_ptr theView){ + if(MYDEBUG) MESSAGE("ViewManager_i::OnDestroy - "<_is_nil()); if(theView->_is_nil()) return; CORBA::Object_var aView = VISU::View::_narrow(theView); if(!CORBA::is_nil(aView)){ - if(MYDEBUG) MESSAGE("ViewManager_i::Destroy - VISU::View"<<(!CORBA::is_nil(aView))); + if(MYDEBUG) MESSAGE("ViewManager_i::OnDestroy - VISU::View"<<(!CORBA::is_nil(aView))); VISU::View_i* pView = dynamic_cast(VISU::GetServant(aView).in()); - if(MYDEBUG) MESSAGE("ViewManager_i::Destroy - dynamic_cast"<Close(); pView->_remove_ref(); } - //if(pView) delete pView; return; } } - - - void ViewManager_i::ProcessEvents() { - while (true) { - qApp->lock(); - qApp->syncX(); - qApp->flushX(); - qApp->processEvents(); - qApp->unlock(); - //sleep(1); - } - } + // SAN - QT_EVENT prototype //=========================================================================== View_i::View_i(SALOMEDS::Study_ptr theStudy) { if(MYDEBUG) MESSAGE("View_i::View_i"); CORBA::String_var aName = theStudy->Name(); - QAD_Desktop* aDesktop = QAD_Application::getDesktop(); - myStudy = aDesktop->findStudy(theStudy); - if(!myStudy){ - aFileInfo.setFile(aName.in()); - if ( aFileInfo.exists() ) - myStudy = aDesktop->loadStudy(aFileInfo.baseName()); - else myStudy = aDesktop->loadStudy(aName.in()); - } + myStudy = CheckStudy(theStudy); if(MYDEBUG) MESSAGE("View_i::View_i - isStudyOpened = "<