-using namespace std;
-// File : SALOMEGUI_Application.cxx
-// Created : Thu Jun 14 12:01:00 2001
-// Author : Nicolas REJNERI
-// Project : SALOME
-// Module : SALOMEGUI
-// Copyright : Open CASCADE
+// SALOME SALOMEGUI : implementation of desktop and GUI kernel
+//
+// 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
+//
+//
+//
+// File : SALOMEGUI_Application.cxx
+// Author : Nicolas REJNERI
+// Module : SALOME
// $Header$
#include "SALOMEGUI_Application.h"
#include "SALOMEGUI_Desktop.h"
#include "SALOMEGUI_ImportOperation.h"
+#include "SALOMEGUI.h"
#include "SALOME_Selection.h"
#include "SALOME_ListIO.hxx"
#include "SALOME_ListIteratorOfListIO.hxx"
#include "QAD_Resource.h"
#include "QAD_Tools.h"
#include "QAD_WaitCursor.h"
+#include "QAD_MessageBox.h"
// QT Includes
#include <qapplication.h>
// Open CASCADE Include
#include <Standard_Failure.hxx>
#include <TCollection_AsciiString.hxx>
+using namespace std;
/*!
Constructor
if ( !palette) palette = QAD_Desktop::createPalette();
// if ( !palette) palette->loadPalette();
- myViewActions.setAutoDelete( true );
+ //myViewActions.setAutoDelete( true );
/* We need to know that the desktop is created to have
some additional internal initialization */
QAD_ResourceMgr* rmgr = QAD_Desktop::getResourceManager();
#define CREATE_ACTION(ID,NAME) \
if(!myViewActions.at(ID)){ \
- QAction* action = new QAction(tr("TOT_APP_VIEW_" #NAME), \
+ QActionP* action = new QActionP(tr("TOT_APP_VIEW_" #NAME), \
rmgr->loadPixmap("SALOMEGUI", tr("ICON_APP_VIEW_" #NAME)), \
tr("MEN_APP_VIEW_" #NAME), 0, QAD_Application::getDesktop()); \
action->setStatusTip(tr("PRP_APP_VIEW_" #NAME)); \
}
QAD_StudyFrame* sf = myActiveStudy->getActiveStudyFrame();
- Standard_CString name = strdup(sf->title().latin1());
+ Standard_CString name = CORBA::string_dup(sf->title().latin1());
SALOMEDS::SComponent_var father = aStudy->FindComponent("Interface Applicative");
SALOMEDS::SObject_var newObj = B->NewObject(father);
if ( vf ) {
QToolBar* tbView = getToolBar( ViewToolBarId );
- QListIterator<QAction> it( myViewActions );
- for( ; it.current(); ++it )
- it.current()->removeFrom( tbView );
+ for ( int cmd = ViewDumpId; cmd <= ViewResetId; cmd++ )
+ if ( myViewActions.at( cmd ) )
+ myViewActions.at( cmd )->removeFrom(tbView);
if( vf->getTypeView() == VIEW_GRAPHSUPERV ) {
//myViewActions.at(ViewDumpId)->addTo(tbView);
//myViewActions.at(ViewFitAllId)->addTo(tbView);
//myViewActions.at(ViewResetId)->addTo(tbView);
}
else {
- it.toFirst();
- for( ; it.current(); ++it )
- it.current()->addTo(tbView);
+ for ( int cmd = ViewDumpId; cmd <= ViewResetId; cmd++ )
+ if ( myViewActions.at( cmd ) )
+ myViewActions.at( cmd )->addTo(tbView);
}
//CONNECT_ACTION(Mu4Id)
CONNECT_ACTION(Dump);
return;
}
- // Obtain the component's GUI library
- // Library cashing will be implemented soon in QAD_Desktop to increase performance
- OSD_Function osdF, osdViewTypeFunc;
- OSD_SharedLibrary foreignGUI;
- void (*builder)(const Handle(SALOME_InteractiveObject)&);
- bool isForeignGUIUsed = false;
bool isViewTypeOK = true;
int viewTypes[VIEW_TYPE_MAX];
for (int i = 0; i < VIEW_TYPE_MAX; i++)
viewTypes[i] = -1;
- if (parentComp.compare(desktop->getActiveComponent()) == 0) { // use active GUI library
- const OSD_SharedLibrary& compGUI = desktop->getHandle();
- osdF = compGUI.DlSymb("buildPresentation");
- if ( osdF == NULL ) {
- MESSAGE("BuildPresentation method not found in component's GUI")
- return;
- }
- osdViewTypeFunc = compGUI.DlSymb("supportedViewType");
- if ( osdViewTypeFunc == NULL ) {
- MESSAGE("supportedViewType method not found in component's GUI")
- }
- MESSAGE("onDisplay(): using active GUI to build presentations")
- } else { // use native GUI library
- QString ComponentLib;
- QCString dir;
- QFileInfo fileInfo ;
- bool found = false;
- if ( getenv("SALOME_SITE_DIR") ) {
- dir.fill('\0');
- dir.sprintf("%s",getenv("SALOME_SITE_DIR"));
- dir = QAD_Tools::addSlash(dir) ;
- dir = dir + "lib" ;
- dir = QAD_Tools::addSlash(dir) ;
-#ifdef WNT
- dir = dir + "lib" + parentComp.latin1() + "GUI.dll" ;
-#else
- dir = dir + "lib" + parentComp.latin1() + "GUI.so" ;
-#endif
- MESSAGE ( " GUI library = " << dir )
- fileInfo.setFile(dir) ;
- if (fileInfo.exists()) {
- ComponentLib = fileInfo.fileName();
- found = true;
- MESSAGE ( " found " )
- } else {
- MESSAGE ( " Not found " )
- }
- }
- if ( !found && getenv("SALOME_ROOT_DIR") ) {
- dir.fill('\0');
- dir.sprintf("%s", getenv("SALOME_ROOT_DIR"));
- dir = QAD_Tools::addSlash(dir) ;
- dir = dir + "lib" ;
- dir = QAD_Tools::addSlash(dir) ;
-#ifdef WNT
- dir = dir + "lib" + parentComp.latin1() + "GUI.dll" ;
-#else
- dir = dir + "lib" + parentComp.latin1() + "GUI.so" ;
-#endif
- MESSAGE ( " GUI library = " << dir )
- fileInfo.setFile(dir) ;
- if (fileInfo.exists()) {
- ComponentLib = fileInfo.fileName() ;
- found = true;
- MESSAGE ( " found " )
- } else {
- MESSAGE ( " Not found " )
- }
- }
- if ( !found && getenv("KERNEL_ROOT_DIR") ) {
- dir.fill('\0');
- dir.sprintf("%s", getenv("KERNEL_ROOT_DIR"));
- dir = QAD_Tools::addSlash(dir) ;
- dir = dir + "lib" ;
- dir = QAD_Tools::addSlash(dir) ;
-#ifdef WNT
- dir = dir + "lib" + parentComp.latin1() + "GUI.dll" ;
-#else
- dir = dir + "lib" + parentComp.latin1() + "GUI.so" ;
-#endif
- MESSAGE ( " GUI library = " << dir )
- fileInfo.setFile(dir) ;
- if (fileInfo.exists()) {
- ComponentLib = fileInfo.fileName() ;
- found = true;
- MESSAGE ( " found " )
- } else {
- MESSAGE ( " Not found " )
- }
- }
-
- if (ComponentLib.isEmpty()) {
- waitCursor.stop();
- QMessageBox::critical( desktop,
- tr("ERR_ERROR"),
- "Empty name of component "+ parentComp + " library");
- return;
- }
-
- foreignGUI.SetName(TCollection_AsciiString((char*)ComponentLib.latin1()).ToCString());
-
- bool ok = foreignGUI.DlOpen(OSD_RTLD_LAZY);
- if (!ok) {
- waitCursor.stop();
- QMessageBox::critical( desktop,
- tr("ERR_ERROR"),
- tr( foreignGUI.DlError() ) );
- return;
- }
-
- osdF = foreignGUI.DlSymb("buildPresentation");
- if ( osdF == NULL ) {
- MESSAGE("BuildPresentation method not found in component's GUI")
- foreignGUI.DlClose();
- return;
- }
- osdViewTypeFunc = foreignGUI.DlSymb("supportedViewType");
- if ( osdViewTypeFunc == NULL ) {
- MESSAGE("supportedViewType method not found in component's GUI")
- }
- isForeignGUIUsed = true;
- MESSAGE("onDisplay(): using parent component's GUI to build presentations")
- }
+ // Obtain the component's GUI
+ SALOMEGUI* aGUI = desktop->getComponentGUI( parentComp );
+ if ( !aGUI )
+ return;
// Check if another view type is required (if viewToActivate < 0 then any type of view is acceptable)
- if (osdViewTypeFunc) {
- void (*viewTypeChecker)(int*, int) = (void (*)(int*, int)) osdViewTypeFunc;
- (*viewTypeChecker)(viewTypes, VIEW_TYPE_MAX);
- if (viewTypes[0] >= 0) { // not all the view types are supported
- for (int i = 0; i < VIEW_TYPE_MAX; i++) {
- if (viewTypes[i] < 0) // no more types supported
- break;
- isViewTypeOK = ((int)myActiveStudy->getActiveStudyFrame()->getTypeView() == viewTypes[i]);
- if (isViewTypeOK) // one of supported views is already active
- break;
- }
+ aGUI->SupportedViewType(viewTypes, VIEW_TYPE_MAX);
+ if (viewTypes[0] >= 0) { // not all the view types are supported
+ for (int i = 0; i < VIEW_TYPE_MAX; i++) {
+ if (viewTypes[i] < 0) // no more types supported
+ break;
+ isViewTypeOK = ((int)myActiveStudy->getActiveStudyFrame()->getTypeView() == viewTypes[i]);
+ if (isViewTypeOK) // one of supported views is already active
+ break;
}
}
QAD_ViewFrame* viewFrame = myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame();
+ // Ensure that parent component's data are loaded
+ QString compName = desktop->getComponentName( parentComp );
+ if ( compName.isEmpty() ) {
+ waitCursor.stop();
+ QAD_MessageBox::error1( desktop,
+ tr("ERR_ERROR"),
+ tr("ERR_EMPTY_COMP_NAME").arg( parentComp ),
+ tr("BUT_OK"));
+ return;
+ }
+
+ desktop->loadComponentData( compName );
+
// Build the graphic presentation (it is stored in the corresponding viewer)
- builder = (void (*) (const Handle(SALOME_InteractiveObject)&)) osdF;
+
+ bool isComponent = false;
+ SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
+ bool needRepaint = false;
// Copy the selection
SALOME_ListIteratorOfListIO itInit( Sel->StoredIObjects() );
SALOME_ListIO selList;
for (; itInit.More(); itInit.Next()) {
- selList.Append(itInit.Value());
+ Handle(SALOME_InteractiveObject) IObject = itInit.Value();
+ if ( IObject->hasEntry() ) {
+ // check whether the component is selected
+ SALOMEDS::SObject_var obj = aStudy->FindObjectID(IObject->getEntry() );
+ if ( !obj->_is_nil() && strcmp( obj->GetFatherComponent()->GetID(), obj->GetID() ) == 0 ) {
+ selList.Clear();
+ isComponent = true;
+ selList.Append( IObject );
+ break;
+ }
+ }
+ selList.Append( IObject );
}
-
- SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
- bool needRepaint = false;
-
if (id == QAD_DisplayOnly_Popup_ID)
viewFrame->EraseAll();
- SALOME_ListIteratorOfListIO It( selList );
- for(;It.More();It.Next()) {
- Handle(SALOME_InteractiveObject) IObject = It.Value();
-
- // First check whether the object is a component or a child object
- bool isComponent = false;
-
- if (!IObject->hasEntry()) continue;
-
- SALOMEDS::SObject_var obj = aStudy->FindObjectID(IObject->getEntry());
- if (!obj->_is_nil()) {
- SALOMEDS::SComponent_var comp = obj->GetFatherComponent();
- isComponent = (strcmp(comp->GetID(), obj->GetID()) == 0);
- }
-
- // For component -> display all children
- if (isComponent) {
- SALOMEDS::ChildIterator_ptr it = aStudy->NewChildIterator(obj);
- it->InitEx(true);
- for ( ; it->More(); it->Next()) {
- SALOMEDS::SObject_ptr child = it->Value();
+ // For component -> display all children
+ if ( isComponent ) {
+ SALOMEDS::SObject_var obj = aStudy->FindObjectID( selList.First()->getEntry() );
+ SALOMEDS::ChildIterator_ptr It = aStudy->NewChildIterator( obj );
+ It->InitEx( true );
+ for ( ; It->More(); It->Next() ) {
+ SALOMEDS::SObject_ptr child = It->Value();
+ SALOMEDS::SObject_ptr ref;
+ if ( !child->ReferencedObject( ref ) ) {
Handle(SALOME_InteractiveObject) childIObject = new SALOME_InteractiveObject();
- childIObject->setEntry(child->GetID());
-
+ childIObject->setEntry( child->GetID() );
// Ensure that proper 3D presentation exists for IObject
- (*builder)(childIObject);
+ aGUI->BuildPresentation(childIObject);
viewFrame->Display(childIObject, false);
needRepaint = true;
}
- } else { // for child object -> simply display it (no children are displayed)
+ }
+ }
+ else { // for child object -> simply display it (no children are displayed)
+ SALOME_ListIteratorOfListIO It( selList );
+ for( ;It.More();It.Next() ) {
+ Handle(SALOME_InteractiveObject) IObject = It.Value();
// Ensure that proper 3D presentation exists for IObject
- (*builder)(IObject);
+ aGUI->BuildPresentation(IObject);
viewFrame->Display(IObject, false);
needRepaint = true;
}
-
}
- if (needRepaint)
+ if ( needRepaint )
viewFrame->Repaint();
- if (isForeignGUIUsed)
- foreignGUI.DlClose();
myActiveStudy->updateObjBrowser(true);
}