diff --git a/ApplicationCode/Commands/ApplicationCommands/CMakeLists_files.cmake b/ApplicationCode/Commands/ApplicationCommands/CMakeLists_files.cmake index 108a396c04..d5a7ebf973 100644 --- a/ApplicationCode/Commands/ApplicationCommands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/ApplicationCommands/CMakeLists_files.cmake @@ -18,6 +18,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicRunCommandFileFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicShowMemoryCleanupDialogFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicDefaultDockConfigEclipseFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicDefaultDockConfigGeoMechFeature.h +${CMAKE_CURRENT_LIST_DIR}/RicExportObjectAndFieldKeywordsFeature.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -39,6 +40,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicRunCommandFileFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicShowMemoryCleanupDialogFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicDefaultDockConfigEclipseFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicDefaultDockConfigGeoMechFeature.cpp +${CMAKE_CURRENT_LIST_DIR}/RicExportObjectAndFieldKeywordsFeature.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/Commands/ApplicationCommands/RicExportObjectAndFieldKeywordsFeature.cpp b/ApplicationCode/Commands/ApplicationCommands/RicExportObjectAndFieldKeywordsFeature.cpp new file mode 100644 index 0000000000..7447ebcb30 --- /dev/null +++ b/ApplicationCode/Commands/ApplicationCommands/RicExportObjectAndFieldKeywordsFeature.cpp @@ -0,0 +1,164 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2019- Equinor 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 "RicExportObjectAndFieldKeywordsFeature.h" + +#include "RiaVersionInfo.h" + +#include "RiuMainWindow.h" + +#include "cafClassTypeName.h" +#include "cafPdmDefaultObjectFactory.h" + +#include +#include +#include +#include +#include + +CAF_CMD_SOURCE_INIT( RicExportObjectAndFieldKeywordsFeature, "RicExportObjectAndFieldKeywordsFeature" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicExportObjectAndFieldKeywordsFeature::isCommandEnabled() +{ + return true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicExportObjectAndFieldKeywordsFeature::onActionTriggered( bool isChecked ) +{ + QString dir = QFileDialog::getExistingDirectory( RiuMainWindow::instance(), + tr( "Select Directory For Export" ), + "c:/temp", + QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks ); + + if ( !dir.isEmpty() ) + { + exportObjectKeywords( dir + "/ri-objectKeywords.txt" ); + exportObjectAndFieldKeywords( dir + "/ri-fieldKeywords.txt" ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicExportObjectAndFieldKeywordsFeature::setupActionLook( QAction* actionToSetup ) +{ + actionToSetup->setText( "Export Object and Field Keywords" ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicExportObjectAndFieldKeywordsFeature::exportObjectKeywords( const QString& filePath ) +{ + auto instance = caf::PdmDefaultObjectFactory::instance(); + + QString textString; + QTextStream stream( &textString ); + + textString = versionHeaderText(); + + std::vector classKeywords = instance->classKeywords(); + for ( const auto& keyword : classKeywords ) + { + stream << keyword << "\n"; + } + + writeTextToFile( filePath, textString ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicExportObjectAndFieldKeywordsFeature::exportObjectAndFieldKeywords( const QString& filePath ) +{ + auto instance = caf::PdmDefaultObjectFactory::instance(); + + QString textString; + QTextStream stream( &textString ); + + bool includeClassName = true; + + textString = versionHeaderText(); + + std::vector classKeywords = instance->classKeywords(); + for ( const auto& keyword : classKeywords ) + { + caf::PdmObjectHandle* myClass = instance->create( keyword ); + + stream << keyword; + + if ( includeClassName ) + { + QString className = qStringTypeName( *myClass ); + + stream << " - " << className; + } + + stream << "\n"; + + std::vector fields; + myClass->fields( fields ); + + for ( auto f : fields ) + { + stream << " " << f->keyword() << "\n"; + } + + stream << "\n"; + + delete myClass; + } + + writeTextToFile( filePath, textString ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicExportObjectAndFieldKeywordsFeature::writeTextToFile( const QString& filePath, const QString& text ) +{ + QFile exportFile( filePath ); + if ( exportFile.open( QIODevice::WriteOnly | QIODevice::Text ) ) + { + QTextStream stream( &exportFile ); + + stream << text; + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RicExportObjectAndFieldKeywordsFeature::versionHeaderText() +{ + QString text; + + text += QString( "// ResInsight version string : %1\n" ).arg( STRPRODUCTVER ); + text += QString( "// Report generated : %1\n" ).arg( QDateTime::currentDateTime().toString() ); + text += "//\n"; + text += "//\n"; + text += "\n"; + + return text; +} diff --git a/ApplicationCode/Commands/ApplicationCommands/RicExportObjectAndFieldKeywordsFeature.h b/ApplicationCode/Commands/ApplicationCommands/RicExportObjectAndFieldKeywordsFeature.h new file mode 100644 index 0000000000..21707e7794 --- /dev/null +++ b/ApplicationCode/Commands/ApplicationCommands/RicExportObjectAndFieldKeywordsFeature.h @@ -0,0 +1,41 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2019- Equinor 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 RicExportObjectAndFieldKeywordsFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + bool isCommandEnabled() override; + void onActionTriggered( bool isChecked ) override; + void setupActionLook( QAction* actionToSetup ) override; + +private: + static void exportObjectKeywords( const QString& filePath ); + static void exportObjectAndFieldKeywords( const QString& filePath ); + + static void writeTextToFile( const QString& filePath, const QString& text ); + static QString versionHeaderText(); +}; diff --git a/ApplicationCode/UserInterface/RiuMainWindow.cpp b/ApplicationCode/UserInterface/RiuMainWindow.cpp index a780622f1a..73eeca355c 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMainWindow.cpp @@ -510,7 +510,6 @@ void RiuMainWindow::createMenus() connect( viewMenu, SIGNAL( aboutToShow() ), SLOT( slotRefreshViewActions() ) ); - // Debug menu testMenu->addAction( m_mockModelAction ); testMenu->addAction( m_mockResultsModelAction ); testMenu->addAction( m_mockLargeResultsModelAction ); @@ -523,6 +522,7 @@ void RiuMainWindow::createMenus() testMenu->addAction( m_executePaintEventPerformanceTest ); testMenu->addAction( cmdFeatureMgr->action( "RicLaunchUnitTestsFeature" ) ); testMenu->addAction( cmdFeatureMgr->action( "RicRunCommandFileFeature" ) ); + testMenu->addAction( cmdFeatureMgr->action( "RicExportObjectAndFieldKeywordsFeature" ) ); testMenu->addSeparator(); testMenu->addAction( cmdFeatureMgr->action( "RicHoloLensExportToFolderFeature" ) );