Skip to content

Commit

Permalink
Feat: Add invert bit distribution button on splitter
Browse files Browse the repository at this point in the history
Merge commit 2090ebf and bdcc4c8 from pull request Logisim-Ita#37 Matt345Fire/Logisim-Locale
  • Loading branch information
Matt345Fire authored and LucaCaruso-dev committed Nov 20, 2024
1 parent 13916f4 commit f6e8689
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 12 deletions.
20 changes: 10 additions & 10 deletions Logisim-Fork/src/main/java/com/cburch/logisim/circuit/Splitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ private synchronized void configureComponent() {
@Override
public void configureMenu(JPopupMenu menu, Project proj) {
menu.addSeparator();
menu.add(new SplitterDistributeItem(proj, this, 1));
menu.add(new SplitterDistributeItem(proj, this, -1));
menu.add(new SplitterDistributeItem(proj, this, 1));
}

@Override
Expand Down Expand Up @@ -195,15 +195,15 @@ public String getToolTip(ComponentUserEvent e) {
appendBuf(buf, beginString, bit_end.length - 1);
String base;
switch (bits) {
case 0:
base = Strings.get("splitterSplit0Tip");
break;
case 1:
base = Strings.get("splitterSplit1Tip");
break;
default:
base = Strings.get("splitterSplitManyTip");
break;
case 0:
base = Strings.get("splitterSplit0Tip");
break;
case 1:
base = Strings.get("splitterSplit1Tip");
break;
default:
base = Strings.get("splitterSplitManyTip");
break;
}
return StringUtil.format(base, buf.toString());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.cburch.logisim.instance.StdAttr;

class SplitterAttributes extends AbstractAttributeSet {

public static int order=0;
static class BitOutAttribute extends Attribute<Integer> {
int which;
BitOutOption[] options;
Expand Down Expand Up @@ -103,6 +105,7 @@ public String toString() {
}
}

//the list of selection for the splitter attributes
public static final AttributeOption APPEAR_LEGACY = new AttributeOption("legacy",
Strings.getter("splitterAppearanceLegacy"));
public static final AttributeOption APPEAR_LEFT = new AttributeOption("left",
Expand All @@ -117,18 +120,32 @@ public String toString() {
Strings.getter("splitterAppearanceAttr"),
new AttributeOption[] { APPEAR_LEFT, APPEAR_RIGHT, APPEAR_CENTER, APPEAR_LEGACY });

//////////////////////////////////////////////////////dis///////////////////////////////////////////////////
public static final AttributeOption APPEAR_ASS = new AttributeOption("ascending",
Strings.getter("splitterDistributeAscending"));

public static final AttributeOption APPEAR_DESS = new AttributeOption("descending",
Strings.getter("splitterDistributeDescending"));
public static final Attribute<AttributeOption> ATTR_ORDER = Attributes.forOption("order",
Strings.getter("splitterDistribute"),
new AttributeOption[] { APPEAR_ASS, APPEAR_DESS });

////////////////////////////////////////////////////////////dis/////////////////////////////////////////////

public static final Attribute<BitWidth> ATTR_WIDTH = Attributes.forBitWidth("incoming",
Strings.getter("splitterBitWidthAttr"));

public static final Attribute<Integer> ATTR_FANOUT = Attributes.forIntegerRange("fanout",
Strings.getter("splitterFanOutAttr"), 1, 32);

private static final List<Attribute<?>> INIT_ATTRIBUTES = Arrays
.asList(new Attribute<?>[] { StdAttr.FACING, ATTR_FANOUT, ATTR_WIDTH, ATTR_APPEARANCE, });
.asList(new Attribute<?>[] { StdAttr.FACING, ATTR_FANOUT, ATTR_WIDTH, ATTR_APPEARANCE,ATTR_ORDER });

private static final String unchosen_val = "none";

static byte[] computeDistribution(int fanout, int bits, int order) {
//order=-1; -1== 3,2,1,0 1=0,1,2,3 order of bits
order=SplitterAttributes.order; //i think i can call it bypass
byte[] ret = new byte[bits];
if (order >= 0) {
if (fanout >= bits) {
Expand Down Expand Up @@ -181,6 +198,8 @@ static byte[] computeDistribution(int fanout, int bits, int order) {
private ArrayList<Attribute<?>> attrs = new ArrayList<Attribute<?>>(INIT_ATTRIBUTES);
private SplitterParameters parameters;
AttributeOption appear = APPEAR_LEFT;
AttributeOption ordershow=APPEAR_ASS;

Direction facing = Direction.EAST;
byte fanout = 4; // number of ends this splits into
byte[] bit_end = new byte[4]; // how each bit maps to an end (0 if nowhere);
Expand Down Expand Up @@ -282,6 +301,7 @@ public SplitterParameters getParameters() {
return ret;
}

// val that will remain in the text box after selection
@Override
public <V> V getValue(Attribute<V> attr) {
if (attr == StdAttr.FACING) {
Expand All @@ -292,6 +312,8 @@ public <V> V getValue(Attribute<V> attr) {
return (V) BitWidth.create(bit_end.length);
} else if (attr == ATTR_APPEARANCE) {
return (V) appear;
} else if (attr == ATTR_ORDER) {
return (V) ordershow;
} else if (attr instanceof BitOutAttribute) {
BitOutAttribute bitOut = (BitOutAttribute) attr;
return (V) Integer.valueOf(bit_end[bitOut.which]);
Expand All @@ -300,6 +322,7 @@ public <V> V getValue(Attribute<V> attr) {
}
}

//what happends when the one of the selection is selected
@Override
public <V> void setValue(Attribute<V> attr, V value) {
if (attr == StdAttr.FACING) {
Expand All @@ -322,7 +345,24 @@ public <V> void setValue(Attribute<V> attr, V value) {
bit_end = new byte[width.getWidth()];
configureOptions();
configureDefaults();
} else if (attr == ATTR_APPEARANCE) {

/////////////////////////////////////////button order///////////////////////////////
} else if (value == APPEAR_ASS) {
SplitterAttributes.order=1;
ordershow = (AttributeOption) value;
configureOptions();
configureDefaults();

} else if (value == APPEAR_DESS) {
SplitterAttributes.order =-1;
ordershow = (AttributeOption) value;
configureOptions();
configureDefaults();

}
///////////////////////////////////////button order////////////////////////////////

else if (attr == ATTR_APPEARANCE) {
appear = (AttributeOption) value;
parameters = null;
} else if (attr instanceof BitOutAttribute) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ splitterAppearanceCenter = Mittig
splitterAppearanceRight = Rechts
splitterDistributeAscending = Aufsteigend verteilen
splitterDistributeDescending = Absteigend verteilen
splitterDistribute = Bitverteilung
#
# circuit/WireClass.java
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ splitterBitWidthAttr= \u0395\u03cd\u03c1\u03bf\u03c2 Bit \u0395\u03b9\u03c3\u03c
splitterFanOutAttr= \u0392\u03b1\u03b8\u03bc\u03cc\u03c2 \u039f\u03b4\u03ae\u03b3\u03b7\u03c3\u03b7\u03c2
splitterBitAttr= Bit %s
splitterBitNone= \u039a\u03b1\u03bd\u03ad\u03bd\u03b1
splitterDistributeAscending = \u0391\u03cd\u03be\u03b7\u03c3\u03b7\u0020\u03c4\u03b7\u03c2\u0020\u03b4\u03b9\u03b1\u03bd\u03bf\u03bc\u03ae\u03c2
splitterDistributeDescending = \u03a6\u03b8\u03af\u03bd\u03bf\u03c5\u03c3\u03b1\u0020\u03ba\u03b1\u03c4\u03b1\u03bd\u03bf\u03bc\u03ae
splitterDistribute = \u039a\u03b1\u03c4\u03b1\u03bd\u03bf\u03bc\u03ae\u000a bit
#
# circuit/WireClass.java
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ splitterAppearanceCenter = Centered
splitterAppearanceRight = Right-handed
splitterDistributeAscending = Distribute Ascending
splitterDistributeDescending = Distribute Descending
splitterDistribute = Bit Distribute
#
# circuit/WireClass.java
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ splitterBitWidthAttr = Bits De Entrada
splitterFanOutAttr = Fan Out
splitterBitAttr = Bit %s
splitterBitNone = Nada
splitterDistributeAscending = Aumento de la distribución
splitterDistributeDescending = Distribución descendente
splitterDistribute = Distribución de bit
#
# circuit/WireClass.java
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ splitterAppearanceCenter = Centr
splitterAppearanceRight = A droite
splitterDistributeAscending = Distribué en montant
splitterDistributeDescending = Distribué en descendant
splitterDistribute = Répartition des bits
#
# circuit/WireClass.java
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ splitterAppearanceCenter = Centrato
splitterAppearanceRight = Rivolto a destra
splitterDistributeAscending = Distribuzione Crescente
splitterDistributeDescending = Distribuzione Decrescente
splitterDistribute = Distribuzione bit
#
# circuit/WireClass.java
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ splitterAppearanceCenter = Central
splitterAppearanceRight = À direita
splitterDistributeAscending = Distribuir em ordem crescente
splitterDistributeDescending = Distribuir em ordem decrescente
splitterDistribute = Distribuição de bits
#
# circuit/WireClass.java
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ splitterAppearanceCenter= \u041f\u043e \u0446\u0435\u043d\u0442\u0440\u0443
splitterAppearanceRight= \u041f\u0440\u0430\u0432\u043e\u0440\u0443\u043a\u0438\u0439
splitterDistributeAscending= \u0420\u0430\u0441\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044e
splitterDistributeDescending= \u0420\u0430\u0441\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u043e \u0443\u0431\u044b\u0432\u0430\u043d\u0438\u044e
splitterDistribute = \u0411\u0438\u0442\u043e\u0432\u043e\u0435\u0020\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435
#
# circuit/WireClass.java
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ splitterAppearanceCenter = \u4E2D\u5FC3\u5F0F
splitterAppearanceRight = \u53F3\u624B\u5F0F
splitterDistributeAscending = \u5206\u7EBF\u7AEF\u5347\u5E8F\u6392\u5217
splitterDistributeDescending = \u5206\u7EBF\u7AEF\u964D\u5E8F\u6392\u5217
splitterDistribute = \u6bd4\u7279\u5206\u5e03
#
# circuit/WireClass.java
#
Expand Down

0 comments on commit f6e8689

Please sign in to comment.