mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
Remove junk from BOM (eyelets, wires, traces)
This commit is contained in:
+9
-1
@@ -4,6 +4,7 @@ import javax.swing.Icon;
|
|||||||
|
|
||||||
import org.diylc.core.CreationMethod;
|
import org.diylc.core.CreationMethod;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
|
import org.diylc.core.annotations.BomPolicy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entity class used to describe a component type.
|
* Entity class used to describe a component type.
|
||||||
@@ -24,10 +25,12 @@ public class ComponentType {
|
|||||||
private Class<? extends IDIYComponent<?>> instanceClass;
|
private Class<? extends IDIYComponent<?>> instanceClass;
|
||||||
private double zOrder;
|
private double zOrder;
|
||||||
private boolean stretchable;
|
private boolean stretchable;
|
||||||
|
private BomPolicy bomPolicy;
|
||||||
|
|
||||||
public ComponentType(String name, String description, CreationMethod creationMethod,
|
public ComponentType(String name, String description, CreationMethod creationMethod,
|
||||||
String category, String namePrefix, String author, Icon icon,
|
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();
|
super();
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
@@ -39,6 +42,7 @@ public class ComponentType {
|
|||||||
this.instanceClass = instanceClass;
|
this.instanceClass = instanceClass;
|
||||||
this.zOrder = zOrder;
|
this.zOrder = zOrder;
|
||||||
this.stretchable = stretchable;
|
this.stretchable = stretchable;
|
||||||
|
this.bomPolicy = bomPolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -81,6 +85,10 @@ public class ComponentType {
|
|||||||
return stretchable;
|
return stretchable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BomPolicy getBomPolicy() {
|
||||||
|
return bomPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name;
|
return name;
|
||||||
|
|||||||
+5
@@ -59,4 +59,9 @@ public @interface ComponentDescriptor {
|
|||||||
*/
|
*/
|
||||||
boolean stretchable() default true;
|
boolean stretchable() default true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return controls what should be shown the BOM
|
||||||
|
*/
|
||||||
|
BomPolicy bomPolicy() default BomPolicy.SHOW_ALL_NAMES;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -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.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 {
|
|||||||
Icon icon;
|
Icon icon;
|
||||||
double zOrder;
|
double zOrder;
|
||||||
boolean stretchable;
|
boolean stretchable;
|
||||||
|
BomPolicy bomPolicy;
|
||||||
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();
|
||||||
@@ -80,6 +82,7 @@ public class ComponentProcessor {
|
|||||||
author = annotation.author();
|
author = annotation.author();
|
||||||
zOrder = annotation.zOrder();
|
zOrder = annotation.zOrder();
|
||||||
stretchable = annotation.stretchable();
|
stretchable = annotation.stretchable();
|
||||||
|
bomPolicy = annotation.bomPolicy();
|
||||||
} else {
|
} else {
|
||||||
name = clazz.getSimpleName();
|
name = clazz.getSimpleName();
|
||||||
description = "";
|
description = "";
|
||||||
@@ -89,6 +92,7 @@ public class ComponentProcessor {
|
|||||||
author = "Unknown";
|
author = "Unknown";
|
||||||
zOrder = IDIYComponent.COMPONENT;
|
zOrder = IDIYComponent.COMPONENT;
|
||||||
stretchable = true;
|
stretchable = true;
|
||||||
|
bomPolicy = BomPolicy.SHOW_ALL_NAMES;
|
||||||
}
|
}
|
||||||
icon = null;
|
icon = null;
|
||||||
// Draw component icon.
|
// Draw component icon.
|
||||||
@@ -108,7 +112,7 @@ public class ComponentProcessor {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
ComponentType componentType = new ComponentType(name, description, creationMethod,
|
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);
|
componentTypeMap.put(clazz.getName(), componentType);
|
||||||
return componentType;
|
return componentType;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -14,6 +14,7 @@ import org.diylc.common.Orientation;
|
|||||||
import org.diylc.common.PropertyWrapper;
|
import org.diylc.common.PropertyWrapper;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
import org.diylc.core.Project;
|
import org.diylc.core.Project;
|
||||||
|
import org.diylc.core.annotations.ComponentDescriptor;
|
||||||
import org.diylc.core.measures.Size;
|
import org.diylc.core.measures.Size;
|
||||||
|
|
||||||
import com.rits.cloning.Cloner;
|
import com.rits.cloning.Cloner;
|
||||||
|
|||||||
+13
-1
@@ -2,18 +2,24 @@ package org.diylc.utils;
|
|||||||
|
|
||||||
public class BomEntry {
|
public class BomEntry {
|
||||||
|
|
||||||
|
private String type;
|
||||||
private String name;
|
private String name;
|
||||||
private String value;
|
private String value;
|
||||||
private Integer quantity;
|
private Integer quantity;
|
||||||
private String notes;
|
private String notes;
|
||||||
|
|
||||||
public BomEntry(String name, String value, int quantity) {
|
public BomEntry(String type, String name, String value, int quantity) {
|
||||||
super();
|
super();
|
||||||
|
this.type = type;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.quantity = quantity;
|
this.quantity = quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@@ -50,6 +56,7 @@ public class BomEntry {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
|
result = prime * result + ((type == null) ? 0 : type.hashCode());
|
||||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||||
result = prime * result + ((notes == null) ? 0 : notes.hashCode());
|
result = prime * result + ((notes == null) ? 0 : notes.hashCode());
|
||||||
result = prime * result + quantity;
|
result = prime * result + quantity;
|
||||||
@@ -66,6 +73,11 @@ public class BomEntry {
|
|||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
BomEntry other = (BomEntry) obj;
|
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 (name == null) {
|
||||||
if (other.name != null)
|
if (other.name != null)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
+18
-3
@@ -7,7 +7,10 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.diylc.common.ComponentType;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
|
import org.diylc.core.annotations.BomPolicy;
|
||||||
|
import org.diylc.presenter.ComponentProcessor;
|
||||||
|
|
||||||
public class BomMaker {
|
public class BomMaker {
|
||||||
|
|
||||||
@@ -26,15 +29,27 @@ public class BomMaker {
|
|||||||
public List<BomEntry> createBom(List<IDIYComponent<?>> components) {
|
public List<BomEntry> createBom(List<IDIYComponent<?>> components) {
|
||||||
Map<String, BomEntry> entryMap = new HashMap<String, BomEntry>();
|
Map<String, BomEntry> entryMap = new HashMap<String, BomEntry>();
|
||||||
for (IDIYComponent<?> component : components) {
|
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 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)) {
|
if ((name != null) && (value != null)) {
|
||||||
String key = name + "|" + value;
|
String key = type.getName() + "|" + value;
|
||||||
if (entryMap.containsKey(key)) {
|
if (entryMap.containsKey(key)) {
|
||||||
BomEntry entry = entryMap.get(key);
|
BomEntry entry = entryMap.get(key);
|
||||||
entry.setQuantity(entry.getQuantity() + 1);
|
entry.setQuantity(entry.getQuantity() + 1);
|
||||||
|
if (type.getBomPolicy() == BomPolicy.SHOW_ALL_NAMES) {
|
||||||
|
entry.setName(entry.getName() + ", " + name);
|
||||||
|
}
|
||||||
} else {
|
} 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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user