cleanup component area map on loading

fixed lead area mapping bug
This commit is contained in:
bancika
2011-01-31 22:05:05 +00:00
parent 12ca93e2c9
commit b96bad2688
7 changed files with 28 additions and 5 deletions
@@ -63,6 +63,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
IDrawingObserver drawingObserver) {
double distance = points[0].distance(points[1]);
Shape shape = getBodyShape();
// If there's no body, just draw the line connecting the ending points.
if (shape == null) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(getLeadThickness()));
g2d.setColor(shouldShadeLeads() ? getLeadColor(componentState).darker()
@@ -313,6 +313,10 @@ public class DrawingManager {
public Area getComponentArea(IDIYComponent<?> component) {
return componentAreaMap.get(component);
}
public void clearComponentAreaMap() {
componentAreaMap.clear();
}
public List<IDIYComponent<?>> findComponentsAt(Point point, Project project) {
List<IDIYComponent<?>> components = new ArrayList<IDIYComponent<?>>();
@@ -179,6 +179,7 @@ class G2DWrapper extends Graphics2D implements IDrawingObserver {
width, thickness);
Area area = new Area(rect);
area.transform(AffineTransform.getRotateInstance(theta, midX, midY));
area.transform(currentTx);
appendShape(area);
// Set the prev point to line end
prevPoint = nextPoint;
@@ -180,6 +180,7 @@ public class Presenter implements IPlugInPort {
public void loadProject(Project project, boolean freshStart) {
LOG.info(String.format("loadProject(%s, %s)", project.getTitle(), freshStart));
this.currentProject = project;
drawingManager.clearComponentAreaMap();
updateSelection(EMPTY_SELECTION);
messageDispatcher.dispatchMessage(EventType.PROJECT_LOADED, project, freshStart);
messageDispatcher.dispatchMessage(EventType.REPAINT);
@@ -32,6 +32,7 @@ import org.diylc.components.passive.RadialFilmCapacitor;
import org.diylc.components.passive.Resistor;
import org.diylc.components.semiconductors.DIL_IC;
import org.diylc.components.semiconductors.DiodePlastic;
import org.diylc.components.semiconductors.LED;
import org.diylc.components.semiconductors.TransistorTO92;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Project;
@@ -302,7 +303,7 @@ public class ProjectFileManager {
}
String sizeAttr = node.getAttributes().getNamedItem("Size").getNodeValue();
if (sizeAttr.equalsIgnoreCase("small")) {
capacitor.setLength(new Size(3d, SizeUnit.mm));
capacitor.setLength(new Size(3.5d, SizeUnit.mm));
} else if (sizeAttr.equalsIgnoreCase("medium")) {
capacitor.setLength(new Size(5d, SizeUnit.mm));
} else if (sizeAttr.equalsIgnoreCase("large")) {
@@ -327,6 +328,17 @@ public class ProjectFileManager {
capacitor.setControlPoint(point1, 0);
capacitor.setControlPoint(point2, 1);
component = capacitor;
} else if (nodeName.equalsIgnoreCase("led")) {
LOG.debug("Recognized " + nodeName);
LED led = new LED();
led.setName(nameAttr);
led.setValue(valueAttr);
led.setBodyColor(Color.red);
led.setBorderColor(Color.red.darker());
led.setLength(new Size(3d, SizeUnit.mm));
led.setControlPoint(point1, 0);
led.setControlPoint(point2, 1);
component = led;
} else if (nodeName.equalsIgnoreCase("transistor")) {
LOG.debug("Recognized " + nodeName);
TransistorTO92 transistor = new TransistorTO92();