} // method /// <summary> /// Given a transformation matrix and the lat, lon, convert to Simio units. /// Assumptions. The Latitude is Y, and the Longitude is X, /// and the latitude is negated to fit with the Simio scheme. /// which becomes Lat=-Z, and Long X, in simio /// </summary> /// <param name="mat">Transformation matrix</param> /// <param name="lat"></param> /// <param name="lon"></param> /// <returns></returns> public static FacilityLocation LatLonToFacilityLocation(Matrix mat, double lat, double lon) { PointF[] points = new PointF[1] { new PointF((float)lon, (float)lat) }; mat.TransformPoints(points); PointF pt = points[0]; FacilityLocation loc = new FacilityLocation(pt.X, 0, -pt.Y); return(loc); }
private void crear() { IIntelligentObjects _objetos = _modelo.Facility.IntelligentObjects; int x = 0; int z = 0; int y = 1; IIntelligentObject combiner = _objetos.CreateObject("Combiner", new FacilityLocation(x, z, y)); combiner.ObjectName = "fabi"; INodeObject input = seekForName("MemberInput@" + combiner.ObjectName) as INodeObject; INodeObject output = seekForName("ParentInput@" + combiner.ObjectName) as INodeObject; List <FacilityLocation> listpoints = new List <FacilityLocation>(); FacilityLocation fl = new FacilityLocation(35, 36, 86); listpoints.Add(fl); IIntelligentObject connect1 = _objetos.CreateLink("Connector", input, output, listpoints); }
public FacilityLocationDTO(FacilityLocation source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } FacilityLocationId = source.FacilityLocationId; FacilityID = source.FacilityID; Address1 = source.Address1; Address2 = source.Address2; City = source.City; State = source.State; PostalCode = source.PostalCode; Phone = source.Phone; SecurityLevel = source.SecurityLevel; }
public static bool Clust() { BoundingBox Bound; List <Facility> Facility; // read data Vertex[] Points = LoadLine.Load(Setup.InputPath, out Bound); // setup dimension of points Setup.Dim = Points[0].Dimension; FacilityLocation fac = new FacilityLocation(); // setup clustering properties Vertex.CoordWeights = Setup.ValueDim; Vertex.CoordBorder = Setup.Border; Vertex.BorderMin = Setup.BorderMin; Vertex.BorderPercent = Setup.BorderPercent; // setup metric VertexExtension.SetLineMetric(); // start clustering fac.ComputeClustering(Points, Bound); // get index of facilities int[] indexCentre = fac.GetAllFacilities(); // create array for facilities Vertex[] centre = new Vertex[indexCentre.Length]; // insert facilities vertices into array for (int f = 0; f < centre.Length; f++) { centre[f] = Points[indexCentre[f]]; } Facility = fac.Facilities; Analysis.SaveSite(ref Points, ref Facility, Setup.OutPath, Setup.SizeFilter); return(false); }
/// <summary> /// This will create a Facility 'route' from the given SimioMapRoute object /// by building two nodes (start and stop) and a path between them, /// and also attaching the start to a Source and the stop to a Sink. /// </summary> /// <param name="context"></param> /// <param name="mapRoute"></param> public static bool BuildSimioFacilityObjectsFromMapRoute(IDesignContext context, SimioMapRoute mapRoute, SimioMapTransform transform, out string explanation) { explanation = ""; string marker = "Begin"; try { if (mapRoute == null || mapRoute.SegmentList.Count == 0) { explanation = $"MapRoute is null or without Segments"; return(false); } var intelligentObjects = context.ActiveModel.Facility.IntelligentObjects; // Get scale to convert from latlon to simio meters float xScale = transform.SimioScaling.X; // 20f / mapData.LonLatBoundingBox.Width; float yScale = transform.SimioScaling.Y; // 20f / mapData.BoundingBox.Height; // Find the center in latlon coordinates, because we are going to transform before we scale float xCenter = -(float)transform.BoxCenter.X; float yCenter = -(float)transform.BoxCenter.Y; // Build a transformation matrix Matrix mat = new Matrix(); // Create identity matrix //mat.Rotate(-90); mat.Translate(xCenter, yCenter); // move to origin mat.Scale(xScale, yScale, MatrixOrder.Append); // scale to size MapSegment seg = mapRoute.SegmentList[0]; FacilityLocation startLoc = GisHelpers.LatLonToFacilityLocation(mat, seg.StartLocation.Lat, seg.StartLocation.Lon); seg = mapRoute.SegmentList[mapRoute.SegmentList.Count - 1]; FacilityLocation endLoc = GisHelpers.LatLonToFacilityLocation(mat, seg.EndLocation.Lat, seg.EndLocation.Lon); var source = intelligentObjects.CreateObject("Source", startLoc) as IFixedObject; source.ObjectName = ConvertToName(mapRoute.StartName); // e.g. "Seattle"; //var server = intelligentObjects.CreateObject("Server", new FacilityLocation(0, 0, 0)) as IFixedObject; var sink = intelligentObjects.CreateObject("Sink", endLoc) as IFixedObject; var obj = (IPropertyObject)sink; obj.ObjectName = ConvertToName(mapRoute.EndName); // e.g. "Key West"; var node1 = intelligentObjects.CreateObject("BasicNode", startLoc); node1.ObjectName = ConvertToName(mapRoute.StartName) + "1"; var node2 = intelligentObjects.CreateObject("BasicNode", endLoc); node2.ObjectName = ConvertToName(mapRoute.EndName) + "1"; // Nodes is an IEnumerable, so we will create a temporary List from it to quickly get to the first node in the set var sourceoutput = new List <INodeObject>(source.Nodes)[0]; var sinkinput = new List <INodeObject>(sink.Nodes)[0]; // This path goes directly from the output of source to the input of server var path1 = intelligentObjects.CreateLink("Path", sourceoutput, (INodeObject)node1, null); // This path goes from the output of server to the input of sink, with one vertex in between var path2 = intelligentObjects.CreateLink("Path", (INodeObject)node2, sinkinput, new List <FacilityLocation> { endLoc }); // Build a path from node1 to node2 List <FacilityLocation> pathList = new List <FacilityLocation>(); pathList.Add(node1.Location); int segmentCount = 0; foreach (MapSegment segment in mapRoute.SegmentList) { pathList.Add(GisHelpers.LatLonToFacilityLocation(mat, segment.StartLocation.Lat, segment.StartLocation.Lon)); segmentCount++; marker = $"Built Segment#={segmentCount} Segment={segment}"; } pathList.Add(node2.Location); var path3 = intelligentObjects.CreateLink("Path", (INodeObject)node1, (INodeObject)node2, pathList); return(true); } catch (Exception ex) { explanation = $"Cannot Build Nodes. Marker={marker} Err={ex}"; return(false); } }
/// <summary> /// Method called when the add-in is run. /// </summary> public void Execute(IDesignContext context) { //Open Status Window string marker = "Begin."; try { // Check to make sure a model has been opened in Simio if (context.ActiveModel == null) { MessageBox.Show("You must have an active model to run this add-in.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Open the file. Return immediately if the user cancels the file open dialog var getFile = new OpenFileDialog(); getFile.Filter = "Excel Files(*.xlsx)|*.xlsx"; if (getFile.ShowDialog() == DialogResult.Cancel) { MessageBox.Show("Canceled by user.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } StatusWindow = new StatusWindow($"Importing From Excel Spreadsheet {getFile.FileName}"); StatusWindow.Show(); Boolean importVertices = true; // Update Status Window StatusWindow.UpdateProgress(25, "Checking worksheets"); ExcelPackage package = new ExcelPackage(new System.IO.FileInfo(getFile.FileName)); ExcelWorkbook xlWorkbook = package.Workbook; // Create the node and link sheet lists List <ExcelWorksheet> objectsWorksheets = new List <ExcelWorksheet>(); List <ExcelWorksheet> linksWorksheets = new List <ExcelWorksheet>(); List <ExcelWorksheet> verticesWorksheets = new List <ExcelWorksheet>(); marker = "Categorizing Worksheets."; // Look through every sheet and categorize them according to objects, links, or vertices // We'll do objects first, then vertices, then links foreach (ExcelWorksheet ws in package.Workbook.Worksheets) { string wsName = ws.Name.ToLower(); if (wsName.Length >= 5) { // Add any sheet that name starts with 'objects' to the objects list if (wsName.ToLower().StartsWith("objects")) { objectsWorksheets.Add(ws); } // Add any sheet that name starts with 'links' to the link list else if (wsName.ToLower().StartsWith("links")) { linksWorksheets.Add(ws); } // Add any sheet that name starts with 'vertices' to the link list else if (wsName.ToLower().StartsWith("vertices")) { verticesWorksheets.Add(ws); } } } // foreach worksheet if (objectsWorksheets.Count + linksWorksheets.Count == 0) { logit("Workbook contains no valid object or link worksheets."); return; } // Update Status Window StatusWindow.UpdateProgress(50, "Building Objects"); // get a reference to intelligent objects... var intellObjects = context.ActiveModel.Facility.IntelligentObjects; // ... and a reference to Elements var elements = context.ActiveModel.Elements; // use bulk update to import quicker context.ActiveModel.BulkUpdate(model => { // Read and create the objects. int addedCount; int updatedCount; foreach (ExcelWorksheet ows in objectsWorksheets) { var dim = ows.Dimension; if (dim.Rows == 0) { continue; } marker = $"Reading {dim.Rows} rows from Object sheet {ows.Name}"; logit(marker); addedCount = 0; updatedCount = 0; for (int ri = 2; ri <= dim.Rows; ri++) { marker = $"Sheet={ows.Name} Row={ri}"; string className = ows.Cells[ri, 1].Value?.ToString(); string itemName = ows.Cells[ri, 2].Value?.ToString(); if (string.IsNullOrEmpty(className) || string.IsNullOrEmpty(itemName)) { logit($"{marker}: Empty ClassName or ItemName"); continue; } // Find the coordinates for the object double x = 0.0, y = 0.0, z = 0.0; bool updateCoordinates = true; if (!GetCellAsDouble(ows.Cells[ri, 3], ref x) || !GetCellAsDouble(ows.Cells[ri, 4], ref y) || !GetCellAsDouble(ows.Cells[ri, 5], ref z)) { updateCoordinates = false; } // Add the coordinates to the intelligent object FacilityLocation loc = new FacilityLocation(x, y, z); var intellObj = intellObjects[itemName]; if (intellObj == null) { intellObj = intellObjects.CreateObject(className, loc); if (intellObj == null) { logit($"{marker}: Cannot create object with className={className}"); continue; } intellObj.ObjectName = itemName; addedCount++; } else { // update coords of existing one. if (updateCoordinates) { intellObj.Location = loc; } updatedCount++; } // Set Size double length = intellObj.Size.Length; double width = intellObj.Size.Width; double height = intellObj.Size.Height; if (GetCellAsDouble(ows.Cells[ri, 6], ref length)) { if (length == 0) { length = intellObj.Size.Length; } } if (GetCellAsDouble(ows.Cells[ri, 7], ref width)) { if (width == 0) { width = intellObj.Size.Width; } } if (GetCellAsDouble(ows.Cells[ri, 8], ref height)) { if (height == 0) { height = intellObj.Size.Height; } } FacilitySize fs = new FacilitySize(length, width, height); intellObj.Size = fs; // update properties on object, which are columns 9 onward for (int ci = 9; ci <= dim.Columns; ci++) { // By convention, the first row on the sheet is the header row, which contains the Property name. string propertyName = ows.Cells[1, ci]?.Value as string; if (string.IsNullOrEmpty(propertyName)) { continue; } propertyName = propertyName.ToLower(); // Find a property with matching text (case insensitive) IProperty prop = intellObj.Properties.AsQueryable() .SingleOrDefault(rr => rr.Name.ToString().ToLower() == propertyName); if (prop == null) { continue; } string cellValue = ows.Cells[ri, ci].Value?.ToString(); if (cellValue != null) { if (!SetPropertyValue(prop, cellValue, out string explanation)) { logit(explanation); } } } // for each column property } // foreach row logit($"Added {addedCount} objects and updated {updatedCount} objects"); } // for each object worksheet var vertexList = new ArrayList(); // Update Status Window if (importVertices) { // Add additional vertices foreach (ExcelWorksheet vws in verticesWorksheets) { var dim = vws.Dimension; if (dim.Rows > 0) { logit($"Info: Reading {dim.Rows} rows from sheet {vws.Name}"); } addedCount = 0; updatedCount = 0; for (int ri = 2; ri <= dim.Rows; ri++) { marker = $"Sheet={vws.Name} Row={ri}"; var cell = vws.Cells[ri, 1]; string linkName = cell.Value as string; if (string.IsNullOrEmpty(linkName)) { logit($"{marker}: No LinkName"); goto DoneWithVertexRows; } // Find the coordinates for the vertex double x = double.MinValue, y = double.MinValue, z = double.MinValue; if (!GetCellAsDouble(vws.Cells[ri, 2], ref x) || !GetCellAsDouble(vws.Cells[ri, 3], ref y) || !GetCellAsDouble(vws.Cells[ri, 4], ref z)) { logit($"{marker}: Bad Vertex Coordinate"); goto DoneWithVertexRows; } vertexList.Add(new string[] { linkName, x.ToString(), y.ToString(), z.ToString() }); } // for each row of vertices DoneWithVertexRows:; } // for each vertex worksheet } // Check if we are importing vertices StatusWindow.UpdateProgress(75, "Building Links"); // Get Links Data // Read and create the links. foreach (ExcelWorksheet lws in linksWorksheets) { var dim = lws.Dimension; if (dim.Rows > 0) { marker = $"Info: Reading {dim.Rows} rows from sheet {lws.Name}"; logit(marker); } addedCount = 0; updatedCount = 0; for (int ri = 2; ri <= dim.Rows; ri++) { marker = $"Sheet={lws.Name} Row={ri}"; string className = lws.Cells[ri, 1]?.Value as string; if (string.IsNullOrEmpty(className)) { logit($"{marker}: Invalid ClassName={className}"); goto DoneWithLinkRow; } string linkName = lws.Cells[ri, 2]?.Value as string; if (string.IsNullOrEmpty(linkName)) { logit($"{marker}: Invalid LinkName={linkName}"); goto DoneWithLinkRow; } string fromNodeName = lws.Cells[ri, 3]?.Value as string; if (string.IsNullOrEmpty(fromNodeName)) { logit($"{marker}: Invalid FromNodeName={fromNodeName}"); goto DoneWithLinkRow; } string toNodeName = lws.Cells[ri, 4]?.Value as string; if (string.IsNullOrEmpty(toNodeName)) { logit($"{marker}: Invalid ToNodeName={toNodeName}"); goto DoneWithLinkRow; } var fromNode = intellObjects[fromNodeName] as INodeObject; if (fromNode == null) { logit($"{marker} Cannot find 'from' node name {fromNodeName}"); goto DoneWithWorksheets; } var toNode = intellObjects[toNodeName] as INodeObject; if (toNode == null) { logit($"{marker}: Cannot find 'to' node name {toNodeName}"); goto DoneWithWorksheets; } // if link exists, remove and re-add var link = intellObjects[linkName]; if (link != null) { intellObjects.Remove(link); updatedCount++; } else { addedCount++; } // Define List of Facility Locations List <FacilityLocation> locs = new List <FacilityLocation>(); foreach (string[] loc in vertexList) { if (loc[0] == linkName) { double xx = double.MinValue, yy = double.MinValue, zz = double.MinValue; xx = Convert.ToDouble(loc[1]); yy = Convert.ToDouble(loc[2]); zz = Convert.ToDouble(loc[3]); // If coordinates are good, add vertex to facility locations if (xx > double.MinValue & yy > double.MinValue & zz > double.MinValue) { // Add the coordinates to the intelligent object FacilityLocation loc2 = new FacilityLocation(xx, yy, zz); locs.Add(loc2); } } } // for each vertex // Add Link link = intellObjects.CreateLink(className, fromNode, toNode, locs); if (link == null) { logit($"{marker}: Cannot create Link"); goto DoneWithWorksheets; } link.ObjectName = linkName; // Add Link to Network string networkName = lws.Cells[ri, 5]?.Value as string; if (string.IsNullOrEmpty(networkName)) { logit($"{marker}: Null NetworkName"); goto DoneWithLinkRow; } var netElement = elements[networkName]; if (netElement == null) { netElement = elements.CreateElement("Network"); netElement.ObjectName = networkName; } var netElementObj = netElement as INetworkElementObject; if (netElement != null) { ILinkObject linkOb = (ILinkObject)link; linkOb.Networks.Add(netElementObj); } // get header row on sheet // update properties on object, which begin with column index 6 for (int ci = 6; ci <= dim.Columns; ci++) { string propertyName = lws.Cells[1, ci]?.Value as string; // Find a property with matching text (case insensitive) IProperty prop = link.Properties.AsQueryable() .SingleOrDefault(rr => rr.Name.ToString().ToLower() == propertyName.ToLower()); if (prop != null) { string cellValue = lws.Cells[ri, ci]?.Value as string; if (!SetPropertyValue(prop, cellValue, out string explanation)) { logit(explanation); goto DoneWithLinkRow; } } } // foreach column DoneWithLinkRow:; } // for each row marker = $"Info: Added {addedCount} links and deleted and re-added {updatedCount} existing links"; logit(marker); DoneWithWorksheets:; } }); // Update Status Window StatusWindow.UpdateProgress(100, "Complete"); } catch (Exception ex) { throw new ApplicationException($"Marker={marker} Err={ex.Message}"); } finally { StatusWindow.UpdateLogs(Loggerton.Instance); } }
public ProgramInstanceDTO(ProgramInstanceDTO program, SORProgramDTO SORProgram, ParentProgram parentProgram, FacilityLocation facilityLocation, Facility facility, int SORProgramSeatCount, int facilitatorID) { if (program.ProgramId == 0) { if (!parentProgram.IsPerpetual) { if (!string.IsNullOrEmpty(SORProgram.EffectiveDateFrom) && DateTime.TryParse(SORProgram.EffectiveDateFrom, out DateTime dateStarted)) { StartDate = dateStarted; } else { StartDate = null; } if (!string.IsNullOrEmpty(SORProgram.EffectiveDateTo) && DateTime.TryParse(SORProgram.EffectiveDateTo, out DateTime dateEnded)) { EndDate = dateEnded; } else { EndDate = null; } } else { StartDate = null; EndDate = null; } } else { ProgramId = program.ProgramId; DateCreated = program.DateCreated; CreatedByUserID = program.CreatedByUserID; StartDate = program.StartDate; EndDate = program.EndDate; } Title = parentProgram.Title; ClassroomId = 0; SessionStartTime = SORProgram.StartTime; if (!string.IsNullOrWhiteSpace(SORProgram.EndTime2)) { SessionEndTime = SORProgram.EndTime2; } else { SessionEndTime = SORProgram.EndTime; } if (SORProgram.Monday == "Y") { Monday = true; Title += " MON"; } else { Monday = false; } if (SORProgram.Tuesday == "Y") { Tuesday = true; Title += " TUE"; } else { Tuesday = false; } if (SORProgram.Wednesday == "Y") { Wednesday = true; Title += " WED"; } else { Wednesday = false; } if (SORProgram.Thursday == "Y") { Thursday = true; Title += " THU"; } else { Thursday = false; } if (SORProgram.Friday == "Y") { Friday = true; Title += " FRI"; } else { Friday = false; } if (SORProgram.Saturday == "Y") { Saturday = true; Title += " SAT"; } else { Saturday = false; } if (SORProgram.Sunday == "Y") { Sunday = true; Title += " SUN"; } else { Sunday = false; } if (Title.Length > 50) { Title = Title.Substring(0, 50); } Address = facilityLocation.Address1; City = facilityLocation.City; State = facilityLocation.State; Zip = facilityLocation.PostalCode; FacilitatorID = facilitatorID; ParentProgramID = parentProgram.ParentProgramId; Deleted = false; FacilityID = facility.FacilityID; IsSORProgram = true; NumberofSeats = SORProgramSeatCount; ReferToOrganizationID = program.ReferToOrganizationID; }