Skip to content

Commit

Permalink
added a reset View feature in view menu that resets the view to the l…
Browse files Browse the repository at this point in the history
…ast save position since students kept loosing their curcuits in the workspace. COuld improve by making it auto fit the current cricuit but this was a quicker fix and works fine for now
  • Loading branch information
sr14978 committed Nov 25, 2016
1 parent 01e1f0f commit aa50590
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/com/modsim/gui/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,10 @@ public void zoomOutToView()
view.zoomOut(view.getWidth()/2,view.getHeight()/2);
}


public void resetView()
{
view.resetView();
}


/**
Expand Down
1 change: 1 addition & 0 deletions src/com/modsim/gui/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private void addViewMenu() {
JMenu view = new JMenu("View");
view.setMnemonic(KeyEvent.VK_V);
view.add(Ops.toggleAA);
view.add(Ops.resetView);
app_menu.add(view);
}

Expand Down
16 changes: 14 additions & 2 deletions src/com/modsim/gui/view/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
*/
public class View extends JPanel {

public int zoomI = 3;
public int init_zoomI = 3;
public double init_camX = 0, init_camY = 0;

public int zoomI = init_zoomI;
public double zoom = zoomI * ZOOM_MULTIPLIER;

public static final double ZOOM_MULTIPLIER = 0.15;
public static final int ZOOM_LIMIT = 12;

public double camX = 0, camY = 0;
public double camX = init_camX, camY = init_camY;
public AffineTransform wToV = new AffineTransform();

private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -250,4 +253,13 @@ public void zoomOut(int x, int y) {
}
}

public void resetView() {
//center view
camX = init_camX;
camY = init_camY;
//reset zoom
zoomI = init_zoomI;
zoom = zoomI * ZOOM_MULTIPLIER;
}

}
4 changes: 2 additions & 2 deletions src/com/modsim/operations/Ops.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static void fileNew() {
// Core application actions
public static final DesignAction undo, redo, copy, paste, delete, rotateCW, rotateCCW, rotate180,
labelEdit, labelBig, labelSmall,
pause, run, step, toggleRun, zoomIn, zoomOut, toggleAA, open, save, saveAs, fileNew, quit;
pause, run, step, toggleRun, zoomIn, zoomOut, resetView, toggleAA, open, save, saveAs, fileNew, quit;

static {
// Keyboard shortcuts
Expand Down Expand Up @@ -248,7 +248,7 @@ public static void fileNew() {
//Zoom controls
zoomIn = new DesignAction(event -> Main.ui.zoomInToView(), "Zoom In");
zoomOut = new DesignAction(event -> Main.ui.zoomOutToView(), "Zoom Out");

resetView = new DesignAction(event -> Main.ui.resetView(), "Reset View");

// View controls
toggleAA = new DesignAction(event -> Main.ui.view.useAA = !Main.ui.view.useAA,
Expand Down
6 changes: 3 additions & 3 deletions src/com/modsim/util/XMLReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public static void readFile(File xmlFile) {
// View load
Element view = (Element) doc.getElementsByTagName("view").item(0);
View v = Main.ui.view;
v.camX = Double.parseDouble(view.getAttribute("camX"));
v.camY = Double.parseDouble(view.getAttribute("camY"));
v.zoomI = Integer.parseInt(view.getAttribute("zoom"));
v.init_camX = v.camX = Double.parseDouble(view.getAttribute("camX"));
v.init_camY = v.camY = Double.parseDouble(view.getAttribute("camY"));
v.init_zoomI = v.zoomI = Integer.parseInt(view.getAttribute("zoom"));
v.zoom = View.ZOOM_MULTIPLIER * v.zoomI;
v.calcXForm();

Expand Down

0 comments on commit aa50590

Please sign in to comment.