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