diff --git a/src/main/java/syscamstranslator/SysCAMSTClock.java b/src/main/java/syscamstranslator/SysCAMSTClock.java index ae05d481a75560139f1453cf92089432dfb2a42c..07fd8383c779e366d5969925fc14bf00743ab925 100644 --- a/src/main/java/syscamstranslator/SysCAMSTClock.java +++ b/src/main/java/syscamstranslator/SysCAMSTClock.java @@ -43,35 +43,25 @@ import java.util.LinkedList; import javax.swing.DefaultListModel; /** - * Class SysCAMSTClock - * Parameters of a SystemC-AMS Clock - * Creation: 08/07/2019 - * @version 1.0 08/07/2019 - * @author Daniela Genius + * Class SysCAMSTClock */ public class SysCAMSTClock extends SysCAMSTComponent{ private String name; - private String frequency; + private double frequency; private String unit; - private String dutyCycle; - private String startTime; - private String posFirst; + private double dutyCycle; + private double startTime; + private boolean posFirst; - //private SysCAMSTCluster cluster; - private LinkedList<SysCAMSTPortClock> portClock; - - - public SysCAMSTClock(String _name, String _frequency, String _unit, String _dutyCycle, String _startTime, String _posFirst) { + public SysCAMSTClock(String _name, double _frequency, String _unit, double _dutyCycle, double _startTime, boolean _posFirst) { name = _name; frequency = _frequency; unit = _unit; dutyCycle = _dutyCycle; startTime = _startTime; - posFirst = _posFirst; - //cluster = _cluster; - portClock = new LinkedList<SysCAMSTPortClock>(); + posFirst = _posFirst; } @@ -79,7 +69,7 @@ public class SysCAMSTClock extends SysCAMSTComponent{ return name; } - public String getFrequency() { + public double getFrequency() { return frequency; } @@ -87,16 +77,16 @@ public class SysCAMSTClock extends SysCAMSTComponent{ return unit; } - public String getDutyCycle() { + public double getDutyCycle() { return dutyCycle; } - public String getStartTime() { + public double getStartTime() { return startTime; } - public String getPosFirst() { + public boolean getPosFirst() { return posFirst; } @@ -105,7 +95,7 @@ public class SysCAMSTClock extends SysCAMSTComponent{ name = _name; } - public void setFrequency(String _frequency) { + public void setFrequency(double _frequency) { frequency = _frequency; } @@ -113,27 +103,18 @@ public class SysCAMSTClock extends SysCAMSTComponent{ unit = _unit; } - public void setDutyCycle(String _dutyCycle) { + public void setDutyCycle(double _dutyCycle) { dutyCycle = _dutyCycle; } - public void setStartTime(String _startTime) { + public void setStartTime(double _startTime) { startTime = _startTime; } - public void setPosFirst(String _posFirst) { + public void setPosFirst(boolean _posFirst) { posFirst = _posFirst; } - - public LinkedList<SysCAMSTPortClock> getPortClock(){ - return portClock; - } - - public void addPortClock(SysCAMSTPortClock cl){ - portClock.add(cl); - } - - + } diff --git a/src/main/java/syscamstranslator/SysCAMSTPortClock.java b/src/main/java/syscamstranslator/SysCAMSTPortClock.java deleted file mode 100644 index c36f23183be1f4e5291fd0f774ba6795296aa1b3..0000000000000000000000000000000000000000 --- a/src/main/java/syscamstranslator/SysCAMSTPortClock.java +++ /dev/null @@ -1,171 +0,0 @@ -/* 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 syscamstranslator; - -import elntranslator.*; - -/** - * Class SysCAMSTPortClock - * Parameters of a SystemC-AMS port Clock - * Creation: 07/05/2018 - * @version 1.0 07/05/2018 - * @author Irina Kit Yan LEE -*/ - -public class SysCAMSTPortClock extends SysCAMSTComponent { - - private String name; -// private int period; -// private String time; -// private int rate; -// private int delay; - private int origin; - private String ClockType; - private boolean sensitive; - private String sensitiveMethod; - - private SysCAMSTBlockClock blockClock; - private SysCAMSTBlockGPIO2VCI blockGPIO2VCI; - private ELNTCluster cluster; - private ELNTModule module; - - public SysCAMSTPortClock(String _name, int _origin, String _ClockType, boolean _sensitive, String _sensitiveMethod, SysCAMSTBlockClock _blockClock) { - name = _name; -// period = _period; -// time = _time; -// rate = _rate; -// delay = _delay; - origin = _origin; - ClockType = _ClockType; - sensitive = _sensitive; - sensitiveMethod = _sensitiveMethod; - blockClock = _blockClock; - } - - public SysCAMSTPortClock(String _name, int _origin, String _ClockType, boolean _sensitive, String _sensitiveMethod, SysCAMSTBlockGPIO2VCI _blockGPIO2VCI) { - name = _name; -// period = _period; -// time = _time; -// rate = _rate; -// delay = _delay; - origin = _origin; - ClockType = _ClockType; - sensitive = _sensitive; - sensitiveMethod = _sensitiveMethod; - blockGPIO2VCI = _blockGPIO2VCI; - } - - public SysCAMSTPortClock(String _name, int _origin, String _ClockType, boolean _sensitive, String _sensitiveMethod, ELNTCluster _cluster) { - name = _name; -// period = _period; -// time = _time; -// rate = _rate; -// delay = _delay;ELNTCluster - origin = _origin; - ClockType = _ClockType; - sensitive = _sensitive; - sensitiveMethod = _sensitiveMethod; - cluster = _cluster; - } - - public SysCAMSTPortClock(String _name, int _origin, String _ClockType, boolean _sensitive, String _sensitiveMethod, ELNTModule _module) { - name = _name; -// period = _period; -// time = _time; -// rate = _rate; -// delay = _delay;ELNTCluster - origin = _origin; - ClockType = _ClockType; - sensitive = _sensitive; - sensitiveMethod = _sensitiveMethod; - module = _module; - } - - public String getName() { - return name; - } - -// public int getPeriod() { -// return period; -// } -// -// public String getTime() { -// return time; -// } -// -// public int getRate() { -// return rate; -// } -// -// public int getDelay() { -// return delay; -// } - - public int getOrigin() { - return origin; - } - - public String getClockType() { - return ClockType; - } - - public boolean getSensitive() { - return sensitive; - } - - public String getSensitiveMethod() { - return sensitiveMethod; - } - - public SysCAMSTBlockClock getBlockClock() { - return blockClock; - } - - public SysCAMSTBlockGPIO2VCI getBlockGPIO2VCI() { - return blockGPIO2VCI; - } - - public ELNTCluster getCluster() { - return cluster; - } - - public ELNTModule getModule() { - return module; - } -} diff --git a/src/main/java/syscamstranslator/toSysCAMS/ClusterCode.java b/src/main/java/syscamstranslator/toSysCAMS/ClusterCode.java index c3b7513f1fb5f64798dbe539a1d3f3a73c9134b7..d6bc3f5da8ced7acf574948b7a5e74f88db87412 100644 --- a/src/main/java/syscamstranslator/toSysCAMS/ClusterCode.java +++ b/src/main/java/syscamstranslator/toSysCAMS/ClusterCode.java @@ -73,7 +73,8 @@ public class ClusterCode { if (cluster != null) { LinkedList<SysCAMSTBlockTDF> tdf = cluster.getBlockTDF(); LinkedList<SysCAMSTBlockDE> de = cluster.getBlockDE(); - LinkedList<SysCAMSTClock> clock = cluster.getClock(); + LinkedList<SysCAMSTClock> clock = cluster.getClock(); + corpsCluster = "// Simulation entry point." + CR + "int sc_main(int argc, char *argv[]) {" + CR2 + "\tusing namespace sc_core;" + CR + "\tusing namespace sca_util;" + CR2; @@ -132,6 +133,17 @@ public class ClusterCode { corpsCluster = corpsCluster + CR + "\t// Instantiate headers files as well as bind their ports to the signal." + CR; + + + + for (SysCAMSTClock t : clock) { + corpsCluster = corpsCluster + "\t sc_clock " + t.getName() + " (\"" + t.getName() + "\"," + t.getFrequency()+","+ t.getUnit()+","+ t.getDutyCycle()+","+ t.getStartTime()+","+ t.getUnit()+","+ t.getPosFirst()+");" + CR; + } + //ToDo 9.7.2019: add lines for reading (several) clock ports and sensitivity lists + + + + for (SysCAMSTBlockTDF t : tdf) { corpsCluster = corpsCluster + "\t" + t.getName() + " " + t.getName() + "_" + nb_block + "(\"" + t.getName() + "_" + nb_block + "\");" + CR; @@ -204,51 +216,8 @@ public class ClusterCode { } - - - //ajoute DG - - - - for (SysCAMSTClock t : clock) { - corpsCluster = corpsCluster + "\t sc_clock " + t.getName() + " (\"" + t.getName() + "\"," + t.getFrequency()+","+ t.getUnit()+","+ t.getDutyCycle()+","+ t.getStartTime()+","+ t.getUnit()+","+ t.getPosFirst()+");" + CR; - - LinkedList<SysCAMSTPortClock> portClock = t.getPortClock(); - - for (SysCAMSTPortClock p : portClock) { - for (int i = 0; i < connectors.size(); i++) { - if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortClock && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortClock) { - if (((SysCAMSTPortClock) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortClock) connectors.get(i).get_p1().getComponent()).getClock().getName().equals(t.getName())) { - corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; - } else if (((SysCAMSTPortClock) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortClock) connectors.get(i).get_p2().getComponent()).getClock().getName().equals(t.getName())) { - corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; - } - } else if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortConverter && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortClock) { - if (((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getBlockTDF().getName().equals(t.getName())) { - corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; - } else if (((SysCAMSTPortClock) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortClock) connectors.get(i).get_p2().getComponent()).getClock().getName().equals(t.getName())) { - corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; - } - } else if (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortConverter && connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortClock) { - if (((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getBlockTDF().getName().equals(t.getName())) { - corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; - } else if (((SysCAMSTPortClock) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortClock) connectors.get(i).get_p1().getComponent()).getClock().getName().equals(t.getName())) { - corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; - } - } - } - } - corpsCluster = corpsCluster + CR; - nb_block++; - } - - //fin ajoute DG - - - - corpsCluster = corpsCluster + "\t// Configure signal tracing." + CR + "\tsca_trace_file* tfp = sca_create_tabular_trace_file(\"" + cluster.getClusterName() + "_tb\");" + CR; diff --git a/src/main/java/syscamstranslator/toSysCAMS/ClusterCode.java-orig b/src/main/java/syscamstranslator/toSysCAMS/ClusterCode.java-orig new file mode 100644 index 0000000000000000000000000000000000000000..9eee38a252b01ca8c7f48d9e8666377fe80c5677 --- /dev/null +++ b/src/main/java/syscamstranslator/toSysCAMS/ClusterCode.java-orig @@ -0,0 +1,221 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * Daniela Genius, Lip6, UMR 7606 + * + * ludovic.apvrille AT enst.fr + * daniela.genius@lip6.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. + */ + +/* this class produces the lines containing essentially the initial #includes; we include all potential components event if they are not used in the deployment diagram*/ + +/* authors: v1.0 Raja GATGOUT 2014 + v2.0 Daniela GENIUS, Julien HENON 2015 */ + +package syscamstranslator.toSysCAMS; + +import java.util.LinkedList; + +import syscamstranslator.*; + +/** + * Class ClusterCode + * Principal code of a cluster component + * Creation: 14/05/2018 + * @version 1.0 14/05/2018 + * @author Irina Kit Yan LEE + */ + +public class ClusterCode { + static private String corpsCluster; + private final static String CR = "\n"; + private final static String CR2 = "\n\n"; + + ClusterCode() {} + + public static String getClusterCode(SysCAMSTCluster cluster, LinkedList<SysCAMSTConnector> connectors) { + int nb_con = 1; + int nb_block = 1; + + LinkedList<String> names = new LinkedList<String>(); + + if (cluster != null) { + LinkedList<SysCAMSTBlockTDF> tdf = cluster.getBlockTDF(); + LinkedList<SysCAMSTBlockDE> de = cluster.getBlockDE(); + + corpsCluster = "// Simulation entry point." + CR + "int sc_main(int argc, char *argv[]) {" + CR2 + + "\tusing namespace sc_core;" + CR + "\tusing namespace sca_util;" + CR2; + + corpsCluster = corpsCluster + "\t// Declare signal to interconnect." + CR; + + for (SysCAMSTConnector c : connectors) { + if ((c.get_p1().getComponent() instanceof SysCAMSTPortTDF && c.get_p2().getComponent() instanceof SysCAMSTPortTDF) + || (c.get_p1().getComponent() instanceof SysCAMSTPortTDF && c.get_p2().getComponent() instanceof SysCAMSTPortTDF)) { + if (c.getName().equals("")) { + corpsCluster = corpsCluster + "\tsca_tdf::sca_signal<" + ((SysCAMSTPortTDF) c.get_p1().getComponent()).getTDFType() + "> " + + "sig_" + nb_con + ";" + CR; + names.add("sig_" + nb_con); + nb_con++; + } else { + corpsCluster = corpsCluster + "\tsca_tdf::sca_signal<" + ((SysCAMSTPortTDF) c.get_p1().getComponent()).getTDFType() + "> " + + c.getName() + ";" + CR; + names.add(c.getName()); + } + } else if ((c.get_p1().getComponent() instanceof SysCAMSTPortConverter && c.get_p2().getComponent() instanceof SysCAMSTPortDE)) { + if (c.getName().equals("")) { + corpsCluster = corpsCluster + "\tsca_tdf::sca_signal<" + ((SysCAMSTPortConverter) c.get_p1().getComponent()).getConvType() + "> " + + "sig_" + nb_con + ";" + CR; + names.add("sig_" + nb_con); + nb_con++; + } else { + corpsCluster = corpsCluster + "\tsca_tdf::sca_signal<" + ((SysCAMSTPortConverter) c.get_p1().getComponent()).getConvType() + "> " + + c.getName() + ";" + CR; + names.add(c.getName()); + } + } else if ((c.get_p2().getComponent() instanceof SysCAMSTPortConverter && c.get_p1().getComponent() instanceof SysCAMSTPortDE)) { + if (c.getName().equals("")) { + corpsCluster = corpsCluster + "\tsca_tdf::sca_signal<" + ((SysCAMSTPortConverter) c.get_p2().getComponent()).getConvType() + "> " + + "sig_" + nb_con + ";" + CR; + names.add("sig_" + nb_con); + nb_con++; + } else { + corpsCluster = corpsCluster + "\tsca_tdf::sca_signal<" + ((SysCAMSTPortConverter) c.get_p2().getComponent()).getConvType() + "> " + + c.getName() + ";" + CR; + names.add(c.getName()); + } + } else if ((c.get_p1().getComponent() instanceof SysCAMSTPortDE && c.get_p2().getComponent() instanceof SysCAMSTPortDE) + || (c.get_p2().getComponent() instanceof SysCAMSTPortDE && c.get_p1 ().getComponent() instanceof SysCAMSTPortDE)) { + if (c.getName().equals("")) { + corpsCluster = corpsCluster + "\tsc_core::sc_signal<" + ((SysCAMSTPortDE) c.get_p1().getComponent()).getDEType() + "> " + + "sig_" + nb_con + ";" + CR; + names.add("sig_" + nb_con); + nb_con++; + } else { + corpsCluster = corpsCluster + "\tsc_core::sc_signal<" + ((SysCAMSTPortDE) c.get_p1().getComponent()).getDEType() + "> " + + c.getName() + ";" + CR; + names.add(c.getName()); + } + } + } + + corpsCluster = corpsCluster + CR + "\t// Instantiate headers files as well as bind their ports to the signal." + CR; + + for (SysCAMSTBlockTDF t : tdf) { + corpsCluster = corpsCluster + "\t" + t.getName() + " " + t.getName() + "_" + nb_block + "(\"" + t.getName() + "_" + nb_block + "\");" + CR; + + LinkedList<SysCAMSTPortTDF> portTDF = t.getPortTDF(); + LinkedList<SysCAMSTPortConverter> portConv = t.getPortConverter(); + + for (SysCAMSTPortTDF p : portTDF) { + for (int i = 0; i < connectors.size(); i++) { + if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortTDF && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortTDF) { + if (((SysCAMSTPortTDF) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortTDF) connectors.get(i).get_p1().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } else if (((SysCAMSTPortTDF) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortTDF) connectors.get(i).get_p2().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } + } + } + } + + for (SysCAMSTPortConverter p : portConv) { + for (int i = 0; i < connectors.size(); i++) { + if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortConverter && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } else if (((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } + } else if (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortConverter && connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } else if (((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } + } + } + } + corpsCluster = corpsCluster + CR; + nb_block++; + } + + for (SysCAMSTBlockDE t : de) { + corpsCluster = corpsCluster + "\t" + t.getName() + " " + t.getName() + "_" + nb_block + "(\"" + t.getName() + "_" + nb_block + "\");" + CR; + + LinkedList<SysCAMSTPortDE> portDE = t.getPortDE(); + + for (SysCAMSTPortDE p : portDE) { + for (int i = 0; i < connectors.size(); i++) { + if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } else if (((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } + } else if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortConverter && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } else if (((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } + } else if (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortConverter && connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } else if (((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } + } + } + } + corpsCluster = corpsCluster + CR; + nb_block++; + } + + corpsCluster = corpsCluster + "\t// Configure signal tracing." + CR + + "\tsca_trace_file* tfp = sca_create_tabular_trace_file(\"" + cluster.getClusterName() + "_tb\");" + CR; + + for (int i = 0; i < connectors.size(); i++) { + corpsCluster = corpsCluster + "\tsca_trace(tfp, "+ names.get(i) + ", \"" + names.get(i) + "\");" + CR; + } + corpsCluster = corpsCluster + CR + "\t// Start simulation." + CR + "\tsc_start(100.0, SC_MS);" + CR2 + + "\t// Close trace file and stop simulation to enable clean-up by" + CR + + "\t// asking SystemC to execute all end_of_simulation() callbacks." + CR + + "\tsca_close_tabular_trace_file(tfp);" + CR + + "\tsc_stop();" + CR + "\treturn 0;" + CR + "}" + CR2; + } else { + corpsCluster = ""; + } + return corpsCluster; + } +} diff --git a/src/main/java/syscamstranslator/toSysCAMS/PrimitiveCode.java b/src/main/java/syscamstranslator/toSysCAMS/PrimitiveCode.java index 289030f2159e6ae5b42a08ed599f8d9ff7a6d702..03552b4092f251ceeabe8f429f9be362d2a813ee 100644 --- a/src/main/java/syscamstranslator/toSysCAMS/PrimitiveCode.java +++ b/src/main/java/syscamstranslator/toSysCAMS/PrimitiveCode.java @@ -602,232 +602,4 @@ public class PrimitiveCode { } return corpsPrimitiveDE; } - - public static String getPrimitiveCodeClock(SysCAMSTBlockClock de) { - corpsPrimitiveClock = ""; - - if (de != null) { - LinkedList<SysCAMSTPortClock> deports = de.getPortClock(); - int cpt = 0; - int cpt2 = 0; - - if ((!de.getTypeTemplate().equals("")) && (!de.getNameTemplate().equals(""))) { - corpsPrimitiveClock = corpsPrimitiveClock + "template<" + de.getTypeTemplate() + " " + de.getNameTemplate() + ">" + CR; - } - //corpsPrimitive = "SCA_TDF_MODULE(" + de.getName() + ") {" + CR2; - corpsPrimitiveClock = corpsPrimitiveClock + "class " + de.getName() + " : public sca_core::sca_module {" + CR2 + "public:" + CR; - - if (!de.getListTypedef().isEmpty()) { - for (int i = 0; i < de.getListTypedef().getSize(); i++) { - String select = de.getListTypedef().get(i); - String[] split = select.split(" : "); - corpsPrimitiveClock = corpsPrimitiveClock + "\ttypedef " + split[1] + "<" + de.getNameTemplate() + "> " + split[0] + ";" + CR; - if (i == de.getListTypedef().getSize()-1) { - corpsPrimitiveClock = corpsPrimitiveClock + CR; - } - } - } - - if (de.getListStruct().getSize() != 0) { - corpsPrimitiveClock = corpsPrimitiveClock + "\tstruct parameters {" + CR; - - String identifier, value, type; - for (int i = 0; i < de.getListStruct().size(); i++) { - String select = de.getListStruct().get(i); - String[] splita = select.split(" = "); - identifier = splita[0]; - String[] splitb = splita[1].split(" : "); - value = splitb[0]; - String[] splitc = splitb[1].split(" "); - if (splitc[0].equals("const")) { - type = splitc[1]; - } else { - type = splitc[0]; - } - corpsPrimitiveClock = corpsPrimitiveClock + "\t\t" + type + " " + identifier + ";" + CR; - } - - corpsPrimitiveClock = corpsPrimitiveClock + "\t\tparameters()" + CR; - - for (int i = 0; i < de.getListStruct().size(); i++) { - String select = de.getListStruct().get(i); - String[] splita = select.split(" = "); - identifier = splita[0]; - String[] splitb = splita[1].split(" : "); - value = splitb[0]; - String[] splitc = splitb[1].split(" "); - if (splitc[0].equals("const")) { - type = splitc[1]; - } else { - type = splitc[0]; - } - if (i == 0) { - corpsPrimitiveClock = corpsPrimitiveClock + "\t\t: " + identifier + "(" + value + ")" + CR; - } - if ((i > 0) && (i < de.getListStruct().getSize()-1)) { - corpsPrimitiveClock = corpsPrimitiveClock + "\t\t, " + identifier + "(" + value + ")" + CR; - } - if (i == de.getListStruct().getSize()-1 && i != 0) { - corpsPrimitiveClock = corpsPrimitiveClock + "\t\t, " + identifier + "(" + value + ")" + CR + "\t\t{}" + CR; - } else { - corpsPrimitiveClock = corpsPrimitiveClock + "\t\t{}" + CR; - } - } - corpsPrimitiveClock = corpsPrimitiveClock + "\t};" + CR2; - } - - if (!deports.isEmpty()) { - for (SysCAMSTPortClock t : deports) { - if (t.getOrigin() == 0) { - corpsPrimitiveClock = corpsPrimitiveClock + "\tsca_core::sca_in<" + t.getClockType() + "> " + t.getName() + ";" + CR; - } else if (t.getOrigin() == 1) { - corpsPrimitiveClock = corpsPrimitiveClock + "\tsca_core::sca_out<" + t.getClockType() + "> " + t.getName() + ";" + CR; - } - } - } - - corpsPrimitiveClock = corpsPrimitiveClock + CR + "\tSC_HAS_PROCESS(" + de.getName() + ");" + CR + - "\texplicit " + de.getName() + "(sc_core::sc_module_name nm"; - - if (de.getListStruct().getSize() != 0) { - corpsPrimitiveClock = corpsPrimitiveClock + ", const parameters& p = parameters())" + CR; - } else { - corpsPrimitiveClock = corpsPrimitiveClock + ")" + CR; - } - - if (!deports.isEmpty() || !de.getListStruct().isEmpty()) { - corpsPrimitiveClock = corpsPrimitiveClock + "\t: "; - if (!deports.isEmpty()) { - for (int i = 0; i < deports.size(); i++) { - if (deports.size() >= 1) { - if (cpt == 0) { - corpsPrimitiveClock = corpsPrimitiveClock + deports.get(i).getName() + "(\"" + deports.get(i).getName() + "\")" + CR; - cpt++; - } else { - corpsPrimitiveClock = corpsPrimitiveClock + "\t, " + deports.get(i).getName() + "(\"" + deports.get(i).getName() + "\")" + CR; - } - } else { - corpsPrimitiveClock = corpsPrimitiveClock + deports.get(i).getName() + "(\"" + deports.get(i).getName() + "\")" + CR; - cpt++; - } - } - } - String identifier; - if (!de.getListStruct().isEmpty()) { - for (int i = 0; i < de.getListStruct().size(); i++) { - String select = de.getListStruct().get(i); - String[] splita = select.split(" = "); - identifier = splita[0]; - if (de.getListStruct().getSize() >= 1) { - if (cpt == 0) { - corpsPrimitiveClock = corpsPrimitiveClock + identifier + "(p." + identifier + ")" + CR; - cpt++; - } else { - corpsPrimitiveClock = corpsPrimitiveClock + "\t, " + identifier + "(p." + identifier + ")" + CR; - } - } else { - corpsPrimitiveClock = corpsPrimitiveClock + identifier + "(p." + identifier + ")" + CR; - cpt++; - } - } - } - } - - boolean sensitive = false, method = false; - if (!de.getCode().equals("")) { - corpsPrimitiveClock = corpsPrimitiveClock + "\t{" + CR + "\t\tSC_METHOD(" + de.getNameFn() + ");" + CR; - method = true; - } - - for (SysCAMSTPortClock t : deports) { - if (t.getSensitive() == true) { - if (method == false) { - corpsPrimitiveClock = corpsPrimitiveClock + "\t{" + CR; - } - corpsPrimitiveClock = corpsPrimitiveClock + "\t\tsensitive << " + t.getName() + "."; - if (t.getSensitiveMethod().equals("positive")) { - corpsPrimitiveClock = corpsPrimitiveClock + "pos();" + CR; - } else if (t.getSensitiveMethod().equals("negative")) { - corpsPrimitiveClock = corpsPrimitiveClock + "neg();" + CR; - } - sensitive = true; - } - } - if (sensitive == true || method == true) { - corpsPrimitiveClock = corpsPrimitiveClock + "\t}" + CR2; - } else { - corpsPrimitiveClock = corpsPrimitiveClock + "\t{}" + CR2; - } - - corpsPrimitiveClock = corpsPrimitiveClock + "private:" + CR; - - if (de.getListStruct().getSize() != 0) { - String identifier, type, constant; - for (int i = 0; i < de.getListStruct().size(); i++) { - String select = de.getListStruct().get(i); - String[] splita = select.split(" = "); - identifier = splita[0]; - String[] splitb = splita[1].split(" : "); - String[] splitc = splitb[1].split(" "); - if (splitc[0].equals("const")) { - constant = splitc[0]; - type = splitc[1]; - } else { - constant = ""; - type = splitc[0]; - } - if (constant.equals("")) { - corpsPrimitiveClock = corpsPrimitiveClock + "\t" + type + " " + identifier + ";" + CR; - } else { - corpsPrimitiveClock = corpsPrimitiveClock + "\t" + constant + " " + type + " " + identifier + ";" + CR; - } - if (i == de.getListStruct().size()-1) { - corpsPrimitiveClock = corpsPrimitiveClock + CR; - } - } - } - - StringBuffer pcbuf = new StringBuffer(de.getCode()); - StringBuffer buffer = new StringBuffer(""); - int tab = 0; - int begin = 0; - - for(int pos = 0; pos != de.getCode().length(); pos++) { - char c = pcbuf.charAt(pos); - switch(c) { - case '\t': - begin = 1; - tab++; - break; - default: - if (begin == 1) { - int i = tab; - while (i >= 0) { - buffer.append("\t"); - i--; - } - buffer.append(pcbuf.charAt(pos)); - begin = 0; - tab = 0; - } else { - if (c == '}') { - buffer.append("\t"); - } - buffer.append(pcbuf.charAt(pos)); - } - break; - } - } - - String pc = buffer.toString(); - corpsPrimitiveClock = corpsPrimitiveClock + "\t" + pc; - - corpsPrimitiveClock = corpsPrimitiveClock + CR + "};" + CR2 + "#endif" + " // " + de.getName().toUpperCase() + "_H"; - } else { - corpsPrimitiveClock = ""; - } - return corpsPrimitiveClock; - } - - } diff --git a/src/main/java/syscamstranslator/toSysCAMSCluster/ClusterCode.java b/src/main/java/syscamstranslator/toSysCAMSCluster/ClusterCode.java index d45c3e4a1731850f1b5c122c847975a60f7af262..b9411223f4dc42f6864f1e925663cdf8c214e41a 100644 --- a/src/main/java/syscamstranslator/toSysCAMSCluster/ClusterCode.java +++ b/src/main/java/syscamstranslator/toSysCAMSCluster/ClusterCode.java @@ -74,7 +74,17 @@ public class ClusterCode { corpsCluster = "template <typename vci_param>" + CR + "class " +cluster.getClusterName()+ " : public sc_core::sc_module { "+ CR; - + + + + + for (SysCAMSTClock t : clock) { + corpsCluster = corpsCluster + "\t sc_clock " + t.getName() + " (\"" + t.getName() + "\"," + t.getFrequency()+","+ t.getUnit()+","+ t.getDutyCycle()+","+ t.getStartTime()+","+ t.getUnit()+","+ t.getPosFirst()+");" + CR; + } + //ToDo 9.7.2019: add lines for reading (several) clock ports and sensitivity lists + + + for (SysCAMSTBlockTDF t : tdf) { if (!t.getListTypedef().isEmpty()) { for (int i = 0; i < t.getListTypedef().getSize(); i++) { @@ -301,7 +311,7 @@ public class ClusterCode { corpsCluster = corpsCluster + CR; nb_block++; } - + corpsCluster = corpsCluster + "\t}" + CR2; corpsCluster = corpsCluster + "\t// Configure signal tracing." + CR; diff --git a/src/main/java/syscamstranslator/toSysCAMSCluster/ClusterCode.java-orig b/src/main/java/syscamstranslator/toSysCAMSCluster/ClusterCode.java-orig new file mode 100644 index 0000000000000000000000000000000000000000..d45c3e4a1731850f1b5c122c847975a60f7af262 --- /dev/null +++ b/src/main/java/syscamstranslator/toSysCAMSCluster/ClusterCode.java-orig @@ -0,0 +1,325 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * Daniela Genius, Lip6, UMR 7606 + * + * ludovic.apvrille AT enst.fr + * daniela.genius@lip6.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 syscamstranslator.toSysCAMSCluster; + +import java.util.LinkedList; + +import syscamstranslator.*; + +/** + * Class ClusterCode + * Principal code of a cluster component that wraps all AMS components. + * Creation: 30/07/2018 + * @version 1.0 30/07/2018 + * @author Rodrigo CORTES PORTO +*/ + +public class ClusterCode { + static private String corpsCluster; + private final static String CR = "\n"; + private final static String CR2 = "\n\n"; + + ClusterCode() {} + + public static String getClusterCode(SysCAMSTCluster cluster, LinkedList<SysCAMSTConnector> connectors) { + int nb_con = 0; + int nb_block = 0; + + LinkedList<String> names = new LinkedList<String>(); + + if (cluster != null) { + LinkedList<SysCAMSTBlockTDF> tdf = cluster.getBlockTDF(); + LinkedList<SysCAMSTBlockDE> de = cluster.getBlockDE(); + + LinkedList<SysCAMSTClock> clock = cluster.getClock(); + + + corpsCluster = "template <typename vci_param>" + CR + + "class " +cluster.getClusterName()+ " : public sc_core::sc_module { "+ CR; + + for (SysCAMSTBlockTDF t : tdf) { + if (!t.getListTypedef().isEmpty()) { + for (int i = 0; i < t.getListTypedef().getSize(); i++) { + String select = t.getListTypedef().get(i); + String[] split = select.split(" : "); + corpsCluster = corpsCluster + "\ttypedef " + split[1] + "<"+ t.getValueTemplate() +"> " + split[0] + ";" + CR; + } + } + } + + for (SysCAMSTBlockDE t : de) { + if (!t.getListTypedef().isEmpty()) { + for (int i = 0; i < t.getListTypedef().getSize(); i++) { + String select = t.getListTypedef().get(i); + String[] split = select.split(" : "); + corpsCluster = corpsCluster + "\ttypedef " + split[1] + "<"+ t.getValueTemplate() +"> " + split[0] + ";" + CR; + } + } + } + + corpsCluster = corpsCluster + CR + "\t// Declare signals to interconnect." + CR; + + for (int i = 0; i < connectors.size(); i++) { + nb_con = i; + if ( !((connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE && ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getBlockGPIO2VCI() != null) + || (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE && ((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getBlockGPIO2VCI() != null)) ) { + if ((connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortTDF && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortTDF) + || (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortTDF && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortTDF)) { + if (connectors.get(i).getName().equals("")) { + corpsCluster = corpsCluster + "\tsca_tdf::sca_signal<" + ((SysCAMSTPortTDF) connectors.get(i).get_p1().getComponent()).getTDFType() + "> " + + "sig_" + nb_con + ";" + CR; + names.add("sig_" + nb_con); + } else { + corpsCluster = corpsCluster + "\tsca_tdf::sca_signal<" + ((SysCAMSTPortTDF) connectors.get(i).get_p1().getComponent()).getTDFType() + "> " + + connectors.get(i).getName() + ";" + CR; + names.add(connectors.get(i).getName()); + } + } else if ((connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortConverter && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE)) { + if (connectors.get(i).getName().equals("")) { + corpsCluster = corpsCluster + "\tsc_core::sc_signal<" + ((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getConvType() + "> " + + "sig_" + nb_con + ";" + CR; + names.add("sig_" + nb_con); + } else { + corpsCluster = corpsCluster + "\tsc_core::sc_signal<" + ((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getConvType() + "> " + + connectors.get(i).getName() + ";" + CR; + names.add(connectors.get(i).getName()); + } + } else if ((connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortConverter && connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE)) { + if (connectors.get(i).getName().equals("")) { + corpsCluster = corpsCluster + "\tsc_core::sc_signal<" + ((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getConvType() + "> " + + "sig_" + nb_con + ";" + CR; + names.add("sig_" + nb_con); + } else { + corpsCluster = corpsCluster + "\tsc_core::sc_signal<" + ((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getConvType() + "> " + + connectors.get(i).getName() + ";" + CR; + names.add(connectors.get(i).getName()); + } + } else if ((connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE) + || (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE && connectors.get(i).get_p1 ().getComponent() instanceof SysCAMSTPortDE)) { + if (connectors.get(i).getName().equals("")) { + corpsCluster = corpsCluster + "\tsc_core::sc_signal<" + ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getDEType() + "> " + + "sig_" + nb_con + ";" + CR; + names.add("sig_" + nb_con); + } else { + corpsCluster = corpsCluster + "\tsc_core::sc_signal<" + ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getDEType() + "> " + + connectors.get(i).getName() + ";" + CR; + names.add(connectors.get(i).getName()); + } + } + + } else { + names.add("gpio_sig" + nb_con); + } + } + + //DG + for (SysCAMSTClock clk : clock) { + corpsCluster = corpsCluster + "sc_clock"+ clk.getName()+ "("+clk.getName()+", "+clk.getFrequency()+", "+clk.getUnit()+", "+clk.getDutyCycle()+", "+clk.getStartTime()+", "+clk.getUnit()+", "+clk.getPosFirst()+");" + CR; + } + //fin ajoute DG + + + + corpsCluster = corpsCluster + CR + "\t// Instantiate cluster's modules." + CR; + for (SysCAMSTBlockTDF t : tdf) { + corpsCluster = corpsCluster + "\t" + t.getName(); + if (!t.getListTypedef().isEmpty()) { + corpsCluster += "<"+t.getValueTemplate()+">"; + } + corpsCluster += " " + t.getName() + "_" + nb_block + ";" + CR; + nb_block++; + } + + for (SysCAMSTBlockDE t : de) { + corpsCluster = corpsCluster + "\t" + t.getName(); + if (!t.getListTypedef().isEmpty()) { + corpsCluster += "<"+t.getValueTemplate()+">"; + } + corpsCluster += " " + t.getName() + "_" + nb_block + ";" + CR; + nb_block++; + } + + corpsCluster = corpsCluster + "public:" + CR; + corpsCluster = corpsCluster + "\tsc_in< typename vci_param::data_t > in_ams;" + CR; + corpsCluster = corpsCluster + "\tsc_out< typename vci_param::data_t > out_ams;" + CR2; + + nb_block = 0; + corpsCluster = corpsCluster + "\tSC_CTOR(" +cluster.getClusterName()+ ") :" + CR; + for (SysCAMSTBlockTDF t : tdf) { + corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "(\"" + t.getName() + "_" + nb_block + "\")," + CR; + nb_block++; + } + for (SysCAMSTBlockDE t : de) { + corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "(\"" + t.getName() + "_" + nb_block + "\")," + CR; + nb_block++; + } + corpsCluster = corpsCluster + "\tin_ams(\"in_ams\")," + CR; + corpsCluster = corpsCluster + "\tout_ams(\"out_ams\") {" + CR; + + nb_block = 0; + for (SysCAMSTBlockTDF t : tdf) { + //corpsCluster = corpsCluster + "\t" + t.getName() + " " + t.getName() + "_" + nb_block + "(\"" + t.getName() + "_" + nb_block + "\");" + CR; + + LinkedList<SysCAMSTPortTDF> portTDF = t.getPortTDF(); + LinkedList<SysCAMSTPortConverter> portConv = t.getPortConverter(); + + for (SysCAMSTPortTDF p : portTDF) { + for (int i = 0; i < connectors.size(); i++) { + if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortTDF && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortTDF) { + if (((SysCAMSTPortTDF) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortTDF) connectors.get(i).get_p1().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } else if (((SysCAMSTPortTDF) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortTDF) connectors.get(i).get_p2().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } + } + } + } + + for (SysCAMSTPortConverter p : portConv) { + for (int i = 0; i < connectors.size(); i++) { + nb_con = i; + + if ( !((connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE && ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getBlockGPIO2VCI() != null) + || (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE && ((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getBlockGPIO2VCI() != null)) ) { + if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortConverter && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } else if (((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } + } else if (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortConverter && connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } else if (((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } + } + } else { + if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE && ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getBlockGPIO2VCI() != null) { + if (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortConverter) { + if (((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(in_ams);" + CR; + } + } + } else if (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE && ((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getBlockGPIO2VCI() != null) { + if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortConverter) { + if (((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(out_ams);" + CR; + } + } + } + } + } + } + corpsCluster = corpsCluster + CR; + nb_block++; + } + + for (SysCAMSTBlockDE t : de) { + //corpsCluster = corpsCluster + "\t" + t.getName() + " " + t.getName() + "_" + nb_block + "(\"" + t.getName() + "_" + nb_block + "\");" + CR; + + LinkedList<SysCAMSTPortDE> portDE = t.getPortDE(); + + for (SysCAMSTPortDE p : portDE) { + for (int i = 0; i < connectors.size(); i++) { + if ( !((connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE && ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getBlockGPIO2VCI() != null) + || (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE && ((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getBlockGPIO2VCI() != null)) ) { + if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } else if (((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } + } else if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortConverter && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } else if (((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } + } else if (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortConverter && connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } else if (((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } + } + } else { + if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE && ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getBlockGPIO2VCI() != null) { + if (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(in_ams);" + CR; + } + } + } else if (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE && ((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getBlockGPIO2VCI() != null) { + if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(out_ams);" + CR; + } + } + } + } + } + } + corpsCluster = corpsCluster + CR; + nb_block++; + } + + corpsCluster = corpsCluster + "\t}" + CR2; + + corpsCluster = corpsCluster + "\t// Configure signal tracing." + CR; + corpsCluster += "\tvoid trace_" + cluster.getClusterName() +"(sca_util::sca_trace_file* tf) {" + CR; + for (int i = 0; i < connectors.size(); i++) { + if ( !((connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE && ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getBlockGPIO2VCI() != null) + || (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE && ((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getBlockGPIO2VCI() != null)) ) { + corpsCluster += "\t\tsca_trace(tf, "+ names.get(i) + ", \"" + names.get(i) + "\");" + CR; + } + } + corpsCluster += "\t}" +CR; + + corpsCluster = corpsCluster + "};" + CR2; + corpsCluster = corpsCluster + "#endif " + CR;//DG + // corpsCluster = corpsCluster + "#endif // " + cluster.getClusterName().toUpperCase() + "_TDF_H"+ CR;//DG + } else { + corpsCluster = ""; + } + return corpsCluster; + } +} diff --git a/src/main/java/syscamstranslator/toSysCAMSSoclib/ClusterCodeSoclib.java b/src/main/java/syscamstranslator/toSysCAMSSoclib/ClusterCodeSoclib.java index e692394bbba6d84d5209e53b94523bc092390859..3e0c261ce731ab18d3cfc5314818ee74ab390cca 100644 --- a/src/main/java/syscamstranslator/toSysCAMSSoclib/ClusterCodeSoclib.java +++ b/src/main/java/syscamstranslator/toSysCAMSSoclib/ClusterCodeSoclib.java @@ -71,6 +71,8 @@ public class ClusterCodeSoclib { if (cluster != null) { LinkedList<SysCAMSTBlockTDF> tdf = cluster.getBlockTDF(); LinkedList<SysCAMSTBlockDE> de = cluster.getBlockDE(); + + LinkedList<SysCAMSTClock> clock = cluster.getClock(); System.out.println("Number of AMS connectors: " + connectors.size()); @@ -101,6 +103,16 @@ public class ClusterCodeSoclib { } corpsCluster = corpsCluster + CR + "\t// Instantiate cluster's modules." + CR; + + + + for (SysCAMSTClock t : clock) { + corpsCluster = corpsCluster + "\t sc_clock " + t.getName() + " (\"" + t.getName() + "\"," + t.getFrequency()+","+ t.getUnit()+","+ t.getDutyCycle()+","+ t.getStartTime()+","+ t.getUnit()+","+ t.getPosFirst()+");" + CR; + } + //ToDo 9.7.2019: add lines for reading (several) clock ports and sensitivity lists + + + for (SysCAMSTBlockTDF t : tdf) { corpsCluster = corpsCluster + "\t" + t.getName() + " " + t.getName() + "_" + nb_block + ";" + CR; diff --git a/src/main/java/ui/syscams/SysCAMSBlockDE.java b/src/main/java/ui/syscams/SysCAMSBlockDE.java index 96fe3b3afdbfde23fc6a7a54f192c976286e7a29..0e5b6e7c41da7ed5773ff499e560fc7ee4cba8b7 100644 --- a/src/main/java/ui/syscams/SysCAMSBlockDE.java +++ b/src/main/java/ui/syscams/SysCAMSBlockDE.java @@ -63,6 +63,7 @@ public class SysCAMSBlockDE extends TGCScalableWithInternalComponent implements private String nameFn; private String code; + private String clock; private DefaultListModel<String> listStruct; private String nameTemplate; private String typeTemplate; @@ -523,6 +524,14 @@ public class SysCAMSBlockDE extends TGCScalableWithInternalComponent implements return list; } + public void setClockName(String _clock) { + clock = _clock; + } + + public String getClockName() { + return clock; + } + public void setNameFn(String nameFn) { this.nameFn = nameFn; } diff --git a/src/main/java/ui/syscams/SysCAMSClock.java b/src/main/java/ui/syscams/SysCAMSClock.java index d9282ef4d39cf7f50a0d37fd4d0a5c28daaca2fb..faaaadd2d2eba1d658fd93e46fd72df61528a2bf 100644 --- a/src/main/java/ui/syscams/SysCAMSClock.java +++ b/src/main/java/ui/syscams/SysCAMSClock.java @@ -68,10 +68,10 @@ public class SysCAMSClock extends TGCScalableWithInternalComponent implements Sw private String valueTemplate; private String name; private String unit; - private String frequency; - private String dutyCycle; - private String startTime; - private String posFirst; + private double frequency; + private double dutyCycle; + private double startTime; + private boolean posFirst; private DefaultListModel<String> listTypedef; private int maxFontSize = 14; @@ -304,8 +304,8 @@ public class SysCAMSClock extends TGCScalableWithInternalComponent implements Sw StringBuffer sb = new StringBuffer("<extraparam>\n"); sb.append("<Attribute name_function=\"" + getNameFn()); - sb.append("\" code=\"" + encode(getCode())); - sb.append("\" listStruct=\"" + splitParameters(getListStruct())); + //sb.append("\" code=\"" + encode(getCode())); + //sb.append("\" listStruct=\"" + splitParameters(getListStruct())); sb.append("\" nameTemplate=\"" + getNameTemplate()); sb.append("\" name=\"" + getName()); sb.append("\" frequency =\"" + getFrequency()); @@ -313,7 +313,7 @@ public class SysCAMSClock extends TGCScalableWithInternalComponent implements Sw sb.append("\" dutyCycle=\"" + getDutyCycle()); sb.append("\" startTime=\"" + getStartTime()); sb.append("\" posFirst =\"" + getPosFirst()); - sb.append("\" listTypedef=\"" + splitParameters(getListTypedef())); + //sb.append("\" listTypedef=\"" + splitParameters(getListTypedef())); sb.append("\" />\n"); sb.append("</extraparam>\n"); return new String(sb); @@ -438,6 +438,8 @@ public class SysCAMSClock extends TGCScalableWithInternalComponent implements Sw Node n1, n2; Element elt; + double frequency, dutyCycle, startTime; + String code, nameFn, listStruct, nameTemplate, typeTemplate, valueTemplate, listTypedef; for(int i=0; i<nl.getLength(); i++) { @@ -451,35 +453,43 @@ public class SysCAMSClock extends TGCScalableWithInternalComponent implements Sw if (elt.getTagName().equals("Attribute")) { // unit = elt.getAttribute("unit"); unit = elt.getAttribute("unit"); - frequency = elt.getAttribute("frequency"); - posFirst = elt.getAttribute("posFirst"); - dutyCycle = elt.getAttribute("dutyCycle"); - startTime = elt.getAttribute("startTime"); - listStruct = elt.getAttribute("listStruct"); + //frequency = elt.getAttribute("frequency"); + frequency = Double.valueOf(elt.getAttribute("frequency")).doubleValue(); + dutyCycle = Double.valueOf(elt.getAttribute("dutyCycle")).doubleValue(); + startTime = Double.valueOf(elt.getAttribute("startTime")).doubleValue(); + //posFirst = elt.getAttribute("posFirst");//ToDo boolean + //posFirst = true; + //dutyCycle = elt.getAttribute("dutyCycle"); + //startTime = elt.getAttribute("startTime"); + //listStruct = elt.getAttribute("listStruct"); nameTemplate = elt.getAttribute("nameTemplate"); - typeTemplate = elt.getAttribute("typeTemplate"); - valueTemplate = elt.getAttribute("valueTemplate"); - listTypedef = elt.getAttribute("listTypedef"); -// - String[] splita = listStruct.split("\\|"); + //typeTemplate = elt.getAttribute("typeTemplate"); + //valueTemplate = elt.getAttribute("valueTemplate"); + //listTypedef = elt.getAttribute("listTypedef"); + setFrequency(frequency); + setDutyCycle(dutyCycle); + setStartTime(startTime); + + //String[] splita = listStruct.split("\\|"); DefaultListModel<String> lista = new DefaultListModel<String>(); - for (String s : splita) { + /* for (String s : splita) { if (!s.equals("")) { lista.addElement(s); } } - setListStruct(lista); + setListStruct(lista);*/ setNameTemplate(nameTemplate); + //setTypeTemplate(typeTemplate); //setValueTemplate(valueTemplate); - String[] splitb = listTypedef.split("\\|"); + //String[] splitb = listTypedef.split("\\|"); DefaultListModel<String> listb = new DefaultListModel<String>(); - for (String s : splitb) { + /*for (String s : splitb) { if (!s.equals("")) { listb.addElement(s); } } - setListTypedef(listb); + setListTypedef(listb);*/ } } } @@ -556,7 +566,7 @@ public class SysCAMSClock extends TGCScalableWithInternalComponent implements Sw return name; }*/ - public String getFrequency() { + public double getFrequency() { return frequency; } @@ -564,16 +574,16 @@ public class SysCAMSClock extends TGCScalableWithInternalComponent implements Sw return unit; } - public String getDutyCycle() { + public double getDutyCycle() { return dutyCycle; } - public String getStartTime() { + public double getStartTime() { return startTime; } - public String getPosFirst() { + public boolean getPosFirst() { return posFirst; } @@ -582,11 +592,11 @@ public class SysCAMSClock extends TGCScalableWithInternalComponent implements Sw } - public void setStartTime(String _startTime) { + public void setStartTime(double _startTime) { startTime = _startTime; } - public void setFrequency(String _frequency) { + public void setFrequency(double _frequency) { frequency = _frequency; } @@ -594,11 +604,11 @@ public class SysCAMSClock extends TGCScalableWithInternalComponent implements Sw unit = _unit; } - public void setDutyCycle(String _dutyCycle) { + public void setDutyCycle(double _dutyCycle) { dutyCycle = _dutyCycle; } - public void setPosFirst(String _posFirst) { + public void setPosFirst(boolean _posFirst) { posFirst = _posFirst; } diff --git a/src/main/java/ui/syscams/SysCAMSComponentTaskDiagramToolBar.java b/src/main/java/ui/syscams/SysCAMSComponentTaskDiagramToolBar.java index ceb608b8f040f8d4f3a07dad6cd713bbb65b4345..dbda02b22ea6f4752ef578914dd3e2afb248f155 100644 --- a/src/main/java/ui/syscams/SysCAMSComponentTaskDiagramToolBar.java +++ b/src/main/java/ui/syscams/SysCAMSComponentTaskDiagramToolBar.java @@ -68,7 +68,6 @@ public class SysCAMSComponentTaskDiagramToolBar extends TToolBar { mgui.actions[TGUIAction.CAMS_BLOCK_DE].setEnabled(b); mgui.actions[TGUIAction.CAMS_PORT_TDF].setEnabled(b); mgui.actions[TGUIAction.CAMS_PORT_DE].setEnabled(b); - mgui.actions[TGUIAction.CAMS_PORT_CLOCK].setEnabled(b); mgui.actions[TGUIAction.CAMS_PORT_CONVERTER].setEnabled(b); mgui.actions[TGUIAction.CAMS_CLUSTER].setEnabled(b); mgui.actions[TGUIAction.CAMS_GENCODE].setEnabled(b); @@ -125,9 +124,6 @@ public class SysCAMSComponentTaskDiagramToolBar extends TToolBar { button = this.add(mgui.actions[TGUIAction.CAMS_PORT_DE]); button.addMouseListener(mgui.mouseHandler); - button = this.add(mgui.actions[TGUIAction.CAMS_PORT_CLOCK]); - button.addMouseListener(mgui.mouseHandler); - button = this.add(mgui.actions[TGUIAction.CAMS_CLOCK]); button.addMouseListener(mgui.mouseHandler); diff --git a/src/main/java/ui/syscams/SysCAMSPortDE.java b/src/main/java/ui/syscams/SysCAMSPortDE.java index 64c1a7e4e6a371c64a9fa95d6b9a21acd9ac8526..5c2478ae454f28817ff40103ad3989fcf81c56b9 100644 --- a/src/main/java/ui/syscams/SysCAMSPortDE.java +++ b/src/main/java/ui/syscams/SysCAMSPortDE.java @@ -49,10 +49,13 @@ import ui.TGComponent; * Creation: 14/05/2018 * @version 1.0 14/05/2018 * @author Irina Kit Yan LEE - * @revision 8/7/2019 Daniela Genius */ public class SysCAMSPortDE extends SysCAMSPrimitivePort { +// private int period; +// private String time; +// private int rate; +// private int delay; private int nbits;//DG private String DEType; private boolean sensitive; @@ -62,6 +65,38 @@ public class SysCAMSPortDE extends SysCAMSPrimitivePort { super(_x, _y, _minX, _maxX, _minY, _maxY, _pos, _father, _tdp); } +// public int getPeriod() { +// return period; +// } +// +// public void setPeriod(int period) { +// this.period = period; +// } +// +// public String getTime() { +// return time; +// } +// +// public void setTime(String time) { +// this.time = time; +// } +// +// public int getRate() { +// return rate; +// } +// +// public void setRate(int rate) { +// this.rate = rate; +// } +// +// public int getDelay() { +// return delay; +// } +// +// public void setDelay(int delay) { +// this.delay = delay; +// } + public void drawParticularity(Graphics g) { } diff --git a/src/main/java/ui/syscams/SysCAMSPrimitivePort.java b/src/main/java/ui/syscams/SysCAMSPrimitivePort.java index 009f916e25a855030e809e46682e3475646986b4..80f14a1992b0044d2df8a042acc5b7d901b05cd9 100644 --- a/src/main/java/ui/syscams/SysCAMSPrimitivePort.java +++ b/src/main/java/ui/syscams/SysCAMSPrimitivePort.java @@ -120,13 +120,6 @@ public class SysCAMSPrimitivePort extends TGCScalableWithInternalComponent imple ((SysCAMSPortDE) this).setOrigin(0); ((SysCAMSPortDE) this).setSensitive(false); ((SysCAMSPortDE) this).setSensitiveMethod(""); - } else if (this instanceof SysCAMSPortClock) { - //((SysCAMSPortClock) this).setFrequency(-1); - // ((SysCAMSPortClock) this).setUnit(""); - // ((SysCAMSPortClock) this).setStartTime(-1); - // ((SysCAMSPortClock) this).setDutyCycle(-1); - // ((SysCAMSPortClock) this).setPosFirst(true); - ((SysCAMSPortClock) this).setOrigin(1); } else if (this instanceof SysCAMSPortConverter) { ((SysCAMSPortConverter) this).setPeriod(-1); ((SysCAMSPortConverter) this).setTime(""); @@ -556,24 +549,20 @@ public class SysCAMSPrimitivePort extends TGCScalableWithInternalComponent imple sb.append("\" type=\"" + encode(((SysCAMSPortTDF) this).getTDFType())); } if (this instanceof SysCAMSPortDE) { +// sb.append("\" period=\"" + ((SysCAMSPortDE) this).getPeriod()); +// sb.append("\" time=\"" + ((SysCAMSPortDE) this).getTime()); +// sb.append("\" rate=\"" + ((SysCAMSPortDE) this).getRate()); +// sb.append("\" delay=\"" + ((SysCAMSPortDE) this).getDelay()); sb.append("\" type=\"" + encode(((SysCAMSPortDE) this).getDEType())); sb.append("\" sensitive=\"" + ((SysCAMSPortDE) this).getSensitive()); sb.append("\" sensitive_method=\"" + ((SysCAMSPortDE) this).getSensitiveMethod()); sb.append("\" nbits=\"" + ((SysCAMSPortDE) this).getNbits());//DG } - if (this instanceof SysCAMSPortClock) { - /* sb.append("\" =\"" + encode(((SysCAMSPortClock) this).getFrequency())); - sb.append("\" =\"" + ((SysCAMSPortClock) this).getUnit()); - sb.append("\" =\"" + ((SysCAMSPortClock) this).getDutyCycle()); - sb.append("\" =\"" + ((SysCAMSPortClock) this).getStartTime()); - sb.append("\" \"" + ((SysCAMSPortClock) this).getPosFirst());*/ - } - if (this instanceof SysCAMSPortConverter) { sb.append("\" period=\"" + ((SysCAMSPortConverter) this).getPeriod()); sb.append("\" time=\"" + ((SysCAMSPortConverter) this).getTime()); sb.append("\" rate=\"" + ((SysCAMSPortConverter) this).getRate()); - sb.append("\" nbits=\"" + ((SysCAMSPortConverter) this).getNbits()); + sb.append("\" nbits=\"" + ((SysCAMSPortConverter) this).getNbits());//DG sb.append("\" delay=\"" + ((SysCAMSPortConverter) this).getDelay()); sb.append("\" type=\"" + encode(((SysCAMSPortConverter) this).getConvType())); @@ -589,10 +578,10 @@ public class SysCAMSPrimitivePort extends TGCScalableWithInternalComponent imple Node n1, n2; Element elt; - double period, frequency, dutyCycle, startTime; + double period; int rate, delay; String type, time, sensitiveMethod; - Boolean sensitive, posFirst; + Boolean sensitive; for(int i=0; i<nl.getLength(); i++) { n1 = nl.item(i); @@ -619,19 +608,16 @@ public class SysCAMSPrimitivePort extends TGCScalableWithInternalComponent imple ((SysCAMSPortTDF) this).setDelay(delay); ((SysCAMSPortTDF) this).setTDFType(type); } else if (this instanceof SysCAMSPortDE) { - type = elt.getAttribute("type"); + // ((SysCAMSPortDE)this).setPeriod(period); + // ((SysCAMSPortDE)this).setTime(time); + // ((SysCAMSPortDE)this).setRate(rate); + // ((SysCAMSPortDE)this).setDelay(delay); + type = elt.getAttribute("type"); sensitive = Boolean.parseBoolean(elt.getAttribute("sensitive")); sensitiveMethod = elt.getAttribute("sensitive_method"); ((SysCAMSPortDE) this).setDEType(type); ((SysCAMSPortDE) this).setSensitive(sensitive); ((SysCAMSPortDE) this).setSensitiveMethod(sensitiveMethod); - } else if (this instanceof SysCAMSPortClock) { - type = elt.getAttribute("type"); - /* ((SysCAMSPortClock) this).setFrequency(frequency); - ((SysCAMSPortClock) this).setUnit(unit); - ((SysCAMSPortClock) this).setStartTime(startTime); - ((SysCAMSPortClock) this).setDutyCycle(dutyCycle); - ((SysCAMSPortClock) this).setPosFirst(posFirst);*/ } else if (this instanceof SysCAMSPortConverter) { period = Double.valueOf(elt.getAttribute("period")).doubleValue(); time = elt.getAttribute("time"); @@ -678,9 +664,6 @@ public class SysCAMSPrimitivePort extends TGCScalableWithInternalComponent imple return "Port DE"; } else if (this instanceof SysCAMSPortConverter) { return "Port Converter"; - } - else if (this instanceof SysCAMSPortClock) { - return "Port Clock"; } return ""; } diff --git a/src/main/java/ui/window/JDialogSysCAMSBlockDE.java b/src/main/java/ui/window/JDialogSysCAMSBlockDE.java index 516e328e0ab4bb4c446e5cf7e5d9f7c539c64850..36ff82daeaaf0c30e2b52bac451b5dc6dfcfcfe6 100644 --- a/src/main/java/ui/window/JDialogSysCAMSBlockDE.java +++ b/src/main/java/ui/window/JDialogSysCAMSBlockDE.java @@ -60,6 +60,7 @@ import javax.swing.event.*; public class JDialogSysCAMSBlockDE extends JDialog implements ActionListener, ListSelectionListener { private JTextField nameTextField; + private JTextField clockTextField; // private JTextField periodTextField; // private String listPeriodString[]; // private JComboBox<String> periodComboBoxString; @@ -268,6 +269,30 @@ public class JDialogSysCAMSBlockDE extends JDialog implements ActionListener, Li // gridBag.setConstraints(periodComboBoxString, constraints); // attributesBoxPanel.add(periodComboBoxString); + + /*GridBagLayout gridBag = new GridBagLayout(); + GridBagConstraints constraints = new GridBagConstraints(); + JPanel attributesBoxPanel = new JPanel(); + attributesBoxPanel.setFont(new Font("Helvetica", Font.PLAIN, 14)); + attributesBoxPanel.setLayout(gridBag);*/ + + JLabel labelClock = new JLabel("Clock : "); + constraints = new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(15, 10, 5, 10), 0, 0); + gridBag.setConstraints(labelClock, constraints); + attributesBoxPanel.add(labelClock); + + if (block.getValue().toString().equals("")) { + clockTextField = new JTextField(10); + } else { + clockTextField = new JTextField(block.getValue().toString(), 10); + } + constraints = new GridBagConstraints(1, 1, 2, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(15, 10, 5, 10), 0, 0); + gridBag.setConstraints(clockTextField, constraints); + attributesBoxPanel.add(clockTextField); + + attributesBox.add(attributesBoxPanel); attributesMainPanel.add(attributesBox, BorderLayout.NORTH); @@ -699,6 +724,11 @@ public class JDialogSysCAMSBlockDE extends JDialog implements ActionListener, Li JOptionPane.WARNING_MESSAGE); } } + + if (!(clockTextField.getText().isEmpty())) { + block.setClockName(clockTextField.getText()); + } + if (block.getFather() != null) { if ("OK".equals(e.getActionCommand())) { nameTypedefTextField.setEditable(true); diff --git a/src/main/java/ui/window/JDialogSysCAMSClock.java b/src/main/java/ui/window/JDialogSysCAMSClock.java index 2d2525dae5c798c0be49fcb89e61cfa77a8610a0..7addeaaf47bdaf8b402ce98c3e1be22de5b59731 100644 --- a/src/main/java/ui/window/JDialogSysCAMSClock.java +++ b/src/main/java/ui/window/JDialogSysCAMSClock.java @@ -1,801 +1,909 @@ -/* 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.syscams.*; -import ui.util.*; -import java.awt.*; -import java.awt.event.*; -import java.util.*; -import javax.swing.*; -import javax.swing.border.*; -import javax.swing.event.*; - -/** - * Class JDialogSystemCAMSBlockDE - * Dialog for managing of SystemC-AMS DE Block - * Creation: 26/04/2018 - * @version 1.0 26/04/2018 - * @author Irina Kit Yan LEE - */ - -@SuppressWarnings("serial") - -public class JDialogSysCAMSClock extends JDialog implements ActionListener, ListSelectionListener { - - private JTextField nameTextField; -// private JTextField periodTextField; -// private String listPeriodString[]; -// private JComboBox<String> periodComboBoxString; - - private JTextField frequencyTextField; - private JTextField unitTextField; - private JTextField dutyCycleTextField; - - private JTextField startTimeTextField; - private String listUnitString[]; - private String posFirstString[]; - private JComboBox<String> unitComboBoxString; - private JComboBox<String> posFirstComboBoxString; - private SysCAMSClock clock; - - private JPanel parametersMainPanel; - private JTextField nameStructTextField; - private JTextField valueStructTextField; - private JRadioButton constantStructRadioButton; - private String listTypeStructString[]; - private JComboBox<String> typeStructComboBoxString; - private ArrayList<String> listTmpStruct; - private JList<String> structList; - private DefaultListModel<String> structListModel; - private boolean structBool = false; - private JTextField nameTemplateTextField; - private JTextField valueTemplateTextField; - private String listTypeTemplateString[]; - private JComboBox<String> typeTemplateComboBoxString; - private JTextField nameTypedefTextField; - private String listTypeTypedefString[]; - private JComboBox<String> typeTypedefComboBoxString; - private JButton addModifyTypedefButton; - private ArrayList<String> listTmpTypedef; - private JList<String> typedefList; - private DefaultListModel<String> typedefListModel; - private boolean typedefBool = false; - - private JButton upButton, downButton, removeButton; - - private JPanel codeMainPanel; - private JTextField nameFnTextField; - private JButton nameFnButton; - private JTextArea codeTextArea; - private String finalString; - - // private SysCAMSClock block; - - public JDialogSysCAMSClock(SysCAMSClock clock) { - this.setTitle("Setting DE Clock Attributes"); - this.setLocationRelativeTo(null); - this.setVisible(true); - this.setAlwaysOnTop(true); - this.setResizable(false); - - this.clock = clock; - - 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 StringBuffer encode(String data) { - StringBuffer databuf = new StringBuffer(data); - StringBuffer buffer = new StringBuffer(""); - int endline = 0; - int nb_arobase = 0; - int condition = 0; - - for (int pos = 0; pos != data.length(); pos++) { - char c = databuf.charAt(pos); - switch (c) { - case '\n': - break; - case '\t': - break; - case '{': - buffer.append("{\n"); - endline = 1; - nb_arobase++; - break; - case '}': - if (nb_arobase == 1) { - buffer.append("}\n"); - endline = 0; - } else { - int i = nb_arobase; - while (i >= 1) { - buffer.append("\t"); - i--; - } - buffer.append("}\n"); - endline = 1; - } - nb_arobase--; - break; - case ';': - if (condition == 1) { - buffer.append(";"); - } else { - buffer.append(";\n"); - endline = 1; - } - break; - case ' ': - if (endline == 0) { - buffer.append(databuf.charAt(pos)); - } - break; - case '(': - buffer.append("("); - condition = 1; - break; - case ')': - buffer.append(")"); - condition = 0; - break; - default: - if (endline == 1) { - endline = 0; - int i = nb_arobase; - while (i >= 1) { - buffer.append("\t"); - i--; - } - } - buffer.append(databuf.charAt(pos)); - break; - } - } - return buffer; - } - - public void dialog() { - JPanel mainPanel = new JPanel(new BorderLayout()); - this.add(mainPanel); - - JPanel attributesMainPanel = new JPanel(); - if (clock.getFather() != null) { - JTabbedPane tabbedPane = new JTabbedPane(); - parametersMainPanel = new JPanel(); - codeMainPanel = new JPanel(); - tabbedPane.add("Attributes", attributesMainPanel); - //tabbedPane.add("Parameters", parametersMainPanel); - //tabbedPane.add("Method Code", codeMainPanel); - - mainPanel.add(tabbedPane, BorderLayout.NORTH); - } else { - mainPanel.add(attributesMainPanel, BorderLayout.NORTH); - } - - // --- Attributes ---// - attributesMainPanel.setLayout(new BorderLayout()); - - Box attributesBox = Box.createVerticalBox(); - attributesBox.setBorder(BorderFactory.createTitledBorder("Setting DE clock 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 (clock.getValue().toString().equals("")) { - nameTextField = new JTextField(10); - } else { - nameTextField = new JTextField(clock.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); - - JLabel labelFrequency = new JLabel("Frequency : "); - constraints = new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, - new Insets(15, 10, 5, 10), 0, 0); - gridBag.setConstraints(labelFrequency, constraints); - attributesBoxPanel.add(labelFrequency); - - if (clock.getValue().toString().equals("")) { - nameTextField = new JTextField(10); - } else { - frequencyTextField = new JTextField(clock.getValue().toString(), 10); - } - constraints = new GridBagConstraints(1, 1, 2, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, - new Insets(15, 10, 5, 10), 0, 0); - gridBag.setConstraints(frequencyTextField, constraints); - attributesBoxPanel.add(frequencyTextField); - - - JLabel labelDutyCycle = new JLabel("DutyCycle : "); - constraints = new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, - new Insets(15, 10, 5, 10), 0, 0); - gridBag.setConstraints(labelDutyCycle, constraints); - attributesBoxPanel.add(labelDutyCycle); - - if (clock.getValue().toString().equals("")) { - nameTextField = new JTextField(10); - } else { - frequencyTextField = new JTextField(clock.getValue().toString(), 10); - } - constraints = new GridBagConstraints(1, 1, 2, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, - new Insets(15, 10, 5, 10), 0, 0); - gridBag.setConstraints(frequencyTextField, constraints); - attributesBoxPanel.add(frequencyTextField); - - listUnitString = new String[4]; - listUnitString[0] = "s"; - listUnitString[1] = "ms"; - listUnitString[2] = "\u03BCs"; - listUnitString[3] = "ns"; - unitComboBoxString = new JComboBox<String>(listUnitString); - if (clock.getUnit().equals("") || clock.getUnit().equals("s")) { - unitComboBoxString.setSelectedIndex(0); - } else if (clock.getUnit().equals("ms")){ - unitComboBoxString.setSelectedIndex(1); - } else if (clock.getUnit().equals("\u03BCs")){ - unitComboBoxString.setSelectedIndex(2); - } else if (clock.getUnit().equals("ns")){ - unitComboBoxString.setSelectedIndex(3); - } - unitComboBoxString.setActionCommand("unit"); - unitComboBoxString.addActionListener(this); - constraints = new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0, - GridBagConstraints.CENTER, - GridBagConstraints.BOTH, - new Insets(5, 10, 5, 10), 0, 0); - gridBag.setConstraints(unitComboBoxString, constraints); - attributesBoxPanel.add(unitComboBoxString); - - posFirstString = new String[2]; - posFirstString[0] = "true"; - posFirstString[1] = "false"; - - posFirstComboBoxString = new JComboBox<String>(posFirstString); - if (clock.getPosFirst().equals("") || clock.getPosFirst().equals("true")) { - posFirstComboBoxString.setSelectedIndex(0); - } else if (clock.getPosFirst().equals("false")){ - posFirstComboBoxString.setSelectedIndex(1); - } - posFirstComboBoxString.setActionCommand("positive edge first"); - posFirstComboBoxString.addActionListener(this); - constraints = new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0, - GridBagConstraints.CENTER, - GridBagConstraints.BOTH, - new Insets(5, 10, 5, 10), 0, 0); - gridBag.setConstraints(posFirstComboBoxString, constraints); - attributesBoxPanel.add(posFirstComboBoxString); - - attributesBox.add(attributesBoxPanel); - attributesMainPanel.add(attributesBox, BorderLayout.NORTH); - - - // -- Button -- / - 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) { - - /* clock.setName(nameTextField.getText()); - clock.setFrequency(frequencyTextField.getText()); - clock.setDutyCycle(dutyCycleTextField.getText()); - clock.setStartTime(startTimeTextField.getText()); - clock.setPosFirst((String) posFirstComboBoxString.getSelectedItem()); - clock.setUnit((String) unitComboBoxString.getSelectedItem()); - */ - if ("Name_OK".equals(e.getActionCommand())) { - if (!nameFnTextField.getText().equals("")) { - codeTextArea.setText("void " + nameFnTextField.getText() + "() {\n\n}"); - } else { - JDialog msg = new JDialog(this); - msg.setLocationRelativeTo(null); - JOptionPane.showMessageDialog(msg, "This method has no name. Please add a name for this method.", "Warning !", - JOptionPane.WARNING_MESSAGE); - } - } - if (clock.getFather() != null) { - if ("OK".equals(e.getActionCommand())) { - nameTypedefTextField.setEditable(true); - typeTypedefComboBoxString.setEnabled(true); - addModifyTypedefButton.setEnabled(true); - } - - if ("Add_Modify_Struct".equals(e.getActionCommand())) { - listTmpStruct = new ArrayList<String>(); - Boolean alreadyExist = false; - int alreadyExistId = -1; - String type = (String) typeStructComboBoxString.getSelectedItem(); - String s = null; - - Boolean valueBoolean = false, valueInteger = false, valueDouble = false, valueLong = false, nameEmpty = false; - - if (nameStructTextField.getText().isEmpty()) { - JDialog msg = new JDialog(this); - msg.setLocationRelativeTo(null); - JOptionPane.showMessageDialog(msg, "The name of struct is empty", "Warning !", - JOptionPane.WARNING_MESSAGE); - nameEmpty = true; - } - - for (int i = 0; i < structListModel.getSize(); i++) { - if (nameStructTextField.getText().equals(structListModel.elementAt(i).split("\\s")[0])) { - alreadyExist = true; - alreadyExistId = i; - } - } - - if (alreadyExist == false) { - try { - if (type.equals("bool")) { - Boolean.parseBoolean(valueStructTextField.getText()); - } else if (type.equals("double")) { - Double.parseDouble(valueStructTextField.getText()); - } else if (type.equals("float")) { - Float.parseFloat(valueStructTextField.getText()); - } else if (type.equals("int")) { - Integer.parseInt(valueStructTextField.getText()); - } else if (type.equals("long")) { - Long.parseLong(valueStructTextField.getText()); - } else if (type.equals("short")) { - Short.parseShort(valueStructTextField.getText()); - } - } catch (NumberFormatException e1) { - if (type.equals("bool")) { - JDialog msg = new JDialog(this); - msg.setLocationRelativeTo(null); - JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Boolean", "Warning !", - JOptionPane.WARNING_MESSAGE); - valueBoolean = true; - } else if (type.equals("double")) { - JDialog msg = new JDialog(this); - msg.setLocationRelativeTo(null); - JOptionPane.showMessageDialog(msg, "The value of the parameteris not a Double", "Warning !", - JOptionPane.WARNING_MESSAGE); - valueInteger = true; - } else if (type.equals("float")) { - JDialog msg = new JDialog(this); - msg.setLocationRelativeTo(null); - JOptionPane.showMessageDialog(msg, "The value of the parameteris not a Float", "Warning !", - JOptionPane.WARNING_MESSAGE); - valueInteger = true; - } else if (type.equals("int")) { - JDialog msg = new JDialog(this); - msg.setLocationRelativeTo(null); - JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Integer", "Warning !", - JOptionPane.WARNING_MESSAGE); - valueDouble = true; - } else if (type.equals("long")) { - JDialog msg = new JDialog(this); - msg.setLocationRelativeTo(null); - JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Long", "Warning !", - JOptionPane.WARNING_MESSAGE); - valueLong = true; - } else if (type.equals("short")) { - JDialog msg = new JDialog(this); - msg.setLocationRelativeTo(null); - JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Short", "Warning !", - JOptionPane.WARNING_MESSAGE); - valueLong = true; - } - } - - if ((valueBoolean == false) && (valueInteger == false) && (valueDouble == false) && (valueLong == false) && (nameEmpty == false)) { - s = nameStructTextField.getText() + " = "; - - if (type.equals("bool")) { - s = s + Boolean.parseBoolean(valueStructTextField.getText()) + " : "; - } else if (type.equals("double")) { - s = s + Double.parseDouble(valueStructTextField.getText()) + " : "; - } else if (type.equals("float")) { - s = s + Float.parseFloat(valueStructTextField.getText()) + " : "; - } else if (type.equals("int")) { - s = s + Integer.parseInt(valueStructTextField.getText()) + " : "; - } else if (type.equals("long")) { - s = s + Long.parseLong(valueStructTextField.getText()) + " : "; - } else if (type.equals("short")) { - s = s + Short.parseShort(valueStructTextField.getText()) + " : "; - } - - if (constantStructRadioButton.isSelected()) { - s = s + "const " + type; - } else { - s = s + type; - } - structListModel.addElement(s); - listTmpStruct.add(s); - } - } else { - try { - if (type.equals("bool")) { - Boolean.parseBoolean(valueStructTextField.getText()); - } else if (type.equals("double")) { - Double.parseDouble(valueStructTextField.getText()); - } else if (type.equals("float")) { - Float.parseFloat(valueStructTextField.getText()); - } else if (type.equals("int")) { - Integer.parseInt(valueStructTextField.getText()); - } else if (type.equals("long")) { - Long.parseLong(valueStructTextField.getText()); - } else if (type.equals("short")) { - Short.parseShort(valueStructTextField.getText()); - } - } catch (NumberFormatException e1) { - if (type.equals("bool")) { - JDialog msg = new JDialog(this); - msg.setLocationRelativeTo(null); - JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Boolean", "Warning !", - JOptionPane.WARNING_MESSAGE); - valueBoolean = true; - } else if (type.equals("double")) { - JDialog msg = new JDialog(this); - msg.setLocationRelativeTo(null); - JOptionPane.showMessageDialog(msg, "The value of the parameteris not a Double", "Warning !", - JOptionPane.WARNING_MESSAGE); - valueInteger = true; - } else if (type.equals("float")) { - JDialog msg = new JDialog(this); - msg.setLocationRelativeTo(null); - JOptionPane.showMessageDialog(msg, "The value of the parameteris not a Float", "Warning !", - JOptionPane.WARNING_MESSAGE); - valueInteger = true; - } else if (type.equals("int")) { - JDialog msg = new JDialog(this); - msg.setLocationRelativeTo(null); - JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Integer", "Warning !", - JOptionPane.WARNING_MESSAGE); - valueDouble = true; - } else if (type.equals("long")) { - JDialog msg = new JDialog(this); - msg.setLocationRelativeTo(null); - JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Long", "Warning !", - JOptionPane.WARNING_MESSAGE); - valueLong = true; - } else if (type.equals("short")) { - JDialog msg = new JDialog(this); - msg.setLocationRelativeTo(null); - JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Short", "Warning !", - JOptionPane.WARNING_MESSAGE); - valueLong = true; - } - } - - if ((valueBoolean == false) && (valueInteger == false) && (valueDouble == false) && (valueLong == false) && (nameEmpty == false)) { - s = nameStructTextField.getText() + " = "; - - if (type.equals("bool")) { - s = s + Boolean.parseBoolean(valueStructTextField.getText()) + " : "; - } else if (type.equals("double")) { - s = s + Double.parseDouble(valueStructTextField.getText()) + " : "; - } else if (type.equals("float")) { - s = s + Float.parseFloat(valueStructTextField.getText()) + " : "; - } else if (type.equals("int")) { - s = s + Integer.parseInt(valueStructTextField.getText()) + " : "; - } else if (type.equals("long")) { - s = s + Long.parseLong(valueStructTextField.getText()) + " : "; - } else if (type.equals("short")) { - s = s + Short.parseShort(valueStructTextField.getText()) + " : "; - } - - if (constantStructRadioButton.isSelected()) { - s = s + "const " + type; - } else { - s = s + type; - } - structListModel.setElementAt(s, alreadyExistId); - listTmpStruct.add(s); - } - } - } - - if ("Add_Modify_Typedef".equals(e.getActionCommand())) { - listTmpTypedef = new ArrayList<String>(); - Boolean alreadyExist = false; - int alreadyExistId = -1; - String type = (String) typeTypedefComboBoxString.getSelectedItem(); - String s = null; - - Boolean nameEmpty = false; - - if (nameTypedefTextField.getText().isEmpty()) { - JDialog msg = new JDialog(this); - msg.setLocationRelativeTo(null); - JOptionPane.showMessageDialog(msg, "The name of typedef is empty", "Warning !", - JOptionPane.WARNING_MESSAGE); - nameEmpty = true; - } - - if (nameEmpty == false) { - for (int i = 0; i < typedefListModel.getSize(); i++) { - if (nameTypedefTextField.getText().equals(typedefListModel.elementAt(i).split("\\s")[0])) { - alreadyExist = true; - alreadyExistId = i; - } - } - - if (alreadyExist == false) { - s = nameTypedefTextField.getText() + " : " + type; - typedefListModel.addElement(s); - listTmpTypedef.add(s); - } else { - s = nameTypedefTextField.getText() + " : " + type; - typedefListModel.setElementAt(s, alreadyExistId); - listTmpTypedef.add(s); - } - } - } - - - if ("Remove".equals(e.getActionCommand())) { - if (structBool == true) { - if (structListModel.getSize() >= 1) { - structListModel.remove(structList.getSelectedIndex()); - } - } - if (typedefBool == true) { - if (typedefListModel.getSize() >= 1) { - typedefListModel.remove(typedefList.getSelectedIndex()); - } - } - } - - if ("Up".equals(e.getActionCommand())) { - if (structBool == true) { - if (structList.getSelectedIndex() >= 1) { - String sprev = structListModel.get(structList.getSelectedIndex()-1); - structListModel.remove(structList.getSelectedIndex()-1); - structListModel.add(structList.getSelectedIndex()+1, sprev); - } else { - JDialog msg = new JDialog(this); - msg.setLocationRelativeTo(null); - JOptionPane.showMessageDialog(msg, "Cannot move the parameter up", "Warning !", - JOptionPane.WARNING_MESSAGE); - } - } - if (typedefBool == true) { - if (typedefList.getSelectedIndex() >= 1) { - String sprev = typedefListModel.get(typedefList.getSelectedIndex()-1); - typedefListModel.remove(typedefList.getSelectedIndex()-1); - typedefListModel.add(typedefList.getSelectedIndex()+1, sprev); - } else { - JDialog msg = new JDialog(this); - msg.setLocationRelativeTo(null); - JOptionPane.showMessageDialog(msg, "Cannot move the parameter up", "Warning !", - JOptionPane.WARNING_MESSAGE); - } - } - } - - if ("Down".equals(e.getActionCommand())) { - if (structBool == true) { - if (structList.getSelectedIndex() < structListModel.getSize()-1) { - String snext = structListModel.get(structList.getSelectedIndex()+1); - structListModel.remove(structList.getSelectedIndex()+1); - structListModel.add(structList.getSelectedIndex(), snext); - } else { - JDialog msg = new JDialog(this); - msg.setLocationRelativeTo(null); - JOptionPane.showMessageDialog(msg, "Cannot move the parameter down", "Warning !", - JOptionPane.WARNING_MESSAGE); - } - } - if (typedefBool == true) { - if (typedefList.getSelectedIndex() < typedefListModel.getSize()-1) { - String snext = typedefListModel.get(typedefList.getSelectedIndex()+1); - typedefListModel.remove(typedefList.getSelectedIndex()+1); - typedefListModel.add(typedefList.getSelectedIndex(), snext); - } else { - JDialog msg = new JDialog(this); - msg.setLocationRelativeTo(null); - JOptionPane.showMessageDialog(msg, "Cannot move the parameter down", "Warning !", - JOptionPane.WARNING_MESSAGE); - } - } - } - } - - if ("Save_Close".equals(e.getActionCommand())) { - clock.setValue(new String(nameTextField.getText())); - -// if (!(periodTextField.getText().isEmpty())) { -// Boolean periodValueInteger = false; -// try { -// Integer.parseInt(periodTextField.getText()); -// } catch (NumberFormatException e1) { -// JDialog msg = new JDialog(this); -// msg.setLocationRelativeTo(null); -// JOptionPane.showMessageDialog(msg, "Period Tm is not a Integer", "Warning !", -// JOptionPane.WARNING_MESSAGE); -// periodValueInteger = true; -// } -// if (periodValueInteger == false) { -// clock.setPeriod(Integer.parseInt(periodTextField.getText())); -// clock.setTime((String) periodComboBoxString.getSelectedItem()); -// } -// } else { -// clock.setPeriod(-1); -// clock.setTime(""); -// } - - if (clock.getFather() != null) { - clock.setListStruct(structListModel); - clock.setNameTemplate(nameTemplateTextField.getText()); - clock.setTypeTemplate((String) typeTemplateComboBoxString.getSelectedItem()); - clock.setValueTemplate(valueTemplateTextField.getText()); - clock.setListTypedef(typedefListModel); - clock.setNameFn(nameFnTextField.getText()); - clock.setCode(codeTextArea.getText()); - } - - this.dispose(); - } - - if ("Cancel".equals(e.getActionCommand())) { - if (clock.getFather() != null) { - if (listTmpStruct != null) { - for (String s : listTmpStruct) { - structListModel.removeElement(s); - } - } - if (listTmpTypedef != null) { - for (String s : listTmpTypedef) { - typedefListModel.removeElement(s); - } - } - } - this.dispose(); - } - } - - public void valueChanged(ListSelectionEvent e) { - JList listTmp = (JList) e.getSource(); - if (listTmp.equals(structList)) { - structBool = true; - typedefBool = false; - } - if (listTmp.equals(typedefList)) { - typedefBool = true; - structBool = false; - } - - if (e.getValueIsAdjusting() == false) { - if (structBool == true) { - if (structList.getSelectedIndex() != -1) { - String select = structListModel.get(structList.getSelectedIndex()); - String[] splita = select.split(" = "); - nameStructTextField.setText(splita[0]); - String[] splitb = splita[1].split(" : "); - valueStructTextField.setText(splitb[0]); - String[] splitc = splitb[1].split(" "); - - if (splitc[0].equals("const")) { - constantStructRadioButton.setSelected(true); - if (splitc[1].equals("bool")) { - typeStructComboBoxString.setSelectedIndex(0); - } else if (splitc[1].equals("double")) { - typeStructComboBoxString.setSelectedIndex(1); - } else if (splitc[1].equals("float")) { - typeStructComboBoxString.setSelectedIndex(2); - } else if (splitc[1].equals("int")) { - typeStructComboBoxString.setSelectedIndex(3); - } else if (splitc[1].equals("long")) { - typeStructComboBoxString.setSelectedIndex(4); - } else if (splitc[1].equals("short")) { - typeStructComboBoxString.setSelectedIndex(5); - } - } else { - constantStructRadioButton.setSelected(false); - if (splitc[0].equals("bool")) { - typeStructComboBoxString.setSelectedIndex(0); - } else if (splitc[0].equals("double")) { - typeStructComboBoxString.setSelectedIndex(1); - } else if (splitc[0].equals("float")) { - typeStructComboBoxString.setSelectedIndex(2); - } else if (splitc[0].equals("int")) { - typeStructComboBoxString.setSelectedIndex(3); - } else if (splitc[0].equals("long")) { - typeStructComboBoxString.setSelectedIndex(4); - } else if (splitc[0].equals("short")) { - typeStructComboBoxString.setSelectedIndex(5); - } - } - - if (structListModel.getSize() >= 2) { - upButton.setEnabled(true); - downButton.setEnabled(true); - } - removeButton.setEnabled(true); - } - } - - if (typedefBool == true) { - if (typedefList.getSelectedIndex() != -1) { - String select = typedefListModel.get(typedefList.getSelectedIndex()); - String[] split = select.split(" : "); - nameTypedefTextField.setText(split[0]); - - if (split[1].equals("sc_dt::sc_int")) { - typeTypedefComboBoxString.setSelectedIndex(0); - } - - if (typedefListModel.getSize() >= 2) { - upButton.setEnabled(true); - downButton.setEnabled(true); - } - removeButton.setEnabled(true); - } - } - } - } -} +/* 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.syscams.SysCAMSClock; +import ui.util.*; +import java.awt.*; +import java.awt.event.*; +import java.util.*; +import javax.swing.*; + +/** + * Class JDialogSysCAMSClock + * Dialog for managing of SystemC-AMS Clock + * Creation: 04/06/2019 + * @version 1.0 04/06/2016 + * @author Daniela GENIUS + */ + +@SuppressWarnings("serial") + +public class JDialogSysCAMSClock extends JDialog implements ActionListener { + + private JTextField nameTextField; + + private JComboBox<String> unitComboBoxString; + + private JTextField posFirstTextField; + private String listPosFirstString[]; + private JComboBox<String> posFirstComboBoxString; + + private JTextField frequencyTextField; + private String listFrequencyString[]; + private JComboBox<String> frequencyComboBoxString; + + private JTextField dutyCycleTextField; + private String listDutyCycleString[]; + private JComboBox<String> dutyCycleComboBoxString; + + private JTextField startTimeTextField; + private String listStartTimeString[]; + private JComboBox<String> startTimeComboBoxString; + + private JTextField nameStructTextField; + private JTextField valueStructTextField; + private JRadioButton constantStructRadioButton; + private String listTypeStructString[]; + private JComboBox<String> typeStructComboBoxString; + private ArrayList<String> listTmpStruct; + private JList<String> structList; + private DefaultListModel<String> structListModel; + private boolean structBool = false; + private JTextField nameTemplateTextField; + private JTextField valueTemplateTextField; + private String listTypeTemplateString[]; + private JComboBox<String> typeTemplateComboBoxString; + private JTextField nameTypedefTextField; + private String listTypeTypedefString[]; + private JComboBox<String> typeTypedefComboBoxString; + private JButton addModifyTypedefButton; + private ArrayList<String> listTmpTypedef; + private JList<String> typedefList; + private DefaultListModel<String> typedefListModel; + private boolean typedefBool = false; + + private JButton upButton, downButton, removeButton; + + + private SysCAMSClock clock; + + + public JDialogSysCAMSClock(SysCAMSClock clock) { + this.setTitle("Setting Clock Attributes"); + this.setLocationRelativeTo(null); + this.setVisible(true); + this.setAlwaysOnTop(true); + this.setResizable(false); + + this.clock = clock; + + 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 StringBuffer encode(String data) { + StringBuffer databuf = new StringBuffer(data); + StringBuffer buffer = new StringBuffer(""); + int endline = 0; + int nb_arobase = 0; + int condition = 0; + + for (int pos = 0; pos != data.length(); pos++) { + char c = databuf.charAt(pos); + switch (c) { + case '\n': + break; + case '\t': + break; + case '{': + buffer.append("{\n"); + endline = 1; + nb_arobase++; + break; + case '}': + if (nb_arobase == 1) { + buffer.append("}\n"); + endline = 0; + } else { + int i = nb_arobase; + while (i >= 1) { + buffer.append("\t"); + i--; + } + buffer.append("}\n"); + endline = 1; + } + nb_arobase--; + break; + case ';': + if (condition == 1) { + buffer.append(";"); + } else { + buffer.append(";\n"); + endline = 1; + } + break; + case ' ': + if (endline == 0) { + buffer.append(databuf.charAt(pos)); + } + break; + case '(': + buffer.append("("); + condition = 1; + break; + case ')': + buffer.append(")"); + condition = 0; + break; + default: + if (endline == 1) { + endline = 0; + int i = nb_arobase; + while (i >= 1) { + buffer.append("\t"); + i--; + } + } + buffer.append(databuf.charAt(pos)); + break; + } + } + return buffer; + } + + + public void dialog() { + JPanel mainPanel = new JPanel(new BorderLayout()); + this.add(mainPanel); + + JTabbedPane tabbedPane = new JTabbedPane(); + JPanel attributesMainPanel = new JPanel(); + JPanel parametersMainPanel = new JPanel(); + JPanel processMainPanel = new JPanel(); + JPanel contructorMainPanel = new JPanel(); + tabbedPane.add("Attributes", attributesMainPanel); + // tabbedPane.add("Parameters", parametersMainPanel); + //tabbedPane.add("Process Code", processMainPanel); + //tabbedPane.add("Constructor Code", contructorMainPanel); + + mainPanel.add(tabbedPane, BorderLayout.NORTH); + + // --- Attributes ---// + attributesMainPanel.setLayout(new BorderLayout()); + + Box attributesBox = Box.createVerticalBox(); + attributesBox.setBorder(BorderFactory.createTitledBorder("Setting Clock 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 (clock.getValue().toString().equals("")) { + nameTextField = new JTextField(10); + } else { + nameTextField = new JTextField(clock.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); + + JLabel frequencyLabel = new JLabel("Frequency Tm : "); + constraints = new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(5, 10, 15, 10), 0, 0); + gridBag.setConstraints(frequencyLabel, constraints); + attributesBoxPanel.add(frequencyLabel); + + if (clock.getFrequency() == -1) { + frequencyTextField = new JTextField(10); + } else { + frequencyTextField = new JTextField("" + clock.getFrequency(), 10); + } + constraints = new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(5, 10, 15, 10), 0, 0); + gridBag.setConstraints(frequencyTextField, constraints); + attributesBoxPanel.add(frequencyTextField); + + listFrequencyString = new String[4]; + listFrequencyString[0] = "s"; + listFrequencyString[1] = "ms"; + listFrequencyString[2] = "\u03BCs"; + listFrequencyString[3] = "ns"; + frequencyComboBoxString = new JComboBox<String>(listFrequencyString); + if (clock.getUnit().equals("") || clock.getUnit().equals("s")) { + frequencyComboBoxString.setSelectedIndex(0); + } else if (clock.getUnit().equals("ms")) { + frequencyComboBoxString.setSelectedIndex(1); + } else if (clock.getUnit().equals("\u03BCs")) { + frequencyComboBoxString.setSelectedIndex(2); + } else if (clock.getUnit().equals("ns")) { + frequencyComboBoxString.setSelectedIndex(3); + } + frequencyComboBoxString.addActionListener(this); + constraints = new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(5, 10, 15, 10), 0, 0); + gridBag.setConstraints(frequencyComboBoxString, constraints); + attributesBoxPanel.add(frequencyComboBoxString); + // + + JLabel dutyCycleLabel = new JLabel("DutyCycle Tm : "); + constraints = new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(5, 10, 15, 10), 0, 0); + gridBag.setConstraints(dutyCycleLabel, constraints); + attributesBoxPanel.add(dutyCycleLabel); + + if (clock.getDutyCycle() == -1) { + dutyCycleTextField = new JTextField(10); + } else { + dutyCycleTextField = new JTextField("" + clock.getDutyCycle(), 10); + } + constraints = new GridBagConstraints(1, 2, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(5, 10, 15, 10), 0, 0); + gridBag.setConstraints(dutyCycleTextField, constraints); + attributesBoxPanel.add(dutyCycleTextField); + + listDutyCycleString = new String[4]; + listDutyCycleString[0] = "s"; + listDutyCycleString[1] = "ms"; + listDutyCycleString[2] = "\u03BCs"; + listDutyCycleString[3] = "ns"; + dutyCycleComboBoxString = new JComboBox<String>(listDutyCycleString); + if (clock.getUnit().equals("") || clock.getUnit().equals("s")) { + dutyCycleComboBoxString.setSelectedIndex(0); + } else if (clock.getUnit().equals("ms")) { + dutyCycleComboBoxString.setSelectedIndex(1); + } else if (clock.getUnit().equals("\u03BCs")) { + dutyCycleComboBoxString.setSelectedIndex(2); + } else if (clock.getUnit().equals("ns")) { + dutyCycleComboBoxString.setSelectedIndex(3); + } + dutyCycleComboBoxString.addActionListener(this); + constraints = new GridBagConstraints(2, 2, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(5, 10, 15, 10), 0, 0); + gridBag.setConstraints(dutyCycleComboBoxString, constraints); + attributesBoxPanel.add(dutyCycleComboBoxString); + // + + JLabel startTimeLabel = new JLabel("StartTime Tm : "); + constraints = new GridBagConstraints(0, 3, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(5, 10, 15, 10), 0, 0); + gridBag.setConstraints(startTimeLabel, constraints); + attributesBoxPanel.add(startTimeLabel); + + if (clock.getStartTime() == -1) { + startTimeTextField = new JTextField(10); + } else { + startTimeTextField = new JTextField("" + clock.getStartTime(), 10); + } + constraints = new GridBagConstraints(1, 3, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(5, 10, 15, 10), 0, 0); + gridBag.setConstraints(startTimeTextField, constraints); + attributesBoxPanel.add(startTimeTextField); + + listStartTimeString = new String[4]; + listStartTimeString[0] = "s"; + listStartTimeString[1] = "ms"; + listStartTimeString[2] = "\u03BCs"; + listStartTimeString[3] = "ns"; + startTimeComboBoxString = new JComboBox<String>(listStartTimeString); + if (clock.getUnit().equals("") || clock.getUnit().equals("s")) { + startTimeComboBoxString.setSelectedIndex(0); + } else if (clock.getUnit().equals("ms")) { + startTimeComboBoxString.setSelectedIndex(1); + } else if (clock.getUnit().equals("\u03BCs")) { + startTimeComboBoxString.setSelectedIndex(2); + } else if (clock.getUnit().equals("ns")) { + startTimeComboBoxString.setSelectedIndex(3); + } + startTimeComboBoxString.addActionListener(this); + constraints = new GridBagConstraints(2, 3, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(5, 10, 15, 10), 0, 0); + gridBag.setConstraints(startTimeComboBoxString, constraints); + attributesBoxPanel.add(startTimeComboBoxString); + + + // + JLabel posFirstLabel = new JLabel("PosFirst Tm : "); + constraints = new GridBagConstraints(0, 4, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(5, 10, 15, 10), 0, 0); + gridBag.setConstraints(posFirstLabel, constraints); + attributesBoxPanel.add(posFirstLabel); + + if (clock.getPosFirst() == false) { + posFirstTextField = new JTextField(10); + } else { + posFirstTextField = new JTextField("" + clock.getPosFirst(), 10); + } + constraints = new GridBagConstraints(1, 4, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(5, 10, 15, 10), 0, 0); + gridBag.setConstraints(posFirstTextField, constraints); + attributesBoxPanel.add(posFirstTextField); + + listPosFirstString = new String[2]; + listPosFirstString[0] = "no"; + listPosFirstString[1] = "yes"; + + posFirstComboBoxString = new JComboBox<String>(listPosFirstString); + if (clock.getUnit().equals("") || clock.getUnit().equals("no")) { + posFirstComboBoxString.setSelectedIndex(0); + } else if (clock.getUnit().equals("yes")) { + posFirstComboBoxString.setSelectedIndex(1); + } + posFirstComboBoxString.addActionListener(this); + constraints = new GridBagConstraints(2, 4, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(5, 10, 15, 10), 0, 0); + gridBag.setConstraints(posFirstComboBoxString, constraints); + attributesBoxPanel.add(posFirstComboBoxString); + // + // + + + attributesBox.add(attributesBoxPanel); + attributesMainPanel.add(attributesBox, BorderLayout.NORTH); + // --- Parameters ---// + /* parametersMainPanel.setLayout(new BorderLayout()); + + Box parametersBox = Box.createVerticalBox(); + parametersBox.setBorder(BorderFactory.createTitledBorder("Setting TDF clock parameters")); + + JPanel clockPanel = new JPanel(new GridLayout(3, 1)); + + // Struct + JPanel structPanel = new JPanel(); + structPanel.setFont(new Font("Helvetica", Font.PLAIN, 14)); + GridBagLayout gridBagParameter = new GridBagLayout(); + GridBagConstraints constraintParameter = new GridBagConstraints(); + structPanel.setLayout(gridBagParameter); + TitledBorder border = new TitledBorder("Struct :"); + border.setTitleJustification(TitledBorder.CENTER); + border.setTitlePosition(TitledBorder.TOP); + structPanel.setBorder(border); + + JLabel nameParameterLabel = new JLabel("identifier"); + constraintParameter = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(nameParameterLabel, constraintParameter); + structPanel.add(nameParameterLabel); + + nameStructTextField = new JTextField(); + constraintParameter = new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(nameStructTextField, constraintParameter); + structPanel.add(nameStructTextField); + + JLabel egalLabel = new JLabel("="); + constraintParameter = new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(egalLabel, constraintParameter); + structPanel.add(egalLabel); + + JLabel valueParameterLabel = new JLabel("value"); + constraintParameter = new GridBagConstraints(2, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(valueParameterLabel, constraintParameter); + structPanel.add(valueParameterLabel); + + valueStructTextField = new JTextField(); + constraintParameter = new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(valueStructTextField, constraintParameter); + structPanel.add(valueStructTextField); + + JLabel pointsLabel = new JLabel(":"); + constraintParameter = new GridBagConstraints(3, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(pointsLabel, constraintParameter); + structPanel.add(pointsLabel); + + JLabel constantLabel = new JLabel("const"); + constraintParameter = new GridBagConstraints(4, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(constantLabel, constraintParameter); + structPanel.add(constantLabel); + + constantStructRadioButton = new JRadioButton(); + constantStructRadioButton.setActionCommand("Const"); + constantStructRadioButton.setSelected(false); + constantStructRadioButton.addActionListener(this); + constraintParameter = new GridBagConstraints(4, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(constantStructRadioButton, constraintParameter); + structPanel.add(constantStructRadioButton); + + JLabel typeParameterLabel = new JLabel("type"); + constraintParameter = new GridBagConstraints(5, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(typeParameterLabel, constraintParameter); + structPanel.add(typeParameterLabel); + + listTypeStructString = new String[6]; + listTypeStructString[0] = "bool"; + listTypeStructString[1] = "double"; + listTypeStructString[2] = "float"; + listTypeStructString[3] = "int"; + listTypeStructString[4] = "long"; + listTypeStructString[5] = "short"; + typeStructComboBoxString = new JComboBox<String>(listTypeStructString); + typeStructComboBoxString.setSelectedIndex(0); + typeStructComboBoxString.addActionListener(this); + constraintParameter = new GridBagConstraints(5, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(typeStructComboBoxString, constraintParameter); + structPanel.add(typeStructComboBoxString); + + JButton addModifyButton = new JButton("Add / Modify parameter"); + addModifyButton.setActionCommand("Add_Modify_Struct"); + addModifyButton.addActionListener(this); + constraintParameter = new GridBagConstraints(0, 2, 6, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(addModifyButton, constraintParameter); + structPanel.add(addModifyButton); + + clockPanel.add(structPanel); + + // Template + JPanel templatePanel = new JPanel(); + templatePanel.setFont(new Font("Helvetica", Font.PLAIN, 14)); + GridBagLayout templateGridBag = new GridBagLayout(); + GridBagConstraints templateConstraint = new GridBagConstraints(); + templatePanel.setLayout(templateGridBag); + TitledBorder templateBorder = new TitledBorder("Template :"); + templateBorder.setTitleJustification(TitledBorder.CENTER); + templateBorder.setTitlePosition(TitledBorder.TOP); + templatePanel.setBorder(templateBorder); + + JLabel nameTemplateLabel = new JLabel("identifier"); + templateConstraint = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + templateGridBag.setConstraints(nameTemplateLabel, templateConstraint); + templatePanel.add(nameTemplateLabel); + + nameTemplateTextField = new JTextField(clock.getNameTemplate()); + templateConstraint = new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + templateGridBag.setConstraints(nameTemplateTextField, templateConstraint); + templatePanel.add(nameTemplateTextField); + + //CHANGES + JLabel egalTemplateLabel = new JLabel("="); + templateConstraint = new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + templateGridBag.setConstraints(egalTemplateLabel, templateConstraint); + templatePanel.add(egalTemplateLabel); + + JLabel valueTemplateLabel = new JLabel("value"); + templateConstraint = new GridBagConstraints(2, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + templateGridBag.setConstraints(valueTemplateLabel, templateConstraint); + templatePanel.add(valueTemplateLabel); + + valueTemplateTextField = new JTextField(clock.getValueTemplate()); + templateConstraint = new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + templateGridBag.setConstraints(valueTemplateTextField, templateConstraint); + templatePanel.add(valueTemplateTextField); + //CHANGES + + JLabel pointsTemplateLabel = new JLabel(":"); + templateConstraint = new GridBagConstraints(3, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + templateGridBag.setConstraints(pointsTemplateLabel, templateConstraint); + templatePanel.add(pointsTemplateLabel); + + JLabel typeTemplateLabel = new JLabel("type"); + templateConstraint = new GridBagConstraints(4, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + templateGridBag.setConstraints(typeTemplateLabel, templateConstraint); + templatePanel.add(typeTemplateLabel); + + listTypeTemplateString = new String[1]; + listTypeTemplateString[0] = "int"; + typeTemplateComboBoxString = new JComboBox<String>(listTypeTemplateString); + if (clock.getTypeTemplate().equals("int") || clock.getTypeTemplate().equals("")) { + typeTemplateComboBoxString.setSelectedIndex(0); + } + typeTemplateComboBoxString.addActionListener(this); + templateConstraint = new GridBagConstraints(4, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + templateGridBag.setConstraints(typeTemplateComboBoxString, templateConstraint); + templatePanel.add(typeTemplateComboBoxString); + + JButton OKButton = new JButton("OK"); + OKButton.setActionCommand("OK"); + OKButton.addActionListener(this); + templateConstraint = new GridBagConstraints(0, 2, 3, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + templateGridBag.setConstraints(OKButton, templateConstraint); + templatePanel.add(OKButton); + + clockPanel.add(templatePanel); + + // Typedef + JPanel typedefPanel = new JPanel(); + typedefPanel.setFont(new Font("Helvetica", Font.PLAIN, 14)); + GridBagLayout typedefGridBag = new GridBagLayout(); + GridBagConstraints typedefConstraint = new GridBagConstraints(); + typedefPanel.setLayout(typedefGridBag); + TitledBorder typedefBorder = new TitledBorder("Typedef :"); + typedefBorder.setTitleJustification(TitledBorder.CENTER); + typedefBorder.setTitlePosition(TitledBorder.TOP); + typedefPanel.setBorder(typedefBorder); + + JLabel nameTypedefLabel = new JLabel("identifier"); + typedefConstraint = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + typedefGridBag.setConstraints(nameTypedefLabel, typedefConstraint); + typedefPanel.add(nameTypedefLabel); + + nameTypedefTextField = new JTextField(); + if (clock.getListTypedef().isEmpty()) { + nameTypedefTextField.setEditable(false); + } else { + nameTypedefTextField.setEditable(true); + } + typedefConstraint = new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + typedefGridBag.setConstraints(nameTypedefTextField, typedefConstraint); + typedefPanel.add(nameTypedefTextField); + + JLabel pointsTypedefLabel = new JLabel(":"); + typedefConstraint = new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + typedefGridBag.setConstraints(pointsTypedefLabel, typedefConstraint); + typedefPanel.add(pointsTypedefLabel); + + JLabel typeTypedefLabel = new JLabel("type"); + typedefConstraint = new GridBagConstraints(2, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + typedefGridBag.setConstraints(typeTypedefLabel, typedefConstraint); + typedefPanel.add(typeTypedefLabel); + + listTypeTypedefString = new String[1]; + listTypeTypedefString[0] = "sc_dt::sc_int"; + typeTypedefComboBoxString = new JComboBox<String>(listTypeTypedefString); + typeTypedefComboBoxString.setSelectedIndex(0); + if (clock.getListTypedef().isEmpty()) { + typeTypedefComboBoxString.setEnabled(false); + } else { + typeTypedefComboBoxString.setEnabled(true); + } + typeTypedefComboBoxString.addActionListener(this); + typedefConstraint = new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + typedefGridBag.setConstraints(typeTypedefComboBoxString, typedefConstraint); + typedefPanel.add(typeTypedefComboBoxString); + + addModifyTypedefButton = new JButton("Add / Modify typedef"); + addModifyTypedefButton.setActionCommand("Add_Modify_Typedef"); + addModifyTypedefButton.addActionListener(this); + if (clock.getListTypedef().isEmpty()) { + addModifyTypedefButton.setEnabled(false); + } else { + addModifyTypedefButton.setEnabled(true); + } + typedefConstraint = new GridBagConstraints(0, 2, 3, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + typedefGridBag.setConstraints(addModifyTypedefButton, typedefConstraint); + typedefPanel.add(addModifyTypedefButton); + + clockPanel.add(typedefPanel); + + parametersBox.add(clockPanel); + parametersMainPanel.add(parametersBox, BorderLayout.WEST); + + Box managingParametersBox = Box.createVerticalBox(); + + JPanel managingParameterBoxPanel = new JPanel(new GridLayout(3, 1)); + managingParameterBoxPanel.setFont(new Font("Helvetica", Font.PLAIN, 14)); + + JPanel listStructPanel = new JPanel(); + TitledBorder listStructBorder = new TitledBorder("Managing struct :"); + listStructBorder.setTitleJustification(TitledBorder.CENTER); + listStructBorder.setTitlePosition(TitledBorder.TOP); + listStructPanel.setBorder(listStructBorder); + + structListModel = clock.getListStruct(); + structList = new JList<String>(structListModel); + structList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + structList.setLayoutOrientation(JList.VERTICAL); + structList.setSelectedIndex(-1); + structList.setVisibleRowCount(5); + structList.addListSelectionListener(this); + JScrollPane scrollPane = new JScrollPane(structList); + scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + scrollPane.setPreferredSize(new Dimension(300, 100)); + listStructPanel.add(scrollPane); + managingParameterBoxPanel.add(listStructPanel); + + JPanel listTypedefPanel = new JPanel(); + TitledBorder listTypedefBorder = new TitledBorder("Managing typedef :"); + listTypedefBorder.setTitleJustification(TitledBorder.CENTER); + listTypedefBorder.setTitlePosition(TitledBorder.TOP); + listTypedefPanel.setBorder(listTypedefBorder); + + typedefListModel = clock.getListTypedef(); + typedefList = new JList<String>(typedefListModel); + typedefList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + typedefList.setLayoutOrientation(JList.VERTICAL); + typedefList.setSelectedIndex(-1); + typedefList.setVisibleRowCount(5); + typedefList.addListSelectionListener(this); + JScrollPane typedefScrollPane = new JScrollPane(typedefList); + typedefScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + typedefScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + typedefScrollPane.setPreferredSize(new Dimension(300, 100)); + listTypedefPanel.add(typedefScrollPane); + managingParameterBoxPanel.add(listTypedefPanel); + + GridBagLayout buttonGridBag = new GridBagLayout(); + GridBagConstraints buttonconstraints = new GridBagConstraints(); + JPanel buttonPanel = new JPanel(); + buttonPanel.setFont(new Font("Helvetica", Font.PLAIN, 14)); + buttonPanel.setLayout(buttonGridBag); + + upButton = new JButton("Up"); + upButton.setActionCommand("Up"); + upButton.setEnabled(false); + upButton.addActionListener(this); + buttonconstraints = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + buttonGridBag.setConstraints(upButton, buttonconstraints); + buttonPanel.add(upButton); + + downButton = new JButton("Down"); + downButton.setActionCommand("Down"); + downButton.setEnabled(false); + downButton.addActionListener(this); + buttonconstraints = new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + buttonGridBag.setConstraints(downButton, buttonconstraints); + buttonPanel.add(downButton); + + removeButton = new JButton("Remove parameter"); + removeButton.setActionCommand("Remove"); + removeButton.setEnabled(false); + removeButton.addActionListener(this); + buttonconstraints = new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 15, 10), 0, 0); + buttonGridBag.setConstraints(removeButton, buttonconstraints); + buttonPanel.add(removeButton); + + managingParameterBoxPanel.add(buttonPanel); + + managingParametersBox.add(managingParameterBoxPanel); + parametersMainPanel.add(managingParametersBox, BorderLayout.EAST); + + // --- ProcessCode ---// + processMainPanel.setLayout(new BorderLayout()); + + Box codeBox = Box.createVerticalBox(); + codeBox.setBorder(BorderFactory.createTitledBorder("Behavior function of TDF clock")); + + JPanel codeBoxPanel = new JPanel(new BorderLayout()); + + StringBuffer stringbuf = encode(clock.getProcessCode()); + String beginString = stringbuf.toString(); + finalString = beginString.replaceAll("\t}", "}"); + + processCodeTextArea = new JTextArea(finalString); + processCodeTextArea.setSize(100, 100); + processCodeTextArea.setTabSize(2); + + processCodeTextArea.setFont(new Font("Arial", Font.PLAIN, 16)); + processCodeTextArea.setLineWrap(true); + processCodeTextArea.setWrapStyleWord(true); + + JScrollPane processScrollPane = new JScrollPane(processCodeTextArea); + processScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + processScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + processScrollPane.setPreferredSize(new Dimension(200, 300)); + processScrollPane.setBorder(new EmptyBorder(15, 10, 15, 10)); + + codeBoxPanel.add(processScrollPane, BorderLayout.SOUTH); + + codeBox.add(codeBoxPanel); + processMainPanel.add(codeBox, BorderLayout.PAGE_START); + + // --- ContructorCode --- // + contructorMainPanel.setLayout(new BorderLayout()); + + Box codeBox2 = Box.createVerticalBox(); + codeBox2.setBorder(BorderFactory.createTitledBorder("Contructor code of TDF clock")); + + JPanel codeBoxPanel2 = new JPanel(new BorderLayout()); + + //StringBuffer stringbuf2 = encode(clock.getConstructorCode()); + //String beginString2 = stringbuf2.toString(); + //finalString = beginString2.replaceAll("\t}", "}"); + finalString = clock.getConstructorCode(); + + constructorCodeTextArea = new JTextArea(finalString); + constructorCodeTextArea.setSize(100, 100); + constructorCodeTextArea.setTabSize(2); + + constructorCodeTextArea.setFont(new Font("Arial", Font.PLAIN, 16)); + constructorCodeTextArea.setLineWrap(true); + constructorCodeTextArea.setWrapStyleWord(true); + + JScrollPane constructorScrollPane = new JScrollPane(constructorCodeTextArea); + constructorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + constructorScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + constructorScrollPane.setPreferredSize(new Dimension(200, 300)); + constructorScrollPane.setBorder(new EmptyBorder(15, 10, 15, 10)); + + codeBoxPanel2.add(constructorScrollPane, BorderLayout.SOUTH); + + codeBox2.add(codeBoxPanel2); + contructorMainPanel.add(codeBox2, BorderLayout.PAGE_START); + */ + // --- Button --- // + 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) { + clock.setName(nameTextField.getText()); + // clock.setFrequency(frequencyTextField.getText()); + //clock.setDutyCycle(dutyCycleTextField.getText()); + //clock.setStartTime(startTimeTextField.getText()); + clock.setPosFirst((boolean)posFirstComboBoxString.getSelectedItem()); //ToDo boolean + clock.setUnit((String) unitComboBoxString.getSelectedItem()); + + + if ("Save_Close".equals(e.getActionCommand())) { + clock.setValue(new String(nameTextField.getText())); + + if (!(frequencyTextField.getText().isEmpty())) { + Boolean frequencyValueInteger = false; + try { + Double.parseDouble(frequencyTextField.getText()); + } catch (NumberFormatException e1) { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "Frequency is not a Double", "Warning !", + JOptionPane.WARNING_MESSAGE); + frequencyValueInteger = true; + } + if (frequencyValueInteger == false) { + clock.setFrequency(Double.parseDouble(frequencyTextField.getText())); + clock.setUnit((String) frequencyComboBoxString.getSelectedItem()); + } + } else { + clock.setFrequency(-1); + clock.setUnit(""); + } + + if (!(dutyCycleTextField.getText().isEmpty())) { + Boolean dutyCycleValueInteger = false; + try { + Double.parseDouble(dutyCycleTextField.getText()); + } catch (NumberFormatException e1) { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "DutyCycle is not a Double", "Warning !", + JOptionPane.WARNING_MESSAGE); + dutyCycleValueInteger = true; + } + if (dutyCycleValueInteger == false) { + clock.setDutyCycle(Double.parseDouble(dutyCycleTextField.getText())); + clock.setUnit((String) dutyCycleComboBoxString.getSelectedItem()); + } + } else { + clock.setDutyCycle(-1); + clock.setUnit(""); + } + + if (!(startTimeTextField.getText().isEmpty())) { + Boolean startTimeValueInteger = false; + try { + Double.parseDouble(startTimeTextField.getText()); + } catch (NumberFormatException e1) { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "StartTime is not a Double", "Warning !", + JOptionPane.WARNING_MESSAGE); + startTimeValueInteger = true; + } + if (startTimeValueInteger == false) { + clock.setStartTime(Double.parseDouble(startTimeTextField.getText())); + clock.setUnit((String) startTimeComboBoxString.getSelectedItem()); + } + } else { + clock.setStartTime(-1); + clock.setUnit(""); + } + + //clock.setProcessCode(processCodeTextArea.getText()); + // clock.setConstructorCode(constructorCodeTextArea.getText()); + clock.setListStruct(structListModel); + clock.setNameTemplate(nameTemplateTextField.getText()); + clock.setTypeTemplate((String) typeTemplateComboBoxString.getSelectedItem()); + clock.setValueTemplate(valueTemplateTextField.getText()); + clock.setListTypedef(typedefListModel); + + this.dispose(); + } + + + /* if ("Save_Close".equals(e.getActionCommand())) { + clock.setValue(new String(nameTextField.getText())); + this.dispose(); + }* + + if ("Cancel".equals(e.getActionCommand())) { + this.dispose(); + }*/ + } +} diff --git a/src/main/java/ui/window/JDialogSysCAMSPortClock.java b/src/main/java/ui/window/JDialogSysCAMSPortClock.java index 2ce2b4af6ad50a2cb260b96d04e457d1e2a1ebd1..fe5e26c3ee159b6cb71a8804bc3a0d904c807fbd 100644 --- a/src/main/java/ui/window/JDialogSysCAMSPortClock.java +++ b/src/main/java/ui/window/JDialogSysCAMSPortClock.java @@ -111,7 +111,7 @@ public class JDialogSysCAMSPortClock extends JDialog implements ActionListener { new Insets(15, 10, 5, 10), 0, 0); gridBag.setConstraints(nameTextField, constraints); boxPanel.add(nameTextField); - + box.add(boxPanel); // -- Button -- //