X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FVISU_I%2FVISU_ViewManager_i.cc;h=cc1df8951a20093cdae537a078efeaf5548027d3;hb=e7e2c50aba46c639191ce54d4b42ae4587abb652;hp=f2f34ed05bcb57cfde4b251891f951936f74a85b;hpb=55d716c5e69656916a6070607a89fb446144fea8;p=modules%2Fvisu.git diff --git a/src/VISU_I/VISU_ViewManager_i.cc b/src/VISU_I/VISU_ViewManager_i.cc index f2f34ed0..cc1df895 100644 --- a/src/VISU_I/VISU_ViewManager_i.cc +++ b/src/VISU_I/VISU_ViewManager_i.cc @@ -1,73 +1,70 @@ -// VISU OBJECT : interactive object for VISU entities implementation +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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. // -// 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 +// 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 // + +// VISU OBJECT : interactive object for VISU entities implementation // File : VISU_ViewManager_i.cc // Author : Alexey PETROV // Module : VISU - +// #include "VISU_ViewManager_i.hh" - -#include "VISU_PrsObject_i.hh" -#include "VISU_Result_i.hh" -#include "VISU_Gen_i.hh" - +#include "VISU_View_i.hh" #include "VISU_Prs3d_i.hh" -#include "VISU_Mesh_i.hh" -#include "VISU_ScalarMap_i.hh" -#include "VISU_IsoSurfaces_i.hh" -#include "VISU_DeformedShape_i.hh" -#include "VISU_CutPlanes_i.hh" -#include "VISU_CutLines_i.hh" -#include "VISU_Vectors_i.hh" -#include "VISU_StreamLines_i.hh" - #include "VISU_Table_i.hh" -#include "VISU_ScalarBarActor.hxx" -#include "VISU_Actor.h" +#include "VISU_Tools.h" -#include "SALOME_Event.hxx" - -#include "QAD_Application.h" -#include "QAD_Desktop.h" -#include "QAD_Tools.h" -#include "QAD_Study.h" -#include "QAD_LeftFrame.h" -#include "QAD_RightFrame.h" -#include "QAD_StudyFrame.h" -#include "QAD_PyEditor.h" - -#include "VTKViewer_ViewFrame.h" -#include "VTKViewer_RenderWindow.h" -#include "SALOMEGUI_TableDlg.h" -#include "Plot2d_CurveContainer.h" +#include "VISU_Actor.h" +#include "VISU_ActorFactory.h" + +#include "SUIT_Tools.h" +#include "SUIT_Session.h" +#include "SUIT_ViewWindow.h" +#include "SUIT_ViewManager.h" + +#include "SVTK_ViewWindow.h" +#include "SVTK_ViewModel.h" +#include "VTKViewer_Algorithm.h" +#include "SPlot2d_Curve.h" +#include "SPlot2d_ViewModel.h" #include "Plot2d_ViewFrame.h" +#include "Plot2d_ViewWindow.h" +#include "Plot2d_ViewModel.h" +#include "Plot2d_ViewManager.h" -#include +#include "SalomeApp_Study.h" +#include "SalomeApp_Application.h" +#include "LightApp_SelectionMgr.h" -#include -#include +#include "SALOME_Event.h" +#include "SALOME_ListIO.hxx" +#include "SALOME_ListIteratorOfListIO.hxx" + +#include "VTKViewer_Algorithm.h" +#include "SVTK_Functor.h" -#include #include +#include +#include + +#include using namespace std; @@ -77,1624 +74,719 @@ static int MYDEBUG = 0; static int MYDEBUG = 0; #endif -static QFileInfo aFileInfo; - -namespace VISU{ - //=========================================================================== - typedef TVoidMemFunEvent TFrameActionEvent; - - template - class TSetBackgroundEvent: public SALOME_Event{ - TObject* myView; - const SALOMEDS::Color& myColor; - public: - TSetBackgroundEvent(TObject* theView, const SALOMEDS::Color& theColor): - myView(theView), myColor(theColor) - {} - virtual void Execute(){ - int aColor[3]; - aColor[0] = int(255.0*myColor.R); - aColor[1] = int(255.0*myColor.G); - aColor[2] = int(255.0*myColor.B); - QColor aNewColor(aColor[0],aColor[1],aColor[2]); - myView->setBackgroundColor(aNewColor); - } - }; +namespace VISU { - class TSetViewRepresentation: public SALOME_Event{ - VISU::View::ViewRepresentation myViewRepr; - View_i* myView; - CORBA::Boolean myState; - public: - TSetViewRepresentation( View_i* aView, - VISU::View::ViewRepresentation ViewRepr, - CORBA::Boolean State ): - SALOME_Event(), myViewRepr( ViewRepr ), myView( aView ), myState( State ) - {} - virtual void Execute(){ - - bool old = myView->IsPartShown( myViewRepr ); - - QAD_RightFrame* fr = myView->myStudyFrame->getRightFrame(); - - if( myView->myStudyFrame != NULL ){ - switch( myViewRepr ) - { - case VISU::View::OBJECTBROWSER: - if( myState!=old ) - if( myState ) - myView->myStudyFrame->unCompressLeft(); - else - myView->myStudyFrame->compressLeft(); - break; - case VISU::View::VIEWER: - if( myState!=old ) - if( myState ) - fr->unCompressUp(); - else - fr->compressUp(); - break; - case VISU::View::PYTHON: - if( myState!=old ) - if( myState ) - fr->unCompressLeft(); - else - fr->compressLeft(); - break; - case VISU::View::MESSAGES: - if( myState!=old ) - if( myState ) - fr->unCompressRight(); - else - fr->compressRight(); - break; - }; - } - } -}; - - class TGetViewRepresentation: public SALOME_Event + struct TNewViewManagerEvent: public SALOME_Event { - public: - typedef CORBA::Boolean TResult; + int myStudyId; + typedef SalomeApp_Application* TResult; TResult myResult; - VISU::View::ViewRepresentation myPart; - View_i* myView; - TGetViewRepresentation( View_i* aView, VISU::View::ViewRepresentation Part ): - SALOME_Event(), myResult( false ), myPart( Part ), myView( aView ) - { - } - virtual void Execute(){ - switch( myPart ) - { - case VISU::View::OBJECTBROWSER: - myResult = !myView->myStudyFrame->isCompressedLeft(); - break; - case VISU::View::VIEWER: - myResult = !myView->myStudyFrame->getRightFrame()->isCompressedViewFrame(); - break; - case VISU::View::PYTHON: - myResult = !myView->myStudyFrame->getRightFrame()->isCompressedPython(); - break; - case VISU::View::MESSAGES: - myResult = !myView->myStudyFrame->getRightFrame()->isCompressedMessage(); - } - } - }; - - class TSetViewWidthHeight: public SALOME_Event{ - CORBA::Long mySize; - bool myIsWidth; - View_i* myView; - public: - TSetViewWidthHeight( View_i* aView, CORBA::Long Size, bool IsWidth ): - SALOME_Event(), mySize( Size ), myView( aView ), myIsWidth( IsWidth ) - {} - virtual void Execute(){ - if( myView->myStudyFrame != NULL ){ - QWidget* aStudyParent = myView->myStudyFrame->parentWidget(true); - int aleft = aStudyParent->frameGeometry().left(); - int atop = aStudyParent->frameGeometry().top(); - int aheight = aStudyParent->frameGeometry().height(); - int awidth = aStudyParent->frameGeometry().width(); - QRect aQRect; - if( myIsWidth ) - aQRect = QRect( aleft, atop, mySize, aheight ); - else - aQRect = QRect( aleft, atop, awidth, mySize ); - - aStudyParent->setGeometry(aQRect); - } - } - }; - - class TGetViewWidthHeight: public SALOME_Event{ - public: - typedef CORBA::Long TResult; - TResult myResult; - bool myIsWidth; - View_i* myView; - public: - TGetViewWidthHeight( View_i* aView, bool IsWidth ): - SALOME_Event(), myView( aView ), myIsWidth( IsWidth ) - {} - - virtual void Execute() - { - if( myView ) { - QWidget* aStudyParent = myView->myStudyFrame->parentWidget(true); - if( myIsWidth ) - myResult = aStudyParent->frameGeometry().width(); - else - myResult = aStudyParent->frameGeometry().height(); - } - } - }; - - class TSetViewPositionHorizontal: public SALOME_Event{ - VISU::View::ViewPosition myViewPos; - View_i* myView; - public: - TSetViewPositionHorizontal ( View_i* aView, - VISU::View::ViewPosition ViewPos ): - SALOME_Event(), myView( aView ), myViewPos(ViewPos) - {} - virtual void Execute(){ - QWidget* aWorkspace = dynamic_cast (myView->myStudy->getApp()->getDesktop()->getMainFrame()); - QWidget* aStudy = dynamic_cast (myView->myStudyFrame); - QWidget* aStudyParent = aStudy->parentWidget(true); - if ( aStudyParent != 0 ) - if ( aWorkspace!=NULL || aStudy != NULL ) - switch(myViewPos){ - case VISU::View::LEFT: - QAD_Tools::alignWidget(aStudyParent,aWorkspace,Qt::AlignLeft); - break; - case VISU::View::CENTER: - QAD_Tools::alignWidget(aStudyParent,aWorkspace,Qt::AlignHCenter); - break; - case VISU::View::RIGHT: - QAD_Tools::alignWidget(aStudyParent,aWorkspace,Qt::AlignRight); - break; - } - } - }; - - class TSetViewPositionVertical: public SALOME_Event{ - VISU::View::ViewPosition myViewPos; - View_i* myView; - public: - TSetViewPositionVertical ( View_i* aView, - VISU::View::ViewPosition ViewPos ): - SALOME_Event(), myView( aView ), myViewPos(ViewPos) + TNewViewManagerEvent (const int theStudyId): + myStudyId(theStudyId), + myResult(NULL) {} - virtual void Execute(){ - QWidget* aWorkspace = dynamic_cast (myView->myStudy->getApp()->getDesktop()->getMainFrame()); - QWidget* aStudy = dynamic_cast (myView->myStudyFrame); - QWidget* aStudyParent = aStudy->parentWidget(true); - if ( aStudyParent != 0 ) - if ( aWorkspace!=NULL || aStudy != NULL ) - switch(myViewPos){ - case VISU::View::TOP: - QAD_Tools::alignWidget(aStudyParent,aWorkspace,Qt::AlignTop); - break; - case VISU::View::CENTER: - QAD_Tools::alignWidget(aStudyParent,aWorkspace,Qt::AlignVCenter); - break; - case VISU::View::BOTTOM: - QAD_Tools::alignWidget(aStudyParent,aWorkspace,Qt::AlignBottom); - break; - } - } - }; - class TSetRelativePosition : public SALOME_Event - { - View_i* myView; - CORBA::Double myX, myY; - public: - TSetRelativePosition ( View_i* aView, CORBA::Double X, CORBA::Double Y ): - SALOME_Event(), myView( aView ), myX( X ), myY( Y ) - {} - virtual void Execute(){ - QWidget* aWorkspace = dynamic_cast (myView->myStudy->getApp()->getDesktop()->getMainFrame()); - if( aWorkspace ) - { - QAD_StudyFrame* aFrame = myView->myStudyFrame; - QWidget* aStudyParent = aFrame->parentWidget(true); - aStudyParent->move( int( myX * aWorkspace->width() ), int( myY * aWorkspace->height() ) ); - } - } - }; - - class TSetRelativeSize : public SALOME_Event - { - View_i* myView; - CORBA::Double myX, myY; - public: - TSetRelativeSize ( View_i* aView, CORBA::Double X, CORBA::Double Y ): - SALOME_Event(), myView( aView ), myX( X ), myY( Y ) - {} - virtual void Execute(){ - QWidget* aWorkspace = dynamic_cast (myView->myStudy->getApp()->getDesktop()->getMainFrame()); - if( aWorkspace ) - { - QAD_StudyFrame* aFrame = myView->myStudyFrame; - QWidget* aStudyParent = aFrame->parentWidget(true); - aStudyParent->setGeometry( aStudyParent->x(), aStudyParent->y(), - int( myX * aWorkspace->width() ), int( myY * aWorkspace->height() ) ); + virtual + void + Execute() + { + MESSAGE("Find application for study with id = : " << myStudyId); + SUIT_Session* aSession = SUIT_Session::session(); + QList anApplications = aSession->applications(); + QList::Iterator anIter = anApplications.begin(); + while ( anIter != anApplications.end() ) { + SUIT_Application* anApp = *anIter; + if (SUIT_Study* aSStudy = anApp->activeStudy()) { + if (SalomeApp_Study* aStudy = dynamic_cast(aSStudy)) { + if (_PTR(Study) aCStudy = aStudy->studyDS()) { + //if (myStudyName == aCStudy->Name()) { + if (myStudyId == aCStudy->StudyId()) { + myResult = dynamic_cast(anApp); + break; + } + } + } + } + anIter++; } - } - }; - - - - class TSavePictureEvent: public SALOME_Event{ - QWidget* myWidget; - const char* myFileName; - public: - typedef CORBA::Boolean TResult; - TResult myResult; - TSavePictureEvent(QWidget* theWidget, const char* theFileName): - myWidget(theWidget), - myFileName(theFileName), - myResult(false) - {} - virtual void Execute(){ - if(myWidget){ - QPixmap px = QPixmap::grabWindow(myWidget->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 (!myResult) { + //MESSAGE("Error: application is not found for study : " << myStudyName); + MESSAGE("Error: application is not found for study with id = : " << myStudyId); } } }; + //=========================================================================== + ViewManager_i::ViewManager_i(SALOMEDS::Study_ptr theStudy) + { + if(MYDEBUG) MESSAGE("ViewManager_i::ViewManager_i - "<(theStudyFrame->getRightFrame()->getViewFrame()); - } - vtkRenderer* GetRenderer(QAD_StudyFrame* theStudyFrame){ - return GetViewFrame(theStudyFrame)->getRenderer(); - } - vtkCamera* GetCamera(QAD_StudyFrame* theStudyFrame){ - return GetRenderer(theStudyFrame)->GetActiveCamera(); - } - - - void RepaintView(VTKViewer_ViewFrame* theViewFrame){ - theViewFrame->getRenderer()->ResetCameraClippingRange(); - theViewFrame->getRW()->getRenderWindow()->Render(); - //GetViewFrame(theStudyFrame)->Repaint(); - } - - void RepaintView(QAD_StudyFrame* theStudyFrame){ - RepaintView(GetViewFrame(theStudyFrame)); + //CORBA::String_var aStudyName = theStudy->Name(); + //myApplication = ProcessEvent(new TNewViewManagerEvent(aStudyName.in())); + int aStudyID = theStudy->StudyId(); + myApplication = ProcessEvent(new TNewViewManagerEvent(aStudyID)); } - VISU_Actor* UpdateViewer(QAD_StudyFrame* theStudyFrame, int theDisplaing, Prs3d_i* thePrs){ - VTKViewer_ViewFrame* vf = GetViewFrame(theStudyFrame); - if (!vf) return NULL; - if(MYDEBUG) MESSAGE("UpdateViewer - theDisplaing = "<GetPrs3d()) { - aResActor = anVISUActor->GetParent(); - if(theDisplaing < eErase) - aResActor->VisibilityOn(); - else - aResActor->VisibilityOff(); - } else { - if(theDisplaing > eDisplay) - anVISUActor->VisibilityOff(); - else - anVISUActor->VisibilityOn(); - } - } - } - if (aResActor) { - RepaintView(theStudyFrame); - return aResActor; - } - if(thePrs != NULL && theDisplaing < eErase){ - try{ - anVISUActor = thePrs->CreateActor(); - vf->AddActor(anVISUActor); - }catch(std::runtime_error& exc){ - INFOS(exc.what()); - return NULL; - } - } - RepaintView(theStudyFrame); - return anVISUActor; - } - void UpdatePlot2d(Plot2d_ViewFrame *theView,int theDisplaying, Curve_i* theCurve) { - if(MYDEBUG) MESSAGE("UpdatePlot2d - theDisplaying = "< clist; - theView->getCurves( clist ); - if ( theDisplaying == eEraseAll ) { - for ( int i = 0; i < clist.count(); i++ ) { - if(MYDEBUG) MESSAGE("UpdatePlot2d - erasing all : curve - "<eraseCurve( clist.at( i ) ); - } - } - else if ( theDisplaying == eErase ) { - for ( int i = 0; i < clist.count(); i++ ) { - if ( theCurve && clist.at( i )->hasIO() && !strcmp( clist.at( i )->getIO()->getEntry(), theCurve->GetEntry() ) ) { - if(MYDEBUG) MESSAGE("UpdatePlot2d - erasing : curve - "<eraseCurve( clist.at( i ) ); - } - } - } - else if ( theDisplaying == eDisplay ) { - bool bFound = false; - for ( int i = 0; i < clist.count(); i++ ) { - if ( theCurve && clist.at( i )->hasIO() && !strcmp( clist.at( i )->getIO()->getEntry(), theCurve->GetEntry() ) ) { - if(MYDEBUG) MESSAGE("UpdatePlot2d - displaying : curve - "<setHorTitle( theCurve->GetHorTitle().c_str() ); - clist.at( i )->setVerTitle( theCurve->GetVerTitle().c_str() ); - clist.at( i )->setHorUnits( theCurve->GetHorUnits().c_str() ); - clist.at( i )->setVerUnits( theCurve->GetVerUnits().c_str() ); - double* xList = 0; - double* yList = 0; - int nbPoints = theCurve->GetData( xList, yList ); - if ( nbPoints > 0 && xList && yList ) { - clist.at( i )->setData( xList, yList, nbPoints ); - } - if ( !theCurve->IsAuto() ) { - clist.at( i )->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() ); - clist.at( i )->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() ); - SALOMEDS::Color color = theCurve->GetColor(); - clist.at( i )->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) ); - } - clist.at( i )->setAutoAssign( theCurve->IsAuto() ); - theView->displayCurve( clist.at( i ) ); - bFound = true; - } - } - if ( !bFound ) { - Plot2d_Curve* crv = theCurve->CreatePresentation(); - if(MYDEBUG) MESSAGE("UpdatePlot2d - displaying : curve (new) - "<displayCurve( crv ); - theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() ); - theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker()); - SALOMEDS::Color newColor; - newColor.R = crv->getColor().red()/255.; - newColor.G = crv->getColor().green()/255.; - newColor.B = crv->getColor().blue()/255.; - theCurve->SetColor( newColor ); - crv->setAutoAssign( theCurve->IsAuto() ); - } - } - } - else if ( theDisplaying == eDisplayOnly ) { - bool bFound = false; - for ( int i = 0; i < clist.count(); i++ ) { - if ( theCurve && clist.at( i )->hasIO() && !strcmp( clist.at( i )->getIO()->getEntry(), theCurve->GetEntry() ) ) { - if(MYDEBUG) MESSAGE("UpdatePlot2d - displaying only : curve - "<setHorTitle( theCurve->GetHorTitle().c_str() ); - clist.at( i )->setVerTitle( theCurve->GetVerTitle().c_str() ); - clist.at( i )->setHorUnits( theCurve->GetHorUnits().c_str() ); - clist.at( i )->setVerUnits( theCurve->GetVerUnits().c_str() ); - double* xList = 0; - double* yList = 0; - int nbPoints = theCurve->GetData( xList, yList ); - if ( nbPoints > 0 && xList && yList ) { - clist.at( i )->setData( xList, yList, nbPoints ); - } - if ( !theCurve->IsAuto() ) { - clist.at( i )->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() ); - clist.at( i )->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() ); - SALOMEDS::Color color = theCurve->GetColor(); - clist.at( i )->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) ); - } - clist.at( i )->setAutoAssign( theCurve->IsAuto() ); - theView->displayCurve( clist.at( i ) ); - bFound = true; - } - else { - theView->eraseCurve( clist.at( i ) ); - } - } - if ( !bFound ) { - Plot2d_Curve* crv = theCurve->CreatePresentation(); - if(MYDEBUG) MESSAGE("UpdatePlot2d - displaying only : curve (new) - "<displayCurve( crv ); - theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() ); - theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker()); - SALOMEDS::Color newColor; - newColor.R = crv->getColor().red()/255.; - newColor.G = crv->getColor().green()/255.; - newColor.B = crv->getColor().blue()/255.; - theCurve->SetColor( newColor ); - crv->setAutoAssign( theCurve->IsAuto() ); - } - } - } + ViewManager_i::~ViewManager_i() + { + if(MYDEBUG) MESSAGE("ViewManager_i::~ViewManager_i - "<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; - } - //=========================================================================== - ViewManager_i::ViewManager_i(SALOMEDS::Study_ptr theStudy) { - if(MYDEBUG) MESSAGE("ViewManager_i::ViewManager_i"); - myStudyDocument = SALOMEDS::Study::_duplicate(theStudy); - } + struct TCurrentViewEvent: public SALOME_Event + { + SalomeApp_Application* myApplication; + typedef VISU::View_ptr TResult; + TResult myResult; - class TGetCurrentViewEvent: public SALOME_Event{ - SALOMEDS::Study_ptr myStudyDocument; - public: - TGetCurrentViewEvent( SALOMEDS::Study_ptr theStudy): - myStudyDocument(theStudy), + TCurrentViewEvent(SalomeApp_Application* theApplication): + myApplication(theApplication), myResult(VISU::View::_nil()) {} - virtual void Execute(){ - 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(); - } - } - } + + virtual + void + Execute() + { + VISU::View3D_i* aView = new View3D_i (myApplication); + if (aView->Create(0)) + myResult = aView->_this(); } - typedef VISU::View_ptr TResult; - TResult myResult; }; VISU::View_ptr ViewManager_i::GetCurrentView(){ - return ProcessEvent(new TGetCurrentViewEvent( myStudyDocument )); + return ProcessEvent(new TCurrentViewEvent(myApplication)); } - - - class TCreateViewEvent: public SALOME_Event{ - public: - TCreateViewEvent( SALOMEDS::Study_ptr theStudy): - myStudyDocument(theStudy) - {}; - protected: - SALOMEDS::Study_ptr myStudyDocument; - }; template - class TCreateViewFrameEvent: public TCreateViewEvent{ - public: + struct TCreateViewFrameEvent: public SALOME_Event + { + SalomeApp_Application* myApplication; typedef typename TViewFrame::TInterface TInterface; typedef typename TInterface::_ptr_type TResult; TResult myResult; - TCreateViewFrameEvent(SALOMEDS::Study_ptr theStudy): - TCreateViewEvent(theStudy), + + TCreateViewFrameEvent (SalomeApp_Application* theApplication): + myApplication(theApplication), myResult(TInterface::_nil()) {} - virtual void Execute(){ - if(CheckStudy(myStudyDocument)){ - TViewFrame* pView = new TViewFrame(myStudyDocument); - if(pView->Create(1)) - myResult = pView->_this(); + + virtual + void + Execute() + { + //if (CheckStudy(myStudyDocument)) { + if (myApplication) { + TViewFrame* pView = new TViewFrame (myApplication); + if (pView->Create(1)) { + myResult = pView->_this(); + qApp->processEvents(); // Fix for bug 9929 + } } } }; - VISU::View3D_ptr ViewManager_i::Create3DView(){ - if(MYDEBUG) MESSAGE("ViewManager_i::Create3DView"); - return ProcessEvent(new TCreateViewFrameEvent(myStudyDocument)); + VISU::View3D_ptr ViewManager_i::Create3DView() + { + if (MYDEBUG) MESSAGE("ViewManager_i::Create3DView"); + return ProcessEvent(new TCreateViewFrameEvent(myApplication)); } - - VISU::XYPlot_ptr ViewManager_i::CreateXYPlot(){ - if(MYDEBUG) MESSAGE("ViewManager_i::CreateXYPlot"); - return ProcessEvent(new TCreateViewFrameEvent(myStudyDocument)); + VISU::XYPlot_ptr ViewManager_i::CreateXYPlot() + { + if (MYDEBUG) MESSAGE("ViewManager_i::CreateXYPlot"); + return ProcessEvent(new TCreateViewFrameEvent(myApplication)); } + class TCreateViewEvent: public SALOME_Event + { + public: + TCreateViewEvent (SalomeApp_Application* theApplication) + : myApplication(theApplication) + {} + protected: + SalomeApp_Application* myApplication; + }; - class TCreateTableViewEvent: public TCreateViewEvent{ + class TCreateTableViewFrameEvent: public TCreateViewEvent + { Table_ptr myTable; public: - TCreateTableViewEvent(SALOMEDS::Study_ptr theStudy, - Table_ptr theTable): - TCreateViewEvent(theStudy), + TCreateTableViewFrameEvent (SalomeApp_Application* theApplication, + Table_ptr theTable): + TCreateViewEvent(theApplication), myTable(theTable), myResult(VISU::TableView::_nil()) {} - virtual void Execute(){ - if ( CheckStudy( myStudyDocument ) ) { - VISU::TableView_i* pView = new TableView_i(myStudyDocument); - if(pView->Create(myTable) != NULL) - myResult = pView->_this(); - } + + virtual void Execute() + { + //if (CheckStudy(myStudyDocument)) { + VISU::TableView_i* pView = new TableView_i (myApplication); + if (pView->Create(myTable) != NULL) + myResult = pView->_this(); + //} } typedef VISU::TableView_ptr TResult; TResult myResult; }; - VISU::TableView_ptr ViewManager_i::CreateTableView(VISU::Table_ptr theTable){ - if(MYDEBUG) MESSAGE("ViewManager_i::CreateTableView"); - return ProcessEvent(new TCreateTableViewEvent(myStudyDocument,theTable)); + VISU::TableView_ptr ViewManager_i::CreateTableView (VISU::Table_ptr theTable) + { + if (MYDEBUG) MESSAGE("ViewManager_i::CreateTableView"); + //return ProcessEvent(new TCreateViewFrameEvent(myApplication)); + return ProcessEvent(new TCreateTableViewFrameEvent (myApplication, theTable)); } - - void ViewManager_i::Destroy(View_ptr theView){ - class TEvent: public SALOME_Event{ + void ViewManager_i::Destroy (View_ptr theView) + { + class TEvent: public SALOME_Event { View_ptr myView; public: TEvent(View_ptr theView): - myView(theView) + myView(theView) {} virtual void Execute(){ - if(!CORBA::is_nil(myView)){ - if(VISU::View_i* pView = dynamic_cast(VISU::GetServant(myView).in())) { - pView->Close(); - pView->_remove_ref(); - } - } + if (!CORBA::is_nil(myView)) { + if (VISU::View_i* pView = dynamic_cast(VISU::GetServant(myView).in())) { + pView->Close(); + pView->_remove_ref(); + } + } } }; - if(MYDEBUG) MESSAGE("ViewManager_i::Destroy - "<_is_nil()); + + if (MYDEBUG) MESSAGE("ViewManager_i::Destroy - " << theView->_is_nil()); ProcessVoidEvent(new TEvent(theView)); } - //=========================================================================== - View_i::View_i(SALOMEDS::Study_ptr theStudy) { - myStudyFrame = NULL; - if(MYDEBUG) MESSAGE("View_i::View_i"); - CORBA::String_var aName = theStudy->Name(); - myStudy = CheckStudy(theStudy); - if(MYDEBUG) MESSAGE("View_i::View_i - isStudyOpened = "<getStudyDocument()->FindObjectIOR(GetID()); - CORBA::String_var anEntry = aSObject->GetID(); - return string(anEntry.in()); - } - - + // VISU namespace functions //=========================================================================== - XYPlot_i::XYPlot_i(SALOMEDS::Study_ptr theStudy) : View_i(theStudy) { - if(MYDEBUG) MESSAGE("XYPlot_i::XYPlot_i"); - } - - Storable* XYPlot_i::Create(int theNew){ - if(theNew) - myStudyFrame = myStudy->newWindow3d("",VIEW_PLOT2D); - else - myStudyFrame = myStudy->getActiveStudyFrame(); - myView = dynamic_cast(myStudyFrame->getRightFrame()->getViewFrame()); - myView->Repaint(); - return this; - } - - - void XYPlot_i::Update() { - ProcessVoidEvent(new TVoidMemFunEvent(myView,&Plot2d_ViewFrame::Repaint)); - } - - - void XYPlot_i::Close(){ - myStudyFrame->close(); - } - - XYPlot_i::~XYPlot_i() { - if(MYDEBUG) MESSAGE("XYPlot_i::~XYPlot_i"); - } - - - void XYPlot_i::SetTitle(const char* theTitle){ - ProcessVoidEvent(new TVoidMemFun1ArgEvent - (myStudyFrame,&QAD_StudyFrame::setCaption,QString(theTitle))); - } - char* XYPlot_i::GetTitle() { - return CORBA::string_dup(myStudyFrame->title().latin1()); - } - - - void XYPlot_i::SetSubTitle(const char* theTitle){ - ProcessVoidEvent(new TVoidMemFun1ArgEvent - (myView,&Plot2d_ViewFrame::setTitle,QString(theTitle))); - } - char* XYPlot_i::GetSubTitle() { - return CORBA::string_dup(myView->getTitle()); - } - - - void XYPlot_i::SetCurveType(VISU::XYPlot::CurveType theType){ - ProcessVoidEvent(new TVoidMemFun2ArgEvent - (myView,&Plot2d_ViewFrame::setCurveType,theType,true)); - } - VISU::XYPlot::CurveType XYPlot_i::GetCurveType(){ - return (VISU::XYPlot::CurveType)myView->getCurveType(); - } - - - void XYPlot_i::SetMarkerSize(CORBA::Long theSize){ - ProcessVoidEvent(new TVoidMemFun2ArgEvent - (myView,&Plot2d_ViewFrame::setMarkerSize,theSize,true)); - } - CORBA::Long XYPlot_i::GetMarkerSize(){ - return myView->getMarkerSize(); - } - - - class TEnbleGridEvent: public SALOME_Event{ - public: - typedef void (Plot2d_ViewFrame::* TFun)(bool, const int, bool, const int, bool = true); - TEnbleGridEvent(Plot2d_ViewFrame* theView, TFun theFun, - CORBA::Boolean theMajor, CORBA::Long theNumMajor, - CORBA::Boolean theMinor, CORBA::Long theNumMinor): - myView(theView), myFun(theFun), - myMajor(theMajor), myNumMajor(theNumMajor), - myMinor(theMinor), myNumMinor(theNumMinor) - {} - virtual void Execute(){ - (myView->*myFun)(myMajor,myNumMajor,myMinor,myNumMinor); - } - protected: - Plot2d_ViewFrame* myView; - TFun myFun; - CORBA::Boolean myMajor, myNumMajor; - CORBA::Boolean myMinor, myNumMinor; - }; - - - void XYPlot_i::EnableXGrid(CORBA::Boolean theMajor, CORBA::Long theNumMajor, - CORBA::Boolean theMinor, CORBA::Long theNumMinor) - { - ProcessVoidEvent(new TEnbleGridEvent(myView,&Plot2d_ViewFrame::setXGrid, - theMajor,theNumMajor,theMinor,theNumMinor)); - } - void XYPlot_i::EnableYGrid(CORBA::Boolean theMajor, CORBA::Long theNumMajor, - CORBA::Boolean theMinor, CORBA::Long theNumMinor) + vtkRenderer* GetRenderer (SUIT_ViewWindow* theViewWindow) { - ProcessVoidEvent(new TEnbleGridEvent(myView,&Plot2d_ViewFrame::setYGrid, - theMajor,theNumMajor,theMinor,theNumMinor)); - } - - - class TSetScaleModeEvent: public SALOME_Event{ - public: - typedef void (Plot2d_ViewFrame::* TFun)(const int, bool = true); - TSetScaleModeEvent(Plot2d_ViewFrame* theView, TFun theFun, int theScaling): - myView(theView), myFun(theFun), myScaling(theScaling) - {} - virtual void Execute(){ - (myView->*myFun)(myScaling); - } - protected: - Plot2d_ViewFrame* myView; - TFun myFun; - int myScaling; - }; - - - void XYPlot_i::SetHorScaling(VISU::Scaling theScaling){ - ProcessVoidEvent(new TSetScaleModeEvent(myView,&Plot2d_ViewFrame::setHorScaleMode, - theScaling == VISU::LOGARITHMIC)); - } - VISU::Scaling XYPlot_i::GetHorScaling(){ - return (VISU::Scaling)myView->getHorScaleMode(); + if (SVTK_ViewWindow* vw = dynamic_cast(theViewWindow)) + return vw->getRenderer(); + return NULL; } - - void XYPlot_i::SetVerScaling(VISU::Scaling theScaling){ - ProcessVoidEvent(new TSetScaleModeEvent(myView,&Plot2d_ViewFrame::setVerScaleMode, - theScaling == VISU::LOGARITHMIC)); - } - VISU::Scaling XYPlot_i::GetVerScaling(){ - return (VISU::Scaling)myView->getVerScaleMode(); + vtkCamera* GetCamera (SUIT_ViewWindow* theViewWindow) + { + return GetRenderer(theViewWindow)->GetActiveCamera(); } - - class TSetTitleEvent: public SALOME_Event{ - public: - typedef void (Plot2d_ViewFrame::* TFun)(bool, const QString&, bool = true); - TSetTitleEvent(Plot2d_ViewFrame* theView, TFun theFun, const char* theTitle): - myView(theView), myFun(theFun), myTitle(theTitle) - {} - virtual void Execute(){ - (myView->*myFun)(true,myTitle); + void RepaintView (SUIT_ViewWindow* theViewWindow) + { + if (SVTK_ViewWindow* vf = dynamic_cast(theViewWindow)) { + vf->getRenderer()->ResetCameraClippingRange(); + vf->getRenderWindow()->Render(); } - protected: - Plot2d_ViewFrame* myView; - TFun myFun; - const char* myTitle; - }; - - - void XYPlot_i::SetXTitle(const char* theTitle){ - ProcessVoidEvent(new TSetTitleEvent(myView,&Plot2d_ViewFrame::setXTitle,theTitle)); - } - char* XYPlot_i::GetXTitle() { - return CORBA::string_dup(myView->getXTitle()); - } - - - void XYPlot_i::SetYTitle(const char* theTitle){ - ProcessVoidEvent(new TSetTitleEvent(myView,&Plot2d_ViewFrame::setYTitle,theTitle)); - } - char* XYPlot_i::GetYTitle() { - return CORBA::string_dup(myView->getYTitle()); - } - - - void XYPlot_i::ShowLegend(CORBA::Boolean theShowing){ - ProcessVoidEvent(new TVoidMemFun2ArgEvent - (myView,&Plot2d_ViewFrame::showLegend,theShowing,true)); } - - void XYPlot_i::SetBackground(const SALOMEDS::Color& theColor){ - ProcessVoidEvent(new TSetBackgroundEvent(myView,theColor)); - } - SALOMEDS::Color XYPlot_i::GetBackground() { - SALOMEDS::Color aColor; - aColor.R = myView->backgroundColor().red()/255.0; - aColor.G = myView->backgroundColor().green()/255.0; - aColor.B = myView->backgroundColor().blue()/255.0; - return aColor; - } - - void XYPlot_i::Minimize() { - ProcessVoidEvent(new TFrameActionEvent(myStudyFrame,&QAD_StudyFrame::showMinimized)); - } - - void XYPlot_i::Restore() { - ProcessVoidEvent(new TFrameActionEvent(myStudyFrame, &QAD_StudyFrame::showNormal)); - } - - void XYPlot_i::Maximize() { - ProcessVoidEvent(new TFrameActionEvent(myStudyFrame, &QAD_StudyFrame::showMaximized)); - } - - - class TXYPlotViewEvent: public SALOME_Event{ - QAD_Study* myStudy; - Plot2d_ViewFrame* myView; - PrsObject_ptr myPrsObj; - int myDisplaing; - public: - TXYPlotViewEvent(QAD_Study* theStudy, - Plot2d_ViewFrame* theView, - PrsObject_ptr thePrsObj, - int theDisplaing): - myStudy(theStudy), - myView(theView), - myPrsObj(thePrsObj), - myDisplaing(theDisplaing) - {} - virtual void Execute(){ - // is it Curve ? - if(Curve_i* aCurve = dynamic_cast(VISU::GetServant(myPrsObj).in())) { - UpdatePlot2d(myView,myDisplaing,aCurve); - } - // is it Container ? - if(Container_i* aContainer = dynamic_cast(VISU::GetServant(myPrsObj).in())) { - int nbCurves = aContainer->GetNbCurves(); - for ( int i = 1; i <= nbCurves; i++ ) { - VISU::Curve_i* aCurve = aContainer->GetCurve( i ); - if ( aCurve && aCurve->IsValid() ) { - UpdatePlot2d(myView,myDisplaing,aCurve); + VISU_Actor* UpdateViewer (SUIT_ViewWindow* theViewWindow, int theDisplaing, Prs3d_i* thePrs) + { + SVTK_ViewWindow* vf = dynamic_cast(theViewWindow); + if (!vf) return NULL; + if(MYDEBUG) MESSAGE("UpdateViewer - theDisplaing = "<GetPrs3d()) { + aResActor = anVISUActor; + if(theDisplaing < eErase) { + aResActor->VisibilityOn(); + VISU::SetVisibilityState(aResActor, Qtx::ShownState); } - } - myView->Repaint(); - } - // is it Table ? - if(Table_i* aTable = dynamic_cast(VISU::GetServant(myPrsObj).in())) { - SALOMEDS::Study_var aStudy = myStudy->getStudyDocument(); - SALOMEDS::SObject_var TableSO = aStudy->FindObjectID( aTable->GetEntry() ); - if ( !TableSO->_is_nil() ) { - SALOMEDS::ChildIterator_var Iter = aStudy->NewChildIterator( TableSO ); - for ( ; Iter->More(); Iter->Next() ) { - CORBA::Object_var childObject = VISU::SObjectToObject( Iter->Value() ); - if( !CORBA::is_nil( childObject ) ) { - CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject ); - if( !CORBA::is_nil( aCurve ) ) - UpdatePlot2d(myView,myDisplaing,dynamic_cast( VISU::GetServant(aCurve).in())); - } + else { + aResActor->VisibilityOff(); + VISU::SetVisibilityState(aResActor, Qtx::HiddenState); + } + } else { + if(theDisplaing == eEraseAll || theDisplaing == eDisplayOnly) { + anVISUActor->VisibilityOff(); + VISU::SetVisibilityState(aResActor, Qtx::HiddenState); } - myView->Repaint(); - } + else if ( theDisplaing == eDisplayAll ) { + anVISUActor->VisibilityOn(); + VISU::SetVisibilityState(aResActor, Qtx::HiddenState); + } + } } } - }; - - - void XYPlot_i::Display(PrsObject_ptr thePrsObj) { - ProcessVoidEvent(new TXYPlotViewEvent(myStudy,myView,thePrsObj,eDisplay)); - } - - - void XYPlot_i::Erase(PrsObject_ptr thePrsObj) { - ProcessVoidEvent(new TXYPlotViewEvent(myStudy,myView,thePrsObj,eErase)); - } - - - void XYPlot_i::DisplayOnly(PrsObject_ptr thePrsObj) { - ProcessVoidEvent(new TXYPlotViewEvent(myStudy,myView,thePrsObj,eDisplayOnly)); - } - - - void XYPlot_i::EraseAll() { - ProcessVoidEvent(new TVoidMemFunEvent(myView,&Plot2d_ViewFrame::EraseAll)); - } - - - void XYPlot_i::FitAll() { - ProcessVoidEvent(new TVoidMemFunEvent(myView,&Plot2d_ViewFrame::fitAll)); - } - - - CORBA::Boolean XYPlot_i::SavePicture(const char* theFileName) { - return ProcessEvent(new TSavePictureEvent(myView->getViewWidget(),theFileName)); - } - - - //=========================================================================== - TableView_i::TableView_i(SALOMEDS::Study_ptr theStudy) : View_i(theStudy) {} - Storable* TableView_i::Create(VISU::Table_ptr theTable){ - if(MYDEBUG) MESSAGE("TableView_i::Create - "<<(!theTable->_is_nil())); - if(!theTable->_is_nil()){ - VISU::Table_i* table = dynamic_cast(VISU::GetServant(theTable).in()); - if(MYDEBUG) MESSAGE("TableView_i::Create - dynamic_cast = "<getStudyDocument()->FindObjectID(table->GetObjectEntry()); - if(!aSObject->_is_nil()) { - myView = new SALOMEGUI_TableDlg(QAD_Application::getDesktop(), - aSObject, - false, - SALOMEGUI_TableDlg::ttAuto, - Qt::Vertical); - myView->show(); - return this; - } + if (aResActor) { + RepaintView(theViewWindow); + return aResActor; + } + if(thePrs != NULL && theDisplaing < eErase){ + try{ + anVISUActor = thePrs->CreateActor(); + vf->AddActor(anVISUActor); + }catch(std::exception& exc){ + if(MYDEBUG) INFOS(exc.what()); + return NULL; + }catch(...){ + if(MYDEBUG) INFOS("Unknown exception was occured!!!"); + return NULL; } } - return NULL; - } - - - TableView_i::~TableView_i() { - if(MYDEBUG) MESSAGE("TableView_i::~TableView_i"); - delete myView; - } - - - void TableView_i::SetTitle(const char* theTitle){ - ProcessVoidEvent(new TVoidMemFun1ArgEvent - (myView,&SALOMEGUI_TableDlg::setCaption,QString(theTitle))); - } - - - char* TableView_i::GetTitle() { - return CORBA::string_dup(myView->caption().latin1()); - } - - - void TableView_i::Close(){ - myView->close(); - } - - - //=========================================================================== - int View3D_i::myNbViewParams = 0; - const string View3D_i::myComment = "VIEW3D"; - const char* View3D_i::GetComment() const { return myComment.c_str();} - QString View3D_i::GenerateViewParamsName() { - return VISU::GenerateName( "ViewParams", ++myNbViewParams ); - } - - View3D_i::View3D_i(SALOMEDS::Study_ptr theStudy) : View_i(theStudy) { - if(MYDEBUG) MESSAGE("View3D_i::View3D_i"); + RepaintView(theViewWindow); + return anVISUActor; } - Storable* View3D_i::Create(int theNew){ - if(MYDEBUG) MESSAGE("View3D_i::Create"); - if(theNew) - myStudyFrame = myStudy->newWindow3d("",VIEW_VTK); - else - myStudyFrame = myStudy->getActiveStudyFrame(); - return this; - } + struct TUpdatePlot2dEvent: public SALOME_Event + { + Curve_i* myCurve; + int myDisplaying; + TUpdatePlot2dEvent (Curve_i* theCurve, const int theDisplaying): + myCurve(theCurve), + myDisplaying(theDisplaying) + {} - void View3D_i::Update(){ - class TEvent: public SALOME_Event{ - QAD_StudyFrame* myStudyFrame; - public: - TEvent(QAD_StudyFrame* theStudyFrame): - myStudyFrame(theStudyFrame) - {} - virtual void Execute(){ - VTKViewer_ViewFrame* vf = GetViewFrame(myStudyFrame); - vtkRenderer* Renderer = vf->getRenderer(); - vtkActorCollection* theActors = Renderer->GetActors(); - theActors->InitTraversal(); - while(vtkActor *anAct = theActors->GetNextActor()){ - if(VISU_Actor* anActor = dynamic_cast(anAct)){ - VISU::Prs3d_i* aPrs3d = anActor->GetPrs3d(); - if(anActor->GetVisibility() && aPrs3d){ - aPrs3d->Update(); - aPrs3d->UpdateActor(anActor); - } - } - } - RepaintView(myStudyFrame); + virtual void Execute() + { + SalomeApp_Application* anApp = NULL; + CORBA::String_var studyName = myCurve->GetStudyDocument()->Name(); + std::string aStudyName = studyName.in(); + SUIT_Session* aSession = SUIT_Session::session(); + QList anApplications = aSession->applications(); + QList::Iterator anIter = anApplications.begin(); + while (anIter != anApplications.end()) { + SUIT_Application* aSUITApp = *anIter; + if (SUIT_Study* aSStudy = aSUITApp->activeStudy()) { + if (SalomeApp_Study* aStudy = dynamic_cast(aSStudy)) { + if (_PTR(Study) aCStudy = aStudy->studyDS()) { + if (aStudyName == aCStudy->Name()) { + anApp = dynamic_cast(aSUITApp); + break; + } + } + } + } + anIter++; } - }; - ProcessVoidEvent(new TEvent(myStudyFrame)); - } - - - CORBA::Boolean View3D_i::SavePicture(const char* theFileName) { - return ProcessEvent(new TSavePictureEvent(myStudyFrame->getRightFrame()->getViewFrame()->getViewWidget(),theFileName)); - } - - - 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 = - 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::SaveViewParams - anEntry = "<FindAttribute(anAttr, "AttributeComment")){ - SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr); - aString = aCmnt->Value(); - string aComm(aString); - if(MYDEBUG) MESSAGE("View3D_i::SaveViewPoint - aComm = "<= 0){ - aCmnt->SetValue(ToString(theStudyFrame).c_str()); - return true; - } - } + if (!anApp) + return; + + ViewManagerList aViewManagerList; + anApp->viewManagers(SPlot2d_Viewer::Type(), aViewManagerList); + SUIT_ViewManager* aViewManager; + foreach( aViewManager, aViewManagerList ) { + if (Plot2d_ViewManager* aManager = dynamic_cast(aViewManager)) { + if (SPlot2d_Viewer* aViewer = dynamic_cast(aManager->getViewModel())) { + if (Plot2d_ViewFrame* aViewFrame = aViewer->getActiveViewFrame()) { + UpdatePlot2d(myCurve, myDisplaying, aViewFrame); + } + } + } } } - 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){ - return SaveViewParams(myStudyFrame,theName); - } - + }; - bool View3D_i::RestoreViewParams(QAD_StudyFrame* theStudyFrame, const char* theName){ - SALOMEDS::Study::ListOfSObject_var aList = - theStudyFrame->getStudy()->getStudyDocument()->FindObjectByName(theName,"VISU"); - SALOMEDS::GenericAttribute_var anAttr; - int iEnd = aList->length(); - if(MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - iEnd = "<GetID(); - string anEntry(aString); - if(MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - anEntry = "<FindAttribute(anAttr, "AttributeComment")){ - SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr); - aString = aCmnt->Value(); - QString strIn(aString); - Storable::TRestoringMap aMap; - Storable::StrToMap(strIn,aMap); - if ( Storable::FindValue( aMap,"myComment").compare( View3D_i::myComment.c_str() ) >= 0 ) { - if(MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - aComm = "<eraseCurve(clist.at(i)); + } + } else if (theDisplaying == eErase) { + if (theCurve) { + for (int i = 0; i < clist.count(); i++) { + SPlot2d_Curve* aSPlot2dC = dynamic_cast(clist.at(i)); + if (aSPlot2dC->hasIO() && + !strcmp(theCurve->GetEntry().c_str(), aSPlot2dC->getIO()->getEntry())) { + if(MYDEBUG) MESSAGE("UpdatePlot2d - erasing : curve - " << aSPlot2dC); + theView->eraseCurve(aSPlot2dC); + } + } + } + } else if (theDisplaying == eDisplay || + theDisplaying == eDisplayOnly || + theDisplaying == eUpdateData) { + if (theCurve) { + bool bFound = false; + for (int i = 0; i < clist.count(); i++) { + SPlot2d_Curve* aSPlot2dC = dynamic_cast(clist.at(i)); + if (aSPlot2dC->hasIO() && + !strcmp(theCurve->GetEntry().c_str(), aSPlot2dC->getIO()->getEntry())) { + if (theDisplaying == eUpdateData) { + if(MYDEBUG) MESSAGE("UpdatePlot2d - updating data : curve - " << aSPlot2dC); + } + else { + if(MYDEBUG) MESSAGE("UpdatePlot2d - displaying : curve - " << aSPlot2dC); + } + double* xList = 0; + double* yList = 0; + QStringList zList; + int nbPoints = theCurve->GetData( xList, yList, zList ); + if (nbPoints > 0 && xList && yList) { + aSPlot2dC->setData( xList, yList, nbPoints, zList ); + } + if (theDisplaying == eUpdateData) { + theView->updateCurve(aSPlot2dC, true); + } else { + aSPlot2dC->setHorTitle( theCurve->GetHorTitle().c_str() ); + aSPlot2dC->setVerTitle( theCurve->GetVerTitle().c_str() ); + aSPlot2dC->setHorUnits( theCurve->GetHorUnits().c_str() ); + aSPlot2dC->setVerUnits( theCurve->GetVerUnits().c_str() ); + if (!theCurve->IsAuto()) { + aSPlot2dC->setLine((Plot2d::LineType)theCurve->GetLine(), + theCurve->GetLineWidth()); + aSPlot2dC->setMarker((Plot2d::MarkerType)theCurve->GetMarker()); + SALOMEDS::Color color = theCurve->GetColor(); + aSPlot2dC->setColor(QColor((int)(color.R*255.), + (int)(color.G*255.), + (int)(color.B*255.))); + } + aSPlot2dC->setAutoAssign(theCurve->IsAuto()); + theView->displayCurve(aSPlot2dC); + bFound = true; + } + } else if (theDisplaying == eDisplayOnly) { + theView->eraseCurve(aSPlot2dC); + } + } + if (!bFound && theDisplaying != eUpdateData) { + Plot2d_Curve* crv = theCurve->CreatePresentation(); + if(MYDEBUG) MESSAGE("UpdatePlot2d - displaying : curve (new) - "<displayCurve( crv ); + theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() ); + theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker()); + SALOMEDS::Color newColor; + newColor.R = crv->getColor().red()/255.; + newColor.G = crv->getColor().green()/255.; + newColor.B = crv->getColor().blue()/255.; + theCurve->SetColor( newColor ); + crv->setAutoAssign( theCurve->IsAuto() ); + } + } } } - return false; } - class TRestoreViewParamsEvent: public SALOME_Event{ - QAD_StudyFrame* myStudyFrame; - const char* myName; - public: - TRestoreViewParamsEvent(QAD_StudyFrame* theStudyFrame, - const char* theName): - myStudyFrame(theStudyFrame), - myName(theName) + //---------------------------------------------------------------------------- + struct TIsSamePrs3d + { + VISU::Prs3d_i* myPrs3d; + + TIsSamePrs3d(VISU::Prs3d_i* thePrs3d): + myPrs3d(thePrs3d) {} - virtual void Execute(){ - myResult = View3D_i::RestoreViewParams(myStudyFrame,myName); + + bool + operator()(VISU_Actor* theActor) + { + return theActor->GetPrs3d() == myPrs3d; } - typedef CORBA::Boolean TResult; - TResult myResult; }; - CORBA::Boolean View3D_i::RestoreViewParams(const char* theName){ - return ProcessEvent(new TRestoreViewParamsEvent(myStudyFrame,theName)); - } - - void View3D_i::Restore(QAD_StudyFrame* theStudyFrame, const Storable::TRestoringMap& theMap){ - SALOMEDS::Color aColor; - aColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble(); - aColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble(); - aColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble(); - - double aPosition[3]; - aPosition[0] = VISU::Storable::FindValue(theMap,"myPosition[0]").toDouble(); - aPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble(); - aPosition[2] = VISU::Storable::FindValue(theMap,"myPosition[2]").toDouble(); - - double aFocalPnt[3]; - aFocalPnt[0] = VISU::Storable::FindValue(theMap,"myFocalPnt[0]").toDouble(); - aFocalPnt[1] = VISU::Storable::FindValue(theMap,"myFocalPnt[1]").toDouble(); - aFocalPnt[2] = VISU::Storable::FindValue(theMap,"myFocalPnt[2]").toDouble(); - - double aViewUp[3]; - aViewUp[0] = VISU::Storable::FindValue(theMap,"myViewUp[0]").toDouble(); - aViewUp[1] = VISU::Storable::FindValue(theMap,"myViewUp[1]").toDouble(); - aViewUp[2] = VISU::Storable::FindValue(theMap,"myViewUp[2]").toDouble(); - - double aParallelScale = VISU::Storable::FindValue(theMap,"myParallelScale").toDouble(); - - double aScaleFactor[3]; - aScaleFactor[0] = VISU::Storable::FindValue(theMap,"myScaleFactor[0]").toDouble(); - aScaleFactor[1] = VISU::Storable::FindValue(theMap,"myScaleFactor[1]").toDouble(); - aScaleFactor[2] = VISU::Storable::FindValue(theMap,"myScaleFactor[2]").toDouble(); - - 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]); - } - - - string View3D_i::ToString(QAD_StudyFrame* theStudyFrame){ - ostringstream strOut; - Storable::DataToStream( strOut, "myComment", myComment.c_str() ); - ToStream(theStudyFrame,strOut); - strOut<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(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(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(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(theStudyFrame)); - - double aScaleFactor[3]; - 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(){ - myStudyFrame->close(); - } - - View3D_i::~View3D_i() { - if(MYDEBUG) MESSAGE("View3D_i::~View3D_i"); - } - - //-------------------- View interface -------------------- - - void View_i::ShowPart( VISU::View::ViewRepresentation ViewRepr, CORBA::Boolean state ) { - ProcessVoidEvent( new TSetViewRepresentation( this, ViewRepr, state ) ); - Update(); - } - - CORBA::Boolean View_i::IsPartShown( VISU::View::ViewRepresentation Part ) + //---------------------------------------------------------------------------- + VISU_Actor* + FindActor(SVTK_ViewWindow* theViewWindow, VISU::Prs3d_i* thePrs3d) { - return ProcessEvent( new TGetViewRepresentation( this, Part ) ); - } - - void View_i::SetViewWidth(CORBA::Long Width){ - ProcessVoidEvent( new TSetViewWidthHeight( this, Width, true ) ); - } - - void View_i::SetViewHeight(CORBA::Long Height){ - ProcessVoidEvent( new TSetViewWidthHeight( this, Height, false ) ); - } - - CORBA::Long View_i::GetViewWidth() - { - return ProcessEvent( new TGetViewWidthHeight( this, true ) ); - } - - CORBA::Long View_i::GetViewHeight() - { - return ProcessEvent( new TGetViewWidthHeight( this, false ) ); - } - - void View_i::SetViewPositionHorizontal( VISU::View::ViewPosition ViewPosHor ){ - ProcessVoidEvent( new TSetViewPositionHorizontal( this, ViewPosHor ) ); - } + if(!thePrs3d) + return NULL; - void View_i::SetViewPositionVertical( VISU::View::ViewPosition ViewPosVer ){ - ProcessVoidEvent( new TSetViewPositionVertical( this, ViewPosVer ) ); + vtkRenderer* aRenderer = theViewWindow->getRenderer(); + VTK::ActorCollectionCopy aCopy(aRenderer->GetActors()); + vtkActorCollection* anActors = aCopy.GetActors(); + return SVTK::Find(anActors, VISU::TIsSamePrs3d(thePrs3d)); } - void View_i::SetRelativePosition( CORBA::Double x, CORBA::Double y ) - { - ProcessVoidEvent( new TSetRelativePosition( this, x, y ) ); - } - void View_i::SetRelativeSize( CORBA::Double x, CORBA::Double y ) + //---------------------------------------------------------------------------- + struct TIsSameActor { - ProcessVoidEvent( new TSetRelativeSize( this, x, y ) ); - } - - - - - void View3D_i::SetTitle(const char* theTitle){ - ProcessVoidEvent(new TVoidMemFun1ArgEvent - (myStudyFrame,&QAD_StudyFrame::setTitle,QString(theTitle))); - } - char* View3D_i::GetTitle() { - return CORBA::string_dup(myStudyFrame->title().latin1()); - } - - - 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); - QColor aNewColor(aColor[0],aColor[1],aColor[2]); - GetViewFrame(theStudyFrame)->setBackgroundColor(aNewColor); - } - void View3D_i::SetBackground(const SALOMEDS::Color& theColor) { - ProcessVoidEvent(new TSetBackgroundEvent(GetViewFrame(myStudyFrame),theColor)); - } + VISU::TActorFactory* myActor; - - SALOMEDS::Color View3D_i::GetBackground(QAD_StudyFrame* theStudyFrame) { - SALOMEDS::Color aColor; - float backint[3]; - GetRenderer(theStudyFrame)->GetBackground(backint); - aColor.R = backint[0]; aColor.G = backint[1]; aColor.B = backint[2]; - return aColor; - } - SALOMEDS::Color View3D_i::GetBackground() { - return GetBackground(myStudyFrame); - } - - - void View3D_i::Minimize() { - ProcessVoidEvent(new TFrameActionEvent(myStudyFrame,&QAD_StudyFrame::showMinimized)); - } - void View3D_i::Restore() { - ProcessVoidEvent(new TFrameActionEvent(myStudyFrame, &QAD_StudyFrame::showNormal)); - } - void View3D_i::Maximize() { - ProcessVoidEvent(new TFrameActionEvent(myStudyFrame, &QAD_StudyFrame::showMaximized)); - } - - - //=========================================================================== - class TUpdateViewerEvent: public SALOME_Event{ - QAD_StudyFrame* myStudyFrame; - Prs3d_i* myPrs3d; - int myDisplaing; - public: - TUpdateViewerEvent(QAD_StudyFrame* theStudyFrame, - Prs3d_i* thePrs3d, - int theDisplaing): - myStudyFrame(theStudyFrame), - myPrs3d(thePrs3d), - myDisplaing(theDisplaing) + TIsSameActor(VISU::TActorFactory* theActor): + myActor(theActor) {} - virtual void Execute(){ - UpdateViewer(myStudyFrame,myDisplaing,myPrs3d); + + bool + operator()(VISU_ActorBase* theActor) + { + return theActor->GetFactory() == myActor; } }; - void View3D_i::EraseAll() { - if(MYDEBUG) MESSAGE("View3D_i::EraseAll"); - ProcessVoidEvent(new TUpdateViewerEvent(myStudyFrame,NULL,eEraseAll)); - } - - void View3D_i::DisplayAll() { - if(MYDEBUG) MESSAGE("View3D_i::DisplayAll"); - 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)); - } - } - - void View3D_i::Display(PrsObject_ptr thePrsObj) { - 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)); - } - } - - void View3D_i::DisplayOnly(PrsObject_ptr thePrsObj) { - 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)); - } - } + //---------------------------------------------------------------------------- + VISU_ActorBase* + FindActorBase(SVTK_ViewWindow* theViewWindow, VISU::TActorFactory* theActor) + { + if(!theActor) + return NULL; - //-------------------- View3D interface -------------------- - void View3D_i::FitAll() { - ProcessVoidEvent(new TVoidMemFunEvent(GetViewFrame(myStudyFrame),&VTKViewer_ViewFrame::onViewFitAll)); - Update(); + vtkRenderer* aRenderer = theViewWindow->getRenderer(); + VTK::ActorCollectionCopy aCopy(aRenderer->GetActors()); + vtkActorCollection* anActors = aCopy.GetActors(); + return SVTK::Find(anActors, VISU::TIsSameActor(theActor)); } - void View3D_i::SetView(VISU::View3D::ViewType theType) { - switch(theType){ - case VISU::View3D::FRONT : - ProcessVoidEvent(new TVoidMemFunEvent(GetViewFrame(myStudyFrame),&VTKViewer_ViewFrame::onViewFront)); - break; - case VISU::View3D::BACK : - ProcessVoidEvent(new TVoidMemFunEvent(GetViewFrame(myStudyFrame),&VTKViewer_ViewFrame::onViewBack)); - break; - case VISU::View3D::LEFT : - ProcessVoidEvent(new TVoidMemFunEvent(GetViewFrame(myStudyFrame),&VTKViewer_ViewFrame::onViewLeft)); - break; - case VISU::View3D::RIGHT : - ProcessVoidEvent(new TVoidMemFunEvent(GetViewFrame(myStudyFrame),&VTKViewer_ViewFrame::onViewRight)); - break; - case VISU::View3D::TOP : - ProcessVoidEvent(new TVoidMemFunEvent(GetViewFrame(myStudyFrame),&VTKViewer_ViewFrame::onViewTop)); - break; - case VISU::View3D::BOTTOM : - ProcessVoidEvent(new TVoidMemFunEvent(GetViewFrame(myStudyFrame),&VTKViewer_ViewFrame::onViewBottom)); - break; - } - Update(); - } - + //---------------------------------------------------------------------------- + struct TDeleteActorsEvent: public SALOME_Event + { + VISU::Curve_i* myPrs; - 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) + TDeleteActorsEvent (VISU::Curve_i* thePrs): + myPrs(thePrs) {} - virtual void Execute(){ - myFun(myStudyFrame,myParam); - } - 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"); - ProcessVoidEvent(new TSet3DViewParamEvent(&SetPointOfView,myStudyFrame,thePosition)); - } - - - void View3D_i::GetPointOfView(QAD_StudyFrame* theStudyFrame, CORBA::Double thePosition[3]) { - GetCamera(theStudyFrame)->GetPosition(thePosition); - } - VISU::View3D::XYZ_slice* View3D_i::GetPointOfView() { - if(MYDEBUG) MESSAGE("View3D_i::GetPointOfView"); - CORBA::Double aPosition[3]; - GetPointOfView(myStudyFrame,aPosition); - 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 theViewUp) { - if(MYDEBUG) MESSAGE("View3D_i::SetViewUp"); - 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"); - 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"); - 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"); - CORBA::Double aFocalPnt[3]; - GetFocalPoint(myStudyFrame,aFocalPnt); - return VISU::View3D::XYZ_dup(aFocalPnt); - } + virtual + void + Execute() + { + if (!myPrs) return; + + // 1. Find appropriate application (code like in TNewViewManagerEvent::Execute()) + SALOMEDS::Study_var myStudyDocument = myPrs->GetStudyDocument(); + SalomeApp_Application* anApp = NULL; + CORBA::String_var studyName = myStudyDocument->Name(); + std::string aStudyName = studyName.in(); + SUIT_Session* aSession = SUIT_Session::session(); + QList anApplications = aSession->applications(); + QList::Iterator anIter = anApplications.begin(); + while ( anIter != anApplications.end() ) { + SUIT_Application* aSUITApp = *anIter; + if (SUIT_Study* aSStudy = aSUITApp->activeStudy()) { + if (SalomeApp_Study* aStudy = dynamic_cast(aSStudy)) { + if (_PTR(Study) aCStudy = aStudy->studyDS()) { + if (aStudyName == aCStudy->Name()) { + anApp = dynamic_cast(aSUITApp); + break; + } + } + } + } + anIter++; + } + if (!anApp) + return; + + // 2. Remove corresponding IO from selection + SALOMEDS::SObject_var aSObject = myPrs->GetSObject(); + CORBA::String_var anEntry = aSObject->GetID(); + + LightApp_SelectionMgr* aSelectionMgr = anApp->selectionMgr(); + SALOME_ListIO aListIO, aNewListIO; + aSelectionMgr->selectedObjects(aListIO); + + for (SALOME_ListIteratorOfListIO it (aListIO); it.More(); it.Next()) { + if (it.Value()->hasEntry()) { + std::string aCurEntry (it.Value()->getEntry()); + if (aCurEntry != std::string( anEntry.in() ) ) { + aNewListIO.Append(it.Value()); + } + } + } - 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 void Execute(){ - myFun(myStudyFrame,myParam); + aSelectionMgr->setSelectedObjects(aNewListIO); + + // 3. Remove Actors + ViewManagerList aViewManagerList; + anApp->viewManagers(SVTK_Viewer::Type(), aViewManagerList); + QList::Iterator anVMIter = aViewManagerList.begin(); + for (; anVMIter != aViewManagerList.end(); anVMIter++ ) { + SUIT_ViewManager* aViewManager = *anVMIter; + QVector aViews = aViewManager->getViews(); + for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) { + if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) { + if (Plot2d_ViewWindow* vw = dynamic_cast(aViewWindow)) { + Plot2d_ViewFrame* vf = vw->getViewFrame(); + QList clist; + vf->getCurves(clist); + for (int i = 0; i < clist.count(); i++) { + if (SPlot2d_Curve* cu = dynamic_cast(clist.at(i))) { + if (cu->hasIO() && + strcmp(myPrs->GetEntry().c_str(), cu->getIO()->getEntry())) { + vf->eraseCurve(cu); + } + } + } + vf->Repaint(); + //jfa tmp:aViewFrame->unHighlightAll(); + } + } + } + } } - private: - TFun myFun; - QAD_StudyFrame* myStudyFrame; - CORBA::Double myParam; }; + void DeleteActors (VISU::Curve_i* thePrs) + { + if (!thePrs) return; + ProcessVoidEvent(new TDeleteActorsEvent (thePrs)); + +/* // 1. Find appropriate application (code like in TNewViewManagerEvent::Execute()) + SALOMEDS::Study_var myStudyDocument = thePrs->GetStudyDocument(); + SalomeApp_Application* anApp = NULL; + CORBA::String_var studyName = myStudyDocument->Name(); + std::string aStudyName = studyName.in(); + SUIT_Session* aSession = SUIT_Session::session(); + QPtrList anApplications = aSession->applications(); + QPtrListIterator anIter (anApplications); + while (SUIT_Application* aSUITApp = anIter.current()) { + ++anIter; + if (SUIT_Study* aSStudy = aSUITApp->activeStudy()) { + if (SalomeApp_Study* aStudy = dynamic_cast(aSStudy)) { + if (_PTR(Study) aCStudy = aStudy->studyDS()) { + if (aStudyName == aCStudy->Name()) { + anApp = dynamic_cast(aSUITApp); + break; + } + } + } + } + } + if (!anApp) + return; - 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"); - 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"); - return GetParallelScale(myStudyFrame); - } - - void View3D_i::ScaleView(QAD_StudyFrame* theStudyFrame, VISU::View3D::Axis theAxis, CORBA::Double theParam) { - VTKViewer_ViewFrame* aViewFrame = GetViewFrame(theStudyFrame); - double aScaleFactor[3]; - aViewFrame->GetScale(aScaleFactor); - 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"); - 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"); - double aScale[3] = {1.0, 1.0, 1.0}; - ProcessVoidEvent(new TSet3DViewParamEvent(&SetScaleView,myStudyFrame,aScale)); - } - //=========================================================================== - - - VISU_Actor* GetActor(VISU::Prs3d_i* thePrs3d, VTKViewer_ViewFrame* theVTKFrame){ - vtkActor *anActor; - vtkActorCollection *anActColl = theVTKFrame->getRenderer()->GetActors(); - anActColl->InitTraversal(); - while(vtkActor *anActor = anActColl->GetNextActor()) - if(VISU_Actor* anVISUActor = dynamic_cast(anActor)) - if(thePrs3d == anVISUActor->GetPrs3d()) - return anVISUActor->GetParent(); - return NULL; - } - - - void DeletePrs3d(Prs3d_ptr thePrs3d){ - if(Prs3d_i* aPrs3d = dynamic_cast(GetServant(thePrs3d).in())){ - SALOMEDS::SObject_var aSObject = aPrs3d->GetSObject(); - SALOMEDS::Study_var aStudyDocument = aSObject->GetStudy(); - if(QAD_Desktop* aDesktop = QAD_Application::getDesktop()){ - if(QAD_Study* aStudy = aDesktop->findStudy(aStudyDocument)){ - aStudy->unHighlightAll(); - int aNbStudyFrames = aStudy->getStudyFramesCount(); - for(int aFrameId = 0; aFrameId < aNbStudyFrames; aFrameId++){ - if(QAD_StudyFrame* aFrame = aStudy->getStudyFrame(aFrameId)){ - QAD_ViewFrame* aViewFrame = aFrame->getRightFrame()->getViewFrame(); - if(VTKViewer_ViewFrame* aVTKFrame = dynamic_cast(aViewFrame)){ - if(VISU_Actor* anActor = VISU::GetActor(aPrs3d,aVTKFrame)){ - aVTKFrame->RemoveActor(anActor); - anActor->Delete(); - } - aVTKFrame->unHighlightAll(); - } - } - } + // 2. Remove corresponding IO from selection + SALOMEDS::SObject_var aSObject = thePrs->GetSObject(); + CORBA::String_var anEntry = aSObject->GetID(); - aPrs3d->RemoveFromStudy(); - aPrs3d->Destroy(); + LightApp_SelectionMgr* aSelectionMgr = anApp->selectionMgr(); + SALOME_ListIO aListIO, aNewListIO; + aSelectionMgr->selectedObjects(aListIO); - aStudy->updateObjBrowser(); //update Object browser - } + for (SALOME_ListIteratorOfListIO it (aListIO); it.More(); it.Next()) { + if (it.Value()->hasEntry()) { + std::string aCurEntry (it.Value()->getEntry()); + if (aCurEntry != std::string( anEntry.in() ) ) { + aNewListIO.Append(it.Value()); + } } } - } + aSelectionMgr->setSelectedObjects(aNewListIO); + + // 3. Remove Actors + ViewManagerList aViewManagerList; + anApp->viewManagers(SVTK_Viewer::Type(), aViewManagerList); + QPtrListIterator anVMIter (aViewManagerList); + for (; anVMIter.current(); ++anVMIter) { + SUIT_ViewManager* aViewManager = anVMIter.current(); + QPtrVector aViews = aViewManager->getViews(); + for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) { + if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) { + if (Plot2d_ViewWindow* vw = dynamic_cast(aViewWindow)) { + Plot2d_ViewFrame* vf = vw->getViewFrame(); + QList clist; + vf->getCurves(clist); + for (int i = 0; i < clist.count(); i++) { + if (SPlot2d_Curve* cu = dynamic_cast(clist.at(i))) { + if (cu->hasIO() && + strcmp(cu->getIO()->getEntry(), thePrs->GetEntry()) == 0) { + vf->eraseCurve(cu); + } + } + } + vf->Repaint(); + //jfa tmp:aViewFrame->unHighlightAll(); + } + } + } +}*/ + } - void VISU_Gen_i::DeleteResult(Result_ptr theResult) + void DeleteActors (VISU::Prs3d_i* thePrs) { - class TEvent: public SALOME_Event{ - Result_ptr myResult; - public: - TEvent(Result_ptr theResult): myResult(theResult) {} - virtual void Execute(){ - if(Result_i* aResult = dynamic_cast(GetServant(myResult).in())){ - SALOMEDS::SObject_var aSObject = aResult->GetSObject(); - SALOMEDS::Study_var aStudyDocument = aSObject->GetStudy(); - SALOMEDS::ChildIterator_var aChildIter = aStudyDocument->NewChildIterator(aSObject); - for(aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()){ - SALOMEDS::SObject_var aChildSObject = aChildIter->Value(); - CORBA::Object_var aChildObj = VISU::SObjectToObject(aChildSObject); - if(CORBA::is_nil(aChildObj)) continue; - VISU::Prs3d_var aPrs3d = VISU::Prs3d::_narrow(aChildObj); - if(CORBA::is_nil(aPrs3d)) continue; - VISU::DeletePrs3d(aPrs3d); - } - - aResult->RemoveFromStudy(); - aResult->Destroy(); - - if(QAD_Desktop* aDesktop = QAD_Application::getDesktop()) - if(QAD_Study* aStudy = aDesktop->findStudy(aStudyDocument)) - aStudy->updateObjBrowser(); //update Object browser - } + if (!thePrs) return; + + // 1. Find appropriate application (code like in TNewViewManagerEvent::Execute()) + SALOMEDS::Study_var myStudyDocument = thePrs->GetStudyDocument(); + SalomeApp_Application* anApp = NULL; + CORBA::String_var studyName = myStudyDocument->Name(); + std::string aStudyName = studyName.in(); + SUIT_Session* aSession = SUIT_Session::session(); + QList anApplications = aSession->applications(); + QList::Iterator anIter = anApplications.begin(); + while (anIter != anApplications.end()) { + SUIT_Application* aSUITApp = *anIter; + if (SUIT_Study* aSStudy = aSUITApp->activeStudy()) { + if (SalomeApp_Study* aStudy = dynamic_cast(aSStudy)) { + if (_PTR(Study) aCStudy = aStudy->studyDS()) { + if (aStudyName == aCStudy->Name()) { + anApp = dynamic_cast(aSUITApp); + break; + } + } + } } - }; + anIter++; + } + if (!anApp) + return; - ProcessVoidEvent(new TEvent(theResult)); - } + // 2. Remove corresponding IO from selection + SALOMEDS::SObject_var aSObject = thePrs->GetSObject(); + CORBA::String_var anEntry = aSObject->GetID(); + LightApp_SelectionMgr* aSelectionMgr = anApp->selectionMgr(); + SALOME_ListIO aListIO, aNewListIO; + aSelectionMgr->selectedObjects(aListIO); - void VISU_Gen_i::DeletePrs3d(Prs3d_ptr thePrs3d) - { - class TEvent: public SALOME_Event{ - Prs3d_ptr myPrs3d; - public: - TEvent(Prs3d_ptr thePrs3d): myPrs3d(thePrs3d) {} - virtual void Execute(){ - VISU::DeletePrs3d(myPrs3d); + for (SALOME_ListIteratorOfListIO it (aListIO); it.More(); it.Next()) { + if (it.Value()->hasEntry()) { + std::string aCurEntry (it.Value()->getEntry()); + if (aCurEntry != std::string( anEntry.in() ) ) { + aNewListIO.Append(it.Value()); + } } - }; + } - ProcessVoidEvent(new TEvent(thePrs3d)); + aSelectionMgr->setSelectedObjects(aNewListIO); + + // 3. Remove Actors + ViewManagerList aViewManagerList; + anApp->viewManagers(SVTK_Viewer::Type(), aViewManagerList); + QList::Iterator anVMIter = aViewManagerList.begin(); + for (; anVMIter != aViewManagerList.end(); anVMIter++ ) { + SUIT_ViewManager* aViewManager = *anVMIter; + QVector aViews = aViewManager->getViews(); + for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) { + if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) { + if (SVTK_ViewWindow* vw = dynamic_cast(aViewWindow)) { + VISU_Actor* anActor = NULL; + VTK::ActorCollectionCopy aCopy(vw->getRenderer()->GetActors()); + vtkActorCollection *anActColl = aCopy.GetActors(); + anActColl->InitTraversal(); + vtkActor *aVTKActor = anActColl->GetNextActor(); + for (; !anActor && aVTKActor; aVTKActor = anActColl->GetNextActor()) { + if (VISU_Actor* anVISUActor = dynamic_cast(aVTKActor)) { + if (thePrs == anVISUActor->GetPrs3d()) { + anActor = anVISUActor; + } + } + } + if (anActor) { + vw->RemoveActor(anActor); + } + } + } + } + } } - }