X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d.csg%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fcsg%2Feditor%2FCSGNodeMap.java;fp=org.simantics.g3d.csg%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fcsg%2Feditor%2FCSGNodeMap.java;h=b4eaa148903d71b793dd09335d2cb88caf178269;hb=84132a1d750c45f9161afbd58b78572964e50d26;hp=a207d5f2829f0485c38fb97a7e76e632051c796d;hpb=6308b57b2793abbd92da9e004f9f7c068f18eba6;p=simantics%2F3d.git diff --git a/org.simantics.g3d.csg/src/org/simantics/g3d/csg/editor/CSGNodeMap.java b/org.simantics.g3d.csg/src/org/simantics/g3d/csg/editor/CSGNodeMap.java index a207d5f2..b4eaa148 100644 --- a/org.simantics.g3d.csg/src/org/simantics/g3d/csg/editor/CSGNodeMap.java +++ b/org.simantics.g3d.csg/src/org/simantics/g3d/csg/editor/CSGNodeMap.java @@ -1,130 +1,128 @@ -/******************************************************************************* - * 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.Session; -import org.simantics.g3d.csg.scenegraph2.CSGrootNode; -import org.simantics.g3d.csg.scenegraph2.ICSGnode; -import org.simantics.g3d.scenegraph.base.ParentNode; -import org.simantics.g3d.vtk.common.AbstractVTKNodeMap; -import org.simantics.g3d.vtk.common.InteractiveVtkPanel; -import org.simantics.objmap.graph.IMapping; -import org.simantics.utils.threads.AWTThread; - -import vtk.vtkProp; -import vtk.vtkProp3D; -import vtk.vtkRenderer; - -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() != AWTThread.getThreadAccess().getThread()) - throw new RuntimeException("Illegal thread."); - - panel.lock(); - - node.visualize(panel); - - for (vtkProp3D act : node.getActors()) { - nodeToActor.add(node, act); - actorToNode.put(act, node); - } - - panel.unlock(); - - } - - - - private boolean hasActor(ICSGnode node) { - List list = nodeToActor.getValues(node); - if (list == null || list.size() == 0) - return false; - return true; - } - - private void remActor(ICSGnode node) { - if (Thread.currentThread() != AWTThread.getThreadAccess().getThread()) - throw new RuntimeException("Illegal thread."); - - List list = nodeToActor.getValues(node); - if (list != null) { - for (vtkProp obj : list) { - actorToNode.remove(obj); - } - nodeToActor.remove(node); - panel.lock(); - - node.stopVisualize(); - - panel.unlock(); - } - } - - -} +/******************************************************************************* + * 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.Session; +import org.simantics.g3d.csg.scenegraph2.CSGrootNode; +import org.simantics.g3d.csg.scenegraph2.ICSGnode; +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); + + for (vtkProp3D act : node.getActors()) { + nodeToActor.add(node, act); + actorToNode.put(act, node); + } + + view.unlock(); + + } + + + + private boolean hasActor(ICSGnode node) { + List list = nodeToActor.getValues(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."); + + List list = nodeToActor.getValues(node); + if (list != null) { + for (vtkProp obj : list) { + actorToNode.remove(obj); + } + nodeToActor.remove(node); + view.lock(); + + node.stopVisualize(); + + view.unlock(); + } + } + + +}