📄 stimuli.java
字号:
Double [] newCP = new Double[controlPoints.length + 1]; for(int i=0; i<controlPoints.length; i++) newCP[i] = controlPoints[i]; newCP[controlPoints.length] = new Double(time); controlPointMap.put(sig, newCP); } } /** * Method to remove control points the list on a signal. * Control points are places where the user has added stimuli to the signal (set a level or strength). * These points can be selected for change of the stimuli. * @param sig the signal in question. * @param time the time of the control point to delete. */ public void removeControlPoint(Signal sig, double time) { Double [] controlPoints = controlPointMap.get(sig); if (controlPoints == null) return; // see if it is in the list already boolean found = false; for(int i=0; i<controlPoints.length; i++) if (controlPoints[i].doubleValue() == time) { found = true; break; } if (!found) return; // shrink the list Double [] newCP = new Double[controlPoints.length - 1]; int j = 0; for(int i=0; i<controlPoints.length; i++) { if (controlPoints[i].doubleValue() != time) newCP[j++] = controlPoints[i]; } controlPointMap.put(sig, newCP); } /** * Method to compute the time and value bounds of this simulation data. * @return a Rectangle2D that has time bounds in the X part and * value bounds in the Y part. */ public Rectangle2D getBounds() { // determine extent of the data Rectangle2D bounds = null; for(Analysis an : analysisList) { Rectangle2D anBounds = an.getBounds(); if (anBounds == null) continue; if (bounds == null) { bounds = new Rectangle2D.Double(anBounds.getMinX(), anBounds.getMinY(), anBounds.getWidth(), anBounds.getHeight()); } else { Rectangle2D.union(bounds, anBounds, bounds); } } return bounds; } /** * Method to return the leftmost X coordinate of this Stimuli. * This value may not be the same as the minimum-x of the bounds, because * the data may not be monotonically increasing (may run backwards, for example). * @return the leftmost X coordinate of this Stimuli. */ public double getLeftEdge() { double leftEdge = 0, rightEdge = 0; for(Analysis an : analysisList) { if (leftEdge == rightEdge) { leftEdge = an.getLeftEdge(); rightEdge = an.getRightEdge(); } else { if (leftEdge < rightEdge) { leftEdge = Math.min(leftEdge, an.getLeftEdge()); rightEdge = Math.max(rightEdge, an.getRightEdge()); } else { leftEdge = Math.max(leftEdge, an.getLeftEdge()); rightEdge = Math.min(rightEdge, an.getRightEdge()); } } } return leftEdge; } /** * Method to return the rightmost X coordinate of this Stimuli. * This value may not be the same as the maximum-x of the bounds, because * the data may not be monotonically increasing (may run backwards, for example). * @return the rightmost X coordinate of this Stimuli. */ public double getRightEdge() { double leftEdge = 0, rightEdge = 0; for(Analysis an : analysisList) { if (leftEdge == rightEdge) { leftEdge = an.getLeftEdge(); rightEdge = an.getRightEdge(); } else { if (leftEdge < rightEdge) { leftEdge = Math.min(leftEdge, an.getLeftEdge()); rightEdge = Math.max(rightEdge, an.getRightEdge()); } else { leftEdge = Math.max(leftEdge, an.getLeftEdge()); rightEdge = Math.min(rightEdge, an.getRightEdge()); } } } return rightEdge; } /** * Method to tell whether this simulation data is analog or digital. * @return true if this simulation data is analog. */ public boolean isAnalog() { for(Analysis an : analysisList) { if (an.isAnalog()) return true; } return false; } /** * Method to convert a strength to an index value. * The strengths are OFF_STRENGTH, NODE_STRENGTH, GATE_STRENGTH, and VDD_STRENGTH. * The indices are integers that can be saved to disk. * @param strength strength level. * @return the index for that strength (0-based). */ public static int strengthToIndex(int strength) { return strength / 4; } /** * Method to convert a strength index to a strength value. * The strengths are OFF_STRENGTH, NODE_STRENGTH, GATE_STRENGTH, and VDD_STRENGTH. * The indices of the strengths are integers that can be saved to disk. * @param index a strength index (0-based). * @return the equivalent strength. */ public static int indexToStrength(int index) { return index * 4; } /** * Method to describe the level in a given state. * A 'state' is a combination of a level and a strength. * The levels are LOGIC_LOW, LOGIC_HIGH, LOGIC_X, and LOGIC_Z. * @param state the given state. * @return a description of the logic level in that state. */ public static String describeLevel(int state) { switch (state&Stimuli.LOGIC) { case Stimuli.LOGIC_LOW: return "low"; case Stimuli.LOGIC_HIGH: return "high"; case Stimuli.LOGIC_X: return "undefined"; case Stimuli.LOGIC_Z: return "floating"; } return "?"; } /** * Method to describe the level in a given state, with only 1 character. * A 'state' is a combination of a level and a strength. * The levels are LOGIC_LOW, LOGIC_HIGH, LOGIC_X, and LOGIC_Z. * @param state the given state. * @return a description of the logic level in that state. */ public static String describeLevelBriefly(int state) { switch (state&Stimuli.LOGIC) { case Stimuli.LOGIC_LOW: return "L"; case Stimuli.LOGIC_HIGH: return "H"; case Stimuli.LOGIC_X: return "X"; case Stimuli.LOGIC_Z: return "Z"; } return "?"; } /** * Method to convert a state representation (L, H, X, Z) to a state * @param s1 character string that contains state value. * @return the state value. */ public static int parseLevel(String s1) { if (s1.length() > 0) { switch (s1.charAt(0)) { case 'L': case 'l': return Stimuli.LOGIC_LOW; case 'X': case 'x': return Stimuli.LOGIC_X; case 'H': case 'h': return Stimuli.LOGIC_HIGH; case 'Z': case 'z': return Stimuli.LOGIC_Z; } } return Stimuli.LOGIC_X; } /** * Method to describe the strength in a given state. * A 'state' is a combination of a level and a strength. * The strengths are OFF_STRENGTH, NODE_STRENGTH, GATE_STRENGTH, and VDD_STRENGTH. * @param strength the given strength. * @return a description of the strength in that state. */ public static String describeStrength(int strength) { switch (strength&Stimuli.STRENGTH) { case Stimuli.OFF_STRENGTH: return "off"; case Stimuli.NODE_STRENGTH: return "node"; case Stimuli.GATE_STRENGTH: return "gate"; case Stimuli.VDD_STRENGTH: return "power"; } return "?"; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -