cleanup isPolarized

This commit is contained in:
Bane Stojkovic
2026-07-17 16:45:15 +02:00
parent 1571d78048
commit 0476dbb876
20 changed files with 2 additions and 120 deletions
@@ -204,13 +204,4 @@ public interface IDIYComponent<T> extends Serializable, Cloneable {
* @param project
*/
void createdIn(Project project);
/**
* Returns whether this component is polarized (direction matters for electronic function).
* Default implementation returns true, components that are not polarized should override this.
* @return true if the component is polarized, false otherwise
*/
default boolean isPolarized() {
return true;
}
}
@@ -222,10 +222,6 @@ public class CompareServiceTest {
netlist2.add(createGroup(componentMap, "Resistor1", "Node2", "Component2", "Node2"));
netlist2.add(createGroup(componentMap, "Resistor1", "Node1", "Component3", "Node3"));
// Make Resistor1 non-polarized
IDIYComponent<?> resistor = componentMap.get("Resistor1");
when(resistor.isPolarized()).thenReturn(false);
CompareResults results = compareService.compare(netlist1, netlist2);
assertTrue(results.matches());
@@ -243,7 +239,6 @@ public class CompareServiceTest {
when(diode1.getControlPoint(1)).thenReturn(new Point2D.Double(0, 0));
when(diode1.isControlPointSticky(0)).thenReturn(true);
when(diode1.isControlPointSticky(1)).thenReturn(true);
when(diode1.isPolarized()).thenReturn(true);
when(diode1.toString()).thenReturn("Diode1");
when(diode1.getControlPointNodeName(0)).thenReturn("Anode");
when(diode1.getControlPointNodeName(1)).thenReturn("Cathode");
@@ -256,7 +251,6 @@ public class CompareServiceTest {
when(component2_1.getControlPoint(0)).thenReturn(new Point2D.Double(0, 0));
when(component2_1.isControlPointSticky(0)).thenReturn(true);
when(component2_1.toString()).thenReturn("Component2");
when(component2_1.isPolarized()).thenReturn(false);
// Create Component3 for netlist1
IDIYComponent<?> component3_1 = mock(IDIYComponent.class);
@@ -266,7 +260,6 @@ public class CompareServiceTest {
when(component3_1.getControlPoint(0)).thenReturn(new Point2D.Double(0, 0));
when(component3_1.isControlPointSticky(0)).thenReturn(true);
when(component3_1.toString()).thenReturn("Component3");
when(component3_1.isPolarized()).thenReturn(false);
// Create first netlist with polarized component in two groups
Netlist netlist1 = new Netlist(List.of(diode1, component2_1, component3_1));
@@ -294,7 +287,6 @@ public class CompareServiceTest {
when(diode2.getControlPoint(1)).thenReturn(new Point2D.Double(0, 0));
when(diode2.isControlPointSticky(0)).thenReturn(true);
when(diode2.isControlPointSticky(1)).thenReturn(true);
when(diode2.isPolarized()).thenReturn(true);
when(diode2.toString()).thenReturn("Diode1");
when(diode2.getControlPointNodeName(0)).thenReturn("Anode");
when(diode2.getControlPointNodeName(1)).thenReturn("Cathode");
@@ -307,7 +299,6 @@ public class CompareServiceTest {
when(component2_2.getControlPoint(0)).thenReturn(new Point2D.Double(0, 0));
when(component2_2.isControlPointSticky(0)).thenReturn(true);
when(component2_2.toString()).thenReturn("Component2");
when(component2_2.isPolarized()).thenReturn(false);
// Create Component3 for netlist2
IDIYComponent<?> component3_2 = mock(IDIYComponent.class);
@@ -317,7 +308,6 @@ public class CompareServiceTest {
when(component3_2.getControlPoint(0)).thenReturn(new Point2D.Double(0, 0));
when(component3_2.isControlPointSticky(0)).thenReturn(true);
when(component3_2.toString()).thenReturn("Component3");
when(component3_2.isPolarized()).thenReturn(false);
// Create second netlist with same connections but different node order
Netlist netlist2 = new Netlist(List.of(diode2, component2_2, component3_2));
@@ -343,8 +333,7 @@ public class CompareServiceTest {
System.out.println("Group: " + g);
for (Node n : g.getNodes()) {
System.out.println(" Node: " + n.getComponent().getName() +
" " + n.getComponent().getControlPointNodeName(n.getPointIndex()) +
" (polarized: " + n.getComponent().isPolarized() + ")");
" " + n.getComponent().getControlPointNodeName(n.getPointIndex()));
}
}
System.out.println("\nNetlist2 groups:");
@@ -352,8 +341,7 @@ public class CompareServiceTest {
System.out.println("Group: " + g);
for (Node n : g.getNodes()) {
System.out.println(" Node: " + n.getComponent().getName() +
" " + n.getComponent().getControlPointNodeName(n.getPointIndex()) +
" (polarized: " + n.getComponent().isPolarized() + ")");
" " + n.getComponent().getControlPointNodeName(n.getPointIndex()));
}
}
@@ -485,11 +473,6 @@ public class CompareServiceTest {
netlist2.add(createGroup(componentMap, "Diode1", "Cathode", "Component4", "Node4"));
// Make Resistor1 non-polarized and Diode1 polarized
IDIYComponent<?> resistor = componentMap.get("Resistor1");
IDIYComponent<?> diode = componentMap.get("Diode1");
when(resistor.isPolarized()).thenReturn(false);
when(diode.isPolarized()).thenReturn(true);
CompareResults results = compareService.compare(netlist1, netlist2);
assertTrue(results.matches());
@@ -519,8 +502,6 @@ public class CompareServiceTest {
when(c.getControlPoint(0)).thenReturn(new Point2D.Double(0, 0));
when(c.isControlPointSticky(0)).thenReturn(true);
when(c.toString()).thenReturn(name);
// Default to non-polarized
when(c.isPolarized()).thenReturn(false);
return c;
});
// For the same component name, update the node name for this instance
@@ -347,9 +347,4 @@ public class FuseHolderPanel extends AbstractMultiPartComponent<String> {
Rectangle2D bounds = getBody()[0].getBounds2D();
return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin, bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin);
}
@Override
public boolean isPolarized() {
return false;
}
}
@@ -155,9 +155,4 @@ public class AirCoreInductor extends AbstractLeadedComponent<Inductance> {
public void setResistance(Resistance resistance) {
this.resistance = resistance;
}
@Override
public boolean isPolarized() {
return false;
}
}
@@ -280,9 +280,4 @@ public class AxialElectrolyticCapacitor extends AbstractLeadedComponent<Capacita
return new Color((int) r, (int) g, (int) b, (int) a);
}
@Override
public boolean isPolarized() {
return polarized;
}
}
@@ -104,9 +104,4 @@ public class AxialFilmCapacitor extends AbstractFilmCapacitor implements IDatash
public boolean getFlipStanding() {
return super.getFlipStanding();
}
@Override
public boolean isPolarized() {
return false;
}
}
@@ -96,11 +96,6 @@ public class CapacitorSymbol extends AbstractSchematicLeadedSymbol<Capacitance>
this.polarized = polarized;
}
@Override
public boolean isPolarized() {
return polarized;
}
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
g2d.setColor(LEAD_COLOR);
@@ -133,9 +133,4 @@ public class CrystalOscillator extends AbstractLeadedComponent<Frequency> implem
protected Size getDefaultWidth() {
return DEFAULT_WIDTH;
}
@Override
public boolean isPolarized() {
return false;
}
}
@@ -147,9 +147,4 @@ public class FuseSymbol extends AbstractSchematicLeadedSymbol<Current> {
public enum DrawStyle {
ANSI, IEC, IEEE
}
@Override
public boolean isPolarized() {
return false;
}
}
@@ -508,11 +508,6 @@ public class HeatSinkResistor extends AbstractLeadedComponent<Resistance> implem
g2d.draw(a);
}
@Override
public boolean isPolarized() {
return false;
}
public enum MountingHoleCount {
TWO_DIAGONAL("2 diagonal"),
FOUR("4 holes"),
@@ -151,9 +151,4 @@ public class InductorSymbol extends AbstractSchematicLeadedSymbol<Inductance> {
public void setCore(boolean core) {
this.core = core;
}
@Override
public boolean isPolarized() {
return false;
}
}
@@ -116,9 +116,4 @@ public class RadialCeramicDiskCapacitor extends AbstractRadialComponent<Capacita
protected Shape getBodyShape() {
return new Ellipse2D.Double(0f, 0f, getLength().convertToPixels(), getClosestOdd(getWidth().convertToPixels()));
}
@Override
public boolean isPolarized() {
return false;
}
}
@@ -323,9 +323,4 @@ public class RadialElectrolytic extends AbstractRadialComponent<Capacitance> imp
}
return new Ellipse2D.Double(0f, 0f, getClosestOdd(diameter), getClosestOdd(diameter));
}
@Override
public boolean isPolarized() {
return polarized;
}
}
@@ -151,9 +151,4 @@ public class RadialFilmCapacitor extends AbstractFilmCapacitor implements IDatas
return name().substring(0, 1) + name().substring(1).toLowerCase();
}
}
@Override
public boolean isPolarized() {
return false;
}
}
@@ -299,9 +299,4 @@ public class RadialInductor extends AbstractRadialComponent<Inductance> {
public void setLip(Size lip) {
this.lip = lip;
}
@Override
public boolean isPolarized() {
return false;
}
}
@@ -147,9 +147,4 @@ public class RadialMicaCapacitor extends AbstractRadialComponent<Capacitance> im
a.add(new Area(new Ellipse2D.Double(length - width, 0, width, width)));
return a;
}
@Override
public boolean isPolarized() {
return false;
}
}
@@ -221,11 +221,6 @@ public class Resistor extends AbstractLeadedComponent<Resistance> implements IGe
return super.getFlipStanding();
}
@Override
public boolean isPolarized() {
return false;
}
public enum ResistorShape {
Tubular, Tubular_Beveled, Standard;
@@ -160,11 +160,6 @@ public class ResistorSymbol extends AbstractSchematicLeadedSymbol<Resistance> {
public enum DrawStyle {
ANSI, IEC
}
@Override
public boolean isPolarized() {
return false;
}
}
@@ -244,9 +244,4 @@ public class TantalumCapacitor extends AbstractRadialComponent<Capacitance> {
}
return new Ellipse2D.Double(0f, 0f, getClosestOdd(diameter), getClosestOdd(diameter));
}
@Override
public boolean isPolarized() {
return true;
}
}
@@ -165,9 +165,4 @@ public class ToroidalInductor extends AbstractLeadedComponent<Inductance> implem
public void setResistance(Resistance resistance) {
this.resistance = resistance;
}
@Override
public boolean isPolarized() {
return false;
}
}