Move IOBlocks to a block/io
[scilab.git] / scilab / modules / xcos / src / java / org / scilab / modules / xcos / block / actions / RegionToSuperblockAction.java
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2009 - DIGITEO - Vincent COUVERT
4  * Copyright (C) 2009 - DIGITEO - Antoine ELIAS
5  * Copyright (C) 2009 - DIGITEO - ClĂ©ment DAVID
6  * 
7  * This file must be used under the terms of the CeCILL.
8  * This source file is licensed as described in the file COPYING, which
9  * you should have received as part of this distribution.  The terms
10  * are also available at    
11  * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
12  *
13  */
14
15 package org.scilab.modules.xcos.block.actions;
16
17 import java.util.ArrayList;
18 import java.util.Arrays;
19 import java.util.Collection;
20 import java.util.Collections;
21 import java.util.EnumMap;
22 import java.util.List;
23 import java.util.Map;
24
25 import org.scilab.modules.graph.ScilabGraph;
26 import org.scilab.modules.graph.actions.DefaultAction;
27 import org.scilab.modules.gui.menuitem.MenuItem;
28 import org.scilab.modules.hdf5.scilabTypes.ScilabDouble;
29 import org.scilab.modules.hdf5.scilabTypes.ScilabList;
30 import org.scilab.modules.hdf5.scilabTypes.ScilabString;
31 import org.scilab.modules.xcos.XcosUIDObject;
32 import org.scilab.modules.xcos.block.BasicBlock;
33 import org.scilab.modules.xcos.block.BlockFactory;
34 import org.scilab.modules.xcos.block.SplitBlock;
35 import org.scilab.modules.xcos.block.SuperBlock;
36 import org.scilab.modules.xcos.block.io.ContextUpdate;
37 import org.scilab.modules.xcos.block.io.EventInBlock;
38 import org.scilab.modules.xcos.block.io.EventOutBlock;
39 import org.scilab.modules.xcos.block.io.ExplicitInBlock;
40 import org.scilab.modules.xcos.block.io.ExplicitOutBlock;
41 import org.scilab.modules.xcos.block.io.ImplicitInBlock;
42 import org.scilab.modules.xcos.block.io.ImplicitOutBlock;
43 import org.scilab.modules.xcos.block.io.ContextUpdate.IOBlocks;
44 import org.scilab.modules.xcos.graph.SuperBlockDiagram;
45 import org.scilab.modules.xcos.graph.XcosDiagram;
46 import org.scilab.modules.xcos.io.BasicBlockInfo;
47 import org.scilab.modules.xcos.io.BlockWriter;
48 import org.scilab.modules.xcos.link.BasicLink;
49 import org.scilab.modules.xcos.link.commandcontrol.CommandControlLink;
50 import org.scilab.modules.xcos.link.explicit.ExplicitLink;
51 import org.scilab.modules.xcos.link.implicit.ImplicitLink;
52 import org.scilab.modules.xcos.port.BasicPort;
53 import org.scilab.modules.xcos.port.command.CommandPort;
54 import org.scilab.modules.xcos.port.control.ControlPort;
55 import org.scilab.modules.xcos.port.input.ExplicitInputPort;
56 import org.scilab.modules.xcos.port.input.ImplicitInputPort;
57 import org.scilab.modules.xcos.port.input.InputPort;
58 import org.scilab.modules.xcos.port.output.ExplicitOutputPort;
59 import org.scilab.modules.xcos.port.output.ImplicitOutputPort;
60 import org.scilab.modules.xcos.utils.BlockPositioning;
61 import org.scilab.modules.xcos.utils.XcosMessages;
62
63 import com.mxgraph.model.mxGeometry;
64
65
66 public class RegionToSuperblockAction extends DefaultAction {
67
68     private class BrokenLink {
69         private BasicLink link;
70         private BasicPort edge;
71         private mxGeometry geom;
72         private boolean outGoing;
73         private int portNumber;
74
75         public BrokenLink(BasicLink link, BasicPort edge, mxGeometry geom, boolean outGoing) {
76             this.link = link;
77             this.edge = edge;
78             this.outGoing = outGoing;
79             this.geom = geom;
80         }
81
82         public boolean getOutGoing() {
83             return outGoing;
84         }
85
86         public BasicLink getLink() {
87             return link;
88         }
89         
90         public BasicPort getCopiedEdge() {
91             return edge;
92         }
93
94         public mxGeometry getGeometry() {
95             return geom;
96         }
97
98         public void setPortNumber(int portNumber) {
99             this.portNumber = portNumber;
100         }
101
102         public int getPortNumber() {
103             return portNumber;
104         }
105     }
106
107     private RegionToSuperblockAction(ScilabGraph scilabGraph) {
108         super(XcosMessages.REGION_TO_SUPERBLOCK, scilabGraph);
109     }
110
111     public static MenuItem createMenu(ScilabGraph scilabGraph) {
112         return createMenu(XcosMessages.REGION_TO_SUPERBLOCK, null,
113                 new RegionToSuperblockAction(scilabGraph), null);
114     }
115
116     public void doAction() {
117
118         XcosDiagram graph = (XcosDiagram) getGraph(null);
119         graph.info(XcosMessages.GENERATE_SUPERBLOCK);
120         graph.getModel().beginUpdate();
121
122         /*
123          * Update selection and return it.
124          */
125         List<XcosUIDObject> selectedCells = updateForNotSelectedLinks(graph);
126         
127         /*
128          * Sort the selected cells to avoid misplacement
129          */
130         Collections.sort(selectedCells);
131         
132         /*
133          * Clone cells and generate a translation matrix between old and new mxCells
134          */
135         Object[] cellArrays = getGraph(null).cloneCells(selectedCells.toArray());
136         Collection<Object> cells = Arrays.asList(cellArrays);
137         XcosUIDObject[] typedCells = new XcosUIDObject[cellArrays.length];
138         cells.toArray(typedCells);
139         List<XcosUIDObject> cellsCopy = Arrays.asList(typedCells);
140         Object[] translationMatrix = new Object[cellsCopy.size()]; 
141         for (int i = 0; i < translationMatrix.length; i++) {
142             translationMatrix[i] = selectedCells.get(i);
143         }
144         
145         List<BasicBlock> blocksCopyWithoutSplitBlocks = getBlocks(cellsCopy);
146         
147         /*
148          * Getting selection rectangle
149          */
150         double minX = Double.MAX_VALUE;
151         double minY = Double.MAX_VALUE;
152         double maxX = Double.MIN_VALUE;
153         double maxY = Double.MIN_VALUE;
154
155         for (BasicBlock current  : blocksCopyWithoutSplitBlocks) {
156                 minX = Math.min(minX, current.getGeometry().getX());
157                 minY = Math.min(minY, current.getGeometry().getY());
158                 maxX = Math.max(maxX, current.getGeometry().getX());
159                 maxY = Math.max(maxY, current.getGeometry().getY());
160         }
161
162         /*
163          * Creating the superblock
164          */
165         SuperBlock superBlock = (SuperBlock) BlockFactory.createBlock("SUPER_f");
166         superBlock.setStyle("SUPER_f");
167         superBlock.getGeometry().setX((maxX + minX) / 2.0);
168         superBlock.getGeometry().setY((maxY + minY) / 2.0);
169
170
171
172         /*
173          * Creating the child graph
174          */
175         SuperBlockDiagram diagram = new SuperBlockDiagram(superBlock);
176
177         diagram.getModel().beginUpdate();
178         diagram.addCells(cellsCopy.toArray());
179         diagram.getModel().endUpdate();
180
181         /*
182          * Find broken links, to insert input/output blocks And update the child
183          * graph
184          */
185         List<BrokenLink> breaks = getBrokenLinks(selectedCells, cellsCopy);
186         List<Integer> maxValues = getMaxBlocksValues(selectedCells);
187         updateChildGraph(diagram, breaks, maxValues);
188
189         /*
190          * Delete the selected cells from the parent graph
191          */
192         graph.removeCells(graph.getSelectionCells());
193         
194         /*
195          * Update block with real parameters
196          */
197         superBlock.setRealParameters(BlockWriter.convertDiagramToMList(diagram));
198         superBlock.createChildDiagram();
199         
200         /*
201          * Update the parent
202          */
203         graph.getModel().beginUpdate();
204         graph.addCell(superBlock);
205         graph.setSelectionCell(superBlock);
206         graph.getModel().endUpdate();
207         
208         /*
209          * Calculate angle/mirrored/flipped statistics
210          */
211         int angle = 0;
212         int flipped = 0;
213         int mirrored = 0;
214         for (BasicBlock basicBlock : blocksCopyWithoutSplitBlocks) {
215             angle += basicBlock.getAngle();
216             flipped += basicBlock.getFlip()?1:0;
217             mirrored += basicBlock.getMirror()?1:0;
218         }
219         
220         /*
221          * Apply statistics to the superblock
222          */
223         int midBlockIndex = blocksCopyWithoutSplitBlocks.size()/2;
224         superBlock.setAngle(BlockPositioning.roundAngle(angle/blocksCopyWithoutSplitBlocks.size()));
225         superBlock.setFlip((flipped > midBlockIndex)?true:false);
226         superBlock.setMirror((mirrored > midBlockIndex)?true:false);
227         
228         /*
229          * Update the view
230          */
231         superBlock.updateExportedPort();
232
233         // change source or target of old link
234         createLinks(graph, superBlock, breaks);
235         superBlock.closeBlockSettings();
236         
237         /*
238          * Update the visible attributes
239          */
240         BlockPositioning.updateBlockView(superBlock);
241         
242         graph.getModel().endUpdate();
243         graph.refresh();
244         diagram.refresh();
245         graph.info(XcosMessages.EMPTY_INFO);
246     }
247
248     /**
249      * Get all the non-SplitBlock blocks in the cellsCopy.
250      */
251     private List<BasicBlock> getBlocks(List<XcosUIDObject> cellsCopy) {
252         List<BasicBlock> list = new ArrayList<BasicBlock>(cellsCopy.size());
253         for (XcosUIDObject cell : cellsCopy) {
254             if (cell instanceof BasicBlock) {
255                 if (!(cell instanceof SplitBlock)) {
256                     list.add((BasicBlock) cell);
257                 }
258             }
259         }
260         return list;
261     }
262
263     /**
264      * Check for missing links or selected ports, to add or exclude them.
265      */
266     private List<XcosUIDObject> updateForNotSelectedLinks(XcosDiagram graph) {
267
268         graph.getModel().beginUpdate();
269
270         for (int i = 0; i < graph.getSelectionCells().length; i++) {
271             XcosUIDObject current = (XcosUIDObject) graph.getSelectionCells()[i];
272             if (current instanceof BasicBlock) {
273                 BasicBlock block = (BasicBlock) current;
274                 for (int j = 0; j < block.getChildCount(); j++) {
275                     if (block.getChildAt(j) instanceof BasicPort) {
276                         BasicPort port = (BasicPort) block.getChildAt(j);
277                         if (port.getEdgeCount() > 0) {
278                             if (port.getEdgeAt(0) instanceof BasicLink) {
279                                 BasicLink link = (BasicLink) port.getEdgeAt(0);
280                                 BasicBlock otherSide = null;
281                                 if (link.getTarget() == port) {
282                                     otherSide = (BasicBlock) link.getSource()
283                                             .getParent();
284                                 } else {
285                                     otherSide = (BasicBlock) link.getTarget()
286                                             .getParent();
287                                 } // target == port
288
289                                 if (isInSelection(graph.getSelectionCells(),
290                                         otherSide)) {
291                                     graph.addSelectionCell(link);
292                                 } // isInSelection
293                                 
294                                 if (otherSide instanceof SplitBlock) {
295                                     graph.addSelectionCell(otherSide);
296                                 } // otherSide is a SplitBlock
297
298                             } // BasicLink
299                         } // Edge > 0
300                     } // BasicPort
301                 } // for child
302             } else if (current instanceof BasicPort) {
303                 // remove orphan port and connected link
304                 graph.removeSelectionCell(current.getEdgeAt(0));
305                 graph.removeSelectionCell(current);
306
307                 // restart loop
308                 i = -1;
309             }
310         } // for selection
311
312         graph.getModel().endUpdate();
313         
314         Object[] selectedCells = graph.getSelectionCells();
315         Collection<Object> cells = Arrays.asList(selectedCells);
316         XcosUIDObject[] typedCells = new XcosUIDObject[selectedCells.length];
317         cells.toArray(typedCells);
318         
319         return new ArrayList<XcosUIDObject>(Arrays.asList(typedCells));
320     }
321     
322     /**
323      * Re-link the parent Graph
324      * 
325      * @param graph
326      *            The parent graph (modified)
327      * @param superBlock
328      *            The added superblock
329      * @param breaks
330      *            The broken links
331      */
332     private void createLinks(XcosDiagram graph, SuperBlock superBlock,
333             List<BrokenLink> breaks) {
334         for (BrokenLink link : breaks) {
335             BasicPort source = null;
336             BasicPort target = null;
337
338             if (link.getOutGoing()) {
339                 target = (BasicPort) link.getLink().getTarget();
340
341                 if (link.getLink() instanceof ExplicitLink) {
342                         source = BasicBlockInfo.getAllExplicitOutputPorts(superBlock, false).get(link.getPortNumber() - 1);
343                 } else if (link.getLink() instanceof ImplicitLink) {
344                         source = BasicBlockInfo.getAllImplicitOutputPorts(superBlock, false).get(link.getPortNumber() - 1);
345                 } else if (link.getLink() instanceof CommandControlLink) {
346                         source = BasicBlockInfo.getAllCommandPorts(superBlock, false).get(link.getPortNumber() - 1);
347                 }
348             } else {
349                 source = (BasicPort) link.getLink().getSource();
350
351                 if (link.getLink() instanceof ExplicitLink) {
352                         target = BasicBlockInfo.getAllExplicitInputPorts(superBlock, false).get(link.getPortNumber() - 1);
353                 } else if (link.getLink() instanceof ImplicitLink) {
354                         target = BasicBlockInfo.getAllImplicitInputPorts(superBlock, false).get(link.getPortNumber() - 1);
355                 } else if (link.getLink() instanceof CommandControlLink) {
356                         target = BasicBlockInfo.getAllControlPorts(superBlock, false).get(link.getPortNumber() - 1);
357                 }
358             }
359
360             BasicLink newLink = BasicLink.createLinkFromPorts(source, target);
361             newLink.setGeometry(link.getLink().getGeometry());
362             newLink.setSource(source);
363             newLink.setTarget(target);
364
365             graph.getModel().beginUpdate();
366             graph.addCell(newLink);
367             graph.getModel().endUpdate();
368
369             // this method don't call CELLS_REMOVED between beginUpdate and
370             // endUpdate
371             // this function unlink source and target correctly too
372             graph.getModel().beginUpdate();
373             graph.getModel().remove(link.getLink());
374             graph.getModel().endUpdate();
375         }
376     }
377
378     /**
379      * Add the IN/OUT blocks and links in the child graph
380      * 
381      * @param diagram
382      *            The child graph
383      * @param breaks
384      *            The broken links in the parent graph
385      * @param maxValues
386      *            The I/O block values previously used in the parent diagram
387      *            (must be unique)
388      */
389     private void updateChildGraph(SuperBlockDiagram diagram,
390             List<BrokenLink> breaks, List<Integer> maxValues) {
391
392         /*
393          * Add in/out blocks in SuperBlock (Child Graph)
394          */
395         for (BrokenLink link : breaks) {
396             BasicBlock block = null;
397
398             if (link.getLink() instanceof ExplicitLink) {
399                 if (link.getOutGoing()) { // OUT_f
400                     block = BlockFactory.createBlock("OUT_f");
401                     ExplicitInputPort port = new ExplicitInputPort();
402                     port.setDefaultValues();
403                     block.addPort(port);
404                     link.setPortNumber(maxValues.get(0) + 1);
405                     maxValues.set(0, maxValues.get(0) + 1);
406                 } else { // IN_f
407                     block = BlockFactory.createBlock("IN_f");
408                     ExplicitOutputPort port = new ExplicitOutputPort();
409                     port.setDefaultValues();
410                     block.addPort(port);
411                     link.setPortNumber(maxValues.get(1) + 1);
412                     maxValues.set(1, maxValues.get(1) + 1);
413                 }
414             } else if (link.getLink() instanceof ImplicitLink) {
415                 if (link.getOutGoing()) { // OUTIMPL_f
416                     block = BlockFactory.createBlock("OUTIMPL_f");
417                     ImplicitInputPort port = new ImplicitInputPort();
418                     port.setDefaultValues();
419                     block.addPort(port);
420                     link.setPortNumber(maxValues.get(2) + 1);
421                     maxValues.set(2, maxValues.get(2) + 1);
422                 } else { // INIMPL_f
423                     block = BlockFactory.createBlock("INIMPL_f");
424                     ImplicitOutputPort port = new ImplicitOutputPort();
425                     port.setDefaultValues();
426                     block.addPort(port);
427                     link.setPortNumber(maxValues.get(3) + 1);
428                     maxValues.set(3, maxValues.get(3) + 1);
429                 }
430             } else if (link.getLink() instanceof CommandControlLink) {
431                 if (link.getOutGoing()) { // CLKOUTV_f
432                     block = BlockFactory.createBlock("CLKOUTV_f");
433                     ControlPort port = new ControlPort();
434                     port.setDefaultValues();
435                     block.addPort(port);
436                     link.setPortNumber(maxValues.get(4) + 1);
437                     maxValues.set(4, maxValues.get(4) + 1);
438                 } else { // CLKINV_f
439                     block = BlockFactory.createBlock("CLKINV_f");
440                     CommandPort port = new CommandPort();
441                     port.setDefaultValues();
442                     block.addPort(port);
443                     link.setPortNumber(maxValues.get(5) + 1);
444                     maxValues.set(5, maxValues.get(5) + 1);
445                 }
446             }
447
448             block.setGeometry(link.getGeometry());
449             block.setExprs(new ScilabString(Integer.toString(link
450                     .getPortNumber())));
451             block.setRealParameters(new ScilabDouble());
452             block.setIntegerParameters(new ScilabDouble(link.getPortNumber()));
453             block.setObjectsParameters(new ScilabList());
454
455             diagram.getModel().beginUpdate();
456             diagram.addCells(new Object[] { block });
457             diagram.getModel().endUpdate();
458
459             /*
460              * create new link in SuperBlock
461              */
462             BasicLink newLink = null;
463             if (link.getOutGoing()) { // old -> new
464                 newLink = BasicLink
465                         .createLinkFromPorts((BasicPort) link.getLink()
466                                 .getSource(), (BasicPort) block.getChildAt(0));
467                 newLink.setGeometry(link.getLink().getGeometry());
468                 newLink.setSource((BasicPort) link.getCopiedEdge());
469                 newLink.setTarget((BasicPort) block.getChildAt(0));
470             } else { // new -> old
471                 newLink = BasicLink.createLinkFromPorts((BasicPort) block
472                         .getChildAt(0), (BasicPort) link.getLink().getTarget());
473                 newLink.setGeometry(link.getLink().getGeometry());
474                 newLink.setSource((BasicPort) block.getChildAt(0));
475                 newLink.setTarget((BasicPort) link.getCopiedEdge());
476             }
477
478             diagram.getModel().beginUpdate();
479             diagram.addCell(newLink);
480             diagram.getModel().endUpdate();
481         }
482
483     }
484
485         /**
486      * Getting the broken links on the diagram and construct a list of these links
487      * @param objs The selected cells
488      * @param copiedCells The copy of the selected cells
489      * @return all the broken links in the diagram
490      */
491     private List<BrokenLink> getBrokenLinks(List<XcosUIDObject> objs, List<XcosUIDObject> copiedCells) {
492         List<BrokenLink> breaks = new ArrayList<BrokenLink>();  
493
494         int objs_length = objs.size();
495         for (int i = 0; i < objs_length; i++) {
496             if (objs.get(i) instanceof BasicBlock) {
497                 BasicBlock block = (BasicBlock) objs.get(i);
498                 for (int j = 0; j < block.getChildCount(); j++) {
499                     BasicPort port = (BasicPort) block.getChildAt(j);
500                     if (port.getEdgeCount() != 0) {
501                         BasicLink link = (BasicLink) port.getEdgeAt(0);
502                         if (block.getChildAt(j) instanceof InputPort
503                                 || block.getChildAt(j) instanceof ControlPort) {
504                             BasicBlock source = (BasicBlock) (link.getSource()
505                                     .getParent());
506                             if (!objs.contains(source)) {
507                                 BasicPort copiedPort = (BasicPort) ((BasicBlock)copiedCells.get(i)).getChildAt(j);
508                                 breaks.add(new BrokenLink(link, copiedPort, source.getGeometry(), false));
509                             }
510                         } else { // OutputPort or CommandPort
511                             BasicBlock target = (BasicBlock) (link.getTarget().getParent());
512                             if (!objs.contains(target)) {
513                                 BasicPort copiedPort = (BasicPort) ((BasicBlock)copiedCells.get(i)).getChildAt(j);
514                                 breaks.add(new BrokenLink(link, copiedPort, target.getGeometry(), true));
515                             }
516                         }
517                     }
518                 }
519             }
520         }
521         return breaks;
522     }
523
524     /**
525      * Check if an object is in a collection
526      * @param objs collection
527      * @param item the searched item
528      * @return 
529      */
530     private boolean isInSelection(Object[] objs, Object item) {
531         return Arrays.asList(objs).contains(item);
532     }
533
534     private void printBreakingLink(List<BrokenLink> breaks) {
535         System.err.println("breaks count : " + breaks.size());
536
537         for (BrokenLink brk : breaks) {
538             System.err.println("Link : " + brk.getLink());
539             System.err.println("OutGoing : " + brk.getOutGoing());
540             System.err.println("Geometry : " + brk.getGeometry());
541         }
542     }
543
544     private List<Integer> getMaxBlocksValues(List<XcosUIDObject> blocks) {
545         List<Integer> values = new ArrayList<Integer>();
546         Map<ContextUpdate.IOBlocks, List<BasicBlock>> items = new EnumMap<ContextUpdate.IOBlocks, List<BasicBlock>>(ContextUpdate.IOBlocks.class);
547
548         // ExplicitInBlock
549         for (XcosUIDObject cell : blocks) {
550             if (cell instanceof ContextUpdate) {
551             if (cell instanceof ExplicitOutBlock) {
552                 if (!items.containsKey(IOBlocks.ExplicitInBlock)) {
553                     items.put(IOBlocks.ExplicitOutBlock, new ArrayList<BasicBlock>());
554                 }
555                 items.get(IOBlocks.ExplicitOutBlock).add((BasicBlock) cell);
556             } else if (cell instanceof ExplicitInBlock) {
557                 if (!items.containsKey(IOBlocks.ExplicitInBlock)) {
558                     items.put(IOBlocks.ExplicitInBlock, new ArrayList<BasicBlock>());
559                 }
560                 items.get(IOBlocks.ExplicitInBlock).add((BasicBlock) cell);
561             } else if (cell instanceof ImplicitOutBlock) {
562                 if (!items.containsKey(IOBlocks.ImplicitOutBlock)) {
563                     items.put(IOBlocks.ImplicitOutBlock, new ArrayList<BasicBlock>());
564                 }
565                 items.get(IOBlocks.ImplicitOutBlock).add((BasicBlock) cell);
566             } else if (cell instanceof ImplicitInBlock) {
567                 if (!items.containsKey(IOBlocks.ImplicitInBlock)) {
568                     items.put(IOBlocks.ImplicitInBlock, new ArrayList<BasicBlock>());
569                 }
570                 items.get(IOBlocks.ImplicitInBlock).add((BasicBlock) cell);
571             } else if (cell instanceof EventOutBlock) {
572                 if (!items.containsKey(IOBlocks.EventOutBlock)) {
573                     items.put(IOBlocks.EventOutBlock, new ArrayList<BasicBlock>());
574                 }
575                 items.get(IOBlocks.EventOutBlock).add((BasicBlock) cell);
576             } else if (cell instanceof EventInBlock) {
577                 if (!items.containsKey(IOBlocks.EventInBlock)) {
578                     items.put(IOBlocks.EventInBlock, new ArrayList<BasicBlock>());
579                 }
580                 items.get(IOBlocks.EventInBlock).add((BasicBlock) cell);
581             }
582             }
583         }
584
585         for (IOBlocks klass : ContextUpdate.IOBlocks.values()) {
586             values.add(getMaxValue(items.get(klass)));
587         }
588
589         return values;
590     }
591
592     private int getMaxValue(List<BasicBlock> blocks) {
593         int maxValue = 0;
594         if (blocks != null) {
595             for (int i = 0; i < blocks.size(); i++) {
596                 if (((BasicBlock) blocks.get(i)).getExprs() instanceof ScilabString) {
597                     maxValue = Math.max(maxValue, Integer
598                             .parseInt(((ScilabString) ((BasicBlock) blocks
599                                     .get(i)).getExprs()).getData()[0][0]));
600                 }
601             }
602         }
603         // System.err.println("maxValue : " + maxValue);
604         return maxValue;
605     }
606 }