2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2010 - DIGITEO - Allan CORNET
4 * Copyright (C) 2012-2015 - Scilab Enterprises - Clement DAVID
5 * Copyright (C) 2015 - Scilab Enterprises - Paul Bignier
7 * Copyright (C) 2012 - 2016 - Scilab Enterprises
9 * This file is hereby licensed under the terms of the GNU GPL v2.0,
10 * pursuant to article 5.3.4 of the CeCILL v.2.1.
11 * This file was originally licensed under the terms of the CeCILL v2.1,
12 * and continues to be available under such terms.
13 * For more information, see the COPYING file which you should have received
14 * along with this program.
17 /*--------------------------------------------------------------------------*/
24 #include "loadStatus.hxx"
25 #include "view_scilab/Adapters.hxx"
28 #include "function.hxx"
32 #include "gw_xcos.hxx"
35 #include "sci_malloc.h"
36 #include "getFullFilename.h"
37 #include "getScilabJavaVM.h"
39 #include "localization.h"
42 using namespace org_scilab_modules_xcos;
43 using namespace org_scilab_modules_scicos;
45 static int callXcos(char* fname, char* file, long diagramId);
47 /*--------------------------------------------------------------------------*/
48 static char funname[] = "xcos";
50 types::Function::ReturnValue sci_Xcos(types::typed_list &in, int _iRetCount, types::typed_list &/*out*/)
54 Scierror(77, _("%s: Wrong number of input argument(s): %d to %d expected.\n"), funname, 0, 2);
55 return types::Function::Error;
60 Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), funname, 1);
61 return types::Function::Error;
69 callXcos(funname, nullptr, ScicosID());
70 return types::Function::OK;
74 * xcos("file.zcos") or xcos(["file.zcos" "foo.zcos"]) call
76 if (in.size() == 1 && in[0]->isString())
78 types::String* arg1 = in[0]->getAs<types::String>();
80 for (int i = 0; i < arg1->getSize(); ++i)
82 char* c_str = wide_string_to_UTF8(arg1->get(0));
83 char* file = getFullFilename(c_str);
87 return types::Function::Error;
89 if (callXcos(funname, file, ScicosID()))
92 return types::Function::Error;
97 return types::Function::OK;
103 if (in.size() == 1 && in[0]->isUserType())
105 const model::BaseObject* o = view_scilab::Adapters::instance().descriptor(in[0]);
106 if (o == nullptr || o->kind() != DIAGRAM)
108 Scierror(77, _("%s: Wrong type for input argument #%d: ""%s"" expected.\n"), funname, 1, "diagram");
109 return types::Function::Error;
112 if (callXcos(funname, nullptr, static_cast<long>(o->id())))
114 return types::Function::Error;
116 return types::Function::OK;
119 // we finished the 1-argument handling ; short-cut return with a clear error message
122 Scierror(999, _("%s: Wrong type for input argument #%d: string or ""%s"" expected.\n"), funname, 1, "diagram");
123 return types::Function::Error;
128 * xcos("file.zcos", scs_m) call ; load the file into an existing diagram
130 if (in.size() == 2 &&
134 if (in[0]->getAs<types::String>()->getSize() != 1)
136 Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), funname, 1);
137 return types::Function::Error;
140 const model::BaseObject* o = view_scilab::Adapters::instance().descriptor(in[1]);
141 if (o == nullptr || o->kind() != DIAGRAM)
143 Scierror(999, _("%s: Wrong type for input argument #%d: ""%s"" expected.\n"), funname, 2, "diagram");
144 return types::Function::Error;
147 char* c_str = wide_string_to_UTF8(in[0]->getAs<types::String>()->get(0));
148 char* file = getFullFilename(c_str);
152 return types::Function::Error;
155 if (callXcos(funname, file, o->id()))
158 return types::Function::Error;
161 return types::Function::OK;
165 * If not returned yet, display a generic error message.
167 Scierror(999, _("%s: Wrong type for input argument #%d: string or ""%s"" expected.\n"), funname, 1, "diagram");
168 return types::Function::Error;
170 /*--------------------------------------------------------------------------*/
172 static int callXcos(char *fname, char* file, long diagramId)
174 set_loaded_status(XCOS_CALLED);
178 Xcos::xcos(getScilabJavaVM(), file, diagramId);
180 catch (GiwsException::JniCallMethodException &exception)
182 std::cerr << exception.getJavaExceptionName() << std::endl;
183 std::cerr << exception.getJavaDescription() << std::endl;
184 std::cerr << exception.getJavaStackTrace() << std::endl;
186 Scierror(999, "%s: %s\n", fname,
187 exception.getJavaDescription().c_str());
190 catch (GiwsException::JniException &exception)
192 std::cerr << exception.getJavaExceptionName() << std::endl;
193 std::cerr << exception.getJavaDescription() << std::endl;
194 std::cerr << exception.getJavaStackTrace() << std::endl;
196 Scierror(999, "%s: %s\n", fname, exception.whatStr().c_str());