Skip to content

Commit

Permalink
setting added- advance drawer dialog added.
Browse files Browse the repository at this point in the history
TODO : diode - graphic(draw circuit)
help page
  • Loading branch information
alinourian committed Aug 5, 2020
1 parent 8017e00 commit 205a1cf
Show file tree
Hide file tree
Showing 18 changed files with 590 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Circuit examples/current sources only and res/file.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ G2 2 0 1 0 3
R1 0 1 1
R2 0 2 3
R3 2 3 2
R4 3 0 4
R4 0 3 4
dV 1m
dI 1m
dT 1m
Expand Down
14 changes: 11 additions & 3 deletions Circuit examples/current sources only and res/new 1.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
I1 1 0 1 0 0 0
I1 1 0 10 0 0 0
R1 0 1 1
C1 0 1 1
dV 1u
R2 0 1 1
R3 0 1 1
R4 0 1 1
R5 0 1 1
R6 0 1 1
R7 0 1 1
R8 0 1 1
R9 0 1 1
R10 0 1 1
dV 1m
dI 1m
dT 1m
.tran 5
19 changes: 15 additions & 4 deletions src/controller/Solver.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class Solver {
public static double time = 0;
public static int step = 0;
public static int measureErrorEachStep = 0;
private final int MAX_ERROR_MEASUREMENT_TRYING = 5_000_000;
private final double KCL_ERROR = Math.pow(10, -2);
private final int MAX_ERROR_MEASUREMENT_TRYING = 6_000_000;
private static double KCL_ERROR = Math.pow(10, -2);
public static StringBuilder output = new StringBuilder();
public ArrayList<Integer> errors = new ArrayList<>();

Expand All @@ -38,9 +38,13 @@ public boolean run() {
unionCreator.run();

do {
if (MainPageController.simulateStop) {
Errors.stopImmediately();
return false;
}

double _time = ((double) Math.round(time * 10000))/10000;
Errors.print("\n***(time = " + _time + ")***");
//Errors.print("\n***(time = " + _time + ")***");
output.append("\n***(time = ").append(_time).append(")***");

if (!solve()) {
Expand Down Expand Up @@ -216,7 +220,7 @@ private void saveCurrents() {
private void printVoltages() {
for (Node node : controller.getNodes()) {
double _voltage = ((double) Math.round(node.getVoltage() * 1000))/1000;
Errors.print(node.getName() + " => voltage : " + _voltage);
//Errors.print(node.getName() + " => voltage : " + _voltage);
Solver.output.append("\n=> voltage node ").append(node.getName()).append(" : ").append(_voltage);
}
}
Expand All @@ -239,4 +243,11 @@ private boolean checkError2() {
return true;
}

public static double getKclError() {
return KCL_ERROR;
}

public static void setKCL_ERROR(double KCL_ERROR) {
Solver.KCL_ERROR = KCL_ERROR;
}
}
4 changes: 2 additions & 2 deletions src/model/CurrentControlledCurrentSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public double getCurrent(Node node) {
double value;
if (branch instanceof Element) {
Element element = (Element)branch;
value = gain * Math.abs(element.getCurrent(element.getNodeP()));
value = gain * element.getCurrent(element.getNodeN());
} else {
Source source = (Source)branch;
value = gain * Math.abs(source.getCurrent(source.getNodeP()));
value = gain * source.getCurrent(source.getNodeP());
}
if (node.getName().equals(nodeP.getName())) {
return value;
Expand Down
4 changes: 2 additions & 2 deletions src/model/CurrentControlledVoltageSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public double getVoltage(Node node) {
double value;
if (branch instanceof Element) {
Element element = (Element)branch;
value = gain * Math.abs(element.getCurrent(element.getNodeP()));
value = gain * element.getCurrent(element.getNodeN());
} else {
Source source = (Source)branch;
value = gain * Math.abs(source.getCurrent(source.getNodeP()));
value = gain * source.getCurrent(source.getNodeP());
}
if (node.getName().equals(nodeP.getName())) {
return value;
Expand Down
5 changes: 5 additions & 0 deletions src/view/Errors.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public static void transitionFailed() {
System.err.println(string);
}

public static void stopImmediately() {
string = "Program stopped!";
System.err.println(string);
}

public static void errors(int num, String errorType) {
string = "ERROR " + num + " : \n" + errorType;
System.err.println(string);
Expand Down
12 changes: 6 additions & 6 deletions src/view/file/CommandsRegex.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
public enum CommandsRegex {
COMMENT_COMMAND("\\*.*"),
//PART 1 - CURRENT SOURCES
RESISTOR("(R\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s*"),
CAPACITOR("(C\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s*"),
INDUCTOR("(L\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s*"),
RESISTOR("([R|r]\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s*"),
CAPACITOR("([C|c]\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s*"),
INDUCTOR("([L|l]\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s*"),
CURRENT_SOURCE("(I\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s*"),
VOLTAGE_CONTROLLED_CURRENT_SOURCE("(G\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s*"),
CURRENT_CONTROLLED_CURRENT_SOURCE("(F\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s*"),
Expand All @@ -17,9 +17,9 @@ public enum CommandsRegex {
VOLTAGE_CONTROLLED_VOLTAGE_SOURCE("(E\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s*"),
CURRENT_CONTROLLED_VOLTAGE_SOURCE("(H\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s*"),
//PART 3 - ANALYSIS PROPERTIES
DELTA_VOLTAGE("dV\\s+(\\S+)\\s*"),
DELTA_CURRENT("dI\\s+(\\S+)\\s*"),
DELTA_TIME("dT\\s+(\\S+)\\s*"),
DELTA_VOLTAGE("d[V|v]\\s+(\\S+)\\s*"),
DELTA_CURRENT("d[I|i]\\s+(\\S+)\\s*"),
DELTA_TIME("d[T|t]\\s+(\\S+)\\s*"),
TRAN("\\.tran\\s+(\\S+)\\s*");

private final Pattern commandPattern;
Expand Down
4 changes: 2 additions & 2 deletions src/view/file/FileInputProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private static boolean addCurrentSource(String name, String node1, String node2,
double amplitude = amplitudeFactor == -1 ? Double.parseDouble(s_amplitude) :
Double.parseDouble(s_amplitude.substring(0, s_amplitude.length() - 1)) * amplitudeFactor;
double frequency = frequencyFactor == -1 ? Double.parseDouble(s_frequency) :
Double.parseDouble(s_frequency.substring(0, s_amplitude.length() - 1)) * frequencyFactor;
Double.parseDouble(s_frequency.substring(0, s_frequency.length() - 1)) * frequencyFactor;
double phase = phaseFactor == -1 ? Double.parseDouble(s_phase) :
Double.parseDouble(s_phase.substring(0, s_phase.length() - 1)) * phaseFactor;
controller.addSource(name, node1, node2, value, amplitude, frequency, phase, Type.CURRENT_SOURCE);
Expand Down Expand Up @@ -207,7 +207,7 @@ private static boolean addVoltageSource(String name, String node1, String node2,
double amplitude = amplitudeFactor == -1 ? Double.parseDouble(s_amplitude) :
Double.parseDouble(s_amplitude.substring(0, s_amplitude.length() - 1)) * amplitudeFactor;
double frequency = frequencyFactor == -1 ? Double.parseDouble(s_frequency) :
Double.parseDouble(s_frequency.substring(0, s_amplitude.length() - 1)) * frequencyFactor;
Double.parseDouble(s_frequency.substring(0, s_frequency.length() - 1)) * frequencyFactor;
double phase = phaseFactor == -1 ? Double.parseDouble(s_phase) :
Double.parseDouble(s_phase.substring(0, s_phase.length() - 1)) * phaseFactor;
controller.addSource(name, node1, node2, value, amplitude, frequency, phase, Type.VOLTAGE_SOURCE);
Expand Down
52 changes: 46 additions & 6 deletions src/view/fxml/MainPageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import javafx.scene.control.*;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.stage.FileChooser;
Expand All @@ -27,6 +29,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Optional;
import java.util.Scanner;
import java.util.concurrent.ExecutorService;
Expand All @@ -43,6 +46,7 @@ public class MainPageController {
@FXML private Label percentLabel;
@FXML private BorderPane borderPane;

public static boolean simulateStop = false;

private File file;
private String firstBackUpText;
Expand All @@ -52,6 +56,7 @@ public class MainPageController {
private long timer = -1;
private AnimationTimer animationTimer;
private double additional = 0;
private String statusKCLError = "10m";

// MENU OPTIONS && TOOLBAR OPTIONS

Expand Down Expand Up @@ -151,7 +156,33 @@ public void showPrintPreview() throws IOException {
}

public void setting() {
//TODO
HashMap<String, Double> results = new HashMap<>();
results.put("100m", 0.1);results.put("10m", 0.01);
results.put("1m", 0.001); results.put("100u", 0.0001);
results.put("10u", 0.00001); results.put("1u", 0.000001);
ArrayList<String> list = new ArrayList<>();
list.add("100m"); list.add("10m"); list.add("1m");
list.add("100u"); list.add("10u"); list.add("1u");

ChoiceDialog<String> dialog = new ChoiceDialog<>(statusKCLError, list);
dialog.setTitle("Setting");
dialog.setHeaderText("");
Stage dialogStage = (Stage) dialog.getDialogPane().getScene().getWindow();
dialogStage.getIcons().add(new Image("view/img/setting-icon.png"));
dialog.setContentText("Choose KCL_ERROR:");
ImageView imageView = new ImageView(new Image("view/img/setting-icon.png"));
imageView.setFitHeight(100);
imageView.setFitWidth(100);
dialog.setGraphic(imageView);

// Traditional way to get the response value.
Optional<String> result = dialog.showAndWait();
if (result.isPresent()) {
Solver.setKCL_ERROR(results.get(result.get()));
statusKCLError = result.get();
System.out.println("KCL ERROR set at : " + Solver.getKclError());
}

}

public void Exit() {
Expand Down Expand Up @@ -182,7 +213,7 @@ public void paste() {
}

public void delete() {
//TODO
resetPage();
}

public void zoomIn() {
Expand All @@ -205,6 +236,7 @@ public void getHelp() throws IOException {
}

public void simulate() {
simulateStop = false;
errorTextArea.setText("");
simulating();
Task displayMessage = new Task<Void>() {
Expand All @@ -224,6 +256,7 @@ public Void call() {
errorTextArea.setText("File successfully simulated.\n" + Solver.output);
percentLabel.setText("100%");
progressBar.setProgress(1);
Errors.print("KCL ERROR : " + Solver.getKclError());
} else {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setContentText("Can not simulate the file!");
Expand All @@ -242,8 +275,15 @@ public Void call() {
executor.execute(displayMessage);
}

public void stopSimulating() {
simulateStop = false;
}

public void drawVCPGraphs() {
if (!FileScanner.hasFile) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setContentText("Please simulate your file first.");
alert.show();
return;
}
ArrayList<String> choices = new ArrayList<>();
Expand Down Expand Up @@ -307,8 +347,8 @@ public void drawVCPGraphs() {
}

public void drawCircuit() {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setContentText("not yet!");
//Alert alert = new Alert(Alert.AlertType.ERROR);
//alert.setContentText("not yet!");
//alert.show();
//Pane pane = DrawCircuit.drawCircuit();
//TODO
Expand All @@ -322,7 +362,7 @@ private void simulating() {
progressBar.setVisible(true);
percentLabel.setVisible(true);
percentLabel.setText("0%");
progressBar.setProgress(-1);
progressBar.setProgress(0);
}

public void fillProgress() {
Expand All @@ -334,7 +374,7 @@ public void handle(long now) {
timer = now;
progressBar.setProgress(0);
} else if (now - timer > PERIOD) {
if (additional == 0.1 && progressBar.getProgress() < 1) {
if (additional == 0.1 && progressBar.getProgress() + additional <= 1) {
progressBar.setProgress(progressBar.getProgress() + additional);
timer = now;
double percent = progressBar.getProgress() * 100;
Expand Down
Loading

0 comments on commit 205a1cf

Please sign in to comment.