mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Merge pull request #5262 from OPM/keywords-from-menu
#5261 System : Allow export of field and object keywords from test menu
This commit is contained in:
commit
be3c40c317
@ -18,6 +18,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicRunCommandFileFeature.h
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/RicShowMemoryCleanupDialogFeature.h
|
${CMAKE_CURRENT_LIST_DIR}/RicShowMemoryCleanupDialogFeature.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicDefaultDockConfigEclipseFeature.h
|
${CMAKE_CURRENT_LIST_DIR}/RicDefaultDockConfigEclipseFeature.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicDefaultDockConfigGeoMechFeature.h
|
${CMAKE_CURRENT_LIST_DIR}/RicDefaultDockConfigGeoMechFeature.h
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/RicExportObjectAndFieldKeywordsFeature.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set (SOURCE_GROUP_SOURCE_FILES
|
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}/RicShowMemoryCleanupDialogFeature.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicDefaultDockConfigEclipseFeature.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RicDefaultDockConfigEclipseFeature.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicDefaultDockConfigGeoMechFeature.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RicDefaultDockConfigGeoMechFeature.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/RicExportObjectAndFieldKeywordsFeature.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
list(APPEND CODE_HEADER_FILES
|
list(APPEND CODE_HEADER_FILES
|
||||||
|
@ -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 <http://www.gnu.org/licenses/gpl.html>
|
||||||
|
// for more details.
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "RicExportObjectAndFieldKeywordsFeature.h"
|
||||||
|
|
||||||
|
#include "RiaVersionInfo.h"
|
||||||
|
|
||||||
|
#include "RiuMainWindow.h"
|
||||||
|
|
||||||
|
#include "cafClassTypeName.h"
|
||||||
|
#include "cafPdmDefaultObjectFactory.h"
|
||||||
|
|
||||||
|
#include <QAction>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QTextStream>
|
||||||
|
|
||||||
|
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<QString> 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<QString> 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<caf::PdmFieldHandle*> 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;
|
||||||
|
}
|
@ -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 <http://www.gnu.org/licenses/gpl.html>
|
||||||
|
// 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();
|
||||||
|
};
|
@ -510,7 +510,6 @@ void RiuMainWindow::createMenus()
|
|||||||
|
|
||||||
connect( viewMenu, SIGNAL( aboutToShow() ), SLOT( slotRefreshViewActions() ) );
|
connect( viewMenu, SIGNAL( aboutToShow() ), SLOT( slotRefreshViewActions() ) );
|
||||||
|
|
||||||
// Debug menu
|
|
||||||
testMenu->addAction( m_mockModelAction );
|
testMenu->addAction( m_mockModelAction );
|
||||||
testMenu->addAction( m_mockResultsModelAction );
|
testMenu->addAction( m_mockResultsModelAction );
|
||||||
testMenu->addAction( m_mockLargeResultsModelAction );
|
testMenu->addAction( m_mockLargeResultsModelAction );
|
||||||
@ -523,6 +522,7 @@ void RiuMainWindow::createMenus()
|
|||||||
testMenu->addAction( m_executePaintEventPerformanceTest );
|
testMenu->addAction( m_executePaintEventPerformanceTest );
|
||||||
testMenu->addAction( cmdFeatureMgr->action( "RicLaunchUnitTestsFeature" ) );
|
testMenu->addAction( cmdFeatureMgr->action( "RicLaunchUnitTestsFeature" ) );
|
||||||
testMenu->addAction( cmdFeatureMgr->action( "RicRunCommandFileFeature" ) );
|
testMenu->addAction( cmdFeatureMgr->action( "RicRunCommandFileFeature" ) );
|
||||||
|
testMenu->addAction( cmdFeatureMgr->action( "RicExportObjectAndFieldKeywordsFeature" ) );
|
||||||
testMenu->addSeparator();
|
testMenu->addSeparator();
|
||||||
|
|
||||||
testMenu->addAction( cmdFeatureMgr->action( "RicHoloLensExportToFolderFeature" ) );
|
testMenu->addAction( cmdFeatureMgr->action( "RicHoloLensExportToFolderFeature" ) );
|
||||||
|
Loading…
Reference in New Issue
Block a user