files = files(isfile(files));
if files == [] then
filename = gif_tlbx + "/" + names(i) + ".gif";
- xcosPalGenerateIcon(filename);
+ xcosPalGenerateIcon(blk, filename);
end
end
endfunction
XCOS_IMPEXP int sci_xcosPalMove(char *fname, void *pvApiCtx);
XCOS_IMPEXP int sci_xcosPalEnable(char *fname, void *pvApiCtx);
XCOS_IMPEXP int sci_xcosPalDisable(char *fname, void *pvApiCtx);
-XCOS_IMPEXP int sci_xcosPalGenerateIcon(char *fname, void *pvApiCtx);
XCOS_IMPEXP int sci_xcosConfigureXmlFile(char *fname, void *pvApiCtx);
XCOS_IMPEXP int sci_xcosAddToolsMenu(char *fname, void *pvApiCtx);
XCOS_IMPEXP int sci_xcosUpdateBlock(char *fname, void *pvApiCtx);
CPP_GATEWAY_PROTOTYPE_EXPORT(sci_Xcos, XCOS_IMPEXP);
CPP_GATEWAY_PROTOTYPE_EXPORT(sci_xcosCellCreated, XCOS_IMPEXP);
CPP_GATEWAY_PROTOTYPE_EXPORT(sci_xcosDiagramToScilab, XCOS_IMPEXP);
+CPP_GATEWAY_PROTOTYPE_EXPORT(sci_xcosPalGenerateIcon, XCOS_IMPEXP);
#endif /* GW_XCOS_HXX_ */
end
// generate the icon
- xcosPalGenerateIcon(iconPath);
+ xcosPalGenerateIcon(blk, iconPath);
blocks($+1) = name;
end
*
*/
+#include <string>
+
+#include "gw_xcos.hxx"
#include "Palette.hxx"
-#include "Controller.hxx"
+#include "model/BaseObject.hxx"
+#include "view_scilab/Adapters.hxx"
+
+#include "types.hxx"
+#include "function.hxx"
+#include "string.hxx"
+#include "UTF8.hxx"
+
#include "GiwsException.hxx"
#include "xcosUtilities.hxx"
#include "loadStatus.hxx"
extern "C"
{
-#include "gw_xcos.h"
-#include "api_scilab.h"
#include "localization.h"
#include "Scierror.h"
-#include "sci_malloc.h"
#include "getScilabJavaVM.h"
}
using namespace org_scilab_modules_xcos_palette;
using namespace org_scilab_modules_scicos;
-int sci_xcosPalGenerateIcon(char *fname, void* pvApiCtx)
+static char funname[] = "xcosPalGenerateIcon";
+
+types::Function::ReturnValue sci_xcosPalGenerateIcon(types::typed_list &in, int _iRetCount, types::typed_list &/*out*/)
{
- CheckRhs(1, 1);
- CheckLhs(0, 1);
+ if (in.size() != 2)
+ {
+ Scierror(999, _("%s: Wrong number of input argument(s): %d expected.\n"), funname, 2);
+ return types::Function::Error;
+ }
- char *iconPath = NULL;
+ if (_iRetCount > 1)
+ {
+ Scierror(999, _("%s: Wrong number of output argument(s): %d expected.\n"), funname, 1);
+ return types::Function::Error;
+ }
- /* iconPath setup */
- if (readSingleString(pvApiCtx, 1, &iconPath, fname))
+ const model::BaseObject* o = view_scilab::Adapters::instance().descriptor(in[0]);
+ if (o == nullptr || o->kind() != BLOCK)
{
- return 0;
+ Scierror(999, _("%s: Argument #%d: ""%s"" expected.\n"), funname, 1, "Block");
+ return types::Function::Error;
}
+ if (!in[1]->isString())
+ {
+ Scierror(999, _("%s: Argument #%d: ""%s"" expected.\n"), funname, 2, "String");
+ return types::Function::Error;
+ }
+ types::String* path = in[1]->getAs<types::String>();
+ if (path->getSize() != 1)
+ {
+ Scierror(999, _("%s: Argument #%d: Scalar (1 element) expected.\n"), funname, 2);
+ return types::Function::Error;
+ }
+ std::string iconPath = scilab::UTF8::toUTF8(path->get(0));
+
/* Call the java implementation */
set_loaded_status(XCOS_CALLED);
try
{
- Controller controller;
- Palette::generatePaletteIcon(getScilabJavaVM(), controller.createObject(DIAGRAM), iconPath);
+ Palette::generatePaletteIcon(getScilabJavaVM(), o->id(), iconPath.c_str());
}
catch (GiwsException::JniCallMethodException &exception)
{
- Scierror(999, "%s: %s\n", fname, exception.getJavaDescription().c_str());
+ Scierror(999, "%s: %s\n", funname, exception.getJavaDescription().c_str());
+ return types::Function::Error;
}
catch (GiwsException::JniException &exception)
{
- Scierror(999, "%s: %s\n", fname, exception.whatStr().c_str());
+ Scierror(999, "%s: %s\n", funname, exception.whatStr().c_str());
+ return types::Function::Error;
}
- FREE(iconPath);
-
- LhsVar(1) = 0;
- PutLhsVar();
- return 0;
+ return types::Function::OK;
}
+
<gateway name="sci_xcosPalMove" function="xcosPalMove" type="0" />
<gateway name="sci_xcosPalEnable" function="xcosPalEnable" type="0" />
<gateway name="sci_xcosPalDisable" function="xcosPalDisable" type="0" />
- <gateway name="sci_xcosPalGenerateIcon" function="xcosPalGenerateIcon" type="0" />
<gateway name="sci_xcosConfigureXmlFile" function="xcosConfigureXmlFile" type="0" />
<gateway name="sci_xcosAddToolsMenu" function="xcosAddToolsMenu" type="0" />
<gateway name="sci_loadXcos" function="loadXcos" type="0" />
<gateway name="sci_Xcos" function="xcos" type="1" />
<gateway name="sci_xcosCellCreated" function="xcosCellCreated" type="1" />
<gateway name="sci_xcosDiagramToScilab" function="xcosDiagramToScilab" type="1" />
+ <gateway name="sci_xcosPalGenerateIcon" function="xcosPalGenerateIcon" type="1" />
</module>
return block;
}
- private static BasicBlock createBlock(final JavaController controller, long uid, Kind kind) {
+ public static BasicBlock createBlock(final JavaController controller, long uid, Kind kind) {
String[] interfaceFunction = new String[1];
if (kind == Kind.BLOCK) {
controller.getObjectProperty(uid, kind, ObjectProperties.INTERFACE_FUNCTION, interfaceFunction);
import com.mxgraph.util.mxRectangle;
import com.mxgraph.view.mxGraphView;
import com.mxgraph.view.mxStylesheet;
-import org.scilab.modules.xcos.ObjectProperties;
+import org.scilab.modules.xcos.graph.model.XcosCellFactory;
/**
* Utility class which is the entry point from Scilab for palette related
if (root instanceof PreLoaded) {
pal = (PreLoaded) root;
} else if (root instanceof Category) {
- LinkedList<Category> stash = new LinkedList<Category>();
+ LinkedList<Category> stash = new LinkedList<>();
stash.add((Category) root);
pal = new PreLoaded();
}
private static List<PaletteBlock> list(Deque<Category> stash, PreLoaded pal) {
- final ArrayList<PaletteBlock> blocks = new ArrayList<PaletteBlock>();
+ final ArrayList<PaletteBlock> blocks = new ArrayList<>();
while (!stash.isEmpty()) {
final Category c = stash.pop();
for (PaletteNode n : c.getNode()) {
JavaController controller = new JavaController();
Kind kind = controller.getKind(uid);
- String[] strUID = new String[] { "" };
- controller.getObjectProperty(uid, kind, ObjectProperties.UID, strUID);
-
- String[] label = new String[] { "" };
- controller.getObjectProperty(uid, kind, ObjectProperties.LABEL, label);
-
- String[] style = new String[] { "" };
- controller.getObjectProperty(uid, kind, ObjectProperties.STYLE, style);
-
- final BasicBlock block = new BasicBlock(new JavaController(), uid, kind, label[0], null, style[0], strUID[0]);
+ final BasicBlock block = XcosCellFactory.createBlock(controller, uid, kind);
generateIcon(block, iconPath);
if (LOG.isLoggable(Level.FINEST)) {
final String extension = iconPath.substring(iconPath.lastIndexOf('.') + 1);
ImageIO.write(image, extension, new File(iconPath));
-
-
- controller.deleteObject(graph.getUID());
}
}
- <package name="org.scilab.modules.xcos.palette">
+<package name="org.scilab.modules.xcos.palette">
<object name="Palette">
<method name="loadPal" returnType="void" modifier="static">
<parameter name="name" type="String"/>