Thread: [Bprocessor-commit] model/src/net/sourceforge/bprocessor/model/modellor TileModellor.java, 1.7, 1.
Status: Pre-Alpha
Brought to you by:
henryml
|
From: rimestad <rim...@us...> - 2007-04-21 13:37:13
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/modellor In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv8847/src/net/sourceforge/bprocessor/model/modellor Modified Files: TileModellor.java Log Message: made the modellor draw a net instead Index: TileModellor.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/modellor/TileModellor.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** TileModellor.java 17 Apr 2007 13:04:44 -0000 1.7 --- TileModellor.java 21 Apr 2007 13:37:12 -0000 1.8 *************** *** 9,12 **** --- 9,15 ---- import java.awt.Dimension; import java.util.ArrayList; + import java.util.Collection; + import java.util.Collections; + import java.util.Comparator; import java.util.LinkedList; import java.util.List; *************** *** 19,23 **** import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Material; ! import net.sourceforge.bprocessor.model.Relation; import net.sourceforge.bprocessor.model.Space; import net.sourceforge.bprocessor.model.Surface; --- 22,26 ---- import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Material; ! import net.sourceforge.bprocessor.model.Net; import net.sourceforge.bprocessor.model.Space; import net.sourceforge.bprocessor.model.Surface; *************** *** 52,55 **** --- 55,60 ---- /** tile thickness in mm */ private int tileThickness = 8; + + private Net net; /** *************** *** 70,75 **** surface = s.getEnvelope().iterator().next(); startPoint = surface.coordinateSystem(); ! startPoint.add(new Relation(surface, "0")); space.add(tileColor); } } --- 75,82 ---- surface = s.getEnvelope().iterator().next(); startPoint = surface.coordinateSystem(); ! space.getOwner().add(startPoint); ! startPoint.relate(surface); space.add(tileColor); + updateNet(startPoint); } } *************** *** 94,100 **** log.info("Modellor update on " + entity); space.clear(); ! space.add(startPoint); ! CoordinateSystem cs = startPoint; //find outer borders double maxX = Double.MIN_VALUE, maxY = Double.MIN_VALUE, minX = Double.MAX_VALUE, minY = Double.MAX_VALUE; --- 101,113 ---- log.info("Modellor update on " + entity); space.clear(); ! space.add(net); //find outer borders + + } + + /** + * @param cs + */ + private void updateNet(CoordinateSystem cs) { double maxX = Double.MIN_VALUE, maxY = Double.MIN_VALUE, minX = Double.MAX_VALUE, minY = Double.MAX_VALUE; *************** *** 114,152 **** } } ! List<Surface> tiles = new LinkedList<Surface>(); CoordinateSystem insertPoint = cs.copy(); insertPoint.setOrigin(cs.unTranslate(new Vertex(minX + jointSize / 2000.0, minY + jointSize / 2000.0, 0))); ! Vertex orig = insertPoint.center(); if (height > 0) { maxY = height / 1000.0; } ! Vertex localHori = new Vertex(tileSize.getWidth() / 1000.0 + jointSize / 2000.0, 0, 0); ! Vertex horizontalAdd = insertPoint.unTranslate(localHori).minus(orig); ! do { ! Vertex localVert = new Vertex(0, tileSize.getHeight() / 1000.0 + jointSize / 2000.0, 0); ! Vertex verticalAdd = insertPoint.unTranslate(localVert).minus(orig); ! int iterations = 0; ! do { ! tiles.add(drawTile(insertPoint, tileColor)); ! orig = orig.add(verticalAdd); ! insertPoint.setOrigin(orig); ! iterations++; ! } while (cs.translate(orig.copy()).getY() < maxY); ! orig = orig.add(horizontalAdd); ! Vertex tmp = verticalAdd.copy(); ! tmp.scale(iterations); ! orig = orig.minus(tmp); ! insertPoint.setOrigin(orig); ! } while (cs.translate(orig.copy()).getX() < maxX); ! ! for (Surface s : tiles) { ! List<Surface> extrusion = new ArrayList<Surface>(); ! Surface back = s.extrusion(-tileThickness / 1000.0, extrusion); ! extrusion.add(back); ! extrusion.add(s); ! space.addAll(extrusion); } } --- 127,233 ---- } } ! ! net = new Net("strip"); ! space.add(net); ! surface.copyall(net); ! Collection<Edge> edges = new ArrayList<Edge>(net.getEdges()); ! Collection<Edge> horEdges = new LinkedList<Edge>(); ! Collection<Edge> vertEdges = new LinkedList<Edge>(); ! Collection<Vertex> createdVerts = new LinkedList<Vertex>(); ! ! // insert horizontal edges CoordinateSystem insertPoint = cs.copy(); insertPoint.setOrigin(cs.unTranslate(new Vertex(minX + jointSize / 2000.0, minY + jointSize / 2000.0, 0))); ! Vertex orig = cs.center(); if (height > 0) { maxY = height / 1000.0; } ! Vertex localHori = new Vertex(0, tileSize.getHeight() / 1000.0 + jointSize / 2000.0, 0); ! Vertex horizontalAdd = cs.unTranslate(localHori).minus(orig); ! Edge slider = new Edge(cs.center().copy(), cs.unTranslate(new Vertex(maxX, 0, 0))); ! findIntersectingEdges(cs, slider, maxX, maxY, edges, horEdges, createdVerts, horizontalAdd); ! //insert vertical edges ! Vertex localVertical = new Vertex(tileSize.getWidth() / 1000.0 + jointSize / 2000.0, 0, 0); ! Vertex verticalAdd = cs.unTranslate(localVertical).minus(orig); ! slider = new Edge(cs.center().copy(), cs.unTranslate(new Vertex(0, maxY, 0))); ! findIntersectingEdges(cs, slider, maxX, maxY, edges, vertEdges, createdVerts, verticalAdd); ! ! Collection<Vertex> extras = new LinkedList<Vertex>(); ! for (Edge e1 : vertEdges) { ! for (Edge e2 : horEdges) { ! Edge inter = e1.intersection(e2); ! if (inter.getLength() < 0.00001 && ! e2.coincides(inter.getFrom()) && ! e1.coincides(inter.getFrom())) { ! extras.add(inter.getFrom()); ! } ! } } + for (Vertex v : createdVerts) { + net.insert(v); + } + for (Edge e : horEdges) { + net.insert(e); + } + for (Edge e : vertEdges) { + net.insert(e); + } + for (Vertex v : extras) { + net.insert(v); + } + //new SurfaceAnalysis().surfaceAnalysis(net); + } + + /** + * @param cs the coordinatesystem to work in + * @param slider The edge that slides over the surface + * @param maxX the maximum value for x + * @param maxY the maximum value for y + * @param edges The edges to check intersection with + * @param createdEdges the list to put all the created edges in + * @param createdVerts the list to put all the found intersection in + * @param increment the vertex to increment with in each step + */ + private void findIntersectingEdges(CoordinateSystem cs, + Edge slider, + double maxX, + double maxY, + Collection<Edge> edges, + Collection<Edge> createdEdges, + Collection<Vertex> createdVerts, + Vertex increment) { + do { + List<Vertex> intersections = new LinkedList<Vertex>(); + for (Edge inside : edges) { + Edge found = slider.intersection(inside); + if (found != null) { + if (found.getLength() < 0.0001 && inside.coincides(found.getTo())) { + intersections.add(found.getTo()); + } + } + } + if (intersections.size() > 1) { + Collections.sort(intersections, new DistComparator(slider.getFrom())); + Vertex prev = null; + for (Vertex v : intersections) { + if (prev != null) { + createdVerts.add(prev); + createdVerts.add(v); + createdEdges.add(new Edge(prev, v)); + prev = null; + } else { + prev = v; + } + } + } else { + if (!intersections.isEmpty()) { + createdVerts.add(intersections.get(0)); + } + } + slider.move(increment); + } while (cs.translate(slider.getFrom()).getY() < maxY && + cs.translate(slider.getFrom()).getX() < maxX); } *************** *** 190,203 **** public void setAttributes(Map<String, Attribute> attributes) { Attribute a = attributes.get("Tilewidth"); if (a != null) { ! tileSize.width = ((Double)a.getValue()).intValue(); } a = attributes.get("Tileheight"); if (a != null) { ! tileSize.height = ((Double)a.getValue()).intValue(); } a = attributes.get("Joint width"); if (a != null) { ! jointSize = ((Double)a.getValue()).intValue(); } a = attributes.get("Material"); --- 271,297 ---- public void setAttributes(Map<String, Attribute> attributes) { Attribute a = attributes.get("Tilewidth"); + boolean updateNet = false; if (a != null) { ! int width = ((Double)a.getValue()).intValue(); ! if (width != tileSize.width) { ! updateNet = true; ! tileSize.width = width; ! } } a = attributes.get("Tileheight"); if (a != null) { ! int height = ((Double)a.getValue()).intValue(); ! if (height != tileSize.width) { ! updateNet = true; ! tileSize.height = height; ! } } a = attributes.get("Joint width"); if (a != null) { ! int joint = ((Double)a.getValue()).intValue(); ! if (joint != jointSize) { ! updateNet = true; ! jointSize = joint; ! } } a = attributes.get("Material"); *************** *** 209,217 **** a = attributes.get("Surface"); if (a != null) { ! surface = (Surface)a.getValue(); } a = attributes.get("Setting height"); if (a != null) { ! height = ((Double)a.getValue()).intValue(); } update(this); --- 303,325 ---- a = attributes.get("Surface"); if (a != null) { ! Surface tmp = (Surface)a.getValue(); ! if (space.getEnvelope().contains(tmp)) { ! if (!tmp.equals(surface)) { ! surface = tmp; ! startPoint = surface.coordinateSystem(); ! updateNet = true; ! } ! } } a = attributes.get("Setting height"); if (a != null) { ! int h = ((Double)a.getValue()).intValue(); ! if (h != height) { ! updateNet = true; ! height = h; ! } ! } ! if (updateNet) { ! updateNet(startPoint); } update(this); *************** *** 304,306 **** --- 412,448 ---- return "Tilemodellor"; } + + /** + * A comparator class to compare vertices distance to at third vertex + * @author Rimestad + */ + public class DistComparator implements Comparator<Vertex> { + + private Vertex origin; + + /** + * Constructor + * @param origin the Vertex that the distance is compared to + */ + public DistComparator(Vertex origin) { + this.origin = origin; + } + + /** + * {@inheritDoc} + */ + public int compare(Vertex o1, Vertex o2) { + double dist1 = origin.distance(o1); + double dist2 = origin.distance(o2); + double diff = dist1 - dist2; + if (diff > 0) { + return 1; + } else if (diff < 0) { + return -1; + } else { + return 0; + } + } + + } } |