using namespace std;
+// asv : 3.12.04 : added checking for NULL GUI objects in almost all methods. In the scope
+// of fixing bug PAL6869. Instance of this class is created every time "import salome" line
+// is typed in stand-alone (Python console) or embedded (InLine nodes in Supervisor) python.
+// SALOME GUI may not be created at this time (desktop and other objects), so checking if they
+// are equal to NULL is neccessary.
+
namespace SALOME{
- QAD_ViewFrame* GetViewFrame(QAD_Study* theStudy){
- return theStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame();
+ QAD_ViewFrame* GetViewFrame( QAD_Study* theStudy ) {
+ if ( theStudy )
+ if ( QAD_StudyFrame* aSF = theStudy->getActiveStudyFrame() )
+ if ( QAD_RightFrame* aRF = aSF->getRightFrame() )
+ return aRF->getViewFrame();
+ return 0;
}
- Handle(SALOME_InteractiveObject) FindIObject(QAD_Study* theStudy, const char *theEntry)
+ Handle(SALOME_InteractiveObject) FindIObject( QAD_Study* theStudy, const char *theEntry )
{
- return GetViewFrame(theStudy)->FindIObject(theEntry);
+ if ( QAD_ViewFrame* aVF = GetViewFrame( theStudy ) )
+ return aVF->FindIObject( theEntry );
+ return Handle(SALOME_InteractiveObject)(); // NULL Handle
}
}
*/
QAD_Study* SALOMEGUI_Swig::getActiveStudy()
{
- if(QAD_Application* app = QAD_Application::getDesktop()->getActiveApp())
- return app->getActiveStudy();
+ if ( QAD_Desktop* aDT = QAD_Application::getDesktop() )
+ if ( QAD_Application* anApp = aDT->getActiveApp() )
+ return anApp->getActiveStudy();
return 0;
}
*/
void SALOMEGUI_Swig::updateObjBrowser( bool updateSelection )
{
- if(QAD_Study* myActiveStudy = getActiveStudy())
- ProcessVoidEvent(new TVoidMemFun1ArgEvent<QAD_Study,bool>
- (myActiveStudy,&QAD_Study::updateObjBrowser,updateSelection));
+ if ( QAD_Study* aStudy = getActiveStudy() )
+ ProcessVoidEvent( new TVoidMemFun1ArgEvent<QAD_Study,bool>
+ ( aStudy, &QAD_Study::updateObjBrowser,updateSelection) );
}
/*!
*/
int SALOMEGUI_Swig::getActiveStudyId()
{
- if(QAD_Study* myActiveStudy = getActiveStudy())
- return myActiveStudy->getStudyId();
+ if ( QAD_Study* aStudy = getActiveStudy() )
+ return aStudy->getStudyId();
return 0;
}
*/
const char *SALOMEGUI_Swig::getActiveStudyName()
{
- if(QAD_Study* myActiveStudy = getActiveStudy())
- return myActiveStudy->getTitle().latin1();
- return QString::null;
+ if ( QAD_Study* aStudy = getActiveStudy() )
+ return aStudy->getTitle().latin1();
+ return NULL;
}
/*!
*/
const char* SALOMEGUI_Swig::getComponentName( const char* ComponentUserName )
{
- return QAD_Application::getDesktop()->getComponentName( ComponentUserName );
+ if ( QAD_Desktop* aDT = QAD_Application::getDesktop() )
+ return aDT->getComponentName( ComponentUserName );
+ return NULL;
}
/*!
Returns the user name of component.
*/
const char* SALOMEGUI_Swig::getComponentUserName( const char* ComponentName )
{
- return QAD_Application::getDesktop()->getComponentUserName( ComponentName );
+ if ( QAD_Desktop* aDT = QAD_Application::getDesktop() )
+ return aDT->getComponentUserName( ComponentName );
+ return NULL;
}
/*!
*/
int SALOMEGUI_Swig::SelectedCount()
{
- if(QAD_Study* myStudy = getActiveStudy()){
- SALOME_Selection* Sel = SALOME_Selection::Selection(myStudy->getSelection());
+ if ( QAD_Study* aStudy = getActiveStudy() ) {
+ SALOME_Selection* Sel = SALOME_Selection::Selection( aStudy->getSelection() );
return Sel->IObjectCount();
}
return 0;
/*!
Returns the selected object at index i.
*/
-const char* SALOMEGUI_Swig::getSelected(int i)
+const char* SALOMEGUI_Swig::getSelected( int i )
{
- if(QAD_Study* myStudy = getActiveStudy()){
- SALOME_Selection* Sel = SALOME_Selection::Selection( myStudy->getSelection() );
+ if ( QAD_Study* aStudy = getActiveStudy() ) {
+ SALOME_Selection* Sel = SALOME_Selection::Selection( aStudy->getSelection() );
SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
int index = 0;
- for(;It.More();It.Next()){
+ for( ;It.More();It.Next() ) {
Handle(SALOME_InteractiveObject) IObject = It.Value();
if( i == index++ ){
if ( IObject->hasEntry() )
/*!
Add object with Entry into selection.
*/
-void SALOMEGUI_Swig::AddIObject(const char *theEntry)
+void SALOMEGUI_Swig::AddIObject( const char *theEntry )
{
- if(QAD_Study* myStudy = getActiveStudy()){
- SALOME_Selection* aSel = SALOME_Selection::Selection( myStudy->getSelection() );
- if(IsInCurrentView(theEntry)){
- Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject(myStudy,theEntry);
- if(anIO.IsNull()) return;
- ProcessEvent(new TMemFun2ArgEvent<SALOME_Selection,int,
- const Handle(SALOME_InteractiveObject)&,bool,
- Handle(SALOME_InteractiveObject)>
- (aSel,&SALOME_Selection::AddIObject,anIO,true));
+ if ( QAD_Study* aStudy = getActiveStudy() ) {
+ SALOME_Selection* aSel = SALOME_Selection::Selection( aStudy->getSelection() );
+ if ( IsInCurrentView( theEntry ) ) {
+ Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( aStudy,theEntry );
+ if ( anIO.IsNull() ) return;
+ ProcessEvent( new TMemFun2ArgEvent<SALOME_Selection,int,
+ const Handle(SALOME_InteractiveObject)&,bool,
+ Handle(SALOME_InteractiveObject)>
+ ( aSel, &SALOME_Selection::AddIObject, anIO, true ) );
}
}
}
/*!
Removes object with Entry into selection.
*/
-void SALOMEGUI_Swig::RemoveIObject(const char *theEntry)
+void SALOMEGUI_Swig::RemoveIObject( const char *theEntry )
{
- if(QAD_Study* myStudy = getActiveStudy()){
- SALOME_Selection* aSel = SALOME_Selection::Selection( myStudy->getSelection() );
- if(IsInCurrentView(theEntry)){
- Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject(myStudy,theEntry);
- if(anIO.IsNull()) return;
- ProcessEvent(new TMemFun2ArgEvent<SALOME_Selection,int,
- const Handle(SALOME_InteractiveObject)&,bool,
- Handle(SALOME_InteractiveObject)>
- (aSel,&SALOME_Selection::RemoveIObject,anIO,true));
+ if ( QAD_Study* aStudy = getActiveStudy() ) {
+ SALOME_Selection* aSel = SALOME_Selection::Selection( aStudy->getSelection() );
+ if ( IsInCurrentView( theEntry ) ) {
+ Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( aStudy,theEntry );
+ if ( anIO.IsNull() ) return;
+ ProcessEvent( new TMemFun2ArgEvent<SALOME_Selection,int,
+ const Handle(SALOME_InteractiveObject)&, bool,
+ Handle(SALOME_InteractiveObject)>
+ ( aSel, &SALOME_Selection::RemoveIObject, anIO, true ) );
}
}
}
*/
void SALOMEGUI_Swig::ClearIObjects()
{
- if(QAD_Study* myStudy = getActiveStudy()){
- SALOME_Selection* aSel = SALOME_Selection::Selection( myStudy->getSelection() );
- ProcessVoidEvent(new TVoidMemFunEvent<SALOME_Selection>
- (aSel,&SALOME_Selection::ClearIObjects));
+ if ( QAD_Study* aStudy = getActiveStudy() ) {
+ SALOME_Selection* aSel = SALOME_Selection::Selection( aStudy->getSelection() );
+ ProcessVoidEvent( new TVoidMemFunEvent<SALOME_Selection>
+ ( aSel, &SALOME_Selection::ClearIObjects ) );
}
}
/*!
Display
*/
-void SALOMEGUI_Swig::Display(const char *theEntry)
+void SALOMEGUI_Swig::Display( const char *theEntry )
{
- if(QAD_Study* myStudy = getActiveStudy()){
- if(IsInCurrentView(theEntry)){
- Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject(myStudy,theEntry);
- if(anIO.IsNull()) return;
- QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame(myStudy);
- ProcessVoidEvent(new TVoidMemFun2ArgEvent<QAD_ViewFrame,
- const Handle(SALOME_InteractiveObject)&,bool,
- Handle(SALOME_InteractiveObject)>
- (aViewFrame,&QAD_ViewFrame::Display,anIO,true));
+ if ( QAD_Study* aStudy = getActiveStudy() ) {
+ if ( IsInCurrentView( theEntry ) ) {
+ Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( aStudy, theEntry );
+ if ( anIO.IsNull() ) return;
+ QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( aStudy );
+ ProcessVoidEvent( new TVoidMemFun2ArgEvent<QAD_ViewFrame,
+ const Handle(SALOME_InteractiveObject)&, bool,
+ Handle(SALOME_InteractiveObject)>
+ ( aViewFrame, &QAD_ViewFrame::Display, anIO, true ) );
}
}
}
/*!
Display only
*/
-void SALOMEGUI_Swig::DisplayOnly(const char *theEntry)
+void SALOMEGUI_Swig::DisplayOnly( const char *theEntry )
{
- if(QAD_Study* myStudy = getActiveStudy()){
- if(IsInCurrentView(theEntry)){
- Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject(myStudy,theEntry);
- if(anIO.IsNull()) return;
- QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame(myStudy);
- ProcessVoidEvent(new TVoidMemFun1ArgEvent<QAD_ViewFrame,
- const Handle(SALOME_InteractiveObject)&,
- Handle(SALOME_InteractiveObject)>
- (aViewFrame,&QAD_ViewFrame::DisplayOnly,anIO));
+ if ( QAD_Study* aStudy = getActiveStudy() ) {
+ if ( IsInCurrentView( theEntry ) ) {
+ Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( aStudy, theEntry );
+ if ( anIO.IsNull() ) return;
+ QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( aStudy );
+ ProcessVoidEvent( new TVoidMemFun1ArgEvent<QAD_ViewFrame,
+ const Handle(SALOME_InteractiveObject)&,
+ Handle(SALOME_InteractiveObject)>
+ ( aViewFrame, &QAD_ViewFrame::DisplayOnly, anIO ) );
}
}
}
/*!
Erase
*/
-void SALOMEGUI_Swig::Erase(const char *theEntry)
+void SALOMEGUI_Swig::Erase( const char *theEntry )
{
- if(QAD_Study* myStudy = getActiveStudy()){
- if(IsInCurrentView(theEntry)){
- Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject(myStudy,theEntry);
- if(anIO.IsNull()) return;
- QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame(myStudy);
- ProcessVoidEvent(new TVoidMemFun2ArgEvent<QAD_ViewFrame,
- const Handle(SALOME_InteractiveObject)&,bool,
- Handle(SALOME_InteractiveObject)>
- (aViewFrame,&QAD_ViewFrame::Erase,anIO,true));
+ if ( QAD_Study* aStudy = getActiveStudy() ) {
+ if ( IsInCurrentView( theEntry ) ) {
+ Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( aStudy, theEntry );
+ if ( anIO.IsNull() ) return;
+ QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( aStudy );
+ ProcessVoidEvent( new TVoidMemFun2ArgEvent<QAD_ViewFrame,
+ const Handle(SALOME_InteractiveObject)&, bool,
+ Handle(SALOME_InteractiveObject)>
+ ( aViewFrame, &QAD_ViewFrame::Erase, anIO, true ) );
}
}
}
*/
void SALOMEGUI_Swig::DisplayAll()
{
- if(QAD_Study* myStudy = getActiveStudy()){
- QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame(myStudy);
- ProcessVoidEvent(new TVoidMemFunEvent<QAD_ViewFrame>
- (aViewFrame,&QAD_ViewFrame::DisplayAll));
+ if ( QAD_Study* aStudy = getActiveStudy() ) {
+ QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( aStudy );
+ ProcessVoidEvent( new TVoidMemFunEvent<QAD_ViewFrame>
+ ( aViewFrame, &QAD_ViewFrame::DisplayAll ) );
}
}
void SALOMEGUI_Swig::EraseAll()
{
ClearIObjects();
- if(QAD_Study* myStudy = getActiveStudy()){
- QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame(myStudy);
- ProcessVoidEvent(new TVoidMemFunEvent<QAD_ViewFrame>
- (aViewFrame,&QAD_ViewFrame::EraseAll));
+ if ( QAD_Study* aStudy = getActiveStudy() ) {
+ QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( aStudy );
+ ProcessVoidEvent ( new TVoidMemFunEvent<QAD_ViewFrame>
+ ( aViewFrame, &QAD_ViewFrame::EraseAll ) );
}
}
/*!
Checks if object is displayed in current viewer
*/
-bool SALOMEGUI_Swig::IsInCurrentView(const char *theEntry)
+bool SALOMEGUI_Swig::IsInCurrentView( const char *theEntry )
{
- if(QAD_Study* myStudy = getActiveStudy())
- return myStudy->isInViewer( theEntry, myStudy->getActiveStudyFrame()->entry() );
+ if ( QAD_Study* aStudy = getActiveStudy() )
+ return aStudy->isInViewer( theEntry, aStudy->getActiveStudyFrame()->entry() );
return false;
}