mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
refactor old version parsing
remove dependency from core to library validate SolderPad size
This commit is contained in:
@@ -4,7 +4,6 @@
|
|||||||
<classpathentry kind="src" path="test"/>
|
<classpathentry kind="src" path="test"/>
|
||||||
<classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/>
|
<classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/junit-4.7.jar"/>
|
<classpathentry kind="lib" path="lib/junit-4.7.jar"/>
|
||||||
<classpathentry kind="lib" path="library/main.jar"/>
|
|
||||||
<classpathentry kind="lib" path="lib/app-framework.jar"/>
|
<classpathentry kind="lib" path="lib/app-framework.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/jettison-1.0.1.jar"/>
|
<classpathentry kind="lib" path="lib/jettison-1.0.1.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/xstream-1.3.1.jar"/>
|
<classpathentry kind="lib" path="lib/xstream-1.3.1.jar"/>
|
||||||
|
|||||||
@@ -33,12 +33,7 @@
|
|||||||
<fileset dir="${basedir}/lib">
|
<fileset dir="${basedir}/lib">
|
||||||
<exclude name="**/*dll" />
|
<exclude name="**/*dll" />
|
||||||
</fileset>
|
</fileset>
|
||||||
</copy>
|
</copy>
|
||||||
<copy todir="${jar.dir}/library" overwrite="true">
|
|
||||||
<fileset dir="${basedir}/library">
|
|
||||||
<exclude name="**/*dll" />
|
|
||||||
</fileset>
|
|
||||||
</copy>
|
|
||||||
<copy todir="${jar.dir}" overwrite="true">
|
<copy todir="${jar.dir}" overwrite="true">
|
||||||
<fileset dir="${basedir}/lib/" includes="**/*.dll" />
|
<fileset dir="${basedir}/lib/" includes="**/*.dll" />
|
||||||
</copy>
|
</copy>
|
||||||
|
|||||||
Binary file not shown.
@@ -29,10 +29,11 @@ public class ComponentType {
|
|||||||
private BomPolicy bomPolicy;
|
private BomPolicy bomPolicy;
|
||||||
private boolean autoEdit;
|
private boolean autoEdit;
|
||||||
private boolean rotatable;
|
private boolean rotatable;
|
||||||
|
private String autoCreateName;
|
||||||
|
|
||||||
public ComponentType(String name, String description, CreationMethod creationMethod, String category,
|
public ComponentType(String name, String description, CreationMethod creationMethod, String category,
|
||||||
String namePrefix, String author, Icon icon, Class<? extends IDIYComponent<?>> instanceClass, double zOrder,
|
String namePrefix, String author, Icon icon, Class<? extends IDIYComponent<?>> instanceClass, double zOrder,
|
||||||
boolean flexibleZOrder, boolean stretchable, BomPolicy bomPolicy, boolean autoEdit, boolean rotatable) {
|
boolean flexibleZOrder, boolean stretchable, BomPolicy bomPolicy, boolean autoEdit, boolean rotatable, String autoCreateName) {
|
||||||
super();
|
super();
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
@@ -48,6 +49,7 @@ public class ComponentType {
|
|||||||
this.bomPolicy = bomPolicy;
|
this.bomPolicy = bomPolicy;
|
||||||
this.autoEdit = autoEdit;
|
this.autoEdit = autoEdit;
|
||||||
this.rotatable = rotatable;
|
this.rotatable = rotatable;
|
||||||
|
this.autoCreateName = autoCreateName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -105,6 +107,10 @@ public class ComponentType {
|
|||||||
public boolean isRotatable() {
|
public boolean isRotatable() {
|
||||||
return rotatable;
|
return rotatable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getAutoCreateName() {
|
||||||
|
return autoCreateName;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package org.diylc.core.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
import org.diylc.core.IDIYComponent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Annotation for {@link IDIYComponent} implementation. Tells the core which component should be auto-created as a solder pad.
|
||||||
|
*
|
||||||
|
* @author Branislav Stojkovic
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface AutoCreated {
|
||||||
|
/**
|
||||||
|
* @return auto-create type name.
|
||||||
|
*/
|
||||||
|
String name();
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@ public class PositiveMeasureValidator implements IPropertyValidator {
|
|||||||
if (value == null)
|
if (value == null)
|
||||||
return;
|
return;
|
||||||
if (value instanceof AbstractMeasure) {
|
if (value instanceof AbstractMeasure) {
|
||||||
AbstractMeasure measure = (AbstractMeasure) value;
|
AbstractMeasure<?> measure = (AbstractMeasure<?>) value;
|
||||||
if (measure.getValue() < 0) {
|
if (measure.getValue() < 0) {
|
||||||
throw new ValidationException("must be greater than zero.");
|
throw new ValidationException("must be greater than zero.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package org.diylc.parsing;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.diylc.core.Project;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
public interface IOldFileParser {
|
||||||
|
|
||||||
|
boolean canParse(String version);
|
||||||
|
|
||||||
|
Project parseFile(Element root, List<String> warnings);
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ import org.diylc.common.PropertyWrapper;
|
|||||||
import org.diylc.core.CreationMethod;
|
import org.diylc.core.CreationMethod;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
import org.diylc.core.IPropertyValidator;
|
import org.diylc.core.IPropertyValidator;
|
||||||
|
import org.diylc.core.annotations.AutoCreated;
|
||||||
import org.diylc.core.annotations.BomPolicy;
|
import org.diylc.core.annotations.BomPolicy;
|
||||||
import org.diylc.core.annotations.ComponentDescriptor;
|
import org.diylc.core.annotations.ComponentDescriptor;
|
||||||
import org.diylc.core.annotations.EditableProperty;
|
import org.diylc.core.annotations.EditableProperty;
|
||||||
@@ -70,6 +71,7 @@ public class ComponentProcessor {
|
|||||||
BomPolicy bomPolicy;
|
BomPolicy bomPolicy;
|
||||||
boolean autoEdit;
|
boolean autoEdit;
|
||||||
boolean rotatable;
|
boolean rotatable;
|
||||||
|
String autoCreateName = null;
|
||||||
if (clazz.isAnnotationPresent(ComponentDescriptor.class)) {
|
if (clazz.isAnnotationPresent(ComponentDescriptor.class)) {
|
||||||
ComponentDescriptor annotation = clazz.getAnnotation(ComponentDescriptor.class);
|
ComponentDescriptor annotation = clazz.getAnnotation(ComponentDescriptor.class);
|
||||||
name = annotation.name();
|
name = annotation.name();
|
||||||
@@ -98,6 +100,10 @@ public class ComponentProcessor {
|
|||||||
autoEdit = true;
|
autoEdit = true;
|
||||||
rotatable = true;
|
rotatable = true;
|
||||||
}
|
}
|
||||||
|
if (clazz.isAnnotationPresent(AutoCreated.class)) {
|
||||||
|
AutoCreated annotation = clazz.getAnnotation(AutoCreated.class);
|
||||||
|
autoCreateName = annotation.name();
|
||||||
|
}
|
||||||
icon = null;
|
icon = null;
|
||||||
// Draw component icon.
|
// Draw component icon.
|
||||||
try {
|
try {
|
||||||
@@ -116,7 +122,7 @@ public class ComponentProcessor {
|
|||||||
}
|
}
|
||||||
ComponentType componentType =
|
ComponentType componentType =
|
||||||
new ComponentType(name, description, creationMethod, category, namePrefix, author, icon, clazz, zOrder,
|
new ComponentType(name, description, creationMethod, category, namePrefix, author, icon, clazz, zOrder,
|
||||||
flexibleZOrder, stretchable, bomPolicy, autoEdit, rotatable);
|
flexibleZOrder, stretchable, bomPolicy, autoEdit, rotatable, autoCreateName);
|
||||||
componentTypeMap.put(clazz.getName(), componentType);
|
componentTypeMap.put(clazz.getName(), componentType);
|
||||||
return componentType;
|
return componentType;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class InstantiationManager {
|
|||||||
|
|
||||||
private static final ComponentType clipboardType = new ComponentType("Clipboard contents",
|
private static final ComponentType clipboardType = new ComponentType("Clipboard contents",
|
||||||
"Components from the clipboard", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, false, null,
|
"Components from the clipboard", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, false, null,
|
||||||
false, true);
|
false, true, null);
|
||||||
|
|
||||||
public InstantiationManager() {}
|
public InstantiationManager() {}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ import org.diylc.common.IPlugInPort;
|
|||||||
import org.diylc.common.Orientation;
|
import org.diylc.common.Orientation;
|
||||||
import org.diylc.common.OrientationHV;
|
import org.diylc.common.OrientationHV;
|
||||||
import org.diylc.common.PropertyWrapper;
|
import org.diylc.common.PropertyWrapper;
|
||||||
import org.diylc.components.connectivity.SolderPad;
|
|
||||||
import org.diylc.core.ExpansionMode;
|
import org.diylc.core.ExpansionMode;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
import org.diylc.core.IView;
|
import org.diylc.core.IView;
|
||||||
@@ -64,6 +63,8 @@ import com.thoughtworks.xstream.io.xml.DomDriver;
|
|||||||
*/
|
*/
|
||||||
public class Presenter implements IPlugInPort {
|
public class Presenter implements IPlugInPort {
|
||||||
|
|
||||||
|
private static final String SOLDER_PAD = "SolderPad";
|
||||||
|
|
||||||
private static final Logger LOG = Logger.getLogger(Presenter.class);
|
private static final Logger LOG = Logger.getLogger(Presenter.class);
|
||||||
|
|
||||||
public static VersionNumber CURRENT_VERSION = new VersionNumber(3, 0, 0);
|
public static VersionNumber CURRENT_VERSION = new VersionNumber(3, 0, 0);
|
||||||
@@ -72,6 +73,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
try {
|
try {
|
||||||
BufferedInputStream in = new BufferedInputStream(new FileInputStream("update.xml"));
|
BufferedInputStream in = new BufferedInputStream(new FileInputStream("update.xml"));
|
||||||
XStream xStream = new XStream(new DomDriver());
|
XStream xStream = new XStream(new DomDriver());
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
List<Version> allVersions = (List<Version>) xStream.fromXML(in);
|
List<Version> allVersions = (List<Version>) xStream.fromXML(in);
|
||||||
in.close();
|
in.close();
|
||||||
CURRENT_VERSION = allVersions.get(allVersions.size() - 1).getVersionNumber();
|
CURRENT_VERSION = allVersions.get(allVersions.size() - 1).getVersionNumber();
|
||||||
@@ -87,6 +89,10 @@ public class Presenter implements IPlugInPort {
|
|||||||
|
|
||||||
private Project currentProject;
|
private Project currentProject;
|
||||||
private Map<String, List<ComponentType>> componentTypes;
|
private Map<String, List<ComponentType>> componentTypes;
|
||||||
|
/**
|
||||||
|
* {@link ComponentType}s that can be autocreated, like Solder Pads
|
||||||
|
*/
|
||||||
|
private Map<String, ComponentType> autoCreateTypes;
|
||||||
// Maps component class names to ComponentType objects.
|
// Maps component class names to ComponentType objects.
|
||||||
private List<IPlugIn> plugIns;
|
private List<IPlugIn> plugIns;
|
||||||
|
|
||||||
@@ -347,6 +353,19 @@ public class Presenter implements IPlugInPort {
|
|||||||
return componentTypes;
|
return componentTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String, ComponentType> getAutoCreateTypes() {
|
||||||
|
if (autoCreateTypes == null) {
|
||||||
|
autoCreateTypes = new HashMap<String, ComponentType>();
|
||||||
|
for (Map.Entry<String, List<ComponentType>> entry : getComponentTypes().entrySet()) {
|
||||||
|
for (ComponentType t : entry.getValue()) {
|
||||||
|
if (t.getAutoCreateName() != null)
|
||||||
|
autoCreateTypes.put(t.getAutoCreateName(), t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return autoCreateTypes;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, Set<DrawOption> drawOptions, IComponentFiler filter) {
|
public void draw(Graphics2D g2d, Set<DrawOption> drawOptions, IComponentFiler filter) {
|
||||||
if (currentProject == null) {
|
if (currentProject == null) {
|
||||||
@@ -670,6 +689,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void mouseMoved(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown) {
|
public void mouseMoved(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown) {
|
||||||
|
|
||||||
@@ -746,6 +766,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
return selectedComponents;
|
return selectedComponents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void selectAll(int layer) {
|
public void selectAll(int layer) {
|
||||||
LOG.info("selectAll()");
|
LOG.info("selectAll()");
|
||||||
@@ -852,6 +873,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
*
|
*
|
||||||
* @param controlPointMap
|
* @param controlPointMap
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private void includeStuckComponents(Map<IDIYComponent<?>, Set<Integer>> controlPointMap) {
|
private void includeStuckComponents(Map<IDIYComponent<?>, Set<Integer>> controlPointMap) {
|
||||||
int oldSize = controlPointMap.size();
|
int oldSize = controlPointMap.size();
|
||||||
LOG.trace("Expanding selected component map");
|
LOG.trace("Expanding selected component map");
|
||||||
@@ -1054,6 +1076,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
*
|
*
|
||||||
* @param direction 1 for clockwise, -1 for counter-clockwise
|
* @param direction 1 for clockwise, -1 for counter-clockwise
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private void rotateComponents(List<IDIYComponent<?>> components, int direction, boolean snapToGrid) {
|
private void rotateComponents(List<IDIYComponent<?>> components, int direction, boolean snapToGrid) {
|
||||||
Point center = getCenterOf(components, snapToGrid);
|
Point center = getCenterOf(components, snapToGrid);
|
||||||
|
|
||||||
@@ -1286,6 +1309,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
messageDispatcher.dispatchMessage(EventType.LAYER_STATE_CHANGED, currentProject.getLockedLayers());
|
messageDispatcher.dispatchMessage(EventType.LAYER_STATE_CHANGED, currentProject.getLockedLayers());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void sendSelectionToBack() {
|
public void sendSelectionToBack() {
|
||||||
LOG.info("sendSelectionToBack()");
|
LOG.info("sendSelectionToBack()");
|
||||||
@@ -1316,6 +1340,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void bringSelectionToFront() {
|
public void bringSelectionToFront() {
|
||||||
LOG.info("bringSelectionToFront()");
|
LOG.info("bringSelectionToFront()");
|
||||||
@@ -1363,6 +1388,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
drawingManager.setTheme(theme);
|
drawingManager.setTheme(theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void renumberSelectedComponents(final boolean xAxisFirst) {
|
public void renumberSelectedComponents(final boolean xAxisFirst) {
|
||||||
LOG.info("renumberSelectedComponents(" + xAxisFirst + ")");
|
LOG.info("renumberSelectedComponents(" + xAxisFirst + ")");
|
||||||
@@ -1453,6 +1479,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents, controlPointMap.keySet());
|
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents, controlPointMap.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void expandSelection(ExpansionMode expansionMode) {
|
public void expandSelection(ExpansionMode expansionMode) {
|
||||||
LOG.info(String.format("expandSelection(%s)", expansionMode));
|
LOG.info(String.format("expandSelection(%s)", expansionMode));
|
||||||
@@ -1596,6 +1623,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
*
|
*
|
||||||
* @param component
|
* @param component
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private void addComponent(IDIYComponent<?> component, boolean canCreatePads) {
|
private void addComponent(IDIYComponent<?> component, boolean canCreatePads) {
|
||||||
int index = currentProject.getComponents().size();
|
int index = currentProject.getComponents().size();
|
||||||
while (index > 0
|
while (index > 0
|
||||||
@@ -1612,9 +1640,10 @@ public class Presenter implements IPlugInPort {
|
|||||||
} else {
|
} else {
|
||||||
currentProject.getComponents().add(component);
|
currentProject.getComponents().add(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ComponentType padType = getAutoCreateTypes().get(SOLDER_PAD);
|
||||||
if (canCreatePads && ConfigurationManager.getInstance().readBoolean(IPlugInPort.AUTO_PADS_KEY, false)
|
if (canCreatePads && ConfigurationManager.getInstance().readBoolean(IPlugInPort.AUTO_PADS_KEY, false)
|
||||||
&& !(component instanceof SolderPad)) {
|
&& padType != null && !(component.getClass().equals(padType.getInstanceClass()))) {
|
||||||
ComponentType padType = ComponentProcessor.getInstance().extractComponentTypeFrom(SolderPad.class);
|
|
||||||
for (int i = 0; i < component.getControlPointCount(); i++) {
|
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||||
if (component.isControlPointSticky(i)) {
|
if (component.isControlPointSticky(i)) {
|
||||||
try {
|
try {
|
||||||
@@ -1626,11 +1655,6 @@ public class Presenter implements IPlugInPort {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.warn("Could not auto-create solder pad", e);
|
LOG.warn("Could not auto-create solder pad", e);
|
||||||
}
|
}
|
||||||
// SolderPad pad = new SolderPad();
|
|
||||||
// pad.setControlPoint(component.getControlPoint(i), 0);
|
|
||||||
// addComponent(pad,
|
|
||||||
// ComponentProcessor.getInstance().extractComponentTypeFrom(
|
|
||||||
// SolderPad.class), false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1742,6 +1766,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void saveSelectedComponentAsTemplate(String templateName) {
|
public void saveSelectedComponentAsTemplate(String templateName) {
|
||||||
LOG.info(String.format("saveSelectedComponentAsTemplate(%s)", templateName));
|
LOG.info(String.format("saveSelectedComponentAsTemplate(%s)", templateName));
|
||||||
@@ -1818,6 +1843,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
ConfigurationManager.getInstance().writeValue(TEMPLATES_KEY, templateMap);
|
ConfigurationManager.getInstance().writeValue(TEMPLATES_KEY, templateMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public List<Template> getTemplatesFor(String categoryName, String componentTypeName) {
|
public List<Template> getTemplatesFor(String categoryName, String componentTypeName) {
|
||||||
Map<String, List<Template>> templateMap =
|
Map<String, List<Template>> templateMap =
|
||||||
@@ -1828,6 +1854,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public List<Template> getTemplatesForSelection() {
|
public List<Template> getTemplatesForSelection() {
|
||||||
if (this.selectedComponents.isEmpty()) {
|
if (this.selectedComponents.isEmpty()) {
|
||||||
@@ -1872,6 +1899,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void deleteTemplate(String categoryName, String componentTypeName, String templateName) {
|
public void deleteTemplate(String categoryName, String componentTypeName, String templateName) {
|
||||||
Map<String, List<Template>> templateMap =
|
Map<String, List<Template>> templateMap =
|
||||||
@@ -1900,6 +1928,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
return lockedComponents;
|
return lockedComponents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private boolean isComponentLocked(IDIYComponent<?> component) {
|
private boolean isComponentLocked(IDIYComponent<?> component) {
|
||||||
ComponentType componentType =
|
ComponentType componentType =
|
||||||
ComponentProcessor.getInstance().extractComponentTypeFrom(
|
ComponentProcessor.getInstance().extractComponentTypeFrom(
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package org.diylc.presenter;
|
package org.diylc.presenter;
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Point;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@@ -10,54 +8,23 @@ import java.io.InputStreamReader;
|
|||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.diylc.appframework.miscutils.Utils;
|
||||||
import org.diylc.appframework.simplemq.MessageDispatcher;
|
import org.diylc.appframework.simplemq.MessageDispatcher;
|
||||||
import org.diylc.common.Display;
|
|
||||||
import org.diylc.common.EventType;
|
import org.diylc.common.EventType;
|
||||||
import org.diylc.common.HorizontalAlignment;
|
|
||||||
import org.diylc.common.Orientation;
|
|
||||||
import org.diylc.common.VerticalAlignment;
|
|
||||||
import org.diylc.components.AbstractLeadedComponent;
|
|
||||||
import org.diylc.components.AbstractTransparentComponent;
|
|
||||||
import org.diylc.components.boards.AbstractBoard;
|
|
||||||
import org.diylc.components.boards.BlankBoard;
|
|
||||||
import org.diylc.components.boards.PerfBoard;
|
|
||||||
import org.diylc.components.boards.VeroBoard;
|
|
||||||
import org.diylc.components.connectivity.CopperTrace;
|
|
||||||
import org.diylc.components.connectivity.HookupWire;
|
|
||||||
import org.diylc.components.connectivity.Jumper;
|
|
||||||
import org.diylc.components.connectivity.SolderPad;
|
|
||||||
import org.diylc.components.misc.Label;
|
|
||||||
import org.diylc.components.passive.PotentiometerPanel;
|
|
||||||
import org.diylc.components.passive.RadialElectrolytic;
|
|
||||||
import org.diylc.components.passive.RadialFilmCapacitor;
|
|
||||||
import org.diylc.components.passive.Resistor;
|
|
||||||
import org.diylc.components.passive.Taper;
|
|
||||||
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;
|
import org.diylc.core.Project;
|
||||||
import org.diylc.core.measures.Capacitance;
|
import org.diylc.parsing.IOldFileParser;
|
||||||
import org.diylc.core.measures.Resistance;
|
|
||||||
import org.diylc.core.measures.Size;
|
|
||||||
import org.diylc.core.measures.SizeUnit;
|
|
||||||
import org.diylc.utils.Constants;
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
@@ -68,18 +35,6 @@ public class ProjectFileManager {
|
|||||||
|
|
||||||
private static final Logger LOG = Logger.getLogger(ProjectFileManager.class);
|
private static final Logger LOG = Logger.getLogger(ProjectFileManager.class);
|
||||||
|
|
||||||
// private static final int V1_PIXELS_PER_INCH = 200;
|
|
||||||
private static final Size V1_GRID_SPACING = new Size(0.1d, SizeUnit.in);
|
|
||||||
private static final Map<String, Color> V1_COLOR_MAP = new HashMap<String, Color>();
|
|
||||||
static {
|
|
||||||
V1_COLOR_MAP.put("red", Color.red);
|
|
||||||
V1_COLOR_MAP.put("blue", Color.blue);
|
|
||||||
V1_COLOR_MAP.put("white", Color.white);
|
|
||||||
V1_COLOR_MAP.put("green", Color.green.darker());
|
|
||||||
V1_COLOR_MAP.put("black", Color.black);
|
|
||||||
V1_COLOR_MAP.put("yellow", Color.yellow);
|
|
||||||
}
|
|
||||||
|
|
||||||
private XStream xStream;
|
private XStream xStream;
|
||||||
// Legacy deserializer for 3.0.1 through 3.0.7, loads Points referenced in
|
// Legacy deserializer for 3.0.1 through 3.0.7, loads Points referenced in
|
||||||
// pixels.
|
// pixels.
|
||||||
@@ -90,6 +45,8 @@ public class ProjectFileManager {
|
|||||||
|
|
||||||
private MessageDispatcher<EventType> messageDispatcher;
|
private MessageDispatcher<EventType> messageDispatcher;
|
||||||
|
|
||||||
|
private List<IOldFileParser> parsers;
|
||||||
|
|
||||||
public ProjectFileManager(MessageDispatcher<EventType> messageDispatcher) {
|
public ProjectFileManager(MessageDispatcher<EventType> messageDispatcher) {
|
||||||
super();
|
super();
|
||||||
this.xStream = new XStream(new DomDriver("UTF-8"));
|
this.xStream = new XStream(new DomDriver("UTF-8"));
|
||||||
@@ -106,6 +63,25 @@ public class ProjectFileManager {
|
|||||||
fireFileStatusChanged();
|
fireFileStatusChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<IOldFileParser> getParsers() {
|
||||||
|
if (parsers == null) {
|
||||||
|
parsers = new ArrayList<IOldFileParser>();
|
||||||
|
Set<Class<?>> componentTypeClasses = null;
|
||||||
|
try {
|
||||||
|
componentTypeClasses = Utils.getClasses("org.diylc.parsing");
|
||||||
|
for (Class<?> clazz : componentTypeClasses) {
|
||||||
|
if (!Modifier.isAbstract(clazz.getModifiers()) && IOldFileParser.class.isAssignableFrom(clazz)) {
|
||||||
|
IOldFileParser instance = (IOldFileParser) clazz.newInstance();
|
||||||
|
parsers.add(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error("Could not find old version parsers", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parsers;
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void serializeProjectToFile(Project project, String fileName, boolean isBackup)
|
public synchronized void serializeProjectToFile(Project project, String fileName, boolean isBackup)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (!isBackup) {
|
if (!isBackup) {
|
||||||
@@ -127,7 +103,7 @@ public class ProjectFileManager {
|
|||||||
public Project deserializeProjectFromFile(String fileName, List<String> warnings) throws SAXException, IOException,
|
public Project deserializeProjectFromFile(String fileName, List<String> warnings) throws SAXException, IOException,
|
||||||
ParserConfigurationException {
|
ParserConfigurationException {
|
||||||
LOG.info(String.format("loadProjectFromFile(%s)", fileName));
|
LOG.info(String.format("loadProjectFromFile(%s)", fileName));
|
||||||
Project project;
|
Project project = null;
|
||||||
File file = new File(fileName);
|
File file = new File(fileName);
|
||||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||||
@@ -140,15 +116,16 @@ public class ProjectFileManager {
|
|||||||
throw new IllegalArgumentException("Could not open DIY file. Root node is not named 'Layout'.");
|
throw new IllegalArgumentException("Could not open DIY file. Root node is not named 'Layout'.");
|
||||||
}
|
}
|
||||||
String formatVersion = doc.getDocumentElement().getAttribute("formatVersion");
|
String formatVersion = doc.getDocumentElement().getAttribute("formatVersion");
|
||||||
if (formatVersion == null || formatVersion.trim().isEmpty()) {
|
|
||||||
LOG.debug("Detected v1 file.");
|
// try to find a parser for an older version
|
||||||
project = parseV1File(doc.getDocumentElement(), warnings);
|
List<IOldFileParser> parsers = getParsers();
|
||||||
} else if (formatVersion.equals("2.0")) {
|
for (int i = 0; i < parsers.size(); i++) {
|
||||||
LOG.debug("Detected v2 file.");
|
if (parsers.get(i).canParse(formatVersion))
|
||||||
project = parseV2File(doc.getDocumentElement());
|
project = parsers.get(i).parseFile(doc.getDocumentElement(), warnings);
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Unknown file format version: " + formatVersion);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (project == null)
|
||||||
|
throw new IllegalArgumentException("Unknown file format version: " + formatVersion);
|
||||||
}
|
}
|
||||||
Collections.sort(warnings);
|
Collections.sort(warnings);
|
||||||
this.currentFileName = fileName;
|
this.currentFileName = fileName;
|
||||||
@@ -173,364 +150,6 @@ public class ProjectFileManager {
|
|||||||
messageDispatcher.dispatchMessage(EventType.FILE_STATUS_CHANGED, getCurrentFileName(), isModified());
|
messageDispatcher.dispatchMessage(EventType.FILE_STATUS_CHANGED, getCurrentFileName(), isModified());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Project parseV1File(Element root, List<String> warnings) {
|
|
||||||
Project project = new Project();
|
|
||||||
project.setTitle(root.getAttribute("Project"));
|
|
||||||
project.setAuthor(root.getAttribute("Credits"));
|
|
||||||
project.setGridSpacing(V1_GRID_SPACING);
|
|
||||||
String type = root.getAttribute("Type");
|
|
||||||
|
|
||||||
// Create the board.
|
|
||||||
int width = Integer.parseInt(root.getAttribute("Width")) + 1;
|
|
||||||
int height = Integer.parseInt(root.getAttribute("Height")) + 1;
|
|
||||||
int boardWidth = (int) (width * Constants.PIXELS_PER_INCH * V1_GRID_SPACING.getValue());
|
|
||||||
int boardHeight = (int) (height * Constants.PIXELS_PER_INCH * V1_GRID_SPACING.getValue());
|
|
||||||
int projectWidth = (int) project.getWidth().convertToPixels();
|
|
||||||
int projectHeight = (int) project.getHeight().convertToPixels();
|
|
||||||
int x = (projectWidth - boardWidth) / 2;
|
|
||||||
int y = (projectHeight - boardHeight) / 2;
|
|
||||||
AbstractBoard board;
|
|
||||||
if (type.equalsIgnoreCase("pcb")) {
|
|
||||||
board = new BlankBoard();
|
|
||||||
board.setBoardColor(Color.white);
|
|
||||||
board.setBorderColor(Color.black);
|
|
||||||
} else if (type.equalsIgnoreCase("perfboard")) {
|
|
||||||
board = new PerfBoard();
|
|
||||||
} else if (type.equalsIgnoreCase("stripboard")) {
|
|
||||||
board = new VeroBoard();
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Unrecognized board type: " + type);
|
|
||||||
}
|
|
||||||
board.setName("Main board");
|
|
||||||
Point referencePoint =
|
|
||||||
new Point(CalcUtils.roundToGrid(x, V1_GRID_SPACING), CalcUtils.roundToGrid(y, V1_GRID_SPACING));
|
|
||||||
board.setControlPoint(referencePoint, 0);
|
|
||||||
board.setControlPoint(
|
|
||||||
new Point(CalcUtils.roundToGrid(x + boardWidth, V1_GRID_SPACING), CalcUtils.roundToGrid(y + boardHeight,
|
|
||||||
V1_GRID_SPACING)), 1);
|
|
||||||
project.getComponents().add(board);
|
|
||||||
|
|
||||||
NodeList childNodes = root.getChildNodes();
|
|
||||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
|
||||||
Node node = childNodes.item(i);
|
|
||||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
|
||||||
String nodeName = node.getNodeName();
|
|
||||||
String nameAttr = node.getAttributes().getNamedItem("Name").getNodeValue();
|
|
||||||
Node valueNode = node.getAttributes().getNamedItem("Value");
|
|
||||||
String valueAttr = valueNode == null ? null : valueNode.getNodeValue();
|
|
||||||
int x1Attr = Integer.parseInt(node.getAttributes().getNamedItem("X1").getNodeValue());
|
|
||||||
int y1Attr = Integer.parseInt(node.getAttributes().getNamedItem("Y1").getNodeValue());
|
|
||||||
Point point1 = convertV1CoordinatesToV3Point(referencePoint, x1Attr, y1Attr);
|
|
||||||
Point point2 = null;
|
|
||||||
Integer x2Attr = null;
|
|
||||||
Integer y2Attr = null;
|
|
||||||
Color color = null;
|
|
||||||
if (node.getAttributes().getNamedItem("Color") != null) {
|
|
||||||
String colorAttr = node.getAttributes().getNamedItem("Color").getNodeValue();
|
|
||||||
color = V1_COLOR_MAP.get(colorAttr.toLowerCase());
|
|
||||||
}
|
|
||||||
if (node.getAttributes().getNamedItem("X2") != null && node.getAttributes().getNamedItem("Y2") != null) {
|
|
||||||
x2Attr = Integer.parseInt(node.getAttributes().getNamedItem("X2").getNodeValue());
|
|
||||||
y2Attr = Integer.parseInt(node.getAttributes().getNamedItem("Y2").getNodeValue());
|
|
||||||
point2 = convertV1CoordinatesToV3Point(referencePoint, x2Attr, y2Attr);
|
|
||||||
}
|
|
||||||
IDIYComponent<?> component = null;
|
|
||||||
if (nodeName.equalsIgnoreCase("text")) {
|
|
||||||
LOG.debug("Recognized " + nodeName);
|
|
||||||
Label label = new Label();
|
|
||||||
label.setName(nameAttr);
|
|
||||||
if (color != null) {
|
|
||||||
label.setColor(color);
|
|
||||||
}
|
|
||||||
label.setText(valueAttr);
|
|
||||||
label.setHorizontalAlignment(HorizontalAlignment.LEFT);
|
|
||||||
label.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
||||||
label.setControlPoint(convertV1CoordinatesToV3Point(referencePoint, x1Attr, y1Attr), 0);
|
|
||||||
component = label;
|
|
||||||
} else if (nodeName.equalsIgnoreCase("pad")) {
|
|
||||||
LOG.debug("Recognized " + nodeName);
|
|
||||||
SolderPad pad = new SolderPad();
|
|
||||||
pad.setName(nameAttr);
|
|
||||||
if (color != null) {
|
|
||||||
pad.setColor(color);
|
|
||||||
}
|
|
||||||
pad.setControlPoint(convertV1CoordinatesToV3Point(referencePoint, x1Attr, y1Attr), 0);
|
|
||||||
component = pad;
|
|
||||||
} else if (nodeName.equalsIgnoreCase("trace")) {
|
|
||||||
LOG.debug("Recognized " + nodeName);
|
|
||||||
CopperTrace trace = new CopperTrace();
|
|
||||||
trace.setName(nameAttr);
|
|
||||||
if (color != null) {
|
|
||||||
trace.setLeadColor(color);
|
|
||||||
}
|
|
||||||
trace.setControlPoint(point1, 0);
|
|
||||||
trace.setControlPoint(point2, 1);
|
|
||||||
component = trace;
|
|
||||||
} else if (nodeName.equalsIgnoreCase("jumper")) {
|
|
||||||
LOG.debug("Recognized " + nodeName);
|
|
||||||
Jumper jumper = new Jumper();
|
|
||||||
jumper.setName(nameAttr);
|
|
||||||
jumper.setControlPoint(point1, 0);
|
|
||||||
jumper.setControlPoint(point2, 1);
|
|
||||||
component = jumper;
|
|
||||||
} else if (nodeName.equalsIgnoreCase("wire")) {
|
|
||||||
LOG.debug("Recognized " + nodeName);
|
|
||||||
HookupWire wire = new HookupWire();
|
|
||||||
Point midPoint = new Point((point1.x + point2.x) / 2, (point1.y + point2.y) / 2);
|
|
||||||
wire.setName(nameAttr);
|
|
||||||
String colorAttr = node.getAttributes().getNamedItem("Color").getNodeValue();
|
|
||||||
wire.setColor(parseV1Color(colorAttr));
|
|
||||||
wire.setControlPoint(point1, 0);
|
|
||||||
wire.setControlPoint(midPoint, 1);
|
|
||||||
wire.setControlPoint(midPoint, 2);
|
|
||||||
wire.setControlPoint(point2, 3);
|
|
||||||
component = wire;
|
|
||||||
} else if (nodeName.equalsIgnoreCase("resistor")) {
|
|
||||||
LOG.debug("Recognized " + nodeName);
|
|
||||||
Resistor resistor = new Resistor();
|
|
||||||
resistor.setName(nameAttr);
|
|
||||||
try {
|
|
||||||
resistor.setValue(Resistance.parseResistance(valueAttr));
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.debug("Could not set value of " + nameAttr);
|
|
||||||
}
|
|
||||||
resistor.setLength(new Size(6.35d, SizeUnit.mm));
|
|
||||||
resistor.setWidth(new Size(2.2d, SizeUnit.mm));
|
|
||||||
resistor.setControlPoint(point1, 0);
|
|
||||||
resistor.setControlPoint(point2, 1);
|
|
||||||
component = resistor;
|
|
||||||
} else if (nodeName.equalsIgnoreCase("capacitor")) {
|
|
||||||
LOG.debug("Recognized " + nodeName);
|
|
||||||
RadialFilmCapacitor capacitor = new RadialFilmCapacitor();
|
|
||||||
capacitor.setName(nameAttr);
|
|
||||||
try {
|
|
||||||
capacitor.setValue(Capacitance.parseCapacitance(valueAttr));
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.debug("Could not set value of " + nameAttr);
|
|
||||||
}
|
|
||||||
capacitor.setLength(new Size(6d, SizeUnit.mm));
|
|
||||||
capacitor.setWidth(new Size(2d, SizeUnit.mm));
|
|
||||||
capacitor.setControlPoint(point1, 0);
|
|
||||||
capacitor.setControlPoint(point2, 1);
|
|
||||||
component = capacitor;
|
|
||||||
} else if (nodeName.equalsIgnoreCase("electrolyte")) {
|
|
||||||
LOG.debug("Recognized " + nodeName);
|
|
||||||
RadialElectrolytic capacitor = new RadialElectrolytic();
|
|
||||||
capacitor.setName(nameAttr);
|
|
||||||
try {
|
|
||||||
capacitor.setValue(Capacitance.parseCapacitance(valueAttr));
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.debug("Could not set value of " + nameAttr);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
String sizeAttr = node.getAttributes().getNamedItem("Size").getNodeValue();
|
|
||||||
if (sizeAttr.equalsIgnoreCase("small")) {
|
|
||||||
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")) {
|
|
||||||
capacitor.setLength(new Size(7d, SizeUnit.mm));
|
|
||||||
} else {
|
|
||||||
capacitor.setLength(new Size(4d, SizeUnit.mm));
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
capacitor.setLength(new Size(5d, SizeUnit.mm));
|
|
||||||
LOG.debug("Could not set size of " + nameAttr);
|
|
||||||
}
|
|
||||||
capacitor.setControlPoint(point1, 0);
|
|
||||||
capacitor.setControlPoint(point2, 1);
|
|
||||||
component = capacitor;
|
|
||||||
} else if (nodeName.equalsIgnoreCase("diode")) {
|
|
||||||
LOG.debug("Recognized " + nodeName);
|
|
||||||
DiodePlastic capacitor = new DiodePlastic();
|
|
||||||
capacitor.setName(nameAttr);
|
|
||||||
try {
|
|
||||||
capacitor.setValue(valueAttr);
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.debug("Could not set value of " + nameAttr);
|
|
||||||
}
|
|
||||||
capacitor.setLength(new Size(6d, SizeUnit.mm));
|
|
||||||
capacitor.setWidth(new Size(2d, SizeUnit.mm));
|
|
||||||
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();
|
|
||||||
transistor.setName(nameAttr);
|
|
||||||
try {
|
|
||||||
transistor.setValue(valueAttr);
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.debug("Could not set value of " + nameAttr);
|
|
||||||
}
|
|
||||||
transistor.setControlPoint(point1, 0);
|
|
||||||
if (point1.y > point2.y) {
|
|
||||||
transistor.setOrientation(Orientation._180);
|
|
||||||
} else if (point1.y < point2.y) {
|
|
||||||
transistor.setOrientation(Orientation.DEFAULT);
|
|
||||||
} else if (point1.x < point2.x) {
|
|
||||||
transistor.setOrientation(Orientation._270);
|
|
||||||
} else if (point1.x > point2.x) {
|
|
||||||
transistor.setOrientation(Orientation._90);
|
|
||||||
}
|
|
||||||
// capacitor.setControlPoint(point2, 1);
|
|
||||||
component = transistor;
|
|
||||||
} else if (nodeName.equalsIgnoreCase("ic")) {
|
|
||||||
LOG.debug("Recognized " + nodeName);
|
|
||||||
DIL_IC ic = new DIL_IC();
|
|
||||||
int pinCount = 8;
|
|
||||||
int rowSpace = 3;
|
|
||||||
if (x1Attr < x2Attr && y1Attr < y2Attr) {
|
|
||||||
pinCount = (y2Attr - y1Attr + 1) * 2;
|
|
||||||
rowSpace = x2Attr - x1Attr;
|
|
||||||
ic.setOrientation(Orientation.DEFAULT);
|
|
||||||
} else if (x1Attr > x2Attr && y1Attr < y2Attr) {
|
|
||||||
pinCount = (x1Attr - x2Attr + 1) * 2;
|
|
||||||
rowSpace = y2Attr - y1Attr;
|
|
||||||
ic.setOrientation(Orientation._90);
|
|
||||||
} else if (x1Attr > x2Attr && y1Attr > y2Attr) {
|
|
||||||
rowSpace = x1Attr - x2Attr;
|
|
||||||
pinCount = (y1Attr - y2Attr + 1) * 2;
|
|
||||||
ic.setOrientation(Orientation._180);
|
|
||||||
} else if (x1Attr < x2Attr && y1Attr > y2Attr) {
|
|
||||||
rowSpace = y1Attr - y2Attr;
|
|
||||||
pinCount = (x2Attr - x1Attr + 1) * 2;
|
|
||||||
ic.setOrientation(Orientation._270);
|
|
||||||
}
|
|
||||||
ic.setRowSpacing(new Size(0.1 * rowSpace, SizeUnit.in));
|
|
||||||
ic.setPinCount(DIL_IC.PinCount.valueOf("_" + pinCount));
|
|
||||||
ic.setName(nameAttr);
|
|
||||||
// Translate control points.
|
|
||||||
for (int j = 0; j < ic.getControlPointCount(); j++) {
|
|
||||||
Point p = new Point(ic.getControlPoint(j));
|
|
||||||
p.translate(point1.x, point1.y);
|
|
||||||
ic.setControlPoint(p, j);
|
|
||||||
}
|
|
||||||
ic.setValue(valueAttr);
|
|
||||||
component = ic;
|
|
||||||
} else if (nodeName.equalsIgnoreCase("pot")) {
|
|
||||||
LOG.debug("Recognized " + nodeName);
|
|
||||||
PotentiometerPanel pot = new PotentiometerPanel();
|
|
||||||
pot.setBodyDiameter(new Size(14d, SizeUnit.mm));
|
|
||||||
pot.setSpacing(new Size(0.2, SizeUnit.in));
|
|
||||||
pot.setName(nameAttr);
|
|
||||||
try {
|
|
||||||
pot.setValue(Resistance.parseResistance(valueAttr));
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.debug("Could not set value of " + nameAttr);
|
|
||||||
}
|
|
||||||
String taperAttr = node.getAttributes().getNamedItem("Taper").getNodeValue();
|
|
||||||
if ("Linear".equals(taperAttr)) {
|
|
||||||
pot.setTaper(Taper.LIN);
|
|
||||||
} else if ("Audio".equals(taperAttr)) {
|
|
||||||
pot.setTaper(Taper.LOG);
|
|
||||||
} else if ("Reverse Audio".equals(taperAttr)) {
|
|
||||||
pot.setTaper(Taper.REV_LOG);
|
|
||||||
}
|
|
||||||
// Pin spacing, we'll need to move pot around a bit.
|
|
||||||
int delta = Constants.PIXELS_PER_INCH / 5;
|
|
||||||
if (x1Attr < x2Attr) {
|
|
||||||
pot.setOrientation(Orientation.DEFAULT);
|
|
||||||
for (int j = 0; j < pot.getControlPointCount(); j++) {
|
|
||||||
Point p = new Point(pot.getControlPoint(j));
|
|
||||||
p.translate(point1.x - delta, point1.y);
|
|
||||||
pot.setControlPoint(p, j);
|
|
||||||
}
|
|
||||||
} else if (x1Attr > x2Attr) {
|
|
||||||
pot.setOrientation(Orientation._180);
|
|
||||||
for (int j = 0; j < pot.getControlPointCount(); j++) {
|
|
||||||
Point p = new Point(pot.getControlPoint(j));
|
|
||||||
p.translate(point1.x + delta, point1.y);
|
|
||||||
pot.setControlPoint(p, j);
|
|
||||||
}
|
|
||||||
} else if (y1Attr < y2Attr) {
|
|
||||||
pot.setOrientation(Orientation._90);
|
|
||||||
for (int j = 0; j < pot.getControlPointCount(); j++) {
|
|
||||||
Point p = new Point(pot.getControlPoint(j));
|
|
||||||
p.translate(point1.x, point1.y - delta);
|
|
||||||
pot.setControlPoint(p, j);
|
|
||||||
}
|
|
||||||
} else if (y1Attr > y2Attr) {
|
|
||||||
pot.setOrientation(Orientation._270);
|
|
||||||
for (int j = 0; j < pot.getControlPointCount(); j++) {
|
|
||||||
Point p = new Point(pot.getControlPoint(j));
|
|
||||||
p.translate(point1.x, point1.y + delta);
|
|
||||||
pot.setControlPoint(p, j);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
component = pot;
|
|
||||||
} else {
|
|
||||||
String message = "Could not recognize component type " + nodeName;
|
|
||||||
LOG.debug(message);
|
|
||||||
if (!warnings.contains(message)) {
|
|
||||||
warnings.add(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (component != null) {
|
|
||||||
if (component instanceof AbstractLeadedComponent<?>) {
|
|
||||||
((AbstractLeadedComponent<?>) component).setDisplay(Display.NAME);
|
|
||||||
}
|
|
||||||
if (component instanceof AbstractTransparentComponent<?>) {
|
|
||||||
((AbstractTransparentComponent<?>) component).setAlpha((byte) 100);
|
|
||||||
}
|
|
||||||
project.getComponents().add(component);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Collections.sort(project.getComponents(), ComparatorFactory.getInstance().getComponentZOrderComparator());
|
|
||||||
return project;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Point convertV1CoordinatesToV3Point(Point reference, int x, int y) {
|
|
||||||
Point point = new Point(reference);
|
|
||||||
point.translate((int) (x * Constants.PIXELS_PER_INCH * V1_GRID_SPACING.getValue()), (int) (y
|
|
||||||
* Constants.PIXELS_PER_INCH * V1_GRID_SPACING.getValue()));
|
|
||||||
return point;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Color parseV1Color(String color) {
|
|
||||||
if ("brown".equals(color.toLowerCase()))
|
|
||||||
return new Color(139, 69, 19);
|
|
||||||
try {
|
|
||||||
Field field = Color.class.getDeclaredField(color.toLowerCase());
|
|
||||||
return (Color) field.get(null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.error("Could not parse color \"" + color + "\"", e);
|
|
||||||
return Color.black;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Project parseV2File(Element root) {
|
|
||||||
Project project = new Project();
|
|
||||||
String projectName = root.getAttribute("projectName");
|
|
||||||
String credits = root.getAttribute("credits");
|
|
||||||
String width = root.getAttribute("width");
|
|
||||||
String height = root.getAttribute("height");
|
|
||||||
NodeList childNodes = root.getChildNodes();
|
|
||||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
|
||||||
Node node = childNodes.item(i);
|
|
||||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
|
||||||
if (node.getNodeName().equalsIgnoreCase("component")) {
|
|
||||||
LOG.debug(node.getAttributes().getNamedItem("name").getNodeValue());
|
|
||||||
} else {
|
|
||||||
LOG.debug("Unrecognized node name found: " + node.getNodeName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return project;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Project parseV3File(String fileName) throws IOException {
|
private Project parseV3File(String fileName) throws IOException {
|
||||||
Project project;
|
Project project;
|
||||||
FileInputStream fis = new FileInputStream(fileName);
|
FileInputStream fis = new FileInputStream(fileName);
|
||||||
|
|||||||
@@ -49,10 +49,7 @@
|
|||||||
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}" />
|
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}" />
|
||||||
<copy todir="../diylc-swing/library" overwrite="true">
|
<copy todir="../diylc-swing/library" overwrite="true">
|
||||||
<fileset dir="${jar.dir}" includes="${ant.project.name}.jar" />
|
<fileset dir="${jar.dir}" includes="${ant.project.name}.jar" />
|
||||||
</copy>
|
</copy>
|
||||||
<copy todir="../diylc-core/library" overwrite="true">
|
|
||||||
<fileset dir="${jar.dir}" includes="${ant.project.name}.jar" />
|
|
||||||
</copy>
|
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="javadoc">
|
<target name="javadoc">
|
||||||
|
|||||||
@@ -11,13 +11,16 @@ import org.diylc.core.IDIYComponent;
|
|||||||
import org.diylc.core.IDrawingObserver;
|
import org.diylc.core.IDrawingObserver;
|
||||||
import org.diylc.core.Project;
|
import org.diylc.core.Project;
|
||||||
import org.diylc.core.VisibilityPolicy;
|
import org.diylc.core.VisibilityPolicy;
|
||||||
|
import org.diylc.core.annotations.AutoCreated;
|
||||||
import org.diylc.core.annotations.BomPolicy;
|
import org.diylc.core.annotations.BomPolicy;
|
||||||
import org.diylc.core.annotations.ComponentDescriptor;
|
import org.diylc.core.annotations.ComponentDescriptor;
|
||||||
import org.diylc.core.annotations.EditableProperty;
|
import org.diylc.core.annotations.EditableProperty;
|
||||||
|
import org.diylc.core.annotations.PositiveMeasureValidator;
|
||||||
import org.diylc.core.measures.Size;
|
import org.diylc.core.measures.Size;
|
||||||
import org.diylc.core.measures.SizeUnit;
|
import org.diylc.core.measures.SizeUnit;
|
||||||
import org.diylc.utils.Constants;
|
import org.diylc.utils.Constants;
|
||||||
|
|
||||||
|
@AutoCreated(name = "SolderPad")
|
||||||
@ComponentDescriptor(name = "Solder Pad", category = "Connectivity", author = "Branislav Stojkovic",
|
@ComponentDescriptor(name = "Solder Pad", category = "Connectivity", author = "Branislav Stojkovic",
|
||||||
description = "Copper solder pad, round or square", instanceNamePrefix = "Pad", stretchable = false,
|
description = "Copper solder pad, round or square", instanceNamePrefix = "Pad", stretchable = false,
|
||||||
zOrder = IDIYComponent.TRACE + 0.1, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false)
|
zOrder = IDIYComponent.TRACE + 0.1, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false)
|
||||||
@@ -67,7 +70,7 @@ public class SolderPad extends AbstractComponent<Void> {
|
|||||||
g2d.fillOval((width - holeDiameter) / 2, (height - holeDiameter) / 2, holeDiameter, holeDiameter);
|
g2d.fillOval((width - holeDiameter) / 2, (height - holeDiameter) / 2, holeDiameter, holeDiameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EditableProperty
|
@EditableProperty(validatorClass = PositiveMeasureValidator.class)
|
||||||
public Size getSize() {
|
public Size getSize() {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,407 @@
|
|||||||
|
package org.diylc.parsing;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.diylc.common.Display;
|
||||||
|
import org.diylc.common.HorizontalAlignment;
|
||||||
|
import org.diylc.common.Orientation;
|
||||||
|
import org.diylc.common.VerticalAlignment;
|
||||||
|
import org.diylc.components.AbstractLeadedComponent;
|
||||||
|
import org.diylc.components.AbstractTransparentComponent;
|
||||||
|
import org.diylc.components.boards.AbstractBoard;
|
||||||
|
import org.diylc.components.boards.BlankBoard;
|
||||||
|
import org.diylc.components.boards.PerfBoard;
|
||||||
|
import org.diylc.components.boards.VeroBoard;
|
||||||
|
import org.diylc.components.connectivity.CopperTrace;
|
||||||
|
import org.diylc.components.connectivity.HookupWire;
|
||||||
|
import org.diylc.components.connectivity.Jumper;
|
||||||
|
import org.diylc.components.connectivity.SolderPad;
|
||||||
|
import org.diylc.components.misc.Label;
|
||||||
|
import org.diylc.components.passive.PotentiometerPanel;
|
||||||
|
import org.diylc.components.passive.RadialElectrolytic;
|
||||||
|
import org.diylc.components.passive.RadialFilmCapacitor;
|
||||||
|
import org.diylc.components.passive.Resistor;
|
||||||
|
import org.diylc.components.passive.Taper;
|
||||||
|
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;
|
||||||
|
import org.diylc.core.measures.Capacitance;
|
||||||
|
import org.diylc.core.measures.Resistance;
|
||||||
|
import org.diylc.core.measures.Size;
|
||||||
|
import org.diylc.core.measures.SizeUnit;
|
||||||
|
import org.diylc.presenter.CalcUtils;
|
||||||
|
import org.diylc.presenter.ComparatorFactory;
|
||||||
|
import org.diylc.utils.Constants;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
|
public class V1FileParser implements IOldFileParser {
|
||||||
|
|
||||||
|
private static final Logger LOG = Logger.getLogger(V1FileParser.class);
|
||||||
|
|
||||||
|
private static final Size V1_GRID_SPACING = new Size(0.1d, SizeUnit.in);
|
||||||
|
private static final Map<String, Color> V1_COLOR_MAP = new HashMap<String, Color>();
|
||||||
|
static {
|
||||||
|
V1_COLOR_MAP.put("red", Color.red);
|
||||||
|
V1_COLOR_MAP.put("blue", Color.blue);
|
||||||
|
V1_COLOR_MAP.put("white", Color.white);
|
||||||
|
V1_COLOR_MAP.put("green", Color.green.darker());
|
||||||
|
V1_COLOR_MAP.put("black", Color.black);
|
||||||
|
V1_COLOR_MAP.put("yellow", Color.yellow);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canParse(String version) {
|
||||||
|
return version == null || version.trim().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Project parseFile(Element root, List<String> warnings) {
|
||||||
|
Project project = new Project();
|
||||||
|
project.setTitle(root.getAttribute("Project"));
|
||||||
|
project.setAuthor(root.getAttribute("Credits"));
|
||||||
|
project.setGridSpacing(V1_GRID_SPACING);
|
||||||
|
String type = root.getAttribute("Type");
|
||||||
|
|
||||||
|
// Create the board.
|
||||||
|
int width = Integer.parseInt(root.getAttribute("Width")) + 1;
|
||||||
|
int height = Integer.parseInt(root.getAttribute("Height")) + 1;
|
||||||
|
int boardWidth = (int) (width * Constants.PIXELS_PER_INCH * V1_GRID_SPACING.getValue());
|
||||||
|
int boardHeight = (int) (height * Constants.PIXELS_PER_INCH * V1_GRID_SPACING.getValue());
|
||||||
|
int projectWidth = (int) project.getWidth().convertToPixels();
|
||||||
|
int projectHeight = (int) project.getHeight().convertToPixels();
|
||||||
|
int x = (projectWidth - boardWidth) / 2;
|
||||||
|
int y = (projectHeight - boardHeight) / 2;
|
||||||
|
AbstractBoard board;
|
||||||
|
if (type.equalsIgnoreCase("pcb")) {
|
||||||
|
board = new BlankBoard();
|
||||||
|
board.setBoardColor(Color.white);
|
||||||
|
board.setBorderColor(Color.black);
|
||||||
|
} else if (type.equalsIgnoreCase("perfboard")) {
|
||||||
|
board = new PerfBoard();
|
||||||
|
} else if (type.equalsIgnoreCase("stripboard")) {
|
||||||
|
board = new VeroBoard();
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Unrecognized board type: " + type);
|
||||||
|
}
|
||||||
|
board.setName("Main board");
|
||||||
|
Point referencePoint =
|
||||||
|
new Point(CalcUtils.roundToGrid(x, V1_GRID_SPACING), CalcUtils.roundToGrid(y, V1_GRID_SPACING));
|
||||||
|
board.setControlPoint(referencePoint, 0);
|
||||||
|
board.setControlPoint(
|
||||||
|
new Point(CalcUtils.roundToGrid(x + boardWidth, V1_GRID_SPACING), CalcUtils.roundToGrid(y + boardHeight,
|
||||||
|
V1_GRID_SPACING)), 1);
|
||||||
|
project.getComponents().add(board);
|
||||||
|
|
||||||
|
NodeList childNodes = root.getChildNodes();
|
||||||
|
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||||
|
Node node = childNodes.item(i);
|
||||||
|
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
|
String nodeName = node.getNodeName();
|
||||||
|
String nameAttr = node.getAttributes().getNamedItem("Name").getNodeValue();
|
||||||
|
Node valueNode = node.getAttributes().getNamedItem("Value");
|
||||||
|
String valueAttr = valueNode == null ? null : valueNode.getNodeValue();
|
||||||
|
int x1Attr = Integer.parseInt(node.getAttributes().getNamedItem("X1").getNodeValue());
|
||||||
|
int y1Attr = Integer.parseInt(node.getAttributes().getNamedItem("Y1").getNodeValue());
|
||||||
|
Point point1 = convertV1CoordinatesToV3Point(referencePoint, x1Attr, y1Attr);
|
||||||
|
Point point2 = null;
|
||||||
|
Integer x2Attr = null;
|
||||||
|
Integer y2Attr = null;
|
||||||
|
Color color = null;
|
||||||
|
if (node.getAttributes().getNamedItem("Color") != null) {
|
||||||
|
String colorAttr = node.getAttributes().getNamedItem("Color").getNodeValue();
|
||||||
|
color = V1_COLOR_MAP.get(colorAttr.toLowerCase());
|
||||||
|
}
|
||||||
|
if (node.getAttributes().getNamedItem("X2") != null && node.getAttributes().getNamedItem("Y2") != null) {
|
||||||
|
x2Attr = Integer.parseInt(node.getAttributes().getNamedItem("X2").getNodeValue());
|
||||||
|
y2Attr = Integer.parseInt(node.getAttributes().getNamedItem("Y2").getNodeValue());
|
||||||
|
point2 = convertV1CoordinatesToV3Point(referencePoint, x2Attr, y2Attr);
|
||||||
|
}
|
||||||
|
IDIYComponent<?> component = null;
|
||||||
|
if (nodeName.equalsIgnoreCase("text")) {
|
||||||
|
LOG.debug("Recognized " + nodeName);
|
||||||
|
Label label = new Label();
|
||||||
|
label.setName(nameAttr);
|
||||||
|
if (color != null) {
|
||||||
|
label.setColor(color);
|
||||||
|
}
|
||||||
|
label.setText(valueAttr);
|
||||||
|
label.setHorizontalAlignment(HorizontalAlignment.LEFT);
|
||||||
|
label.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
|
label.setControlPoint(convertV1CoordinatesToV3Point(referencePoint, x1Attr, y1Attr), 0);
|
||||||
|
component = label;
|
||||||
|
} else if (nodeName.equalsIgnoreCase("pad")) {
|
||||||
|
LOG.debug("Recognized " + nodeName);
|
||||||
|
SolderPad pad = new SolderPad();
|
||||||
|
pad.setName(nameAttr);
|
||||||
|
if (color != null) {
|
||||||
|
pad.setColor(color);
|
||||||
|
}
|
||||||
|
pad.setControlPoint(convertV1CoordinatesToV3Point(referencePoint, x1Attr, y1Attr), 0);
|
||||||
|
component = pad;
|
||||||
|
} else if (nodeName.equalsIgnoreCase("trace")) {
|
||||||
|
LOG.debug("Recognized " + nodeName);
|
||||||
|
CopperTrace trace = new CopperTrace();
|
||||||
|
trace.setName(nameAttr);
|
||||||
|
if (color != null) {
|
||||||
|
trace.setLeadColor(color);
|
||||||
|
}
|
||||||
|
trace.setControlPoint(point1, 0);
|
||||||
|
trace.setControlPoint(point2, 1);
|
||||||
|
component = trace;
|
||||||
|
} else if (nodeName.equalsIgnoreCase("jumper")) {
|
||||||
|
LOG.debug("Recognized " + nodeName);
|
||||||
|
Jumper jumper = new Jumper();
|
||||||
|
jumper.setName(nameAttr);
|
||||||
|
jumper.setControlPoint(point1, 0);
|
||||||
|
jumper.setControlPoint(point2, 1);
|
||||||
|
component = jumper;
|
||||||
|
} else if (nodeName.equalsIgnoreCase("wire")) {
|
||||||
|
LOG.debug("Recognized " + nodeName);
|
||||||
|
HookupWire wire = new HookupWire();
|
||||||
|
Point midPoint = new Point((point1.x + point2.x) / 2, (point1.y + point2.y) / 2);
|
||||||
|
wire.setName(nameAttr);
|
||||||
|
String colorAttr = node.getAttributes().getNamedItem("Color").getNodeValue();
|
||||||
|
wire.setColor(parseV1Color(colorAttr));
|
||||||
|
wire.setControlPoint(point1, 0);
|
||||||
|
wire.setControlPoint(midPoint, 1);
|
||||||
|
wire.setControlPoint(midPoint, 2);
|
||||||
|
wire.setControlPoint(point2, 3);
|
||||||
|
component = wire;
|
||||||
|
} else if (nodeName.equalsIgnoreCase("resistor")) {
|
||||||
|
LOG.debug("Recognized " + nodeName);
|
||||||
|
Resistor resistor = new Resistor();
|
||||||
|
resistor.setName(nameAttr);
|
||||||
|
try {
|
||||||
|
resistor.setValue(Resistance.parseResistance(valueAttr));
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.debug("Could not set value of " + nameAttr);
|
||||||
|
}
|
||||||
|
resistor.setLength(new Size(6.35d, SizeUnit.mm));
|
||||||
|
resistor.setWidth(new Size(2.2d, SizeUnit.mm));
|
||||||
|
resistor.setControlPoint(point1, 0);
|
||||||
|
resistor.setControlPoint(point2, 1);
|
||||||
|
component = resistor;
|
||||||
|
} else if (nodeName.equalsIgnoreCase("capacitor")) {
|
||||||
|
LOG.debug("Recognized " + nodeName);
|
||||||
|
RadialFilmCapacitor capacitor = new RadialFilmCapacitor();
|
||||||
|
capacitor.setName(nameAttr);
|
||||||
|
try {
|
||||||
|
capacitor.setValue(Capacitance.parseCapacitance(valueAttr));
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.debug("Could not set value of " + nameAttr);
|
||||||
|
}
|
||||||
|
capacitor.setLength(new Size(6d, SizeUnit.mm));
|
||||||
|
capacitor.setWidth(new Size(2d, SizeUnit.mm));
|
||||||
|
capacitor.setControlPoint(point1, 0);
|
||||||
|
capacitor.setControlPoint(point2, 1);
|
||||||
|
component = capacitor;
|
||||||
|
} else if (nodeName.equalsIgnoreCase("electrolyte")) {
|
||||||
|
LOG.debug("Recognized " + nodeName);
|
||||||
|
RadialElectrolytic capacitor = new RadialElectrolytic();
|
||||||
|
capacitor.setName(nameAttr);
|
||||||
|
try {
|
||||||
|
capacitor.setValue(Capacitance.parseCapacitance(valueAttr));
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.debug("Could not set value of " + nameAttr);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
String sizeAttr = node.getAttributes().getNamedItem("Size").getNodeValue();
|
||||||
|
if (sizeAttr.equalsIgnoreCase("small")) {
|
||||||
|
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")) {
|
||||||
|
capacitor.setLength(new Size(7d, SizeUnit.mm));
|
||||||
|
} else {
|
||||||
|
capacitor.setLength(new Size(4d, SizeUnit.mm));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
capacitor.setLength(new Size(5d, SizeUnit.mm));
|
||||||
|
LOG.debug("Could not set size of " + nameAttr);
|
||||||
|
}
|
||||||
|
capacitor.setControlPoint(point1, 0);
|
||||||
|
capacitor.setControlPoint(point2, 1);
|
||||||
|
component = capacitor;
|
||||||
|
} else if (nodeName.equalsIgnoreCase("diode")) {
|
||||||
|
LOG.debug("Recognized " + nodeName);
|
||||||
|
DiodePlastic capacitor = new DiodePlastic();
|
||||||
|
capacitor.setName(nameAttr);
|
||||||
|
try {
|
||||||
|
capacitor.setValue(valueAttr);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.debug("Could not set value of " + nameAttr);
|
||||||
|
}
|
||||||
|
capacitor.setLength(new Size(6d, SizeUnit.mm));
|
||||||
|
capacitor.setWidth(new Size(2d, SizeUnit.mm));
|
||||||
|
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();
|
||||||
|
transistor.setName(nameAttr);
|
||||||
|
try {
|
||||||
|
transistor.setValue(valueAttr);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.debug("Could not set value of " + nameAttr);
|
||||||
|
}
|
||||||
|
transistor.setControlPoint(point1, 0);
|
||||||
|
if (point1.y > point2.y) {
|
||||||
|
transistor.setOrientation(Orientation._180);
|
||||||
|
} else if (point1.y < point2.y) {
|
||||||
|
transistor.setOrientation(Orientation.DEFAULT);
|
||||||
|
} else if (point1.x < point2.x) {
|
||||||
|
transistor.setOrientation(Orientation._270);
|
||||||
|
} else if (point1.x > point2.x) {
|
||||||
|
transistor.setOrientation(Orientation._90);
|
||||||
|
}
|
||||||
|
// capacitor.setControlPoint(point2, 1);
|
||||||
|
component = transistor;
|
||||||
|
} else if (nodeName.equalsIgnoreCase("ic")) {
|
||||||
|
LOG.debug("Recognized " + nodeName);
|
||||||
|
DIL_IC ic = new DIL_IC();
|
||||||
|
int pinCount = 8;
|
||||||
|
int rowSpace = 3;
|
||||||
|
if (x1Attr < x2Attr && y1Attr < y2Attr) {
|
||||||
|
pinCount = (y2Attr - y1Attr + 1) * 2;
|
||||||
|
rowSpace = x2Attr - x1Attr;
|
||||||
|
ic.setOrientation(Orientation.DEFAULT);
|
||||||
|
} else if (x1Attr > x2Attr && y1Attr < y2Attr) {
|
||||||
|
pinCount = (x1Attr - x2Attr + 1) * 2;
|
||||||
|
rowSpace = y2Attr - y1Attr;
|
||||||
|
ic.setOrientation(Orientation._90);
|
||||||
|
} else if (x1Attr > x2Attr && y1Attr > y2Attr) {
|
||||||
|
rowSpace = x1Attr - x2Attr;
|
||||||
|
pinCount = (y1Attr - y2Attr + 1) * 2;
|
||||||
|
ic.setOrientation(Orientation._180);
|
||||||
|
} else if (x1Attr < x2Attr && y1Attr > y2Attr) {
|
||||||
|
rowSpace = y1Attr - y2Attr;
|
||||||
|
pinCount = (x2Attr - x1Attr + 1) * 2;
|
||||||
|
ic.setOrientation(Orientation._270);
|
||||||
|
}
|
||||||
|
ic.setRowSpacing(new Size(0.1 * rowSpace, SizeUnit.in));
|
||||||
|
ic.setPinCount(DIL_IC.PinCount.valueOf("_" + pinCount));
|
||||||
|
ic.setName(nameAttr);
|
||||||
|
// Translate control points.
|
||||||
|
for (int j = 0; j < ic.getControlPointCount(); j++) {
|
||||||
|
Point p = new Point(ic.getControlPoint(j));
|
||||||
|
p.translate(point1.x, point1.y);
|
||||||
|
ic.setControlPoint(p, j);
|
||||||
|
}
|
||||||
|
ic.setValue(valueAttr);
|
||||||
|
component = ic;
|
||||||
|
} else if (nodeName.equalsIgnoreCase("pot")) {
|
||||||
|
LOG.debug("Recognized " + nodeName);
|
||||||
|
PotentiometerPanel pot = new PotentiometerPanel();
|
||||||
|
pot.setBodyDiameter(new Size(14d, SizeUnit.mm));
|
||||||
|
pot.setSpacing(new Size(0.2, SizeUnit.in));
|
||||||
|
pot.setName(nameAttr);
|
||||||
|
try {
|
||||||
|
pot.setValue(Resistance.parseResistance(valueAttr));
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.debug("Could not set value of " + nameAttr);
|
||||||
|
}
|
||||||
|
String taperAttr = node.getAttributes().getNamedItem("Taper").getNodeValue();
|
||||||
|
if ("Linear".equals(taperAttr)) {
|
||||||
|
pot.setTaper(Taper.LIN);
|
||||||
|
} else if ("Audio".equals(taperAttr)) {
|
||||||
|
pot.setTaper(Taper.LOG);
|
||||||
|
} else if ("Reverse Audio".equals(taperAttr)) {
|
||||||
|
pot.setTaper(Taper.REV_LOG);
|
||||||
|
}
|
||||||
|
// Pin spacing, we'll need to move pot around a bit.
|
||||||
|
int delta = Constants.PIXELS_PER_INCH / 5;
|
||||||
|
if (x1Attr < x2Attr) {
|
||||||
|
pot.setOrientation(Orientation.DEFAULT);
|
||||||
|
for (int j = 0; j < pot.getControlPointCount(); j++) {
|
||||||
|
Point p = new Point(pot.getControlPoint(j));
|
||||||
|
p.translate(point1.x - delta, point1.y);
|
||||||
|
pot.setControlPoint(p, j);
|
||||||
|
}
|
||||||
|
} else if (x1Attr > x2Attr) {
|
||||||
|
pot.setOrientation(Orientation._180);
|
||||||
|
for (int j = 0; j < pot.getControlPointCount(); j++) {
|
||||||
|
Point p = new Point(pot.getControlPoint(j));
|
||||||
|
p.translate(point1.x + delta, point1.y);
|
||||||
|
pot.setControlPoint(p, j);
|
||||||
|
}
|
||||||
|
} else if (y1Attr < y2Attr) {
|
||||||
|
pot.setOrientation(Orientation._90);
|
||||||
|
for (int j = 0; j < pot.getControlPointCount(); j++) {
|
||||||
|
Point p = new Point(pot.getControlPoint(j));
|
||||||
|
p.translate(point1.x, point1.y - delta);
|
||||||
|
pot.setControlPoint(p, j);
|
||||||
|
}
|
||||||
|
} else if (y1Attr > y2Attr) {
|
||||||
|
pot.setOrientation(Orientation._270);
|
||||||
|
for (int j = 0; j < pot.getControlPointCount(); j++) {
|
||||||
|
Point p = new Point(pot.getControlPoint(j));
|
||||||
|
p.translate(point1.x, point1.y + delta);
|
||||||
|
pot.setControlPoint(p, j);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
component = pot;
|
||||||
|
} else {
|
||||||
|
String message = "Could not recognize component type " + nodeName;
|
||||||
|
LOG.debug(message);
|
||||||
|
if (!warnings.contains(message)) {
|
||||||
|
warnings.add(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (component != null) {
|
||||||
|
if (component instanceof AbstractLeadedComponent<?>) {
|
||||||
|
((AbstractLeadedComponent<?>) component).setDisplay(Display.NAME);
|
||||||
|
}
|
||||||
|
if (component instanceof AbstractTransparentComponent<?>) {
|
||||||
|
((AbstractTransparentComponent<?>) component).setAlpha((byte) 100);
|
||||||
|
}
|
||||||
|
project.getComponents().add(component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Collections.sort(project.getComponents(), ComparatorFactory.getInstance().getComponentZOrderComparator());
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Point convertV1CoordinatesToV3Point(Point reference, int x, int y) {
|
||||||
|
Point point = new Point(reference);
|
||||||
|
point.translate((int) (x * Constants.PIXELS_PER_INCH * V1_GRID_SPACING.getValue()), (int) (y
|
||||||
|
* Constants.PIXELS_PER_INCH * V1_GRID_SPACING.getValue()));
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Color parseV1Color(String color) {
|
||||||
|
if ("brown".equals(color.toLowerCase()))
|
||||||
|
return new Color(139, 69, 19);
|
||||||
|
try {
|
||||||
|
Field field = Color.class.getDeclaredField(color.toLowerCase());
|
||||||
|
return (Color) field.get(null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error("Could not parse color \"" + color + "\"", e);
|
||||||
|
return Color.black;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package org.diylc.parsing;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.diylc.core.Project;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
|
public class V2FileParser implements IOldFileParser {
|
||||||
|
|
||||||
|
private static final Logger LOG = Logger.getLogger(V2FileParser.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canParse(String version) {
|
||||||
|
return version.equals("2.0");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Project parseFile(Element root, List<String> warnings) {
|
||||||
|
Project project = new Project();
|
||||||
|
String projectName = root.getAttribute("projectName");
|
||||||
|
String credits = root.getAttribute("credits");
|
||||||
|
String width = root.getAttribute("width");
|
||||||
|
String height = root.getAttribute("height");
|
||||||
|
NodeList childNodes = root.getChildNodes();
|
||||||
|
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||||
|
Node node = childNodes.item(i);
|
||||||
|
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
|
if (node.getNodeName().equalsIgnoreCase("component")) {
|
||||||
|
LOG.debug(node.getAttributes().getNamedItem("name").getNodeValue());
|
||||||
|
} else {
|
||||||
|
LOG.debug("Unrecognized node name found: " + node.getNodeName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
<classpathentry kind="lib" path="lib/jettison-1.0.1.jar"/>
|
<classpathentry kind="lib" path="lib/jettison-1.0.1.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/app-framework.jar"/>
|
<classpathentry kind="lib" path="lib/app-framework.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/swing-framework.jar"/>
|
<classpathentry kind="lib" path="lib/swing-framework.jar"/>
|
||||||
|
<classpathentry kind="lib" path="library/main.jar"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/diylc-core"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/diylc-core"/>
|
||||||
<classpathentry kind="lib" path="lib/xstream-1.4.3.jar"/>
|
<classpathentry kind="lib" path="lib/xstream-1.4.3.jar"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_45"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_45"/>
|
||||||
|
|||||||
@@ -1357,7 +1357,11 @@
|
|||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>BUG_FIX</changeType>
|
<changeType>BUG_FIX</changeType>
|
||||||
<description>Changing Display to one trimmer affects all trimmers and does not get saved to the file</description>
|
<description>Changing Display to one trimmer affects all trimmers and does not get saved to the file</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>BUG_FIX</changeType>
|
||||||
|
<description>Solder pad component should not allow negative size</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
</changes>
|
</changes>
|
||||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||||
</org.diylc.appframework.update.Version>
|
</org.diylc.appframework.update.Version>
|
||||||
|
|||||||
Reference in New Issue
Block a user