22
22
package com.sun.electric.tool.user;
24
24
import com.sun.electric.database.EditingPreferences;
25
import com.sun.electric.database.geometry.EPoint;
25
26
import com.sun.electric.database.geometry.ERectangle;
26
27
import com.sun.electric.database.geometry.Poly;
28
import com.sun.electric.database.geometry.ScreenPoint;
27
29
import com.sun.electric.database.hierarchy.Cell;
28
30
import com.sun.electric.database.hierarchy.EDatabase;
29
31
import com.sun.electric.database.hierarchy.Export;
1594
1595
// determine the height of text in screen space
1595
1596
int fontSize = EditWindow.getDefaultFontSize();
1596
Point screenOrigin = wnd.databaseToScreen(0, 0);
1597
Point2D thPoint = wnd.screenToDatabase(screenOrigin.x, screenOrigin.y + fontSize);
1597
ScreenPoint screenOrigin = wnd.databaseToScreen(0, 0);
1598
Point2D thPoint = wnd.screenToDatabase(screenOrigin.getX(), screenOrigin.getY() + fontSize);
1598
1599
double textHeight = Math.abs(thPoint.getY());
1600
1601
// determine the location of the port labels
1694
1695
String msg = portList[index].pp.getName();
1696
1697
// get the connecting-line coordinates in screen space
1697
Point locationLabel = wnd.databaseToScreen(loc.getX(), loc.getY());
1698
Point locationPort = wnd.databaseToScreen(portList[index].loc.getX(), portList[index].loc.getY());
1698
ScreenPoint locationLabel = wnd.databaseToScreen(loc.getX(), loc.getY());
1699
long locationLabelX = locationLabel.getX(), locationLabelY = locationLabel.getY();
1700
ScreenPoint locationPort = wnd.databaseToScreen(portList[index].loc.getX(), portList[index].loc.getY());
1700
1702
// determine the opposite corner of the text
1701
1703
GlyphVector v = font.createGlyphVector(frc, msg);
1702
1704
Rectangle2D glyphBounds = v.getLogicalBounds();
1703
int otherX = locationLabel.x + (int)glyphBounds.getWidth();
1704
int otherY = locationLabel.y - (int)glyphBounds.getHeight();
1705
long otherX = locationLabelX + (int)glyphBounds.getWidth();
1706
long otherY = locationLabelY - (int)glyphBounds.getHeight();
1705
1707
Point2D locOther = wnd.screenToDatabase(otherX, otherY);
1707
1709
// if the text is off-screen, adjust it
1708
1710
if (otherX > wnd.getSize().width)
1710
int offDist = otherX - wnd.getSize().width;
1711
locationLabel.x -= offDist;
1712
long offDist = otherX - wnd.getSize().width;
1713
locationLabelX -= offDist;
1712
1714
otherX -= offDist;
1713
loc = wnd.screenToDatabase(locationLabel.x, locationLabel.y);
1715
loc = wnd.screenToDatabase(locationLabelX, locationLabelY);
1716
1718
// change the attachment point on the label to be closest to the port
1717
if (Math.abs(locationPort.x-locationLabel.x) > Math.abs(locationPort.x-otherX))
1718
locationLabel.x = otherX;
1719
if (Math.abs(locationPort.y-locationLabel.y) > Math.abs(locationPort.y-otherY))
1720
locationLabel.y = otherY;
1719
if (Math.abs(locationPort.getX()-locationLabelX) > Math.abs(locationPort.getX()-otherX))
1720
locationLabelX = otherX;
1721
if (Math.abs(locationPort.getY()-locationLabelY) > Math.abs(locationPort.getY()-otherY))
1722
locationLabelY = otherY;
1722
1724
// convert this shift back to database units for the highlight
1723
Point2D locLineEnd = wnd.screenToDatabase(locationLabel.x, locationLabel.y);
1725
Point2D locLineEnd = wnd.screenToDatabase(locationLabelX, locationLabelY);
1725
1727
// draw the port name
1726
1728
highlighter.addMessage(cell, msg, new Point2D.Double(loc.getX()+baselineHor, loc.getY()+baselineVer));
1938
1940
NodeInst ni = it.next();
1939
1941
Cell newType = cellsToReplace.get(ni);
1940
ni.replace(newType, ep, true, true);
1942
ni.replace(newType, ep, true, true, true);
1941
1943
replacements++;
1943
1945
System.out.println("Changed " + replacements + " cell instances");