/* * Moonlight|3D Copyright (C) 2005 The Moonlight|3D team * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Created on Jan 5, 2005 */ package ml.backend.og; import ml.backend.selection.PathElement; import ml.core.exceptions.Exception; /** * This class implements input and output slots for operator graph nodes. * Slots are endpoints for Links. * * @author gregor */ public class Slot implements PathElement { public enum Type { Input, Output } protected Type type; protected String name; protected ml.backend.og.Node node; protected ml.backend.sg.Node graph; protected Link link; /** * sets the type of this Slot */ public void setType(Type type) { this.type=type; } /** * returns the type of this Slot */ public Type getType() { return type; } /** * sets the name of this Slot */ public void setName(String name) { this.name=name; } /** * returns the name of this Slot */ public String getName() { return name; } /** * sets the Node this Slot is attached to */ public void setNode(ml.backend.og.Node node) { this.node=node; } /** * returns the Node this Slot belongs to */ public ml.backend.og.Node getNode() { return node; } /** * stores a new scene graph in this slot for further processing */ public void setGraph(ml.backend.sg.Node graph) throws ml.core.exceptions.Exception { if(type==Type.Input) { throw new ml.core.exceptions.Exception("unable to assign a scene graph to an input node"); } this.graph=graph; } /** * returns the scene graph that is stored in this slot for * further processing */ public ml.backend.sg.Node getGraph() throws ml.core.exceptions.Exception { try { switch(type) { case Output: return graph; case Input: if(link!=null) { Slot slot=link.getInput(); if(slot!=null) { if(slot.graph!=null) { return slot.graph.deepCopy(); } } } return null; } return null; } catch (Exception e) { throw new ml.core.exceptions.Exception("unable to generate scene graph copy",e); } } public void setCurrentLink(Link link) { this.link=link; } public Link getCurrentLink() { return link; } /** * This call passes on a request to update the scene graph. If this * Slot is an Input slot, the attached Node will recieve the request. * If this Slot is an Output slot, the attached Link will recieve the request. * @throws Exception */ public void recursiveUpdate(Manager manager) throws Exception { if(type==Type.Input) { node.recursiveUpdate(manager); } else { if(link!=null) { link.recursiveUpdate(manager); } } } public PathElement findChildElement(String childName) { ml.backend.sg.Node graph; if(type==Type.Input) { if(link!=null) { Slot input=link.getInput(); if(input!=null) { graph=input.graph; } else { return null; } } else { return null; } } else { graph=this.graph; } try { return graph.getChildByName(childName); } catch(Exception e) { return null; } } public boolean isValidAppendixName(String appendix) { return false; } public Object getFromAppendix(String appendix) { return null; } }