/******************************************************************************* * 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.base; import java.util.Collection; import java.util.HashMap; import java.util.Map; import org.simantics.db.Resource; import org.simantics.layer0.utils.IEntity; import org.simantics.utils.ui.plugin.Extension; import org.simantics.utils.ui.plugin.ExtensionLoader; import com.jme.scene.Geometry; public class GeometryProviderRegistry { private static GeometryProviderRegistry instance; public final static String ELEMENT_NAME = "Geometry"; public final static String NAME_SPACE = "org.simantics.proconf.g3d"; public final static String EP_NAME = "geometry"; private ExtensionLoader loader; private Map providers; private GeometryProviderRegistry() { loader = new ExtensionLoader(ELEMENT_NAME, NAME_SPACE, EP_NAME); providers = new HashMap(); } public static GeometryProviderRegistry getInstance() { if (instance==null) instance = new GeometryProviderRegistry(); return instance; } public Extension[] getExtensions() { return loader.getExtensions(); } private Map getProviderMap() { return providers; } public static Geometry[] getGeometry(IEntity thing, boolean transform) { GeometryProvider provider = getGeometryProvider(thing); return provider.getGeometryFromResource(thing, transform); } public static GeometryProvider getGeometryProvider(IEntity thing) { Collection types = thing.getRelatedObjects(thing.getGraph().getBuiltins().InstanceOf); //Resource types[] = OntologyUtils.getTypes(resource); for (IEntity t : types) { GeometryProvider provider = getInstance().getProviderMap().get(t.getResource()); if (provider == null) { for (Extension e : getInstance().getExtensions()) { if (e.getInstance().canHandle(thing)) { getInstance().getProviderMap().put(t.getResource(), e.getInstance()); return e.getInstance(); } } } else { return provider; } } throw new UnsupportedOperationException("Cannot handle resource " + thing); } }