Thread: [Bprocessor-commit] /model/src/net/sourceforge/bprocessor/model/modellor TileModellor.java, NONE,
Status: Pre-Alpha
Brought to you by:
henryml
Update of /cvsroot/bprocessor//model/src/net/sourceforge/bprocessor/model/modellor In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv27279/src/net/sourceforge/bprocessor/model/modellor Modified Files: Modellor.java LayerModellor.java Added Files: TileModellor.java WindowModellor.java Cylinder.java ModelBathModellor.java Log Message: moved modellors not regarding Facade to the Modellor Package --- NEW FILE: ModelBathModellor.java --- //--------------------------------------------------------------------------------- // $Id: ModelBathModellor.java,v 1.1 2007/04/10 20:59:01 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.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 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; } /** {@inheritDoc} */ @Override public int getUseableLevel() { return Space.PROJECT_LEVEL; } } --- NEW FILE: WindowModellor.java --- //--------------------------------------------------------------------------------- // $Id: WindowModellor.java,v 1.1 2007/04/10 20:59:01 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.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Iterator; 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.Plane; 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 to make windows */ public class WindowModellor extends Modellor { /** Id */ private static final long serialVersionUID = 1L; /** The logger */ private static Logger log = Logger.getLogger(WindowModellor.class); /** The width of the frame */ private double framewidth = 0.054; /** The depth of the frame */ private double framedepth = 0.125; /** The offset in the window */ private double offset = 0; /** The number of vertical sprosses */ private int verticalSprosses = 0; /** The number of horizontal sprosses */ private int horizontalSprosses = 0; /** The used space */ private Space space; /** The bound surface */ private Surface surface; /** The created bounding */ private Surface opposite; /** The constructed geometry */ private Set extension; /** The direction of action */ private int sign; /** * the constructor */ public WindowModellor() { } /** * the constructor * @param s The space this modellor makes * @param sur The surface in the given space is use as base */ public WindowModellor(Space s, Surface sur) { space = s; surface = sur; extension = new HashSet(); if (s.getEnvelope().size() == 1) { Surface ext = sur.getExterior(); double minDist = Double.NaN; if (ext != null) { Collection tryout = new ArrayList(0); if (sur.getFrontDomain() == s) { Space front = ext.getFrontDomain(); if (front != null) { tryout = front.getEnvelope(); } } else { Space back = ext.getBackDomain(); if (back != null) { tryout = back.getEnvelope(); } } Iterator iter = tryout.iterator(); Vertex normal = sur.normal(); Vertex center = sur.center(); while (iter.hasNext()) { Surface cur = (Surface)iter.next(); Plane p = cur.plane(); Vertex inter = p.intersection(center, normal, true); if (inter != null) { double dist = center.distance(inter); if (Double.isNaN(minDist) || (dist < minDist && dist > 0.00001)) { minDist = dist; } } } } if (Double.isNaN(minDist)) { minDist = framedepth + offset; } sign = 1; if (surface.getBackDomain() == space) { sign = -1; } opposite = sur.extrude(sign * minDist, extension); Geometry.holeAnalysis(opposite); extension.add(opposite); } drawWindow(); } /** {@inheritDoc} */ public void update(Object entity) { if (entity == space || entity == surface) { cleanUp(); drawWindow(); } } /** Draw the window */ public void drawWindow() { Space frame = new Space("Frame", Space.CONSTRUCTION, Space.ELEMENT_LEVEL, true); Space glass = new Space("Glass", Space.CONSTRUCTION, Space.ELEMENT_LEVEL, true); glass.setTransparent(true); Surface inner = surface.copy(space); inner.setFrontDomain(frame); //make hole in frame Vertex normal = surface.normal(); normal.scale(-offset); inner.move(normal.getX(), normal.getY(), normal.getZ()); List holeedges = Edge.offset(inner.getEdges(), inner, -framewidth); Iterator iter = holeedges.iterator(); space.add(((Edge)holeedges.get(0)).getTo()); while (iter.hasNext()) { Edge e = (Edge)iter.next(); space.add(e.getFrom()); space.add(e); } Surface glasssurface = new Surface(holeedges); inner.addHole(glasssurface); space.add(glasssurface); glasssurface.setFrontDomain(glass); HashSet tmp = new HashSet(); Surface frametop = inner.extrude(sign * framedepth, tmp); tmp.clear(); Surface hole = glasssurface.extrude(sign * framedepth, tmp); frametop.addHole(hole); space.add(frame); space.add(glass); } /** {@inheritDoc} */ public Modellor newInstance(Space s) { if (s.getLevel() == Space.SPACE_LEVEL) { return new WindowModellor(s, (Surface)(s.getEnvelope().iterator().next())); } 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) { framewidth = ((Double)((Attribute)attributes.get(1)).getValue()).doubleValue(); framedepth = ((Double)((Attribute)attributes.get(2)).getValue()).doubleValue(); offset = ((Double)((Attribute)attributes.get(3)).getValue()).doubleValue(); Iterator sit = Project.getInstance().getActiveSpace().getSurfaces().iterator(); Object value = ((Attribute)attributes.get(4)).getValue(); while (sit.hasNext()) { Project.getInstance().checkpoint(); Surface s = (Surface)sit.next(); if (s.getName().equals(value)) { surface = s; } } update(space); } /** {@inheritDoc} */ public List getAttributes() { List res = new LinkedList(); res.add(new Attribute("Name", getName(), false)); res.add(new Attribute("Framewidth", new Double(framewidth))); res.add(new Attribute("Framedepth", new Double(framedepth))); res.add(new Attribute("Offset", new Double(offset))); res.add(new Attribute("Surface", surface)); return res; } /** {@inheritDoc} */ public String getName() { return "Window"; } /** {@inheritDoc} */ public String getGeneralName() { return "Window modellor"; } /** {@inheritDoc} */ public void setContent(Map m) { framewidth = ((Double)m.get("Framewidth")).doubleValue(); framedepth = ((Double)m.get("Framedepth")).doubleValue(); offset = ((Double)m.get("Offset")).doubleValue(); sign = ((Integer)m.get("Sign")).intValue(); surface = (Surface)m.get("Surface"); space = (Space)m.get("Space"); } /** {@inheritDoc} */ public Map getContent() { Map what = new HashMap(); what.put("Framewidth", new Double(framewidth)); what.put("Framedepth", new Double(framedepth)); what.put("Offset", new Double(offset)); what.put("Sign", new Integer(sign)); what.put("Space", space); what.put("Surface", surface); return what; } /** {@inheritDoc} */ @Override public int getUseableLevel() { return Space.ELEMENT_LEVEL; } } --- NEW FILE: TileModellor.java --- //--------------------------------------------------------------------------------- // $Id: TileModellor.java,v 1.1 2007/04/10 20:59:01 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.awt.Dimension; import java.util.ArrayList; import java.util.List; import net.sourceforge.bprocessor.model.CoordinateSystem; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Material; import net.sourceforge.bprocessor.model.Space; import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; /** * @author rimestad * A modellor for filling a space with tiles in a ordered way */ public class TileModellor extends Modellor { private static final long serialVersionUID = 1L; /** tile dimension */ private Dimension tileSize = new Dimension(100, 100); /** The width of the joint between tiles */ private static int jointSize = 3; private Material tileColor = new Material("White", new float[]{.0f, .0f, .0f}); private Surface surface; private CoordinateSystem startPoint; private Space space; /** tile thickness in mm */ private static int tileThickness = 8; /** * Fill the give space with tiles * @param s The space */ public TileModellor(Space s) { space = s; surface = s.getSurfaces().iterator().next(); startPoint = surface.coordinateSystem(); } /** * {@inheritDoc} */ @Override public Modellor newInstance(Space s) { return new TileModellor(s); } /** * {@inheritDoc} */ @Override public void update(Object entity) { Space tile = new Space("Tile", Space.CONSTRUCTION, Space.PART_LEVEL, true); tile.setUnion(true); space.add(tile); Vertex v1 = new Vertex(0, 0, 0); Vertex v2 = new Vertex(tileSize.width, 0, 0); Vertex v3 = new Vertex(tileSize.width, tileSize.height, 0); Vertex v4 = new Vertex(0, tileSize.height, 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 front = new Surface(edges); front.setFrontMaterial(tileColor); front.setFrontDomain(tile); space.insert(front); List<Surface> extrusion = new ArrayList<Surface>(); front.extrusion(tileThickness / 1000, extrusion); space.addAll(extrusion); } /** * {@inheritDoc} */ @Override public void delete() { // TODO Auto-generated method stub } /** {@inheritDoc} */ @Override public int getUseableLevel() { return Space.PART_LEVEL; } } Index: Modellor.java =================================================================== RCS file: /cvsroot/bprocessor//model/src/net/sourceforge/bprocessor/model/modellor/Modellor.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Modellor.java 10 Apr 2007 13:19:52 -0000 1.6 --- Modellor.java 10 Apr 2007 20:59:01 -0000 1.7 *************** *** 87,90 **** --- 87,96 ---- /** + * The level this modellor is useable in (statics can be found in Space) + * @return The level + */ + public abstract int getUseableLevel(); + + /** * Get parameter block for element * @param element Space Index: LayerModellor.java =================================================================== RCS file: /cvsroot/bprocessor//model/src/net/sourceforge/bprocessor/model/modellor/LayerModellor.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** LayerModellor.java 2 Jan 2007 17:48:58 -0000 1.10 --- LayerModellor.java 10 Apr 2007 20:59:01 -0000 1.11 *************** *** 238,240 **** --- 238,246 ---- return null; } + + /** {@inheritDoc} */ + @Override + public int getUseableLevel() { + return Space.PART_LEVEL; + } } --- NEW FILE: Cylinder.java --- //--------------------------------------------------------------------------------- // $Id: Cylinder.java,v 1.1 2007/04/10 20:59:01 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.Arrays; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Project; import net.sourceforge.bprocessor.model.Space; import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; /** * The cylinder class parametrically generates a cylinder. */ public class Cylinder extends Modellor { /** Default */ private static final long serialVersionUID = 1L; /** radius */ private double radius = 1.0; /** height */ private double height = 1.0; /** axis divisions */ private int axisDivisions = 12; /*** * Generate a Cylinder * @param entity Changed entity */ public void update(Object entity) { /** Origin */ Vertex o = new Vertex(0, 0, 0); /** Bottom vertices */ Vertex[] bv = new Vertex[axisDivisions]; /** Top vertices */ Vertex[] tv = new Vertex[axisDivisions]; /** Bottom edges */ Edge[] be = new Edge[axisDivisions]; /** Top edges */ Edge te[] = new Edge[axisDivisions]; /** Side edges */ Edge se[] = new Edge[axisDivisions]; /** Side faces */ Surface sf[] = new Surface[axisDivisions]; Surface top; Surface bottom; Space space = Project.getInstance().world(); for (int i = 0; i < axisDivisions; i++) { double angle = ((2 * Math.PI) * i) / (double) axisDivisions; double x = radius * Math.cos(angle) + o.getX(); double y = radius * Math.sin(angle) + o.getY(); double z = o.getZ(); bv[i] = new Vertex(x, y, z); tv[i] = new Vertex(x, y, z + height); space.add(bv[i]); space.add(tv[i]); } for (int i = 0; i < axisDivisions; i++) { be[i] = new Edge(bv[i], bv[(i + 1) % axisDivisions]); space.add(be[i]); } for (int i = 0; i < axisDivisions; i++) { te[i] = new Edge(tv[i], tv[(i + 1) % axisDivisions]); space.add(te[i]); } for (int i = 0; i < axisDivisions; i++) { se[i] = new Edge(bv[i], tv[i]); space.add(se[i]); } for (int i = 0; i < axisDivisions; i++) { List edges = new LinkedList(); edges.add(be[i]); edges.add(se[(i + 1) % axisDivisions]); edges.add(te[i]); edges.add(se[i]); sf[i] = new Surface(edges); space.add(sf[i]); } { List edges = new LinkedList(Arrays.asList(be)); bottom = new Surface(edges); space.add(bottom); } { List edges = new LinkedList(Arrays.asList(te)); top = new Surface(edges); space.add(top); } } /** * Return null for center * @return Center */ public Vertex center() { return null; } /** * FIXME: empty implementation to make compile * (pfff make sure stuff compiles before you check in please) */ public void delete() { return; } /** {@inheritDoc} */ public void setAttributes(List attributes) { // TODO Auto-generated method stub } /** {@inheritDoc} */ public List getAttributes() { // TODO Auto-generated method stub return null; } /** {@inheritDoc} */ public Modellor newInstance(Space s) { // TODO Auto-generated method stub return null; } /** {@inheritDoc} */ public void setContent(Map m) { axisDivisions = ((Integer)m.get("Axis")).intValue(); height = ((Double)m.get("Height")).doubleValue(); radius = ((Double)m.get("Radius")).doubleValue(); } /** {@inheritDoc} */ public Map getContent() { Map m = new HashMap(); m.put("Axis", new Integer(axisDivisions)); m.put("Height", new Double(height)); m.put("Radius", new Double(radius)); return m; } /** {@inheritDoc} */ @Override public int getUseableLevel() { return Space.PART_LEVEL; } } |