reorganized "stretchable" property into more granular control at the

point level

added controlable label to pot symbol and transistor symbols
This commit is contained in:
Branislav Stojkovic
2019-03-20 19:21:31 +01:00
parent 3c45336afe
commit 2faa2c6d61
73 changed files with 312 additions and 131 deletions
@@ -43,7 +43,6 @@ public class ComponentType {
private Class<? extends IDIYComponent<?>> instanceClass;
private double zOrder;
private boolean flexibleZOrder;
private boolean stretchable;
private BomPolicy bomPolicy;
private boolean autoEdit;
private IComponentTransformer transformer;
@@ -52,8 +51,8 @@ public class ComponentType {
public ComponentType(String name, String description, CreationMethod creationMethod, String category,
String namePrefix, String author, Icon icon, Class<? extends IDIYComponent<?>> instanceClass, double zOrder,
boolean flexibleZOrder, boolean stretchable, BomPolicy bomPolicy, boolean autoEdit,
IComponentTransformer transformer, KeywordPolicy keywordPolicy, String keywordTag) {
boolean flexibleZOrder, BomPolicy bomPolicy, boolean autoEdit, IComponentTransformer transformer,
KeywordPolicy keywordPolicy, String keywordTag) {
super();
this.name = name;
this.description = description;
@@ -65,7 +64,6 @@ public class ComponentType {
this.instanceClass = instanceClass;
this.zOrder = zOrder;
this.flexibleZOrder = flexibleZOrder;
this.stretchable = stretchable;
this.bomPolicy = bomPolicy;
this.autoEdit = autoEdit;
this.transformer = transformer;
@@ -113,10 +111,6 @@ public class ComponentType {
return flexibleZOrder;
}
public boolean isStretchable() {
return stretchable;
}
public BomPolicy getBomPolicy() {
return bomPolicy;
}
@@ -301,5 +301,10 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
@Override
public String getCommonPointName(int pointIndex) {
return null;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return true;
}
}
@@ -141,7 +141,13 @@ public interface IDIYComponent<T> extends Serializable {
* @param pointIndex
* @return name of the common point that joins all the other points with the same name together, e.g. GND
*/
String getCommonPointName(int pointIndex);
String getCommonPointName(int pointIndex);
/**
* @param pointIndex
* @return true if the control point can move without affecting other points' position, false otherwise
*/
boolean canPointMoveFreely(int pointIndex);
/**
* Draws the component onto the {@link Graphics2D}.
@@ -82,12 +82,6 @@ public @interface ComponentDescriptor {
*/
boolean flexibleZOrder() default false;
/**
* @return when false, moving one control point will cause all the others to move together with
* it.
*/
boolean stretchable() default true;
/**
* @return controls what should be shown the BOM
*/
@@ -92,7 +92,6 @@ public class ComponentProcessor {
Icon icon;
double zOrder;
boolean flexibleZOrder;
boolean stretchable;
BomPolicy bomPolicy;
boolean autoEdit;
IComponentTransformer transformer;
@@ -108,7 +107,6 @@ public class ComponentProcessor {
author = annotation.author();
zOrder = annotation.zOrder();
flexibleZOrder = annotation.flexibleZOrder();
stretchable = annotation.stretchable();
bomPolicy = annotation.bomPolicy();
autoEdit = annotation.autoEdit();
transformer = getComponentTransformer(annotation.transformer());
@@ -135,7 +133,7 @@ public class ComponentProcessor {
}
ComponentType componentType =
new ComponentType(name, description, creationMethod, category, namePrefix, author, icon, clazz, zOrder,
flexibleZOrder, stretchable, bomPolicy, autoEdit, transformer, keywordPolicy, keywordTag);
flexibleZOrder, bomPolicy, autoEdit, transformer, keywordPolicy, keywordTag);
componentTypeMap.put(clazz.getName(), componentType);
return componentType;
}
@@ -62,10 +62,10 @@ public class InstantiationManager {
private Point potentialControlPoint;
public 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, null,
false, null, KeywordPolicy.NEVER_SHOW, null);
public static final ComponentType blockType = new ComponentType("Building block",
"Components from the building block", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, false, null,
"Components from the building block", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, null,
false, null, KeywordPolicy.NEVER_SHOW, null);
public InstantiationManager() {}
@@ -821,7 +821,6 @@ public class Presenter implements IPlugInPort {
}
}
@SuppressWarnings("unchecked")
@Override
public void mouseMoved(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown) {
if (point == null)
@@ -857,24 +856,15 @@ public class Presenter implements IPlugInPort {
// Go backwards so we take the highest z-order components first.
for (int i = currentProject.getComponents().size() - 1; i >= 0; i--) {
IDIYComponent<?> component = currentProject.getComponents().get(i);
ComponentType componentType =
ComponentProcessor.getInstance().extractComponentTypeFrom(
(Class<? extends IDIYComponent<?>>) component.getClass());
for (int pointIndex = 0; pointIndex < component.getControlPointCount(); pointIndex++) {
Point controlPoint = component.getControlPoint(pointIndex);
// Only consider selected components that are not grouped.
if (selectedComponents.contains(component) && componentType.isStretchable()
if (selectedComponents.contains(component) && component.canPointMoveFreely(pointIndex)
&& findAllGroupedComponents(component).size() == 1) {
try {
if (previousScaledPoint.distance(controlPoint) < DrawingManager.CONTROL_POINT_SIZE) {
Set<Integer> indices = new HashSet<Integer>();
if (componentType.isStretchable()) {
indices.add(pointIndex);
} else {
for (int j = 0; j < component.getControlPointCount(); j++) {
indices.add(j);
}
}
components.put(component, indices);
break;
}
@@ -1101,15 +1091,10 @@ public class Presenter implements IPlugInPort {
*
* @param controlPointMap
*/
@SuppressWarnings("unchecked")
private void includeStuckComponents(Map<IDIYComponent<?>, Set<Integer>> controlPointMap) {
int oldSize = controlPointMap.size();
LOG.trace("Expanding selected component map");
for (IDIYComponent<?> component : currentProject.getComponents()) {
ComponentType componentType =
ComponentProcessor.getInstance().extractComponentTypeFrom(
(Class<? extends IDIYComponent<?>>) component.getClass());
// Check if there's a control point in the current selection
// that matches with one of its control points.
for (int i = 0; i < component.getControlPointCount(); i++) {
@@ -1142,7 +1127,7 @@ public class Presenter implements IPlugInPort {
// For stretchable components just add the
// matching component. Otherwise, add all control
// points.
if (componentType.isStretchable()) {
if (component.canPointMoveFreely(i)) {
indices.add(i);
} else {
for (int k = 0; k < component.getControlPointCount(); k++) {