From 2633d63b9b2b3fb61ae801d6078d7f7ad5b13971 Mon Sep 17 00:00:00 2001 From: jfa Date: Mon, 1 Aug 2005 11:56:51 +0000 Subject: [PATCH] Provide tables exporting for V3.0.X --- src/VISUGUI/VISU_msg_en.po | 9 +++- src/VISUGUI/VisuGUI.cxx | 98 +++++++++++++++++++++++++++++++++++++- 2 files changed, 104 insertions(+), 3 deletions(-) diff --git a/src/VISUGUI/VISU_msg_en.po b/src/VISUGUI/VISU_msg_en.po index 627949ea..41f32151 100644 --- a/src/VISUGUI/VISU_msg_en.po +++ b/src/VISUGUI/VISU_msg_en.po @@ -39,6 +39,11 @@ msgstr "Failed to activate MED engine!" msgid "ERR_CANT_BUILD_PRESENTATION" msgstr "The object can't be built" +msgid "ERR_CANT_CREATE_ACTOR" +msgstr "Can't create actor for this presentation" + +# Preferences for VISU module (VisuGUI.cxx) + msgid "VISU_SCALAR_BAR" msgstr "Scalar Bar" @@ -351,8 +356,8 @@ msgstr "Arrange Actors" msgid "VisuGUI::ERR_ERROR_IN_THE_FILE" msgstr "Error in the file" -msgid "ERR_CANT_CREATE_ACTOR" -msgstr "Can't create actor for this presentation" +msgid "VisuGUI::ERR_ERROR_DURING_EXPORT" +msgstr "Error has been occured during exporting to file" msgid "VisuGUI::ERR_ACTIVATE_VIEW3D" msgstr "Please activate 3D view before" diff --git a/src/VISUGUI/VisuGUI.cxx b/src/VISUGUI/VisuGUI.cxx index d2c810d2..5b874110 100644 --- a/src/VISUGUI/VisuGUI.cxx +++ b/src/VISUGUI/VisuGUI.cxx @@ -277,6 +277,102 @@ VisuGUI:: OnExportTableToFile() { if(MYDEBUG) MESSAGE("VisuGUI::OnExportTableToFile()"); + + _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this)); + + SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this); + SALOME_ListIO aListIO; + aSelectionMgr->selectedObjects(aListIO); + + if (aListIO.Extent() > 0) { + const Handle(SALOME_InteractiveObject)& anIO = aListIO.First(); + if (anIO->hasEntry()) { + _PTR(SObject) aSObj = aCStudy->FindObjectID(anIO->getEntry()); + if (!aSObj) return; + + // find table attribute + bool isTOR = true; + _PTR(GenericAttribute) anAttr; + + if (!aSObj->FindAttribute(anAttr, "AttributeTableOfReal")) { + isTOR = false; + if (!aSObj->FindAttribute(anAttr, "AttributeTableOfInteger")) { + // if the current SObject is a table title + // we take a father contaning the table + aSObj = aSObj->GetFather(); + + if (aSObj->FindAttribute(anAttr, "AttributeTableOfReal")) { + isTOR = true; + } else { + if (!aSObj->FindAttribute(anAttr, "AttributeTableOfInteger")) { + return; + } + } + } + } + + // get table title in order to have default name of the file + QString aTitle; + if (isTOR) { + _PTR(AttributeTableOfReal) aTabAttr (anAttr); + if (!aTabAttr) return; + aTitle = aTabAttr->GetTitle(); + } else { + _PTR(AttributeTableOfInteger) aTabAttr (anAttr); + if (!aTabAttr) return; + aTitle = aTabAttr->GetTitle(); + } + aTitle.simplifyWhiteSpace(); + aTitle = aTitle.replace(QRegExp(" "), "_"); + + // get default path for the file + SUIT_ResourceMgr* aResourceMgr = GetResourceMgr(); + QString aDir = aResourceMgr->stringValue("VISU","OutputDir",""); + if (aDir.isEmpty()) { + aDir = aResourceMgr->stringValue("VISU","InputDir",""); + if (aDir.isEmpty()) { + aDir = getenv("CSF_PATHData"); + } + } + QString aPath = Qtx::addSlash(aDir) + aTitle; + + // get name for the file + QStringList aFilter; + aFilter.append("Table Files (*.xls)"); + + QFileInfo aFileInfo = + SUIT_FileDlg::getFileName(GetDesktop(this), + aPath, + aFilter, + tr("MEN_EXPORT_TABLE"), // "Export Table To File" + false); + + // export + QString aFile = aFileInfo.filePath(); + if (!aFile.isEmpty()) { + application()->putInfo(tr("MEN_EXPORT_TABLE") + " " + aFile + " ..."); + aDir = Qtx::dir(aFile, true); + aResourceMgr->setValue("VISU", "OutputDir", aDir); + + try { + GetVisuGen(this)->ExportTableToFile(GetSObject(aSObj), aFile.latin1()); + application()->putInfo(aFile + " " + tr("INF_DONE")); + } catch(std::exception& ex) { + INFOS(ex.what()); + SUIT_MessageBox::warn1(GetDesktop(this), + tr("WRN_VISU"), + tr("ERR_ERROR_DURING_EXPORT") + " " + tr(ex.what()), + tr("BUT_OK")); + } catch(...) { + INFOS(tr("ERR_ERROR_DURING_EXPORT")); + SUIT_MessageBox::warn1(GetDesktop(this), + tr("WRN_VISU"), + tr("ERR_ERROR_DURING_EXPORT"), + tr("BUT_OK") ); + } + } + } + } } void @@ -431,7 +527,7 @@ CreatePrs3d(SalomeApp_Module* theModule, QApplication::restoreOverrideCursor(); if(aPrs3d){ SUIT_ResourceMgr* aResourceMgr = GetResourceMgr(); - int aValue = aResourceMgr->integerValue("Visu:BuildDefaultPrs3d",0); + int aValue = aResourceMgr->integerValue("VISU","BuildDefaultPrs3d",0); if(!aValue){ if(TDlg* aDlg = new TDlg(theModule)){ // dialog box in creation mode aDlg->initFromPrsObject(aPrs3d); -- 2.39.2