Skip to content

Commit aa50590

Browse files
committed
added a reset View feature in view menu that resets the view to the last 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
1 parent 01e1f0f commit aa50590

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

src/com/modsim/gui/GUI.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,10 @@ public void zoomOutToView()
265265
view.zoomOut(view.getWidth()/2,view.getHeight()/2);
266266
}
267267

268-
268+
public void resetView()
269+
{
270+
view.resetView();
271+
}
269272

270273

271274
/**

src/com/modsim/gui/Menu.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ private void addViewMenu() {
8383
JMenu view = new JMenu("View");
8484
view.setMnemonic(KeyEvent.VK_V);
8585
view.add(Ops.toggleAA);
86+
view.add(Ops.resetView);
8687
app_menu.add(view);
8788
}
8889

src/com/modsim/gui/view/View.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@
2121
*/
2222
public class View extends JPanel {
2323

24-
public int zoomI = 3;
24+
public int init_zoomI = 3;
25+
public double init_camX = 0, init_camY = 0;
26+
27+
public int zoomI = init_zoomI;
2528
public double zoom = zoomI * ZOOM_MULTIPLIER;
2629

2730
public static final double ZOOM_MULTIPLIER = 0.15;
2831
public static final int ZOOM_LIMIT = 12;
2932

30-
public double camX = 0, camY = 0;
33+
public double camX = init_camX, camY = init_camY;
3134
public AffineTransform wToV = new AffineTransform();
3235

3336
private static final long serialVersionUID = 1L;
@@ -250,4 +253,13 @@ public void zoomOut(int x, int y) {
250253
}
251254
}
252255

256+
public void resetView() {
257+
//center view
258+
camX = init_camX;
259+
camY = init_camY;
260+
//reset zoom
261+
zoomI = init_zoomI;
262+
zoom = zoomI * ZOOM_MULTIPLIER;
263+
}
264+
253265
}

src/com/modsim/operations/Ops.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public static void fileNew() {
136136
// Core application actions
137137
public static final DesignAction undo, redo, copy, paste, delete, rotateCW, rotateCCW, rotate180,
138138
labelEdit, labelBig, labelSmall,
139-
pause, run, step, toggleRun, zoomIn, zoomOut, toggleAA, open, save, saveAs, fileNew, quit;
139+
pause, run, step, toggleRun, zoomIn, zoomOut, resetView, toggleAA, open, save, saveAs, fileNew, quit;
140140

141141
static {
142142
// Keyboard shortcuts
@@ -248,7 +248,7 @@ public static void fileNew() {
248248
//Zoom controls
249249
zoomIn = new DesignAction(event -> Main.ui.zoomInToView(), "Zoom In");
250250
zoomOut = new DesignAction(event -> Main.ui.zoomOutToView(), "Zoom Out");
251-
251+
resetView = new DesignAction(event -> Main.ui.resetView(), "Reset View");
252252

253253
// View controls
254254
toggleAA = new DesignAction(event -> Main.ui.view.useAA = !Main.ui.view.useAA,

src/com/modsim/util/XMLReader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public static void readFile(File xmlFile) {
4444
// View load
4545
Element view = (Element) doc.getElementsByTagName("view").item(0);
4646
View v = Main.ui.view;
47-
v.camX = Double.parseDouble(view.getAttribute("camX"));
48-
v.camY = Double.parseDouble(view.getAttribute("camY"));
49-
v.zoomI = Integer.parseInt(view.getAttribute("zoom"));
47+
v.init_camX = v.camX = Double.parseDouble(view.getAttribute("camX"));
48+
v.init_camY = v.camY = Double.parseDouble(view.getAttribute("camY"));
49+
v.init_zoomI = v.zoomI = Integer.parseInt(view.getAttribute("zoom"));
5050
v.zoom = View.ZOOM_MULTIPLIER * v.zoomI;
5151
v.calcXForm();
5252

0 commit comments

Comments
 (0)