X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fproconf%2Fg3d%2Factions%2FFocusAction.java;fp=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fproconf%2Fg3d%2Factions%2FFocusAction.java;h=3e5738583790e3831d3c83f85a4ee01fc524c390;hb=10f144a2bb2d7bec98b812b83acecb333fd098ea;hp=0000000000000000000000000000000000000000;hpb=3055b543aa5afc0cca4bb3b341704e7c5103fa6a;p=simantics%2F3d.git diff --git a/org.simantics.g3d/src/org/simantics/proconf/g3d/actions/FocusAction.java b/org.simantics.g3d/src/org/simantics/proconf/g3d/actions/FocusAction.java new file mode 100644 index 00000000..3e573858 --- /dev/null +++ b/org.simantics.g3d/src/org/simantics/proconf/g3d/actions/FocusAction.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2007- VTT Technical Research Centre of Finland. + * 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); + } + + +}