Skip to content

Commit 4bfd4d4

Browse files
committed
Save Matlab path
1 parent ee3f7fb commit 4bfd4d4

File tree

4 files changed

+44
-28
lines changed

4 files changed

+44
-28
lines changed

src/Interface/Modules/Matlab/CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11

22
#
33
# For more information, please see: http://software.sci.utah.edu
4-
#
4+
#
55
# The MIT License
6-
#
6+
#
77
# Copyright (c) 2015 Scientific Computing and Imaging Institute,
88
# University of Utah.
9-
#
10-
#
9+
#
10+
#
1111
# Permission is hereby granted, free of charge, to any person obtaining a
1212
# copy of this software and associated documentation files (the "Software"),
1313
# to deal in the Software without restriction, including without limitation
1414
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
1515
# and/or sell copies of the Software, and to permit persons to whom the
1616
# Software is furnished to do so, subject to the following conditions:
17-
#
17+
#
1818
# The above copyright notice and this permission notice shall be included
19-
# in all copies or substantial portions of the Software.
20-
#
19+
# in all copies or substantial portions of the Software.
20+
#
2121
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2222
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2323
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
@@ -38,7 +38,7 @@ SET(Interface_Modules_Matlab_HEADERS
3838
share.h
3939
)
4040

41-
SET(Interface_Modules_Matlab_SOURCES
41+
SET(Interface_Modules_Matlab_SOURCES
4242
ImportDatatypesFromMatlabDialog.cc
4343
InterfaceWithMatlabDialog.cc
4444
)
@@ -53,15 +53,15 @@ SCIRUN_ADD_LIBRARY(Interface_Modules_Matlab
5353
${Interface_Modules_Matlab_SOURCES}
5454
)
5555

56-
TARGET_LINK_LIBRARIES(Interface_Modules_Matlab
57-
#Algorithms_DataIO
56+
TARGET_LINK_LIBRARIES(Interface_Modules_Matlab
5857
Modules_Legacy_Matlab_DataIO
58+
Modules_Legacy_MatlabInterface
5959
Interface_Modules_Base
6060
${SCI_BOOST_LIBRARY}
6161
${QT_LIBRARIES})
6262

6363
IF(BUILD_SHARED_LIBS)
6464
ADD_DEFINITIONS(-DBUILD_Interface_Modules_Matlab)
6565
ENDIF(BUILD_SHARED_LIBS)
66-
66+
6767
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})

src/Interface/Modules/Matlab/InterfaceWithMatlabDialog.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828

2929
#include <Interface/Modules/Matlab/InterfaceWithMatlabDialog.h>
3030
#include <Core/Algorithms/Base/AlgorithmVariableNames.h>
31+
#include <Modules/Legacy/Matlab/Interface/InterfaceWithMatlab.h>
3132
#include <QFileDialog>
3233
#include <boost/regex.hpp>
3334
#include <boost/lexical_cast.hpp>
3435

3536
using namespace SCIRun::Gui;
3637
using namespace SCIRun::Dataflow::Networks;
3738
using namespace SCIRun::Core::Algorithms;
39+
using namespace SCIRun::Core::Algorithms::Matlab;
3840

3941
InterfaceWithMatlabDialog::InterfaceWithMatlabDialog(const std::string& name, ModuleStateHandle state,
4042
QWidget* parent /* = 0 */)
@@ -50,6 +52,7 @@ InterfaceWithMatlabDialog::InterfaceWithMatlabDialog(const std::string& name, Mo
5052
WidgetStyleMixin::tabStyle(matrixTabWidget_);
5153
WidgetStyleMixin::tableHeaderStyle(matrixInputTableWidget_);
5254
addTextEditManager(matlabCodeTextEdit_, Variables::FunctionString);
55+
addLineEditManager(matlabPathLineEdit_, Parameters::MatlabPath);
5356
}
5457

5558
namespace TableColumns

src/Modules/Legacy/Matlab/Interface/InterfaceWithMatlab.cc

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -700,18 +700,24 @@ bool InterfaceWithMatlabImpl::send_matlab_job()
700700
{
701701
if (exitcond)
702702
{
703-
module_->error("InterfaceWithMatlab: the matlab engine crashed or did not start: "+ thread_info_->code_error_);
704-
module_->error("InterfaceWithMatlab: possible causes are:");
705-
module_->error("(1) matlab code failed in such a way that the engine was no able to catch the error (e.g. failure mex of code)");
706-
module_->error("(2) matlab crashed and the matlab engine detected an end of communication of the matlab process");
707-
module_->error("(3) temparory files could not be created or are corrupted");
708-
module_->error("(4) improper matlab version, use matlab V5 or higher, currently matlab V5-V7 are supported");
703+
std::ostringstream ostr;
704+
ostr <<
705+
"InterfaceWithMatlab: the matlab engine crashed or did not start: " << thread_info_->code_error_ << "\n" <<
706+
"Possible causes are:\n" <<
707+
"(1) matlab code failed in such a way that the engine was no able to catch the error (e.g. failure mex of code)\n" <<
708+
"(2) matlab crashed and the matlab engine detected an end of communication of the matlab process\n" <<
709+
"(3) temparory files could not be created or are corrupted\n" <<
710+
"(4) improper matlab version, use matlab V5 or higher, currently matlab V5-V7 are supported";
711+
module_->error(ostr.str());
709712
}
710713
else
711714
{
712-
module_->error("InterfaceWithMatlab: matlab code failed: "+thread_info_->code_error_);
713-
module_->error("InterfaceWithMatlab: Detected an error in the Matlab code, the matlab engine is still running and caught the exception");
714-
module_->error("InterfaceWithMatlab: Please check the matlab code in the GUI and try again. The output window in the GUI should contain the reported error message generated by matlab");
715+
std::ostringstream ostr;
716+
ostr <<
717+
"InterfaceWithMatlab: matlab code failed: " << thread_info_->code_error_ << "\n"
718+
"InterfaceWithMatlab: Detected an error in the Matlab code, the matlab engine is still running and caught the exception\n" <<
719+
"InterfaceWithMatlab: Please check the matlab code in the GUI and try again. The output window in the GUI should contain the reported error message generated by matlab";
720+
module_->error(ostr.str());
715721
}
716722
thread_info_->code_done_ = false;
717723
thread_info_->unlock();
@@ -772,15 +778,19 @@ bool InterfaceWithMatlab::send_input(std::string str)
772778
bool InterfaceWithMatlabImpl::open_matlab_engine()
773779
{
774780
std::string matlablibrary;
775-
const std::string inetaddress, inetport, passwd, session, startmatlab;
781+
const std::string inetaddress, inetport, passwd, session;
782+
std::string startmatlab = module_->get_state()->getValue(Parameters::MatlabPath).toString();
776783
#if 0
777784
inetaddress = inet_address_.get();
778785
inetport = inet_port_.get();
779786
passwd = inet_passwd_.get();
780787
session = inet_session_.get();
781788
startmatlab;
782789

783-
if ( sci_getenv("SCIRUN_STARTMATLAB") ) startmatlab = sci_getenv("SCIRUN_STARTMATLAB");
790+
if (startmatlab.empty())
791+
if ( sci_getenv("SCIRUN_STARTMATLAB") )
792+
startmatlab = sci_getenv("SCIRUN_STARTMATLAB");
793+
784794
if ( sci_getenv("SCIRUN_MATLABLIBRARY") ) matlablibrary = sci_getenv("SCIRUN_MATLABLIBRARY");
785795
#endif
786796
int timeout = 0;
@@ -833,12 +843,13 @@ bool InterfaceWithMatlabImpl::open_matlab_engine()
833843
matlab_engine_.reset(new ServiceClient());
834844
if(!(matlab_engine_->open(address,"matlabengine",sessionnum,passwd,timeout,startmatlab)))
835845
{
836-
module_->error(std::string("InterfaceWithMatlab: Could not open matlab engine (error=") + matlab_engine_->geterror() + std::string(")"));
837-
module_->error(std::string("InterfaceWithMatlab: Make sure the matlab engine has not been disabled in [SCIRUN_DIRECTORY]/services/matlabengine.rc"));
838-
module_->error(std::string("InterfaceWithMatlab: Press the 'Edit Local Config of Matlab Engine' to change the configuration"));
839-
module_->error(std::string("InterfaceWithMatlab: Check remote address information, or leave all fields except 'session' blank to connect to local matlab engine"));
840-
841-
matlab_engine_ = 0;
846+
std::ostringstream ostr;
847+
ostr << "InterfaceWithMatlab: Could not open matlab engine (error=" << matlab_engine_->geterror() << ").\n" <<
848+
"Make sure the matlab engine has not been disabled in [SCIRUN_DIRECTORY]/services/matlabengine.rc\n" <<
849+
"Press the 'Edit Local Config of Matlab Engine' to change the configuration.\n" <<
850+
"Check remote address information, or leave all fields except 'session' blank to connect to local matlab engine.";
851+
module_->error(ostr.str());
852+
matlab_engine_.reset();
842853
return(false);
843854
}
844855
#else
@@ -1891,6 +1902,7 @@ void InterfaceWithMatlab::tcl_command(GuiArgs& args, void* userdata)
18911902
#endif
18921903

18931904
ALGORITHM_PARAMETER_DEF(Matlab, MatlabCode);
1905+
ALGORITHM_PARAMETER_DEF(Matlab, MatlabPath);
18941906
ALGORITHM_PARAMETER_DEF(Matlab, InputMatrixNames);
18951907
ALGORITHM_PARAMETER_DEF(Matlab, InputMatrixTypes);
18961908
ALGORITHM_PARAMETER_DEF(Matlab, InputMatrixArrays);

src/Modules/Legacy/Matlab/Interface/InterfaceWithMatlab.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ namespace SCIRun {
4040
namespace Matlab
4141
{
4242
ALGORITHM_PARAMETER_DECL(MatlabCode);
43+
ALGORITHM_PARAMETER_DECL(MatlabPath);
4344
ALGORITHM_PARAMETER_DECL(InputMatrixNames);
4445
ALGORITHM_PARAMETER_DECL(InputMatrixTypes);
4546
ALGORITHM_PARAMETER_DECL(InputMatrixArrays);

0 commit comments

Comments
 (0)