📄 circuitpainterapplet.java
字号:
/* * CircuitPainterApplet.java * * Created on 11 August 2003, 13:03 */package jaga.pj.circuits.fpgaft;import jaga.pj.circuits.SimulatorLogicElement;import jaga.pj.circuits.CircuitMapping;import jaga.pj.circuits.CoinDelayModel;import jaga.pj.circuits.OptimizedMapping;import jaga.pj.circuits.VassilevMapping;import jaga.Genotype;import java.util.StringTokenizer;/** * * @author mmg20 */public class CircuitPainterApplet extends java.applet.Applet { protected static final String selectedString = "Selected: "; protected CircuitPainter painter; protected SimulatorLogicElement[][] inoutels = null; protected int inputSampleSeparation = 50; protected SimulatorLogicElement selected = null; /** Initializes the applet CircuitPainterApplet */ public void init() { initComponents(); String runDesc = getParameter( "run_desc" ); String genotypeDesc = getParameter( "genotype_desc" ); String genotype = extractGenotype( genotypeDesc ); int nrIns = extractKey( "#", "inputs", runDesc ); int nrOuts = extractKey( "#", "outputs", runDesc ); int bitsPerVar = extractKey( "per", "Variable", runDesc ); int lutIns = extractKey( "LUT", "inputs", runDesc ); int genLength = extractKey( "initialGenotypeLength", runDesc ); //int genLength = extractGenotypeLength( genotypeDesc ); CircuitMapping inMap; if( runDesc.indexOf( "FPGALUT" ) >= 0 ) { inMap = new FPGALUTAbsoluteMapping( nrIns, nrOuts, bitsPerVar, lutIns, new CoinDelayModel() ); }else { inMap = new LUTAbsoluteMapping( nrIns, nrOuts, bitsPerVar, lutIns, new CoinDelayModel() ); if( runDesc.indexOf( "Vassilev" ) >= 0 ) { inMap = new VassilevMapping( inMap, nrOuts, bitsPerVar ); } } CircuitMapping circuitMapping = new OptimizedMapping( inMap ); System.out.println("" + runDesc ); System.out.println("" + circuitMapping); Genotype ind = new Genotype( genotype, genLength, 6 ); inoutels = circuitMapping.map( ind ); int gateDimension = 50; if( lutIns > 2 ) { gateDimension = 60; } // Custom IO names String[] outputNames = null; int nrEs = 0; if( runDesc.indexOf( "Interaction Model: BIST" ) >= 0 ) { nrEs = 1; } if( runDesc.indexOf( "Interaction Model: Testing the Tester BIST" ) >= 0 ) { nrEs = extractKey( "Error", "Lines", runDesc ); } if( runDesc.indexOf( "Dual Rail" ) >= 0 ) { nrEs = 2; } outputNames = new String[ nrOuts ]; for( int ql = 0; ql < nrOuts - nrEs; ql++ ) { outputNames[ ql ] = "Y_" + ql; } for( int qel = 0; qel < nrEs; qel++ ) { outputNames[ nrOuts - nrEs + qel ] = "Z_" + qel; } String[] inputNames = null; if( runDesc.indexOf( "Sequential" ) >= 0 ) { inputNames = new String[ nrIns ]; if( runDesc.indexOf( "CINV" ) >= 0 ) { for( int ql = 0; ql < nrIns - 1; ql++ ) { inputNames[ nrIns - ql - 1 ] = "X_" + ql; } inputNames[ 0 ] = "C"; }else { for( int ql = 0; ql < nrIns - 1; ql++ ) { inputNames[ ql ] = "X_" + ql; } inputNames[ nrIns - 1 ] = "C"; } } painter = new CircuitPainter( new java.awt.Dimension( gateDimension, gateDimension ), outputNames, inputNames ); } public int extractKey( String key, String barn ) { StringTokenizer stk = new StringTokenizer( barn ); while( stk.hasMoreTokens() ) { if( stk.nextToken().equals( key ) ) { stk.nextToken(); return new Integer( stk.nextToken() ).intValue(); } } return -1; } public int extractKey( String key1, String key2, String barn ) { StringTokenizer stk = new StringTokenizer( barn, "\n \t" ); while( stk.hasMoreTokens() ) { if( stk.nextToken().equals( key1 ) && stk.nextToken().equals( key2 ) ) // fails if first token twice in row { stk.nextToken(); return new Integer( stk.nextToken() ).intValue(); } } return -1; } public String extractTag( String stuff, String tag ) { int startTag = stuff.indexOf("<" + tag + ">"); if( startTag < 0 ) { return stuff; }else { int endTag = stuff.indexOf("</" + tag + ">"); return stuff.substring( startTag + 2 + tag.length() , endTag ); } } public int extractGenotypeLength( String genDesc ) { String lenDesc = extractTag( genDesc, "l" ); return Integer.parseInt( lenDesc ); } public String extractGenotype( String genDesc ) { return extractTag( genDesc, "g" ); } public void paint( java.awt.Graphics g ) { super.paint( g ); java.awt.Graphics jpg = jPanel1.getGraphics(); painter.paint( inoutels, jpg ); } /** This method is called from within the init() method to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void initComponents() {//GEN-BEGIN:initComponents jPanel3 = new javax.swing.JPanel(); selectedLabel = new javax.swing.JLabel(); jPanel2 = new javax.swing.JPanel(); jPanel9 = new javax.swing.JPanel(); jPanel511 = new javax.swing.JPanel(); jLabel211 = new javax.swing.JLabel(); jPanel1011 = new javax.swing.JPanel(); textISS = new javax.swing.JTextField(); jPanel611 = new javax.swing.JPanel(); jButton111 = new javax.swing.JButton(); jPanel711 = new javax.swing.JPanel(); clickSimulates = new javax.swing.JCheckBox(); jPanel5 = new javax.swing.JPanel(); jTextArea1 = new javax.swing.JTextArea(); jScrollPane1 = new javax.swing.JScrollPane(); jPanel1 = new javax.swing.JPanel(); setLayout(new java.awt.BorderLayout()); setBackground(java.awt.Color.white); jPanel3.setLayout(new java.awt.BorderLayout()); selectedLabel.setText(selectedString); jPanel3.add(selectedLabel, java.awt.BorderLayout.CENTER); add(jPanel3, java.awt.BorderLayout.SOUTH); jPanel2.setLayout(new java.awt.GridLayout(2, 1)); jPanel9.setLayout(new java.awt.GridLayout(7, 1)); jLabel211.setText("Steps:"); jPanel511.add(jLabel211); jPanel9.add(jPanel511); textISS.setToolTipText("A Simulator Step is the unit of time of the Digital Logic Simulator."); textISS.setColumns(6); textISS.setText("50"); textISS.setHorizontalAlignment(javax.swing.JTextField.TRAILING); textISS.setName("textInputs"); jPanel1011.add(textISS); jPanel9.add(jPanel1011); jButton111.setToolTipText("Run the simulator for as many steps as specified above. Even in combinational circuits there is a delay between a change in inputs and the appropraite response at the outputs."); jButton111.setText("Simulate"); jButton111.setName("buttSetInputs"); jPanel611.add(jButton111); jPanel9.add(jPanel611); clickSimulates.setToolTipText("If to Simulate every time you change something by clicking the mouse"); clickSimulates.setSelected(true); clickSimulates.setFont(new java.awt.Font("Dialog", 1, 10)); clickSimulates.setText("Auto Simulate"); jPanel711.add(clickSimulates); jPanel9.add(jPanel711); jPanel2.add(jPanel9); jTextArea1.setWrapStyleWord(true); jTextArea1.setLineWrap(true); jTextArea1.setEditable(false); jTextArea1.setColumns(9); jTextArea1.setText("Left click on inputs to change them. Left-click on gates to select. Right-click on gates to cycle through failure: 1 click inserts a Single Stuck At (SSA) 0 fault, 2 clicks inserts a SSA 1 fault and 3 clicks removes the failure. Red gates have high output."); jTextArea1.setBackground((java.awt.Color) javax.swing.UIManager.getDefaults().get("Button.background")); jPanel5.add(jTextArea1); jPanel2.add(jPanel5); add(jPanel2, java.awt.BorderLayout.EAST); jPanel1.setBackground(java.awt.Color.white); jPanel1.setPreferredSize(new java.awt.Dimension(500, 2000)); jPanel1.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentMoved(java.awt.event.ComponentEvent evt) { jPanel1ComponentMoved(evt); } }); jPanel1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jPanel1MouseClicked(evt); } }); jScrollPane1.setViewportView(jPanel1); add(jScrollPane1, java.awt.BorderLayout.CENTER); }//GEN-END:initComponents private void jPanel1ComponentMoved(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jPanel1ComponentMoved // Add your handling code here: repaint(); }//GEN-LAST:event_jPanel1ComponentMoved private void jPanel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel1MouseClicked // Add your handling code here: SimulatorLogicElement clickedOn = painter.getElementFromClick(inoutels, evt.getX(), evt.getY() ); if( clickedOn != null ) { if( jaga.ESLib.indexOf( clickedOn, inoutels[ 0 ] ) >= 0 ) { clickedOn.setNow( !clickedOn.getNow() ); }else { if( ( evt.getModifiers() & evt.BUTTON3_MASK ) > 0 ) { if( clickedOn instanceof SimulatorFaultyDelayLE ) { SimulatorFaultyDelayLE fClickedOn = ( SimulatorFaultyDelayLE ) clickedOn; if( fClickedOn.SSA ) { if( fClickedOn.SSAV ) { fClickedOn.SSA = false; }else { fClickedOn.SSAV = true; } }else { /*SimulatorLogicElement[] els = inoutels[ 2 ]; for( int el = 0; el < els.length; el++ ) { if( els[ el ] instanceof SimulatorFaultyDelayLE ) { ( ( SimulatorFaultyDelayLE )els[ el ] ).setFault( jaga.pj.circuits.fpgaft.FTLib.NOFAULT ); } }*/ fClickedOn.SSA = true; fClickedOn.SSAV = false; } } }else { selected = clickedOn; selectedLabel.setText( selectedString + selected ); } } if( clickSimulates.isSelected() ) { jButton1ActionPerformed( null ); }else { repaint(); } } }//GEN-LAST:event_jPanel1MouseClicked private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed SimulatorLogicElement[] ins = inoutels[ 0 ]; SimulatorLogicElement[] outs = inoutels[ 1 ]; SimulatorLogicElement[] els = inoutels[ 2 ]; inputSampleSeparation = new Integer( textISS.getText() ).intValue(); for( int sdl = 0; sdl < inputSampleSeparation; sdl++ ) { // Update state for( int vl = 0; vl < els.length; vl++ ) { els[ vl ].sampleInputs(); } for( int vl = 0; vl < els.length; vl++ ) { els[ vl ].refreshOutput(); } } repaint(); }//GEN-LAST:event_jButton1ActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel jPanel711; private javax.swing.JPanel jPanel611; private javax.swing.JTextField textISS; private javax.swing.JLabel jLabel211; private javax.swing.JButton jButton111; private javax.swing.JPanel jPanel511; private javax.swing.JCheckBox clickSimulates; private javax.swing.JLabel selectedLabel; private javax.swing.JPanel jPanel9; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JPanel jPanel5; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel1; private javax.swing.JTextArea jTextArea1; private javax.swing.JPanel jPanel1011; // End of variables declaration//GEN-END:variables }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -