This commit is contained in:
Bane Stojkovic
2026-09-03 14:25:27 +02:00
parent 9f52efafbb
commit 47250ed612
5 changed files with 44 additions and 44 deletions
@@ -73,7 +73,7 @@ public class CompositeComponent extends AbstractComponent<Void> {
private static final long serialVersionUID = 1L;
private List<IDIYComponent<?>> components = new ArrayList<IDIYComponent<?>>();
private List<IDIYComponent<?>> childComponents = new ArrayList<IDIYComponent<?>>();
// Name of the building block this instance was created from. Drives its display identity in
// the BOM, netlist report and AI project description (see ComponentProcessor.getDisplayTypeName).
@@ -97,14 +97,14 @@ public class CompositeComponent extends AbstractComponent<Void> {
return;
}
int total = 0;
for (IDIYComponent<?> c : components) {
for (IDIYComponent<?> c : childComponents) {
total += c.getControlPointCount();
}
int[] newChildOf = new int[total];
int[] newPointOf = new int[total];
int idx = 0;
for (int ci = 0; ci < components.size(); ci++) {
IDIYComponent<?> c = components.get(ci);
for (int ci = 0; ci < childComponents.size(); ci++) {
IDIYComponent<?> c = childComponents.get(ci);
int count = c.getControlPointCount();
for (int pi = 0; pi < count; pi++) {
newChildOf[idx] = ci;
@@ -119,11 +119,11 @@ public class CompositeComponent extends AbstractComponent<Void> {
/**
* @return the embedded child components, in save order. Never {@code null}.
*/
public List<IDIYComponent<?>> getComponents() {
if (components == null) {
components = new ArrayList<IDIYComponent<?>>();
public List<IDIYComponent<?>> getChildComponents() {
if (childComponents == null) {
childComponents = new ArrayList<IDIYComponent<?>>();
}
return components;
return childComponents;
}
@EditableProperty(name = "Block", defaultable = false, sortOrder = 1)
@@ -150,43 +150,43 @@ public class CompositeComponent extends AbstractComponent<Void> {
@Override
public Point2D getControlPoint(int index) {
buildIndexIfNeeded();
return components.get(childOf[index]).getControlPoint(pointOf[index]);
return childComponents.get(childOf[index]).getControlPoint(pointOf[index]);
}
@Override
public void setControlPoint(Point2D point, int index) {
buildIndexIfNeeded();
components.get(childOf[index]).setControlPoint(point, pointOf[index]);
childComponents.get(childOf[index]).setControlPoint(point, pointOf[index]);
}
@Override
public boolean isControlPointSticky(int index) {
buildIndexIfNeeded();
return components.get(childOf[index]).isControlPointSticky(pointOf[index]);
return childComponents.get(childOf[index]).isControlPointSticky(pointOf[index]);
}
@Override
public boolean canControlPointOverlap(int index) {
buildIndexIfNeeded();
return components.get(childOf[index]).canControlPointOverlap(pointOf[index]);
return childComponents.get(childOf[index]).canControlPointOverlap(pointOf[index]);
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
buildIndexIfNeeded();
return components.get(childOf[index]).getControlPointVisibilityPolicy(pointOf[index]);
return childComponents.get(childOf[index]).getControlPointVisibilityPolicy(pointOf[index]);
}
@Override
public String getControlPointNodeName(int index) {
buildIndexIfNeeded();
return components.get(childOf[index]).getControlPointNodeName(pointOf[index]);
return childComponents.get(childOf[index]).getControlPointNodeName(pointOf[index]);
}
@Override
public String[] getSectionNames(int pointIndex) {
buildIndexIfNeeded();
return new String[] {components.get(childOf[pointIndex]).getName()};
return new String[] {childComponents.get(childOf[pointIndex]).getName()};
}
/**
@@ -200,7 +200,7 @@ public class CompositeComponent extends AbstractComponent<Void> {
@Override
public void createdIn(Project project) {
for (IDIYComponent<?> c : getComponents()) {
for (IDIYComponent<?> c : getChildComponents()) {
c.createdIn(project);
}
}
@@ -218,7 +218,7 @@ public class CompositeComponent extends AbstractComponent<Void> {
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
IDrawingObserver drawingObserver) {
for (IDIYComponent<?> c : getComponents()) {
for (IDIYComponent<?> c : getChildComponents()) {
// Children always draw in their normal state - the composite draws its own selection
// outline below instead of letting every child paint its own highlight.
c.draw(g2d, ComponentState.NORMAL, outlineMode, project, drawingObserver);
@@ -294,11 +294,11 @@ public class CompositeComponent extends AbstractComponent<Void> {
clone.setId(getId());
clone.setName(getName());
clone.blockName = this.blockName;
List<IDIYComponent<?>> clonedComponents = new ArrayList<IDIYComponent<?>>(getComponents().size());
for (IDIYComponent<?> c : getComponents()) {
List<IDIYComponent<?>> clonedComponents = new ArrayList<IDIYComponent<?>>(getChildComponents().size());
for (IDIYComponent<?> c : getChildComponents()) {
clonedComponents.add(c.clone());
}
clone.components = clonedComponents;
clone.childComponents = clonedComponents;
return clone;
}
@@ -319,12 +319,12 @@ public class CompositeComponent extends AbstractComponent<Void> {
if (!Objects.equals(getName(), o.getName()) || !Objects.equals(blockName, o.blockName)) {
return false;
}
List<IDIYComponent<?>> otherComponents = o.getComponents();
if (getComponents().size() != otherComponents.size()) {
List<IDIYComponent<?>> otherComponents = o.getChildComponents();
if (getChildComponents().size() != otherComponents.size()) {
return false;
}
for (int i = 0; i < components.size(); i++) {
if (!components.get(i).equalsTo(otherComponents.get(i))) {
for (int i = 0; i < childComponents.size(); i++) {
if (!childComponents.get(i).equalsTo(otherComponents.get(i))) {
return false;
}
}
@@ -42,9 +42,9 @@ public class CompositeComponentTransformer implements IComponentTransformer {
@Override
public boolean canRotate(IDIYComponent<?> component) {
CompositeComponent composite = (CompositeComponent) component;
if (composite.getComponents().isEmpty())
if (composite.getChildComponents().isEmpty())
return false;
for (IDIYComponent<?> child : composite.getComponents()) {
for (IDIYComponent<?> child : composite.getChildComponents()) {
if (!childTransformer(child).canRotate(child))
return false;
}
@@ -54,9 +54,9 @@ public class CompositeComponentTransformer implements IComponentTransformer {
@Override
public boolean canMirror(IDIYComponent<?> component) {
CompositeComponent composite = (CompositeComponent) component;
if (composite.getComponents().isEmpty())
if (composite.getChildComponents().isEmpty())
return false;
for (IDIYComponent<?> child : composite.getComponents()) {
for (IDIYComponent<?> child : composite.getChildComponents()) {
if (!childTransformer(child).canMirror(child))
return false;
}
@@ -75,7 +75,7 @@ public class CompositeComponentTransformer implements IComponentTransformer {
@Override
public void rotate(IDIYComponent<?> component, Point2D center, int direction) {
CompositeComponent composite = (CompositeComponent) component;
for (IDIYComponent<?> child : composite.getComponents()) {
for (IDIYComponent<?> child : composite.getChildComponents()) {
childTransformer(child).rotate(child, center, direction);
}
}
@@ -83,7 +83,7 @@ public class CompositeComponentTransformer implements IComponentTransformer {
@Override
public void mirror(IDIYComponent<?> component, Point2D center, int direction) {
CompositeComponent composite = (CompositeComponent) component;
for (IDIYComponent<?> child : composite.getComponents()) {
for (IDIYComponent<?> child : composite.getChildComponents()) {
childTransformer(child).mirror(child, center, direction);
}
}
@@ -190,7 +190,7 @@ public class BuildingBlockManager {
}
CompositeComponent composite = new CompositeComponent();
composite.getComponents().addAll(childClones);
composite.getChildComponents().addAll(childClones);
composite.initBlockName(blockName);
composite.setId(UUID.randomUUID());
ComponentType compositeType =
@@ -47,9 +47,9 @@ public class CompositeComponentTest {
CompositeComponent composite = new CompositeComponent();
composite.setName("BLK1");
composite.initBlockName("Test Block");
composite.getComponents().add(new TwoPointTestComponent("R1",
composite.getChildComponents().add(new TwoPointTestComponent("R1",
new Point2D.Double(0, 0), new Point2D.Double(10, 0)));
composite.getComponents().add(new TwoPointTestComponent("R2",
composite.getChildComponents().add(new TwoPointTestComponent("R2",
new Point2D.Double(20, 0), new Point2D.Double(30, 0)));
return composite;
}
@@ -79,14 +79,14 @@ public class CompositeComponentTest {
assertEquals(new Point2D.Double(99, 99), composite.getControlPoint(2));
// the sibling child's points must be untouched
assertEquals(new Point2D.Double(30, 0), composite.getControlPoint(3));
TwoPointTestComponent r2 = (TwoPointTestComponent) composite.getComponents().get(1);
TwoPointTestComponent r2 = (TwoPointTestComponent) composite.getChildComponents().get(1);
assertEquals(new Point2D.Double(99, 99), r2.getControlPoint(0));
}
@Test
public void stickinessIsDelegatedPerChildPoint() {
CompositeComponent composite = twoChildComposite();
((TwoPointTestComponent) composite.getComponents().get(0)).setSticky(1, false);
((TwoPointTestComponent) composite.getChildComponents().get(0)).setSticky(1, false);
assertTrue(composite.isControlPointSticky(0));
assertFalse(composite.isControlPointSticky(1));
@@ -134,12 +134,12 @@ public class CompositeComponentTest {
// that needs a genuinely new component (e.g. BuildingBlockManager placing a fresh instance)
// reassigns ids itself, exactly as it does for any other component's clone().
CompositeComponent original = twoChildComposite();
UUID originalChildId = original.getComponents().get(0).getId();
UUID originalChildId = original.getChildComponents().get(0).getId();
CompositeComponent clone = (CompositeComponent) original.clone();
assertEquals(original.getId(), clone.getId());
assertEquals(originalChildId, clone.getComponents().get(0).getId());
assertEquals(originalChildId, clone.getChildComponents().get(0).getId());
}
@Test
@@ -192,7 +192,7 @@ public class CompositeComponentTest {
g2d.dispose();
// no exception means components list (empty) was never dereferenced as if populated
assertNotNull(blank.getComponents());
assertTrue(blank.getComponents().isEmpty());
assertNotNull(blank.getChildComponents());
assertTrue(blank.getChildComponents().isEmpty());
}
}
@@ -109,8 +109,8 @@ public class BuildingBlockManagerTest {
// children are namespaced under the composite's own name in the netlist, so their saved
// names must survive untouched
assertEquals("R1", composite.getComponents().get(0).getName());
assertEquals("R2", composite.getComponents().get(1).getName());
assertEquals("R1", composite.getChildComponents().get(0).getName());
assertEquals("R2", composite.getChildComponents().get(1).getName());
}
@Test
@@ -125,9 +125,9 @@ public class BuildingBlockManagerTest {
.loadBlock(BLOCK_NAME, existing, BlockInstantiationMode.COMPOSITE).get(0);
assertNotEquals(first.getName(), second.getName());
assertEquals(first.getComponents().get(0).getName(), second.getComponents().get(0).getName());
assertEquals(first.getChildComponents().get(0).getName(), second.getChildComponents().get(0).getName());
// but the underlying child components must be distinct objects with distinct ids
assertNotEquals(first.getComponents().get(0).getId(), second.getComponents().get(0).getId());
assertNotEquals(first.getChildComponents().get(0).getId(), second.getChildComponents().get(0).getId());
}
@Test(expected = InvalidBlockException.class)
@@ -155,6 +155,6 @@ public class BuildingBlockManagerTest {
assertNotNull(result);
assertEquals(1, result.size());
assertTrue(((CompositeComponent) result.get(0)).getComponents().get(0) instanceof ISwitch);
assertTrue(((CompositeComponent) result.get(0)).getChildComponents().get(0) instanceof ISwitch);
}
}