1 /*******************************************************************************
\r
2 * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * which accompanies this distribution, and is available at
\r
6 * http://www.eclipse.org/legal/epl-v10.html
\r
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.proconf.g3d.base;
\r
13 import java.util.Collection;
\r
14 import java.util.HashMap;
\r
15 import java.util.Map;
\r
17 import org.simantics.db.Resource;
\r
18 import org.simantics.layer0.utils.IEntity;
\r
19 import org.simantics.utils.ui.plugin.Extension;
\r
20 import org.simantics.utils.ui.plugin.ExtensionLoader;
\r
22 import com.jme.scene.Geometry;
\r
24 public class GeometryProviderRegistry {
\r
25 private static GeometryProviderRegistry instance;
\r
26 public final static String ELEMENT_NAME = "Geometry";
\r
27 public final static String NAME_SPACE = "org.simantics.proconf.g3d";
\r
28 public final static String EP_NAME = "geometry";
\r
30 private ExtensionLoader<GeometryProvider> loader;
\r
31 private Map<Resource,GeometryProvider> providers;
\r
33 private GeometryProviderRegistry() {
\r
34 loader = new ExtensionLoader<GeometryProvider>(ELEMENT_NAME, NAME_SPACE, EP_NAME);
\r
35 providers = new HashMap<Resource,GeometryProvider>();
\r
38 public static GeometryProviderRegistry getInstance() {
\r
39 if (instance==null) instance = new GeometryProviderRegistry();
\r
43 public Extension<GeometryProvider>[] getExtensions() {
\r
44 return loader.getExtensions();
\r
47 private Map<Resource,GeometryProvider> getProviderMap() {
\r
51 public static Geometry[] getGeometry(IEntity thing, boolean transform) {
\r
52 GeometryProvider provider = getGeometryProvider(thing);
\r
53 return provider.getGeometryFromResource(thing, transform);
\r
56 public static GeometryProvider getGeometryProvider(IEntity thing) {
\r
57 Collection<IEntity> types = thing.getRelatedObjects(thing.getGraph().getBuiltins().InstanceOf);
\r
59 //Resource types[] = OntologyUtils.getTypes(resource);
\r
60 for (IEntity t : types) {
\r
61 GeometryProvider provider = getInstance().getProviderMap().get(t.getResource());
\r
62 if (provider == null) {
\r
63 for (Extension<GeometryProvider> e : getInstance().getExtensions()) {
\r
64 if (e.getInstance().canHandle(thing)) {
\r
65 getInstance().getProviderMap().put(t.getResource(), e.getInstance());
\r
66 return e.getInstance();
\r
75 throw new UnsupportedOperationException("Cannot handle resource " + thing);
\r