📄 cif.java
字号:
translateMatrix(temp.xt, temp.yt); } else if (temp.kind == ROTATE) { rotateMatrix(temp.xRot, temp.yRot); } else { errorReport("interpreter: no such transformation", FATALINTERNAL); } appendTransformEntry(newtlist, temp); // copy the list } FrontCall obj = new FrontCall(); // must make a copy of the matrix obj.matrix = new FrontMatrix(); obj.matrix.a11 = matrixStackTop.a11; obj.matrix.a12 = matrixStackTop.a12; obj.matrix.a21 = matrixStackTop.a21; obj.matrix.a22 = matrixStackTop.a22; obj.matrix.a31 = matrixStackTop.a31; obj.matrix.a32 = matrixStackTop.a32; obj.matrix.a33 = matrixStackTop.a33; obj.matrix.type = matrixStackTop.type; obj.matrix.multiplied = matrixStackTop.multiplied; popTransform(); // return to previous state obj.symNumber = symbol; obj.unID = null; obj.transList = newtlist; if (namePending) { if (statementsSince91) errorReport("statements between name and instance", ADVISORY); namePending = false; } if (isInCellDefinition) { // insert into guts of symbol obj.next = currentFrontSymbol.guts; currentFrontSymbol.guts = obj; currentFrontSymbol.numCalls++; } else { topLevelItem(obj); } } private void rotateMatrix(int xRot, int yRot) { double si = yRot; double co = xRot; if (yRot == 0 && xRot >= 0) return; matrixStackTop.type |= TROTATE; if (xRot == 0) { double temp = matrixStackTop.a11; matrixStackTop.a11 = -matrixStackTop.a12; matrixStackTop.a12 = temp; temp = matrixStackTop.a21; matrixStackTop.a21 = -matrixStackTop.a22; matrixStackTop.a22 = temp; temp = matrixStackTop.a31; matrixStackTop.a31 = -matrixStackTop.a32; matrixStackTop.a32 = temp; if (yRot < 0) matrixStackTop.a33 = -matrixStackTop.a33; } else if (yRot == 0) matrixStackTop.a33 = -matrixStackTop.a33; // xRot < 0 else { double temp = matrixStackTop.a11*co - matrixStackTop.a12*si; matrixStackTop.a12 = matrixStackTop.a11*si + matrixStackTop.a12*co; matrixStackTop.a11 = temp; temp = matrixStackTop.a21*co - matrixStackTop.a22*si; matrixStackTop.a22 = matrixStackTop.a21*si + matrixStackTop.a22*co; matrixStackTop.a21 = temp; temp = matrixStackTop.a31*co - matrixStackTop.a32*si; matrixStackTop.a32 = matrixStackTop.a31*si + matrixStackTop.a32*co; matrixStackTop.a31 = temp; matrixStackTop.a33 = new Point2D.Double(0, 0).distance(new Point2D.Double(co, si)); } } private void translateMatrix(int xtrans, int ytrans) { if (xtrans != 0 || ytrans != 0) { matrixStackTop.a31 += matrixStackTop.a33*xtrans; matrixStackTop.a32 += matrixStackTop.a33*ytrans; matrixStackTop.type |= TTRANSLATE; } } private void mirrorMatrix(boolean xCoord) { if (xCoord) { matrixStackTop.a11 = -matrixStackTop.a11; matrixStackTop.a21 = -matrixStackTop.a21; matrixStackTop.a31 = -matrixStackTop.a31; } else { matrixStackTop.a12 = -matrixStackTop.a12; matrixStackTop.a22 = -matrixStackTop.a22; matrixStackTop.a32 = -matrixStackTop.a32; } matrixStackTop.type |= TMIRROR; } private int getFrontTransformListLength(FrontTransformList a) { if (a == null) return 0; return a.tLength; } private FrontTransformEntry removeFrontTransformEntry(FrontTransformList a) { if (a.tFirst == null) { // added extra code to initialize "ans" to a dummy value FrontTransformEntry ans = new FrontTransformEntry(); ans.kind = TRANSLATE; ans.xt = ans.yt = 0; return ans; } FrontLinkedTransform temp = a.tFirst.tNext; FrontTransformEntry ans = a.tFirst.tValue; a.tFirst = temp; if (a.tFirst == null) a.tLast = null; a.tLength -= 1; return ans; } private void makeDeleteDefinition(int n) { statementsSince91 = true; errorReport("DD not supported (ignored)", ADVISORY); } private void makeEndDefinition() { statementsSince91 = true; if (ignoreStatements) { ignoreStatements = false; return; } isInCellDefinition = false; currentLayer = backupLayer; // restore old layer if (!symbolNamed) { String s = "SYM" + currentFrontSymbol.symNumber; currentFrontSymbol.name = s; } currentFrontSymbol.defined = true; } private void makeStartDefinition(int symbol, int mtl, int div) { statementsSince91 = true; currentFrontSymbol = lookupSymbol(symbol); if (currentFrontSymbol.defined) { // redefining this symbol String mess = "attempt to redefine symbol " + symbol + " (ignored)"; errorReport(mess, ADVISORY); ignoreStatements = true; return; } isInCellDefinition = true; if (mtl != 0 && div != 0) cellScaleFactor = ((float) mtl)/((float) div); else { errorReport("illegal scale factor, ignored", ADVISORY); cellScaleFactor = 1.0; } backupLayer = currentLayer; // save current layer currentLayer = null; symbolNamed = false; // symbol not named } private void makeWire(int width, FrontPath a) { int length = a.pLength; statementsSince91 = true; if (ignoreStatements) return; if (currentLayer == null) { numNullLayerErrors = true; return; } FrontWire obj = new FrontWire(); FrontPath tPath = a; FrontPath sPath = null; // path in case of scaling obj.layer = currentLayer; if (isInCellDefinition && cellScaleFactor != 1.0) { sPath = new FrontPath(); scalePath(a, sPath); // scale all points width = (int)(cellScaleFactor * width); tPath = sPath; } obj.width = width; FrontPath bbpath = new FrontPath(); // get a new path for bb use copyPath(tPath, bbpath); boundsWire(width, bbpath); obj.points = new Point[length]; for (int i = 0; i < length; i++) obj.points[i] = removePoint(tPath); if (isInCellDefinition) { // insert into symbol's guts obj.next = currentFrontSymbol.guts; currentFrontSymbol.guts = obj; } else topLevelItem(obj); // stick into item list } private Rectangle boundsWire(int width, FrontPath pPath) { int half = (width+1)/2; int limit = pPath.pLength; pushTransform(); // newtrans initMinMax(transformPoint(removePoint(pPath))); for (int i = 1; i < limit; i++) { minMax(transformPoint(removePoint(pPath))); } popTransform(); Rectangle rect = new Rectangle(getMinMaxMinX()-half, getMinMaxMinY()-half, getMinMaxMaxX()-getMinMaxMinX()+half*2, getMinMaxMaxY()-getMinMaxMinY()+half*2); doneMinMax(); return rect; } private String getUserText() { StringBuffer user = new StringBuffer(); for(;;) { if (atEndOfFile()) break; if (peekNextCharacter() == ';') break; user.append(getNextCharacter()); } return user.toString(); } private String parseName() { StringBuffer nText = new StringBuffer(); boolean noChar = true; for(;;) { if (atEndOfFile()) break; int c = peekNextCharacter(); if (c == ';' || c == ' ' || c == '\t' || c == '{' || c == '}') break; noChar = false; getNextCharacter(); nText.append((char)c); } if (noChar) logIt(NONAME); return nText.toString(); } private void appendTransformEntry(FrontTransformList a, FrontTransformEntry p) { FrontLinkedTransform newT = new FrontLinkedTransform(); if (newT == null) return; FrontLinkedTransform temp = a.tLast; a.tLast = newT; if (temp != null) temp.tNext = a.tLast; a.tLast.tValue = p; a.tLast.tNext = null; if (a.tFirst == null) a.tFirst = a.tLast; a.tLength += 1; } private int getNumber() { boolean somedigit = false; int ans = 0; skipSpaces(); while (ans < BIGSIGNED && TextUtils.isDigit(peekNextCharacter())) { ans *= 10; ans += getNextCharacter() - '0'; somedigit = true; } if (!somedigit) { logIt(NOUNSIGNED); return 0; } if (TextUtils.isDigit(peekNextCharacter())) { logIt(NUMTOOBIG); return 0XFFFFFFFF; } return ans; } private boolean skipSemicolon() { boolean ans = false; skipBlanks(); if (peekNextCharacter() == ';') { getNextCharacter(); ans = true; skipBlanks(); } return ans; } private boolean skipSpaces() { boolean ans = false; for(;;) { int c = peekNextCharacter(); if (c != ' ' && c != '\t') break; getNextCharacter(); ans = true; } return ans; } private void makePolygon(FrontPath a) { int length = a.pLength; statementsSince91 = true; if (ignoreStatements) return; if (currentLayer == null) { numNullLayerErrors = true; return; } if (length < 3) { errorReport("polygon with < 3 pts in path, ignored", ADVISORY); return; } FrontPoly obj = new FrontPoly(); FrontPath tPath = a; obj.layer = currentLayer; if (isInCellDefinition && cellScaleFactor != 1.0) { FrontPath sPath = new FrontPath(); scalePath(a, sPath); // scale all points tPath = sPath; } FrontPath bbpath = new FrontPath(); // get a new path for bb use copyPath(tPath, bbpath); Rectangle box = getPolyBounds(bbpath); obj.bb.l = box.x; obj.bb.r = box.x + box.width; obj.bb.b = box.y; obj.bb.t = box.y + box.height; obj.points = new Point[length]; for (int i = 0; i < length; i++) obj.points[i] = removePoint(tPath); if (isInCellDefinition) { // insert into symbol's guts obj.next = currentFrontSymbol.guts; currentFrontSymbol.guts = obj; } else topLevelItem(obj); // stick into item list } /** * a bare item has been found */ private void topLevelItem(FrontObjBase object) { if (object == null) { errorReport("item: null object", FATALINTERNAL); return; } FrontItem newItem = new FrontItem(); newItem.same = currentItemList; // hook into linked list currentItemList = newItem; newItem.what = object; // symbol calls only if (object instanceof FrontCall) findCallBounds((FrontCall)object); } /** * find the bb for this particular call */ private void findCallBounds(FrontCall object) { FrontSymbol thisST = lookupSymbol(object.symNumber); if (!thisST.defined) { String mess = "call to undefined symbol " + thisST.symNumber; errorReport(mess, FATALSEMANTIC); return; } if (thisST.expanded) { String mess = "recursive call on symbol " + thisST.symNumber; errorReport(mess, FATALSEMANTIC); return; } thisST.expanded = true; // mark as under expansion findBounds(thisST); // get the bb of the symbol in its FrontSymbol object.unID = thisST; // get this symbol's id pushTransform(); // set up a new frame of reference applyLocal(object.matrix); Point temp = new Point(); temp.x = thisST.bounds.l; temp.y = thisST.bounds.b; // ll Point comperror = transformPoint(temp); initMinMax(comperror); temp.x = thisST.bounds.r; comperror = transformPoint(temp); minMax(comperror); temp.y = thisST.bounds.t; // ur comperror = transformPoint(temp); minMax(comperror); temp.x = thisST.bounds.l; comperror = transformPoint(temp); minMax(comperror); object.bb.l = getMinMaxMinX(); object.bb.r = getMinMaxMaxX(); object.bb.b = getMinMaxMinY(); object.bb.t = getMinMaxMaxY(); doneMinMax(); // object now has transformed bb of the symbol popTransform(); thisST.expanded = false; } /** * find bb for sym */ private void findBounds(FrontSymbol sym) { boolean first = true; FrontObjBase ob = sym.guts; if (sym.boundsValid) return; // already done if (ob == null) // empty symbol { String name = sym.name; if (name == null) name = "#" + sym.symNumber; System.out.println("Warning: cell " + name + " has no geometry in it"); sym.bounds.l = 0; sym.bounds.r = 0; sym.bounds.b = 0; sym.bounds.t = 0; sym.boundsValid = true; return; } while (ob != null) { // find bb for symbol calls, all primitive are done already if (ob instanceof FrontCall) findCallBounds((FrontCall)ob); Point temp = new Point(); temp.x = ob.bb.l; temp.y = ob.bb.b; if (first) {first = false; initMinMax(temp);} else minMax(temp); temp.x = ob.bb.r; temp.y = ob.bb.t; minMax(temp); ob = ob.next; } sym.bounds.l = getMinMaxMinX(); sym.bounds.r = getMinMaxMaxX(); sym.bounds.b = getMinMaxMinY(); sym.bounds.t = getMinMaxMaxY(); sym.boundsValid = true; doneMinMax(); } /** * Method to find a given symbol. * If none, make a blank entry. * @return a pointer to whichever. */ private FrontSymbol lookupSymbol(int sym) { FrontSymbol val = symbolTable.get(new Integer(sym)); if (val == null) { // create a new entry val = new FrontSymbol(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -