[Bprocessor-commit] facade/src/net/sourceforge/bprocessor/facade/modellor ModelBathModellor.java,
Status: Pre-Alpha
Brought to you by:
henryml
|
From: rimestad <rim...@us...> - 2007-03-28 21:33:28
|
Update of /cvsroot/bprocessor/facade/src/net/sourceforge/bprocessor/facade/modellor In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv28510/src/net/sourceforge/bprocessor/facade/modellor Added Files: ModelBathModellor.java Log Message: Initial version of badkabine --- NEW FILE: ModelBathModellor.java --- //--------------------------------------------------------------------------------- // $Id: ModelBathModellor.java,v 1.1 2007/03/28 21:33:27 rimestad 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.Collection; import java.util.HashMap; import java.util.HashSet; 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.Space; import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.model.modellor.Modellor; import org.apache.log4j.Logger; /** A modellor to make windows */ public class ModelBathModellor extends Modellor { /** Id */ private static final long serialVersionUID = 1L; /** The logger */ private static Logger log = Logger.getLogger(ModelBathModellor.class); private Space space; private Surface bottom; private Surface top; private double shaftOffset; private double length; private double width; private double height; private double floorThickness = 55; private double wallThickness = 55; private double ceilingThickness = 55; /** * the constructor */ public ModelBathModellor() { super(); shaftOffset = 100; } /** * the constructor * @param s the Space to realize the modellor in */ public ModelBathModellor(Space s) { this(); space = s; bottom = null; Collection<Surface> vertical = new HashSet<Surface>(); Collection<Surface> horizontal = new HashSet<Surface>(); Collection<Surface> surs = s.getEnvelope(); if (surs.size() != 6) { log.info("Have to be a square box with 6 sides 4 vertical and 2 horizontal"); return; } Vertex up = new Vertex(0, 0, 1); for (Surface sur : surs) { double dot = (sur.normal()).dot(up); if (Math.abs(dot) - 1 < 0.001) { horizontal.add(sur); } else if (dot < 0.001 && dot > -0.001) { vertical.add(sur); } } if (vertical.size() + horizontal.size() != surs.size()) { log.error("Sides were not vertical and top and bottom vertical"); return; } for (Surface sur : horizontal) { if (bottom == null) { bottom = sur; } else { if (bottom.getFirstVertex().getZ() > sur.getFirstVertex().getZ()) { top = bottom; bottom = sur; } else { top = sur; } } } if (bottom == null || top == null) { log.error("Could not find at bottom surface"); return; } else { List<Edge> edges = bottom.getEdges(); width = edges.get(0).getLength() * 1000; length = edges.get(1).getLength() * 1000; height = bottom.plane().distance(top.getFirstVertex()) * 1000; } generate(); } /** * */ private void generate() { Surface making = makeFloor(); Space wallSystem = new Space("Vægsystem", Space.CONSTRUCTION, Space.ELEMENT_LEVEL, true); space.add(wallSystem); making.setBackDomain(wallSystem); { List<Edge> offset = Edge.offset(making.getEdges(), making, -wallThickness / 1000); Surface room = new Surface(offset); for (Edge e : offset) { space.add(e.getFrom()); space.add(e.getTo()); space.add(e); } space.add(room); room.setFrontDomain(making.getFrontDomain()); room.setBackDomain(making.getBackDomain()); Geometry.holeAnalysis(room); Space badkabine = new Space("Badekabine", Space.FUNCTIONAL, Space.ELEMENT_LEVEL, true); space.add(badkabine); room.setBackDomain(badkabine); } { Set<Surface> sides = new HashSet<Surface>(); Set<Surface> tops = new HashSet<Surface>(); Surface top = making.extrusionall(-(height - floorThickness - ceilingThickness) / 1000, sides, tops); space.addAll(sides); space.addAll(tops); Space ceiling = new Space("Ceiling", Space.CONSTRUCTION, Space.ELEMENT_LEVEL, true); space.add(ceiling); for (Surface s : tops) { s.setFrontDomain(ceiling); } sides.clear(); sides.add(top.extrusion(ceilingThickness / 1000, sides)); space.addAll(sides); } } /** * */ private Surface makeFloor() { Space floor = new Space("Floor", Space.CONSTRUCTION, Space.ELEMENT_LEVEL, true); space.add(floor); bottom = bottom.copy(space); bottom.setFrontDomain(floor); Collection<Surface> geom = new LinkedList<Surface>(); Surface floorTop = bottom.extrusion(floorThickness / 1000, geom); geom.add(floorTop); space.addAll(geom); return floorTop; } /** {@inheritDoc} */ public void update(Object entity) { cleanUp(); generate(); } /** {@inheritDoc} */ public Modellor newInstance(Space s) { if (s.getLevel() == Space.SPACE_LEVEL) { return new ModelBathModellor(s); } else { return null; } } /** {@inheritDoc} */ public void delete() { space.setModellor(null); } /** * Clean up the constructed geometry */ private void cleanUp() { space.clear(); } /** {@inheritDoc} */ public void setAttributes(List attributes) { update(space); } /** {@inheritDoc} */ public List getAttributes() { List res = new LinkedList(); res.add(new Attribute("Name", getName(), false)); res.add(new Attribute("Length", length, true)); res.add(new Attribute("Width", width, true)); res.add(new Attribute("Height", height, true)); res.add(new Attribute("Shaft-offset", shaftOffset, true)); return res; } /** {@inheritDoc} */ public String getName() { return "Bath-module"; } /** {@inheritDoc} */ public String getGeneralName() { return "Bath-module modellor"; } /** {@inheritDoc} */ public void setContent(Map m) { space = (Space)m.get("Space"); } /** {@inheritDoc} */ public Map getContent() { Map what = new HashMap(); what.put("Space", space); return what; } } |