2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) DIGITEO - 2010-2010 - Clément DAVID <clement.david@scilab.org>
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
7 * This file is hereby licensed under the terms of the GNU GPL v2.0,
8 * pursuant to article 5.3.4 of the CeCILL v.2.1.
9 * This file was originally licensed under the terms of the CeCILL v2.1,
10 * and continues to be available under such terms.
11 * For more information, see the COPYING file which you should have received
12 * along with this program.
18 #include "gw_xcos.hxx"
19 #include "Palette.hxx"
20 #include "model/BaseObject.hxx"
21 #include "view_scilab/Adapters.hxx"
24 #include "function.hxx"
28 #include "GiwsException.hxx"
29 #include "xcosUtilities.hxx"
30 #include "loadStatus.hxx"
34 #include "localization.h"
36 #include "getScilabJavaVM.h"
39 using namespace org_scilab_modules_xcos_palette;
40 using namespace org_scilab_modules_scicos;
42 static char funname[] = "xcosPalGenerateIcon";
44 types::Function::ReturnValue sci_xcosPalGenerateIcon(types::typed_list &in, int _iRetCount, types::typed_list &/*out*/)
48 Scierror(999, _("%s: Wrong number of input argument(s): %d expected.\n"), funname, 2);
49 return types::Function::Error;
54 Scierror(999, _("%s: Wrong number of output argument(s): %d expected.\n"), funname, 1);
55 return types::Function::Error;
58 const model::BaseObject* o = view_scilab::Adapters::instance().descriptor(in[0]);
59 if (o == nullptr || o->kind() != BLOCK)
61 Scierror(999, _("%s: Argument #%d: ""%s"" expected.\n"), funname, 1, "Block");
62 return types::Function::Error;
65 if (!in[1]->isString())
67 Scierror(999, _("%s: Argument #%d: ""%s"" expected.\n"), funname, 2, "String");
68 return types::Function::Error;
70 types::String* path = in[1]->getAs<types::String>();
71 if (path->getSize() != 1)
73 Scierror(999, _("%s: Argument #%d: Scalar (1 element) expected.\n"), funname, 2);
74 return types::Function::Error;
76 std::string iconPath = scilab::UTF8::toUTF8(path->get(0));
78 /* Call the java implementation */
79 set_loaded_status(XCOS_CALLED);
82 Palette::generatePaletteIcon(getScilabJavaVM(), o->id(), iconPath.c_str());
84 catch (GiwsException::JniCallMethodException &exception)
86 Scierror(999, "%s: %s\n", funname, exception.getJavaDescription().c_str());
87 return types::Function::Error;
89 catch (GiwsException::JniException &exception)
91 Scierror(999, "%s: %s\n", funname, exception.whatStr().c_str());
92 return types::Function::Error;
95 return types::Function::OK;