//===================================================================== // IsValid(IInputExchangeItem inputExchangeItem, IOutputExchangeItem outputExchangeItem, // IDataOperation[] SelectedDataOperations): bool //===================================================================== /// <summary> /// For a given combination of inputExchangeItem, outputExchangeItem and list of dataOperation /// it is decided if the dataOperations constitutes a valid set seen from a spatial settings /// point of view. /// </summary> /// <param name="inputExchangeItem">The input exchange item</param> /// <param name="outputExchangeItem">The output exchange item</param> /// <param name="SelectedDataOperations">List of selected dataOperations</param> public override bool IsValid(IInputExchangeItem inputExchangeItem, IOutputExchangeItem outputExchangeItem, IDataOperation[] SelectedDataOperations) { bool returnValue = true; bool methodAvaileble = false; ElementMapper elementMapper = new ElementMapper(); foreach (string idString in elementMapper.GetIDsForAvailableDataOperations(outputExchangeItem.ElementSet.ElementType, inputExchangeItem.ElementSet.ElementType)) { if (ID == idString) { methodAvaileble = true; } } if (!methodAvaileble) { return(false); } // --- check that only one SpatialMapping dataoperation is selected. --- int numberOfSelectedSpatialMappingDataOperations = 0; foreach (IDataOperation dataOperation in SelectedDataOperations) { for (int i = 0; i < dataOperation.ArgumentCount; i++) { if (dataOperation.GetArgument(i).Id == "Type") { if (dataOperation.GetArgument(i).Value == "SpatialMapping") { numberOfSelectedSpatialMappingDataOperations++; //this counting is done to check if the same dataOpertion is added twise if (dataOperation.ID != ID) //the selected dataoperation must be this dataOperation { returnValue = false; //the selected dataoperation must be this } } } } } if (numberOfSelectedSpatialMappingDataOperations > 1) { returnValue = false; } return(returnValue); }
/// <summary> /// For a given combination of inputExchangeItem, outputExchangeItem and list of dataOperation /// it is decided if the dataOperations constitutes a valid set seen from a spatial settings /// point of view. /// </summary> /// <param name="inputExchangeItem">The input exchange item</param> /// <param name="outputExchangeItem">The output exchange item</param> /// <param name="SelectedDataOperations">List of selected dataOperations</param> public override bool IsValid(IInputExchangeItem inputExchangeItem, IOutputExchangeItem outputExchangeItem, IDataOperation[] SelectedDataOperations) { bool returnValue = true; bool methodAvaileble = false; ElementMapper elementMapper = new ElementMapper(); foreach (string idString in elementMapper.GetIDsForAvailableDataOperations(outputExchangeItem.ElementSet.ElementType,inputExchangeItem.ElementSet.ElementType)) { if (ID == idString) { methodAvaileble = true; } } if (!methodAvaileble) { return false; } // --- check that only one SpatialMapping dataoperation is selected. --- int numberOfSelectedSpatialMappingDataOperations = 0; foreach (IDataOperation dataOperation in SelectedDataOperations) { for (int i = 0; i < dataOperation.ArgumentCount; i++) { if (dataOperation.GetArgument(i).Key == "Type") { if (dataOperation.GetArgument(i).Value == "SpatialMapping") { numberOfSelectedSpatialMappingDataOperations++; //this counting is done to check if the same dataOpertion is added twise if (dataOperation.ID != ID) //the selected dataoperation must be this dataOperation { returnValue = false; //the selected dataoperation must be this } } } } } if (numberOfSelectedSpatialMappingDataOperations > 1) { returnValue = false; } return returnValue; }
public void GetOutputExchangeItem() { LinkableTimeSeriesGroup linkableTimeSeriesGroup = new LinkableTimeSeriesGroup(); linkableTimeSeriesGroup.Initialize(arguments); IOutputExchangeItem output01 = linkableTimeSeriesGroup.GetOutputExchangeItem(0); Assert.AreEqual(0, output01.DataOperationCount); Assert.AreEqual(ElementType.IDBased, output01.ElementSet.ElementType); Assert.AreEqual(1, output01.ElementSet.ElementCount); Assert.AreEqual("IDBased", output01.ElementSet.Description); Assert.AreEqual("Flow", output01.Quantity.ID); Assert.AreEqual("Measured Flow", output01.Quantity.Description); Assert.AreEqual("Liters pr. sec", output01.Quantity.Unit.ID); Assert.AreEqual(0.001, output01.Quantity.Unit.ConversionFactorToSI); Assert.AreEqual(0.0, output01.Quantity.Unit.OffSetToSI); Assert.AreEqual("Liters pr second", output01.Quantity.Unit.Description); Assert.AreEqual(3, output01.Quantity.Dimension.GetPower(DimensionBase.Length)); Assert.AreEqual(-1, output01.Quantity.Dimension.GetPower(DimensionBase.Time)); Assert.AreEqual("Flow", ((TsQuantity)output01.Quantity).BaseTimeSeries.Name); }
/// <summary> /// The linear dataoperation is valid for any input and output exchange items and can be combined with any other /// dataopertion, consequently this method always return true. /// See also documentation for : OpenMI.Standard.IDataOperation for details /// </summary> /// <param name="inputExchangeItem">inputExchangeItem</param> /// <param name="outputExchangeItem">outputExchangeItem</param> /// <param name="SelectedDataOperations">SelectedDataOperations</param> /// <returns></returns> public bool IsValid(IInputExchangeItem inputExchangeItem, IOutputExchangeItem outputExchangeItem, IDataOperation[] SelectedDataOperations) { return(true); }
/// <summary> /// Loads composition from XML document. /// </summary> /// <param name="omiRelativeDirectory">Directory the OMI files are relative to.</param> /// <param name="xmlDocument">XML document</param> private void LoadFromXmlDocument(string omiRelativeDirectory, XmlDocument xmlDocument) { // once you choose to load new file, all previously opened models are closed Release(); CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = new CultureInfo(""); XmlElement xmlRoot = (XmlElement)xmlDocument.ChildNodes[0]; XmlElement xmlModels = (XmlElement)xmlRoot.ChildNodes[0]; XmlElement xmlLinks = (XmlElement)xmlRoot.ChildNodes[1]; // run properties aren't mandatory XmlElement xmlRunProperties = null; if (xmlRoot.ChildNodes.Count > 2) { xmlRunProperties = (XmlElement)xmlRoot.ChildNodes[2]; } // check if (xmlRoot.GetAttribute("version") != "1.0") { throw (new FormatException("Version of file not supported. Currently supported only version '1.0'")); } if (xmlModels.Name != "models" || xmlLinks.Name != "links") { throw (new FormatException("Unknown file format ('models' or 'links' tag not present where expected).")); } if (xmlRunProperties != null) { if (xmlRunProperties.Name != "runproperties") { throw (new FormatException("Unknown file format ('runproperties' tag not present where expected).")); } } // read UIModels foreach (XmlElement xmlUiModel in xmlModels.ChildNodes) { try { UIModel uiModel = AddModel(omiRelativeDirectory, xmlUiModel.GetAttribute("omi")); uiModel.Rect.X = Int32.Parse(xmlUiModel.GetAttribute("rect_x")); uiModel.Rect.Y = Int32.Parse(xmlUiModel.GetAttribute("rect_y")); uiModel.Rect.Width = Int32.Parse(xmlUiModel.GetAttribute("rect_width")); uiModel.Rect.Height = Int32.Parse(xmlUiModel.GetAttribute("rect_height")); } catch (Exception e) { throw (new Exception( "Model cannot be added to composition due to exception.\n" + "OMI filename: " + xmlUiModel.GetAttribute("omi") + "\n" + "Exception: " + e.ToString())); } } // read UILinks foreach (XmlElement xmlUiLink in xmlLinks.ChildNodes) { // find models corresponding to this UIConnection UIModel providingModel = null, acceptingModel = null; foreach (UIModel uiModel in _models) { if (uiModel.ModelID == xmlUiLink.GetAttribute("model_providing")) { providingModel = uiModel; break; } } foreach (UIModel uiModel in _models) { if (uiModel.ModelID == xmlUiLink.GetAttribute("model_accepting")) { acceptingModel = uiModel; break; } } if (providingModel == null || acceptingModel == null) { throw (new Exception( "One model (or both) corresponding to this link cannot be found...\n" + "Providing model: " + xmlUiLink.GetAttribute("model_providing") + "\n" + "Accepting model: " + xmlUiLink.GetAttribute("model_accepting"))); } // construct UIConnection UIConnection uiLink = new UIConnection(providingModel, acceptingModel); // read OpenMI Links foreach (XmlElement xmlLink in xmlUiLink.ChildNodes) { // find corresponding exchange items IOutputExchangeItem outputExchangeItem = null; IInputExchangeItem inputExchangeItem = null; int count = providingModel.LinkableComponent.OutputExchangeItemCount; string sourceElementSetID = xmlLink.GetAttribute("source_elementset"); string sourceQuantityID = xmlLink.GetAttribute("source_quantity"); for (int i = 0; i < count; i++) { if (sourceElementSetID == providingModel.LinkableComponent.GetOutputExchangeItem(i).ElementSet.ID && sourceQuantityID == providingModel.LinkableComponent.GetOutputExchangeItem(i).Quantity.ID) { outputExchangeItem = providingModel.LinkableComponent.GetOutputExchangeItem(i); break; } } for (int i = 0; i < acceptingModel.LinkableComponent.InputExchangeItemCount; i++) { if (xmlLink.GetAttribute("target_elementset") == acceptingModel.LinkableComponent.GetInputExchangeItem(i).ElementSet.ID && xmlLink.GetAttribute("target_quantity") == acceptingModel.LinkableComponent.GetInputExchangeItem(i).Quantity.ID) { inputExchangeItem = acceptingModel.LinkableComponent.GetInputExchangeItem(i); break; } } if (outputExchangeItem == null || inputExchangeItem == null) { throw (new Exception( "Cannot find exchange item\n" + "Providing model: " + providingModel.ModelID + "\n" + "Accepting model: " + acceptingModel.ModelID + "\n" + "Source ElementSet: " + xmlLink.GetAttribute("source_elementset") + "\n" + "Source Quantity: " + xmlLink.GetAttribute("source_quantity") + "\n" + "Target ElementSet: " + xmlLink.GetAttribute("target_elementset") + "\n" + "Target Quantity: " + xmlLink.GetAttribute("target_quantity"))); } // read selected DataOperation's IDs, find their equivalents // in outputExchangeItem, and add these to link ArrayList dataOperationsToAdd = new ArrayList(); foreach (XmlElement xmlDataOperation in xmlLink.ChildNodes) { for (int i = 0; i < outputExchangeItem.DataOperationCount; i++) { IDataOperation dataOperation = outputExchangeItem.GetDataOperation(i); if (dataOperation.ID == xmlDataOperation.GetAttribute("id")) { // set data operation's arguments if any foreach (XmlElement xmlArgument in xmlDataOperation.ChildNodes) { string argumentKey = xmlArgument.GetAttribute("key"); for (int j = 0; j < dataOperation.ArgumentCount; j++) { IArgument argument = dataOperation.GetArgument(j); if (argument.Key == argumentKey && !argument.ReadOnly) { argument.Value = xmlArgument.GetAttribute("value"); } } } dataOperationsToAdd.Add(dataOperation); break; } } } // now construct the Link... Link link = new Link( providingModel.LinkableComponent, outputExchangeItem.ElementSet, outputExchangeItem.Quantity, acceptingModel.LinkableComponent, inputExchangeItem.ElementSet, inputExchangeItem.Quantity, "No description available.", xmlLink.GetAttribute("id"), dataOperationsToAdd); // ...add the link to the list uiLink.Links.Add(link); // and add it to both LinkableComponents uiLink.AcceptingModel.LinkableComponent.AddLink(link); uiLink.ProvidingModel.LinkableComponent.AddLink(link); } // add new UIConnection to list of connections _connections.Add(uiLink); } // read run properties (if present) if (xmlRunProperties != null) { string str = xmlRunProperties.GetAttribute("listenedeventtypes"); if (str.Length != (int)EventType.NUM_OF_EVENT_TYPES) { throw (new FormatException("Invalid number of event types in 'runproperties' tag, expected " + EventType.NUM_OF_EVENT_TYPES + ", but only " + str.Length + " found.")); } for (int i = 0; i < (int)EventType.NUM_OF_EVENT_TYPES; i++) { switch (str[i]) { case '1': _listenedEventTypes[i] = true; break; case '0': _listenedEventTypes[i] = false; break; default: throw (new FormatException("Unknown format of 'listenedeventtypes' attribute in 'runproperties' tag.")); } } _triggerInvokeTime = DateTime.Parse(xmlRunProperties.GetAttribute("triggerinvoke")); _logFileName = xmlRunProperties.GetAttribute("logfilename"); if (_logFileName != null) { _logFileName = _logFileName.Trim(); if (_logFileName == "") { _logFileName = null; // if not set, logfile isn't used } } str = xmlRunProperties.GetAttribute("showeventsinlistbox"); if (str == null || str == "" || str == "1") { _showEventsInListbox = true; // if not set, value is true } else { _showEventsInListbox = false; } str = xmlRunProperties.GetAttribute("runinsamethread"); if (str == "1") { _runInSameThread = true; } } Thread.CurrentThread.CurrentCulture = currentCulture; }
/// <summary> /// Adds an output exchange item /// </summary> /// <param name="exchangeItem">The output exchange item</param> public virtual void AddOutputExchangeItem(IOutputExchangeItem exchangeItem) { _outputExchangeItems.Add(exchangeItem); }
/// <summary> /// Checks whether the current data operation is valid for the combination of /// input and output exchange items /// </summary> /// <param name="inputExchangeItem">The input exchange item</param> /// <param name="outputExchangeItem">The output exchange item</param> /// <param name="SelectedDataOperations">The selected data operations</param> /// <returns>True if the data operation is valid</returns> public virtual bool IsValid(IInputExchangeItem inputExchangeItem,IOutputExchangeItem outputExchangeItem, IDataOperation[] SelectedDataOperations) { return true; }
public bool IsValid(IInputExchangeItem inputExchangeItem, IOutputExchangeItem outputExchangeItem, IDataOperation[] SelectedDataOperations) { throw new NotImplementedException(); }
public bool IsValid(IInputExchangeItem inputExchangeItem, IOutputExchangeItem outputExchangeItem, IDataOperation[] SelectedDataOperations) { throw new NotImplementedException(); }
public void Initialize(IArgument[] properties) { // ---------------------------------------------------------------------------------------------------- // The method queries a HydroDesktop database and builds OpenMI exchange items based on // the themes present in the database. // // If omi file has a DbPath attribute, that will set the path to the HydrDesktop database. If the omi // file does not have a DbPath attribute, the path will be set as the current database selected by // HydroDesktop. // ---------------------------------------------------------------------------------------------------- //extract argument(s) from OMI file foreach (IArgument property in properties) { if (property.Key == "DbPath") { _dbPath = property.Value; } ; //default value for relationFactor is 1; if (property.Key == "Relaxation") { //check to see if the property is a string if (property.Value.GetType().Name == "String") { if (property.Value == "ExactMatch") { _exactMatch = true; } } else { _relaxationFactor = Convert.ToDouble(property.Value); } } else if (property.Key == "RangeInSeconds") { _range = Convert.ToInt32(property.Value); } } //---- set database to default if dbpath is invalid string fullpath = ""; //-- first check if dbpath is null bool pass = true; if (String.IsNullOrWhiteSpace(_dbPath)) { pass = false; } //-- next, check that dbpath points to an actual file else { //-- if relative path is given if (!Path.IsPathRooted(_dbPath)) { fullpath = System.IO.Path.GetFullPath(System.IO.Directory.GetCurrentDirectory() + _dbPath); } //-- if absolute path else { fullpath = System.IO.Path.GetFullPath(_dbPath); } if (!File.Exists(fullpath)) { pass = false; //-- warn the user that the database could not be found System.Windows.Forms.MessageBox.Show("The database supplied in DbReader.omi could not be found. As a result the DbReader will connect to the current HydroDesktop database." + "\n\n--- The following database could not be found --- \n" + fullpath, "An Error Occurred While Loading Database...", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } } //-- set the connection string if (!pass) { conn = Settings.Instance.DataRepositoryConnectionString; } else { conn = @"Data Source = " + fullpath + ";New=False;Compress=True;Version=3"; } //-- get the database _db = new DbOperations(conn, DatabaseTypes.SQLite); //----build list of output exchange items from db themes List <string> warnings = new List <string>(); //-- get all themes DataTable themes = _db.LoadTable("themes", "SELECT ThemeID, ThemeName from DataThemeDescriptions"); foreach (DataRow theme in themes.Rows) { //-- get all the variables associated with the theme DataTable variables = _db.LoadTable("vars", "SELECT Variables.VariableUnitsID,ThemeName " + "FROM Variables " + "INNER JOIN DataSeries ON Variables.VariableID=DataSeries.VariableID " + "INNER JOIN DataThemes ON DataSeries.SeriesID=DataThemes.SeriesID " + "INNER JOIN DataThemeDescriptions ON DataThemes.ThemeID=DataThemeDescriptions.ThemeID " + "WHERE DataThemes.ThemeID = " + theme[0].ToString()); //-- make sure that all series in theme have the same variable bool saveTheme = true; for (int i = 1; i <= variables.Rows.Count - 1; i++) { if (variables.Rows[0][0].ToString() != variables.Rows[i][0].ToString()) { //-- don't save this theme saveTheme = false; //-- add this theme to the warnings list warnings.Add("\"" + variables.Rows[0][1].ToString() + "\""); break; } } //-- save all themes containing exactly one variable if (saveTheme) { IOutputExchangeItem outExchangeItem = buildExchangeItemFromTheme(theme["ThemeID"].ToString(), theme["ThemeName"].ToString()); _outputExchangeItems.Add(outExchangeItem); } } //---- notify the user if some themes cannot be loaded if (warnings.Count > 0) { string title = "One or more themes could not be loaded..."; string message = "The DbReader component requires that all data series in given theme have a unique variable. " + "One or more of the themes in this database do not fit this criteria, and therefore cannot be loaded. " + "\n\n--- The following themes will not be loaded --- \n"; foreach (string warning in warnings) { message += "\nTheme Name: " + warning; } //TODO: write this to the output window instead of using MessageBox //-- suppress the messagebox for now b/c its annoying. //System.Windows.Forms.MessageBox.Show(message,title,System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Warning); } }
public void LinkedToTestComponent() { CreateHydroNetInputfile(); HydroNumerics.OpenMI.Sdk.Backbone.OmiFileParser omiFileParser = new HydroNumerics.OpenMI.Sdk.Backbone.OmiFileParser(); omiFileParser.ReadOmiFile(filename + ".omi"); IArgument[] arguments = omiFileParser.GetArgumentsAsIArgumentArray(); // Create the HydroNet linkableComponent LinkableComponent hydroNetLC = new LinkableComponent(); hydroNetLC.Initialize(arguments); Assert.AreEqual("Lake model", hydroNetLC.ModelID); // Create the TestLinkableComponent TestLinkableComponent testLC = new TestLinkableComponent(); testLC.Initialize(new HydroNumerics.OpenMI.Sdk.Backbone.Argument[0] { }); // Link (hydroNet to TestLC) (leakage --> infiltration) IOutputExchangeItem leakageOutputExchangeItem = hydroNetLC.GetOutputExchangeItem(0); HydroNumerics.OpenMI.Sdk.Backbone.Link hydroNetLC2testLC = new HydroNumerics.OpenMI.Sdk.Backbone.Link(); hydroNetLC2testLC.ID = "HydroNet2TestLC"; hydroNetLC2testLC.SourceComponent = hydroNetLC; hydroNetLC2testLC.TargetComponent = testLC; hydroNetLC2testLC.SourceElementSet = hydroNetLC.GetOutputExchangeItem(0).ElementSet; hydroNetLC2testLC.SourceQuantity = hydroNetLC.GetOutputExchangeItem(0).Quantity; Assert.AreEqual("Leakage", hydroNetLC2testLC.SourceQuantity.ID); hydroNetLC2testLC.TargetElementSet = testLC.GetOutputExchangeItem(0).ElementSet; hydroNetLC2testLC.TargetQuantity = testLC.GetInputExchangeItem(0).Quantity; hydroNetLC2testLC.AddDataOperation(hydroNetLC.GetOutputExchangeItem(0).GetDataOperation(3)); // Link (TestLC to hydroNet) (groundwaterhead --> groundwaterhead) HydroNumerics.OpenMI.Sdk.Backbone.Link testLC2HydroNetLC = new HydroNumerics.OpenMI.Sdk.Backbone.Link(); testLC2HydroNetLC.ID = "testLC2HydroNetLc"; testLC2HydroNetLC.SourceComponent = testLC; testLC2HydroNetLC.TargetComponent = hydroNetLC; testLC2HydroNetLC.SourceQuantity = testLC.GetOutputExchangeItem(0).Quantity; testLC2HydroNetLC.SourceElementSet = testLC.GetOutputExchangeItem(0).ElementSet; testLC2HydroNetLC.TargetQuantity = hydroNetLC.GetInputExchangeItem(0).Quantity; Assert.AreEqual("Head", testLC2HydroNetLC.TargetQuantity.ID); //check to see if this is the right quantity testLC2HydroNetLC.TargetElementSet = hydroNetLC.GetInputExchangeItem(0).ElementSet; testLC2HydroNetLC.AddDataOperation(testLC.GetOutputExchangeItem(0).GetDataOperation(3)); testLC.AddLink(testLC2HydroNetLC); hydroNetLC.AddLink(testLC2HydroNetLC); hydroNetLC.AddLink(hydroNetLC2testLC); testLC.AddLink(hydroNetLC2testLC); // triggerlink HydroNumerics.OpenMI.Sdk.DevelopmentSupport.Trigger trigger = new HydroNumerics.OpenMI.Sdk.DevelopmentSupport.Trigger(); trigger.Initialize(new HydroNumerics.OpenMI.Sdk.Backbone.Argument[0] { }); HydroNumerics.OpenMI.Sdk.Backbone.Link triggerLink = new HydroNumerics.OpenMI.Sdk.Backbone.Link(); triggerLink.ID = "TriggerLink"; triggerLink.SourceComponent = testLC; triggerLink.TargetComponent = trigger; triggerLink.SourceQuantity = testLC.GetOutputExchangeItem(0).Quantity; triggerLink.SourceElementSet = testLC.GetOutputExchangeItem(0).ElementSet; triggerLink.TargetQuantity = trigger.GetInputExchangeItem(0).Quantity; triggerLink.TargetElementSet = trigger.GetInputExchangeItem(0).ElementSet; testLC.AddLink(triggerLink); trigger.AddLink(triggerLink); // prepare trigger.Prepare(); hydroNetLC.Prepare(); testLC.Prepare(); ScalarSet scalarSet = (ScalarSet)hydroNetLC.GetValues(new TimeStamp(new DateTime(2001, 6, 1)), hydroNetLC2testLC.ID); double expected = -0.0000065836086956521805 * 2.0; Assert.AreEqual(0, scalarSet.data[0], 0.000000000001); Assert.AreEqual(0, scalarSet.data[1], 0.000000000001); Assert.AreEqual(expected, scalarSet.data[2], 0.000000000001); Assert.AreEqual(0, scalarSet.data[3], 0.000000000001); // Run //trigger.Run(testLC.TimeHorizon.End); //TimestampSeries infiltTSS = ((TimestampSeries) testLC.TestEngine.Infiltrations.Items[0]); trigger.Finish(); hydroNetLC.Finish(); testLC.Finish(); trigger.Dispose(); hydroNetLC.Dispose(); testLC.Dispose(); }
/// <summary> /// Creates the tree based on element sets and quantities in exchange items /// passed with <see cref="PopulateExchangeItemTree">PopulateExchangeItemTree</see> method. /// </summary> public void CreateTree() { treeView1.BeginUpdate(); treeView1.Nodes.Clear(); string lastQuantityID = null; // fill tree with exchange items (if there are any because DrawTree could be called // before _exchangeItems was assigned ) if (_exchangeItems != null) { foreach (IExchangeItem exchangeItem in _exchangeItems) { TreeNode elementSetNode = null; // newly added node (if any) // apply filters (if any) if (_filterDimension != null && !Utils.CompareDimensions(_filterDimension, exchangeItem.Quantity.Dimension)) { continue; } if (_filterElementSet != null && _filterElementSet.ElementType != ElementType.IDBased && (exchangeItem.ElementSet.ElementType != ElementType.IDBased || exchangeItem.ElementSet.ElementCount != _filterElementSet.ElementCount)) { continue; } TreeNode quantityNode; if (lastQuantityID != exchangeItem.Quantity.ID) { // adding new quantity node quantityNode = treeView1.Nodes.Add(exchangeItem.Quantity.ID); quantityNode.Tag = exchangeItem.Quantity; if (exchangeItem.Quantity.ValueType == global::OpenMI.Standard.ValueType.Scalar) { quantityNode.ImageIndex = quantityNode.SelectedImageIndex = 0; } else { quantityNode.ImageIndex = quantityNode.SelectedImageIndex = 1; } lastQuantityID = exchangeItem.Quantity.ID; } else { // last node corresponds to quantity with same ID quantityNode = treeView1.Nodes[treeView1.Nodes.Count - 1]; } // Add ElementSet node elementSetNode = quantityNode.Nodes.Add(exchangeItem.ElementSet.ID); Debug.Assert(0 <= (int)exchangeItem.ElementSet.ElementType && (int)exchangeItem.ElementSet.ElementType <= 9); elementSetNode.ImageIndex = elementSetNode.SelectedImageIndex = (int)exchangeItem.ElementSet.ElementType + 2; elementSetNode.Tag = exchangeItem.ElementSet; // add DataOperation subnodes only if newly added node is IOutputExchangeItem if (exchangeItem is IOutputExchangeItem) { IOutputExchangeItem item = (IOutputExchangeItem)exchangeItem; for (int j = 0; j < item.DataOperationCount; j++) { TreeNode dataOperationNode = elementSetNode.Nodes.Add(item.GetDataOperation(j).ID); dataOperationNode.ImageIndex = dataOperationNode.SelectedImageIndex = 12; dataOperationNode.Tag = item.GetDataOperation(j); } } } } treeView1.CollapseAll(); treeView1.EndUpdate(); _checkedQuantity = null; _checkedElementSet = null; _checkedDataOperations = new ArrayList(); }
/// <summary> /// Adds an output exchange item /// </summary> /// <param name="exchangeItem">The output exchange item</param> public virtual void AddOutputExchangeItem(IOutputExchangeItem exchangeItem) { _outputExchangeItems.Add(exchangeItem); }
public InternalLink(ILinkableComponent1 component1Source, IOutputExchangeItem source1, ITimeSpan timeHorizon) { _component1Source = component1Source; _component1Target = new DummyComponent1Target(timeHorizon); _quantity1 = source1.Quantity; _elementSet1 = source1.ElementSet; }