[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model/modellor InnerWallModellor.java, NO
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Nordholt <nor...@us...> - 2007-04-23 14:50:46
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/modellor In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv30838/src/net/sourceforge/bprocessor/model/modellor Added Files: InnerWallModellor.java Log Message: added the innerwall modellor --- NEW FILE: InnerWallModellor.java --- //--------------------------------------------------------------------------------- // $Id: InnerWallModellor.java,v 1.1 2007/04/23 14:50:36 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.model.modellor; 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.Edge; import net.sourceforge.bprocessor.model.Geometry; 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.Vertex; import org.apache.log4j.Logger; /** * A modellor for detailing inner wall elements with parts such as wooden frameworks. * */ public class InnerWallModellor extends Modellor { /** The logger */ private static Logger log = Logger.getLogger(InnerWallModellor.class); /** The space of this modellor */ private Space space; /** A surface in the space to start the modellor */ private Surface surface; /** The interval between joists */ private static double joistInterval = 0.5; /** The spaces for the joists */ private Set<Space> joists; /** Says whether or not the modellor should be build, * is false when there is no-need to rebuild the innerwall */ private boolean build = true; /** * The empty constructor * */ public InnerWallModellor() { build = false; } /** * Constructor * @param s the space of the modellor */ public InnerWallModellor(Space s) { this.space = s; } /** * {@inheritDoc} */ public void getAttributes(List<Attribute> l) { l.add(new Attribute("Space", space)); l.add(new Attribute("Surface", surface)); l.add(new Attribute("Joist Interval", joistInterval)); } /** * {@inheritDoc} */ public void getSubContent(Map<String, Object> c) { // TODO Auto-generated method stub } /** * {@inheritDoc} */ public int getUseableLevel() { return Space.SPACE_LEVEL; } /** * {@inheritDoc} */ @Override public Modellor newInstance(Space s) { InnerWallModellor mod = new InnerWallModellor(s); //mod.setSurface(surface); Project.getInstance().addObserver(mod); return mod; } /** * {@inheritDoc} */ @Override public void setAttributes(Map<String, Attribute> m) { Attribute a = m.get("Joist Interval"); if (a != null && a.getValue() instanceof Double) { joistInterval = (Double)a.getValue(); space.clear(); build = true; } } /** * {@inheritDoc} */ @Override public void setSubContent(Map<String, Object> c) { // TODO Auto-generated method stub } /** * * {@inheritDoc} */ @Override public void update(Object entity) { if (build) { Net n = null; space.add(buildNet()); for (Space net : space.getElements()) { if (net instanceof Net) { n = (Net)net; break; } } if (n != null) { Vertex x = new Vertex(0.05, 0, 0); Vertex y = new Vertex(0, 0.05, 0); Vertex z = new Vertex(0, 0, 0.05); for (Edge e : n.getEdges()) { Space joist = new Space("joist", Space.CONSTRUCTION, space.getLevel() + 1, true); space.add(joist); Vertex to = e.getTo(); Vertex from = e.getFrom(); Vertex dir = e.getDirection(); Surface base = null; if (Math.abs(to.getZ() - from.getZ()) < Geometry.EPS) { base = joistBase(from, y, z); } else { base = joistBase(from, x, y); } space.add(base); if (dir.dot(base.normal()) < 0) { base.flip(); } base.setFrontDomain(joist); Set<Surface> sides = new HashSet<Surface>(); base.extrude(e.getLength(), sides); space.addAll(sides); } build = false; } } } private static Surface joistBase(Vertex origin, Vertex x, Vertex y) { List<Vertex> vl = new LinkedList<Vertex>(); Vertex first = origin; vl.add(origin.add(x)); vl.add(origin.add(x).add(y)); vl.add(origin.add(y)); List<Edge> el = new LinkedList<Edge>(); Vertex prevV = first; for (Vertex v : vl) { el.add(new Edge(prevV, v)); prevV = v; } el.add(new Edge(prevV, first)); Surface base = new Surface(el); return base; } private Net buildNet() { if (space != null && !space.getEnvelope().isEmpty()) { Net net = new Net("net"); space.add(net); surface = space.getEnvelope().iterator().next(); surface.copy(net); Edge vertical = null; Edge horizontal = null; for (Edge e : surface.getEdges()) { Vertex to = e.getTo(); Vertex from = e.getFrom(); if (Math.abs(to.getZ() - from.getZ()) < Geometry.EPS) { horizontal = e; } } for (Edge e : surface.getEdges()) { Vertex to = e.getTo(); Vertex from = e.getFrom(); if (!(Math.abs(to.getZ() - from.getZ()) < Geometry.EPS) && Edge.commonVertex(horizontal, e) == horizontal.getFrom()) { vertical = e; } } Vertex origin = horizontal.getFrom(); Vertex verticalV = vertical.otherVertex(origin).minus(origin); Vertex interval = horizontal.getDirection(); interval.scale(joistInterval / interval.length()); Vertex current = origin.copy(); current.move(interval.getX(), interval.getY(), interval.getZ()); while (origin.minus(current).length() < horizontal.getLength()) { Vertex from = current.copy(); Vertex to = from.add(verticalV); net.insert(from); net.insert(to); net.insert(new Edge(from, to)); current.move(interval.getX(), interval.getY(), interval.getZ()); } return net; } return null; } /** * {@inheritDoc} */ @Override public void delete() { // TODO Auto-generated method stub } /** * Gets the space of this modellor * @return the space */ public Space getSpace() { return space; } /** Sets the space of this modellor * @param space the space */ public void setSpace(Space space) { this.space = space; } /** Gets the surface of this modellor * @return the surface */ public Surface getSurface() { return surface; } /** Sets the surface of this modellor * @param surface the surface */ public void setSurface(Surface surface) { this.surface = surface; } /** * Finds the outline of a net, if it makes sence. * The outline must be a sequence of connected outer edges, so that * the last edge is connected to the first. Also all outer edges most be * in the outline. * @param net a net * @return a list of connected edges making up the net outline */ private List netOutline(Net net) { /*Find outer edges*/ Iterator edges = net.getEdges().iterator(); Set<Edge> outer = new HashSet<Edge>(); while (edges.hasNext()) { Edge current = (Edge)edges.next(); if (current.getSurfaces().size() == 1) { outer.add(current); } } /*If there are outer edges sort them in order*/ if (!outer.isEmpty()) { LinkedList<Edge> outline = new LinkedList<Edge>(); Edge first = (Edge)outer.iterator().next(); outline.add(first); outer.remove(first); Vertex nextVertex = first.getTo(); boolean doneAll = false; while (!doneAll) { Edge next = null; Iterator nextEdges = nextVertex.getEdges().iterator(); while (nextEdges.hasNext()) { Object e = nextEdges.next(); if (outer.contains(e)) { next = (Edge)e; break; } } if (next != null) { outer.remove(next); nextVertex = next.otherVertex(nextVertex); outline.add(next); } else { doneAll = true; } } /*If all outer edges are in the outline, * and the last edge is connected to the first, * return the outline */ if (outer.isEmpty() && first.getFrom().getEdges().contains(outline.getLast())) { return outline; } else { log.warn("Outline not well defined, " + " outer edges left: " + outer.size() + " outline connected: " + first.getFrom().getEdges().contains(outline.getLast())); } } return new LinkedList(); } } |