#include "SMESHGUI_MakeNodeAtPointDlg.h"
#include "SMESHGUI_BuildCompoundDlg.h"
#include "SMESHGUI_ComputeDlg.h"
+#include "SMESHGUI_FileInfoDlg.h"
#include "SMESHGUI_Utils.h"
#include "SMESHGUI_GEOMGenUtils.h"
#include "SALOMEconfig.h"
#include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
-#include CORBA_SERVER_HEADER(SMESH_MeshEditor)
+#include CORBA_CLIENT_HEADER(SMESH_MeshEditor)
// QT Includes
#define INCLUDE_MENUITEM_DEF
// Definitions
//=============================================================
- void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
- int theCommandID)
+ void ImportMeshesFromFile( SMESH::SMESH_Gen_ptr theComponentMesh,
+ int theCommandID )
{
QStringList filter;
string myExtension;
- if(theCommandID == 113){
- filter.append(QObject::tr("MED files (*.med)"));
- filter.append(QObject::tr("All files (*)"));
- }else if (theCommandID == 112){
- filter.append(QObject::tr("IDEAS files (*.unv)"));
- }else if (theCommandID == 111){
- filter.append(QObject::tr("DAT files (*.dat)"));
- }
- QString filename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(),
- QDir::currentDirPath(),
- filter,
- QObject::tr("Import mesh"),
- true);
- if(!filename.isEmpty()) {
+ if ( theCommandID == 113 ) {
+ filter.append( QObject::tr( "MED files (*.med)" ) );
+ filter.append( QObject::tr( "All files (*)" ) );
+ }
+ else if ( theCommandID == 112 ) {
+ filter.append( QObject::tr( "IDEAS files (*.unv)" ) );
+ }
+ else if ( theCommandID == 111 ) {
+ filter.append( QObject::tr( "DAT files (*.dat)" ) );
+ }
+
+ QString anInitialPath = "";
+ if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
+ anInitialPath = QDir::currentDirPath();
+
+ QStringList filenames = SUIT_FileDlg::getOpenFileNames( SMESHGUI::desktop(),
+ anInitialPath,
+ filter,
+ QObject::tr( "SMESH_IMPORT_MESH" ) );
+ if ( filenames.count() > 0 ) {
SUIT_OverrideCursor wc;
_PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
- try {
+ QStringList errors;
+ bool isEmpty = false;
+ for ( QStringList::ConstIterator it = filenames.begin(); it != filenames.end(); ++it ) {
+ QString filename = *it;
SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
- switch ( theCommandID ) {
- case 112:
- {
- aMeshes->length( 1 );
- aMeshes[0] = theComponentMesh->CreateMeshesFromUNV(filename.latin1());
- break;
- }
- case 113:
- {
- SMESH::DriverMED_ReadStatus res;
- aMeshes = theComponentMesh->CreateMeshesFromMED(filename.latin1(),res);
- if ( res != SMESH::DRS_OK ) {
- wc.suspend();
- SUIT_MessageBox::warn1(SMESHGUI::desktop(),
- QObject::tr("SMESH_WRN_WARNING"),
- QObject::tr(QString("SMESH_DRS_%1").arg(res)),
- QObject::tr("SMESH_BUT_OK"));
- aMeshes->length( 0 );
- wc.resume();
+ try {
+ switch ( theCommandID ) {
+ case 111:
+ {
+ // DAT format (currently unsupported)
+ errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
+ arg( QObject::tr( "SMESH_ERR_NOT_SUPPORTED_FORMAT" ) ) );
+ break;
+ }
+ case 112:
+ {
+ // UNV format
+ aMeshes->length( 1 );
+ aMeshes[0] = theComponentMesh->CreateMeshesFromUNV( filename.latin1() );
+ if ( aMeshes[0]->_is_nil() )
+ errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
+ arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
+ break;
+ }
+ case 113:
+ {
+ // MED format
+ SMESH::DriverMED_ReadStatus res;
+ aMeshes = theComponentMesh->CreateMeshesFromMED( filename.latin1(), res );
+ if ( res != SMESH::DRS_OK ) {
+ errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
+ arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ) ) ) );
+ }
+ break;
}
- break;
}
}
+ catch ( const SALOME::SALOME_Exception& S_ex ) {
+ errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
+ arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
+ }
- bool isEmpty = false;
for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ ) {
_PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
if ( aMeshSO ) {
_PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
_PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
- aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_IMPORTED");
+ aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
if ( theCommandID == 112 ) // mesh names aren't taken from the file for UNV import
SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() );
- } else
+ }
+ else {
isEmpty = true;
+ }
}
+ }
- if ( isEmpty ) {
- wc.suspend();
- SUIT_MessageBox::warn1(SMESHGUI::desktop(),
- QObject::tr("SMESH_WRN_WARNING"),
- QObject::tr("SMESH_DRS_EMPTY"),
- QObject::tr("SMESH_BUT_OK"));
- wc.resume();
- }
-
- SMESHGUI::GetSMESHGUI()->updateObjBrowser();
+ // update Object browser
+ SMESHGUI::GetSMESHGUI()->updateObjBrowser();
+
+ // show Error message box if there were errors
+ if ( errors.count() > 0 ) {
+ SUIT_MessageBox::error1( SMESHGUI::desktop(),
+ QObject::tr( "SMESH_ERROR" ),
+ QObject::tr( "SMESH_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ),
+ QObject::tr( "SMESH_BUT_OK" ) );
}
- catch (const SALOME::SALOME_Exception& S_ex){
- wc.suspend();
- SalomeApp_Tools::QtCatchCorbaException(S_ex);
- wc.resume();
+
+ // show warning message box, if some imported mesh is empty
+ if ( isEmpty ) {
+ SUIT_MessageBox::warn1( SMESHGUI::desktop(),
+ QObject::tr( "SMESH_WRN_WARNING" ),
+ QObject::tr( "SMESH_DRS_SOME_EMPTY" ),
+ QObject::tr( "SMESH_BUT_OK" ) );
}
}
}
-
void ExportMeshToFile( int theCommandID )
{
LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
return;
}
// PAL18696
- QString v21( aMesh->GetVersionString( SMESH::MED_V2_1, 2));
- QString v22( aMesh->GetVersionString( SMESH::MED_V2_2, 2));
+ QString v21 (aMesh->GetVersionString(SMESH::MED_V2_1, 2));
+ QString v22 (aMesh->GetVersionString(SMESH::MED_V2_2, 2));
aFilterMap.insert( QString("MED ") + v21 + " (*.med)", SMESH::MED_V2_1 );
aFilterMap.insert( QString("MED ") + v22 + " (*.med)", SMESH::MED_V2_2 );
}
if ( resMgr )
toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
- if ( theCommandID != 122 && theCommandID != 125 && theCommandID != 140 && theCommandID != 141)
-
- aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), "", aFilter, aTitle, false);
+ QString anInitialPath = "";
+ if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
+ anInitialPath = QDir::currentDirPath();
+ if ( theCommandID != 122 && theCommandID != 125 && theCommandID != 140 && theCommandID != 141)
+ aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), anInitialPath + QString("/") + anIObject->getName(),
+ aFilter, aTitle, false);
else if(theCommandID == 140 || theCommandID == 141) { // Export to STL
QStringList filters;
QMap<QString, int>::const_iterator it = aFilterMapSTL.begin();
fd->setCaption( aTitle );
fd->setFilters( filters );
fd->setSelectedFilter( QObject::tr("STL ASCII (*.stl)") );
+ if ( !anInitialPath.isEmpty() )
+ fd->setDir( anInitialPath );
+ fd->setSelection(anIObject->getName());
bool is_ok = false;
while (!is_ok) {
fd->exec();
}
delete fd;
}
- else {
+ else { // Export to MED
QStringList filters;
+ QString aDefaultFilter;
QMap<QString, SMESH::MED_VERSION>::const_iterator it = aFilterMap.begin();
- for ( ; it != aFilterMap.end(); ++it )
+ for ( ; it != aFilterMap.end(); ++it ) {
filters.push_back( it.key() );
+ if (it.data() == SMESH::MED_V2_2)
+ aDefaultFilter = it.key();
+ }
//SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
( SMESHGUI::desktop(), false, QObject::tr("SMESH_AUTO_GROUPS") ,true, true );
fd->setCaption( aTitle );
fd->setFilters( filters );
- fd->setSelectedFilter( QObject::tr("MED 2.2 (*.med)") );
+ //fd->setSelectedFilter( QObject::tr("MED 2.2 (*.med)") );
+ fd->setSelectedFilter(aDefaultFilter);
fd->SetChecked(toCreateGroups);
+ if ( !anInitialPath.isEmpty() )
+ fd->setDir( anInitialPath );
+ fd->setSelection(anIObject->getName());
bool is_ok = false;
while (!is_ok) {
fd->exec();
LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
SALOME_ListIO selected; aSel->selectedObjects( selected, QString::null, false );
+ _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+ _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
+ _PTR(GenericAttribute) anAttr;
+ _PTR(AttributeIOR) anIOR;
+
+ int objectCount = 0;
QString aParentComponent = QString::null;
for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
{
+ _PTR(SObject) aSO = aStudy->FindObjectID(anIt.Value()->getEntry());
+ if (aSO) {
+ // check if object is not reference
+ _PTR(SObject) refobj;
+ if ( !aSO->ReferencedObject( refobj ) )
+ objectCount++;
+ }
+
QString cur = anIt.Value()->getComponentDataType();
if( aParentComponent.isNull() )
aParentComponent = cur;
aParentComponent = "";
}
+ if ( objectCount == 0 )
+ return; // No Valid Objects Selected
+
if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() ) {
SUIT_MessageBox::warn1 ( SMESHGUI::desktop(),
QObject::tr("ERR_ERROR"),
SUIT_ViewManager* vm = anApp->activeViewManager();
int nbSf = vm->getViewsCount();
- _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
- _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
- _PTR(GenericAttribute) anAttr;
- _PTR(AttributeIOR) anIOR;
-
SALOME_ListIteratorOfListIO It(selected);
aStudyBuilder->NewCommand(); // There is a transaction
continue;
}
+ _PTR(SObject) refobj;
+ if ( aSO && aSO->ReferencedObject( refobj ) )
+ continue; // skip references
+
// put the whole hierarchy of sub-objects of the selected SO into a list and
// then treat them all starting from the deepest objects (at list back)
break;
}
+ case 150: //MED FILE INFORMATION
+ {
+ SALOME_ListIO selected;
+ LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
+ if( aSel )
+ aSel->selectedObjects( selected );
+ if( selected.Extent() )
+ {
+ Handle(SALOME_InteractiveObject) anIObject = selected.First();
+ SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
+ if ( !aMesh->_is_nil() )
+ {
+ SMESHGUI_FileInfoDlg dlg( desktop(), aMesh->GetMEDFileInfo() );
+ dlg.exec();
+ }
+ }
+ break;
+ }
case 122: // EXPORT MED
case 121:
case 123:
new SMESHGUI_BuildCompoundDlg( this );
}
break;
+
case 407: // DIAGONAL INVERSION
case 408: // Delete diagonal
{
if( aSel )
aSel->selectedObjects( selected );
+ bool isAny = false; // iss there any appropriate object selected
+
SALOME_ListIteratorOfListIO It( selected );
for ( ; It.More(); It.Next() )
{
{
aName = anAttr;
QString newName = QString(aName->Value().c_str());
- newName = LightApp_NameDlg::getName(desktop(), newName);
- if ( !newName.isEmpty() )
- {
- //old source: aStudy->renameIObject( IObject, newName );
- aName->SetValue( newName.latin1() );
-
- // if current object is group update group's name
- SMESH::SMESH_GroupBase_var aGroup =
- SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
- if (!aGroup->_is_nil() )
- aGroup->SetName( newName.latin1() );
- updateObjBrowser();
+ // check type to prevent renaming of inappropriate objects
+ int aType = SMESHGUI_Selection::type(IObject->getEntry(), aStudy);
+ if (aType == MESH || aType == GROUP ||
+ aType == SUBMESH || aType == SUBMESH_COMPOUND ||
+ aType == SUBMESH_SOLID || aType == SUBMESH_FACE ||
+ aType == SUBMESH_EDGE || aType == SUBMESH_VERTEX ||
+ aType == HYPOTHESIS || aType == ALGORITHM)
+ {
+ isAny = true;
+ newName = LightApp_NameDlg::getName(desktop(), newName);
+ if ( !newName.isEmpty() )
+ {
+ //old source: aStudy->renameIObject( IObject, newName );
+ aName->SetValue( newName.latin1() );
+
+ // if current object is group update group's name
+ SMESH::SMESH_GroupBase_var aGroup =
+ SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
+ if (!aGroup->_is_nil() )
+ aGroup->SetName( newName.latin1() );
+
+ updateObjBrowser();
+ }
}
}
}
+ } // for
+
+ if (!isAny) {
+ SUIT_MessageBox::warn1(desktop(),
+ QObject::tr("SMESH_WRN_WARNING"),
+ QObject::tr("SMESH_WRN_NO_APPROPRIATE_SELECTION"),
+ QObject::tr("SMESH_BUT_OK"));
}
break;
}
}
break;
}
+ case 4043: { // CLEAR_MESH
+
+ if(checkLock(aStudy)) break;
+
+ SALOME_ListIO selected;
+ if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
+ aSel->selectedObjects( selected );
+
+ SUIT_OverrideCursor wc;
+ SALOME_ListIteratorOfListIO It (selected);
+ for ( ; It.More(); It.Next() )
+ {
+ Handle(SALOME_InteractiveObject) IOS = It.Value();
+ SMESH::SMESH_Mesh_var aMesh =
+ SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IOS);
+ if ( aMesh->_is_nil()) continue;
+ try {
+ SMESH::UpdateView(SMESH::eErase, IOS->getEntry());
+ aMesh->Clear();
+ _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
+ SMESH::ModifiedMesh( aMeshSObj, false, true);
+ // hide groups and submeshes
+ _PTR(ChildIterator) anIter =
+ SMESH::GetActiveStudyDocument()->NewChildIterator( aMeshSObj );
+ for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
+ {
+ _PTR(SObject) so = anIter->Value();
+ SMESH::UpdateView(SMESH::eErase, so->GetID().c_str());
+ }
+ }
+ catch (const SALOME::SALOME_Exception& S_ex){
+ wc.suspend();
+ SalomeApp_Tools::QtCatchCorbaException(S_ex);
+ wc.resume();
+ }
+ }
+ SMESH::UpdateView();
+ updateObjBrowser();
+ break;
+ }
case 4051: // RENUMBERING NODES
{
if(checkLock(aStudy)) break;
createSMESHAction( 125, "EXPORT_MED" );
createSMESHAction( 126, "EXPORT_UNV" );
createSMESHAction( 141, "EXPORT_STL" );
+ createSMESHAction( 150, "FILE_INFO" );
createSMESHAction( 33, "DELETE", "ICON_DELETE", Key_Delete );
createSMESHAction( 5105, "SEL_FILTER_LIB" );
createSMESHAction( 701, "COMPUTE", "ICON_COMPUTE" );
createSMESHAction( 4032, "HEXA", "ICON_DLG_HEXAS" );
createSMESHAction( 4041, "REMOVE_NODES", "ICON_DLG_REM_NODE" );
createSMESHAction( 4042, "REMOVE_ELEMENTS", "ICON_DLG_REM_ELEMENT" );
+ createSMESHAction( 4043, "CLEAR_MESH" , "ICON_CLEAR_MESH" );
createSMESHAction( 4051, "RENUM_NODES", "ICON_DLG_RENUMBERING_NODES" );
createSMESHAction( 4052, "RENUM_ELEMENTS", "ICON_DLG_RENUMBERING_ELEMENTS" );
createSMESHAction( 4061, "TRANS", "ICON_SMESH_TRANSLATION_VECTOR" );
createMenu( 5105, toolsId, -1 );
- createMenu( 702, meshId, -1 );
+ createMenu( 702, meshId, -1 ); // "Mesh" menu
createMenu( 703, meshId, -1 );
createMenu( 704, meshId, -1 );
createMenu( 710, meshId, -1 );
createMenu( 4041, removeId, -1 );
createMenu( 4042, removeId, -1 );
+ createMenu( 4043, removeId, -1 );
createMenu( 4051, renumId, -1 );
createMenu( 4052, renumId, -1 );
createTool( separator(), addRemTb );
createTool( 4041, addRemTb );
createTool( 4042, addRemTb );
+ createTool( 4043, addRemTb );
createTool( separator(), addRemTb );
createTool( 4051, addRemTb );
createTool( 4052, addRemTb );
// popup for object browser
+ createPopupItem( 150, OB, mesh, "&& selcount=1 && isImported" ); // FILE INFORMATION
+
createPopupItem( 704, OB, mesh, "&& isComputable"); // EDIT_MESHSUBMESH
createPopupItem( 704, OB, subMesh, "&& isComputable" ); // EDIT_MESHSUBMESH
createPopupItem( 803, OB, group ); // EDIT_GROUP
createPopupItem( 801, OB, mesh ); // CREATE_GROUP
createPopupItem( 802, OB, subMesh ); // CONSTRUCT_GROUP
popupMgr()->insert( separator(), -1, 0 );
- createPopupItem( 1100, OB, hypo, "" /*"&& $hasReference={false}"*/ ); // EDIT HYPOTHESIS
+ createPopupItem( 1100, OB, hypo); // EDIT HYPOTHESIS
createPopupItem( 1102, OB, hyp_alg ); // REMOVE HYPOTHESIS / ALGORITHMS
- createPopupItem( 1101, OB, mesh_group + " " + hyp_alg, "" /*"&& $hasReference={false}"*/ ); // RENAME
+ createPopupItem( 1101, OB, mesh_group + " " + hyp_alg ); // RENAME
+ popupMgr()->insert( separator(), -1, 0 );
+ createPopupItem( 4043, OB, mesh ); // CLEAR_MESH
popupMgr()->insert( separator(), -1, 0 );
- QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
+ QString nbSelected = QtxPopupMgr::Selection::defSelCountParam();
+ QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( nbSelected );
+
createPopupItem( 125, OB, mesh, only_one_non_empty ); // EXPORT_MED
createPopupItem( 126, OB, mesh, only_one_non_empty ); // EXPORT_UNV
createPopupItem( 141, OB, mesh, only_one_non_empty ); // EXPORT_STL
action(112)->setAccel(QKeySequence(CTRL + Key_U)); // Import UNV
action(113)->setAccel(QKeySequence(CTRL + Key_M)); // Import MED
+ action( 33)->setEnabled(true); // Delete: Key_Delete
+ action(1101)->setEnabled(true); // Rename: Key_F2
+
return res;
}
action(112)->setAccel(QKeySequence()); // Import UNV
action(113)->setAccel(QKeySequence()); // Import MED
+ action( 33)->setEnabled(false); // Delete: Key_Delete
+ action(1101)->setEnabled(false); // Rename: Key_F2
+
return SalomeApp_Module::deactivateModule( study );
}
return QString( anIOR.in() );
}
-void SMESHGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& /*title*/ )
+void SMESHGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& title )
{
SMESHGUI_Selection sel;
sel.init( client, selectionMgr() );
popupMgr()->updatePopup( menu, &sel );
+
+ SALOME_ListIO lst;
+ selectionMgr()->selectedObjects( lst );
+ if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
+ Handle(SALOME_InteractiveObject) io = lst.First();
+ SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
+ _PTR(Study) study = appStudy->studyDS();
+ _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
+ if ( obj ) {
+ QString aName = QString( obj->GetName().c_str() );
+ while ( aName.at( aName.length() - 1 ) == ' ' ) // Remove extraspaces in Name of Popup
+ aName.remove( (aName.length() - 1), 1 );
+ title = aName;
+ }
+ }
}
void SMESHGUI::windows( QMap<int, int>& aMap ) const