/// <summary> /// Construct Simio facility objects from all routes. /// </summary> /// <param name="context"></param> /// <param name="routes"></param> /// <param name="transform"></param> /// <param name="explanation"></param> /// <returns></returns> public static bool BuildSimioFacilityObjectsFromMapRoutes(IDesignContext context, SimioMapRoutes routes, SimioMapTransform transform, out string explanation) { explanation = ""; string marker = "Begin."; try { int routeCount = 0; foreach (SimioMapRoute route in routes.RouteList) { routeCount++; if (!BuildSimioFacilityObjectsFromMapRoute(context, route, transform, out explanation)) { marker = $"Route:{routeCount} Info={route} Err={explanation}"; throw new ApplicationException(marker); } } return(true); } catch (Exception ex) { explanation = $"BuildSimioFacilityObjects failure. Err={ex.Message}"; return(false); } }
/// <summary> /// Method called when the add-in is run. /// </summary> public void Execute(IDesignContext context) { // This example code places some new objects from the Standard Library into the active model of the project. if (context.ActiveModel != null) { // Example of how to place some new fixed objects into the active model. // This example code places three new fixed objects: a Source, a Server, and a Sink. IIntelligentObjects intelligentObjects = context.ActiveModel.Facility.IntelligentObjects; IFixedObject sourceObject = intelligentObjects.CreateObject("Source", new FacilityLocation(-10, 0, -10)) as IFixedObject; IFixedObject serverObject = intelligentObjects.CreateObject("Server", new FacilityLocation(0, 0, 0)) as IFixedObject; IFixedObject sinkObject = intelligentObjects.CreateObject("Sink", new FacilityLocation(10, 0, 10)) as IFixedObject; // Example of how to place some new link objects into the active model (to add network paths between nodes). // This example code places two new link objects: a Path connecting the Source 'output' node to the Server 'input' node, // and a Path connecting the Server 'output' node to the Sink 'input' node. INodeObject sourceOutputNode = sourceObject.Nodes[0]; INodeObject serverInputNode = serverObject.Nodes[0]; INodeObject serverOutputNode = serverObject.Nodes[1]; INodeObject sinkInputNode = sinkObject.Nodes[0]; ILinkObject pathObject1 = intelligentObjects.CreateLink("Path", sourceOutputNode, serverInputNode, null) as ILinkObject; ILinkObject pathObject2 = intelligentObjects.CreateLink("Path", serverOutputNode, sinkInputNode, null) as ILinkObject; // Example of how to edit the property of an object. // This example code edits the 'ProcessingTime' property of the added Server object. serverObject.Properties["ProcessingTime"].Value = "100"; } }
/// <summary> /// Method called when the add-in is run. /// </summary> public void Execute(IDesignContext context) { // This example code places some new objects from the Standard Library into the active model of the project. if (context.ActiveModel != null) { var table = context.ActiveModel.Tables["Resources"]; context.ActiveModel.BulkUpdate(model => { foreach (IRow row in table.Rows) { var io = context.ActiveModel.Facility.IntelligentObjects[row.Properties["ResourceName"].Value]; io = context.ActiveModel.Facility.IntelligentObjects.CreateObject(row.Properties["ResourceType"].Value, new FacilityLocation(0, 0, 0)); // System.Windows.Forms.MessageBox.Show(String.Format("The \"{0}\" object type does not exist in this model. This object type is referenced on {1} in the Resources table.", row.Properties["ResourceType"].Value, row.Properties["ResourceName"].Value), Name); //return; // newObject = true; io.ObjectName = row.Properties["ResourceName"].Value; } }); } }
public Project(IViewModelFactory factory, IDesignContext context, IEnumerable <Tool> tools) { Tools = tools; var selectedObjectObs = this.WhenAnyValue(x => x.SelectedDocument); selectedObjectObs.Subscribe(document => { if (document != null) { context.Nodes = document.Graphics; } context.Selection = new List <Graphic>(); }); var selectedObjects = this.WhenAnyObservable(x => x.SelectedDocument.Selection); selectedObjects.Subscribe(selection => context.Selection = selection); AddDocument = ReactiveCommand.Create(() => { var item = factory.CreateDocument(); item.Name = "New document"; Documents.Add(item); }); }
/// <summary> /// Method called when the add-in is run. /// </summary> public void Execute(IDesignContext context) { // This example code places some new objects from the Standard Library into the active model of the project. if (context.ActiveModel != null) { var table = context.ActiveModel.Tables["Resources"]; var table2 = context.ActiveModel.Tables["LinkTable"]; context.ActiveModel.BulkUpdate(model => { foreach (IRow row in table.Rows) { var io = context.ActiveModel.Facility.IntelligentObjects[row.Properties["ResourceName"].Value]; io = context.ActiveModel.Facility.IntelligentObjects.CreateObject(row.Properties["ResourceType"].Value, new FacilityLocation(Double.Parse(row.Properties["XLocation"].Value), 0, Double.Parse(row.Properties["ZLocation"].Value))); io.ObjectName = row.Properties["ResourceName"].Value; } foreach (IRow row in table2.Rows) { INodeObject j = context.ActiveModel.Facility.IntelligentObjects[row.Properties["Node1"].Value] as INodeObject; INodeObject j2 = context.ActiveModel.Facility.IntelligentObjects[row.Properties["Node2"].Value] as INodeObject; var j4 = context.ActiveModel.Facility.IntelligentObjects.CreateLink("Path", j, j2, null) as ILinkObject; } }); } }
public void Execute(IDesignContext context) { if (context.ActiveModel != null) { form = new FormB(); form.ShowDialog(); } }
private void LaunchForm(IDesignContext context, SimioMapRoute mapData) { try { } catch (Exception ex) { throw new ApplicationException($"Launch Error={ex}"); } }
public void Execute(IDesignContext context) { _context = context; if (form == null || form.IsDisposed) { form = new Form1(); form.button1.Click += sendrespose; form.Show(); } }
public void Execute(IDesignContext context) { // This example code places some new objects from the Standard Library into the active model of the project. if (context.ActiveModel != null) { form = new FormA(); form.button.Click += ClickButton; form.ShowDialog(); } }
protected Tool(IDesignContext context) { CreateCommand = ReactiveCommand.CreateFromTask(async() => { var creationResult = await Create(CreationArea); if (creationResult.IsSuccessful) { context.Nodes.Add(creationResult.Node); } }); }
/// <summary> /// Method called when the add-in is run. /// </summary> public void Execute(IDesignContext context) { try { // Check to make sure a model has been opened in StrinbSimio if (context.ActiveModel == null) { alert("You must have an active model to run this add-in."); return; } IModel am = context.ActiveModel; StringBuilder sb = new StringBuilder(); // Get the path to the project file string filepath = GetStringProperty(context.ActiveProject, "FileName"); foreach (IIntelligentObject io in context.ActiveModel.Facility.IntelligentObjects) { PointF pt = new PointF((float)io.Location.X, (float)io.Location.Z); sb.AppendLine($"Name={io.ObjectName} Type={io.TypeName} Location={pt}"); var link = io as ILinkObject; if (link == null) { } } string pathToObjects = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); pathToObjects = Path.Combine(pathToObjects, "SimioObjects.txt"); if (Directory.Exists(pathToObjects)) { File.WriteAllText(pathToObjects, sb.ToString()); } SimioMapRoute mapData = new SimioMapRoute("", ""); // Launch the form and give it access to the Simio Design Context FormGis FormViewer = new FormGis(); FormViewer.DesignContext = context; FormViewer.MapRoute = mapData; FormViewer.Show(); } catch (Exception ex) { if (ex.Message != "Canceled") { MessageBox.Show(ex.Message, "Error"); } } }
/// <summary> /// Method called when the add-in is run. /// </summary> public void Execute(IDesignContext context) { // This example code places some new objects from the Standard Library into the active model of the project. if (context.ActiveModel != null) { // Example of how to place some new fixed objects into the active model. // This example code places three new fixed objects: a Source, a Server, and a Sink. var intelligentObjects = context.ActiveModel.Facility.IntelligentObjects; var sourceObject = intelligentObjects.CreateObject("Source", new FacilityLocation(0, 0, 0)) as IFixedObject; context.ActiveModel.Elements.CreateElement("Arta"); } }
public MainViewModel(IFilePicker filePicker, IProjectMapper mapper, IProjectStore projectStore, ImportExtensionsViewModel importViewModel, IDesignContext designContext) { DesignContext = designContext; this.mapper = mapper; this.projectStore = projectStore; var saveExtensions = new[] { new KeyValuePair <string, IList <string> >(Constants.FileFormatName, new List <string> { Constants.FileFormatExtension }) }; Load = ReactiveCommand.CreateFromObservable(() => LoadProject(filePicker, new[] { Constants.FileFormatExtension })); New = ReactiveCommand.Create(CreateNewDocument); Save = ReactiveCommand.CreateFromObservable(() => SaveProject(filePicker, Project, saveExtensions)); LoadFromFile = ReactiveCommand.CreateFromTask <ZafiroFile, Domain.Models.Project>(zafiroFile => LoadProject(zafiroFile, projectStore)); var projects = Load .Merge(New) .Merge(LoadFromFile) .Merge(importViewModel.ImportedProjects) .Do(_ => IsImportVisible = false); project = projects .Select(mapper.Map) .Do(x => x.SelectedDocument = x.Documents.FirstOrDefault()) .ToProperty(this, model => model.Project); isBusy = Load.IsExecuting .Merge(Save.IsExecuting) .Merge(importViewModel.IsBusy) .Merge(LoadFromFile.IsExecuting) .ToProperty(this, x => x.IsBusy); New.Execute().Subscribe(); ShowImport = ReactiveCommand.Create(() => IsImportVisible = true); HideImport = ReactiveCommand.Create(() => IsImportVisible = false); align = this.WhenAnyObservable(x => x.Project.SelectedDocument.AlignChanged).ToProperty(this, x => x.Align); }
public void Execute(IDesignContext context) { if (context.ActiveModel != null)// if there are tables in the facility { IIntelligentObjects intelligentObjects = context.ActiveModel.Facility.IntelligentObjects; string filename = @"C:\Users\Simiotest\Resources.csv"; // Displays an OpenFileDialog so the user can select a Cursor. OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "CSV Files|*.csv"; openFileDialog1.Title = "Select a CSV File"; // Show the Dialog. // If the user clicked OK in the dialog and // a .CUR file was selected, open it. if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // Assign the cursor in the Stream to the Form's Cursor property. filename = openFileDialog1.FileName; } using (CsvFileReader reader = new CsvFileReader(filename)) { CsvRow row = new CsvRow(); while (true) { String columnNames = reader.ReadLine(); String[] colNameTypeStr = columnNames.Split(','); foreach (String properties in colNameTypeStr) { if (properties == "") { continue; } String[] colNameTypeArr = properties.Split(';'); Tuple <String, String, String> objectProperties = new Tuple <String, String, String>(colNameTypeArr[0], colNameTypeArr[1], colNameTypeArr[2]); var objectname = context.ActiveModel.Facility.IntelligentObjects[objectProperties.Item1]; objectname.Properties[objectProperties.Item2].Value = objectProperties.Item3; } } } } }
/// <summary> /// Method called when the add-in is run. /// </summary> public void Execute(IDesignContext context) { // This example code places some new objects from the Standard Library into the active model of the project. var TableNameUserSpecified = context.ActiveModel.Properties["TableName"].Value; var columnNameObject = context.ActiveModel.Properties["ObjectsRefColumnName"].Value; var columnObjectCreator = context.ActiveModel.Properties["ObjectsColumnName"].Value; var Xlocation = context.ActiveModel.Properties["XLocation"].Value; var ZLocation = context.ActiveModel.Properties["ZLocation"].Value; if (context.ActiveModel != null) { if (context.ActiveModel.Properties["TableName"].Value != "null") { IIntelligentObjects intelligentObjects = context.ActiveModel.Facility.IntelligentObjects; var table = context.ActiveModel.Tables[TableNameUserSpecified]; context.ActiveModel.BulkUpdate(model => { foreach (IRow row in table.Rows) { //var Xlocationdefn = context.ActiveModel.Facility.IntelligentObjects[row.Properties[Xlocation].Value]; //(Xlocationdefn as IUnitizedTableColumn).UnitType = SimioUnitType.Length; //var Zlocationdefn = context.ActiveModel.Facility.IntelligentObjects[row.Properties[ZLocation].Value]; //(Zlocationdefn as IUnitizedTableColumn).UnitType = SimioUnitType.Length; var io = context.ActiveModel.Facility.IntelligentObjects[row.Properties[columnNameObject].Value]; io = context.ActiveModel.Facility.IntelligentObjects.CreateObject(row.Properties[columnObjectCreator].Value, new FacilityLocation(Double.Parse(row.Properties[Xlocation].Value), 0, Double.Parse(row.Properties[ZLocation].Value))); io.ObjectName = row.Properties[columnNameObject].Value; } }); } #endregion } }
public TextTool(IDesignContext context) : base(context) { }
public EllipseTool(IDesignContext context) : base(context) { }
public void Execute(IDesignContext context) { if (context.ActiveModel != null)// if there are tables in the facility { string filename = @"C:\Users\Simiotest\Resources.csv"; // Displays an OpenFileDialog so the user can select a Cursor. OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "CSV Files|*.csv"; openFileDialog1.Title = "Select a CSV File"; // Show the Dialog. // If the user clicked OK in the dialog and // a .CUR file was selected, open it. if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // Assign the cursor in the Stream to the Form's Cursor property. filename = openFileDialog1.FileName; } else { } using (CsvFileReader reader = new CsvFileReader(filename)) { CsvRow row = new CsvRow(); List <string> propertiesList = new List <string>(); Dictionary <String, String> columnnames = new Dictionary <string, string>(); Dictionary <String, String> propertyname = new Dictionary <string, string>(); List <GridDataColumnInfo> colmninfo = new List <GridDataColumnInfo>(); List <String> columnData = new List <string>(); IGridDataRecord gd; ITableColumn columnns = null; ITable t = null; String[] colNames; var tableName = context.ActiveModel.PropertyDefinitions.AddStringProperty("TableName", "null"); tableName.CategoryName = "OUPrpperties"; var ObjectRefColName = context.ActiveModel.PropertyDefinitions.AddStringProperty("ObjectsRefColumnName", "null"); ObjectRefColName.CategoryName = "OUPrpperties"; var ObjectName = context.ActiveModel.PropertyDefinitions.AddStringProperty("ObjectsColumnName", "null"); ObjectName.CategoryName = "OUPrpperties"; var XLocation = context.ActiveModel.PropertyDefinitions.AddStringProperty("XLocation", "null"); ObjectName.CategoryName = "OUPrpperties"; var ZLocation = context.ActiveModel.PropertyDefinitions.AddStringProperty("ZLocation", "null"); ObjectName.CategoryName = "OUPrpperties"; if (context.ActiveModel.Properties["TableName"].Value == "null") { while (true) { String tableNames = reader.ReadLine(); String[] tableNamesArray = tableNames.Split(','); foreach (String tables in tableNamesArray) { if (tables == "") { continue; } tableList.Add((tables)); t = context.ActiveModel.Tables.Create(tables); } String columnNames = reader.ReadLine(); String[] colNameTypeStr = columnNames.Split(','); foreach (String properties in colNameTypeStr) { if (properties == "") { continue; } String[] colNameTypeArr = properties.Split(';'); columnnames.Add(colNameTypeArr[0], colNameTypeArr[1]); } foreach (var item in columnnames) { var columnName = item.Key; var propertyType = item.Value; if (propertyType == "AddActivityReferenceColumn") { columnns = t.Columns.AddActivityReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddBatchLogicReferenceColumn") { columnns = t.Columns.AddBatchLogicReferenceColumn(columnName); columnData.Add(columnName); } //else if (propertyType == "AddBatchLogicReferenceColumn") //{ // columnns = t.Columns.AddBooleanColumn(columnName); // columnData.Add(columnName); //} else if (propertyType == "AddChangeoverLogicReferenceColumn") { columnns = t.Columns.AddChangeoverLogicReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddChangeoverMatrixReferenceColumn") { columnns = t.Columns.AddChangeoverMatrixReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddColorColumn") { columnns = t.Columns.AddColorColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddContainerReferenceColumn") { columnns = t.Columns.AddContainerReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddCostCenterReferenceColumn") { columnns = t.Columns.AddCostCenterReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddDateTimeColum") { DateTime date1 = new DateTime(2008, 5, 1, 8, 30, 52); columnns = t.Columns.AddDateTimeColumn(columnName, (date1)); columnData.Add(columnName); } else if (propertyType == "AddDayPatternReferenceColumn") { columnns = t.Columns.AddDayPatternReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddEntityReferenceColumn") { columnns = t.Columns.AddEntityReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddEnumColumn") { columnns = t.Columns.AddEnumColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddEventReferenceColumn") { columnns = t.Columns.AddEventReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddExpressionColumn") { columnns = t.Columns.AddExpressionColumn(columnName, "0.0"); columnData.Add(columnName); } else if (propertyType == "AddFailureReferenceColumn") { columnns = t.Columns.AddFailureReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddForeignKeyColumn") { columnns = t.Columns.AddForeignKeyColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddIntegerColumn") { columnns = t.Columns.AddIntegerColumn(columnName, 0); columnData.Add(columnName); } else if (propertyType == "AddListReferenceColumn") { columnns = t.Columns.AddListReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddMaterialReferenceColumn") { columnns = t.Columns.AddMaterialReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddMonitorReferenceColumn") { columnns = t.Columns.AddMonitorReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddNetworkReferenceColumn") { columnns = t.Columns.AddNetworkReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddNodeListReferenceColumn") { columnns = t.Columns.AddNodeListReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddNodeReferenceColumn") { columnns = t.Columns.AddNodeReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddObjectListReferenceColumn") { columnns = t.Columns.AddObjectListReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddObjectReferenceColumn") { columnns = t.Columns.AddObjectReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddObjectTypeReferenceColumn") { columnns = t.Columns.AddObjectTypeReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddOperationReferenceColumn") { columnns = t.Columns.AddOperationReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddOutputStatisticReferenceColumn") { columnns = t.Columns.AddOutputStatisticReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddProcessReferenceColumn") { columnns = t.Columns.AddProcessReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddRateTableReferenceColumn") { columnns = t.Columns.AddRateTableReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddProcessReferenceColumn") { columnns = t.Columns.AddProcessReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddRealColumn") { columnns = t.Columns.AddRealColumn(columnName, 0); columnData.Add(columnName); } else if (propertyType == "AddRegulatorReferenceColumn") { columnns = t.Columns.AddRegulatorReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddRoutingGroupReferenceColumn") { columnns = t.Columns.AddRoutingGroupReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddScheduleReferenceColumn") { columnns = t.Columns.AddScheduleReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddSelectionRuleReferenceColumn") { columnns = t.Columns.AddSelectionRuleReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddSequenceDestinationColumn") { columnns = t.Columns.AddSequenceDestinationColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddSequenceNumberColumn") { columnns = t.Columns.AddSequenceNumberColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddStateReferenceColumn") { columnns = t.Columns.AddStateReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddStateStatisticReferenceColumn") { columnns = t.Columns.AddStateStatisticReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddStationReferenceColumn") { columnns = t.Columns.AddStationReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddSteeringBehaviorReferenceColumn") { columnns = t.Columns.AddSteeringBehaviorReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddStorageReferenceColumn") { columnns = t.Columns.AddStorageReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddStringColumn") { columnns = t.Columns.AddStringColumn(columnName, "null"); columnData.Add(columnName); } else if (propertyType == "AddTableReferenceColumn") { columnns = t.Columns.AddTableReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddTallyStatisticReferenceColumn") { columnns = t.Columns.AddTallyStatisticReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddTaskDependencyColumn") { columnns = t.Columns.AddTaskDependencyColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddTaskSequenceReferenceColumn") { columnns = t.Columns.AddTaskSequenceReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddTimerReferenceColumn") { columnns = t.Columns.AddTimerReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddTransporterListReferenceColumn") { columnns = t.Columns.AddTransporterListReferenceColumn(columnName); columnData.Add(columnName); } else if (propertyType == "AddTransporterReferenceColumn") { columnns = t.Columns.AddTransporterReferenceColumn(columnName); columnData.Add(columnName); } } columnnames.Clear(); } } } } }
public ImageTool(IFilePicker filePicker, IDesignContext context) : base(context) { this.filePicker = filePicker; }
public RectangleTool(IDesignContext context) : base(context) { }
/// <summary> /// Method called when the add-in is run. /// </summary> public void Execute(IDesignContext context) { var warnings = new List <String>(); // This example code places some new objects from the Standard Library into the active model of the project. if (context.ActiveModel != null) { IIntelligentObjects intelligentObjects = context.ActiveModel.Facility.IntelligentObjects; ITable entitydatatable = context.ActiveModel.Tables.Create("HospitalData"); var i = entitydatatable.Columns.AddEntityReferenceColumn("PatientTypes"); var mix = entitydatatable.Columns.AddRealColumn("Mix", 0.0); var admisiontime = entitydatatable.Columns.AddExpressionColumn("AdmissionTime", "0.0"); (admisiontime as IUnitizedTableColumn).UnitType = SimioUnitType.Time; var rnrounding = entitydatatable.Columns.AddExpressionColumn("RNRounding", "0.0"); var nurserounding = entitydatatable.Columns.AddExpressionColumn("ANRounding", "0.0"); var therapistrounding = entitydatatable.Columns.AddExpressionColumn("TherapistRounding", "0.0"); var bedtime = entitydatatable.Columns.AddExpressionColumn("BedStayTime", "0.0"); var RVisitTime = entitydatatable.Columns.AddExpressionColumn("RegNurseVisitTime", "0.0"); var TVisitTime = entitydatatable.Columns.AddExpressionColumn("TherapistVisitTime", "0.0"); var AVisitTime = entitydatatable.Columns.AddExpressionColumn("AssistantNurseNextVisit", "0.0"); //var resourceType = context.ActiveModel.NamedLists["ResourceType"]; //if (resourceType != null) //{ // warnings.Add(string.Format(FormatListMessage(resourceType.Name))); //} //else //{ // resourceType = context.ActiveModel.NamedLists.AddObjectList("ResourceType"); // var firstRow = resourceType.Rows.Create(); // firstRow.Properties[0].Value = "Source"; // var secondRow = resourceType.Rows.Create(); // secondRow.Properties[0].Value = "Server"; // var thirdRow = resourceType.Rows.Create(); // thirdRow.Properties[0].Value = "Patient"; // var fourthRow = resourceType.Rows.Create(); // fourthRow.Properties[0].Value = "RegNurse"; // var fifthRow = resourceType.Rows.Create(); // fifthRow.Properties[0].Value = "Therapist"; // var sixthrow = resourceType.Rows.Create(); // sixthrow.Properties[0].Value = "Ass.Nurse"; // var seventhRow = resourceType.Rows.Create(); // seventhRow.Properties[0].Value = "Sink"; // var eigthRow = resourceType.Rows.Create(); // eigthRow.Properties[0].Value = "Bed"; // var ninthRow = resourceType.Rows.Create(); // ninthRow.Properties[0].Value = "Worker"; //} //Adding Resource Table ITable resourceTable = context.ActiveModel.Tables["Resources"]; if (resourceTable != null) { warnings.Add(string.Format(FormatListMessage(resourceTable.Name))); } else { resourceTable = context.ActiveModel.Tables.Create("Resources"); var j = resourceTable.Columns.AddObjectReferenceColumn("ResourceName"); j.FilterToResources = false; j.IsKey = true; // j.DefaultValueInstantiation = DefaultValueInstantiation.AutoCreateInstance; j.AutoCreatedOffsetX = "XLocation"; j.AutoCreatedOffsetY = "0.0"; j.AutoCreatedOffsetZ = "ZLocation"; var resourceTypes = resourceTable.Columns.AddObjectTypeReferenceColumn("ResourceType"); // resourceTypes. = ("ResourceType"); resourceTypes.DefaultString = ("Bed"); var xl = resourceTable.Columns.AddRealColumn("XLocation", 0.0); (xl as IUnitizedTableColumn).UnitType = SimioUnitType.Length; var zl = resourceTable.Columns.AddRealColumn("ZLocation", 0.0); (zl as IUnitizedTableColumn).UnitType = SimioUnitType.Length; } ITable linkTable = context.ActiveModel.Tables["LinkTable"]; if (linkTable != null) { warnings.Add(string.Format(FormatListMessage(resourceTable.Name))); } else { linkTable = context.ActiveModel.Tables.Create("LinkTable"); var nodeLists1 = linkTable.Columns.AddNodeReferenceColumn("Node1"); var nodeLists2 = linkTable.Columns.AddNodeReferenceColumn("Node2"); } } #endregion }
public LineTool(IDesignContext context) : base(context) { }
/// <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) { var warnings = new List <String>(); // This example code places some new objects from the Standard Library into the active model of the project. if (context.ActiveModel != null) { IIntelligentObjects intelligentObjects = context.ActiveModel.Facility.IntelligentObjects; IFixedObject bed = intelligentObjects.CreateObject("Bed", new FacilityLocation(0, 0, 0)) as IFixedObject; IFixedObject sourceObject = intelligentObjects.CreateObject("Source", new FacilityLocation(-10, 0, -10)) as IFixedObject; IFixedObject serverObject = intelligentObjects.CreateObject("Server", new FacilityLocation(0, 0, 0)) as IFixedObject; IFixedObject sinkObject = intelligentObjects.CreateObject("Sink", new FacilityLocation(10, 0, 10)) as IFixedObject; IEntityInstanceReferencePropertyDefinition modelentitiy = intelligentObjects.CreateObject("Patient", new FacilityLocation(-20, 0, -10)) as IEntityInstanceReferencePropertyDefinition; ITransporterInstanceReferencePropertyDefinition regnurse = intelligentObjects.CreateObject("Worker", new FacilityLocation(-30, 0, -30)) as ITransporterInstanceReferencePropertyDefinition; //var RNurseName = context.ActiveModel.Facility.IntelligentObjects["Worker1"]; //RNurseName.Properties["Name"].Value = "RegularNurse"; //var modelentitiy = context.ActiveModel.Facility.IntelligentObjects["Patient"]; // Example of how to place some new link objects into the active model (to add network paths between nodes). // This example code places two new link objects: a Path connecting the Source 'output' node to the Server 'input' node, // and a Path connecting the Server 'output' node to the Sink 'input' node. INodeObject sourceOutputNode = sourceObject.Nodes[0]; INodeObject serverInputNode = serverObject.Nodes[0]; INodeObject serverOutputNode = serverObject.Nodes[1]; INodeObject sinkInputNode = sinkObject.Nodes[0]; INodeObject bedinputnode = bed.Nodes[0]; INodeObject bedoutputnode = bed.Nodes[1]; ILinkObject pathObject1 = intelligentObjects.CreateLink("Path", sourceOutputNode, serverInputNode, null) as ILinkObject; ILinkObject pathObject2 = intelligentObjects.CreateLink("Path", serverOutputNode, bedinputnode, null) as ILinkObject; ILinkObject pathObject3 = intelligentObjects.CreateLink("Path", bedoutputnode, sinkInputNode, null) as ILinkObject; // Example of how to edit the property of an object. // This example code edits the 'ProcessingTime' property of the added Server object. serverObject.Properties["ProcessingTime"].Value = "0"; sourceObject.Properties["EntityType"].Value = "Patient1"; var defaultEntity = context.ActiveModel.Facility.IntelligentObjects["Patient1"]; defaultEntity.Properties["RegNurseCheckTime"].Value = "HospitalData.RNRounding"; defaultEntity.Properties["TherapistCheckTime"].Value = "HospitalData.TherapistRounding"; defaultEntity.Properties["AssistantNurseCheckTime"].Value = "HospitalData.ANRounding"; defaultEntity.Properties["BedStayTime"].Value = "HospitalData.BedStayTime"; defaultEntity.Properties["TherapistVisitTime"].Value = "HospitalData.TherapistVisitTime"; defaultEntity.Properties["RegNurseVisitTime"].Value = "HospitalData.RegNurseVisitTime"; defaultEntity.Properties["AssistantNurseNextVisit"].Value = "HospitalData.AssistantNurseNextVisit"; ITable entitydatatable = context.ActiveModel.Tables.Create("HospitalData"); var i = entitydatatable.Columns.AddEntityReferenceColumn("PatientTypes"); var mix = entitydatatable.Columns.AddRealColumn("Mix", 0.0); var admisiontime = entitydatatable.Columns.AddExpressionColumn("AdmissionTime", "0.0"); (admisiontime as IUnitizedTableColumn).UnitType = SimioUnitType.Time; var rnrounding = entitydatatable.Columns.AddExpressionColumn("RNRounding", "0.0"); var nurserounding = entitydatatable.Columns.AddExpressionColumn("ANRounding", "0.0"); var therapistrounding = entitydatatable.Columns.AddExpressionColumn("TherapistRounding", "0.0"); var bedtime = entitydatatable.Columns.AddExpressionColumn("BedStayTime", "0.0"); var RVisitTime = entitydatatable.Columns.AddExpressionColumn("RegNurseVisitTime", "0.0"); var TVisitTime = entitydatatable.Columns.AddExpressionColumn("TherapistVisitTime", "0.0"); var AVisitTime = entitydatatable.Columns.AddExpressionColumn("AssistantNurseNextVisit", "0.0"); //Add Resource Type List var resourceType = context.ActiveModel.NamedLists["ResourceType"]; if (resourceType != null) { warnings.Add(string.Format(FormatListMessage(resourceType.Name))); } else { resourceType = context.ActiveModel.NamedLists.AddObjectList("ResourceType"); var firstRow = resourceType.Rows.Create(); firstRow.Properties[0].Value = "Source"; var secondRow = resourceType.Rows.Create(); secondRow.Properties[0].Value = "Server"; var thirdRow = resourceType.Rows.Create(); thirdRow.Properties[0].Value = "Patient"; var fourthRow = resourceType.Rows.Create(); fourthRow.Properties[0].Value = "RegNurse"; var fifthRow = resourceType.Rows.Create(); fifthRow.Properties[0].Value = "Therapist"; var sixthrow = resourceType.Rows.Create(); sixthrow.Properties[0].Value = "Ass.Nurse"; var seventhRow = resourceType.Rows.Create(); seventhRow.Properties[0].Value = "Sink"; var eigthRow = resourceType.Rows.Create(); eigthRow.Properties[0].Value = "Bed"; var ninthRow = resourceType.Rows.Create(); ninthRow.Properties[0].Value = "Worker"; } //Adding Resource Table ITable resourceTable = context.ActiveModel.Tables["Resources"]; if (resourceTable != null) { warnings.Add(string.Format(FormatListMessage(resourceTable.Name))); } else { resourceTable = context.ActiveModel.Tables.Create("Resources"); var j = resourceTable.Columns.AddObjectReferenceColumn("ResourceName"); j.FilterToResources = false; j.IsKey = true; var resourceTypes = resourceTable.Columns.AddListReferenceColumn("ResourceType"); resourceTypes.ListName = ("ResourceType"); resourceTypes.DefaultString = ("Bed"); } ITable link = context.ActiveModel.Tables["LinkBetweenResources"]; if (link != null) { warnings.Add(string.Format(FormatLinkMessage(link.Name))); } else { } //var modelentity1 = context.ActiveModel.Facility.IntelligentObjects["Patient"]; //modelentity1.Properties["BedStayTime"].Value = "5"; } #endregion }
public void Execute(IDesignContext context) { if (context.ActiveModel != null)// if there are tables in the facility { IIntelligentObjects intelligentObjects = context.ActiveModel.Facility.IntelligentObjects; string filename = @"C:\Users\Simiotest\Resources.csv"; // Displays an OpenFileDialog so the user can select a Cursor. OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "CSV Files|*.csv"; openFileDialog1.Title = "Select a CSV File"; // Show the Dialog. // If the user clicked OK in the dialog and // a .CUR file was selected, open it. if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // Assign the cursor in the Stream to the Form's Cursor property. filename = openFileDialog1.FileName; } using (CsvFileReader reader = new CsvFileReader(filename)) { CsvRow row = new CsvRow(); List <string> propertiesList = new List <string>(); INamedList newlist = null; Dictionary <String, String> listnamedic = new Dictionary <string, string>(); List <String> propertydata = new List <string>(); while (true) { String listname = reader.ReadLine(); String[] listnameTypeStr = listname.Split(','); foreach (String properties in listnameTypeStr) { if (properties == "") { continue; } String[] listdictionaryType = properties.Split(';'); listnamedic.Add(listdictionaryType[0], listdictionaryType[1]); } foreach (var item in listnamedic) { var listNAme = item.Key; var propertyType = item.Value; if (propertyType == "AddNodeList") { newlist = context.ActiveModel.NamedLists.AddNodeList(listNAme); // propertydata.Add(listNAme); } else if (propertyType == "AddObjectList") { newlist = context.ActiveModel.NamedLists.AddObjectList(listNAme); propertydata.Add(listNAme); } else if (propertyType == "AddStringList") { newlist = context.ActiveModel.NamedLists.AddStringList(listNAme); } else if (propertyType == "AddTransporterList") { newlist = context.ActiveModel.NamedLists.AddTransporterList(listNAme); } String data = reader.ReadLine(); if (data == null) { continue; } String[] Rowvalues = data.Split(','); foreach (String properties in Rowvalues) { if (properties == "") { continue; } var rows = newlist.Rows.Create(); propertiesList.Add(properties); rows.Properties[0].Value = properties; } } listnamedic.Clear(); } } } }
/// <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); } }