Skip to content

Commit

Permalink
Few GUI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
anderson- committed Jan 27, 2016
1 parent 0722e1d commit e93c421
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 22 deletions.
22 changes: 8 additions & 14 deletions src/resources/Welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,24 @@
<body>
<center>
<h1>Welcome to Pyrite!</h1>
<h2>The #1 Volumetric Circuit Editor</h2>
<h3><em>by Anderson Antunes - anderson.utf@gmail.com</em></h3>
<h2><font color=red>Warning! This is an pre-release build, <em>lots of bugs ahead</em></font></h2>
<h2>The first Volumetric Circuit Editor</h2>
<h3><em>by Anderson Antunes - https://github.com/anderson-</em></h3>
<h2><font color=red>Warning! This is a pre-alpha build, <em>lots of bugs ahead</em></font></h2>
</center>
<h3>&emsp;2D Schematic editor shortcuts</h3>
<p>&emsp;&emsp;[;] - add sub-circuit (rigth click-edit for choosing the circuit)
<p>&emsp;&emsp;[;] - add sub-circuit (rigth click>edit for choosing the circuit)
<p>&emsp;&emsp;[+] - add input
<p>&emsp;&emsp;[-] - add output
<h3>&emsp;3D schematic editor shortcuts</h3>
<p>&emsp;&emsp;[MOUSE1] - enter panel / select object
<p>&emsp;&emsp;[ESC] - leave panel
<p>&emsp;&emsp;[W][A][S][D] or [ARROWS] - move
<p>&emsp;&emsp;[SPACE] or [PAGE UP] - move up
<p>&emsp;&emsp;[SHIFT] or [PAGE DOWN] - move down
<p>&emsp;&emsp;[1]~[5] - change grid type
<p>&emsp;&emsp;[r] - place source and ground in positions {4, 2, 2} and {2, 2, 2}, respectively
<p>&emsp;&emsp;[ENTER] - start auto fitting
<p>&emsp;&emsp;[h] - start breadcrumb placer
<p>&emsp;&emsp;[b] - set background color
<p>&emsp;&emsp;[I][J][K][L] - move selected components
<p>&emsp;&emsp;[c] - clear selection
<p>&emsp;&emsp;[CTRL] + [Z] - undo
<p>&emsp;&emsp;[CTRL] + [R] - redo
<p>&emsp;* Use the floating window to interact with the circuit
<p>
<center>
<h2>Project page: http://hackaday.io/project/2396</h2>
<h2>Project page: https://hackaday.io/project/2396</h2>
<h2>GitHub: https://github.com/anderson-/Pyrite</h2>
</center>
</body>
Expand Down
9 changes: 9 additions & 0 deletions src/s3f/pyrite/core/Circuit.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class Circuit {
private final Vector<Component> outputs;
private final Vector<Circuit> subCircuits;
private String status = "";
private boolean satisfied;

public Circuit() {
edges = new Vector<>();
Expand Down Expand Up @@ -313,6 +314,14 @@ public void printDOT() {
}
}

public void setSatisfied(boolean satisfied){
this.satisfied = satisfied;
}

public boolean isSatisfied() {
return satisfied;
}

public static class POJO {

public List<List<Double>> pos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
public class ForceDirectedGraphFoldingAlgorithm implements FoldingAlgorithm {

public static double[] weights = new double[]{0.05, 0.15, 0.1, 0.7, 0.0};
private static final int edgeLen = 16;
public static final ConvexUniformHoneycomb H = new SimpleCubicHoneycomb(edgeLen, true);

Expand All @@ -47,7 +48,6 @@ public void fold(Circuit circuit) {
ForceDirectedGraphSimulation sim = new ForceDirectedGraphSimulation(circuit);
sim.runSimulation();
GraphFolder.waitForEqui(sim);
double[] weights = new double[]{0.05, 0.15, 0.1, 0.7, 0.0};

GraphFolder.fold(circuit, sim, new GreedyStrategy(H, weights), H);
sim.kill();
Expand Down
19 changes: 17 additions & 2 deletions src/s3f/pyrite/core/fdgfa/fdgs/ForceDirectedGraphSimulation.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package s3f.pyrite.core.fdgfa.fdgs;

import java.awt.Color;
import java.util.logging.Level;
import java.util.logging.Logger;
import s3f.pyrite.core.Circuit;
import s3f.pyrite.core.Component;
import s3f.pyrite.core.fdgfa.fdgs.force.DefaultForce;
Expand All @@ -46,6 +48,10 @@ public ForceDirectedGraphSimulation(Circuit circuit) {
this.circuit = circuit;
}

public void setFlatMode(boolean flatMode) {
this.flatMode = flatMode;
}

public Circuit getGraph() {
return circuit;
}
Expand Down Expand Up @@ -96,6 +102,15 @@ public void run() {
simThread.start();
return true;
}

public void waitSim(){
if (simThread != null && simThread.isAlive()) {
try {
simThread.join();
} catch (InterruptedException ex) {
}
}
}

public void kill() {
kill = true;
Expand Down Expand Up @@ -129,12 +144,12 @@ public void step() {
e.printStackTrace();
}

totalforce = affectForces(forces);
if (flatMode) {
for (Component node : circuit.getComponents()) {
node.getPos().setZ(0);
}
}
totalforce = affectForces(forces);

if (tick.get() > 7 && getKE() < 1500) { //refine calculations
threads = 1;
Expand All @@ -143,7 +158,7 @@ public void step() {
}

public boolean isEqu() {
return (tick.get() > 7 && getKE() < 5000);
return (tick.get() > 7 && getKE() < 50000);
}

public double getKE() {
Expand Down
60 changes: 59 additions & 1 deletion src/s3f/pyrite/ui/ConfigurationTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public class ConfigurationTab {

}

@Retention(RetentionPolicy.RUNTIME)
public @interface BreakLine {

}

@Retention(RetentionPolicy.RUNTIME)
public @interface CustomComponent {

Expand All @@ -50,6 +55,14 @@ public class ConfigurationTab {
public long interval();
}

@Retention(RetentionPolicy.RUNTIME)
public @interface TrackValueLabel {

public String name();

public long interval();
}

@Retention(RetentionPolicy.RUNTIME)
public @interface Panel {

Expand Down Expand Up @@ -91,19 +104,48 @@ public void createFrame(Object parameters) {
}

public void build(Object parameters, Container panel) {
JPanel dontBreakLinePanel = null;
boolean dontBreakLine = false;
for (Field field : parameters.getClass().getDeclaredFields()) {
field.setAccessible(true);
for (Annotation annotation : field.getDeclaredAnnotations()) {
if (annotation instanceof DontBreakLine) {
if (dontBreakLinePanel == null) {
dontBreakLinePanel = new JPanel();
}
dontBreakLine = true;
continue;
} else if (annotation instanceof BreakLine) {
if (dontBreakLinePanel != null) {
panel.add(dontBreakLinePanel);
dontBreakLinePanel = null;
}
dontBreakLine = false;
continue;
}

try {
JComponent c = createJComponent(annotation, field, parameters);
if (c != null) {
panel.add(c);
if (dontBreakLine) {
dontBreakLinePanel.add(c);
dontBreakLine = false;
} else {
if (dontBreakLinePanel != null) {
panel.add(dontBreakLinePanel);
dontBreakLinePanel = null;
}
panel.add(c);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
if (dontBreakLinePanel != null) {
panel.add(dontBreakLinePanel);
}
}

private JComponent createJComponent(Annotation annotation, final Field field, final Object obj) throws Exception {
Expand Down Expand Up @@ -151,6 +193,22 @@ public void actionPerformed(ActionEvent e) {
}
});
return c;
} else if (annotation instanceof TrackValueLabel) {
final JLabel label = new JLabel();
final TrackValueLabel trackValue = (TrackValueLabel) annotation;
new Thread() {
@Override
public void run() {
while (true) {
try {
label.setText(trackValue.name() + field.get(obj));
Thread.sleep(trackValue.interval());
} catch (Exception ex) {
}
}
}
}.start();
return label;
} else if (annotation instanceof Spinner) {
Spinner spinner = (Spinner) annotation;
JPanel p = new JPanel();
Expand Down
2 changes: 1 addition & 1 deletion src/s3f/pyrite/ui/graphmonitor/GraphMonitor3D.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public synchronized void draw(GL2 gl, GLUT glut, boolean colorPicking) {
String label = e.getSubComponent();

gl.glLineWidth(2f);
if (ForceDirectedGraphFoldingAlgorithm.H.isSatisfied(e)) {
if (circuit.isSatisfied() || ForceDirectedGraphFoldingAlgorithm.H.isSatisfied(e)) {
gl.glPushMatrix();
DrawingPanel3D.rotateAndGoToMidPoint(gl, new float[]{(float) p.getX(), (float) p.getY(), (float) p.getZ()}, new float[]{(float) p2.getX(), (float) p2.getY(), (float) p2.getZ()});
if (label != null) {
Expand Down
91 changes: 88 additions & 3 deletions src/s3f/pyrite/ui/graphmonitor/TempTestWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,73 @@
package s3f.pyrite.ui.graphmonitor;

import java.awt.event.ActionEvent;
import java.util.ArrayList;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import s3f.pyrite.core.Circuit;
import s3f.pyrite.core.Component;
import s3f.pyrite.core.fdgfa.ForceDirectedGraphFoldingAlgorithm;
import s3f.pyrite.core.fdgfa.fdgs.ForceDirectedGraphSimulation;
import s3f.pyrite.ui.ConfigurationTab;
import s3f.pyrite.ui.ConfigurationTab.*;
import s3f.pyrite.util.Vector;

/**
*
* @author andy
*/
public class TempTestWindow {

@Spinner(name = "1: ", max = 100, min = 0, step = 1)
int p1 = 5;
@Spinner(name = "2: ", max = 100, min = 0, step = 1)
int p2 = 15;
@Spinner(name = "3: ", max = 100, min = 0, step = 1)
int p3 = 10;
@Spinner(name = "4: ", max = 100, min = 0, step = 1)
int p4 = 70;
@Spinner(name = "5: ", max = 100, min = 0, step = 1)
int p5 = 0;
@DontBreakLine
@CustomComponent(method = "buildAsd")
public String s = "sjadh";
@DontBreakLine
@CustomComponent(method = "buildAsd2")
public String s2 = "sjadh";

@BreakLine
@DontBreakLine
@Spinner(name = "Sec: ", max = 100, min = 0, step = 1)
int sec = 1;
@DontBreakLine
@Spinner(name = "Delay: ", max = 1000, min = 0, step = 1)
int delay = 10;
@BreakLine

@DontBreakLine
@Checkbox(name = "Flat")
boolean flatmode;
@DontBreakLine
@CustomComponent(method = "buildAsd3")
public String s3 = "sjadh";

@TrackValueLabel(interval = 100, name = "Is busy: ")
Thread t = null;

public JButton buildAsd() {
return new JButton(new AbstractAction("Hello") {
return new JButton(new AbstractAction("Fold") {
@Override
public void actionPerformed(ActionEvent ae) {
// ForceDirectedGraphSimulation s = new ForceDirectedGraphSimulation(circuit);
// s.runSimulation(1000, 10);
if (t == null || !t.isAlive()) {
circuit.setSatisfied(false);
t = new Thread("Fold Thread") {
@Override
public void run() {
ForceDirectedGraphFoldingAlgorithm.weights[0] = p1 / 100.0;
ForceDirectedGraphFoldingAlgorithm.weights[1] = p2 / 100.0;
ForceDirectedGraphFoldingAlgorithm.weights[2] = p3 / 100.0;
ForceDirectedGraphFoldingAlgorithm.weights[3] = p4 / 100.0;
ForceDirectedGraphFoldingAlgorithm.weights[4] = p5 / 100.0;
new ForceDirectedGraphFoldingAlgorithm().fold(circuit);
}

Expand All @@ -44,6 +83,52 @@ public void run() {
});
}

public JButton buildAsd2() {
return new JButton(new AbstractAction("Force Stop") {
@Override
public void actionPerformed(ActionEvent ae) {
if (t != null && t.isAlive()) {
t.stop();
if (!t.isAlive()) {
System.err.println("Stop fail");
}
}
}
});
}

public JButton buildAsd3() {
return new JButton(new AbstractAction("Reset layout") {
@Override
public void actionPerformed(ActionEvent ae) {
if (t == null || !t.isAlive()) {
synchronized (circuit) {
for (Component n : new ArrayList<>(circuit.getComponents())) {
n.setFixed(false);
}
}
final ForceDirectedGraphSimulation s = new ForceDirectedGraphSimulation(circuit);
s.setFlatMode(flatmode);
s.runSimulation(sec * 1000, delay);
t = new Thread() {
@Override
public void run() {
s.waitSim();
circuit.setSatisfied(true);
synchronized (circuit) {
for (Component n : new ArrayList<>(circuit.getComponents())) {
n.setFixed(true);
}
}
}
};
t.start();
}
}
}
);
}

Circuit circuit;

public TempTestWindow(Circuit circuit) {
Expand Down

0 comments on commit e93c421

Please sign in to comment.