1 /*******************************************************************************
\r
2 * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g3d.csg.adapters;
\r
14 import java.util.ArrayList;
\r
15 import java.util.Collection;
\r
16 import java.util.Collections;
\r
17 import java.util.List;
\r
19 import org.eclipse.core.runtime.IAdaptable;
\r
20 import org.jcae.opencascade.jni.TopoDS_Shape;
\r
21 import org.simantics.db.ReadGraph;
\r
22 import org.simantics.db.Resource;
\r
23 import org.simantics.db.exception.DatabaseException;
\r
24 import org.simantics.db.request.Read;
\r
25 import org.simantics.g3d.csg.scenegraph2.CSGrootNode;
\r
26 import org.simantics.g3d.csg.scenegraph2.ICSGnode;
\r
27 import org.simantics.g3d.csg.scenegraph2.SchemaBuilder;
\r
28 import org.simantics.objmap.graph.IMapping;
\r
29 import org.simantics.objmap.graph.Mappings;
\r
30 import org.simantics.objmap.graph.schema.IMappingSchema;
\r
31 import org.simantics.objmap.structural.IStructuralObject;
\r
32 import org.simantics.opencascade.SolidModelProvider;
\r
33 import org.simantics.Simantics;
\r
35 public class CSGSolidModelAdapter implements SolidModelProvider, IAdaptable, IStructuralObject {
\r
37 private Resource model;
\r
39 public CSGSolidModelAdapter(Resource model) {
\r
44 public Collection<TopoDS_Shape> getModel() throws Exception {
\r
45 return Simantics.getSession().syncRequest(new Read<Collection<TopoDS_Shape>>() {
\r
47 public Collection<TopoDS_Shape> perform(ReadGraph graph)
\r
48 throws DatabaseException {
\r
49 Collection<TopoDS_Shape> shapes = new ArrayList<TopoDS_Shape>();
\r
50 IMappingSchema<Resource,Object> schema = SchemaBuilder.getSchema(graph);
\r
51 IMapping<Resource,Object> mapping = Mappings.createWithoutListening(schema);
\r
52 CSGrootNode rootNode = (CSGrootNode)mapping.map(graph, model);
\r
53 for (ICSGnode node : rootNode.getNodes("child")) {
\r
54 TopoDS_Shape shape = node.getGeometry();
\r
58 // FIXME: clear CSG scene-graph
\r
66 public <C> C getAdapter(Class<C> adapter) {
\r
67 if (adapter.isAssignableFrom(Resource.class))
\r
68 return adapter.cast(model);
\r
72 @SuppressWarnings("unchecked")
\r
74 public List<IStructuralObject> getContext() {
\r
75 return Collections.EMPTY_LIST;
\r
79 public Resource getType() {
\r
84 public void setContext(List<IStructuralObject> object) {
\r
85 throw new RuntimeException();
\r
89 public void setType(Resource type) {
\r
90 throw new RuntimeException();
\r