From db6e3baab6b1a447f61b4d7f25189f3ce782a56d Mon Sep 17 00:00:00 2001 From: smh Date: Thu, 15 Apr 2004 09:25:49 +0000 Subject: [PATCH] Completing VISU::View3d event processing implemtnatation --- src/VISUGUI/VisuGUI.cxx | 97 +---- src/VISU_I/VISU_ViewManager_i.cc | 625 +++++++++++++++++++------------ src/VISU_I/VISU_ViewManager_i.hh | 25 +- 3 files changed, 404 insertions(+), 343 deletions(-) diff --git a/src/VISUGUI/VisuGUI.cxx b/src/VISUGUI/VisuGUI.cxx index 6fd8031a..5469510a 100644 --- a/src/VISUGUI/VisuGUI.cxx +++ b/src/VISUGUI/VisuGUI.cxx @@ -2238,57 +2238,31 @@ void VisuGUI::DeletePrs() { void VisuGUI::SaveViewParams() { if (checkLock(GetStudyDocument())) return; - SALOME_Selection* Sel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() ); - if ( Sel->IObjectCount() > 1 || GetActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_VTK ) + SALOME_Selection* aSel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() ); + QAD_StudyFrame* aStudyFrame = GetActiveStudy()->getActiveStudyFrame(); + if ( aSel->IObjectCount() > 1 || aStudyFrame->getTypeView() != VIEW_VTK ) return; - VISU::ViewManager_var aVM = GetVisuGen()->GetViewManager(); - if(!CORBA::is_nil(aVM.in())){ - VISU::View_var aView = aVM->GetCurrentView(); - if(!CORBA::is_nil(aView.in())){ - VISU::View3D_var aView3D = VISU::View3D::_narrow(aView); - if(CORBA::is_nil(aView3D.in())) return; - if ( Sel->IObjectCount() == 0 ) { - // Save view parameters by new name - aView3D->SaveViewParams( 0 ); - GetActiveStudy()->updateObjBrowser( true ); - }else{ - bool isExist; - VISU::Storable::TRestoringMap aMap; - Handle(SALOME_InteractiveObject) anIO; - CORBA::Object_var anObject = GetSelectedObj(&anIO,GetActiveStudy(),&aMap); - VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt(); - if(isExist && aType == VISU::TVIEW3D){ - aView3D->SaveViewParams( anIO->getName() ); - GetActiveStudy()->updateObjBrowser( true ); - } - } - } + if ( aSel->IObjectCount() == 0 ) { + VISU::View3D_i::SaveViewParams(aStudyFrame,VISU::View3D_i::GenerateViewParamsName().latin1()); + }else{ + const Handle(SALOME_InteractiveObject)& anIO = aSel->firstIObject(); + VISU::View3D_i::SaveViewParams(aStudyFrame,anIO->getName()); } + GetActiveStudy()->updateObjBrowser( true ); } void VisuGUI::RestoreViewParams() { - SALOME_Selection* Sel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() ); - if ( Sel->IObjectCount() > 1 || GetActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_VTK ) + SALOME_Selection* aSel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() ); + QAD_StudyFrame* aStudyFrame = GetActiveStudy()->getActiveStudyFrame(); + if ( aSel->IObjectCount() > 1 || aStudyFrame->getTypeView() != VIEW_VTK ) return; - VISU::ViewManager_var aVM = GetVisuGen()->GetViewManager(); - if(!CORBA::is_nil(aVM.in())){ - VISU::View_var aView = aVM->GetCurrentView(); - if(!CORBA::is_nil(aView.in())){ - VISU::View3D_var aView3D = VISU::View3D::_narrow(aView); - if(CORBA::is_nil(aView3D.in())) return; - bool isExist; - VISU::Storable::TRestoringMap aMap; - Handle(SALOME_InteractiveObject) anIO; - CORBA::Object_var anObject = GetSelectedObj(&anIO,GetActiveStudy(),&aMap); - VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt(); - if(isExist && aType == VISU::TVIEW3D) - aView3D->RestoreViewParams( anIO->getName() ); - } - } + const Handle(SALOME_InteractiveObject)& anIO = aSel->firstIObject(); + VISU::View3D_i::RestoreViewParams(aStudyFrame,anIO->getName()); } + //===================================================================================== // function : DeleteViewParams() // purpose : @@ -4017,46 +3991,7 @@ void VisuGUI::SetActiveDialogBox(QDialog* aDlg) */ //=========================================================== 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() { diff --git a/src/VISU_I/VISU_ViewManager_i.cc b/src/VISU_I/VISU_ViewManager_i.cc index 07c1804b..eadf3ecf 100644 --- a/src/VISU_I/VISU_ViewManager_i.cc +++ b/src/VISU_I/VISU_ViewManager_i.cc @@ -89,11 +89,28 @@ namespace VISU{ vtkCamera* GetCamera(QAD_StudyFrame* theStudyFrame){ return GetRenderer(theStudyFrame)->GetActiveCamera(); } + + void RepaintView(QAD_StudyFrame* theStudyFrame){ GetRenderer(theStudyFrame)->ResetCameraClippingRange(); GetViewFrame(theStudyFrame)->getRW()->getRenderWindow()->Render(); //GetViewFrame(theStudyFrame)->Repaint(); } + + + class TRepaintViewEvent: public SALOME_Event{ + QAD_StudyFrame* myStudyFrame; + public: + TRepaintViewEvent(QAD_StudyFrame* theStudyFrame): + myStudyFrame(theStudyFrame) + {} + virtual bool Execute(){ + RepaintView(myStudyFrame); + return true; + } + }; + + VISU_Actor* UpdateViewer(QAD_StudyFrame* theStudyFrame, int theDisplaing, Prs3d_i* thePrs){ VTKViewer_ViewFrame* vf = GetViewFrame(theStudyFrame); if (!vf) return NULL; @@ -235,15 +252,11 @@ namespace VISU{ //=========================================================================== ViewManager_i::ViewManager_i(SALOMEDS::Study_ptr theStudy) { if(MYDEBUG) MESSAGE("ViewManager_i::ViewManager_i"); - Mutex mt(myMutex,qApp,MYDELAY); myStudyDocument = SALOMEDS::Study::_duplicate(theStudy); } - - VISU::View3D_ptr ViewManager_i::Create3DView(){ - if(MYDEBUG) MESSAGE("ViewManager_i::Create3DView"); - + VISU::View_ptr ViewManager_i::GetCurrentView(){ class TEvent: public SALOME_Event{ SALOMEDS::Study_ptr myStudyDocument; public: @@ -251,130 +264,146 @@ namespace VISU{ myStudyDocument(theStudy) {} virtual bool Execute(){ - if ( CheckStudy( myStudyDocument ) ) { - VISU::View3D_i* pView = new View3D_i(myStudyDocument); - if(pView->Create(1) != NULL) - myResult = pView->_this(); + if(QAD_Study* aStudy = QAD_Application::getDesktop()->findStudy( myStudyDocument )){ + if ( QAD_StudyFrame* aStudyFrame = aStudy->getActiveStudyFrame() ) { + if(MYDEBUG) + MESSAGE("GetCurrentView::Execute - TypeView = "<getTypeView()); + if ( aStudyFrame->getTypeView() == VIEW_VTK ) { + VISU::View3D_i* pView = new View3D_i(myStudyDocument); + if(pView->Create(0)) + myResult = pView->_this(); + } else if ( aStudyFrame->getTypeView() == VIEW_PLOT2D ) { + VISU::XYPlot_i* pView = new XYPlot_i(myStudyDocument); + if(pView->Create(0)) + myResult = pView->_this(); + } + } } - return CORBA::is_nil(myResult.in()); + return true; } - typedef VISU::View3D_var TResult; + typedef VISU::View_var TResult; TResult myResult; }; - TEvent* ve = new TEvent( myStudyDocument ); ve->process(); TEvent::TResult aResult = ve->myResult; ve->release(); return aResult._retn(); } - + + class TCreateViewEvent: public SALOME_Event{ + public: + TCreateViewEvent( SALOMEDS::Study_ptr theStudy): + myStudyDocument(theStudy) + {}; + protected: + SALOMEDS::Study_ptr myStudyDocument; + }; - VISU::View_ptr ViewManager_i::GetCurrentView(){ - Mutex mt(myMutex,qApp,MYDELAY); - QAD_Study* Study = QAD_Application::getDesktop()->findStudy( myStudyDocument ); - if(MYDEBUG) MESSAGE("ViewManager_i::GetCurrent3DView - Study = "<getActiveStudyFrame() ) ) { - if(MYDEBUG) - MESSAGE("ViewManager_i::GetCurrent3DView - TypeView = "<getTypeView()); - if ( StudyFrame->getTypeView() == VIEW_VTK ) { + + class TCreate3DViewEvent: public TCreateViewEvent{ + public: + typedef VISU::View3D TInterface; + typedef TInterface::_ptr_type TResult; + TResult myResult; + TCreate3DViewEvent( SALOMEDS::Study_ptr theStudy): + TCreateViewEvent(theStudy), + myResult(TInterface::_nil()) + {} + virtual bool Execute(){ + if ( CheckStudy( myStudyDocument ) ) { VISU::View3D_i* pView = new View3D_i(myStudyDocument); - if(pView->Create(0) != NULL) - return VISU::View3D::_duplicate(pView->_this()); - } - else if ( StudyFrame->getTypeView() == VIEW_PLOT2D ) { - VISU::XYPlot_i* pView = new XYPlot_i(myStudyDocument); - if(pView->Create(0) != NULL) - return VISU::XYPlot::_duplicate(pView->_this()); + if(pView->Create(1) != NULL) + myResult = pView->_this(); } + return true; } - return VISU::View::_nil(); + }; + VISU::View3D_ptr ViewManager_i::Create3DView(){ + if(MYDEBUG) MESSAGE("ViewManager_i::Create3DView"); + return ProcessEvent(new TCreate3DViewEvent(myStudyDocument)); } + VISU::XYPlot_ptr ViewManager_i::CreateXYPlot(){ if(MYDEBUG) MESSAGE("ViewManager_i::CreateXYPlot"); - VISU_ViewEvent* ve = new VISU_ViewEvent( VISU_Event::CreateXYPlot, true, this ); + + class TEvent: public TCreateViewEvent{ + public: + TEvent( SALOMEDS::Study_ptr theStudy): + TCreateViewEvent(theStudy) + {} + virtual bool Execute(){ + if ( CheckStudy( myStudyDocument ) ) { + VISU::XYPlot_i* pView = new XYPlot_i(myStudyDocument); + if(pView->Create(1) != NULL) + myResult = pView->_this(); + } + return true; + } + typedef VISU::XYPlot_var TResult; + TResult myResult; + }; + + TEvent* ve = new TEvent(myStudyDocument); ve->process(); - VISU::XYPlot_ptr aView = VISU::XYPlot::_narrow( ve->getView() ); + TEvent::TResult aResult = ve->myResult; ve->release(); - return aView; + return aResult._retn(); } VISU::TableView_ptr ViewManager_i::CreateTableView(VISU::Table_ptr theTable){ + class TEvent: public TCreateViewEvent{ + Table_ptr myTable; + public: + TEvent(SALOMEDS::Study_ptr theStudy, + Table_ptr theTable): + TCreateViewEvent(theStudy), + myTable(theTable) + {} + virtual bool Execute(){ + if ( CheckStudy( myStudyDocument ) ) { + VISU::TableView_i* pView = new TableView_i(myStudyDocument); + if(pView->Create(myTable) != NULL) + myResult = pView->_this(); + } + return true; + } + typedef VISU::TableView_var TResult; + TResult myResult; + }; if(MYDEBUG) MESSAGE("ViewManager_i::CreateTableView"); - VISU_ViewEvent* ve = new VISU_ViewEvent( VISU_Event::CreateTableView, true, this ); - ve->setArg( theTable ); + TEvent* ve = new TEvent(myStudyDocument,theTable); ve->process(); - VISU::TableView_ptr aView = VISU::TableView::_narrow( ve->getView() ); + TEvent::TResult aResult = ve->myResult; ve->release(); - return aView; + return aResult._retn(); } 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::OnDestroy - VISU::View"<<(!CORBA::is_nil(aView))); - VISU::View_i* pView = dynamic_cast(VISU::GetServant(aView).in()); - if(MYDEBUG) MESSAGE("ViewManager_i::OnDestroy - dynamic_cast"<Close(); - pView->_remove_ref(); + class TEvent: public SALOME_Event{ + View_ptr myView; + public: + TEvent(View_ptr theView): + myView(theView) + {} + virtual bool Execute(){ + if(!CORBA::is_nil(myView)){ + if(VISU::View_i* pView = dynamic_cast(VISU::GetServant(myView).in())) { + pView->Close(); + pView->_remove_ref(); + } + } + return true; } - return; - } + }; + if(MYDEBUG) MESSAGE("ViewManager_i::Destroy - "<_is_nil()); + ProcessVoidEvent(new TEvent(theView)); } - // SAN - QT_EVENT prototype //=========================================================================== @@ -737,11 +766,10 @@ namespace VISU{ //=========================================================================== TableView_i::TableView_i(SALOMEDS::Study_ptr theStudy) : View_i(theStudy) {} - Storable* TableView_i::Create(VISU::Table_var theTable){ + Storable* TableView_i::Create(VISU::Table_ptr theTable){ if(MYDEBUG) MESSAGE("TableView_i::Create - "<<(!theTable->_is_nil())); - Mutex mt(myMutex,qApp,MYDELAY); if(!theTable->_is_nil()){ - VISU::Table_i* table = dynamic_cast(VISU::GetServant(theTable.in()).in()); + VISU::Table_i* table = dynamic_cast(VISU::GetServant(theTable).in()); if(MYDEBUG) MESSAGE("TableView_i::Create - dynamic_cast = "<getStudyDocument()->FindObjectID(table->GetObjectEntry()); @@ -805,12 +833,10 @@ namespace VISU{ void View3D_i::Update(){ - if(MYDEBUG) MESSAGE("View3D_i::Update"); - class TEvent: public SALOME_Event{ QAD_StudyFrame* myStudyFrame; public: - TEvent( QAD_StudyFrame* theStudyFrame ): + TEvent(QAD_StudyFrame* theStudyFrame): myStudyFrame(theStudyFrame) {} virtual bool Execute(){ @@ -828,85 +854,90 @@ namespace VISU{ } } } - myResult = myStudyFrame->title().latin1(); return true; } - typedef string TResult; - TResult myResult; }; - - TEvent* ve = new TEvent( myStudyFrame ); - ve->process(); - myName = ve->myResult; - ve->release(); + if(MYDEBUG) MESSAGE("View3D_i::Update"); + myName = myStudyFrame->title().latin1(); + ProcessVoidEvent(new TEvent(myStudyFrame)); } + CORBA::Boolean View3D_i::SavePicture(const char* theFileName) { + class TEvent: public SALOME_Event{ + QAD_StudyFrame* myStudyFrame; + const char* myFileName; + public: + typedef CORBA::Boolean TResult; + TResult myResult; + TEvent(QAD_StudyFrame* theStudyFrame, + const char* theFileName): + myStudyFrame(theStudyFrame), + myFileName(theFileName), + myResult(false) + {} + virtual bool Execute(){ + QPixmap px = QPixmap::grabWindow(myStudyFrame->getRightFrame()->getViewFrame()->getViewWidget()->winId()); + if (!QString(myFileName).isNull()) { + QString fmt = QAD_Tools::getFileExtensionFromPath(myFileName).upper(); + if (fmt.isEmpty()) + fmt = QString("BMP"); // default format + if (fmt == "JPG") + fmt = "JPEG"; + myResult = px.save(myFileName, fmt.latin1()); + } + } + }; if(MYDEBUG) MESSAGE("View3D_i::SavePicture"); - Mutex mt(myMutex,qApp,MYDELAY); if (!myStudyFrame->getRightFrame()->getViewFrame()->getViewWidget()) return false; - - QApplication::setOverrideCursor( Qt::waitCursor ); - QPixmap px = QPixmap::grabWindow(myStudyFrame->getRightFrame()->getViewFrame()->getViewWidget()->winId()); - QApplication::restoreOverrideCursor(); - - if (!QString(theFileName).isNull()) { - QApplication::setOverrideCursor( Qt::waitCursor ); - QString fmt = QAD_Tools::getFileExtensionFromPath(theFileName).upper(); - if (fmt.isEmpty()) - fmt = QString("BMP"); // default format - if (fmt == "JPG") - fmt = "JPEG"; - bool bOk = px.save(theFileName, fmt.latin1()); - QApplication::restoreOverrideCursor(); - return bOk; - } - return false; + TEvent* ve = new TEvent(myStudyFrame,theFileName); + ve->process(); + TEvent::TResult aResult = ve->myResult; + ve->release(); + return aResult; } - CORBA::Boolean View3D_i::SaveViewParams(const char* theName){ - if(MYDEBUG) MESSAGE("View3D_i::SaveViewPoint"); - Mutex mt(myMutex,qApp,MYDELAY); + + bool View3D_i::SaveViewParams(QAD_StudyFrame* theStudyFrame, const char* theName){ + QAD_Study* aStudy = theStudyFrame->getStudy(); + SALOMEDS::Study_var aStudyDoc = aStudy->getStudyDocument(); if ( theName ) { SALOMEDS::Study::ListOfSObject_var aList = - myStudy->getStudyDocument()->FindObjectByName(theName,"VISU"); + aStudyDoc->FindObjectByName(theName,"VISU"); SALOMEDS::GenericAttribute_var anAttr; int iEnd = aList->length(); for(int i = 0; i < iEnd; i++){ SALOMEDS::SObject_var anObj = aList[i]; CORBA::String_var aString = anObj->GetID(); string anEntry(aString); - if(MYDEBUG) MESSAGE("View3D_i::SaveViewPoint - anEntry = "<Value(); string aComm(aString); if(MYDEBUG) MESSAGE("View3D_i::SaveViewPoint - aComm = "<= 0){ - aCmnt->SetValue(ToString().c_str()); - return 1; + aCmnt->SetValue(ToString(theStudyFrame).c_str()); + return true; } } } } - QString newName; - if ( theName ) - newName = QString( theName ); - else - newName = QString( GenerateViewParamsName() ); - SALOMEDS::SComponent_var aSComponent = - FindOrCreateVisuComponent(myStudy->getStudyDocument()); - CORBA::String_var aSComponentEntry = aSComponent->GetID(), anIOR(GetID()); - string anEntry = CreateAttributes(myStudy->getStudyDocument(),aSComponentEntry,"","",newName.latin1(),"",ToString().c_str()); - return 1; + SALOMEDS::SComponent_var aSComponent = FindOrCreateVisuComponent(aStudyDoc); + CORBA::String_var aSComponentEntry = aSComponent->GetID(); + string anEntry = CreateAttributes(aStudyDoc,aSComponentEntry.in(),"","",theName,"",ToString(theStudyFrame).c_str()); + return true; + } + CORBA::Boolean View3D_i::SaveViewParams(const char* theName){ + if(MYDEBUG) MESSAGE("View3D_i::SaveViewPoint"); + return SaveViewParams(myStudyFrame,theName); } - CORBA::Boolean View3D_i::RestoreViewParams(const char* theName){ - if(MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - "<getStudyDocument()->FindObjectByName(theName,"VISU"); + theStudyFrame->getStudy()->getStudyDocument()->FindObjectByName(theName,"VISU"); SALOMEDS::GenericAttribute_var anAttr; int iEnd = aList->length(); if(MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - iEnd = "<= 0 ) { if(MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - aComm = "<process(); + TEvent::TResult aResult = ve->myResult; + ve->release(); + return aResult; + } + + + void View3D_i::Restore(QAD_StudyFrame* theStudyFrame, const Storable::TRestoringMap& theMap) throw(std::logic_error&) { SALOMEDS::Color aColor; aColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble(); aColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble(); @@ -961,98 +1017,134 @@ namespace VISU{ aScaleFactor[1] = VISU::Storable::FindValue(theMap,"myScaleFactor[1]").toDouble(); aScaleFactor[2] = VISU::Storable::FindValue(theMap,"myScaleFactor[2]").toDouble(); - //myStudyFrame->setTitle(myName.c_str()); - SetBackground(aColor); - SetPointOfView(aPosition); - SetViewUp(aViewUp); - SetFocalPoint(aFocalPnt); - SetParallelScale(aParallelScale); - ScaleView(VISU::View3D::XAxis,aScaleFactor[0]); - ScaleView(VISU::View3D::YAxis,aScaleFactor[1]); - ScaleView(VISU::View3D::ZAxis,aScaleFactor[2]); - RepaintView(myStudyFrame); + SetBackground(theStudyFrame,aColor); + SetPointOfView(theStudyFrame,aPosition); + SetViewUp(theStudyFrame,aViewUp); + SetFocalPoint(theStudyFrame,aFocalPnt); + SetParallelScale(theStudyFrame,aParallelScale); + ScaleView(theStudyFrame,VISU::View3D::XAxis,aScaleFactor[0]); + ScaleView(theStudyFrame,VISU::View3D::YAxis,aScaleFactor[1]); + ScaleView(theStudyFrame,VISU::View3D::ZAxis,aScaleFactor[2]); + } + Storable* View3D_i::Restore(const Storable::TRestoringMap& theMap) throw(std::logic_error&) { + Restore(myStudyFrame,theMap); return this; } - void View3D_i::ToStream(std::ostringstream& theStr) { + string View3D_i::ToString(QAD_StudyFrame* theStudyFrame){ + ostringstream strOut; + Storable::DataToStream( strOut, "myComment", myComment.c_str() ); + ToStream(theStudyFrame,strOut); + strOut<GetBackground(backint); + GetRenderer(theStudyFrame)->GetBackground(backint); Storable::DataToStream(theStr,"myColor.R",backint[0]); Storable::DataToStream(theStr,"myColor.G",backint[1]); Storable::DataToStream(theStr,"myColor.B",backint[2]); double aPosition[3]; - GetPointOfView(myStudyFrame,aPosition); + GetPointOfView(theStudyFrame,aPosition); Storable::DataToStream(theStr,"myPosition[0]",aPosition[0]); Storable::DataToStream(theStr,"myPosition[1]",aPosition[1]); Storable::DataToStream(theStr,"myPosition[2]",aPosition[2]); double aFocalPnt[3]; - GetFocalPoint(myStudyFrame,aFocalPnt); + GetFocalPoint(theStudyFrame,aFocalPnt); Storable::DataToStream(theStr,"myFocalPnt[0]",aFocalPnt[0]); Storable::DataToStream(theStr,"myFocalPnt[1]",aFocalPnt[1]); Storable::DataToStream(theStr,"myFocalPnt[2]",aFocalPnt[2]); double aViewUp[3]; - GetCamera(myStudyFrame)->GetViewUp(aViewUp); + GetCamera(theStudyFrame)->GetViewUp(aViewUp); Storable::DataToStream(theStr,"myViewUp[0]",aViewUp[0]); Storable::DataToStream(theStr,"myViewUp[1]",aViewUp[1]); Storable::DataToStream(theStr,"myViewUp[2]",aViewUp[2]); - Storable::DataToStream(theStr,"myParallelScale",GetParallelScale(myStudyFrame)); + Storable::DataToStream(theStr,"myParallelScale",GetParallelScale(theStudyFrame)); double aScaleFactor[3]; - GetViewFrame(myStudyFrame)->GetScale(aScaleFactor); + GetViewFrame(theStudyFrame)->GetScale(aScaleFactor); Storable::DataToStream(theStr,"myScaleFactor[0]",aScaleFactor[0]); Storable::DataToStream(theStr,"myScaleFactor[1]",aScaleFactor[1]); Storable::DataToStream(theStr,"myScaleFactor[2]",aScaleFactor[2]); } + void View3D_i::ToStream(std::ostringstream& theStr) { + ToStream(myStudyFrame,theStr); + } void View3D_i::Close(){ if(MYDEBUG) MESSAGE("View3D_i::Close"); - Mutex mt(myMutex,qApp,MYDELAY); myStudyFrame->close(); } View3D_i::~View3D_i() { if(MYDEBUG) MESSAGE("View3D_i::~View3D_i"); - Mutex mt(myMutex,qApp,MYDELAY); myStudyFrame->close(); } //-------------------- View interface -------------------- void View3D_i::SetTitle(const char* theTitle){ + class TEvent: public SALOME_Event{ + QAD_StudyFrame* myStudyFrame; + const char* myName; + public: + TEvent(QAD_StudyFrame* theStudyFrame, + const char* theName): + myStudyFrame(theStudyFrame), + myName(theName) + {} + virtual bool Execute(){ + myStudyFrame->setTitle(myName); + return true; + } + }; if(MYDEBUG) MESSAGE("View3D_i::SetTitle"); - Mutex mt(myMutex,qApp,MYDELAY); myName = theTitle; - myStudyFrame->setTitle(myName.c_str()); + ProcessVoidEvent(new TEvent(myStudyFrame,theTitle)); } char* View3D_i::GetTitle() { if(MYDEBUG) MESSAGE("View3D_i::GetTitle"); - Mutex mt(myMutex,qApp,MYDELAY); - myName = (const char*)myStudyFrame->title(); + myName = myStudyFrame->title().latin1(); return CORBA::string_dup(myName.c_str()); } + void View3D_i::SetBackground(QAD_StudyFrame* theStudyFrame, const SALOMEDS::Color& theColor) { int aColor[3]; - aColor[0] = (int)(255.0*theColor.R); - aColor[1] = (int)(255.0*theColor.G); - aColor[2] = (int)(255.0*theColor.B); + aColor[0] = int(255.0*theColor.R); + aColor[1] = int(255.0*theColor.G); + aColor[2] = int(255.0*theColor.B); QColor aNewColor(aColor[0],aColor[1],aColor[2]); GetViewFrame(theStudyFrame)->setBackgroundColor(aNewColor); } void View3D_i::SetBackground(const SALOMEDS::Color& theColor) { + class TEvent: public SALOME_Event{ + QAD_StudyFrame* myStudyFrame; + const SALOMEDS::Color& myColor; + public: + TEvent(QAD_StudyFrame* theStudyFrame, + const SALOMEDS::Color& theColor): + myStudyFrame(theStudyFrame), + myColor(theColor) + {} + virtual bool Execute(){ + SetBackground(myStudyFrame,myColor); + return true; + } + }; if(MYDEBUG) MESSAGE("View3D_i::SetBackground"); - Mutex mt(myMutex,qApp,MYDELAY); - //myColor.R = theColor.R; myColor.G = theColor.G; myColor.B = theColor.B; - SetBackground(myStudyFrame,theColor); + ProcessVoidEvent(new TEvent(myStudyFrame,theColor)); } + SALOMEDS::Color View3D_i::GetBackground(QAD_StudyFrame* theStudyFrame) { SALOMEDS::Color aColor; float backint[3]; @@ -1062,25 +1154,39 @@ namespace VISU{ } SALOMEDS::Color View3D_i::GetBackground() { if(MYDEBUG) MESSAGE("View3D_i::GetBackground"); - Mutex mt(myMutex,qApp,MYDELAY); - //myColor = GetBackground(myStudyFrame); - return GetBackground(myStudyFrame); //myColor; + return GetBackground(myStudyFrame); } + + class TFrameActionEvent: public SALOME_Event{ + public: + typedef void (QAD_StudyFrame::* TFrameAction)(); + TFrameActionEvent(QAD_StudyFrame* theStudyFrame, + TFrameAction theFrameAction): + myStudyFrame(theStudyFrame), + myFrameAction(theFrameAction) + {} + virtual bool Execute(){ + (myStudyFrame->*myFrameAction)(); + return true; + } + private: + QAD_StudyFrame* myStudyFrame; + TFrameAction myFrameAction; + }; + + void View3D_i::Minimize() { if(MYDEBUG) MESSAGE("View3D_i::Minimize"); - Mutex mt(myMutex,qApp,MYDELAY); - myStudyFrame->showMinimized(); + ProcessVoidEvent(new TFrameActionEvent(myStudyFrame,&QAD_StudyFrame::showMinimized)); } void View3D_i::Restore() { if(MYDEBUG) MESSAGE("View3D_i::Restore"); - Mutex mt(myMutex,qApp,MYDELAY); - myStudyFrame->showNormal(); + ProcessVoidEvent(new TFrameActionEvent(myStudyFrame, &QAD_StudyFrame::showNormal)); } void View3D_i::Maximize() { if(MYDEBUG) MESSAGE("View3D_i::Maximize"); - Mutex mt(myMutex,qApp,MYDELAY); - myStudyFrame->showMaximized(); + ProcessVoidEvent(new TFrameActionEvent(myStudyFrame, &QAD_StudyFrame::showMaximized)); } @@ -1090,9 +1196,9 @@ namespace VISU{ Prs3d_i* myPrs3d; int myDisplaing; public: - TUpdateViewerEvent( QAD_StudyFrame* theStudyFrame, - Prs3d_i* thePrs3d, - int theDisplaing ): + TUpdateViewerEvent(QAD_StudyFrame* theStudyFrame, + Prs3d_i* thePrs3d, + int theDisplaing): myStudyFrame(theStudyFrame), myPrs3d(thePrs3d), myDisplaing(theDisplaing) @@ -1105,19 +1211,19 @@ namespace VISU{ void View3D_i::EraseAll() { if(MYDEBUG) MESSAGE("View3D_i::EraseAll"); - ProcessVoidEvent(new TUpdateViewerEvent( myStudyFrame, NULL, eEraseAll )); + ProcessVoidEvent(new TUpdateViewerEvent(myStudyFrame,NULL,eEraseAll)); } void View3D_i::DisplayAll() { if(MYDEBUG) MESSAGE("View3D_i::DisplayAll"); - ProcessVoidEvent(new TUpdateViewerEvent( myStudyFrame, NULL, eDisplayAll )); + ProcessVoidEvent(new TUpdateViewerEvent(myStudyFrame,NULL,eDisplayAll)); } void View3D_i::Erase(PrsObject_ptr thePrsObj) { if(MYDEBUG) MESSAGE("View3D_i::Erase"); CORBA::Object_ptr anObj = thePrsObj; if(Prs3d_i* aPrs = dynamic_cast(VISU::GetServant(anObj).in())){ - ProcessVoidEvent(new TUpdateViewerEvent( myStudyFrame, aPrs, eErase )); + ProcessVoidEvent(new TUpdateViewerEvent(myStudyFrame,aPrs,eErase)); } } @@ -1125,7 +1231,7 @@ namespace VISU{ if(MYDEBUG) MESSAGE("View3D_i::Display"); CORBA::Object_ptr anObj = thePrsObj; if(Prs3d_i* aPrs = dynamic_cast(VISU::GetServant(anObj).in())){ - ProcessVoidEvent(new TUpdateViewerEvent( myStudyFrame, aPrs, eDisplay )); + ProcessVoidEvent(new TUpdateViewerEvent(myStudyFrame,aPrs,eDisplay)); } } @@ -1133,7 +1239,7 @@ namespace VISU{ if(MYDEBUG) MESSAGE("View3D_i::DisplayOnly"); CORBA::Object_ptr anObj = thePrsObj; if(Prs3d_i* aPrs = dynamic_cast(VISU::GetServant(anObj).in())){ - ProcessVoidEvent(new TUpdateViewerEvent( myStudyFrame, aPrs, eDisplayOnly )); + ProcessVoidEvent(new TUpdateViewerEvent(myStudyFrame,aPrs,eDisplayOnly)); } } @@ -1141,8 +1247,8 @@ namespace VISU{ class TViewActionEvent: public SALOME_Event{ public: typedef void (VTKViewer_ViewFrame::* TViewAction)(); - TViewActionEvent( QAD_StudyFrame* theStudyFrame, - TViewAction theViewAction ): + TViewActionEvent(QAD_StudyFrame* theStudyFrame, + TViewAction theViewAction): myStudyFrame(theStudyFrame), myViewAction(theViewAction) {} @@ -1158,59 +1264,64 @@ namespace VISU{ void View3D_i::FitAll() { if(MYDEBUG) MESSAGE("View3D_i::FitAll"); - ProcessVoidEvent(new TViewActionEvent( myStudyFrame, &VTKViewer_ViewFrame::onViewFitAll )); + ProcessVoidEvent(new TViewActionEvent(myStudyFrame,&VTKViewer_ViewFrame::onViewFitAll)); Update(); } + void View3D_i::SetView(VISU::View3D::ViewType theType) { if(MYDEBUG) MESSAGE("View3D_i::SetView"); switch(theType){ case VISU::View3D::FRONT : - ProcessVoidEvent(new TViewActionEvent( myStudyFrame, &VTKViewer_ViewFrame::onViewFront )); + ProcessVoidEvent(new TViewActionEvent(myStudyFrame,&VTKViewer_ViewFrame::onViewFront)); break; case VISU::View3D::BACK : - ProcessVoidEvent(new TViewActionEvent( myStudyFrame, &VTKViewer_ViewFrame::onViewBack )); + ProcessVoidEvent(new TViewActionEvent(myStudyFrame,&VTKViewer_ViewFrame::onViewBack)); break; case VISU::View3D::LEFT : - ProcessVoidEvent(new TViewActionEvent( myStudyFrame, &VTKViewer_ViewFrame::onViewLeft )); + ProcessVoidEvent(new TViewActionEvent(myStudyFrame,&VTKViewer_ViewFrame::onViewLeft)); break; case VISU::View3D::RIGHT : - ProcessVoidEvent(new TViewActionEvent( myStudyFrame, &VTKViewer_ViewFrame::onViewRight )); + ProcessVoidEvent(new TViewActionEvent(myStudyFrame,&VTKViewer_ViewFrame::onViewRight)); break; case VISU::View3D::TOP : - ProcessVoidEvent(new TViewActionEvent( myStudyFrame, &VTKViewer_ViewFrame::onViewTop )); + ProcessVoidEvent(new TViewActionEvent(myStudyFrame,&VTKViewer_ViewFrame::onViewTop)); break; case VISU::View3D::BOTTOM : - ProcessVoidEvent(new TViewActionEvent( myStudyFrame, &VTKViewer_ViewFrame::onViewBottom )); + ProcessVoidEvent(new TViewActionEvent(myStudyFrame,&VTKViewer_ViewFrame::onViewBottom)); break; } Update(); } + class TSet3DViewParamEvent: public SALOME_Event{ + public: + typedef void (*TFun)(QAD_StudyFrame* theStudyFrame, const CORBA::Double theParam[3]); + TSet3DViewParamEvent(TFun theFun, + QAD_StudyFrame* theStudyFrame, + const CORBA::Double theParam[3]): + myFun(theFun), + myStudyFrame(theStudyFrame), + myParam(theParam) + {} + virtual bool Execute(){ + myFun(myStudyFrame,myParam); + return true; + } + private: + TFun myFun; + QAD_StudyFrame* myStudyFrame; + const CORBA::Double* myParam; + }; + + void View3D_i::SetPointOfView(QAD_StudyFrame* theStudyFrame, const CORBA::Double thePosition[3]) { GetCamera(theStudyFrame)->SetPosition(thePosition); } void View3D_i::SetPointOfView(const VISU::View3D::XYZ thePosition) { if(MYDEBUG) MESSAGE("View3D_i::SetPointOfView"); - - class TEvent: public SALOME_Event{ - public: - TEvent( QAD_StudyFrame* theStudyFrame, - const CORBA::Double thePosition[3] ): - myStudyFrame(theStudyFrame), - myPosition(thePosition) - {} - virtual bool Execute(){ - SetPointOfView(myStudyFrame, myPosition); - return true; - } - private: - QAD_StudyFrame* myStudyFrame; - const CORBA::Double* myPosition; - }; - - ProcessVoidEvent(new TEvent( myStudyFrame, thePosition)); + ProcessVoidEvent(new TSet3DViewParamEvent(&SetPointOfView,myStudyFrame,thePosition)); } @@ -1224,64 +1335,82 @@ namespace VISU{ return VISU::View3D::XYZ_dup(aPosition); } + void View3D_i::SetViewUp(QAD_StudyFrame* theStudyFrame, const CORBA::Double theViewUp[3]) { GetCamera(theStudyFrame)->SetViewUp(theViewUp); } - void View3D_i::SetViewUp(const VISU::View3D::XYZ theDir) { + void View3D_i::SetViewUp(const VISU::View3D::XYZ theViewUp) { if(MYDEBUG) MESSAGE("View3D_i::SetViewUp"); - Mutex mt(myMutex,qApp,MYDELAY); - //VISU::View3D::XYZ_copy(myViewUp,theDir); - SetViewUp(myStudyFrame, theDir); + ProcessVoidEvent(new TSet3DViewParamEvent(&SetViewUp,myStudyFrame,theViewUp)); } + void View3D_i::GetViewUp(QAD_StudyFrame* theStudyFrame, CORBA::Double theViewUp[3]) { GetCamera(theStudyFrame)->GetViewUp(theViewUp); } VISU::View3D::XYZ_slice* View3D_i::GetViewUp() { if(MYDEBUG) MESSAGE("View3D_i::GetViewUp"); - Mutex mt(myMutex,qApp,MYDELAY); CORBA::Double aViewUp[3]; GetCamera(myStudyFrame)->GetViewUp(aViewUp); return VISU::View3D::XYZ_dup(aViewUp); } + void View3D_i::SetFocalPoint(QAD_StudyFrame* theStudyFrame, const CORBA::Double theFocalPnt[3]) { GetCamera(theStudyFrame)->SetFocalPoint(theFocalPnt); } void View3D_i::SetFocalPoint(const VISU::View3D::XYZ theCoord) { if(MYDEBUG) MESSAGE("View3D_i::SetFocalPoint"); - Mutex mt(myMutex,qApp,MYDELAY); - //VISU::View3D::XYZ_copy(myFocalPnt,theCoord); - SetFocalPoint(myStudyFrame,theCoord); + ProcessVoidEvent(new TSet3DViewParamEvent(&SetFocalPoint,myStudyFrame,theCoord)); } + void View3D_i::GetFocalPoint(QAD_StudyFrame* theStudyFrame, CORBA::Double theFocalPnt[3]) { GetCamera(theStudyFrame)->GetFocalPoint(theFocalPnt); } VISU::View3D::XYZ_slice* View3D_i::GetFocalPoint() { if(MYDEBUG) MESSAGE("View3D_i::GetFocalPoint"); - Mutex mt(myMutex,qApp,MYDELAY); CORBA::Double aFocalPnt[3]; GetFocalPoint(myStudyFrame,aFocalPnt); return VISU::View3D::XYZ_dup(aFocalPnt); } + + class TSetViewParamEvent: public SALOME_Event{ + public: + typedef void (*TFun)(QAD_StudyFrame* theStudyFrame, CORBA::Double theParam); + TSetViewParamEvent(TFun theFun, + QAD_StudyFrame* theStudyFrame, + CORBA::Double theParam): + myFun(theFun), + myStudyFrame(theStudyFrame), + myParam(theParam) + {} + virtual bool Execute(){ + myFun(myStudyFrame,myParam); + return true; + } + private: + TFun myFun; + QAD_StudyFrame* myStudyFrame; + CORBA::Double myParam; + }; + + void View3D_i::SetParallelScale(QAD_StudyFrame* theStudyFrame, CORBA::Double theScale) { GetCamera(theStudyFrame)->SetParallelScale(theScale); } void View3D_i::SetParallelScale(CORBA::Double theScale) { if(MYDEBUG) MESSAGE("View3D_i::SetParallelScale"); - Mutex mt(myMutex,qApp,MYDELAY); - //myParallelScale = theScale; - SetParallelScale(myStudyFrame, theScale); + ProcessVoidEvent(new TSetViewParamEvent(&SetParallelScale,myStudyFrame,theScale)); } + CORBA::Double View3D_i::GetParallelScale(QAD_StudyFrame* theStudyFrame) { return GetCamera(theStudyFrame)->GetParallelScale(); } CORBA::Double View3D_i::GetParallelScale() { if(MYDEBUG) MESSAGE("View3D_i::GetParallelScale"); - Mutex mt(myMutex,qApp); return GetParallelScale(myStudyFrame); } @@ -1292,18 +1421,22 @@ namespace VISU{ aScaleFactor[theAxis] = theParam; aViewFrame->SetScale(aScaleFactor); } + + void SetScaleView(QAD_StudyFrame* theStudyFrame, const CORBA::Double theScale[3]){ + double aScale[3] = {theScale[0], theScale[1], theScale[2]}; + GetViewFrame(theStudyFrame)->SetScale(aScale); + } void View3D_i::ScaleView(VISU::View3D::Axis theAxis, CORBA::Double theParam) { if(MYDEBUG) MESSAGE("View3D_i::ScaleView"); - Mutex mt(myMutex,qApp); - //myScaleFactor[theAxis] = theParam; - ScaleView(myStudyFrame,theAxis,theParam); + double aScale[3]; + GetViewFrame(myStudyFrame)->GetScale(aScale); + aScale[theAxis] = theParam; + ProcessVoidEvent(new TSet3DViewParamEvent(&SetScaleView,myStudyFrame,aScale)); } void View3D_i::RemoveScale() { if(MYDEBUG) MESSAGE("View3D_i::RemoveScale"); - Mutex mt(myMutex,qApp); - double aScaleFactor[]={1,1,1}; - //myScaleFactor[0] = myScaleFactor[0] = myScaleFactor[0] = 1.0; - GetViewFrame(myStudyFrame)->SetScale(aScaleFactor); + double aScale[3] = {1.0, 1.0, 1.0}; + ProcessVoidEvent(new TSet3DViewParamEvent(&SetScaleView,myStudyFrame,aScale)); } //=========================================================================== } diff --git a/src/VISU_I/VISU_ViewManager_i.hh b/src/VISU_I/VISU_ViewManager_i.hh index 0fb26364..0d4a7e70 100644 --- a/src/VISU_I/VISU_ViewManager_i.hh +++ b/src/VISU_I/VISU_ViewManager_i.hh @@ -57,14 +57,6 @@ namespace VISU{ virtual XYPlot_ptr CreateXYPlot(); virtual void Destroy(View_ptr theView); - // SAN - QT_EVENT prototype - // SALOME event handlers - virtual View3D_ptr OnCreate3DView(); - virtual TableView_ptr OnCreateTableView(VISU::Table_ptr theTable); - virtual XYPlot_ptr OnCreateXYPlot(); - virtual void OnDestroy(View_ptr theView); - // SAN - QT_EVENT prototype - protected: SALOMEDS::Study_var myStudyDocument; }; @@ -178,7 +170,7 @@ namespace VISU{ protected: SALOMEGUI_TableDlg* myView; public: - virtual Storable* Create(VISU::Table_var theTable); + virtual Storable* Create(VISU::Table_ptr theTable); }; //=========================================================================== @@ -244,17 +236,20 @@ namespace VISU{ virtual void ScaleView(VISU::View3D::Axis theAxis, CORBA::Double theParam); virtual void RemoveScale(); - virtual QString GenerateViewParamsName(); + static std::string ToString(QAD_StudyFrame* theStudyFrame); + static void ToStream(QAD_StudyFrame* theStudyFrame, std::ostringstream& theStr); + static bool SaveViewParams(QAD_StudyFrame* theStudyFrame, const char* theName); virtual CORBA::Boolean SaveViewParams(const char* theName); + static QString GenerateViewParamsName(); + + static void Restore(QAD_StudyFrame* theStudyFrame, const Storable::TRestoringMap& theMap) throw(std::logic_error&); + static bool RestoreViewParams(QAD_StudyFrame* theStudyFrame, const char* theName); virtual CORBA::Boolean RestoreViewParams(const char* theName); virtual void Close(); + protected: QAD_StudyFrame* myStudyFrame; - //SALOMEDS::Color myColor; - //CORBA::Double myPosition[3], myFocalPnt[3], myViewUp[3], myParallelScale, myScaleFactor[3]; - - //Storable* Build(int theRestoring); static int myNbViewParams; public: @@ -265,8 +260,6 @@ namespace VISU{ static const string myComment; QAD_StudyFrame* GetStudyFrame() const { return myStudyFrame;} }; - //Storable* View3DRestore(SALOMEDS::SComponent_var& theSComponent, SALOMEDS::Study_var& theStudy, - // const char* thePrefix, const Storable::TRestoringMap& theMap); VTKViewer_ViewFrame* GetViewFrame(QAD_StudyFrame* theStudyFrame); vtkRenderer* GetRenderer(QAD_StudyFrame* theStudyFrame); -- 2.39.2