X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSALOME_SWIG%2FSALOMEGUI_Swig.cxx;h=ff1eaf98bbbec700bfcbf2a40a0aaf50707df4e1;hb=99013c0818f44a7eb370a86ad99c1809f3ff8c5b;hp=eb14a5384a020ffc8d73e80f7bcf9404fac28e93;hpb=cac0b4571c951b557e1956d4777cf1e5199637c3;p=modules%2Fgui.git diff --git a/src/SALOME_SWIG/SALOMEGUI_Swig.cxx b/src/SALOME_SWIG/SALOMEGUI_Swig.cxx index eb14a5384..ff1eaf98b 100644 --- a/src/SALOME_SWIG/SALOMEGUI_Swig.cxx +++ b/src/SALOME_SWIG/SALOMEGUI_Swig.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2016 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 @@ -45,7 +45,6 @@ #ifndef DISABLE_SALOMEOBJECT #include #include - #include #ifndef DISABLE_OCCVIEWER #include #include @@ -53,12 +52,17 @@ #ifndef DISABLE_VTKVIEWER #include #include + #include + + #include + #include #endif #ifndef DISABLE_PLOT2DVIEWER #include #endif #endif +#include /*! \class SALOMEGUI_Swig @@ -480,7 +484,7 @@ void SALOMEGUI_Swig::DisplayOnly( const char* theEntry ) QStringList comps; aStudy->components( comps ); foreach( QString comp, comps ) { - LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true ); + LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), false ); if ( d ) d->EraseAll( false, false, 0 ); } @@ -590,7 +594,7 @@ void SALOMEGUI_Swig::EraseAll() QStringList comps; aStudy->components( comps ); foreach( QString comp, comps ) { - LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true ); + LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), false ); if ( d ) d->EraseAll( false, false, 0 ); } } @@ -620,9 +624,11 @@ public: virtual void Execute() { if ( LightApp_Application* anApp = getApplication() ) { - SUIT_ViewWindow* window = anApp->desktop()->activeWindow(); + SUIT_ViewManager* viewMgr = anApp->activeViewManager(); + if (!viewMgr) return; + SUIT_ViewWindow* window = viewMgr->getActiveView(); if ( window ) { - SALOME_View* view = dynamic_cast( window->getViewManager()->getActiveView() ); + SALOME_View* view = dynamic_cast( window->getViewManager()->getViewModel() ); if ( view ) { SALOME_Prs* aPrs = view->CreatePrs( myEntry.toLatin1() ); myResult = !aPrs->IsNull(); @@ -648,9 +654,11 @@ void SALOMEGUI_Swig::UpdateView() virtual void Execute() { if ( LightApp_Application* anApp = getApplication() ) { - SUIT_ViewWindow* window = anApp->desktop()->activeWindow(); + SUIT_ViewManager* viewMgr = anApp->activeViewManager(); + if (!viewMgr) return; + SUIT_ViewWindow* window = viewMgr->getActiveView(); if ( window ) { - SALOME_View* view = dynamic_cast( window->getViewManager()->getActiveView() ); + SALOME_View* view = dynamic_cast( window->getViewManager()->getViewModel() ); if ( view ) view->Repaint(); } @@ -665,6 +673,7 @@ void SALOMEGUI_Swig::UpdateView() */ void SALOMEGUI_Swig::FitAll() { + MESSAGE("FitAll"); class TEvent: public SALOME_Event { public: @@ -672,7 +681,9 @@ void SALOMEGUI_Swig::FitAll() virtual void Execute() { if ( LightApp_Application* anApp = getApplication() ) { - SUIT_ViewWindow* window = anApp->desktop()->activeWindow(); + SUIT_ViewManager* viewMgr = anApp->activeViewManager(); + if (!viewMgr) return; + SUIT_ViewWindow* window = viewMgr->getActiveView(); if ( window ) { #ifndef DISABLE_SALOMEOBJECT #ifndef DISABLE_VTKVIEWER @@ -695,6 +706,63 @@ void SALOMEGUI_Swig::FitAll() ProcessVoidEvent( new TEvent() ); } +void SALOMEGUI_Swig::FitSelection() +{ + class TEvent: public SALOME_Event + { + public: + TEvent() {} + virtual void Execute() + { + if ( LightApp_Application* anApp = getApplication() ) { + SUIT_ViewManager* viewMgr = anApp->activeViewManager(); + if (!viewMgr) return; + SUIT_ViewWindow* window = viewMgr->getActiveView(); + if ( window ) { +#if !defined(DISABLE_SALOMEOBJECT) && !defined(DISABLE_VTKVIEWER) + if ( dynamic_cast( window ) ) + (dynamic_cast( window ))->onFitSelection(); +#endif +#if !defined(DISABLE_OCCVIEWER) + if ( dynamic_cast( window ) ) + (dynamic_cast( window ))->onFitSelection(); +#endif + } + } + } + }; + ProcessVoidEvent( new TEvent() ); +} + +void SALOMEGUI_Swig::FitIObjects(const std::list& entries) +{ + class TEvent: public SALOME_Event + { + const std::list& myEntries; + public: + TEvent( const std::list& objs ) : myEntries( objs ) {} + virtual void Execute() + { + if ( LightApp_Application* anApp = getApplication() ) { + SUIT_ViewManager* viewMgr = anApp->activeViewManager(); + if (!viewMgr) return; + SUIT_ViewWindow* window = viewMgr->getActiveView(); + if ( window ) { + SALOME_ListIO objects; + std::list::const_iterator it; + for ( it = myEntries.begin(); it != myEntries.end(); ++it ) + objects.Append( new SALOME_InteractiveObject( (*it).c_str(), "" ) ); +#if !defined(DISABLE_SALOMEOBJECT) && !defined(DISABLE_VTKVIEWER) + if ( dynamic_cast( window ) ) + (dynamic_cast( window ))->onFitIObjects( objects ); +#endif + } + } + } + }; + ProcessVoidEvent( new TEvent( entries ) ); +} + /*! \brief Reset current view window to the default state. */ @@ -707,7 +775,9 @@ void SALOMEGUI_Swig::ResetView() virtual void Execute() { if ( LightApp_Application* anApp = getApplication() ) { - SUIT_ViewWindow* window = anApp->desktop()->activeWindow(); + SUIT_ViewManager* viewMgr = anApp->activeViewManager(); + if (!viewMgr) return; + SUIT_ViewWindow* window = viewMgr->getActiveView(); if ( window ) { #ifndef DISABLE_SALOMEOBJECT #ifndef DISABLE_VTKVIEWER @@ -761,7 +831,9 @@ static void setView( int view ) virtual void Execute() { if ( LightApp_Application* anApp = getApplication() ) { - SUIT_ViewWindow* window = anApp->desktop()->activeWindow(); + SUIT_ViewManager* viewMgr = anApp->activeViewManager(); + if (!viewMgr) return; + SUIT_ViewWindow* window = viewMgr->getActiveView(); if ( window ) { #ifndef DISABLE_SALOMEOBJECT #ifndef DISABLE_VTKVIEWER @@ -859,3 +931,194 @@ void SALOMEGUI_Swig::ViewBack() { setView( __ViewBack ); } + +/* + \fn bool SALOMEGUI_Swig::getViewParameters() + \brief Get camera parameters of the active view. + + NOTE: For the current moment implemented for VTK viewer only. + + \return \c string with the view parameters +*/ + +class TGetViewParameters: public SALOME_Event +{ +public: + typedef QString TResult; + TResult myResult; + TGetViewParameters() : myResult( "" ) {} + virtual void Execute() { + if ( LightApp_Application* anApp = getApplication() ) { + SUIT_ViewManager* viewMgr = anApp->activeViewManager(); + if (!viewMgr) return; + if ( SUIT_ViewWindow* window = viewMgr->getActiveView() ) { +#ifndef DISABLE_VTKVIEWER + if ( SVTK_ViewWindow* svtk = dynamic_cast( window ) ) { + if ( vtkRenderer* ren = svtk->getRenderer()) { + if ( vtkCamera* camera = ren->GetActiveCamera() ) { + double pos[3], focalPnt[3], viewUp[3], scale[3], parScale; + + // save position, focal point, viewUp, scale + camera->GetPosition( pos ); + camera->GetFocalPoint( focalPnt ); + camera->GetViewUp( viewUp ); + parScale = camera->GetParallelScale(); + svtk->GetRenderer()->GetScale( scale ); + + myResult += QString("sg.setCameraPosition( %1, %2, %3 )\n").arg(pos[0]).arg(pos[1]).arg(pos[2]); + myResult += QString("sg.setCameraFocalPoint( %1, %2, %3 )\n").arg(focalPnt[0]).arg(focalPnt[1]).arg(focalPnt[2]); + myResult += QString("sg.setCameraViewUp( %1, %2, %3 )\n").arg(viewUp[0]).arg(viewUp[1]).arg(viewUp[2]); + myResult += QString("sg.setViewScale(%1, %2, %3, %4 )\n").arg(parScale).arg(scale[0]).arg(scale[1]).arg(scale[2]); + } + } + } +#endif + } + } + } +}; + +const char* SALOMEGUI_Swig::getViewParameters() { + QString result = ProcessEvent( new TGetViewParameters() ); + return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() ); +} + + +/*! + \brief View parameter type. + \internal +*/ +enum { + __CameraPosition, //!< position of the active camera + __CameraFocalPoint, //!< focal point of the active camera + __CameraViewUp, //!< view up of the active camera + __ViewScale //!< scale of the view +}; + + +/*! + \brief Change the camera parameters of the current view window. + \internal + + NOTE: For the current moment implemented for VTK viewer only. + + \param parameter type of the parameter + \param values value of the parameter +*/ +static void setViewParameter( int parameter, QList& values ) { + class TEvent: public SALOME_Event { + private: + int myParameter; + QList myValues; + public: + TEvent( int parameter , QList& values ) : myParameter(parameter), myValues( values ) {} + + virtual void Execute() { + if ( LightApp_Application* anApp = getApplication() ) { + SUIT_ViewManager* viewMgr = anApp->activeViewManager(); + if (!viewMgr) return; + if ( SUIT_ViewWindow* window = viewMgr->getActiveView() ) { +#ifndef DISABLE_VTKVIEWER + if ( SVTK_ViewWindow* svtk = dynamic_cast( window ) ) { + if ( vtkRenderer* ren = svtk->getRenderer()) { + if ( vtkCamera* camera = ren->GetActiveCamera() ) { + switch(myParameter) { + case __CameraPosition : { + if ( myValues.size() == 3 ) { + camera->SetPosition( myValues[0], myValues[1], myValues[2] ); + } + break; + } + case __CameraFocalPoint : { + if ( myValues.size() == 3 ) { + camera->SetFocalPoint( myValues[0], myValues[1], myValues[2] ); + } + break; + } + case __CameraViewUp : { + if ( myValues.size() == 3 ) { + camera->SetViewUp( myValues[0], myValues[1], myValues[2] ); + } + break; + } + case __ViewScale : { + if ( myValues.size() == 4 ) { + camera->SetParallelScale( myValues[0] ); + double scale[] = { myValues[1], myValues[2], myValues[3] }; + svtk->GetRenderer()->SetScale( scale ); + } + break; + } + default: break; + } + } + } + svtk->Repaint(); + } +#endif + } + } + } + }; + ProcessVoidEvent( new TEvent( parameter, values ) ); +} + +/*! + \brief Set camera position of the active view . + \param x - X coordinate of the camera + \param y - Y coordinate of the camera + \param z - Z coordinate of the camera +*/ +void SALOMEGUI_Swig::setCameraPosition( double x, double y, double z ) { + QList lst; + lst.push_back( x ); + lst.push_back( y ); + lst.push_back( z ); + setViewParameter( __CameraPosition, lst ); +} + +/*! + \brief Set camera focal point of the active view. + \param x - X coordinate of the focal point + \param y - Y coordinate of the focal point + \param z - Z coordinate of the focal point +*/ +void SALOMEGUI_Swig::setCameraFocalPoint( double x, double y, double z ) { + QList lst; + lst.push_back( x ); + lst.push_back( y ); + lst.push_back( z ); + setViewParameter( __CameraFocalPoint, lst ); +} + +/*! + \brief Set the view up direction for the camera. + \param x - X component of the direction vector + \param y - Y component of the direction vector + \param z - Z component of the direction vector +*/ +void SALOMEGUI_Swig::setCameraViewUp( double x, double y, double z ) { + QList lst; + lst.push_back( x ); + lst.push_back( y ); + lst.push_back( z ); + setViewParameter( __CameraViewUp, lst ); +} + +/*! + \brief Set view scale. + \param parallelScale - scaling used for a parallel projection. + \param x - X scale + \param y - Y scale + \param z - Z scale +*/ +void SALOMEGUI_Swig::setViewScale( double parallelScale, double x, double y, double z ) { + QList lst; + lst.push_back( parallelScale ); + lst.push_back( x ); + lst.push_back( y ); + lst.push_back( z ); + setViewParameter( __ViewScale, lst ); +} + +