Commit 98982531 authored by Dieter Devlaminck's avatar Dieter Devlaminck

Merge branch 'master' of...

Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/openvibe/openvibe into wip-ddevlami-P300Stimulator
parents 503d5664 e132ef2b
......@@ -12,6 +12,7 @@
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <openvibe/ovITimeArithmetics.h>
......@@ -944,17 +945,21 @@ CString CApplication::getWorkingDirectory(void)
{
if(l_pCurrentScenario->m_bHasFileName)
{
char* l_sCurrentDirectory=g_path_get_dirname(l_pCurrentScenario->m_sFileName.c_str());
l_sWorkingDirectory=l_sCurrentDirectory;
g_free(l_sCurrentDirectory);
std::string l_sCurrentDirectory=std::string(g_path_get_dirname(l_pCurrentScenario->m_sFileName.c_str()));
#if defined TARGET_OS_Windows
std::replace(l_sCurrentDirectory.begin(), l_sCurrentDirectory.end(), '\\', '/');
#endif
l_sWorkingDirectory=l_sCurrentDirectory.c_str();
}
}
if(!g_path_is_absolute(l_sWorkingDirectory.toASCIIString()))
{
char* l_sCurrentDirectory=g_get_current_dir();
l_sWorkingDirectory=l_sCurrentDirectory+CString("/")+l_sWorkingDirectory;
g_free(l_sCurrentDirectory);
std::string l_sCurrentDirectory=g_get_current_dir();
#if defined TARGET_OS_Windows
std::replace(l_sCurrentDirectory.begin(), l_sCurrentDirectory.end(), '\\', '/');
#endif
l_sWorkingDirectory=l_sCurrentDirectory.c_str()+CString("/")+l_sWorkingDirectory;
}
return l_sWorkingDirectory;
......
......@@ -179,6 +179,7 @@ static void context_menu_cb(::GtkMenuItem* pMenuItem, gpointer pUserData)
case ContextMenu_BoxRemoveSetting: l_pContextMenuCB->pInterfacedScenario->contextMenuBoxRemoveSettingCB(*l_pContextMenuCB->pBox, l_pContextMenuCB->ui32Index); break;
case ContextMenu_BoxConfigure: l_pContextMenuCB->pInterfacedScenario->contextMenuBoxConfigureCB(*l_pContextMenuCB->pBox); break;
case ContextMenu_BoxAbout: l_pContextMenuCB->pInterfacedScenario->contextMenuBoxAboutCB(*l_pContextMenuCB->pBox); break;
case ContextMenu_BoxDocumentation: l_pContextMenuCB->pInterfacedScenario->contextMenuBoxDocumentationCB(*l_pContextMenuCB->pBox); break;
case ContextMenu_BoxMute: l_pContextMenuCB->pInterfacedScenario->contextMenuBoxMuteCB(*l_pContextMenuCB->pBox); break;
case ContextMenu_ScenarioAbout: l_pContextMenuCB->pInterfacedScenario->contextMenuScenarioAboutCB(); break;
......@@ -1689,6 +1690,7 @@ void CInterfacedScenario::scenarioDrawingAreaButtonPressedCB(::GtkWidget* pWidge
gtk_menu_add_new_image_menu_item_with_cb(l_pMenu, l_pMenuItemRename, GTK_STOCK_EDIT, "rename box...", context_menu_cb, l_pBox, ContextMenu_BoxRename, -1);
gtk_menu_add_new_image_menu_item_with_cb(l_pMenu, l_pMenuItemDelete, GTK_STOCK_CUT, "delete box...", context_menu_cb, l_pBox, ContextMenu_BoxDelete, -1);
gtk_menu_add_new_image_menu_item_with_cb(l_pMenu, l_pMenuItemAbout, GTK_STOCK_ABOUT, "about box...", context_menu_cb, l_pBox, ContextMenu_BoxAbout, -1);
gtk_menu_add_new_image_menu_item_with_cb(l_pMenu, l_pMenuItemDocumentation, GTK_STOCK_ABOUT, "box documentation...", context_menu_cb, l_pBox, ContextMenu_BoxDocumentation, -1);
}
}
......@@ -1907,9 +1909,6 @@ void CInterfacedScenario::scenarioDrawingAreaKeyPressEventCB(::GtkWidget* pWidge
// F1 : browse documentation
if(pEvent->keyval==GDK_F1)
{
CString l_sWebBrowser=m_rKernelContext.getConfigurationManager().expand("${Designer_WebBrowserCommand}");
CString l_sURLBase=m_rKernelContext.getConfigurationManager().expand("${Designer_WebBrowserHelpURLBase}");
map < CIdentifier, boolean > l_vSelectedBoxAlgorithm;
map < CIdentifier, boolean >::const_iterator it;
for(it=m_vCurrentObject.begin(); it!=m_vCurrentObject.end(); it++)
......@@ -1927,21 +1926,7 @@ void CInterfacedScenario::scenarioDrawingAreaKeyPressEventCB(::GtkWidget* pWidge
{
for(it=l_vSelectedBoxAlgorithm.begin(); it!=l_vSelectedBoxAlgorithm.end(); it++)
{
if(it->first!=OV_UndefinedIdentifier)
{
if(m_rKernelContext.getPluginManager().canCreatePluginObject(it->first))
{
const IPluginObjectDesc* l_pPluginObjectDesc=m_rKernelContext.getPluginManager().getPluginObjectDescCreating(it->first);
CString l_sHTMLName=CString("Doc_BoxAlgorithm_")+CString(getBoxAlgorithmURL(l_pPluginObjectDesc->getName().toASCIIString()).c_str())+CString(".html");
CString l_sFullURL=l_sURLBase+CString("/")+l_sHTMLName;
m_rKernelContext.getLogManager() << LogLevel_Trace << "Requesting web browser on URL " << l_sFullURL << "\n";
int l_iResult=::system((l_sWebBrowser+CString(" ")+l_sFullURL).toASCIIString());
if(l_iResult<0)
{
m_rKernelContext.getLogManager() << LogLevel_Warning << "Could not launch command " << l_sWebBrowser+CString(" ")+l_sFullURL << "\n";
}
}
}
browseBoxDocumentation(it->first);
}
}
else
......@@ -1949,12 +1934,11 @@ void CInterfacedScenario::scenarioDrawingAreaKeyPressEventCB(::GtkWidget* pWidge
CString l_sFullURL=m_rScenario.getAttributeValue(OV_AttributeId_Scenario_DocumentationPage);
if(l_sFullURL!=CString(""))
{
m_rKernelContext.getLogManager() << LogLevel_Trace << "Requesting web browser on URL " << l_sFullURL << "\n";
int l_iResult=::system((l_sWebBrowser+CString(" ")+l_sFullURL).toASCIIString());
if(l_iResult<0)
{
m_rKernelContext.getLogManager() << LogLevel_Warning << "Could not launch command " << l_sWebBrowser+CString(" ")+l_sFullURL << "\n";
}
browseURL(l_sFullURL);
}
else
{
m_rKernelContext.getLogManager() << LogLevel_Info << "The scenario does not define a documentation page.\n";
}
}
}
......@@ -2491,6 +2475,51 @@ void CInterfacedScenario::contextMenuBoxAboutCB(IBox& rBox)
l_oAboutPluginDialog.run();
}
bool CInterfacedScenario::browseURL(CString sURL) {
CString l_sWebBrowser=m_rKernelContext.getConfigurationManager().expand("${Designer_WebBrowserCommand}");
m_rKernelContext.getLogManager() << LogLevel_Trace << "Requesting web browser on URL " << sURL << "\n";
#if TARGET_OS_Linux
CString l_sCommand = l_sWebBrowser+CString(" ")+sURL+CString(" &");
#else
CString l_sCommand = l_sWebBrowser+CString(" ")+sURL;
#endif
m_rKernelContext.getLogManager() << LogLevel_Trace << "Launching '" << l_sCommand << "'\n";
int l_iResult=::system(l_sCommand.toASCIIString());
if(l_iResult<0)
{
m_rKernelContext.getLogManager() << LogLevel_Warning << "Could not launch command " << l_sWebBrowser+CString(" ")+sURL << "\n";
return false;
}
return true;
}
bool CInterfacedScenario::browseBoxDocumentation(CIdentifier oBoxId)
{
if(oBoxId!=OV_UndefinedIdentifier && m_rKernelContext.getPluginManager().canCreatePluginObject(oBoxId))
{
CString l_sURLBase=m_rKernelContext.getConfigurationManager().expand("${Designer_WebBrowserHelpURLBase}");
const IPluginObjectDesc* l_pPluginObjectDesc=m_rKernelContext.getPluginManager().getPluginObjectDescCreating(oBoxId);
CString l_sHTMLName=CString("Doc_BoxAlgorithm_")+CString(getBoxAlgorithmURL(l_pPluginObjectDesc->getName().toASCIIString()).c_str())+CString(".html");
CString l_sFullURL=l_sURLBase+CString("/")+l_sHTMLName;
return browseURL(l_sFullURL);
} else {
m_rKernelContext.getLogManager() << LogLevel_Warning << "Box with id " << oBoxId << " can not create a pluging object\n";
return false;
}
return true;
}
void CInterfacedScenario::contextMenuBoxDocumentationCB(IBox& rBox)
{
m_rKernelContext.getLogManager() << LogLevel_Debug << "contextMenuBoxDocumentationCB\n";
CIdentifier l_oBoxId = rBox.getAlgorithmClassIdentifier();
browseBoxDocumentation(l_oBoxId);
}
void CInterfacedScenario::contextMenuScenarioAboutCB(void)
{
m_rKernelContext.getLogManager() << LogLevel_Debug << "contextMenuScenarioAboutCB\n";
......
......@@ -69,9 +69,13 @@ namespace OpenViBEDesigner
void contextMenuBoxConfigureCB(OpenViBE::Kernel::IBox& rBox);
void contextMenuBoxAboutCB(OpenViBE::Kernel::IBox& rBox);
void contextMenuBoxMuteCB(OpenViBE::Kernel::IBox& rBox);
void contextMenuBoxDocumentationCB(OpenViBE::Kernel::IBox& rBox);
void contextMenuScenarioAboutCB(void);
bool browseURL(OpenViBE::CString sURL);
bool browseBoxDocumentation(OpenViBE::CIdentifier oBoxId);
void toggleDesignerVisualisation();
OpenViBE::boolean isDesignerVisualisationToggled();
......
......@@ -49,6 +49,8 @@ namespace OpenViBEDesigner
ContextMenu_SelectionMute,
ContextMenu_BoxMute,
ContextMenu_BoxDocumentation
};
enum
......
......@@ -17,9 +17,18 @@ IF(UNIX OR WIN32)
# Alternative way to try to find matlab
FILE(GLOB_RECURSE Executable_Candidates "/usr/local/matlab*/matlab")
IF(Executable_Candidates)
LIST(GET Executable_Candidates 1 Matlab_EXECUTABLE)
LIST(GET Executable_Candidates 0 Matlab_EXECUTABLE)
ENDIF(Executable_Candidates)
ENDIF(UNIX AND NOT Matlab_EXECUTABLE)
IF(UNIX AND NOT Matlab_EXECUTABLE)
# Alternative way 2 to try to find matlab
FILE(GLOB_RECURSE Executable_Candidates "/usr/local/MATLAB*/matlab")
IF(Executable_Candidates)
LIST(GET Executable_Candidates 0 Matlab_EXECUTABLE)
ENDIF(Executable_Candidates)
ENDIF(UNIX AND NOT Matlab_EXECUTABLE)
IF(Matlab_EXECUTABLE)
GET_FILENAME_COMPONENT(Matlab_ROOT ${Matlab_EXECUTABLE} PATH)
SET(Matlab_ROOT ${Matlab_ROOT}/..)
......@@ -71,4 +80,4 @@ IF(Matlab_FOUND)
ENDIF(Matlab_LIB_FOUND)
ELSE(Matlab_FOUND)
MESSAGE(STATUS " FAILED to find Matlab...")
ENDIF(Matlab_FOUND)
\ No newline at end of file
ENDIF(Matlab_FOUND)
# These files can be included by non-contrib projects.
Copyright (c) 2000-2013 Chih-Chung Chang and Chih-Jen Lin
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither name of copyright holders nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
......@@ -16,6 +16,9 @@ namespace FS
static FS::boolean createPath(const char* sPath);
// Creates all components of a path to the filesystem except the last part (i.e. for paths including a filename in the end)
static FS::boolean createParentPath(const char* sPath);
// Returns a path omitting the last part of it (essentially boost::filesystem::parent_path). Output sParentPath needs to be pre-allocated.
static FS::boolean getParentPath(const char *sPath, char *sParentPath);
private:
Files(void);
......
......@@ -158,3 +158,14 @@ bool Files::createParentPath(const char *sPath)
{
return boost::filesystem::create_directories(boost::filesystem::path(sPath).parent_path());
}
bool Files::getParentPath(const char *sPath, char *sParentPath)
{
if(!sPath || !sParentPath) {
return false;
}
strcpy(sParentPath, boost::filesystem::path(sPath).parent_path().string().c_str());
return true;
}
......@@ -6,7 +6,9 @@ SET(PROJECT_VERSION_PATCH ${OV_GLOBAL_VERSION_PATCH})
SET(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
FILE(GLOB_RECURSE source_files src/*.cpp src/*.h src/*.inl)
ADD_LIBRARY(${PROJECT_NAME} SHARED ${source_files})
ADD_LIBRARY(${PROJECT_NAME} SHARED ${source_files}
"../../../contrib/packages/libSVM/svm.cpp"
"../../../contrib/packages/libSVM/svm.h")
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
......
......@@ -9,7 +9,7 @@
#include <xml/IReader.h>
#include <stack>
#include "libSVM/svm.h"
#include "../../../contrib/packages/libSVM/svm.h"
#define OVP_ClassId_Algorithm_ClassifierSVM OpenViBE::CIdentifier(0x50486EC2, 0x6F2417FC)
#define OVP_ClassId_Algorithm_ClassifierSVMDesc OpenViBE::CIdentifier(0x272B056E, 0x0C6502AC)
......
......@@ -100,9 +100,9 @@
</Setting>
<Setting>
<TypeIdentifier>(0x79a9edeb, 0x245d83fc)</TypeIdentifier>
<Name>Path to Matlab Executables</Name>
<DefaultValue>C:/Program Files (x86)/MATLAB/R2011b/bin/win32</DefaultValue>
<Value>C:/Program Files (x86)/MATLAB/R2011b/bin/win32</Value>
<Name>Matlab executable (path)</Name>
<DefaultValue>C:/Program Files (x86)/MATLAB/R2011b/bin/win32/matlab.exe</DefaultValue>
<Value>C:/Program Files (x86)/MATLAB/R2011b/bin/win32/matlab.exe</Value>
</Setting>
<Setting>
<TypeIdentifier>(0x79a9edeb, 0x245d83fc)</TypeIdentifier>
......@@ -495,7 +495,7 @@
<Identifier>(0x000037be, 0x000071f3)</Identifier>
<Text>&lt;b&gt;Configure the Matlab Scripting box:&lt;/b&gt;
&lt;span color=&quot;red&quot;&gt; Set the matlab installation directory before use !&lt;/span&gt;
&lt;span color=&quot;red&quot;&gt; Set the matlab executable path before use !&lt;/span&gt;
Enter the path to your local Matlab installation.
......@@ -601,4 +601,4 @@ The documentation page for this tutorial is available at:
<NumChildren>0</NumChildren>
</VisualisationWidget>
</VisualisationTree>
</OpenViBE-Scenario>
\ No newline at end of file
</OpenViBE-Scenario>
......@@ -293,9 +293,9 @@
</Setting>
<Setting>
<TypeIdentifier>(0x79a9edeb, 0x245d83fc)</TypeIdentifier>
<Name>Path to Matlab Executables</Name>
<DefaultValue>C:/Program Files (x86)/MATLAB/R2011b/bin/win32</DefaultValue>
<Value>C:/Program Files (x86)/MATLAB/R2011b/bin/win32</Value>
<Name>Matlab executable (path)</Name>
<DefaultValue>C:/Program Files (x86)/MATLAB/R2011b/bin/win32/matlab.exe</DefaultValue>
<Value>C:/Program Files (x86)/MATLAB/R2011b/bin/win32/matlab.exe</Value>
</Setting>
<Setting>
<TypeIdentifier>(0x79a9edeb, 0x245d83fc)</TypeIdentifier>
......@@ -672,8 +672,8 @@ every 2 seconds</Text>
<Identifier>(0x000042fe, 0x00002140)</Identifier>
<Text>&lt;b&gt;Configure the Matlab Scripting box:&lt;/b&gt;
&lt;span color=&quot;red&quot;&gt; Set the matlab installation directory
and working directory before use !&lt;/span&gt;
&lt;span color=&quot;red&quot;&gt; Set the matlab executable path
and the working directory before use !&lt;/span&gt;
If you want to add a sinusoid noise to the signal
set the noise frequency and amplitude.
......@@ -756,4 +756,4 @@ Set the frequency range for the plot scale.</Text>
<NumChildren>0</NumChildren>
</VisualisationWidget>
</VisualisationTree>
</OpenViBE-Scenario>
\ No newline at end of file
</OpenViBE-Scenario>
......@@ -23,9 +23,9 @@
</Setting>
<Setting>
<TypeIdentifier>(0x79a9edeb, 0x245d83fc)</TypeIdentifier>
<Name>Path to Matlab Executables</Name>
<DefaultValue>C:/Program Files (x86)/MATLAB/R2011b/bin/win32</DefaultValue>
<Value>C:/Program Files (x86)/MATLAB/R2011b/bin/win32</Value>
<Name>Matlab executable (path)</Name>
<DefaultValue>C:/Program Files (x86)/MATLAB/R2011b/bin/win32/matlab.exe</DefaultValue>
<Value>C:/Program Files (x86)/MATLAB/R2011b/bin/win32/matlab.exe</Value>
</Setting>
<Setting>
<TypeIdentifier>(0x79a9edeb, 0x245d83fc)</TypeIdentifier>
......@@ -268,8 +268,8 @@
<Identifier>(0x000035a5, 0x000068bb)</Identifier>
<Text>&lt;b&gt;Configure the Matlab Scripting box:&lt;/b&gt;
&lt;span color=&quot;red&quot;&gt; Set the matlab installation directory
and working directory before use !&lt;/span&gt;
&lt;span color=&quot;red&quot;&gt; Set the matlab executable path
and the working directory before use !&lt;/span&gt;
You can select the number of channels
and size of data chunk.
......@@ -354,4 +354,4 @@ The documentation page for this tutorial is available at:
<NumChildren>0</NumChildren>
</VisualisationWidget>
</VisualisationTree>
</OpenViBE-Scenario>
\ No newline at end of file
</OpenViBE-Scenario>
......@@ -15,6 +15,8 @@
#include <windows.h>
#endif
#include <fs/Files.h>
#define MATLAB_BUFFER 2048
#define m_pMatlabEngine ((Engine*)m_pMatlabEngineHandle)
#define m_pMatlabStimulation ((mxArray*)m_pMatlabStimulationHandle)
......@@ -32,11 +34,44 @@ using namespace OpenViBEPlugins::Tools;
#define boolean OpenViBE::boolean
// Sanitizes a path so that it only has / or \ characters and has a / or \ in the end.
// @fixme should move to plugins-FS possibly
void CBoxAlgorithmMatlabFilter::sanitizePath(OpenViBE::CString &sPathToModify) const {
std::string l_oTmpPath(sPathToModify);
// Append / to end of path if its not there already
if(l_oTmpPath.length()>0)
{
char l_cLastChar = l_oTmpPath.at(l_oTmpPath.length()-1);
if(l_cLastChar != '\\' && l_cLastChar != '/')
{
l_oTmpPath = l_oTmpPath + "/";
}
}
#if defined TARGET_OS_Windows
// Convert '/' to '\'
for (size_t i=0; i < l_oTmpPath.length(); i++) {
if(l_oTmpPath[i] == '/')
{
l_oTmpPath[i] = '\\';
}
}
#endif
sPathToModify = OpenViBE::CString(l_oTmpPath.c_str());
}
boolean CBoxAlgorithmMatlabFilter::OpenMatlabEngineSafely(void)
{
this->getLogManager() << LogLevel_Trace << "Trying to open Matlab engine\n";
this->getLogManager() << LogLevel_Trace << "Trying to open the Matlab engine\n";
#if defined TARGET_OS_Linux
m_pMatlabEngineHandle=::engOpen(m_sMatlabPath.toASCIIString());
if(!m_pMatlabEngine)
{
this->getLogManager() << LogLevel_Error << "Could not open the Matlab engine.\n" <<
"The configured path to the matlab executable was expanded as '" << m_sMatlabPath << "'.\n";
return false;
}
#elif defined TARGET_OS_Windows
__try
{
......@@ -44,18 +79,20 @@ boolean CBoxAlgorithmMatlabFilter::OpenMatlabEngineSafely(void)
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
this->getLogManager() << LogLevel_Error << "First call to MATLAB engine failed.\n"
this->getLogManager() << LogLevel_Error << "First call to the MATLAB engine failed.\n"
<< "\tTo use this box you must have MATLAB (32 bits version) installed on your computer.\n";
return false;
m_pMatlabEngineHandle = NULL;
}
#else
#endif
if(!m_pMatlabEngine)
{
this->getLogManager() << LogLevel_Error << "Could not open Matlab engine\n";
this->getLogManager() << LogLevel_Error << "Could not open the Matlab engine.\n" <<
"The configured path to the matlab bin directory was expanded as '" << m_sMatlabPath << "'.\n";
return false;
}
#else
this->getLogManager() << LogLevel_Error << "Only Linux and Windows are supported\n";
return false;
#endif
return true;
}
......@@ -78,30 +115,27 @@ boolean CBoxAlgorithmMatlabFilter::initialize(void)
ip_pMatrix.initialize(m_pStreamedMatrixEncoder->getInputParameter(OVP_GD_Algorithm_StreamedMatrixStreamEncoder_InputParameterId_Matrix));
m_ui64LatestStimulationChunkEndTime=0;
uint32 l_ui32FirstCommonIndex = 0;
getStaticBoxContext().getSettingValue(0, m_sMatlabPath);
#if defined TARGET_OS_Windows
std::string l_oTmpPath(m_sMatlabPath);
// Convert '/' to '\'
for (size_t i=0; i < l_oTmpPath.length(); i++) {
if(l_oTmpPath[i] == '/')
{
l_oTmpPath[i] = '\\';
}
if(!FS::Files::directoryExists(m_sMatlabPath) && FS::Files::fileExists(m_sMatlabPath))
{
// The path might be pointing to the executable, try to extract the directory
char l_sParentPath[MAX_PATH];
FS::Files::getParentPath(m_sMatlabPath, l_sParentPath);
m_sMatlabPath = OpenViBE::CString(l_sParentPath);
}
// Append \ to end of path if its not there already
if(l_oTmpPath.length()>0)
sanitizePath(m_sMatlabPath);
this->getLogManager() << LogLevel_Trace << "Interpreting Matlab path as '" << m_sMatlabPath << "'\n";
if(!FS::Files::directoryExists(m_sMatlabPath))
{
char l_cLastChar = l_oTmpPath.at(l_oTmpPath.length()-1);
if(l_cLastChar != '\\')
{
l_oTmpPath = l_oTmpPath + "\\";
}
m_sMatlabPath = OpenViBE::CString(l_oTmpPath.c_str());
this->getLogManager() << LogLevel_Error << "Configured Matlab path'" << m_sMatlabPath << "' does not seem to be a directory\n";
return false;
}
m_sMatlabPath = OpenViBE::CString(l_oTmpPath.c_str());
char * l_sPath = getenv("PATH");
if(l_sPath == NULL)
......
......@@ -54,13 +54,15 @@ namespace OpenViBEPlugins
void* m_pMatlabMatrixHandle;
void* m_pMatlabBCIContextHandle;
OpenViBE::CString m_sMatlabPath;
OpenViBE::CString m_sMatlabPath; // On Linux, path of the executable. On Windows, the executable directory.
OpenViBE::CString m_sProcessFunction;
OpenViBE::CString m_sInitializeFunction;
private:
OpenViBE::boolean OpenMatlabEngineSafely(void);
OpenViBE::boolean CloseMatlabEngineSafely(void);
void sanitizePath(OpenViBE::CString &sPathToModify) const;
};
class CBoxAlgorithmMatlabFilterDesc : virtual public OpenViBE::Plugins::IBoxAlgorithmDesc
......@@ -89,9 +91,9 @@ namespace OpenViBEPlugins
rBoxAlgorithmPrototype.addOutput ("Filtered streamed matrix", OV_TypeId_StreamedMatrix);
rBoxAlgorithmPrototype.addOutput ("Stimulations", OV_TypeId_Stimulations);
#if defined TARGET_OS_Linux
rBoxAlgorithmPrototype.addSetting("Matlab launch command", OV_TypeId_String, "[ssh user@host] /path/to/matlab");
rBoxAlgorithmPrototype.addSetting("Matlab executable (path)", OV_TypeId_String, "[ssh user@host] /path/to/matlab");
#elif defined TARGET_OS_Windows
rBoxAlgorithmPrototype.addSetting("Path to Matlab Executable", OV_TypeId_String, "C:/Program Files (x86)/MATLAB/R2011b/bin/win32");
rBoxAlgorithmPrototype.addSetting("Matlab executable (path)", OV_TypeId_String, "C:/Program Files (x86)/MATLAB/R2011b/bin/win32/matlab.exe");
#else
#endif
rBoxAlgorithmPrototype.addSetting("Matlab working directory", OV_TypeId_String, "${__volatile_ScenarioDir}");
......@@ -99,6 +101,7 @@ namespace OpenViBEPlugins
rBoxAlgorithmPrototype.addSetting("Process function", OV_TypeId_String, "bci_Process");
rBoxAlgorithmPrototype.addFlag(OpenViBE::Kernel::BoxFlag_IsUnstable);
rBoxAlgorithmPrototype.addFlag(OpenViBE::Kernel::BoxFlag_IsDeprecated);
return true;
}
......
......@@ -92,9 +92,15 @@ boolean CBoxAlgorithmMatlabScripting::checkFailureRoutine(boolean bResult, const
boolean CBoxAlgorithmMatlabScripting::OpenMatlabEngineSafely(void)
{
this->getLogManager() << LogLevel_Trace << "Trying to open Matlab engine\n";
this->getLogManager() << LogLevel_Trace << "Trying to open the Matlab engine\n";
#if defined TARGET_OS_Linux
m_pMatlabEngineHandle=::engOpen(m_sMatlabPath.toASCIIString());
if(!m_pMatlabEngine)
{
this->getLogManager() << LogLevel_Error << "Could not open the Matlab engine.\n" <<
"The configured path to the matlab executable was expanded as '" << m_sMatlabPath << "'.\n";
return false;
}
#elif defined TARGET_OS_Windows
__try
{
......@@ -106,13 +112,16 @@ boolean CBoxAlgorithmMatlabScripting::OpenMatlabEngineSafely(void)
<< "\tTo use this box you must have MATLAB (32 bits version) installed on your computer.\n";
m_pMatlabEngineHandle = NULL;
}
#endif
if(!m_pMatlabEngine)
{
this->getLogManager() << LogLevel_Error << "Could not open the Matlab engine.\n" <<
"The path in the box configuration was interpreted as '" << m_sMatlabPath << "'.\n";
"The matlab binary path was reasoned to be '" << m_sMatlabPath << "'.\n";
return false;
}
#else
this->getLogManager() << LogLevel_Error << "Only Linux and Windows are supported\n";
return false;
#endif
return true;
}
......@@ -226,24 +235,30 @@ boolean CBoxAlgorithmMatlabScripting::initialize(void)
}
getStaticBoxContext().getSettingValue(1, m_sMatlabPath);
sanitizePath(m_sMatlabPath);
this->getLogManager() << LogLevel_Trace << "Interpreting Matlab path as '" << m_sMatlabPath << "'\n";
#if defined TARGET_OS_Windows
if(!FS::Files::directoryExists(m_sMatlabPath) && FS::Files::fileExists(m_sMatlabPath))
{
// The path might be pointing to the executable, try to extract the directory
char l_sParentPath[MAX_PATH];
FS::Files::getParentPath(m_sMatlabPath, l_sParentPath);
m_sMatlabPath = OpenViBE::CString(l_sParentPath);
}
sanitizePath(m_sMatlabPath);
this->getLogManager() << LogLevel_Trace << "Interpreting Matlab path as '" << m_sMatlabPath << "'\n";
if(!FS::Files::directoryExists(m_sMatlabPath))
{
this->getLogManager() << LogLevel_Error << "Problem with Matlab path '" << m_sMatlabPath << "'\n";
this->getLogManager() << LogLevel_Error << "Configured Matlab path '" << m_sMatlabPath << "' does not seem to be a directory\n";
return false;
}
#if defined TARGET_OS_Windows
char * l_sPath = getenv("PATH");
if(l_sPath == NULL)
{
this->getLogManager() << LogLevel_Error << "Could not access the environment variable PATH to add Matlab.\n";
this->getLogManager() << LogLevel_Error << "Could not access the environment variable PATH to add Matlab path to it.\n";
return false;
}
string l_sStrPath = string(l_sPath);
......
......@@ -49,7 +49,7 @@ namespace OpenViBEPlugins
CMatlabHelper m_oMatlabHelper;
OpenViBE::CString m_sMatlabPath;
OpenViBE::CString m_sMatlabPath; // On Linux, path of the executable. On Windows, the executable directory.
OpenViBE::CString m_sProcessFunction;
OpenViBE::CString m_sInitializeFunction;
OpenViBE::CString m_sUninitializeFunction;
......@@ -123,9 +123,13 @@ namespace OpenViBEPlugins
rBoxAlgorithmPrototype.addSetting("Box clock frequency in Hz", OV_TypeId_Integer, "64");
#if defined TARGET_OS_Linux
rBoxAlgorithmPrototype.addSetting("Matlab launch command", OV_TypeId_String, "[ssh user@host] /path/to/matlab");
rBoxAlgorithmPrototype.addSetting("Matlab executable (path)", OV_TypeId_String, "[ssh user@host] /path/to/matlab");
#elif defined TARGET_OS_Windows
rBoxAlgorithmPrototype.addSetting("Path to Matlab Executables", OV_TypeId_String, "C:/Program Files (x86)/MATLAB/R2011b/bin/win32");
// On Windows, the executable is not actually used, but its path is parsed from it and added to PATH.
// Background: Matlab's engOpen() takes a different argument on Windows and on Linux. On Windows, we need to have Matlab
// on PATH, in Linux we need to provide a full path of the executable. However, we'd like our example scenarios to give
// correct instructions to the user on both platforms, hence we use a setting that contains the information for both use-cases.
rBoxAlgorithmPrototype.addSetting("Matlab executable (path)", OV_TypeId_String, "C:/Program Files (x86)/MATLAB/R2011b/bin/win32/matlab.exe");
#else
#endif
rBoxAlgorithmPrototype.addSetting("Matlab working directory", OV_TypeId_String, "${__volatile_ScenarioDir}");
......
......@@ -103,7 +103,7 @@ boolean CMatlabHelper::setSignalInputHeader(uint32 ui32InputIndex, IMatrix * pMa
sprintf(l_sBuffer, "%i",pMatrix->getDimensionSize(1));
l_sCommand = l_sCommand + CString(l_sBuffer) + CString(",");
l_sCommand = l_sCommand + CString("{")+ l_sLabelList + CString("},");
sprintf(l_sBuffer, "%i",ui64SamplingRate);
sprintf(l_sBuffer, "%i",(int)ui64SamplingRate);