init
This commit is contained in:
+56
@@ -0,0 +1,56 @@
|
||||
project(openvibe-designer)
|
||||
|
||||
set(PROJECT_PRODUCT_NAME "${BRAND_NAME} Designer")
|
||||
|
||||
if(WIN32)
|
||||
# Should be uncommented once we stop using cmd as launcher
|
||||
#SET(ENTRYPOINT WIN32)
|
||||
set(ENTRYPOINT )
|
||||
else()
|
||||
set(ENTRYPOINT )
|
||||
endif()
|
||||
|
||||
file(GLOB_RECURSE SRC_FILES src/*.cpp src/*.h src/*.hpp src/visualization/*.cpp src/dynamic_settings/*.cpp)
|
||||
|
||||
include("FindSourceDependencyJSON")
|
||||
|
||||
set(SRC_FILES "${SRC_FILES};${CMAKE_BINARY_DIR}/resource-files/${LOWER_BRAND_NAME}-${LOWER_DESIGNER_NAME}.rc")
|
||||
add_executable(${PROJECT_NAME} ${ENTRYPOINT} ${SRC_FILES})
|
||||
|
||||
# Generate launch script
|
||||
OV_INSTALL_LAUNCH_SCRIPT(SCRIPT_PREFIX "${LOWER_BRAND_NAME}-${LOWER_DESIGNER_NAME}" EXECUTABLE_NAME "${PROJECT_NAME}" ICON_PATH "${OV_ICON_PATH}/designer.ico")
|
||||
|
||||
SET(INCLUDED_OV_SDK_COMPONENTS BASE ALLPLUGINS ALLMODULES DEPENDENCIES)
|
||||
include("AddOpenViBESDKComponents")
|
||||
include("FindOpenViBEVisualizationToolkit")
|
||||
include("FindThirdPartyGTK")
|
||||
include("FindThirdPartyBoost")
|
||||
include("FindThirdPartyBoost_System")
|
||||
include("FindThirdPartyBoost_Thread")
|
||||
include("FindThirdPartyBoost_Filesystem")
|
||||
|
||||
add_definitions(-DProjectVersion=\"${OV_GLOBAL_VERSION_STRING}\")
|
||||
add_definitions(-DM_VERSION_MAJOR=${OV_GLOBAL_VERSION_MAJOR})
|
||||
add_definitions(-DM_VERSION_MINOR=${OV_GLOBAL_VERSION_MINOR})
|
||||
|
||||
SET_BUILD_PLATFORM()
|
||||
|
||||
# Install files
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
RUNTIME DESTINATION ${DIST_BINDIR}
|
||||
LIBRARY DESTINATION ${DIST_LIBDIR}
|
||||
ARCHIVE DESTINATION ${DIST_LIBDIR})
|
||||
|
||||
|
||||
configure_file(share/designer.conf-base "${CMAKE_CURRENT_BINARY_DIR}/designer.conf" @ONLY)
|
||||
configure_file(share/about-dialog.ui-base "${CMAKE_CURRENT_BINARY_DIR}/about-dialog.ui")
|
||||
configure_file(share/interface.ui-base "${CMAKE_CURRENT_BINARY_DIR}/interface.ui")
|
||||
configure_file(share/interface-settings.ui-base "${CMAKE_CURRENT_BINARY_DIR}/interface-settings.ui")
|
||||
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/designer.conf" DESTINATION ${DIST_DATADIR}/openvibe/applications/designer)
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/about-dialog.ui" DESTINATION ${DIST_DATADIR}/openvibe/applications/designer)
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/interface.ui" DESTINATION ${DIST_DATADIR}/openvibe/applications/designer)
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/interface-settings.ui" DESTINATION ${DIST_DATADIR}/openvibe/applications/designer)
|
||||
|
||||
install(DIRECTORY share/ DESTINATION ${DIST_DATADIR}/openvibe/applications/designer PATTERN PATTERN "*-base*" EXCLUDE)
|
||||
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
<?xml version="1.0"?>
|
||||
<interface>
|
||||
<requires lib="gtk+" version="2.16"/>
|
||||
<!-- interface-naming-policy project-wide -->
|
||||
<object class="GtkAboutDialog" id="about">
|
||||
<property name="border_width">5</property>
|
||||
<property name="resizable">False</property>
|
||||
<property name="modal">True</property>
|
||||
<property name="type_hint">dialog</property>
|
||||
<property name="program_name">@BRAND_NAME@ @DESIGNER_NAME@</property>
|
||||
<property name="version">@OV_GLOBAL_VERSION_STRING@</property>
|
||||
<property name="comments" translatable="yes">Software technologies for the development of new research, diagnostic and therapeutic solutions leveraging real-time EEG and neurofeedback.
|
||||
Based on OpenViBE, a software from Inria.
|
||||
</property>
|
||||
<property name="license" translatable="yes">
|
||||
@LICENCE_TEXT@
|
||||
</property>
|
||||
<property name="authors">Inria & Mensia Technologies SA
|
||||
---
|
||||
Contributors :
|
||||
- Guillermo Andrade-Barroso / Inria
|
||||
- Quentin Barthélémy / Mensia
|
||||
- Laurent Bonnet / Mensia
|
||||
- Alison Cellard / Inria
|
||||
- Jérôme Chabrol / Inria
|
||||
- Vincent Delannoy / Inria
|
||||
- Morgane Fauvet / Mensia
|
||||
- Charles Garraud / Inria
|
||||
- Thierry Gaugry / Inria
|
||||
- Esrevi Huynh / Mensia
|
||||
- Anatole Lecuyer / Inria
|
||||
- Jozef Legény / Mensia
|
||||
- Jussi T. Lindgren / Inria
|
||||
- Fabien Lotte / Inria
|
||||
- Loïc Mahë / Inria
|
||||
- Benoit Perrin / Mensia
|
||||
- Alexis Placet / Mensia
|
||||
- Yann Renard / Mensia
|
||||
- Cédric Riou / Inria
|
||||
- Guillaume Serrière / Inria
|
||||
|
||||
Testers:
|
||||
- Marie Prat / Mensia
|
||||
- Agnès Dos Santos / Mensia
|
||||
|
||||
</property>
|
||||
<property name="documenters">Inria & Mensia Technologies SA
|
||||
---
|
||||
Documenters :
|
||||
- Quentin Barthélémy / Mensia
|
||||
- Laurent Bonnet / Mensia
|
||||
- Jérôme Chabrol / Inria
|
||||
- Morgane Fauvet / Mensia
|
||||
- Charles Garraud / Inria
|
||||
- Thierry Gaugry / Inria
|
||||
- Esrevi Huynh / Mensia
|
||||
- Jozef Legény / Mensia
|
||||
- Jussi T. Lindgren / Inria
|
||||
- Alexis Placet / Mensia
|
||||
- Marie Prat / Mensia
|
||||
- Yann Renard / Mensia
|
||||
- Cédric Riou / Inria
|
||||
- Agnès Dos Santos / Mensia
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</property>
|
||||
<property name="logo">header_logo.png</property>
|
||||
<property name="wrap_license">True</property>
|
||||
<child internal-child="vbox">
|
||||
<object class="GtkVBox" id="dialog-vbox26">
|
||||
<property name="visible">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK</property>
|
||||
<property name="spacing">2</property>
|
||||
<child internal-child="action_area">
|
||||
<object class="GtkHButtonBox" id="dialog-action_area26">
|
||||
<property name="visible">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
ProjectVersion_Major = @OV_GLOBAL_VERSION_MAJOR@
|
||||
ProjectVersion_Minor = @OV_GLOBAL_VERSION_MINOR@
|
||||
ProjectVersion_Patch = @OV_GLOBAL_VERSION_PATCH@
|
||||
ProjectVersion_Components = \{"openvibe-sdk":"@OV_SDK_VERSION_STRING@", "openvibe-designer":"@OV_GLOBAL_VERSION_MAJOR@.@OV_GLOBAL_VERSION_MINOR@.@OV_GLOBAL_VERSION_PATCH@"\}
|
||||
|
||||
Designer_Locale = C
|
||||
Designer_UndoRedoStackSize = 64
|
||||
Designer_ShowAlgorithms = false
|
||||
Designer_ShowDeprecated = true
|
||||
Designer_ShowOriginalBoxName = true
|
||||
Designer_FullscreenEditor = false
|
||||
#Designer_FullscreenVisualisation = true
|
||||
Designer_UnaffectedVisualizationWindowWidth = 480
|
||||
Designer_UnaffectedVisualizationWindowHeight = 320
|
||||
#Designer_UnaffectedVisualisationWindowFullscreen = false
|
||||
Designer_DefaultWorkingDirectory = ${Path_UserData}
|
||||
Designer_WindowManager_Center = false
|
||||
Designer_ScenarioFileNameTrimmingLimit = 15
|
||||
Designer_ScenarioTabsVerticalStack = false
|
||||
|
||||
Designer_ThrowPopUpWhenBoxIsOutdated = false
|
||||
|
||||
Designer_WebBrowserCommand_Windows = start ""
|
||||
Designer_WebBrowserCommand_Linux = nohup xdg-open
|
||||
Designer_WebBrowserCommand_MacOS = open
|
||||
Designer_WebBrowserCommand = ${Designer_WebBrowserCommand_${OperatingSystem}}
|
||||
Designer_WebBrowserCommandPostfix_Windows =
|
||||
Designer_WebBrowserCommandPostfix_Linux = >/dev/null 2>&1
|
||||
Designer_WebBrowserCommandPostfix_MacOS = &
|
||||
Designer_WebBrowserCommandPostfix = ${Designer_WebBrowserCommandPostfix_${OperatingSystem}}
|
||||
Designer_WebBrowserOpenViBEHomepage = http://openvibe.inria.fr/
|
||||
Designer_WebBrowserSupportURL = ${Designer_WebBrowserOpenViBEHomepage}/tracker
|
||||
Designer_WebBrowserHelpURLBase = ${Designer_WebBrowserOpenViBEHomepage}/documentation/@OV_GLOBAL_VERSION_STRING@
|
||||
|
||||
#####################################################################################
|
||||
# Designer Help (F1) Configuration
|
||||
#####################################################################################
|
||||
|
||||
Designer_HelpBrowserCommand_Windows = ${Designer_WebBrowserCommand_Windows}
|
||||
Designer_HelpBrowserCommand_Linux = ${Designer_WebBrowserCommand_Linux}
|
||||
Designer_HelpBrowserCommand_MacOS = ${Designer_WebBrowserCommand_MacOS}
|
||||
Designer_HelpBrowserCommand = ${Designer_WebBrowserCommand}
|
||||
Designer_HelpBrowserCommandPostfix_Windows = ${Designer_WebBrowserCommandPostfix_Windows}
|
||||
Designer_HelpBrowserCommandPostfix_Linux = ${Designer_WebBrowserCommandPostfix_Linux}
|
||||
Designer_HelpBrowserCommandPostfix_MacOS = ${Designer_WebBrowserCommandPostfix_MacOS}
|
||||
Designer_HelpBrowserURLBase = ${Designer_WebBrowserHelpURLBase}
|
||||
Designer_HelpBrowserDocumentationIndex = ${Designer_WebBrowserOpenViBEHomepage}/documentation-index
|
||||
Designer_HelpBrowserCommandPostfix = ${Designer_HelpBrowserCommandPostfix_${OperatingSystem}}
|
||||
|
||||
|
||||
Designer_ScriptEditorCommand_Windows = notepad
|
||||
Designer_ScriptEditorCommand_Linux = xdg-open
|
||||
Designer_ScriptEditorCommand_MacOS = open
|
||||
Designer_ScriptEditorCommand = ${Designer_ScriptEditorCommand_${OperatingSystem}}
|
||||
Designer_PopUpOnError = false
|
||||
Designer_AllowUpCastConnection = false
|
||||
Designer_ConsoleLogWithHexa = false
|
||||
Designer_ConsoleLogTimeInSecond = True
|
||||
Designer_ConsoleLogTimePrecision = 3
|
||||
|
||||
Designer_FastForwardFactor = 100.0
|
||||
|
||||
#Use all OpenViBE plugins, including SDK, Designer and extras
|
||||
Kernel_PluginsPatternMacOS = ${Path_Lib}/libopenvibe-plugins-*.dylib
|
||||
Kernel_PluginsPatternLinux = ${Path_Lib}/libopenvibe-plugins-*.so
|
||||
Kernel_PluginsPatternWindows = ${Path_Bin}/openvibe-plugins-*.dll
|
||||
|
||||
Designer_CustomConfigurationFile = ${Path_UserData}/openvibe-designer.conf
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 97 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 53 KiB |
+444
@@ -0,0 +1,444 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<requires lib="gtk+" version="2.22"/>
|
||||
<!-- interface-naming-policy project-wide -->
|
||||
<object class="GtkDialog" id="dialog-engine-configuration">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="title" translatable="yes">NeuroRT Engine Control Panel</property>
|
||||
<property name="default_width">800</property>
|
||||
<property name="default_height">600</property>
|
||||
<property name="destroy_with_parent">True</property>
|
||||
<property name="type_hint">normal</property>
|
||||
<child internal-child="vbox">
|
||||
<object class="GtkVBox" id="dialog-vbox35">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">2</property>
|
||||
<child>
|
||||
<object class="GtkToolbar" id="toolbar3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkToolItem" id="engine-dropdown_engine_type">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<child>
|
||||
<object class="GtkComboBox" id="combobox-engine-connection-type">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="model">liststore-engine-connection-types</property>
|
||||
<property name="active">0</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText" id="cellrenderertext1"/>
|
||||
<attributes>
|
||||
<attribute name="text">0</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolButton" id="button-launch-engine-server">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Launch Engine Server</property>
|
||||
<property name="use_underline">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolButton" id="button-configure-acquisition">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="label" translatable="yes">Configure Acquisition</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-properties</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToggleToolButton" id="toggle-acquire-impedance">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Acquire Impedance</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-go-up</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolButton" id="button-reinitialize-archway">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="label" translatable="yes">Reinitialize Archway</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-refresh</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSeparatorToolItem" id="toolbutton1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolButton" id="button-start-engine">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="label" translatable="yes">Start Engine</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-media-play</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolButton" id="button-start-engine-fast">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="label" translatable="yes">Fast Forward</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-media-forward</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolButton" id="button-stop-engine">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="label" translatable="yes">Stop Engine</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-media-stop</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label10">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes"><b>Available Pipelines</b></property>
|
||||
<property name="use_markup">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow" id="scrolledwindow5">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="hscrollbar_policy">never</property>
|
||||
<property name="vscrollbar_policy">automatic</property>
|
||||
<child>
|
||||
<object class="GtkViewport" id="viewport3">
|
||||
<property name="width_request">100</property>
|
||||
<property name="height_request">80</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="shadow_type">none</property>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="treeview-engine-pipelines">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="model">liststore-pipelines</property>
|
||||
<property name="headers_clickable">False</property>
|
||||
<property name="search_column">1</property>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
|
||||
<property name="title" translatable="yes">Id</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText" id="cellrenderertext2">
|
||||
<property name="alignment">right</property>
|
||||
<property name="font">monospace</property>
|
||||
</object>
|
||||
<attributes>
|
||||
<attribute name="text">1</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn" id="treeviewcolumn2">
|
||||
<property name="min_width">100</property>
|
||||
<property name="title" translatable="yes">Description</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText" id="cellrenderertext3"/>
|
||||
<attributes>
|
||||
<attribute name="text">2</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn" id="treeviewcolumn4">
|
||||
<property name="title" translatable="yes">Has Configuration</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererPixbuf" id="cellrendererpixbuf2">
|
||||
<property name="stock_id">gtk-edit</property>
|
||||
</object>
|
||||
<attributes>
|
||||
<attribute name="visible">3</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child internal-child="action_area">
|
||||
<object class="GtkHButtonBox" id="dialog-action_area35">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="layout_style">end</property>
|
||||
<child>
|
||||
<object class="GtkSpinner" id="spinner-engine-activity">
|
||||
<property name="width_request">40</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkDialog" id="dialog-pipeline-configuration">
|
||||
<property name="width_request">640</property>
|
||||
<property name="height_request">600</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="title" translatable="yes">Pipeline Configuration</property>
|
||||
<property name="border_width">5</property>
|
||||
<property name="modal">True</property>
|
||||
<property name="destroy_with_parent">True</property>
|
||||
<property name="type_hint">dialog</property>
|
||||
<property name="skip_taskbar_hint">True</property>
|
||||
<property name="transient_for">dialog-engine-configuration</property>
|
||||
<child internal-child="vbox">
|
||||
<object class="GtkVBox" id="dialog-vbox33">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">2</property>
|
||||
<child internal-child="action_area">
|
||||
<object class="GtkHButtonBox" id="dialog-action_area33">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="layout_style">end</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="button-pipeline-configuration-apply">
|
||||
<property name="label" translatable="yes">Apply</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="button-pipeline-configuration-cancel">
|
||||
<property name="label" translatable="yes">Cancel</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow" id="scrolledwindow6">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="hscrollbar_policy">automatic</property>
|
||||
<property name="vscrollbar_policy">automatic</property>
|
||||
<child>
|
||||
<object class="GtkViewport" id="viewport4">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="shadow_type">none</property>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="treeview-pipeline-configuration">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="model">liststore-pipeline-configuration</property>
|
||||
<property name="headers_clickable">False</property>
|
||||
<property name="search_column">0</property>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn" id="treeviewcolumn3">
|
||||
<property name="resizable">True</property>
|
||||
<property name="sizing">autosize</property>
|
||||
<property name="title" translatable="yes">Name</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText" id="cellrenderertext6"/>
|
||||
<attributes>
|
||||
<attribute name="text">1</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn" id="treeviewcolumn5">
|
||||
<property name="resizable">True</property>
|
||||
<property name="sizing">autosize</property>
|
||||
<property name="title" translatable="yes">Default Value</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText" id="cellrenderertext5"/>
|
||||
<attributes>
|
||||
<attribute name="text">2</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn" id="treeviewcolumn6">
|
||||
<property name="resizable">True</property>
|
||||
<property name="sizing">autosize</property>
|
||||
<property name="title" translatable="yes">Value</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText" id="pipeline-configuration-cellrenderer-parameter-value">
|
||||
<property name="editable">True</property>
|
||||
</object>
|
||||
<attributes>
|
||||
<attribute name="text">3</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<action-widgets>
|
||||
<action-widget response="1">button-pipeline-configuration-apply</action-widget>
|
||||
<action-widget response="-6">button-pipeline-configuration-cancel</action-widget>
|
||||
</action-widgets>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="engine-activity-adjustment">
|
||||
<property name="upper">100</property>
|
||||
<property name="step_increment">1</property>
|
||||
<property name="page_increment">10</property>
|
||||
</object>
|
||||
<object class="GtkListStore" id="liststore-engine-connection-types">
|
||||
<columns>
|
||||
<!-- column-name Text -->
|
||||
<column type="gchararray"/>
|
||||
</columns>
|
||||
<data>
|
||||
<row>
|
||||
<col id="0" translatable="yes">Local</col>
|
||||
</row>
|
||||
<row>
|
||||
<col id="0" translatable="yes">LAN</col>
|
||||
</row>
|
||||
</data>
|
||||
</object>
|
||||
<object class="GtkListStore" id="liststore-pipeline-configuration">
|
||||
<columns>
|
||||
<!-- column-name pipeline-id -->
|
||||
<column type="guint64"/>
|
||||
<!-- column-name name -->
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name default-value -->
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name value -->
|
||||
<column type="gchararray"/>
|
||||
</columns>
|
||||
</object>
|
||||
<object class="GtkListStore" id="liststore-pipelines">
|
||||
<columns>
|
||||
<!-- column-name pipeline-id -->
|
||||
<column type="guint64"/>
|
||||
<!-- column-name pipeline-hex-id -->
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name pipeline-description -->
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name pipeline-has-configuration -->
|
||||
<column type="gboolean"/>
|
||||
</columns>
|
||||
</object>
|
||||
</interface>
|
||||
+1245
File diff suppressed because it is too large
Load Diff
+5910
File diff suppressed because it is too large
Load Diff
BIN
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
+125
@@ -0,0 +1,125 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#if defined TARGET_OS_Windows
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
#include <tlhelp32.h>
|
||||
#include <tchar.h>
|
||||
#elif defined TARGET_OS_Linux || defined TARGET_OS_MacOS
|
||||
#include <cstdlib>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
#include <fs/IEntryEnumerator.h>
|
||||
#include <fs/Files.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#endif
|
||||
|
||||
#if defined TARGET_OS_Linux || defined TARGET_OS_MacOS
|
||||
namespace
|
||||
{
|
||||
class CProcessEnumeratorCB : public FS::IEntryEnumeratorCallBack
|
||||
{
|
||||
public:
|
||||
CProcessEnumeratorCB(std::string processName, bool& rbFoundProcess) : m_name(processName), m_found(rbFoundProcess) { }
|
||||
|
||||
virtual FS::boolean callback(FS::IEntryEnumerator::IEntry& entry, FS::IEntryEnumerator::IAttributes& /*attributes*/)
|
||||
{
|
||||
std::ifstream fsInputStream;
|
||||
FS::Files::openIFStream(fsInputStream, entry.getName());
|
||||
std::string fileContents;
|
||||
|
||||
if (fsInputStream.is_open())
|
||||
{
|
||||
while(!fsInputStream.eof()) { fsInputStream >> fileContents; }
|
||||
size_t pos = fileContents.rfind(m_name);
|
||||
if (pos != std::string::npos && pos == fileContents.length() - m_name.length() - 1 ) { m_found = true; }
|
||||
|
||||
}
|
||||
fsInputStream.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string m_name;
|
||||
bool& m_found;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace ProcessUtilities {
|
||||
bool doesProcessExist(const std::string& name)
|
||||
{
|
||||
#if defined TARGET_OS_Windows
|
||||
PROCESSENTRY32 pe32;
|
||||
|
||||
// Take a snapshot of all processes in the system.
|
||||
const HANDLE processSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||
if (processSnap == INVALID_HANDLE_VALUE) { return false; }
|
||||
|
||||
// Set the size of the structure before using it.
|
||||
pe32.dwSize = sizeof(PROCESSENTRY32);
|
||||
|
||||
// Retrieve information about the first process,
|
||||
// and exit if unsuccessful
|
||||
if (!Process32First(processSnap, &pe32))
|
||||
{
|
||||
CloseHandle(processSnap); // clean the snapshot object
|
||||
return false;
|
||||
}
|
||||
|
||||
bool bReturnValue = false;
|
||||
// Now walk the snapshot of processes
|
||||
do { if (name + ".exe" == std::string(pe32.szExeFile)) { bReturnValue = true; } } while (Process32Next(processSnap, &pe32));
|
||||
|
||||
CloseHandle(processSnap);
|
||||
|
||||
return bReturnValue;
|
||||
#elif defined TARGET_OS_Linux || defined TARGET_OS_MacOS
|
||||
|
||||
bool found = false;
|
||||
CProcessEnumeratorCB* cb = new CProcessEnumeratorCB(name, found);
|
||||
|
||||
FS::IEntryEnumerator* entry = FS::createEntryEnumerator(*cb);
|
||||
entry->enumerate("/proc/*/cmdline");
|
||||
entry->release();
|
||||
|
||||
delete cb;
|
||||
return found;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool launchCommand(const char* sCommandLine)
|
||||
{
|
||||
#if defined TARGET_OS_Windows
|
||||
/*
|
||||
LPTSTR szCmdline = TEXT(const_cast<char*>(sCommandLine));
|
||||
|
||||
STARTUPINFO lpStartupInfo;
|
||||
ZeroMemory(&lpStartupInfo,sizeof(lpStartupInfo));
|
||||
lpStartupInfo.cb = sizeof(lpStartupInfo);
|
||||
lpStartupInfo.dwFlags |= CREATE_NEW_CONSOLE;
|
||||
|
||||
PROCESS_INFORMATION lpProcessInfo;
|
||||
// Create the process
|
||||
if (!CreateProcess(nullptr,szCmdline, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, &lpStartupInfo, &lpProcessInfo)) { exit(1); }
|
||||
*/
|
||||
const std::string cmd = "start \"\" \"" + std::string(sCommandLine) + "\"";
|
||||
system(cmd.c_str());
|
||||
#elif defined TARGET_OS_Linux || defined TARGET_OS_MacOS
|
||||
|
||||
if (fork() == 0)
|
||||
{
|
||||
system(sCommandLine);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// FIXME: temporary solution using system()
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace ProcessUtilities
|
||||
} // namespace OpenViBE
|
||||
+611
@@ -0,0 +1,611 @@
|
||||
#ifdef MENSIA_DISTRIBUTION
|
||||
|
||||
#include "ovdCArchwayHandler.h"
|
||||
|
||||
#include <openvibe/ov_directories.h>
|
||||
#include <openvibe/kernel/log/ovILogManager.h>
|
||||
#include <openvibe/kernel/configuration/ovIConfigurationManager.h>
|
||||
#include <fs/Files.h>
|
||||
|
||||
#include <ios>
|
||||
#include <cassert>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <regex>
|
||||
|
||||
namespace OpenViBE {
|
||||
|
||||
const std::string CArchwayHandler::ARCHWAY_CONFIG_FILE = (Directories::getUserDataDir() + "/studio-archway.conf").toASCIIString();
|
||||
const std::string CArchwayHandler::ARCHWAY_PIPELINES_CONFIG_FILE = (Directories::getUserDataDir() + "/studio-archway-pipeline-configuration.conf").
|
||||
toASCIIString();
|
||||
|
||||
std::string CArchwayHandler::getArchwayErrorString() const
|
||||
{
|
||||
assert(m_Archway);
|
||||
const auto errorCode = m_archway->getLastError();
|
||||
const auto errorString = m_archway->getErrorString(errorCode);
|
||||
|
||||
std::stringstream stream;
|
||||
stream << std::hex << errorCode;
|
||||
return "[0x" + stream.str() + "] " + errorString;
|
||||
}
|
||||
|
||||
|
||||
EEngineInitialisationStatus CArchwayHandler::initialize()
|
||||
{
|
||||
#if defined TARGET_OS_Windows
|
||||
m_archwayModule.loadFromPath("mensia-engine.dll", "initialize");
|
||||
#elif defined TARGET_OS_Linux
|
||||
m_archwayModule.loadFromPath("libmensia-engine.so", "initialize");
|
||||
#elif defined TARGET_OS_MacOS
|
||||
m_archwayModule.loadFromPath("libmensia-engine.dylib", "initialize");
|
||||
#endif
|
||||
|
||||
if (!m_archwayModule.isLoaded()) { return EEngineInitialisationStatus::NotAvailable; }
|
||||
m_archway = new struct ArchwayAPI();
|
||||
|
||||
bool didLoad = true;
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "getLastError", &m_archway->getLastError);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "getErrorString", &m_archway->getErrorString);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "getVersionDescription", &m_archway->getVersionDescription);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "getConfigurationParameterAsString",
|
||||
&m_archway->getConfigurationParameterAsString);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "getPipelineScenarioPath", &m_archway->getPipelineScenarioPath);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "initialize", &m_archway->initialize);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "startAllAcquisitionDevices", &m_archway->startAllAcquisitionDevices);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "startImpedanceCheckOnAllAcquisitionDevices",
|
||||
&m_archway->startImpedanceCheckOnAllAcquisitionDevices);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "startEngine", &m_archway->startEngine);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "startEngineInFastForward", &m_archway->startEngineInFastForward);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "stopEngine", &m_archway->stopEngine);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "stopAllAcquisitionDevices", &m_archway->stopAllAcquisitionDevices);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "uninitialize", &m_archway->uninitialize);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "enumerateAvailablePipelines", &m_archway->enumerateAvailablePipelines);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "createPipeline", &m_archway->createPipeline);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "releasePipeline", &m_archway->releasePipeline);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "isPipelineRunning", &m_archway->isPipelineRunning);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "isPipelineInErrorState", &m_archway->isPipelineInErrorState);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "enumeratePipelineParameters", &m_archway->enumeratePipelineParameters);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "setPipelineParameterAsString", &m_archway->setPipelineParameterAsString);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "mainloop", &m_archway->mainloop);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "getPendingValueCount", &m_archway->getPendingValueCount);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "getPendingValueDimension", &m_archway->getPendingValueDimension);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "getPendingValue", &m_archway->getPendingValue);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "getPendingLogMessageCount", &m_archway->getPendingLogMessageCount);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "getPendingLogMessage", &m_archway->getPendingLogMessage);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "dropPendingValues", &m_archway->dropPendingValues);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "dropPendingEvents", &m_archway->dropPendingEvents);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "isInitialized", &m_archway->isInitialized);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "isAcquiring", &m_archway->isAcquiring);
|
||||
didLoad &= System::CDynamicModuleSymbolLoader::getSymbol<>(m_archwayModule, "isStarted", &m_archway->isStarted);
|
||||
|
||||
|
||||
if (!didLoad)
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "Failed to load symbols from Archway library [" << m_archwayModule.getErrorDetails() <<
|
||||
"]\n";
|
||||
delete m_archway;
|
||||
m_archway = nullptr;
|
||||
return EEngineInitialisationStatus::NotAvailable;
|
||||
}
|
||||
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Trace << "Working with Archway version: " << m_archway->getVersionDescription() << "\n";
|
||||
|
||||
// Now initialize the ArchwayBridge structure with closures that bridge to local Archway functions
|
||||
// this way we do not have to expose the Archway object or the C API
|
||||
|
||||
m_ArchwayBridge.isStarted = [this]() { return this->m_archway->isStarted(); };
|
||||
m_ArchwayBridge.getAvailableValueMatrixCount = [this](size_t valueChannelId)
|
||||
{
|
||||
return this->m_archway->getPendingValueCount(m_RunningPipelineId, valueChannelId);
|
||||
};
|
||||
|
||||
// This function returns the last getPendingValue result as a vector
|
||||
// Such encapsulation enables us to avoid a call to getPendingValueDimension
|
||||
// from the client plugin.
|
||||
m_ArchwayBridge.popValueMatrix = [this](const size_t valueChannelId)
|
||||
{
|
||||
std::vector<float> valueMatrix;
|
||||
const auto valueChannelDim = this->m_archway->getPendingValueDimension(m_RunningPipelineId, valueChannelId);
|
||||
valueMatrix.resize(valueChannelDim);
|
||||
if (valueChannelDim > 0)
|
||||
{
|
||||
if (!this->m_archway->getPendingValue(m_RunningPipelineId, valueChannelId, &valueMatrix[0]))
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "Failed to get pending value " << this->getArchwayErrorString().c_str() << "\n";
|
||||
}
|
||||
}
|
||||
return valueMatrix;
|
||||
};
|
||||
|
||||
// As archway buffers signals we have to expose this function to the client plugins
|
||||
m_ArchwayBridge.dropBuffers = [this]()
|
||||
{
|
||||
m_archway->dropPendingEvents(0);
|
||||
m_archway->dropPendingValues(0);
|
||||
return true;
|
||||
};
|
||||
|
||||
// We save the address of the structure in the heap memory as a string and save it in
|
||||
// the ConfigurationManager, this is because a box can not communicate directly with the Designer
|
||||
std::ostringstream archwayBridgeAddress;
|
||||
archwayBridgeAddress << static_cast<void const*>(&m_ArchwayBridge);
|
||||
m_kernelCtx.getConfigurationManager().createConfigurationToken("Designer_ArchwayBridgeAddress", archwayBridgeAddress.str().c_str());
|
||||
|
||||
if (!this->loadPipelineConfigurations()) { return EEngineInitialisationStatus::Failure; }
|
||||
|
||||
m_EngineType = EEngineType::Local;
|
||||
|
||||
// Get the starting engine type from configuration
|
||||
std::ifstream archwayConfigFile;
|
||||
FS::Files::openIFStream(archwayConfigFile, ARCHWAY_CONFIG_FILE.c_str());
|
||||
if (archwayConfigFile.good())
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string line;
|
||||
while (std::getline(archwayConfigFile, line))
|
||||
{
|
||||
std::cmatch cm;
|
||||
if (std::regex_match(line.c_str(), cm, std::regex("config.server\\s*=\\s*'(lan|local)'")))
|
||||
{
|
||||
if (cm[1] == "lan") { m_EngineType = EEngineType::LAN; }
|
||||
}
|
||||
else if (std::regex_match(line.c_str(), cm, std::regex("config.device[1]\\s*=\\s*'([^']*)'"))) { m_DeviceURL = cm[1]; }
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// An exception will be thrown when using libc++ from ubuntu 14.04
|
||||
// in that case we do nothing and keep the defaults
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!this->initializeArchway())
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "Failed to initialize the engine " << this->getArchwayErrorString().c_str() << "\n";
|
||||
return EEngineInitialisationStatus::Failure;
|
||||
}
|
||||
|
||||
char deviceURL[2048];
|
||||
m_archway->getConfigurationParameterAsString("config.device[1]", deviceURL, sizeof(deviceURL));
|
||||
m_DeviceURL = deviceURL;
|
||||
|
||||
return EEngineInitialisationStatus::Success;
|
||||
}
|
||||
|
||||
bool CArchwayHandler::uninitialize()
|
||||
{
|
||||
assert(m_Archway);
|
||||
|
||||
if (m_archway->isStarted())
|
||||
{
|
||||
if (!m_archway->stopEngine())
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "Failed to stop Engine " << this->getArchwayErrorString().c_str() << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (m_archway->isAcquiring())
|
||||
{
|
||||
if (!m_archway->stopAllAcquisitionDevices())
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "Failed to stop all acquisition devices " << this->getArchwayErrorString().c_str() <<
|
||||
"\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (m_archway->isInitialized())
|
||||
{
|
||||
if (!m_archway->uninitialize())
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "Failed to uninitialize Archway " << this->getArchwayErrorString().c_str() << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
delete m_archway;
|
||||
m_archway = nullptr;
|
||||
|
||||
if (!this->savePipelineConfigurations()) { return false; }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
CArchwayHandler::~CArchwayHandler() { if (m_archway) { this->uninitialize(); } }
|
||||
|
||||
|
||||
bool CArchwayHandler::initializeArchway()
|
||||
{
|
||||
assert(m_Archway);
|
||||
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Trace << "Re-initializing engine in [" << (m_EngineType == EEngineType::Local ? "Local" : "LAN") << "]" <<
|
||||
"\n";
|
||||
return m_archway->initialize("user", "pass", "neurort-studio", ARCHWAY_CONFIG_FILE.c_str());
|
||||
}
|
||||
|
||||
bool CArchwayHandler::uninitializeArchway()
|
||||
{
|
||||
assert(m_Archway);
|
||||
|
||||
if (m_archway->isInitialized())
|
||||
{
|
||||
if (!m_archway->uninitialize())
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "Failed to uninitialize Archway " << this->getArchwayErrorString().c_str() << "\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CArchwayHandler::reinitializeArchway()
|
||||
{
|
||||
assert(m_Archway);
|
||||
|
||||
if (!this->uninitializeArchway())
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "Failed to uninitialize Engine " << this->getArchwayErrorString().c_str() << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
this->writeArchwayConfigurationFile();
|
||||
|
||||
if (!this->initializeArchway())
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "Failed to initialize Engine " << this->getArchwayErrorString().c_str() << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Info << "Archway re-initialized \n";
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CArchwayHandler::startEngineWithPipeline(const size_t pipelineClassID, const bool isFastForward, const bool shouldAcquireImpedance)
|
||||
{
|
||||
assert(m_Archway);
|
||||
|
||||
if (m_archway->isStarted())
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Info << "Engine is already started\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!m_archway->isAcquiring())
|
||||
{
|
||||
if (shouldAcquireImpedance)
|
||||
{
|
||||
if (!m_archway->startImpedanceCheckOnAllAcquisitionDevices())
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Error << "Failed to start the impedance acquisition" << this->getArchwayErrorString().c_str() <<
|
||||
"\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!m_archway->startAllAcquisitionDevices())
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Error << "Failed to start the data acquisition" << this->getArchwayErrorString().c_str() << "\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
m_RunningPipelineId = m_archway->createPipeline(pipelineClassID, "");
|
||||
|
||||
if (m_RunningPipelineId == 0)
|
||||
{
|
||||
m_archway->stopAllAcquisitionDevices();
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Error << "Failed to create pipeline " << this->getArchwayErrorString().c_str() << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_pipelineSettings.count(pipelineClassID) != 0)
|
||||
{
|
||||
for (auto& parameter : m_pipelineSettings[pipelineClassID])
|
||||
{
|
||||
m_archway->setPipelineParameterAsString(m_RunningPipelineId, parameter.first.c_str(), parameter.second.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
if (!(isFastForward ? m_archway->startEngineInFastForward() : m_archway->startEngine()))
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Error << "Engine failed to start " << this->getArchwayErrorString().c_str() << "\n";
|
||||
|
||||
const size_t nPendingLogMessage = m_archway->getPendingLogMessageCount(m_RunningPipelineId);
|
||||
|
||||
for (size_t i = 0; i < nPendingLogMessage; ++i)
|
||||
{
|
||||
size_t logLevel;
|
||||
char messageBuffer[2048];
|
||||
std::string logMessages;
|
||||
|
||||
m_archway->getPendingLogMessage(m_RunningPipelineId, &logLevel, messageBuffer, sizeof(messageBuffer));
|
||||
m_kernelCtx.getLogManager() << Kernel::ELogLevel(logLevel) << messageBuffer;
|
||||
}
|
||||
|
||||
if (!m_archway->stopAllAcquisitionDevices())
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Error << "Failed to stop all acquisition devices " << this->getArchwayErrorString().c_str() << "\n";
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Info << "Engine Started\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CArchwayHandler::stopEngine()
|
||||
{
|
||||
assert(m_Archway);
|
||||
|
||||
bool hasStopSucceeded = true;
|
||||
|
||||
if (m_archway->isStarted())
|
||||
{
|
||||
if (!m_archway->stopEngine())
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "Failed to stop Engine " << this->getArchwayErrorString().c_str() << "\n";
|
||||
hasStopSucceeded = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_archway->isAcquiring())
|
||||
{
|
||||
if (!m_archway->stopAllAcquisitionDevices())
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "Failed to all acquisition devices " << this->getArchwayErrorString().c_str() << "\n";
|
||||
hasStopSucceeded = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_RunningPipelineId != 0)
|
||||
{
|
||||
if (!m_archway->releasePipeline(m_RunningPipelineId))
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "Failed to release pipeline [" << m_RunningPipelineId << "] " << this->
|
||||
getArchwayErrorString().c_str() << "\n";
|
||||
hasStopSucceeded = false;
|
||||
}
|
||||
|
||||
m_RunningPipelineId = 0;
|
||||
}
|
||||
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Info << "Engine Stopped\n";
|
||||
return hasStopSucceeded;
|
||||
}
|
||||
|
||||
bool CArchwayHandler::loopEngine()
|
||||
{
|
||||
assert(m_Archway);
|
||||
|
||||
const bool success = m_archway->mainloop();
|
||||
|
||||
const bool isPipelineRunning = m_archway->isPipelineRunning(m_RunningPipelineId);
|
||||
const bool isPipelineInErrorState = m_archway->isPipelineInErrorState(m_RunningPipelineId);
|
||||
|
||||
if (!isPipelineRunning) { m_kernelCtx.getLogManager() << Kernel::LogLevel_Info << "Pipeline [" << m_RunningPipelineId << "] is not running.\n"; }
|
||||
|
||||
if (isPipelineInErrorState) { m_kernelCtx.getLogManager() << Kernel::LogLevel_Error << "Pipeline [" << m_RunningPipelineId << "] is in error state.\n"; }
|
||||
|
||||
const size_t nPendingLogMessage = m_archway->getPendingLogMessageCount(m_RunningPipelineId);
|
||||
|
||||
for (size_t i = 0; i < nPendingLogMessage; ++i)
|
||||
{
|
||||
size_t logLevel;
|
||||
char messageBuffer[2048];
|
||||
std::string logMessages;
|
||||
|
||||
m_archway->getPendingLogMessage(m_RunningPipelineId, &logLevel, messageBuffer, sizeof(messageBuffer));
|
||||
m_kernelCtx.getLogManager() << Kernel::ELogLevel(logLevel) << messageBuffer;
|
||||
}
|
||||
|
||||
if (!isPipelineRunning || isPipelineInErrorState)
|
||||
{
|
||||
if (!this->stopEngine()) { return false; }
|
||||
|
||||
m_GUIBridge.refreshStoppedEngine();
|
||||
|
||||
return success && !isPipelineInErrorState;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool CArchwayHandler::isEngineStarted()
|
||||
{
|
||||
if (!m_archway) { return false; }
|
||||
return m_archway->isStarted();
|
||||
}
|
||||
|
||||
namespace {
|
||||
void enumerateEnginePipelinesCallback(const size_t pipelineID, const char* pipelineDescription, void* userData)
|
||||
{
|
||||
const auto callbackParameters = static_cast<std::pair<std::vector<SPipeline>*, std::map<size_t, std::map<std::string, std::string>>*>*>(userData);
|
||||
auto enginePipelines = callbackParameters->first;
|
||||
const auto pipelineSettings = callbackParameters->second;
|
||||
|
||||
enginePipelines->push_back({ pipelineID, pipelineDescription, pipelineSettings->count(pipelineID) != 0 });
|
||||
}
|
||||
|
||||
void enumeratePipelineParametersCallback(size_t/*pipelineID*/, const char* parameterName, const char* parameterValue, void* userData)
|
||||
{
|
||||
// This callback will go through the pipeline parameters one by one and push them into the
|
||||
// vector of SPipelineParameters which is passed as the first element of the data input pair
|
||||
// This callback receives the parameter's name and default value from Archway, which is why we pass
|
||||
// it the list of the _currently set_ parameters for the pipeline
|
||||
const auto parameters = static_cast<std::pair<std::vector<SPipelineParameter>*, std::map<std::string, std::string> const*>*>(userData);
|
||||
|
||||
// Our output parameter is the list of pipeline parameters
|
||||
auto pipelineParameters = parameters->first;
|
||||
// Our additional input parameter is the map of currently set parameters for the pipeline
|
||||
// (note that if no parameters are set for the pipeline then this pointer will be null)
|
||||
const auto pipelineSettings = parameters->second;
|
||||
|
||||
// Search for the currently set value of the currently handled parameter
|
||||
std::string str;
|
||||
|
||||
if (pipelineSettings && pipelineSettings->count(parameterName) != 0) { str = pipelineSettings->at(parameterName); }
|
||||
|
||||
pipelineParameters->push_back({ parameterName, parameterValue, str });
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::vector<SPipeline> CArchwayHandler::getEnginePipelines() const
|
||||
{
|
||||
assert(m_Archway);
|
||||
|
||||
std::vector<SPipeline> enginePipelines;
|
||||
auto callbackParameters = make_pair(&enginePipelines, &m_pipelineSettings);
|
||||
|
||||
if (!m_archway->enumerateAvailablePipelines(enumerateEnginePipelinesCallback, &callbackParameters))
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "Failed enumerate the available pipelines " << this->getArchwayErrorString().c_str() << "\n";
|
||||
}
|
||||
|
||||
return enginePipelines;
|
||||
}
|
||||
|
||||
std::vector<SPipelineParameter> CArchwayHandler::getPipelineParameters(const size_t pipelineClassID) const
|
||||
{
|
||||
assert(m_Archway);
|
||||
|
||||
std::vector<SPipelineParameter> pipelineParameters;
|
||||
std::map<std::string, std::string> const* pipelineSettings = nullptr;
|
||||
|
||||
if (m_pipelineSettings.count(pipelineClassID) != 0) { pipelineSettings = &m_pipelineSettings.at(pipelineClassID); }
|
||||
|
||||
auto callbackParameters = std::make_pair(&pipelineParameters, pipelineSettings);
|
||||
|
||||
const size_t pipelineID = m_archway->createPipeline(pipelineClassID, "");
|
||||
|
||||
if (!m_archway->enumeratePipelineParameters(pipelineID, enumeratePipelineParametersCallback, &callbackParameters))
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "Failed enumerate the pipeline's parameters " << this->getArchwayErrorString().c_str() <<
|
||||
"\n";
|
||||
}
|
||||
|
||||
if (!m_archway->releasePipeline(pipelineID))
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "Failed to release pipeline " << this->getArchwayErrorString().c_str() << "\n";
|
||||
}
|
||||
|
||||
return pipelineParameters;
|
||||
}
|
||||
|
||||
std::string CArchwayHandler::getPipelineScenarioPath(size_t pipelineClassID) const
|
||||
{
|
||||
assert(m_Archway);
|
||||
|
||||
char messageBuffer[2048];
|
||||
std::string logMessages;
|
||||
|
||||
if (!m_archway->getPipelineScenarioPath(pipelineClassID, messageBuffer, sizeof(messageBuffer))) { return ""; }
|
||||
return std::string(messageBuffer);
|
||||
}
|
||||
|
||||
|
||||
bool CArchwayHandler::setPipelineParameterValue(const size_t pipelineClassID, std::string const& parameterName, std::string const& parameterValue)
|
||||
{
|
||||
if (m_pipelineSettings.find(pipelineClassID) == m_pipelineSettings.end())
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Error << "Failed to set the value [" << parameterValue << "] to the parameter [" << parameterName <<
|
||||
"]. The pipeline class id is invalid.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (parameterValue != "") { m_pipelineSettings[pipelineClassID][parameterName] = parameterValue; }
|
||||
else
|
||||
{
|
||||
if (m_pipelineSettings.count(pipelineClassID) != 0)
|
||||
{
|
||||
if (m_pipelineSettings[pipelineClassID].count(parameterName) != 0)
|
||||
{
|
||||
m_pipelineSettings[pipelineClassID].erase(m_pipelineSettings[pipelineClassID].find(parameterName));
|
||||
if (m_pipelineSettings[pipelineClassID].size() == 0) { m_pipelineSettings.erase(m_pipelineSettings.find(pipelineClassID)); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// m_kernelCtx.getLogManager() << Kernel::LogLevel_Info << "Set [" << uiPipelineClassId << "/" << sParameterName << "] to [" << sParameterValue << "]\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CArchwayHandler::writeArchwayConfigurationFile()
|
||||
{
|
||||
std::ofstream file;
|
||||
FS::Files::openOFStream(file, ARCHWAY_CONFIG_FILE.c_str());
|
||||
|
||||
if (!file.good())
|
||||
{
|
||||
file.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
file << "config.server = '" << (m_EngineType == EEngineType::LAN ? "lan" : "local") << "'\n";
|
||||
file << "config.device[1] = '" << m_DeviceURL << "'\n";
|
||||
file.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CArchwayHandler::savePipelineConfigurations()
|
||||
{
|
||||
std::ofstream file;
|
||||
FS::Files::openOFStream(file, ARCHWAY_PIPELINES_CONFIG_FILE.c_str());
|
||||
|
||||
if (!file.good())
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "Cannot open file for writing\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto& pipeline : m_pipelineSettings)
|
||||
{
|
||||
for (auto& setting : pipeline.second) { file << pipeline.first << "\t" << setting.first << "\t" << setting.second << "\n"; }
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CArchwayHandler::loadPipelineConfigurations()
|
||||
{
|
||||
std::ifstream file;
|
||||
FS::Files::openIFStream(file, ARCHWAY_PIPELINES_CONFIG_FILE.c_str());
|
||||
|
||||
if (!file.good())
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Trace << "Cannot open Engine Pipeline Configuration file for reading\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
while (!file.eof())
|
||||
{
|
||||
size_t pipelineClassID;
|
||||
file >> pipelineClassID;
|
||||
|
||||
std::string parameterName;
|
||||
// The first one simply trashes the tab after the pipeline Id
|
||||
getline(file, parameterName, '\t');
|
||||
getline(file, parameterName, '\t');
|
||||
|
||||
std::string parameterValue;
|
||||
getline(file, parameterValue, '\n');
|
||||
|
||||
if (parameterValue != "")
|
||||
{
|
||||
m_pipelineSettings[pipelineClassID];
|
||||
m_pipelineSettings[pipelineClassID][parameterName] = parameterValue;
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace OpenViBE
|
||||
#endif
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef MENSIA_DISTRIBUTION
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <functional>
|
||||
|
||||
#include <openvibe/kernel/ovIKernelContext.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <system/ovCDynamicModule.h>
|
||||
|
||||
namespace OpenViBE {
|
||||
enum class EEngineType { Local, LAN };
|
||||
|
||||
enum class EEngineInitialisationStatus { Success, Failure, NotAvailable };
|
||||
|
||||
struct SPipelineParameter
|
||||
{
|
||||
std::string name;
|
||||
std::string defaultValue;
|
||||
std::string value;
|
||||
};
|
||||
|
||||
struct SPipeline
|
||||
{
|
||||
size_t id;
|
||||
std::string description;
|
||||
bool isConfigured;
|
||||
};
|
||||
|
||||
struct SArchwayBridge
|
||||
{
|
||||
std::function<bool()> isStarted;
|
||||
std::function<size_t(size_t)> getAvailableValueMatrixCount;
|
||||
std::function<std::vector<float>(size_t)> popValueMatrix;
|
||||
std::function<bool()> dropBuffers;
|
||||
};
|
||||
|
||||
struct SGUIBridge
|
||||
{
|
||||
std::function<void()> refreshStoppedEngine;
|
||||
};
|
||||
|
||||
class CArchwayHandler final
|
||||
{
|
||||
public:
|
||||
explicit CArchwayHandler(const Kernel::IKernelContext& ctx) : m_DeviceURL("simulator://"), m_kernelCtx(ctx) { }
|
||||
~CArchwayHandler();
|
||||
|
||||
EEngineInitialisationStatus initialize();
|
||||
bool uninitialize();
|
||||
|
||||
bool reinitializeArchway();
|
||||
std::vector<SPipeline> getEnginePipelines() const;
|
||||
std::vector<SPipelineParameter> getPipelineParameters(size_t pipelineClassID) const;
|
||||
bool setPipelineParameterValue(size_t pipelineClassID, std::string const& parameterName, std::string const& parameterValue);
|
||||
std::string getPipelineScenarioPath(size_t pipelineID) const;
|
||||
|
||||
bool startEngineWithPipeline(size_t pipelineClassID, bool isFastForward, bool shouldAcquireImpedance);
|
||||
bool loopEngine();
|
||||
bool stopEngine();
|
||||
|
||||
bool isEngineStarted();
|
||||
bool writeArchwayConfigurationFile();
|
||||
|
||||
std::map<std::string, std::string>& getPipelineSettings(const size_t pipelineClassID) { return m_pipelineSettings[pipelineClassID]; }
|
||||
|
||||
SArchwayBridge m_ArchwayBridge;
|
||||
SGUIBridge m_GUIBridge;
|
||||
std::string m_DeviceURL;
|
||||
EEngineType m_EngineType = EEngineType::Local;
|
||||
|
||||
private:
|
||||
bool initializeArchway();
|
||||
bool uninitializeArchway();
|
||||
bool savePipelineConfigurations();
|
||||
bool loadPipelineConfigurations();
|
||||
std::string getArchwayErrorString() const;
|
||||
|
||||
private:
|
||||
typedef void (*FPEnumerateAvailablePipelinesCallback)(size_t pipelineClassID, const char* pipelineDescription, void* userData);
|
||||
typedef void (*FPEnumeratePipelineParametersCallback)(size_t pipelineID, const char* parameterName, const char* parameterValue, void* userData);
|
||||
|
||||
struct ArchwayAPI
|
||||
{
|
||||
size_t (*getLastError)();
|
||||
const char* (*getErrorString)(size_t errorCode);
|
||||
|
||||
const char* (*getVersionDescription)();
|
||||
|
||||
void (*getConfigurationParameterAsString)(const char* configurationParameter, char* outputBuffer, size_t bufferLength);
|
||||
bool (*getPipelineScenarioPath)(size_t pipelineID, char* messageBuffer, size_t bufferLength);
|
||||
|
||||
bool (*initialize)(const char* login, const char* password, const char* applicationName, const char* configFilename);
|
||||
bool (*startAllAcquisitionDevices)();
|
||||
bool (*startImpedanceCheckOnAllAcquisitionDevices)();
|
||||
bool (*startEngine)();
|
||||
bool (*startEngineInFastForward)();
|
||||
bool (*stopEngine)();
|
||||
bool (*stopAllAcquisitionDevices)();
|
||||
bool (*uninitialize)();
|
||||
|
||||
bool (*enumerateAvailablePipelines)(FPEnumerateAvailablePipelinesCallback callback, void* userData);
|
||||
size_t (*createPipeline)(size_t pipelineClassID, const char* profileName);
|
||||
bool (*releasePipeline)(size_t pipelineID);
|
||||
bool (*isPipelineRunning)(size_t pipelineID);
|
||||
bool (*isPipelineInErrorState)(size_t pipelineID);
|
||||
|
||||
bool (*enumeratePipelineParameters)(size_t pipelineID, FPEnumeratePipelineParametersCallback callback, void* userData);
|
||||
bool (*setPipelineParameterAsString)(size_t pipelineID, const char* parameterName, const char* value);
|
||||
|
||||
bool (*mainloop)();
|
||||
size_t (*getPendingValueCount)(size_t pipelineID, size_t matrixOutputIdx);
|
||||
size_t (*getPendingValueDimension)(size_t pipelineID, size_t matrixOutputIdx);
|
||||
bool (*getPendingValue)(size_t pipelineID, size_t matrixOutputIdx, float* value);
|
||||
size_t (*getPendingLogMessageCount)(size_t pipelineID);
|
||||
bool (*getPendingLogMessage)(size_t pipelineID, size_t* logLevel, char* messageBuffer, size_t bufferSize);
|
||||
|
||||
bool (*dropPendingValues)(size_t pipelineID);
|
||||
bool (*dropPendingEvents)(size_t pipelineID);
|
||||
|
||||
bool (*isInitialized)();
|
||||
bool (*isAcquiring)();
|
||||
bool (*isStarted)();
|
||||
};
|
||||
|
||||
struct ArchwayAPI* m_archway = nullptr;
|
||||
System::CDynamicModule m_archwayModule;
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
|
||||
// Current Configuration
|
||||
std::map<size_t, std::map<std::string, std::string>> m_pipelineSettings;
|
||||
|
||||
static const std::string ARCHWAY_CONFIG_FILE;
|
||||
static const std::string ARCHWAY_PIPELINES_CONFIG_FILE;
|
||||
|
||||
size_t m_RunningPipelineId = 0;
|
||||
};
|
||||
} // namespace OpenViBE
|
||||
|
||||
#endif
|
||||
+482
@@ -0,0 +1,482 @@
|
||||
#ifdef MENSIA_DISTRIBUTION
|
||||
#include "ovdCArchwayHandlerGUI.h"
|
||||
#include <openvibe/ov_directories.h>
|
||||
#include <fs/Files.h>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <sstream>
|
||||
|
||||
#include "../ovdCApplication.h"
|
||||
#include "ovProcessUtilities.hpp"
|
||||
|
||||
#if defined TARGET_OS_Windows
|
||||
#define pclose _pclose
|
||||
#endif
|
||||
|
||||
namespace OpenViBE {
|
||||
|
||||
namespace {
|
||||
enum EnginePipelinesModelColumn
|
||||
{
|
||||
Column_PipelineId = 0,
|
||||
Column_PipelineHexId,
|
||||
Column_PipelineDescription,
|
||||
Column_PipelineIsConfigured
|
||||
};
|
||||
|
||||
enum PipelineConfigurationModelColumn
|
||||
{
|
||||
Column_SettingPipelineId = 0,
|
||||
Column_SettingName = 1,
|
||||
Column_SettingDefaultValue = 2,
|
||||
Column_SettingValue = 3
|
||||
};
|
||||
|
||||
void on_button_configure_acquisition_clicked(GtkMenuItem* menuItem, gpointer data)
|
||||
{
|
||||
auto gui = static_cast<CArchwayHandlerGUI*>(data);
|
||||
|
||||
const std::string configToolLaunchCmd = std::string(Directories::getBinDir().toASCIIString()) + "/mensia-device-configuration";
|
||||
//std::string configFilePath = std::string(getenv("USERPROFILE")) + "\\lib-mensia-engine.conf";
|
||||
|
||||
std::string escapedURL = gui->m_Controller.m_DeviceURL;
|
||||
|
||||
size_t startPosition = 0;
|
||||
while ((startPosition = escapedURL.find('\"', startPosition)) != std::string::npos)
|
||||
{
|
||||
escapedURL.replace(startPosition, 1, "\\\"");
|
||||
startPosition += 2; // Handles case where 'to' is a substring of 'from'
|
||||
}
|
||||
|
||||
|
||||
#if defined TARGET_OS_Windows
|
||||
std::string command = "\"\"" + configToolLaunchCmd + "\" --no-file \"" + escapedURL + "\"\"";
|
||||
for (std::string stringToEscape : { "^", "<", ">", "&", "|", "%" }) // ^ must be escaped first!
|
||||
{
|
||||
startPosition = 0;
|
||||
while ((startPosition = command.find(stringToEscape, startPosition)) != std::string::npos)
|
||||
{
|
||||
command.replace(startPosition, stringToEscape.size(), "^" + stringToEscape);
|
||||
startPosition += 1 + stringToEscape.size();
|
||||
}
|
||||
}
|
||||
#elif defined TARGET_OS_Linux || defined TARGET_OS_MacOS
|
||||
std::string command = configurationToolLaunchCmd + " --no-file \"" + escapedURL + "\"";
|
||||
#endif
|
||||
FILE* commandPipe = FS::Files::popen(command.c_str(), "r");
|
||||
|
||||
char buffer[512];
|
||||
std::stringstream urlStream;
|
||||
while (fgets(buffer, sizeof(buffer), commandPipe) != nullptr) { urlStream << buffer; }
|
||||
pclose(commandPipe);
|
||||
|
||||
auto deviceURL = urlStream.str();
|
||||
deviceURL = deviceURL.substr(0, deviceURL.length() - 1);
|
||||
|
||||
gui->m_Controller.m_DeviceURL = deviceURL;
|
||||
gui->m_Controller.writeArchwayConfigurationFile();
|
||||
}
|
||||
|
||||
void on_button_reinitialize_archway_clicked(GtkMenuItem*, gpointer data)
|
||||
{
|
||||
auto gui = static_cast<CArchwayHandlerGUI*>(data);
|
||||
const auto engineTypeCombobox = GTK_COMBO_BOX(gtk_builder_get_object(gui->m_Builder, "combobox-engine-connection-type"));
|
||||
gui->m_Controller.m_EngineType = (gtk_combo_box_get_active(engineTypeCombobox) == 0 ? EEngineType::Local : EEngineType::LAN);
|
||||
|
||||
gui->m_Controller.reinitializeArchway();
|
||||
gui->refreshEnginePipelines();
|
||||
}
|
||||
|
||||
void on_combobox_engine_type_changed(GtkComboBox*, gpointer data)
|
||||
{
|
||||
const auto gui = static_cast<CArchwayHandlerGUI*>(data);
|
||||
if (gtk_combo_box_get_active(gui->m_ComboBoxEngineType) == 0) { gtk_widget_set_sensitive(gui->m_ButtonLaunchEngine, FALSE); }
|
||||
else { gtk_widget_set_sensitive(gui->m_ButtonLaunchEngine, TRUE); }
|
||||
on_button_reinitialize_archway_clicked(nullptr, data);
|
||||
}
|
||||
|
||||
gboolean on_dialog_engine_configuration_delete_event(GtkDialog* dialog, GdkEvent*, gpointer data)
|
||||
{
|
||||
const auto gui = static_cast<CArchwayHandlerGUI*>(data);
|
||||
gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(gui->m_ButtonOpenEngineConfigurationDialog), false);
|
||||
gtk_widget_hide(GTK_WIDGET(dialog));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean on_dialog_pipeline_configuration_delete_event(GtkDialog* pDialog, GdkEvent*, gpointer)
|
||||
{
|
||||
gtk_dialog_response(pDialog, GTK_RESPONSE_CANCEL);
|
||||
gtk_widget_hide(GTK_WIDGET(pDialog));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void view_pipeline_config(CArchwayHandlerGUI* gui)
|
||||
{
|
||||
const auto treeModel = gtk_tree_view_get_model(GTK_TREE_VIEW(gui->m_TreeViewEnginePipelines));
|
||||
guint64 pipelineID;
|
||||
gtk_tree_model_get(treeModel, &gui->m_SelectedPipelineIter, Column_PipelineId, &pipelineID, -1);
|
||||
|
||||
gui->displayPipelineConfigurationDialog(size_t(pipelineID));
|
||||
|
||||
auto enginePipelines = gui->m_Controller.getEnginePipelines();
|
||||
for (const auto& pipeline : enginePipelines)
|
||||
{
|
||||
if (pipeline.id != pipelineID) { continue; }
|
||||
gtk_list_store_set(GTK_LIST_STORE(treeModel), &gui->m_SelectedPipelineIter, Column_PipelineIsConfigured, pipeline.isConfigured, -1);
|
||||
}
|
||||
}
|
||||
|
||||
void view_popup_menu_onOpenScenario(GtkWidget* menuitem, gpointer data)
|
||||
{
|
||||
auto gui = static_cast<CArchwayHandlerGUI*>(data);
|
||||
const auto treeModel = gtk_tree_view_get_model(GTK_TREE_VIEW(gui->m_TreeViewEnginePipelines));
|
||||
guint64 pipelineID;
|
||||
gtk_tree_model_get(treeModel, &gui->m_SelectedPipelineIter, Column_PipelineId, &pipelineID, -1);
|
||||
|
||||
if (gui->m_Controller.m_EngineType == EEngineType::Local)
|
||||
{
|
||||
const std::string path = gui->m_Controller.getPipelineScenarioPath(size_t(pipelineID));
|
||||
gui->m_Application->openScenario(path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void view_popup_menu_onConfItem(GtkWidget* menuitem, gpointer data)
|
||||
{
|
||||
const auto gui = static_cast<CArchwayHandlerGUI*>(data);
|
||||
view_pipeline_config(gui);
|
||||
}
|
||||
|
||||
void on_treeview_engine_pipelines_popup_menu(CArchwayHandlerGUI* gui, GdkEventButton* event)
|
||||
{
|
||||
GtkWidget* menu = gtk_menu_new();
|
||||
GtkWidget* openConfItem = gtk_menu_item_new_with_label("Open configuration file");
|
||||
g_signal_connect(openConfItem, "activate", GCallback(view_popup_menu_onConfItem), gui);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), openConfItem);
|
||||
|
||||
if (gui->m_Controller.m_EngineType == EEngineType::Local)
|
||||
{
|
||||
GtkWidget* openScenarioItem = gtk_menu_item_new_with_label("Open scenario");
|
||||
g_signal_connect(openScenarioItem, "activate", GCallback(view_popup_menu_onOpenScenario), gui);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), openScenarioItem);
|
||||
}
|
||||
|
||||
gtk_widget_show_all(menu);
|
||||
gtk_menu_popup(GTK_MENU(menu), nullptr, nullptr, nullptr, nullptr, event->button, gdk_event_get_time(reinterpret_cast<GdkEvent*>(event)));
|
||||
}
|
||||
|
||||
gboolean on_treeview_engine_pipelines_button_pressed(GtkWidget* treeView, GdkEventButton* event, gpointer userData)
|
||||
{
|
||||
// Only acknowledge, if it's a right click, or double click
|
||||
if (!(event->type == GDK_BUTTON_PRESS && event->button == 3) && !(event->type == GDK_2BUTTON_PRESS && event->button == 1)) { return FALSE; }
|
||||
|
||||
auto gui = static_cast<CArchwayHandlerGUI*>(userData);
|
||||
|
||||
GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(gui->m_TreeViewEnginePipelines));
|
||||
if (gtk_tree_selection_count_selected_rows(selection) == 1)
|
||||
{
|
||||
gtk_tree_selection_get_selected(selection, &gui->m_TreeModelEnginePipelines, &gui->m_SelectedPipelineIter);
|
||||
|
||||
// single click with the right mouse button
|
||||
if (event->type == GDK_BUTTON_PRESS && event->button == 3)
|
||||
{
|
||||
on_treeview_engine_pipelines_popup_menu(gui, event);
|
||||
return TRUE;
|
||||
}
|
||||
else if (event->type == GDK_2BUTTON_PRESS && event->button == 1)
|
||||
{
|
||||
view_pipeline_config(gui);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void startEngine(GtkWidget* widget, gpointer data, bool isFastForward)
|
||||
{
|
||||
auto gui = static_cast<CArchwayHandlerGUI*>(data);
|
||||
|
||||
// Get the currently selected pipeline in the list
|
||||
const auto selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(gui->m_TreeViewEnginePipelines));
|
||||
|
||||
if (gtk_tree_selection_count_selected_rows(selection) == 1)
|
||||
{
|
||||
gtk_tree_selection_get_selected(selection, &gui->m_TreeModelEnginePipelines, &gui->m_SelectedPipelineIter);
|
||||
|
||||
size_t pipelineID = 0;
|
||||
gtk_tree_model_get(gui->m_TreeModelEnginePipelines, &gui->m_SelectedPipelineIter, Column_PipelineId, &pipelineID, -1);
|
||||
|
||||
const bool shouldAcquireImpedance = (gtk_toggle_tool_button_get_active(gui->m_ToggleAcquireImpedance) == gboolean(true));
|
||||
if (gui->m_Controller.startEngineWithPipeline(size_t(pipelineID), isFastForward, shouldAcquireImpedance))
|
||||
{
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(gui->m_ToggleAcquireImpedance), false);
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(gui->m_ComboBoxEngineType), false);
|
||||
gtk_widget_set_sensitive(gui->m_ButtonConfigureAcquisition, false);
|
||||
gtk_widget_set_sensitive(gui->m_ButtonLaunchEngine, false);
|
||||
gtk_widget_set_sensitive(gui->m_ButtonStartEngine, false);
|
||||
gtk_widget_set_sensitive(gui->m_ButtonStartEngineFastFoward, false);
|
||||
gtk_widget_set_sensitive(gui->m_ButtonStopEngine, true);
|
||||
gtk_widget_set_sensitive(gui->m_TreeViewEnginePipelines, false);
|
||||
gtk_spinner_start(gui->m_SpinnerEngineActivity);
|
||||
gtk_widget_show(GTK_WIDGET(gui->m_SpinnerEngineActivity));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto alertDialog = gtk_message_dialog_new(nullptr, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, "Please select a pipeline to run.");
|
||||
gtk_dialog_run(GTK_DIALOG(alertDialog));
|
||||
gtk_widget_destroy(alertDialog);
|
||||
}
|
||||
}
|
||||
|
||||
void on_button_start_engine_clicked(GtkWidget* widget, gpointer data) { startEngine(widget, data, false); }
|
||||
|
||||
void on_button_start_engine_fast_forward_clicked(GtkWidget* widget, gpointer data) { startEngine(widget, data, true); }
|
||||
|
||||
void on_button_stop_engine_clicked(GtkWidget* widget, gpointer data)
|
||||
{
|
||||
auto gui = static_cast<CArchwayHandlerGUI*>(data);
|
||||
|
||||
if (gui->m_Controller.stopEngine())
|
||||
{
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(gui->m_ToggleAcquireImpedance), true);
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(gui->m_ComboBoxEngineType), true);
|
||||
gtk_widget_set_sensitive(gui->m_ButtonConfigureAcquisition, true);
|
||||
gtk_widget_set_sensitive(gui->m_ButtonLaunchEngine, true);
|
||||
gtk_widget_set_sensitive(gui->m_ButtonStartEngine, true);
|
||||
gtk_widget_set_sensitive(gui->m_ButtonStartEngineFastFoward, true);
|
||||
gtk_widget_set_sensitive(gui->m_ButtonStopEngine, false);
|
||||
gtk_widget_set_sensitive(gui->m_TreeViewEnginePipelines, true);
|
||||
gtk_spinner_stop(gui->m_SpinnerEngineActivity);
|
||||
gtk_widget_hide(GTK_WIDGET(gui->m_SpinnerEngineActivity));
|
||||
}
|
||||
}
|
||||
|
||||
void on_button_pipeline_configuration_apply_clicked(GtkWidget* widget, gpointer)
|
||||
{
|
||||
GtkWidget* dialog = gtk_widget_get_parent(gtk_widget_get_parent((gtk_widget_get_parent(widget))));
|
||||
gtk_dialog_response(GTK_DIALOG(dialog), GTK_RESPONSE_APPLY);
|
||||
gtk_widget_hide(dialog);
|
||||
}
|
||||
|
||||
void on_button_pipeline_configuration_cancel_clicked(GtkWidget* widget, gpointer)
|
||||
{
|
||||
GtkWidget* dialog = gtk_widget_get_parent(gtk_widget_get_parent((gtk_widget_get_parent(widget))));
|
||||
gtk_dialog_response(GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL);
|
||||
gtk_widget_hide(dialog);
|
||||
}
|
||||
|
||||
void on_pipeline_configuration_cellrenderer_parameter_value_edited(GtkCellRendererText* cell, gchar* path, gchar* newText, gpointer data)
|
||||
{
|
||||
auto gui = static_cast<CArchwayHandlerGUI*>(data);
|
||||
gui->setPipelineParameterValueAtPath(path, newText);
|
||||
}
|
||||
|
||||
gboolean on_pipeline_configuration_cellrenderer_parameter_value_entry_focus_out(GtkWidget* widget, GdkEvent* event, gpointer data)
|
||||
{
|
||||
auto gui = static_cast<CArchwayHandlerGUI*>(data);
|
||||
const auto entry = GTK_ENTRY(widget);
|
||||
gui->setPipelineParameterValueAtPath(gui->m_CurrentlyEditedCellPath.c_str(), gtk_entry_get_text(entry));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void on_pipeline_configuration_cellrenderer_parameter_value_editing_started(GtkCellRenderer* cell, GtkCellEditable* editable, gchar* path, gpointer data)
|
||||
{
|
||||
auto gui = static_cast<CArchwayHandlerGUI*>(data);
|
||||
|
||||
// As we are sending data to a callback created within a callback, we really want to avoid
|
||||
// allocating memory.
|
||||
gui->m_CurrentlyEditedCellPath = path;
|
||||
|
||||
const auto entry = GTK_ENTRY(editable);
|
||||
g_signal_connect(G_OBJECT(entry),
|
||||
"focus-out-event",
|
||||
G_CALLBACK(on_pipeline_configuration_cellrenderer_parameter_value_entry_focus_out), data);
|
||||
}
|
||||
|
||||
|
||||
void on_button_launch_engine_clicked(GtkWidget* widget, gpointer data)
|
||||
{
|
||||
// auto gui = static_cast<CArchwayHandlerGUI*>(data);
|
||||
|
||||
if (!ProcessUtilities::doesProcessExist("mensia-engine-server"))
|
||||
{
|
||||
#if defined TARGET_OS_Windows
|
||||
if (FS::Files::fileExists(Directories::getBinDir() + "/mensia-engine-server.exe"))
|
||||
{
|
||||
ProcessUtilities::launchCommand(std::string(Directories::getBinDir() + "/mensia-engine-server.exe").c_str());
|
||||
}
|
||||
else if (FS::Files::fileExists("C:/Program Files (x86)/NeuroRT/NeuroRT Engine Server/bin/mensia-engine-server.exe"))
|
||||
{
|
||||
ProcessUtilities::launchCommand(std::string("C:/Program Files (x86)/NeuroRT/NeuroRT Engine Server/neurort-engine-server.cmd").c_str());
|
||||
}
|
||||
#elif defined TARGET_OS_Linux || defined TARGET_OS_MacOS
|
||||
if (FS::Files::fileExists(Directories::getBinDir() + "/mensia-engine-server"))
|
||||
{
|
||||
ProcessUtilities::launchCommand(std::string(Directories::getBinDir() + "/mensia-engine-server").c_str());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CArchwayHandlerGUI::CArchwayHandlerGUI(CArchwayHandler& controller, Designer::CApplication* application)
|
||||
: m_Controller(controller), m_Application(application)
|
||||
{
|
||||
m_Builder = gtk_builder_new();
|
||||
GError* gtkError = nullptr;
|
||||
gtk_builder_add_from_file(m_Builder, Directories::getDataDir() + "/applications/designer/interface-archway.ui", >kError);
|
||||
|
||||
assert(gtkError == nullptr);
|
||||
// gtk_builder_connect_signals(m_builder, nullptr);
|
||||
|
||||
|
||||
m_ButtonConfigureAcquisition = GTK_WIDGET(gtk_builder_get_object(m_Builder, "button-configure-acquisition"));
|
||||
g_signal_connect(G_OBJECT(m_ButtonConfigureAcquisition), "clicked", G_CALLBACK(on_button_configure_acquisition_clicked), this);
|
||||
|
||||
m_ButtonReinitializeArchway = GTK_WIDGET(gtk_builder_get_object(m_Builder, "button-reinitialize-archway"));
|
||||
g_signal_connect(G_OBJECT(m_ButtonReinitializeArchway), "clicked", G_CALLBACK(on_button_reinitialize_archway_clicked), this);
|
||||
|
||||
g_signal_connect(G_OBJECT(gtk_builder_get_object(m_Builder, "button-pipeline-configuration-apply")),
|
||||
"clicked", G_CALLBACK(on_button_pipeline_configuration_apply_clicked), this);
|
||||
|
||||
g_signal_connect(G_OBJECT(gtk_builder_get_object(m_Builder, "button-pipeline-configuration-cancel")),
|
||||
"clicked", G_CALLBACK(on_button_pipeline_configuration_cancel_clicked), this);
|
||||
|
||||
m_SpinnerEngineActivity = GTK_SPINNER(gtk_builder_get_object(m_Builder, "spinner-engine-activity"));
|
||||
gtk_widget_hide(GTK_WIDGET(m_SpinnerEngineActivity));
|
||||
|
||||
m_ToggleAcquireImpedance = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(m_Builder, "toggle-acquire-impedance"));
|
||||
|
||||
m_ButtonStartEngine = GTK_WIDGET(gtk_builder_get_object(m_Builder, "button-start-engine"));
|
||||
m_ButtonStartEngineFastFoward = GTK_WIDGET(gtk_builder_get_object(m_Builder, "button-start-engine-fast"));
|
||||
m_ButtonStopEngine = GTK_WIDGET(gtk_builder_get_object(m_Builder, "button-stop-engine"));
|
||||
gtk_widget_set_sensitive(m_ButtonStopEngine, false);
|
||||
|
||||
g_signal_connect(G_OBJECT(m_ButtonStartEngine), "clicked", G_CALLBACK(on_button_start_engine_clicked), this);
|
||||
g_signal_connect(G_OBJECT(m_ButtonStartEngineFastFoward), "clicked", G_CALLBACK(on_button_start_engine_fast_forward_clicked), this);
|
||||
g_signal_connect(G_OBJECT(m_ButtonStopEngine), "clicked", G_CALLBACK(on_button_stop_engine_clicked), this);
|
||||
|
||||
g_signal_connect(G_OBJECT(gtk_builder_get_object(m_Builder, "dialog-engine-configuration")),
|
||||
"delete-event", G_CALLBACK(on_dialog_engine_configuration_delete_event), this);
|
||||
|
||||
g_signal_connect(G_OBJECT(gtk_builder_get_object(m_Builder, "dialog-pipeline-configuration")),
|
||||
"delete-event", G_CALLBACK(on_dialog_pipeline_configuration_delete_event), this);
|
||||
|
||||
m_TreeViewEnginePipelines = GTK_WIDGET(gtk_builder_get_object(m_Builder, "treeview-engine-pipelines"));
|
||||
g_signal_connect(m_TreeViewEnginePipelines, "button-press-event", GCallback(on_treeview_engine_pipelines_button_pressed), this);
|
||||
|
||||
g_signal_connect(G_OBJECT(gtk_builder_get_object(m_Builder, "pipeline-configuration-cellrenderer-parameter-value")),
|
||||
"edited",
|
||||
G_CALLBACK(on_pipeline_configuration_cellrenderer_parameter_value_edited), this);
|
||||
|
||||
g_signal_connect(G_OBJECT(gtk_builder_get_object(m_Builder, "pipeline-configuration-cellrenderer-parameter-value")),
|
||||
"editing-started",
|
||||
G_CALLBACK(on_pipeline_configuration_cellrenderer_parameter_value_editing_started), this);
|
||||
|
||||
m_TreeModelEnginePipelines = GTK_TREE_MODEL(gtk_builder_get_object(m_Builder, "liststore-pipelines"));
|
||||
|
||||
m_Controller.m_GUIBridge.refreshStoppedEngine = [this]()
|
||||
{
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(m_ToggleAcquireImpedance), true);
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(m_ComboBoxEngineType), true);
|
||||
gtk_widget_set_sensitive(m_ButtonConfigureAcquisition, true);
|
||||
gtk_widget_set_sensitive(m_ButtonLaunchEngine, true);
|
||||
gtk_widget_set_sensitive(m_ButtonStartEngine, true);
|
||||
gtk_widget_set_sensitive(m_ButtonStartEngineFastFoward, true);
|
||||
gtk_widget_set_sensitive(m_ButtonStopEngine, false);
|
||||
gtk_widget_set_sensitive(m_TreeViewEnginePipelines, true);
|
||||
gtk_spinner_stop(m_SpinnerEngineActivity);
|
||||
gtk_widget_hide(GTK_WIDGET(m_SpinnerEngineActivity));
|
||||
};
|
||||
|
||||
m_ComboBoxEngineType = GTK_COMBO_BOX(gtk_builder_get_object(m_Builder, "combobox-engine-connection-type"));
|
||||
g_signal_connect(G_OBJECT(m_ComboBoxEngineType), "changed", G_CALLBACK(on_combobox_engine_type_changed), this);
|
||||
|
||||
m_ButtonLaunchEngine = GTK_WIDGET(gtk_builder_get_object(m_Builder, "button-launch-engine-server"));
|
||||
g_signal_connect(G_OBJECT(m_ButtonLaunchEngine), "clicked", G_CALLBACK(on_button_launch_engine_clicked), this);
|
||||
}
|
||||
|
||||
CArchwayHandlerGUI::~CArchwayHandlerGUI() { if (m_Builder) { g_object_unref(G_OBJECT(m_Builder)); } }
|
||||
|
||||
void CArchwayHandlerGUI::refreshEnginePipelines()
|
||||
{
|
||||
const auto listStorePipelines = GTK_LIST_STORE(m_TreeModelEnginePipelines);
|
||||
|
||||
gtk_list_store_clear(listStorePipelines);
|
||||
auto enginePipelines = m_Controller.getEnginePipelines();
|
||||
GtkTreeIter iter;
|
||||
for (auto& pipeline : enginePipelines)
|
||||
{
|
||||
std::stringstream pipelineIdInHex;
|
||||
pipelineIdInHex << std::hex << pipeline.id;
|
||||
|
||||
gtk_list_store_append(listStorePipelines, &iter);
|
||||
gtk_list_store_set(listStorePipelines, &iter, Column_PipelineId, pipeline.id, Column_PipelineHexId, pipelineIdInHex.str().c_str(),
|
||||
Column_PipelineDescription, pipeline.description.c_str(), Column_PipelineIsConfigured, pipeline.isConfigured, -1);
|
||||
}
|
||||
}
|
||||
|
||||
void CArchwayHandlerGUI::toggleNeuroRTEngineConfigurationDialog(const bool shouldDisplay)
|
||||
{
|
||||
const auto engineConfigurationWidget = GTK_WIDGET(gtk_builder_get_object(m_Builder, "dialog-engine-configuration"));
|
||||
|
||||
if (shouldDisplay)
|
||||
{
|
||||
gtk_combo_box_set_active(m_ComboBoxEngineType, m_Controller.m_EngineType == EEngineType::Local ? 0 : 1);
|
||||
this->refreshEnginePipelines();
|
||||
gtk_widget_show(engineConfigurationWidget);
|
||||
}
|
||||
else { gtk_widget_hide(engineConfigurationWidget); }
|
||||
}
|
||||
|
||||
void CArchwayHandlerGUI::displayPipelineConfigurationDialog(const size_t pipelineID)
|
||||
{
|
||||
const auto pipelineConfigurationWidget = GTK_WIDGET(gtk_builder_get_object(m_Builder, "dialog-pipeline-configuration"));
|
||||
const auto pipelineConfigurationListStore = GTK_LIST_STORE(gtk_builder_get_object(m_Builder, "liststore-pipeline-configuration"));
|
||||
|
||||
gtk_list_store_clear(pipelineConfigurationListStore);
|
||||
|
||||
auto pipelineParameters = m_Controller.getPipelineParameters(pipelineID);
|
||||
|
||||
GtkTreeIter iter;
|
||||
for (auto& parameter : pipelineParameters)
|
||||
{
|
||||
gtk_list_store_append(pipelineConfigurationListStore, &iter);
|
||||
gtk_list_store_set(pipelineConfigurationListStore, &iter,
|
||||
Column_SettingPipelineId, static_cast<size_t>(pipelineID),
|
||||
Column_SettingName, parameter.name.c_str(),
|
||||
Column_SettingDefaultValue, parameter.defaultValue.c_str(),
|
||||
Column_SettingValue, parameter.value.c_str(),
|
||||
-1);
|
||||
}
|
||||
|
||||
const auto savedSettings = m_Controller.getPipelineSettings(pipelineID);
|
||||
const auto response = gtk_dialog_run(GTK_DIALOG(pipelineConfigurationWidget));
|
||||
if (response == GTK_RESPONSE_CANCEL) { m_Controller.getPipelineSettings(pipelineID) = savedSettings; }
|
||||
}
|
||||
|
||||
bool CArchwayHandlerGUI::setPipelineParameterValueAtPath(gchar const* path, gchar const* value)
|
||||
{
|
||||
const auto pipelineConfigurationListStore =
|
||||
GTK_TREE_MODEL(gtk_builder_get_object(this->m_Builder, "liststore-pipeline-configuration"));
|
||||
|
||||
GtkTreeIter iter;
|
||||
gboolean valid = gtk_tree_model_get_iter_from_string(pipelineConfigurationListStore, &iter, path);
|
||||
assert(valid);
|
||||
|
||||
size_t id = 0;
|
||||
gchar* name;
|
||||
|
||||
gtk_tree_model_get(pipelineConfigurationListStore, &iter, Column_SettingName, &name, -1);
|
||||
gtk_tree_model_get(pipelineConfigurationListStore, &iter, Column_SettingPipelineId, &id, -1);
|
||||
gtk_list_store_set(GTK_LIST_STORE(pipelineConfigurationListStore), &iter, Column_SettingValue, value, -1);
|
||||
|
||||
this->m_Controller.setPipelineParameterValue(size_t(id), name, value);
|
||||
g_free(name);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace OpenViBE
|
||||
#endif
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef MENSIA_DISTRIBUTION
|
||||
|
||||
#include "ovdCArchwayHandler.h"
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
class CApplication;
|
||||
}
|
||||
}
|
||||
|
||||
namespace OpenViBE {
|
||||
class CArchwayHandlerGUI final
|
||||
{
|
||||
public:
|
||||
CArchwayHandlerGUI(CArchwayHandler& controller, Designer::CApplication* application);
|
||||
~CArchwayHandlerGUI();
|
||||
|
||||
void refreshEnginePipelines();
|
||||
void toggleNeuroRTEngineConfigurationDialog(const bool shouldDisplay);
|
||||
void displayPipelineConfigurationDialog(const size_t pipelineID);
|
||||
|
||||
bool setPipelineParameterValueAtPath(gchar const* path, gchar const* value);
|
||||
|
||||
GtkBuilder* m_Builder = nullptr;
|
||||
GtkBuilder* m_ApplicationBuilder = nullptr;
|
||||
CArchwayHandler& m_Controller;
|
||||
Designer::CApplication* m_Application = nullptr;
|
||||
|
||||
// This variable is used to store the path of an edited cell
|
||||
// while editing the PipelineParameters.
|
||||
std::string m_CurrentlyEditedCellPath;
|
||||
|
||||
GtkWidget* m_ButtonOpenEngineConfigurationDialog = nullptr;
|
||||
|
||||
GtkWidget* m_ButtonConfigureAcquisition = nullptr;
|
||||
GtkToggleToolButton* m_ToggleAcquireImpedance = nullptr;
|
||||
|
||||
GtkComboBox* m_ComboBoxEngineType = nullptr;
|
||||
GtkWidget* m_ButtonReinitializeArchway = nullptr;
|
||||
GtkWidget* m_ButtonLaunchEngine = nullptr;
|
||||
|
||||
GtkWidget* m_ButtonStartEngine = nullptr;
|
||||
GtkWidget* m_ButtonStartEngineFastFoward = nullptr;
|
||||
GtkWidget* m_ButtonStopEngine = nullptr;
|
||||
|
||||
GtkWidget* m_TreeViewEnginePipelines = nullptr;
|
||||
|
||||
GtkSpinner* m_SpinnerEngineActivity = nullptr;
|
||||
|
||||
GtkTreeModel* m_TreeModelEnginePipelines = nullptr;
|
||||
GtkTreeIter m_SelectedPipelineIter;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
#include "ovdCAbstractSettingView.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
|
||||
static void CollectWidgetCB(GtkWidget* widget, gpointer data) { static_cast<std::vector<GtkWidget*>*>(data)->push_back(widget); }
|
||||
|
||||
CAbstractSettingView::~CAbstractSettingView()
|
||||
{
|
||||
if (GTK_IS_WIDGET(m_nameWidget)) { gtk_widget_destroy(m_nameWidget); }
|
||||
if (GTK_IS_WIDGET(m_entryNameWidget)) { gtk_widget_destroy(m_entryNameWidget); }
|
||||
if (G_IS_OBJECT(m_builder)) { g_object_unref(m_builder); }
|
||||
}
|
||||
|
||||
CAbstractSettingView::CAbstractSettingView(Kernel::IBox& box, const size_t index, const char* builderName, const char* widgetName)
|
||||
: m_box(box), m_index(index), m_settingWidgetName("")
|
||||
{
|
||||
if (builderName != nullptr)
|
||||
{
|
||||
m_builder = gtk_builder_new();
|
||||
gtk_builder_add_from_file(m_builder, builderName, nullptr);
|
||||
gtk_builder_connect_signals(m_builder, nullptr);
|
||||
|
||||
if (widgetName != nullptr)
|
||||
{
|
||||
m_settingWidgetName = widgetName;
|
||||
CAbstractSettingView::generateNameWidget();
|
||||
m_entryFieldWidget = CAbstractSettingView::generateEntryWidget();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CAbstractSettingView::setNameWidget(GtkWidget* widget)
|
||||
{
|
||||
if (m_nameWidget) { gtk_widget_destroy(m_nameWidget); }
|
||||
m_nameWidget = widget;
|
||||
}
|
||||
|
||||
void CAbstractSettingView::setEntryWidget(GtkWidget* widget)
|
||||
{
|
||||
if (m_entryNameWidget) { gtk_widget_destroy(m_entryNameWidget); }
|
||||
m_entryNameWidget = widget;
|
||||
}
|
||||
|
||||
void CAbstractSettingView::generateNameWidget()
|
||||
{
|
||||
GtkWidget* settingName = GTK_WIDGET(gtk_builder_get_object(m_builder, "settings_collection-label_setting_name"));
|
||||
gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(settingName)), settingName);
|
||||
setNameWidget(settingName);
|
||||
|
||||
CString name;
|
||||
getBox().getSettingName(m_index, name);
|
||||
gtk_label_set_text(GTK_LABEL(settingName), name);
|
||||
}
|
||||
|
||||
GtkWidget* CAbstractSettingView::generateEntryWidget()
|
||||
{
|
||||
GtkTable* table = GTK_TABLE(gtk_table_new(1, 3, false));
|
||||
|
||||
GtkWidget* settingWidget = GTK_WIDGET(gtk_builder_get_object(m_builder, m_settingWidgetName.toASCIIString()));
|
||||
GtkWidget* settingRevert = GTK_WIDGET(gtk_builder_get_object(m_builder, "settings_collection-button_setting_revert"));
|
||||
GtkWidget* settingDefault = GTK_WIDGET(gtk_builder_get_object(m_builder, "settings_collection-button_setting_default"));
|
||||
|
||||
gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(settingWidget)), settingWidget);
|
||||
gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(settingRevert)), settingRevert);
|
||||
gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(settingDefault)), settingDefault);
|
||||
|
||||
gtk_table_attach(table, settingWidget, 0, 1, 0, 1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(GTK_FILL | GTK_EXPAND), 0, 0);
|
||||
//gtk_table_attach(m_table, settingDefault, 1, 2, 0, 1, GtkAttachOptions(GTK_SHRINK), GtkAttachOptions(GTK_SHRINK), 0, 0);
|
||||
//gtk_table_attach(m_table, settingRevert, 2, 3, 0, 1, GtkAttachOptions(GTK_SHRINK), GtkAttachOptions(GTK_SHRINK), 0, 0);
|
||||
|
||||
setEntryWidget(GTK_WIDGET(table));
|
||||
gtk_widget_set_visible(getEntryWidget(), true);
|
||||
//If we don't increase the ref counter it will cause trouble when we gonna move it later
|
||||
g_object_ref(G_OBJECT(table));
|
||||
return settingWidget;
|
||||
}
|
||||
|
||||
void CAbstractSettingView::initializeValue()
|
||||
{
|
||||
CString value;
|
||||
getBox().getSettingValue(m_index, value);
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
void CAbstractSettingView::extractWidget(GtkWidget* widget, std::vector<GtkWidget*>& widgets)
|
||||
{
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), CollectWidgetCB, &widgets);
|
||||
}
|
||||
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ovd_base.h"
|
||||
#include <cstdlib> // size_t for unix
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
class CAbstractSettingView
|
||||
{
|
||||
public:
|
||||
virtual ~CAbstractSettingView();
|
||||
|
||||
//Store the value of the setting in value
|
||||
virtual void getValue(CString& value) const = 0;
|
||||
//Set the view with the value contains in value
|
||||
virtual void setValue(const CString& value) = 0;
|
||||
|
||||
//Get the label which contains the name of the setting
|
||||
virtual GtkWidget* getNameWidget() { return m_nameWidget; }
|
||||
//Get the table of widget which display the value of the setting (the entry and all interaction buttons)
|
||||
virtual GtkWidget* getEntryWidget() { return m_entryNameWidget; }
|
||||
|
||||
//This function is use to update the setting index when a setting is suppressed or inserted
|
||||
virtual void setSettingIndex(const size_t index) { m_index = index; }
|
||||
|
||||
//Get the index of the setting
|
||||
virtual size_t getSettingIndex() { return m_index; }
|
||||
|
||||
protected:
|
||||
//Initialize the common part of all view. If builderName and widgetName are not nullptr, the entryTable and the label
|
||||
//will be set according to these informations.
|
||||
//If there are nullptr, name and entry widget will have to be set after with corresponding setter.
|
||||
CAbstractSettingView(Kernel::IBox& box, const size_t index, const char* builderName, const char* widgetName);
|
||||
|
||||
//Return the box which contains the setting
|
||||
virtual Kernel::IBox& getBox() { return m_box; }
|
||||
|
||||
|
||||
//Set the widget as the new widget name
|
||||
virtual void setNameWidget(GtkWidget* widget);
|
||||
//Set the widget as the new widget name
|
||||
virtual void setEntryWidget(GtkWidget* widget);
|
||||
|
||||
//Set the setting view with the current value of the setting
|
||||
virtual void initializeValue();
|
||||
|
||||
//Return a vector which contains the list of the widget contains int the widget widget
|
||||
virtual void extractWidget(GtkWidget* widget, std::vector<GtkWidget*>& widgets);
|
||||
|
||||
//Return the part of the entry table which is not revert or default button
|
||||
virtual GtkWidget* getEntryFieldWidget() { return m_entryFieldWidget; }
|
||||
|
||||
private:
|
||||
//Generate the label of the setting
|
||||
virtual void generateNameWidget();
|
||||
//Generate the table of widget which display the value of the setting (the entry and all interaction buttons)
|
||||
virtual GtkWidget* generateEntryWidget();
|
||||
|
||||
|
||||
Kernel::IBox& m_box;
|
||||
size_t m_index = 0;
|
||||
CString m_settingWidgetName;
|
||||
GtkWidget* m_nameWidget = nullptr;
|
||||
GtkWidget* m_entryNameWidget = nullptr;
|
||||
GtkWidget* m_entryFieldWidget = nullptr;
|
||||
|
||||
//If we don't store the builder, the setting name will be free when we'll unref the builder
|
||||
GtkBuilder* m_builder = nullptr;
|
||||
};
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
#include "ovdCBitMaskSettingView.h"
|
||||
#include "../ovd_base.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
|
||||
static void OnCheckbuttonPressed(GtkToggleButton* /*button*/, gpointer data) { static_cast<CBitMaskSettingView*>(data)->onChange(); }
|
||||
|
||||
CBitMaskSettingView::CBitMaskSettingView(Kernel::IBox& box, const size_t index, CString& builderName, const Kernel::IKernelContext& ctx,
|
||||
const CIdentifier& typeID)
|
||||
: CAbstractSettingView(box, index, builderName, "settings_collection-table_setting_bitmask"), m_typeID(typeID), m_kernelCtx(ctx)
|
||||
{
|
||||
GtkWidget* settingWidget = CAbstractSettingView::getEntryFieldWidget();
|
||||
|
||||
const gint tableSize = guint((m_kernelCtx.getTypeManager().getBitMaskEntryCount(m_typeID) + 1) >> 1);
|
||||
GtkTable* bitMaskTable = GTK_TABLE(settingWidget);
|
||||
gtk_table_resize(bitMaskTable, 2, tableSize);
|
||||
|
||||
for (size_t i = 0; i < m_kernelCtx.getTypeManager().getBitMaskEntryCount(m_typeID); ++i)
|
||||
{
|
||||
CString name;
|
||||
uint64_t value;
|
||||
if (m_kernelCtx.getTypeManager().getBitMaskEntry(m_typeID, i, name, value))
|
||||
{
|
||||
GtkWidget* button = gtk_check_button_new();
|
||||
gtk_table_attach_defaults(bitMaskTable, button, guint(i & 1), guint((i & 1) + 1), guint(i >> 1), guint((i >> 1) + 1));
|
||||
gtk_button_set_label(GTK_BUTTON(button), name.toASCIIString());
|
||||
m_toggleButton.push_back(GTK_TOGGLE_BUTTON(button));
|
||||
g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(OnCheckbuttonPressed), this);
|
||||
}
|
||||
}
|
||||
gtk_widget_show_all(GTK_WIDGET(bitMaskTable));
|
||||
|
||||
CAbstractSettingView::initializeValue();
|
||||
}
|
||||
|
||||
|
||||
void CBitMaskSettingView::getValue(CString& value) const
|
||||
{
|
||||
std::string res;
|
||||
for (auto& toggle : m_toggleButton)
|
||||
{
|
||||
if (gtk_toggle_button_get_active(toggle))
|
||||
{
|
||||
if (!res.empty()) { res += ':'; }
|
||||
res += gtk_button_get_label(GTK_BUTTON(toggle));
|
||||
}
|
||||
}
|
||||
value = res.c_str();
|
||||
}
|
||||
|
||||
void CBitMaskSettingView::setValue(const CString& value)
|
||||
{
|
||||
m_onValueSetting = true;
|
||||
const std::string str(value);
|
||||
|
||||
for (auto& toggle : m_toggleButton)
|
||||
{
|
||||
const gchar* label = gtk_button_get_label(GTK_BUTTON(toggle));
|
||||
if (str.find(label) != std::string::npos) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), true); }
|
||||
else { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), false); }
|
||||
}
|
||||
|
||||
m_onValueSetting = false;
|
||||
}
|
||||
|
||||
void CBitMaskSettingView::onChange()
|
||||
{
|
||||
if (!m_onValueSetting)
|
||||
{
|
||||
CString value;
|
||||
this->getValue(value);
|
||||
getBox().setSettingValue(getSettingIndex(), value);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ovd_base.h"
|
||||
#include "ovdCAbstractSettingView.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
class CBitMaskSettingView final : public CAbstractSettingView
|
||||
{
|
||||
public:
|
||||
CBitMaskSettingView(Kernel::IBox& box, const size_t index, CString& builderName, const Kernel::IKernelContext& ctx, const CIdentifier& typeID);
|
||||
|
||||
void getValue(CString& value) const override;
|
||||
void setValue(const CString& value) override;
|
||||
|
||||
void onChange();
|
||||
|
||||
private:
|
||||
CIdentifier m_typeID = CIdentifier::undefined();
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
|
||||
std::vector<GtkToggleButton*> m_toggleButton;
|
||||
bool m_onValueSetting = false;
|
||||
};
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
#include "ovdCBooleanSettingView.h"
|
||||
#include "../ovd_base.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
|
||||
static void OnCheckbuttonSettingBooleanPressed(GtkToggleButton* /*button*/, gpointer data) { static_cast<CBooleanSettingView*>(data)->toggleButtonClick(); }
|
||||
|
||||
static void OnInsertion(GtkEntry* /*entry*/, gpointer data) { static_cast<CBooleanSettingView*>(data)->onChange(); }
|
||||
|
||||
CBooleanSettingView::CBooleanSettingView(Kernel::IBox& box, const size_t index, CString& builderName)
|
||||
: CAbstractSettingView(box, index, builderName, "settings_collection-hbox_setting_boolean")
|
||||
{
|
||||
GtkWidget* settingWidget = CAbstractSettingView::getEntryFieldWidget();
|
||||
|
||||
std::vector<GtkWidget*> widgets;
|
||||
CAbstractSettingView::extractWidget(settingWidget, widgets);
|
||||
m_toggle = GTK_TOGGLE_BUTTON(widgets[1]);
|
||||
m_entry = GTK_ENTRY(widgets[0]);
|
||||
|
||||
g_signal_connect(G_OBJECT(m_entry), "changed", G_CALLBACK(OnInsertion), this);
|
||||
g_signal_connect(G_OBJECT(m_toggle), "toggled", G_CALLBACK(OnCheckbuttonSettingBooleanPressed), this);
|
||||
|
||||
CAbstractSettingView::initializeValue();
|
||||
}
|
||||
|
||||
void CBooleanSettingView::getValue(CString& value) const { value = CString(gtk_entry_get_text(m_entry)); }
|
||||
|
||||
void CBooleanSettingView::setValue(const CString& value)
|
||||
{
|
||||
m_onValueSetting = true;
|
||||
if (value == CString("true"))
|
||||
{
|
||||
gtk_toggle_button_set_active(m_toggle, true);
|
||||
gtk_toggle_button_set_inconsistent(m_toggle, false);
|
||||
}
|
||||
else if (value == CString("false"))
|
||||
{
|
||||
gtk_toggle_button_set_active(m_toggle, false);
|
||||
gtk_toggle_button_set_inconsistent(m_toggle, false);
|
||||
}
|
||||
else { gtk_toggle_button_set_inconsistent(m_toggle, true); }
|
||||
|
||||
gtk_entry_set_text(m_entry, value);
|
||||
m_onValueSetting = false;
|
||||
}
|
||||
|
||||
|
||||
void CBooleanSettingView::toggleButtonClick()
|
||||
{
|
||||
if (!m_onValueSetting)
|
||||
{
|
||||
if (gtk_toggle_button_get_active(m_toggle))
|
||||
{
|
||||
getBox().setSettingValue(getSettingIndex(), "true");
|
||||
setValue("true");
|
||||
}
|
||||
else
|
||||
{
|
||||
getBox().setSettingValue(getSettingIndex(), "false");
|
||||
setValue("false");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CBooleanSettingView::onChange()
|
||||
{
|
||||
if (!m_onValueSetting)
|
||||
{
|
||||
const gchar* value = gtk_entry_get_text(m_entry);
|
||||
getBox().setSettingValue(getSettingIndex(), value);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ovd_base.h"
|
||||
#include "ovdCAbstractSettingView.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
class CBooleanSettingView final : public CAbstractSettingView
|
||||
{
|
||||
public:
|
||||
CBooleanSettingView(Kernel::IBox& box, const size_t index, CString& builderName);
|
||||
|
||||
void getValue(CString& value) const override;
|
||||
void setValue(const CString& value) override;
|
||||
|
||||
void toggleButtonClick();
|
||||
void onChange();
|
||||
|
||||
|
||||
private:
|
||||
GtkToggleButton* m_toggle = nullptr;
|
||||
GtkEntry* m_entry = nullptr;
|
||||
bool m_onValueSetting = false;
|
||||
};
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+250
@@ -0,0 +1,250 @@
|
||||
#include "ovdCColorGradientSettingView.h"
|
||||
#include "../ovd_base.h"
|
||||
#include <visualization-toolkit/ovvizColorGradient.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
|
||||
static void OnColorGradientColorButtonPressed(GtkColorButton* button, gpointer data) { static_cast<CColorGradientSettingView*>(data)->colorChange(button); }
|
||||
|
||||
static void OnButtonSettingColorGradientConfigurePressed(GtkButton* /*button*/, gpointer data)
|
||||
{
|
||||
static_cast<CColorGradientSettingView*>(data)->configurePressed();
|
||||
}
|
||||
|
||||
static void OnRefreshColorGradient(GtkWidget* /*widget*/, GdkEventExpose* /*event*/, gpointer data)
|
||||
{
|
||||
static_cast<CColorGradientSettingView*>(data)->refreshColorGradient();
|
||||
}
|
||||
|
||||
static void OnGTKWidgetDestroy(GtkWidget* widget, gpointer /*data*/) { gtk_widget_destroy(widget); }
|
||||
static void OnInitializeColorGradient(GtkWidget* /*widget*/, gpointer data) { static_cast<CColorGradientSettingView*>(data)->initializeGradient(); }
|
||||
static void OnButtonColorGradientAddPressed(GtkButton* /*button*/, gpointer data) { static_cast<CColorGradientSettingView*>(data)->addColor(); }
|
||||
static void OnButtonColorGradientRemovePressed(GtkButton* /*button*/, gpointer data) { static_cast<CColorGradientSettingView*>(data)->removeColor(); }
|
||||
static void OnColorGradientSpinButtonValueChanged(GtkSpinButton* button, gpointer data) { static_cast<CColorGradientSettingView*>(data)->spinChange(button); }
|
||||
static void OnChange(GtkEntry* /*entry*/, gpointer data) { static_cast<CColorGradientSettingView*>(data)->onChange(); }
|
||||
|
||||
CColorGradientSettingView::CColorGradientSettingView(Kernel::IBox& box, const size_t index, CString& builderName, const Kernel::IKernelContext& ctx)
|
||||
: CAbstractSettingView(box, index, builderName, "settings_collection-hbox_setting_color_gradient"), m_kernelCtx(ctx), m_builderName(builderName)
|
||||
{
|
||||
GtkWidget* settingWidget = CAbstractSettingView::getEntryFieldWidget();
|
||||
|
||||
std::vector<GtkWidget*> widgets;
|
||||
CAbstractSettingView::extractWidget(settingWidget, widgets);
|
||||
m_entry = GTK_ENTRY(widgets[0]);
|
||||
|
||||
g_signal_connect(G_OBJECT(m_entry), "changed", G_CALLBACK(OnChange), this);
|
||||
g_signal_connect(G_OBJECT(widgets[1]), "clicked", G_CALLBACK(OnButtonSettingColorGradientConfigurePressed), this);
|
||||
|
||||
CAbstractSettingView::initializeValue();
|
||||
}
|
||||
|
||||
void CColorGradientSettingView::getValue(CString& value) const { value = CString(gtk_entry_get_text(m_entry)); }
|
||||
|
||||
void CColorGradientSettingView::setValue(const CString& value)
|
||||
{
|
||||
m_onValueSetting = true;
|
||||
gtk_entry_set_text(m_entry, value);
|
||||
m_onValueSetting = false;
|
||||
}
|
||||
|
||||
void CColorGradientSettingView::configurePressed()
|
||||
{
|
||||
GtkBuilder* builder = gtk_builder_new();
|
||||
gtk_builder_add_from_file(builder, m_builderName.toASCIIString(), nullptr);
|
||||
gtk_builder_connect_signals(builder, nullptr);
|
||||
|
||||
m_dialog = GTK_WIDGET(gtk_builder_get_object(builder, "setting_editor-color_gradient-dialog"));
|
||||
|
||||
const CString initialGradient = m_kernelCtx.getConfigurationManager().expand(gtk_entry_get_text(m_entry));
|
||||
CMatrix colorGradient;
|
||||
|
||||
VisualizationToolkit::ColorGradient::parse(colorGradient, initialGradient);
|
||||
m_colorGradient.resize(std::max<size_t>(colorGradient.getDimensionSize(1), 2));
|
||||
for (size_t i = 0; i < colorGradient.getDimensionSize(1); ++i)
|
||||
{
|
||||
const size_t idx = i * 4;
|
||||
m_colorGradient[i].percent = colorGradient[idx];
|
||||
m_colorGradient[i].color.red = guint(colorGradient[idx + 1] * .01 * 65535.);
|
||||
m_colorGradient[i].color.green = guint(colorGradient[idx + 2] * .01 * 65535.);
|
||||
m_colorGradient[i].color.blue = guint(colorGradient[idx + 3] * .01 * 65535.);
|
||||
}
|
||||
|
||||
m_container = GTK_WIDGET(gtk_builder_get_object(builder, "setting_editor-color_gradient-vbox"));
|
||||
m_drawingArea = GTK_WIDGET(gtk_builder_get_object(builder, "setting_editor-color_gradient-drawingarea"));
|
||||
|
||||
g_signal_connect(G_OBJECT(m_dialog), "show", G_CALLBACK(OnInitializeColorGradient), this);
|
||||
g_signal_connect(G_OBJECT(m_drawingArea), "expose_event", G_CALLBACK(OnRefreshColorGradient), this);
|
||||
g_signal_connect(G_OBJECT(gtk_builder_get_object(builder, "setting_editor-color_gradient-add_button")), "pressed",
|
||||
G_CALLBACK(OnButtonColorGradientAddPressed), this);
|
||||
g_signal_connect(G_OBJECT(gtk_builder_get_object(builder, "setting_editor-color_gradient-remove_button")), "pressed",
|
||||
G_CALLBACK(OnButtonColorGradientRemovePressed), this);
|
||||
|
||||
if (gtk_dialog_run(GTK_DIALOG(m_dialog)) == GTK_RESPONSE_APPLY)
|
||||
{
|
||||
CString finalGradient;
|
||||
CMatrix finalColorGradient(4, m_colorGradient.size());
|
||||
size_t idx = 0;
|
||||
for (size_t i = 0; i < m_colorGradient.size(); ++i)
|
||||
{
|
||||
finalColorGradient[idx++] = m_colorGradient[i].percent;
|
||||
finalColorGradient[idx++] = round(m_colorGradient[i].color.red * 100. / 65535.);
|
||||
finalColorGradient[idx++] = round(m_colorGradient[i].color.green * 100. / 65535.);
|
||||
finalColorGradient[idx++] = round(m_colorGradient[i].color.blue * 100. / 65535.);
|
||||
}
|
||||
VisualizationToolkit::ColorGradient::format(finalGradient, finalColorGradient);
|
||||
if (!m_onValueSetting) { getBox().setSettingValue(getSettingIndex(), finalGradient.toASCIIString()); }
|
||||
setValue(finalGradient.toASCIIString());
|
||||
}
|
||||
|
||||
gtk_widget_destroy(m_dialog);
|
||||
g_object_unref(builder);
|
||||
}
|
||||
|
||||
|
||||
void CColorGradientSettingView::initializeGradient()
|
||||
{
|
||||
gtk_widget_hide(m_container);
|
||||
|
||||
gtk_container_foreach(GTK_CONTAINER(m_container), OnGTKWidgetDestroy, nullptr);
|
||||
|
||||
size_t i = 0;
|
||||
const size_t count = m_colorGradient.size();
|
||||
m_colorButtons.clear();
|
||||
m_spinButtons.clear();
|
||||
for (auto& cg : m_colorGradient)
|
||||
{
|
||||
GtkBuilder* builder = gtk_builder_new();
|
||||
gtk_builder_add_from_file(builder, m_builderName.toASCIIString(), nullptr);
|
||||
gtk_builder_connect_signals(builder, nullptr);
|
||||
|
||||
GtkWidget* widget = GTK_WIDGET(gtk_builder_get_object(builder, "setting_editor-color_gradient-hbox"));
|
||||
|
||||
cg.colorButton = GTK_COLOR_BUTTON(gtk_builder_get_object(builder, "setting_editor-color_gradient-colorbutton"));
|
||||
cg.spinButton = GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "setting_editor-color_gradient-spinbutton"));
|
||||
|
||||
gtk_color_button_set_color(cg.colorButton, &cg.color);
|
||||
gtk_spin_button_set_value(cg.spinButton, cg.percent);
|
||||
|
||||
g_signal_connect(G_OBJECT(cg.colorButton), "color-set", G_CALLBACK(OnColorGradientColorButtonPressed), this);
|
||||
g_signal_connect(G_OBJECT(cg.spinButton), "value-changed", G_CALLBACK(OnColorGradientSpinButtonValueChanged), this);
|
||||
|
||||
g_object_ref(widget);
|
||||
gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(widget)), widget);
|
||||
gtk_container_add(GTK_CONTAINER(m_container), widget);
|
||||
g_object_unref(widget);
|
||||
|
||||
g_object_unref(builder);
|
||||
|
||||
m_colorButtons[cg.colorButton] = i;
|
||||
m_spinButtons[cg.spinButton] = i;
|
||||
i++;
|
||||
}
|
||||
|
||||
gtk_spin_button_set_value(m_colorGradient[0].spinButton, 0);
|
||||
gtk_spin_button_set_value(m_colorGradient[count - 1].spinButton, 100);
|
||||
|
||||
gtk_widget_show(m_container);
|
||||
}
|
||||
|
||||
void CColorGradientSettingView::refreshColorGradient()
|
||||
{
|
||||
const size_t steps = 100;
|
||||
gint sizex = 0;
|
||||
gint sizey = 0;
|
||||
gdk_drawable_get_size(m_drawingArea->window, &sizex, &sizey);
|
||||
|
||||
CMatrix gradient(4, m_colorGradient.size());
|
||||
for (size_t i = 0; i < m_colorGradient.size(); ++i)
|
||||
{
|
||||
const size_t idx = i * 4;
|
||||
gradient[idx] = m_colorGradient[i].percent;
|
||||
gradient[idx + 1] = m_colorGradient[i].color.red * 100. / 65535.;
|
||||
gradient[idx + 2] = m_colorGradient[i].color.green * 100. / 65535.;
|
||||
gradient[idx + 3] = m_colorGradient[i].color.blue * 100. / 65535.;
|
||||
}
|
||||
|
||||
CMatrix interpolated;
|
||||
VisualizationToolkit::ColorGradient::interpolate(interpolated, gradient, steps);
|
||||
|
||||
GdkGC* gc = gdk_gc_new(m_drawingArea->window);
|
||||
GdkColor color;
|
||||
|
||||
for (size_t i = 0; i < steps; ++i)
|
||||
{
|
||||
color.red = guint(interpolated[i * 4 + 1] * 65535 * .01);
|
||||
color.green = guint(interpolated[i * 4 + 2] * 65535 * .01);
|
||||
color.blue = guint(interpolated[i * 4 + 3] * 65535 * .01);
|
||||
gdk_gc_set_rgb_fg_color(gc, &color);
|
||||
gdk_draw_rectangle(m_drawingArea->window, gc, TRUE, gint((sizex * i) / steps), 0, gint((sizex * (i + 1)) / steps), sizey);
|
||||
}
|
||||
g_object_unref(gc);
|
||||
}
|
||||
|
||||
void CColorGradientSettingView::addColor()
|
||||
{
|
||||
m_colorGradient.resize(m_colorGradient.size() + 1);
|
||||
m_colorGradient[m_colorGradient.size() - 1].percent = 100;
|
||||
initializeGradient();
|
||||
refreshColorGradient();
|
||||
}
|
||||
|
||||
void CColorGradientSettingView::removeColor()
|
||||
{
|
||||
if (m_colorGradient.size() > 2)
|
||||
{
|
||||
m_colorGradient.resize(m_colorGradient.size() - 1);
|
||||
m_colorGradient[m_colorGradient.size() - 1].percent = 100;
|
||||
initializeGradient();
|
||||
refreshColorGradient();
|
||||
}
|
||||
}
|
||||
|
||||
void CColorGradientSettingView::spinChange(GtkSpinButton* button)
|
||||
{
|
||||
gtk_spin_button_update(button);
|
||||
|
||||
const size_t i = m_spinButtons[button];
|
||||
GtkSpinButton* prevSpinButton = i > 0 ? m_colorGradient[i - 1].spinButton : nullptr;
|
||||
GtkSpinButton* nextSpinButton = i < m_colorGradient.size() - 1 ? m_colorGradient[i + 1].spinButton : nullptr;
|
||||
if (!prevSpinButton) { gtk_spin_button_set_value(button, 0); }
|
||||
if (!nextSpinButton) { gtk_spin_button_set_value(button, 100); }
|
||||
if (prevSpinButton && gtk_spin_button_get_value(button) < gtk_spin_button_get_value(prevSpinButton))
|
||||
{
|
||||
gtk_spin_button_set_value(button, gtk_spin_button_get_value(prevSpinButton));
|
||||
}
|
||||
if (nextSpinButton && gtk_spin_button_get_value(button) > gtk_spin_button_get_value(nextSpinButton))
|
||||
{
|
||||
gtk_spin_button_set_value(button, gtk_spin_button_get_value(nextSpinButton));
|
||||
}
|
||||
|
||||
m_colorGradient[i].percent = gtk_spin_button_get_value(button);
|
||||
|
||||
refreshColorGradient();
|
||||
}
|
||||
|
||||
void CColorGradientSettingView::colorChange(GtkColorButton* button)
|
||||
{
|
||||
GdkColor color;
|
||||
gtk_color_button_get_color(button, &color);
|
||||
|
||||
m_colorGradient[m_colorButtons[button]].color = color;
|
||||
|
||||
refreshColorGradient();
|
||||
}
|
||||
|
||||
void CColorGradientSettingView::onChange()
|
||||
{
|
||||
if (!m_onValueSetting)
|
||||
{
|
||||
const gchar* value = gtk_entry_get_text(m_entry);
|
||||
getBox().setSettingValue(getSettingIndex(), value);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ovd_base.h"
|
||||
#include "ovdCAbstractSettingView.h"
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
typedef struct
|
||||
{
|
||||
double percent;
|
||||
GdkColor color;
|
||||
GtkColorButton* colorButton;
|
||||
GtkSpinButton* spinButton;
|
||||
} color_gradient_data_node_t;
|
||||
|
||||
|
||||
class CColorGradientSettingView final : public CAbstractSettingView
|
||||
{
|
||||
public:
|
||||
CColorGradientSettingView(Kernel::IBox& box, const size_t index, CString& builderName, const Kernel::IKernelContext& ctx);
|
||||
|
||||
void getValue(CString& value) const override;
|
||||
void setValue(const CString& value) override;
|
||||
|
||||
void configurePressed();
|
||||
|
||||
void initializeGradient();
|
||||
void refreshColorGradient();
|
||||
void addColor();
|
||||
void removeColor();
|
||||
|
||||
void spinChange(GtkSpinButton* button);
|
||||
void colorChange(GtkColorButton* button);
|
||||
|
||||
void onChange();
|
||||
|
||||
|
||||
private:
|
||||
GtkEntry* m_entry = nullptr;
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
CString m_builderName;
|
||||
|
||||
GtkWidget* m_dialog = nullptr;
|
||||
GtkWidget* m_container = nullptr;
|
||||
GtkWidget* m_drawingArea = nullptr;
|
||||
std::vector<color_gradient_data_node_t> m_colorGradient;
|
||||
std::map<GtkColorButton*, size_t> m_colorButtons;
|
||||
std::map<GtkSpinButton*, size_t> m_spinButtons;
|
||||
|
||||
bool m_onValueSetting = false;
|
||||
};
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
#include "ovdCColorSettingView.h"
|
||||
#include "../ovd_base.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
|
||||
static int Color2Percent(const guint16 color) { return int(round(color / 655.350)); } // c * 100 / 65535
|
||||
static guint16 Percent2Color(const int color) { return guint16(color * 655.35); } // c * 65535 / 100
|
||||
|
||||
static void OnButtonSettingColorChoosePressed(GtkColorButton* /*button*/, gpointer data) { static_cast<CColorSettingView*>(data)->selectColor(); }
|
||||
static void OnChange(GtkEntry* /*entry*/, gpointer data) { static_cast<CColorSettingView*>(data)->onChange(); }
|
||||
|
||||
CColorSettingView::CColorSettingView(Kernel::IBox& box, const size_t index, CString& builderName, const Kernel::IKernelContext& ctx)
|
||||
: CAbstractSettingView(box, index, builderName, "settings_collection-hbox_setting_color"), m_kernelCtx(ctx)
|
||||
{
|
||||
GtkWidget* settingWidget = CAbstractSettingView::getEntryFieldWidget();
|
||||
|
||||
std::vector<GtkWidget*> widgets;
|
||||
CAbstractSettingView::extractWidget(settingWidget, widgets);
|
||||
m_entry = GTK_ENTRY(widgets[0]);
|
||||
m_button = GTK_COLOR_BUTTON(widgets[1]);
|
||||
|
||||
g_signal_connect(G_OBJECT(m_entry), "changed", G_CALLBACK(OnChange), this);
|
||||
g_signal_connect(G_OBJECT(m_button), "color-set", G_CALLBACK(OnButtonSettingColorChoosePressed), this);
|
||||
|
||||
CAbstractSettingView::initializeValue();
|
||||
}
|
||||
|
||||
|
||||
void CColorSettingView::getValue(CString& value) const { value = CString(gtk_entry_get_text(m_entry)); }
|
||||
|
||||
void CColorSettingView::setValue(const CString& value)
|
||||
{
|
||||
m_onValueSetting = true;
|
||||
int r = 0, g = 0, b = 0;
|
||||
sscanf(m_kernelCtx.getConfigurationManager().expand(value).toASCIIString(), "%i,%i,%i", &r, &g, &b);
|
||||
|
||||
GdkColor color;
|
||||
color.red = Percent2Color(r);
|
||||
color.green = Percent2Color(g);
|
||||
color.blue = Percent2Color(b);
|
||||
gtk_color_button_set_color(m_button, &color);
|
||||
|
||||
gtk_entry_set_text(m_entry, value);
|
||||
m_onValueSetting = false;
|
||||
}
|
||||
|
||||
void CColorSettingView::selectColor()
|
||||
{
|
||||
GdkColor color;
|
||||
gtk_color_button_get_color(m_button, &color);
|
||||
const std::string value = std::to_string(Color2Percent(color.red)) + "," + std::to_string(Color2Percent(color.green)) + ","
|
||||
+ std::to_string(Color2Percent(color.blue));
|
||||
getBox().setSettingValue(getSettingIndex(), value.c_str());
|
||||
setValue(value.c_str());
|
||||
}
|
||||
|
||||
void CColorSettingView::onChange()
|
||||
{
|
||||
if (!m_onValueSetting)
|
||||
{
|
||||
const gchar* value = gtk_entry_get_text(m_entry);
|
||||
getBox().setSettingValue(getSettingIndex(), value);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ovd_base.h"
|
||||
#include "ovdCAbstractSettingView.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
class CColorSettingView final : public CAbstractSettingView
|
||||
{
|
||||
public:
|
||||
CColorSettingView(Kernel::IBox& box, const size_t index, CString& builderName, const Kernel::IKernelContext& ctx);
|
||||
|
||||
void getValue(CString& value) const override;
|
||||
void setValue(const CString& value) override;
|
||||
|
||||
void selectColor();
|
||||
void onChange();
|
||||
|
||||
private:
|
||||
GtkEntry* m_entry = nullptr;
|
||||
GtkColorButton* m_button = nullptr;
|
||||
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
bool m_onValueSetting = false;
|
||||
};
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
#include "ovdCEnumerationSettingView.h"
|
||||
#include "../ovd_base.h"
|
||||
|
||||
#include <algorithm> // std::sort
|
||||
#include <map>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
|
||||
static void OnChange(GtkEntry* /*entry*/, gpointer data) { static_cast<CEnumerationSettingView*>(data)->onChange(); }
|
||||
|
||||
CEnumerationSettingView::CEnumerationSettingView(Kernel::IBox& box, const size_t index, CString& builderName, const Kernel::IKernelContext& ctx,
|
||||
const CIdentifier& typeID)
|
||||
: CAbstractSettingView(box, index, builderName, "settings_collection-comboboxentry_setting_enumeration"), m_typeID(typeID), m_kernelCtx(ctx)
|
||||
{
|
||||
GtkWidget* setting = CAbstractSettingView::getEntryFieldWidget();
|
||||
|
||||
m_comboBox = GTK_COMBO_BOX(setting);
|
||||
|
||||
std::vector<std::string> entries;
|
||||
|
||||
for (size_t i = 0; i < m_kernelCtx.getTypeManager().getEnumerationEntryCount(m_typeID); ++i)
|
||||
{
|
||||
CString name;
|
||||
uint64_t value;
|
||||
if (m_kernelCtx.getTypeManager().getEnumerationEntry(m_typeID, i, name, value)) { entries.push_back(name.toASCIIString()); }
|
||||
}
|
||||
|
||||
std::sort(entries.begin(), entries.end());
|
||||
|
||||
GtkTreeIter it;
|
||||
GtkListStore* list = GTK_LIST_STORE(gtk_combo_box_get_model(m_comboBox));
|
||||
gtk_combo_box_set_wrap_width(m_comboBox, 0);
|
||||
gtk_list_store_clear(list);
|
||||
|
||||
for (size_t i = 0; i < entries.size(); ++i)
|
||||
{
|
||||
gtk_list_store_append(list, &it);
|
||||
gtk_list_store_set(list, &it, 0, entries[i].c_str(), -1);
|
||||
|
||||
m_entriesIdx[CString(entries[i].c_str())] = uint64_t(i);
|
||||
}
|
||||
|
||||
CString value;
|
||||
box.getSettingValue(index, value);
|
||||
if (m_entriesIdx.count(value.toASCIIString()) == 0)
|
||||
{
|
||||
gtk_list_store_append(list, &it);
|
||||
gtk_list_store_set(list, &it, 0, value.toASCIIString(), -1);
|
||||
}
|
||||
|
||||
CAbstractSettingView::initializeValue();
|
||||
|
||||
g_signal_connect(G_OBJECT(m_comboBox), "changed", G_CALLBACK(OnChange), this);
|
||||
}
|
||||
|
||||
|
||||
void CEnumerationSettingView::getValue(CString& value) const { value = CString(gtk_combo_box_get_active_text(m_comboBox)); }
|
||||
|
||||
|
||||
void CEnumerationSettingView::setValue(const CString& value)
|
||||
{
|
||||
m_onValueSetting = true;
|
||||
|
||||
// If the current value of the setting is not in the enumeration list, we will add or replace the last value in the list, so it can be set to this value
|
||||
if (m_entriesIdx.count(value) == 0)
|
||||
{
|
||||
GtkTreeIter it;
|
||||
GtkListStore* list = GTK_LIST_STORE(gtk_combo_box_get_model(m_comboBox));
|
||||
int valuesInModel = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(list), nullptr);
|
||||
if (valuesInModel == int(m_entriesIdx.size()))
|
||||
{
|
||||
gtk_list_store_append(list, &it);
|
||||
valuesInModel += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We just set the iterator at the end
|
||||
GtkTreePath* treePath = gtk_tree_path_new_from_indices(valuesInModel - 1, -1);
|
||||
gtk_tree_model_get_iter(GTK_TREE_MODEL(list), &it, treePath);
|
||||
gtk_tree_path_free(treePath);
|
||||
}
|
||||
gtk_list_store_set(list, &it, 0, value.toASCIIString(), -1);
|
||||
gtk_combo_box_set_active(m_comboBox, valuesInModel - 1);
|
||||
}
|
||||
else { gtk_combo_box_set_active(m_comboBox, gint(m_entriesIdx[value])); }
|
||||
m_onValueSetting = false;
|
||||
}
|
||||
|
||||
void CEnumerationSettingView::onChange()
|
||||
{
|
||||
if (!m_onValueSetting)
|
||||
{
|
||||
gchar* value = gtk_combo_box_get_active_text(m_comboBox);
|
||||
getBox().setSettingValue(getSettingIndex(), value);
|
||||
g_free(value);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ovd_base.h"
|
||||
#include "ovdCAbstractSettingView.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
class CEnumerationSettingView final : public CAbstractSettingView
|
||||
{
|
||||
public:
|
||||
CEnumerationSettingView(Kernel::IBox& box, const size_t index, CString& builderName, const Kernel::IKernelContext& ctx, const CIdentifier& typeID);
|
||||
|
||||
void getValue(CString& value) const override;
|
||||
void setValue(const CString& value) override;
|
||||
|
||||
void onChange();
|
||||
|
||||
|
||||
private:
|
||||
GtkComboBox* m_comboBox = nullptr;
|
||||
CIdentifier m_typeID = CIdentifier::undefined();
|
||||
|
||||
std::map<CString, size_t> m_entriesIdx;
|
||||
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
bool m_onValueSetting = false;
|
||||
};
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
#include "ovdCFilenameSettingView.h"
|
||||
#include "../ovd_base.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <iterator>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
|
||||
static void OnButtonSettingFilenameBrowsePressed(GtkButton* /*button*/, gpointer data) { static_cast<CFilenameSettingView*>(data)->browse(); }
|
||||
static void OnChange(GtkEntry* /*entry*/, gpointer data) { static_cast<CFilenameSettingView*>(data)->onChange(); }
|
||||
|
||||
#if defined TARGET_OS_Windows
|
||||
static gboolean OnFocusOutEvent(GtkEntry* /*entry*/, GdkEvent* /*event*/, gpointer data)
|
||||
{
|
||||
static_cast<CFilenameSettingView*>(data)->onFocusLost();
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
CFilenameSettingView::CFilenameSettingView(Kernel::IBox& box, const size_t index, CString& builderName, const Kernel::IKernelContext& ctx)
|
||||
: CAbstractSettingView(box, index, builderName, "settings_collection-hbox_setting_filename"), m_kernelCtx(ctx)
|
||||
{
|
||||
GtkWidget* settingWidget = CAbstractSettingView::getEntryFieldWidget();
|
||||
|
||||
std::vector<GtkWidget*> widgets;
|
||||
CAbstractSettingView::extractWidget(settingWidget, widgets);
|
||||
m_entry = GTK_ENTRY(widgets[0]);
|
||||
|
||||
g_signal_connect(G_OBJECT(m_entry), "changed", G_CALLBACK(OnChange), this);
|
||||
#if defined TARGET_OS_Windows
|
||||
// Only called for Windows path
|
||||
g_signal_connect(G_OBJECT(m_entry), "focus_out_event", G_CALLBACK(OnFocusOutEvent), this);
|
||||
#endif
|
||||
g_signal_connect(G_OBJECT(widgets[1]), "clicked", G_CALLBACK(OnButtonSettingFilenameBrowsePressed), this);
|
||||
|
||||
CAbstractSettingView::initializeValue();
|
||||
}
|
||||
|
||||
void CFilenameSettingView::getValue(CString& value) const { value = CString(gtk_entry_get_text(m_entry)); }
|
||||
|
||||
void CFilenameSettingView::setValue(const CString& value)
|
||||
{
|
||||
m_onValueSetting = true;
|
||||
gtk_entry_set_text(m_entry, value);
|
||||
m_onValueSetting = false;
|
||||
}
|
||||
|
||||
void CFilenameSettingView::browse() const
|
||||
{
|
||||
GtkWidget* widgetDialogOpen = gtk_file_chooser_dialog_new("Select file to open...", nullptr, GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, nullptr);
|
||||
|
||||
const CString initialFilename = m_kernelCtx.getConfigurationManager().expand(gtk_entry_get_text(m_entry));
|
||||
if (g_path_is_absolute(initialFilename.toASCIIString()))
|
||||
{
|
||||
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(widgetDialogOpen), initialFilename.toASCIIString());
|
||||
}
|
||||
else
|
||||
{
|
||||
char* fullPath = g_build_filename(g_get_current_dir(), initialFilename.toASCIIString(), nullptr);
|
||||
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(widgetDialogOpen), fullPath);
|
||||
g_free(fullPath);
|
||||
}
|
||||
|
||||
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(widgetDialogOpen), false);
|
||||
|
||||
if (gtk_dialog_run(GTK_DIALOG(widgetDialogOpen)) == GTK_RESPONSE_ACCEPT)
|
||||
{
|
||||
char* fileName = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widgetDialogOpen));
|
||||
char* backslash;
|
||||
while ((backslash = strchr(fileName, '\\')) != nullptr) { *backslash = '/'; }
|
||||
gtk_entry_set_text(m_entry, fileName);
|
||||
g_free(fileName);
|
||||
}
|
||||
gtk_widget_destroy(widgetDialogOpen);
|
||||
}
|
||||
|
||||
void CFilenameSettingView::onChange()
|
||||
{
|
||||
if (!m_onValueSetting)
|
||||
{
|
||||
const gchar* value = gtk_entry_get_text(m_entry);
|
||||
getBox().setSettingValue(getSettingIndex(), value);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined TARGET_OS_Windows
|
||||
void CFilenameSettingView::onFocusLost()
|
||||
{
|
||||
// We replace antislash, interpreted as escape, by slash in Windows path
|
||||
if (!m_onValueSetting)
|
||||
{
|
||||
std::string fileName = gtk_entry_get_text(m_entry);
|
||||
auto it = fileName.begin();
|
||||
|
||||
while ((it = std::find(it, fileName.end(), '\\')) != fileName.end())
|
||||
{
|
||||
if (it == std::prev(fileName.end()))
|
||||
{
|
||||
*it = '/';
|
||||
break;
|
||||
}
|
||||
if (*std::next(it) != '{' && *std::next(it) != '$' && *std::next(it) != '}') { *it = '/'; }
|
||||
|
||||
std::advance(it, 1);
|
||||
}
|
||||
|
||||
gtk_entry_set_text(m_entry, fileName.c_str());
|
||||
getBox().setSettingValue(this->getSettingIndex(), fileName.c_str());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ovd_base.h"
|
||||
#include "ovdCAbstractSettingView.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
class CFilenameSettingView final : public CAbstractSettingView
|
||||
{
|
||||
public:
|
||||
CFilenameSettingView(Kernel::IBox& box, const size_t index, CString& builderName, const Kernel::IKernelContext& ctx);
|
||||
|
||||
void getValue(CString& value) const override;
|
||||
void setValue(const CString& value) override;
|
||||
|
||||
void browse() const;
|
||||
void onChange();
|
||||
|
||||
#if defined TARGET_OS_Windows
|
||||
void onFocusLost();
|
||||
#endif
|
||||
|
||||
private:
|
||||
GtkEntry* m_entry = nullptr;
|
||||
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
bool m_onValueSetting = false;
|
||||
};
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
#include "ovdCFloatSettingView.h"
|
||||
#include "../ovd_base.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
|
||||
static void OnButtonSettingFloatUpPressed(GtkButton* /*button*/, gpointer data) { static_cast<CFloatSettingView*>(data)->adjustValue(1.0); }
|
||||
static void OnButtonSettingFloatDownPressed(GtkButton* /*button*/, gpointer data) { static_cast<CFloatSettingView*>(data)->adjustValue(-1.0); }
|
||||
static void OnChange(GtkEntry* /*entry*/, gpointer data) { static_cast<CFloatSettingView*>(data)->onChange(); }
|
||||
|
||||
CFloatSettingView::CFloatSettingView(Kernel::IBox& box, const size_t index, CString& builderName, const Kernel::IKernelContext& ctx)
|
||||
: CAbstractSettingView(box, index, builderName, "settings_collection-hbox_setting_float"), m_kernelCtx(ctx)
|
||||
{
|
||||
GtkWidget* settingWidget = CAbstractSettingView::getEntryFieldWidget();
|
||||
|
||||
std::vector<GtkWidget*> widgets;
|
||||
CAbstractSettingView::extractWidget(settingWidget, widgets);
|
||||
m_entry = GTK_ENTRY(widgets[0]);
|
||||
|
||||
g_signal_connect(G_OBJECT(m_entry), "changed", G_CALLBACK(OnChange), this);
|
||||
|
||||
g_signal_connect(G_OBJECT(widgets[1]), "clicked", G_CALLBACK(OnButtonSettingFloatUpPressed), this);
|
||||
g_signal_connect(G_OBJECT(widgets[2]), "clicked", G_CALLBACK(OnButtonSettingFloatDownPressed), this);
|
||||
|
||||
CAbstractSettingView::initializeValue();
|
||||
}
|
||||
|
||||
void CFloatSettingView::getValue(CString& value) const { value = CString(gtk_entry_get_text(m_entry)); }
|
||||
|
||||
void CFloatSettingView::setValue(const CString& value)
|
||||
{
|
||||
m_onValueSetting = true;
|
||||
gtk_entry_set_text(m_entry, value);
|
||||
m_onValueSetting = false;
|
||||
}
|
||||
|
||||
void CFloatSettingView::adjustValue(const double amount)
|
||||
{
|
||||
const double value = m_kernelCtx.getConfigurationManager().expandAsFloat(gtk_entry_get_text(m_entry), 0) + amount;
|
||||
const std::string str = std::to_string(value);
|
||||
getBox().setSettingValue(getSettingIndex(), str.c_str());
|
||||
setValue(str.c_str());
|
||||
}
|
||||
|
||||
void CFloatSettingView::onChange()
|
||||
{
|
||||
if (!m_onValueSetting)
|
||||
{
|
||||
const gchar* value = gtk_entry_get_text(m_entry);
|
||||
getBox().setSettingValue(getSettingIndex(), value);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ovd_base.h"
|
||||
#include "ovdCAbstractSettingView.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
class CFloatSettingView final : public CAbstractSettingView
|
||||
{
|
||||
public:
|
||||
CFloatSettingView(Kernel::IBox& box, const size_t index, CString& builderName, const Kernel::IKernelContext& ctx);
|
||||
|
||||
void getValue(CString& value) const override;
|
||||
void setValue(const CString& value) override;
|
||||
|
||||
void adjustValue(double amount);
|
||||
void onChange();
|
||||
|
||||
|
||||
private:
|
||||
GtkEntry* m_entry = nullptr;
|
||||
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
bool m_onValueSetting = false;
|
||||
};
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
#include "ovdCIntegerSettingView.h"
|
||||
#include "../ovd_base.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
|
||||
static void OnButtonSettingIntegerUpPressed(GtkButton* /*button*/, gpointer data) { static_cast<CIntegerSettingView*>(data)->adjustValue(1); }
|
||||
static void OnButtonSettingIntegerDownPressed(GtkButton* /*button*/, gpointer data) { static_cast<CIntegerSettingView*>(data)->adjustValue(-1); }
|
||||
static void OnInsertion(GtkEntry* /*entry*/, gpointer data) { static_cast<CIntegerSettingView*>(data)->onChange(); }
|
||||
|
||||
CIntegerSettingView::CIntegerSettingView(Kernel::IBox& box, const size_t index, CString& builderName, const Kernel::IKernelContext& ctx)
|
||||
: CAbstractSettingView(box, index, builderName, "settings_collection-hbox_setting_integer"), m_kernelCtx(ctx)
|
||||
{
|
||||
GtkWidget* settingWidget = CAbstractSettingView::getEntryFieldWidget();
|
||||
|
||||
std::vector<GtkWidget*> widgets;
|
||||
CAbstractSettingView::extractWidget(settingWidget, widgets);
|
||||
m_entry = GTK_ENTRY(widgets[0]);
|
||||
|
||||
g_signal_connect(G_OBJECT(m_entry), "changed", G_CALLBACK(OnInsertion), this);
|
||||
|
||||
g_signal_connect(G_OBJECT(widgets[1]), "clicked", G_CALLBACK(OnButtonSettingIntegerUpPressed), this);
|
||||
g_signal_connect(G_OBJECT(widgets[2]), "clicked", G_CALLBACK(OnButtonSettingIntegerDownPressed), this);
|
||||
|
||||
CAbstractSettingView::initializeValue();
|
||||
}
|
||||
|
||||
void CIntegerSettingView::getValue(CString& value) const { value = CString(gtk_entry_get_text(m_entry)); }
|
||||
|
||||
void CIntegerSettingView::setValue(const CString& value)
|
||||
{
|
||||
m_onValueSetting = true;
|
||||
gtk_entry_set_text(m_entry, value);
|
||||
m_onValueSetting = false;
|
||||
}
|
||||
|
||||
void CIntegerSettingView::adjustValue(const int amount)
|
||||
{
|
||||
const int64_t value = m_kernelCtx.getConfigurationManager().expandAsInteger(gtk_entry_get_text(m_entry), 0) + amount;
|
||||
const std::string res = std::to_string(value);
|
||||
|
||||
getBox().setSettingValue(getSettingIndex(), res.c_str());
|
||||
setValue(res.c_str());
|
||||
}
|
||||
|
||||
void CIntegerSettingView::onChange()
|
||||
{
|
||||
if (!m_onValueSetting)
|
||||
{
|
||||
const gchar* value = gtk_entry_get_text(m_entry);
|
||||
getBox().setSettingValue(getSettingIndex(), value);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ovd_base.h"
|
||||
#include "ovdCAbstractSettingView.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
class CIntegerSettingView final : public CAbstractSettingView
|
||||
{
|
||||
public:
|
||||
CIntegerSettingView(Kernel::IBox& box, const size_t index, CString& builderName, const Kernel::IKernelContext& ctx);
|
||||
|
||||
void getValue(CString& value) const override;
|
||||
void setValue(const CString& value) override;
|
||||
|
||||
void adjustValue(int amount);
|
||||
void onChange();
|
||||
|
||||
private:
|
||||
GtkEntry* m_entry = nullptr;
|
||||
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
bool m_onValueSetting = false;
|
||||
};
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
#include "ovdCScriptSettingView.h"
|
||||
#include "../ovd_base.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
|
||||
static void OnButtonSettingFilenameBrowsePressed(GtkButton* /*button*/, gpointer data) { static_cast<CScriptSettingView*>(data)->browse(); }
|
||||
static void OnButtonSettingScriptEditPressed(GtkButton* /*button*/, gpointer data) { static_cast<CScriptSettingView*>(data)->edit(); }
|
||||
static void OnChange(GtkEntry* /*entry*/, gpointer data) { static_cast<CScriptSettingView*>(data)->onChange(); }
|
||||
|
||||
#if defined TARGET_OS_Windows
|
||||
static gboolean OnFocusOutEvent(GtkEntry* /*entry*/, GdkEvent* /*event*/, gpointer data)
|
||||
{
|
||||
static_cast<CScriptSettingView*>(data)->onFocusLost();
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
CScriptSettingView::CScriptSettingView(Kernel::IBox& box, const size_t index, CString& builderName, const Kernel::IKernelContext& ctx)
|
||||
: CAbstractSettingView(box, index, builderName, "settings_collection-hbox_setting_script"), m_kernelCtx(ctx)
|
||||
{
|
||||
GtkWidget* settingWidget = CAbstractSettingView::getEntryFieldWidget();
|
||||
|
||||
std::vector<GtkWidget*> widgets;
|
||||
CAbstractSettingView::extractWidget(settingWidget, widgets);
|
||||
m_entry = GTK_ENTRY(widgets[0]);
|
||||
|
||||
g_signal_connect(G_OBJECT(m_entry), "changed", G_CALLBACK(OnChange), this);
|
||||
#if defined TARGET_OS_Windows
|
||||
// Only called for Windows path
|
||||
g_signal_connect(G_OBJECT(m_entry), "focus_out_event", G_CALLBACK(OnFocusOutEvent), this);
|
||||
#endif
|
||||
g_signal_connect(G_OBJECT(widgets[1]), "clicked", G_CALLBACK(OnButtonSettingScriptEditPressed), this);
|
||||
g_signal_connect(G_OBJECT(widgets[2]), "clicked", G_CALLBACK(OnButtonSettingFilenameBrowsePressed), this);
|
||||
|
||||
CAbstractSettingView::initializeValue();
|
||||
}
|
||||
|
||||
void CScriptSettingView::getValue(CString& value) const { value = CString(gtk_entry_get_text(m_entry)); }
|
||||
|
||||
void CScriptSettingView::setValue(const CString& value)
|
||||
{
|
||||
m_onValueSetting = true;
|
||||
gtk_entry_set_text(m_entry, value);
|
||||
m_onValueSetting = false;
|
||||
}
|
||||
|
||||
void CScriptSettingView::browse() const
|
||||
{
|
||||
GtkWidget* widgetDialogOpen = gtk_file_chooser_dialog_new("Select file to open...", nullptr, GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, nullptr);
|
||||
|
||||
const CString initialFileName = m_kernelCtx.getConfigurationManager().expand(gtk_entry_get_text(m_entry));
|
||||
if (g_path_is_absolute(initialFileName.toASCIIString()))
|
||||
{
|
||||
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(widgetDialogOpen), initialFileName.toASCIIString());
|
||||
}
|
||||
else
|
||||
{
|
||||
char* fullPath = g_build_filename(g_get_current_dir(), initialFileName.toASCIIString(), nullptr);
|
||||
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(widgetDialogOpen), fullPath);
|
||||
g_free(fullPath);
|
||||
}
|
||||
|
||||
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(widgetDialogOpen), false);
|
||||
|
||||
if (gtk_dialog_run(GTK_DIALOG(widgetDialogOpen)) == GTK_RESPONSE_ACCEPT)
|
||||
{
|
||||
char* fileName = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widgetDialogOpen));
|
||||
char* backslash;
|
||||
while ((backslash = strchr(fileName, '\\')) != nullptr) { *backslash = '/'; }
|
||||
gtk_entry_set_text(m_entry, fileName);
|
||||
g_free(fileName);
|
||||
}
|
||||
gtk_widget_destroy(widgetDialogOpen);
|
||||
}
|
||||
|
||||
void CScriptSettingView::edit() const
|
||||
{
|
||||
const CString fileName = m_kernelCtx.getConfigurationManager().expand(gtk_entry_get_text(m_entry));
|
||||
const CString editorCmd = m_kernelCtx.getConfigurationManager().expand("${Designer_ScriptEditorCommand}");
|
||||
|
||||
if (editorCmd != CString(""))
|
||||
{
|
||||
CString fullCmd = editorCmd + CString(" \"") + fileName + CString("\"");
|
||||
#if defined TARGET_OS_Windows
|
||||
fullCmd = "START " + fullCmd;
|
||||
#elif defined TARGET_OS_Linux
|
||||
fullCmd = fullCmd + " &";
|
||||
#else
|
||||
#endif
|
||||
if (system(fullCmd.toASCIIString()) < 0) { m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "Could not run command " << fullCmd << "\n"; }
|
||||
}
|
||||
}
|
||||
|
||||
void CScriptSettingView::onChange()
|
||||
{
|
||||
if (!m_onValueSetting)
|
||||
{
|
||||
const gchar* value = gtk_entry_get_text(m_entry);
|
||||
getBox().setSettingValue(getSettingIndex(), value);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined TARGET_OS_Windows
|
||||
void CScriptSettingView::onFocusLost()
|
||||
{
|
||||
// We replace antislash, interpreted as escape, by slash in Windows path
|
||||
if (!m_onValueSetting)
|
||||
{
|
||||
std::string fileName = gtk_entry_get_text(m_entry);
|
||||
auto it = fileName.begin();
|
||||
|
||||
while ((it = std::find(it, fileName.end(), '\\')) != fileName.end())
|
||||
{
|
||||
if (it == std::prev(fileName.end()))
|
||||
{
|
||||
*it = '/';
|
||||
break;
|
||||
}
|
||||
if (*std::next(it) != '{' && *std::next(it) != '$' && *std::next(it) != '}') { *it = '/'; }
|
||||
|
||||
std::advance(it, 1);
|
||||
}
|
||||
|
||||
gtk_entry_set_text(m_entry, fileName.c_str());
|
||||
getBox().setSettingValue(this->getSettingIndex(), fileName.c_str());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ovd_base.h"
|
||||
#include "ovdCAbstractSettingView.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
class CScriptSettingView final : public CAbstractSettingView
|
||||
{
|
||||
public:
|
||||
CScriptSettingView(Kernel::IBox& box, const size_t index, CString& builderName, const Kernel::IKernelContext& ctx);
|
||||
|
||||
void getValue(CString& value) const override;
|
||||
void setValue(const CString& value) override;
|
||||
|
||||
void browse() const;
|
||||
void edit() const;
|
||||
|
||||
void onChange();
|
||||
#if defined TARGET_OS_Windows
|
||||
void onFocusLost();
|
||||
#endif
|
||||
|
||||
private:
|
||||
GtkEntry* m_entry = nullptr;
|
||||
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
bool m_onValueSetting = false;
|
||||
};
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
#include "ovdCSettingViewFactory.h"
|
||||
|
||||
#include "ovdCBooleanSettingView.h"
|
||||
#include "ovdCIntegerSettingView.h"
|
||||
#include "ovdCFloatSettingView.h"
|
||||
#include "ovdCStringSettingView.h"
|
||||
#include "ovdCFilenameSettingView.h"
|
||||
#include "ovdCScriptSettingView.h"
|
||||
#include "ovdCColorSettingView.h"
|
||||
#include "ovdCColorGradientSettingView.h"
|
||||
#include "ovdCEnumerationSettingView.h"
|
||||
#include "ovdCBitMaskSettingView.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
|
||||
CAbstractSettingView* CSettingViewFactory::getSettingView(Kernel::IBox& box, const size_t index)
|
||||
{
|
||||
CIdentifier type;
|
||||
box.getSettingType(index, type);
|
||||
|
||||
if (type == OV_TypeId_Boolean) { return new CBooleanSettingView(box, index, m_builderName); }
|
||||
if (type == OV_TypeId_Integer) { return new CIntegerSettingView(box, index, m_builderName, m_kernelCtx); }
|
||||
if (type == OV_TypeId_Float) { return new CFloatSettingView(box, index, m_builderName, m_kernelCtx); }
|
||||
if (type == OV_TypeId_String) { return new CStringSettingView(box, index, m_builderName); }
|
||||
if (type == OV_TypeId_Filename) { return new CFilenameSettingView(box, index, m_builderName, m_kernelCtx); }
|
||||
if (type == OV_TypeId_Script) { return new CScriptSettingView(box, index, m_builderName, m_kernelCtx); }
|
||||
if (type == OV_TypeId_Color) { return new CColorSettingView(box, index, m_builderName, m_kernelCtx); }
|
||||
if (type == OV_TypeId_ColorGradient) { return new CColorGradientSettingView(box, index, m_builderName, m_kernelCtx); }
|
||||
if (m_kernelCtx.getTypeManager().isEnumeration(type)) { return new CEnumerationSettingView(box, index, m_builderName, m_kernelCtx, type); }
|
||||
if (m_kernelCtx.getTypeManager().isBitMask(type)) { return new CBitMaskSettingView(box, index, m_builderName, m_kernelCtx, type); }
|
||||
|
||||
//By default we consider every settings as a string
|
||||
return new CStringSettingView(box, index, m_builderName);
|
||||
}
|
||||
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ovd_base.h"
|
||||
#include "ovdCAbstractSettingView.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
class CSettingViewFactory final
|
||||
{
|
||||
public:
|
||||
CSettingViewFactory(const CString& builderName, const Kernel::IKernelContext& ctx)
|
||||
: m_builderName(builderName), m_kernelCtx(ctx) { }
|
||||
|
||||
~CSettingViewFactory() = default;
|
||||
|
||||
CAbstractSettingView* getSettingView(Kernel::IBox& box, const size_t index);
|
||||
|
||||
private:
|
||||
CString m_builderName;
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
};
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
#include "ovdCStringSettingView.h"
|
||||
#include "../ovd_base.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
|
||||
static void OnChange(GtkEntry* /*entry*/, gpointer data) { static_cast<CStringSettingView*>(data)->onChange(); }
|
||||
|
||||
CStringSettingView::CStringSettingView(Kernel::IBox& box, const size_t index, CString& builderName)
|
||||
: CAbstractSettingView(box, index, builderName, "settings_collection-entry_setting_string")
|
||||
{
|
||||
GtkWidget* settingWidget = CAbstractSettingView::getEntryFieldWidget();
|
||||
|
||||
m_entry = GTK_ENTRY(settingWidget);
|
||||
g_signal_connect(G_OBJECT(m_entry), "changed", G_CALLBACK(OnChange), this);
|
||||
|
||||
CAbstractSettingView::initializeValue();
|
||||
}
|
||||
|
||||
void CStringSettingView::getValue(CString& value) const { value = CString(gtk_entry_get_text(m_entry)); }
|
||||
|
||||
void CStringSettingView::setValue(const CString& value)
|
||||
{
|
||||
m_onValueSetting = true;
|
||||
gtk_entry_set_text(m_entry, value);
|
||||
m_onValueSetting = false;
|
||||
}
|
||||
|
||||
void CStringSettingView::onChange()
|
||||
{
|
||||
if (!m_onValueSetting)
|
||||
{
|
||||
const gchar* value = gtk_entry_get_text(m_entry);
|
||||
getBox().setSettingValue(getSettingIndex(), value);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ovd_base.h"
|
||||
#include "ovdCAbstractSettingView.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
namespace Setting {
|
||||
class CStringSettingView final : public CAbstractSettingView
|
||||
{
|
||||
public:
|
||||
CStringSettingView(Kernel::IBox& box, const size_t index, CString& builderName);
|
||||
|
||||
void getValue(CString& value) const override;
|
||||
void setValue(const CString& value) override;
|
||||
|
||||
void onChange();
|
||||
|
||||
private:
|
||||
GtkEntry* m_entry = nullptr;
|
||||
bool m_onValueSetting = false;
|
||||
};
|
||||
} // namespace Setting
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
@@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <fs/Files.h>
|
||||
|
||||
#include <openvibe/ovAssert.h>
|
||||
#include <openvibe/kernel/error/ovIErrorManager.h>
|
||||
#include <openvibe/kernel/error/ovIError.h>
|
||||
|
||||
#define OV_ERROR_D(description, type, returnValue) OV_ERROR(description, type, returnValue, m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
|
||||
#define OV_ERROR_DRF(description, type) OV_ERROR(description, type, false, m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
|
||||
#define OV_ERROR_DRZ(description, type) OV_ERROR(description, type, 0, m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
|
||||
#define OV_ERROR_DRU(description, type) OV_ERROR(description, type, CIdentifier::undefined(), m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
|
||||
#define OV_ERROR_DRV(description, type) OV_ERROR(description, type, void(), m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
|
||||
#define OV_ERROR_DRN(description, type) OV_ERROR(description, type, nullptr, m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
|
||||
|
||||
#define OV_ERROR_UNLESS_D(expression, description, type, returnValue) OV_ERROR_UNLESS(expression, description, type, returnValue, m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
|
||||
#define OV_ERROR_UNLESS_DRF(expression, description, type) OV_ERROR_UNLESS(expression, description, type, false, m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
|
||||
#define OV_ERROR_UNLESS_DRZ(expression, description, type) OV_ERROR_UNLESS(expression, description, type, 0, m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
|
||||
#define OV_ERROR_UNLESS_DRU(expression, description, type) OV_ERROR_UNLESS(expression, description, type, CIdentifier::undefined(), m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
|
||||
#define OV_ERROR_UNLESS_DRV(expression, description, type) OV_ERROR_UNLESS(expression, description, type, void() , m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
|
||||
#define OV_ERROR_UNLESS_DRN(expression, description, type) OV_ERROR_UNLESS(expression, description, type, nullptr, m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
|
||||
|
||||
#define OV_FATAL_D(description, type) OV_FATAL(description, type, m_kernelCtx.getLogManager())
|
||||
#define OV_FATAL_UNLESS_D(expression, description, type) OV_FATAL_UNLESS(expression, description, type, m_kernelCtx.getLogManager())
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#define NOEXCEPT noexcept
|
||||
#else
|
||||
#define NOEXCEPT
|
||||
#endif
|
||||
|
||||
class DesignerException final : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
DesignerException(OpenViBE::Kernel::IErrorManager& errorManager)
|
||||
: std::runtime_error("Designer caused an exception"), m_ErrorManager(errorManager) {}
|
||||
|
||||
const char* what() const NOEXCEPT override { return m_ErrorManager.getLastErrorString(); }
|
||||
|
||||
std::string getErrorString() const
|
||||
{
|
||||
std::string errorMessage;
|
||||
const OpenViBE::Kernel::IError* error = m_ErrorManager.getLastError();
|
||||
while (error)
|
||||
{
|
||||
char location[1024];
|
||||
FS::Files::getFilename(error->getErrorLocation(), location);
|
||||
errorMessage += "Message: " + std::string(error->getErrorString()) + "\nFile: " + location + "\n";
|
||||
error = error->getNestedError();
|
||||
}
|
||||
m_ErrorManager.releaseErrors();
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
void releaseErrors() NOEXCEPT { m_ErrorManager.releaseErrors(); }
|
||||
|
||||
OpenViBE::Kernel::IErrorManager& m_ErrorManager;
|
||||
};
|
||||
|
||||
#define OV_EXCEPTION_D(description, type) \
|
||||
do { \
|
||||
m_kernelCtx.getErrorManager().pushErrorAtLocation(type, static_cast<const OpenViBE::ErrorStream&>(OpenViBE::ErrorStream() << description).str().c_str(), __FILE__, __LINE__ ); \
|
||||
m_kernelCtx.getLogManager() << OpenViBE::Kernel::LogLevel_Fatal << "[Error description] = " << description << "; [Error code] = " << size_t((type)) << "\n"; \
|
||||
throw DesignerException(m_kernelCtx.getErrorManager()); \
|
||||
} while(0)
|
||||
|
||||
#define OV_EXCEPTION_UNLESS_D(expression, description, type) \
|
||||
do { if (!(expression)) { OV_EXCEPTION_D(description, type); } } while(0)
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
#include "ovdCAboutPluginDialog.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
bool CAboutPluginDialog::run()
|
||||
{
|
||||
if (m_pods == nullptr) { m_pods = m_kernelCtx.getPluginManager().getPluginObjectDescCreating(m_pluginClassID); }
|
||||
if (!m_pods) { return false; }
|
||||
|
||||
GtkBuilder* interface = gtk_builder_new(); // glade_xml_new(m_guiFilename.toASCIIString(), "plugin_about", nullptr);
|
||||
gtk_builder_add_from_file(interface, m_guiFilename.toASCIIString(), nullptr);
|
||||
gtk_builder_connect_signals(interface, nullptr);
|
||||
|
||||
GtkWidget* dialog = GTK_WIDGET(gtk_builder_get_object(interface, "plugin_about"));
|
||||
GtkWidget* type = GTK_WIDGET(gtk_builder_get_object(interface, "plugin_about-entry_type"));
|
||||
GtkWidget* name = GTK_WIDGET(gtk_builder_get_object(interface, "plugin_about-entry_name"));
|
||||
GtkWidget* authorName = GTK_WIDGET(gtk_builder_get_object(interface, "plugin_about-entry_author_name"));
|
||||
GtkWidget* authorCompanyName = GTK_WIDGET(gtk_builder_get_object(interface, "plugin_about-entry_company_name"));
|
||||
GtkWidget* category = GTK_WIDGET(gtk_builder_get_object(interface, "plugin_about-entry_category"));
|
||||
GtkWidget* version = GTK_WIDGET(gtk_builder_get_object(interface, "plugin_about-entry_version"));
|
||||
GtkWidget* addedSoftwareVersion = GTK_WIDGET(gtk_builder_get_object(interface, "plugin_about-entry_added_software_version"));
|
||||
GtkWidget* updatedSoftwareVersion = GTK_WIDGET(gtk_builder_get_object(interface, "plugin_about-entry_update_software_version"));
|
||||
GtkWidget* shortDesc = GTK_WIDGET(gtk_builder_get_object(interface, "plugin_about-textview_short_description"));
|
||||
GtkWidget* detailedDesc = GTK_WIDGET(gtk_builder_get_object(interface, "plugin_about-textview_detailed_description"));
|
||||
g_object_unref(interface);
|
||||
|
||||
if (m_pods->isDerivedFromClass(OV_ClassId_Plugins_AlgorithmDesc)) { gtk_entry_set_text(GTK_ENTRY(type), "Algorithm"); }
|
||||
else if (m_pods->isDerivedFromClass(OV_ClassId_Plugins_BoxAlgorithmDesc)) { gtk_entry_set_text(GTK_ENTRY(type), "Box algorithm"); }
|
||||
else if (m_pods->isDerivedFromClass(OV_ClassId_Plugins_ScenarioImporterDesc)) { gtk_entry_set_text(GTK_ENTRY(type), "Scenario importer"); }
|
||||
else if (m_pods->isDerivedFromClass(OV_ClassId_Plugins_ScenarioExporterDesc)) { gtk_entry_set_text(GTK_ENTRY(type), "Scenario exporter"); }
|
||||
|
||||
GtkTextBuffer* shortDescBuffer = gtk_text_buffer_new(nullptr);
|
||||
GtkTextBuffer* detailedDescBuffer = gtk_text_buffer_new(nullptr);
|
||||
gtk_text_buffer_set_text(shortDescBuffer, m_pods->getShortDescription(), -1);
|
||||
gtk_text_buffer_set_text(detailedDescBuffer, m_pods->getDetailedDescription(), -1);
|
||||
gtk_entry_set_text(GTK_ENTRY(name), m_pods->getName());
|
||||
gtk_entry_set_text(GTK_ENTRY(authorName), m_pods->getAuthorName());
|
||||
gtk_entry_set_text(GTK_ENTRY(authorCompanyName), m_pods->getAuthorCompanyName());
|
||||
gtk_entry_set_text(GTK_ENTRY(category), m_pods->getCategory());
|
||||
gtk_entry_set_text(GTK_ENTRY(version), m_pods->getVersion());
|
||||
gtk_entry_set_text(GTK_ENTRY(addedSoftwareVersion), m_pods->getAddedSoftwareVersion());
|
||||
gtk_entry_set_text(GTK_ENTRY(updatedSoftwareVersion), m_pods->getUpdatedSoftwareVersion());
|
||||
gtk_text_view_set_buffer(GTK_TEXT_VIEW(shortDesc), shortDescBuffer);
|
||||
gtk_text_view_set_buffer(GTK_TEXT_VIEW(detailedDesc), detailedDescBuffer);
|
||||
g_object_unref(shortDescBuffer);
|
||||
g_object_unref(detailedDescBuffer);
|
||||
|
||||
gtk_dialog_run(GTK_DIALOG(dialog));
|
||||
gtk_widget_destroy(dialog);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "ovd_base.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
class CAboutPluginDialog final
|
||||
{
|
||||
public:
|
||||
|
||||
CAboutPluginDialog(const Kernel::IKernelContext& ctx, const CIdentifier& pluginClassID, const char* guiFilename)
|
||||
: m_kernelCtx(ctx), m_pluginClassID(pluginClassID), m_guiFilename(guiFilename) { }
|
||||
|
||||
CAboutPluginDialog(const Kernel::IKernelContext& ctx, const Plugins::IPluginObjectDesc* pod, const char* guiFilename)
|
||||
: m_kernelCtx(ctx), m_pluginClassID(CIdentifier::undefined()), m_guiFilename(guiFilename), m_pods(pod) { }
|
||||
|
||||
~CAboutPluginDialog() = default;
|
||||
|
||||
bool run();
|
||||
|
||||
protected:
|
||||
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
CIdentifier m_pluginClassID = CIdentifier::undefined();
|
||||
CString m_guiFilename;
|
||||
const Plugins::IPluginObjectDesc* m_pods = nullptr;
|
||||
|
||||
CAboutPluginDialog() = delete;
|
||||
};
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
Masterarbeit/openvibe/designer-master/applications/platform/designer/src/ovdCAboutScenarioDialog.cpp
Executable
+99
@@ -0,0 +1,99 @@
|
||||
#include "ovdCAboutScenarioDialog.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
static void buttonMetaboxReset_clicked(GtkWidget* /*widget*/, gpointer data) { gtk_entry_set_text(GTK_ENTRY(data), CIdentifier::random().str().c_str()); }
|
||||
|
||||
bool CAboutScenarioDialog::run()
|
||||
|
||||
{
|
||||
GtkBuilder* interface = gtk_builder_new(); // glade_xml_new(m_guiFilename.toASCIIString(), "scenario_about", nullptr);
|
||||
gtk_builder_add_from_file(interface, m_guiFilename.toASCIIString(), nullptr);
|
||||
gtk_builder_connect_signals(interface, nullptr);
|
||||
|
||||
GtkWidget* dialog = GTK_WIDGET(gtk_builder_get_object(interface, "scenario_about"));
|
||||
GtkWidget* name = GTK_WIDGET(gtk_builder_get_object(interface, "scenario_about-entry_name"));
|
||||
GtkWidget* authorName = GTK_WIDGET(gtk_builder_get_object(interface, "scenario_about-entry_author_name"));
|
||||
GtkWidget* authorCompanyName = GTK_WIDGET(gtk_builder_get_object(interface, "scenario_about-entry_company_name"));
|
||||
GtkWidget* category = GTK_WIDGET(gtk_builder_get_object(interface, "scenario_about-entry_category"));
|
||||
GtkWidget* version = GTK_WIDGET(gtk_builder_get_object(interface, "scenario_about-entry_version"));
|
||||
GtkWidget* documentationPage = GTK_WIDGET(gtk_builder_get_object(interface, "scenario_about-entry_documentation_page"));
|
||||
GtkWidget* addedSoftwareVersion = GTK_WIDGET(gtk_builder_get_object(interface, "scenario_about-entry_added_software_version"));
|
||||
GtkWidget* updatedSoftwareVersion = GTK_WIDGET(gtk_builder_get_object(interface, "scenario_about-entry_update_software_version"));
|
||||
|
||||
GtkWidget* metaboxId = GTK_WIDGET(gtk_builder_get_object(interface, "scenario_about-entry_metabox_id"));
|
||||
|
||||
GtkWidget* resetMetaboxId = GTK_WIDGET(gtk_builder_get_object(interface, "scenario_about-button_reset_metabox_id"));
|
||||
const gulong signalHandlerId = g_signal_connect(G_OBJECT(resetMetaboxId), "clicked", G_CALLBACK(buttonMetaboxReset_clicked), metaboxId);
|
||||
|
||||
GtkWidget* shortDesc = GTK_WIDGET(gtk_builder_get_object(interface, "scenario_about-textview_short_description"));
|
||||
GtkWidget* detailedDesc = GTK_WIDGET(gtk_builder_get_object(interface, "scenario_about-textview_detailed_description"));
|
||||
|
||||
g_object_unref(interface);
|
||||
|
||||
gtk_entry_set_text(GTK_ENTRY(name), m_scenario.getAttributeValue(OV_AttributeId_Scenario_Name).toASCIIString());
|
||||
gtk_entry_set_text(GTK_ENTRY(authorName), m_scenario.getAttributeValue(OV_AttributeId_Scenario_Author).toASCIIString());
|
||||
gtk_entry_set_text(GTK_ENTRY(authorCompanyName), m_scenario.getAttributeValue(OV_AttributeId_Scenario_Company).toASCIIString());
|
||||
gtk_entry_set_text(GTK_ENTRY(category), m_scenario.getAttributeValue(OV_AttributeId_Scenario_Category).toASCIIString());
|
||||
gtk_entry_set_text(GTK_ENTRY(version), m_scenario.getAttributeValue(OV_AttributeId_Scenario_Version).toASCIIString());
|
||||
gtk_entry_set_text(GTK_ENTRY(documentationPage), m_scenario.getAttributeValue(OV_AttributeId_Scenario_DocumentationPage).toASCIIString());
|
||||
gtk_entry_set_text(GTK_ENTRY(addedSoftwareVersion), m_scenario.getAttributeValue(OV_AttributeId_Scenario_AddedSoftwareVersion).toASCIIString());
|
||||
gtk_entry_set_text(GTK_ENTRY(updatedSoftwareVersion), m_scenario.getAttributeValue(OV_AttributeId_Scenario_UpdatedSoftwareVersion).toASCIIString());
|
||||
|
||||
if (m_scenario.isMetabox()) { gtk_entry_set_text(GTK_ENTRY(metaboxId), m_scenario.getAttributeValue(OVP_AttributeId_Metabox_ID).toASCIIString()); }
|
||||
else
|
||||
{
|
||||
gtk_widget_set_sensitive(metaboxId, FALSE);
|
||||
gtk_widget_set_sensitive(resetMetaboxId, FALSE);
|
||||
}
|
||||
|
||||
GtkTextBuffer* shortDescBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(shortDesc));
|
||||
gtk_text_buffer_set_text(shortDescBuffer, m_scenario.getAttributeValue(OV_AttributeId_Scenario_ShortDescription).toASCIIString(), -1);
|
||||
GtkTextBuffer* detailedDescBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(detailedDesc));
|
||||
gtk_text_buffer_set_text(detailedDescBuffer, m_scenario.getAttributeValue(OV_AttributeId_Scenario_DetailedDescription).toASCIIString(), -1);
|
||||
|
||||
gtk_dialog_run(GTK_DIALOG(dialog));
|
||||
|
||||
g_signal_handler_disconnect(G_OBJECT(resetMetaboxId), signalHandlerId);
|
||||
m_scenario.setAttributeValue(OV_AttributeId_Scenario_Name, gtk_entry_get_text(GTK_ENTRY(name)));
|
||||
m_scenario.setAttributeValue(OV_AttributeId_Scenario_Author, gtk_entry_get_text(GTK_ENTRY(authorName)));
|
||||
m_scenario.setAttributeValue(OV_AttributeId_Scenario_Company, gtk_entry_get_text(GTK_ENTRY(authorCompanyName)));
|
||||
m_scenario.setAttributeValue(OV_AttributeId_Scenario_Category, gtk_entry_get_text(GTK_ENTRY(category)));
|
||||
m_scenario.setAttributeValue(OV_AttributeId_Scenario_Version, gtk_entry_get_text(GTK_ENTRY(version)));
|
||||
m_scenario.setAttributeValue(OV_AttributeId_Scenario_DocumentationPage, gtk_entry_get_text(GTK_ENTRY(documentationPage)));
|
||||
m_scenario.setAttributeValue(OV_AttributeId_Scenario_AddedSoftwareVersion, gtk_entry_get_text(GTK_ENTRY(addedSoftwareVersion)));
|
||||
m_scenario.setAttributeValue(OV_AttributeId_Scenario_UpdatedSoftwareVersion, gtk_entry_get_text(GTK_ENTRY(updatedSoftwareVersion)));
|
||||
|
||||
if (m_scenario.isMetabox())
|
||||
{
|
||||
const CString id(gtk_entry_get_text(GTK_ENTRY(metaboxId)));
|
||||
CIdentifier tmp;
|
||||
if (!tmp.fromString(id))
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Error << "Invalid identifier " << id
|
||||
<< " is not in the \"(0x[0-9a-f]{1-8}, 0x[0-9a-f]{1-8})\" format. ";
|
||||
m_kernelCtx.getLogManager() << "Reverting to " << m_scenario.getAttributeValue(OVP_AttributeId_Metabox_ID).toASCIIString() << ".\n";
|
||||
}
|
||||
else { m_scenario.setAttributeValue(OVP_AttributeId_Metabox_ID, id); }
|
||||
}
|
||||
|
||||
GtkTextIter start, end;
|
||||
|
||||
gtk_text_buffer_get_start_iter(shortDescBuffer, &start);
|
||||
gtk_text_buffer_get_end_iter(shortDescBuffer, &end);
|
||||
m_scenario.setAttributeValue(OV_AttributeId_Scenario_ShortDescription,
|
||||
gtk_text_buffer_get_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(shortDesc)), &start, &end, FALSE));
|
||||
|
||||
gtk_text_buffer_get_start_iter(detailedDescBuffer, &start);
|
||||
gtk_text_buffer_get_end_iter(detailedDescBuffer, &end);
|
||||
m_scenario.setAttributeValue(OV_AttributeId_Scenario_DetailedDescription,
|
||||
gtk_text_buffer_get_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(detailedDesc)), &start, &end, FALSE));
|
||||
|
||||
gtk_widget_destroy(dialog);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "ovd_base.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
class CAboutScenarioDialog final
|
||||
{
|
||||
public:
|
||||
|
||||
CAboutScenarioDialog(const Kernel::IKernelContext& ctx, Kernel::IScenario& scenario, const char* guiFilename)
|
||||
: m_kernelCtx(ctx), m_scenario(scenario), m_guiFilename(guiFilename) { }
|
||||
|
||||
~CAboutScenarioDialog() = default;
|
||||
|
||||
bool run();
|
||||
|
||||
protected:
|
||||
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
Kernel::IScenario& m_scenario;
|
||||
CString m_guiFilename;
|
||||
|
||||
CAboutScenarioDialog() = delete;
|
||||
};
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
Executable
+2923
File diff suppressed because it is too large
Load Diff
Executable
+190
@@ -0,0 +1,190 @@
|
||||
#pragma once
|
||||
|
||||
#include <visualization-toolkit/ovvizIVisualizationManager.h>
|
||||
#include "ovd_base.h"
|
||||
|
||||
#include "archway/ovdCArchwayHandler.h"
|
||||
#include "archway/ovdCArchwayHandlerGUI.h"
|
||||
|
||||
#define OVD_ScenarioImportContext_OpenScenario OpenViBE::CIdentifier(0xA180DB91, 0x19235AEE)
|
||||
#define OVD_ScenarioExportContext_SaveScenario OpenViBE::CIdentifier(0xC98C47AD, 0xCBD952B2)
|
||||
#define OVD_ScenarioExportContext_SaveMetabox OpenViBE::CIdentifier(0x529494F1, 0x6C2527D9)
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
class CInterfacedScenario;
|
||||
|
||||
class CLogListenerDesigner;
|
||||
|
||||
class CApplication
|
||||
{
|
||||
public:
|
||||
explicit CApplication(const Kernel::IKernelContext& ctx);
|
||||
~CApplication();
|
||||
|
||||
void initialize(ECommandLineFlag cmdLineFlags);
|
||||
bool openScenario(const char* filename);
|
||||
|
||||
/** \name Drag and drop management */
|
||||
//@{
|
||||
|
||||
void dragDataGetCB(GtkWidget* widget, GdkDragContext* dragCtx, GtkSelectionData* selectionData, guint info, guint time) const;
|
||||
|
||||
//@}
|
||||
|
||||
/** \name Selection management */
|
||||
//@{
|
||||
|
||||
void undoCB();
|
||||
void redoCB();
|
||||
|
||||
void copySelectionCB();
|
||||
void cutSelectionCB();
|
||||
void pasteSelectionCB();
|
||||
void deleteSelectionCB();
|
||||
void preferencesCB() const;
|
||||
|
||||
//@}
|
||||
|
||||
/** \name Scenario management */
|
||||
//@{
|
||||
|
||||
CString getWorkingDirectory();
|
||||
|
||||
bool hasRunningScenario();
|
||||
bool hasUnsavedScenario();
|
||||
|
||||
CInterfacedScenario* getCurrentInterfacedScenario();
|
||||
void saveOpenedScenarios();
|
||||
|
||||
void testCB() const;
|
||||
void newScenarioCB();
|
||||
void openScenarioCB();
|
||||
void saveScenarioCB(CInterfacedScenario* scenario = nullptr); // defaults to current scenario if nullptr
|
||||
void saveScenarioAsCB(CInterfacedScenario* scenario = nullptr); // defaults to current scenario if nullptr
|
||||
void closeScenarioCB(CInterfacedScenario* scenario);
|
||||
void restoreDefaultScenariosCB() const;
|
||||
|
||||
void stopScenarioCB();
|
||||
void pauseScenarioCB();
|
||||
void nextScenarioCB();
|
||||
void playScenarioCB();
|
||||
void forwardScenarioCB();
|
||||
|
||||
void configureScenarioSettingsCB(CInterfacedScenario* scenario) const;
|
||||
|
||||
void addCommentCB(CInterfacedScenario* scenario) const;
|
||||
|
||||
void changeCurrentScenario(int pageIdx);
|
||||
void reorderCurrentScenario(size_t newPageIdx);
|
||||
void addRecentScenario(const std::string& scenarioPath);
|
||||
|
||||
static void cannotSaveScenarioBeforeUpdate();
|
||||
|
||||
//@}
|
||||
|
||||
/** \name Designer visualization management */
|
||||
//@{
|
||||
|
||||
void deleteDesignerVisualizationCB();
|
||||
void toggleDesignerVisualizationCB();
|
||||
|
||||
//@}
|
||||
|
||||
/** \name Player management */
|
||||
//@{
|
||||
|
||||
Kernel::IPlayer* getPlayer();
|
||||
bool createPlayer();
|
||||
void stopInterfacedScenarioAndReleasePlayer(CInterfacedScenario* scenario);
|
||||
|
||||
//@}
|
||||
|
||||
/** \name Application management */
|
||||
//@{
|
||||
|
||||
bool quitApplicationCB();
|
||||
void aboutOpenViBECB() const;
|
||||
void aboutScenarioCB(CInterfacedScenario* scenario) const;
|
||||
void aboutLinkClickedCB(const gchar* url) const;
|
||||
|
||||
void browseDocumentationCB() const;
|
||||
static void registerLicenseCB();
|
||||
void reportIssueCB() const;
|
||||
void windowStateChangedCB(bool isMaximized);
|
||||
bool displayChangelogWhenAvailable();
|
||||
|
||||
//@}
|
||||
|
||||
void logLevelCB() const;
|
||||
//void logLevelMessagesCB();
|
||||
void cpuUsageCB();
|
||||
void zoomInCB(); //Call when a zoom in is required
|
||||
void zoomOutCB(); //Call when a zoom out is required
|
||||
void spinnerZoomChangedCB(const size_t scaleDelta);
|
||||
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
Kernel::IPluginManager* m_PluginMgr = nullptr;
|
||||
Kernel::IScenarioManager* m_ScenarioMgr = nullptr;
|
||||
VisualizationToolkit::IVisualizationManager* m_VisualizationMgr = nullptr;
|
||||
Kernel::IScenario* m_ClipboardScenario = nullptr;
|
||||
|
||||
ECommandLineFlag m_CmdLineFlags = CommandLineFlag_None;
|
||||
|
||||
GtkBuilder* m_Builder = nullptr;
|
||||
GtkWidget* m_MainWindow = nullptr;
|
||||
|
||||
GtkTreeStore* m_BoxAlgorithmTreeModel = nullptr;
|
||||
GtkTreeModel* m_BoxAlgorithmTreeModelFilter = nullptr;
|
||||
GtkTreeModel* m_BoxAlgorithmTreeModelFilter2 = nullptr;
|
||||
GtkTreeModel* m_BoxAlgorithmTreeModelFilter3 = nullptr;
|
||||
GtkTreeModel* m_BoxAlgorithmTreeModelFilter4 = nullptr;
|
||||
GtkTreeView* m_BoxAlgorithmTreeView = nullptr;
|
||||
GtkTreeStore* m_AlgorithmTreeModel = nullptr;
|
||||
|
||||
GtkSpinButton* m_FastForwardFactor = nullptr;
|
||||
|
||||
// UI for adding inputs and outputs to a scenario
|
||||
GtkWidget* m_Inputs = nullptr;
|
||||
GtkWidget* m_Outputs = nullptr;
|
||||
|
||||
gint m_FilterTimeout = 0;
|
||||
const gchar* m_SearchTerm = nullptr;
|
||||
|
||||
uint64_t m_LastTimeRefresh = 0;
|
||||
bool m_IsQuitting = false;
|
||||
bool m_IsNewVersion = false;
|
||||
|
||||
std::vector<CInterfacedScenario*> m_Scenarios;
|
||||
std::vector<const Plugins::IPluginObjectDesc*> m_NewBoxes;
|
||||
std::vector<const Plugins::IPluginObjectDesc*> m_UpdatedBoxes;
|
||||
|
||||
#ifdef MENSIA_DISTRIBUTION
|
||||
CArchwayHandler* m_ArchwayHandler = nullptr;
|
||||
CArchwayHandlerGUI* m_ArchwayHandlerGUI = nullptr;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
VisualizationToolkit::IVisualizationContext* m_visualizationCtx = nullptr;
|
||||
|
||||
CLogListenerDesigner* m_logListener = nullptr;
|
||||
|
||||
GtkWidget* m_splashScreen = nullptr;
|
||||
GtkNotebook* m_scenarioNotebook = nullptr;
|
||||
GtkNotebook* m_resourceNotebook = nullptr;
|
||||
GtkTreeView* m_algorithmTreeView = nullptr;
|
||||
GtkWidget* m_configureSettingsAddSettingButton = nullptr;
|
||||
GtkContainer* m_menuOpenRecent = nullptr;
|
||||
std::vector<const GtkWidget*> m_recentScenarios;
|
||||
|
||||
bool m_isMaximized = false;
|
||||
|
||||
size_t m_currentScenarioIdx = 0;
|
||||
std::vector<std::string> m_documentedBoxes;
|
||||
};
|
||||
|
||||
} //namespace Designer
|
||||
} //namespace OpenViBE
|
||||
+548
@@ -0,0 +1,548 @@
|
||||
#include "ovdCBoxConfigurationDialog.h"
|
||||
#include "ovdCSettingCollectionHelper.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <xml/IXMLHandler.h>
|
||||
#include <xml/IXMLNode.h>
|
||||
|
||||
#include <fs/Files.h>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
static const char* const ROOT_NAME = "OpenViBE-SettingsOverride";
|
||||
static const char* const SETTING_NAME = "SettingValue";
|
||||
|
||||
static void onFileOverrideCheckToggled(GtkToggleButton* button, gpointer data)
|
||||
{
|
||||
gtk_widget_set_sensitive(static_cast<GtkWidget*>(data), !gtk_toggle_button_get_active(button));
|
||||
}
|
||||
|
||||
static void OnButtonLoadClicked(GtkButton* /*button*/, gpointer data) { static_cast<CBoxConfigurationDialog*>(data)->loadConfig(); }
|
||||
static void OnButtonSaveClicked(GtkButton* /*button*/, gpointer data) { static_cast<CBoxConfigurationDialog*>(data)->saveConfig(); }
|
||||
static void OnOverrideBrowseClicked(GtkButton* /*button*/, gpointer data) { static_cast<CBoxConfigurationDialog*>(data)->onOverrideBrowse(); }
|
||||
static void CollectWidgetCB(GtkWidget* widget, gpointer data) { static_cast<std::vector<GtkWidget*>*>(data)->push_back(widget); }
|
||||
|
||||
CBoxConfigurationDialog::CBoxConfigurationDialog(const Kernel::IKernelContext& ctx, Kernel::IBox& box, const char* guiFilename,
|
||||
const char* guiSettingsFilename, const bool isScenarioRunning)
|
||||
: m_kernelCtx(ctx), m_box(box), m_guiFilename(guiFilename), m_guiSettingsFilename(guiSettingsFilename),
|
||||
m_settingFactory(m_guiSettingsFilename.toASCIIString(), ctx), m_isScenarioRunning(isScenarioRunning)
|
||||
{
|
||||
m_box.addObserver(this);
|
||||
|
||||
if (m_box.getInterfacorCountIncludingDeprecated(Kernel::EBoxInterfacorType::Setting))
|
||||
{
|
||||
GtkBuilder* builder = gtk_builder_new(); // glade_xml_new(m_guiFilename.toASCIIString(), "box_configuration", nullptr);
|
||||
gtk_builder_add_from_file(builder, m_guiFilename.toASCIIString(), nullptr);
|
||||
gtk_builder_connect_signals(builder, nullptr);
|
||||
|
||||
if (!m_isScenarioRunning)
|
||||
{
|
||||
// TODO : This is not a modal dialog. It would be better if it was.
|
||||
m_settingDialog = GTK_WIDGET(gtk_builder_get_object(builder, "box_configuration"));
|
||||
const std::string title = std::string("Configure ") + m_box.getName().toASCIIString() + " settings";
|
||||
gtk_window_set_title(GTK_WINDOW(m_settingDialog), title.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
// This is actually *not* a dialog
|
||||
m_settingDialog = GTK_WIDGET(gtk_builder_get_object(builder, "box_configuration-scrolledwindow"));
|
||||
}
|
||||
m_settingsTable = GTK_TABLE(gtk_builder_get_object(builder, "box_configuration-table"));
|
||||
m_scrolledWindow = GTK_SCROLLED_WINDOW(gtk_builder_get_object(builder, "box_configuration-scrolledwindow"));
|
||||
m_viewPort = GTK_VIEWPORT(gtk_builder_get_object(builder, "box_configuration-viewport"));
|
||||
|
||||
gtk_table_resize(m_settingsTable, guint(m_box.getInterfacorCountIncludingDeprecated(Kernel::EBoxInterfacorType::Setting)), 4);
|
||||
|
||||
generateSettingsTable();
|
||||
|
||||
const CSettingCollectionHelper helper(m_kernelCtx, m_guiSettingsFilename.toASCIIString());
|
||||
|
||||
if (!m_isScenarioRunning)
|
||||
{
|
||||
GtkContainer* fileOverrideContainer = GTK_CONTAINER(gtk_builder_get_object(builder, "box_configuration-hbox_filename_override"));
|
||||
m_fileOverrideCheck = GTK_CHECK_BUTTON(gtk_builder_get_object(builder, "box_configuration-checkbutton_filename_override"));
|
||||
GtkButton* buttonLoad = GTK_BUTTON(gtk_builder_get_object(builder, "box_configuration-button_load_current_from_file"));
|
||||
GtkButton* buttonSave = GTK_BUTTON(gtk_builder_get_object(builder, "box_configuration-button_save_current_to_file"));
|
||||
|
||||
const std::string settingOverrideWidgetName = helper.getSettingWidgetName(OV_TypeId_Filename).toASCIIString();
|
||||
GtkBuilder* builderInterfaceSettingCollection = gtk_builder_new();
|
||||
gtk_builder_add_from_file(builderInterfaceSettingCollection, m_guiSettingsFilename.toASCIIString(), nullptr);
|
||||
|
||||
m_overrideEntryContainer = GTK_WIDGET(gtk_builder_get_object(builderInterfaceSettingCollection, settingOverrideWidgetName.c_str()));
|
||||
|
||||
std::vector<GtkWidget*> widgets;
|
||||
gtk_container_foreach(GTK_CONTAINER(m_overrideEntryContainer), CollectWidgetCB, &widgets);
|
||||
|
||||
gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(m_overrideEntryContainer)), m_overrideEntryContainer);
|
||||
gtk_container_add(fileOverrideContainer, m_overrideEntryContainer);
|
||||
m_overrideEntry = GTK_ENTRY(widgets[0]);
|
||||
|
||||
|
||||
g_signal_connect(G_OBJECT(m_fileOverrideCheck), "toggled", G_CALLBACK(onFileOverrideCheckToggled), GTK_WIDGET(m_settingsTable));
|
||||
g_signal_connect(G_OBJECT(widgets[1]), "clicked", G_CALLBACK(OnOverrideBrowseClicked), this);
|
||||
g_signal_connect(G_OBJECT(buttonLoad), "clicked", G_CALLBACK(OnButtonLoadClicked), this);
|
||||
g_signal_connect(G_OBJECT(buttonSave), "clicked", G_CALLBACK(OnButtonSaveClicked), this);
|
||||
|
||||
if (m_box.hasAttribute(OV_AttributeId_Box_SettingOverrideFilename))
|
||||
{
|
||||
GtkExpander* expander = GTK_EXPANDER(gtk_builder_get_object(builder, "box_configuration-expander"));
|
||||
gtk_expander_set_expanded(expander, true);
|
||||
|
||||
gtk_entry_set_text(m_overrideEntry, m_box.getAttributeValue(OV_AttributeId_Box_SettingOverrideFilename).toASCIIString());
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_fileOverrideCheck), true);
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(m_settingsTable), false);
|
||||
}
|
||||
else { gtk_entry_set_text(m_overrideEntry, ""); }
|
||||
|
||||
g_object_unref(builder);
|
||||
g_object_unref(builderInterfaceSettingCollection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CBoxConfigurationDialog::~CBoxConfigurationDialog()
|
||||
{
|
||||
m_box.deleteObserver(this);
|
||||
if (m_settingDialog) { gtk_widget_destroy(m_settingDialog); }
|
||||
}
|
||||
|
||||
bool CBoxConfigurationDialog::run()
|
||||
{
|
||||
bool modified = false;
|
||||
if (m_box.getInterfacorCountIncludingDeprecated(Kernel::EBoxInterfacorType::Setting))
|
||||
{
|
||||
//CSettingCollectionHelper helper(m_kernelCtx, m_guiSettingsFilename.toASCIIString());
|
||||
storeState();
|
||||
bool finished = false;
|
||||
while (!finished)
|
||||
{
|
||||
const gint result = gtk_dialog_run(GTK_DIALOG(m_settingDialog));
|
||||
if (result == GTK_RESPONSE_APPLY)
|
||||
{
|
||||
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_fileOverrideCheck)))
|
||||
{
|
||||
const gchar* fileName = gtk_entry_get_text(m_overrideEntry);
|
||||
if (m_box.hasAttribute(OV_AttributeId_Box_SettingOverrideFilename))
|
||||
{
|
||||
m_box.setAttributeValue(OV_AttributeId_Box_SettingOverrideFilename, fileName);
|
||||
}
|
||||
else { m_box.addAttribute(OV_AttributeId_Box_SettingOverrideFilename, fileName); }
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_box.hasAttribute(OV_AttributeId_Box_SettingOverrideFilename)) { m_box.removeAttribute(OV_AttributeId_Box_SettingOverrideFilename); }
|
||||
}
|
||||
|
||||
finished = true;
|
||||
modified = true;
|
||||
}
|
||||
else if (result == GTK_RESPONSE_CANCEL)
|
||||
{
|
||||
restoreState();
|
||||
finished = true;
|
||||
}
|
||||
else if (result == 1) // default
|
||||
{
|
||||
// Some settings will add/remove other settings;
|
||||
// by evaluating m_box.getSettingCount() each time we ensure not ending somewhere in the oblivion
|
||||
for (size_t i = 0; i < m_settingViews.size(); ++i)
|
||||
{
|
||||
CString value;
|
||||
m_box.getSettingDefaultValue(i, value);
|
||||
m_box.setSettingValue(i, value);
|
||||
//m_settingViews[i]->setValue(value);
|
||||
//helper.setValue(settingType, i < m_settingViews.size()? m_settingViews[i]->getEntryWidget() : nullptr, value);
|
||||
}
|
||||
gtk_entry_set_text(GTK_ENTRY(m_overrideEntryContainer), "");
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_fileOverrideCheck), false);
|
||||
//gtk_widget_set_sensitive(GTK_WIDGET(m_settingsTable), true);
|
||||
modified = false;
|
||||
}
|
||||
else if (result == 2) // revert
|
||||
{
|
||||
restoreState();
|
||||
|
||||
if (m_box.hasAttribute(OV_AttributeId_Box_SettingOverrideFilename))
|
||||
{
|
||||
gtk_entry_set_text(
|
||||
GTK_ENTRY(m_overrideEntryContainer), m_box.getAttributeValue(OV_AttributeId_Box_SettingOverrideFilename).toASCIIString());
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_fileOverrideCheck), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_entry_set_text(GTK_ENTRY(m_overrideEntryContainer), "");
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_fileOverrideCheck), false);
|
||||
}
|
||||
}
|
||||
else if (result == 3) { modified = true; } // load
|
||||
else if (result == 4) { } // save
|
||||
else { finished = true; }
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
void CBoxConfigurationDialog::update(CObservable& /*o*/, void* data)
|
||||
{
|
||||
const Kernel::BoxEventMessage* event = static_cast<Kernel::BoxEventMessage*>(data);
|
||||
|
||||
switch (event->m_Type)
|
||||
{
|
||||
case Kernel::SettingsAllChange:
|
||||
generateSettingsTable();
|
||||
break;
|
||||
|
||||
case Kernel::SettingValueUpdate:
|
||||
{
|
||||
CString value;
|
||||
m_box.getSettingValue(event->m_FirstIdx, value);
|
||||
|
||||
m_settingViews[event->m_FirstIdx]->setValue(value);
|
||||
break;
|
||||
}
|
||||
|
||||
case Kernel::SettingDelete:
|
||||
removeSetting(event->m_FirstIdx);
|
||||
break;
|
||||
|
||||
case Kernel::SettingAdd:
|
||||
addSetting(event->m_FirstIdx);
|
||||
break;
|
||||
|
||||
case Kernel::SettingChange:
|
||||
settingChange(event->m_FirstIdx);
|
||||
break;
|
||||
|
||||
case Kernel::SettingsReorder: break;
|
||||
default: break; //OV_ERROR_KRF("wtf", Kernel::ErrorType::BadSetting);
|
||||
}
|
||||
}
|
||||
|
||||
void CBoxConfigurationDialog::generateSettingsTable()
|
||||
{
|
||||
std::for_each(m_settingViews.begin(), m_settingViews.end(), [](Setting::CAbstractSettingView* elem) { delete elem; });
|
||||
m_settingViews.clear();
|
||||
//Remove rows
|
||||
gtk_container_foreach(GTK_CONTAINER(GTK_WIDGET(m_settingsTable)),
|
||||
[](GtkWidget* widget, gpointer data) { gtk_container_remove(GTK_CONTAINER(data), widget); },
|
||||
GTK_WIDGET(m_settingsTable));
|
||||
|
||||
size_t size = 0;
|
||||
if (m_isScenarioRunning)
|
||||
{
|
||||
for (size_t i = 0; i < m_box.getInterfacorCountIncludingDeprecated(Kernel::EBoxInterfacorType::Setting); ++i)
|
||||
{
|
||||
bool mod = false;
|
||||
m_box.getSettingMod(i, mod);
|
||||
if (mod) { size++; }
|
||||
}
|
||||
}
|
||||
else { size = m_box.getInterfacorCountIncludingDeprecated(Kernel::EBoxInterfacorType::Setting); }
|
||||
gtk_table_resize(m_settingsTable, guint(size + 2), 4);
|
||||
|
||||
// Iterate over box settings, generate corresponding gtk widgets. If the scenario is running, we are making a
|
||||
// 'modifiable settings' dialog and use a subset of widgets with a slightly different layout and buttons.
|
||||
for (size_t settingIdx = 0, tableIdx = 0; settingIdx < m_box.getInterfacorCountIncludingDeprecated(Kernel::EBoxInterfacorType::Setting); ++settingIdx)
|
||||
{
|
||||
if (addSettingsToView(settingIdx, tableIdx)) { ++tableIdx; }
|
||||
}
|
||||
updateSize();
|
||||
}
|
||||
|
||||
bool CBoxConfigurationDialog::addSettingsToView(const size_t settingIdx, const size_t tableIdx)
|
||||
{
|
||||
bool modifiable;
|
||||
m_box.getSettingMod(settingIdx, modifiable);
|
||||
|
||||
if ((!m_isScenarioRunning) || (m_isScenarioRunning && modifiable))
|
||||
{
|
||||
CString name;
|
||||
|
||||
m_box.getSettingName(settingIdx, name);
|
||||
Setting::CAbstractSettingView* view = m_settingFactory.getSettingView(m_box, settingIdx);
|
||||
|
||||
bool isDeprecated = false;
|
||||
m_box.getInterfacorDeprecatedStatus(Kernel::EBoxInterfacorType::Setting, settingIdx, isDeprecated);
|
||||
if (isDeprecated)
|
||||
{
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(view->getNameWidget()), false);
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(view->getEntryWidget()), false);
|
||||
}
|
||||
|
||||
gtk_table_attach(m_settingsTable, view->getNameWidget(), 0, 1, guint(tableIdx), guint(tableIdx + 1), GtkAttachOptions(GTK_FILL),
|
||||
GtkAttachOptions(GTK_FILL), 0, 0);
|
||||
gtk_table_attach(m_settingsTable, view->getEntryWidget(), 1, 4, guint(tableIdx), guint(tableIdx + 1),
|
||||
GtkAttachOptions(GTK_SHRINK | GTK_FILL | GTK_EXPAND), GtkAttachOptions(GTK_SHRINK), 0, 0);
|
||||
|
||||
m_settingViews.insert(m_settingViews.begin() + tableIdx, view);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CBoxConfigurationDialog::settingChange(const size_t index)
|
||||
{
|
||||
//We remeber the place to add the new setting at the same place
|
||||
const size_t indexTable = getTableIndex(index);
|
||||
|
||||
removeSetting(index, false);
|
||||
addSettingsToView(index, indexTable);
|
||||
}
|
||||
|
||||
void CBoxConfigurationDialog::addSetting(const size_t index)
|
||||
{
|
||||
bool modifiable;
|
||||
m_box.getSettingMod(index, modifiable);
|
||||
|
||||
if ((!m_isScenarioRunning) || (m_isScenarioRunning && modifiable))
|
||||
{
|
||||
const size_t size = m_settingViews.size();
|
||||
/*There is two case.
|
||||
1) we just add at the end of the setting box
|
||||
2) we add it in the middle end we need to shift
|
||||
*/
|
||||
const size_t tableIdx = (index > m_settingViews[size - 1]->getSettingIndex()) ? size : getTableIndex(index);
|
||||
|
||||
gtk_table_resize(m_settingsTable, guint(size + 2), 4);
|
||||
|
||||
if (index <= m_settingViews[size - 1]->getSettingIndex())
|
||||
{
|
||||
for (size_t i = size - 1; i >= tableIdx; --i)
|
||||
{
|
||||
Setting::CAbstractSettingView* view = m_settingViews[i];
|
||||
|
||||
//We need to update the index
|
||||
view->setSettingIndex(view->getSettingIndex() + 1);
|
||||
|
||||
gtk_container_remove(GTK_CONTAINER(m_settingsTable), view->getNameWidget());
|
||||
gtk_table_attach(m_settingsTable, view->getNameWidget(), 0, 1, guint(i + 1), guint(i + 2), GtkAttachOptions(GTK_FILL),
|
||||
GtkAttachOptions(GTK_FILL), 0, 0);
|
||||
|
||||
gtk_container_remove(GTK_CONTAINER(m_settingsTable), view->getEntryWidget());
|
||||
gtk_table_attach(m_settingsTable, view->getEntryWidget(), 1, 4, guint(i + 1), guint(i + 2),
|
||||
GtkAttachOptions(GTK_SHRINK | GTK_FILL | GTK_EXPAND), GtkAttachOptions(GTK_SHRINK), 0, 0);
|
||||
}
|
||||
}
|
||||
addSettingsToView(size_t(tableIdx), index);
|
||||
updateSize();
|
||||
}
|
||||
//Even if nothing is add to the interface, we still need to update index
|
||||
else
|
||||
{
|
||||
for (Setting::CAbstractSettingView* view : m_settingViews)
|
||||
{
|
||||
if (view->getSettingIndex() >= index) { view->setSettingIndex(view->getSettingIndex() + 1); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CBoxConfigurationDialog::removeSetting(const size_t index, const bool shift)
|
||||
{
|
||||
const int tableIdx = getTableIndex(index);
|
||||
|
||||
if (tableIdx != -1)
|
||||
{
|
||||
Setting::CAbstractSettingView* view = m_settingViews[tableIdx];
|
||||
GtkWidget* name = view->getNameWidget();
|
||||
GtkWidget* entry = view->getEntryWidget();
|
||||
|
||||
gtk_container_remove(GTK_CONTAINER(m_settingsTable), name);
|
||||
gtk_container_remove(GTK_CONTAINER(m_settingsTable), entry);
|
||||
|
||||
delete view;
|
||||
m_settingViews.erase(m_settingViews.begin() + tableIdx);
|
||||
|
||||
//Now if we need to do it we shift everything to avoid an empty row in the table
|
||||
if (shift)
|
||||
{
|
||||
for (size_t i = tableIdx; i < m_settingViews.size(); ++i)
|
||||
{
|
||||
view = m_settingViews[i];
|
||||
view->setSettingIndex(view->getSettingIndex() - 1);
|
||||
|
||||
gtk_container_remove(GTK_CONTAINER(m_settingsTable), view->getNameWidget());
|
||||
gtk_table_attach(m_settingsTable, view->getNameWidget(), 0, 1, guint(i), guint(i + 1), GtkAttachOptions(GTK_FILL), GtkAttachOptions(GTK_FILL),
|
||||
0, 0);
|
||||
|
||||
gtk_container_remove(GTK_CONTAINER(m_settingsTable), view->getEntryWidget());
|
||||
gtk_table_attach(m_settingsTable, view->getEntryWidget(), 1, 4, guint(i), guint(i + 1), GtkAttachOptions(GTK_SHRINK | GTK_FILL | GTK_EXPAND),
|
||||
GtkAttachOptions(GTK_SHRINK), 0, 0);
|
||||
}
|
||||
//Now let's resize everything
|
||||
gtk_table_resize(m_settingsTable, guint(m_settingViews.size() + 2), 4);
|
||||
updateSize();
|
||||
}
|
||||
}
|
||||
//Even if we delete an "invisible" setting we need to update every index.
|
||||
else
|
||||
{
|
||||
for (Setting::CAbstractSettingView* view : m_settingViews)
|
||||
{
|
||||
if (view->getSettingIndex() >= index) { view->setSettingIndex(view->getSettingIndex() - 1); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int CBoxConfigurationDialog::getTableIndex(const size_t index)
|
||||
{
|
||||
size_t tableIdx = 0;
|
||||
for (auto it = m_settingViews.begin(); it != m_settingViews.end(); ++it, ++tableIdx)
|
||||
{
|
||||
Setting::CAbstractSettingView* view = *it;
|
||||
if (view->getSettingIndex() == index) { return int(index); }
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void CBoxConfigurationDialog::updateSize() const
|
||||
{
|
||||
// Resize the window to fit as much of the table as possible, but keep the max size
|
||||
// limited so it doesn't get outside the screen. For safety, we cap to 800x600
|
||||
// anyway to hopefully prevent the window from going under things such as the gnome toolbar.
|
||||
// The ui file at the moment does not allow resize of this window because the result
|
||||
// looked ugly if the window was made overly large, and no satisfying solution at the time was
|
||||
// found by the limited intellectual resources available.
|
||||
const gint maxWidth = std::min(800, gdk_screen_get_width(gdk_screen_get_default()));
|
||||
const gint maxHeight = std::min(600, gdk_screen_get_height(gdk_screen_get_default()));
|
||||
GtkRequisition size;
|
||||
gtk_widget_size_request(GTK_WIDGET(m_viewPort), &size);
|
||||
gtk_widget_set_size_request(GTK_WIDGET(m_scrolledWindow), gint(std::min(maxWidth, size.width)), gint(std::min(maxHeight, size.height)));
|
||||
}
|
||||
|
||||
void CBoxConfigurationDialog::saveConfig() const
|
||||
{
|
||||
GtkWidget* widgetDialogOpen = gtk_file_chooser_dialog_new("Select file to save settings to...", nullptr, GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, nullptr);
|
||||
|
||||
const gchar* initialFileNameToExpand = gtk_entry_get_text(GTK_ENTRY(m_overrideEntryContainer));
|
||||
const CString initialFileName = m_kernelCtx.getConfigurationManager().expand(initialFileNameToExpand);
|
||||
if (g_path_is_absolute(initialFileName.toASCIIString()))
|
||||
{
|
||||
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(widgetDialogOpen), initialFileName.toASCIIString());
|
||||
}
|
||||
else
|
||||
{
|
||||
char* fullPath = g_build_filename(g_get_current_dir(), initialFileName.toASCIIString(), nullptr);
|
||||
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(widgetDialogOpen), fullPath);
|
||||
g_free(fullPath);
|
||||
}
|
||||
|
||||
if (gtk_dialog_run(GTK_DIALOG(widgetDialogOpen)) == GTK_RESPONSE_ACCEPT)
|
||||
{
|
||||
char* fileName = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widgetDialogOpen));
|
||||
|
||||
XML::IXMLHandler* handler = XML::createXMLHandler();
|
||||
XML::IXMLNode* rootNode = XML::createNode(ROOT_NAME);
|
||||
for (size_t i = 0; i < m_box.getInterfacorCountIncludingDeprecated(Kernel::EBoxInterfacorType::Setting); ++i)
|
||||
{
|
||||
XML::IXMLNode* tmpNode = XML::createNode(SETTING_NAME);
|
||||
CString value;
|
||||
m_box.getSettingValue(size_t(i), value);
|
||||
tmpNode->setPCData(value.toASCIIString());
|
||||
|
||||
rootNode->addChild(tmpNode);
|
||||
}
|
||||
|
||||
handler->writeXMLInFile(*rootNode, fileName);
|
||||
|
||||
handler->release();
|
||||
rootNode->release();
|
||||
g_free(fileName);
|
||||
}
|
||||
gtk_widget_destroy(widgetDialogOpen);
|
||||
}
|
||||
|
||||
void CBoxConfigurationDialog::loadConfig() const
|
||||
{
|
||||
GtkWidget* widgetDialogOpen = gtk_file_chooser_dialog_new("Select file to load settings from...", nullptr, GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, nullptr);
|
||||
|
||||
const gchar* filenameToExpand = gtk_entry_get_text(GTK_ENTRY(m_overrideEntryContainer));
|
||||
|
||||
const CString filename = m_kernelCtx.getConfigurationManager().expand(filenameToExpand);
|
||||
if (g_path_is_absolute(filename.toASCIIString())) { gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(widgetDialogOpen), filename.toASCIIString()); }
|
||||
else
|
||||
{
|
||||
char* fullPath = g_build_filename(g_get_current_dir(), filename.toASCIIString(), nullptr);
|
||||
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(widgetDialogOpen), fullPath);
|
||||
g_free(fullPath);
|
||||
}
|
||||
|
||||
if (gtk_dialog_run(GTK_DIALOG(widgetDialogOpen)) == GTK_RESPONSE_ACCEPT)
|
||||
{
|
||||
char* path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widgetDialogOpen));
|
||||
|
||||
XML::IXMLHandler* handler = XML::createXMLHandler();
|
||||
XML::IXMLNode* rootNode = handler->parseFile(path);
|
||||
|
||||
for (size_t i = 0; i < rootNode->getChildCount(); ++i)
|
||||
{
|
||||
//Hope everything will fit in the right place
|
||||
m_box.setSettingValue(size_t(i), rootNode->getChild(i)->getPCData());
|
||||
}
|
||||
|
||||
rootNode->release();
|
||||
handler->release();
|
||||
g_free(path);
|
||||
}
|
||||
gtk_widget_destroy(widgetDialogOpen);
|
||||
}
|
||||
|
||||
void CBoxConfigurationDialog::onOverrideBrowse() const
|
||||
{
|
||||
GtkWidget* widgetDialogOpen = gtk_file_chooser_dialog_new("Select file to open...", nullptr, GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, nullptr);
|
||||
|
||||
const CString initialFilename = m_kernelCtx.getConfigurationManager().expand(gtk_entry_get_text(GTK_ENTRY(m_overrideEntry)));
|
||||
if (g_path_is_absolute(initialFilename.toASCIIString()))
|
||||
{
|
||||
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(widgetDialogOpen), initialFilename.toASCIIString());
|
||||
}
|
||||
else
|
||||
{
|
||||
char* fullPath = g_build_filename(g_get_current_dir(), initialFilename.toASCIIString(), nullptr);
|
||||
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(widgetDialogOpen), fullPath);
|
||||
g_free(fullPath);
|
||||
}
|
||||
|
||||
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(widgetDialogOpen), false);
|
||||
|
||||
if (gtk_dialog_run(GTK_DIALOG(widgetDialogOpen)) == GTK_RESPONSE_ACCEPT)
|
||||
{
|
||||
gchar* name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widgetDialogOpen));
|
||||
std::string filename(name);
|
||||
g_free(name);
|
||||
std::replace(filename.begin(), filename.end(), '\\', '/');
|
||||
gtk_entry_set_text(GTK_ENTRY(m_overrideEntry), filename.c_str());
|
||||
}
|
||||
gtk_widget_destroy(widgetDialogOpen);
|
||||
}
|
||||
|
||||
|
||||
void CBoxConfigurationDialog::storeState()
|
||||
{
|
||||
m_settingsMemory.clear();
|
||||
for (size_t i = 0; i < m_box.getInterfacorCountIncludingDeprecated(Kernel::EBoxInterfacorType::Setting); ++i)
|
||||
{
|
||||
CString temp;
|
||||
m_box.getSettingValue(i, temp);
|
||||
m_settingsMemory.push_back(temp);
|
||||
}
|
||||
}
|
||||
|
||||
void CBoxConfigurationDialog::restoreState()
|
||||
{
|
||||
for (size_t i = 0; i < m_settingsMemory.size(); ++i)
|
||||
{
|
||||
if (i >= m_box.getInterfacorCountIncludingDeprecated(Kernel::EBoxInterfacorType::Setting)) { return; } // This is not supposed to happen
|
||||
m_box.setSettingValue(i, m_settingsMemory[i]);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
#include "ovd_base.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "dynamic_settings/ovdCAbstractSettingView.h"
|
||||
#include "dynamic_settings/ovdCSettingViewFactory.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
class CBoxConfigurationDialog final : public IObserver
|
||||
{
|
||||
public:
|
||||
|
||||
CBoxConfigurationDialog(const Kernel::IKernelContext& ctx, Kernel::IBox& box, const char* guiFilename,
|
||||
const char* guiSettingsFilename, const bool isScenarioRunning = false);
|
||||
~CBoxConfigurationDialog() override;
|
||||
|
||||
bool run();
|
||||
void update(CObservable& o, void* data) override;
|
||||
|
||||
void saveConfig() const;
|
||||
void loadConfig() const;
|
||||
void onOverrideBrowse() const;
|
||||
|
||||
void storeState();
|
||||
void restoreState();
|
||||
|
||||
CIdentifier getBoxID() const { return m_box.getIdentifier(); }
|
||||
GtkWidget* getWidget() const { return m_settingDialog; }
|
||||
protected:
|
||||
|
||||
void generateSettingsTable();
|
||||
bool addSettingsToView(const size_t settingIdx, const size_t tableIdx);
|
||||
void updateSize() const;
|
||||
void settingChange(const size_t index);
|
||||
void addSetting(const size_t index);
|
||||
void removeSetting(const size_t index, bool shift = true);
|
||||
int getTableIndex(const size_t index);
|
||||
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
Kernel::IBox& m_box;
|
||||
CString m_guiFilename;
|
||||
CString m_guiSettingsFilename;
|
||||
|
||||
Setting::CSettingViewFactory m_settingFactory;
|
||||
std::vector<Setting::CAbstractSettingView*> m_settingViews;
|
||||
GtkTable* m_settingsTable = nullptr;
|
||||
GtkViewport* m_viewPort = nullptr;
|
||||
GtkScrolledWindow* m_scrolledWindow = nullptr;
|
||||
GtkEntry* m_overrideEntry = nullptr;
|
||||
GtkWidget* m_overrideEntryContainer = nullptr;
|
||||
GtkWidget* m_settingDialog = nullptr;
|
||||
GtkCheckButton* m_fileOverrideCheck = nullptr;
|
||||
bool m_isScenarioRunning = false;
|
||||
|
||||
std::vector<CString> m_settingsMemory;
|
||||
};
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
Executable
+194
@@ -0,0 +1,194 @@
|
||||
#include "ovdCBoxProxy.h"
|
||||
#include "ovdTAttributeHandler.h"
|
||||
#include <fs/Files.h>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
CBoxProxy::CBoxProxy(const Kernel::IKernelContext& ctx, Kernel::IScenario& scenario, const CIdentifier& boxID)
|
||||
: m_kernelCtx(ctx), m_constBox(scenario.getBoxDetails(boxID)), m_box(scenario.getBoxDetails(boxID)),
|
||||
m_isDeprecated(m_kernelCtx.getPluginManager().isPluginObjectFlaggedAsDeprecated(m_constBox->getAlgorithmClassIdentifier()))
|
||||
{
|
||||
m_isBoxAlgorithmPresent = false;
|
||||
|
||||
if (m_constBox)
|
||||
{
|
||||
if (m_constBox->getAlgorithmClassIdentifier() == OVP_ClassId_BoxAlgorithm_Metabox)
|
||||
{
|
||||
CIdentifier metaboxId;
|
||||
metaboxId.fromString(m_constBox->getAttributeValue(OVP_AttributeId_Metabox_ID));
|
||||
const CString path(m_kernelCtx.getMetaboxManager().getMetaboxFilePath(metaboxId));
|
||||
|
||||
m_isBoxAlgorithmPresent = FS::Files::fileExists(path.toASCIIString());
|
||||
}
|
||||
else { m_isBoxAlgorithmPresent = m_kernelCtx.getPluginManager().canCreatePluginObject(m_constBox->getAlgorithmClassIdentifier()); }
|
||||
|
||||
const TAttributeHandler handler(*m_constBox);
|
||||
m_centerX = handler.getAttributeValue<int>(OV_AttributeId_Box_XCenterPosition);
|
||||
m_centerY = handler.getAttributeValue<int>(OV_AttributeId_Box_YCenterPosition);
|
||||
}
|
||||
m_showOriginalNameWhenModified = m_kernelCtx.getConfigurationManager().expandAsBoolean("${Designer_ShowOriginalBoxName}", true);
|
||||
}
|
||||
|
||||
int CBoxProxy::getWidth(GtkWidget* widget) const
|
||||
{
|
||||
int x, y;
|
||||
updateSize(widget, getLabel(), getStatusLabel(), &x, &y);
|
||||
return x;
|
||||
}
|
||||
|
||||
int CBoxProxy::getHeight(GtkWidget* widget) const
|
||||
{
|
||||
int x, y;
|
||||
updateSize(widget, getLabel(), getStatusLabel(), &x, &y);
|
||||
return y;
|
||||
}
|
||||
|
||||
void CBoxProxy::setCenter(const int x, const int y)
|
||||
{
|
||||
m_centerX = x;
|
||||
m_centerY = y;
|
||||
m_applied = false;
|
||||
}
|
||||
|
||||
void CBoxProxy::setBoxAlgorithmDescriptorOverride(const Plugins::IBoxAlgorithmDesc* pBoxAlgorithmDescriptor)
|
||||
{
|
||||
m_boxAlgorithmDescOverride = pBoxAlgorithmDescriptor;
|
||||
}
|
||||
|
||||
void CBoxProxy::apply()
|
||||
{
|
||||
if (m_box)
|
||||
{
|
||||
TAttributeHandler handler(*m_box);
|
||||
|
||||
if (handler.hasAttribute(OV_AttributeId_Box_XCenterPosition)) { handler.setAttributeValue<int>(OV_AttributeId_Box_XCenterPosition, m_centerX); }
|
||||
else { handler.addAttribute<int>(OV_AttributeId_Box_XCenterPosition, m_centerX); }
|
||||
|
||||
if (handler.hasAttribute(OV_AttributeId_Box_YCenterPosition)) { handler.setAttributeValue<int>(OV_AttributeId_Box_YCenterPosition, m_centerY); }
|
||||
else { handler.addAttribute<int>(OV_AttributeId_Box_YCenterPosition, m_centerY); }
|
||||
|
||||
m_applied = true;
|
||||
}
|
||||
}
|
||||
|
||||
const char* CBoxProxy::getLabel() const
|
||||
{
|
||||
const bool canChangeInput(
|
||||
m_constBox->hasAttribute(OV_AttributeId_Box_FlagCanModifyInput) || m_constBox->hasAttribute(OV_AttributeId_Box_FlagCanAddInput));
|
||||
const bool canChangeOutput(
|
||||
m_constBox->hasAttribute(OV_AttributeId_Box_FlagCanModifyOutput) || m_constBox->hasAttribute(OV_AttributeId_Box_FlagCanAddOutput));
|
||||
const bool canChangeSetting(
|
||||
m_constBox->hasAttribute(OV_AttributeId_Box_FlagCanModifySetting) || m_constBox->hasAttribute(OV_AttributeId_Box_FlagCanAddSetting));
|
||||
|
||||
const Plugins::IPluginObjectDesc* desc = (m_boxAlgorithmDescOverride == nullptr
|
||||
? m_kernelCtx.getPluginManager().getPluginObjectDescCreating(m_constBox->getAlgorithmClassIdentifier())
|
||||
: m_boxAlgorithmDescOverride);
|
||||
|
||||
std::string name(m_constBox->getName());
|
||||
|
||||
const std::string red("#602020"), green("#206020"), grey("#404040");
|
||||
|
||||
// pango is used in the box diplay to format the box name (e.g. bold to tell it's a configurable box)
|
||||
// incidently, this makes the box name pango-enabled. If an error appears in the markup, the box display would be wrong.
|
||||
if (!pango_parse_markup(name.c_str(), -1, 0, nullptr, nullptr, nullptr, nullptr))
|
||||
{
|
||||
// the name uses invalid markup characters
|
||||
// we sanitize the markup tag overture '<'
|
||||
// markup should not be used in the box name anyway (hidden feature),
|
||||
// but the character '<' may actually be useful in a valid name
|
||||
for (size_t c = 0; c < name.size(); ++c)
|
||||
{
|
||||
if (name[c] == '<')
|
||||
{
|
||||
name[c] = ';';
|
||||
name.insert(c, "<");
|
||||
}
|
||||
else if (name[c] == '&')
|
||||
{
|
||||
name[c] = ';';
|
||||
name.insert(c, "&");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_label = name;
|
||||
|
||||
if (name.empty()) { m_label = "Unnamed Box"; }
|
||||
|
||||
const std::string boxNameColor = "#000000";
|
||||
|
||||
if (m_constBox->getSettingCount() != 0) { m_label = "<span color=\"" + boxNameColor + R"(" weight="bold">)" + m_label + "</span>"; }
|
||||
|
||||
if (m_showOriginalNameWhenModified)
|
||||
{
|
||||
const std::string boxOriginalName(desc ? std::string(desc->getName()) : name);
|
||||
if (boxOriginalName != name) { m_label = "<small><i><span foreground=\"" + grey + "\">" + boxOriginalName + "</span></i></small>\n" + m_label; }
|
||||
}
|
||||
|
||||
if (canChangeInput || canChangeOutput || canChangeSetting)
|
||||
{
|
||||
m_label += "\n<span size=\"smaller\">";
|
||||
m_label += "<span foreground=\"" + (canChangeInput ? green : red) + "\">In</span>";
|
||||
m_label += "|<span foreground=\"" + (canChangeOutput ? green : red) + "\">Out</span>";
|
||||
m_label += "|<span foreground=\"" + (canChangeSetting ? green : red) + "\">Set</span>";
|
||||
m_label += "</span>";
|
||||
}
|
||||
|
||||
return m_label.c_str();
|
||||
}
|
||||
|
||||
const char* CBoxProxy::getStatusLabel() const
|
||||
{
|
||||
const bool toBeUpdated(m_box->hasAttribute(OV_AttributeId_Box_ToBeUpdated));
|
||||
const bool pendingDeprecatedInterfacors(m_box->hasAttribute(OV_AttributeId_Box_PendingDeprecatedInterfacors));
|
||||
const bool isDeprecated(this->isBoxAlgorithmPluginPresent() && this->isDeprecated());
|
||||
const bool isDisabled(this->isDisabled());
|
||||
|
||||
const std::string blue("#202060");
|
||||
|
||||
m_status = "";
|
||||
if (isDeprecated || toBeUpdated || isDisabled || pendingDeprecatedInterfacors)
|
||||
{
|
||||
m_status += R"(<span size="smaller" foreground=")" + blue + "\">";
|
||||
if (isDeprecated) { m_status += " <span style=\"italic\">deprecated</span>"; }
|
||||
if (toBeUpdated) { m_status += " <span style=\"italic\">update</span>"; }
|
||||
if (isDisabled) { m_status += " <span style=\"italic\">disabled</span>"; }
|
||||
if (pendingDeprecatedInterfacors) { m_status += " <span style=\"italic\">deprecated I/O/S</span>"; }
|
||||
m_status += " </span>";
|
||||
}
|
||||
return m_status.c_str();
|
||||
}
|
||||
|
||||
bool CBoxProxy::isDisabled() const
|
||||
{
|
||||
const TAttributeHandler handler(*m_constBox);
|
||||
return handler.hasAttribute(OV_AttributeId_Box_Disabled);
|
||||
}
|
||||
|
||||
void CBoxProxy::updateSize(GtkWidget* widget, const char* label, const char* status, int* xSize, int* ySize) const
|
||||
{
|
||||
PangoRectangle labelRect;
|
||||
PangoRectangle statusRect;
|
||||
PangoContext* context = gtk_widget_create_pango_context(widget);
|
||||
PangoLayout* layout = pango_layout_new(context);
|
||||
pango_layout_set_markup(layout, label, -1);
|
||||
pango_layout_get_pixel_extents(layout, nullptr, &labelRect);
|
||||
pango_layout_set_markup(layout, status, -1);
|
||||
pango_layout_get_pixel_extents(layout, nullptr, &statusRect);
|
||||
|
||||
if (!strlen(status))
|
||||
{
|
||||
statusRect.width = 0;
|
||||
statusRect.height = 0;
|
||||
}
|
||||
|
||||
*xSize = std::max(labelRect.width, statusRect.width);
|
||||
*ySize = labelRect.height + statusRect.height;
|
||||
|
||||
g_object_unref(layout);
|
||||
g_object_unref(context);
|
||||
}
|
||||
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include "ovd_base.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
class CBoxProxy final
|
||||
{
|
||||
public:
|
||||
|
||||
CBoxProxy(const Kernel::IKernelContext& ctx, Kernel::IScenario& scenario, const CIdentifier& boxID);
|
||||
~CBoxProxy() { if (!m_applied) { this->apply(); } }
|
||||
|
||||
operator Kernel::IBox*() const { return m_box; }
|
||||
operator const Kernel::IBox*() const { return m_constBox; }
|
||||
|
||||
int getWidth(GtkWidget* widget) const;
|
||||
int getHeight(GtkWidget* widget) const;
|
||||
|
||||
int getXCenter() const { return m_centerX; }
|
||||
int getYCenter() const { return m_centerY; }
|
||||
void setCenter(int x, int y);
|
||||
|
||||
void setBoxAlgorithmDescriptorOverride(const Plugins::IBoxAlgorithmDesc* pBoxAlgorithmDescriptor);
|
||||
|
||||
void apply();
|
||||
|
||||
const char* getLabel() const;
|
||||
const char* getStatusLabel() const;
|
||||
|
||||
bool isBoxAlgorithmPluginPresent() const { return m_isBoxAlgorithmPresent; }
|
||||
bool isUpToDate() const { return !m_box->hasAttribute(OV_AttributeId_Box_ToBeUpdated); }
|
||||
bool hasPendingDeprecatedInterfacors() const { return m_box->hasAttribute(OV_AttributeId_Box_PendingDeprecatedInterfacors); }
|
||||
bool isDeprecated() const { return m_isDeprecated; }
|
||||
static bool isUnstable() { return false; }
|
||||
bool isDisabled() const;
|
||||
bool isMetabox() const { return m_constBox->getAlgorithmClassIdentifier() == OVP_ClassId_BoxAlgorithm_Metabox; }
|
||||
|
||||
protected:
|
||||
|
||||
void updateSize(GtkWidget* widget, const char* label, const char* status, int* xSize, int* ySize) const;
|
||||
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
const Plugins::IBoxAlgorithmDesc* m_boxAlgorithmDescOverride = nullptr;
|
||||
const Kernel::IBox* m_constBox = nullptr;
|
||||
Kernel::IBox* m_box = nullptr;
|
||||
bool m_applied = false;
|
||||
bool m_showOriginalNameWhenModified = false;
|
||||
int m_centerX = 0;
|
||||
int m_centerY = 0;
|
||||
mutable std::string m_label;
|
||||
mutable std::string m_status;
|
||||
bool m_isBoxAlgorithmPresent = false;
|
||||
bool m_isDeprecated = false;
|
||||
};
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
#include "ovdCCommentEditorDialog.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
static void BoldSelectionCB(GtkButton* /*button*/, gpointer data) { static_cast<CCommentEditorDialog*>(data)->applyTagCB("<b>", "</b>"); }
|
||||
static void ItalicSelectionCB(GtkButton* /*button*/, gpointer data) { static_cast<CCommentEditorDialog*>(data)->applyTagCB("<i>", "</i>"); }
|
||||
static void UnderlineCB(GtkButton* /*button*/, gpointer data) { static_cast<CCommentEditorDialog*>(data)->applyTagCB("<u>", "</u>"); }
|
||||
static void StrikethroughCB(GtkButton* /*button*/, gpointer data) { static_cast<CCommentEditorDialog*>(data)->applyTagCB("<s>", "</s>"); }
|
||||
static void MonoCB(GtkButton* /*button*/, gpointer data) { static_cast<CCommentEditorDialog*>(data)->applyTagCB("<tt>", "</tt>"); }
|
||||
static void SubscriptCB(GtkButton* /*button*/, gpointer data) { static_cast<CCommentEditorDialog*>(data)->applyTagCB("<sub>", "</sub>"); }
|
||||
static void SuperscriptCB(GtkButton* /*button*/, gpointer data) { static_cast<CCommentEditorDialog*>(data)->applyTagCB("<sup>", "</sup>"); }
|
||||
static void BigCB(GtkButton* /*button*/, gpointer data) { static_cast<CCommentEditorDialog*>(data)->applyTagCB("<big>", "</big>"); }
|
||||
static void SmallCB(GtkButton* /*button*/, gpointer data) { static_cast<CCommentEditorDialog*>(data)->applyTagCB("<small>", "</small>"); }
|
||||
static void RedCB(GtkButton* /*button*/, gpointer data) { static_cast<CCommentEditorDialog*>(data)->applyTagCB("<span color=\"red\">", "</span>"); }
|
||||
static void GreenCB(GtkButton* /*button*/, gpointer data) { static_cast<CCommentEditorDialog*>(data)->applyTagCB("<span color=\"green\">", "</span>"); }
|
||||
static void BlueCB(GtkButton* /*button*/, gpointer data) { static_cast<CCommentEditorDialog*>(data)->applyTagCB("<span color=\"blue\">", "</span>"); }
|
||||
static void InfoCB(GtkButton* /*button*/, gpointer data) { static_cast<CCommentEditorDialog*>(data)->infoCB(); }
|
||||
|
||||
bool CCommentEditorDialog::run()
|
||||
{
|
||||
bool res = false;
|
||||
|
||||
m_interface = gtk_builder_new(); // glade_xml_new(m_guiFilename.toASCIIString(), "comment", nullptr);
|
||||
gtk_builder_add_from_file(m_interface, m_guiFilename.toASCIIString(), nullptr);
|
||||
gtk_builder_connect_signals(m_interface, nullptr);
|
||||
|
||||
::g_signal_connect(gtk_builder_get_object(m_interface, "comment_toolbutton_bold"), "clicked", G_CALLBACK(BoldSelectionCB), this);
|
||||
::g_signal_connect(gtk_builder_get_object(m_interface, "comment_toolbutton_italic"), "clicked", G_CALLBACK(ItalicSelectionCB), this);
|
||||
::g_signal_connect(gtk_builder_get_object(m_interface, "comment_toolbutton_underline"), "clicked", G_CALLBACK(UnderlineCB), this);
|
||||
::g_signal_connect(gtk_builder_get_object(m_interface, "comment_toolbutton_strikethrough"), "clicked", G_CALLBACK(StrikethroughCB), this);
|
||||
::g_signal_connect(gtk_builder_get_object(m_interface, "comment_toolbutton_mono"), "clicked", G_CALLBACK(MonoCB), this);
|
||||
::g_signal_connect(gtk_builder_get_object(m_interface, "comment_toolbutton_subscript"), "clicked", G_CALLBACK(SubscriptCB), this);
|
||||
::g_signal_connect(gtk_builder_get_object(m_interface, "comment_toolbutton_superscript"), "clicked", G_CALLBACK(SuperscriptCB), this);
|
||||
::g_signal_connect(gtk_builder_get_object(m_interface, "comment_toolbutton_big"), "clicked", G_CALLBACK(BigCB), this);
|
||||
::g_signal_connect(gtk_builder_get_object(m_interface, "comment_toolbutton_small"), "clicked", G_CALLBACK(SmallCB), this);
|
||||
::g_signal_connect(gtk_builder_get_object(m_interface, "comment_toolbutton_red"), "clicked", G_CALLBACK(RedCB), this);
|
||||
::g_signal_connect(gtk_builder_get_object(m_interface, "comment_toolbutton_green"), "clicked", G_CALLBACK(GreenCB), this);
|
||||
::g_signal_connect(gtk_builder_get_object(m_interface, "comment_toolbutton_blue"), "clicked", G_CALLBACK(BlueCB), this);
|
||||
::g_signal_connect(gtk_builder_get_object(m_interface, "comment_toolbutton_info"), "clicked", G_CALLBACK(InfoCB), this);
|
||||
|
||||
m_dialog = GTK_WIDGET(gtk_builder_get_object(m_interface, "comment"));
|
||||
m_desc = GTK_WIDGET(gtk_builder_get_object(m_interface, "comment-textview_description"));
|
||||
|
||||
m_infoDialog = GTK_WIDGET(gtk_builder_get_object(m_interface, "messagedialog_howto_comment"));
|
||||
::g_signal_connect(m_infoDialog, "close", G_CALLBACK(gtk_widget_hide), nullptr);
|
||||
::g_signal_connect(m_infoDialog, "delete-event", G_CALLBACK(gtk_widget_hide), nullptr);
|
||||
|
||||
//::g_signal_connect(GTK_WIDGET(gtk_builder_get_object(m_interface, "messagedialog_howto_comment_button_close")), "clicked", G_CALLBACK(gtk_widget_hide), nullptr);
|
||||
|
||||
g_object_unref(m_interface);
|
||||
|
||||
m_buffer = gtk_text_buffer_new(nullptr);
|
||||
gtk_text_buffer_set_text(m_buffer, m_comment.getText().toASCIIString(), -1);
|
||||
gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_desc), m_buffer);
|
||||
g_object_unref(m_buffer);
|
||||
|
||||
gtk_widget_grab_focus(m_desc);
|
||||
|
||||
const gint result = gtk_dialog_run(GTK_DIALOG(m_dialog));
|
||||
if (result == GTK_RESPONSE_APPLY)
|
||||
{
|
||||
res = true;
|
||||
GtkTextIter start, end;
|
||||
m_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(m_desc));
|
||||
gtk_text_buffer_get_start_iter(m_buffer, &start);
|
||||
gtk_text_buffer_get_end_iter(m_buffer, &end);
|
||||
m_comment.setText(gtk_text_buffer_get_text(m_buffer, &start, &end, TRUE));
|
||||
}
|
||||
gtk_widget_destroy(m_infoDialog);
|
||||
gtk_widget_destroy(m_dialog);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------
|
||||
void CCommentEditorDialog::applyTagCB(const char* in, const char* out) const
|
||||
{
|
||||
GtkTextIter start, end;
|
||||
|
||||
if (gtk_text_buffer_get_has_selection(m_buffer))
|
||||
{
|
||||
gtk_text_buffer_get_selection_bounds(m_buffer, &start, &end);
|
||||
gtk_text_buffer_insert(m_buffer, &start, in, gint(strlen(in)));
|
||||
gtk_text_buffer_get_selection_bounds(m_buffer, &start, &end);
|
||||
gtk_text_buffer_insert(m_buffer, &end, out, gint(strlen(out)));
|
||||
|
||||
// reset selection to the selected text, as the tagOut is now selected
|
||||
gtk_text_buffer_get_selection_bounds(m_buffer, &start, &end);
|
||||
gtk_text_iter_backward_chars(&end, gint(strlen(out)));
|
||||
gtk_text_buffer_select_range(m_buffer, &start, &end);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_text_buffer_get_selection_bounds(m_buffer, &start, &end);
|
||||
const gint offset = gtk_text_iter_get_offset(&start);
|
||||
|
||||
gtk_text_buffer_insert_at_cursor(m_buffer, in, gint(strlen(in)));
|
||||
gtk_text_buffer_insert_at_cursor(m_buffer, out, gint(strlen(out)));
|
||||
|
||||
gtk_text_buffer_get_iter_at_offset(m_buffer, &start, gint(offset + strlen(in)));
|
||||
gtk_text_buffer_place_cursor(m_buffer, &start);
|
||||
}
|
||||
|
||||
// set focus on the text, to get back in edition mode directly
|
||||
gtk_widget_grab_focus(m_desc);
|
||||
}
|
||||
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "ovd_base.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
class CCommentEditorDialog final
|
||||
{
|
||||
public:
|
||||
|
||||
CCommentEditorDialog(const Kernel::IKernelContext& ctx, Kernel::IComment& comment, const char* guiFilename)
|
||||
: m_kernelCtx(ctx), m_comment(comment), m_guiFilename(guiFilename) { }
|
||||
|
||||
~CCommentEditorDialog() = default;
|
||||
|
||||
bool run();
|
||||
|
||||
// Callback for text formatting
|
||||
void applyTagCB(const char* in, const char* out) const;
|
||||
|
||||
// help formatting pango
|
||||
void infoCB() const { gtk_widget_show(m_infoDialog); }
|
||||
protected:
|
||||
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
Kernel::IComment& m_comment;
|
||||
CString m_guiFilename;
|
||||
|
||||
GtkBuilder* m_interface = nullptr;
|
||||
GtkWidget* m_dialog = nullptr;
|
||||
GtkWidget* m_infoDialog = nullptr;
|
||||
GtkWidget* m_desc = nullptr;
|
||||
GtkTextBuffer* m_buffer = nullptr;
|
||||
|
||||
CCommentEditorDialog() = delete;
|
||||
};
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
#include "ovdCCommentProxy.h"
|
||||
#include "ovdTAttributeHandler.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
CCommentProxy::CCommentProxy(const Kernel::IKernelContext& ctx, const Kernel::IComment& comment)
|
||||
: m_kernelCtx(ctx), m_constComment(&comment)
|
||||
{
|
||||
if (m_constComment)
|
||||
{
|
||||
const TAttributeHandler handler(*m_constComment);
|
||||
m_centerX = handler.getAttributeValue<int>(OV_AttributeId_Comment_XCenterPosition);
|
||||
m_centerY = handler.getAttributeValue<int>(OV_AttributeId_Comment_YCenterPosition);
|
||||
}
|
||||
}
|
||||
|
||||
CCommentProxy::CCommentProxy(const Kernel::IKernelContext& ctx, Kernel::IScenario& scenario, const CIdentifier& commentID)
|
||||
: m_kernelCtx(ctx), m_constComment(scenario.getCommentDetails(commentID)), m_comment(scenario.getCommentDetails(commentID))
|
||||
{
|
||||
if (m_constComment)
|
||||
{
|
||||
const TAttributeHandler handler(*m_constComment);
|
||||
m_centerX = handler.getAttributeValue<int>(OV_AttributeId_Comment_XCenterPosition);
|
||||
m_centerY = handler.getAttributeValue<int>(OV_AttributeId_Comment_YCenterPosition);
|
||||
}
|
||||
}
|
||||
|
||||
int CCommentProxy::getWidth(GtkWidget* widget) const
|
||||
{
|
||||
int x, y;
|
||||
updateSize(widget, getLabel(), &x, &y);
|
||||
return x;
|
||||
}
|
||||
|
||||
int CCommentProxy::getHeight(GtkWidget* widget) const
|
||||
{
|
||||
int x, y;
|
||||
updateSize(widget, getLabel(), &x, &y);
|
||||
return y;
|
||||
}
|
||||
|
||||
void CCommentProxy::setCenter(const int centerX, const int centerY)
|
||||
{
|
||||
m_centerX = centerX;
|
||||
m_centerY = centerY;
|
||||
m_applied = false;
|
||||
}
|
||||
|
||||
void CCommentProxy::apply()
|
||||
{
|
||||
if (m_comment)
|
||||
{
|
||||
TAttributeHandler handler(*m_comment);
|
||||
|
||||
if (handler.hasAttribute(OV_AttributeId_Comment_XCenterPosition)) { handler.setAttributeValue<int>(OV_AttributeId_Comment_XCenterPosition, m_centerX); }
|
||||
else { handler.addAttribute<int>(OV_AttributeId_Comment_XCenterPosition, m_centerX); }
|
||||
|
||||
if (handler.hasAttribute(OV_AttributeId_Comment_YCenterPosition)) { handler.setAttributeValue<int>(OV_AttributeId_Comment_YCenterPosition, m_centerY); }
|
||||
else { handler.addAttribute<int>(OV_AttributeId_Comment_YCenterPosition, m_centerY); }
|
||||
m_applied = true;
|
||||
}
|
||||
}
|
||||
|
||||
const char* CCommentProxy::getLabel() const
|
||||
{
|
||||
m_label = m_constComment->getText().toASCIIString();
|
||||
return m_label.c_str();
|
||||
}
|
||||
|
||||
void CCommentProxy::updateSize(GtkWidget* widget, const char* text, int* xSize, int* ySize)
|
||||
{
|
||||
PangoRectangle rectangle;
|
||||
PangoContext* context = gtk_widget_create_pango_context(widget);
|
||||
PangoLayout* layout = pango_layout_new(context);
|
||||
|
||||
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
|
||||
if (pango_parse_markup(text, -1, 0, nullptr, nullptr, nullptr, nullptr)) { pango_layout_set_markup(layout, text, -1); }
|
||||
else { pango_layout_set_text(layout, text, -1); }
|
||||
pango_layout_get_pixel_extents(layout, nullptr, &rectangle);
|
||||
*xSize = rectangle.width;
|
||||
*ySize = rectangle.height;
|
||||
g_object_unref(layout);
|
||||
g_object_unref(context);
|
||||
}
|
||||
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include "ovd_base.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
class CCommentProxy final
|
||||
{
|
||||
public:
|
||||
|
||||
CCommentProxy(const Kernel::IKernelContext& ctx, const Kernel::IComment& comment);
|
||||
CCommentProxy(const Kernel::IKernelContext& ctx, Kernel::IScenario& scenario, const CIdentifier& commentID);
|
||||
~CCommentProxy() { if (!m_applied) { this->apply(); } }
|
||||
|
||||
operator Kernel::IComment*() const { return m_comment; }
|
||||
operator const Kernel::IComment*() const { return m_constComment; }
|
||||
|
||||
int getWidth(GtkWidget* widget) const;
|
||||
int getHeight(GtkWidget* widget) const;
|
||||
|
||||
int getXCenter() const { return m_centerX; }
|
||||
int getYCenter() const { return m_centerY; }
|
||||
|
||||
void setCenter(int centerX, int centerY);
|
||||
|
||||
void apply();
|
||||
|
||||
const char* getLabel() const;
|
||||
|
||||
protected:
|
||||
|
||||
static void updateSize(GtkWidget* widget, const char* text, int* xSize, int* ySize);
|
||||
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
const Kernel::IComment* m_constComment = nullptr;
|
||||
Kernel::IComment* m_comment = nullptr;
|
||||
bool m_applied = false;
|
||||
int m_centerX = 0;
|
||||
int m_centerY = 0;
|
||||
mutable std::string m_label;
|
||||
};
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
#include "ovdCConnectorEditor.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
static void reset_scenario_connector_identifier(GtkWidget* /*widget*/, CConnectorEditor* self)
|
||||
{
|
||||
const CIdentifier newID = self->m_Box.getUnusedInputIdentifier(CIdentifier::undefined());
|
||||
if (self->m_IDEntry && newID != CIdentifier::undefined()) { gtk_entry_set_text(self->m_IDEntry, newID.str().c_str()); }
|
||||
}
|
||||
|
||||
bool CConnectorEditor::run()
|
||||
{
|
||||
//get_identifier_t getID;
|
||||
set_name_t setName;
|
||||
set_type_t setType;
|
||||
is_type_supported_t isTypeSupported;
|
||||
//update_identifier_t updateID;
|
||||
|
||||
Kernel::EBoxInterfacorType interfacorType;
|
||||
switch (m_type)
|
||||
{
|
||||
case Box_Input:
|
||||
setName = &Kernel::IBox::setInputName;
|
||||
setType = &Kernel::IBox::setInputType;
|
||||
isTypeSupported = &Kernel::IBox::hasInputSupport;
|
||||
interfacorType = Kernel::Input;
|
||||
break;
|
||||
|
||||
case Box_Output:
|
||||
setName = &Kernel::IBox::setOutputName;
|
||||
setType = &Kernel::IBox::setOutputType;
|
||||
isTypeSupported = &Kernel::IBox::hasOutputSupport;
|
||||
interfacorType = Kernel::Output;
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
CString name;
|
||||
CIdentifier typeID;
|
||||
CIdentifier id;
|
||||
m_Box.getInterfacorIdentifier(interfacorType, m_index, id);
|
||||
m_Box.getInterfacorName(interfacorType, m_index, name);
|
||||
m_Box.getInterfacorType(interfacorType, m_index, typeID);
|
||||
|
||||
GtkBuilder* builder = gtk_builder_new();
|
||||
gtk_builder_add_from_file(builder, m_guiFilename.c_str(), nullptr);
|
||||
gtk_builder_connect_signals(builder, nullptr);
|
||||
|
||||
GtkWidget* dialog = GTK_WIDGET(gtk_builder_get_object(builder, "connector_editor"));
|
||||
GtkEntry* nameEntry = GTK_ENTRY(gtk_builder_get_object(builder, "connector_editor-connector_name_entry"));
|
||||
GtkComboBox* typeComboBox = GTK_COMBO_BOX(gtk_builder_get_object(builder, "connector_editor-connector_type_combobox"));
|
||||
m_IDEntry = GTK_ENTRY(gtk_builder_get_object(builder, "connector_editor-connector_identifier_entry"));
|
||||
GtkButton* idResetButton = GTK_BUTTON(gtk_builder_get_object(builder, "connector_editor-connector_identifier_reset_button"));
|
||||
gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(typeComboBox)));
|
||||
gtk_window_set_title(GTK_WINDOW(dialog), m_title.c_str());
|
||||
|
||||
if (m_Box.getAlgorithmClassIdentifier() == CIdentifier::undefined())
|
||||
{
|
||||
gtk_widget_show(GTK_WIDGET(gtk_builder_get_object(builder, "connector_editor-connector_identifier_label")));
|
||||
gtk_widget_show(GTK_WIDGET(m_IDEntry));
|
||||
gtk_widget_show(GTK_WIDGET(idResetButton));
|
||||
g_signal_connect(GTK_WIDGET(idResetButton), "clicked", G_CALLBACK(reset_scenario_connector_identifier), this);
|
||||
}
|
||||
|
||||
//get a list of stream types and display connector type
|
||||
std::map<std::string, CIdentifier> streamTypes;
|
||||
gint active = -1;
|
||||
|
||||
for (const auto& currentTypeID : m_kernelCtx.getTypeManager().getSortedTypes())
|
||||
{
|
||||
//First check if the type is support by the connector
|
||||
if ((m_Box.*isTypeSupported)(currentTypeID.first))
|
||||
{
|
||||
//If the input type is support by the connector, let's add it to the list
|
||||
if (m_kernelCtx.getTypeManager().isStream(currentTypeID.first))
|
||||
{
|
||||
gtk_combo_box_append_text(typeComboBox, currentTypeID.second.toASCIIString());
|
||||
if (currentTypeID.first == typeID)
|
||||
{
|
||||
active = gint(streamTypes.size());
|
||||
gtk_combo_box_set_active(typeComboBox, active);
|
||||
}
|
||||
streamTypes[currentTypeID.second.toASCIIString()] = currentTypeID.first;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//display connector name
|
||||
gtk_entry_set_text(nameEntry, name.toASCIIString());
|
||||
gtk_entry_set_text(m_IDEntry, id.str().c_str());
|
||||
|
||||
bool finished = false;
|
||||
bool res = false;
|
||||
while (!finished)
|
||||
{
|
||||
const gint result = gtk_dialog_run(GTK_DIALOG(dialog));
|
||||
if (result == GTK_RESPONSE_APPLY)
|
||||
{
|
||||
char* activeText = gtk_combo_box_get_active_text(typeComboBox);
|
||||
if (activeText)
|
||||
{
|
||||
const auto newName = gtk_entry_get_text(nameEntry);
|
||||
auto newType = streamTypes[activeText];
|
||||
const auto newIdStr = gtk_entry_get_text(m_IDEntry);
|
||||
|
||||
(m_Box.*setType)(m_index, newType);
|
||||
(m_Box.*setName)(m_index, newName);
|
||||
|
||||
// If the connector identifier is valid then create a new one and swap it with the edited one
|
||||
// this is because we can not change the identifier of a setting
|
||||
CIdentifier newID;
|
||||
if (newID.fromString(newIdStr) && (newID != id)) { m_Box.updateInterfacorIdentifier(interfacorType, m_index, newID); }
|
||||
// (m_Box.*addConnector)(newName, newType);
|
||||
finished = true;
|
||||
res = true;
|
||||
}
|
||||
}
|
||||
else if (result == 2) // revert
|
||||
{
|
||||
m_Box.getInterfacorName(interfacorType, m_index, name);
|
||||
m_Box.getInterfacorType(interfacorType, m_index, typeID);
|
||||
|
||||
gtk_entry_set_text(nameEntry, name.toASCIIString());
|
||||
gtk_combo_box_set_active(typeComboBox, active);
|
||||
}
|
||||
else
|
||||
{
|
||||
finished = true;
|
||||
res = false;
|
||||
}
|
||||
}
|
||||
|
||||
gtk_widget_destroy(dialog);
|
||||
g_object_unref(builder);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
} //namespace Designer
|
||||
} //namespace OpenViBE
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "ovd_base.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
class CConnectorEditor final
|
||||
{
|
||||
public:
|
||||
|
||||
CConnectorEditor(const Kernel::IKernelContext& ctx, Kernel::IBox& box, const size_t type, const size_t index, const char* title, const char* guiFilename)
|
||||
: m_Box(box), m_kernelCtx(ctx), m_type(type), m_index(index), m_guiFilename(guiFilename), m_title(title ? title : "") { }
|
||||
|
||||
~CConnectorEditor() = default;
|
||||
bool run();
|
||||
|
||||
Kernel::IBox& m_Box;
|
||||
GtkEntry* m_IDEntry = nullptr;
|
||||
|
||||
protected:
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
size_t m_type = 0;
|
||||
size_t m_index = 0;
|
||||
const std::string m_guiFilename;
|
||||
const std::string m_title;
|
||||
|
||||
typedef bool (Kernel::IBox::*get_identifier_t)(size_t index, CIdentifier& identifier) const;
|
||||
typedef bool (Kernel::IBox::*get_type_t)(size_t index, CIdentifier& typeID) const;
|
||||
typedef bool (Kernel::IBox::*get_name_t)(size_t index, CString& name) const;
|
||||
typedef bool (Kernel::IBox::*set_type_t)(size_t index, const CIdentifier& typeID);
|
||||
typedef bool (Kernel::IBox::*set_name_t)(size_t index, const CString& name);
|
||||
typedef bool (Kernel::IBox::*is_type_supported_t)(const CIdentifier& typeID) const;
|
||||
typedef bool (Kernel::IBox::*update_identifier_t)(size_t index, const CIdentifier& newID);
|
||||
};
|
||||
} //namespace Designer
|
||||
} //namespace OpenViBE
|
||||
+1752
File diff suppressed because it is too large
Load Diff
+173
@@ -0,0 +1,173 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <visualization-toolkit/ovvizIVisualizationTree.h>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
typedef void (*visualization_delete_event_cb_t)(gpointer data);
|
||||
|
||||
class CInterfacedScenario;
|
||||
|
||||
class CDesignerVisualization final : public VisualizationToolkit::ITreeViewCB
|
||||
{
|
||||
public:
|
||||
CDesignerVisualization(const Kernel::IKernelContext& ctx, VisualizationToolkit::IVisualizationTree& tree, CInterfacedScenario& scenario)
|
||||
: m_kernelCtx(ctx), m_tree(tree), m_scenario(scenario) { }
|
||||
|
||||
~CDesignerVisualization() override;
|
||||
|
||||
void init(const std::string& guiFile);
|
||||
void load();
|
||||
void show() const;
|
||||
void hide();
|
||||
|
||||
void setDeleteEventCB(visualization_delete_event_cb_t cb, gpointer data);
|
||||
|
||||
void onVisualizationBoxAdded(const Kernel::IBox* box);
|
||||
void onVisualizationBoxRemoved(const CIdentifier& boxID);
|
||||
void onVisualizationBoxRenamed(const CIdentifier& boxID);
|
||||
|
||||
//ITreeViewCB callbacks overloading
|
||||
void createTreeWidget(VisualizationToolkit::IVisualizationWidget* widget) override;
|
||||
GtkWidget* loadTreeWidget(VisualizationToolkit::IVisualizationWidget* widget) override;
|
||||
void endLoadTreeWidget(VisualizationToolkit::IVisualizationWidget* widget) override;
|
||||
GtkWidget* getTreeWidget(GtkWidget* widget) override;
|
||||
GtkWidget* getVisualizationWidget(GtkWidget* widget) override;
|
||||
const char* getTreeWidgetIcon(VisualizationToolkit::EVisualizationTreeNode type) override;
|
||||
|
||||
//callbacks for dialog
|
||||
#ifdef HANDLE_MIN_MAX_EVENTS
|
||||
static gboolean window_state_event_cb(GtkWidget* widget, GdkEventWindowState* event, gpointer data);
|
||||
#endif
|
||||
static gboolean configureEventCB(GtkWidget* widget, GdkEventConfigure* event, gpointer data);
|
||||
static gboolean widgetExposeEventCB(GtkWidget* widget, GdkEventExpose* event, gpointer data);
|
||||
void resizeCB(VisualizationToolkit::IVisualizationWidget* widget);
|
||||
|
||||
static void notebookPageSwitchCB(GtkNotebook* notebook, GtkNotebookPage* page, guint pagenum, gpointer data);
|
||||
|
||||
//callback for paned handle position changes
|
||||
static gboolean notifyPositionPanedCB(GtkWidget* widget, GParamSpec* spec, gpointer data);
|
||||
|
||||
static void askNewVisualizationWindowCB(gpointer data, guint action, GtkWidget* widget);
|
||||
static void newVisualizationWindowCB(GtkWidget* widget, gpointer data);
|
||||
static void askRenameVisualizationWindowCB(gpointer data, guint action, GtkWidget* widget);
|
||||
static void renameVisualizationWindowCB(GtkWidget* widget, gpointer data);
|
||||
static void removeVisualizationWindowCB(gpointer data, guint action, GtkWidget* widget);
|
||||
|
||||
static void askNewVisualizationPanelCB(gpointer data, guint action, GtkWidget* widget);
|
||||
static void newVisualizationPanelCB(GtkWidget* widget, gpointer data);
|
||||
static void askRenameVisualizationPanelCB(gpointer data, guint action, GtkWidget* widget);
|
||||
static void renameVisualizationPanelCB(GtkWidget* widget, gpointer data);
|
||||
static void removeVisualizationPanelCB(gpointer data, guint action, GtkWidget* widget);
|
||||
|
||||
static void removeVisualizationWidgetCB(gpointer data, guint action, GtkWidget* widget);
|
||||
|
||||
private:
|
||||
static gboolean deleteEventCB(GtkWidget* widget, GdkEvent* event, gpointer data);
|
||||
bool deleteEvent() const;
|
||||
|
||||
void refreshActiveVisualization(GtkTreePath* selectedItemPath);
|
||||
|
||||
void setActiveVisualization(const char* activeWindow, const char* activePanel);
|
||||
|
||||
GtkTable* newWidgetsTable();
|
||||
void setupNewEventBoxTable(GtkBuilder* xml);
|
||||
|
||||
//visualization windows
|
||||
void askNewVisualizationWindow();
|
||||
public:
|
||||
bool newVisualizationWindow(const char* label);
|
||||
private:
|
||||
void askRenameVisualizationWindow();
|
||||
bool renameVisualizationWindow(const char* label);
|
||||
bool removeVisualizationWindow();
|
||||
|
||||
//visualization panels
|
||||
void askNewVisualizationPanel();
|
||||
bool newVisualizationPanel(const char* label);
|
||||
void askRenameVisualizationPanel();
|
||||
bool renameVisualizationPanel(const char* label);
|
||||
bool removeVisualizationPanel();
|
||||
|
||||
//visualization widgets
|
||||
bool removeVisualizationWidget();
|
||||
bool removeVisualizationWidget(const CIdentifier& identifier);
|
||||
bool destroyVisualizationWidget(const CIdentifier& identifier);
|
||||
|
||||
void enableNotebookSignals(GtkWidget* notebook, bool b);
|
||||
void notebookPageSelectedCB(GtkNotebook* notebook, guint pagenum);
|
||||
|
||||
void enablePanedSignals(GtkWidget* paned, bool b);
|
||||
void notifyPositionPaned(GtkWidget* widget);
|
||||
|
||||
//Mouse/Key event callbacks
|
||||
static void widgetKeyPressEventCB(GtkWidget* widget, GdkEventKey* event, gpointer data);
|
||||
static gboolean widgetEnterNotifyEventCB(GtkWidget* widget, GdkEventCrossing* event, gpointer data);
|
||||
static gboolean widgetLeaveNotifyEventCB(GtkWidget* widget, GdkEventCrossing* event, gpointer data);
|
||||
|
||||
//Mouse/Key event methods
|
||||
void widgetKeyPressEvent(GtkWidget* widget, GdkEventKey* event);
|
||||
void widgetEnterNotifyEvent(GtkWidget* widget, GdkEventCrossing* event);
|
||||
void widgetLeaveNotifyEvent(GtkWidget* widget, GdkEventCrossing* event);
|
||||
|
||||
//Tree management callbacks
|
||||
static gboolean buttonReleaseCB(GtkWidget* widget, GdkEventButton* event, gpointer data);
|
||||
static void cursorChangedCB(GtkTreeView* treeView, gpointer data);
|
||||
|
||||
//Tree management methods
|
||||
void buttonRelease(GtkWidget* widget, GdkEventButton* event) const;
|
||||
void cursorChanged(GtkTreeView* treeView);
|
||||
|
||||
//Drag methods
|
||||
static void dragDataGetFromTreeCB(GtkWidget* srcWidget, GdkDragContext* dc, GtkSelectionData* selection, guint info, guint time, gpointer data);
|
||||
static void dragDataGetFromWidgetCB(GtkWidget* srcWidget, GdkDragContext* dc, GtkSelectionData* selection, guint info, guint time, gpointer data);
|
||||
|
||||
//Drop methods
|
||||
static void dragDataReceivedInWidgetCB(GtkWidget* dstWidget, GdkDragContext*, gint, gint, GtkSelectionData* selection, guint info, guint time,
|
||||
gpointer data);
|
||||
static void dataReceivedInEventBoxCB(GtkWidget* dstWidget, GdkDragContext* dc, gint x, gint y, GtkSelectionData* selection, guint info, guint time,
|
||||
gpointer data);
|
||||
void dragDataReceivedInWidget(GtkWidget* dstWidget, GtkSelectionData* selection);
|
||||
void dragDataReceivedInEventBox(GtkWidget* dstWidget, GtkSelectionData* selection, VisualizationToolkit::EDragLocation location);
|
||||
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
VisualizationToolkit::IVisualizationTree& m_tree;
|
||||
CInterfacedScenario& m_scenario;
|
||||
visualization_delete_event_cb_t m_deleteEventCB = nullptr;
|
||||
gpointer m_deleteEventUserData = nullptr;
|
||||
std::string m_guiFile;
|
||||
GtkTreeView* m_treeView = nullptr;
|
||||
GtkWidget* m_dialog = nullptr;
|
||||
GtkWidget* m_pane = nullptr;
|
||||
|
||||
//highlighted widget
|
||||
GtkWidget* m_highlightedWidget = nullptr;
|
||||
|
||||
//active items
|
||||
CString m_activeVisualizationWindowName, m_activeVisualizationPanelName;
|
||||
CIdentifier m_activeVisualizationBoxID = CIdentifier::undefined();
|
||||
|
||||
//preview window visibility flag
|
||||
bool m_previewWindowVisible = false;
|
||||
size_t m_previewWindowW = 0;
|
||||
size_t m_previewWindowH = 0;
|
||||
|
||||
//Factories
|
||||
GtkItemFactory* m_unaffectedItemFactory = nullptr;
|
||||
GtkItemFactory* m_visualizationWindowItemFactory = nullptr;
|
||||
GtkItemFactory* m_visualizationPanelItemFactory = nullptr;
|
||||
GtkItemFactory* m_visualizationBoxItemFactory = nullptr;
|
||||
GtkItemFactory* m_undefinedItemFactory = nullptr;
|
||||
GtkItemFactory* m_splitItemFactory = nullptr;
|
||||
|
||||
std::string m_topEventBoxData;
|
||||
std::string m_leftEventBoxData;
|
||||
std::string m_rightEventBoxData;
|
||||
std::string m_bottomEventBoxData;
|
||||
};
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
#include "ovdCInputDialog.h"
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
CInputDialog::CInputDialog(const char* gtkBuilder, const fpButtonCB okButtonCB, void* data, const char* title, const char* label, const char* entry)
|
||||
{
|
||||
m_okButtonCB = okButtonCB;
|
||||
m_userData = data;
|
||||
|
||||
//retrieve input dialog
|
||||
GtkBuilder* builder = gtk_builder_new(); // glade_xml_new(gtkBuilder, "input", nullptr);
|
||||
gtk_builder_add_from_file(builder, gtkBuilder, nullptr);
|
||||
gtk_builder_connect_signals(builder, nullptr);
|
||||
|
||||
m_dialog = GTK_DIALOG(gtk_builder_get_object(builder, "input"));
|
||||
m_dialogLabel = GTK_LABEL(gtk_builder_get_object(builder, "input-label"));
|
||||
m_dialogEntry = GTK_ENTRY(gtk_builder_get_object(builder, "input-entry"));
|
||||
m_dialogOkButton = GTK_BUTTON(gtk_builder_get_object(builder, "input-button_ok"));
|
||||
m_dialogCancelButton = GTK_BUTTON(gtk_builder_get_object(builder, "input-button_cancel"));
|
||||
|
||||
GTK_WIDGET_SET_FLAGS(GTK_WIDGET(m_dialogEntry), GDK_KEY_PRESS_MASK);
|
||||
g_signal_connect(G_OBJECT(m_dialogEntry), "key-press-event", G_CALLBACK(keyPressEventCB), m_dialog);
|
||||
|
||||
if (label != nullptr) { gtk_label_set(m_dialogLabel, label); }
|
||||
if (entry != nullptr) { gtk_entry_set_text(m_dialogEntry, entry); }
|
||||
|
||||
g_signal_connect(G_OBJECT(m_dialogOkButton), "clicked", G_CALLBACK(buttonClickedCB), this);
|
||||
g_signal_connect(G_OBJECT(m_dialogCancelButton), "clicked", G_CALLBACK(buttonClickedCB), this);
|
||||
|
||||
gtk_window_set_position(GTK_WINDOW(m_dialog), GTK_WIN_POS_MOUSE);
|
||||
gtk_window_set_title(GTK_WINDOW(m_dialog), title);
|
||||
}
|
||||
|
||||
CInputDialog::~CInputDialog() { gtk_widget_destroy(GTK_WIDGET(m_dialog)); }
|
||||
|
||||
void CInputDialog::run()
|
||||
{
|
||||
const gint res = gtk_dialog_run(m_dialog);
|
||||
if (res == GTK_RESPONSE_ACCEPT) { if (m_okButtonCB != nullptr) { m_okButtonCB(GTK_WIDGET(m_dialogOkButton), this); } }
|
||||
gtk_widget_hide_all(GTK_WIDGET(m_dialog));
|
||||
}
|
||||
|
||||
gboolean CInputDialog::keyPressEventCB(GtkWidget* /*widget*/, GdkEventKey* eventKey, gpointer data)
|
||||
{
|
||||
if (eventKey->keyval == GDK_Return || eventKey->keyval == GDK_KP_Enter)
|
||||
{
|
||||
gtk_dialog_response(GTK_DIALOG(data), GTK_RESPONSE_ACCEPT);
|
||||
return TRUE;
|
||||
}
|
||||
if (eventKey->keyval == GDK_Escape)
|
||||
{
|
||||
gtk_dialog_response(GTK_DIALOG(data), GTK_RESPONSE_REJECT);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void CInputDialog::buttonClickedCB(GtkButton* button, gpointer data) { static_cast<CInputDialog*>(data)->buttonClicked(button); }
|
||||
|
||||
void CInputDialog::buttonClicked(GtkButton* button) const
|
||||
{
|
||||
if (button == m_dialogOkButton) { gtk_dialog_response(m_dialog, GTK_RESPONSE_ACCEPT); }
|
||||
else { gtk_dialog_response(m_dialog, GTK_RESPONSE_REJECT); }
|
||||
}
|
||||
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "ovd_base.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
typedef void (*fpButtonCB)(GtkWidget* pWidget, gpointer data);
|
||||
|
||||
class CInputDialog
|
||||
{
|
||||
public:
|
||||
|
||||
CInputDialog(const char* gtkBuilder, fpButtonCB okButtonCB, void* data = nullptr, const char* title = nullptr, const char* label = nullptr,
|
||||
const char* entry = nullptr);
|
||||
~CInputDialog();
|
||||
|
||||
void run();
|
||||
void* getUserData() const { return m_userData; }
|
||||
const char* getEntry() const { return static_cast<const char*>(gtk_entry_get_text(m_dialogEntry)); }
|
||||
|
||||
private:
|
||||
|
||||
static gboolean keyPressEventCB(GtkWidget* widget, GdkEventKey* eventKey, gpointer data);
|
||||
static void buttonClickedCB(GtkButton* button, gpointer data);
|
||||
void buttonClicked(GtkButton* button) const;
|
||||
|
||||
void* m_userData = nullptr;
|
||||
fpButtonCB m_okButtonCB;
|
||||
GtkDialog* m_dialog = nullptr;
|
||||
GtkLabel* m_dialogLabel = nullptr;
|
||||
GtkEntry* m_dialogEntry = nullptr;
|
||||
GtkButton* m_dialogOkButton = nullptr;
|
||||
GtkButton* m_dialogCancelButton = nullptr;
|
||||
};
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "ovd_base.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
class CInterfacedObject
|
||||
{
|
||||
public:
|
||||
|
||||
CInterfacedObject() = default;
|
||||
explicit CInterfacedObject(const CIdentifier& identifier) : m_ID(identifier) { }
|
||||
|
||||
CInterfacedObject(const CIdentifier& identifier, const size_t connectorType, const size_t connectorIndex)
|
||||
: m_ID(identifier), m_ConnectorType(connectorType), m_ConnectorIdx(connectorIndex) { }
|
||||
|
||||
CIdentifier m_ID = CIdentifier::undefined();
|
||||
size_t m_ConnectorType = 0;
|
||||
size_t m_ConnectorIdx = 0;
|
||||
};
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
Executable
+3699
File diff suppressed because it is too large
Load Diff
Executable
+272
@@ -0,0 +1,272 @@
|
||||
#pragma once
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#include "ovd_base.h"
|
||||
|
||||
#include "ovdCInterfacedObject.h"
|
||||
#include "ovdCScenarioStateStack.h"
|
||||
#include "ovdCSettingCollectionHelper.h"
|
||||
#include "ovdCBoxConfigurationDialog.h"
|
||||
#include <visualization-toolkit/ovvizIVisualizationTree.h>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
class CApplication;
|
||||
class CDesignerVisualization;
|
||||
class CPlayerVisualization;
|
||||
|
||||
class CInterfacedScenario
|
||||
{
|
||||
public:
|
||||
|
||||
CInterfacedScenario(const Kernel::IKernelContext& ctx, CApplication& application, Kernel::IScenario& scenario,
|
||||
CIdentifier& scenarioID, GtkNotebook& notebook, const char* guiFilename, const char* guiSettingsFilename);
|
||||
virtual ~CInterfacedScenario();
|
||||
|
||||
virtual bool isLocked() const { return m_Player != nullptr; }
|
||||
virtual void redraw();
|
||||
virtual void redraw(Kernel::IBox& box);
|
||||
virtual void redraw(Kernel::IComment& comment);
|
||||
virtual void redraw(Kernel::ILink& link);
|
||||
virtual void updateScenarioLabel();
|
||||
size_t pickInterfacedObject(int x, int y) const;
|
||||
bool pickInterfacedObject(int x, int y, int sizeX, int sizeY);
|
||||
|
||||
void undoCB(bool manageModifiedStatusFlag = true);
|
||||
void redoCB(bool manageModifiedStatusFlag = true);
|
||||
void snapshotCB(bool manageModifiedStatusFlag = true);
|
||||
void addCommentCB(int x = -1, int y = -1);
|
||||
|
||||
// Utility functions for scenario settings, inputs and outputs
|
||||
|
||||
void addScenarioSettingCB();
|
||||
//void editScenarioSettingCB(size_t index);
|
||||
void swapScenarioSettings(size_t indexA, size_t indexB);
|
||||
|
||||
void addScenarioInputCB();
|
||||
void editScenarioInputCB(size_t index);
|
||||
void swapScenarioInputs(size_t indexA, size_t indexB);
|
||||
|
||||
void addScenarioOutputCB();
|
||||
void editScenarioOutputCB(size_t index);
|
||||
void swapScenarioOutputs(size_t indexA, size_t indexB);
|
||||
|
||||
|
||||
// Utility functions for scenario settings, inputs and outputs
|
||||
void configureScenarioSettingsCB();
|
||||
|
||||
// Drawing functions for scenario settings, inputs and outputs
|
||||
void redrawConfigureScenarioSettingsDialog();
|
||||
void redrawScenarioSettings();
|
||||
void redrawScenarioInputSettings();
|
||||
void redrawScenarioOutputSettings();
|
||||
|
||||
void scenarioDrawingAreaExposeCB(GdkEventExpose* event);
|
||||
void scenarioDrawingAreaDragDataReceivedCB(GdkDragContext* dc, gint x, gint y, GtkSelectionData* selectionData, guint info, guint t);
|
||||
void scenarioDrawingAreaMotionNotifyCB(GtkWidget* widget, GdkEventMotion* event);
|
||||
void scenarioDrawingAreaButtonPressedCB(GtkWidget* widget, GdkEventButton* event);
|
||||
void scenarioDrawingAreaButtonReleasedCB(GtkWidget* widget, GdkEventButton* event);
|
||||
void scenarioDrawingAreaKeyPressEventCB(GtkWidget* widget, GdkEventKey* event);
|
||||
void scenarioDrawingAreaKeyReleaseEventCB(GtkWidget* widget, GdkEventKey* event);
|
||||
|
||||
void copySelection();
|
||||
void cutSelection();
|
||||
void pasteSelection();
|
||||
void deleteSelection();
|
||||
|
||||
void deleteBox(const CIdentifier& boxID); // Utility method to remove box from scenario and visualization
|
||||
void contextMenuBoxUpdateCB(Kernel::IBox& box);
|
||||
void contextMenuBoxRemoveDeprecatedInterfacorsCB(Kernel::IBox& box);
|
||||
void contextMenuBoxRenameCB(Kernel::IBox& box);
|
||||
void contextMenuBoxRenameAllCB();
|
||||
void contextMenuBoxToggleEnableAllCB();
|
||||
void contextMenuBoxAddInputCB(Kernel::IBox& box);
|
||||
void contextMenuBoxEditInputCB(Kernel::IBox& box, const size_t index);
|
||||
void contextMenuBoxRemoveInputCB(Kernel::IBox& box, const size_t index);
|
||||
void contextMenuBoxAddOutputCB(Kernel::IBox& box);
|
||||
void contextMenuBoxEditOutputCB(Kernel::IBox& box, const size_t index);
|
||||
void contextMenuBoxRemoveOutputCB(Kernel::IBox& box, const size_t index);
|
||||
|
||||
void contextMenuBoxConnectScenarioInputCB(Kernel::IBox& box, size_t boxInputIdx, size_t scenarioInputIdx);
|
||||
void contextMenuBoxConnectScenarioOutputCB(Kernel::IBox& box, size_t boxOutputIdx, size_t scenarioOutputIdx);
|
||||
void contextMenuBoxDisconnectScenarioInputCB(Kernel::IBox& box, size_t boxInputIdx, size_t scenarioInputIdx);
|
||||
void contextMenuBoxDisconnectScenarioOutputCB(Kernel::IBox& box, size_t boxOutputIdx, size_t scenarioOutputIdx);
|
||||
|
||||
void contextMenuBoxAddSettingCB(Kernel::IBox& box);
|
||||
void contextMenuBoxEditSettingCB(Kernel::IBox& box, const size_t index);
|
||||
void contextMenuBoxRemoveSettingCB(Kernel::IBox& box, const size_t index);
|
||||
void contextMenuBoxConfigureCB(Kernel::IBox& box);
|
||||
void contextMenuBoxAboutCB(Kernel::IBox& box) const;
|
||||
void contextMenuBoxEditMetaboxCB(Kernel::IBox& box) const;
|
||||
|
||||
void contextMenuBoxEnableCB(Kernel::IBox& box);
|
||||
void contextMenuBoxDisableCB(Kernel::IBox& box);
|
||||
void contextMenuBoxEnableAllCB();
|
||||
void contextMenuBoxDisableAllCB();
|
||||
|
||||
void contextMenuBoxDocumentationCB(Kernel::IBox& box) const;
|
||||
|
||||
void contextMenuScenarioAddCommentCB();
|
||||
void contextMenuScenarioAboutCB();
|
||||
|
||||
bool browseURL(const CString& url, const CString& browserPrefix, const CString& browserPostfix) const;
|
||||
bool browseBoxDocumentation(const CIdentifier& boxID) const;
|
||||
|
||||
void toggleDesignerVisualization();
|
||||
bool isDesignerVisualizationToggled() const { return m_designerVisualizationToggled; }
|
||||
|
||||
void showCurrentVisualization() const;
|
||||
void hideCurrentVisualization() const;
|
||||
|
||||
void createPlayerVisualization(VisualizationToolkit::IVisualizationTree* tree = nullptr);
|
||||
void releasePlayerVisualization();
|
||||
|
||||
|
||||
void stopAndReleasePlayer();
|
||||
bool setModifiableSettingsWidgets();
|
||||
bool hasSelection() const { return !m_SelectedObjects.empty(); }
|
||||
bool centerOnBox(const CIdentifier& identifier);
|
||||
void setScale(double scale);
|
||||
double getScale() const { return m_currentScale; }
|
||||
|
||||
//-----------------------------
|
||||
//---------- typedef ----------
|
||||
//-----------------------------
|
||||
typedef struct SBoxContextMenuCB
|
||||
{
|
||||
EContextMenu command;
|
||||
size_t index;
|
||||
size_t secondaryIndex; // Used for connecting two streams
|
||||
Kernel::IBox* box;
|
||||
CInterfacedScenario* scenario;
|
||||
} box_ctx_menu_cb_t;
|
||||
|
||||
// This struct is used for both settings inside the scenario and inside
|
||||
// the settings configurator
|
||||
typedef struct SSettingCallbackData
|
||||
{
|
||||
CInterfacedScenario* scenario;
|
||||
size_t index;
|
||||
GtkWidget* widgetValue;
|
||||
GtkWidget* widgetEntryValue;
|
||||
GtkWidget* container;
|
||||
} setting_cb_data_t;
|
||||
|
||||
// This struct is used for both inputs and outputs of the scenario
|
||||
typedef struct SLinkCallbackData
|
||||
{
|
||||
CInterfacedScenario* scenario;
|
||||
size_t index;
|
||||
bool input;
|
||||
} link_cb_data_t;
|
||||
|
||||
//-------------------------------
|
||||
//---------- variables ----------
|
||||
//-------------------------------
|
||||
Kernel::EPlayerStatus m_PlayerStatus;
|
||||
CIdentifier m_ScenarioID = CIdentifier::undefined();
|
||||
CIdentifier m_PlayerID = CIdentifier::undefined();
|
||||
CIdentifier m_TreeID = CIdentifier::undefined();
|
||||
|
||||
CApplication& m_Application;
|
||||
Kernel::IScenario& m_Scenario;
|
||||
Kernel::IPlayer* m_Player = nullptr;
|
||||
VisualizationToolkit::IVisualizationTree* m_Tree = nullptr;
|
||||
CDesignerVisualization* m_DesignerVisualization = nullptr;
|
||||
|
||||
uint64_t m_LastLoopTime = 0;
|
||||
bool m_HasFileName = false;
|
||||
bool m_HasBeenModified = false;
|
||||
bool m_DebugCPUUsage = false;
|
||||
|
||||
std::string m_Filename;
|
||||
|
||||
std::set<CIdentifier> m_SelectedObjects;
|
||||
|
||||
std::unique_ptr<CScenarioStateStack> m_StateStack;
|
||||
|
||||
// Objects necessary for holding settings GUI
|
||||
std::map<std::string, CIdentifier> m_SettingTypes;
|
||||
CSettingCollectionHelper* m_SettingHelper = nullptr;
|
||||
std::string m_SerializedSettingGUIXML;
|
||||
|
||||
private:
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
GtkNotebook& m_notebook;
|
||||
bool m_designerVisualizationToggled = false;
|
||||
CPlayerVisualization* m_playerVisualization = nullptr;
|
||||
GtkBuilder* m_guiBuilder = nullptr;
|
||||
GtkWidget* m_notebookPageTitle = nullptr;
|
||||
GtkWidget* m_notebookPageContent = nullptr;
|
||||
GtkViewport* m_scenarioViewport = nullptr;
|
||||
GtkDrawingArea* m_scenarioDrawingArea = nullptr;
|
||||
GdkPixmap* m_stencilBuffer = nullptr;
|
||||
GdkPixbuf* m_mensiaLogoPixbuf = nullptr;
|
||||
|
||||
bool m_buttonPressed = false;
|
||||
bool m_shiftPressed = false;
|
||||
bool m_controlPressed = false;
|
||||
bool m_altPressed = false;
|
||||
bool m_aPressed = false;
|
||||
bool m_wPressed = false;
|
||||
std::string m_guiFilename;
|
||||
std::string m_guiSettingsFilename;
|
||||
|
||||
double m_pressMouseX = 0;
|
||||
double m_pressMouseY = 0;
|
||||
double m_releaseMouseX = 0;
|
||||
double m_releaseMouseY = 0;
|
||||
double m_currentMouseX = 0;
|
||||
double m_currentMouseY = 0;
|
||||
int m_viewOffsetX = 0;
|
||||
int m_viewOffsetY = 0;
|
||||
size_t m_currentMode = 0;
|
||||
|
||||
size_t m_nBox = 0;
|
||||
size_t m_nComment = 0;
|
||||
size_t m_nLink = 0;
|
||||
|
||||
size_t m_interfacedObjectId = 0;
|
||||
std::map<size_t, CInterfacedObject> m_interfacedObjects;
|
||||
CInterfacedObject m_currentObject;
|
||||
|
||||
GtkWidget* m_configureSettingsDialog = nullptr;
|
||||
GtkWidget* m_settingsVBox = nullptr;
|
||||
GtkWidget* m_noHelpDialog = nullptr;
|
||||
GtkWidget* m_errorPendingDeprecatedInterfacorsDialog = nullptr;
|
||||
|
||||
std::map<std::string, CIdentifier> m_streamTypes;
|
||||
|
||||
std::map<size_t, box_ctx_menu_cb_t> m_boxCtxMenuCBs;
|
||||
std::vector<setting_cb_data_t> m_settingConfigCBDatas;
|
||||
std::vector<setting_cb_data_t> m_settingCBDatas;
|
||||
std::vector<link_cb_data_t> m_scenarioInputCBDatas;
|
||||
std::vector<link_cb_data_t> m_scenarioOutputCBDatas;
|
||||
|
||||
double m_currentScale = 1;
|
||||
gint m_normalFontSize = 0;
|
||||
|
||||
std::vector<CBoxConfigurationDialog*> m_boxConfigDialogs;
|
||||
|
||||
typedef void (*menu_cb_function_t)(GtkMenuItem*, box_ctx_menu_cb_t*);
|
||||
GtkImageMenuItem* addNewImageMenuItemWithCBGeneric(GtkMenu* menu, const char* icon, const char* label, menu_cb_function_t cb,
|
||||
Kernel::IBox* box, EContextMenu command, const size_t index, const size_t index2);
|
||||
|
||||
GtkImageMenuItem* addNewImageMenuItemWithCB(GtkMenu* menu, const char* icon, const char* label, const menu_cb_function_t cb,
|
||||
Kernel::IBox* box, const EContextMenu command, const size_t index)
|
||||
{
|
||||
return addNewImageMenuItemWithCBGeneric(menu, icon, label, cb, box, command, index, 0);
|
||||
}
|
||||
|
||||
void redrawScenarioLinkSettings(GtkWidget* links, bool isInput, std::vector<link_cb_data_t>& linkCBDatas,
|
||||
size_t (Kernel::IScenario::* getNLink)() const,
|
||||
bool (Kernel::IScenario::* getLinkName)(size_t, CString&) const,
|
||||
bool (Kernel::IScenario::* getLinkType)(size_t, CIdentifier&) const);
|
||||
};
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
#include "ovdCLinkProxy.h"
|
||||
#include "ovdTAttributeHandler.h"
|
||||
#include "../../../../../sdk/openvibe/include/openvibe/ov_defines.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
CLinkProxy::CLinkProxy(const Kernel::ILink& link) : m_constLink(&link)
|
||||
{
|
||||
if (m_constLink)
|
||||
{
|
||||
const TAttributeHandler handler(*m_constLink);
|
||||
m_xSrc = handler.getAttributeValue<int>(OV_AttributeId_Link_XSrc);
|
||||
m_ySrc = handler.getAttributeValue<int>(OV_AttributeId_Link_YSrc);
|
||||
m_xDst = handler.getAttributeValue<int>(OV_AttributeId_Link_XDst);
|
||||
m_yDst = handler.getAttributeValue<int>(OV_AttributeId_Link_YDst);
|
||||
}
|
||||
}
|
||||
|
||||
CLinkProxy::CLinkProxy(Kernel::IScenario& scenario, const CIdentifier& linkID)
|
||||
: m_constLink(scenario.getLinkDetails(linkID)), m_link(scenario.getLinkDetails(linkID))
|
||||
{
|
||||
if (m_constLink)
|
||||
{
|
||||
const TAttributeHandler handler(*m_constLink);
|
||||
m_xSrc = handler.getAttributeValue<int>(OV_AttributeId_Link_XSrc);
|
||||
m_ySrc = handler.getAttributeValue<int>(OV_AttributeId_Link_YSrc);
|
||||
m_xDst = handler.getAttributeValue<int>(OV_AttributeId_Link_XDst);
|
||||
m_yDst = handler.getAttributeValue<int>(OV_AttributeId_Link_YDst);
|
||||
}
|
||||
}
|
||||
|
||||
CLinkProxy::~CLinkProxy()
|
||||
{
|
||||
if (m_link)
|
||||
{
|
||||
TAttributeHandler handler(*m_link);
|
||||
|
||||
if (handler.hasAttribute(OV_AttributeId_Link_XSrc)) { handler.setAttributeValue<int>(OV_AttributeId_Link_XSrc, m_xSrc); }
|
||||
else { handler.addAttribute<int>(OV_AttributeId_Link_XSrc, m_xSrc); }
|
||||
|
||||
if (handler.hasAttribute(OV_AttributeId_Link_YSrc)) { handler.setAttributeValue<int>(OV_AttributeId_Link_YSrc, m_ySrc); }
|
||||
else { handler.addAttribute<int>(OV_AttributeId_Link_YSrc, m_ySrc); }
|
||||
|
||||
if (handler.hasAttribute(OV_AttributeId_Link_XDst)) { handler.setAttributeValue<int>(OV_AttributeId_Link_XDst, m_xDst); }
|
||||
else { handler.addAttribute<int>(OV_AttributeId_Link_XDst, m_xDst); }
|
||||
|
||||
if (handler.hasAttribute(OV_AttributeId_Link_YDst)) { handler.setAttributeValue<int>(OV_AttributeId_Link_YDst, m_yDst); }
|
||||
else { handler.addAttribute<int>(OV_AttributeId_Link_YDst, m_yDst); }
|
||||
}
|
||||
}
|
||||
|
||||
void CLinkProxy::setSource(const int x, const int y)
|
||||
{
|
||||
m_xSrc = x;
|
||||
m_ySrc = y;
|
||||
}
|
||||
|
||||
void CLinkProxy::setTarget(const int x, const int y)
|
||||
{
|
||||
m_xDst = x;
|
||||
m_yDst = y;
|
||||
}
|
||||
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "ovd_base.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
class CLinkProxy final
|
||||
{
|
||||
public:
|
||||
|
||||
explicit CLinkProxy(const Kernel::ILink& link);
|
||||
CLinkProxy(Kernel::IScenario& scenario, const CIdentifier& linkID);
|
||||
~CLinkProxy();
|
||||
|
||||
operator Kernel::ILink*() const { return m_link; }
|
||||
operator const Kernel::ILink*() const { return m_constLink; }
|
||||
|
||||
int getXSource() const { return m_xSrc; }
|
||||
int getYSource() const { return m_ySrc; }
|
||||
int getXTarget() const { return m_xDst; }
|
||||
int getYTarget() const { return m_yDst; }
|
||||
|
||||
void setSource(int x, int y);
|
||||
void setTarget(int x, int y);
|
||||
|
||||
protected:
|
||||
|
||||
const Kernel::ILink* m_constLink;
|
||||
Kernel::ILink* m_link = nullptr;
|
||||
int m_xSrc = 0;
|
||||
int m_ySrc = 0;
|
||||
int m_xDst = 0;
|
||||
int m_yDst = 0;
|
||||
};
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
Masterarbeit/openvibe/designer-master/applications/platform/designer/src/ovdCLogListenerDesigner.cpp
Executable
+433
@@ -0,0 +1,433 @@
|
||||
#include "ovdCLogListenerDesigner.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#define OVD_GUI_File OpenViBE::Directories::getDataDir() + "/applications/designer/interface.ui"
|
||||
|
||||
namespace {
|
||||
void close_messages_alert_window_cb(GtkButton* /*button*/, gpointer data) { gtk_widget_hide(GTK_WIDGET(data)); }
|
||||
void focus_message_window_cb(GtkButton* /*button*/, gpointer data) { static_cast<OpenViBE::Designer::CLogListenerDesigner*>(data)->focusMessageWindow(); }
|
||||
|
||||
void refresh_search_log_entry(GtkEntry* text, gpointer data)
|
||||
{
|
||||
auto* ptr = static_cast<OpenViBE::Designer::CLogListenerDesigner*>(data);
|
||||
ptr->m_SearchTerm = gtk_entry_get_text(text);
|
||||
ptr->searchMessages(ptr->m_SearchTerm);
|
||||
}
|
||||
|
||||
void focus_on_box_cidentifier_clicked(GtkWidget* widget, GdkEventButton* event, gpointer data)
|
||||
{
|
||||
//log text view grab the focus so isLogAreaClicked() return true and CTRL+F will focus on the log searchEntry
|
||||
gtk_widget_grab_focus(widget);
|
||||
|
||||
auto* ptr = static_cast<OpenViBE::Designer::CLogListenerDesigner*>(data);
|
||||
|
||||
//if left click
|
||||
if (event->button == 1)
|
||||
{
|
||||
GtkTextView* textView = GTK_TEXT_VIEW(widget);
|
||||
const GtkTextWindowType windowType = gtk_text_view_get_window_type(textView, event->window);
|
||||
gint bufferX, bufferY;
|
||||
//convert event coord (mouse position) in buffer coord (character in buffer)
|
||||
gtk_text_view_window_to_buffer_coords(textView, windowType, gint(round(event->x)), gint(round(event->y)), &bufferX, &bufferY);
|
||||
//get the text iter corresponding to that position
|
||||
GtkTextIter iter;
|
||||
gtk_text_view_get_iter_at_location(textView, &iter, bufferX, bufferY);
|
||||
|
||||
//if this position is not tagged, exit
|
||||
if (!gtk_text_iter_has_tag(&iter, ptr->m_IdTag)) { return; }
|
||||
//the position is tagged, we are on a CIdentifier
|
||||
GtkTextIter start = iter;
|
||||
GtkTextIter end = iter;
|
||||
|
||||
while (gtk_text_iter_has_tag(&end, ptr->m_IdTag)) { gtk_text_iter_forward_char(&end); }
|
||||
while (gtk_text_iter_has_tag(&start, ptr->m_IdTag)) { gtk_text_iter_backward_char(&start); }
|
||||
//we went one char to far for start
|
||||
gtk_text_iter_forward_char(&start);
|
||||
//this contains the CIdentifier
|
||||
gchar* link = gtk_text_iter_get_text(&start, &end);
|
||||
//std::cout << "cid is |" << link << "|" << std::endl;
|
||||
OpenViBE::CIdentifier id;
|
||||
id.fromString(OpenViBE::CString(link));
|
||||
ptr->m_CenterOnBoxFun(id);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
void CLogListenerDesigner::searchMessages(const CString& searchTerm)
|
||||
{
|
||||
//clear displayed buffer
|
||||
gtk_text_buffer_set_text(m_buffer, "", -1);
|
||||
m_SearchTerm = searchTerm;
|
||||
for (CLogObject* log : m_storedLogs) { if (log->filter(searchTerm)) { appendLog(log); } } //display the log
|
||||
}
|
||||
|
||||
void CLogListenerDesigner::appendLog(CLogObject* log) const
|
||||
{
|
||||
GtkTextIter endIter, begin, end;
|
||||
gtk_text_buffer_get_end_iter(m_buffer, &endIter);
|
||||
//get log buffer bounds
|
||||
gtk_text_buffer_get_start_iter(log->getTextBuffer(), &begin);
|
||||
gtk_text_buffer_get_end_iter(log->getTextBuffer(), &end);
|
||||
//copy at the end of the displayed buffer
|
||||
gtk_text_buffer_insert_range(m_buffer, &endIter, &begin, &end);
|
||||
}
|
||||
|
||||
CLogListenerDesigner::CLogListenerDesigner(const Kernel::IKernelContext& ctx, GtkBuilder* builder)
|
||||
: m_SearchTerm(""), m_CenterOnBoxFun([](CIdentifier& /*id*/) {}), m_builder(builder)
|
||||
{
|
||||
m_textView = GTK_TEXT_VIEW(gtk_builder_get_object(m_builder, "openvibe-textview_messages"));
|
||||
m_alertWindow = GTK_WINDOW(gtk_builder_get_object(m_builder, "dialog_error_popup"));
|
||||
|
||||
m_buttonPopup = GTK_TOGGLE_BUTTON(gtk_builder_get_object(m_builder, "openvibe-messages_alert_on_error"));
|
||||
|
||||
m_labelnMsg = GTK_LABEL(gtk_builder_get_object(m_builder, "openvibe-messages_count_message_label"));
|
||||
m_labelnWarnings = GTK_LABEL(gtk_builder_get_object(m_builder, "openvibe-messages_count_warning_label"));
|
||||
m_labelnErrors = GTK_LABEL(gtk_builder_get_object(m_builder, "openvibe-messages_count_error_label"));
|
||||
m_labelDialognWarnings = GTK_LABEL(gtk_builder_get_object(m_builder, "dialog_error_popup-warning_count"));
|
||||
m_labelDialognErrors = GTK_LABEL(gtk_builder_get_object(m_builder, "dialog_error_popup-error_count"));
|
||||
|
||||
m_imageWarnings = GTK_WIDGET(gtk_builder_get_object(m_builder, "openvibe-messages_count_warning_image"));
|
||||
m_imageErrors = GTK_WIDGET(gtk_builder_get_object(m_builder, "openvibe-messages_count_error_image"));
|
||||
|
||||
m_buttonActiveDebug = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(m_builder, "openvibe-messages_tb_debug"));
|
||||
m_buttonActiveBenchmark = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(m_builder, "openvibe-messages_tb_bench"));
|
||||
m_buttonActiveTrace = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(m_builder, "openvibe-messages_tb_trace"));
|
||||
m_buttonActiveInfo = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(m_builder, "openvibe-messages_tb_info"));
|
||||
m_buttonActiveWarning = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(m_builder, "openvibe-messages_tb_warning"));
|
||||
m_buttonActiveImportantWarning = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(m_builder, "openvibe-messages_tb_impwarning"));
|
||||
m_buttonActiveError = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(m_builder, "openvibe-messages_tb_error"));
|
||||
m_buttonActiveFatal = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(m_builder, "openvibe-messages_tb_fatal"));
|
||||
|
||||
// set the popup-on-error checkbox according to the configuration token
|
||||
gtk_toggle_button_set_active(m_buttonPopup, bool(ctx.getConfigurationManager().expandAsBoolean("${Designer_PopUpOnError}")));
|
||||
|
||||
g_signal_connect(G_OBJECT(m_alertWindow), "delete_event", G_CALLBACK(gtk_widget_hide), nullptr);
|
||||
g_signal_connect(G_OBJECT(gtk_builder_get_object(m_builder, "dialog_error_popup-button_view")), "clicked", G_CALLBACK(focus_message_window_cb), this);
|
||||
g_signal_connect(G_OBJECT(gtk_builder_get_object(m_builder, "dialog_error_popup-button_ok")), "clicked",
|
||||
G_CALLBACK(close_messages_alert_window_cb), m_alertWindow);
|
||||
|
||||
g_signal_connect(G_OBJECT(gtk_builder_get_object(m_builder, "searchEntry")), "changed", G_CALLBACK(refresh_search_log_entry), this);
|
||||
g_signal_connect(G_OBJECT(m_textView), "button_press_event", G_CALLBACK(focus_on_box_cidentifier_clicked), this);
|
||||
m_buffer = gtk_text_view_get_buffer(m_textView);
|
||||
|
||||
gtk_text_buffer_create_tag(m_buffer, "f_mono", "family", "monospace", nullptr);
|
||||
gtk_text_buffer_create_tag(m_buffer, "w_bold", "weight", PANGO_WEIGHT_BOLD, nullptr);
|
||||
gtk_text_buffer_create_tag(m_buffer, "c_blue", "foreground", "#0000FF", nullptr); // debug
|
||||
gtk_text_buffer_create_tag(m_buffer, "c_magenta", "foreground", "#FF00FF", nullptr); // benchmark
|
||||
gtk_text_buffer_create_tag(m_buffer, "c_darkOrange", "foreground", "#FF9000", nullptr); // important warning
|
||||
gtk_text_buffer_create_tag(m_buffer, "c_red", "foreground", "#FF0000", nullptr); // error, fatal
|
||||
gtk_text_buffer_create_tag(m_buffer, "c_watercourse", "foreground", "#008238", nullptr); // trace
|
||||
gtk_text_buffer_create_tag(m_buffer, "c_aqua", "foreground", "#00FFFF", nullptr); // number
|
||||
gtk_text_buffer_create_tag(m_buffer, "c_darkViolet", "foreground", "#6900D7", nullptr); // warning
|
||||
gtk_text_buffer_create_tag(m_buffer, "c_blueChill", "foreground", "#3d889b", nullptr); // information
|
||||
gtk_text_buffer_create_tag(m_buffer, "link", "underline", PANGO_UNDERLINE_SINGLE, nullptr); // link for CIdentifier
|
||||
|
||||
GtkTextTagTable* tagTable = gtk_text_buffer_get_tag_table(m_buffer);
|
||||
m_IdTag = gtk_text_tag_table_lookup(tagTable, "link");
|
||||
|
||||
m_logWithHexa = ctx.getConfigurationManager().expandAsBoolean("${Designer_ConsoleLogWithHexa}", false);
|
||||
m_logTimeInSecond = ctx.getConfigurationManager().expandAsBoolean("${Kernel_ConsoleLogTimeInSecond}", false);
|
||||
m_logTimePrecision = size_t(ctx.getConfigurationManager().expandAsUInteger("${Designer_ConsoleLogTimePrecision}", 3));
|
||||
}
|
||||
|
||||
bool CLogListenerDesigner::isActive(const Kernel::ELogLevel level)
|
||||
{
|
||||
const auto it = m_activeLevels.find(level);
|
||||
if (it == m_activeLevels.end()) { return true; }
|
||||
return it->second;
|
||||
}
|
||||
|
||||
bool CLogListenerDesigner::activate(const Kernel::ELogLevel level, const bool active)
|
||||
{
|
||||
m_activeLevels[level] = active;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CLogListenerDesigner::activate(const Kernel::ELogLevel startLevel, const Kernel::ELogLevel endLevel, const bool active)
|
||||
{
|
||||
for (int i = startLevel; i <= endLevel; ++i) { m_activeLevels[Kernel::ELogLevel(i)] = active; }
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CLogListenerDesigner::activate(const bool active) { return activate(Kernel::LogLevel_First, Kernel::LogLevel_Last, active); }
|
||||
|
||||
void CLogListenerDesigner::log(const CTime value)
|
||||
{
|
||||
if (m_ignoreMsg) { return; }
|
||||
checkAppendFilterCurrentLog("c_watercourse", value.str(m_logTimeInSecond, m_logWithHexa).c_str());
|
||||
}
|
||||
|
||||
void CLogListenerDesigner::log(const uint64_t value)
|
||||
{
|
||||
if (m_ignoreMsg) { return; }
|
||||
|
||||
std::stringstream txt;
|
||||
txt << std::dec << value;
|
||||
if (m_logWithHexa) { txt << " (0x" << std::hex << value << ")"; }
|
||||
|
||||
checkAppendFilterCurrentLog("c_watercourse", txt.str().c_str());
|
||||
}
|
||||
|
||||
void CLogListenerDesigner::log(const uint32_t value)
|
||||
{
|
||||
if (m_ignoreMsg) { return; }
|
||||
|
||||
std::stringstream txt;
|
||||
txt << std::dec << value;
|
||||
if (m_logWithHexa) { txt << " (0x" << std::hex << value << ")"; }
|
||||
|
||||
checkAppendFilterCurrentLog("c_watercourse", txt.str().c_str());
|
||||
}
|
||||
|
||||
void CLogListenerDesigner::log(const int64_t value)
|
||||
{
|
||||
if (m_ignoreMsg) { return; }
|
||||
|
||||
std::stringstream txt;
|
||||
txt << std::dec << value;
|
||||
if (m_logWithHexa) { txt << " (0x" << std::hex << value << ")"; }
|
||||
|
||||
checkAppendFilterCurrentLog("c_watercourse", txt.str().c_str());
|
||||
}
|
||||
|
||||
void CLogListenerDesigner::log(const int value)
|
||||
{
|
||||
if (m_ignoreMsg) { return; }
|
||||
|
||||
std::stringstream txt;
|
||||
txt << std::dec << value;
|
||||
if (m_logWithHexa) { txt << " (0x" << std::hex << value << ")"; }
|
||||
|
||||
checkAppendFilterCurrentLog("c_watercourse", txt.str().c_str());
|
||||
}
|
||||
|
||||
void CLogListenerDesigner::log(const double value)
|
||||
{
|
||||
if (m_ignoreMsg) { return; }
|
||||
checkAppendFilterCurrentLog("c_watercourse", std::to_string(value).c_str());
|
||||
}
|
||||
|
||||
void CLogListenerDesigner::log(const bool value)
|
||||
{
|
||||
if (m_ignoreMsg) { return; }
|
||||
checkAppendFilterCurrentLog("c_watercourse", (value ? "true" : "false"));
|
||||
}
|
||||
|
||||
void CLogListenerDesigner::log(const CIdentifier& value)
|
||||
{
|
||||
if (m_ignoreMsg) { return; }
|
||||
checkAppendFilterCurrentLog("c_blueChill", value.str().c_str(), true);
|
||||
}
|
||||
|
||||
void CLogListenerDesigner::log(const CString& value)
|
||||
{
|
||||
if (m_ignoreMsg) { return; }
|
||||
checkAppendFilterCurrentLog("c_blueChill", value.toASCIIString());
|
||||
}
|
||||
|
||||
void CLogListenerDesigner::log(const std::string& value)
|
||||
{
|
||||
if (m_ignoreMsg) { return; }
|
||||
checkAppendFilterCurrentLog(nullptr, value.c_str());
|
||||
}
|
||||
|
||||
void CLogListenerDesigner::log(const char* value)
|
||||
{
|
||||
if (m_ignoreMsg) { return; }
|
||||
checkAppendFilterCurrentLog(nullptr, value);
|
||||
}
|
||||
|
||||
void CLogListenerDesigner::log(const Kernel::ELogLevel level)
|
||||
{
|
||||
// GtkTextIter textIter;
|
||||
// gtk_text_buffer_get_end_iter(m_Buffer, &l_oTextIter);
|
||||
|
||||
//new log, will be deleted when m_storedLogs is cleared
|
||||
m_currentLog = new CLogObject(m_buffer);//m_pNonFilteredBuffer);
|
||||
|
||||
//copy this newly added content in the current log
|
||||
GtkTextIter endIter;
|
||||
gtk_text_buffer_get_end_iter(m_currentLog->getTextBuffer(), &endIter);
|
||||
|
||||
const auto addTagName = [this, &endIter](GtkToggleToolButton* activeButton, size_t& countVariable, const char* state, const char* color)
|
||||
{
|
||||
m_ignoreMsg = !gtk_toggle_tool_button_get_active(activeButton);
|
||||
if (m_ignoreMsg) { return; }
|
||||
|
||||
countVariable++;
|
||||
gtk_text_buffer_insert_with_tags_by_name(m_currentLog->getTextBuffer(), &endIter, "[ ", -1, "w_bold", "f_mono", nullptr);
|
||||
gtk_text_buffer_insert_with_tags_by_name(m_currentLog->getTextBuffer(), &endIter, state, -1, "w_bold", "f_mono", color, nullptr);
|
||||
gtk_text_buffer_insert_with_tags_by_name(m_currentLog->getTextBuffer(), &endIter, " ] ", -1, "w_bold", "f_mono", nullptr);
|
||||
};
|
||||
|
||||
switch (level)
|
||||
{
|
||||
case Kernel::LogLevel_Debug:
|
||||
addTagName(m_buttonActiveDebug, m_nMsg, "DEBUG", "c_blue");
|
||||
break;
|
||||
|
||||
case Kernel::LogLevel_Benchmark:
|
||||
addTagName(m_buttonActiveBenchmark, m_nMsg, "BENCH", "c_magenta");
|
||||
break;
|
||||
|
||||
case Kernel::LogLevel_Trace:
|
||||
addTagName(m_buttonActiveTrace, m_nMsg, "TRACE", "c_watercourse");
|
||||
break;
|
||||
|
||||
case Kernel::LogLevel_Info:
|
||||
addTagName(m_buttonActiveInfo, m_nMsg, "INF", "c_blueChill");
|
||||
break;
|
||||
|
||||
case Kernel::LogLevel_Warning:
|
||||
addTagName(m_buttonActiveWarning, m_nWarning, "WARNING", "c_darkViolet");
|
||||
break;
|
||||
|
||||
case Kernel::LogLevel_ImportantWarning:
|
||||
addTagName(m_buttonActiveImportantWarning, m_nWarning, "WARNING", "c_darkOrange");
|
||||
break;
|
||||
|
||||
case Kernel::LogLevel_Error:
|
||||
addTagName(m_buttonActiveError, m_nError, "ERROR", "c_red");
|
||||
break;
|
||||
|
||||
case Kernel::LogLevel_Fatal:
|
||||
addTagName(m_buttonActiveFatal, m_nError, "FATAL", "c_red");
|
||||
break;
|
||||
|
||||
default:
|
||||
addTagName(nullptr, m_nMsg, "UNKNOWN", nullptr);
|
||||
break;
|
||||
}
|
||||
|
||||
if (gtk_toggle_button_get_active(m_buttonPopup) && (level == Kernel::LogLevel_Warning || level == Kernel::LogLevel_ImportantWarning
|
||||
|| level == Kernel::LogLevel_Error || level == Kernel::LogLevel_Fatal))
|
||||
{
|
||||
if (!gtk_widget_get_visible(GTK_WIDGET(m_alertWindow)))
|
||||
{
|
||||
gtk_window_set_position(GTK_WINDOW(m_alertWindow), GTK_WIN_POS_CENTER);
|
||||
gtk_window_present(GTK_WINDOW(m_alertWindow));
|
||||
gtk_window_set_keep_above(GTK_WINDOW(m_alertWindow), true);
|
||||
}
|
||||
}
|
||||
m_storedLogs.push_back(m_currentLog);
|
||||
|
||||
//see if the log passes the filter
|
||||
const bool passFilter = m_currentLog->filter(m_SearchTerm);
|
||||
//if it does mark this position and insert the log in the text buffer displayed
|
||||
GtkTextIter endDisplayedTextIter;
|
||||
gtk_text_buffer_get_end_iter(m_buffer, &endDisplayedTextIter);
|
||||
gtk_text_buffer_create_mark(m_buffer, "current_log", &endDisplayedTextIter,
|
||||
true); //creating a mark will erase the previous one with the same name so no worry here
|
||||
if (passFilter) { displayLog(m_currentLog); }
|
||||
|
||||
this->updateMessageCounts();
|
||||
|
||||
GtkTextMark mark;
|
||||
mark = *(gtk_text_buffer_get_mark(gtk_text_view_get_buffer(m_textView), "insert"));
|
||||
gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(m_textView), &mark, 0.0, FALSE, 0.0, 0.0);
|
||||
}
|
||||
|
||||
void CLogListenerDesigner::log(const Kernel::ELogColor /*color*/) { }
|
||||
|
||||
void CLogListenerDesigner::updateMessageCounts() const
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "<b>" << m_nMsg << "</b> Message";
|
||||
|
||||
if (m_nMsg > 1) { ss << "s"; }
|
||||
|
||||
gtk_label_set_markup(m_labelnMsg, ss.str().data());
|
||||
|
||||
if (m_nWarning > 0)
|
||||
{
|
||||
ss.str("");
|
||||
ss << "<b>" << m_nWarning << "</b> Warning";
|
||||
if (m_nWarning > 1) { ss << "s"; }
|
||||
|
||||
gtk_label_set_markup(m_labelnWarnings, ss.str().data());
|
||||
gtk_label_set_markup(m_labelDialognWarnings, ss.str().data());
|
||||
gtk_widget_set_visible(GTK_WIDGET(m_labelnWarnings), true);
|
||||
gtk_widget_set_visible(GTK_WIDGET(m_imageWarnings), true);
|
||||
}
|
||||
|
||||
if (m_nError > 0)
|
||||
{
|
||||
ss.str("");
|
||||
ss << "<b>" << m_nError << "</b> Error";
|
||||
if (m_nError > 1) { ss << "s"; }
|
||||
|
||||
gtk_label_set_markup(m_labelnErrors, ss.str().data());
|
||||
gtk_label_set_markup(m_labelDialognErrors, ss.str().data());
|
||||
gtk_widget_set_visible(GTK_WIDGET(m_labelnErrors), true);
|
||||
gtk_widget_set_visible(GTK_WIDGET(m_imageErrors), true);
|
||||
}
|
||||
}
|
||||
|
||||
void CLogListenerDesigner::clearMessages()
|
||||
{
|
||||
m_nMsg = 0;
|
||||
m_nWarning = 0;
|
||||
m_nError = 0;
|
||||
|
||||
gtk_label_set_markup(m_labelnMsg, "<b>0</b> Messages");
|
||||
gtk_label_set_markup(m_labelnWarnings, "<b>0</b> Warnings");
|
||||
gtk_label_set_markup(m_labelnErrors, "<b>0</b> Errors");
|
||||
gtk_label_set_markup(m_labelDialognWarnings, "<b>0</b> Warnings");
|
||||
gtk_label_set_markup(m_labelDialognErrors, "<b>0</b> Errors");
|
||||
|
||||
gtk_widget_set_visible(m_imageWarnings, false);
|
||||
gtk_widget_set_visible(GTK_WIDGET(m_labelnWarnings), false);
|
||||
gtk_widget_set_visible(m_imageErrors, false);
|
||||
gtk_widget_set_visible(GTK_WIDGET(m_labelnErrors), false);
|
||||
|
||||
gtk_text_buffer_set_text(m_buffer, "", -1);
|
||||
|
||||
std::for_each(m_storedLogs.begin(), m_storedLogs.end(), [](CLogObject* elem) { delete elem; });
|
||||
m_storedLogs.clear();
|
||||
|
||||
m_currentLog = nullptr;
|
||||
}
|
||||
|
||||
void CLogListenerDesigner::focusMessageWindow() const
|
||||
{
|
||||
gtk_widget_hide(GTK_WIDGET(m_alertWindow));
|
||||
gtk_expander_set_expanded(GTK_EXPANDER(gtk_builder_get_object(m_builder, "openvibe-expander_messages")), true);
|
||||
}
|
||||
|
||||
|
||||
void CLogListenerDesigner::checkAppendFilterCurrentLog(const char* textColor, const char* logMessage, const bool isLink) const
|
||||
{
|
||||
if (!m_currentLog)
|
||||
{
|
||||
std::cout << "Ouch, current log had been deleted before creating new, this shouldn't happen...\n";
|
||||
return;
|
||||
}
|
||||
m_currentLog->appendToCurrentLog(textColor, logMessage, isLink);
|
||||
|
||||
if (m_currentLog->filter(m_SearchTerm)) { displayLog(m_currentLog); }
|
||||
}
|
||||
|
||||
void CLogListenerDesigner::displayLog(CLogObject* log) const
|
||||
{
|
||||
GtkTextMark* mark = gtk_text_buffer_get_mark(m_buffer, "current_log");
|
||||
GtkTextIter iter, endIter, begin, end;
|
||||
gtk_text_buffer_get_iter_at_mark(m_buffer, &iter, mark);
|
||||
gtk_text_buffer_get_end_iter(m_buffer, &endIter);
|
||||
|
||||
//delete what after the mark
|
||||
gtk_text_buffer_delete(m_buffer, &iter, &endIter);
|
||||
//get iter
|
||||
gtk_text_buffer_get_iter_at_mark(m_buffer, &iter, mark);
|
||||
//rewrite the log
|
||||
gtk_text_buffer_get_start_iter(log->getTextBuffer(), &begin);
|
||||
gtk_text_buffer_get_end_iter(log->getTextBuffer(), &end);
|
||||
gtk_text_buffer_insert_range(m_buffer, &iter, &begin, &end);
|
||||
}
|
||||
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
Executable
+172
@@ -0,0 +1,172 @@
|
||||
#pragma once
|
||||
|
||||
#include "ovd_base.h"
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#define OVK_ClassId_Designer_LogListener OpenViBE::CIdentifier(0x0FE155FA, 0x313C17A7)
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
class CApplication;
|
||||
|
||||
class CLogListenerDesigner final : public Kernel::ILogListener
|
||||
{
|
||||
public:
|
||||
class CLogObject
|
||||
{
|
||||
public:
|
||||
explicit CLogObject(GtkTextBuffer* buffer)
|
||||
{
|
||||
m_Buffer = gtk_text_buffer_new(gtk_text_buffer_get_tag_table(buffer));
|
||||
m_PassedFilter = false;//by default the log does not pass the filter;
|
||||
}
|
||||
|
||||
GtkTextBuffer* getTextBuffer() const { return m_Buffer; }
|
||||
|
||||
//determine if the log contains the searchTerm and tag the part with the sSerachTerm in gray
|
||||
bool filter(const CString& searchTerm)
|
||||
{
|
||||
m_PassedFilter = false;
|
||||
GtkTextIter startFind, endFind;
|
||||
gtk_text_buffer_get_start_iter(m_Buffer, &startFind);
|
||||
gtk_text_buffer_get_end_iter(m_Buffer, &endFind);
|
||||
|
||||
//tag for highlighting the search term
|
||||
GtkTextTag* tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(m_Buffer), "gray_bg");
|
||||
if (tag == nullptr) { gtk_text_buffer_create_tag(m_Buffer, "gray_bg", "background", "gray", nullptr); }
|
||||
|
||||
//remove previous tagging
|
||||
gtk_text_buffer_remove_tag_by_name(m_Buffer, "gray_bg", &startFind, &endFind);
|
||||
|
||||
//no term means no research so no filter we let all pass
|
||||
if (searchTerm == CString(""))
|
||||
{
|
||||
m_PassedFilter = true;
|
||||
return m_PassedFilter;
|
||||
}
|
||||
|
||||
|
||||
GtkTextIter startMatch, endMatch;
|
||||
const gchar* text = searchTerm.toASCIIString();
|
||||
while (gtk_text_iter_forward_search(&startFind, text, GTK_TEXT_SEARCH_TEXT_ONLY, &startMatch, &endMatch, nullptr))
|
||||
{
|
||||
gtk_text_buffer_apply_tag_by_name(m_Buffer, "gray_bg", &startMatch, &endMatch);
|
||||
//offset to end_match
|
||||
const int offset = gtk_text_iter_get_offset(&endMatch);
|
||||
//begin next search at end match
|
||||
gtk_text_buffer_get_iter_at_offset(m_Buffer, &startFind, offset);
|
||||
m_PassedFilter = true;
|
||||
}
|
||||
return m_PassedFilter;
|
||||
}
|
||||
|
||||
void appendToCurrentLog(const char* textColor, const char* logMessage, const bool isLink /* = false */) const
|
||||
{
|
||||
GtkTextIter endIter;
|
||||
gtk_text_buffer_get_end_iter(m_Buffer, &endIter);
|
||||
|
||||
if (isLink) { gtk_text_buffer_insert_with_tags_by_name(m_Buffer, &endIter, logMessage, -1, "f_mono", textColor, "link", nullptr); }
|
||||
else { gtk_text_buffer_insert_with_tags_by_name(m_Buffer, &endIter, logMessage, -1, "f_mono", textColor, nullptr); }
|
||||
}
|
||||
|
||||
GtkTextBuffer* m_Buffer = nullptr;
|
||||
bool m_PassedFilter = false;
|
||||
};
|
||||
|
||||
CLogListenerDesigner(const Kernel::IKernelContext& ctx, GtkBuilder* builder);
|
||||
|
||||
bool isActive(const Kernel::ELogLevel level) override;
|
||||
bool activate(const Kernel::ELogLevel level, const bool active) override;
|
||||
bool activate(const Kernel::ELogLevel startLevel, const Kernel::ELogLevel endLevel, const bool active) override;
|
||||
bool activate(const bool active) override;
|
||||
|
||||
void log(const CTime value) override;
|
||||
|
||||
void log(const uint64_t value) override;
|
||||
void log(const uint32_t value) override;
|
||||
|
||||
void log(const int64_t value) override;
|
||||
void log(const int value) override;
|
||||
|
||||
void log(const double value) override;
|
||||
|
||||
void log(const bool value) override;
|
||||
|
||||
void log(const CIdentifier& value) override;
|
||||
void log(const CString& value) override;
|
||||
void log(const std::string& value) override;
|
||||
void log(const char* value) override;
|
||||
|
||||
void log(const Kernel::ELogLevel level) override;
|
||||
void log(const Kernel::ELogColor color) override;
|
||||
|
||||
void clearMessages();
|
||||
void focusMessageWindow() const;
|
||||
|
||||
// TODO
|
||||
void searchMessages(const CString& searchTerm);
|
||||
void displayLog(CLogObject* log) const;
|
||||
void appendLog(CLogObject* log) const;
|
||||
|
||||
_IsDerivedFromClass_Final_(Kernel::ILogListener, CIdentifier::undefined())
|
||||
|
||||
CString m_SearchTerm;
|
||||
GtkTextTag* m_IdTag = nullptr;
|
||||
std::function<void(CIdentifier&)> m_CenterOnBoxFun;
|
||||
|
||||
protected:
|
||||
|
||||
std::map<Kernel::ELogLevel, bool> m_activeLevels;
|
||||
|
||||
//logs
|
||||
std::vector<CLogObject*> m_storedLogs;
|
||||
|
||||
private:
|
||||
|
||||
GtkBuilder* m_builder = nullptr;
|
||||
GtkTextView* m_textView = nullptr;
|
||||
GtkTextBuffer* m_buffer = nullptr;
|
||||
|
||||
GtkToggleButton* m_buttonPopup = nullptr;
|
||||
|
||||
GtkToggleToolButton* m_buttonActiveDebug = nullptr;
|
||||
GtkToggleToolButton* m_buttonActiveBenchmark = nullptr;
|
||||
GtkToggleToolButton* m_buttonActiveTrace = nullptr;
|
||||
GtkToggleToolButton* m_buttonActiveInfo = nullptr;
|
||||
GtkToggleToolButton* m_buttonActiveWarning = nullptr;
|
||||
GtkToggleToolButton* m_buttonActiveImportantWarning = nullptr;
|
||||
GtkToggleToolButton* m_buttonActiveError = nullptr;
|
||||
GtkToggleToolButton* m_buttonActiveFatal = nullptr;
|
||||
|
||||
GtkLabel* m_labelnMsg = nullptr;
|
||||
GtkLabel* m_labelnWarnings = nullptr;
|
||||
GtkLabel* m_labelnErrors = nullptr;
|
||||
GtkLabel* m_labelDialognWarnings = nullptr;
|
||||
GtkLabel* m_labelDialognErrors = nullptr;
|
||||
|
||||
GtkWidget* m_imageWarnings = nullptr;
|
||||
GtkWidget* m_imageErrors = nullptr;
|
||||
|
||||
GtkWindow* m_alertWindow = nullptr;
|
||||
|
||||
bool m_ignoreMsg = false;
|
||||
|
||||
size_t m_nMsg = 0;
|
||||
size_t m_nWarning = 0;
|
||||
size_t m_nError = 0;
|
||||
|
||||
bool m_logWithHexa = false;
|
||||
bool m_logTimeInSecond = false;
|
||||
size_t m_logTimePrecision = 0;
|
||||
|
||||
CLogObject* m_currentLog = nullptr;
|
||||
|
||||
void updateMessageCounts() const;
|
||||
void checkAppendFilterCurrentLog(const char* textColor, const char* logMessage, bool isLink = false) const;
|
||||
};
|
||||
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
Masterarbeit/openvibe/designer-master/applications/platform/designer/src/ovdCPlayerVisualization.cpp
Executable
+778
@@ -0,0 +1,778 @@
|
||||
#include "ovd_base.h"
|
||||
#include "ovdCApplication.h"
|
||||
#include "ovdCInterfacedScenario.h"
|
||||
#include "ovdCPlayerVisualization.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
using EVTColumn = VisualizationToolkit::EVisualizationTreeColumn;
|
||||
using EVTNode = VisualizationToolkit::EVisualizationTreeNode;
|
||||
using EVTWidget = VisualizationToolkit::EVisualizationWidget;
|
||||
using IVTWidget = VisualizationToolkit::IVisualizationWidget;
|
||||
|
||||
static GtkTargetEntry targets[] = { { static_cast<gchar*>("STRING"), 0, 0 }, { static_cast<gchar*>("text/plain"), 0, 0 }, };
|
||||
|
||||
static void delete_window_manager_window_cb(GtkWidget* widget, GdkEvent* /*event*/, gpointer data)
|
||||
{
|
||||
CPlayerVisualization* visualization = reinterpret_cast<CPlayerVisualization*>(data);
|
||||
CInterfacedScenario& scenario = visualization->getInterfacedScenario();
|
||||
GtkWidget* dialog = gtk_message_dialog_new(GTK_WINDOW(widget), GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
|
||||
"Would you like to stop the scenario execution?");
|
||||
const gint res = gtk_dialog_run(GTK_DIALOG(dialog));
|
||||
|
||||
if (res == GTK_RESPONSE_YES) { if (visualization != nullptr) { scenario.m_Player->stop(); } }
|
||||
else if (res == GTK_RESPONSE_NO) {}
|
||||
|
||||
gtk_widget_destroy(dialog);
|
||||
}
|
||||
|
||||
CPlayerVisualization::~CPlayerVisualization()
|
||||
{
|
||||
hideTopLevelWindows();
|
||||
|
||||
m_activeToolbarButton = nullptr;
|
||||
|
||||
for (auto& window : m_windows)
|
||||
{
|
||||
g_signal_handlers_disconnect_by_func(G_OBJECT(window), G_CALLBACK2(CPlayerVisualization::configureEventCB), this);
|
||||
gtk_widget_destroy(GTK_WIDGET(window));
|
||||
}
|
||||
|
||||
m_visualizationTree.setTreeViewCB(nullptr);
|
||||
}
|
||||
|
||||
void CPlayerVisualization::init()
|
||||
{
|
||||
m_windows.clear(); // empty windows vector
|
||||
m_splitWidgets.clear(); // empty split widgets map
|
||||
m_toolbars.clear(); // empty toolbars map
|
||||
m_plugins.clear(); // empty plugin widgets map
|
||||
m_activeToolbarButton = nullptr;
|
||||
m_visualizationTree.setTreeViewCB(this); // register towards tree store
|
||||
m_visualizationTree.reloadTree(); // rebuild widgets
|
||||
m_interfacedScenario.setModifiableSettingsWidgets(); // must be called after the previous call to reload tree
|
||||
}
|
||||
|
||||
GtkWidget* CPlayerVisualization::loadTreeWidget(IVTWidget* widget)
|
||||
{
|
||||
GtkWidget* treeWidget = nullptr;
|
||||
|
||||
if (widget->getType() == EVTWidget::Panel)
|
||||
{
|
||||
//retrieve panel index
|
||||
IVTWidget* window = m_visualizationTree.getVisualizationWidget(widget->getParentIdentifier());
|
||||
if (window != nullptr)
|
||||
{
|
||||
size_t index;
|
||||
window->getChildIndex(widget->getIdentifier(), index);
|
||||
|
||||
//create notebook if this is the first panel
|
||||
if (index == 0) { treeWidget = gtk_notebook_new(); }
|
||||
else //otherwise retrieve it from first panel
|
||||
{
|
||||
CIdentifier id;
|
||||
window->getChildIdentifier(0, id);
|
||||
GtkTreeIter iter;
|
||||
m_visualizationTree.findChildNodeFromRoot(&iter, id);
|
||||
void* notebookWidget = nullptr;
|
||||
m_visualizationTree.getPointerValueFromTreeIter(&iter, notebookWidget, EVTColumn::PointerWidget);
|
||||
treeWidget = static_cast<GtkWidget*>(notebookWidget);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (widget->getType() == EVTWidget::VerticalSplit || widget->getType() == EVTWidget::HorizontalSplit
|
||||
|| widget->getType() == EVTWidget::Undefined || widget->getType() == EVTWidget::Box)
|
||||
{
|
||||
if (widget->getType() == EVTWidget::Box)
|
||||
{
|
||||
if (widget->getParentIdentifier() != CIdentifier::undefined())
|
||||
{
|
||||
//dummy widget (actual one will be created at plugin initialization time)
|
||||
treeWidget = gtk_button_new();
|
||||
}
|
||||
else { } //widget will be added to a top level window in setWidget()
|
||||
}
|
||||
else if (widget->getType() == EVTWidget::Undefined)
|
||||
{
|
||||
treeWidget = gtk_button_new();
|
||||
gtk_button_set_label(GTK_BUTTON(treeWidget), widget->getName().toASCIIString());
|
||||
}
|
||||
else if (widget->getType() == EVTWidget::HorizontalSplit || widget->getType() == EVTWidget::VerticalSplit)
|
||||
{
|
||||
treeWidget = (widget->getType() == EVTWidget::HorizontalSplit) ? gtk_hpaned_new() : gtk_vpaned_new();
|
||||
|
||||
//store paned widget in paned map
|
||||
m_splitWidgets[GTK_PANED(treeWidget)] = widget->getIdentifier();
|
||||
|
||||
//retrieve its attributes
|
||||
const int handlePos = widget->getDividerPosition();
|
||||
|
||||
//initialize paned handle position
|
||||
gtk_paned_set_position(GTK_PANED(treeWidget), handlePos);
|
||||
}
|
||||
|
||||
//parent widget to its parent
|
||||
//---------------------------
|
||||
IVTWidget* parentWidget = m_visualizationTree.getVisualizationWidget(widget->getParentIdentifier());
|
||||
|
||||
if (parentWidget != nullptr) //unparented visualization boxes don't have a parent
|
||||
{
|
||||
GtkTreeIter parentIter;
|
||||
m_visualizationTree.findChildNodeFromRoot(&parentIter, parentWidget->getIdentifier());
|
||||
|
||||
if (parentWidget->getType() == EVTWidget::Panel)
|
||||
{
|
||||
//parent widget to notebook as a new page
|
||||
void* notebook = nullptr;
|
||||
m_visualizationTree.getPointerValueFromTreeIter(&parentIter, notebook, EVTColumn::PointerWidget);
|
||||
char* name = nullptr;
|
||||
m_visualizationTree.getStringValueFromTreeIter(&parentIter, name, EVTColumn::StringName);
|
||||
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), treeWidget, gtk_label_new(name));
|
||||
}
|
||||
else if (parentWidget->getType() == EVTWidget::VerticalSplit || parentWidget->getType() == EVTWidget::HorizontalSplit)
|
||||
{
|
||||
//insert widget in parent paned
|
||||
void* paned = nullptr;
|
||||
m_visualizationTree.getPointerValueFromTreeIter(&parentIter, paned, EVTColumn::PointerWidget);
|
||||
if (paned != nullptr && GTK_IS_PANED(paned))
|
||||
{
|
||||
size_t index;
|
||||
if (parentWidget->getChildIndex(widget->getIdentifier(), index))
|
||||
{
|
||||
if (index == 0) { gtk_paned_pack1(GTK_PANED(paned), treeWidget, TRUE, TRUE); }
|
||||
else { gtk_paned_pack2(GTK_PANED(paned), treeWidget, TRUE, TRUE); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (widget->getType() == EVTWidget::Window)
|
||||
{
|
||||
//create this window only if it contains at least one visualization box
|
||||
CIdentifier identifier = CIdentifier::undefined();
|
||||
bool createWindow = false;
|
||||
|
||||
//for all visualization boxes
|
||||
while (m_visualizationTree.getNextVisualizationWidgetIdentifier(identifier, EVTWidget::Box))
|
||||
{
|
||||
//retrieve window containing current visualization box
|
||||
CIdentifier parentID;
|
||||
IVTWidget* visualizationWidget = m_visualizationTree.getVisualizationWidget(identifier);
|
||||
while (visualizationWidget->getParentIdentifier() != CIdentifier::undefined())
|
||||
{
|
||||
parentID = visualizationWidget->getParentIdentifier();
|
||||
visualizationWidget = m_visualizationTree.getVisualizationWidget(parentID);
|
||||
}
|
||||
|
||||
//if current box is parented to window passed in parameter, break and create it
|
||||
if (m_visualizationTree.getVisualizationWidget(parentID) == widget)
|
||||
{
|
||||
createWindow = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (createWindow)
|
||||
{
|
||||
//create new top level window
|
||||
treeWidget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
m_windows.push_back(GTK_WINDOW(treeWidget));
|
||||
|
||||
//retrieve its size
|
||||
gtk_window_set_default_size(GTK_WINDOW(treeWidget), int(widget->getWidth()), int(widget->getHeight()));
|
||||
//set its title
|
||||
gtk_window_set_title(GTK_WINDOW(treeWidget), static_cast<const char*>(widget->getName()));
|
||||
|
||||
//set it transient for main window
|
||||
//gtk_window_set_transient_for(GTK_WINDOW(treeWidget), GTK_WINDOW(m_interfacedScenario.m_rApplication.m_MainWindow));
|
||||
|
||||
//centered on the main window
|
||||
if (m_kernelCtx.getConfigurationManager().expandAsBoolean("${Designer_WindowManager_Center}", false))
|
||||
{
|
||||
gtk_window_set_position(GTK_WINDOW(treeWidget), GTK_WIN_POS_CENTER_ON_PARENT);
|
||||
}
|
||||
|
||||
//FIXME wrong spelling (-)
|
||||
gtk_signal_connect(GTK_OBJECT(treeWidget), "configure_event", G_CALLBACK(configureEventCB), this);
|
||||
//FIXME wrong spelling (-)
|
||||
g_signal_connect(treeWidget, "delete_event", G_CALLBACK(delete_window_manager_window_cb), this);
|
||||
}
|
||||
}
|
||||
|
||||
//show newly created widget
|
||||
if (treeWidget != nullptr && widget->getType() != EVTWidget::Window) { gtk_widget_show(treeWidget); }
|
||||
|
||||
return treeWidget;
|
||||
}
|
||||
|
||||
void CPlayerVisualization::endLoadTreeWidget(IVTWidget* widget)
|
||||
{
|
||||
//retrieve tree widget
|
||||
GtkTreeIter iter;
|
||||
m_visualizationTree.findChildNodeFromRoot(&iter, widget->getIdentifier());
|
||||
void* treeWidget;
|
||||
m_visualizationTree.getPointerValueFromTreeIter(&iter, treeWidget, EVTColumn::PointerWidget);
|
||||
|
||||
if (treeWidget != nullptr && widget->getType() == EVTWidget::Window)
|
||||
{
|
||||
//retrieve notebook
|
||||
CIdentifier id;
|
||||
widget->getChildIdentifier(0, id);
|
||||
GtkTreeIter childIter;
|
||||
m_visualizationTree.findChildNodeFromRoot(&childIter, id);
|
||||
void* childTree;
|
||||
m_visualizationTree.getPointerValueFromTreeIter(&childIter, childTree, EVTColumn::PointerWidget);
|
||||
|
||||
//insert notebook in window
|
||||
if (childTree != nullptr && GTK_IS_NOTEBOOK(static_cast<GtkWidget*>(childTree)))
|
||||
{
|
||||
gtk_container_add(GTK_CONTAINER(static_cast<GtkWidget*>(treeWidget)), static_cast<GtkWidget*>(childTree));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CPlayerVisualization::setToolbar(const CIdentifier& boxID, GtkWidget* widget)
|
||||
{
|
||||
//retrieve visualization widget
|
||||
IVTWidget* visuWidget = m_visualizationTree.getVisualizationWidgetFromBoxIdentifier(boxID);
|
||||
if (visuWidget == nullptr)
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "CPlayerVisualization::setToolbar FAILED : couldn't retrieve simulated box with identifier "
|
||||
<< boxID << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
//ensure toolbar pointer is not null
|
||||
if (widget == nullptr)
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "CPlayerVisualization::setToolbar FAILED : toolbar pointer is nullptr for plugin "
|
||||
<< visuWidget->getName() << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
//ensure toolbar pointer is a window
|
||||
if (GTK_IS_WINDOW(widget) == 0)
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "CPlayerVisualization::setToolbar FAILED : toolbar pointer is not a GtkWindow for plugin "
|
||||
<< visuWidget->getName() << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
//retrieve identifier
|
||||
const CIdentifier id = visuWidget->getIdentifier();
|
||||
|
||||
//store toolbar
|
||||
m_plugins[id].m_Toolbar = widget;
|
||||
|
||||
//ensure it is open at mouse position
|
||||
gtk_window_set_position(GTK_WINDOW(widget), GTK_WIN_POS_MOUSE);
|
||||
|
||||
//if toolbar button has been created, set it sensitive (otherwise it will be set active later)
|
||||
if (m_plugins[id].m_ToolbarButton != nullptr)
|
||||
{
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(m_plugins[id].m_ToolbarButton), 1);
|
||||
|
||||
//associate toolbar button to toolbar window
|
||||
m_toolbars[m_plugins[id].m_ToolbarButton] = widget;
|
||||
}
|
||||
|
||||
//catch delete events
|
||||
g_signal_connect(G_OBJECT(widget), "delete-event", G_CALLBACK(toolbarDeleteEventCB), this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CPlayerVisualization::setWidget(const CIdentifier& boxID, GtkWidget* widget)
|
||||
{
|
||||
//retrieve visualization widget
|
||||
IVTWidget* visuWidget = m_visualizationTree.getVisualizationWidgetFromBoxIdentifier(boxID);
|
||||
if (visuWidget == nullptr)
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "CPlayerVisualization::setWidget FAILED : couldn't retrieve simulated box with identifier "
|
||||
<< boxID << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
//ensure widget pointer is not null
|
||||
if (widget == nullptr)
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Warning << "CPlayerVisualization::setWidget FAILED : widget pointer is nullptr for plugin "
|
||||
<< visuWidget->getName() << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
//unparent top widget, if necessary
|
||||
GtkWidget* parent = gtk_widget_get_parent(widget);
|
||||
if (GTK_IS_CONTAINER(parent))
|
||||
{
|
||||
gtk_object_ref(GTK_OBJECT(widget));
|
||||
gtk_container_remove(GTK_CONTAINER(parent), widget);
|
||||
}
|
||||
|
||||
//create a box to store toolbar button and plugin widget
|
||||
GtkBox* box = GTK_BOX(gtk_vbox_new(FALSE, 0));
|
||||
//gtk_widget_set_size_request(GTK_WIDGET(vBox), 0, 0);
|
||||
|
||||
//create toolbar button
|
||||
GtkToggleButton* button = GTK_TOGGLE_BUTTON(gtk_toggle_button_new());
|
||||
{
|
||||
//horizontal container : icon + label
|
||||
GtkBox* hBox = GTK_BOX(gtk_hbox_new(FALSE, 0));
|
||||
//gtk_widget_set_size_request(GTK_WIDGET(hBox), 0, 0);
|
||||
|
||||
//retrieve icon name
|
||||
GtkTreeIter iter;
|
||||
char* iconString = nullptr;
|
||||
if (m_visualizationTree.findChildNodeFromRoot(&iter, static_cast<const char*>(visuWidget->getName()), EVTNode::VisualizationBox))
|
||||
{
|
||||
m_visualizationTree.getStringValueFromTreeIter(&iter, iconString, EVTColumn::StringStockIcon);
|
||||
}
|
||||
|
||||
//create icon
|
||||
GtkWidget* icon = gtk_image_new_from_stock(iconString != nullptr ? iconString : GTK_STOCK_EXECUTE, GTK_ICON_SIZE_BUTTON);
|
||||
//gtk_widget_set_size_request(icon, 0, 0);
|
||||
gtk_box_pack_start(hBox, icon, TRUE, TRUE, 0);
|
||||
|
||||
//create label
|
||||
GtkWidget* label = gtk_label_new(static_cast<const char*>(visuWidget->getName()));
|
||||
//gtk_widget_set_size_request(label, 0, 0);
|
||||
gtk_box_pack_start(hBox, label, TRUE, TRUE, 0);
|
||||
|
||||
//add box to button
|
||||
gtk_container_add(GTK_CONTAINER(button), GTK_WIDGET(hBox));
|
||||
}
|
||||
|
||||
//detect toolbar button toggle events
|
||||
g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(toolbarButtonToggledCB), this);
|
||||
|
||||
//set up toolbar button as drag destination
|
||||
gtk_drag_dest_set(GTK_WIDGET(button), GTK_DEST_DEFAULT_ALL, targets, sizeof(targets) / sizeof(GtkTargetEntry), GDK_ACTION_COPY);
|
||||
g_signal_connect(G_OBJECT(button), "drag_data_received", G_CALLBACK(dragDataReceivedInWidgetCB), this);
|
||||
|
||||
//set up toolbar button as drag source as well
|
||||
gtk_drag_source_set(GTK_WIDGET(button), GDK_BUTTON1_MASK, targets, sizeof(targets) / sizeof(GtkTargetEntry), GDK_ACTION_COPY);
|
||||
g_signal_connect(G_OBJECT(button), "drag_data_get", G_CALLBACK(dragDataGetFromWidgetCB), this);
|
||||
|
||||
//store plugin widget and toolbar button
|
||||
const CIdentifier id = visuWidget->getIdentifier();
|
||||
m_plugins[id].m_Widget = widget;
|
||||
m_plugins[id].m_ToolbarButton = button;
|
||||
|
||||
//if a toolbar was registered for this widget, set its button sensitive
|
||||
if (m_plugins[id].m_Toolbar != nullptr)
|
||||
{
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(button), 1);
|
||||
|
||||
//associate toolbar button to toolbar window
|
||||
m_toolbars[button] = m_plugins[id].m_Toolbar;
|
||||
}
|
||||
else { gtk_widget_set_sensitive(GTK_WIDGET(button), 0); }
|
||||
|
||||
//vertical container : button on top, visualization box below
|
||||
gtk_box_pack_start(box, GTK_WIDGET(button), FALSE, TRUE, 0);
|
||||
gtk_box_pack_start(box, widget, TRUE, TRUE, 0);
|
||||
|
||||
//show vbox hierarchy
|
||||
gtk_widget_show_all(GTK_WIDGET(box));
|
||||
|
||||
//parent box at the appropriate location
|
||||
parentWidgetBox(visuWidget, box);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CPlayerVisualization::parentWidgetBox(IVTWidget* widget, GtkBox* widgetBox)
|
||||
{
|
||||
//if widget is unaffected, open it in its own window
|
||||
if (widget->getParentIdentifier() == CIdentifier::undefined())
|
||||
{
|
||||
//create a top level window
|
||||
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
m_windows.push_back(GTK_WINDOW(window));
|
||||
const uint64_t width = m_kernelCtx.getConfigurationManager().expandAsUInteger("${Designer_UnaffectedVisualizationWindowWidth}", 400);
|
||||
const uint64_t height = m_kernelCtx.getConfigurationManager().expandAsUInteger("${Designer_UnaffectedVisualizationWindowHeight}", 400);
|
||||
|
||||
gtk_window_set_default_size(GTK_WINDOW(window), gint(width), gint(height));
|
||||
//set its title
|
||||
gtk_window_set_title(GTK_WINDOW(window), static_cast<const char*>(widget->getName()));
|
||||
//set it transient for main window
|
||||
//gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(m_interfacedScenario.m_rApplication.m_MainWindow));
|
||||
//insert box in top level window
|
||||
gtk_container_add(GTK_CONTAINER(window), reinterpret_cast<GtkWidget*>(widgetBox));
|
||||
//prevent user from closing this window
|
||||
g_signal_connect(window, "delete_event", G_CALLBACK(delete_window_manager_window_cb), this);
|
||||
|
||||
//position: centered in the main window
|
||||
if (m_kernelCtx.getConfigurationManager().expandAsBoolean("${Designer_WindowManager_Center}", false))
|
||||
{
|
||||
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ON_PARENT);
|
||||
}
|
||||
|
||||
//show window (and realize widget in doing so)
|
||||
gtk_widget_show(window);
|
||||
}
|
||||
else //retrieve parent widget in which to insert current widget
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
if (m_visualizationTree.findChildNodeFromRoot(&iter, widget->getParentIdentifier()))
|
||||
{
|
||||
void* parent = nullptr;
|
||||
m_visualizationTree.getPointerValueFromTreeIter(&iter, parent, EVTColumn::PointerWidget);
|
||||
CIdentifier id;
|
||||
m_visualizationTree.getIdentifierFromTreeIter(&iter, id, EVTColumn::StringIdentifier);
|
||||
|
||||
//widget is to be parented to a paned widget
|
||||
if (GTK_IS_PANED(parent))
|
||||
{
|
||||
//retrieve index at which to insert child
|
||||
IVTWidget* parentWidget = m_visualizationTree.getVisualizationWidget(id);
|
||||
size_t index;
|
||||
parentWidget->getChildIndex(widget->getIdentifier(), index);
|
||||
//insert visualization box in paned
|
||||
if (index == 0)
|
||||
{
|
||||
gtk_container_remove(GTK_CONTAINER(parent), gtk_paned_get_child1(GTK_PANED(parent)));
|
||||
gtk_paned_pack1(GTK_PANED(parent), GTK_WIDGET(widgetBox), TRUE, TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_container_remove(GTK_CONTAINER(parent), gtk_paned_get_child2(GTK_PANED(parent)));
|
||||
gtk_paned_pack2(GTK_PANED(parent), GTK_WIDGET(widgetBox), TRUE, TRUE);
|
||||
}
|
||||
}
|
||||
else if (GTK_IS_NOTEBOOK(parent)) //widget is to be added to a notebook page
|
||||
{
|
||||
//retrieve notebook page index
|
||||
IVTWidget* parentWidget = m_visualizationTree.getVisualizationWidget(id);
|
||||
IVTWidget* parentWindow = m_visualizationTree.getVisualizationWidget(parentWidget->getParentIdentifier());
|
||||
size_t index;
|
||||
parentWindow->getChildIndex(parentWidget->getIdentifier(), index);
|
||||
|
||||
//remove temporary page
|
||||
gtk_notebook_remove_page(GTK_NOTEBOOK(parent), index);
|
||||
|
||||
//insert final page
|
||||
gtk_notebook_insert_page(GTK_NOTEBOOK(parent), GTK_WIDGET(widgetBox), gtk_label_new(parentWidget->getName().toASCIIString()), index);
|
||||
}
|
||||
|
||||
//resize widgets once they are allocated : this is the case when they are shown on an expose event
|
||||
//FIXME : perform resizing only once (when it is done as many times as there are widgets in the tree here)
|
||||
if (parent != nullptr) { gtk_signal_connect(GTK_OBJECT(parent), "expose-event", G_CALLBACK(widgetExposeEventCB), this); }
|
||||
|
||||
//show window (and realize widget if it owns a 3D context)
|
||||
//--------------------------------------------------------
|
||||
//get panel containing widget
|
||||
GtkTreeIter panelIter = iter;
|
||||
if (m_visualizationTree.findParentNode(&panelIter, EVTNode::VisualizationPanel))
|
||||
{
|
||||
//get panel identifier
|
||||
m_visualizationTree.getIdentifierFromTreeIter(&panelIter, id, EVTColumn::StringIdentifier);
|
||||
|
||||
//get panel index in window
|
||||
size_t index;
|
||||
m_visualizationTree.getVisualizationWidgetIndex(id, index);
|
||||
|
||||
//get notebook pointer
|
||||
void* panelWidget = nullptr;
|
||||
m_visualizationTree.getPointerValueFromTreeIter(&panelIter, panelWidget, EVTColumn::PointerWidget);
|
||||
|
||||
//get parent window
|
||||
GtkTreeIter windowIter = panelIter;
|
||||
if (m_visualizationTree.findParentNode(&windowIter, EVTNode::VisualizationWindow))
|
||||
{
|
||||
//get parent window pointer
|
||||
void* windowWidget = nullptr;
|
||||
m_visualizationTree.getPointerValueFromTreeIter(&windowIter, windowWidget, EVTColumn::PointerWidget);
|
||||
|
||||
//show parent window
|
||||
gtk_widget_show(GTK_WIDGET(windowWidget));
|
||||
// gtk_widget_realize(GTK_WIDGET(windowWidget));
|
||||
// gdk_flush();
|
||||
|
||||
//set panel containing widget as current (this realizes the widget)
|
||||
gtk_notebook_set_current_page(GTK_NOTEBOOK(panelWidget), index);
|
||||
|
||||
//then reset first panel as current
|
||||
gtk_notebook_set_current_page(GTK_NOTEBOOK(panelWidget), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//called upon Player start
|
||||
void CPlayerVisualization::showTopLevelWindows()
|
||||
|
||||
{
|
||||
for (auto& window : m_windows) { gtk_widget_show(GTK_WIDGET(window)); }
|
||||
if (m_activeToolbarButton != nullptr)
|
||||
{
|
||||
//show active toolbar
|
||||
gtk_widget_show(m_toolbars[m_activeToolbarButton]);
|
||||
}
|
||||
auto it = m_plugins.begin();
|
||||
while (it != m_plugins.end())
|
||||
{
|
||||
if (GTK_IS_WIDGET(it->second.m_Widget)) { gtk_widget_show(it->second.m_Widget); }
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
//called upon Player stop
|
||||
void CPlayerVisualization::hideTopLevelWindows()
|
||||
|
||||
{
|
||||
auto it = m_plugins.begin();
|
||||
while (it != m_plugins.end())
|
||||
{
|
||||
if (GTK_IS_WIDGET(it->second.m_Widget)) { gtk_widget_hide(it->second.m_Widget); }
|
||||
++it;
|
||||
}
|
||||
|
||||
for (auto& window : m_windows) { gtk_widget_hide(GTK_WIDGET(window)); }
|
||||
|
||||
//hide active toolbar
|
||||
if (m_activeToolbarButton != nullptr) { gtk_widget_hide(m_toolbars[m_activeToolbarButton]); }
|
||||
}
|
||||
|
||||
//event generated whenever window changes size, including when it is first created
|
||||
gboolean CPlayerVisualization::configureEventCB(GtkWidget* widget, GdkEventConfigure* /*event*/, gpointer data)
|
||||
{
|
||||
//paned positions aren't to be saved, they are to be read once only
|
||||
g_signal_handlers_disconnect_by_func(G_OBJECT(widget), G_CALLBACK2(CPlayerVisualization::configureEventCB), data);
|
||||
|
||||
if (GTK_IS_CONTAINER(widget)) { static_cast<CPlayerVisualization*>(data)->resizeCB(GTK_CONTAINER(widget)); }
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean CPlayerVisualization::widgetExposeEventCB(GtkWidget* widget, GdkEventExpose* /*event*/, gpointer data)
|
||||
{
|
||||
g_signal_handlers_disconnect_by_func(G_OBJECT(widget), G_CALLBACK2(CPlayerVisualization::widgetExposeEventCB), data);
|
||||
/*
|
||||
//retrieve topmost widget
|
||||
while(gtk_widget_get_parent(widget) != nullptr && GTK_IS_CONTAINER(gtk_widget_get_parent(widget))) { widget = gtk_widget_get_parent(widget); }
|
||||
*/
|
||||
if (GTK_IS_CONTAINER(widget)) { static_cast<CPlayerVisualization*>(data)->resizeCB(GTK_CONTAINER(widget)); }
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void CPlayerVisualization::resizeCB(GtkContainer* container)
|
||||
{
|
||||
if (GTK_IS_WINDOW(container))
|
||||
{
|
||||
const gpointer data = g_list_first(gtk_container_get_children(container))->data;
|
||||
|
||||
if (GTK_IS_CONTAINER(data)) { resizeCB(GTK_CONTAINER(data)); }
|
||||
}
|
||||
else if (GTK_IS_NOTEBOOK(container))
|
||||
{
|
||||
GtkNotebook* notebook = GTK_NOTEBOOK(container);
|
||||
|
||||
for (int i = 0; i < gtk_notebook_get_n_pages(notebook); ++i)
|
||||
{
|
||||
GtkWidget* widget = gtk_notebook_get_nth_page(notebook, i);
|
||||
if (GTK_IS_CONTAINER(widget)) { resizeCB(GTK_CONTAINER(widget)); }
|
||||
}
|
||||
}
|
||||
else if (GTK_IS_PANED(container))
|
||||
{
|
||||
GtkPaned* paned = GTK_PANED(container);
|
||||
|
||||
//retrieve paned identifier from paned map
|
||||
CIdentifier& id = m_splitWidgets[GTK_PANED(paned)];
|
||||
|
||||
//retrieve its attributes
|
||||
IVTWidget* widget = m_visualizationTree.getVisualizationWidget(id);
|
||||
const int pos = widget->getDividerPosition();
|
||||
const int maxPos = widget->getMaxDividerPosition();
|
||||
|
||||
if (maxPos > 0)
|
||||
{
|
||||
//retrieve current maximum handle position
|
||||
const int currentMaxPos = GTK_IS_VPANED(paned) ? paned->container.widget.allocation.height
|
||||
: paned->container.widget.allocation.width;
|
||||
|
||||
//set new paned handle position
|
||||
gtk_paned_set_position(paned, pos * currentMaxPos / maxPos);
|
||||
}
|
||||
|
||||
//go down each child
|
||||
GtkWidget* child = gtk_paned_get_child1(paned);
|
||||
if (GTK_IS_CONTAINER(child)) { resizeCB(GTK_CONTAINER(child)); }
|
||||
|
||||
child = gtk_paned_get_child2(paned);
|
||||
if (GTK_IS_CONTAINER(child)) { resizeCB(GTK_CONTAINER(child)); }
|
||||
}
|
||||
}
|
||||
|
||||
void CPlayerVisualization::dragDataGetFromWidgetCB(GtkWidget* srcWidget, GdkDragContext* /*dc*/, GtkSelectionData* selectionData,
|
||||
guint /*info*/, guint /*time*/, gpointer /*data*/)
|
||||
{
|
||||
char str[1024];
|
||||
sprintf(str, "%p", srcWidget);
|
||||
gtk_selection_data_set_text(selectionData, str, gint(strlen(str)));
|
||||
}
|
||||
|
||||
void CPlayerVisualization::dragDataReceivedInWidgetCB(GtkWidget* dstWidget, GdkDragContext* /*dc*/, gint /*x*/, gint /*y*/, GtkSelectionData* selectionData,
|
||||
guint /*info*/, guint /*time*/, gpointer /*data*/)
|
||||
{
|
||||
void* srcWidget = nullptr;
|
||||
sscanf(reinterpret_cast<const char*>(gtk_selection_data_get_text(selectionData)), "%p", &srcWidget);
|
||||
|
||||
//retrieve source box and parent widgets
|
||||
GtkWidget* srcBoxWidget;
|
||||
do { srcBoxWidget = gtk_widget_get_parent(GTK_WIDGET(srcWidget)); } while (srcBoxWidget != nullptr && !GTK_IS_VBOX(srcBoxWidget));
|
||||
|
||||
if (srcBoxWidget == nullptr) { return; }
|
||||
|
||||
GtkWidget* srcParentWidget = gtk_widget_get_parent(srcBoxWidget);
|
||||
|
||||
if (srcParentWidget == nullptr) { return; }
|
||||
|
||||
//retrieve dest box and parent widgets
|
||||
GtkWidget* dstBoxWidget;
|
||||
do { dstBoxWidget = gtk_widget_get_parent(dstWidget); } while (dstBoxWidget != nullptr && !GTK_IS_VBOX(dstBoxWidget));
|
||||
|
||||
if (dstBoxWidget == nullptr) { return; }
|
||||
|
||||
GtkWidget* dstParentWidget = gtk_widget_get_parent(dstBoxWidget);
|
||||
|
||||
if (dstParentWidget == nullptr) { return; }
|
||||
|
||||
//ensure src and dst widgets are different
|
||||
if (srcBoxWidget == dstBoxWidget) { return; }
|
||||
|
||||
//remove src box from parent
|
||||
int srcIndex;
|
||||
GtkWidget* srcTabLabel = nullptr;
|
||||
|
||||
if (GTK_IS_WINDOW(srcParentWidget)) { srcIndex = 0; }
|
||||
else if (GTK_IS_NOTEBOOK(srcParentWidget))
|
||||
{
|
||||
srcIndex = gtk_notebook_page_num(GTK_NOTEBOOK(srcParentWidget), srcBoxWidget);
|
||||
srcTabLabel = gtk_label_new(gtk_notebook_get_tab_label_text(GTK_NOTEBOOK(srcParentWidget), srcBoxWidget));
|
||||
}
|
||||
else if (GTK_IS_PANED(srcParentWidget)) { srcIndex = reinterpret_cast<GtkPaned*>(srcParentWidget)->child1 == srcBoxWidget ? 1 : 2; }
|
||||
else { return; }
|
||||
|
||||
//remove dst box from parent
|
||||
int dstIndex;
|
||||
GtkWidget* dstTabLabel = nullptr;
|
||||
if (GTK_IS_WINDOW(dstParentWidget)) { dstIndex = 0; }
|
||||
else if (GTK_IS_NOTEBOOK(dstParentWidget))
|
||||
{
|
||||
dstIndex = gtk_notebook_page_num(GTK_NOTEBOOK(dstParentWidget), dstBoxWidget);
|
||||
dstTabLabel = gtk_label_new(gtk_notebook_get_tab_label_text(GTK_NOTEBOOK(dstParentWidget), dstBoxWidget));
|
||||
}
|
||||
else if (GTK_IS_PANED(dstParentWidget)) { dstIndex = reinterpret_cast<GtkPaned*>(dstParentWidget)->child1 == dstBoxWidget ? 1 : 2; }
|
||||
else { return; }
|
||||
|
||||
gtk_object_ref(GTK_OBJECT(srcBoxWidget));
|
||||
gtk_container_remove(GTK_CONTAINER(srcParentWidget), srcBoxWidget);
|
||||
|
||||
gtk_object_ref(GTK_OBJECT(dstBoxWidget));
|
||||
gtk_container_remove(GTK_CONTAINER(dstParentWidget), dstBoxWidget);
|
||||
|
||||
//parent src box to dst parent
|
||||
if (GTK_IS_WINDOW(dstParentWidget)) { gtk_container_add(GTK_CONTAINER(dstParentWidget), srcBoxWidget); }
|
||||
else if (GTK_IS_NOTEBOOK(dstParentWidget)) { gtk_notebook_insert_page(GTK_NOTEBOOK(dstParentWidget), srcBoxWidget, dstTabLabel, dstIndex); }
|
||||
else //dst parent is a paned
|
||||
{
|
||||
if (dstIndex == 1) { gtk_paned_pack1(GTK_PANED(dstParentWidget), srcBoxWidget, TRUE, TRUE); }
|
||||
else { gtk_paned_pack2(GTK_PANED(dstParentWidget), srcBoxWidget, TRUE, TRUE); }
|
||||
}
|
||||
|
||||
//parent dst box to src parent
|
||||
if (GTK_IS_WINDOW(srcParentWidget)) { gtk_container_add(GTK_CONTAINER(srcParentWidget), dstBoxWidget); }
|
||||
else if (GTK_IS_NOTEBOOK(srcParentWidget)) { gtk_notebook_insert_page(GTK_NOTEBOOK(srcParentWidget), dstBoxWidget, srcTabLabel, srcIndex); }
|
||||
else //src parent is a paned
|
||||
{
|
||||
if (srcIndex == 1) { gtk_paned_pack1(GTK_PANED(srcParentWidget), dstBoxWidget, TRUE, TRUE); }
|
||||
else { gtk_paned_pack2(GTK_PANED(srcParentWidget), dstBoxWidget, TRUE, TRUE); }
|
||||
}
|
||||
}
|
||||
|
||||
void CPlayerVisualization::toolbarButtonToggledCB(GtkToggleButton* button, gpointer data) { static_cast<CPlayerVisualization*>(data)->toggleToolbarCB(button); }
|
||||
|
||||
bool CPlayerVisualization::toggleToolbarCB(GtkToggleButton* button)
|
||||
{
|
||||
//retrieve toolbar
|
||||
if (m_toolbars.find(button) == m_toolbars.end()) { return false; }
|
||||
GtkWidget* toolbar = m_toolbars[button];
|
||||
|
||||
//if current toolbar is toggled on or off, update toolbar state accordingly
|
||||
if (button == m_activeToolbarButton)
|
||||
{
|
||||
//hiding active toolbar
|
||||
if (gtk_toggle_button_get_active(button) == FALSE)
|
||||
{
|
||||
gtk_widget_hide(toolbar);
|
||||
m_activeToolbarButton = nullptr;
|
||||
}
|
||||
else { gtk_widget_show(toolbar); } //showing active toolbar
|
||||
}
|
||||
else //a new toolbar is to be shown
|
||||
{
|
||||
//hide previously active toolbar, if any
|
||||
if (m_activeToolbarButton != nullptr)
|
||||
{
|
||||
gtk_widget_hide(m_toolbars[m_activeToolbarButton]);
|
||||
|
||||
g_signal_handlers_disconnect_by_func(m_activeToolbarButton, G_CALLBACK2(toolbarButtonToggledCB), this);
|
||||
gtk_toggle_button_set_active(m_activeToolbarButton, FALSE);
|
||||
g_signal_connect(m_activeToolbarButton, "toggled", G_CALLBACK(toolbarButtonToggledCB), this);
|
||||
}
|
||||
/*
|
||||
//set toolbar transient for plugin window
|
||||
::GtkWidget* widget = GTK_WIDGET(pToolbarButton);
|
||||
while(widget!=nullptr && !GTK_IS_WINDOW(widget)) { widget = gtk_widget_get_parent(widget); }
|
||||
if(widget != nullptr && GTK_IS_WINDOW(toolbar)) { gtk_window_set_transient_for(GTK_WINDOW(toolbar), GTK_WINDOW(widget)); }
|
||||
*/
|
||||
//show new toolbar
|
||||
gtk_widget_show(toolbar);
|
||||
|
||||
//update active toolbar button
|
||||
m_activeToolbarButton = button;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
gboolean CPlayerVisualization::toolbarDeleteEventCB(GtkWidget* widget, GdkEvent* /*event*/, gpointer data)
|
||||
{
|
||||
if (data != nullptr) { static_cast<CPlayerVisualization*>(data)->deleteToolbarCB(widget); }
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool CPlayerVisualization::deleteToolbarCB(GtkWidget* widget)
|
||||
{
|
||||
if (m_activeToolbarButton == nullptr || m_toolbars[m_activeToolbarButton] != widget)
|
||||
{
|
||||
//error : active toolbar isn't the one registered as such
|
||||
gtk_widget_hide(widget);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//toggle toolbar button off
|
||||
g_signal_handlers_disconnect_by_func(m_activeToolbarButton, G_CALLBACK2(toolbarButtonToggledCB), this);
|
||||
gtk_toggle_button_set_active(m_activeToolbarButton, FALSE);
|
||||
g_signal_connect(m_activeToolbarButton, "toggled", G_CALLBACK(toolbarButtonToggledCB), this);
|
||||
|
||||
//hide toolbar
|
||||
gtk_widget_hide(widget);
|
||||
|
||||
//clear active toolbar button pointer
|
||||
m_activeToolbarButton = nullptr;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
#pragma once
|
||||
|
||||
#include "ovd_base.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
class CInterfacedScenario;
|
||||
|
||||
class CPlayerVisualization final : public VisualizationToolkit::ITreeViewCB
|
||||
{
|
||||
public:
|
||||
CPlayerVisualization(const Kernel::IKernelContext& ctx, VisualizationToolkit::IVisualizationTree& tree,
|
||||
CInterfacedScenario& interfacedScenario)
|
||||
: m_kernelCtx(ctx), m_visualizationTree(tree), m_interfacedScenario(interfacedScenario) { }
|
||||
|
||||
~CPlayerVisualization() override;
|
||||
|
||||
void init();
|
||||
|
||||
/** \name ITreeViewCB interface implementation */
|
||||
//@{
|
||||
GtkWidget* loadTreeWidget(VisualizationToolkit::IVisualizationWidget* widget) override;
|
||||
void endLoadTreeWidget(VisualizationToolkit::IVisualizationWidget* widget) override;
|
||||
bool setToolbar(const CIdentifier& boxID, GtkWidget* widget) override;
|
||||
bool setWidget(const CIdentifier& boxID, GtkWidget* widget) override;
|
||||
//@}
|
||||
|
||||
void showTopLevelWindows();
|
||||
void hideTopLevelWindows();
|
||||
CInterfacedScenario& getInterfacedScenario() const { return m_interfacedScenario; }
|
||||
|
||||
protected:
|
||||
bool parentWidgetBox(VisualizationToolkit::IVisualizationWidget* widget, GtkBox* widgetBox);
|
||||
|
||||
static gboolean configureEventCB(GtkWidget* widget, GdkEventConfigure* event, gpointer data);
|
||||
static gboolean widgetExposeEventCB(GtkWidget* widget, GdkEventExpose* event, gpointer data);
|
||||
void resizeCB(GtkContainer* container);
|
||||
|
||||
//callbacks for DND
|
||||
static void dragDataGetFromWidgetCB(GtkWidget* srcWidget, GdkDragContext* dc, GtkSelectionData* selectionData, guint info, guint time, gpointer data);
|
||||
static void dragDataReceivedInWidgetCB(GtkWidget* dstWidget, GdkDragContext* dc, gint x, gint y, GtkSelectionData* selectionData, guint info, guint time,
|
||||
gpointer data);
|
||||
|
||||
//callback for toolbar
|
||||
static void toolbarButtonToggledCB(GtkToggleButton* button, gpointer data);
|
||||
bool toggleToolbarCB(GtkToggleButton* button);
|
||||
static gboolean toolbarDeleteEventCB(GtkWidget* widget, GdkEvent* event, gpointer data);
|
||||
bool deleteToolbarCB(GtkWidget* widget);
|
||||
|
||||
private:
|
||||
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
VisualizationToolkit::IVisualizationTree& m_visualizationTree;
|
||||
CInterfacedScenario& m_interfacedScenario;
|
||||
|
||||
/**
|
||||
* \brief Vector of top level windows
|
||||
*/
|
||||
std::vector<GtkWindow*> m_windows;
|
||||
|
||||
/**
|
||||
* \brief Map of split (paned) widgets associated to their identifiers
|
||||
* This map is used to retrieve size properties of split widgets upon window resizing,
|
||||
* so as to keep the relative sizes of a hierarchy of widgets
|
||||
*/
|
||||
std::map<GtkPaned*, CIdentifier> m_splitWidgets;
|
||||
|
||||
/**
|
||||
* \brief Map associating toolbar buttons to toolbar windows
|
||||
*/
|
||||
std::map<GtkToggleButton*, GtkWidget*> m_toolbars;
|
||||
|
||||
/**
|
||||
* \brief Pointer to active toolbar button
|
||||
*/
|
||||
GtkToggleButton* m_activeToolbarButton = nullptr;
|
||||
|
||||
class CPluginWidgets
|
||||
{
|
||||
public:
|
||||
CPluginWidgets() = default;
|
||||
~CPluginWidgets() = default;
|
||||
GtkWidget* m_Widget = nullptr;
|
||||
GtkToggleButton* m_ToolbarButton = nullptr;
|
||||
GtkWidget* m_Toolbar = nullptr;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Map of visualization plugins
|
||||
*/
|
||||
std::map<CIdentifier, CPluginWidgets> m_plugins;
|
||||
};
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
#include "ovdCRenameDialog.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
bool CRenameDialog::run()
|
||||
{
|
||||
GtkBuilder* interface = gtk_builder_new(); // glade_xml_new(m_guiFilename.toASCIIString(), "rename", nullptr);
|
||||
gtk_builder_add_from_file(interface, m_guiFilename.toASCIIString(), nullptr);
|
||||
gtk_builder_connect_signals(interface, nullptr);
|
||||
|
||||
GtkWidget* dialog = GTK_WIDGET(gtk_builder_get_object(interface, "rename"));
|
||||
GtkWidget* name = GTK_WIDGET(gtk_builder_get_object(interface, "rename-entry"));
|
||||
g_object_unref(interface);
|
||||
|
||||
gtk_entry_set_text(GTK_ENTRY(name), m_initialName.toASCIIString());
|
||||
|
||||
bool finished = false;
|
||||
bool res = false;
|
||||
while (!finished)
|
||||
{
|
||||
const gint valid = gtk_dialog_run(GTK_DIALOG(dialog));
|
||||
if (valid == GTK_RESPONSE_APPLY)
|
||||
{
|
||||
m_result = gtk_entry_get_text(GTK_ENTRY(name));
|
||||
finished = true;
|
||||
res = true;
|
||||
}
|
||||
else if (valid == 1) { gtk_entry_set_text(GTK_ENTRY(name), m_defaultName.toASCIIString()); } // default
|
||||
else if (valid == 2) { gtk_entry_set_text(GTK_ENTRY(name), m_initialName.toASCIIString()); } // revert
|
||||
else
|
||||
{
|
||||
finished = true;
|
||||
res = false;
|
||||
}
|
||||
}
|
||||
|
||||
gtk_widget_destroy(dialog);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "ovd_base.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
class CRenameDialog final
|
||||
{
|
||||
public:
|
||||
|
||||
CRenameDialog(const Kernel::IKernelContext& ctx, const CString& initialName, const CString& defaultName, const char* guiFilename)
|
||||
: m_kernelCtx(ctx), m_initialName(initialName), m_defaultName(defaultName), m_result(initialName), m_guiFilename(guiFilename) { }
|
||||
|
||||
~CRenameDialog() = default;
|
||||
|
||||
bool run();
|
||||
CString getResult() const { return m_result; }
|
||||
|
||||
protected:
|
||||
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
CString m_initialName;
|
||||
CString m_defaultName;
|
||||
CString m_result;
|
||||
CString m_guiFilename;
|
||||
|
||||
private:
|
||||
CRenameDialog() = delete;
|
||||
};
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+190
@@ -0,0 +1,190 @@
|
||||
#include "ovdCScenarioStateStack.h"
|
||||
|
||||
#include "ovdCInterfacedScenario.h"
|
||||
#include <zlib.h>
|
||||
#include <ovp_global_defines.h>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
CScenarioStateStack::CScenarioStateStack(const Kernel::IKernelContext& ctx, CInterfacedScenario& interfacedScenario, Kernel::IScenario& scenario)
|
||||
: m_kernelCtx(ctx), m_interfacedScenario(interfacedScenario), m_scenario(scenario)
|
||||
{
|
||||
m_currentState = m_states.begin();
|
||||
m_nMaximumState = size_t(m_kernelCtx.getConfigurationManager().expandAsUInteger("${Designer_UndoRedoStackSize}", 64));
|
||||
}
|
||||
|
||||
bool CScenarioStateStack::undo()
|
||||
{
|
||||
auto it = m_currentState;
|
||||
if (it == m_states.begin()) { return false; }
|
||||
|
||||
--it;
|
||||
m_currentState = it;
|
||||
|
||||
return this->restoreState(**m_currentState);
|
||||
}
|
||||
|
||||
bool CScenarioStateStack::isRedoPossible()
|
||||
{
|
||||
auto it = m_currentState;
|
||||
if (it == m_states.end()) { return false; }
|
||||
|
||||
++it;
|
||||
return it != m_states.end();
|
||||
}
|
||||
|
||||
bool CScenarioStateStack::redo()
|
||||
{
|
||||
auto it = m_currentState;
|
||||
if (it == m_states.end()) { return false; }
|
||||
|
||||
++it;
|
||||
if (it == m_states.end()) { return false; }
|
||||
|
||||
m_currentState = it;
|
||||
|
||||
return this->restoreState(**m_currentState);
|
||||
}
|
||||
|
||||
bool CScenarioStateStack::snapshot()
|
||||
{
|
||||
CMemoryBuffer* newState = new CMemoryBuffer();
|
||||
|
||||
if (!this->dumpState(*newState))
|
||||
{
|
||||
delete newState;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_currentState != m_states.end()) { ++m_currentState; }
|
||||
|
||||
while (m_currentState != m_states.end())
|
||||
{
|
||||
delete*m_currentState;
|
||||
m_currentState = m_states.erase(m_currentState);
|
||||
}
|
||||
|
||||
if (m_nMaximumState != 0) { while (m_states.size() >= m_nMaximumState) { m_states.erase(m_states.begin()); } }
|
||||
|
||||
m_states.push_back(newState);
|
||||
|
||||
m_currentState = m_states.end();
|
||||
--m_currentState;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CScenarioStateStack::restoreState(const IMemoryBuffer& state)
|
||||
{
|
||||
CMemoryBuffer uncompressedBuffer;
|
||||
|
||||
if (state.getSize() == 0) { return false; }
|
||||
|
||||
const CIdentifier importerID = m_kernelCtx.getAlgorithmManager().createAlgorithm(OVP_GD_ClassId_Algorithm_XMLScenarioImporter);
|
||||
if (importerID == CIdentifier::undefined()) { return false; }
|
||||
|
||||
Kernel::IAlgorithmProxy* importer = &m_kernelCtx.getAlgorithmManager().getAlgorithm(importerID);
|
||||
if (!importer) { return false; }
|
||||
|
||||
const uLongf srcSize = uLongf(state.getSize()) - sizeof(uLongf);
|
||||
Bytef* srcBuffer = const_cast<Bytef*>(state.getDirectPointer());
|
||||
|
||||
uLongf dstSize = *(uLongf*)(state.getDirectPointer() + state.getSize() - sizeof(uLongf));
|
||||
uncompressedBuffer.setSize(dstSize, true);
|
||||
Bytef* dstBuffer = static_cast<Bytef*>(uncompressedBuffer.getDirectPointer());
|
||||
|
||||
if (uncompress(dstBuffer, &dstSize, srcBuffer, srcSize) != Z_OK) { return false; }
|
||||
|
||||
importer->initialize();
|
||||
|
||||
Kernel::TParameterHandler<const IMemoryBuffer*> ip_buffer(importer->getInputParameter(OV_Algorithm_ScenarioImporter_InputParameterId_MemoryBuffer));
|
||||
Kernel::TParameterHandler<Kernel::IScenario*> op_scenario(importer->getOutputParameter(OV_Algorithm_ScenarioImporter_OutputParameterId_Scenario));
|
||||
|
||||
m_scenario.clear();
|
||||
|
||||
ip_buffer = &uncompressedBuffer;
|
||||
op_scenario = &m_scenario;
|
||||
|
||||
importer->process();
|
||||
importer->uninitialize();
|
||||
m_kernelCtx.getAlgorithmManager().releaseAlgorithm(*importer);
|
||||
|
||||
// Find the VisualizationTree metadata
|
||||
Kernel::IMetadata* treeMetadata = nullptr;
|
||||
CIdentifier metadataID = CIdentifier::undefined();
|
||||
while ((metadataID = m_scenario.getNextMetadataIdentifier(metadataID)) != CIdentifier::undefined())
|
||||
{
|
||||
treeMetadata = m_scenario.getMetadataDetails(metadataID);
|
||||
if (treeMetadata && treeMetadata->getType() == OVVIZ_MetadataIdentifier_VisualizationTree) { break; }
|
||||
}
|
||||
|
||||
VisualizationToolkit::IVisualizationTree* visualizationTree = m_interfacedScenario.m_Tree;
|
||||
if (treeMetadata && visualizationTree) { visualizationTree->deserialize(treeMetadata->getData()); }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CScenarioStateStack::dumpState(IMemoryBuffer& state)
|
||||
{
|
||||
CMemoryBuffer uncompressedBuffer;
|
||||
CMemoryBuffer compressedBuffer;
|
||||
|
||||
// Update the scenario metadata according to the current state of the visualization tree
|
||||
|
||||
// Remove all VisualizationTree type metadata
|
||||
CIdentifier oldTreeMetadataID = CIdentifier::undefined();
|
||||
CIdentifier metadataID = CIdentifier::undefined();
|
||||
while ((metadataID = m_scenario.getNextMetadataIdentifier(metadataID)) != CIdentifier::undefined())
|
||||
{
|
||||
if (m_scenario.getMetadataDetails(metadataID)->getType() == OVVIZ_MetadataIdentifier_VisualizationTree)
|
||||
{
|
||||
oldTreeMetadataID = metadataID;
|
||||
m_scenario.removeMetadata(metadataID);
|
||||
metadataID = CIdentifier::undefined();
|
||||
}
|
||||
}
|
||||
|
||||
// Insert new metadata
|
||||
m_scenario.addMetadata(metadataID, oldTreeMetadataID);
|
||||
m_scenario.getMetadataDetails(metadataID)->setType(OVVIZ_MetadataIdentifier_VisualizationTree);
|
||||
m_scenario.getMetadataDetails(metadataID)->setData(m_interfacedScenario.m_Tree->serialize());
|
||||
|
||||
const CIdentifier exporterID = m_kernelCtx.getAlgorithmManager().createAlgorithm(OVP_GD_ClassId_Algorithm_XMLScenarioExporter);
|
||||
|
||||
if (exporterID == CIdentifier::undefined()) { return false; }
|
||||
|
||||
Kernel::IAlgorithmProxy* exporter = &m_kernelCtx.getAlgorithmManager().getAlgorithm(exporterID);
|
||||
if (!exporter) { return false; }
|
||||
|
||||
exporter->initialize();
|
||||
|
||||
Kernel::TParameterHandler<const Kernel::IScenario*> ip_scenario(exporter->getInputParameter(OV_Algorithm_ScenarioExporter_InputParameterId_Scenario));
|
||||
Kernel::TParameterHandler<IMemoryBuffer*> op_buffer(exporter->getOutputParameter(OV_Algorithm_ScenarioExporter_OutputParameterId_MemoryBuffer));
|
||||
|
||||
ip_scenario = &m_scenario;
|
||||
op_buffer = &uncompressedBuffer;
|
||||
|
||||
exporter->process();
|
||||
exporter->uninitialize();
|
||||
m_kernelCtx.getAlgorithmManager().releaseAlgorithm(*exporter);
|
||||
|
||||
uLongf srcSize = uLongf(uncompressedBuffer.getSize());
|
||||
Bytef* srcBuffer = static_cast<Bytef*>(uncompressedBuffer.getDirectPointer());
|
||||
|
||||
compressedBuffer.setSize(12 + uint64_t(srcSize * 1.1), true);
|
||||
|
||||
uLongf dstSize = uLongf(compressedBuffer.getSize());
|
||||
Bytef* dstBuffer = static_cast<Bytef*>(compressedBuffer.getDirectPointer());
|
||||
|
||||
if (compress(dstBuffer, &dstSize, srcBuffer, srcSize) != Z_OK) { return false; }
|
||||
|
||||
state.setSize(0, true);
|
||||
state.append(compressedBuffer.getDirectPointer(), dstSize);
|
||||
state.append(reinterpret_cast<const uint8_t*>(&srcSize), sizeof(uLongf));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "ovd_base.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
class CInterfacedScenario;
|
||||
|
||||
class CScenarioStateStack
|
||||
{
|
||||
public:
|
||||
|
||||
CScenarioStateStack(const Kernel::IKernelContext& ctx, CInterfacedScenario& interfacedScenario, Kernel::IScenario& scenario);
|
||||
virtual ~CScenarioStateStack() { for (auto& state : m_states) { delete state; } }
|
||||
|
||||
virtual bool isUndoPossible() { return m_currentState != m_states.begin(); }
|
||||
virtual bool undo();
|
||||
virtual bool isRedoPossible();
|
||||
virtual bool redo();
|
||||
void dropLastState() { m_states.pop_back(); }
|
||||
|
||||
virtual bool snapshot();
|
||||
|
||||
private:
|
||||
|
||||
virtual bool restoreState(const IMemoryBuffer& state);
|
||||
virtual bool dumpState(IMemoryBuffer& state);
|
||||
|
||||
protected:
|
||||
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
CInterfacedScenario& m_interfacedScenario;
|
||||
Kernel::IScenario& m_scenario;
|
||||
|
||||
std::list<CMemoryBuffer*> m_states;
|
||||
std::list<CMemoryBuffer*>::iterator m_currentState;
|
||||
|
||||
size_t m_nMaximumState = 0;
|
||||
};
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+805
@@ -0,0 +1,805 @@
|
||||
#include "ovdCSettingCollectionHelper.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <visualization-toolkit/ovvizColorGradient.h>
|
||||
// ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- -----------
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double percent;
|
||||
GdkColor color;
|
||||
GtkColorButton* colorButton;
|
||||
GtkSpinButton* spinButton;
|
||||
} color_gradient_node_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
std::string guiFilename;
|
||||
GtkWidget* dialog;
|
||||
GtkWidget* container;
|
||||
GtkWidget* drawingArea;
|
||||
std::vector<color_gradient_node_t> colorGradient;
|
||||
std::map<GtkColorButton*, uint32_t> colorButtons;
|
||||
std::map<GtkSpinButton*, uint32_t> spinButtons;
|
||||
} color_gradient_t;
|
||||
|
||||
static void gradients2Matrix(const std::vector<color_gradient_node_t>& in, CMatrix& out)
|
||||
{
|
||||
out.resize(4, in.size());
|
||||
size_t i = 0;
|
||||
for (const auto& color : in)
|
||||
{
|
||||
out[i++] = color.percent;
|
||||
out[i++] = color.color.red / 655.35; // * 100.0 / 65535.0;
|
||||
out[i++] = color.color.green / 655.35; // * 100.0 / 65535.0;
|
||||
out[i++] = color.color.blue / 655.35; // * 100.0 / 65535.0;
|
||||
}
|
||||
}
|
||||
|
||||
static void CollectWidgetCB(GtkWidget* widget, gpointer data) { static_cast<std::vector<GtkWidget*>*>(data)->push_back(widget); }
|
||||
static void RemoveWidgetCB(GtkWidget* widget, gpointer data) { gtk_container_remove(GTK_CONTAINER(data), widget); }
|
||||
|
||||
// ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- -----------
|
||||
|
||||
static void OnEntrySettingBOOLEdited(GtkEntry* entry, gpointer /*data*/)
|
||||
{
|
||||
std::vector<GtkWidget*> widgets;
|
||||
gtk_container_foreach(GTK_CONTAINER(gtk_widget_get_parent(GTK_WIDGET(entry))), CollectWidgetCB, &widgets);
|
||||
GtkToggleButton* widget = GTK_TOGGLE_BUTTON(widgets[1]);
|
||||
|
||||
const std::string value = gtk_entry_get_text(entry);
|
||||
if (value == "true")
|
||||
{
|
||||
gtk_toggle_button_set_active(widget, true);
|
||||
gtk_toggle_button_set_inconsistent(widget, false);
|
||||
}
|
||||
else if (value == "false")
|
||||
{
|
||||
gtk_toggle_button_set_active(widget, false);
|
||||
gtk_toggle_button_set_inconsistent(widget, false);
|
||||
}
|
||||
else { gtk_toggle_button_set_inconsistent(widget, true); }
|
||||
}
|
||||
|
||||
static void OnCheckbuttonSettingBOOLPressed(GtkToggleButton* button, gpointer /*data*/)
|
||||
{
|
||||
std::vector<GtkWidget*> widgets;
|
||||
gtk_container_foreach(GTK_CONTAINER(gtk_widget_get_parent(GTK_WIDGET(button))), CollectWidgetCB, &widgets);
|
||||
GtkEntry* widget = GTK_ENTRY(widgets[0]);
|
||||
|
||||
if (gtk_toggle_button_get_active(button)) { gtk_entry_set_text(widget, "true"); }
|
||||
else { gtk_entry_set_text(widget, "false"); }
|
||||
gtk_toggle_button_set_inconsistent(button, false);
|
||||
}
|
||||
|
||||
static void OnButtonSettingIntegerPressed(GtkButton* button, gpointer data, const gint iOffset)
|
||||
{
|
||||
const Kernel::IKernelContext& ctx = static_cast<CSettingCollectionHelper*>(data)->m_KernelCtx;
|
||||
|
||||
std::vector<GtkWidget*> widgets;
|
||||
gtk_container_foreach(GTK_CONTAINER(gtk_widget_get_parent(GTK_WIDGET(button))), CollectWidgetCB, &widgets);
|
||||
GtkEntry* widget = GTK_ENTRY(widgets[0]);
|
||||
|
||||
const int64_t value = ctx.getConfigurationManager().expandAsInteger(gtk_entry_get_text(widget), 0) + iOffset;
|
||||
const std::string res = std::to_string(value);
|
||||
gtk_entry_set_text(widget, res.c_str());
|
||||
}
|
||||
|
||||
static void OnButtonSettingIntegerUpPressed(GtkButton* button, gpointer data) { OnButtonSettingIntegerPressed(button, data, 1); }
|
||||
static void OnButtonSettingIntegerDownPressed(GtkButton* button, gpointer data) { OnButtonSettingIntegerPressed(button, data, -1); }
|
||||
|
||||
static void OnButtonSettingFloatPressed(GtkButton* button, gpointer data, const gdouble offset)
|
||||
{
|
||||
const Kernel::IKernelContext& ctx = static_cast<CSettingCollectionHelper*>(data)->m_KernelCtx;
|
||||
|
||||
std::vector<GtkWidget*> widgets;
|
||||
gtk_container_foreach(GTK_CONTAINER(gtk_widget_get_parent(GTK_WIDGET(button))), CollectWidgetCB, &widgets);
|
||||
GtkEntry* widget = GTK_ENTRY(widgets[0]);
|
||||
|
||||
double value = ctx.getConfigurationManager().expandAsFloat(gtk_entry_get_text(widget), 0);
|
||||
value += offset;
|
||||
const std::string res = std::to_string(value);
|
||||
gtk_entry_set_text(widget, res.c_str());
|
||||
}
|
||||
|
||||
static void OnButtonSettingFloatUpPressed(GtkButton* button, gpointer data) { OnButtonSettingFloatPressed(button, data, 1); }
|
||||
static void OnButtonSettingFloatDownPressed(GtkButton* button, gpointer data) { OnButtonSettingFloatPressed(button, data, -1); }
|
||||
|
||||
static void OnButtonSettingFilenameBrowsePressed(GtkButton* button, gpointer data)
|
||||
{
|
||||
const Kernel::IKernelContext& ctx = static_cast<CSettingCollectionHelper*>(data)->m_KernelCtx;
|
||||
|
||||
std::vector<GtkWidget*> widgets;
|
||||
gtk_container_foreach(GTK_CONTAINER(gtk_widget_get_parent(GTK_WIDGET(button))), CollectWidgetCB, &widgets);
|
||||
GtkEntry* widget = GTK_ENTRY(widgets[0]);
|
||||
|
||||
GtkWidget* widgetDialogOpen = gtk_file_chooser_dialog_new("Select file to open...", nullptr, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL,
|
||||
GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, nullptr);
|
||||
|
||||
const CString filename = ctx.getConfigurationManager().expand(gtk_entry_get_text(widget));
|
||||
if (g_path_is_absolute(filename.toASCIIString())) { gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(widgetDialogOpen), filename.toASCIIString()); }
|
||||
else
|
||||
{
|
||||
char* fullPath = g_build_filename(g_get_current_dir(), filename.toASCIIString(), nullptr);
|
||||
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(widgetDialogOpen), fullPath);
|
||||
g_free(fullPath);
|
||||
}
|
||||
|
||||
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(widgetDialogOpen), false);
|
||||
|
||||
if (gtk_dialog_run(GTK_DIALOG(widgetDialogOpen)) == GTK_RESPONSE_ACCEPT)
|
||||
{
|
||||
char* name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widgetDialogOpen));
|
||||
char* backslash;
|
||||
while ((backslash = strchr(name, '\\')) != nullptr) { *backslash = '/'; }
|
||||
gtk_entry_set_text(widget, name);
|
||||
g_free(name);
|
||||
}
|
||||
gtk_widget_destroy(widgetDialogOpen);
|
||||
}
|
||||
|
||||
static void OnButtonSettingFoldernameBrowsePressed(GtkButton* button, gpointer data)
|
||||
{
|
||||
const Kernel::IKernelContext& ctx = static_cast<CSettingCollectionHelper*>(data)->m_KernelCtx;
|
||||
|
||||
std::vector<GtkWidget*> widgets;
|
||||
gtk_container_foreach(GTK_CONTAINER(gtk_widget_get_parent(GTK_WIDGET(button))), CollectWidgetCB, &widgets);
|
||||
GtkEntry* widget = GTK_ENTRY(widgets[0]);
|
||||
|
||||
GtkWidget* widgetDialogOpen = gtk_file_chooser_dialog_new("Select folder to open...", nullptr, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, nullptr);
|
||||
|
||||
const CString filename = ctx.getConfigurationManager().expand(gtk_entry_get_text(widget));
|
||||
if (g_path_is_absolute(filename.toASCIIString())) { gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(widgetDialogOpen), filename.toASCIIString()); }
|
||||
else
|
||||
{
|
||||
char* fullPath = g_build_filename(g_get_current_dir(), filename.toASCIIString(), nullptr);
|
||||
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(widgetDialogOpen), fullPath);
|
||||
g_free(fullPath);
|
||||
}
|
||||
|
||||
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(widgetDialogOpen), false);
|
||||
|
||||
if (gtk_dialog_run(GTK_DIALOG(widgetDialogOpen)) == GTK_RESPONSE_ACCEPT)
|
||||
{
|
||||
char* name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widgetDialogOpen));
|
||||
char* backslash;
|
||||
while ((backslash = strchr(name, '\\')) != nullptr) { *backslash = '/'; }
|
||||
gtk_entry_set_text(widget, name);
|
||||
g_free(name);
|
||||
}
|
||||
gtk_widget_destroy(widgetDialogOpen);
|
||||
}
|
||||
// ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- -----------
|
||||
|
||||
static void OnButtonSettingScriptEditPressed(GtkButton* button, gpointer data)
|
||||
{
|
||||
const Kernel::IKernelContext& ctx = static_cast<CSettingCollectionHelper*>(data)->m_KernelCtx;
|
||||
|
||||
std::vector<GtkWidget*> widgets;
|
||||
gtk_container_foreach(GTK_CONTAINER(gtk_widget_get_parent(GTK_WIDGET(button))), CollectWidgetCB, &widgets);
|
||||
GtkEntry* widget = GTK_ENTRY(widgets[0]);
|
||||
|
||||
const CString name = ctx.getConfigurationManager().expand(gtk_entry_get_text(widget));
|
||||
const CString cmd = ctx.getConfigurationManager().expand("${Designer_ScriptEditorCommand}");
|
||||
|
||||
if (cmd != CString(""))
|
||||
{
|
||||
CString fullCmd = cmd + CString(" \"") + name + CString("\"");
|
||||
#if defined TARGET_OS_Windows
|
||||
fullCmd = "START " + fullCmd;
|
||||
#elif defined TARGET_OS_Linux || defined TARGET_OS_MacOS
|
||||
fullCmd = fullCmd + " &";
|
||||
#else
|
||||
#endif
|
||||
if (system(fullCmd.toASCIIString()) < 0) { ctx.getLogManager() << Kernel::LogLevel_Warning << "Could not run command " << fullCmd << "\n"; }
|
||||
}
|
||||
}
|
||||
|
||||
// ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- -----------
|
||||
|
||||
static void OnButtonSettingColorChoosePressed(GtkColorButton* button, gpointer /*data*/)
|
||||
{
|
||||
std::vector<GtkWidget*> widgets;
|
||||
gtk_container_foreach(GTK_CONTAINER(gtk_widget_get_parent(GTK_WIDGET(button))), CollectWidgetCB, &widgets);
|
||||
GtkEntry* widget = GTK_ENTRY(widgets[0]);
|
||||
GdkColor color;
|
||||
gtk_color_button_get_color(button, &color);
|
||||
|
||||
const std::string res = std::to_string((color.red * 100) / 65535) + "," + std::to_string((color.green * 100) / 65535) + ","
|
||||
+ std::to_string((color.blue * 100) / 65535);
|
||||
gtk_entry_set_text(widget, res.c_str());
|
||||
}
|
||||
|
||||
// ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- -----------
|
||||
|
||||
static void OnGTKWidgetDestroy(GtkWidget* widget, gpointer /*data*/) { gtk_widget_destroy(widget); }
|
||||
static void OnInitializeColorGradient(GtkWidget* widget, gpointer data);
|
||||
|
||||
static void OnRefreshColorGradient(GtkWidget* /*widget*/, GdkEventExpose* /*event*/, gpointer data)
|
||||
{
|
||||
auto* userData = static_cast<color_gradient_t*>(data);
|
||||
|
||||
const size_t steps = 100;
|
||||
gint sizex = 0;
|
||||
gint sizey = 0;
|
||||
gdk_drawable_get_size(userData->drawingArea->window, &sizex, &sizey);
|
||||
|
||||
CMatrix gradient;
|
||||
gradients2Matrix(userData->colorGradient, gradient);
|
||||
|
||||
CMatrix interpolated;
|
||||
VisualizationToolkit::ColorGradient::interpolate(interpolated, gradient, steps);
|
||||
|
||||
GdkGC* gc = gdk_gc_new(userData->drawingArea->window);
|
||||
GdkColor color;
|
||||
|
||||
for (size_t i = 0; i < steps; ++i)
|
||||
{
|
||||
color.red = guint(interpolated[i * 4 + 1] * 655.35);
|
||||
color.green = guint(interpolated[i * 4 + 2] * 655.35);
|
||||
color.blue = guint(interpolated[i * 4 + 3] * 655.35);
|
||||
gdk_gc_set_rgb_fg_color(gc, &color);
|
||||
gdk_draw_rectangle(userData->drawingArea->window, gc, TRUE, (sizex * i) / steps, 0, (sizex * (i + 1)) / steps, sizey);
|
||||
}
|
||||
g_object_unref(gc);
|
||||
}
|
||||
|
||||
static void OnColorGradientSpinButtonValueChanged(GtkSpinButton* button, gpointer data)
|
||||
{
|
||||
auto* userData = static_cast<color_gradient_t*>(data);
|
||||
|
||||
gtk_spin_button_update(button);
|
||||
|
||||
const size_t i = userData->spinButtons[button];
|
||||
GtkSpinButton* prevSpin = (i > 0 ? userData->colorGradient[i - 1].spinButton : nullptr);
|
||||
GtkSpinButton* nextSpin = (i < userData->colorGradient.size() - 1 ? userData->colorGradient[i + 1].spinButton : nullptr);
|
||||
if (!prevSpin) { gtk_spin_button_set_value(button, 0); }
|
||||
if (!nextSpin) { gtk_spin_button_set_value(button, 100); }
|
||||
if (prevSpin && gtk_spin_button_get_value(button) < gtk_spin_button_get_value(prevSpin))
|
||||
{
|
||||
gtk_spin_button_set_value(button, gtk_spin_button_get_value(prevSpin));
|
||||
}
|
||||
if (nextSpin && gtk_spin_button_get_value(button) > gtk_spin_button_get_value(nextSpin))
|
||||
{
|
||||
gtk_spin_button_set_value(button, gtk_spin_button_get_value(nextSpin));
|
||||
}
|
||||
|
||||
userData->colorGradient[i].percent = gtk_spin_button_get_value(button);
|
||||
|
||||
OnRefreshColorGradient(nullptr, nullptr, data);
|
||||
}
|
||||
|
||||
static void OnColorGradientColorButtonPressed(GtkColorButton* button, gpointer data)
|
||||
{
|
||||
auto* userData = static_cast<color_gradient_t*>(data);
|
||||
|
||||
GdkColor color;
|
||||
gtk_color_button_get_color(button, &color);
|
||||
|
||||
userData->colorGradient[userData->colorButtons[button]].color = color;
|
||||
|
||||
OnRefreshColorGradient(nullptr, nullptr, data);
|
||||
}
|
||||
|
||||
static void OnInitializeColorGradient(GtkWidget* /*widget*/, gpointer data)
|
||||
{
|
||||
auto* userData = static_cast<color_gradient_t*>(data);
|
||||
|
||||
gtk_widget_hide(userData->container);
|
||||
|
||||
gtk_container_foreach(GTK_CONTAINER(userData->container), OnGTKWidgetDestroy, nullptr);
|
||||
|
||||
const size_t count = userData->colorGradient.size();
|
||||
userData->colorButtons.clear();
|
||||
userData->spinButtons.clear();
|
||||
size_t i = 0;
|
||||
for (auto& it : userData->colorGradient)
|
||||
{
|
||||
GtkBuilder* builder = gtk_builder_new(); // glade_xml_new(userData->guiFilename.c_str(), "setting_editor-color_gradient-hbox", nullptr);
|
||||
gtk_builder_add_from_file(builder, userData->guiFilename.c_str(), nullptr);
|
||||
gtk_builder_connect_signals(builder, nullptr);
|
||||
|
||||
GtkWidget* widget = GTK_WIDGET(gtk_builder_get_object(builder, "setting_editor-color_gradient-hbox"));
|
||||
|
||||
it.colorButton = GTK_COLOR_BUTTON(gtk_builder_get_object(builder, "setting_editor-color_gradient-colorbutton"));
|
||||
it.spinButton = GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "setting_editor-color_gradient-spinbutton"));
|
||||
|
||||
gtk_color_button_set_color(it.colorButton, &it.color);
|
||||
gtk_spin_button_set_value(it.spinButton, it.percent);
|
||||
|
||||
g_signal_connect(G_OBJECT(it.colorButton), "color-set", G_CALLBACK(OnColorGradientColorButtonPressed), userData);
|
||||
g_signal_connect(G_OBJECT(it.spinButton), "value-changed", G_CALLBACK(OnColorGradientSpinButtonValueChanged), userData);
|
||||
|
||||
g_object_ref(widget);
|
||||
gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(widget)), widget);
|
||||
gtk_container_add(GTK_CONTAINER(userData->container), widget);
|
||||
g_object_unref(widget);
|
||||
|
||||
g_object_unref(builder);
|
||||
|
||||
userData->colorButtons[it.colorButton] = i;
|
||||
userData->spinButtons[it.spinButton] = i;
|
||||
i++;
|
||||
}
|
||||
|
||||
gtk_spin_button_set_value(userData->colorGradient[0].spinButton, 0);
|
||||
gtk_spin_button_set_value(userData->colorGradient[count - 1].spinButton, 100);
|
||||
|
||||
gtk_widget_show(userData->container);
|
||||
}
|
||||
|
||||
static void OnButtonColorGradientAddPressed(GtkButton* /*button*/, gpointer data)
|
||||
{
|
||||
auto* userData = static_cast<color_gradient_t*>(data);
|
||||
userData->colorGradient.resize(userData->colorGradient.size() + 1);
|
||||
userData->colorGradient[userData->colorGradient.size() - 1].percent = 100;
|
||||
OnInitializeColorGradient(nullptr, data);
|
||||
OnRefreshColorGradient(nullptr, nullptr, data);
|
||||
}
|
||||
|
||||
static void OnButtonColorGradientRemovePressed(GtkButton* /*button*/, gpointer data)
|
||||
{
|
||||
auto* userData = static_cast<color_gradient_t*>(data);
|
||||
if (userData->colorGradient.size() > 2)
|
||||
{
|
||||
userData->colorGradient.resize(userData->colorGradient.size() - 1);
|
||||
userData->colorGradient[userData->colorGradient.size() - 1].percent = 100;
|
||||
OnInitializeColorGradient(nullptr, data);
|
||||
OnRefreshColorGradient(nullptr, nullptr, data);
|
||||
}
|
||||
}
|
||||
|
||||
static void OnButtonSettingColorGradientConfigurePressed(GtkButton* button, gpointer data)
|
||||
{
|
||||
color_gradient_t userData;
|
||||
|
||||
userData.guiFilename = static_cast<CSettingCollectionHelper*>(data)->m_GUIFilename.toASCIIString();
|
||||
|
||||
std::vector<GtkWidget*> widgets;
|
||||
gtk_container_foreach(GTK_CONTAINER(gtk_widget_get_parent(GTK_WIDGET(button))), CollectWidgetCB, &widgets);
|
||||
GtkEntry* widget = GTK_ENTRY(widgets[0]);
|
||||
|
||||
GtkBuilder* builder = gtk_builder_new(); // glade_xml_new(userData.guiFilename.c_str(), "setting_editor-color_gradient-dialog", nullptr);
|
||||
gtk_builder_add_from_file(builder, userData.guiFilename.c_str(), nullptr);
|
||||
gtk_builder_connect_signals(builder, nullptr);
|
||||
|
||||
userData.dialog = GTK_WIDGET(gtk_builder_get_object(builder, "setting_editor-color_gradient-dialog"));
|
||||
|
||||
const CString sInitialGradient = static_cast<CSettingCollectionHelper*>(data)->m_KernelCtx.getConfigurationManager().expand(gtk_entry_get_text(widget));
|
||||
CMatrix initialGradient;
|
||||
|
||||
VisualizationToolkit::ColorGradient::parse(initialGradient, sInitialGradient);
|
||||
|
||||
userData.colorGradient.resize(initialGradient.getDimensionSize(1) > 2 ? initialGradient.getDimensionSize(1) : 2);
|
||||
for (size_t i = 0; i < initialGradient.getDimensionSize(1); ++i)
|
||||
{
|
||||
userData.colorGradient[i].percent = initialGradient[i * 4];
|
||||
userData.colorGradient[i].color.red = guint(initialGradient[i * 4 + 1] * 655.35);
|
||||
userData.colorGradient[i].color.green = guint(initialGradient[i * 4 + 2] * 655.35);
|
||||
userData.colorGradient[i].color.blue = guint(initialGradient[i * 4 + 3] * 655.35);
|
||||
}
|
||||
|
||||
userData.container = GTK_WIDGET(gtk_builder_get_object(builder, "setting_editor-color_gradient-vbox"));
|
||||
userData.drawingArea = GTK_WIDGET(gtk_builder_get_object(builder, "setting_editor-color_gradient-drawingarea"));
|
||||
|
||||
g_signal_connect(G_OBJECT(userData.dialog), "show", G_CALLBACK(OnInitializeColorGradient), &userData);
|
||||
g_signal_connect(G_OBJECT(userData.drawingArea), "expose_event", G_CALLBACK(OnRefreshColorGradient), &userData);
|
||||
g_signal_connect(G_OBJECT(gtk_builder_get_object(builder, "setting_editor-color_gradient-add_button")), "pressed",
|
||||
G_CALLBACK(OnButtonColorGradientAddPressed), &userData);
|
||||
g_signal_connect(G_OBJECT(gtk_builder_get_object(builder, "setting_editor-color_gradient-remove_button")), "pressed",
|
||||
G_CALLBACK(OnButtonColorGradientRemovePressed), &userData);
|
||||
|
||||
if (gtk_dialog_run(GTK_DIALOG(userData.dialog)) == GTK_RESPONSE_APPLY)
|
||||
{
|
||||
CString str;
|
||||
CMatrix gradient;
|
||||
gradients2Matrix(userData.colorGradient, gradient);
|
||||
|
||||
VisualizationToolkit::ColorGradient::format(str, gradient);
|
||||
gtk_entry_set_text(widget, str.toASCIIString());
|
||||
}
|
||||
|
||||
gtk_widget_destroy(userData.dialog);
|
||||
g_object_unref(builder);
|
||||
}
|
||||
|
||||
// ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- -----------
|
||||
|
||||
CString CSettingCollectionHelper::getSettingWidgetName(const CIdentifier& typeID) const
|
||||
{
|
||||
if (typeID == OV_TypeId_Boolean) { return "settings_collection-hbox_setting_boolean"; }
|
||||
if (typeID == OV_TypeId_Integer) { return "settings_collection-hbox_setting_integer"; }
|
||||
if (typeID == OV_TypeId_Float) { return "settings_collection-hbox_setting_float"; }
|
||||
if (typeID == OV_TypeId_String) { return "settings_collection-entry_setting_string"; }
|
||||
if (typeID == OV_TypeId_Filename) { return "settings_collection-hbox_setting_filename"; }
|
||||
if (typeID == OV_TypeId_Foldername) { return "settings_collection-hbox_setting_foldername"; }
|
||||
if (typeID == OV_TypeId_Script) { return "settings_collection-hbox_setting_script"; }
|
||||
if (typeID == OV_TypeId_Color) { return "settings_collection-hbox_setting_color"; }
|
||||
if (typeID == OV_TypeId_ColorGradient) { return "settings_collection-hbox_setting_color_gradient"; }
|
||||
if (m_KernelCtx.getTypeManager().isEnumeration(typeID)) { return "settings_collection-comboboxentry_setting_enumeration"; }
|
||||
if (m_KernelCtx.getTypeManager().isBitMask(typeID)) { return "settings_collection-table_setting_bitmask"; }
|
||||
return "settings_collection-entry_setting_string";
|
||||
}
|
||||
|
||||
// ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- -----------
|
||||
|
||||
CString CSettingCollectionHelper::getSettingEntryWidgetName(const CIdentifier& typeID) const
|
||||
{
|
||||
if (typeID == OV_TypeId_Boolean) { return "settings_collection-entry_setting_boolean"; }
|
||||
if (typeID == OV_TypeId_Integer) { return "settings_collection-entry_setting_integer_string"; }
|
||||
if (typeID == OV_TypeId_Float) { return "settings_collection-entry_setting_float_string"; }
|
||||
if (typeID == OV_TypeId_String) { return "settings_collection-entry_setting_string"; }
|
||||
if (typeID == OV_TypeId_Filename) { return "settings_collection-entry_setting_filename_string"; }
|
||||
if (typeID == OV_TypeId_Foldername) { return "settings_collection-entry_setting_foldername_string"; }
|
||||
if (typeID == OV_TypeId_Script) { return "settings_collection-entry_setting_script_string"; }
|
||||
if (typeID == OV_TypeId_Color) { return "settings_collection-hbox_setting_color_string"; }
|
||||
if (typeID == OV_TypeId_ColorGradient) { return "settings_collection-hbox_setting_color_gradient_string"; }
|
||||
if (m_KernelCtx.getTypeManager().isEnumeration(typeID)) { return "settings_collection-comboboxentry_setting_enumeration"; }
|
||||
if (m_KernelCtx.getTypeManager().isBitMask(typeID)) { return "settings_collection-table_setting_bitmask"; }
|
||||
return "settings_collection-entry_setting_string";
|
||||
}
|
||||
|
||||
// ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- -----------
|
||||
|
||||
CString CSettingCollectionHelper::getValue(const CIdentifier& typeID, GtkWidget* widget) const
|
||||
{
|
||||
if (!widget) { return ""; }
|
||||
if (typeID == OV_TypeId_Boolean) { return getValueBoolean(widget); }
|
||||
if (typeID == OV_TypeId_Integer) { return getValueInteger(widget); }
|
||||
if (typeID == OV_TypeId_Float) { return getValueFloat(widget); }
|
||||
if (typeID == OV_TypeId_String) { return getValueString(widget); }
|
||||
if (typeID == OV_TypeId_Filename) { return getValueFilename(widget); }
|
||||
if (typeID == OV_TypeId_Foldername) { return getValueFoldername(widget); }
|
||||
if (typeID == OV_TypeId_Script) { return getValueScript(widget); }
|
||||
if (typeID == OV_TypeId_Color) { return getValueColor(widget); }
|
||||
if (typeID == OV_TypeId_ColorGradient) { return getValueColorGradient(widget); }
|
||||
if (m_KernelCtx.getTypeManager().isEnumeration(typeID)) { return getValueEnumeration(typeID, widget); }
|
||||
if (m_KernelCtx.getTypeManager().isBitMask(typeID)) { return getValueBitMask(typeID, widget); }
|
||||
return getValueString(widget);
|
||||
}
|
||||
|
||||
CString CSettingCollectionHelper::getValueBoolean(GtkWidget* widget)
|
||||
{
|
||||
std::vector<GtkWidget*> widgets;
|
||||
if (!GTK_IS_CONTAINER(widget)) { return "false"; }
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), CollectWidgetCB, &widgets);
|
||||
if (!GTK_IS_ENTRY(widgets[1])) { return "false"; }
|
||||
GtkEntry* entry = GTK_ENTRY(widgets[1]);
|
||||
return CString(gtk_entry_get_text(entry));
|
||||
}
|
||||
|
||||
CString CSettingCollectionHelper::getValueInteger(GtkWidget* widget)
|
||||
{
|
||||
std::vector<GtkWidget*> widgets;
|
||||
if (!GTK_IS_CONTAINER(widget)) { return "0"; }
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), CollectWidgetCB, &widgets);
|
||||
if (!GTK_IS_ENTRY(widgets[0])) { return "O"; }
|
||||
GtkEntry* entry = GTK_ENTRY(widgets[0]);
|
||||
return CString(gtk_entry_get_text(entry));
|
||||
}
|
||||
|
||||
CString CSettingCollectionHelper::getValueFloat(GtkWidget* widget)
|
||||
{
|
||||
std::vector<GtkWidget*> widgets;
|
||||
if (!GTK_IS_CONTAINER(widget)) { return "0"; }
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), CollectWidgetCB, &widgets);
|
||||
if (!GTK_IS_ENTRY(widgets[0])) { return "O"; }
|
||||
GtkEntry* entry = GTK_ENTRY(widgets[0]);
|
||||
return CString(gtk_entry_get_text(entry));
|
||||
}
|
||||
|
||||
CString CSettingCollectionHelper::getValueString(GtkWidget* widget)
|
||||
{
|
||||
if (!GTK_IS_ENTRY(widget)) { return ""; }
|
||||
GtkEntry* entry = GTK_ENTRY(widget);
|
||||
return CString(gtk_entry_get_text(entry));
|
||||
}
|
||||
|
||||
CString CSettingCollectionHelper::getValueFilename(GtkWidget* widget)
|
||||
{
|
||||
std::vector<GtkWidget*> widgets;
|
||||
if (!GTK_IS_CONTAINER(widget)) { return ""; }
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), CollectWidgetCB, &widgets);
|
||||
if (!GTK_IS_ENTRY(widgets[0])) { return ""; }
|
||||
GtkEntry* entry = GTK_ENTRY(widgets[0]);
|
||||
return CString(gtk_entry_get_text(entry));
|
||||
}
|
||||
|
||||
CString CSettingCollectionHelper::getValueFoldername(GtkWidget* widget)
|
||||
{
|
||||
std::vector<GtkWidget*> widgets;
|
||||
if (!GTK_IS_CONTAINER(widget)) { return ""; }
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), CollectWidgetCB, &widgets);
|
||||
if (!GTK_IS_ENTRY(widgets[0])) { return ""; }
|
||||
GtkEntry* entry = GTK_ENTRY(widgets[0]);
|
||||
return CString(gtk_entry_get_text(entry));
|
||||
}
|
||||
|
||||
CString CSettingCollectionHelper::getValueScript(GtkWidget* widget)
|
||||
{
|
||||
std::vector<GtkWidget*> widgets;
|
||||
if (!GTK_IS_CONTAINER(widget)) { return ""; }
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), CollectWidgetCB, &widgets);
|
||||
if (!GTK_IS_ENTRY(widgets[0])) { return ""; }
|
||||
GtkEntry* entry = GTK_ENTRY(widgets[0]);
|
||||
return CString(gtk_entry_get_text(entry));
|
||||
}
|
||||
|
||||
CString CSettingCollectionHelper::getValueColor(GtkWidget* widget)
|
||||
{
|
||||
std::vector<GtkWidget*> widgets;
|
||||
if (!GTK_IS_CONTAINER(widget)) { return ""; }
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), CollectWidgetCB, &widgets);
|
||||
if (!GTK_IS_ENTRY(widgets[0])) { return ""; }
|
||||
GtkEntry* entry = GTK_ENTRY(widgets[0]);
|
||||
return CString(gtk_entry_get_text(entry));
|
||||
}
|
||||
|
||||
CString CSettingCollectionHelper::getValueColorGradient(GtkWidget* widget)
|
||||
{
|
||||
std::vector<GtkWidget*> widgets;
|
||||
if (!GTK_IS_CONTAINER(widget)) { return ""; }
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), CollectWidgetCB, &widgets);
|
||||
if (!GTK_IS_ENTRY(widgets[0])) { return ""; }
|
||||
GtkEntry* entry = GTK_ENTRY(widgets[0]);
|
||||
return CString(gtk_entry_get_text(entry));
|
||||
}
|
||||
|
||||
CString CSettingCollectionHelper::getValueEnumeration(const CIdentifier& /*typeID*/, GtkWidget* widget)
|
||||
{
|
||||
if (!GTK_IS_COMBO_BOX(widget)) { return ""; }
|
||||
GtkComboBox* comboBox = GTK_COMBO_BOX(widget);
|
||||
return CString(gtk_combo_box_get_active_text(comboBox));
|
||||
}
|
||||
|
||||
CString CSettingCollectionHelper::getValueBitMask(const CIdentifier& /*typeID*/, GtkWidget* widget)
|
||||
{
|
||||
std::vector<GtkWidget*> widgets;
|
||||
if (!GTK_IS_CONTAINER(widget)) { return ""; }
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), CollectWidgetCB, &widgets);
|
||||
std::string res;
|
||||
|
||||
for (auto& window : widgets)
|
||||
{
|
||||
if (!GTK_IS_TOGGLE_BUTTON(window)) { return ""; }
|
||||
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window)))
|
||||
{
|
||||
if (!res.empty()) { res += std::string(1, OV_Value_EnumeratedStringSeparator); }
|
||||
res += gtk_button_get_label(GTK_BUTTON(window));
|
||||
}
|
||||
}
|
||||
return res.c_str();
|
||||
}
|
||||
|
||||
// ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- -----------
|
||||
|
||||
void CSettingCollectionHelper::setValue(const CIdentifier& typeID, GtkWidget* widget, const CString& value)
|
||||
{
|
||||
if (!widget) { return; }
|
||||
if (typeID == OV_TypeId_Boolean) { return setValueBoolean(widget, value); }
|
||||
if (typeID == OV_TypeId_Integer) { return setValueInteger(widget, value); }
|
||||
if (typeID == OV_TypeId_Float) { return setValueFloat(widget, value); }
|
||||
if (typeID == OV_TypeId_String) { return setValueString(widget, value); }
|
||||
if (typeID == OV_TypeId_Filename) { return setValueFilename(widget, value); }
|
||||
if (typeID == OV_TypeId_Foldername) { return setValueFoldername(widget, value); }
|
||||
if (typeID == OV_TypeId_Script) { return setValueScript(widget, value); }
|
||||
if (typeID == OV_TypeId_Color) { return setValueColor(widget, value); }
|
||||
if (typeID == OV_TypeId_ColorGradient) { return setValueColorGradient(widget, value); }
|
||||
if (m_KernelCtx.getTypeManager().isEnumeration(typeID)) { return setValueEnumeration(typeID, widget, value); }
|
||||
if (m_KernelCtx.getTypeManager().isBitMask(typeID)) { return setValueBitMask(typeID, widget, value); }
|
||||
return setValueString(widget, value);
|
||||
}
|
||||
|
||||
void CSettingCollectionHelper::setValueBoolean(GtkWidget* widget, const CString& value)
|
||||
{
|
||||
std::vector<GtkWidget*> widgets;
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), CollectWidgetCB, &widgets);
|
||||
GtkEntry* entry = GTK_ENTRY(widgets[0]);
|
||||
GtkToggleButton* toggleButton = GTK_TOGGLE_BUTTON(widgets[1]);
|
||||
|
||||
if (value == CString("true")) { gtk_toggle_button_set_active(toggleButton, true); }
|
||||
else if (value == CString("false")) { gtk_toggle_button_set_active(toggleButton, false); }
|
||||
else { gtk_toggle_button_set_inconsistent(toggleButton, true); }
|
||||
|
||||
gtk_entry_set_text(entry, value);
|
||||
|
||||
g_signal_connect(G_OBJECT(toggleButton), "toggled", G_CALLBACK(OnCheckbuttonSettingBOOLPressed), this);
|
||||
g_signal_connect(G_OBJECT(entry), "changed", G_CALLBACK(OnEntrySettingBOOLEdited), this);
|
||||
}
|
||||
|
||||
void CSettingCollectionHelper::setValueInteger(GtkWidget* widget, const CString& value)
|
||||
{
|
||||
std::vector<GtkWidget*> widgets;
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), CollectWidgetCB, &widgets);
|
||||
GtkEntry* entry = GTK_ENTRY(widgets[0]);
|
||||
|
||||
g_signal_connect(G_OBJECT(widgets[1]), "clicked", G_CALLBACK(OnButtonSettingIntegerUpPressed), this);
|
||||
g_signal_connect(G_OBJECT(widgets[2]), "clicked", G_CALLBACK(OnButtonSettingIntegerDownPressed), this);
|
||||
|
||||
gtk_entry_set_text(entry, value);
|
||||
}
|
||||
|
||||
void CSettingCollectionHelper::setValueFloat(GtkWidget* widget, const CString& value)
|
||||
{
|
||||
std::vector<GtkWidget*> widgets;
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), CollectWidgetCB, &widgets);
|
||||
GtkEntry* entry = GTK_ENTRY(widgets[0]);
|
||||
|
||||
g_signal_connect(G_OBJECT(widgets[1]), "clicked", G_CALLBACK(OnButtonSettingFloatUpPressed), this);
|
||||
g_signal_connect(G_OBJECT(widgets[2]), "clicked", G_CALLBACK(OnButtonSettingFloatDownPressed), this);
|
||||
|
||||
gtk_entry_set_text(entry, value);
|
||||
}
|
||||
|
||||
void CSettingCollectionHelper::setValueString(GtkWidget* widget, const CString& value)
|
||||
{
|
||||
GtkEntry* entry = GTK_ENTRY(widget);
|
||||
gtk_entry_set_text(entry, value);
|
||||
}
|
||||
|
||||
void CSettingCollectionHelper::setValueFilename(GtkWidget* widget, const CString& value)
|
||||
{
|
||||
std::vector<GtkWidget*> widgets;
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), CollectWidgetCB, &widgets);
|
||||
GtkEntry* entry = GTK_ENTRY(widgets[0]);
|
||||
|
||||
g_signal_connect(G_OBJECT(widgets[1]), "clicked", G_CALLBACK(OnButtonSettingFilenameBrowsePressed), this);
|
||||
|
||||
gtk_entry_set_text(entry, value);
|
||||
}
|
||||
|
||||
void CSettingCollectionHelper::setValueFoldername(GtkWidget* widget, const CString& value)
|
||||
{
|
||||
std::vector<GtkWidget*> widgets;
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), CollectWidgetCB, &widgets);
|
||||
GtkEntry* entry = GTK_ENTRY(widgets[0]);
|
||||
|
||||
g_signal_connect(G_OBJECT(widgets[1]), "clicked", G_CALLBACK(OnButtonSettingFoldernameBrowsePressed), this);
|
||||
|
||||
gtk_entry_set_text(entry, value);
|
||||
}
|
||||
|
||||
void CSettingCollectionHelper::setValueScript(GtkWidget* widget, const CString& value)
|
||||
{
|
||||
std::vector<GtkWidget*> widgets;
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), CollectWidgetCB, &widgets);
|
||||
GtkEntry* entry = GTK_ENTRY(widgets[0]);
|
||||
|
||||
g_signal_connect(G_OBJECT(widgets[1]), "clicked", G_CALLBACK(OnButtonSettingScriptEditPressed), this);
|
||||
g_signal_connect(G_OBJECT(widgets[2]), "clicked", G_CALLBACK(OnButtonSettingFilenameBrowsePressed), this);
|
||||
|
||||
gtk_entry_set_text(entry, value);
|
||||
}
|
||||
|
||||
void CSettingCollectionHelper::setValueColor(GtkWidget* widget, const CString& value)
|
||||
{
|
||||
std::vector<GtkWidget*> widgets;
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), CollectWidgetCB, &widgets);
|
||||
GtkEntry* entry = GTK_ENTRY(widgets[0]);
|
||||
|
||||
g_signal_connect(G_OBJECT(widgets[1]), "color-set", G_CALLBACK(OnButtonSettingColorChoosePressed), this);
|
||||
|
||||
int r = 0, g = 0, b = 0;
|
||||
sscanf(m_KernelCtx.getConfigurationManager().expand(value).toASCIIString(), "%i,%i,%i", &r, &g, &b);
|
||||
|
||||
GdkColor color;
|
||||
color.red = (r * 65535) / 100;
|
||||
color.green = (g * 65535) / 100;
|
||||
color.blue = (b * 65535) / 100;
|
||||
gtk_color_button_set_color(GTK_COLOR_BUTTON(widgets[1]), &color);
|
||||
|
||||
gtk_entry_set_text(entry, value);
|
||||
}
|
||||
|
||||
void CSettingCollectionHelper::setValueColorGradient(GtkWidget* widget, const CString& value)
|
||||
{
|
||||
std::vector<GtkWidget*> widgets;
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), CollectWidgetCB, &widgets);
|
||||
GtkEntry* entry = GTK_ENTRY(widgets[0]);
|
||||
|
||||
g_signal_connect(G_OBJECT(widgets[1]), "clicked", G_CALLBACK(OnButtonSettingColorGradientConfigurePressed), this);
|
||||
|
||||
gtk_entry_set_text(entry, value);
|
||||
}
|
||||
|
||||
void CSettingCollectionHelper::setValueEnumeration(const CIdentifier& typeID, GtkWidget* widget, const CString& value) const
|
||||
{
|
||||
GtkTreeIter listIter;
|
||||
GtkComboBox* comboBox = GTK_COMBO_BOX(widget);
|
||||
GtkListStore* list = GTK_LIST_STORE(gtk_combo_box_get_model(comboBox));
|
||||
const uint64_t v = m_KernelCtx.getTypeManager().getEnumerationEntryValueFromName(typeID, value);
|
||||
uint64_t i;
|
||||
|
||||
#if 0
|
||||
if (typeID == OV_TypeId_Stimulation)
|
||||
{
|
||||
#endif
|
||||
|
||||
std::map<CString, uint64_t> listEntries;
|
||||
for (i = 0; i < m_KernelCtx.getTypeManager().getEnumerationEntryCount(typeID); ++i)
|
||||
{
|
||||
CString entryName;
|
||||
uint64_t entryValue;
|
||||
if (m_KernelCtx.getTypeManager().getEnumerationEntry(typeID, i, entryName, entryValue)) { listEntries[entryName] = entryValue; }
|
||||
}
|
||||
|
||||
gtk_combo_box_set_wrap_width(comboBox, 0);
|
||||
gtk_list_store_clear(list);
|
||||
i = 0;
|
||||
for (auto it = listEntries.begin(); it != listEntries.end(); ++it, i++)
|
||||
{
|
||||
gtk_list_store_append(list, &listIter);
|
||||
gtk_list_store_set(list, &listIter, 0, it->first.toASCIIString(), -1);
|
||||
|
||||
if (v == it->second) { gtk_combo_box_set_active(comboBox, gint(i)); }
|
||||
}
|
||||
#if 0
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_list_store_clear(list);
|
||||
for (i = 0; i < m_kernelCtx.getTypeManager().getEnumerationEntryCount(typeID); ++i)
|
||||
{
|
||||
CString entryName;
|
||||
uint64_t entryValue;
|
||||
if (m_kernelCtx.getTypeManager().getEnumerationEntry(typeID, i, entryName, entryValue))
|
||||
{
|
||||
gtk_list_store_append(list, &listIter);
|
||||
gtk_list_store_set(list, &listIter, 0, entryName.toASCIIString(), -1);
|
||||
|
||||
if (v == entryValue) { gtk_combo_box_set_active(l_widget, gint(i)); }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (gtk_combo_box_get_active(comboBox) == -1)
|
||||
{
|
||||
gtk_list_store_append(list, &listIter);
|
||||
gtk_list_store_set(list, &listIter, 0, value.toASCIIString(), -1);
|
||||
gtk_combo_box_set_active(comboBox, gint(i)); // $$$ i should be ok :)
|
||||
}
|
||||
}
|
||||
|
||||
void CSettingCollectionHelper::setValueBitMask(const CIdentifier& typeID, GtkWidget* widget, const CString& value) const
|
||||
{
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), RemoveWidgetCB, widget);
|
||||
|
||||
const std::string str(value);
|
||||
|
||||
const gint size = guint((m_KernelCtx.getTypeManager().getBitMaskEntryCount(typeID) + 1) >> 1);
|
||||
GtkTable* bitMaskTable = GTK_TABLE(widget);
|
||||
gtk_table_resize(bitMaskTable, 2, size);
|
||||
|
||||
for (uint64_t i = 0; i < m_KernelCtx.getTypeManager().getBitMaskEntryCount(typeID); ++i)
|
||||
{
|
||||
CString entryName;
|
||||
uint64_t entryValue;
|
||||
if (m_KernelCtx.getTypeManager().getBitMaskEntry(typeID, i, entryName, entryValue))
|
||||
{
|
||||
GtkWidget* settingButton = gtk_check_button_new();
|
||||
gtk_table_attach_defaults(bitMaskTable, settingButton, guint(i & 1), guint((i & 1) + 1), guint(i >> 1), guint((i >> 1) + 1));
|
||||
gtk_button_set_label(GTK_BUTTON(settingButton), entryName.toASCIIString());
|
||||
|
||||
if (str.find(entryName.toASCIIString()) != std::string::npos) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(settingButton), true); }
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO - Add an entry text somewhere to manage
|
||||
* configuration through configuration manager !
|
||||
*/
|
||||
|
||||
gtk_widget_show_all(GTK_WIDGET(bitMaskTable));
|
||||
}
|
||||
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "ovd_base.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
class CSettingCollectionHelper final
|
||||
{
|
||||
public:
|
||||
|
||||
CSettingCollectionHelper(const Kernel::IKernelContext& ctx, const char* guiFilename) : m_KernelCtx(ctx), m_GUIFilename(guiFilename) { }
|
||||
~CSettingCollectionHelper() = default;
|
||||
|
||||
CString getSettingWidgetName(const CIdentifier& typeID) const;
|
||||
CString getSettingEntryWidgetName(const CIdentifier& typeID) const;
|
||||
|
||||
CString getValue(const CIdentifier& typeID, GtkWidget* widget) const;
|
||||
static CString getValueBoolean(GtkWidget* widget);
|
||||
static CString getValueInteger(GtkWidget* widget);
|
||||
static CString getValueFloat(GtkWidget* widget);
|
||||
static CString getValueString(GtkWidget* widget);
|
||||
static CString getValueFilename(GtkWidget* widget);
|
||||
static CString getValueFoldername(GtkWidget* widget);
|
||||
static CString getValueScript(GtkWidget* widget);
|
||||
static CString getValueColor(GtkWidget* widget);
|
||||
static CString getValueColorGradient(GtkWidget* widget);
|
||||
static CString getValueEnumeration(const CIdentifier& typeID, GtkWidget* widget);
|
||||
static CString getValueBitMask(const CIdentifier& typeID, GtkWidget* widget);
|
||||
|
||||
void setValue(const CIdentifier& typeID, GtkWidget* widget, const CString& value);
|
||||
void setValueBoolean(GtkWidget* widget, const CString& value);
|
||||
void setValueInteger(GtkWidget* widget, const CString& value);
|
||||
void setValueFloat(GtkWidget* widget, const CString& value);
|
||||
static void setValueString(GtkWidget* widget, const CString& value);
|
||||
void setValueFilename(GtkWidget* widget, const CString& value);
|
||||
void setValueFoldername(GtkWidget* widget, const CString& value);
|
||||
void setValueScript(GtkWidget* widget, const CString& value);
|
||||
void setValueColor(GtkWidget* widget, const CString& value);
|
||||
void setValueColorGradient(GtkWidget* widget, const CString& value);
|
||||
void setValueEnumeration(const CIdentifier& typeID, GtkWidget* widget, const CString& value) const;
|
||||
void setValueBitMask(const CIdentifier& typeID, GtkWidget* widget, const CString& value) const;
|
||||
|
||||
const Kernel::IKernelContext& m_KernelCtx;
|
||||
CString m_GUIFilename;
|
||||
|
||||
private:
|
||||
CSettingCollectionHelper() = delete;
|
||||
};
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
Masterarbeit/openvibe/designer-master/applications/platform/designer/src/ovdCSettingEditorDialog.cpp
Executable
+105
@@ -0,0 +1,105 @@
|
||||
#include "ovdCSettingEditorDialog.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
static void TypeChangedCB(GtkComboBox* /*widget*/, gpointer data) { static_cast<CSettingEditorDialog*>(data)->typeChangedCB(); }
|
||||
|
||||
bool CSettingEditorDialog::run()
|
||||
{
|
||||
GtkBuilder* builder = gtk_builder_new(); // glade_xml_new(m_guiFilename.toASCIIString(), "setting_editor", nullptr);
|
||||
gtk_builder_add_from_file(builder, m_guiFilename.toASCIIString(), nullptr);
|
||||
gtk_builder_connect_signals(builder, nullptr);
|
||||
|
||||
GtkWidget* dialog = GTK_WIDGET(gtk_builder_get_object(builder, "setting_editor"));
|
||||
GtkWidget* name = GTK_WIDGET(gtk_builder_get_object(builder, "setting_editor-setting_name_entry"));
|
||||
m_table = GTK_WIDGET(gtk_builder_get_object(builder, "setting_editor-table"));
|
||||
m_type = GTK_WIDGET(gtk_builder_get_object(builder, "setting_editor-setting_type_combobox"));
|
||||
gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(m_type))));
|
||||
g_object_unref(builder);
|
||||
|
||||
gtk_window_set_title(GTK_WINDOW(dialog), m_title.c_str());
|
||||
|
||||
g_signal_connect(G_OBJECT(m_type), "changed", G_CALLBACK(TypeChangedCB), this);
|
||||
|
||||
CString settingName;
|
||||
CIdentifier settingType;
|
||||
m_box.getSettingName(m_settingIdx, settingName);
|
||||
m_box.getSettingType(m_settingIdx, settingType);
|
||||
|
||||
gtk_entry_set_text(GTK_ENTRY(name), settingName.toASCIIString());
|
||||
|
||||
gint active = -1;
|
||||
size_t nSettings = 0; // Cannot rely on m_settingTypes.size() -- if there are any duplicates, it wont increment properly (and should be an error anyway) ...
|
||||
|
||||
for (const auto& currentTypeID : m_kernelCtx.getTypeManager().getSortedTypes())
|
||||
{
|
||||
if (!m_kernelCtx.getTypeManager().isStream(currentTypeID.first))
|
||||
{
|
||||
gtk_combo_box_append_text(GTK_COMBO_BOX(m_type), currentTypeID.second.toASCIIString());
|
||||
if (currentTypeID.first == settingType) { active = gint(nSettings); }
|
||||
m_settingTypes[currentTypeID.second.toASCIIString()] = currentTypeID.first;
|
||||
nSettings++;
|
||||
}
|
||||
}
|
||||
|
||||
if (active != -1) { gtk_combo_box_set_active(GTK_COMBO_BOX(m_type), active); }
|
||||
|
||||
bool finished = false;
|
||||
bool res = false;
|
||||
while (!finished)
|
||||
{
|
||||
const gint result = gtk_dialog_run(GTK_DIALOG(dialog));
|
||||
if (result == GTK_RESPONSE_APPLY)
|
||||
{
|
||||
char* activeText = gtk_combo_box_get_active_text(GTK_COMBO_BOX(m_type));
|
||||
if (activeText)
|
||||
{
|
||||
settingType = m_settingTypes[activeText];
|
||||
m_box.setSettingName(m_settingIdx, gtk_entry_get_text(GTK_ENTRY(name)));
|
||||
m_box.setSettingType(m_settingIdx, settingType);
|
||||
m_box.setSettingValue(m_settingIdx, m_helper.getValue(settingType, m_defaultValue));
|
||||
m_box.setSettingDefaultValue(m_settingIdx, m_helper.getValue(settingType, m_defaultValue));
|
||||
finished = true;
|
||||
res = true;
|
||||
}
|
||||
}
|
||||
else if (result == 2) // revert
|
||||
{
|
||||
gtk_entry_set_text(GTK_ENTRY(name), settingName.toASCIIString());
|
||||
if (active != -1) { gtk_combo_box_set_active(GTK_COMBO_BOX(m_type), active); }
|
||||
}
|
||||
else
|
||||
{
|
||||
finished = true;
|
||||
res = false;
|
||||
}
|
||||
}
|
||||
|
||||
gtk_widget_destroy(dialog);
|
||||
return res;
|
||||
}
|
||||
|
||||
void CSettingEditorDialog::typeChangedCB()
|
||||
|
||||
{
|
||||
const CIdentifier settingType = m_settingTypes[gtk_combo_box_get_active_text(GTK_COMBO_BOX(m_type))];
|
||||
|
||||
const CString name = m_helper.getSettingWidgetName(settingType);
|
||||
GtkBuilder* builderDummy = gtk_builder_new(); // glade_xml_new(m_guiFilename.toASCIIString(), name, nullptr);
|
||||
gtk_builder_add_from_file(builderDummy, m_guiSettingsFilename.toASCIIString(), nullptr);
|
||||
gtk_builder_connect_signals(builderDummy, nullptr);
|
||||
|
||||
if (m_defaultValue) { gtk_container_remove(GTK_CONTAINER(m_table), m_defaultValue); }
|
||||
m_defaultValue = GTK_WIDGET(gtk_builder_get_object(builderDummy, name.toASCIIString()));
|
||||
gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(m_defaultValue)), m_defaultValue);
|
||||
gtk_table_attach(GTK_TABLE(m_table), m_defaultValue, 1, 2, 2, 3, GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(GTK_FILL | GTK_EXPAND), 0, 0);
|
||||
g_object_unref(builderDummy);
|
||||
|
||||
CString value;
|
||||
m_box.getSettingDefaultValue(m_settingIdx, value);
|
||||
m_helper.setValue(settingType, m_defaultValue, value);
|
||||
}
|
||||
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include "ovdCSettingCollectionHelper.h"
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
class CSettingEditorDialog final
|
||||
{
|
||||
public:
|
||||
|
||||
CSettingEditorDialog(const Kernel::IKernelContext& ctx, Kernel::IBox& box, const size_t index, const char* title,
|
||||
const char* guiFilename, const char* guiSettingsFilename)
|
||||
: m_kernelCtx(ctx), m_box(box), m_helper(ctx, guiFilename), m_settingIdx(index), m_guiFilename(guiFilename),
|
||||
m_guiSettingsFilename(guiSettingsFilename), m_title(title) { }
|
||||
|
||||
~CSettingEditorDialog() = default;
|
||||
|
||||
bool run();
|
||||
void typeChangedCB();
|
||||
|
||||
protected:
|
||||
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
Kernel::IBox& m_box;
|
||||
CSettingCollectionHelper m_helper;
|
||||
size_t m_settingIdx = 0;
|
||||
CString m_guiFilename;
|
||||
CString m_guiSettingsFilename;
|
||||
std::string m_title;
|
||||
GtkWidget* m_table = nullptr;
|
||||
GtkWidget* m_type = nullptr;
|
||||
GtkWidget* m_defaultValue = nullptr;
|
||||
std::map<std::string, CIdentifier> m_settingTypes;
|
||||
};
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
#include "ovdTAttributeHandler.h"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
bool TAttributeHandler::removeAttribute(const CIdentifier& id)
|
||||
{
|
||||
if (!m_attributable) { return false; }
|
||||
return m_attributable->removeAttribute(id);
|
||||
}
|
||||
|
||||
bool TAttributeHandler::removeAllAttributes()
|
||||
|
||||
{
|
||||
if (!m_attributable) { return false; }
|
||||
return m_attributable->removeAllAttributes();
|
||||
}
|
||||
|
||||
template <>
|
||||
bool TAttributeHandler::addAttribute(const CIdentifier& id, const int& value) const
|
||||
{
|
||||
if (!m_attributable) { return false; }
|
||||
const std::string str = std::to_string(value); // pass directly std::to_string().c_str() with int value can return anything
|
||||
return m_attributable->addAttribute(id, str.c_str());
|
||||
}
|
||||
|
||||
template <>
|
||||
bool TAttributeHandler::addAttribute(const CIdentifier& id, const bool& value) const
|
||||
{
|
||||
if (!m_attributable) { return false; }
|
||||
|
||||
return m_attributable->addAttribute(id, (value ? "true" : "false"));
|
||||
}
|
||||
|
||||
template <>
|
||||
int TAttributeHandler::getAttributeValue<int>(const CIdentifier& id) const { return strtol(m_constAttributable->getAttributeValue(id), nullptr, 10); }
|
||||
|
||||
template <>
|
||||
bool TAttributeHandler::getAttributeValue<bool>(const CIdentifier& id) const
|
||||
{
|
||||
bool res = false;
|
||||
const CString value(m_constAttributable->getAttributeValue(id));
|
||||
if (value == CString("true")) { res = true; }
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool TAttributeHandler::setAttributeValue(const CIdentifier& id, const int& value)
|
||||
{
|
||||
if (!m_attributable) { return false; }
|
||||
const std::string str = std::to_string(value); // pass directly std::to_string().c_str() with int value can return anything
|
||||
return m_attributable->setAttributeValue(id, str.c_str());
|
||||
}
|
||||
|
||||
template <>
|
||||
bool TAttributeHandler::setAttributeValue(const CIdentifier& id, const bool& value)
|
||||
{
|
||||
if (!m_attributable) { return false; }
|
||||
return m_attributable->setAttributeValue(id, (value ? "true" : "false"));
|
||||
}
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "ovd_base.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
class TAttributeHandler
|
||||
{
|
||||
public:
|
||||
|
||||
explicit TAttributeHandler(Kernel::IAttributable& attributable) : m_constAttributable(&attributable), m_attributable(&attributable) { }
|
||||
explicit TAttributeHandler(const Kernel::IAttributable& attributable) : m_constAttributable(&attributable) { }
|
||||
|
||||
template <class T>
|
||||
bool addAttribute(const CIdentifier& id, const T& value) const;
|
||||
|
||||
bool removeAttribute(const CIdentifier& id);
|
||||
|
||||
bool removeAllAttributes();
|
||||
|
||||
template <class T>
|
||||
T getAttributeValue(const CIdentifier& id) const;
|
||||
|
||||
template <class T>
|
||||
bool setAttributeValue(const CIdentifier& id, const T& value);
|
||||
|
||||
bool hasAttribute(const CIdentifier& id) const { return m_constAttributable->hasAttribute(id); }
|
||||
bool hasAttributes() const { return m_constAttributable->hasAttributes(); }
|
||||
|
||||
protected:
|
||||
|
||||
const Kernel::IAttributable* m_constAttributable;
|
||||
Kernel::IAttributable* m_attributable = nullptr;
|
||||
};
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <openvibe/ov_all.h>
|
||||
#include <toolkit/ovtk_all.h>
|
||||
#include <visualization-toolkit/ovviz_all.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
#include "ovd_defines.h"
|
||||
|
||||
#include <boost/interprocess/ipc/message_queue.hpp>
|
||||
#include <boost/archive/text_oarchive.hpp>
|
||||
#include <boost/interprocess/sync/scoped_lock.hpp>
|
||||
#include <boost/interprocess/sync/named_mutex.hpp>
|
||||
|
||||
#define MUTEX_NAME "openvibe_designer_mutex"
|
||||
#define MESSAGE_NAME "openvibe_designer_message"
|
||||
|
||||
#define G_CALLBACK2(x) G_CALLBACK_AUTOCAST(G_CALLBACK(x))
|
||||
|
||||
class G_CALLBACK_AUTOCAST
|
||||
{
|
||||
public:
|
||||
|
||||
typedef union
|
||||
{
|
||||
GCallback fp;
|
||||
gpointer p;
|
||||
} data_t;
|
||||
|
||||
data_t m_Data;
|
||||
|
||||
G_CALLBACK_AUTOCAST(const gpointer p) { m_Data.p = p; }
|
||||
G_CALLBACK_AUTOCAST(const GCallback fp) { m_Data.fp = fp; }
|
||||
|
||||
operator gpointer() const { return m_Data.p; }
|
||||
operator GCallback() const { return m_Data.fp; }
|
||||
|
||||
private:
|
||||
|
||||
G_CALLBACK_AUTOCAST();
|
||||
};
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
#pragma once
|
||||
|
||||
//Attributes of visualisation window :
|
||||
#define OVD_AttributeId_VisualisationWindow_Width OpenViBE::CIdentifier(0x7B814CCA, 0x271DF6DD)
|
||||
#define OVD_AttributeId_VisualisationWindow_Height OpenViBE::CIdentifier(0x4C90D4AD, 0x7A2554EC)
|
||||
|
||||
//Attributes of visualisation paned :
|
||||
#define OVD_AttributeId_VisualisationWidget_DividerPosition OpenViBE::CIdentifier(0x54E45F5B, 0x76C036E2)
|
||||
#define OVD_AttributeId_VisualisationWidget_MaxDividerPosition OpenViBE::CIdentifier(0x237E56D2, 0x10CD68AE)
|
||||
|
||||
#define OV_AttributeId_Box_Disabled OpenViBE::CIdentifier(0x341D3912, 0x1478DE86)
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
typedef enum
|
||||
{
|
||||
CommandLineFlag_None = 0x00000000,
|
||||
CommandLineFlag_Open = 0x00000001,
|
||||
CommandLineFlag_Play = 0x00000002,
|
||||
CommandLineFlag_PlayFast = 0x00000004,
|
||||
CommandLineFlag_NoGui = 0x00000008,
|
||||
CommandLineFlag_NoCheckColorDepth = 0x00000010,
|
||||
CommandLineFlag_NoManageSession = 0x00000020,
|
||||
CommandLineFlag_Define = 0x00000040,
|
||||
CommandLineFlag_Config = 0x00000080,
|
||||
CommandLineFlag_RandomSeed = 0x00000100,
|
||||
CommandLineFlag_NoVisualization = 0x00000200 /** flag to hide visualisation widget */
|
||||
} ECommandLineFlag;
|
||||
|
||||
enum class EContextMenu
|
||||
{
|
||||
SelectionCopy, SelectionCut, SelectionPaste, SelectionDelete,
|
||||
|
||||
BoxUpdate, BoxRemoveDeprecatedInterfacors, BoxRename, BoxDelete,
|
||||
BoxAddInput, BoxEditInput, BoxRemoveInput,
|
||||
BoxAddOutput, BoxEditOutput, BoxRemoveOutput,
|
||||
|
||||
BoxConnectScenarioInput, BoxConnectScenarioOutput,
|
||||
BoxDisconnectScenarioInput, BoxDisconnectScenarioOutput,
|
||||
|
||||
BoxAddSetting, BoxRemoveSetting, BoxEditSetting,
|
||||
BoxConfigure, BoxAbout, BoxEnable, BoxDisable,
|
||||
|
||||
BoxAddMessageInput, BoxRemoveMessageInput,
|
||||
BoxAddMessageOutput, BoxRemoveMessageOutput,
|
||||
BoxEditMessageInput, BoxEditMessageOutput,
|
||||
|
||||
BoxEditMetabox,
|
||||
BoxDocumentation,
|
||||
ScenarioAddComment,
|
||||
ScenarioAbout
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
Resource_StringName,
|
||||
Resource_StringShortDescription,
|
||||
Resource_StringIdentifier,
|
||||
Resource_StringStockIcon,
|
||||
Resource_StringColor,
|
||||
Resource_StringFont,
|
||||
Resource_BooleanIsPlugin,
|
||||
Resource_BooleanIsUnstable,
|
||||
Resource_BackGroundColor,
|
||||
Resource_BooleanIsGhost = 8001,
|
||||
Resource_BooleanIsMensia = 8002
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
Color_BackgroundPlayerStarted,
|
||||
Color_BoxBackground,
|
||||
Color_BoxBackgroundSelected,
|
||||
Color_BoxBackgroundMissing,
|
||||
Color_BoxBackgroundDisabled,
|
||||
Color_BoxBackgroundDeprecated,
|
||||
Color_BoxBackgroundUnstable,
|
||||
Color_BoxBackgroundOutdated,
|
||||
Color_BoxBackgroundMetabox,
|
||||
Color_BoxBorder,
|
||||
Color_BoxBorderSelected,
|
||||
Color_BoxInputBackground,
|
||||
Color_BoxInputBorder,
|
||||
Color_BoxOutputBackground,
|
||||
Color_BoxOutputBorder,
|
||||
Color_BoxSettingBackground,
|
||||
Color_BoxSettingBorder,
|
||||
Color_CommentBackground,
|
||||
Color_CommentBackgroundSelected,
|
||||
Color_CommentBorder,
|
||||
Color_CommentBorderSelected,
|
||||
Color_Link,
|
||||
Color_LinkSelected,
|
||||
Color_LinkDownCast,
|
||||
Color_LinkUpCast,
|
||||
Color_LinkInvalid,
|
||||
Color_SelectionArea,
|
||||
Color_SelectionAreaBorder,
|
||||
};
|
||||
|
||||
enum { Box_None, Box_Input, Box_Output, Box_Setting, Box_Link, Box_ScenarioInput, Box_ScenarioOutput, Box_Update };
|
||||
|
||||
enum { Mode_None, Mode_Selection, Mode_SelectionAdd, Mode_MoveScenario, Mode_MoveSelection, Mode_Connect, Mode_EditSettings };
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
|
||||
//___________________________________________________________________//
|
||||
// //
|
||||
// Global defines //
|
||||
//___________________________________________________________________//
|
||||
// //
|
||||
|
||||
#ifdef TARGET_HAS_ThirdPartyOpenViBEPluginsGlobalDefines
|
||||
#include "ovp_global_defines.h"
|
||||
#endif // TARGET_HAS_ThirdPartyOpenViBEPluginsGlobalDefines
|
||||
+874
@@ -0,0 +1,874 @@
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <json/json.h>
|
||||
|
||||
#include <system/ovCTime.h>
|
||||
#include <system/ovCMath.h>
|
||||
#include <openvibe/kernel/metabox/ovIMetaboxManager.h>
|
||||
#include "ovd_base.h"
|
||||
|
||||
#include "ovdCInterfacedObject.h"
|
||||
#include "ovdCInterfacedScenario.h"
|
||||
#include "ovdCApplication.h"
|
||||
|
||||
#include "ovdAssert.h"
|
||||
#if defined TARGET_OS_Windows
|
||||
#include "Windows.h"
|
||||
#include "shellapi.h"
|
||||
#endif
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
std::map<size_t, GdkColor> gColors;
|
||||
|
||||
class CPluginObjectDescEnum
|
||||
{
|
||||
public:
|
||||
|
||||
explicit CPluginObjectDescEnum(const Kernel::IKernelContext& ctx) : m_kernelCtx(ctx) { }
|
||||
virtual ~CPluginObjectDescEnum() = default;
|
||||
|
||||
virtual bool enumeratePluginObjectDesc()
|
||||
{
|
||||
CIdentifier id;
|
||||
while ((id = m_kernelCtx.getPluginManager().getNextPluginObjectDescIdentifier(id)) != CIdentifier::undefined())
|
||||
{
|
||||
this->callback(*m_kernelCtx.getPluginManager().getPluginObjectDesc(id));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool enumeratePluginObjectDesc(const CIdentifier& parentClassID)
|
||||
{
|
||||
CIdentifier id;
|
||||
while ((id = m_kernelCtx.getPluginManager().getNextPluginObjectDescIdentifier(id, parentClassID)) != CIdentifier::undefined())
|
||||
{
|
||||
this->callback(*m_kernelCtx.getPluginManager().getPluginObjectDesc(id));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool callback(const Plugins::IPluginObjectDesc& pod) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
class CPluginObjectDescCollector final : public CPluginObjectDescEnum
|
||||
{
|
||||
public:
|
||||
|
||||
explicit CPluginObjectDescCollector(const Kernel::IKernelContext& ctx) : CPluginObjectDescEnum(ctx) { }
|
||||
|
||||
bool callback(const Plugins::IPluginObjectDesc& pod) override
|
||||
{
|
||||
const std::string name = std::string(pod.getCategory()) + "/" + std::string(pod.getName());
|
||||
const auto it = m_pods.find(name);
|
||||
if (it != m_pods.end())
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_ImportantWarning << "Duplicate plugin object name " << name << " "
|
||||
<< it->second->getCreatedClass() << " and " << pod.getCreatedClass() << "\n";
|
||||
}
|
||||
m_pods[name] = &pod;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::map<std::string, const Plugins::IPluginObjectDesc*>& getPluginObjectDescMap() { return m_pods; }
|
||||
|
||||
private:
|
||||
|
||||
std::map<std::string, const Plugins::IPluginObjectDesc*> m_pods;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
class CPluginObjectDescLogger final : public CPluginObjectDescEnum
|
||||
{
|
||||
public:
|
||||
|
||||
explicit CPluginObjectDescLogger(const Kernel::IKernelContext& ctx) : CPluginObjectDescEnum(ctx) { }
|
||||
|
||||
bool callback(const Plugins::IPluginObjectDesc& pod) override
|
||||
{
|
||||
// Outputs plugin info to console
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Trace << "Plugin <" << pod.getName() << ">\n";
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Debug << " | Plugin category : " << pod.getCategory() << "\n";
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Debug << " | Class identifier : " << pod.getCreatedClass() << "\n";
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Debug << " | Author name : " << pod.getAuthorName() << "\n";
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Debug << " | Author company name : " << pod.getAuthorCompanyName() << "\n";
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Debug << " | Short description : " << pod.getShortDescription() << "\n";
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Debug << " | Detailed description : " << pod.getDetailedDescription() << "\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace {
|
||||
typedef std::map<std::string, std::tuple<int, int, int>> components_map_t;
|
||||
// Parses a JSON encoded list of components with their versions
|
||||
// We use an output variable because we want to be able to "enhance" an already existing list if necessary
|
||||
void getVersionComponentsFromConfigToken(const Kernel::IKernelContext& ctx, const char* configToken, components_map_t& componentVersions)
|
||||
{
|
||||
json::Object versionsObject;
|
||||
// We use a lookup instead of expansion as JSON can contain { } characters
|
||||
|
||||
const CString versionsJSON = ctx.getConfigurationManager().expand(CString("${") + configToken + "}");
|
||||
if (versionsJSON.length() != 0)
|
||||
{
|
||||
// This check is necessary because the asignemt operator would fail with an assert
|
||||
if (json::Deserialize(versionsJSON.toASCIIString()).GetType() == json::ObjectVal) { versionsObject = json::Deserialize(versionsJSON.toASCIIString()); }
|
||||
for (const auto& component : versionsObject)
|
||||
{
|
||||
int versionMajor, versionMinor, versionPatch;
|
||||
sscanf(component.second, "%d.%d.%d", &versionMajor, &versionMinor, &versionPatch);
|
||||
componentVersions[component.first] = std::make_tuple(versionMajor, versionMinor, versionPatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
static void InsertPluginObjectDescToGtkTreeStore(const Kernel::IKernelContext& ctx, std::map<std::string, const Plugins::IPluginObjectDesc*>& pods,
|
||||
GtkTreeStore* treeStore, std::vector<const Plugins::IPluginObjectDesc*>& newBoxes,
|
||||
std::vector<const Plugins::IPluginObjectDesc*>& updatedBoxes, bool isNewVersion = false)
|
||||
{
|
||||
typedef std::map<std::string, std::tuple<int, int, int>> components_map_t;
|
||||
components_map_t currentVersions;
|
||||
getVersionComponentsFromConfigToken(ctx, "ProjectVersion_Components", currentVersions);
|
||||
// By default, fix version to current version - to display the new/update boxes available since current version only
|
||||
components_map_t lastUsedVersions = currentVersions;
|
||||
getVersionComponentsFromConfigToken(ctx, "Designer_LastComponentVersionsUsed", lastUsedVersions);
|
||||
|
||||
for (const auto& pod : pods)
|
||||
{
|
||||
const Plugins::IPluginObjectDesc* p = pod.second;
|
||||
|
||||
CString stockItemName;
|
||||
|
||||
const auto* desc = dynamic_cast<const Plugins::IBoxAlgorithmDesc*>(p);
|
||||
if (desc != nullptr) { stockItemName = desc->getStockItemName(); }
|
||||
|
||||
bool shouldShow = true;
|
||||
|
||||
if (ctx.getPluginManager().isPluginObjectFlaggedAsDeprecated(p->getCreatedClass())
|
||||
&& !ctx.getConfigurationManager().expandAsBoolean("${Designer_ShowDeprecated}", false)) { shouldShow = false; }
|
||||
|
||||
/*
|
||||
if (ctx.getPluginManager().isPluginObjectFlaggedAsUnstable(desc->getCreatedClass())
|
||||
&& !ctx.getConfigurationManager().expandAsBoolean("${Designer_ShowUnstable}", false)) { shouldShow = false; }
|
||||
*/
|
||||
|
||||
if (shouldShow)
|
||||
{
|
||||
GtkStockItem stockItem;
|
||||
if (gtk_stock_lookup(stockItemName, &stockItem) == 0) { stockItemName = GTK_STOCK_NEW; }
|
||||
|
||||
// Splits the plugin category
|
||||
std::vector<std::string> categories;
|
||||
std::string str = std::string(p->getCategory());
|
||||
size_t j, i = size_t(-1);
|
||||
while ((j = str.find('/', i + 1)) != std::string::npos)
|
||||
{
|
||||
std::string subCategory = std::string(str, i + 1, j - i - 1);
|
||||
if (subCategory != std::string("")) { categories.push_back(subCategory); }
|
||||
i = j;
|
||||
}
|
||||
if (i + 1 != str.length()) { categories.emplace_back(str, i + 1, str.length() - i - 1); }
|
||||
|
||||
// Fills plugin in the tree
|
||||
GtkTreeIter iter1;
|
||||
GtkTreeIter iter2;
|
||||
GtkTreeIter* iterParent = nullptr;
|
||||
GtkTreeIter* iterChild = &iter1;
|
||||
for (const std::string& category : categories)
|
||||
{
|
||||
bool found = false;
|
||||
bool valid = gtk_tree_model_iter_children(GTK_TREE_MODEL(treeStore), iterChild, iterParent) != 0;
|
||||
while (valid && !found)
|
||||
{
|
||||
gchar* name = nullptr;
|
||||
gboolean isPlugin;
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(treeStore), iterChild, Resource_StringName, &name, Resource_BooleanIsPlugin, &isPlugin, -1);
|
||||
if ((isPlugin == 0) && name == category) { found = true; }
|
||||
else { valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(treeStore), iterChild) != 0; }
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
gtk_tree_store_append(GTK_TREE_STORE(treeStore), iterChild, iterParent);
|
||||
gtk_tree_store_set(GTK_TREE_STORE(treeStore), iterChild, Resource_StringName, category.c_str(),
|
||||
Resource_StringShortDescription, "", Resource_StringStockIcon, "gtk-directory", Resource_StringColor, "#000000",
|
||||
Resource_StringFont, "", Resource_BooleanIsPlugin, gboolean(FALSE), -1);
|
||||
}
|
||||
if (iterParent == nullptr) { iterParent = &iter2; }
|
||||
GtkTreeIter* iterSwap = iterChild;
|
||||
iterChild = iterParent;
|
||||
iterParent = iterSwap;
|
||||
}
|
||||
gtk_tree_store_append(GTK_TREE_STORE(treeStore), iterChild, iterParent);
|
||||
|
||||
// define color of the text of the box
|
||||
std::string textColor = "black";
|
||||
std::string bgColor = "white";
|
||||
std::string textFont;
|
||||
str = p->getName().toASCIIString();
|
||||
|
||||
if (ctx.getPluginManager().isPluginObjectFlaggedAsDeprecated(p->getCreatedClass())) { textColor = "#3f7f7f"; }
|
||||
|
||||
// If the software is launched for the first time after update, highlight new/updated boxes in tree-view
|
||||
std::string boxSoftwareComponent = p->getSoftwareComponent().toASCIIString();
|
||||
|
||||
if (boxSoftwareComponent != "unknown")
|
||||
{
|
||||
int currentVMajor = std::get<0>(currentVersions[boxSoftwareComponent]);
|
||||
int currentVMinor = std::get<1>(currentVersions[boxSoftwareComponent]);
|
||||
int currentVPatch = std::get<2>(currentVersions[boxSoftwareComponent]);
|
||||
int lastUsedVMajor = std::get<0>(lastUsedVersions[boxSoftwareComponent]);
|
||||
int lastUsedVMinor = std::get<1>(lastUsedVersions[boxSoftwareComponent]);
|
||||
int lastUsedVPatch = std::get<2>(lastUsedVersions[boxSoftwareComponent]);
|
||||
int boxCompoVMajor = 0;
|
||||
int boxCompoVMinor = 0;
|
||||
int boxCompoVPatch = 0;
|
||||
|
||||
sscanf(p->getAddedSoftwareVersion().toASCIIString(), "%d.%d.%d", &boxCompoVMajor, &boxCompoVMinor, &boxCompoVPatch);
|
||||
// If this is a new version, then add in list all the updated/new boxes since last version opened
|
||||
if (isNewVersion
|
||||
&& ((lastUsedVMajor < boxCompoVMajor && boxCompoVMajor <= currentVMajor)
|
||||
|| (boxCompoVMajor == currentVMajor && lastUsedVMinor < boxCompoVMinor && boxCompoVMinor <= currentVMinor)
|
||||
|| (boxCompoVMinor == currentVMinor && lastUsedVPatch < boxCompoVPatch && boxCompoVPatch <= currentVPatch)
|
||||
// As default value for lastUsedVMinor and lastUsedVMajor are the current software version
|
||||
|| (boxCompoVMajor == currentVMajor && boxCompoVMinor == currentVMinor && boxCompoVPatch == currentVPatch)))
|
||||
{
|
||||
str += " (New)";
|
||||
bgColor = "#FFFFC4";
|
||||
newBoxes.push_back(p);
|
||||
}
|
||||
// Otherwise
|
||||
else if (boxCompoVMajor == currentVMajor && boxCompoVMinor == currentVMinor && boxCompoVPatch ==
|
||||
currentVPatch) { newBoxes.push_back(p); }
|
||||
else
|
||||
{
|
||||
int boxCompoUpdatedVMajor = 0;
|
||||
int boxCompoUpdatedVMinor = 0;
|
||||
int boxCompoUpdatedVPatch = 0;
|
||||
sscanf(p->getUpdatedSoftwareVersion().toASCIIString(), "%d.%d.%d", &boxCompoUpdatedVMajor,
|
||||
&boxCompoUpdatedVMinor, &boxCompoUpdatedVPatch);
|
||||
// If this is a new version, then add in list all the updated/new boxes since last version opened
|
||||
if (isNewVersion
|
||||
&& ((lastUsedVMajor < boxCompoUpdatedVMajor && boxCompoUpdatedVMajor <= currentVMajor)
|
||||
|| (boxCompoUpdatedVMajor == currentVMajor && lastUsedVMinor < boxCompoUpdatedVMinor && boxCompoUpdatedVMinor <= currentVMinor)
|
||||
|| (boxCompoUpdatedVMinor == currentVMinor && lastUsedVPatch < boxCompoUpdatedVPatch && boxCompoUpdatedVPatch <= currentVPatch)
|
||||
// If this is a new version Designer, and last version opened was set to default value i.e. version of current software
|
||||
|| (boxCompoUpdatedVMajor == currentVMajor && boxCompoUpdatedVMinor == currentVMinor && boxCompoUpdatedVPatch == currentVPatch)))
|
||||
{
|
||||
str += " (New)";
|
||||
bgColor = "#FFFFC4";
|
||||
updatedBoxes.push_back(p);
|
||||
}
|
||||
// Otherwise
|
||||
else if (!isNewVersion && (boxCompoUpdatedVMajor == currentVMajor && boxCompoUpdatedVMinor == currentVMinor
|
||||
&& boxCompoUpdatedVPatch == currentVPatch)) { updatedBoxes.push_back(p); }
|
||||
}
|
||||
}
|
||||
|
||||
// Construct a string containing the BoxAlgorithmIdentifier concatenated with a metabox identifier if necessary
|
||||
std::string boxAlgorithmDesc = p->getCreatedClass().str();
|
||||
|
||||
if (p->getCreatedClass() == OVP_ClassId_BoxAlgorithm_Metabox)
|
||||
{
|
||||
boxAlgorithmDesc += dynamic_cast<const Metabox::IMetaboxObjectDesc*>(p)->getMetaboxDescriptor();
|
||||
textColor = "#007020";
|
||||
}
|
||||
|
||||
gtk_tree_store_set(GTK_TREE_STORE(treeStore), iterChild, Resource_StringName, str.c_str(),
|
||||
Resource_StringShortDescription, static_cast<const char*>(p->getShortDescription()),
|
||||
Resource_StringIdentifier, static_cast<const char*>(boxAlgorithmDesc.c_str()),
|
||||
Resource_StringStockIcon, static_cast<const char*>(stockItemName), Resource_StringColor, textColor.c_str(),
|
||||
Resource_StringFont, textFont.c_str(), Resource_BooleanIsPlugin, gboolean(TRUE),
|
||||
Resource_BackGroundColor, static_cast<const char*>(bgColor.c_str()), -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
typedef struct SConfig
|
||||
{
|
||||
SConfig() = default;
|
||||
|
||||
ECommandLineFlag getFlags() const { return ECommandLineFlag(noGui | noCheckColorDepth | noManageSession | noVisualization | define | randomSeed | config); }
|
||||
|
||||
std::vector<std::pair<ECommandLineFlag, std::string>> flags;
|
||||
ECommandLineFlag noGui = CommandLineFlag_None;
|
||||
ECommandLineFlag noCheckColorDepth = CommandLineFlag_None;
|
||||
ECommandLineFlag noManageSession = CommandLineFlag_None;
|
||||
ECommandLineFlag noVisualization = CommandLineFlag_None;
|
||||
ECommandLineFlag define = CommandLineFlag_None;
|
||||
ECommandLineFlag randomSeed = CommandLineFlag_None;
|
||||
ECommandLineFlag config = CommandLineFlag_None;
|
||||
bool help = false;
|
||||
// to resolve warning: padding struct 'SConfig' with 4 bytes to align 'tokens
|
||||
int structPadding = 0;
|
||||
std::map<std::string, std::string> tokens;
|
||||
} config_t;
|
||||
|
||||
static char backslash_to_slash(const char c) { return c == '\\' ? '/' : c; }
|
||||
|
||||
/** ------------------------------------------------------------------------------------------------------------------------------------
|
||||
* Use Mutex to ensure that only one instance with GUI of Designer runs at the same time
|
||||
* if another instance exists, sends a message to it so that it opens a scenario or get the focus back
|
||||
* \param config: play, play-fast or open
|
||||
* \param logMgr: name of the scenario to open
|
||||
------------------------------------------------------------------------------------------------------------------------------------**/
|
||||
#if defined NDEBUG
|
||||
static bool ensureOneInstanceOfDesigner(config_t& config, Kernel::ILogManager& logMgr)
|
||||
{
|
||||
try
|
||||
{
|
||||
// If the mutex cannot be opened, it's the first instance of Designer, go to catch
|
||||
boost::interprocess::named_mutex mutex(boost::interprocess::open_only, MUTEX_NAME);
|
||||
|
||||
// If the mutex was opened, then an instance of designer is already running, we send it a message before dying
|
||||
// The message contains the command to send: sMode: open, play, play-fast a scenario, sScenarioPath: path of the scenario
|
||||
boost::interprocess::scoped_lock<boost::interprocess::named_mutex> lock(mutex);
|
||||
std::string msg;
|
||||
if (config.flags.empty()) { msg = std::to_string(int(CommandLineFlag_None)) + ": ;"; }
|
||||
|
||||
for (auto& flag : config.flags)
|
||||
{
|
||||
std::string fileName = flag.second;
|
||||
std::transform(fileName.begin(), fileName.end(), fileName.begin(), backslash_to_slash);
|
||||
|
||||
msg += std::to_string(int(flag.first)) + ": <" + fileName + "> ; ";
|
||||
}
|
||||
|
||||
const size_t msgSize = strlen(msg.c_str()) * sizeof(char);
|
||||
|
||||
boost::interprocess::message_queue messageToFirstInstance(boost::interprocess::open_or_create, MESSAGE_NAME, msgSize, msgSize);
|
||||
messageToFirstInstance.send(msg.c_str(), msgSize, 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
catch (boost::interprocess::interprocess_exception&)
|
||||
{
|
||||
//Create the named mutex to catch the potential next instance of Designer that could open
|
||||
boost::interprocess::named_mutex mutex(boost::interprocess::create_only, MUTEX_NAME);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#else
|
||||
static bool ensureOneInstanceOfDesigner(config_t& /*config*/, Kernel::ILogManager& /*logMgr*/) { return true; }
|
||||
#endif
|
||||
|
||||
bool parse_arguments(int argc, char** argv, config_t& config)
|
||||
{
|
||||
config_t tmp;
|
||||
|
||||
std::vector<std::string> args;
|
||||
#if defined TARGET_OS_Windows
|
||||
int nArg;
|
||||
LPWSTR* argListUtf16 = CommandLineToArgvW(GetCommandLineW(), &nArg);
|
||||
for (int i = 1; i < nArg; ++i)
|
||||
{
|
||||
GError* error = nullptr;
|
||||
glong itemsRead, itemsWritten;
|
||||
char* argUtf8 = g_utf16_to_utf8(reinterpret_cast<gunichar2*>(argListUtf16[i]), glong(wcslen(argListUtf16[i])), &itemsRead, &itemsWritten, &error);
|
||||
args.emplace_back(argUtf8);
|
||||
if (error != nullptr)
|
||||
{
|
||||
g_error_free(error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#else
|
||||
args = std::vector<std::string>(argv + 1, argv + argc);
|
||||
#endif
|
||||
args.emplace_back("");
|
||||
|
||||
for (auto it = args.cbegin(); it != args.cend(); ++it)
|
||||
{
|
||||
if (*it == "") {}
|
||||
else if (*it == "-h" || *it == "--help")
|
||||
{
|
||||
tmp.help = true;
|
||||
config = tmp;
|
||||
return false;
|
||||
}
|
||||
else if (*it == "-o" || *it == "--open") { tmp.flags.emplace_back(CommandLineFlag_Open, *++it); }
|
||||
else if (*it == "-p" || *it == "--play") { tmp.flags.emplace_back(CommandLineFlag_Play, *++it); }
|
||||
else if (*it == "-pf" || *it == "--play-fast") { tmp.flags.emplace_back(CommandLineFlag_PlayFast, *++it); }
|
||||
else if (*it == "--no-gui")
|
||||
{
|
||||
tmp.noGui = CommandLineFlag_NoGui;
|
||||
tmp.noCheckColorDepth = CommandLineFlag_NoCheckColorDepth;
|
||||
tmp.noManageSession = CommandLineFlag_NoManageSession;
|
||||
}
|
||||
else if (*it == "--no-visualization") { tmp.noVisualization = CommandLineFlag_NoVisualization; }
|
||||
else if (*it == "--invisible")
|
||||
{
|
||||
// no-gui + no-visualization
|
||||
tmp.noVisualization = CommandLineFlag_NoVisualization;
|
||||
tmp.noGui = CommandLineFlag_NoGui;
|
||||
tmp.noCheckColorDepth = CommandLineFlag_NoCheckColorDepth;
|
||||
tmp.noManageSession = CommandLineFlag_NoManageSession;
|
||||
}
|
||||
else if (*it == "--no-check-color-depth") { tmp.noCheckColorDepth = CommandLineFlag_NoCheckColorDepth; }
|
||||
else if (*it == "--no-session-management") { tmp.noManageSession = CommandLineFlag_NoManageSession; }
|
||||
else if (*it == "-c" || *it == "--config")
|
||||
{
|
||||
if (*++it == "")
|
||||
{
|
||||
std::cout << "Error: Switch --config needs an argument\n";
|
||||
return false;
|
||||
}
|
||||
tmp.flags.emplace_back(CommandLineFlag_Config, *it);
|
||||
}
|
||||
else if (*it == "-d" || *it == "--define")
|
||||
{
|
||||
if (*++it == "")
|
||||
{
|
||||
std::cout << "Error: Need two arguments after -d / --define.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Were not using = as a separator for token/value, as on Windows its a problem passing = to the cmd interpreter
|
||||
// which is used to launch the actual designer exe.
|
||||
const std::string& token = *it;
|
||||
if (*++it == "")
|
||||
{
|
||||
std::cout << "Error: Need two arguments after -d / --define.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string& value = *it; // iterator will increment later
|
||||
|
||||
tmp.tokens[token] = value;
|
||||
}
|
||||
else if (*it == "--random-seed")
|
||||
{
|
||||
if (*++it == "")
|
||||
{
|
||||
std::cout << "Error: Switch --random-seed needs an argument\n";
|
||||
return false;
|
||||
}
|
||||
tmp.flags.emplace_back(CommandLineFlag_RandomSeed, *it);
|
||||
}
|
||||
else if (*it == "--g-fatal-warnings")
|
||||
{
|
||||
// Do nothing here but accept this gtk flag
|
||||
}
|
||||
else
|
||||
{
|
||||
#if 0
|
||||
// Assumes we just open a scenario - this is for retro compatibility and should not be supported in the future
|
||||
config.flags.push_back(std::make_pair(CommandLineFlag_Open, *++it));
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
config.flags = config.flags;
|
||||
config.checkColorDepth = config.m_bCheckColorDepth;
|
||||
config.showGui = config.m_bShowGui;
|
||||
#else
|
||||
config = tmp;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#if defined OPENVIBE_SPLASHSCREEN
|
||||
|
||||
gboolean cb_remove_splashscreen(gpointer data)
|
||||
{
|
||||
gtk_widget_hide(GTK_WIDGET(data));
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
void message(const char* title, const char* msg, const GtkMessageType type)
|
||||
{
|
||||
GtkWidget* dialog = gtk_message_dialog_new(nullptr, GtkDialogFlags(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), type, GTK_BUTTONS_OK, "%s", title);
|
||||
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), "%s", msg);
|
||||
::gtk_window_set_icon_from_file(GTK_WINDOW(dialog), (Directories::getDataDir() + CString("/applications/designer/designer.ico")).toASCIIString(),
|
||||
nullptr);
|
||||
gtk_window_set_title(GTK_WINDOW(dialog), title);
|
||||
gtk_dialog_run(GTK_DIALOG(dialog));
|
||||
gtk_widget_destroy(dialog);
|
||||
}
|
||||
|
||||
void user_info(char** argv, Kernel::ILogManager* logManager)
|
||||
{
|
||||
const std::vector<std::string> messages =
|
||||
{
|
||||
"Syntax : " + std::string(argv[0]) + " [ switches ]\n",
|
||||
"Possible switches :\n",
|
||||
" --help : displays this help message and exits\n",
|
||||
" --config filename : path to config file\n",
|
||||
" --define token value : specify configuration token with a given value\n",
|
||||
" --open filename : opens a scenario (see also --no-session-management)\n",
|
||||
" --play filename : plays the opened scenario (see also --no-session-management)\n",
|
||||
" --play-fast filename : plays fast forward the opened scenario (see also --no-session-management)\n",
|
||||
" --no-gui : hides the " DESIGNER_NAME " graphical user interface (assumes --no-color-depth-test)\n",
|
||||
" --no-visualization : hides the visualisation widgets\n",
|
||||
" --invisible : hides the designer and the visualisation widgets (assumes --no-check-color-depth and --no-session-management)\n",
|
||||
" --no-check-color-depth : does not check 24/32 bits color depth\n",
|
||||
" --no-session-management : neither restore last used scenarios nor saves them at exit\n",
|
||||
" --random-seed uint : initialize random number generator with value, default=time(nullptr)\n"
|
||||
};
|
||||
|
||||
if (logManager != nullptr) { for (const auto& m : messages) { (*logManager) << Kernel::LogLevel_Info << m; } }
|
||||
else { for (const auto& m : messages) { std::cout << m; } }
|
||||
}
|
||||
|
||||
int go(int argc, char** argv)
|
||||
{
|
||||
bool errorWhileLoadingScenario = false, playRequested = false;
|
||||
/*
|
||||
{ 0, 0, 0, 0 },
|
||||
{ 0, 16383, 16383, 16383 },
|
||||
{ 0, 32767, 32767, 32767 },
|
||||
{ 0, 49151, 49151, 49151 },
|
||||
{ 0, 65535, 65535, 65535 },
|
||||
*/
|
||||
#define GDK_COLOR_SET(c, r, g, b) { (c).pixel=0; (c).red=r; (c).green=g; (c).blue=b; }
|
||||
GDK_COLOR_SET(gColors[Color_BackgroundPlayerStarted], 32767, 32767, 32767);
|
||||
GDK_COLOR_SET(gColors[Color_BoxBackgroundSelected], 65535, 65535, 49151);
|
||||
GDK_COLOR_SET(gColors[Color_BoxBackgroundMissing], 49151, 32767, 32767);
|
||||
GDK_COLOR_SET(gColors[Color_BoxBackgroundDisabled], 46767, 46767, 59151);
|
||||
GDK_COLOR_SET(gColors[Color_BoxBackgroundDeprecated], 65535, 50000, 32767);
|
||||
GDK_COLOR_SET(gColors[Color_BoxBackgroundOutdated], 57343, 57343, 57343);
|
||||
GDK_COLOR_SET(gColors[Color_BoxBackgroundMetabox], 58343, 65535, 62343);
|
||||
GDK_COLOR_SET(gColors[Color_BoxBackgroundUnstable], 49151, 49151, 49151);
|
||||
GDK_COLOR_SET(gColors[Color_BoxBackground], 65535, 65535, 65535);
|
||||
GDK_COLOR_SET(gColors[Color_BoxBorderSelected], 0, 0, 0);
|
||||
GDK_COLOR_SET(gColors[Color_BoxBorder], 0, 0, 0);
|
||||
GDK_COLOR_SET(gColors[Color_BoxInputBackground], 65535, 49151, 32767);
|
||||
GDK_COLOR_SET(gColors[Color_BoxInputBorder], 16383, 16383, 16383);
|
||||
GDK_COLOR_SET(gColors[Color_BoxOutputBackground], 32767, 65535, 49151);
|
||||
GDK_COLOR_SET(gColors[Color_BoxOutputBorder], 16383, 16383, 16383);
|
||||
GDK_COLOR_SET(gColors[Color_BoxSettingBackground], 49151, 32767, 65535);
|
||||
GDK_COLOR_SET(gColors[Color_BoxSettingBorder], 16383, 16383, 16383);
|
||||
|
||||
GDK_COLOR_SET(gColors[Color_CommentBackground], 65535, 65535, 57343);
|
||||
GDK_COLOR_SET(gColors[Color_CommentBackgroundSelected], 65535, 65535, 49151);
|
||||
GDK_COLOR_SET(gColors[Color_CommentBorder], 32767, 32767, 32767);
|
||||
GDK_COLOR_SET(gColors[Color_CommentBorderSelected], 32767, 32767, 32767);
|
||||
|
||||
GDK_COLOR_SET(gColors[Color_Link], 0, 0, 0);
|
||||
GDK_COLOR_SET(gColors[Color_LinkSelected], 49151, 49151, 16383);
|
||||
GDK_COLOR_SET(gColors[Color_LinkUpCast], 32767, 16383, 16383);
|
||||
GDK_COLOR_SET(gColors[Color_LinkDownCast], 16383, 32767, 16383);
|
||||
GDK_COLOR_SET(gColors[Color_LinkInvalid], 49151, 16383, 16383);
|
||||
GDK_COLOR_SET(gColors[Color_SelectionArea], 0x3f00, 0x3f00, 0x3f00);
|
||||
GDK_COLOR_SET(gColors[Color_SelectionAreaBorder], 0, 0, 0);
|
||||
#undef GDK_COLOR_SET
|
||||
//___________________________________________________________________//
|
||||
// //
|
||||
|
||||
config_t config;
|
||||
bool bArgParseResult = parse_arguments(argc, argv, config);
|
||||
if (!bArgParseResult)
|
||||
{
|
||||
if (config.help)
|
||||
{
|
||||
user_info(argv, nullptr);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
CKernelLoader loader;
|
||||
|
||||
std::cout << "[ INF ] Created kernel loader, trying to load kernel module" << "\n";
|
||||
CString errorMsg;
|
||||
#if defined TARGET_OS_Windows
|
||||
CString file = Directories::getLibDir() + "/openvibe-kernel.dll";
|
||||
#elif defined TARGET_OS_Linux
|
||||
CString file = Directories::getLibDir() + "/libopenvibe-kernel.so";
|
||||
#elif defined TARGET_OS_MacOS
|
||||
CString file = Directories::getLibDir() + "/libopenvibe-kernel.dylib";
|
||||
#endif
|
||||
if (!loader.load(file, &errorMsg)) { std::cout << "[ FAILED ] Error loading kernel (" << errorMsg << ")" << " from [" << file << "]\n"; }
|
||||
else
|
||||
{
|
||||
std::cout << "[ INF ] Kernel module loaded, trying to get kernel descriptor" << "\n";
|
||||
Kernel::IKernelDesc* desc = nullptr;
|
||||
Kernel::IKernelContext* context = nullptr;
|
||||
loader.initialize();
|
||||
loader.getKernelDesc(desc);
|
||||
if (desc == nullptr) { std::cout << "[ FAILED ] No kernel descriptor" << "\n"; }
|
||||
else
|
||||
{
|
||||
std::cout << "[ INF ] Got kernel descriptor, trying to create kernel" << "\n";
|
||||
|
||||
context = desc->createKernel("designer", Directories::getDataDir() + "/kernel/openvibe.conf");
|
||||
context->initialize();
|
||||
context->getConfigurationManager().addConfigurationFromFile(Directories::getDataDir() + "/applications/designer/designer.conf");
|
||||
CString appConfigFile = context->getConfigurationManager().expand("${Designer_CustomConfigurationFile}");
|
||||
context->getConfigurationManager().addConfigurationFromFile(appConfigFile);
|
||||
// add other configuration file if --config option
|
||||
auto it = config.flags.begin();
|
||||
|
||||
// initialize random number generator with nullptr by default
|
||||
System::Math::initializeRandomMachine(time(nullptr));
|
||||
|
||||
while (it != config.flags.end())
|
||||
{
|
||||
if (it->first == CommandLineFlag_Config)
|
||||
{
|
||||
appConfigFile = CString(it->second.c_str());
|
||||
context->getConfigurationManager().addConfigurationFromFile(appConfigFile);
|
||||
}
|
||||
else if (it->first == CommandLineFlag_RandomSeed)
|
||||
{
|
||||
const size_t seed = size_t(strtol(it->second.c_str(), nullptr, 10));
|
||||
System::Math::initializeRandomMachine(seed);
|
||||
}
|
||||
++it;
|
||||
}
|
||||
|
||||
|
||||
if (context == nullptr) { std::cout << "[ FAILED ] No kernel created by kernel descriptor" << "\n"; }
|
||||
else
|
||||
{
|
||||
Toolkit::initialize(*context);
|
||||
VisualizationToolkit::initialize(*context);
|
||||
|
||||
//initialise Gtk before 3D context
|
||||
gtk_init(&argc, &argv);
|
||||
// gtk_rc_parse(Directories::getDataDir() + "/applications/designer/interface.gtkrc");
|
||||
|
||||
|
||||
#if defined OPENVIBE_SPLASHSCREEN
|
||||
GtkWidget* splashScreenWindow = gtk_window_new(GTK_WINDOW_POPUP);
|
||||
gtk_window_set_position(GTK_WINDOW(splashScreenWindow), GTK_WIN_POS_CENTER);
|
||||
gtk_window_set_type_hint(GTK_WINDOW(splashScreenWindow), GDK_WINDOW_TYPE_HINT_SPLASHSCREEN);
|
||||
gtk_window_set_default_size(GTK_WINDOW(splashScreenWindow), 600, 400);
|
||||
GtkWidget* splashScreenImage = gtk_image_new_from_file(Directories::getDataDir() + "/applications/designer/splashscreen.png");
|
||||
gtk_container_add(GTK_CONTAINER(splashScreenWindow), (splashScreenImage));
|
||||
gtk_widget_show(splashScreenImage);
|
||||
gtk_widget_show(splashScreenWindow);
|
||||
g_timeout_add(500, cb_remove_splashscreen, splashScreenWindow);
|
||||
|
||||
while (gtk_events_pending()) { gtk_main_iteration(); }
|
||||
#endif
|
||||
|
||||
Kernel::IConfigurationManager& configMgr = context->getConfigurationManager();
|
||||
Kernel::ILogManager& logMgr = context->getLogManager();
|
||||
|
||||
bArgParseResult = parse_arguments(argc, argv, config);
|
||||
|
||||
context->getPluginManager().addPluginsFromFiles(configMgr.expand("${Kernel_Plugins}"));
|
||||
|
||||
//FIXME : set locale only when needed
|
||||
CString locale = configMgr.expand("${Designer_Locale}");
|
||||
if (locale == CString("")) { locale = "C"; }
|
||||
setlocale(LC_ALL, locale.toASCIIString());
|
||||
|
||||
if (!(bArgParseResult || config.help)) { user_info(argv, &logMgr); }
|
||||
else
|
||||
{
|
||||
if ((!configMgr.expandAsBoolean("${Kernel_WithGUI}", true)) && ((config.getFlags() & CommandLineFlag_NoGui) == 0))
|
||||
{
|
||||
logMgr << Kernel::LogLevel_ImportantWarning <<
|
||||
"${Kernel_WithGUI} is set to false and --no-gui flag not set. Forcing the --no-gui flag\n";
|
||||
config.noGui = CommandLineFlag_NoGui;
|
||||
config.noCheckColorDepth = CommandLineFlag_NoCheckColorDepth;
|
||||
config.noManageSession = CommandLineFlag_NoManageSession;
|
||||
}
|
||||
|
||||
if (config.noGui != CommandLineFlag_NoGui && !ensureOneInstanceOfDesigner(config, logMgr))
|
||||
{
|
||||
logMgr << Kernel::LogLevel_Trace << "An instance of Designer is already running.\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
{
|
||||
CApplication app(*context);
|
||||
app.initialize(config.getFlags());
|
||||
|
||||
// FIXME is it necessary to keep next line uncomment ?
|
||||
//bool isScreenValid=true;
|
||||
if (config.noCheckColorDepth == 0)
|
||||
{
|
||||
if (GDK_IS_DRAWABLE(GTK_WIDGET(app.m_MainWindow)->window))
|
||||
{
|
||||
// FIXME is it necessary to keep next line uncomment ?
|
||||
//isScreenValid=false;
|
||||
switch (gdk_drawable_get_depth(GTK_WIDGET(app.m_MainWindow)->window))
|
||||
{
|
||||
case 24:
|
||||
case 32:
|
||||
// FIXME is it necessary to keep next line uncomment ?
|
||||
//isScreenValid=true;
|
||||
break;
|
||||
default:
|
||||
logMgr << Kernel::LogLevel_Error << "Please change the color depth of your screen to either 24 or 32 bits\n";
|
||||
// TODO find a way to break
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add or replace a configuration token if required in command line
|
||||
for (const auto& t : config.tokens)
|
||||
{
|
||||
logMgr << Kernel::LogLevel_Trace << "Adding command line configuration token [" << t.first << " = " << t.second << "]\n";
|
||||
configMgr.addOrReplaceConfigurationToken(t.first.c_str(), t.second.c_str());
|
||||
}
|
||||
|
||||
for (const auto& f : config.flags)
|
||||
{
|
||||
std::string fileName = f.second;
|
||||
std::transform(fileName.begin(), fileName.end(), fileName.begin(), backslash_to_slash);
|
||||
bool error;
|
||||
switch (f.first)
|
||||
{
|
||||
case CommandLineFlag_Open:
|
||||
logMgr << Kernel::LogLevel_Info << "Opening scenario [" << fileName << "]\n";
|
||||
if (!app.openScenario(fileName.c_str()))
|
||||
{
|
||||
logMgr << Kernel::LogLevel_Error << "Could not open scenario " << fileName << "\n";
|
||||
errorWhileLoadingScenario = config.noGui == CommandLineFlag_NoGui;
|
||||
}
|
||||
break;
|
||||
case CommandLineFlag_Play:
|
||||
logMgr << Kernel::LogLevel_Info << "Opening and playing scenario [" << fileName << "]\n";
|
||||
error = !app.openScenario(fileName.c_str());
|
||||
if (!error)
|
||||
{
|
||||
app.playScenarioCB();
|
||||
error = app.getCurrentInterfacedScenario()->m_PlayerStatus != Kernel::EPlayerStatus::Play;
|
||||
}
|
||||
if (error)
|
||||
{
|
||||
logMgr << Kernel::LogLevel_Error << "Scenario open or load error with --play.\n";
|
||||
errorWhileLoadingScenario = config.noGui == CommandLineFlag_NoGui;
|
||||
}
|
||||
break;
|
||||
case CommandLineFlag_PlayFast:
|
||||
logMgr << Kernel::LogLevel_Info << "Opening and fast playing scenario [" << fileName << "]\n";
|
||||
error = !app.openScenario(fileName.c_str());
|
||||
if (!error)
|
||||
{
|
||||
app.forwardScenarioCB();
|
||||
error = app.getCurrentInterfacedScenario()->m_PlayerStatus != Kernel::EPlayerStatus::Forward;
|
||||
}
|
||||
if (error)
|
||||
{
|
||||
logMgr << Kernel::LogLevel_Error << "Scenario open or load error with --play-fast.\n";
|
||||
errorWhileLoadingScenario = config.noGui == CommandLineFlag_NoGui;
|
||||
}
|
||||
playRequested = true;
|
||||
break;
|
||||
//case CommandLineFlag_Define:
|
||||
//break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!playRequested && config.noGui == CommandLineFlag_NoGui)
|
||||
{
|
||||
logMgr << Kernel::LogLevel_Info
|
||||
<< "Switch --no-gui is enabled but no play operation was requested. Designer will exit automatically.\n";
|
||||
}
|
||||
|
||||
if (app.m_Scenarios.empty() && config.noGui != CommandLineFlag_NoGui) { app.newScenarioCB(); }
|
||||
|
||||
if (!app.m_Scenarios.empty())
|
||||
{
|
||||
CPluginObjectDescCollector cbCollector1(*context);
|
||||
CPluginObjectDescCollector cbCollector2(*context);
|
||||
CPluginObjectDescLogger cbLogger(*context);
|
||||
cbLogger.enumeratePluginObjectDesc();
|
||||
cbCollector1.enumeratePluginObjectDesc(OV_ClassId_Plugins_BoxAlgorithmDesc);
|
||||
cbCollector2.enumeratePluginObjectDesc(OV_ClassId_Plugins_AlgorithmDesc);
|
||||
InsertPluginObjectDescToGtkTreeStore(*context, cbCollector1.getPluginObjectDescMap(), app.m_BoxAlgorithmTreeModel, app.m_NewBoxes,
|
||||
app.m_UpdatedBoxes, app.m_IsNewVersion);
|
||||
InsertPluginObjectDescToGtkTreeStore(*context, cbCollector2.getPluginObjectDescMap(), app.m_AlgorithmTreeModel, app.m_NewBoxes,
|
||||
app.m_UpdatedBoxes);
|
||||
|
||||
std::map<std::string, const Plugins::IPluginObjectDesc*> metaboxDescMap;
|
||||
CIdentifier id;
|
||||
while ((id = context->getMetaboxManager().getNextMetaboxObjectDescIdentifier(id)) != CIdentifier::undefined()
|
||||
) { metaboxDescMap[id.str()] = context->getMetaboxManager().getMetaboxObjectDesc(id); }
|
||||
InsertPluginObjectDescToGtkTreeStore(*context, metaboxDescMap, app.m_BoxAlgorithmTreeModel, app.m_NewBoxes, app.m_UpdatedBoxes,
|
||||
app.m_IsNewVersion);
|
||||
|
||||
context->getLogManager() << Kernel::LogLevel_Info << "Initialization took "
|
||||
<< context->getConfigurationManager().expand("$Core{real-time}") << " ms\n";
|
||||
// If the application is a newly launched version, and not launched without GUI -> display changelog
|
||||
if (app.m_IsNewVersion && config.noGui != CommandLineFlag_NoGui) { app.displayChangelogWhenAvailable(); }
|
||||
try { gtk_main(); }
|
||||
catch (DesignerException& ex)
|
||||
{
|
||||
std::cerr << "Caught designer exception" << std::endl;
|
||||
GtkWidget* errorDialog = gtk_message_dialog_new(nullptr, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
|
||||
"%s", ex.getErrorString().c_str());
|
||||
gtk_window_set_title(GTK_WINDOW(errorDialog), (std::string(BRAND_NAME) + " has stopped functioning").c_str());
|
||||
gtk_dialog_run(GTK_DIALOG(errorDialog));
|
||||
}
|
||||
catch (...) { std::cerr << "Caught top level exception" << std::endl; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logMgr << Kernel::LogLevel_Info << "Application terminated, releasing allocated objects\n";
|
||||
|
||||
VisualizationToolkit::uninitialize(*context);
|
||||
Toolkit::uninitialize(*context);
|
||||
|
||||
desc->releaseKernel(context);
|
||||
|
||||
// Remove the mutex only if the application was run with a gui
|
||||
if (config.noGui != CommandLineFlag_NoGui) { boost::interprocess::named_mutex::remove(MUTEX_NAME); }
|
||||
}
|
||||
}
|
||||
loader.uninitialize();
|
||||
loader.unload();
|
||||
}
|
||||
return errorWhileLoadingScenario ? -1 : 0;
|
||||
}
|
||||
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
|
||||
int main(const int argc, char** argv)
|
||||
{
|
||||
// Remove mutex at startup, as the main loop regenerates frequently this mutex,
|
||||
// if another instance is running, it should have the time to regenerate it
|
||||
// Avoids that after crashing, a mutex stays blocking
|
||||
boost::interprocess::named_mutex::remove(MUTEX_NAME);
|
||||
try { OpenViBE::Designer::go(argc, argv); }
|
||||
catch (...) { std::cout << "Caught an exception at the very top...\nLeaving application!\n"; }
|
||||
//return go(argc, argv);
|
||||
}
|
||||
|
||||
#if defined TARGET_OS_Windows
|
||||
// Should be used once we get rid of the .cmd launchers
|
||||
int WINAPI WinMain(HINSTANCE /*instance*/, HINSTANCE /*prevInstance*/, LPSTR /*cmdLine*/, int /*windowStyle*/) { return main(__argc, __argv); }
|
||||
#endif //defined TARGET_OS_Windows
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
#include "ovdCVisualizationTree.h"
|
||||
#include "ovdCVisualizationManager.h"
|
||||
|
||||
#if defined TARGET_OS_Windows
|
||||
#include <gdk/gdkwin32.h>
|
||||
#elif defined TARGET_OS_Linux
|
||||
#include <gdk/gdkx.h>
|
||||
#elif defined TARGET_OS_MacOS
|
||||
#define Cursor XCursor
|
||||
#include <gdk/gdkx.h>
|
||||
#undef Cursor
|
||||
#else
|
||||
#endif
|
||||
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
using IVTTree = VisualizationToolkit::IVisualizationTree;
|
||||
|
||||
bool CVisualizationManager::createVisualizationTree(CIdentifier& treeID)
|
||||
{
|
||||
IVTTree* newTree = new CVisualizationTree(m_kernelCtx);
|
||||
treeID = getUnusedIdentifier();
|
||||
m_trees[treeID] = newTree;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVisualizationManager::releaseVisualizationTree(const CIdentifier& treeID)
|
||||
{
|
||||
auto it = m_trees.find(treeID);
|
||||
if (it != m_trees.end())
|
||||
{
|
||||
delete it->second;
|
||||
m_trees.erase(it);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
IVTTree& CVisualizationManager::getVisualizationTree(const CIdentifier& id)
|
||||
{
|
||||
const auto it = m_trees.find(id);
|
||||
if (it == m_trees.end()) { m_kernelCtx.getLogManager() << Kernel::LogLevel_Fatal << "Visualization Tree " << id << " does not exist !\n"; }
|
||||
return *it->second;
|
||||
}
|
||||
|
||||
bool CVisualizationManager::setToolbar(const CIdentifier& treeID, const CIdentifier& boxID, GtkWidget* toolbar)
|
||||
{
|
||||
IVTTree& tree = getVisualizationTree(treeID);
|
||||
tree.setToolbar(boxID, toolbar);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVisualizationManager::setWidget(const CIdentifier& treeID, const CIdentifier& boxID, GtkWidget* topmostWidget)
|
||||
{
|
||||
IVTTree& tree = getVisualizationTree(treeID);
|
||||
tree.setWidget(boxID, topmostWidget);
|
||||
return true;
|
||||
}
|
||||
|
||||
CIdentifier CVisualizationManager::getUnusedIdentifier() const
|
||||
{
|
||||
uint64_t id = CIdentifier::random().id();
|
||||
CIdentifier res;
|
||||
std::map<CIdentifier, IVTTree*>::const_iterator it;
|
||||
do
|
||||
{
|
||||
res = CIdentifier(id++);
|
||||
it = m_trees.find(res);
|
||||
} while (it != m_trees.end() || res == CIdentifier::undefined());
|
||||
return res;
|
||||
}
|
||||
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <openvibe/ov_all.h>
|
||||
#include <map>
|
||||
|
||||
#include <visualization-toolkit/ovvizIVisualizationManager.h>
|
||||
#include <visualization-toolkit/ovvizIVisualizationTree.h>
|
||||
|
||||
typedef struct _GtkWidget GtkWidget;
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
class CVisualizationManager final : public VisualizationToolkit::IVisualizationManager
|
||||
{
|
||||
public:
|
||||
|
||||
explicit CVisualizationManager(const Kernel::IKernelContext& ctx) : m_kernelCtx(ctx) {}
|
||||
~CVisualizationManager() override = default;
|
||||
|
||||
bool createVisualizationTree(CIdentifier& treeID) override;
|
||||
bool releaseVisualizationTree(const CIdentifier& treeID) override;
|
||||
VisualizationToolkit::IVisualizationTree& getVisualizationTree(const CIdentifier& id) override;
|
||||
|
||||
bool setToolbar(const CIdentifier& treeID, const CIdentifier& boxID, GtkWidget* toolbar) override;
|
||||
bool setWidget(const CIdentifier& treeID, const CIdentifier& boxID, GtkWidget* topmostWidget) override;
|
||||
|
||||
private:
|
||||
|
||||
CIdentifier getUnusedIdentifier() const;
|
||||
|
||||
/// Map of visualization trees (one per scenario, storing visualization widgets arrangement in space)
|
||||
std::map<CIdentifier, VisualizationToolkit::IVisualizationTree*> m_trees;
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
};
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+930
@@ -0,0 +1,930 @@
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <json/json.h>
|
||||
|
||||
#include "ovdCVisualizationTree.h"
|
||||
#include "ovdCVisualizationWidget.h"
|
||||
#include "../ovdAssert.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
using EVTColumn = VisualizationToolkit::EVisualizationTreeColumn;
|
||||
using EVTNode = VisualizationToolkit::EVisualizationTreeNode;
|
||||
using EVTWidget = VisualizationToolkit::EVisualizationWidget;
|
||||
using IVTWidget = VisualizationToolkit::IVisualizationWidget;
|
||||
using IVTTree = VisualizationToolkit::IVisualizationTree;
|
||||
|
||||
namespace {
|
||||
template <class T>
|
||||
struct STestTrue
|
||||
{
|
||||
bool operator()(typename std::map<CIdentifier, T*>::const_iterator /*it*/) const { return true; }
|
||||
};
|
||||
|
||||
struct STestEqVisualizationWidgetType
|
||||
{
|
||||
STestEqVisualizationWidgetType(const EVTWidget widgetType) : type(widgetType) { }
|
||||
|
||||
bool operator()(const std::map<CIdentifier, IVTWidget*>::const_iterator& it) const { return it->second->getType() == type; }
|
||||
|
||||
EVTWidget type;
|
||||
};
|
||||
|
||||
template <class T, class TTest>
|
||||
bool getNextID(const std::map<CIdentifier, T*>& ids, CIdentifier& id, const TTest& test)
|
||||
{
|
||||
typename std::map<CIdentifier, T*>::const_iterator it;
|
||||
|
||||
if (id == CIdentifier::undefined()) { it = ids.begin(); }
|
||||
else
|
||||
{
|
||||
it = ids.find(id);
|
||||
if (it == ids.end())
|
||||
{
|
||||
id = CIdentifier::undefined();
|
||||
return false;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
|
||||
while (it != ids.end())
|
||||
{
|
||||
if (test(it))
|
||||
{
|
||||
id = it->first;
|
||||
return true;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
CVisualizationTree::~CVisualizationTree()
|
||||
{
|
||||
for (auto& widget : m_widgets) { delete widget.second; }
|
||||
g_object_unref(m_treeStore);
|
||||
}
|
||||
|
||||
bool CVisualizationTree::init(const Kernel::IScenario* scenario)
|
||||
{
|
||||
m_scenario = scenario;
|
||||
//create tree store
|
||||
m_treeStore = gtk_tree_store_new(5, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_ULONG, G_TYPE_STRING, G_TYPE_POINTER);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::getNextVisualizationWidgetIdentifier(CIdentifier& id) const
|
||||
{
|
||||
return getNextID<IVTWidget, STestTrue<IVTWidget>>(m_widgets, id, STestTrue<IVTWidget>());
|
||||
}
|
||||
|
||||
bool CVisualizationTree::getNextVisualizationWidgetIdentifier(CIdentifier& id, const EVTWidget type) const
|
||||
{
|
||||
return getNextID<IVTWidget, STestEqVisualizationWidgetType>(m_widgets, id, STestEqVisualizationWidgetType(type));
|
||||
}
|
||||
|
||||
bool CVisualizationTree::isVisualizationWidget(const CIdentifier& id) const { return m_widgets.find(id) != m_widgets.end(); }
|
||||
|
||||
IVTWidget* CVisualizationTree::getVisualizationWidget(const CIdentifier& id) const
|
||||
{
|
||||
const auto it = m_widgets.find(id);
|
||||
if (it == m_widgets.end()) { return nullptr; }
|
||||
return it->second;
|
||||
}
|
||||
|
||||
IVTWidget* CVisualizationTree::getVisualizationWidgetFromBoxIdentifier(const CIdentifier& boxID) const
|
||||
{
|
||||
for (auto& widget : m_widgets) { if (widget.second->getBoxIdentifier() == boxID) { return widget.second; } }
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::addVisualizationWidget(CIdentifier& id, const CString& name, const EVTWidget type, const CIdentifier& parentID,
|
||||
const size_t parentIdx, const CIdentifier& boxID, const size_t nChild, const CIdentifier& suggestedID)
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Debug << "Adding new visualization widget\n";
|
||||
|
||||
//create new widget
|
||||
IVTWidget* widget = new CVisualizationWidget(m_kernelCtx);
|
||||
id = getUnusedIdentifier(suggestedID);
|
||||
|
||||
if (!widget->initialize(id, name, type, parentID, boxID, nChild))
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Error << "Failed to add new visualization widget (couldn't initialize it)\n";
|
||||
delete widget;
|
||||
return false;
|
||||
}
|
||||
|
||||
// assign a parent to it
|
||||
if (parentID != CIdentifier::undefined())
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Debug << "Parenting visualization widget\n";
|
||||
IVTWidget* parentWidget = getVisualizationWidget(parentID);
|
||||
|
||||
if (parentWidget != nullptr)
|
||||
{
|
||||
if (parentWidget->getType() == EVTWidget::Window)
|
||||
{
|
||||
//extend number of children of parent window if necessary
|
||||
if (parentWidget->getNbChildren() <= parentIdx)
|
||||
{
|
||||
for (size_t i = parentWidget->getNbChildren(); i <= parentIdx; ++i) { parentWidget->addChild(CIdentifier::undefined()); }
|
||||
}
|
||||
}
|
||||
|
||||
if (!parentWidget->setChildIdentifier(parentIdx, id))
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Error <<
|
||||
"Failed to add new visualization widget (couldn't set child identifier in parent window)\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Error << "Failed to add new visualization widget (couldn't find parent)\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//add it to widgets map
|
||||
m_widgets[id] = widget;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::getVisualizationWidgetIndex(const CIdentifier& id, size_t& index) const
|
||||
{
|
||||
IVTWidget* visualizationWidget = getVisualizationWidget(id);
|
||||
if (!visualizationWidget)
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Error << "Failed to get widget.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
const CIdentifier& parentIdentifier = visualizationWidget->getParentIdentifier();
|
||||
if (parentIdentifier == CIdentifier::undefined())
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Error << "Failed to get parent identifier widget\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
IVTWidget* parentVisualizationWidget = getVisualizationWidget(parentIdentifier);
|
||||
if (!parentVisualizationWidget)
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Error << "Failed to unparent visualization widget (couldn't find parent)\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
parentVisualizationWidget->getChildIndex(id, index);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::destroyHierarchy(const CIdentifier& id, const bool destroyVisualizationBoxes)
|
||||
{
|
||||
bool res = true;
|
||||
|
||||
IVTWidget* visualizationWidget = getVisualizationWidget(id);
|
||||
|
||||
//is hierarchy top item a window?
|
||||
if (visualizationWidget->getType() == EVTWidget::Window)
|
||||
{
|
||||
CIdentifier childIdentifier;
|
||||
for (size_t i = 0; i < visualizationWidget->getNbChildren(); ++i)
|
||||
{
|
||||
visualizationWidget->getChildIdentifier(i, childIdentifier);
|
||||
res &= destroyHierarchyR(childIdentifier, destroyVisualizationBoxes);
|
||||
}
|
||||
|
||||
//delete this window in kernel factory and erase its slot in map
|
||||
delete visualizationWidget;
|
||||
const auto it = m_widgets.find(id);
|
||||
m_widgets.erase(it);
|
||||
}
|
||||
else //top item is a widget
|
||||
{
|
||||
size_t index;
|
||||
unparentVisualizationWidget(id, index);
|
||||
destroyHierarchyR(id, destroyVisualizationBoxes);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::destroyHierarchyR(const CIdentifier& id, const bool destroy)
|
||||
{
|
||||
IVTWidget* widget = getVisualizationWidget(id);
|
||||
if (!widget) { return false; }
|
||||
|
||||
//remove children
|
||||
CIdentifier childID;
|
||||
const size_t nChildren = widget->getNbChildren();
|
||||
for (size_t i = 0; i < nChildren; ++i)
|
||||
{
|
||||
widget->getChildIdentifier(i, childID);
|
||||
destroyHierarchyR(childID, destroy);
|
||||
}
|
||||
|
||||
//if parent widget is a window, remove this widget from it
|
||||
if (widget->getType() == EVTWidget::Panel)
|
||||
{
|
||||
IVTWidget* window = getVisualizationWidget(widget->getParentIdentifier());
|
||||
if (window != nullptr) { window->removeChild(id); }
|
||||
}
|
||||
|
||||
//if this widget is a visualization box and they are to be unaffected
|
||||
if (widget->getType() == EVTWidget::Box && !destroy)
|
||||
{
|
||||
size_t index;
|
||||
unparentVisualizationWidget(id, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Debug << "Deleting visualization widget\n";
|
||||
delete widget;
|
||||
const auto it = m_widgets.find(id);
|
||||
m_widgets.erase(it);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::unparentVisualizationWidget(const CIdentifier& id, size_t& index)
|
||||
{
|
||||
//retrieve widget to be unparented
|
||||
IVTWidget* widget = getVisualizationWidget(id);
|
||||
if (widget == nullptr) { return false; }
|
||||
|
||||
//get its parent identifier
|
||||
const CIdentifier& parentID = widget->getParentIdentifier();
|
||||
if (parentID == CIdentifier::undefined()) { return true; }
|
||||
|
||||
//unparent widget
|
||||
widget->setParentIdentifier(CIdentifier::undefined());
|
||||
|
||||
//retrieve parent and remove widget from its children list
|
||||
IVTWidget* parentWidget = getVisualizationWidget(parentID);
|
||||
if (parentWidget != nullptr)
|
||||
{
|
||||
parentWidget->getChildIndex(id, index);
|
||||
parentWidget->removeChild(id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::parentVisualizationWidget(const CIdentifier& id, const CIdentifier& parentID, const size_t index)
|
||||
{
|
||||
if (parentID == CIdentifier::undefined()) { return false; }
|
||||
|
||||
//retrieve widget to be parented
|
||||
IVTWidget* widget = getVisualizationWidget(id);
|
||||
if (!widget) { return false; }
|
||||
|
||||
widget->setParentIdentifier(parentID);
|
||||
|
||||
//retrieve its parent
|
||||
IVTWidget* parentWidget = getVisualizationWidget(parentID);
|
||||
if (!parentWidget)
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Error << "Failed to parent visualization widget (couldn't find parent)\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
parentWidget->setChildIdentifier(index, id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
CIdentifier CVisualizationTree::getUnusedIdentifier(const CIdentifier& suggestedID) const
|
||||
{
|
||||
uint64_t id = (uint64_t(rand()) << 32) + uint64_t(rand());
|
||||
if (suggestedID != CIdentifier::undefined()) { id = suggestedID.id() - 1; }
|
||||
|
||||
CIdentifier result;
|
||||
std::map<CIdentifier, IVTWidget*>::const_iterator i;
|
||||
do
|
||||
{
|
||||
id++;
|
||||
result = CIdentifier(id);
|
||||
i = m_widgets.find(result);
|
||||
} while (i != m_widgets.end() || result == CIdentifier::undefined());
|
||||
return result;
|
||||
}
|
||||
|
||||
GtkTreeView* CVisualizationTree::createTreeViewWithModel() { return GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(m_treeStore))); }
|
||||
|
||||
bool CVisualizationTree::setTreeViewCB(VisualizationToolkit::ITreeViewCB* callback)
|
||||
{
|
||||
m_treeViewCB = callback;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::reloadTree()
|
||||
{
|
||||
if (!m_treeViewCB) { return false; }
|
||||
|
||||
//clear current tree
|
||||
GtkTreeIter iter;
|
||||
while (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(m_treeStore), &iter, nullptr, 0) != FALSE) { gtk_tree_store_remove(m_treeStore, &iter); }
|
||||
//create 'unaffected display plugins' node
|
||||
gtk_tree_store_append(m_treeStore, &iter, nullptr);
|
||||
gtk_tree_store_set(m_treeStore, &iter,
|
||||
EVTColumn::StringName, "Unaffected display plugins",
|
||||
EVTColumn::StringStockIcon, m_treeViewCB->getTreeWidgetIcon(EVTNode::Unaffected),
|
||||
EVTColumn::ULongNodeType, static_cast<unsigned long>(EVTNode::Unaffected),
|
||||
EVTColumn::StringIdentifier, CIdentifier::undefined().str().c_str(), -1);
|
||||
|
||||
//reload unaffected visualization boxes
|
||||
CIdentifier id = CIdentifier::undefined();
|
||||
while (getNextVisualizationWidgetIdentifier(id, EVTWidget::Box))
|
||||
{
|
||||
IVTWidget* widget = getVisualizationWidget(id);
|
||||
//load widget if it doesn't have a parent (== is unaffected)
|
||||
if (widget->getParentIdentifier() == CIdentifier::undefined()) { loadVisualizationWidget(widget, &iter); }
|
||||
}
|
||||
|
||||
//reload visualization windows
|
||||
id = CIdentifier::undefined();
|
||||
while (getNextVisualizationWidgetIdentifier(id, EVTWidget::Window)) { loadVisualizationWidget(getVisualizationWidget(id), nullptr); }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//Tree helper functions
|
||||
//---------------------
|
||||
|
||||
bool CVisualizationTree::getTreeSelection(GtkTreeView* preeView, GtkTreeIter* iter)
|
||||
{
|
||||
GtkTreeSelection* treeSelection = gtk_tree_view_get_selection(preeView);
|
||||
GtkTreeModel* treeModel = GTK_TREE_MODEL(m_treeStore);
|
||||
return gtk_tree_selection_get_selected(treeSelection, &treeModel, iter) != 0;
|
||||
}
|
||||
|
||||
GtkTreePath* CVisualizationTree::getTreePath(GtkTreeIter* iter) const
|
||||
{
|
||||
return (iter == nullptr) ? nullptr : gtk_tree_model_get_path(GTK_TREE_MODEL(m_treeStore), iter);
|
||||
}
|
||||
|
||||
size_t CVisualizationTree::getULongValueFromTreeIter(GtkTreeIter* iter, const EVTColumn colType) const
|
||||
{
|
||||
size_t value = 0;
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(m_treeStore), iter, colType, &value, -1);
|
||||
return value;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::getStringValueFromTreeIter(GtkTreeIter* iter, char*& string, const EVTColumn colType) const
|
||||
{
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(m_treeStore), iter, colType, &string, -1);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::getPointerValueFromTreeIter(GtkTreeIter* iter, void*& pointer, const EVTColumn colType) const
|
||||
{
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(m_treeStore), iter, colType, &pointer, -1);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::getIdentifierFromTreeIter(GtkTreeIter* iter, CIdentifier& id, const EVTColumn colType) const
|
||||
{
|
||||
char* str = nullptr;
|
||||
getStringValueFromTreeIter(iter, str, colType);
|
||||
id.fromString(CString(str));
|
||||
return true;
|
||||
}
|
||||
|
||||
//looks for a tree node named 'label' of class 'type' from tree root
|
||||
bool CVisualizationTree::findChildNodeFromRoot(GtkTreeIter* iter, const char* label, const EVTNode type)
|
||||
{
|
||||
if (!label) { return false; }
|
||||
|
||||
//if tree is empty return false
|
||||
if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(m_treeStore), iter) == 0) { return false; }
|
||||
|
||||
//look for node in the whole tree
|
||||
do
|
||||
{
|
||||
//look for node in current subtree
|
||||
if (findChildNodeFromParent(iter, label, type)) { return true; }
|
||||
|
||||
//proceed with next top-level node
|
||||
} while (gtk_tree_model_iter_next(GTK_TREE_MODEL(m_treeStore), iter) != 0);
|
||||
|
||||
//node wasn't found
|
||||
return false;
|
||||
}
|
||||
|
||||
//looks for a tree node named 'label' of class 'type' from parent passed as parameter
|
||||
bool CVisualizationTree::findChildNodeFromParent(GtkTreeIter* iter, const char* label, const EVTNode type)
|
||||
{
|
||||
if (findChildNodeFromParentR(iter, label, type))
|
||||
{
|
||||
*iter = m_internalTreeNode;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//looks for a tree node named 'label' of class 'type' from parent passed as parameter
|
||||
bool CVisualizationTree::findChildNodeFromParentR(GtkTreeIter* iter, const char* label, const EVTNode type)
|
||||
{
|
||||
gchar* name;
|
||||
unsigned long typeAsInt;
|
||||
|
||||
//is current node the one looked for?
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(m_treeStore), iter, EVTColumn::StringName, &name, EVTColumn::ULongNodeType, &typeAsInt, -1);
|
||||
|
||||
if (!name)
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Error << "Can not get values from the model" << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strcmp(label, name) == 0 && type == EVTNode(typeAsInt))
|
||||
{
|
||||
m_internalTreeNode = *iter;
|
||||
return true;
|
||||
}
|
||||
|
||||
//look among current node's children
|
||||
const int nChild = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(m_treeStore), iter);
|
||||
GtkTreeIter childIter;
|
||||
for (int i = 0; i < nChild; ++i)
|
||||
{
|
||||
gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(m_treeStore), &childIter, iter, i);
|
||||
|
||||
if (findChildNodeFromParentR(&childIter, label, type)) { return true; }
|
||||
}
|
||||
|
||||
//node wasn't found
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::findChildNodeFromRoot(GtkTreeIter* iter, void* widget)
|
||||
{
|
||||
// if tree is empty
|
||||
if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(m_treeStore), iter) == 0) { return false; }
|
||||
|
||||
//look for node in the whole tree
|
||||
do
|
||||
{
|
||||
//look for node in current subtree
|
||||
if (findChildNodeFromParent(iter, widget)) { return true; }
|
||||
|
||||
//proceed with next top-level node
|
||||
} while (gtk_tree_model_iter_next(GTK_TREE_MODEL(m_treeStore), iter) != 0);
|
||||
|
||||
//node wasn't found
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::findChildNodeFromParent(GtkTreeIter* iter, void* widget)
|
||||
{
|
||||
if (findChildNodeFromParentR(iter, widget))
|
||||
{
|
||||
*iter = m_internalTreeNode;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::findChildNodeFromParentR(GtkTreeIter* iter, void* widget)
|
||||
{
|
||||
void* currentWidget;
|
||||
|
||||
//is current node the one looked for?
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(m_treeStore), iter, EVTColumn::PointerWidget, ¤tWidget, -1);
|
||||
if (widget == currentWidget)
|
||||
{
|
||||
m_internalTreeNode = *iter;
|
||||
return true;
|
||||
}
|
||||
|
||||
//look among current node's children
|
||||
const int nChild = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(m_treeStore), iter);
|
||||
GtkTreeIter childIter;
|
||||
for (int i = 0; i < nChild; ++i)
|
||||
{
|
||||
gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(m_treeStore), &childIter, iter, i);
|
||||
|
||||
if (findChildNodeFromParentR(&childIter, widget)) { return true; }
|
||||
}
|
||||
|
||||
//node wasn't found
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::findChildNodeFromRoot(GtkTreeIter* iter, const CIdentifier id)
|
||||
{
|
||||
//if tree is empty return false
|
||||
if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(m_treeStore), iter) == 0) { return false; }
|
||||
|
||||
//look for node in the whole tree
|
||||
do
|
||||
{
|
||||
//look for node in current subtree
|
||||
if (findChildNodeFromParent(iter, id)) { return true; }
|
||||
//proceed with next top-level node
|
||||
} while (gtk_tree_model_iter_next(GTK_TREE_MODEL(m_treeStore), iter) != 0);
|
||||
|
||||
//node wasn't found
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::findChildNodeFromParent(GtkTreeIter* iter, const CIdentifier id)
|
||||
{
|
||||
if (findChildNodeFromParentR(iter, id))
|
||||
{
|
||||
*iter = m_internalTreeNode;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::findChildNodeFromParentR(GtkTreeIter* iter, const CIdentifier& id)
|
||||
{
|
||||
gchar* str;
|
||||
CIdentifier currentID;
|
||||
|
||||
//is current node the one looked for?
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(m_treeStore), iter, EVTColumn::StringIdentifier, &str, -1);
|
||||
currentID.fromString(CString(str));
|
||||
if (id == currentID)
|
||||
{
|
||||
m_internalTreeNode = *iter;
|
||||
return true;
|
||||
}
|
||||
|
||||
//look among current node's children
|
||||
const int nChild = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(m_treeStore), iter);
|
||||
GtkTreeIter childIter;
|
||||
for (int i = 0; i < nChild; ++i)
|
||||
{
|
||||
gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(m_treeStore), &childIter, iter, i);
|
||||
if (findChildNodeFromParentR(&childIter, id)) { return true; }
|
||||
}
|
||||
|
||||
//node wasn't found
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::findParentNode(GtkTreeIter* iter, const EVTNode type)
|
||||
{
|
||||
unsigned long typeAsInt;
|
||||
GtkTreeIter currentIter;
|
||||
|
||||
//is current node the one looked for?
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(m_treeStore), iter, EVTColumn::ULongNodeType, &typeAsInt, -1);
|
||||
if (type == EVTNode(typeAsInt)) { return true; }
|
||||
//look one level higher
|
||||
if (gtk_tree_model_iter_parent(GTK_TREE_MODEL(m_treeStore), ¤tIter, iter) != 0)
|
||||
{
|
||||
*iter = currentIter;
|
||||
return findParentNode(iter, type);
|
||||
}
|
||||
//couldn't find desired parent node
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::dragDataReceivedOutsideWidgetCB(const CIdentifier& srcWidgetID, GtkWidget* dstWidget, const VisualizationToolkit::EDragLocation location)
|
||||
{
|
||||
//retrieve source widget parent
|
||||
//-----------------------------
|
||||
IVTWidget* srcWidget = getVisualizationWidget(srcWidgetID);
|
||||
if (!srcWidget) { return false; }
|
||||
|
||||
//retrieve dest widget and dest widget parent identifiers
|
||||
//-------------------------------------------------------
|
||||
GtkTreeIter dstIt;
|
||||
if (!findChildNodeFromRoot(&dstIt, m_treeViewCB->getTreeWidget(dstWidget))) { return false; }
|
||||
CIdentifier dstWidgetID;
|
||||
getIdentifierFromTreeIter(&dstIt, dstWidgetID, EVTColumn::StringIdentifier);
|
||||
IVTWidget* dstVisualizationWidget = getVisualizationWidget(dstWidgetID);
|
||||
if (dstVisualizationWidget == nullptr) { return false; }
|
||||
// dst widget is the widget already present in
|
||||
const CIdentifier dstParentID = dstVisualizationWidget->getParentIdentifier();
|
||||
|
||||
//unparent source widget
|
||||
size_t srcIdx = 0;
|
||||
unparentVisualizationWidget(srcWidgetID, srcIdx);
|
||||
|
||||
//unparent dest widget
|
||||
size_t dstIdx = 0;
|
||||
unparentVisualizationWidget(dstWidgetID, dstIdx);
|
||||
|
||||
//create paned widget
|
||||
const EVTWidget panedType = (location == VisualizationToolkit::EDragLocation::Top || location == VisualizationToolkit::EDragLocation::Bottom)
|
||||
? EVTWidget::VerticalSplit : EVTWidget::HorizontalSplit;
|
||||
CIdentifier panedID;
|
||||
addVisualizationWidget(panedID, CString(panedType == EVTWidget::VerticalSplit ? "Vertical split" : "Horizontal split"), panedType,
|
||||
dstParentID, //parent paned to dest widget parent
|
||||
dstIdx, //put it at the index occupied by dest widget
|
||||
CIdentifier::undefined(), //no box algorithm for a paned
|
||||
2, //2 children
|
||||
CIdentifier::undefined()); //no prefered visualization identifier
|
||||
IVTWidget* panedWidget = getVisualizationWidget(panedID);
|
||||
|
||||
//add attributes
|
||||
if (m_treeViewCB != nullptr) { m_treeViewCB->createTreeWidget(panedWidget); }
|
||||
|
||||
//reparent widgets
|
||||
const size_t newSrcIdx = (location == VisualizationToolkit::EDragLocation::Top || location == VisualizationToolkit::EDragLocation::Left) ? 0 : 1;
|
||||
parentVisualizationWidget(srcWidgetID, panedID, newSrcIdx);
|
||||
parentVisualizationWidget(dstWidgetID, panedID, 1 - newSrcIdx);
|
||||
|
||||
//update Gtk tree
|
||||
reloadTree();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::dragDataReceivedInWidgetCB(const CIdentifier& srcWidgetID, GtkWidget* dstWidget)
|
||||
{
|
||||
//retrieve source widget parent
|
||||
IVTWidget* srcWidget = getVisualizationWidget(srcWidgetID);
|
||||
OV_EXCEPTION_UNLESS_D(srcWidget, "Source visualization identifier does not exist in the tree", Kernel::ErrorType::ResourceNotFound);
|
||||
|
||||
const CIdentifier srcParentID = srcWidget->getParentIdentifier();
|
||||
|
||||
//retrieve dest widget and dest widget parent identifiers
|
||||
GtkTreeIter dstIt;
|
||||
if (!findChildNodeFromRoot(&dstIt, m_treeViewCB->getTreeWidget(dstWidget))) { return false; }
|
||||
|
||||
CIdentifier dstWidgetID;
|
||||
getIdentifierFromTreeIter(&dstIt, dstWidgetID, EVTColumn::StringIdentifier);
|
||||
IVTWidget* dstVisualizationWidget = getVisualizationWidget(dstWidgetID);
|
||||
if (!dstVisualizationWidget) { return false; }
|
||||
|
||||
const CIdentifier dstParentID = dstVisualizationWidget->getParentIdentifier();
|
||||
|
||||
//unparent source widget
|
||||
size_t srcIdx;
|
||||
unparentVisualizationWidget(srcWidgetID, srcIdx);
|
||||
|
||||
//destroy, unparent or reparent dest widget
|
||||
size_t dstIdx;
|
||||
|
||||
//if source widget was unaffected
|
||||
if (srcParentID == CIdentifier::undefined())
|
||||
{
|
||||
//if dest widget was dummy, destroy it
|
||||
if (dstVisualizationWidget->getType() == EVTWidget::Undefined)
|
||||
{
|
||||
getVisualizationWidgetIndex(dstWidgetID, dstIdx);
|
||||
destroyHierarchy(dstWidgetID, true);
|
||||
}
|
||||
else //dest widget becomes unaffected
|
||||
{
|
||||
unparentVisualizationWidget(dstWidgetID, dstIdx);
|
||||
}
|
||||
}
|
||||
else //source widget was affected
|
||||
{
|
||||
//unparent dest widget
|
||||
unparentVisualizationWidget(dstWidgetID, dstIdx);
|
||||
|
||||
//reparent it to source widget parent
|
||||
parentVisualizationWidget(dstWidgetID, srcParentID, srcIdx);
|
||||
}
|
||||
|
||||
//reparent source widget
|
||||
parentVisualizationWidget(srcWidgetID, dstParentID, dstIdx);
|
||||
|
||||
//update Gtk tree
|
||||
reloadTree();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::loadVisualizationWidget(IVTWidget* widget, GtkTreeIter* parentIter)
|
||||
{
|
||||
//create visualization widget
|
||||
//---------------------------
|
||||
GtkWidget* tmp = m_treeViewCB->loadTreeWidget(widget);
|
||||
|
||||
//add visualization widget node to tree store
|
||||
GtkTreeIter iter;
|
||||
gtk_tree_store_append(m_treeStore, &iter, parentIter);
|
||||
|
||||
//retrieve values of tree node fields
|
||||
EVTNode childType;
|
||||
switch (widget->getType())
|
||||
{
|
||||
case EVTWidget::Window: childType = EVTNode::VisualizationWindow;
|
||||
break;
|
||||
case EVTWidget::Panel: childType = EVTNode::VisualizationPanel;
|
||||
break;
|
||||
case EVTWidget::Box: childType = EVTNode::VisualizationBox;
|
||||
break;
|
||||
case EVTWidget::HorizontalSplit: childType = EVTNode::HorizontalSplit;
|
||||
break;
|
||||
case EVTWidget::VerticalSplit: childType = EVTNode::VerticalSplit;
|
||||
break;
|
||||
case EVTWidget::Undefined: childType = EVTNode::Undefined;
|
||||
break;
|
||||
default: childType = EVTNode::Undefined;
|
||||
break;
|
||||
}
|
||||
|
||||
CString stockIconString = m_treeViewCB->getTreeWidgetIcon(childType);
|
||||
|
||||
if (widget->getType() == EVTWidget::Box)
|
||||
{
|
||||
const Kernel::IBox* box = m_scenario->getBoxDetails(widget->getBoxIdentifier());
|
||||
if (!box)
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Error << "Box with identifier " << widget->getBoxIdentifier() <<
|
||||
" not found in the scenario" << "\n";
|
||||
return false;
|
||||
}
|
||||
const Plugins::IBoxAlgorithmDesc* boxDesc = dynamic_cast<const Plugins::IBoxAlgorithmDesc*>(m_kernelCtx.getPluginManager().getPluginObjectDescCreating(box->getAlgorithmClassIdentifier()));
|
||||
if (boxDesc) { stockIconString = boxDesc->getStockItemName(); }
|
||||
}
|
||||
|
||||
//set tree node fields
|
||||
gtk_tree_store_set(m_treeStore, &iter,
|
||||
EVTColumn::StringName, widget->getName().toASCIIString(),
|
||||
EVTColumn::StringStockIcon, stockIconString.toASCIIString(),
|
||||
EVTColumn::ULongNodeType, static_cast<unsigned long>(childType),
|
||||
EVTColumn::StringIdentifier, widget->getIdentifier().str().c_str(),
|
||||
EVTColumn::PointerWidget, tmp, -1);
|
||||
|
||||
//load visualization widget hierarchy
|
||||
//-----------------------------------
|
||||
//create a dummy child for visualization panels if none exists
|
||||
if (widget->getType() == EVTWidget::Panel)
|
||||
{
|
||||
CIdentifier id;
|
||||
widget->getChildIdentifier(0, id);
|
||||
if (id == CIdentifier::undefined())
|
||||
{
|
||||
addVisualizationWidget(id, "Empty", EVTWidget::Undefined, widget->getIdentifier(), 0, CIdentifier::undefined(), 0, CIdentifier::undefined());
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < widget->getNbChildren(); ++i)
|
||||
{
|
||||
CIdentifier id;
|
||||
widget->getChildIdentifier(i, id);
|
||||
|
||||
loadVisualizationWidget(getVisualizationWidget(id), &iter);
|
||||
}
|
||||
|
||||
//complete visualization widget loading now that its hierarchy is loaded
|
||||
m_treeViewCB->endLoadTreeWidget(widget);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::setToolbar(const CIdentifier& boxID, GtkWidget* toolbar)
|
||||
{
|
||||
if (m_treeViewCB != nullptr) { return m_treeViewCB->setToolbar(boxID, toolbar); }
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CVisualizationTree::setWidget(const CIdentifier& boxID, GtkWidget* widget)
|
||||
{
|
||||
if (m_treeViewCB != nullptr) { return m_treeViewCB->setWidget(boxID, widget); }
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
json::Object CVisualizationTree::serializeWidget(IVTWidget& widget) const
|
||||
{
|
||||
json::Object representation;
|
||||
|
||||
representation["identifier"] = widget.getIdentifier().str().c_str();
|
||||
|
||||
// visualization box name can be retrieved from corresponding IBox, so we can skip it for these
|
||||
if (widget.getType() != EVTWidget::Box) { representation["name"] = widget.getName().toASCIIString(); }
|
||||
|
||||
representation["type"] = int(widget.getType());
|
||||
representation["parentIdentifier"] = widget.getParentIdentifier().str().c_str();
|
||||
|
||||
// visualization widget index
|
||||
IVTWidget* parentVisualizationWidget = this->getVisualizationWidget(widget.getParentIdentifier());
|
||||
if (parentVisualizationWidget)
|
||||
{
|
||||
size_t childIndex = 0;
|
||||
parentVisualizationWidget->getChildIndex(widget.getIdentifier(), childIndex);
|
||||
representation["index"] = int(childIndex);
|
||||
}
|
||||
|
||||
representation["boxIdentifier"] = widget.getBoxIdentifier().str().c_str();
|
||||
representation["childCount"] = int(widget.getNbChildren());
|
||||
|
||||
if (widget.getType() == EVTWidget::Window)
|
||||
{
|
||||
representation["width"] = int(widget.getWidth());
|
||||
representation["height"] = int(widget.getHeight());
|
||||
}
|
||||
if (widget.getType() == EVTWidget::HorizontalSplit || widget.getType() == EVTWidget::VerticalSplit)
|
||||
{
|
||||
representation["dividerPosition"] = widget.getDividerPosition();
|
||||
representation["maxDividerPosition"] = widget.getMaxDividerPosition();
|
||||
}
|
||||
|
||||
return representation;
|
||||
}
|
||||
|
||||
CString CVisualizationTree::serialize() const
|
||||
{
|
||||
json::Array representation;
|
||||
|
||||
std::vector<CIdentifier> widgetsToExport;
|
||||
|
||||
CIdentifier widgetID;
|
||||
while (this->getNextVisualizationWidgetIdentifier(widgetID))
|
||||
{
|
||||
IVTWidget* widget = this->getVisualizationWidget(widgetID);
|
||||
if (widget->getType() == EVTWidget::Window || widget->getParentIdentifier() == CIdentifier::undefined()) { widgetsToExport.push_back(widgetID); }
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < widgetsToExport.size(); ++i)
|
||||
{
|
||||
IVTWidget* widget = this->getVisualizationWidget(widgetsToExport[i]);
|
||||
|
||||
representation.push_back(this->serializeWidget(*widget));
|
||||
|
||||
for (size_t j = 0; j < widget->getNbChildren(); ++j) { if (widget->getChildIdentifier(j, widgetID)) { widgetsToExport.push_back(widgetID); } }
|
||||
}
|
||||
|
||||
return CString(Serialize(representation).c_str());
|
||||
}
|
||||
|
||||
bool CVisualizationTree::deserialize(const CString& tree)
|
||||
{
|
||||
// Empty this visualization tree
|
||||
auto widgetID = CIdentifier::undefined();
|
||||
while (this->getNextVisualizationWidgetIdentifier(widgetID) && widgetID != CIdentifier::undefined())
|
||||
{
|
||||
this->destroyHierarchy(widgetID, true);
|
||||
widgetID = CIdentifier::undefined();
|
||||
}
|
||||
|
||||
|
||||
json::Array representation = json::Deserialize(tree.toASCIIString());
|
||||
|
||||
for (auto it = representation.begin(); it != representation.end(); ++it)
|
||||
{
|
||||
json::Value& jsonWidget = *it;
|
||||
|
||||
widgetID.fromString(jsonWidget["identifier"].ToString().c_str());
|
||||
|
||||
CIdentifier boxID;
|
||||
boxID.fromString(jsonWidget["boxIdentifier"].ToString().c_str());
|
||||
|
||||
const EVTWidget widgetType = EVTWidget(jsonWidget["type"].ToInt());
|
||||
|
||||
CString name;
|
||||
if (widgetType == EVTWidget::Box)
|
||||
{
|
||||
const Kernel::IBox* box = m_scenario->getBoxDetails(boxID);
|
||||
if (!box)
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Error << "The box identifier [" << boxID << "] used in Window manager was not found in the scenario.\n";
|
||||
return false;
|
||||
}
|
||||
name = box->getName();
|
||||
}
|
||||
else { name = jsonWidget["name"].ToString().c_str(); }
|
||||
|
||||
CIdentifier id, parentID;
|
||||
parentID.fromString(jsonWidget["parentIdentifier"].ToString().c_str());
|
||||
|
||||
size_t index = 0;
|
||||
if (this->getVisualizationWidget(parentID)) { index = size_t(jsonWidget["index"].ToInt()); }
|
||||
const size_t nChild = size_t(jsonWidget["childCount"].ToInt());
|
||||
|
||||
this->addVisualizationWidget(id, name, widgetType, parentID, index, boxID, nChild, widgetID);
|
||||
|
||||
if (widgetID != id)
|
||||
{
|
||||
m_kernelCtx.getLogManager() << Kernel::LogLevel_Error << "Visualization widget [" << widgetID << "] for box [" << boxID << "] could not be imported.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
IVTWidget* widget = this->getVisualizationWidget(widgetID);
|
||||
|
||||
if (widget)
|
||||
{
|
||||
if (widget->getType() == EVTWidget::Window)
|
||||
{
|
||||
widget->setWidth(size_t(jsonWidget["width"].ToInt()));
|
||||
widget->setHeight(size_t(jsonWidget["height"].ToInt()));
|
||||
}
|
||||
if (widget->getType() == EVTWidget::HorizontalSplit || widget->getType() == EVTWidget::VerticalSplit)
|
||||
{
|
||||
widget->setDividerPosition(jsonWidget["dividerPosition"].ToInt());
|
||||
widget->setMaxDividerPosition(jsonWidget["maxDividerPosition"].ToInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
|
||||
#include <visualization-toolkit/ovvizIVisualizationTree.h>
|
||||
|
||||
#include <map>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
namespace json {
|
||||
class Object;
|
||||
}
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
class CVisualizationTree final : public VisualizationToolkit::IVisualizationTree
|
||||
{
|
||||
public:
|
||||
CVisualizationTree(const Kernel::IKernelContext& ctx) : m_kernelCtx(ctx) {}
|
||||
~CVisualizationTree() override;
|
||||
|
||||
bool init(const Kernel::IScenario* scenario) override;
|
||||
|
||||
bool getNextVisualizationWidgetIdentifier(CIdentifier& id) const override;
|
||||
bool getNextVisualizationWidgetIdentifier(CIdentifier& id, VisualizationToolkit::EVisualizationWidget type) const override;
|
||||
bool isVisualizationWidget(const CIdentifier& id) const override;
|
||||
VisualizationToolkit::IVisualizationWidget* getVisualizationWidget(const CIdentifier& id) const override;
|
||||
VisualizationToolkit::IVisualizationWidget* getVisualizationWidgetFromBoxIdentifier(const CIdentifier& boxID) const override;
|
||||
bool addVisualizationWidget(CIdentifier& id, const CString& name, VisualizationToolkit::EVisualizationWidget type, const CIdentifier& parentID,
|
||||
size_t parentIdx, const CIdentifier& boxID, size_t nChild, const CIdentifier& suggestedID) override;
|
||||
bool getVisualizationWidgetIndex(const CIdentifier& id, size_t& index) const override;
|
||||
bool unparentVisualizationWidget(const CIdentifier& id, size_t& index) override;
|
||||
bool parentVisualizationWidget(const CIdentifier& id, const CIdentifier& parentID, const size_t index) override;
|
||||
bool destroyHierarchy(const CIdentifier& id, bool destroyVisualizationBoxes) override;
|
||||
|
||||
GtkTreeView* createTreeViewWithModel() override;
|
||||
bool setTreeViewCB(VisualizationToolkit::ITreeViewCB* callback) override;
|
||||
|
||||
bool reloadTree() override;
|
||||
|
||||
bool getTreeSelection(GtkTreeView* preeView, GtkTreeIter* iter) override;
|
||||
GtkTreePath* getTreePath(GtkTreeIter* iter) const override;
|
||||
size_t getULongValueFromTreeIter(GtkTreeIter* iter, VisualizationToolkit::EVisualizationTreeColumn colType) const override;
|
||||
bool getStringValueFromTreeIter(GtkTreeIter* iter, char*& string, VisualizationToolkit::EVisualizationTreeColumn colType) const override;
|
||||
bool getPointerValueFromTreeIter(GtkTreeIter* iter, void*& pointer, VisualizationToolkit::EVisualizationTreeColumn colType) const override;
|
||||
bool getIdentifierFromTreeIter(GtkTreeIter* iter, CIdentifier& id, VisualizationToolkit::EVisualizationTreeColumn colType) const override;
|
||||
|
||||
bool findChildNodeFromRoot(GtkTreeIter* iter, const char* label, VisualizationToolkit::EVisualizationTreeNode type) override;
|
||||
bool findChildNodeFromParent(GtkTreeIter* iter, const char* label, VisualizationToolkit::EVisualizationTreeNode type) override;
|
||||
bool findChildNodeFromRoot(GtkTreeIter* iter, void* widget) override;
|
||||
bool findChildNodeFromParent(GtkTreeIter* iter, void* widget) override;
|
||||
bool findChildNodeFromRoot(GtkTreeIter* iter, CIdentifier id) override;
|
||||
bool findChildNodeFromParent(GtkTreeIter* iter, CIdentifier id) override;
|
||||
bool findParentNode(GtkTreeIter* iter, VisualizationToolkit::EVisualizationTreeNode type) override;
|
||||
|
||||
bool dragDataReceivedInWidgetCB(const CIdentifier& srcWidgetID, GtkWidget* dstWidget) override;
|
||||
bool dragDataReceivedOutsideWidgetCB(const CIdentifier& srcWidgetID, GtkWidget* dstWidget, VisualizationToolkit::EDragLocation location) override;
|
||||
|
||||
bool setToolbar(const CIdentifier& boxID, GtkWidget* toolbar) override;
|
||||
bool setWidget(const CIdentifier& boxID, GtkWidget* widget) override;
|
||||
|
||||
CString serialize() const override;
|
||||
bool deserialize(const CString& tree) override;
|
||||
|
||||
private:
|
||||
json::Object serializeWidget(VisualizationToolkit::IVisualizationWidget& widget) const;
|
||||
|
||||
bool destroyHierarchyR(const CIdentifier& id, bool destroy);
|
||||
CIdentifier getUnusedIdentifier(const CIdentifier& suggestedID) const;
|
||||
|
||||
bool findChildNodeFromParentR(GtkTreeIter* iter, const char* label, VisualizationToolkit::EVisualizationTreeNode type);
|
||||
bool findChildNodeFromParentR(GtkTreeIter* iter, void* widget);
|
||||
bool findChildNodeFromParentR(GtkTreeIter* iter, const CIdentifier& id);
|
||||
|
||||
bool loadVisualizationWidget(VisualizationToolkit::IVisualizationWidget* widget, GtkTreeIter* parentIter);
|
||||
|
||||
std::map<CIdentifier, VisualizationToolkit::IVisualizationWidget*> m_widgets;
|
||||
CIdentifier m_scenarioID = CIdentifier::undefined();
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
const Kernel::IScenario* m_scenario = nullptr;
|
||||
GtkTreeStore* m_treeStore = nullptr;
|
||||
GtkTreeIter m_internalTreeNode;
|
||||
VisualizationToolkit::ITreeViewCB* m_treeViewCB = nullptr;
|
||||
};
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
#include <vector>
|
||||
|
||||
#include "../ovdAssert.h"
|
||||
|
||||
#include "ovdCVisualizationWidget.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
|
||||
bool CVisualizationWidget::initialize(const CIdentifier& id, const CString& name, const VisualizationToolkit::EVisualizationWidget type,
|
||||
const CIdentifier& parentID, const CIdentifier& boxID, const size_t nChild)
|
||||
{
|
||||
m_id = id;
|
||||
m_name = name;
|
||||
m_type = type;
|
||||
m_parentID = parentID;
|
||||
m_boxID = boxID;
|
||||
m_childrens.resize(nChild, CIdentifier::undefined());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVisualizationWidget::getChildIndex(const CIdentifier& id, size_t& index) const
|
||||
{
|
||||
for (index = 0; index < m_childrens.size(); ++index) { if (m_childrens[index] == id) { return true; } }
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CVisualizationWidget::addChild(const CIdentifier& childID)
|
||||
{
|
||||
m_childrens.push_back(childID);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVisualizationWidget::removeChild(const CIdentifier& id)
|
||||
{
|
||||
for (size_t i = 0; i < m_childrens.size(); ++i)
|
||||
{
|
||||
if (m_childrens[i] == id)
|
||||
{
|
||||
//remove tab from a window (variable number of children)
|
||||
if (m_type == VisualizationToolkit::EVisualizationWidget::Window) { m_childrens.erase(m_childrens.begin() + i); }
|
||||
else //clear identifier if ith child for a regular widget (fixed number of children)
|
||||
{
|
||||
m_childrens[i] = CIdentifier::undefined();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
OV_ERROR_DRF("Trying to remove non existing visualization widget " << id.str(), Kernel::ErrorType::ResourceNotFound);
|
||||
}
|
||||
|
||||
bool CVisualizationWidget::getChildIdentifier(const size_t index, CIdentifier& id) const
|
||||
{
|
||||
if (index >= m_childrens.size())
|
||||
{
|
||||
id = CIdentifier::undefined();
|
||||
OV_ERROR_DRF("Child with index " << index << " not found", Kernel::ErrorType::ResourceNotFound);
|
||||
}
|
||||
id = m_childrens[index];
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVisualizationWidget::setChildIdentifier(const size_t index, const CIdentifier& id)
|
||||
{
|
||||
if (index >= m_childrens.size()) { OV_ERROR_DRF("Child with index " << index << " not found", Kernel::ErrorType::ResourceNotFound); }
|
||||
m_childrens[index] = id;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include <visualization-toolkit/ovvizIVisualizationWidget.h>
|
||||
|
||||
#include <vector>
|
||||
#include <limits>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Designer {
|
||||
class CVisualizationWidget final : public VisualizationToolkit::IVisualizationWidget
|
||||
{
|
||||
public:
|
||||
explicit CVisualizationWidget(const Kernel::IKernelContext& ctx) : m_kernelCtx(ctx) { }
|
||||
~CVisualizationWidget() override = default;
|
||||
|
||||
bool initialize(const CIdentifier& id, const CString& name, const VisualizationToolkit::EVisualizationWidget type,
|
||||
const CIdentifier& parentID, const CIdentifier& boxID, const size_t nChild) override;
|
||||
|
||||
CIdentifier getIdentifier() const override { return m_id; }
|
||||
const CString& getName() const override { return m_name; }
|
||||
void setName(const CString& name) override { m_name = name; }
|
||||
VisualizationToolkit::EVisualizationWidget getType() const override { return m_type; }
|
||||
CIdentifier getParentIdentifier() const override { return m_parentID; }
|
||||
void setParentIdentifier(const CIdentifier& parentID) override { m_parentID = parentID; }
|
||||
CIdentifier getBoxIdentifier() const override { return m_boxID; }
|
||||
size_t getNbChildren() const override { return m_childrens.size(); }
|
||||
bool getChildIndex(const CIdentifier& id, size_t& index) const override;
|
||||
|
||||
//for windows, the number of children is unknown a priori
|
||||
bool addChild(const CIdentifier& childID) override;
|
||||
bool removeChild(const CIdentifier& id) override;
|
||||
bool getChildIdentifier(const size_t index, CIdentifier& id) const override;
|
||||
bool setChildIdentifier(const size_t index, const CIdentifier& id) override;
|
||||
|
||||
void setWidth(const size_t width) override { m_width = width; }
|
||||
void setHeight(const size_t height) override { m_height = height; }
|
||||
|
||||
size_t getWidth() override { return m_width; }
|
||||
size_t getHeight() override { return m_height; }
|
||||
|
||||
void setDividerPosition(const int pos) override { m_dividerPosition = pos; }
|
||||
void setMaxDividerPosition(const int pos) override { m_maxDividerPosition = pos; }
|
||||
|
||||
int getDividerPosition() override { return m_dividerPosition; }
|
||||
int getMaxDividerPosition() override { return m_maxDividerPosition; }
|
||||
|
||||
private:
|
||||
|
||||
const Kernel::IKernelContext& m_kernelCtx;
|
||||
CIdentifier m_id = CIdentifier::undefined();
|
||||
CString m_name;
|
||||
VisualizationToolkit::EVisualizationWidget m_type = VisualizationToolkit::EVisualizationWidget::Undefined;
|
||||
CIdentifier m_parentID = CIdentifier::undefined();
|
||||
CIdentifier m_boxID = CIdentifier::undefined();
|
||||
std::vector<CIdentifier> m_childrens;
|
||||
|
||||
// @fixme should initialize meaningfully in constructor or initialize()?
|
||||
size_t m_width = 0;
|
||||
size_t m_height = 0;
|
||||
int m_dividerPosition = std::numeric_limits<int>::min();
|
||||
int m_maxDividerPosition = std::numeric_limits<int>::min();
|
||||
};
|
||||
} // namespace Designer
|
||||
} // namespace OpenViBE
|
||||
Reference in New Issue
Block a user