mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-19 01:44:44 -04:00
added option to create only NAnd-Gates
This commit is contained in:
parent
b1b3ba0378
commit
c5bb167715
@ -1,5 +1,7 @@
|
|||||||
package de.neemann.digital.analyse.expression;
|
package de.neemann.digital.analyse.expression;
|
||||||
|
|
||||||
|
import de.neemann.digital.analyse.expression.modify.ExpressionModifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An expression which can be evaluated to a boolean value
|
* An expression which can be evaluated to a boolean value
|
||||||
*
|
*
|
||||||
@ -25,6 +27,14 @@ public interface Expression {
|
|||||||
*/
|
*/
|
||||||
<V extends ExpressionVisitor> V traverse(V visitor);
|
<V extends ExpressionVisitor> V traverse(V visitor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to modify the ast
|
||||||
|
*
|
||||||
|
* @param modifier the modifier
|
||||||
|
*/
|
||||||
|
default void modify(ExpressionModifier modifier) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String used to order expressions
|
* String used to order expressions
|
||||||
*
|
*
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package de.neemann.digital.analyse.expression;
|
package de.neemann.digital.analyse.expression;
|
||||||
|
|
||||||
|
import de.neemann.digital.analyse.expression.modify.ExpressionModifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public final class Not implements Expression {
|
public final class Not implements Expression {
|
||||||
|
|
||||||
private final Expression expression;
|
private Expression expression;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a not expression
|
* Creates a not expression
|
||||||
@ -25,7 +27,7 @@ public final class Not implements Expression {
|
|||||||
return new Not(a);
|
return new Not(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Not(Expression expression) {
|
public Not(Expression expression) {
|
||||||
this.expression = expression;
|
this.expression = expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,6 +44,12 @@ public final class Not implements Expression {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void modify(ExpressionModifier modifier) {
|
||||||
|
expression.modify(modifier);
|
||||||
|
expression = modifier.modify(expression);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getOrderString() {
|
public String getOrderString() {
|
||||||
return expression.getOrderString();
|
return expression.getOrderString();
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package de.neemann.digital.analyse.expression;
|
package de.neemann.digital.analyse.expression;
|
||||||
|
|
||||||
|
import de.neemann.digital.analyse.expression.modify.ExpressionModifier;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -101,6 +103,15 @@ public abstract class Operation implements Expression {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void modify(ExpressionModifier modifier) {
|
||||||
|
for (int i = 0; i < expr.size(); i++) {
|
||||||
|
Expression e = expr.get(i);
|
||||||
|
e.modify(modifier);
|
||||||
|
expr.set(i, modifier.modify(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the sub expressions
|
* @return the sub expressions
|
||||||
*/
|
*/
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
package de.neemann.digital.analyse.expression.modify;
|
||||||
|
|
||||||
|
import de.neemann.digital.analyse.expression.Expression;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hneemann
|
||||||
|
*/
|
||||||
|
public interface ExpressionModifier {
|
||||||
|
ExpressionModifier IDENTITY = expression -> expression;
|
||||||
|
|
||||||
|
Expression modify(Expression expression);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package de.neemann.digital.analyse.expression.modify;
|
||||||
|
|
||||||
|
import de.neemann.digital.analyse.expression.Expression;
|
||||||
|
import de.neemann.digital.analyse.expression.Operation;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import static de.neemann.digital.analyse.expression.Not.not;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hneemann
|
||||||
|
*/
|
||||||
|
public class NAnd implements ExpressionModifier {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Expression modify(Expression expression) {
|
||||||
|
if (expression instanceof Operation.Or) {
|
||||||
|
ArrayList<Expression> exp = new ArrayList<>();
|
||||||
|
for (Expression e : ((Operation.Or) expression).getExpressions())
|
||||||
|
exp.add(not(e));
|
||||||
|
return not(Operation.and(exp));
|
||||||
|
} else
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package de.neemann.digital.analyse.expression.modify;
|
||||||
|
|
||||||
|
import de.neemann.digital.analyse.expression.Expression;
|
||||||
|
import de.neemann.digital.analyse.expression.Operation;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import static de.neemann.digital.analyse.expression.Not.not;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hneemann
|
||||||
|
*/
|
||||||
|
public class NOr implements ExpressionModifier {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Expression modify(Expression expression) {
|
||||||
|
if (expression instanceof Operation.And) {
|
||||||
|
ArrayList<Expression> exp = new ArrayList<>();
|
||||||
|
for (Expression e : ((Operation.And) expression).getExpressions())
|
||||||
|
exp.add(not(e));
|
||||||
|
return not(Operation.or(exp));
|
||||||
|
} else
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,8 @@ import de.neemann.digital.analyse.expression.Expression;
|
|||||||
import de.neemann.digital.analyse.expression.ExpressionException;
|
import de.neemann.digital.analyse.expression.ExpressionException;
|
||||||
import de.neemann.digital.analyse.expression.format.FormatToExpression;
|
import de.neemann.digital.analyse.expression.format.FormatToExpression;
|
||||||
import de.neemann.digital.analyse.expression.format.FormatterException;
|
import de.neemann.digital.analyse.expression.format.FormatterException;
|
||||||
|
import de.neemann.digital.analyse.expression.modify.ExpressionModifier;
|
||||||
|
import de.neemann.digital.analyse.expression.modify.NAnd;
|
||||||
import de.neemann.digital.draw.builder.Builder;
|
import de.neemann.digital.draw.builder.Builder;
|
||||||
import de.neemann.digital.draw.builder.BuilderException;
|
import de.neemann.digital.draw.builder.BuilderException;
|
||||||
import de.neemann.digital.draw.elements.Circuit;
|
import de.neemann.digital.draw.elements.Circuit;
|
||||||
@ -122,9 +124,22 @@ public class TableFrame extends JFrame {
|
|||||||
createMenu.add(new ToolTipAction(Lang.get("menu_table_create")) {
|
createMenu.add(new ToolTipAction(Lang.get("menu_table_create")) {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent actionEvent) {
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
createCircuit();
|
createCircuit(ExpressionModifier.IDENTITY);
|
||||||
}
|
}
|
||||||
}.setToolTip(Lang.get("menu_table_create_tt")).createJMenuItem());
|
}.setToolTip(Lang.get("menu_table_create_tt")).createJMenuItem());
|
||||||
|
createMenu.add(new ToolTipAction(Lang.get("menu_table_createNAnd")) {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
createCircuit(new NAnd());
|
||||||
|
}
|
||||||
|
}.setToolTip(Lang.get("menu_table_createNAnd_tt")).createJMenuItem());
|
||||||
|
// createMenu.add(new ToolTipAction(Lang.get("menu_table_createNOr")) {
|
||||||
|
// @Override
|
||||||
|
// public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
// createCircuit(new NOr());
|
||||||
|
// }
|
||||||
|
// }.setToolTip(Lang.get("menu_table_createNOr_tt")).createJMenuItem());
|
||||||
|
|
||||||
bar.add(createMenu);
|
bar.add(createMenu);
|
||||||
|
|
||||||
|
|
||||||
@ -138,7 +153,7 @@ public class TableFrame extends JFrame {
|
|||||||
setLocationRelativeTo(parent);
|
setLocationRelativeTo(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createCircuit() {
|
private void createCircuit(ExpressionModifier modifier) {
|
||||||
try {
|
try {
|
||||||
Builder builder = new Builder(shapeFactory);
|
Builder builder = new Builder(shapeFactory);
|
||||||
HashSet<String> contained = new HashSet<>();
|
HashSet<String> contained = new HashSet<>();
|
||||||
@ -148,7 +163,8 @@ public class TableFrame extends JFrame {
|
|||||||
if (!contained.contains(name)) {
|
if (!contained.contains(name)) {
|
||||||
contained.add(name);
|
contained.add(name);
|
||||||
try {
|
try {
|
||||||
builder.addExpression(name, expression);
|
expression.modify(modifier);
|
||||||
|
builder.addExpression(name, modifier.modify(expression));
|
||||||
} catch (BuilderException e) {
|
} catch (BuilderException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@ -268,6 +268,8 @@ menu_table_columnsAdd=hinzuf\u00FCgen
|
|||||||
menu_table_columnsAdd_tt=F\u00FCgt der Tabelle eine Ergebnisspalte hinzu.
|
menu_table_columnsAdd_tt=F\u00FCgt der Tabelle eine Ergebnisspalte hinzu.
|
||||||
menu_table_create=Model erzeugen
|
menu_table_create=Model erzeugen
|
||||||
menu_table_create_tt=Erzeugt ein Model, welches der Wahrheitstabelle entspricht.
|
menu_table_create_tt=Erzeugt ein Model, welches der Wahrheitstabelle entspricht.
|
||||||
|
menu_table_createNAnd=Model erzeugen mit NAnd
|
||||||
|
menu_table_createNAnd_tt=Erzeugt ein Model, welches der Wahrheitstabelle entspricht nur mit NAnd-Gattern.
|
||||||
|
|
||||||
menu_about=\u00DCber Digital
|
menu_about=\u00DCber Digital
|
||||||
|
|
||||||
|
@ -248,6 +248,8 @@ menu_table_columnsAdd=Add a Column
|
|||||||
menu_table_columnsAdd_tt=Adds a new result column.
|
menu_table_columnsAdd_tt=Adds a new result column.
|
||||||
menu_table_create=create circuit
|
menu_table_create=create circuit
|
||||||
menu_table_create_tt=Creates a circuit which reproduces the truth table.
|
menu_table_create_tt=Creates a circuit which reproduces the truth table.
|
||||||
|
menu_table_createNAnd=create with NAnd
|
||||||
|
menu_table_createNAnd_tt=Creates a circuit which reproduces the truth table only with NAnd gates.
|
||||||
|
|
||||||
win_saveChanges=Save Changes?
|
win_saveChanges=Save Changes?
|
||||||
win_confirmExit=Confirm Exit!
|
win_confirmExit=Confirm Exit!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user