diff --git a/src/main/java/elntranslator/ELNTConnector.java b/src/main/java/elntranslator/ELNTConnector.java index 8de1931a37aed9af4d92c79c7a1b2c61db784189..0451de435e9aed75675bc67b1ffed0e0c93f0106 100644 --- a/src/main/java/elntranslator/ELNTConnector.java +++ b/src/main/java/elntranslator/ELNTConnector.java @@ -38,6 +38,8 @@ package elntranslator; +import java.util.LinkedList; + /** * Class ELNTConnector * Parameters of a ELN connector @@ -49,10 +51,13 @@ package elntranslator; public class ELNTConnector{ private ELNTConnectingPoint connectingPoint1; private ELNTConnectingPoint connectingPoint2; + + private LinkedList<ELNTMidPortTerminal> term; public ELNTConnector(ELNTConnectingPoint _connectingPoint1, ELNTConnectingPoint _connectingPoint2) { connectingPoint1 = _connectingPoint1; connectingPoint2 = _connectingPoint2; + term = new LinkedList<ELNTMidPortTerminal>(); } public ELNTConnectingPoint get_p1() { @@ -62,4 +67,12 @@ public class ELNTConnector{ public ELNTConnectingPoint get_p2() { return connectingPoint2; } + + public LinkedList<ELNTMidPortTerminal> getMidPortTerminal() { + return term; + } + + public void addMidPortTerminal(ELNTMidPortTerminal _term){ + term.add(_term); + } } \ No newline at end of file diff --git a/src/main/java/elntranslator/ELNTModule.java b/src/main/java/elntranslator/ELNTModule.java index bdeb99cf6ab7bb4ba9040eceb91cc37a2178edf9..2f78341883e7e6a21d0f6581dd00c60e54053f93 100644 --- a/src/main/java/elntranslator/ELNTModule.java +++ b/src/main/java/elntranslator/ELNTModule.java @@ -204,11 +204,11 @@ public class ELNTModule extends ELNTComponent { TDF_vsource.add(_TDF_vsource); } - public LinkedList<ELNTComponentModuleTerminal> getModuleTerminal() { + public LinkedList<ELNTModuleTerminal> getModuleTerminal() { return moduleTerminal; } - public void addModuleTerminal(ELNTComponentModuleTerminal _moduleTerminal){ + public void addModuleTerminal(ELNTModuleTerminal _moduleTerminal){ moduleTerminal.add(_moduleTerminal); } } \ No newline at end of file diff --git a/src/main/java/syscamstranslator/SysCAMSSpecification.java b/src/main/java/syscamstranslator/SysCAMSSpecification.java index f6d04675b8998798e797ec0c4bc40faddfd466e0..41ea6420f37be16a138c5fc3b0ba1b4755c00466 100644 --- a/src/main/java/syscamstranslator/SysCAMSSpecification.java +++ b/src/main/java/syscamstranslator/SysCAMSSpecification.java @@ -47,26 +47,26 @@ import java.util.List; * Creation: 14/05/2018 * @version 1.0 14/05/2018 * @author Irina Kit Yan LEE -*/ + */ public class SysCAMSSpecification{ - private List<SysCAMSTComponent> components; - private List<SysCAMSTConnector> connectors; - - public SysCAMSSpecification(List<SysCAMSTComponent> _components, List<SysCAMSTConnector> _connectors){ + private List<SysCAMSTComponent> components; + private List<SysCAMSTConnector> connectors; + + public SysCAMSSpecification(List<SysCAMSTComponent> _components, List<SysCAMSTConnector> _connectors){ components = _components ; connectors = _connectors ; } - - public List<SysCAMSTComponent> getComponents(){ - return components; - } - public List<SysCAMSTConnector> getConnectors(){ - return connectors; - } + public List<SysCAMSTComponent> getComponents(){ + return components; + } + + public List<SysCAMSTConnector> getConnectors(){ + return connectors; + } - public LinkedList<SysCAMSTBlockTDF> getAllBlockTDF(){ + public LinkedList<SysCAMSTBlockTDF> getAllBlockTDF(){ LinkedList<SysCAMSTBlockTDF> blocksTDF = new LinkedList<SysCAMSTBlockTDF>(); for (SysCAMSTComponent blockTDF : components) { if (blockTDF instanceof SysCAMSTBlockTDF) { @@ -74,121 +74,116 @@ public class SysCAMSSpecification{ } } return blocksTDF; - } - - public LinkedList<SysCAMSTBlockDE> getAllBlockDE(){ - LinkedList<SysCAMSTBlockDE> blocksDE = new LinkedList<SysCAMSTBlockDE>(); - for (SysCAMSTComponent blockDE : components) { - if (blockDE instanceof SysCAMSTBlockDE) { - blocksDE.add((SysCAMSTBlockDE) blockDE); - } - } - return blocksDE; - } - - public LinkedList<SysCAMSTBlockGPIO2VCI> getAllBlockGPIO2VCI(){ - LinkedList<SysCAMSTBlockGPIO2VCI> blocksGPIO2VCI = new LinkedList<SysCAMSTBlockGPIO2VCI>(); - for (SysCAMSTComponent blockGPIO2VCI : components) { - if (blockGPIO2VCI instanceof SysCAMSTBlockGPIO2VCI) { - blocksGPIO2VCI.add((SysCAMSTBlockGPIO2VCI) blockGPIO2VCI); - } - } - return blocksGPIO2VCI; - } - - public LinkedList<SysCAMSTCluster> getAllCluster(){ - LinkedList<SysCAMSTCluster> clusters = new LinkedList<SysCAMSTCluster>(); - for (SysCAMSTComponent cluster : components) { - if (cluster instanceof SysCAMSTCluster) { - clusters.add((SysCAMSTCluster) cluster); - } - } - return clusters; - } - - public LinkedList<SysCAMSTPortConverter> getAllPortConverter(){ - LinkedList<SysCAMSTPortConverter> portsConv = new LinkedList<SysCAMSTPortConverter>(); - for (SysCAMSTComponent portConv : components) { - if (portConv instanceof SysCAMSTPortConverter) { - portsConv.add((SysCAMSTPortConverter) portConv); - } - } - return portsConv; - } - - public LinkedList<SysCAMSTPortTDF> getAllPortTDF(){ - LinkedList<SysCAMSTPortTDF> portsTDF = new LinkedList<SysCAMSTPortTDF>(); - for (SysCAMSTComponent portTDF : components) { - if (portTDF instanceof SysCAMSTPortTDF) { - portsTDF.add((SysCAMSTPortTDF) portTDF); - } - } - return portsTDF; - } - - public LinkedList<SysCAMSTPortDE> getAllPortDE(){ - LinkedList<SysCAMSTPortDE> portsDE = new LinkedList<SysCAMSTPortDE>(); - for (SysCAMSTComponent portDE : components) { - if (portDE instanceof SysCAMSTPortDE) { - portsDE.add((SysCAMSTPortDE) portDE); - } - } - return portsDE; - } - - public LinkedList<SysCAMSTConnector> getAllConnectorCluster(){ - LinkedList<SysCAMSTConnector> cons = new LinkedList<SysCAMSTConnector>(); - for (SysCAMSTConnector con : connectors) { - if (con instanceof SysCAMSTConnector) { - if (con.get_p1().getComponent() instanceof SysCAMSTPortTDF && con.get_p2().getComponent() instanceof SysCAMSTPortTDF) { - cons.add(con); - } else if (con.get_p1().getComponent() instanceof SysCAMSTPortConverter && con.get_p2().getComponent() instanceof SysCAMSTPortDE) { - if (((SysCAMSTPortDE) con.get_p2().getComponent()).getBlockDE() != null) { - if ((((SysCAMSTPortDE) con.get_p2().getComponent()).getBlockDE()).getCluster() != null ) { - cons.add(con); - } - } - } else if (con.get_p2().getComponent() instanceof SysCAMSTPortConverter && con.get_p1().getComponent() instanceof SysCAMSTPortDE) { - if (((SysCAMSTPortDE) con.get_p1().getComponent()).getBlockDE() != null) { - if ((((SysCAMSTPortDE) con.get_p2().getComponent()).getBlockDE()).getCluster() != null ) { - cons.add(con); - } - } - } - } - } - return cons; - } - - public int getNbBlockTDF(){ - return (getAllBlockTDF()).size(); - } - - public int getNbBlockDE(){ - return (getAllBlockDE()).size(); - } - - public int getNbBlockGPIO2VCI(){ - return (getAllBlockGPIO2VCI()).size(); - } - - public int getNbCluster(){ - return (getAllCluster()).size(); - } - - public int getNbPortConverter(){ - return (getAllPortConverter()).size(); - } - - public int getNbPortTDF(){ - return (getAllPortTDF()).size(); - } - - public int getNbPortDE(){ - return (getAllPortDE()).size(); - } - - public int getNbConnectorCluster(){ - return (getAllConnectorCluster()).size(); - } + } + + public LinkedList<SysCAMSTBlockDE> getAllBlockDE(){ + LinkedList<SysCAMSTBlockDE> blocksDE = new LinkedList<SysCAMSTBlockDE>(); + for (SysCAMSTComponent blockDE : components) { + if (blockDE instanceof SysCAMSTBlockDE) { + blocksDE.add((SysCAMSTBlockDE) blockDE); + } + } + return blocksDE; + } + + public LinkedList<SysCAMSTBlockGPIO2VCI> getAllBlockGPIO2VCI(){ + LinkedList<SysCAMSTBlockGPIO2VCI> blocksGPIO2VCI = new LinkedList<SysCAMSTBlockGPIO2VCI>(); + for (SysCAMSTComponent blockGPIO2VCI : components) { + if (blockGPIO2VCI instanceof SysCAMSTBlockGPIO2VCI) { + blocksGPIO2VCI.add((SysCAMSTBlockGPIO2VCI) blockGPIO2VCI); + } + } + return blocksGPIO2VCI; + } + + public SysCAMSTCluster getCluster(){ + for (SysCAMSTComponent comp : components) { + if (comp instanceof SysCAMSTCluster) { + return (SysCAMSTCluster) comp; + } + } + return null; + } + + public LinkedList<SysCAMSTPortConverter> getAllPortConverter(){ + LinkedList<SysCAMSTPortConverter> portsConv = new LinkedList<SysCAMSTPortConverter>(); + for (SysCAMSTComponent portConv : components) { + if (portConv instanceof SysCAMSTPortConverter) { + portsConv.add((SysCAMSTPortConverter) portConv); + } + } + return portsConv; + } + + public LinkedList<SysCAMSTPortTDF> getAllPortTDF(){ + LinkedList<SysCAMSTPortTDF> portsTDF = new LinkedList<SysCAMSTPortTDF>(); + for (SysCAMSTComponent portTDF : components) { + if (portTDF instanceof SysCAMSTPortTDF) { + portsTDF.add((SysCAMSTPortTDF) portTDF); + } + } + return portsTDF; + } + + public LinkedList<SysCAMSTPortDE> getAllPortDE(){ + LinkedList<SysCAMSTPortDE> portsDE = new LinkedList<SysCAMSTPortDE>(); + for (SysCAMSTComponent portDE : components) { + if (portDE instanceof SysCAMSTPortDE) { + portsDE.add((SysCAMSTPortDE) portDE); + } + } + return portsDE; + } + + public LinkedList<SysCAMSTConnector> getAllConnectorCluster(){ + LinkedList<SysCAMSTConnector> cons = new LinkedList<SysCAMSTConnector>(); + for (SysCAMSTConnector con : connectors) { + if (con instanceof SysCAMSTConnector) { + if (con.get_p1().getComponent() instanceof SysCAMSTPortTDF && con.get_p2().getComponent() instanceof SysCAMSTPortTDF) { + cons.add(con); + } else if (con.get_p1().getComponent() instanceof SysCAMSTPortConverter && con.get_p2().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortDE) con.get_p2().getComponent()).getBlockDE() != null) { + if ((((SysCAMSTPortDE) con.get_p2().getComponent()).getBlockDE()).getCluster() != null ) { + cons.add(con); + } + } + } else if (con.get_p2().getComponent() instanceof SysCAMSTPortConverter && con.get_p1().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortDE) con.get_p1().getComponent()).getBlockDE() != null) { + if ((((SysCAMSTPortDE) con.get_p2().getComponent()).getBlockDE()).getCluster() != null ) { + cons.add(con); + } + } + } + } + } + return cons; + } + + public int getNbBlockTDF(){ + return (getAllBlockTDF()).size(); + } + + public int getNbBlockDE(){ + return (getAllBlockDE()).size(); + } + + public int getNbBlockGPIO2VCI(){ + return (getAllBlockGPIO2VCI()).size(); + } + + public int getNbPortConverter(){ + return (getAllPortConverter()).size(); + } + + public int getNbPortTDF(){ + return (getAllPortTDF()).size(); + } + + public int getNbPortDE(){ + return (getAllPortDE()).size(); + } + + public int getNbConnectorCluster(){ + return (getAllConnectorCluster()).size(); + } } \ No newline at end of file diff --git a/src/main/java/syscamstranslator/toSysCAMS/MakefileCode.java b/src/main/java/syscamstranslator/toSysCAMS/MakefileCode.java index 0f5dd750dda66fbc965b8639a373074f424e039e..6080c5e4dd30844b5e12be61e623727f1f168627 100644 --- a/src/main/java/syscamstranslator/toSysCAMS/MakefileCode.java +++ b/src/main/java/syscamstranslator/toSysCAMS/MakefileCode.java @@ -50,46 +50,64 @@ import java.util.LinkedList; import syscamstranslator.*; /** - * Class MakefileCode - * Principal code of a makefile - * Creation: 02/06/2018 + * Class MakefileCode Principal code of a makefile Creation: 02/06/2018 + * * @version 1.0 02/06/2018 * @author Irina Kit Yan LEE -*/ + */ public class MakefileCode { static private String corpsMakefile; private final static String CR = "\n"; private final static String CR2 = "\n\n"; - MakefileCode() {} + MakefileCode() { + } - public static String getMakefileCode(SysCAMSTCluster cluster) { - if (cluster != null) { - LinkedList<SysCAMSTBlockTDF> tdf = cluster.getBlockTDF(); - LinkedList<SysCAMSTBlockDE> de = cluster.getBlockDE(); - - corpsMakefile = "# Compiler and linker flags" + CR + "CXXFLAGS = -g -Wall -I. $(SYSTEMC_INCLUDE_DIRS)" + CR + public static String getMakefileCode(LinkedList<SysCAMSTCluster> clusters) { + if (clusters != null) { + corpsMakefile = "# Compiler and linker flags" + CR + "CXXFLAGS = -g -Wall -I. $(SYSTEMC_INCLUDE_DIRS)" + CR + "LDFLAGS = $(SYSTEMC_LIBRARY_DIRS)" + CR2 + "# List of all ecutables to be compiled" + CR - + "EXECUTABLES = " + cluster.getClusterName() + "_tb" + CR2 + "# .PHONY targets don't generate files" + CR - + ".PHONY: all clean" + CR2 + "# Default targets" + CR + "all: $(EXECUTABLES)" + CR2; - - corpsMakefile = corpsMakefile + cluster.getClusterName() + "_tb: " + cluster.getClusterName() + "_tb.cpp"; - - for (SysCAMSTBlockTDF t : tdf) { - corpsMakefile = corpsMakefile + " " + t.getName() + ".h"; + + "EXECUTABLES = "; + + for (int i = 0; i < clusters.size(); i++) { + if (i == 0) { + corpsMakefile = corpsMakefile + clusters.get(i).getClusterName() + "_tb"; + } + if (i > 0) { + corpsMakefile = corpsMakefile + " " + clusters.get(i).getClusterName() + "_tb"; + } + if (i == clusters.size() - 1) { + corpsMakefile = corpsMakefile + CR2; + } } - - for (SysCAMSTBlockDE t : de) { - corpsMakefile = corpsMakefile + " " + t.getName() + ".h"; + + corpsMakefile = corpsMakefile + "# .PHONY targets don't generate files" + CR + ".PHONY: all clean" + CR2 + + "# Default targets" + CR + "all: $(EXECUTABLES)" + CR2; + + for (int i = 0; i < clusters.size(); i++) { + LinkedList<SysCAMSTBlockTDF> tdf = clusters.get(i).getBlockTDF(); + LinkedList<SysCAMSTBlockDE> de = clusters.get(i).getBlockDE(); + + corpsMakefile = corpsMakefile + clusters.get(i).getClusterName() + "_tb: " + + clusters.get(i).getClusterName() + "_tb.cpp"; + + for (SysCAMSTBlockTDF t : tdf) { + corpsMakefile = corpsMakefile + " " + t.getName() + ".h"; + } + + for (SysCAMSTBlockDE t : de) { + corpsMakefile = corpsMakefile + " " + t.getName() + ".h"; + } + corpsMakefile = corpsMakefile + CR + + "\t$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $< -lsystemc-ams -lsystemc | c++filt" + CR2; } - - corpsMakefile = corpsMakefile + CR + "\t$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $< -lsystemc-ams -lsystemc | c++filt" - + CR2 + "# Clean rule to delete temporary and generated files" + CR + "clean:" + CR - + "\trm -rf *~ *.o *.dat *.vcd *.dSYM $(EXECUTABLES)" + CR; + + corpsMakefile = corpsMakefile + "# Clean rule to delete temporary and generated files" + CR + "clean:" + CR + + "\trm -rf *~ *.o *.dat *.vcd *.dSYM $(EXECUTABLES)" + CR; } else { corpsMakefile = ""; } return corpsMakefile; } -} +} \ No newline at end of file diff --git a/src/main/java/syscamstranslator/toSysCAMS/PrimitiveCode.java b/src/main/java/syscamstranslator/toSysCAMS/PrimitiveCode.java index 98e8bc68bdf783254ccb58dd4b47e888ed9d564b..d088f050c8c8bedfb37121efd5b8fc9a7b814262 100644 --- a/src/main/java/syscamstranslator/toSysCAMS/PrimitiveCode.java +++ b/src/main/java/syscamstranslator/toSysCAMS/PrimitiveCode.java @@ -205,7 +205,7 @@ public class PrimitiveCode { String select = tdf.getListStruct().get(i); String[] splita = select.split(" = "); identifier = splita[0]; - if (tdf.getListStruct().getSize() > 1) { + if (tdf.getListStruct().getSize() >= 1) { if (cpt == 0) { corpsPrimitiveTDF = corpsPrimitiveTDF + identifier + "(p." + identifier + ")" + CR; cpt++; @@ -533,9 +533,9 @@ public class PrimitiveCode { corpsPrimitiveDE = corpsPrimitiveDE + "\t{}" + CR2; } + corpsPrimitiveDE = corpsPrimitiveDE + "private:" + CR; + if (de.getListStruct().getSize() != 0) { - corpsPrimitiveDE = corpsPrimitiveDE + "private:" + CR; - String identifier, type, constant; for (int i = 0; i < de.getListStruct().size(); i++) { String select = de.getListStruct().get(i); @@ -555,6 +555,9 @@ public class PrimitiveCode { } else { corpsPrimitiveDE = corpsPrimitiveDE + "\t" + constant + " " + type + " " + identifier + ";" + CR; } + if (i == de.getListStruct().size()-1) { + corpsPrimitiveDE = corpsPrimitiveDE + CR; + } } } @@ -591,7 +594,7 @@ public class PrimitiveCode { } String pc = buffer.toString(); - corpsPrimitiveDE = corpsPrimitiveDE + CR + "\t" + pc; + corpsPrimitiveDE = corpsPrimitiveDE + "\t" + pc; corpsPrimitiveDE = corpsPrimitiveDE + CR + "};" + CR2 + "#endif" + " // " + de.getName().toUpperCase() + "_H"; } else { diff --git a/src/main/java/syscamstranslator/toSysCAMS/TopCellGenerator.java b/src/main/java/syscamstranslator/toSysCAMS/TopCellGenerator.java index 0c3dc7e3da0277dd6bee0c57814163f8bf458175..bdd086cb14809db39231753ad3e2768ddb88af3c 100644 --- a/src/main/java/syscamstranslator/toSysCAMS/TopCellGenerator.java +++ b/src/main/java/syscamstranslator/toSysCAMS/TopCellGenerator.java @@ -47,7 +47,6 @@ package syscamstranslator.toSysCAMS; import syscamstranslator.*; - import java.io.*; import java.util.LinkedList; @@ -70,7 +69,7 @@ public class TopCellGenerator { } public String generateTopCell(SysCAMSTCluster c, LinkedList<SysCAMSTConnector> connectors) { - if (TopCellGenerator.syscams.getNbCluster() == 0) { + if (c == null) { System.out.println("***Warning: require at least one cluster***"); } if (TopCellGenerator.syscams.getNbBlockTDF() == 0) { @@ -96,35 +95,23 @@ public class TopCellGenerator { } public void saveFile(String path) { - LinkedList<SysCAMSTCluster> clusters = TopCellGenerator.syscams.getAllCluster(); + SysCAMSTCluster cluster = TopCellGenerator.syscams.getCluster(); LinkedList<SysCAMSTConnector> connectors = TopCellGenerator.syscams.getAllConnectorCluster(); - - String top, makefile; - - for (SysCAMSTCluster c : clusters) { - try { - // Save file .cpp - System.err.println(path + GENERATED_PATH1 + c.getClusterName() + ".cpp"); - FileWriter fw = new FileWriter(path + GENERATED_PATH1 + "/" + c.getClusterName() + "_tb.cpp"); - top = generateTopCell(c, connectors); - fw.write(top); - fw.close(); - } catch (Exception ex) { - ex.printStackTrace(); - } - try { - // Save Makefile - System.err.println(path + "Makefile"); - FileWriter fw = new FileWriter(path + "/" + "Makefile"); - makefile = MakefileCode.getMakefileCode(c); - fw.write(makefile); - fw.close(); - } catch (Exception ex) { - ex.printStackTrace(); - } - // Save files .h - saveFileBlock(path, c); + + String top; + + try { + // Save file .cpp + System.err.println(path + GENERATED_PATH1 + cluster.getClusterName() + ".cpp"); + FileWriter fw = new FileWriter(path + GENERATED_PATH1 + "/" + cluster.getClusterName() + "_tb.cpp"); + top = generateTopCell(cluster, connectors); + fw.write(top); + fw.close(); + } catch (Exception ex) { + ex.printStackTrace(); } + // Save files .h + saveFileBlock(path, cluster); } public void saveFileBlock(String path, SysCAMSTCluster c) { diff --git a/src/main/java/ui/ELNPanelTranslator.java b/src/main/java/ui/ELNPanelTranslator.java new file mode 100644 index 0000000000000000000000000000000000000000..e90c3f1818b22c6e116461839e875ffc708dd345 --- /dev/null +++ b/src/main/java/ui/ELNPanelTranslator.java @@ -0,0 +1,360 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package ui; + +import ui.eln.*; +import ui.eln.sca_eln.*; +import ui.eln.sca_eln_sca_tdf.*; +import java.util.*; + +/** + * Class ELNPanelTranslator + * Translation of semantics of ELN Diagrams + * Creation: 24/07/2018 + * @version 1.0 24/07/2018 + * @author Irina Kit Yan LEE + */ + +public class ELNPanelTranslator { + private List<TGComponent> tgcComponents; + private List<ELNTComponent> elnComponents; + private List<ELNTConnector> elnConnectors; + + public ELNPanelTranslator(ELNDiagramPanel _elnDiagramPanel) { + tgcComponents = _elnDiagramPanel.getComponentList(); + + elnComponents = new LinkedList<ELNTComponent>(); + elnConnectors = new LinkedList<ELNTConnector>(); + + MakeListOfComponent(_elnDiagramPanel); + } + + private void MakeListOfComponent(ELNDiagramPanel elnDiagramPanel) { + + Map<TGComponent, ELNTComponent> elnMap = new HashMap<TGComponent, ELNTComponent>(); + + TGComponent tgc; + Iterator<TGComponent> iterator1 = tgcComponents.listIterator(); + Iterator<TGComponent> iterator2 = tgcComponents.listIterator(); + List<TGComponent> list = new ArrayList<TGComponent>(); + + while (iterator1.hasNext()) { + tgc = iterator1.next(); + if (!(tgc instanceof TGConnector)) { + list.add(tgc); + } + } + + while (iterator2.hasNext()) { + tgc = iterator2.next(); + if (tgc instanceof TGConnector) { + list.add(tgc); + } + } + + for (TGComponent dp : list) { + if (dp instanceof ELNModule) { + ELNModule module = (ELNModule) dp; + + String name = module.getValue(); + + ELNTModule elnModule = new ELNTModule(name); + + List<ELNComponentCapacitor> capacitors = module.getAllComponentCapacitor(); + for (int i = 0; i < capacitors.size(); i++) { + ELNComponentCapacitor capacitor = capacitors.get(i); + + String name = capacitor.getValue(); + double val = capacitor.getVal(); + double q0 = capacitor.getQ0(); + String unit0 = capacitor.getUnit0(); + String unit1 = capacitor.getUnit1(); + + ELNTComponentCapacitor elnCapacitor = new ELNTComponentCapacitor(name, val, q0, unit0, unit1, elnModule); + + elnMap.put(capacitor, elnCapacitor); + elnModule.addComponentCapacitor(elnCapacitor); + elnComponents.add(elnCapacitor); + } + List<ELNComponentCurrentSinkTDF> TDF_isinks = module.getAllComponentCurrentSinkTDF(); + for (int i = 0; i < TDF_isinks.size(); i++) { + ELNComponentCurrentSinkTDF TDF_isink = TDF_isinks.get(i); + + String name = TDF_isink.getValue(); + double scale = TDF_isink.getScale(); + + ELNTComponentCurrentSinkTDF elnTDF_isink = new ELNTComponentCurrentSinkTDF(name, scale, elnModule); + + elnMap.put(TDF_isink, elnTDF_isink); + elnModule.addComponentCurrentSinkTDF(elnTDF_isink); + elnComponents.add(elnTDF_isink); + } + List<ELNComponentCurrentSourceTDF> TDF_isources = module.getAllComponentCurrentSourceTDF(); + for (int i = 0; i < TDF_isources.size(); i++) { + ELNComponentCurrentSourceTDF TDF_isource = TDF_isources.get(i); + + String name = TDF_isource.getValue(); + double scale = TDF_isource.getScale(); + + ELNTComponentCurrentSourceTDF elnTDF_isource = new ELNTComponentCurrentSourceTDF(name, scale, elnModule); + + elnMap.put(TDF_isource, elnTDF_isource); + elnModule.addComponentCurrentSourceTDF(elnTDF_isource); + elnComponents.add(elnTDF_isource); + } + List<ELNComponentIdealTransformer> idealTransformers = module.getAllComponentIdealTransformer(); + for (int i = 0; i < idealTransformers.size(); i++) { + ELNComponentIdealTransformer idealTransformer = idealTransformers.get(i); + + String name = idealTransformer.getValue(); + double ratio = idealTransformer.getRatio(); + + ELNTComponentIdealTransformer elnIdealTransformer = new ELNTComponentIdealTransformer(name, ratio, elnModule); + + elnMap.put(idealTransformer, elnIdealTransformer); + elnModule.addComponentIdealTransformer(elnIdealTransformer); + elnComponents.add(elnIdealTransformer); + } + List<ELNComponentIndependentCurrentSource> isources = module.getAllComponentIndependentCurrentSource(); + for (int i = 0; i < isources.size(); i++) { + ELNComponentIndependentCurrentSource isource = isources.get(i); + + String name = isource.getValue(); + double initValue = isource.getInitValue(); + double offset = isource.getOffset(); + double amplitude = isource.getAmplitude(); + double frequency = isource.getFrequency(); + double phase = isource.getPhase(); + double acAmplitude = isource.getAcAmplitude(); + double acPhase = isource.getAcPhase(); + double acNoiseAmpliture = isource.getAcNoiseAmplitude(); + String delay = isource.getDelay(); + String unit0 = isource.getUnit0(); + + ELNTComponentIndependentCurrentSource elnISource = new ELNTComponentIndependentCurrentSource(name, initValue, offset, amplitude, frequency, phase, acAmplitude, acPhase, acNoiseAmpliture, delay, unit0, elnModule); + + elnMap.put(isource, elnISource); + elnModule.addComponentIndependentCurrentSource(elnISource); + elnComponents.add(elnISource); + } + List<ELNComponentIndependentVoltageSource> vsources = module.getAllComponentIndependentVoltageSource(); + for (int i = 0; i < vsources.size(); i++) { + ELNComponentIndependentVoltageSource vsource = vsources.get(i); + + String name = vsource.getValue(); + double initValue = vsource.getInitValue(); + double offset = vsource.getOffset(); + double amplitude = vsource.getAmplitude(); + double frequency = vsource.getFrequency(); + double phase = vsource.getPhase(); + double acAmplitude = vsource.getAcAmplitude(); + double acPhase = vsource.getAcPhase(); + double acNoiseAmpliture = vsource.getAcNoiseAmplitude(); + String delay = vsource.getDelay(); + String unit0 = vsource.getUnit0(); + + ELNTComponentIndependentVoltageSource elnVSource = new ELNTComponentIndependentVoltageSource(name, initValue, offset, amplitude, frequency, phase, acAmplitude, acPhase, acNoiseAmpliture, delay, unit0, elnModule); + + elnMap.put(vsource, elnVSource); + elnModule.addComponentIndependentVoltageSource(elnVSource); + elnComponents.add(elnVSource); + } + List<ELNComponentInductor> inductors = module.getAllComponentInductor(); + for (int i = 0; i < inductors.size(); i++) { + ELNComponentInductor inductor = inductors.get(i); + + String name = inductor.getValue(); + double val = inductor.getVal(); + double phi0 = inductor.getPhi0(); + String unit0 = inductor.getUnit0(); + String unit1 = inductor.getUnit1(); + + ELNTComponentInductor elnInductor = new ELNTComponentInductor(name, val, q0, unit0, unit1, elnModule); + + elnMap.put(inductor, elnInductor); + elnModule.addComponentInductor(elnInductor); + elnComponents.add(elnInductor); + } + List<ELNComponentNodeRef> nodeRefs = module.getAllComponentNodeRef(); + for (int i = 0; i < nodeRefs.size(); i++) { + ELNComponentNodeRef nodeRef = nodeRefs.get(i); + + String name = nodeRef.getValue(); + + ELNTComponentNodeRef elnNodeRef = new ELNTComponentNodeRef(name, elnModule); + + elnMap.put(nodeRef, elnNodeRef); + elnModule.addComponentNodeRef(elnNodeRef); + elnComponents.add(elnNodeRef); + } + List<ELNComponentResistor> resistors = module.getAllComponentResistor(); + for (int i = 0; i < resistors.size(); i++) { + ELNComponentResistor resistor = resistors.get(i); + + String name = resistor.getValue(); + double val = resistor.getVal(); + String unit = resistor.getUnit(); + + ELNTComponentResistor elnResistor = new ELNTComponentResistor(name, val, unit, elnModule); + + elnMap.put(resistor, elnResistor); + elnModule.addComponentResistor(elnResistor); + elnComponents.add(elnResistor); + } + List<ELNComponentTransmissionLine> transmissionLines = module.getAllComponentTransmissionLine(); + for (int i = 0; i < transmissionLines.size(); i++) { + ELNComponentTransmissionLine transmissionLine = transmissionLines.get(i); + + String name = transmissionLine.getValue(); + double z0 = transmissionLine.getZ0(); + double delta0 = transmissionLine.getDelta0(); + String delay = transmissionLine.getDelay(); + String unit0 = transmissionLine.getUnit0(); + String unit2 = transmissionLine.getUnit2(); + + ELNTComponentTransmissionLine elnTransmissionLine = new ELNTComponentTransmissionLine(name, z0, delta0, delay, unit0, unit2, elnModule); + + elnMap.put(transmissionLine, elnTransmissionLine); + elnModule.addComponentTransmissionLine(elnTransmissionLine); + elnComponents.add(elnTransmissionLine); + } + List<ELNComponentVoltageControlledCurrentSource> vccss = module.getAllComponentVoltageControlledCurrentSource(); + for (int i = 0; i < vccss.size(); i++) { + ELNComponentVoltageControlledCurrentSource vccs = vccss.get(i); + + String name = vccs.getValue(); + double val = vccs.getVal(); + String unit = vccs.getUnit(); + + ELNTComponentVoltageControlledCurrentSource elnVCCS = new ELNTComponentVoltageControlledCurrentSource(name, val, unit, elnModule); + + elnMap.put(vccs, elnVCCS); + elnModule.addComponentVoltageControlledCurrentSource(elnVCCS); + elnComponents.add(elnVCCS); + } + List<ELNComponentVoltageControlledVoltageSource> vcvss = module.getAllComponentVoltageControlledVoltageSource(); + for (int i = 0; i < vcvss.size(); i++) { + ELNComponentVoltageControlledVoltageSource vcvs = vcvss.get(i); + + String name = vcvs.getValue(); + double val = vcvs.getVal(); + + ELNTComponentVoltageControlledVoltageSource elnVCVS = new ELNTComponentVoltageControlledVoltageSource(name, val, elnModule); + + elnMap.put(vcvs, elnVCVS); + elnModule.addComponentVoltageControlledVoltageSource(elnVCVS); + elnComponents.add(elnVCVS); + } + List<ELNComponentVoltageSinkTDF> TDF_vsinks = module.getAllComponentVoltageSinkTDF(); + for (int i = 0; i < TDF_vsinks.size(); i++) { + ELNComponentVoltageSinkTDF TDF_vsink = TDF_vsinks.get(i); + + String name = TDF_vsink.getValue(); + double scale = TDF_vsink.getScale(); + + ELNTComponentVoltageSinkTDF elnTDF_vsink = new ELNTComponentVoltageSinkTDF(name, scale, elnModule); + + elnMap.put(TDF_vsink, elnTDF_vsink); + elnModule.addComponentVoltageSinkTDF(elnTDF_vsink); + elnComponents.add(elnTDF_vsink); + } + List<ELNComponentVoltageSourceTDF> TDF_vsources = module.getAllComponentVoltageSourceTDF(); + for (int i = 0; i < TDF_vsources.size(); i++) { + ELNComponentVoltageSourceTDF TDF_vsource = TDF_vsources.get(i); + + String name = TDF_vsource.getValue(); + double scale = TDF_vsource.getScale(); + + ELNTComponentVoltageSourceTDF elnTDF_vsource = new ELNTComponentVoltageSourceTDF(name, scale, elnModule); + + elnMap.put(TDF_vsource, elnTDF_vsource); + elnModule.addComponentVoltageSourceTDF(elnTDF_vsource); + elnComponents.add(elnTDF_vsource); + } + List<ELNModuleTerminal> moduleTerminals = module.getAllModuleTerminal(); + for (int i = 0; i < moduleTerminals.size(); i++) { + ELNModuleTerminal moduleTerminal = moduleTerminals.get(i); + + String name = moduleTerminal.getValue(); + + ELNTModuleTerminal elnModuleTerminal = new ELNTModuleTerminal(name, elnModule); + + elnMap.put(moduleTerminal, elnModuleTerminal); + elnModule.addModuleTerminal(elnModuleTerminal); + elnComponents.add(elnModuleTerminal); + } + elnMap.put(module, elnModule); + elnComponents.add(elnModule); + } else if (dp instanceof ELNConnector) { + ELNConnector connector = (ELNConnector) dp; + + TGConnectingPoint connectingPoint1 = connector.get_p1(); + TGConnectingPoint connectingPoint2 = connector.get_p2(); + + TGComponent owner_p1 = elnDiagramPanel.getComponentToWhichBelongs(connectingPoint1); + TGComponent owner_p2 = elnDiagramPanel.getComponentToWhichBelongs(connectingPoint2); + + ELNTComponent avowner_p1 = elnMap.get(owner_p1); + ELNTComponent avowner_p2 = elnMap.get(owner_p2); + + ELNTConnectingPoint avConnectingPoint1 = new ELNTConnectingPoint(avowner_p1); + ELNTConnectingPoint avConnectingPoint2 = new ELNTConnectingPoint(avowner_p2); + + ELNTConnector avconnector = new ELNTConnector(avConnectingPoint1, avConnectingPoint2); + + List<ELNMidPortTerminal> midPortTerminals = connector.getAllMidPortTerminal(); + for (int i = 0; i < midPortTerminals.size(); i++) { + ELNMidPortTerminal midPortTerminal = midPortTerminals.get(i); + + ELNTMidPortTerminal elnMidPortTerminal = new ELNTMidPortTerminal(avconnector); + + elnMap.put(midPortTerminal, elnMidPortTerminal); + avconnector.addMidPortTerminal(elnMidPortTerminal); + elnComponents.add(elnMidPortTerminal); + } + + elnConnectors.add(avconnector); + } + } + } + + public ELNSpecification getELNSpecification() { + return new ELNSpecification(elnComponents, elnConnectors); + } +} \ No newline at end of file diff --git a/src/main/java/ui/MainGUI.java b/src/main/java/ui/MainGUI.java index 434d751cf435b125396f8bf2ec95ed5e4ec1f565..891aa6172d0fe629ba288660a992fcb9f4e6699b 100644 --- a/src/main/java/ui/MainGUI.java +++ b/src/main/java/ui/MainGUI.java @@ -8582,18 +8582,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Per return null; } } - - public SysCAMSComponentTaskDiagramPanel getFirstSysCAMSPanelFound() { - SysCAMSComponentTaskDiagramPanel syscamsdp = null; - for (int i = 0; i < tabs.size(); i++) - if (tabs.get(i) instanceof SysCAMSComponentDesignPanel) { - syscamsdp = ((SysCAMSComponentDesignPanel) tabs.get(i)).syscamsctdp; - } - if (syscamsdp == null) - System.err.println("No SysCAMS Panel Found : MainGUI.getFirstSysCAMSPanelFound()"); - return syscamsdp; - } - + public void syscamsExecutableCodeGeneration() { JDialogSysCAMSExecutableCodeGeneration jgen = new JDialogSysCAMSExecutableCodeGeneration(frame, this, "Executable Code generation, compilation and execution", "../SysCAMSGenerationCode/"); diff --git a/src/main/java/ui/eln/ELNConnector.java b/src/main/java/ui/eln/ELNConnector.java index e9a8b5cb69b8080732d64f30e2db39a704ad99dd..a37827b45e32aaeaed388f8e11bdf668f0d6cb3c 100644 --- a/src/main/java/ui/eln/ELNConnector.java +++ b/src/main/java/ui/eln/ELNConnector.java @@ -40,63 +40,87 @@ package ui.eln; import ui.*; import ui.util.IconManager; - +import ui.window.JDialogELNConnector; import java.awt.*; -import java.util.Vector; +import java.util.*; +import javax.swing.JFrame; /** - * Class ELNConnector - * Connector used in ELN diagrams + * Class ELNConnector + * Connector used in ELN diagrams * Creation: 11/06/2018 * @version 1.0 11/06/2018 * @author Irina Kit Yan LEE */ -public class ELNConnector extends TGConnector implements ScalableTGComponent { - +public class ELNConnector extends TGConnector implements ScalableTGComponent { protected double oldScaleFactor; - protected int c = 10; //square length - - public ELNConnector(int _x, int _y, int _minX, int _minY, int _maxX, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp, TGConnectingPoint _p1, TGConnectingPoint _p2, Vector<Point> _listPoint) { - super(_x, _y, _minX, _minY, _maxX, _maxY, _pos, _father, _tdp, _p1, _p2, _listPoint); - myImageIcon = IconManager.imgic202; - value = "Connector between ports"; - editable = false; - oldScaleFactor = tdp.getZoom(); - p1 = _p1; - p2 = _p2; - } - - public TGConnectingPoint get_p1(){ - return p1; + + public ELNConnector(int _x, int _y, int _minX, int _minY, int _maxX, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp, TGConnectingPoint _p1, TGConnectingPoint _p2, Vector<Point> _listPoint) { + super(_x, _y, _minX, _minY, _maxX, _maxY, _pos, _father, _tdp, _p1, _p2, _listPoint); + + myImageIcon = IconManager.imgic202; + value = ""; + editable = true; + oldScaleFactor = tdp.getZoom(); + + p1 = _p1; + p2 = _p2; } - public TGConnectingPoint get_p2(){ - return p2; + public TGConnectingPoint get_p1() { + return p1; } - protected void drawLastSegment(Graphics g, int x1, int y1, int x2, int y2) { - g.drawLine(x1, y1, x2, y2); - } - - public void rescale(double scaleFactor){ - int xx, yy; - - for(int i=0; i<nbInternalTGComponent; i++) { - xx = tgcomponent[i].getX(); - yy = tgcomponent[i].getY(); - tgcomponent[i].dx = (tgcomponent[i].dx + xx) / oldScaleFactor * scaleFactor; - tgcomponent[i].dy = (tgcomponent[i].dy + yy) / oldScaleFactor * scaleFactor; - xx = (int)(tgcomponent[i].dx); - tgcomponent[i].dx = tgcomponent[i].dx - xx; - yy = (int)(tgcomponent[i].dy); - tgcomponent[i].dy = tgcomponent[i].dy - yy; - tgcomponent[i].setCd(xx, yy); - } - oldScaleFactor = scaleFactor; - } - - public int getType() { - return TGComponentManager.ELN_CONNECTOR; - } + public TGConnectingPoint get_p2() { + return p2; + } + + public boolean editOndoubleClick(JFrame frame) { + JDialogELNConnector jde = new JDialogELNConnector(this); + jde.setVisible(true); + return true; + } + + protected void drawLastSegment(Graphics g, int x1, int y1, int x2, int y2) { + int w = g.getFontMetrics().stringWidth(value); + Font fold = g.getFont(); + Font f = fold.deriveFont(Font.ITALIC, (float) (tdp.getFontSize())); + g.setFont(f); + g.drawString(value, (x1 + x2 - w) / 2, (y1 + y2) / 2); + g.setFont(fold); + + g.drawLine(x1, y1, x2, y2); + } + + public void rescale(double scaleFactor) { + int xx, yy; + + for (int i = 0; i < nbInternalTGComponent; i++) { + xx = tgcomponent[i].getX(); + yy = tgcomponent[i].getY(); + tgcomponent[i].dx = (tgcomponent[i].dx + xx) / oldScaleFactor * scaleFactor; + tgcomponent[i].dy = (tgcomponent[i].dy + yy) / oldScaleFactor * scaleFactor; + xx = (int) (tgcomponent[i].dx); + tgcomponent[i].dx = tgcomponent[i].dx - xx; + yy = (int) (tgcomponent[i].dy); + tgcomponent[i].dy = tgcomponent[i].dy - yy; + tgcomponent[i].setCd(xx, yy); + } + oldScaleFactor = scaleFactor; + } + + public int getType() { + return TGComponentManager.ELN_CONNECTOR; + } + + public java.util.List<ELNMidPortTerminal> getAllMidPortTerminal() { + java.util.List<ELNMidPortTerminal> list = new ArrayList<ELNMidPortTerminal>(); + for (int i = 0; i < nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof ELNMidPortTerminal) { + list.add((ELNMidPortTerminal) (tgcomponent[i])); + } + } + return list; + } } \ No newline at end of file diff --git a/src/main/java/ui/eln/ELNModule.java b/src/main/java/ui/eln/ELNModule.java index 3784c2cbf303a1b7b973cd6229826da904766803..08f9c1895b3fb8a35a72170ce042fc5dd0491c15 100644 --- a/src/main/java/ui/eln/ELNModule.java +++ b/src/main/java/ui/eln/ELNModule.java @@ -41,6 +41,7 @@ package ui.eln; import myutil.GraphicLib; import ui.*; import ui.eln.sca_eln.*; +import ui.eln.sca_eln_sca_tdf.*; import ui.util.IconManager; import ui.window.*; import java.awt.*; @@ -262,8 +263,148 @@ public class ELNModule extends TGCScalableWithInternalComponent implements Swall public int getCurrentFontSize() { return currentFontSize; } - - public java.util.List<ELNModuleTerminal> getAllPorts() { + + public java.util.List<ELNComponentCapacitor> getAllComponentCapacitor() { + java.util.List<ELNComponentCapacitor> list = new ArrayList<ELNComponentCapacitor>(); + for(int i=0; i<nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof ELNComponentCapacitor) { + list.add((ELNComponentCapacitor)(tgcomponent[i])); + } + } + return list; + } + + public java.util.List<ELNComponentCurrentSinkTDF> getAllComponentCurrentSinkTDF() { + java.util.List<ELNComponentCurrentSinkTDF> list = new ArrayList<ELNComponentCurrentSinkTDF>(); + for(int i=0; i<nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof ELNComponentCurrentSinkTDF) { + list.add((ELNComponentCurrentSinkTDF)(tgcomponent[i])); + } + } + return list; + } + + public java.util.List<ELNComponentCurrentSourceTDF> getAllComponentCurrentSourceTDF() { + java.util.List<ELNComponentCurrentSourceTDF> list = new ArrayList<ELNComponentCurrentSourceTDF>(); + for(int i=0; i<nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof ELNComponentCurrentSourceTDF) { + list.add((ELNComponentCurrentSourceTDF)(tgcomponent[i])); + } + } + return list; + } + + public java.util.List<ELNComponentIdealTransformer> getAllComponentIdealTransformer() { + java.util.List<ELNComponentIdealTransformer> list = new ArrayList<ELNComponentIdealTransformer>(); + for(int i=0; i<nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof ELNComponentIdealTransformer) { + list.add((ELNComponentIdealTransformer)(tgcomponent[i])); + } + } + return list; + } + + public java.util.List<ELNComponentIndependentCurrentSource> getAllComponentIndependentCurrentSource() { + java.util.List<ELNComponentIndependentCurrentSource> list = new ArrayList<ELNComponentIndependentCurrentSource>(); + for(int i=0; i<nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof ELNComponentIndependentCurrentSource) { + list.add((ELNComponentIndependentCurrentSource)(tgcomponent[i])); + } + } + return list; + } + + public java.util.List<ELNComponentIndependentVoltageSource> getAllComponentIndependentVoltageSource() { + java.util.List<ELNComponentIndependentVoltageSource> list = new ArrayList<ELNComponentIndependentVoltageSource>(); + for(int i=0; i<nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof ELNComponentIndependentVoltageSource) { + list.add((ELNComponentIndependentVoltageSource)(tgcomponent[i])); + } + } + return list; + } + + public java.util.List<ELNComponentInductor> getAllComponentInductor() { + java.util.List<ELNComponentInductor> list = new ArrayList<ELNComponentInductor>(); + for(int i=0; i<nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof ELNComponentInductor) { + list.add((ELNComponentInductor)(tgcomponent[i])); + } + } + return list; + } + + public java.util.List<ELNComponentNodeRef> getAllComponentNodeRef() { + java.util.List<ELNComponentNodeRef> list = new ArrayList<ELNComponentNodeRef>(); + for(int i=0; i<nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof ELNComponentNodeRef) { + list.add((ELNComponentNodeRef)(tgcomponent[i])); + } + } + return list; + } + + public java.util.List<ELNComponentResistor> getAllComponentResistor() { + java.util.List<ELNComponentResistor> list = new ArrayList<ELNComponentResistor>(); + for(int i=0; i<nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof ELNComponentResistor) { + list.add((ELNComponentResistor)(tgcomponent[i])); + } + } + return list; + } + + public java.util.List<ELNComponentTransmissionLine> getAllComponentTransmissionLine() { + java.util.List<ELNComponentTransmissionLine> list = new ArrayList<ELNComponentTransmissionLine>(); + for(int i=0; i<nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof ELNComponentTransmissionLine) { + list.add((ELNComponentTransmissionLine)(tgcomponent[i])); + } + } + return list; + } + + public java.util.List<ELNComponentVoltageControlledCurrentSource> getAllComponentVoltageControlledCurrentSource() { + java.util.List<ELNComponentVoltageControlledCurrentSource> list = new ArrayList<ELNComponentVoltageControlledCurrentSource>(); + for(int i=0; i<nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof ELNComponentVoltageControlledCurrentSource) { + list.add((ELNComponentVoltageControlledCurrentSource)(tgcomponent[i])); + } + } + return list; + } + + public java.util.List<ELNComponentVoltageControlledVoltageSource> getAllComponentVoltageControlledVoltageSource() { + java.util.List<ELNComponentVoltageControlledVoltageSource> list = new ArrayList<ELNComponentVoltageControlledVoltageSource>(); + for(int i=0; i<nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof ELNComponentVoltageControlledVoltageSource) { + list.add((ELNComponentVoltageControlledVoltageSource)(tgcomponent[i])); + } + } + return list; + } + + public java.util.List<ELNComponentVoltageSinkTDF> getAllComponentVoltageSinkTDF() { + java.util.List<ELNComponentVoltageSinkTDF> list = new ArrayList<ELNComponentVoltageSinkTDF>(); + for(int i=0; i<nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof ELNComponentVoltageSinkTDF) { + list.add((ELNComponentVoltageSinkTDF)(tgcomponent[i])); + } + } + return list; + } + + public java.util.List<ELNComponentVoltageSourceTDF> getAllComponentVoltageSourceTDF() { + java.util.List<ELNComponentVoltageSourceTDF> list = new ArrayList<ELNComponentVoltageSourceTDF>(); + for(int i=0; i<nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof ELNComponentVoltageSourceTDF) { + list.add((ELNComponentVoltageSourceTDF)(tgcomponent[i])); + } + } + return list; + } + + public java.util.List<ELNModuleTerminal> getAllModuleTerminal() { java.util.List<ELNModuleTerminal> list = new ArrayList<ELNModuleTerminal>(); for(int i=0; i<nbInternalTGComponent; i++) { if (tgcomponent[i] instanceof ELNModuleTerminal) { diff --git a/src/main/java/ui/syscams/SysCAMSPrimitivePort.java b/src/main/java/ui/syscams/SysCAMSPrimitivePort.java index f2072a66a16df8495b07b94c0bc03e2072b69335..9b5b5bffb497041d88b350ca3d5e3eb950ca7277 100644 --- a/src/main/java/ui/syscams/SysCAMSPrimitivePort.java +++ b/src/main/java/ui/syscams/SysCAMSPrimitivePort.java @@ -401,6 +401,9 @@ public class SysCAMSPrimitivePort extends TGCScalableWithInternalComponent imple case '>' : buffer.append(">"); break; + case '\u03BC': + buffer.append("μ"); + break; default : buffer.append(databuf.charAt(pos)); break; diff --git a/src/main/java/ui/window/JDialogELNConnector.java b/src/main/java/ui/window/JDialogELNConnector.java new file mode 100644 index 0000000000000000000000000000000000000000..4a71e3196d48b59b5c0d393e58ecd905e04772fd --- /dev/null +++ b/src/main/java/ui/window/JDialogELNConnector.java @@ -0,0 +1,151 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package ui.window; + +import ui.eln.ELNConnector; +import ui.util.*; +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +/** + * Class JDialogELNConnector + * Dialog for managing of ELN connector + * Creation: 24/07/2018 + * @version 1.0 24/07/2018 + * @author Irina Kit Yan LEE + */ + +@SuppressWarnings("serial") + +public class JDialogELNConnector extends JDialog implements ActionListener { + + private JTextField nameTextField; + + private ELNConnector con; + + public JDialogELNConnector(ELNConnector con) { + this.setTitle("Setting Connector Attributes"); + this.setLocationRelativeTo(null); + this.setVisible(true); + this.setAlwaysOnTop(true); + this.setResizable(false); + + this.con = con; + + getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "close"); + getRootPane().getActionMap().put("close", new AbstractAction() { + public void actionPerformed(ActionEvent e) { + dispose(); + } + }); + + dialog(); + } + + public void dialog() { + JPanel mainPanel = new JPanel(new BorderLayout()); + this.add(mainPanel); + + JPanel attributesMainPanel = new JPanel(); + mainPanel.add(attributesMainPanel, BorderLayout.NORTH); + + attributesMainPanel.setLayout(new BorderLayout()); + + Box attributesBox = Box.createVerticalBox(); + attributesBox.setBorder(BorderFactory.createTitledBorder("Setting connector attributes")); + + GridBagLayout gridBag = new GridBagLayout(); + GridBagConstraints constraints = new GridBagConstraints(); + JPanel attributesBoxPanel = new JPanel(); + attributesBoxPanel.setFont(new Font("Helvetica", Font.PLAIN, 14)); + attributesBoxPanel.setLayout(gridBag); + + JLabel labelName = new JLabel("Name : "); + constraints = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(15, 10, 5, 10), 0, 0); + gridBag.setConstraints(labelName, constraints); + attributesBoxPanel.add(labelName); + + if (con.getValue().toString().equals("")) { + nameTextField = new JTextField(10); + } else { + nameTextField = new JTextField(con.getValue().toString(), 10); + } + constraints = new GridBagConstraints(1, 0, 2, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(15, 10, 5, 10), 0, 0); + gridBag.setConstraints(nameTextField, constraints); + attributesBoxPanel.add(nameTextField); + + attributesBox.add(attributesBoxPanel); + + attributesMainPanel.add(attributesBox, BorderLayout.NORTH); + + JPanel downPanel = new JPanel(new FlowLayout()); + + JButton saveCloseButton = new JButton("Save and close"); + saveCloseButton.setIcon(IconManager.imgic25); + saveCloseButton.setActionCommand("Save_Close"); + saveCloseButton.addActionListener(this); + saveCloseButton.setPreferredSize(new Dimension(200, 30)); + downPanel.add(saveCloseButton); + + JButton cancelButton = new JButton("Cancel"); + cancelButton.setIcon(IconManager.imgic27); + cancelButton.setActionCommand("Cancel"); + cancelButton.addActionListener(this); + cancelButton.setPreferredSize(new Dimension(200, 30)); + downPanel.add(cancelButton); + + mainPanel.add(downPanel, BorderLayout.CENTER); + pack(); + this.getRootPane().setDefaultButton(saveCloseButton); + } + + public void actionPerformed(ActionEvent e) { + if ("Save_Close".equals(e.getActionCommand())) { + con.setValue(new String(nameTextField.getText())); + this.dispose(); + } + + if ("Cancel".equals(e.getActionCommand())) { + this.dispose(); + } + } +} \ No newline at end of file diff --git a/src/main/java/ui/window/JDialogSysCAMSExecutableCodeGeneration.java b/src/main/java/ui/window/JDialogSysCAMSExecutableCodeGeneration.java index 82286b763bf2e173bbd907073539d00ca417ee07..b87a16a33582dd67bc8a589270813f55afd4706a 100644 --- a/src/main/java/ui/window/JDialogSysCAMSExecutableCodeGeneration.java +++ b/src/main/java/ui/window/JDialogSysCAMSExecutableCodeGeneration.java @@ -38,11 +38,13 @@ package ui.window; +import syscamstranslator.toSysCAMS.MakefileCode; import syscamstranslator.toSysCAMS.TopCellGenerator; import launcher.LauncherException; import launcher.RshClient; import myutil.*; import syscamstranslator.SysCAMSSpecification; +import syscamstranslator.SysCAMSTCluster; import ui.util.IconManager; import ui.MainGUI; import ui.SysCAMSPanelTranslator; @@ -52,8 +54,11 @@ import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.FileWriter; import java.io.StringWriter; import java.io.Writer; +import java.util.LinkedList; +import java.util.Vector; /** * Class JDialogSysCAMSExecutableCodeGeneration @@ -500,38 +505,56 @@ public class JDialogSysCAMSExecutableCodeGeneration extends javax.swing.JFrame i if (jp1.getSelectedIndex() == 0) { jta.append("Generating executable code (SystemC-AMS version)\n"); - SysCAMSComponentTaskDiagramPanel syscamsDiagramPanel = mgui.getFirstSysCAMSPanelFound(); - SysCAMSPanelTranslator syscamspaneltranslator = new SysCAMSPanelTranslator(syscamsDiagramPanel); - SysCAMSSpecification syscalsspec = syscamspaneltranslator.getSysCAMSSpecification(); - - // Generating code - if (syscalsspec == null) { - jta.append("Error: No SYSCAMS specification\n"); - } else { - System.err.println("**SYSCAMS TOPCELL found"); - - TopCellGenerator topCellGenerator = new TopCellGenerator(syscalsspec); - testGo(); - jta.append("Generation of TopCell executable code: done\n"); - - try { - jta.append("Saving SysCAMS code in files\n"); - System.err.println("Saving SysCAMS code in files\n"); - pathCode = code2.getText(); - - System.err.println("SYSCAMS TOPCELL saved in " + code2.getText()); - topCellGenerator.saveFile(pathCode); - - jta.append("Code saved\n"); - } catch (Exception e) { - jta.append("Could not generate files\n"); - System.err.println("Could not generate SysCAMS files\n"); - e.printStackTrace(); - } + Vector<SysCAMSComponentTaskDiagramPanel> syscamsDiagramPanels = mgui.getListSysCAMSPanel(); + LinkedList<SysCAMSTCluster> clusters = new LinkedList<SysCAMSTCluster>(); + for (SysCAMSComponentTaskDiagramPanel syscamsDiagramPanel : syscamsDiagramPanels) { + SysCAMSPanelTranslator syscamspaneltranslator = new SysCAMSPanelTranslator(syscamsDiagramPanel); + SysCAMSSpecification syscalsspec = syscamspaneltranslator.getSysCAMSSpecification(); + clusters.add(syscalsspec.getCluster()); } - + for (SysCAMSComponentTaskDiagramPanel syscamsDiagramPanel : syscamsDiagramPanels) { + SysCAMSPanelTranslator syscamspaneltranslator = new SysCAMSPanelTranslator(syscamsDiagramPanel); + SysCAMSSpecification syscalsspec = syscamspaneltranslator.getSysCAMSSpecification(); + + // Generating code + if (syscalsspec == null) { + jta.append("Error: No SYSCAMS specification\n"); + } else { + System.err.println("**SYSCAMS TOPCELL found"); + + TopCellGenerator topCellGenerator = new TopCellGenerator(syscalsspec); + testGo(); + jta.append("Generation of TopCell \"" + syscalsspec.getCluster().getClusterName() + "\" executable code: done\n"); + + try { + jta.append("Saving SysCAMS code in files\n"); + System.err.println("Saving SysCAMS code in files\n"); + pathCode = code2.getText(); + + System.err.println("SYSCAMS TOPCELL : " + syscalsspec.getCluster().getClusterName() + "saved in " + code2.getText()); + topCellGenerator.saveFile(pathCode); + + jta.append("Code saved\n"); + } catch (Exception e) { + jta.append("Could not generate files\n"); + System.err.println("Could not generate SysCAMS files\n"); + e.printStackTrace(); + } + } + testGo(); + } + try { + String makefile; + System.err.println(pathCode + "Makefile"); + FileWriter fw = new FileWriter(pathCode + "/" + "Makefile"); + makefile = MakefileCode.getMakefileCode(clusters); + fw.write(makefile); + fw.close(); + } catch (Exception ex) { + ex.printStackTrace(); + } testGo(); - + } // if (removeCFiles.isSelected()) { // // jta.append("Removing all .h files\n"); @@ -652,7 +675,7 @@ public class JDialogSysCAMSExecutableCodeGeneration extends javax.swing.JFrame i // if ((hasError == false) && (jp1.getSelectedIndex() < 2)) { // jp1.setSelectedIndex(jp1.getSelectedIndex() + 1); // } - }} catch (InterruptedException ie) { + } catch (InterruptedException ie) { jta.append("Interrupted\n"); } diff --git a/src/main/java/ui/window/JDialogSysCAMSPortConverter.java b/src/main/java/ui/window/JDialogSysCAMSPortConverter.java index f97aad8c14411735f518fb6c0b506de489fa1369..1a985c62dd4b2219bd803e256f802511c0b61d61 100644 --- a/src/main/java/ui/window/JDialogSysCAMSPortConverter.java +++ b/src/main/java/ui/window/JDialogSysCAMSPortConverter.java @@ -144,17 +144,20 @@ public class JDialogSysCAMSPortConverter extends JDialog implements ActionListen gridBag.setConstraints(periodTextField, constraints); boxPanel.add(periodTextField); - listPeriodString = new String[3]; - listPeriodString[0] = "us"; + listPeriodString = new String[4]; + listPeriodString[0] = "s"; listPeriodString[1] = "ms"; - listPeriodString[2] = "s"; + listPeriodString[2] = "\u03BCs"; + listPeriodString[3] = "ns"; periodComboBoxString = new JComboBox<String>(listPeriodString); - if (port.getTime().equals("") || port.getTime().equals("us")) { + if (port.getTime().equals("") || port.getTime().equals("s")) { periodComboBoxString.setSelectedIndex(0); } else if (port.getTime().equals("ms")){ periodComboBoxString.setSelectedIndex(1); - } else { + } else if (port.getTime().equals("\u03BCs")){ periodComboBoxString.setSelectedIndex(2); + } else if (port.getTime().equals("ns")){ + periodComboBoxString.setSelectedIndex(3); } periodComboBoxString.setActionCommand("time"); periodComboBoxString.addActionListener(this); diff --git a/src/main/java/ui/window/JDialogSysCAMSPortTDF.java b/src/main/java/ui/window/JDialogSysCAMSPortTDF.java index 51362637cb1ef689adeaca671573d61e86073382..75702fa326c0b73de7877444b15747fade6bfba4 100644 --- a/src/main/java/ui/window/JDialogSysCAMSPortTDF.java +++ b/src/main/java/ui/window/JDialogSysCAMSPortTDF.java @@ -144,17 +144,20 @@ public class JDialogSysCAMSPortTDF extends JDialog implements ActionListener { gridBag.setConstraints(periodTextField, constraints); boxPanel.add(periodTextField); - listPeriodString = new String[3]; - listPeriodString[0] = "us"; + listPeriodString = new String[4]; + listPeriodString[0] = "s"; listPeriodString[1] = "ms"; - listPeriodString[2] = "s"; + listPeriodString[2] = "\u03BCs"; + listPeriodString[3] = "ns"; periodComboBoxString = new JComboBox<String>(listPeriodString); - if (port.getTime().equals("") || port.getTime().equals("us")) { + if (port.getTime().equals("") || port.getTime().equals("s")) { periodComboBoxString.setSelectedIndex(0); } else if (port.getTime().equals("ms")){ periodComboBoxString.setSelectedIndex(1); - } else if (port.getTime().equals("s")){ + } else if (port.getTime().equals("\u03BCs")){ periodComboBoxString.setSelectedIndex(2); + } else if (port.getTime().equals("ns")){ + periodComboBoxString.setSelectedIndex(3); } periodComboBoxString.setActionCommand("time"); periodComboBoxString.addActionListener(this);