internal void SetBoundingBox(List <ColoBox> staticBoxes, bool isCandidate = false) { boundingBox = GetBiggestBox(staticBoxes, isCandidate); boundingBox.LayoutManager = this; if (this.LocationMachine == null) { ColoEngine.Model.LocationStatemachine.Machine locationMachine = new LocationStatemachine.Machine(initParam, boundingBox); this.LocationMachine = locationMachine; this.LocationMachine.direction = DirectionController; } this.LocationMachine.boundingBox = boundingBox; //assign the layout manager to all the static boxes foreach (ColoBox box in staticBoxes) { box.LayoutManager = this; } borderVerifier = new BorderVerifier(staticBoxes, this.LocationMachine); this.LocationMachine.BorderVerifier = borderVerifier; //if (borderVerifier.IsRotating) //{ // double angle = borderVerifier.Angle; // foreach (ColoBox cb in staticBoxes) // { // cb.Rotate(angle); // } //} //borderVerifier = new BorderVerifier(staticBoxes, locationMachine); }
public ColoBox Clone() { ColoBox ret = new ColoBox(); foreach (Point v in Points) { ret.AddPoint(v.X, v.Y); } return(ret); }
public ColoBox GetBiggestBox(List <ColoBox> staticObjects, bool isCandidate) { if (!isCandidate) { double area = -1; ColoBox ret = null; foreach (ColoBox b in staticObjects) { if (b.Area > area) { area = b.Area; ret = b; } } return(ret); } else { double minX, minY, maxX, maxY; minX = minY = double.MaxValue; maxX = maxY = double.MinValue; foreach (ColoBox b in staticObjects) { if (b.MinX < minX) { minX = b.MinX; } if (b.MinY < minY) { minY = b.MinY; } if (b.MaxX > maxX) { maxX = b.MaxX; } if (b.MaxY > maxY) { maxY = b.MaxY; } } ColoBox ret = new ColoBox(); ret.AddPoint(minX, minY); ret.AddPoint(minX, maxY); ret.AddPoint(maxX, maxY); ret.AddPoint(maxX, minY); ret.LayoutManager = this; string x = ret.PointsCollection; return(ret); } }
public string GetUniverseCandidate() { List <ColoBox> lines = staticObjects.Where(s => s.Layer == universeLayer).ToList(); ColoBox universe = new ColoBox(); double minX, minY, maxX, maxY; minX = minY = double.MaxValue; maxX = maxY = double.MinValue; foreach (ColoBox line in lines) { if (line.MinX < minX) { minX = line.MinX; } if (line.MinY < minY) { minY = line.MinY; } if (line.MaxX > maxX) { maxX = line.MaxX; } if (line.MaxY > maxY) { maxY = line.MaxY; } Point point1 = new Point() { X = minX, Y = minY }; Point point2 = new Point() { X = maxX, Y = maxY }; universe.Borders.Add(new RawBorder(point1, point2)); } universe.AddPoint(minX, minY); universe.AddPoint(maxX, maxY); return(universe.PointsCollection); }
private void loadGraphicsObject(List <ColoBox> staticObjects, LayoutManager manager, List <ColoBox> boxes2relo) { foreach (ColoBox box in boxes) { if (staticLayers.Contains(box.Layer))// == "wals") { //manager = new LayoutManager(box); staticObjects.Add(box); continue; } if (box.Layer == "racks") { ColoBox cloned = box.Clone(); if (manager != null) { cloned.LayoutManager = manager; } boxes2relo.Add(cloned); } } }
public ColoOptimizer(string fileName, InitParams init, ProjectClass project = null) { this.fileName = fileName; this.initParams = init; RawBorder.Tolerance = 0.5;//init.Tolerance; if (!init.UseExistingData) { try { dxf = DxfDocument.Load(fileName); } catch (Exception) { } staticLayers = init.StaticLayers.Aggregate(new List <string>(), (lst, entry) => { lst.Add(entry.Name); if (entry.IsUniverse) { universeLayer = entry.Name; } return(lst); }); boxes = new List <ColoBox>(); loadPolylinesToBoxes(project); } else { //string sJson = File.ReadAllText(init.DataFile); Boxes2relo = new List <ColoBox>(); staticObjects = new List <ColoBox>(); manager = new LayoutManager(this.initParams); //loading all the Boxes2relo for (int i = 0; i < project.Racks.Length; ++i) { Point p1 = new Point { X = 0, Y = 0 }; Point p2 = new Point { }; for (int j = 0; j < project.Racks[i].Quantity; ++j) { ColoBox box = new ColoBox("racks", i * j); box.LayoutManager = manager; double maxX = project.Racks[i].Width; double maxY = project.Racks[i].Height; box.AddPoint(0, 0); box.AddPoint(maxX, 0); box.AddPoint(maxX, maxY); box.AddPoint(0, maxY); Boxes2relo.Add(box); } } //loading the universe ColoBox universeBox = new ColoBox(); universeBox.LayoutManager = manager; for (int i = 0; i < project.UniverseNodes.Length; ++i) { universeBox.AddPoint(project.UniverseNodes[i].X, project.UniverseNodes[i].Y); } staticObjects.Add(universeBox); //loading the obstacles ColoBox obst = null; for (int i = 0; i < project.Obstacles.Length; ++i) { obst = new ColoBox(); obst.Layer = "pillar"; obst.LayoutManager = manager; for (int j = 0; j < project.Obstacles[i].Points.Length; ++j) { obst.AddPoint(project.Obstacles[i].Points[j].X, project.Obstacles[i].Points[j].Y); } staticObjects.Add(obst); } } }
public void AddUniverse(ColoBox universe) { staticObjects.Add(universe); }
public string GetUniverse() { ColoBox universe = staticObjects.First(s => s.Layer == universeLayer); return(universe.PointsCollection);// }
private void loadPolylinesToBoxes(ProjectClass project) { int id = 0; HashSet <string> layerNames = new HashSet <string>(); List <LwPolyline> polylines = new List <LwPolyline>(); List <Line> lines = new List <Line>(); lines.AddRange(dxf.Lines); lines.AddRange(getAllBlockLines(dxf.Blocks)); foreach (var line in lines) { if (!layerNames.Contains(line.Layer.Name)) { layerNames.Add(line.Layer.Name); } ColoBox box = new ColoBox(line.Layer.Name, id++); boxes.Add(box); box.AddPoint(line.StartPoint.X, line.StartPoint.Y); box.AddPoint(line.EndPoint.X, line.EndPoint.Y); } polylines.AddRange(dxf.LwPolylines); polylines.AddRange(getAllPolylines(dxf.Inserts)); polylines.AddRange(getAllPolylinesFromBlocks(dxf.Blocks)); //every Polyline from DXF turns into a box (ColoBox) foreach (LwPolyline pl in polylines) { if (!layerNames.Contains(pl.Layer.Name)) { layerNames.Add(pl.Layer.Name); } if (pl.Layer.Name == "Layer 4") { } ColoBox box = new ColoBox(pl.Layer.Name, id++); boxes.Add(box); foreach (var v in pl.Vertexes) { box.AddPoint(v.Location.X, v.Location.Y); } } foreach (Spline sp in dxf.Splines) { if (!layerNames.Contains(sp.Layer.Name)) { layerNames.Add(sp.Layer.Name); } if (sp.Layer.Name == "Layer 4") { } ColoBox box = new ColoBox(sp.Layer.Name, id++); boxes.Add(box); foreach (var v in sp.ControlPoints) { box.AddPoint(v.Location.X, v.Location.Y); } } Boxes2relo = new List <ColoBox>(); staticObjects = new List <ColoBox>(); manager = new LayoutManager(this.initParams); loadGraphicsObject(staticObjects, manager, Boxes2relo); if (initParams.Stage == 1 && project != null) { ColoBox bounding = new ColoBox(); double minX = project.BoundingBox[0].X; double minY = project.BoundingBox[0].Y; double maxX = project.BoundingBox[1].X; double maxY = project.BoundingBox [1].Y; bounding.AddPoint(minX, minY); bounding.AddPoint(minX, maxY); bounding.AddPoint(maxX, maxY); bounding.AddPoint(maxX, minY); staticObjects.Add(bounding); } }