/******************************************************************************* * Copyright (c) 2007 VTT Technical Research Centre of Finland and others. * 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.proconf.g3d.actions; import java.util.Collection; import java.util.List; import javax.vecmath.Vector3d; import org.simantics.db.Graph; import org.simantics.db.Resource; import org.simantics.layer0.utils.IEntity; import org.simantics.layer0.utils.EntityFactory; import org.simantics.proconf.g3d.Activator; import org.simantics.proconf.g3d.Resources; import org.simantics.proconf.g3d.base.G3DTools; import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase; import org.simantics.proconf.g3d.common.OrbitalCamera; import org.simantics.proconf.g3d.stubs.Tuple3; public class FocusAction extends ContextAction{ private OrbitalCamera camera; Vector3d focusPoint = null; public FocusAction(ThreeDimensionalEditorBase parent) { super(parent); camera = parent.getCamera(); } public void init() { this.setText("Focus"); this.setToolTipText("Focus"); this.setImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/eye.png")); } @Override public boolean usable(Graph graph,List resources) { if (resources.size() != 1) return false; IEntity t = EntityFactory.create(graph, resources.get(0)); if (t.isInstanceOf(Resources.g3dResource.G3DNode)) { Collection p = t.getRelatedObjects(Resources.g3dResource.HasWorldPosition); if (p == null || p.size() != 1) return false; else //focusPoint = new Vector3d(G3DTools.getPoint(new Position(graph,p.iterator().next().getResource()))); focusPoint = new Vector3d(G3DTools.getPoint(new Tuple3(graph,p.iterator().next().getResource()))); } return true; } public void run() { camera.setTarget(focusPoint); parent.setViewChanged(true); } }