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 org.eclipse.core.commands.AbstractHandler;
15 import org.eclipse.core.commands.Command;
16 import org.eclipse.core.commands.ExecutionEvent;
17 import org.eclipse.core.commands.ExecutionException;
18 import org.eclipse.ui.IWorkbenchPart;
19 import org.eclipse.ui.handlers.HandlerUtil;
20 import org.simantics.g3d.vtk.common.VtkView;
21 import org.simantics.utils.threads.AWTThread;
22 import org.simantics.utils.threads.ThreadUtils;
25 import vtk.vtkRenderer;
27 public class ParallelPerspectiveHandler extends AbstractHandler {
31 public Object execute(ExecutionEvent event) throws ExecutionException {
32 Command command = event.getCommand();
33 boolean oldValue = HandlerUtil.toggleCommandState(command);
34 final boolean activate = !oldValue;
36 final IWorkbenchPart ap = HandlerUtil.getActiveEditor(event);
37 final VtkView panel = (VtkView)ap.getAdapter(VtkView.class);
39 ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {
43 vtkRenderer ren = panel.getRenderer();
44 vtkCamera cam = ren.GetActiveCamera();
46 double distance = cam.GetDistance();
47 double angle = cam.GetViewAngle();
48 double scale = Math.tan(Math.toRadians(angle / 2)) * distance;
49 cam.SetParallelScale(scale);
50 cam.SetParallelProjection(1);
51 ren.ResetCameraClippingRange();
53 cam.SetParallelProjection(0);
54 ren.ResetCameraClippingRange();