From e88fe2163a70b3cc548f37392c7200113ae0e9ff 2017-06-08 13:15:22 From: Alexandre Leroux Date: 2017-06-08 13:15:22 Subject: [PATCH] Merge branch 'feature/MockPlugin' into develop --- diff --git a/cmake/sciqlop_applications.cmake b/cmake/sciqlop_applications.cmake index b36eb27..1c47446 100644 --- a/cmake/sciqlop_applications.cmake +++ b/cmake/sciqlop_applications.cmake @@ -35,6 +35,13 @@ ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/gui") ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/app") +OPTION (BUILD_PLUGINS "Build the plugins" OFF) +IF(BUILD_PLUGINS) + set(sciqlop-mockplugin_DIR "${CMAKE_SOURCE_DIR}/plugins/mockplugin/cmake") + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-mockplugin_DIR}") + ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/plugins/mockplugin") +ENDIF(BUILD_PLUGINS) + # LOGGER set(QTLOGGING_INI_FILE "${CMAKE_SOURCE_DIR}/config/QtProject/qtlogging.ini") FILE(COPY ${QTLOGGING_INI_FILE} DESTINATION ${CONFIG_OUTPUT_PATH}) diff --git a/plugins/mockplugin/CMakeLists.txt b/plugins/mockplugin/CMakeLists.txt new file mode 100644 index 0000000..fed127f --- /dev/null +++ b/plugins/mockplugin/CMakeLists.txt @@ -0,0 +1,145 @@ +## mockplugin - CMakeLists.txt +STRING(TOLOWER ${CMAKE_PROJECT_NAME} LIBRARY_PREFFIX) +SET(SQPMOCKPLUGIN_LIBRARY_NAME "${LIBRARY_PREFFIX}_mockplugin${DEBUG_SUFFIX}") +SET(SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src") +SET(INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") +SET(RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources") + +# Include mockplugin directory +INCLUDE_DIRECTORIES(${INCLUDES_DIR}) +INCLUDE_DIRECTORIES(${RESOURCES_DIR}) + +# +# Find Qt modules +# +SCIQLOP_FIND_QT(Core Widgets) + +# +# Find dependent libraries +# ======================== + +# sciqlop plugin +find_package(sciqlop-plugin) +INCLUDE_DIRECTORIES(${SCIQLOP-PLUGIN_INCLUDE_DIR}) + +# sciqlop core +find_package(sciqlop-core) +INCLUDE_DIRECTORIES(${SCIQLOP-CORE_INCLUDE_DIR}) +list(APPEND LIBRARIES ${SCIQLOP-CORE_LIBRARIES}) + +# sciqlop gui +find_package(sciqlop-gui) +INCLUDE_DIRECTORIES(${SCIQLOP-GUI_INCLUDE_DIR}) +list(APPEND LIBRARIES ${SCIQLOP-GUI_LIBRARIES}) + +# Resources files +FILE (GLOB_RECURSE PROJECT_RESOURCES ${RESOURCES_DIR}/*.json) + +# +# Compile the library +# +FILE (GLOB_RECURSE MODULE_SOURCES + ${INCLUDES_DIR}/*.h + ${SOURCES_DIR}/*.c + ${SOURCES_DIR}/*.cpp + ${SOURCES_DIR}/*.h + ${PROJECT_RESOURCES}) + +ADD_LIBRARY(${SQPMOCKPLUGIN_LIBRARY_NAME} ${MODULE_SOURCES}) +set_property(TARGET ${SQPMOCKPLUGIN_LIBRARY_NAME} PROPERTY CXX_STANDARD 14) +set_property(TARGET ${SQPMOCKPLUGIN_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) + +TARGET_LINK_LIBRARIES(${SQPMOCKPLUGIN_LIBRARY_NAME} ${LIBRARIES}) +qt5_use_modules(${SQPMOCKPLUGIN_LIBRARY_NAME} Core Widgets) + +# From cmake documentation: http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html +# Entries in the COMPILE_DEFINITIONS are prefixed with -D or /D and added to the compile line in an unspecified order. +# The DEFINE_SYMBOL target property is also added as a compile definition as a special convenience case for SHARED and MODULE library targets +IF(BUILD_SHARED_LIBS) + SET_TARGET_PROPERTIES(${SQPMOCKPLUGIN_LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS "SCIQLOP_EXPORT") +ELSE() + TARGET_COMPILE_DEFINITIONS(${SQPMOCKPLUGIN_LIBRARY_NAME} PUBLIC "SCIQLOP_STATIC_LIBRARIES") +ENDIF() + +# Set the variable to parent scope so that the other projects can copy the +# dependent shared libraries +SCIQLOP_SET_TO_PARENT_SCOPE(SQPMOCKPLUGIN_LIBRARY_NAME) + +# Copy extern shared libraries to the lib folder +SCIQLOP_COPY_TO_TARGET(LIBRARY ${SQPMOCKPLUGIN_LIBRARY_NAME} ${EXTERN_SHARED_LIBRARIES}) + +# Add the files to the list of files to be analyzed +LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES}) +SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES) +# Vera++ exclusion files +#LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/vera-exclusions/exclusions.txt) +SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES) + +# +# Compile the tests +# +IF(BUILD_TESTS) + INCLUDE_DIRECTORIES(${SOURCES_DIR}) + FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp) + FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h) + SET( TEST_LIBRARIES ${SQPGUI_LIBRARY_NAME}) + + FOREACH( testFile ${TESTS_SOURCES} ) + GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY ) + GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE ) + + # Add to the list of sources files all the sources in the same + # directory that aren't another test + FILE (GLOB currentTestSources + ${testDirectory}/*.c + ${testDirectory}/*.cpp + ${testDirectory}/*.h) + LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES}) + # LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS}) + + ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources}) + set_property(TARGET ${testName} PROPERTY CXX_STANDARD 14) + set_property(TARGET ${testName} PROPERTY CXX_STANDARD_REQUIRED ON) + TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} ) + qt5_use_modules(${testName} Test) + + ADD_TEST( NAME ${testName} COMMAND ${testName} ) + + SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES}) + ENDFOREACH( testFile ) + + LIST(APPEND testFilesToFormat ${TESTS_SOURCES}) + LIST(APPEND testFilesToFormat ${TESTS_HEADERS}) + LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat}) + SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES) +ENDIF(BUILD_TESTS) + +# +# Set the files that must be formatted by clang-format. +# +LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES}) +SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES) + +# +# Set the directories that doxygen must browse to generate the +# documentation. +# +# Source directories: +LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs") +LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src") +SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS) +# Source directories to exclude from the documentation generation +#LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*") +SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS) + +# +# Set the directories with the sources to analyze and propagate the +# modification to the parent scope +# +# Source directories to analyze: +LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src") +LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests") +SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS) +# Source directories to exclude from the analysis +#LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir") +SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS) diff --git a/plugins/mockplugin/cmake/Findsciqlop-mockplugin.cmake b/plugins/mockplugin/cmake/Findsciqlop-mockplugin.cmake new file mode 100644 index 0000000..0c0d764 --- /dev/null +++ b/plugins/mockplugin/cmake/Findsciqlop-mockplugin.cmake @@ -0,0 +1,21 @@ +# - Try to find sciqlop-mockplugin +# Once done this will define +# SCIQLOP-MOCKPLUGIN_FOUND - System has sciqlop-mockplugin +# SCIQLOP-MOCKPLUGIN_INCLUDE_DIR - The sciqlop-mockplugin include directories +# SCIQLOP-MOCKPLUGIN_LIBRARIES - The libraries needed to use sciqlop-mockplugin + +if(SCIQLOP-MOCKPLUGIN_FOUND) + return() +endif(SCIQLOP-MOCKPLUGIN_FOUND) + +set(SCIQLOP-MOCKPLUGIN_INCLUDE_DIR ${sciqlop-mockplugin_DIR}/../include) + +set (OS_LIB_EXTENSION "so") + +if(WIN32) + set (OS_LIB_EXTENSION "dll") +endif(WIN32) +# TODO: Add Mac Support +set(SCIQLOP-MOCKPLUGIN_LIBRARIES ${LIBRARY_OUTPUT_PATH}/libsciqlop_mockplugin${DEBUG_SUFFIX}.${OS_LIB_EXTENSION}) + +set(SCIQLOP-MOCKPLUGIN_FOUND TRUE) diff --git a/plugins/mockplugin/include/MockPlugin.h b/plugins/mockplugin/include/MockPlugin.h new file mode 100644 index 0000000..7d18987 --- /dev/null +++ b/plugins/mockplugin/include/MockPlugin.h @@ -0,0 +1,27 @@ +#ifndef SCIQLOP_MOCKPLUGIN_H +#define SCIQLOP_MOCKPLUGIN_H + +#include + +#include + +#include + +Q_DECLARE_LOGGING_CATEGORY(LOG_MockPlugin) + +class DataSourceItem; + +class MockPlugin : public QObject, public IPlugin { + Q_OBJECT + Q_INTERFACES(IPlugin) + Q_PLUGIN_METADATA(IID "sciqlop.plugin.IPlugin" FILE "mockplugin.json") +public: + /// @sa IPlugin::initialize() + void initialize() override; + +private: + /// Creates the data source item relative to the plugin + std::unique_ptr createDataSourceItem() const noexcept; +}; + +#endif // SCIQLOP_MOCKPLUGIN_H diff --git a/plugins/mockplugin/resources/mockplugin.json b/plugins/mockplugin/resources/mockplugin.json new file mode 100644 index 0000000..09ac778 --- /dev/null +++ b/plugins/mockplugin/resources/mockplugin.json @@ -0,0 +1,3 @@ +{ + "name" : "MockPlugin" +} diff --git a/plugins/mockplugin/src/MockPlugin.cpp b/plugins/mockplugin/src/MockPlugin.cpp new file mode 100644 index 0000000..599ad04 --- /dev/null +++ b/plugins/mockplugin/src/MockPlugin.cpp @@ -0,0 +1,55 @@ +#include + +#include +#include + +#include + +Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin") + +namespace { + +/// Name of the data source +const auto DATA_SOURCE_NAME = QStringLiteral("MMS"); + +} // namespace + +void MockPlugin::initialize() +{ + if (auto app = sqpApp) { + // Registers to the data source controller + auto &dataSourceController = app->dataSourceController(); + auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME); + + dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem()); + } + else { + qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application"); + } +} + +std::unique_ptr MockPlugin::createDataSourceItem() const noexcept +{ + // Magnetic field products + auto fgmProduct = std::make_unique(DataSourceItemType::PRODUCT, + QVector{QStringLiteral("FGM")}); + auto scProduct = std::make_unique(DataSourceItemType::PRODUCT, + QVector{QStringLiteral("SC")}); + + auto magneticFieldFolder = std::make_unique( + DataSourceItemType::NODE, QVector{QStringLiteral("Magnetic field")}); + magneticFieldFolder->appendChild(std::move(fgmProduct)); + magneticFieldFolder->appendChild(std::move(scProduct)); + + // Electric field products + auto electricFieldFolder = std::make_unique( + DataSourceItemType::NODE, QVector{QStringLiteral("Electric field")}); + + // Root + auto root = std::make_unique(DataSourceItemType::NODE, + QVector{DATA_SOURCE_NAME}); + root->appendChild(std::move(magneticFieldFolder)); + root->appendChild(std::move(electricFieldFolder)); + + return std::move(root); +}