diff --git a/ApplicationCode/Application/RiaApplication.cpp b/ApplicationCode/Application/RiaApplication.cpp index 87591ea4a5..c08fc6ce1b 100644 --- a/ApplicationCode/Application/RiaApplication.cpp +++ b/ApplicationCode/Application/RiaApplication.cpp @@ -90,7 +90,8 @@ #include "RiuFlowCharacteristicsPlot.h" #include "RicImportSummaryCaseFeature.h" -#include "ExportCommands/RicSnapshotViewToClipboardFeature.h" +#include "ExportCommands/RicSnapshotViewToFileFeature.h" +#include "ExportCommands/RicSnapshotAllPlotsToFileFeature.h" #include "SummaryPlotCommands/RicNewSummaryPlotFeature.h" #include "RicfCommandFileExecutor.h" @@ -2183,6 +2184,7 @@ void RiaApplication::waitForProcess() const #else usleep(100000); #endif + processEvents(); } } diff --git a/ApplicationCode/CommandFileInterface/RicfComputeCaseGroupStatistics.cpp b/ApplicationCode/CommandFileInterface/RicfComputeCaseGroupStatistics.cpp index 18846c28f3..7754c52a89 100644 --- a/ApplicationCode/CommandFileInterface/RicfComputeCaseGroupStatistics.cpp +++ b/ApplicationCode/CommandFileInterface/RicfComputeCaseGroupStatistics.cpp @@ -37,7 +37,7 @@ CAF_PDM_SOURCE_INIT(RicfComputeCaseGroupStatistics, "computeCaseGroupStatistics" //-------------------------------------------------------------------------------------------------- RicfComputeCaseGroupStatistics::RicfComputeCaseGroupStatistics() { - RICF_InitField(&m_caseIds, "cases", std::vector(), "Case IDs", "", "", ""); + RICF_InitField(&m_caseIds, "caseIds", std::vector(), "Case IDs", "", "", ""); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/CommandFileInterface/RicfExportMsw.cpp b/ApplicationCode/CommandFileInterface/RicfExportMsw.cpp index 22b4ad9821..1c6489ebce 100644 --- a/ApplicationCode/CommandFileInterface/RicfExportMsw.cpp +++ b/ApplicationCode/CommandFileInterface/RicfExportMsw.cpp @@ -41,8 +41,8 @@ CAF_PDM_SOURCE_INIT(RicfExportMsw, "exportMsw"); //-------------------------------------------------------------------------------------------------- RicfExportMsw::RicfExportMsw() { - RICF_InitField(&m_caseId, "case", -1, "Case", "", "", ""); - RICF_InitField(&m_wellPathName, "wellPath", QString(), "Case", "", "", ""); + RICF_InitField(&m_caseId, "caseId", -1, "Case ID", "", "", ""); + RICF_InitField(&m_wellPathName, "wellPath", QString(), "Well Path Name", "", "", ""); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/CommandFileInterface/RicfExportProperty.cpp b/ApplicationCode/CommandFileInterface/RicfExportProperty.cpp index c5dc56fe20..03409eccae 100644 --- a/ApplicationCode/CommandFileInterface/RicfExportProperty.cpp +++ b/ApplicationCode/CommandFileInterface/RicfExportProperty.cpp @@ -41,7 +41,7 @@ CAF_PDM_SOURCE_INIT(RicfExportProperty, "exportProperty"); //-------------------------------------------------------------------------------------------------- RicfExportProperty::RicfExportProperty() { - RICF_InitField(&m_caseId, "case", -1, "Case", "", "", ""); + RICF_InitField(&m_caseId, "caseId", -1, "Case ID", "", "", ""); RICF_InitField(&m_timeStepIndex, "timeStep", -1, "Time Step Index", "", "", ""); RICF_InitField(&m_propertyName, "property", QString(), "Property Name", "", "", ""); RICF_InitField(&m_eclipseKeyword, "eclipseKeyword", QString(), "Eclipse Keyword", "", "", ""); diff --git a/ApplicationCode/CommandFileInterface/RicfExportSnapshots.cpp b/ApplicationCode/CommandFileInterface/RicfExportSnapshots.cpp index 3dfe25537e..bd363d0b11 100644 --- a/ApplicationCode/CommandFileInterface/RicfExportSnapshots.cpp +++ b/ApplicationCode/CommandFileInterface/RicfExportSnapshots.cpp @@ -20,7 +20,7 @@ #include "RicfCommandFileExecutor.h" -#include "ExportCommands/RicSnapshotViewToClipboardFeature.h" +#include "ExportCommands/RicSnapshotAllPlotsToFileFeature.h" #include "RiaApplication.h" @@ -46,7 +46,7 @@ namespace caf { //-------------------------------------------------------------------------------------------------- RicfExportSnapshots::RicfExportSnapshots() { - RICF_InitField(&m_type, "type", RicfExportSnapshots::SnapshotsTypeEnum(), "Type", "", "", ""); + RICF_InitField(&m_type, "type", RicfExportSnapshots::SnapshotsTypeEnum(), "Type", "", "", ""); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/CommandFileInterface/RicfExportWellPathCompletions.cpp b/ApplicationCode/CommandFileInterface/RicfExportWellPathCompletions.cpp index 4f195cb836..6d99c5d52f 100644 --- a/ApplicationCode/CommandFileInterface/RicfExportWellPathCompletions.cpp +++ b/ApplicationCode/CommandFileInterface/RicfExportWellPathCompletions.cpp @@ -39,7 +39,7 @@ CAF_PDM_SOURCE_INIT(RicfExportWellPathCompletions, "exportWellPathCompletions"); //-------------------------------------------------------------------------------------------------- RicfExportWellPathCompletions::RicfExportWellPathCompletions() { - RICF_InitField(&m_caseId, "case", -1, "Case ID", "", "", ""); + RICF_InitField(&m_caseId, "caseId", -1, "Case ID", "", "", ""); RICF_InitField(&m_timeStep, "timeStep", -1, "Time Step Index", "", "", ""); RICF_InitField(&m_wellPathNames, "wellPathNames", std::vector(), "Well Path Names", "", "", ""); RICF_InitField(&m_wellSelection, "wellSelection", RicExportCompletionDataSettingsUi::WellSelectionType(), "Well Selection", "", "", ""); diff --git a/ApplicationCode/CommandFileInterface/RicfReplaceCase.cpp b/ApplicationCode/CommandFileInterface/RicfReplaceCase.cpp index 2ea04ee8d4..669e41d3fd 100644 --- a/ApplicationCode/CommandFileInterface/RicfReplaceCase.cpp +++ b/ApplicationCode/CommandFileInterface/RicfReplaceCase.cpp @@ -31,7 +31,7 @@ CAF_PDM_SOURCE_INIT(RicfReplaceCase, "replaceCase"); //-------------------------------------------------------------------------------------------------- RicfReplaceCase::RicfReplaceCase() { - RICF_InitField(&m_caseId, "case", -1, "Case ID", "", "", ""); + RICF_InitField(&m_caseId, "caseId", -1, "Case ID", "", "", ""); RICF_InitField(&m_newGridFile, "newGridFile", QString(), "New Grid File", "", "", ""); } diff --git a/ApplicationCode/CommandFileInterface/RicfReplaceSourceCases.cpp b/ApplicationCode/CommandFileInterface/RicfReplaceSourceCases.cpp index 10463d2863..caa8ddd240 100644 --- a/ApplicationCode/CommandFileInterface/RicfReplaceSourceCases.cpp +++ b/ApplicationCode/CommandFileInterface/RicfReplaceSourceCases.cpp @@ -31,7 +31,7 @@ CAF_PDM_SOURCE_INIT(RicfReplaceSourceCases, "replaceSourceCases"); //-------------------------------------------------------------------------------------------------- RicfReplaceSourceCases::RicfReplaceSourceCases() { - RICF_InitField(&m_caseGroupId, "group", -1, "Group ID", "", "", ""); + RICF_InitField(&m_caseGroupId, "caseGroupId", -1, "Case Group ID", "", "", ""); RICF_InitField(&m_gridListFile, "gridListFile", QString(), "Grid List File", "", "", ""); } diff --git a/ApplicationCode/CommandFileInterface/RicfRunOctaveScript.cpp b/ApplicationCode/CommandFileInterface/RicfRunOctaveScript.cpp index 83c2d9389c..3b88f4e76a 100644 --- a/ApplicationCode/CommandFileInterface/RicfRunOctaveScript.cpp +++ b/ApplicationCode/CommandFileInterface/RicfRunOctaveScript.cpp @@ -31,8 +31,8 @@ CAF_PDM_SOURCE_INIT(RicfRunOctaveScript, "runOctaveScript"); //-------------------------------------------------------------------------------------------------- RicfRunOctaveScript::RicfRunOctaveScript() { - RICF_InitField(&m_path, "path", QString(), "Path", "", "", ""); - RICF_InitField(&m_caseIds, "cases", std::vector(), "Case IDs", "", "", ""); + RICF_InitField(&m_path, "path", QString(), "Path", "", "", ""); + RICF_InitField(&m_caseIds, "caseIds", std::vector(), "Case IDs", "", "", ""); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/CommandFileInterface/RicfSetTimeStep.cpp b/ApplicationCode/CommandFileInterface/RicfSetTimeStep.cpp index f487b37352..12b5434bd5 100644 --- a/ApplicationCode/CommandFileInterface/RicfSetTimeStep.cpp +++ b/ApplicationCode/CommandFileInterface/RicfSetTimeStep.cpp @@ -34,7 +34,7 @@ CAF_PDM_SOURCE_INIT(RicfSetTimeStep, "setTimeStep"); //-------------------------------------------------------------------------------------------------- RicfSetTimeStep::RicfSetTimeStep() { - RICF_InitField(&m_caseId, "case", -1, "Case ID", "", "", ""); + RICF_InitField(&m_caseId, "caseId", -1, "Case ID", "", "", ""); RICF_InitField(&m_timeStepIndex, "timeStep", -1, "Time Step Index", "", "", ""); } diff --git a/ApplicationCode/Commands/ExportCommands/CMakeLists_files.cmake b/ApplicationCode/Commands/ExportCommands/CMakeLists_files.cmake index e21334253f..70dd562b89 100644 --- a/ApplicationCode/Commands/ExportCommands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/ExportCommands/CMakeLists_files.cmake @@ -5,31 +5,35 @@ if (${CMAKE_VERSION} VERSION_GREATER "2.8.2") endif() set (SOURCE_GROUP_HEADER_FILES +${CEE_CURRENT_LIST_DIR}RicCellRangeUi.h ${CEE_CURRENT_LIST_DIR}RicExportCarfin.h ${CEE_CURRENT_LIST_DIR}RicExportCarfinUi.h -${CEE_CURRENT_LIST_DIR}RicExportToLasFileFeature.h -${CEE_CURRENT_LIST_DIR}RicExportToLasFileResampleUi.h -${CEE_CURRENT_LIST_DIR}RicSnapshotViewToClipboardFeature.h ${CEE_CURRENT_LIST_DIR}RicExportFaultsFeature.h ${CEE_CURRENT_LIST_DIR}RicExportMultipleSnapshotsFeature.h +${CEE_CURRENT_LIST_DIR}RicExportToLasFileFeature.h +${CEE_CURRENT_LIST_DIR}RicExportToLasFileResampleUi.h ${CEE_CURRENT_LIST_DIR}RicSaveEclipseInputPropertyFeature.h ${CEE_CURRENT_LIST_DIR}RicSaveEclipseResultAsInputPropertyExec.h ${CEE_CURRENT_LIST_DIR}RicSaveEclipseResultAsInputPropertyFeature.h -${CEE_CURRENT_LIST_DIR}RicCellRangeUi.h +${CEE_CURRENT_LIST_DIR}RicSnapshotAllPlotsToFileFeature.h +${CEE_CURRENT_LIST_DIR}RicSnapshotViewToClipboardFeature.h +${CEE_CURRENT_LIST_DIR}RicSnapshotViewToFileFeature.h ) set (SOURCE_GROUP_SOURCE_FILES +${CEE_CURRENT_LIST_DIR}RicCellRangeUi.cpp ${CEE_CURRENT_LIST_DIR}RicExportCarfin.cpp ${CEE_CURRENT_LIST_DIR}RicExportCarfinUi.cpp -${CEE_CURRENT_LIST_DIR}RicExportToLasFileFeature.cpp -${CEE_CURRENT_LIST_DIR}RicExportToLasFileResampleUi.cpp -${CEE_CURRENT_LIST_DIR}RicSnapshotViewToClipboardFeature.cpp ${CEE_CURRENT_LIST_DIR}RicExportFaultsFeature.cpp ${CEE_CURRENT_LIST_DIR}RicExportMultipleSnapshotsFeature.cpp +${CEE_CURRENT_LIST_DIR}RicExportToLasFileFeature.cpp +${CEE_CURRENT_LIST_DIR}RicExportToLasFileResampleUi.cpp ${CEE_CURRENT_LIST_DIR}RicSaveEclipseInputPropertyFeature.cpp ${CEE_CURRENT_LIST_DIR}RicSaveEclipseResultAsInputPropertyExec.cpp ${CEE_CURRENT_LIST_DIR}RicSaveEclipseResultAsInputPropertyFeature.cpp -${CEE_CURRENT_LIST_DIR}RicCellRangeUi.cpp +${CEE_CURRENT_LIST_DIR}RicSnapshotAllPlotsToFileFeature.cpp +${CEE_CURRENT_LIST_DIR}RicSnapshotViewToClipboardFeature.cpp +${CEE_CURRENT_LIST_DIR}RicSnapshotViewToFileFeature.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/Commands/ExportCommands/RicExportMultipleSnapshotsFeature.cpp b/ApplicationCode/Commands/ExportCommands/RicExportMultipleSnapshotsFeature.cpp index 5d8c09df3a..ff579259d6 100644 --- a/ApplicationCode/Commands/ExportCommands/RicExportMultipleSnapshotsFeature.cpp +++ b/ApplicationCode/Commands/ExportCommands/RicExportMultipleSnapshotsFeature.cpp @@ -20,7 +20,7 @@ #include "RiaApplication.h" -#include "RicSnapshotViewToClipboardFeature.h" +#include "RicSnapshotViewToFileFeature.h" #include "RigFemResultPosEnum.h" diff --git a/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.cpp b/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.cpp new file mode 100644 index 0000000000..d6c0aa2ce2 --- /dev/null +++ b/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.cpp @@ -0,0 +1,152 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2016 Statoil ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight 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 General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RicSnapshotAllPlotsToFileFeature.h" + +#include "RiaApplication.h" +#include "RiaLogging.h" + +#include "RimMainPlotCollection.h" +#include "RimProject.h" +#include "RimViewWindow.h" + +#include "RicSnapshotViewToFileFeature.h" + +#include "RiuMainPlotWindow.h" + +#include "cafUtils.h" + +#include +#include +#include +#include +#include +#include +#include + + +CAF_CMD_SOURCE_INIT(RicSnapshotAllPlotsToFileFeature, "RicSnapshotAllPlotsToFileFeature"); + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicSnapshotAllPlotsToFileFeature::saveAllPlots() +{ + RiaApplication* app = RiaApplication::instance(); + + RiuMainPlotWindow* mainPlotWindow = app->mainPlotWindow(); + if (!mainPlotWindow) return; + + RimProject* proj = app->project(); + if (!proj) return; + + // Save images in snapshot catalog relative to project directory + QString snapshotFolderName = app->createAbsolutePathFromProjectRelativePath("snapshots"); + + exportSnapshotOfAllPlotsIntoFolder(snapshotFolderName); + + QString text = QString("Exported snapshots to folder : \n%1").arg(snapshotFolderName); + QMessageBox::information(nullptr, "Export Snapshots To Folder", text); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicSnapshotAllPlotsToFileFeature::exportSnapshotOfAllPlotsIntoFolder(QString snapshotFolderName) +{ + RiaApplication* app = RiaApplication::instance(); + + RimProject* proj = app->project(); + if (!proj) return; + + QDir snapshotPath(snapshotFolderName); + if (!snapshotPath.exists()) + { + if (!snapshotPath.mkpath(".")) return; + } + + const QString absSnapshotPath = snapshotPath.absolutePath(); + + std::vector viewWindows; + proj->mainPlotCollection()->descendantsIncludingThisOfType(viewWindows); + + for (auto viewWindow : viewWindows) + { + if (viewWindow->isMdiWindow() && viewWindow->viewWidget()) + { + QString fileName; + if ( viewWindow->userDescriptionField()) + { + fileName = viewWindow->userDescriptionField()->uiCapability()->uiValue().toString(); + } + else + { + fileName = viewWindow->uiCapability()->uiName(); + } + + fileName = caf::Utils::makeValidFileBasename(fileName); + + QString absoluteFileName = caf::Utils::constructFullFileName(absSnapshotPath, fileName, ".png"); + absoluteFileName.replace(" ", "_"); + + RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName, viewWindow); + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicSnapshotAllPlotsToFileFeature::isCommandEnabled() +{ + return true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicSnapshotAllPlotsToFileFeature::onActionTriggered(bool isChecked) +{ + QWidget* currentActiveWidget = nullptr; + if (RiaApplication::activeViewWindow()) + { + currentActiveWidget = RiaApplication::activeViewWindow()->viewWidget(); + } + + RicSnapshotAllPlotsToFileFeature::saveAllPlots(); + + if (currentActiveWidget) + { + RiuMainPlotWindow* mainPlotWindow = RiaApplication::instance()->mainPlotWindow(); + if (mainPlotWindow) + { + mainPlotWindow->setActiveViewer(currentActiveWidget); + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicSnapshotAllPlotsToFileFeature::setupActionLook(QAction* actionToSetup) +{ + actionToSetup->setText("Snapshot All Plots To File"); + actionToSetup->setIcon(QIcon(":/SnapShotSaveViews.png")); +} + diff --git a/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.h b/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.h new file mode 100644 index 0000000000..922fe3914b --- /dev/null +++ b/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.h @@ -0,0 +1,44 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2016 Statoil ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight 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 General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafCmdFeature.h" + +class RimViewWindow; + +//================================================================================================== +/// +//================================================================================================== +class RicSnapshotAllPlotsToFileFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +public: + static void saveAllPlots(); + + static void exportSnapshotOfAllPlotsIntoFolder(QString snapshotFolderName); + +protected: + // Overrides + virtual bool isCommandEnabled() override; + virtual void onActionTriggered(bool isChecked) override; + virtual void setupActionLook(QAction* actionToSetup) override; +}; + + diff --git a/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToClipboardFeature.cpp b/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToClipboardFeature.cpp index d884e8e9dd..bcccfbd273 100644 --- a/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToClipboardFeature.cpp +++ b/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToClipboardFeature.cpp @@ -78,206 +78,3 @@ void RicSnapshotViewToClipboardFeature::setupActionLook(QAction* actionToSetup) actionToSetup->setText("Snapshot To Clipboard"); actionToSetup->setIcon(QIcon(":/SnapShot.png")); } - - - - -CAF_CMD_SOURCE_INIT(RicSnapshotViewToFileFeature, "RicSnapshotViewToFileFeature"); - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicSnapshotViewToFileFeature::saveSnapshotAs(const QString& fileName, RimViewWindow* viewWindow) -{ - if (viewWindow) - { - QImage image = viewWindow->snapshotWindowContent(); - if (!image.isNull()) - { - if (image.save(fileName)) - { - qDebug() << "Exported snapshot image to " << fileName; - } - else - { - qDebug() << "Error when trying to export snapshot image to " << fileName; - } - } - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RicSnapshotViewToFileFeature::isCommandEnabled() -{ - return true; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicSnapshotViewToFileFeature::onActionTriggered(bool isChecked) -{ - RiaApplication* app = RiaApplication::instance(); - RimProject* proj = app->project(); - - // Get active view window before displaying the file selection dialog - // If this is done after the file save dialog is displayed (and closed) - // app->activeViewWindow() returns NULL on Linux - RimViewWindow* viewWindow = app->activeViewWindow(); - if (!viewWindow) - { - RiaLogging::error("No view window is available, nothing to do"); - - return; - } - - QString startPath; - if (!proj->fileName().isEmpty()) - { - QFileInfo fi(proj->fileName()); - startPath = fi.absolutePath(); - } - else - { - startPath = app->lastUsedDialogDirectory("IMAGE_SNAPSHOT"); - } - - startPath += "/image.png"; - - QString fileName = QFileDialog::getSaveFileName(NULL, tr("Export to File"), startPath); - if (fileName.isEmpty()) - { - return; - } - - // Remember the directory to next time - app->setLastUsedDialogDirectory("IMAGE_SNAPSHOT", QFileInfo(fileName).absolutePath()); - - RicSnapshotViewToFileFeature::saveSnapshotAs(fileName, viewWindow); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicSnapshotViewToFileFeature::setupActionLook(QAction* actionToSetup) -{ - actionToSetup->setText("Snapshot To File"); - actionToSetup->setIcon(QIcon(":/SnapShotSave.png")); -} - - - - - -CAF_CMD_SOURCE_INIT(RicSnapshotAllPlotsToFileFeature, "RicSnapshotAllPlotsToFileFeature"); - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicSnapshotAllPlotsToFileFeature::saveAllPlots() -{ - RiaApplication* app = RiaApplication::instance(); - - RiuMainPlotWindow* mainPlotWindow = app->mainPlotWindow(); - if (!mainPlotWindow) return; - - RimProject* proj = app->project(); - if (!proj) return; - - // Save images in snapshot catalog relative to project directory - QString snapshotFolderName = app->createAbsolutePathFromProjectRelativePath("snapshots"); - - exportSnapshotOfAllPlotsIntoFolder(snapshotFolderName); - - QString text = QString("Exported snapshots to folder : \n%1").arg(snapshotFolderName); - QMessageBox::information(nullptr, "Export Snapshots To Folder", text); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicSnapshotAllPlotsToFileFeature::exportSnapshotOfAllPlotsIntoFolder(QString snapshotFolderName) -{ - RiaApplication* app = RiaApplication::instance(); - - RimProject* proj = app->project(); - if (!proj) return; - - QDir snapshotPath(snapshotFolderName); - if (!snapshotPath.exists()) - { - if (!snapshotPath.mkpath(".")) return; - } - - const QString absSnapshotPath = snapshotPath.absolutePath(); - - std::vector viewWindows; - proj->mainPlotCollection()->descendantsIncludingThisOfType(viewWindows); - - for (auto viewWindow : viewWindows) - { - if (viewWindow->isMdiWindow() && viewWindow->viewWidget()) - { - QString fileName; - if ( viewWindow->userDescriptionField()) - { - fileName = viewWindow->userDescriptionField()->uiCapability()->uiValue().toString(); - } - else - { - fileName = viewWindow->uiCapability()->uiName(); - } - - fileName = caf::Utils::makeValidFileBasename(fileName); - - QString absoluteFileName = caf::Utils::constructFullFileName(absSnapshotPath, fileName, ".png"); - absoluteFileName.replace(" ", "_"); - - RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName, viewWindow); - } - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RicSnapshotAllPlotsToFileFeature::isCommandEnabled() -{ - return true; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicSnapshotAllPlotsToFileFeature::onActionTriggered(bool isChecked) -{ - QWidget* currentActiveWidget = nullptr; - if (RiaApplication::activeViewWindow()) - { - currentActiveWidget = RiaApplication::activeViewWindow()->viewWidget(); - } - - RicSnapshotAllPlotsToFileFeature::saveAllPlots(); - - if (currentActiveWidget) - { - RiuMainPlotWindow* mainPlotWindow = RiaApplication::instance()->mainPlotWindow(); - if (mainPlotWindow) - { - mainPlotWindow->setActiveViewer(currentActiveWidget); - } - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicSnapshotAllPlotsToFileFeature::setupActionLook(QAction* actionToSetup) -{ - actionToSetup->setText("Snapshot All Plots To File"); - actionToSetup->setIcon(QIcon(":/SnapShotSaveViews.png")); -} - diff --git a/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToClipboardFeature.h b/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToClipboardFeature.h index ede5e606fc..f07092a77e 100644 --- a/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToClipboardFeature.h +++ b/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToClipboardFeature.h @@ -37,42 +37,3 @@ protected: }; - -//================================================================================================== -/// -//================================================================================================== -class RicSnapshotViewToFileFeature : public caf::CmdFeature -{ - CAF_CMD_HEADER_INIT; - -public: - static void saveSnapshotAs(const QString& fileName, RimViewWindow* viewWindow); - -protected: - // Overrides - virtual bool isCommandEnabled() override; - virtual void onActionTriggered(bool isChecked) override; - virtual void setupActionLook(QAction* actionToSetup) override; -}; - - -//================================================================================================== -/// -//================================================================================================== -class RicSnapshotAllPlotsToFileFeature : public caf::CmdFeature -{ - CAF_CMD_HEADER_INIT; - -public: - static void saveAllPlots(); - - static void exportSnapshotOfAllPlotsIntoFolder(QString snapshotFolderName); - -protected: - // Overrides - virtual bool isCommandEnabled() override; - virtual void onActionTriggered(bool isChecked) override; - virtual void setupActionLook(QAction* actionToSetup) override; -}; - - diff --git a/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.cpp b/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.cpp new file mode 100644 index 0000000000..24a0ca6991 --- /dev/null +++ b/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.cpp @@ -0,0 +1,123 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2016 Statoil ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight 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 General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RicSnapshotViewToFileFeature.h" + +#include "RiaApplication.h" +#include "RiaLogging.h" + +#include "RimMainPlotCollection.h" +#include "RimProject.h" +#include "RimViewWindow.h" +#include "RiuMainPlotWindow.h" + +#include "cafUtils.h" + +#include +#include +#include +#include +#include +#include +#include + + +CAF_CMD_SOURCE_INIT(RicSnapshotViewToFileFeature, "RicSnapshotViewToFileFeature"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicSnapshotViewToFileFeature::saveSnapshotAs(const QString& fileName, RimViewWindow* viewWindow) +{ + if (viewWindow) + { + QImage image = viewWindow->snapshotWindowContent(); + if (!image.isNull()) + { + if (image.save(fileName)) + { + qDebug() << "Exported snapshot image to " << fileName; + } + else + { + qDebug() << "Error when trying to export snapshot image to " << fileName; + } + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicSnapshotViewToFileFeature::isCommandEnabled() +{ + return true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicSnapshotViewToFileFeature::onActionTriggered(bool isChecked) +{ + RiaApplication* app = RiaApplication::instance(); + RimProject* proj = app->project(); + + // Get active view window before displaying the file selection dialog + // If this is done after the file save dialog is displayed (and closed) + // app->activeViewWindow() returns NULL on Linux + RimViewWindow* viewWindow = app->activeViewWindow(); + if (!viewWindow) + { + RiaLogging::error("No view window is available, nothing to do"); + + return; + } + + QString startPath; + if (!proj->fileName().isEmpty()) + { + QFileInfo fi(proj->fileName()); + startPath = fi.absolutePath(); + } + else + { + startPath = app->lastUsedDialogDirectory("IMAGE_SNAPSHOT"); + } + + startPath += "/image.png"; + + QString fileName = QFileDialog::getSaveFileName(NULL, tr("Export to File"), startPath); + if (fileName.isEmpty()) + { + return; + } + + // Remember the directory to next time + app->setLastUsedDialogDirectory("IMAGE_SNAPSHOT", QFileInfo(fileName).absolutePath()); + + RicSnapshotViewToFileFeature::saveSnapshotAs(fileName, viewWindow); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicSnapshotViewToFileFeature::setupActionLook(QAction* actionToSetup) +{ + actionToSetup->setText("Snapshot To File"); + actionToSetup->setIcon(QIcon(":/SnapShotSave.png")); +} diff --git a/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.h b/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.h new file mode 100644 index 0000000000..ae83718d21 --- /dev/null +++ b/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.h @@ -0,0 +1,40 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2016 Statoil ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight 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 General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafCmdFeature.h" + +class RimViewWindow; + +//================================================================================================== +/// +//================================================================================================== +class RicSnapshotViewToFileFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +public: + static void saveSnapshotAs(const QString& fileName, RimViewWindow* viewWindow); + +protected: + // Overrides + virtual bool isCommandEnabled() override; + virtual void onActionTriggered(bool isChecked) override; + virtual void setupActionLook(QAction* actionToSetup) override; +}; diff --git a/ApplicationCode/ModelVisualization/RivPipeGeometryGenerator.h b/ApplicationCode/ModelVisualization/RivPipeGeometryGenerator.h index 46c94f6de4..82e685a509 100644 --- a/ApplicationCode/ModelVisualization/RivPipeGeometryGenerator.h +++ b/ApplicationCode/ModelVisualization/RivPipeGeometryGenerator.h @@ -63,7 +63,7 @@ public: void centerlineTextureCoords(cvf::Vec2fArray* textureCoords, const std::vector& segmentResults, const cvf::ScalarMapper* mapper) const; void setFirstVisibleSegmentIndex(size_t segmentIndex); - size_t pipeSegmentIndexFromTriangleIndex(size_t triangleIndex) const; + size_t segmentIndexFromTriangleIndex(size_t triangleIndex) const; void cylinderWithCenterLineParts(cvf::Collection* destinationParts, const std::vector& centerCoords, const cvf::Color3f& color, double radius); private: diff --git a/ApplicationCode/ProjectDataModel/Completions/RimFishbonesMultipleSubs.cpp b/ApplicationCode/ProjectDataModel/Completions/RimFishbonesMultipleSubs.cpp index 1d592d01dc..498553ac38 100644 --- a/ApplicationCode/ProjectDataModel/Completions/RimFishbonesMultipleSubs.cpp +++ b/ApplicationCode/ProjectDataModel/Completions/RimFishbonesMultipleSubs.cpp @@ -711,9 +711,16 @@ std::vector RimFishbonesMultipleSubs::locationsFromStartSpacingAndCount( //-------------------------------------------------------------------------------------------------- int RimFishbonesMultipleSubs::randomValueFromRange(int min, int max) { + // See http://www.cplusplus.com/reference/cstdlib/rand/ + int range = abs(max - min); int random_integer = min + int(range*rand() / (RAND_MAX + 1.0)); - + return random_integer; + int randomNumberInRange = rand() % range; + + int randomValue = min + randomNumberInRange; + + return randomValue; } diff --git a/ApplicationCode/ReservoirDataModel/RigTransmissibilityEquations.cpp b/ApplicationCode/ReservoirDataModel/RigTransmissibilityEquations.cpp index c8a234a609..e4a991f81b 100644 --- a/ApplicationCode/ReservoirDataModel/RigTransmissibilityEquations.cpp +++ b/ApplicationCode/ReservoirDataModel/RigTransmissibilityEquations.cpp @@ -32,14 +32,14 @@ double RigTransmissibilityEquations::peacemanRadius(double permeabilityNormalDir double cellSizeNormalDirection1, double cellSizeNormalDirection2) { - double nominator = cvf::Math::sqrt( - pow(cellSizeNormalDirection2, 2) + pow(permeabilityNormalDirection1 / permeabilityNormalDirection2, 1 / 2) - + pow(cellSizeNormalDirection1, 2) + pow(permeabilityNormalDirection2 / permeabilityNormalDirection1, 1 / 2)); + double numerator = cvf::Math::sqrt( + pow(cellSizeNormalDirection2, 2) * pow(permeabilityNormalDirection1 / permeabilityNormalDirection2, 1 / 2) + + pow(cellSizeNormalDirection1, 2) * pow(permeabilityNormalDirection2 / permeabilityNormalDirection1, 1 / 2)); double denominator = pow((permeabilityNormalDirection1 / permeabilityNormalDirection2), 1 / 4) + pow((permeabilityNormalDirection2 / permeabilityNormalDirection1), 1 / 4); - double r0 = 0.28 * nominator / denominator; + double r0 = 0.28 * numerator / denominator; return r0; }