X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d.vtk%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fvtk%2Fhandlers%2FParallelPerspectiveHandler.java;h=855a0d145286696194ac03b0511878b7b7d8ab04;hb=84132a1d750c45f9161afbd58b78572964e50d26;hp=aad92f987a20271e8790e59eb4ae6403b401a8ea;hpb=6308b57b2793abbd92da9e004f9f7c068f18eba6;p=simantics%2F3d.git diff --git a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/handlers/ParallelPerspectiveHandler.java b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/handlers/ParallelPerspectiveHandler.java index aad92f98..855a0d14 100644 --- a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/handlers/ParallelPerspectiveHandler.java +++ b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/handlers/ParallelPerspectiveHandler.java @@ -1,82 +1,82 @@ -/******************************************************************************* - * Copyright (c) 2012, 2013 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.g3d.vtk.handlers; - -import java.util.HashMap; -import java.util.Map; - -import javax.vecmath.Vector3d; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.Command; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.handlers.HandlerUtil; -import org.simantics.g3d.vtk.common.InteractiveVtkPanel; -import org.simantics.utils.threads.AWTThread; -import org.simantics.utils.threads.ThreadUtils; - -public class ParallelPerspectiveHandler extends AbstractHandler { - - - private Map cameraPos = new HashMap(); - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - Command command = event.getCommand(); - boolean oldValue = HandlerUtil.toggleCommandState(command); - final boolean activate = !oldValue; - - final IWorkbenchPart ap = HandlerUtil.getActiveEditor(event); - final InteractiveVtkPanel panel = (InteractiveVtkPanel)ap.getAdapter(InteractiveVtkPanel.class); - - ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() { - - @Override - public void run() { - if (activate){ - Vector3d focal = new Vector3d(panel.GetRenderer().GetActiveCamera().GetFocalPoint()); - Vector3d pos = new Vector3d(panel.GetRenderer().GetActiveCamera().GetPosition()); - cameraPos.put(panel, pos); - Vector3d dir = new Vector3d(pos); - dir.sub(focal); - dir.normalize(); - dir.scale(100); - dir.add(focal); - panel.GetRenderer().GetActiveCamera().SetPosition(dir.x, dir.y, dir.z); - - - panel.GetRenderer().GetActiveCamera().SetParallelProjection(1); - panel.GetRenderer().ResetCameraClippingRange(); - } else { - panel.GetRenderer().GetActiveCamera().SetParallelProjection(0); - Vector3d pos = cameraPos.get(panel); - if (pos != null) { - panel.GetRenderer().GetActiveCamera().SetPosition(pos.x, pos.y, pos.z); - } - panel.GetRenderer().ResetCameraClippingRange(); - - } - panel.UpdateLight(); - panel.repaint(); - - } - }); - - return null; - - } - - - -} +/******************************************************************************* + * Copyright (c) 2012, 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.g3d.vtk.handlers; + +import java.util.HashMap; +import java.util.Map; + +import javax.vecmath.Vector3d; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.g3d.vtk.common.VtkView; +import org.simantics.utils.threads.AWTThread; +import org.simantics.utils.threads.ThreadUtils; + +public class ParallelPerspectiveHandler extends AbstractHandler { + + + private Map cameraPos = new HashMap(); + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + Command command = event.getCommand(); + boolean oldValue = HandlerUtil.toggleCommandState(command); + final boolean activate = !oldValue; + + final IWorkbenchPart ap = HandlerUtil.getActiveEditor(event); + final VtkView panel = (VtkView)ap.getAdapter(VtkView.class); + + ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() { + + @Override + public void run() { + if (activate){ + Vector3d focal = new Vector3d(panel.getRenderer().GetActiveCamera().GetFocalPoint()); + Vector3d pos = new Vector3d(panel.getRenderer().GetActiveCamera().GetPosition()); + cameraPos.put(panel, pos); + Vector3d dir = new Vector3d(pos); + dir.sub(focal); + dir.normalize(); + dir.scale(100); + dir.add(focal); + panel.getRenderer().GetActiveCamera().SetPosition(dir.x, dir.y, dir.z); + + + panel.getRenderer().GetActiveCamera().SetParallelProjection(1); + panel.getRenderer().ResetCameraClippingRange(); + } else { + panel.getRenderer().GetActiveCamera().SetParallelProjection(0); + Vector3d pos = cameraPos.get(panel); + if (pos != null) { + panel.getRenderer().GetActiveCamera().SetPosition(pos.x, pos.y, pos.z); + } + panel.getRenderer().ResetCameraClippingRange(); + + } +// panel.UpdateLight(); + panel.refresh(); + + } + }); + + return null; + + } + + + +}