diff --git a/src/main/java/syscamstranslator/SysCAMSSpecification.java b/src/main/java/syscamstranslator/SysCAMSSpecification.java index 6003750dc6ba7a9c132d9e1d0970fb0b86967112..21aec4b4b470ce2301c24881416e6bdb1e689bb6 100644 --- a/src/main/java/syscamstranslator/SysCAMSSpecification.java +++ b/src/main/java/syscamstranslator/SysCAMSSpecification.java @@ -91,7 +91,6 @@ public class SysCAMSSpecification{ for (SysCAMSTComponent blockGPIO2VCI : components) { if (blockGPIO2VCI instanceof SysCAMSTBlockGPIO2VCI) { blocksGPIO2VCI.add((SysCAMSTBlockGPIO2VCI) blockGPIO2VCI); - //System.out.println("@@@@@GPIO block found in spec"); } } return blocksGPIO2VCI; @@ -136,6 +135,17 @@ public class SysCAMSSpecification{ return portsDE; } + public LinkedList<SysCAMSTClock> getAllClock(){ + LinkedList<SysCAMSTClock> clocks = new LinkedList<SysCAMSTClock>(); + for (SysCAMSTComponent clock : components) { + if (clock instanceof SysCAMSTClock) { + clocks.add((SysCAMSTClock) clock); + } + } + return clocks; + } + + public LinkedList<SysCAMSTConnector> getAllConnectorCluster(){ LinkedList<SysCAMSTConnector> cons = new LinkedList<SysCAMSTConnector>(); for (SysCAMSTConnector con : connectors) { @@ -275,4 +285,8 @@ public class SysCAMSSpecification{ public int getNbConnectorCluster(){ return (getAllConnectorCluster()).size(); } + + /* public int getNbClocks(){ + return (getAllClocks()).size(); + }*/ } diff --git a/src/main/java/syscamstranslator/SysCAMSTClock.java b/src/main/java/syscamstranslator/SysCAMSTClock.java new file mode 100644 index 0000000000000000000000000000000000000000..369705e19b1ed03d88736804d3f9f209b56e0e07 --- /dev/null +++ b/src/main/java/syscamstranslator/SysCAMSTClock.java @@ -0,0 +1,120 @@ +/* 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 java.util.LinkedList; + +import javax.swing.DefaultListModel; + +/** + * Class SysCAMSTClock +*/ + +public class SysCAMSTClock extends SysCAMSTComponent{ + private String name; + private String frequency; + private String unit; + private String dutyCycle; + private String startTime; + private String posFirst; + + public SysCAMSTClock(String _name, String _frequency, String _unit, String _dutyCycle, String _startTime, String _posFirst) { + + name = _name; + frequency = _frequency; + unit = _unit; + dutyCycle = _dutyCycle; + startTime = _startTime; + posFirst = _posFirst; + } + + + public String getName() { + return name; + } + + public String getFrequency() { + return frequency; + } + + public String getUnit() { + return unit; + } + + public String getDutyCycle() { + return dutyCycle; + } + + public String getStartTime() { + return startTime; + } + + + public String getPosFirst() { + return posFirst; + } + + + public void setName(String _name) { + name = _name; + } + + public void setFrequency(String _frequency) { + frequency = _frequency; + } + + public void setUnit(String _unit) { + unit = _unit; + } + + public void setDutyCycle(String _dutyCycle) { + dutyCycle = _dutyCycle; + } + + + public void setStartTime(String _startTime) { + startTime = _startTime; + } + + + public void setPosFirst(String _posFirst) { + posFirst = _posFirst; + } + +} diff --git a/src/main/java/syscamstranslator/SysCAMSTCluster.java b/src/main/java/syscamstranslator/SysCAMSTCluster.java index 6d0558d75bccc495572d13fe66cbf2bf6fc656b6..17b8059778c918b3b4ec2e8c3b92869f70639d08 100644 --- a/src/main/java/syscamstranslator/SysCAMSTCluster.java +++ b/src/main/java/syscamstranslator/SysCAMSTCluster.java @@ -53,11 +53,13 @@ public class SysCAMSTCluster extends SysCAMSTComponent { private LinkedList<SysCAMSTBlockTDF> blockTDF; private LinkedList<SysCAMSTBlockDE> blockDE; + private LinkedList<SysCAMSTClock> clock; public SysCAMSTCluster(String _clusterName) { clusterName = _clusterName; blockTDF = new LinkedList<SysCAMSTBlockTDF>(); blockDE = new LinkedList<SysCAMSTBlockDE>(); + clock = new LinkedList<SysCAMSTClock>(); } public String getClusterName() { @@ -79,4 +81,13 @@ public class SysCAMSTCluster extends SysCAMSTComponent { public void addBlockDE(SysCAMSTBlockDE _blockDE){ blockDE.add(_blockDE); } -} \ No newline at end of file + + public LinkedList<SysCAMSTClock> getClock(){ + return clock; + } + + public void addBlockDE(SysCAMSTClock _clock){ + clock.add(_clock); + } + +} diff --git a/src/main/java/syscamstranslator/toSysCAMSCluster/ClusterCode.java b/src/main/java/syscamstranslator/toSysCAMSCluster/ClusterCode.java index 6af907a99a9b984efcfdd5ce4de463192ce10d30..d45c3e4a1731850f1b5c122c847975a60f7af262 100644 --- a/src/main/java/syscamstranslator/toSysCAMSCluster/ClusterCode.java +++ b/src/main/java/syscamstranslator/toSysCAMSCluster/ClusterCode.java @@ -69,7 +69,9 @@ public class ClusterCode { 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; @@ -146,7 +148,15 @@ public class ClusterCode { } 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) { diff --git a/src/main/java/syscamstranslator/toSysCAMSCluster/TopCellGeneratorCluster.java b/src/main/java/syscamstranslator/toSysCAMSCluster/TopCellGeneratorCluster.java index 77f164c4a1c6b17fc1d7a08e4165f55005d6d600..b19109685986197382b2547516727067d684d040 100644 --- a/src/main/java/syscamstranslator/toSysCAMSCluster/TopCellGeneratorCluster.java +++ b/src/main/java/syscamstranslator/toSysCAMSCluster/TopCellGeneratorCluster.java @@ -139,7 +139,7 @@ public class TopCellGeneratorCluster { System.err.println(path + GENERATED_PATH2 + t.getName() + "_tdf.h"); System.err.println(path + t.getName() + "_tdf.h"); if(standalone==true){ - //System.out.println("@@@ TDF Cluster standalone"); + fw = new FileWriter(path + "/" + t.getName() + "_tdf.h"); } @@ -147,8 +147,7 @@ public class TopCellGeneratorCluster { fw = new FileWriter(path + GENERATED_PATH2 + "/" + t.getName() + "_tdf.h"); headerTDF = HeaderCluster.getPrimitiveHeaderTDF(t); fw.write(headerTDF); - codeTDF = PrimitiveCodeCluster.getPrimitiveCodeTDF(t); - //if(standalone==false) + codeTDF = PrimitiveCodeCluster.getPrimitiveCodeTDF(t); codeTDF = codeTDF + "#endif"+ CR; fw.write(codeTDF); fw.close(); @@ -164,15 +163,14 @@ public class TopCellGeneratorCluster { if(standalone==true) { - //System.out.println("@@@ DE Cluster standalone"); + fw = new FileWriter(path +"/" + t.getName() + "_tdf.h");} else fw = new FileWriter(path + GENERATED_PATH2 + "/" + t.getName() + "_tdf.h"); headerDE = HeaderCluster.getPrimitiveHeaderDE(t); fw.write(headerDE); - codeDE = PrimitiveCodeCluster.getPrimitiveCodeDE(t); - //if(standalone==false) + codeDE = PrimitiveCodeCluster.getPrimitiveCodeDE(t); codeDE = codeDE + "#endif "+ CR; fw.write(codeDE); fw.close(); diff --git a/src/main/java/ui/TGComponentManager.java b/src/main/java/ui/TGComponentManager.java index a9b2441d42717ddb0178960d7e1ad160d4ba0cc6..9c8c92ebb4fadc46e057113fa7be907fafc5dac2 100644 --- a/src/main/java/ui/TGComponentManager.java +++ b/src/main/java/ui/TGComponentManager.java @@ -347,7 +347,7 @@ public class TGComponentManager { public static final int CAMS_PORT_CONVERTER = 1606; public static final int CAMS_CLUSTER = 1607; public static final int CAMS_BLOCK_GPIO2VCI = 1608; - + public static final int CAMS_CLOCK = 5721; // ELN public static final int ELN_CONNECTOR = 1610; public static final int ELN_RESISTOR = 1611; @@ -559,12 +559,12 @@ public class TGComponentManager { public static final int CONNECTOR = 1; - public static LinkedList<ADDConnector> addconnectors = new LinkedList<ADDConnector>(); //DG 21.02. + public static LinkedList<ADDConnector> addconnectors = new LinkedList<ADDConnector>(); public static LinkedList<ADDConnector> getAllADDConnectors() { return addconnectors; - }//DG 21.02. + } public final static TGComponent addComponent(int x, int y, int id, TDiagramPanel tdp) { TGComponent tgc = null; @@ -1311,6 +1311,9 @@ public class TGComponentManager { case CAMS_BLOCK_GPIO2VCI: tgc = new SysCAMSBlockGPIO2VCI(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); break; + case CAMS_CLOCK: + tgc = new SysCAMSClock(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); + break; // ELN case ELN_RESISTOR: tgc = new ELNComponentResistor(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); @@ -1790,7 +1793,8 @@ public class TGComponentManager { return CAMS_CLUSTER; } else if (tgc instanceof SysCAMSBlockGPIO2VCI) { return CAMS_BLOCK_GPIO2VCI; - + } else if (tgc instanceof SysCAMSClock) { + return CAMS_CLOCK; // ELN } else if (tgc instanceof ELNConnector) { return ELN_CONNECTOR; diff --git a/src/main/java/ui/TGUIAction.java b/src/main/java/ui/TGUIAction.java index dc580d18e71d991f867a965d10b0cdbdb2dc73df..0bb0f2e8941f8c95be89dcdf5169407ad4f410bd 100644 --- a/src/main/java/ui/TGUIAction.java +++ b/src/main/java/ui/TGUIAction.java @@ -282,6 +282,7 @@ public class TGUIAction extends AbstractAction { public static final int CAMS_CLUSTER = 480; public static final int CAMS_GENCODE = 482; public static final int CAMS_BLOCK_GPIO2VCI = 497; + public static final int CAMS_CLOCK = 520; // ELN public static final int ELN_EDIT = 483; @@ -674,7 +675,7 @@ public class TGUIAction extends AbstractAction { public static final int MOVE_ENABLED = 463; public static final int FIRST_DIAGRAM = 464; - public static final int NB_ACTION = 520; + public static final int NB_ACTION = 521; private static final TAction [] actions = new TAction[NB_ACTION]; @@ -1188,7 +1189,7 @@ public class TGUIAction extends AbstractAction { actions[CAMS_CLUSTER] = new TAction("C-AMS-cluster", "Add a cluster", IconManager.imgic8003, IconManager.imgic8003, "Cluster", "Add a cluster to the currently opened SystemC-AMS Diagram", 0); actions[CAMS_GENCODE] = new TAction("C-AMS-gencode", "SystemC-AMS code generation",IconManager.imgic94, IconManager.imgic94, "Generate SystemC-AMS code", "SystemC-AMS diagram without check syntax", 0); actions[CAMS_BLOCK_GPIO2VCI] = new TAction("C-AMS-block-GPIO2VCI", "Add a block GPIO2VCI",IconManager.imgic8006, IconManager.imgic8006, "GPIO2VCI block", "Add a GPIO2VCI block to the currently opened SystemC-AMS Diagram", 0); - +actions[CAMS_CLOCK] = new TAction("C-AMS-Clock", "Clock", IconManager.imgic999, IconManager.imgic999, "Clock", "Add a clock to the currently opened SystemC-AMS diagram", 0); // ELN actions[ELN_EDIT] = new TAction("add-action-eln", "Action state", IconManager.imgic100, IconManager.imgic101, "Action state", "Add an action state to the currently opened ELN diagram", 0); actions[ELN_CONNECTOR] = new TAction("eln-connector", "Add a connection", IconManager.imgic202, IconManager.imgic202, "Connector", "Connects two block of the currently opened ELN Diagram", 0); diff --git a/src/main/java/ui/syscams/SysCAMSClock.java b/src/main/java/ui/syscams/SysCAMSClock.java new file mode 100644 index 0000000000000000000000000000000000000000..0183e84406b4369d940012120451d0b8e2046eaf --- /dev/null +++ b/src/main/java/ui/syscams/SysCAMSClock.java @@ -0,0 +1,627 @@ +/* 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.syscams; + +import myutil.GraphicLib; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import ui.*; +import ui.util.IconManager; +import ui.window.JDialogSysCAMSClock; +import javax.swing.*; + +import java.awt.*; +import java.util.ArrayList; +import java.util.LinkedList; + +/** + * Class SysCAMSClock + * Primitive Component. To be used in SystemC-AMS diagrams + * Creation: 13/05/2018 + * @version 1.0 04/06/2019 + * @author Daniela GENIUS + */ + +public class SysCAMSClock extends TGCScalableWithInternalComponent implements SwallowTGComponent, SwallowedTGComponent { + private String nameFn; + private String code; + private DefaultListModel<String> listStruct; + private String nameTemplate; + private String unitTemplate; + private String frequencyTemplate; + private String dutyCycleTemplate; + private String startTimeTemplate; + private String posFirstTemplate; + private DefaultListModel<String> listTypedef; + + private int maxFontSize = 14; + private int minFontSize = 4; + private int currentFontSize = -1; + private Color myColor; + + private int textX = 15; + private double dtextX = 0.0; + + public String oldValue; + + public SysCAMSClock(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) { + super(_x, _y, _minX, _maxX, _minY, _maxY, _pos, _father, _tdp); + + initScaling(200, 150); + + oldScaleFactor = tdp.getZoom(); + dtextX = textX * oldScaleFactor; + textX = (int)dtextX; + dtextX = dtextX - textX; + + minWidth = 1; + minHeight = 1; + + nbConnectingPoint = 0; + + addTGConnectingPointsComment(); + + nbInternalTGComponent = 0; + + moveable = true; + multieditable = true; + editable = true; + removable = true; + userResizable = true; + + value = tdp.findSysCAMSPrimitiveComponentName("Clock"); + name = "Primitive component - Clock"; + +// setPeriod(-1); +// setTime(""); + setNameFn(""); + setCode(""); + setListStruct(new DefaultListModel<String>()); + setNameTemplate(""); + // setTypeTemplate(""); + //setValueTemplate(""); + setListTypedef(new DefaultListModel<String>()); + + myImageIcon = IconManager.imgic1202; + + actionOnAdd(); + } + + public void internalDrawing(Graphics g) { + int w; + Font f = g.getFont(); + Font fold = f; + + if (myColor == null) { + myColor = Color.white; + } + + if (this.rescaled && !this.tdp.isScaled()) { + this.rescaled = false; + int maxCurrentFontSize = Math.max(0, Math.min(this.height, (int) (this.maxFontSize * this.tdp.getZoom()))); + f = f.deriveFont((float) maxCurrentFontSize); + + while (maxCurrentFontSize > (this.minFontSize * this.tdp.getZoom() - 1)) { + if (g.getFontMetrics().stringWidth(value) < (width - (2 * textX))) { + break; + } + maxCurrentFontSize--; + f = f.deriveFont((float) maxCurrentFontSize); + } + + if (this.currentFontSize < this.minFontSize * this.tdp.getZoom()) { + maxCurrentFontSize++; + f = f.deriveFont((float) maxCurrentFontSize); + } + g.setFont(f); + this.currentFontSize = maxCurrentFontSize; + } else { + f = f.deriveFont(this.currentFontSize); + } + + Color c = g.getColor(); + g.drawRect(x, y, width, height); + if ((width > 2) && (height > 2)) { + g.setColor(myColor); + g.fillRect(x+1, y+1, width-1, height-1); + g.setColor(c); + } + + int attributeFontSize = this.currentFontSize * 5 / 6; + g.setFont(f.deriveFont((float) attributeFontSize)); + g.setFont(f); + w = g.getFontMetrics().stringWidth(value); + if (w > (width - 2 * textX)) { + g.setFont(f.deriveFont(Font.BOLD)); + g.drawString(value, x + textX + 1, y + currentFontSize + textX); + g.setFont(f.deriveFont(Font.PLAIN)); +// if (this.getPeriod() != -1) { +// String s = "Tm = " + this.getPeriod() + " " + this.getTime(); +// g.drawString(s, x + textX + 1, y + height - currentFontSize - textX); +// } + } else { + g.setFont(f.deriveFont(Font.BOLD)); + g.drawString(value, x + (width - w)/2, y + currentFontSize + textX); + g.setFont(f.deriveFont(Font.PLAIN)); +// if (this.getPeriod() != -1) { +// String s = "Tm = " + this.getPeriod() + " " + this.getTime(); +// w = g.getFontMetrics().stringWidth(s); +// g.drawString(s, x + (width - w)/2, y + height - currentFontSize - textX); +// } + } + + g.setFont(fold); + } + + public void rescale(double scaleFactor){ + dtextX = (textX + dtextX) / oldScaleFactor * scaleFactor; + textX = (int)(dtextX); + dtextX = dtextX - textX; + super.rescale(scaleFactor); + } + + public TGComponent isOnOnlyMe(int _x, int _y) { + if (GraphicLib.isInRectangle(_x, _y, x, y, width, height)) { + return this; + } + return null; + } + + public boolean editOndoubleClick(JFrame frame, int _x, int _y) { + // On the name ? + if (_y <= (y + currentFontSize + textX)) { + oldValue = value; + String s = (String)JOptionPane.showInputDialog(frame, "Name:", "Setting component name", + JOptionPane.PLAIN_MESSAGE, IconManager.imgic100, + null, + getValue()); + if ((s != null) && (s.length() > 0)) { + if (!TAttribute.isAValidId(s, false, false, false)) { + JOptionPane.showMessageDialog(frame, + "Could not change the name of the component: the new name is not a valid name", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return false; + } + if (oldValue.compareTo(s) != 0) { + if (((SysCAMSComponentTaskDiagramPanel)(tdp)).nameBlockTDFComponentInUse(oldValue, s)) { + JOptionPane.showMessageDialog(frame, + "Error: the name is already in use", + "Name modification", + JOptionPane.ERROR_MESSAGE); + return false; + } + } + setComponentName(s); + setValueWithChange(s); + rescaled = true; + return true; + + } + return false; + } + + JDialogSysCAMSClock jde = new JDialogSysCAMSClock(this); + jde.setVisible(true); + rescaled = true; + return true; + } + + public int getType() { + return TGComponentManager.CAMS_CLOCK; + } + + public void wasSwallowed() { + myColor = null; + } + + public void wasUnswallowed() { + myColor = null; + setFather(null); + TDiagramPanel tdp = getTDiagramPanel(); + setCdRectangle(tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY()); + } + + public boolean acceptSwallowedTGComponent(TGComponent tgc) { + return tgc instanceof SysCAMSClock; + } + + public boolean addSwallowedTGComponent(TGComponent tgc, int x, int y) { + if (tgc instanceof SysCAMSClock) { + tgc.setFather(this); + tgc.setDrawingZone(true); + tgc.resizeWithFather(); + addInternalComponent(tgc, 0); + return true; + } + return false; + } + + public void removeSwallowedTGComponent(TGComponent tgc) { + removeInternalComponent(tgc); + } + + public void hasBeenResized() { + rescaled = true; + for(int i=0; i<nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof SysCAMSClock) { + tgcomponent[i].resizeWithFather(); + } + } + if (getFather() != null) { + resizeWithFather(); + } + } + + public void resizeWithFather() { + if ((father != null) && (father instanceof SysCAMSCompositeComponent)) { + resizeToFatherSize(); + + setCdRectangle(0, father.getWidth() - getWidth(), 0, father.getHeight() - getHeight()); + setMoveCd(x, y); + } + } + + protected String translateExtraParam() { + StringBuffer sb = new StringBuffer("<extraparam>\n"); + sb.append("<Attribute name_function=\"" + getNameFn()); + + sb.append("\" code=\"" + encode(getCode())); + sb.append("\" listStruct=\"" + splitParameters(getListStruct())); + sb.append("\" nameTemplate=\"" + getNameTemplate()); + sb.append("\" nameTemplate=\"" + getFrequencyTemplate()); + sb.append("\" nameTemplate=\"" + getUnitTemplate()); + sb.append("\" nameTemplate=\"" + getDutyCycleTemplate()); + sb.append("\" nameTemplate=\"" + getStartTimeTemplate()); + sb.append("\" nameTemplate=\"" + getPosFirstTemplate()); + sb.append("\" listTypedef=\"" + splitParameters(getListTypedef())); + sb.append("\" />\n"); + sb.append("</extraparam>\n"); + return new String(sb); + } + + public String splitParameters(DefaultListModel<String> listStruct) { + String s = ""; + + for (int i = 0; i < listStruct.getSize(); i++) { + if (i < listStruct.getSize()-1) { + s = s + listStruct.get(i) + "|"; + } else { + s = s + listStruct.get(i); + } + } + return s; + } + + public StringBuffer encode(String data) { + StringBuffer databuf = new StringBuffer(data); + StringBuffer buffer = new StringBuffer(""); + for(int pos = 0; pos != data.length(); pos++) { + char c = databuf.charAt(pos); + switch(c) { + case '&' : + buffer.append("&"); + break; + case '\"' : + buffer.append("""); + break; + case '\'' : + buffer.append("'"); + break; + case '<' : + buffer.append("<"); + break; + case '>' : + buffer.append(">"); + break; + default : + buffer.append(databuf.charAt(pos)); + break; + } + } + return buffer; + } + + public StringBuffer decode(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 loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException{ + try { + NodeList nli; + Node n1, n2; + Element elt; + + String code, nameFn, listStruct, nameTemplate, typeTemplate, valueTemplate, listTypedef; + + for(int i=0; i<nl.getLength(); i++) { + n1 = nl.item(i); + if (n1.getNodeType() == Node.ELEMENT_NODE) { + nli = n1.getChildNodes(); + for(int j=0; j<nli.getLength(); j++) { + n2 = nli.item(j); + if (n2.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) n2; + if (elt.getTagName().equals("Attribute")) { +// period = Integer.decode(elt.getAttribute("period")).intValue(); +// time = elt.getAttribute("time"); + code = elt.getAttribute("code"); + nameFn = elt.getAttribute("name_function"); + listStruct = elt.getAttribute("listStruct"); + nameTemplate = elt.getAttribute("nameTemplate"); + typeTemplate = elt.getAttribute("typeTemplate"); + valueTemplate = elt.getAttribute("valueTemplate"); + listTypedef = elt.getAttribute("listTypedef"); +// setPeriod(period); +// setTime(time); + setNameFn(nameFn); + code = decode(code).toString(); + setCode(code); + String[] splita = listStruct.split("\\|"); + DefaultListModel<String> lista = new DefaultListModel<String>(); + for (String s : splita) { + if (!s.equals("")) { + lista.addElement(s); + } + } + setListStruct(lista); + setNameTemplate(nameTemplate); + //setTypeTemplate(typeTemplate); + //setValueTemplate(valueTemplate); + String[] splitb = listTypedef.split("\\|"); + DefaultListModel<String> listb = new DefaultListModel<String>(); + for (String s : splitb) { + if (!s.equals("")) { + listb.addElement(s); + } + } + setListTypedef(listb); + } + } + } + } + } + } catch (Exception e) { + throw new MalformedModelingException(); + } + } + + public int getCurrentFontSize() { + return currentFontSize; + } + + public java.util.List<SysCAMSPortDE> getAllDEOriginPorts() { + return getAllPorts(1, 1); + } + + public java.util.List<SysCAMSPortDE> getAllDEDestinationPorts() { + return getAllPorts(1, 0); + } + + public java.util.List<SysCAMSPortDE> getAllPorts(int _type, int _isOrigin) { + java.util.List<SysCAMSPortDE> ret = new LinkedList<SysCAMSPortDE>(); + SysCAMSPortDE port; + + for(int i=0; i<nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof SysCAMSPortDE) { + port = (SysCAMSPortDE)tgcomponent[i]; + if ((port.getPortType() == _type) && (port.getOrigin() == _isOrigin)) { + ret.add(port); + } + } + } + return ret; + } + + public java.util.List<SysCAMSPortDE> getAllInternalPortsClock() { + java.util.List<SysCAMSPortDE> list = new ArrayList<SysCAMSPortDE>(); + for(int i=0; i<nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof SysCAMSPortDE) { + list.add((SysCAMSPortDE)(tgcomponent[i])); + } + } + return list; + } + +// public int getPeriod() { +// return period; +// } +// +// public void setPeriod(int _period) { +// period = _period; +// } +// +// public String getTime() { +// return time; +// } +// +// public void setTime(String _time) { +// time = _time; +// } + + public void setNameFn(String nameFn) { + this.nameFn = nameFn; + } + + public void setCode(String _code) { + code = _code; + } + + public String getCode() { + return code; + } + + public String getNameFn() { + return nameFn; + } + + public DefaultListModel<String> getListStruct() { + return listStruct; + } + + public void setListStruct(DefaultListModel<String> _listStruct) { + listStruct = _listStruct; + } + + public String getNameTemplate() { + return nameTemplate; + } + + public String getFrequencyTemplate() { + return frequencyTemplate; + } + + public String getUnitTemplate() { + return unitTemplate; + } + + public String getDutyCycleTemplate() { + return dutyCycleTemplate; + } + + public String getStartTimeTemplate() { + return startTimeTemplate; + } + + + public String getPosFirstTemplate() { + return posFirstTemplate; + } + + public void setNameTemplate(String _nameTemplate) { + nameTemplate = _nameTemplate; + } + + + public void setStartTimeTemplate(String _startTimeTemplate) { + startTimeTemplate = _startTimeTemplate; + } + + public void setFrequencyTemplate(String _frequencyTemplate) { + frequencyTemplate = _frequencyTemplate; + } + + public void setUnitTemplate(String _unitTemplate) { + unitTemplate = _unitTemplate; + } + + public void setDutyCycleTemplate(String _dutyCycleTemplate) { + dutyCycleTemplate = _dutyCycleTemplate; + } + + public void setPosFirstTemplate(String _posFirstTemplate) { + posFirstTemplate = _posFirstTemplate; + } + + public DefaultListModel<String> getListTypedef() { + return listTypedef; + } + + public void setListTypedef(DefaultListModel<String> _listTypedef) { + listTypedef = _listTypedef; + } +} diff --git a/src/main/java/ui/util/IconManager.java b/src/main/java/ui/util/IconManager.java index 32db68db2b2ccf61140673968ebdaec6832f3c1f..3794e4bf9157665b6041bcbe8ac25841ffecb6f1 100755 --- a/src/main/java/ui/util/IconManager.java +++ b/src/main/java/ui/util/IconManager.java @@ -184,7 +184,7 @@ public class IconManager { public static ImageIcon imgic2111; //New icon created by Solange // SystemC-AMS - public static ImageIcon imgic8000, imgic8001, imgic8002, imgic8003, imgic8004, imgic8005, imgic8006; + public static ImageIcon imgic8000, imgic8001, imgic8002, imgic8003, imgic8004, imgic8005, imgic8006, imgic999; // ELN public static ImageIcon imgic8010, imgic8011, imgic8012, imgic8013, imgic8014, imgic8015, imgic8016, imgic8017, imgic8018, imgic8019, @@ -679,7 +679,7 @@ public class IconManager { private static String icon8004 = "camstdfblock.gif"; private static String icon8005 = "camsdeblock.gif"; private static String icon8006 = "camsgpio2vciblock.gif"; - + private static String icon999 = "clock.gif"; // ELN private static String icon8010 = "elnresistor.gif"; private static String icon8011 = "elncapacitor.gif"; diff --git a/src/main/java/ui/window/JDialogSysCAMSClock.java b/src/main/java/ui/window/JDialogSysCAMSClock.java new file mode 100644 index 0000000000000000000000000000000000000000..96032b4e7427d78c0483d1492c8a2c53968dda91 --- /dev/null +++ b/src/main/java/ui/window/JDialogSysCAMSClock.java @@ -0,0 +1,245 @@ +/* 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 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; + + 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 void dialog() { + JPanel mainPanel = new JPanel(new BorderLayout()); + this.add(mainPanel); + + JPanel attributesMainPanel = new JPanel(); + mainPanel.add(attributesMainPanel, BorderLayout.NORTH); + + attributesMainPanel.setLayout(new BorderLayout()); + + Box attributesBox = Box.createVerticalBox(); + attributesBox.setBorder(BorderFactory.createTitledBorder("Setting 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.getUnitTemplate().equals("") || clock.getUnitTemplate().equals("s")) { + unitComboBoxString.setSelectedIndex(0); + } else if (clock.getUnitTemplate().equals("ms")){ + unitComboBoxString.setSelectedIndex(1); + } else if (clock.getUnitTemplate().equals("\u03BCs")){ + unitComboBoxString.setSelectedIndex(2); + } else if (clock.getUnitTemplate().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.getPosFirstTemplate().equals("") || clock.getPosFirstTemplate().equals("true")) { + posFirstComboBoxString.setSelectedIndex(0); + } else if (clock.getPosFirstTemplate().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); + + 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.setNameTemplate(nameTextField.getText()); + clock.setFrequencyTemplate(frequencyTextField.getText()); + clock.setDutyCycleTemplate(dutyCycleTextField.getText()); + clock.setStartTimeTemplate(startTimeTextField.getText()); + clock.setPosFirstTemplate((String) posFirstComboBoxString.getSelectedItem()); + clock.setUnitTemplate((String) unitComboBoxString.getSelectedItem()); + + 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/resources/ui/util/clock.png b/src/main/resources/ui/util/clock.png new file mode 100644 index 0000000000000000000000000000000000000000..c1f95cb8229086e5425490bed631c069dc5f5135 Binary files /dev/null and b/src/main/resources/ui/util/clock.png differ