summaryrefslogtreecommitdiffstats
path: root/scilab
diff options
context:
space:
mode:
authorJerzy ZAGORSKI <xendoo@gmail.com>2010-06-04 16:42:23 +0200
committerJerzy ZAGORSKI <xendoo@gmail.com>2010-06-10 15:31:20 +0200
commit7804d4132ec13f624b68084d0345442ba39ab321 (patch)
treeb9086dd96e8ef069428b4666106310c3227ddfba /scilab
parent4f22d04d05afd56267f402606b85e2a7f56d7b3d (diff)
downloadscilab-7804d4132ec13f624b68084d0345442ba39ab321.zip
scilab-7804d4132ec13f624b68084d0345442ba39ab321.tar.gz
Added initial GraphicElement mapping
Change-Id: I09a3f7814d0d6d2b9ccf1da51b307dd44a8830d6
Diffstat (limited to 'scilab')
-rw-r--r--scilab/modules/xcos/src/java/org/scilab/modules/xcos/simulink/BlockElement.java43
-rw-r--r--scilab/modules/xcos/src/java/org/scilab/modules/xcos/simulink/BlockGraphicElement.java95
-rw-r--r--scilab/modules/xcos/src/java/org/scilab/modules/xcos/simulink/BlockSpecificElement.java44
-rw-r--r--scilab/modules/xcos/src/java/org/scilab/modules/xcos/simulink/ImportMdl.java41
4 files changed, 192 insertions, 31 deletions
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/simulink/BlockElement.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/simulink/BlockElement.java
index a333050..0b3904b 100644
--- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/simulink/BlockElement.java
+++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/simulink/BlockElement.java
@@ -1,3 +1,15 @@
1/*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2010 - Jerzy Zagorski
4 *
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10 *
11 */
12
1package org.scilab.modules.xcos.simulink; 13package org.scilab.modules.xcos.simulink;
2 14
3import java.io.IOException; 15import java.io.IOException;
@@ -8,6 +20,7 @@ import org.apache.commons.logging.Log;
8import org.apache.commons.logging.LogFactory; 20import org.apache.commons.logging.LogFactory;
9import org.scilab.modules.xcos.block.BasicBlock; 21import org.scilab.modules.xcos.block.BasicBlock;
10import org.scilab.modules.xcos.block.BlockFactory; 22import org.scilab.modules.xcos.block.BlockFactory;
23import org.scilab.modules.xcos.simulink.BlockGraphicElement;
11import org.scilab.modules.xcos.simulink.InputPortElement; 24import org.scilab.modules.xcos.simulink.InputPortElement;
12import org.scilab.modules.xcos.simulink.OutputPortElement; 25import org.scilab.modules.xcos.simulink.OutputPortElement;
13 26
@@ -21,6 +34,8 @@ import edu.tum.cs.simulink.model.SimulinkOutPort;
21public class BlockElement extends AbstractElement<BasicBlock> { 34public class BlockElement extends AbstractElement<BasicBlock> {
22 35
23 private SimulinkBlock base; 36 private SimulinkBlock base;
37 private BlockGraphicElement graphicElement = new BlockGraphicElement();
38 private BlockSpecificElement specificElement = new BlockSpecificElement();
24 private static final Log LOG = LogFactory.getLog(BlockElement.class); 39 private static final Log LOG = LogFactory.getLog(BlockElement.class);
25 40
26 /** Map from index to blocks */ 41 /** Map from index to blocks */
@@ -58,23 +73,27 @@ public class BlockElement extends AbstractElement<BasicBlock> {
58 private void decodeParams(BasicBlock block) { 73 private void decodeParams(BasicBlock block) {
59 // TODO Auto-generated method stub 74 // TODO Auto-generated method stub
60 75
61 /*
62 * Allocate and setup ports
63 */
64 OutputPortElement outElement = new OutputPortElement(base); 76 OutputPortElement outElement = new OutputPortElement(base);
65 UnmodifiableIterator<SimulinkOutPort> portOutIter = base.getOutPorts().iterator(); 77 UnmodifiableIterator<SimulinkOutPort> portOutIter = base.getOutPorts().iterator();
66 while(portOutIter.hasNext()) { 78 while(portOutIter.hasNext()) {
67 //block.addPort( 79 //TODO: block.addPort(outElement.decode(portOutIter.next(), null);
68 outElement.decode(portOutIter.next(), null); 80 outElement.decode(portOutIter.next(), null);
69 } 81 }
70 82
71 InputPortElement inElement = new InputPortElement(base); 83 InputPortElement inElement = new InputPortElement(base);
72 UnmodifiableIterator<SimulinkInPort> portInIter = base.getInPorts().iterator(); 84 UnmodifiableIterator<SimulinkInPort> portInIter = base.getInPorts().iterator();
73 while(portInIter.hasNext()) { 85 while(portInIter.hasNext()) {
74 //block.addPort( 86 //TODO:block.addPort(inElement.decode(portInIter.next(), null);
75 inElement.decode(portInIter.next(), null); 87 inElement.decode(portInIter.next(), null);
76 } 88 }
77 89 /*
90 * decode graphics elements of BasicBlock
91 */
92 graphicElement.decode(base, block);
93 specificElement.decode(base, block);
94 /*
95 * recursively decode all of the Block subBlocks
96 */
78 decodeSubBlocks(block); 97 decodeSubBlocks(block);
79 } 98 }
80 99
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/simulink/BlockGraphicElement.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/simulink/BlockGraphicElement.java
new file mode 100644
index 0000000..fec502a
--- /dev/null
+++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/simulink/BlockGraphicElement.java
@@ -0,0 +1,95 @@
1/*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2010 - Jerzy Zagorski
4 *
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10 *
11 */
12
13package org.scilab.modules.xcos.simulink;
14
15import org.apache.commons.logging.Log;
16import org.apache.commons.logging.LogFactory;
17import org.scilab.modules.xcos.block.BasicBlock;
18import org.scilab.modules.xcos.utils.BlockPositioning;
19
20import edu.tum.cs.simulink.model.SimulinkBlock;
21
22public class BlockGraphicElement{
23
24 private static final Log LOG = LogFactory.getLog(BlockGraphicElement.class);
25
26 public BasicBlock decode(SimulinkBlock from, BasicBlock into) {
27
28 /**
29 * mutable field used to share decoded BasicBlock with submethods
30 */
31 BasicBlock base = into;
32 validate();
33
34 /*
35 * fill the data
36 */
37 fillDimension(from, base);
38 fillOrigin(from, base);
39 fillFlipAndRotation(from, base);
40
41 return base;
42 }
43
44 private void fillFlipAndRotation(SimulinkBlock from, BasicBlock into) {
45 // TODO: Check if compatibility pattern needed
46 // TODO: Add Flip handling
47
48 String rotation = from.getParameter("BlockRotation");
49 int theta = Integer.parseInt(rotation);
50 theta = BlockPositioning.roundAngle(theta);
51
52 into.setAngle(theta);
53 }
54
55 private void fillOrigin(SimulinkBlock from, BasicBlock into) {
56 // TODO: Check if compatibility pattern needed
57 /**
58 * Position parameter read by parser is string and looks like this [55, 43, 54, 42]
59 * \\W is used to strip string from non-word characters
60 * \\s+ to split string around whitespaces
61 */
62 String[] position = from.getParameter("Position").replaceAll("\\W", " ").trim().split("\\s+");
63 if (LOG.isTraceEnabled()) {
64 LOG.trace(Integer.toString(position.length));
65 for(int i = 0; i < position.length ; i++){
66 LOG.trace(position[i]);
67 }
68 }
69 double x = Double.parseDouble(position[0]);
70 double y = Double.parseDouble(position[1]);
71
72 into.getGeometry().setX(x);
73 into.getGeometry().setY(y);
74 }
75
76 private void fillDimension(SimulinkBlock from, BasicBlock into) {
77 // TODO: Check if compatibility pattern needed
78 /**
79 * Position parameter read by parser is string and looks like this [55, 43, 54, 42]
80 * \\W is used to strip string from non-word characters
81 * \\s+ to split string around whitespaces
82 */
83 String[] position = from.getParameter("Position").replaceAll("\\W", " ").trim().split("\\s+");
84 double w = Double.parseDouble(position[2]) - Double.parseDouble(position[0]);
85 double h = Double.parseDouble(position[3]) - Double.parseDouble(position[1]);
86
87 into.getGeometry().setWidth(w);
88 into.getGeometry().setHeight(h);
89 }
90
91 private void validate() {
92 // TODO Auto-generated method stub
93
94 }
95}
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/simulink/BlockSpecificElement.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/simulink/BlockSpecificElement.java
new file mode 100644
index 0000000..79410fb
--- /dev/null
+++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/simulink/BlockSpecificElement.java
@@ -0,0 +1,44 @@
1/*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2010 - Jerzy Zagorski
4 *
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10 *
11 */
12
13package org.scilab.modules.xcos.simulink;
14
15import org.scilab.modules.xcos.block.BasicBlock;
16
17import edu.tum.cs.simulink.model.SimulinkBlock;
18
19public class BlockSpecificElement {
20 PatternElement patternElement;
21
22 public BlockSpecificElement() {
23 patternElement = new PatternElement();
24 }
25
26 public BasicBlock decode(SimulinkBlock from ,BasicBlock into) {
27
28
29 validate();
30 patternElement.printPattern();
31
32 /*
33 * fill the data
34 */
35 //findCorrespondingParameter(string simulinkParameter);
36
37 return into;
38 }
39
40 private void validate() {
41 // TODO Auto-generated method stub
42
43 }
44}
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/simulink/ImportMdl.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/simulink/ImportMdl.java
index e063489..2bc28c3 100644
--- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/simulink/ImportMdl.java
+++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/simulink/ImportMdl.java
@@ -1,3 +1,15 @@
1/*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2010 - Jerzy Zagorski
4 *
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10 *
11 */
12
1package org.scilab.modules.xcos.simulink; 13package org.scilab.modules.xcos.simulink;
2 14
3import java.io.File; 15import java.io.File;
@@ -15,6 +27,7 @@ import edu.tum.cs.simulink.model.SimulinkModel;
15import edu.tum.cs.simulink.model.SimulinkOutPort; 27import edu.tum.cs.simulink.model.SimulinkOutPort;
16 28
17import org.apache.commons.logging.LogFactory; 29import org.apache.commons.logging.LogFactory;
30import org.scilab.modules.xcos.XcosTab;
18import org.scilab.modules.xcos.graph.XcosDiagram; 31import org.scilab.modules.xcos.graph.XcosDiagram;
19import org.scilab.modules.xcos.simulink.DiagramElement; 32import org.scilab.modules.xcos.simulink.DiagramElement;
20 33
@@ -34,24 +47,14 @@ public class ImportMdl {
34 */ 47 */
35 public static void fromFile(String filename) throws IOException,SimulinkModelBuildingException { 48 public static void fromFile(String filename) throws IOException,SimulinkModelBuildingException {
36 SimulinkModelBuilder builder = new SimulinkModelBuilder(new File( 49 SimulinkModelBuilder builder = new SimulinkModelBuilder(new File(
37 filename), new SimpleLogger()); 50 filename), new SimpleLogger());
38 SimulinkModel model = builder.buildModel(); 51 SimulinkModel model = builder.buildModel();
39 DiagramElement diagram = new DiagramElement(); 52 DiagramElement diagram = new DiagramElement();
40 try { 53 try {
41 XcosDiagram into = diagram.decode(model, null); 54 XcosDiagram into = diagram.decode(model, null);
42 } catch(SimulinkFormatException e1) { 55 XcosTab.showTabFromDiagram(into);
43 LogFactory.getLog(ImportMdl.class).error(e1); 56 } catch(SimulinkFormatException e1) {
44 } 57 LogFactory.getLog(ImportMdl.class).error(e1);
45 } 58 }
46 /**
47 *
48 * @param block
49 * block or model that will be added to Xcos Schema
50 */
51 public static void readSimulinkBlock(SimulinkBlock block) {
52 UnmodifiableIterator<SimulinkBlock> blockIter = block.getSubBlocks().iterator();
53 while(blockIter.hasNext()) {
54 readSimulinkBlock(blockIter.next());
55 }
56 } 59 }
57} 60}