#include <SUIT_Tools.h>
#include <SUIT_FileDlg.h>
#include <SUIT_Desktop.h>
+#include <SUIT_ViewModel.h>
#include <SalomeApp_Application.h>
#include <SalomeApp_Study.h>
+#include <SalomeApp_SelectionMgr.h>
-//#include "OCCViewer_Viewer3d.h"
-//#include "VTKViewer_ViewWindow.h"
-//#include "VTKViewer_RenderWindowInteractor.h"
-
-#include "SALOME_ListIteratorOfListIO.hxx"
-//#include "SALOMEGUI_ImportOperation.h"
-//#include "SALOMEGUI_QtCatchCorbaException.hxx"
+#include <SALOME_ListIteratorOfListIO.hxx>
+#include <SALOME_Prs.h>
#include <qapplication.h>
#include <qmap.h>
typedef QMap<QString, QString> FilterMap;
-#include "SALOMEDSClient.hxx"
-#include "SALOMEDS_SObject.hxx"
-#include "SALOMEDS_Study.hxx"
+#include <SALOMEDS_SObject.hxx>
}
+
//===============================================================================
// function : OnEditDelete()
// purpose :
//===============================================================================
void GEOMToolsGUI::OnEditDelete()
{
-/*
- SALOME_Selection* Sel = SALOME_Selection::Selection(
- QAD_Application::getDesktop()->getActiveStudy()->getSelection() );
-
- if ( Sel->IObjectCount() == 0 )
- return;
-
- _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
-
- bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
- if ( aLocked ) {
- QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
- QObject::tr("WRN_WARNING"),
- QObject::tr("WRN_STUDY_LOCKED"),
- QObject::tr("BUT_OK") );
- return;
- }
-
- // VSR 17/11/04: check if all objects selected belong to GEOM component --> start
- QString aParentComponent = ((SALOMEGUI_Desktop*)QAD_Application::getDesktop())->getComponentFromSelection();
- if ( aParentComponent != QAD_Application::getDesktop()->getActiveComponent() ) {
- QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
- QObject::tr("ERR_ERROR"),
- QObject::tr("NON_GEOM_OBJECTS_SELECTED").arg(QAD_Application::getDesktop()->getComponentUserName( "GEOM" )),
- QObject::tr("BUT_OK") );
- return;
- }
- // VSR 17/11/04: check if all objects selected belong to GEOM component <-- finish
-
- if ( QAD_MessageBox::warn2( QAD_Application::getDesktop(),
- tr( "GEOM_WRN_WARNING" ),
- tr( "GEOM_REALLY_DELETE" ),
- tr( "GEOM_BUT_YES" ),
- tr( "GEOM_BUT_NO" ), 1, 0, 0 ) != 1 )
- return;
-
- int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
-
- Standard_Boolean found;
- _PTR(GenericAttribute) anAttr;
-
- SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
-
- QAD_Operation* op = new SALOMEGUI_ImportOperation( QAD_Application::getDesktop()->getActiveStudy() );
-
- op->start();
-
- Standard_Boolean deleted = false;
+ SALOME_ListIO selected;
+ SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+ if ( app ) {
+ SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
+ SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+ if ( aSelMgr && appStudy ) {
+ aSelMgr->selectedObjects( selected );
+ if ( !selected.IsEmpty() ) {
+ _PTR(Study) aStudy = appStudy->studyDS();
+
+ bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
+ if ( aLocked ) {
+ SUIT_MessageBox::warn1 ( app->desktop(),
+ QObject::tr("WRN_WARNING"),
+ QObject::tr("WRN_STUDY_LOCKED"),
+ QObject::tr("BUT_OK") );
+ return;
+ }
- for ( ;It.More();It.Next() )
- {
- Handle( SALOME_InteractiveObject ) IObject = It.Value();
-
- if ( !IObject->hasEntry() )
- continue;
-
- _PTR(SObject) SO ( aStudy->FindObjectID( IObject->getEntry() ) );
- _PTR(AttributeIOR) anIOR;
-
- // Erase child graphical objects
-
- _PTR(ChildIterator) it ( aStudy->NewChildIterator( SO ) );
- for ( ; it->More();it->Next() )
- {
- _PTR(SObject) CSO ( it->Value() );
-
- if ( CSO->FindAttribute( anAttr, "AttributeIOR" ) )
- {
- anIOR = anAttr;
-
- // Delete child( s ) shape in Client :
-
- const TCollection_AsciiString ASCior( (char*)anIOR->Value().c_str() ) ;
- GeometryGUI::GetGeomGUI()->GetShapeReader().RemoveShapeFromBuffer( ASCior );
-
- for ( int i = 0; i < nbSf; i++ )
- {
- GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( dynamic_cast<SALOMEDS_SObject*>(CSO.get())->GetObject() );
- if ( !aGeomObj->_is_nil() )
- GEOM_Displayer().Erase( aGeomObj, true );
- }
- }
- }
-
- // Erase main graphical object
-
- for ( int i = 0; i < nbSf; i++ )
- {
- QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame( i );
- GEOM_Displayer().Erase( IObject, true );
- }
-
- // Delete main shape in Client :
-
- if ( SO->FindAttribute( anAttr, "AttributeIOR" ) )
- {
- anIOR = anAttr;
- const TCollection_AsciiString ASCIor( (char*)anIOR->Value().c_str() ) ;
- GeometryGUI::GetGeomGUI()->GetShapeReader().RemoveShapeFromBuffer( ASCIor );
- }
-
- // Erase objects in Study
-
- _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
- if ( obj )
- {
- _PTR(StudyBuilder) aStudyBuilder (aStudy->NewBuilder());
- aStudyBuilder->RemoveObject( obj );
-
- GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(dynamic_cast<SALOMEDS_SObject*>(obj.get())->GetObject());
- if ( !aGeomObj->_is_nil() )
- GeometryGUI::GetGeomGUI()->GetGeomGen()->RemoveObject( aGeomObj );
+ // VSR 17/11/04: check if all objects selected belong to GEOM component --> start
+ // modifications of ASV 01.06.05
+ QString parentComp = getParentComponent( aStudy, selected );
+ const char* geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() );
+ QString geomComp = getParentComponent( aStudy->FindObjectIOR( geomIOR ) );
+
+ if ( parentComp != geomComp ) {
+ SUIT_MessageBox::warn1 ( app->desktop(),
+ QObject::tr("ERR_ERROR"),
+ QObject::tr("NON_GEOM_OBJECTS_SELECTED").arg( getGeometryGUI()->moduleName() ),
+ QObject::tr("BUT_OK") );
+ return;
+ }
+ // VSR 17/11/04: check if all objects selected belong to GEOM component <-- finish
+
+ if ( SUIT_MessageBox::warn2( app->desktop(),
+ QObject::tr( "GEOM_WRN_WARNING" ),
+ QObject::tr( "GEOM_REALLY_DELETE" ),
+ QObject::tr( "GEOM_BUT_YES" ),
+ QObject::tr( "GEOM_BUG_NO" ), 1, 0, 0 ) != 1 )
+ return;
+
+ // QAD_Operation* op = new SALOMEGUI_ImportOperation(.....);
+ // op->start();
+
+ // prepare list of SALOME_Views
+ QPtrList<SALOME_View> views;
+ SALOME_View* view;
+ // fill the list
+ ViewManagerList vmans = app->viewManagers();
+ SUIT_ViewManager* vman;
+ for ( vman = vmans.first(); vman; vman = vmans.next() ) {
+ SUIT_ViewModel* vmod = vman->getViewModel();
+ view = dynamic_cast<SALOME_View*> ( vmod ); // must work for OCC and VTK views
+ if ( view )
+ views.append( view );
+ }
+
+ _PTR(StudyBuilder) aStudyBuilder (aStudy->NewBuilder());
+ _PTR(GenericAttribute) anAttr;
+ GEOM_Displayer* disp = new GEOM_Displayer( appStudy );
+
+ // MAIN LOOP OF SELECTED OBJECTS
+ for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
+
+ Handle(SALOME_InteractiveObject) io = It.Value();
+ if ( !io->hasEntry() )
+ continue;
+
+ _PTR(SObject) obj ( aStudy->FindObjectID( io->getEntry() ) );
+
+ // disable removal of "Geometry" component object
+ if ( !strcmp( obj->GetIOR().c_str(), geomIOR ) )
+ continue;
+
+ // iterate through all childres of obj, find IOR attributes on children and remove shapes that
+ // correspond to these IORs
+ for ( _PTR(ChildIterator) it ( aStudy->NewChildIterator( obj ) ); it->More();it->Next() ) {
+ _PTR(SObject) child ( it->Value() );
+ if ( child->FindAttribute( anAttr, "AttributeIOR" ) ) {
+ _PTR(AttributeIOR) anIOR( anAttr );
+
+ // Delete child( s ) shape in Client :
+ const TCollection_AsciiString ASCior( (char*)anIOR->Value().c_str() ) ;
+ getGeometryGUI()->GetShapeReader().RemoveShapeFromBuffer( ASCior );
+
+ for ( view = views.first(); view; view = views.next() ) {
+ CORBA::Object_var corbaObj = (dynamic_cast<SALOMEDS_SObject*>(child.get()))->GetObject();
+ GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
+ if ( !CORBA::is_nil( geomObj ) )
+ disp->Erase( geomObj, true, view );
+ }
+ }
+ } // for ( childres of obj )
+
+ // Erase main graphical object
+ for ( view = views.first(); view; view = views.next() )
+ disp->Erase( io, true, view );
+
+ // Delete main shape in Client :
+ if ( obj->FindAttribute( anAttr, "AttributeIOR" ) ) {
+ _PTR(AttributeIOR) anIOR( anAttr );
+ const TCollection_AsciiString ASCIor( (char*)anIOR->Value().c_str() ) ;
+ getGeometryGUI()->GetShapeReader().RemoveShapeFromBuffer( ASCIor );
+ }
+
+ // Remove objects from Study
+ aStudyBuilder->RemoveObject( obj );
+
+ CORBA::Object_var corbaObj = (dynamic_cast<SALOMEDS_SObject*>(obj.get()))->GetObject();
+ GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
+ if ( !CORBA::is_nil( geomObj ) )
+ GeometryGUI::GetGeomGen()->RemoveObject( geomObj );
- deleted = true;
- }
- }
-
- if ( deleted )
- op->finish();
- else
- op->abort();
-
- // Clear any previous selection
- Sel->ClearIObjects();
- QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser();
- */
+ //deleted = true;
+ } // MAIN LOOP of selected
+
+ selected.Clear();
+ aSelMgr->setSelectedObjects( selected );
+ getGeometryGUI()->updateObjBrowser();
+ } // if ( selected not empty )
+ } // if ( selMgr && appStudy )
+ } // if ( app )
+
+ // if ( deleted )
+ // op->finish();
+ // else
+ // op->abort();
}
return true;
}
+QString GEOMToolsGUI::getParentComponent( _PTR( Study ) study, const SALOME_ListIO& iobjs )
+{
+ QString parentComp;
+
+ for ( SALOME_ListIteratorOfListIO it( iobjs ); it.More(); it.Next() ) {
+
+ Handle(SALOME_InteractiveObject) io = it.Value();
+ if ( !io->hasEntry() )
+ continue;
+
+ QString compName = getParentComponent( study->FindObjectID( io->getEntry() ) );
+
+ if ( parentComp.isNull() )
+ parentComp = compName;
+ else if ( parentComp.compare( compName) != 0 ) { // objects belonging to different components are selected
+ parentComp = QString::null;
+ break;
+ }
+ }
+
+ return parentComp;
+}
+
+QString GEOMToolsGUI::getParentComponent( _PTR( SObject ) obj )
+{
+ if ( obj ) {
+ _PTR(SComponent) comp = obj->GetFatherComponent();
+ if ( comp ) {
+ _PTR(GenericAttribute) anAttr;
+ if ( comp->FindAttribute( anAttr, "AttributeName") ) {
+ _PTR(AttributeName) aName( anAttr );
+ return QString( aName->Value().c_str() );
+ }
+ }
+ }
+ return QString();
+}
//=====================================================================================
// EXPORTED METHODS
#include "GEOMBase.h"
#include "GEOMToolsGUI_TransparencyDlg.h"
#include "GEOMToolsGUI_NbIsosDlg.h" // Method ISOS adjustement
+#include "GEOMToolsGUI_NameDlg.h"
#include <SALOME_ListIO.hxx>
#include <SALOME_ListIteratorOfListIO.hxx>
#include <SUIT_ResourceMgr.h>
#include <SUIT_Session.h>
#include <SUIT_OverrideCursor.h>
+#include <SUIT_MessageBox.h>
#include <SalomeApp_Application.h>
#include <SalomeApp_SelectionMgr.h>
+#include <SalomeApp_Study.h>
+#include <SalomeApp_Module.h>
#include <AIS_Drawer.hxx>
#include <AIS_ListOfInteractive.hxx>
void GEOMToolsGUI::OnRename()
{
-/*
- SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
- _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
-
- bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
- if ( aLocked ) {
- QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
- QObject::tr("WRN_WARNING"),
- QObject::tr("WRN_STUDY_LOCKED"),
- QObject::tr("BUT_OK") );
- return;
- }
+ SALOME_ListIO selected;
+ SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+ if ( app ) {
+ SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
+ SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+ if ( aSelMgr && appStudy ) {
+ aSelMgr->selectedObjects( selected );
+ if ( !selected.IsEmpty() ) {
+ _PTR(Study) aStudy = appStudy->studyDS();
+
+ bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
+ if ( aLocked ) {
+ SUIT_MessageBox::warn1 ( app->desktop(),
+ QObject::tr("WRN_WARNING"),
+ QObject::tr("WRN_STUDY_LOCKED"),
+ QObject::tr("BUT_OK") );
+ return;
+ }
- SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
- for(; It.More(); It.Next()) {
- Handle(SALOME_InteractiveObject) IObject = It.Value();
+ for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
+ Handle(SALOME_InteractiveObject) IObject = It.Value();
- _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
- _PTR(GenericAttribute) anAttr;
- if(obj) {
- if(obj->FindAttribute(anAttr, "AttributeName")) {
- _PTR(AttributeName) aName (anAttr);
+ _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
+ _PTR(GenericAttribute) anAttr;
+ if ( obj ) {
+ if( obj->FindAttribute(anAttr, "AttributeName") ) {
+ _PTR(AttributeName) aName (anAttr);
- QString nm = QString(aName->Value().c_str());
- nm = SALOMEGUI_NameDlg::getName(QAD_Application::getDesktop(), nm);
- if(!nm.isEmpty()) {
- QApplication::setOverrideCursor(Qt::waitCursor);
- QAD_Application::getDesktop()->getActiveStudy()->renameIObject(IObject, nm);
- QApplication::restoreOverrideCursor();
- }
+ QString newName = GEOMToolsGUI_NameDlg::getName( app->desktop(), aName->Value().c_str() );
+ if ( !newName.isEmpty() ) {
+ aName->SetValue( newName.latin1() ); // rename the SObject
+ IObject->setName( newName.latin1() );// rename the InteractiveObject
+ (dynamic_cast<SalomeApp_Module*>(app->activeModule()))->updateObjBrowser( false );
+ }
+ } // if ( name attribute )
+ } // if ( obj )
+ } // iterator
}
}
}
-*/
}
void GEOMToolsGUI::OnCheckGeometry()
--- /dev/null
+// SALOME GEOMToolsGUI : implementation of desktop and GUI kernel
+//
+// Copyright (C) 2003 CEA/DEN, EDF R&D
+//
+//
+//
+// File : GEOMToolsGUI_NameDlg.cxx
+// Author : Vadim SANDLER
+// Module : SALOME
+// $Header$
+
+#include "GEOMToolsGUI_NameDlg.h"
+
+#include <SUIT_Session.h>
+#include <SUIT_Application.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_Tools.h>
+
+#include <qgroupbox.h>
+#include <qlabel.h>
+#include <qlineedit.h>
+#include <qpushbutton.h>
+#include <qlayout.h>
+using namespace std;
+
+/*!
+ Constructor
+*/
+GEOMToolsGUI_NameDlg::GEOMToolsGUI_NameDlg( QWidget* parent )
+ : QDialog( parent ? parent : SUIT_Session::session()->activeApplication()->desktop(),
+ "GEOMToolsGUI_NameDlg",
+ true,
+ WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
+{
+ setCaption( tr("TLT_RENAME") );
+ setSizeGripEnabled( TRUE );
+
+ QVBoxLayout* topLayout = new QVBoxLayout( this );
+ topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
+
+ /***************************************************************/
+ QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" );
+ GroupC1->setColumnLayout(0, Qt::Vertical );
+ GroupC1->layout()->setMargin( 0 ); GroupC1->layout()->setSpacing( 0 );
+ QHBoxLayout* GroupC1Layout = new QHBoxLayout( GroupC1->layout() );
+ GroupC1Layout->setAlignment( Qt::AlignTop );
+ GroupC1Layout->setMargin( 11 ); GroupC1Layout->setSpacing( 6 );
+
+ QLabel* TextLabel = new QLabel( GroupC1, "TextLabel1" );
+ TextLabel->setText( tr( "NAME_LBL" ) );
+ GroupC1Layout->addWidget( TextLabel );
+
+ myLineEdit = new QLineEdit( GroupC1, "LineEdit1" );
+ myLineEdit->setMinimumSize( 250, 0 );
+ GroupC1Layout->addWidget( myLineEdit );
+
+ /***************************************************************/
+ QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
+ GroupButtons->setColumnLayout(0, Qt::Vertical );
+ GroupButtons->layout()->setMargin( 0 ); GroupButtons->layout()->setSpacing( 0 );
+ QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() );
+ GroupButtonsLayout->setAlignment( Qt::AlignTop );
+ GroupButtonsLayout->setMargin( 11 ); GroupButtonsLayout->setSpacing( 6 );
+
+ myButtonOk = new QPushButton( GroupButtons, "buttonOk" );
+ myButtonOk->setText( tr( "BUT_OK" ) );
+ myButtonOk->setAutoDefault( TRUE ); myButtonOk->setDefault( TRUE );
+ GroupButtonsLayout->addWidget( myButtonOk );
+
+ GroupButtonsLayout->addStretch();
+
+ myButtonCancel = new QPushButton( GroupButtons, "buttonCancel" );
+ myButtonCancel->setText( tr( "BUT_CANCEL" ) );
+ myButtonCancel->setAutoDefault( TRUE );
+ GroupButtonsLayout->addWidget( myButtonCancel );
+ /***************************************************************/
+
+ topLayout->addWidget( GroupC1 );
+ topLayout->addWidget( GroupButtons );
+
+ // signals and slots connections
+ connect( myButtonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
+ connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
+
+ /* Move widget on the botton right corner of main widget */
+ SUIT_Tools::centerWidget( this, parent );
+}
+
+/*!
+ Destructor
+*/
+GEOMToolsGUI_NameDlg::~GEOMToolsGUI_NameDlg()
+{
+}
+
+/*!
+ Sets name
+*/
+void GEOMToolsGUI_NameDlg::setName( const QString& name )
+{
+ myLineEdit->setText( name );
+ myLineEdit->end(false);
+ myLineEdit->home(true);
+}
+
+/*!
+ Returns name entered by user
+*/
+QString GEOMToolsGUI_NameDlg::name()
+{
+ return myLineEdit->text();
+}
+
+void GEOMToolsGUI_NameDlg::accept()
+{
+ if ( name().stripWhiteSpace().isEmpty() )
+ return;
+ QDialog::accept();
+}
+
+/*!
+ Creates modal <Rename> dialog and returns name entered [ static ]
+*/
+QString GEOMToolsGUI_NameDlg::getName( QWidget* parent, const QString& oldName )
+{
+ QString n;
+ GEOMToolsGUI_NameDlg* dlg = new GEOMToolsGUI_NameDlg( parent );
+ if ( !oldName.isNull() )
+ dlg->setName( oldName );
+ if ( dlg->exec() == QDialog::Accepted )
+ n = dlg->name();
+ delete dlg;
+ return n;
+}