/******************************************************************************* * Copyright (c) 2012, 2013 Association for Decentralized Information Management in * Industry THTH ry. * 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.g3d.csg.editor; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Set; import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.g3d.csg.scenegraph2.CSGrootNode; import org.simantics.g3d.csg.scenegraph2.ICSGnode; import org.simantics.g3d.scenegraph.base.INode; import org.simantics.g3d.scenegraph.base.ParentNode; import org.simantics.g3d.vtk.awt.InteractiveVtkPanel; import org.simantics.g3d.vtk.common.AbstractVTKNodeMap; import org.simantics.objmap.graph.IMapping; import vtk.vtkProp; import vtk.vtkProp3D; public class CSGNodeMap extends AbstractVTKNodeMap { public CSGNodeMap(Session session, IMapping mapping, InteractiveVtkPanel panel, CSGrootNode rootNode) { super(session, mapping, panel, rootNode); rootNode.setNodeMap(this); } @SuppressWarnings("unchecked") protected void updateActor(ICSGnode node, Set ids) { //System.out.println("CSGNodeMap.updateActor " + node); if (node.getParent() instanceof ICSGnode) { ICSGnode parent = (ICSGnode) node.getParent(); if (!"child".equals(node.getParentRel())) { updateActor(parent,null); return; } } if (node instanceof ParentNode) { ParentNode p = (ParentNode)node; for (ICSGnode n : p.getNodes()) remActor(n); } remActor(node); addActor(node); } @Override protected Collection getActors(ICSGnode node) { List props = new ArrayList(); for (vtkProp3D p : ((ICSGnode)node).getActors()) props.add(p); return props; } protected void removeActor(ICSGnode node) { //System.out.println("CSGNodeMap.removeActor " + node); remActor(node); if (!"child".equals(node.getParentRel())) { if (node.getParent() instanceof ICSGnode) updateActor((ICSGnode)node.getParent(),null); } } protected void addActor(ICSGnode node) { //System.out.println("CSGNodeMap.addActor " + node); if (hasActor(node)) return; if (Thread.currentThread() != view.getThreadQueue().getThread()) throw new RuntimeException("Illegal thread."); view.lock(); node.visualize(view); map(node, node.getActors()); view.unlock(); } private boolean hasActor(ICSGnode node) { Collection list = getRenderObjects(node); if (list == null || list.size() == 0) return false; return true; } private void remActor(ICSGnode node) { if (Thread.currentThread() != view.getThreadQueue().getThread()) throw new RuntimeException("Illegal thread."); Collection list = getRenderObjects(node); if (list.size() > 0) { removeMap(node); view.lock(); node.stopVisualize(); view.unlock(); } } }