Thread: [Bprocessor-commit] model/src/net/sourceforge/bprocessor/model/modellor ModelBathModellor2.java, N
Status: Pre-Alpha
Brought to you by:
henryml
|
From: rimestad <rim...@us...> - 2007-05-15 16:28:12
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/modellor In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv5055/src/net/sourceforge/bprocessor/model/modellor Added Files: ModelBathModellor2.java Log Message: started on new bath modellor --- NEW FILE: ModelBathModellor2.java --- //--------------------------------------------------------------------------------- // $Id: ModelBathModellor2.java,v 1.1 2007/05/15 16:28:09 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.model.modellor; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import net.sourceforge.bprocessor.model.Attribute; import net.sourceforge.bprocessor.model.CoordinateSystem; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Geometry; import net.sourceforge.bprocessor.model.Geometric; import net.sourceforge.bprocessor.model.Net; import net.sourceforge.bprocessor.model.Project; import net.sourceforge.bprocessor.model.Selector; 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 to make windows */ public class ModelBathModellor2 extends Modellor { /** Id */ private static final long serialVersionUID = 1L; /** The logger */ private static Logger log = Logger.getLogger(ModelBathModellor2.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 = 0.080; private double wallThickness = 0.055; private double ceilingThickness = 0.055; private HashSet<Surface> vertical; private CoordinateSystem coord; private Net net; /** * the constructor */ public ModelBathModellor2() { super(); shaftOffset = 100; } /** * the constructor * @param s the Space to realize the modellor in */ public ModelBathModellor2(Space s) { this(); space = s; space.setUnion(true); coord = Project.getInstance().getActiveCoordinateSystem(); width = 2.800; length = 3.200; height = 2.800; generateNet(); space.add(net); net.edit(); Project.getInstance().addObserver(this); } /** * Generates the initial net */ private void generateNet() { Vertex v1 = new Vertex(0, 0, 0); Vertex v2 = new Vertex(width, 0, 0); Vertex v3 = new Vertex(width, length, 0); Vertex v4 = new Vertex(0, length, 0); Edge e1 = new Edge(v1, v2); Edge e2 = new Edge(v2, v3); Edge e3 = new Edge(v3, v4); Edge e4 = new Edge(v4, v1); List<Edge> edges = new ArrayList<Edge>(4); edges.add(e1); edges.add(e2); edges.add(e3); edges.add(e4); Surface s = new Surface(edges); net = new Net("Boundary"); net.add(v1); net.add(v2); net.add(v3); net.add(v4); net.add(e1); net.add(e2); net.add(e3); net.add(e4); net.add(s); } /** {@inheritDoc} */ public void update(Object entity) { if (entity.equals(net) || entity.equals(this) || entity.equals(space)) { cleanUp(); space.add(net); checkNetProperties(); generateBath(); } } /** * Create the floor, wall, ceiling and bath elements */ private void generateBath() { makeFloor(); makeWalls(); } /** * Generate wall element */ private void makeWalls() { Collection<Geometric> border = Geometry.copy(net.getEdges()); } /** * Generate floor element */ private void makeFloor() { Surface s = net.getSurfaces().iterator().next(); Space floor = new Space("Floor", Space.CONSTRUCTION, Space.SPACE_LEVEL, true); space.add(floor); s = s.copy(space); if (s.normal().getZ() < 0) { s.flip(); } s.setFrontDomain(floor); Collection<Surface> geom = new LinkedList<Surface>(); Surface floorTop = s.extrusion(floorThickness, geom); geom.add(floorTop); space.addAll(geom); } /** * check if edges have correct properties */ private void checkNetProperties() { for (Edge e : net.getEdges()) { Map<String, Object> env = e.getParameters().environment(); if (!env.containsKey("Type")) { List options = new LinkedList(); options.add("Wall"); options.add("Door"); options.add("Window"); Selector sel = new Selector(options); sel.setCurrentValue("Wall"); e.getParameters().put(new Attribute("Type", sel)); } } for (Vertex v : net.getVertices()) { Map<String, Object> env = v.getParameters().environment(); if (!env.containsKey("Corner")) { switch (v.getEdges().size()) { case 3 : v.getParameters().put(new Attribute("Corner", "Straight")); break; case 2 : List options = new LinkedList(); options.add("Left"); options.add("Right"); Selector sel = new Selector(options); sel.setCurrentValue("Left"); v.getParameters().put(new Attribute("Corner", sel)); break; default: break; } } } } /** {@inheritDoc} */ public Modellor newInstance(Space s) { if (s.getLevel() == Space.SPACE_LEVEL) { return new ModelBathModellor2(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(Map<String, Attribute> attributes) { Attribute a = attributes.get("Length"); if (a != null) { length = (Double)a.getValue(); } a = attributes.get("Width"); if (a != null) { width = (Double)a.getValue(); } a = attributes.get("Height"); if (a != null) { height = (Double)a.getValue(); } a = attributes.get("Shaft-offset"); if (a != null) { shaftOffset = (Double)a.getValue(); } update(space); } /** {@inheritDoc} */ public void getAttributes(List<Attribute> l) { l.add(new Attribute("Length", length, true)); l.add(new Attribute("Width", width, true)); l.add(new Attribute("Height", height, true)); l.add(new Attribute("Shaft-offset", shaftOffset, true)); } /** {@inheritDoc} */ public String getName() { return "New Bath-module"; } /** {@inheritDoc} */ public String getGeneralName() { return "New Bath-module modellor"; } /** {@inheritDoc} */ public void setSubContent(Map<String, Object> m) { space = (Space)m.get("Space"); } /** {@inheritDoc} */ public void getSubContent(Map<String, Object> m) { m.put("Space", space); } /** {@inheritDoc} */ @Override public int getUseableLevel() { return Space.SPACE_LEVEL; } } |