Xcos GUI: implement modelica initialization 43/17543/3
Clément DAVID [Fri, 4 Dec 2015 08:52:27 +0000 (09:52 +0100)]
Change-Id: I50b7c12801850f70e1d5ad51e79097e297668726

scilab/modules/xcos/macros/xcosConfigureModelica.sci
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/InitModelicaAction.java

index 2ed10cb..fe5546a 100644 (file)
@@ -11,7 +11,7 @@
 //
 //
 
-function xcosConfigureModelica()
+function xcosConfigureModelica(scs_m)
     // Configure the current diagram with the modelica setting UI.
     //
     // Description
index 2e97fca..9d297e5 100644 (file)
 package org.scilab.modules.xcos.actions;
 
 import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.logging.Logger;
 
 import javax.swing.JButton;
+import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.InterpreterException;
+import org.scilab.modules.graph.ScilabComponent;
 
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xcos.graph.XcosDiagram;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
+import static org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.asynchronousScilabExec;
+
 /**
  * Launch the modelica compiler configuration TCL UI
  */
@@ -77,37 +83,22 @@ public final class InitModelicaAction extends SimulationNotRunningAction {
     public void actionPerformed(ActionEvent e) {
         final XcosDiagram graph = (XcosDiagram) getGraph(e);
 
-        // FIXME: implement the modelica init
-        //        // action disabled when the cell is edited
-        //        final ScilabComponent comp = ((ScilabComponent) graph.getAsComponent());
-        //        if (comp.isEditing()) {
-        //            return;
-        //        }
-        //
-        //        final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
-        //        if (handler == null) {
-        //            return;
-        //        }
-        //
-        //        graph.info(XcosMessages.INITIALIZING_MODELICA_COMPILER);
-        //
-        //        handler.writeDiagram(graph.getRootDiagram());
-        //
-        //        final String cmd = buildCall("xcosConfigureModelica");
-        //
-        //        final ActionListener action = new ActionListener() {
-        //            @Override
-        //            public void actionPerformed(ActionEvent e) {
-        //                graph.info(XcosMessages.EMPTY_INFO);
-        //                handler.release();
-        //            }
-        //        };
-        //
-        //        try {
-        //            asynchronousScilabExec(action, cmd);
-        //        } catch (InterpreterException e1) {
-        //            Logger.getLogger(InitModelicaAction.class.getName()).severe(e.toString());
-        //            handler.release();
-        //        }
+        // action disabled when the cell is edited
+        final ScilabComponent comp = ((ScilabComponent) graph.getAsComponent());
+        if (comp.isEditing()) {
+            return;
+        }
+
+        graph.info(XcosMessages.INITIALIZING_MODELICA_COMPILER);
+
+        final StringBuilder command = new StringBuilder();
+        command.append("scs_m = scicos_new(\"0x").append(Long.toHexString(graph.getRootDiagram().getUID())).append("\"); ");
+        command.append("xcosConfigureModelica(scs_m); ");
+
+        try {
+            asynchronousScilabExec((ActionEvent e1) -> { graph.info(XcosMessages.EMPTY_INFO); }, command.toString());
+        } catch (InterpreterException e1) {
+            Logger.getLogger(InitModelicaAction.class.getName()).severe(e.toString());
+        }
     }
 }