summaryrefslogtreecommitdiffstats
path: root/scilab/modules
diff options
context:
space:
mode:
authorClément David <clement.david@esi-group.com>2021-03-16 14:14:35 +0100
committerCédric DELAMARRE <cedric.delamarre@esi-group.com>2021-04-26 14:03:36 +0200
commit35bb3727aa4d6a4dd3b04f942c7a7db3b30029ea (patch)
tree2027e2c2ffb6ef1e81ec6573f019764ac68032a9 /scilab/modules
parentafa2f09c0db4abd3ddddef1e1b24d2732c96aaca (diff)
downloadscilab-35bb3727aa4d6a4dd3b04f942c7a7db3b30029ea.zip
scilab-35bb3727aa4d6a4dd3b04f942c7a7db3b30029ea.tar.gz
Bug #8761 fixed: Xcos masked superblocks had invalid names
Change-Id: I82c5d0481c832dbdeb4bf53eae95833050351687
Diffstat (limited to 'scilab/modules')
-rw-r--r--scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/SuperblockMaskCustomizeAction.java8
-rw-r--r--scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/XcosDiagram.java14
-rw-r--r--scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/Handler.java3
-rw-r--r--scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/ScilabDirectHandler.java35
4 files changed, 34 insertions, 26 deletions
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/SuperblockMaskCustomizeAction.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/SuperblockMaskCustomizeAction.java
index 7d4c1cb..6b8cfb2 100644
--- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/SuperblockMaskCustomizeAction.java
+++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/SuperblockMaskCustomizeAction.java
@@ -29,6 +29,7 @@ import java.util.logging.Logger;
29 29
30import javax.swing.BorderFactory; 30import javax.swing.BorderFactory;
31import javax.swing.DefaultCellEditor; 31import javax.swing.DefaultCellEditor;
32import javax.swing.ImageIcon;
32import javax.swing.JComboBox; 33import javax.swing.JComboBox;
33import javax.swing.JFrame; 34import javax.swing.JFrame;
34import javax.swing.WindowConstants; 35import javax.swing.WindowConstants;
@@ -41,6 +42,7 @@ import javax.swing.event.TableModelListener;
41import javax.swing.table.DefaultTableModel; 42import javax.swing.table.DefaultTableModel;
42import javax.swing.table.TableColumn; 43import javax.swing.table.TableColumn;
43 44
45import org.scilab.modules.commons.gui.FindIconHelper;
44import org.scilab.modules.graph.ScilabComponent; 46import org.scilab.modules.graph.ScilabComponent;
45import org.scilab.modules.graph.ScilabGraph; 47import org.scilab.modules.graph.ScilabGraph;
46import org.scilab.modules.graph.actions.base.DefaultAction; 48import org.scilab.modules.graph.actions.base.DefaultAction;
@@ -160,6 +162,8 @@ public final class SuperblockMaskCustomizeAction extends DefaultAction {
160 public CustomizeFrame(XcosDiagram diagram) { 162 public CustomizeFrame(XcosDiagram diagram) {
161 setTitle(XcosMessages.MASK_TITLE); 163 setTitle(XcosMessages.MASK_TITLE);
162 setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); 164 setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
165 ImageIcon scilabIcon = new ImageIcon(FindIconHelper.findIcon("scilab"));
166 setIconImage(scilabIcon.getImage());
163 controler = new CustomizeFrameControler(diagram); 167 controler = new CustomizeFrameControler(diagram);
164 initComponents(); 168 initComponents();
165 } 169 }
@@ -686,7 +690,7 @@ public final class SuperblockMaskCustomizeAction extends DefaultAction {
686 switch (e.getType()) { 690 switch (e.getType()) {
687 case TableModelEvent.INSERT: 691 case TableModelEvent.INSERT:
688 String key = (String) customModel.getValueAt(row, 0); 692 String key = (String) customModel.getValueAt(row, 0);
689 String value = context.get(key); 693 String value = context.get(key).toString();
690 valuesModel.addRow(new Object[] { key, value }); 694 valuesModel.addRow(new Object[] { key, value });
691 break; 695 break;
692 696
@@ -717,7 +721,7 @@ public final class SuperblockMaskCustomizeAction extends DefaultAction {
717 } 721 }
718 }; 722 };
719 723
720 private final Map<String, String> context; 724 private final Map<String, ScilabType> context;
721 private Iterator<String> keyIterator; 725 private Iterator<String> keyIterator;
722 726
723 /** 727 /**
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/XcosDiagram.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/XcosDiagram.java
index 8e29c85..d903f61 100644
--- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/XcosDiagram.java
+++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/XcosDiagram.java
@@ -117,6 +117,7 @@ import java.util.HashMap;
117import java.util.Hashtable; 117import java.util.Hashtable;
118import java.util.Optional; 118import java.util.Optional;
119import java.util.stream.Collectors; 119import java.util.stream.Collectors;
120import org.scilab.modules.types.ScilabType;
120import org.scilab.modules.xcos.VectorOfBool; 121import org.scilab.modules.xcos.VectorOfBool;
121import org.scilab.modules.xcos.VectorOfScicosID; 122import org.scilab.modules.xcos.VectorOfScicosID;
122import org.scilab.modules.xcos.block.SuperBlock; 123import org.scilab.modules.xcos.block.SuperBlock;
@@ -2414,8 +2415,8 @@ public class XcosDiagram extends ScilabGraph {
2414 * @return The resulting data. Keys are variable names and Values are 2415 * @return The resulting data. Keys are variable names and Values are
2415 * evaluated values. 2416 * evaluated values.
2416 */ 2417 */
2417 public Map<String, String> evaluateContext() { 2418 public Map<String, ScilabType> evaluateContext() {
2418 Map<String, String> result = Collections.emptyMap(); 2419 Map<String, ScilabType> result = Collections.emptyMap();
2419 final ScilabDirectHandler handler = ScilabDirectHandler.acquire(); 2420 final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
2420 if (handler == null) { 2421 if (handler == null) {
2421 return result; 2422 return result;
@@ -2425,8 +2426,13 @@ public class XcosDiagram extends ScilabGraph {
2425 // first write the context strings 2426 // first write the context strings
2426 handler.writeContext(getContext()); 2427 handler.writeContext(getContext());
2427 2428
2428 // evaluate using script2var 2429 // evaluate using script2var and convert to string keys and list of values
2429 ScilabInterpreterManagement.synchronousScilabExec(ScilabDirectHandler.CONTEXT + " = script2var(" + ScilabDirectHandler.CONTEXT + ", struct());"); 2430 ScilabInterpreterManagement.synchronousScilabExec(ScilabDirectHandler.CONTEXT + " = script2var(" + ScilabDirectHandler.CONTEXT + ", struct()); "
2431 + ScilabDirectHandler.CONTEXT + "_names = fieldnames("+ScilabDirectHandler.CONTEXT+")'; "
2432 + ScilabDirectHandler.CONTEXT + "_values = list(); "
2433 + "for i=1:size(" + ScilabDirectHandler.CONTEXT + "_names, '*') ;"
2434 + " " + ScilabDirectHandler.CONTEXT + "_values(i) = " + ScilabDirectHandler.CONTEXT + "(" + ScilabDirectHandler.CONTEXT + "_names(i));"
2435 + "end");
2430 2436
2431 // read the structure 2437 // read the structure
2432 result = handler.readContext(); 2438 result = handler.readContext();
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/Handler.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/Handler.java
index a823e07..d2b6316 100644
--- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/Handler.java
+++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/Handler.java
@@ -16,6 +16,7 @@
16package org.scilab.modules.xcos.io.scicos; 16package org.scilab.modules.xcos.io.scicos;
17 17
18import java.util.Map; 18import java.util.Map;
19import org.scilab.modules.types.ScilabType;
19 20
20public interface Handler { 21public interface Handler {
21 22
@@ -24,7 +25,7 @@ public interface Handler {
24 * 25 *
25 * @return the decoded context 26 * @return the decoded context
26 */ 27 */
27 public abstract Map<String, String> readContext(); 28 public abstract Map<String, ScilabType> readContext();
28 29
29 /** 30 /**
30 * Encode an Xcos context 31 * Encode an Xcos context
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/ScilabDirectHandler.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/ScilabDirectHandler.java
index 124521f..7221b34 100644
--- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/ScilabDirectHandler.java
+++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/ScilabDirectHandler.java
@@ -15,7 +15,7 @@
15 15
16package org.scilab.modules.xcos.io.scicos; 16package org.scilab.modules.xcos.io.scicos;
17 17
18import java.util.LinkedHashMap; 18import java.util.HashMap;
19import java.util.Map; 19import java.util.Map;
20import java.util.concurrent.Semaphore; 20import java.util.concurrent.Semaphore;
21import java.util.concurrent.TimeUnit; 21import java.util.concurrent.TimeUnit;
@@ -23,7 +23,7 @@ import java.util.logging.Logger;
23 23
24import org.scilab.modules.javasci.JavasciException; 24import org.scilab.modules.javasci.JavasciException;
25import org.scilab.modules.javasci.Scilab; 25import org.scilab.modules.javasci.Scilab;
26import org.scilab.modules.types.ScilabMList; 26import org.scilab.modules.types.ScilabList;
27import org.scilab.modules.types.ScilabString; 27import org.scilab.modules.types.ScilabString;
28import org.scilab.modules.types.ScilabType; 28import org.scilab.modules.types.ScilabType;
29 29
@@ -117,34 +117,31 @@ public class ScilabDirectHandler implements Handler {
117 */ 117 */
118 118
119 @Override 119 @Override
120 public synchronized Map<String, String> readContext() { 120 public synchronized Map<String, ScilabType> readContext() {
121 LOG.entering("ScilabDirectHandler", "readContext"); 121 LOG.entering("ScilabDirectHandler", "readContext");
122 final ScilabMList list; 122 final Map<String, ScilabType> result = new HashMap<String, ScilabType>();
123 final Map<String, String> result = new LinkedHashMap<String, String>();
124 123
125 final ScilabType data; 124 final ScilabType keys;
125 final ScilabType values;
126 try { 126 try {
127 data = Scilab.getInCurrentScilabSession(CONTEXT); 127 keys = Scilab.getInCurrentScilabSession(CONTEXT + "_names");
128 values = Scilab.getInCurrentScilabSession(CONTEXT + "_values");
128 } catch (JavasciException e) { 129 } catch (JavasciException e) {
129 throw new RuntimeException(e); 130 throw new RuntimeException(e);
130 } 131 }
131 if (data instanceof ScilabMList) { 132 final ScilabString k;
132 list = (ScilabMList) data; 133 final ScilabList v;
134 if (keys instanceof ScilabString && values instanceof ScilabList) {
135 k = (ScilabString) keys;
136 v = (ScilabList) values;
133 LOG.finer("data available"); 137 LOG.finer("data available");
134 } else { 138 } else {
135 list = new ScilabMList();
136 LOG.finer("data unavailable"); 139 LOG.finer("data unavailable");
140 return result;
137 } 141 }
138 142
139 // We are starting at 2 because a struct is composed of 143 for (int i = 0; i < Math.min(k.getWidth(), v.size()); i++) {
140 // - the fields names (ScilabString) 144 result.put(k.getData()[0][i], v.get(i));
141 // - the dimension
142 // - variables values...
143 for (int index = 2; index < list.size(); index++) {
144 String key = ((ScilabString) list.get(0)).getData()[0][index];
145 String value = list.get(index).toString();
146
147 result.put(key, value);
148 } 145 }
149 146
150 LOG.exiting("ScilabDirectHandler", "readContext"); 147 LOG.exiting("ScilabDirectHandler", "readContext");