[Bprocessor-commit] facade/src/net/sourceforge/bprocessor/facade/modellor NetFacadeModellor.java,
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Nordholt <nor...@us...> - 2006-11-28 16:18:32
|
Update of /cvsroot/bprocessor/facade/src/net/sourceforge/bprocessor/facade/modellor In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv14809/src/net/sourceforge/bprocessor/facade/modellor Added Files: NetFacadeModellor.java Log Message: added facade modellor using nets --- NEW FILE: NetFacadeModellor.java --- //--------------------------------------------------------------------------------- // $Id: NetFacadeModellor.java,v 1.1 2006/11/28 16:18:18 nordholt Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.facade.modellor; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import net.sourceforge.bprocessor.model.Attribute; import net.sourceforge.bprocessor.model.Net; import net.sourceforge.bprocessor.model.Project; import net.sourceforge.bprocessor.model.Space; import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.modellor.Modellor; import org.apache.log4j.Logger; /** * The new facade modellor using nets. * */ public class NetFacadeModellor extends Modellor { /** serial id */ private static final long serialVersionUID = 1L; /** The space of the facade */ private Space space; /** The net for this facade */ private Net net; /** The framewidth of the facade */ private double frameWidth = 0.1; /** The depth of the facade */ private double depth = 0.4; /** The front surface of the facade */ private Surface front; /** The logger */ private static Logger log = Logger.getLogger(NetFacadeModellor.class); /** * Empty constructor for the net facade */ public NetFacadeModellor() { space = null; net = null; } /** * Get content of the modellor for persistence * @return a map for persistence */ public Map getContent() { Map content = new HashMap(); content.put("space", space); content.put("net", net); content.put("depth", new Double(depth)); content.put("frameWidth", new Double(frameWidth)); content.put("front", front); return content; } /** * get a new instance of the net facade modellor * @param s the space of the modellor * @return a new modellor */ public Modellor newInstance(Space s) { NetFacadeModellor mod = new NetFacadeModellor(); mod.setSpace(s); Project.getInstance().addObserver(mod); s.setModellor(mod); Iterator it = s.getEnvelope().iterator(); if (it.hasNext()) { mod.setFront((Surface)it.next()); } mod.setNet(mod.createNet(mod.getFront())); mod.regenerate(); return mod; } /** * Set the content of the modellor from a map, for persistence * @param m persistence map */ public void setContent(Map m) { space = (Space)m.get("space"); net = (Net)m.get("net"); depth = ((Double)m.get("depth")).doubleValue(); frameWidth = ((Double)m.get("frameWidth")).doubleValue(); front = (Surface)m.get("front"); } /** * Update when an entity changes * @param entity the changed entity */ public void update(Object entity) { log.info("update"); regenerate(); } /** * Delete this modellor */ public void delete() { space.setModellor(null); } /** * Get the attributes of this modellor */ public List getAttributes() { List attributes = new LinkedList(); attributes.add(new Attribute("Net", net, true)); attributes.add(new Attribute("Framewidth", new Double(frameWidth), true)); attributes.add(new Attribute("Depth", new Double(depth), true)); return attributes; } /** * Set the attributes of the modellor */ public void setAttributes(List attributes) { Iterator it = attributes.iterator(); while (it.hasNext()) { Attribute att = (Attribute)it.next(); if (att.getName() == "Net") { setNet((Space)att.getValue()); } else if(att.getName() == "Framewidth") { setFrameWidth(((Double)att.getValue()).doubleValue()); } } } /** * @see net.sourceforge.bprocessor.model.Parametric#getGeneralName() */ public String getGeneralName() { return "Net Facade Modellor"; } /** *@return the space */ public Space getSpace() { return space; } /** * Set the space of this modellor * @param space the space */ public void setSpace(Space space) { this.space = space; } /** * get the net of the modellor * @return the net of this modellor */ public Net getNet() { return net; } /** * Set the net of this modellor * @param net the net */ public void setNet(Space net) { this.net = (Net)net; space.add(net); } /** * Gets the framewidth of the facade * @return the frameWidth */ public double getFrameWidth() { return frameWidth; } /** * Sets the framewidth of the facade * @param frameWidth the framewidth */ public void setFrameWidth(double frameWidth) { this.frameWidth = frameWidth; } /** * Regenerate the entire facade, deleting what ever was there before. */ private void regenerate() { space.setVertices(new HashMap()); space.setEdges(new HashMap()); space.setSurfaces(new HashMap()); createFacade(net); } /** * Creates a facade from a net. * @param net the net */ private void createFacade(Net net) { if (net != null) { Iterator fields = net.getSurfaces().iterator(); while (fields.hasNext()) { Surface field = (Surface)fields.next(); Surface fcopy = field.copyall(space); Set sides = new HashSet(); fcopy.extrude(depth, sides); } } } /** * Creates a net the size of a suface. * @param front the front surface * @return a new net */ private Net createNet(Surface front) { Net n = new Net("Facade net"); if (front != null) { Surface s = front.copyall(n); } return n; } /** * gets the front surface for the facade * @return front surface */ public Surface getFront() { return front; } /** * Sets the front surface of the facade * @param front the front surface */ public void setFront(Surface front) { this.front = front; } } |