From e93c42193db382ea70f2f38fea3d02f740351007 Mon Sep 17 00:00:00 2001 From: Anderson Antunes Date: Wed, 27 Jan 2016 05:38:04 +0000 Subject: [PATCH] Few GUI improvements --- src/resources/Welcome.html | 22 ++--- src/s3f/pyrite/core/Circuit.java | 9 ++ .../ForceDirectedGraphFoldingAlgorithm.java | 2 +- .../fdgs/ForceDirectedGraphSimulation.java | 19 +++- src/s3f/pyrite/ui/ConfigurationTab.java | 60 +++++++++++- .../ui/graphmonitor/GraphMonitor3D.java | 2 +- .../ui/graphmonitor/TempTestWindow.java | 91 ++++++++++++++++++- 7 files changed, 183 insertions(+), 22 deletions(-) diff --git a/src/resources/Welcome.html b/src/resources/Welcome.html index d71cd86..2ea071b 100644 --- a/src/resources/Welcome.html +++ b/src/resources/Welcome.html @@ -2,30 +2,24 @@

Welcome to Pyrite!

-

The #1 Volumetric Circuit Editor

-

by Anderson Antunes - anderson.utf@gmail.com

-

Warning! This is an pre-release build, lots of bugs ahead

+

The first Volumetric Circuit Editor

+

by Anderson Antunes - https://github.com/anderson-

+

Warning! This is a pre-alpha build, lots of bugs ahead

 2D Schematic editor shortcuts

-

  [;] - add sub-circuit (rigth click-edit for choosing the circuit) +

  [;] - add sub-circuit (rigth click>edit for choosing the circuit)

  [+] - add input

  [-] - add output

 3D schematic editor shortcuts

+

  [MOUSE1] - enter panel / select object +

  [ESC] - leave panel

  [W][A][S][D] or [ARROWS] - move

  [SPACE] or [PAGE UP] - move up

  [SHIFT] or [PAGE DOWN] - move down -

  [1]~[5] - change grid type -

  [r] - place source and ground in positions {4, 2, 2} and {2, 2, 2}, respectively -

  [ENTER] - start auto fitting -

  [h] - start breadcrumb placer -

  [b] - set background color -

  [I][J][K][L] - move selected components -

  [c] - clear selection -

  [CTRL] + [Z] - undo -

  [CTRL] + [R] - redo +

 * Use the floating window to interact with the circuit

-

Project page: http://hackaday.io/project/2396

+

Project page: https://hackaday.io/project/2396

GitHub: https://github.com/anderson-/Pyrite

diff --git a/src/s3f/pyrite/core/Circuit.java b/src/s3f/pyrite/core/Circuit.java index cc1fc68..8918911 100644 --- a/src/s3f/pyrite/core/Circuit.java +++ b/src/s3f/pyrite/core/Circuit.java @@ -32,6 +32,7 @@ public class Circuit { private final Vector outputs; private final Vector subCircuits; private String status = ""; + private boolean satisfied; public Circuit() { edges = new Vector<>(); @@ -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> pos; diff --git a/src/s3f/pyrite/core/fdgfa/ForceDirectedGraphFoldingAlgorithm.java b/src/s3f/pyrite/core/fdgfa/ForceDirectedGraphFoldingAlgorithm.java index 94f31bf..b8ce91e 100644 --- a/src/s3f/pyrite/core/fdgfa/ForceDirectedGraphFoldingAlgorithm.java +++ b/src/s3f/pyrite/core/fdgfa/ForceDirectedGraphFoldingAlgorithm.java @@ -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); @@ -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(); diff --git a/src/s3f/pyrite/core/fdgfa/fdgs/ForceDirectedGraphSimulation.java b/src/s3f/pyrite/core/fdgfa/fdgs/ForceDirectedGraphSimulation.java index 2210d71..06c1952 100644 --- a/src/s3f/pyrite/core/fdgfa/fdgs/ForceDirectedGraphSimulation.java +++ b/src/s3f/pyrite/core/fdgfa/fdgs/ForceDirectedGraphSimulation.java @@ -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; @@ -46,6 +48,10 @@ public ForceDirectedGraphSimulation(Circuit circuit) { this.circuit = circuit; } + public void setFlatMode(boolean flatMode) { + this.flatMode = flatMode; + } + public Circuit getGraph() { return circuit; } @@ -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; @@ -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; @@ -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() { diff --git a/src/s3f/pyrite/ui/ConfigurationTab.java b/src/s3f/pyrite/ui/ConfigurationTab.java index 53a1ec6..e3bf42f 100644 --- a/src/s3f/pyrite/ui/ConfigurationTab.java +++ b/src/s3f/pyrite/ui/ConfigurationTab.java @@ -38,6 +38,11 @@ public class ConfigurationTab { } + @Retention(RetentionPolicy.RUNTIME) + public @interface BreakLine { + + } + @Retention(RetentionPolicy.RUNTIME) public @interface CustomComponent { @@ -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 { @@ -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 { @@ -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(); diff --git a/src/s3f/pyrite/ui/graphmonitor/GraphMonitor3D.java b/src/s3f/pyrite/ui/graphmonitor/GraphMonitor3D.java index 0f14be7..0ae227e 100644 --- a/src/s3f/pyrite/ui/graphmonitor/GraphMonitor3D.java +++ b/src/s3f/pyrite/ui/graphmonitor/GraphMonitor3D.java @@ -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) { diff --git a/src/s3f/pyrite/ui/graphmonitor/TempTestWindow.java b/src/s3f/pyrite/ui/graphmonitor/TempTestWindow.java index c4edecb..763781f 100644 --- a/src/s3f/pyrite/ui/graphmonitor/TempTestWindow.java +++ b/src/s3f/pyrite/ui/graphmonitor/TempTestWindow.java @@ -6,13 +6,16 @@ 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; /** * @@ -20,20 +23,56 @@ */ 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); } @@ -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) {