1 /*******************************************************************************
\r
2 * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g3d.vtk.handlers;
\r
14 import java.util.HashMap;
\r
15 import java.util.Map;
\r
17 import javax.vecmath.Vector3d;
\r
19 import org.eclipse.core.commands.AbstractHandler;
\r
20 import org.eclipse.core.commands.Command;
\r
21 import org.eclipse.core.commands.ExecutionEvent;
\r
22 import org.eclipse.core.commands.ExecutionException;
\r
23 import org.eclipse.ui.IWorkbenchPart;
\r
24 import org.eclipse.ui.handlers.HandlerUtil;
\r
25 import org.simantics.g3d.vtk.common.InteractiveVtkPanel;
\r
26 import org.simantics.utils.threads.AWTThread;
\r
27 import org.simantics.utils.threads.ThreadUtils;
\r
29 public class ParallelPerspectiveHandler extends AbstractHandler {
\r
32 private Map<InteractiveVtkPanel,Vector3d> cameraPos = new HashMap<InteractiveVtkPanel, Vector3d>();
\r
35 public Object execute(ExecutionEvent event) throws ExecutionException {
\r
36 Command command = event.getCommand();
\r
37 boolean oldValue = HandlerUtil.toggleCommandState(command);
\r
38 final boolean activate = !oldValue;
\r
40 final IWorkbenchPart ap = HandlerUtil.getActiveEditor(event);
\r
41 final InteractiveVtkPanel panel = (InteractiveVtkPanel)ap.getAdapter(InteractiveVtkPanel.class);
\r
43 ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {
\r
48 Vector3d focal = new Vector3d(panel.GetRenderer().GetActiveCamera().GetFocalPoint());
\r
49 Vector3d pos = new Vector3d(panel.GetRenderer().GetActiveCamera().GetPosition());
\r
50 cameraPos.put(panel, pos);
\r
51 Vector3d dir = new Vector3d(pos);
\r
56 panel.GetRenderer().GetActiveCamera().SetPosition(dir.x, dir.y, dir.z);
\r
59 panel.GetRenderer().GetActiveCamera().SetParallelProjection(1);
\r
60 panel.GetRenderer().ResetCameraClippingRange();
\r
62 panel.GetRenderer().GetActiveCamera().SetParallelProjection(0);
\r
63 Vector3d pos = cameraPos.get(panel);
\r
65 panel.GetRenderer().GetActiveCamera().SetPosition(pos.x, pos.y, pos.z);
\r
67 panel.GetRenderer().ResetCameraClippingRange();
\r
70 panel.UpdateLight();
\r