Thread: [Bprocessor-commit] model/src/net/sourceforge/bprocessor/model/modellor InnerWallModellor.java, 1.
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Nordholt <nor...@us...> - 2007-05-07 15:44:39
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/modellor In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv32369/src/net/sourceforge/bprocessor/model/modellor Modified Files: InnerWallModellor.java Log Message: improved drawing of the innerwall Index: InnerWallModellor.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/modellor/InnerWallModellor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** InnerWallModellor.java 23 Apr 2007 14:50:36 -0000 1.1 --- InnerWallModellor.java 7 May 2007 15:44:38 -0000 1.2 *************** *** 7,12 **** package net.sourceforge.bprocessor.model.modellor; import java.util.HashSet; - import java.util.Iterator; import java.util.LinkedList; import java.util.List; --- 7,13 ---- package net.sourceforge.bprocessor.model.modellor; + import java.util.Collection; + import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; *************** *** 15,21 **** --- 16,25 ---- import net.sourceforge.bprocessor.model.Attribute; + import net.sourceforge.bprocessor.model.Classification; + import net.sourceforge.bprocessor.model.CoordinateSystem; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Geometry; import net.sourceforge.bprocessor.model.Net; + import net.sourceforge.bprocessor.model.Plane; import net.sourceforge.bprocessor.model.Project; import net.sourceforge.bprocessor.model.Space; *************** *** 31,37 **** --- 35,55 ---- public class InnerWallModellor extends Modellor { + /** + * Id + */ + private static final long serialVersionUID = 1L; + /** The logger */ private static Logger log = Logger.getLogger(InnerWallModellor.class); + /** The width of a standart joist */ + public static final double JOIST_WIDTH = 0.035; + + /** The depth of a standart joist */ + public static final double JOIST_DEPTH = 0.070; + + /** The classification id for a innerwall */ + public static final String INNERWALL_CLASS = "-205"; + /** The space of this modellor */ private Space space; *************** *** 41,53 **** /** 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 --- 59,73 ---- /** The interval between joists */ ! private double joistInterval = 0.5; /** Says whether or not the modellor should be build, * is false when there is no-need to rebuild the innerwall */ ! private boolean build = true; ! ! /** Coordinate system of the modellor */ ! private CoordinateSystem cs; ! ! /** The net of the modellor */ ! private Net net; /** * The empty constructor *************** *** 95,99 **** public Modellor newInstance(Space s) { InnerWallModellor mod = new InnerWallModellor(s); - //mod.setSurface(surface); Project.getInstance().addObserver(mod); return mod; --- 115,118 ---- *************** *** 107,113 **** Attribute a = m.get("Joist Interval"); if (a != null && a.getValue() instanceof Double) { ! joistInterval = (Double)a.getValue(); ! space.clear(); ! build = true; } } --- 126,130 ---- Attribute a = m.get("Joist Interval"); if (a != null && a.getValue() instanceof Double) { ! joistInterval = buildIfDifferent(joistInterval, (Double)a.getValue()); } } *************** *** 118,123 **** @Override public void setSubContent(Map<String, Object> c) { - // TODO Auto-generated method stub - } --- 135,138 ---- *************** *** 129,176 **** 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; --- 144,273 ---- public void update(Object entity) { if (build) { ! if (net == null) { ! for (Space net : space.getElements()) { ! if (net instanceof Net) { ! net = (Net)net; ! break; ! } } } ! if (net == null) { ! net = buildNet(); ! } ! if (net != null) { ! addSupport(); ! space.clear(); ! space.add(net); ! buildFramework(net); ! build = false; ! } ! } ! } ! ! private void buildFramework(Net net) { ! Map<Edge, Edge> edge2Run = getRuns(net); ! Set<Edge> runs = new HashSet<Edge>(edge2Run.values()); ! Edge right = null; ! Edge bottom = null; ! double maxX = Double.NEGATIVE_INFINITY; ! double minZ = Double.POSITIVE_INFINITY; ! for (Edge e : runs) { ! Vertex v = cs.translate(e.getFrom()); ! if (vertical(e) && maxX < v.getX()) { ! right = e; ! maxX = v.getX(); ! } else if (horizontal(e) && minZ > v.getZ()) { ! bottom = e; ! minZ = v.getZ(); ! } ! } ! runs.remove(bottom); ! runs.remove(right); ! ! Edge topCopy = bottom.copy(); ! Edge rightCopy = right.copy(); ! Vertex up = cs.getN().copy(JOIST_WIDTH / cs.getN().length()); ! Vertex left = cs.getI().copy(-JOIST_WIDTH / cs.getI().length()); ! topCopy.move(up); ! rightCopy.move(left); ! runs.add(topCopy); ! runs.add(rightCopy); ! ! for (Edge e : runs) { ! Surface base = joistBase(); ! space.add(base); ! Space joist = new Space("joist", Space.CONSTRUCTION, space.getLevel() + 1, true); ! space.add(joist); ! Vertex dir = e.getDirection(); ! Vertex i; ! Vertex j; ! Vertex n; ! Vertex o; ! double length; ! if (vertical(e)) { ! dir.normalize(); ! dir.scale(JOIST_WIDTH); ! o = e.getFrom(); ! o = o.add(dir); ! i = cs.getI().copy(); ! j = cs.getJ().copy(); ! n = cs.getN().copy(); ! length = e.getLength() - (JOIST_WIDTH * 2); ! } else if (horizontal(e)) { ! i = cs.getN().copy(-1); ! j = cs.getJ().copy(); ! n = cs.getI().copy(); ! o = e.getFrom(); ! length = e.getLength(); ! } else { ! log.info("Can currently only work with horizontal and vertical edges"); ! continue; ! } ! CoordinateSystem local = new CoordinateSystem(i, j, n, o); ! Geometry.unTranslateGeometry(base.collect(), local); ! if (dir.dot(base.normal()) < 0) { ! base.flip(); ! } ! base.setFrontDomain(joist); ! Set<Surface> sides = new HashSet<Surface>(); ! base.extrude(length, sides); ! space.addAll(sides); ! } ! } ! ! private Map<Edge, Edge> getRuns(Net net) { ! Map<Edge, Edge> edge2Run = new HashMap<Edge, Edge>(); ! if (net != null) { ! Collection<Edge> netEdges = net.getEdges(); ! for (Edge e : netEdges) { ! if (edge2Run.get(e) == null) { ! List<Edge> run = e.parrallelRun(); ! int size = run.size(); ! if (size > 1) { ! Edge first = run.get(0); ! Edge second = run.get(1); ! Edge last = run.get(size - 1); ! Edge secondLast = run.get(size - 2); ! Vertex from = first.otherVertex(Edge.commonVertex(first, second)); ! Vertex to = last.otherVertex(Edge.commonVertex(last, secondLast)); ! Edge runEdge = new Edge(from, to); ! for (Edge r : run) { ! edge2Run.put(r, runEdge); ! } } else { ! edge2Run.put(e, e); } } } } + return edge2Run; } ! private static Surface joistBase() { List<Vertex> vl = new LinkedList<Vertex>(); ! Vertex first = new Vertex(0, 0, 0); ! vl.add(new Vertex(JOIST_WIDTH, 0, 0)); ! vl.add(new Vertex(JOIST_WIDTH, JOIST_DEPTH, 0)); ! vl.add(new Vertex(0, JOIST_DEPTH, 0)); List<Edge> el = new LinkedList<Edge>(); Vertex prevV = first; *************** *** 182,186 **** Surface base = new Surface(el); return base; ! } private Net buildNet() { --- 279,283 ---- Surface base = new Surface(el); return base; ! } private Net buildNet() { *************** *** 188,223 **** 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; --- 285,334 ---- Net net = new Net("net"); space.add(net); ! surface = findSurface(); ! Surface netSurface = surface.copy(net); Edge vertical = null; Edge horizontal = null; ! for (Edge e : netSurface.getEdges()) { ! if (horizontal(e)) { horizontal = e; } } ! for (Edge e : netSurface.getEdges()) { ! Vertex common = Edge.commonVertex(horizontal, e); ! if (common == horizontal.getFrom() && vertical(e)) { vertical = e; } } ! if (horizontal != null && vertical != null) { ! Vertex origin = horizontal.getFrom(); ! Vertex topToBottom = 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() - joistInterval) { + Vertex from = current.copy(); + Vertex to = from.add(topToBottom); + net.insert(from); + net.insert(to); + net.insert(new Edge(from, to)); + current.move(interval.getX(), interval.getY(), interval.getZ()); + } + Vertex i; + Vertex j; + Vertex n; + n = new Vertex(0, 0, 1); + j = surface.normal(); + if (surface.getBackDomain() == space) { + j.scale(-1); + } + i = j.cross(n); + i.normalize(); + j.normalize(); + n.normalize(); + cs = new CoordinateSystem(i, j, n, origin); + } else { + log.error("The surface found did not meet the requirements"); + return null; } return net; *************** *** 227,235 **** /** * {@inheritDoc} */ @Override public void delete() { ! // TODO Auto-generated method stub } --- 338,421 ---- /** + * Adds edges to the net of this modellor to support other + * innerwalls. + */ + private void addSupport() { + if (net != null) { + log.info("net not null"); + Set<Surface> envelope = space.getEnvelope(); + for (Surface s : envelope) { + Space front = s.getFrontDomain(); + Space back = s.getBackDomain(); + Classification frontClass = front.getClassification(); + Classification backClass = back.getClassification(); + if ((frontClass != null && backClass != null) && + ((frontClass.getFullId(front).equalsIgnoreCase(INNERWALL_CLASS) && front != space) || + (backClass.getFullId(back).equalsIgnoreCase(INNERWALL_CLASS) && back != space))) { + log.info("found suiteable surface"); + Edge left = null; + double minX = Double.POSITIVE_INFINITY; + double maxX = Double.NEGATIVE_INFINITY; + for (Edge e : s.getEdges()) { + Vertex from = cs.translate(e.getFrom()); + double x = from.getX(); + if (vertical(e)) { + if (minX > x) { + minX = x; + left = e; + } + if (maxX < x) { + maxX = x; + } + } + } + if (maxX > minX) { + log.info("found left succesfully"); + Vertex to = cs.translate(left.getTo()); + Vertex from = cs.translate(left.getFrom()); + to.setY(0); + from.setY(0); + to = cs.unTranslate(to); + from = cs.unTranslate(from); + Edge support1 = new Edge(to, from); + net.insert(support1); + Edge support2 = support1.copy(); + Vertex move = cs.getI().copy(JOIST_WIDTH / cs.getI().length()); + support2.move(move); + net.insert(support2); + } + } + } + } + } + + private Surface findSurface() { + Surface surface = space.getEnvelope().iterator().next(); + for (Surface s : space.getEnvelope()) { + Space front = s.getFrontDomain(); + Space back = s.getBackDomain(); + Classification frontClass = front.getClassification(); + Classification backClass = back.getClassification(); + if ((frontClass != null && backClass != null) && + ((frontClass.getFullId(front).equalsIgnoreCase("-80") && front != space) || + (backClass.getFullId(back).equalsIgnoreCase("-80") && back != space))) { + surface = s; + break; + } + } + return surface; + } + + + /** * {@inheritDoc} */ @Override public void delete() { ! space.clear(); ! if (space.getModellor() == this) { ! space.setModellor(null); ! } ! build = false; } *************** *** 261,324 **** 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(); } } --- 447,503 ---- public void setSurface(Surface surface) { this.surface = surface; ! } ! /** ! * Checks if all of a net is in a given plane. ! * @param net the net ! * @param p the plane ! * @return true if all geometry in the net is in the plane, false otherwise */ ! private boolean getPlaneCheck(Net net, Plane p) { ! for (Edge e : net.getEdges()) { ! if (!p.contains(e)) { ! return false; } } ! return true; ! } ! ! /** ! * For setting attributes. If the candidate is different from the current ! * the space is cleared, the build flag is set and the candidate is returned. Otherwise ! * the current value is returned. ! * @param <Type> ! * @param current current value ! * @param candidate candidate value ! * @return the result ! */ ! private <Type> Type buildIfDifferent(Type current, Type candidate) { ! if (candidate != null && !current.equals(candidate)) { ! build = true; ! return candidate; } ! return current; ! } ! ! private boolean horizontal(Edge e) { ! Vertex to = e.getTo(); ! Vertex from = e.getFrom(); ! return Math.abs(to.getZ() - from.getZ()) < Geometry.EPS; ! } ! ! private boolean vertical(Edge e) { ! Vertex to = e.getTo(); ! Vertex from = e.getFrom(); ! return (Math.abs(to.getX() - from.getX()) < Geometry.EPS && ! Math.abs(to.getY() - from.getY()) < Geometry.EPS); } + /** + * Gets the net + * @return the net of this modellor + */ + public Net getNet() { + return net; + } } |