// 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
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
//
//
#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.hxx"
#include "SALOME_ListIO.hxx"
using namespace std;
-//////////////////////////////////////////////////////////////////////////////
-// asv : 3.12.04 : added checking for NULL GUI objects in almost all methods.
-// In the scope of fixing bug PAL6869.
-//////////////////////////////////////////////////////////////////////////////
-// (PR : modify comments)
-// Instance of this class is created every time "import salome" line is typed
-// - in IAPP embedded Python interpretor (SALOME_Session_Server executable),
-// - in inline Python nodes in Supervisor (in SALOME_Container executable),
-// - in stand-alone Python console outside any executable.
-// SALOME GUI(desktop and other objects) is only available in SALOME_Session_Server
-//////////////////////////////////////////////////////////////////////////////
-// VSR : 19.04.05 : Reimplemented for new SALOME GUI (SUIT-based)
-// All methods are implemeted using Event mechanism.
-// Display/Erase methods use SALOME_Prs/SALOME_View mechanism. It is currently
-// implemented only for OCC and VTK viewers.
-//////////////////////////////////////////////////////////////////////////////
+/*!
+ asv : 3.12.04 : added checking for NULL GUI objects in almost all methods.
+ In the scope of fixing bug PAL6869.
+
+ (PR : modify comments)
+ Instance of this class is created every time "import salome" line is typed
+ - in IAPP embedded Python interpretor (SALOME_Session_Server executable),
+ - in inline Python nodes in Supervisor (in SALOME_Container executable),
+ - in stand-alone Python console outside any executable.
+ SALOME GUI(desktop and other objects) is only available in SALOME_Session_Server
+
+ VSR : 19.04.05 : Reimplemented for new SALOME GUI (SUIT-based)
+ All methods are implemeted using Event mechanism.
+ Display/Erase methods use SALOME_Prs/SALOME_View mechanism. It is currently
+ implemented only for OCC and VTK viewers.
+*/
/*!
getApplication()
myResult = (bool)( getApplication() && getApplication()->desktop() );
}
};
+
+/*!
+ \return true if GUI is available.
+*/
bool SALOMEGUI_Swig::hasDesktop()
{
return ProcessEvent( new THasDesktopEvent() );
}
}
};
+
+/*!
+ \return active study's ID or 0 if there is no active study.
+*/
int SALOMEGUI_Swig::getActiveStudyId()
{
return ProcessEvent( new TGetActiveStudyIdEvent() );
}
}
};
+
+/*!
+ \return active study's name or NULL if there is no active study.
+*/
const char* SALOMEGUI_Swig::getActiveStudyName()
{
string result = ProcessEvent( new TGetActiveStudyNameEvent() );
SALOMEGUI_Swig::getComponentName
Returns the name of the component by its user name.
*/
+class TGetModulCatalogEvent: public SALOME_Event {
+public:
+ typedef CORBA::Object_var TResult;
+ TResult myResult;
+ TGetModulCatalogEvent() : myResult(CORBA::Object::_nil()) {}
+ virtual void Execute() {
+ if (SalomeApp_Application* anApp = getApplication())
+ myResult = anApp->namingService()->Resolve("/Kernel/ModulCatalog");
+ }
+};
+
+/*!
+ \return the name of the component by its user name.
+*/
const char* SALOMEGUI_Swig::getComponentName( const char* componentUserName )
{
- if ( SalomeApp_Application* anApp = getApplication() ) {
- CORBA::Object_var anObject = anApp->namingService()->Resolve("/Kernel/ModulCatalog");
- if ( !CORBA::is_nil( anObject ) ) {
- SALOME_ModuleCatalog::ModuleCatalog_var aCatalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow( anObject );
- SALOME_ModuleCatalog::ListOfIAPP_Affich_var aModules = aCatalogue->GetComponentIconeList();
- for ( unsigned int ind = 0; ind < aModules->length(); ind++ ) {
- string aModuleName = CORBA::string_dup( aModules[ ind ].modulename ) ;
- string aModuleUserName = CORBA::string_dup( aModules[ ind ].moduleusername ) ;
- if ( componentUserName == aModuleUserName )
- return aModuleName.c_str();
- }
+ CORBA::Object_var anObject = ProcessEvent(new TGetModulCatalogEvent());
+ if (!CORBA::is_nil(anObject)) {
+ SALOME_ModuleCatalog::ModuleCatalog_var aCatalogue =
+ SALOME_ModuleCatalog::ModuleCatalog::_narrow( anObject );
+ SALOME_ModuleCatalog::ListOfIAPP_Affich_var aModules = aCatalogue->GetComponentIconeList();
+ for ( unsigned int ind = 0; ind < aModules->length(); ind++ ) {
+ CORBA::String_var aModuleName = aModules[ ind ].modulename;
+ CORBA::String_var aModuleUserName = aModules[ ind ].moduleusername;
+ if ( strcmp(componentUserName, aModuleUserName.in()) == 0 )
+ return aModuleName._retn();
}
}
return 0;
*/
const char* SALOMEGUI_Swig::getComponentUserName( const char* componentName )
{
- if ( SalomeApp_Application* anApp = getApplication() ) {
- CORBA::Object_var anObject = anApp->namingService()->Resolve("/Kernel/ModulCatalog");
- if ( !CORBA::is_nil( anObject ) ) {
- SALOME_ModuleCatalog::ModuleCatalog_var aCatalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow( anObject );
- SALOME_ModuleCatalog::ListOfIAPP_Affich_var aModules = aCatalogue->GetComponentIconeList();
- for ( unsigned int ind = 0; ind < aModules->length(); ind++ ) {
- string aModuleName = CORBA::string_dup( aModules[ ind ].modulename ) ;
- string aModuleUserName = CORBA::string_dup( aModules[ ind ].moduleusername ) ;
- if ( componentName == aModuleName )
- return aModuleUserName.c_str();
- }
+ CORBA::Object_var anObject = ProcessEvent(new TGetModulCatalogEvent());
+ if (!CORBA::is_nil(anObject)) {
+ SALOME_ModuleCatalog::ModuleCatalog_var aCatalogue =
+ SALOME_ModuleCatalog::ModuleCatalog::_narrow( anObject );
+ SALOME_ModuleCatalog::ListOfIAPP_Affich_var aModules = aCatalogue->GetComponentIconeList();
+ for ( unsigned int ind = 0; ind < aModules->length(); ind++ ) {
+ CORBA::String_var aModuleName = aModules[ ind ].modulename;
+ CORBA::String_var aModuleUserName = aModules[ ind ].moduleusername;
+ if ( strcmp(componentName, aModuleName.in()) == 0 )
+ return aModuleUserName._retn();
}
}
return 0;
}
}
};
+
+/*!
+ \return the number of selected objects.
+*/
int SALOMEGUI_Swig::SelectedCount()
{
return ProcessEvent( new TSelectedCountEvent() );
}
}
};
+
+/*!
+ \return the selected object entry by the given index.
+*/
const char* SALOMEGUI_Swig::getSelected( int index )
{
QString result = ProcessEvent( new TGetSelectedEvent( index ) );
SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getViewModel() );
if ( view ) {
SALOME_Prs* aPrs = view->CreatePrs( myEntry );
- myResult = aPrs->IsNull();
+ myResult = !aPrs->IsNull();
}
}
}
}
};
+
+/*!
+ \return TRUE if the object with given entry is in the current viewer.
+ VSR: For the current moment implemented for OCC and VTK viewers only.
+*/
bool SALOMEGUI_Swig::IsInCurrentView( const char* theEntry )
{
return ProcessEvent( new TIsInViewerEvent( theEntry ) );
}
+
+/*!
+ Updates (repaint) current view
+*/
+void SALOMEGUI_Swig::UpdateView()
+{
+ class TEvent: public SALOME_Event {
+ public:
+ TEvent() {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
+ if ( window ) {
+ SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getViewModel() );
+ if ( view )
+ view->Repaint();
+ }
+ }
+ }
+ };
+ ProcessVoidEvent( new TEvent() );
+}
+
+/*!
+ Fit all the contents of the current view window
+ */
+void SALOMEGUI_Swig::FitAll()
+{
+ class TEvent: public SALOME_Event {
+ public:
+ TEvent() {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
+ if ( window ) {
+ if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
+ (dynamic_cast<SVTK_ViewWindow*>( window ))->onFitAll();
+ else if ( dynamic_cast<SOCC_ViewWindow*>( window ) )
+ (dynamic_cast<SOCC_ViewWindow*>( window ))->onFitAll();
+ else if ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )
+ (dynamic_cast<SPlot2d_ViewWindow*>( window ))->onFitAll();
+ }
+ }
+ }
+ };
+ ProcessVoidEvent( new TEvent() );
+}
+
+/*!
+ Reset current view window to the default state.
+ */
+void SALOMEGUI_Swig::ResetView()
+{
+ class TEvent: public SALOME_Event {
+ public:
+ TEvent() {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
+ if ( window ) {
+ if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
+ (dynamic_cast<SVTK_ViewWindow*>( window ))->onResetView();
+ else if ( dynamic_cast<SOCC_ViewWindow*>( window ) )
+ (dynamic_cast<SOCC_ViewWindow*>( window ))->onResetView();
+ else 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.
+ }
+ }
+ }
+ };
+ ProcessVoidEvent( new TEvent() );
+}
+
+enum {
+ __ViewTop,
+ __ViewBottom,
+ __ViewLeft,
+ __ViewRight,
+ __ViewFront,
+ __ViewBack
+};
+
+void setView( int view )
+{
+ class TEvent: public SALOME_Event {
+ private:
+ int myView;
+ public:
+ TEvent( int view ) : myView( view ) {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
+ if ( window ) {
+ if ( dynamic_cast<SVTK_ViewWindow*>( window ) ) {
+ switch( myView ) {
+ case __ViewTop:
+ (dynamic_cast<SVTK_ViewWindow*>( window ))->onTopView(); break;
+ case __ViewBottom:
+ (dynamic_cast<SVTK_ViewWindow*>( window ))->onBottomView(); break;
+ case __ViewLeft:
+ (dynamic_cast<SVTK_ViewWindow*>( window ))->onLeftView(); break;
+ case __ViewRight:
+ (dynamic_cast<SVTK_ViewWindow*>( window ))->onRightView(); break;
+ case __ViewFront:
+ (dynamic_cast<SVTK_ViewWindow*>( window ))->onFrontView(); break;
+ case __ViewBack:
+ (dynamic_cast<SVTK_ViewWindow*>( window ))->onBackView(); break;
+ default:
+ break;
+ }
+ }
+ else if ( dynamic_cast<SOCC_ViewWindow*>( window ) ) {
+ switch( myView ) {
+ case __ViewTop:
+ (dynamic_cast<SOCC_ViewWindow*>( window ))->onTopView(); break;
+ case __ViewBottom:
+ (dynamic_cast<SOCC_ViewWindow*>( window ))->onBottomView(); break;
+ case __ViewLeft:
+ (dynamic_cast<SOCC_ViewWindow*>( window ))->onLeftView(); break;
+ case __ViewRight:
+ (dynamic_cast<SOCC_ViewWindow*>( window ))->onRightView(); break;
+ case __ViewFront:
+ (dynamic_cast<SOCC_ViewWindow*>( window ))->onFrontView(); break;
+ case __ViewBack:
+ (dynamic_cast<SOCC_ViewWindow*>( window ))->onBackView(); break;
+ default:
+ break;
+ }
+ }
+ }
+ }
+ }
+ };
+ ProcessVoidEvent( new TEvent( view ) );
+}
+
+/*!
+ Switch current view window to show top view
+ */
+void SALOMEGUI_Swig::ViewTop()
+{
+ setView( __ViewTop );
+}
+
+/*!
+ Switch current view window to show bottom view
+ */
+void SALOMEGUI_Swig::ViewBottom()
+{
+ setView( __ViewBottom );
+}
+
+/*!
+ Switch current view window to show left view
+ */
+void SALOMEGUI_Swig::ViewLeft()
+{
+ setView( __ViewLeft );
+}
+
+/*!
+ Switch current view window to show right view
+ */
+void SALOMEGUI_Swig::ViewRight()
+{
+ setView( __ViewRight );
+}
+
+/*!
+ Switch current view window to show front view
+ */
+void SALOMEGUI_Swig::ViewFront()
+{
+ setView( __ViewFront );
+}
+
+/*!
+ Switch current view window to show back view
+ */
+void SALOMEGUI_Swig::ViewBack()
+{
+ setView( __ViewBack );
+}