Remove junk from BOM (eyelets, wires, traces)

This commit is contained in:
bancika
2012-08-16 15:51:21 +00:00
parent ccc90dd3a6
commit 162b67bf25
6 changed files with 52 additions and 7 deletions
@@ -4,6 +4,7 @@ import javax.swing.Icon;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.BomPolicy;
/**
* Entity class used to describe a component type.
@@ -24,10 +25,12 @@ public class ComponentType {
private Class<? extends IDIYComponent<?>> instanceClass;
private double zOrder;
private boolean stretchable;
private BomPolicy bomPolicy;
public ComponentType(String name, String description, CreationMethod creationMethod,
String category, String namePrefix, String author, Icon icon,
Class<? extends IDIYComponent<?>> instanceClass, double zOrder, boolean stretchable) {
Class<? extends IDIYComponent<?>> instanceClass, double zOrder,
boolean stretchable, BomPolicy bomPolicy) {
super();
this.name = name;
this.description = description;
@@ -39,6 +42,7 @@ public class ComponentType {
this.instanceClass = instanceClass;
this.zOrder = zOrder;
this.stretchable = stretchable;
this.bomPolicy = bomPolicy;
}
public String getName() {
@@ -80,6 +84,10 @@ public class ComponentType {
public boolean isStretchable() {
return stretchable;
}
public BomPolicy getBomPolicy() {
return bomPolicy;
}
@Override
public String toString() {
@@ -14,7 +14,7 @@ import org.diylc.core.IDIYComponent;
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface ComponentDescriptor {
/**
* @return component type name.
*/
@@ -58,5 +58,10 @@ public @interface ComponentDescriptor {
* move together with it.
*/
boolean stretchable() default true;
/**
* @return controls what should be shown the BOM
*/
BomPolicy bomPolicy() default BomPolicy.SHOW_ALL_NAMES;
}
@@ -20,6 +20,7 @@ import org.diylc.common.PropertyWrapper;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IPropertyValidator;
import org.diylc.core.annotations.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
@@ -70,6 +71,7 @@ public class ComponentProcessor {
Icon icon;
double zOrder;
boolean stretchable;
BomPolicy bomPolicy;
if (clazz.isAnnotationPresent(ComponentDescriptor.class)) {
ComponentDescriptor annotation = clazz.getAnnotation(ComponentDescriptor.class);
name = annotation.name();
@@ -80,6 +82,7 @@ public class ComponentProcessor {
author = annotation.author();
zOrder = annotation.zOrder();
stretchable = annotation.stretchable();
bomPolicy = annotation.bomPolicy();
} else {
name = clazz.getSimpleName();
description = "";
@@ -89,6 +92,7 @@ public class ComponentProcessor {
author = "Unknown";
zOrder = IDIYComponent.COMPONENT;
stretchable = true;
bomPolicy = BomPolicy.SHOW_ALL_NAMES;
}
icon = null;
// Draw component icon.
@@ -108,7 +112,7 @@ public class ComponentProcessor {
e.printStackTrace();
}
ComponentType componentType = new ComponentType(name, description, creationMethod,
category, namePrefix, author, icon, clazz, zOrder, stretchable);
category, namePrefix, author, icon, clazz, zOrder, stretchable, bomPolicy);
componentTypeMap.put(clazz.getName(), componentType);
return componentType;
}
@@ -14,6 +14,7 @@ import org.diylc.common.Orientation;
import org.diylc.common.PropertyWrapper;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Project;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.measures.Size;
import com.rits.cloning.Cloner;
@@ -2,17 +2,23 @@ package org.diylc.utils;
public class BomEntry {
private String type;
private String name;
private String value;
private Integer quantity;
private String notes;
public BomEntry(String name, String value, int quantity) {
public BomEntry(String type, String name, String value, int quantity) {
super();
this.type = type;
this.name = name;
this.value = value;
this.quantity = quantity;
}
public String getType() {
return type;
}
public String getName() {
return name;
@@ -50,6 +56,7 @@ public class BomEntry {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((notes == null) ? 0 : notes.hashCode());
result = prime * result + quantity;
@@ -66,6 +73,11 @@ public class BomEntry {
if (getClass() != obj.getClass())
return false;
BomEntry other = (BomEntry) obj;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
if (name == null) {
if (other.name != null)
return false;
@@ -7,7 +7,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.diylc.common.ComponentType;
import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.BomPolicy;
import org.diylc.presenter.ComponentProcessor;
public class BomMaker {
@@ -26,15 +29,27 @@ public class BomMaker {
public List<BomEntry> createBom(List<IDIYComponent<?>> components) {
Map<String, BomEntry> entryMap = new HashMap<String, BomEntry>();
for (IDIYComponent<?> component : components) {
ComponentType type = ComponentProcessor.getInstance()
.extractComponentTypeFrom(
(Class<? extends IDIYComponent<?>>) component
.getClass());
if (type.getBomPolicy() == BomPolicy.NEVER_SHOW)
continue;
String name = component.getName();
String value = component.getValue() == null ? null : component.getValue().toString();
String value = component.getValue() == null ? null : component
.getValue().toString();
if ((name != null) && (value != null)) {
String key = name + "|" + value;
String key = type.getName() + "|" + value;
if (entryMap.containsKey(key)) {
BomEntry entry = entryMap.get(key);
entry.setQuantity(entry.getQuantity() + 1);
if (type.getBomPolicy() == BomPolicy.SHOW_ALL_NAMES) {
entry.setName(entry.getName() + ", " + name);
}
} else {
entryMap.put(key, new BomEntry(name, value, 1));
entryMap.put(key, new BomEntry(type.getName(), type
.getBomPolicy() == BomPolicy.SHOW_ALL_NAMES ? name
: type.getName(), value, 1));
}
}
}