-// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023 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.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
#include <SUIT_Desktop.h>
#include <SUIT_ViewWindow.h>
#include <SUIT_ViewManager.h>
+#include <SUIT_ViewModel.h>
#include <SUIT_DataObjectIterator.h>
#include <CAM_DataModel.h>
#include <LightApp_Application.h>
#include <LightApp_SelectionMgr.h>
#include <LightApp_DataOwner.h>
#include <SALOME_Prs.h>
-#include <SOCC_ViewModel.h>
-#include <SVTK_ViewModel.h>
-#include <SVTK_ViewWindow.h>
-#include <SOCC_ViewWindow.h>
-#include <SPlot2d_ViewWindow.h>
-
#include <SALOME_Event.h>
-#include <SALOME_ListIO.hxx>
-#include <SALOME_InteractiveObject.hxx>
-#include <SALOME_ListIteratorOfListIO.hxx>
+
+#ifndef DISABLE_SALOMEOBJECT
+ #include <SALOME_ListIO.hxx>
+ #include <SALOME_InteractiveObject.hxx>
+#ifndef DISABLE_OCCVIEWER
+ #include <SOCC_ViewModel.h>
+ #include <SOCC_ViewWindow.h>
+#endif
+#ifndef DISABLE_VTKVIEWER
+ #include <SVTK_ViewModel.h>
+ #include <SVTK_ViewWindow.h>
+ #include <SVTK_Renderer.h>
+
+ #include <vtkCamera.h>
+ #include <vtkRenderer.h>
+#endif
+#ifndef DISABLE_PLOT2DVIEWER
+ #include <SPlot2d_ViewWindow.h>
+#endif
+#endif
+
+#include <utilities.h>
/*!
\class SALOMEGUI_Swig
This module provides an access to the SALOME GUI implementing set of functions
which can be used from Python. This module is implemented using SWIG wrappings
for some GUI functionality:
- - getActiveStudyId(), getActiveStudyName() : get active study identifier and name
+ - getActiveStudyName() : get active study name
- updateObjBrowser() : update contents of the Object Browser
- SelectedCount() : get number of currently selected items
- getSelected() : get entry of the speicified selected item
/*!
\brief Update active study's Object Browser.
- \param updateSelection this parameter is obsolete
*/
-void SALOMEGUI_Swig::updateObjBrowser( bool /*updateSelection*/ )
+void SALOMEGUI_Swig::updateObjBrowser()
{
class TEvent: public SALOME_Event
{
ProcessVoidEvent( new TEvent() );
}
-/*!
- \fn int SALOMEGUI_Swig::getActiveStudyId()
- \brief Get active study identifier
- \return active study's ID or 0 if there is no active study
-*/
-
-class TGetActiveStudyIdEvent: public SALOME_Event
-{
-public:
- typedef int TResult;
- TResult myResult;
- TGetActiveStudyIdEvent() : myResult( 0 ) {}
- virtual void Execute()
- {
- if ( LightApp_Study* aStudy = getActiveStudy() ) {
- myResult = aStudy->id();
- }
- }
-};
-int SALOMEGUI_Swig::getActiveStudyId()
-{
- return ProcessEvent( new TGetActiveStudyIdEvent() );
-}
-
/*!
\fn const char* SALOMEGUI_Swig::getActiveStudyName()
\brief Get active study name
virtual void Execute()
{
if ( LightApp_Study* aStudy = getActiveStudy() ) {
- myResult = aStudy->id();
+ myResult = aStudy->studyName().toUtf8().constData();
}
}
};
{
QStringList selected = ProcessEvent( new TGetSelectedEvent() );
return index >= 0 && index < selected.count() ?
- strdup( selected[ index ].toLatin1().constData() ) : 0;
+ strdup( selected[ index ].toUtf8().constData() ) : 0;
}
/*!
LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr();
if ( aStudy && aSelMgr ) {
SALOME_ListIO anIOList;
- anIOList.Append( new SALOME_InteractiveObject( myEntry.toLatin1(), "", "" ) );
+ anIOList.Append( new SALOME_InteractiveObject( myEntry.toUtf8(), "", "" ) );
aSelMgr->setSelectedObjects( anIOList, true );
}
}
aSelMgr->selectedObjects( anIOList );
SALOME_ListIteratorOfListIO anIter( anIOList );
for( ; anIter.More(); anIter.Next() ) {
- if ( anIter.Value()->isSame( new SALOME_InteractiveObject( myEntry.toLatin1(), "", "" ) ) ) {
+ if ( anIter.Value()->isSame( new SALOME_InteractiveObject( myEntry.toUtf8(), "", "" ) ) ) {
anIOList.Remove( anIter );
aSelMgr->setSelectedObjects( anIOList, true );
return;
LightApp_Application* anApp = getApplication();
LightApp_Study* aStudy = getActiveStudy();
if ( anApp && aStudy ) {
- QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
+ QString mname = aStudy->componentDataType( myEntry );
LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
if ( d ) {
QStringList entries;
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( comp, false );
if ( d ) d->EraseAll( false, false, 0 );
}
- QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
+ QString mname = aStudy->componentDataType( myEntry );
LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
if ( d ) {
QStringList entries;
LightApp_Application* anApp = getApplication();
LightApp_Study* aStudy = getActiveStudy();
if ( anApp && aStudy ) {
- QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
+ QString mname = aStudy->componentDataType( myEntry );
LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
if ( d ) {
QStringList entries;
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( comp, true );
if ( d ) {
QStringList entries;
aStudy->children( aStudy->centry( comp ), entries );
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( comp, false );
if ( d ) d->EraseAll( false, false, 0 );
}
}
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<SALOME_View*>( window->getViewManager()->getViewModel() );
if ( view ) {
- SALOME_Prs* aPrs = view->CreatePrs( myEntry.toLatin1() );
+ SALOME_Prs* aPrs = view->CreatePrs( myEntry.toUtf8() );
myResult = !aPrs->IsNull();
}
}
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<SALOME_View*>( window->getViewManager()->getViewModel() );
if ( view )
*/
void SALOMEGUI_Swig::FitAll()
{
+ MESSAGE("FitAll");
class TEvent: public SALOME_Event
{
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 ) {
+#ifndef DISABLE_SALOMEOBJECT
+#ifndef DISABLE_VTKVIEWER
if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
( dynamic_cast<SVTK_ViewWindow*>( window ) )->onFitAll();
- else if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
- ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )->onFitAll();
- else if ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )
+#endif
+#ifndef DISABLE_PLOT2DVIEWER
+ if ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )
( dynamic_cast<SPlot2d_ViewWindow*>( window ) )->onFitAll();
+#endif
+#endif
+#ifndef DISABLE_OCCVIEWER
+ if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
+ ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )->onFitAll();
+#endif
+ }
+ }
+ }
+ };
+ 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<SVTK_ViewWindow*>( window ) )
+ (dynamic_cast<SVTK_ViewWindow*>( window ))->onFitSelection();
+#endif
+#if !defined(DISABLE_OCCVIEWER)
+ if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
+ (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onFitSelection();
+#endif
}
}
}
ProcessVoidEvent( new TEvent() );
}
+void SALOMEGUI_Swig::FitIObjects(const std::list<std::string>& entries)
+{
+ class TEvent: public SALOME_Event
+ {
+ const std::list<std::string>& myEntries;
+ public:
+ TEvent( const std::list<std::string>& 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<std::string>::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<SVTK_ViewWindow*>( window ) )
+ (dynamic_cast<SVTK_ViewWindow*>( window ))->onFitIObjects( objects );
+#endif
+ }
+ }
+ }
+ };
+ ProcessVoidEvent( new TEvent( entries ) );
+}
+
/*!
\brief Reset current view window to the default state.
*/
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
if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
(dynamic_cast<SVTK_ViewWindow*>( window ))->onResetView();
- else if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
- (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onResetView();
- else if ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )
+#endif
+#ifndef DISABLE_PLOT2DVIEWER
+ if ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )
(dynamic_cast<SPlot2d_ViewWindow*>( window ))->onFitAll();
// VSR: there is no 'ResetView' functionality for Plot2d viewer,
// so we use 'FitAll' instead.
+#endif
+#endif
+#ifndef DISABLE_OCCVIEWER
+ if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
+ (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onResetView();
+#endif
}
}
}
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
if ( dynamic_cast<SVTK_ViewWindow*>( window ) ) {
switch( myView ) {
case __ViewTop:
break;
}
}
- else if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) ) {
+#endif
+#endif
+#ifndef DISABLE_OCCVIEWER
+ if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) ) {
switch( myView ) {
case __ViewTop:
(dynamic_cast<OCCViewer_ViewWindow*>( window ))->onTopView(); break;
break;
}
}
+#endif
}
}
}
{
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<SVTK_ViewWindow*>( 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.toUtf8().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<double>& values ) {
+ class TEvent: public SALOME_Event {
+ private:
+ int myParameter;
+ QList<double> myValues;
+ public:
+ TEvent( int parameter , QList<double>& 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<SVTK_ViewWindow*>( 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<double> 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<double> 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<double> 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<double> lst;
+ lst.push_back( parallelScale );
+ lst.push_back( x );
+ lst.push_back( y );
+ lst.push_back( z );
+ setViewParameter( __ViewScale, lst );
+}
+
+