private void myShowIE(TreeNode node, InternalElementType IE) { TreeNode childNode = node.Nodes.Add(IE.Name.Value); childNode.Tag = IE; foreach (InternalElementType childIE in IE.InternalElement) { myShowIE(childNode, childIE); } }
static void AddECLASSAttributes(InternalElementType element, SystemUnitFamilyType eclass) { // add the class reference without any attributes element.SystemUnitClass = eclass; if (eclass.Attribute["ECLASS"].Value == "19234103") { // you need a ECLASS license to get the data, this is only an example element.SetAttributeValue("MC_Power", 220.0); } }
private static void ShowMyInternalElement(TreeNode node, InternalElementType ie) { var childNode = node.Nodes.Add(ie.Name); childNode.Tag = ie; foreach (var childIe in ie.InternalElement) { ShowMyInternalElement(childNode, childIe); } }
public override void PopulateFromAml(string Name, InternalElementType ie, MtpDataSourceSubscriber subscriber) { if (ie == null || subscriber == null) { return; } this.TagName = "" + Name; subscriber.SubscribeToAmlIdRefWith <double>(ie.Attribute, "V", (ct, o) => { this.Value = (double)o; }); }
/// <summary> /// Creates the Structur to reference a picture and set the correct value <paramref name="pic"/>. /// If the structur is already there, it will only update the value. /// </summary> /// <param name="pic">the absolut path to the picture</param> /// <param name="pictype">Picturetyp like 'DevicePicture' or 'DeviceIcon'</param> /// <param name="externalname">The name of the externalElement</param> /// <param name="systemUnitClass">the systemUnitClass to insert the structure into</param> /// <returns></returns> public Uri createPictureRef(string pic, string pictype, string externalname, SystemUnitClassType systemUnitClass) { // create the package paths FileInfo pictureInfo = new FileInfo(pic); Uri picturePath = new Uri(pictureInfo.Name, UriKind.Relative); Uri picturePart = PackUriHelper.CreatePartUri(picturePath); // Create the InternalElement which refers to the picture InternalElementType pictureIE = null; foreach (var internalElement in systemUnitClass.InternalElement) { if (internalElement.Name.Equals(pictype)) { pictureIE = internalElement; break; } } if (pictureIE == null) { pictureIE = systemUnitClass.InternalElement.Append(pictype); } // create the externalelement ExternalInterfaceType pictureEI = null; foreach (var externalinterface in pictureIE.ExternalInterface) { if (externalinterface.Name.Equals(externalname)) { pictureEI = externalinterface; break; } } if (pictureEI == null) { pictureEI = pictureIE.ExternalInterface.Append(externalname); } pictureEI.RefBaseClassPath = AutomationMLInterfaceClassLib.ExternalDataConnector; // create the refURI Attribute with the value of the path AttributeType pictureAtt = null; if (pictureEI.Attribute.GetCAEXAttribute("refURI") == null) { pictureAtt = pictureEI.Attribute.Append("refURI"); } pictureAtt.AttributeDataType = "xs:anyURI"; pictureAtt.Value = picturePart.ToString(); return(picturePart); }
public void Parse(InternalElementType ie) { x = MtpAmlHelper.FindAttributeValueByNameFromDouble(ie.Attribute, "X"); y = MtpAmlHelper.FindAttributeValueByNameFromDouble(ie.Attribute, "Y"); width = MtpAmlHelper.FindAttributeValueByNameFromDouble(ie.Attribute, "Width"); height = MtpAmlHelper.FindAttributeValueByNameFromDouble(ie.Attribute, "Height"); rotation = MtpAmlHelper.FindAttributeValueByNameFromDouble(ie.Attribute, "Rotation"); viewType = MtpAmlHelper.FindAttributeValueByName(ie.Attribute, "ViewType"); eVer = MtpAmlHelper.FindAttributeValueByName(ie.Attribute, "eClassVersion"); eClass = MtpAmlHelper.FindAttributeValueByName(ie.Attribute, "eClassClassificationClass"); eIrdi = MtpAmlHelper.FindAttributeValueByName(ie.Attribute, "eClassIRDI"); refID = MtpAmlHelper.FindAttributeValueByName(ie.Attribute, "RefID"); }
/// <summary> /// The <see cref="CreateCommand"/> Execution Action. Ne Child Elements are added to the /// Selected Internal Element. If no Internal Element is selected, the Child /// InternalElements are added to the selected InstanceHierarchy. /// </summary> /// <param name="parameter">unused parameter.</param> private void CreateCommandExecute(object parameter) { if (this.ElementCount > 0) { var ie = this.InternalElements.CurrentItem as ElementViewModel; if (ie != null) { int index = this.InternalElementCollection.IndexOf(ie); InternalElementType parent = ie.CAEX as InternalElementType; if (parent != null) { for (int i = 0; i < ElementCount; i++) { var ie_new = parent.New_InternalElement("InternalElement " + (i + 1)); var element_new = new ElementViewModel(); element_new.Init(ie_new, ie.Level + 1); this.InternalElementCollection.Insert(++index, element_new); } this.TotalElementCount += ElementCount; OnPropertyChanged("InternalElements"); } } else { var ih = this.InstanceHierarchies.CurrentItem as InstanceHierarchyType; if (ih != null) { for (int i = 0; i < ElementCount; i++) { var ie_new = ih.New_InternalElement("InternalElement " + (i + 1)); var element_new = new ElementViewModel(); element_new.Init(ie_new, 1); this.InternalElementCollection.Insert(0, element_new); } this.TotalElementCount += ElementCount; OnPropertyChanged("InternalElements"); } } } }
/// <summary> /// Shows the internal elements of an InternalElement /// </summary> /// <param name="ie"> The ie.</param> /// <param name="level">The level.</param> private void ShowInternalElements(InternalElementType ie, int level) { var element = new ElementViewModel(); element.Init(ie, level); this.InternalElementCollection.Add(element); this.TotalElementCount++; foreach (InternalElementType cie in ie.InternalElement) { // incr. the Hierarchy Level ShowInternalElements(cie, level + 1); } }
/// <summary> /// Create a attribute <paramref name="attribute"/> with the given datatype <paramref name="datatype"/> in the <paramref name="ie"/> /// </summary> /// <param name="attribute">the name of the attribute</param> /// <param name="datatype">the xs datatype</param> /// <param name="ie">the internalelement for these attributes</param> /// <returns></returns> private AttributeType initCAEXAttribute(string attribute, string datatype, InternalElementType ie) { AttributeType attributeType = null; // check if the attribute exists, if not create it if (ie.Attribute.GetCAEXAttribute(attribute) == null) { attributeType = ie.Attribute.Append(attribute); attributeType.AttributeDataType = datatype; } else { ie.Attribute.GetCAEXAttribute(attribute).AttributeDataType = datatype; } return(attributeType); }
/// <summary> /// Takes the url of the picture and setup in the value attribute of the corresponding internal element <paramref name="pic"/>. /// </summary> /// <param name="url">the absolut path to the picture or document in the internet</param> /// <param name="urltype">Picturetyp like 'DevicePicture' or 'DeviceIcon' and document type like "Short guide" or "Bill of materials" etc</param> /// <param name="externalname">The name of the externalElement</param> /// <param name="systemUnitClass">the systemUnitClass to insert the structure into</param> /// <returns></returns> public void interneturl(string url, string urltype, string externalname, SystemUnitClassType systemUnitClass) { // Create the InternalElement which refers to the picture InternalElementType urlIE = null; foreach (var internalElement in systemUnitClass.InternalElement) { if (internalElement.Name.Equals(urltype)) { urlIE = internalElement; break; } } if (urlIE == null) { urlIE = systemUnitClass.InternalElement.Append(urltype); } // create the externalelement ExternalInterfaceType urlEI = null; foreach (var externalinterface in urlIE.ExternalInterface) { if (externalinterface.Name.Equals(externalname)) { urlEI = externalinterface; break; } } if (urlEI == null) { urlEI = urlIE.ExternalInterface.Append(externalname); } urlEI.RefBaseClassPath = AutomationMLInterfaceClassLib.ExternalDataConnector; // create the refURI Attribute with the value of the path AttributeType urlAtt = null; if (urlEI.Attribute.GetCAEXAttribute("refURI") == null) { urlAtt = urlEI.Attribute.Append("refURI"); } urlAtt.AttributeDataType = "xs:anyURI"; urlAtt.Value = url.ToString(); }
/// <summary> /// /// </summary> /// <param name="ie"></param> private void initCAEXattributes(InternalElementType ie) { initCAEXAttribute("CommunicationTechnology", "xs:string", ie); initCAEXAttribute("VendorName", "xs:string", ie); initCAEXAttribute("DeviceName", "xs:string", ie); initCAEXAttribute("DeviceFamiliy", "xs:string", ie); initCAEXAttribute("ProductName", "xs:string", ie); initCAEXAttribute("OrderNumber", "xs:string", ie); initCAEXAttribute("ProductText", "xs:string", ie); initCAEXAttribute("IPProtection", "xs:string", ie); initCAEXAttribute("VendorHompage", "xs:string", ie); initCAEXAttribute("HardwareRelease", "xs:string", ie); initCAEXAttribute("SoftwareRelease", "xs:string", ie); initCAEXAttribute("OperatingTemperatureMin", "xs:double", ie); initCAEXAttribute("OperatingTemperatureMax", "xs:double", ie); initCAEXAttribute("VendorId", "xs:integer", ie); initCAEXAttribute("DeviceId", "xs:integer", ie); }
/// <summary> /// assign the values of the <paramref name="device"/> to the corresponding attributes /// </summary> /// <param name="ie">the DeviceIdentification InternalElement</param> /// <param name="device">the device for this aml</param> private void setCAEXattribute(InternalElementType ie, MWDevice device) { writeIfNotNull(ie.Attribute.GetCAEXAttribute("CommunicationTechnology"), device.deviceType); writeIfNotNull(ie.Attribute.GetCAEXAttribute("VendorId"), device.vendorID); writeIfNotNull(ie.Attribute.GetCAEXAttribute("VendorName"), device.vendorName); writeIfNotNull(ie.Attribute.GetCAEXAttribute("DeviceId"), device.deviceID); writeIfNotNull(ie.Attribute.GetCAEXAttribute("DeviceName"), device.deviceName); writeIfNotNull(ie.Attribute.GetCAEXAttribute("DeviceFamiliy"), device.deviceFamily); writeIfNotNull(ie.Attribute.GetCAEXAttribute("OrderNumber"), device.orderNumber); writeIfNotNull(ie.Attribute.GetCAEXAttribute("ProductName"), device.productName); writeIfNotNull(ie.Attribute.GetCAEXAttribute("ProductText"), device.productText); writeIfNotNull(ie.Attribute.GetCAEXAttribute("IPProtection"), device.ipProtection); writeIfNotNull(ie.Attribute.GetCAEXAttribute("OperatingTemperatureMin"), device.minTemperature); writeIfNotNull(ie.Attribute.GetCAEXAttribute("OperatingTemperatureMax"), device.maxTemperature); writeIfNotNull(ie.Attribute.GetCAEXAttribute("VendorHompage"), device.vendorHomepage); writeIfNotNull(ie.Attribute.GetCAEXAttribute("HardwareRelease"), device.harwareRelease); writeIfNotNull(ie.Attribute.GetCAEXAttribute("SoftwareRelease"), device.softwareRelease); }
/** * This function is a recursive hekper function for findInternalElement and cycles through the children * of a given internal element until the sought-after is found or until there are no more descendants. */ private InternalElementType cycleElements(InternalElementType ie, string nameToBeSearched) { foreach (var internalElementChild in ie.InternalElement) // cycle through children { if (internalElementChild.Name == nameToBeSearched) // element found { return(internalElementChild); } else { if (internalElementChild.InternalElement != null) // element has children { var ieToReturn = cycleElements(internalElementChild, nameToBeSearched); // start recursion if (ieToReturn.Name != null) // found element in children { return(ieToReturn); } } } } return(new InternalElementType(new System.Xml.Linq.XElement("NULL"))); // cant return null element, therefor return useless element }
/// <summary> /// Create the AMLX File with the correct AML File and optional pictures /// </summary> /// <param name="device">The device which will be created</param> /// <param name="isEdit">true if an amlx file get update, false if a new file will be created</param> /// <returns></returns> public string CreateDevice(MWDevice device, bool isEdit) { CAEXDocument document = null; AutomationMLContainer amlx = null; // Init final .amlx Filepath //first of all create a folder on "Vendor Name" string vendorCompanyName = device.vendorName; string vendorCompanyNameFilePath = ""; string fileName = device.fileName; string amlFilePath = System.IO.Path.Combine(device.filepath, fileName + ".amlx"); FileInfo file = new FileInfo(amlFilePath); // Create directory if it's not existing file.Directory.Create(); // Init CAEX Document if (isEdit) { // Load the amlx file amlx = new AutomationMLContainer(amlFilePath, FileMode.Open); IEnumerable <PackagePart> rootParts = amlx.GetPartsByRelationShipType(AutomationMLContainer.RelationshipType.Root); // We expect the aml to only have one root part if (rootParts.First() != null) { PackagePart part = rootParts.First(); // load the aml file as an CAEX document document = CAEXDocument.LoadFromStream(part.GetStream()); } else { // the amlx contains no aml file document = CAEXDocument.New_CAEXDocument(); } } else { // create a new CAEX document document = CAEXDocument.New_CAEXDocument(); try { amlx = new AutomationMLContainer(amlFilePath, FileMode.Create); } catch (Exception) {} } // Init the default Libs AutomationMLBaseRoleClassLibType.RoleClassLib(document); AutomationMLInterfaceClassLibType.InterfaceClassLib(document); var structureRoleFamilyType = AutomationMLBaseRoleClassLibType.RoleClassLib(document).Structure; SystemUnitFamilyType systemUnitClass = null; // Create the SystemUnitClass for our device if (!isEdit) { systemUnitClass = document.CAEXFile.SystemUnitClassLib.Append("ComponentSystemUnitClassLib").SystemUnitClass.Append(device.deviceName); device.listWithURIConvertedToString = new List <AttachablesDataGridViewParameters>(); foreach (AttachablesDataGridViewParameters eachparameter in device.dataGridAttachablesParametrsList) { if (eachparameter.FilePath.Contains("https://") || eachparameter.FilePath.Contains("http://") || eachparameter.FilePath.Contains("www") || eachparameter.FilePath.Contains("WWW")) { interneturl(eachparameter.FilePath, eachparameter.ElementName.ToString(), "ExternalDataConnector", systemUnitClass); } else { Boolean myBool; Boolean.TryParse(eachparameter.AddToFile, out myBool); if (myBool == true) { } Uri eachUri = null; AttachablesDataGridViewParameters par = new AttachablesDataGridViewParameters(); eachUri = createPictureRef(eachparameter.FilePath, eachparameter.ElementName.ToString(), "ExternalDataConnector", systemUnitClass); par.ElementName = eachUri.ToString(); par.FilePath = eachparameter.FilePath; device.listWithURIConvertedToString.Add(par); } } foreach (var pair in device.DictionaryForRoleClassofComponent) { SupportedRoleClassType supportedRoleClass = null; Match numberfromElectricalConnectorType = Regex.Match(pair.Key.ToString(), @"\((\d+)\)"); string initialnumberbetweenparanthesisofElectricalConnectorType = numberfromElectricalConnectorType.Groups[1].Value; // string stringinparanthesis = Regex.Match(pair.Key.ToString(), @"\{(\d+)\}").Groups[1].Value; string supportedRoleClassFromDictionary = Regex.Replace(pair.Key.ToString(), @"\(.+?\)", ""); supportedRoleClassFromDictionary = Regex.Replace(supportedRoleClassFromDictionary, @"\{.+?\}", ""); var SRC = systemUnitClass.SupportedRoleClass.Append(); var attributesOfSystemUnitClass = systemUnitClass.Attribute; foreach (var valueList in pair.Value) { foreach (var item in valueList) { if (item.AttributePath.Contains("/") || item.AttributePath.Contains(".")) { int count = 2; int counter = 0; Stack <char> stack = new Stack <char>(); string searchAttributeName = item.AttributePath.Substring(0, item.AttributePath.Length - item.Name.Length); foreach (var character in searchAttributeName.Reverse()) { if (!char.IsLetterOrDigit(character)) { counter++; if (counter == count) { break; } } if (char.IsLetterOrDigit(character)) { stack.Push(character); } } string finalAttributeName = new string(stack.ToArray()); foreach (var attribute in systemUnitClass.Attribute) { if (attribute.Name == finalAttributeName) { var eachattribute = attribute.Attribute.Append(item.Name.ToString()); eachattribute.Value = item.Value; eachattribute.DefaultValue = item.Default; eachattribute.Unit = item.Unit; eachattribute.AttributeDataType = item.DataType; eachattribute.Description = item.Description; eachattribute.Copyright = item.CopyRight; eachattribute.ID = item.ID; foreach (var val in item.RefSemanticList.Elements) { var refsem = eachattribute.RefSemantic.Append(); refsem.CorrespondingAttributePath = val.FirstAttribute.Value; } SRC.RefRoleClassPath = item.SupportesRoleClassType; } if (attribute.Attribute.Exists) { SearchForAttributesInsideAttributesofAutomationComponent(finalAttributeName, attribute, item, SRC); } } } else { var eachattribute = attributesOfSystemUnitClass.Append(item.Name.ToString()); eachattribute.Value = item.Value; eachattribute.DefaultValue = item.Default; eachattribute.Unit = item.Unit; eachattribute.AttributeDataType = item.DataType; eachattribute.Description = item.Description; eachattribute.Copyright = item.CopyRight; eachattribute.ID = item.ID; foreach (var val in item.RefSemanticList.Elements) { var refsem = eachattribute.RefSemantic.Append(); refsem.CorrespondingAttributePath = val.FirstAttribute.Value; } SRC.RefRoleClassPath = item.SupportesRoleClassType; } } } foreach (var pairofList in device.DictionaryForExternalInterfacesUnderRoleClassofComponent) { Match numberfromElectricalConnectorPins = Regex.Match(pairofList.Key.ToString(), @"\((\d+)\)"); string initialnumberbetweenparanthesisElectricalConnectorPins = numberfromElectricalConnectorPins.Groups[1].Value; string electricalConnectorPinName = Regex.Replace(pairofList.Key.ToString(), @"\(.*?\)", ""); electricalConnectorPinName = Regex.Replace(electricalConnectorPinName, @"\{.*?\}", ""); electricalConnectorPinName = electricalConnectorPinName.Replace(supportedRoleClassFromDictionary, ""); /*if (initialnumberbetweenparanthesisofElectricalConnectorType == initialnumberbetweenparanthesisElectricalConnectorPins) * { * supportedRoleClass.RoleReference = pairofList.Key.ToString(); * * systemUnitClass.SupportedRoleClass.Append(supportedRoleClass); * systemUnitClass.BaseClass.Name = supportedRoleClassFromDictionary; * * var attributesOfSystemUnitClassattributes = systemUnitClass.Attribute; * * foreach (var valueList in pairofList.Value) * { * foreach (var item in valueList) * { * var eachattribute = attributesOfSystemUnitClassattributes.Append(item.Name.ToString()); * eachattribute.Value = item.Value; * eachattribute.DefaultValue = item.Default; * eachattribute.Unit = item.Unit; * //eachattribute.AttributeDataType = * eachattribute.Description = item.Description; * eachattribute.Copyright = item.CopyRight; * * eachattribute.ID = item.ID; * * * * // systemUnitClass.BaseClass.Name = item.RefBaseClassPath; * } * } * }*/ } } } else { // check if our format is given in the amlx file if not: create it bool foundSysClassLib = false; foreach (var sysclasslib in document.CAEXFile.SystemUnitClassLib) { if (sysclasslib.Name.Equals("ComponentSystemUnitClassLib")) { bool foundSysClass = false; foreach (var sysclass in sysclasslib.SystemUnitClass) { if (sysclass.Name.Equals(device.deviceName)) { foundSysClass = true; systemUnitClass = sysclass; break; } } if (!foundSysClass) { systemUnitClass = sysclasslib.SystemUnitClass.Append(device.deviceName); } foundSysClassLib = true; } } if (!foundSysClassLib) { systemUnitClass = document.CAEXFile.SystemUnitClassLib.Append("ComponentSystemUnitClassLib").SystemUnitClass.Append(device.deviceName); } } // Create the internalElement Electrical Interfaces if (device.vendorName != null) { InternalElementType electricalInterface = null; RoleRequirementsType roleRequirements = null; foreach (var internalElement in systemUnitClass.InternalElement) { if (internalElement.Name.Equals("ElectricalInterfaces")) { electricalInterface = internalElement; roleRequirements = electricalInterface.RoleRequirements.Append(); roleRequirements.RefBaseRoleClassPath = structureRoleFamilyType.CAEXPath(); break; } } if (electricalInterface == null) { electricalInterface = systemUnitClass.InternalElement.Append("ElectricalInterfaces"); } roleRequirements = electricalInterface.RoleRequirements.Append(); roleRequirements.RefBaseRoleClassPath = structureRoleFamilyType.CAEXPath(); foreach (var pair in device.DictionaryForInterfaceClassesInElectricalInterfaces) { InternalElementType internalElementofElectricalConnectorType = null; ExternalInterfaceType electricalConnectorType = null; ExternalInterfaceType electricalConnectorPins = null; Match numberfromElectricalConnectorType = Regex.Match(pair.Key.ToString(), @"\((\d+)\)"); string initialnumberbetweenparanthesisofElectricalConnectorType = numberfromElectricalConnectorType.Groups[1].Value; string electricalConnectorTypeName = Regex.Replace(pair.Key.ToString(), @"\(.+?\)", ""); electricalConnectorTypeName = Regex.Replace(electricalConnectorTypeName, @"\{.+?\}", ""); internalElementofElectricalConnectorType = electricalInterface.InternalElement.Append(electricalConnectorTypeName); electricalConnectorType = internalElementofElectricalConnectorType.ExternalInterface.Append(electricalConnectorTypeName); var attributesOfConnectorType = electricalConnectorType.Attribute; foreach (var valueList in pair.Value) { foreach (var item in valueList) { if (item.AttributePath.Contains("/") || item.AttributePath.Contains(".")) { int count = 2; int counter = 0; Stack <char> stack = new Stack <char>(); string searchAttributeName = item.AttributePath.Substring(0, item.AttributePath.Length - item.Name.Length); foreach (var character in searchAttributeName.Reverse()) { if (!char.IsLetterOrDigit(character)) { counter++; if (counter == count) { break; } } if (char.IsLetterOrDigit(character)) { stack.Push(character); } } string finalAttributeName = new string(stack.ToArray()); foreach (var attribute in electricalConnectorType.Attribute) { if (attribute.Name == finalAttributeName) { var eachattribute = attribute.Attribute.Append(item.Name.ToString()); eachattribute.Value = item.Value; eachattribute.DefaultValue = item.Default; eachattribute.Unit = item.Unit; eachattribute.AttributeDataType = item.DataType; eachattribute.Description = item.Description; eachattribute.Copyright = item.CopyRight; eachattribute.ID = item.ID; foreach (var val in item.RefSemanticList.Elements) { var refsem = eachattribute.RefSemantic.Append(); refsem.CorrespondingAttributePath = val.FirstAttribute.Value; } electricalConnectorType.RefBaseClassPath = item.RefBaseClassPath; } if (attribute.Attribute.Exists) { SearchAttributesInsideAttributesOFElectricConnectorType(finalAttributeName, attribute, item, electricalConnectorType); } } } else { var eachattribute = attributesOfConnectorType.Append(item.Name.ToString()); eachattribute.Value = item.Value; eachattribute.DefaultValue = item.Default; eachattribute.Unit = item.Unit; eachattribute.AttributeDataType = item.DataType; eachattribute.Description = item.Description; eachattribute.Copyright = item.CopyRight; eachattribute.ID = item.ID; foreach (var val in item.RefSemanticList.Elements) { var refsem = eachattribute.RefSemantic.Append(); refsem.CorrespondingAttributePath = val.FirstAttribute.Value; } electricalConnectorType.RefBaseClassPath = item.RefBaseClassPath; } } } foreach (var pairofList in device.DictionaryForExternalInterfacesUnderInterfaceClassInElectricalInterfaces) { Match numberfromElectricalConnectorPins = Regex.Match(pairofList.Key.ToString(), @"\((\d+)\)"); string initialnumberbetweenparanthesisElectricalConnectorPins = numberfromElectricalConnectorPins.Groups[1].Value; string electricalConnectorPinName = Regex.Replace(pairofList.Key.ToString(), @"\(.*?\)", ""); electricalConnectorPinName = Regex.Replace(electricalConnectorPinName, @"\{.*?\}", ""); electricalConnectorPinName = electricalConnectorPinName.Replace(electricalConnectorTypeName, ""); if (initialnumberbetweenparanthesisofElectricalConnectorType == initialnumberbetweenparanthesisElectricalConnectorPins) { electricalConnectorPins = electricalConnectorType.ExternalInterface.Append(electricalConnectorPinName); var attributesOfConnectorPins = electricalConnectorPins.Attribute; foreach (var valueList in pairofList.Value) { foreach (var item in valueList) { if (item.AttributePath.Contains("/") || item.AttributePath.Contains(".")) { int count = 2; int counter = 0; Stack <char> stack = new Stack <char>(); string searchAttributeName = item.AttributePath.Substring(0, item.AttributePath.Length - item.Name.Length); foreach (var character in searchAttributeName.Reverse()) { if (!char.IsLetterOrDigit(character)) { counter++; if (counter == count) { break; } } if (char.IsLetterOrDigit(character)) { stack.Push(character); } } string finalAttributeName = new string(stack.ToArray()); foreach (var attribute in electricalConnectorPins.Attribute) { if (attribute.Name == finalAttributeName) { var eachattribute = attribute.Attribute.Append(item.Name.ToString()); eachattribute.Value = item.Value; eachattribute.DefaultValue = item.Default; eachattribute.Unit = item.Unit; eachattribute.AttributeDataType = item.DataType; eachattribute.Description = item.Description; eachattribute.Copyright = item.CopyRight; eachattribute.ID = item.ID; foreach (var val in item.RefSemanticList.Elements) { var refsem = eachattribute.RefSemantic.Append(); refsem.CorrespondingAttributePath = val.FirstAttribute.Value; } electricalConnectorPins.RefBaseClassPath = item.RefBaseClassPath; } if (attribute.Attribute.Exists) { SearchAttributesInsideAttributesOFElectricConnectorType(finalAttributeName, attribute, item, electricalConnectorPins); } } } else { var eachattribute = attributesOfConnectorPins.Append(item.Name.ToString()); eachattribute.Value = item.Value; eachattribute.DefaultValue = item.Default; eachattribute.Unit = item.Unit; eachattribute.AttributeDataType = item.DataType; eachattribute.Description = item.Description; eachattribute.Copyright = item.CopyRight; eachattribute.ID = item.ID; foreach (var val in item.RefSemanticList.Elements) { var refsem = eachattribute.RefSemantic.Append(); refsem.CorrespondingAttributePath = val.FirstAttribute.Value; } electricalConnectorPins.RefBaseClassPath = item.RefBaseClassPath; } } } } } } } // create the PackageUri for the root aml file Uri partUri = PackUriHelper.CreatePartUri(new Uri("/" + fileName + "-root.aml", UriKind.Relative)); // tcreate the aml file as a temporary file string path = Path.GetTempFileName(); document.SaveToFile(path, true); if (isEdit) { // delete the old aml file amlx.Package.DeletePart(partUri); // delete all files in the amlx package. // Directory.Delete(Path.GetFullPath(amlx.ContainerFilename), true); } // write the new aml file into the package PackagePart root = amlx.AddRoot(path, partUri); if (!isEdit) { foreach (AttachablesDataGridViewParameters listWithUri in device.listWithURIConvertedToString) { if (listWithUri.ElementName != null) { Uri newuri = null; newuri = new Uri(listWithUri.ElementName, UriKind.Relative); amlx.AddAnyContent(root, listWithUri.FilePath.ToString(), newuri); } } } DirectoryInfo directory = new DirectoryInfo(Path.GetDirectoryName(amlFilePath)); foreach (FileInfo fileInfos in directory.GetFiles()) { if (fileInfos.Extension != ".amlx") { fileInfos.Delete(); } } amlx.Save(); amlx.Close(); if (isEdit) { return("Sucessfully updated device!\nFilepath " + amlFilePath); } else { return("Device description file created!\nFilepath " + amlFilePath); } }
public Frame(IAmlProvider provider) : base(provider) { _internalElement = provider.CaexDocument.Create <InternalElementType>(); Initialize(); }
/// <summary> /// Creates an example CAEX file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Btn_CreateCAEX_Click(object sender, EventArgs e) { myErrorListBox.Items.Clear(); CAEXTreeView.Nodes.Clear(); // Create a new CAEX document _myDoc = CAEXDocument.New_CAEXDocument(); // *************************** // ******** SystemUnitClass // *************************** // Create a set of SystemUnitClassLibs var sucLib1 = _myDoc.CAEXFile.SystemUnitClassLib.Append(); sucLib1.Name = "MySUCLib"; var sucLib2 = _myDoc.CAEXFile.SystemUnitClassLib.Append(); sucLib2.Name = "MySUCLib1"; var sucLib3 = _myDoc.CAEXFile.SystemUnitClassLib.Append(); sucLib3.Name = "MySUCLib2"; // Create a new SystemUnitClass var suc = sucLib1.SystemUnitClass.Append(); suc.Name = "Class MyTank"; // Create another SystemUnitClass var suc1 = sucLib1.SystemUnitClass.Append(); suc1.Name = "Class MyLid"; // Create a nested InternalElement within the SystemUnitClass "MyTank" var sucIntElem1 = suc.InternalElement.Append(); sucIntElem1.Name = "IE MyGround"; // Create an instance of the "MyLid" within the SystemUnitClass "MyTank" var sucIntElem2 = suc1.CreateClassInstance(); sucIntElem2.Name = "Instance of class MyLid"; suc.InternalElement.Insert(sucIntElem2); // Create a list with all SystemUnitClassLibs with the name "MySUCLib" var exampleSucLibList = _myDoc.CAEXFile.SystemUnitClassLib.Where(x => "MySUCLib".Equals(x.Name)); Debug.Assert(exampleSucLibList.Count() == 1, nameof(exampleSucLibList) + " != 1"); // *************************** // ******** RoleClasses // *************************** var roleClassLib = _myDoc.CAEXFile.RoleClassLib.Append(); roleClassLib.Name = "MyRoleLib"; var roleClass = roleClassLib.RoleClass.Append(); roleClass.Name = "Role Lid"; // *************************** // ******** InstanceHierarchy // *************************** // Create a new InstanceHierarchy var insHierarchy = _myDoc.CAEXFile.InstanceHierarchy.Append(); insHierarchy.Name = "MyHierarchy"; // Set change mode insHierarchy.ChangeMode = ChangeMode.Change; Debug.Assert(ChangeMode.Change == insHierarchy.ChangeMode, nameof(insHierarchy) + "does not have the correct change mode"); // Create a new InternalElement var intElem = insHierarchy.InternalElement.Append(); intElem.Name = "IE"; intElem.ID = "GUID1"; intElem.Description = "Another description"; // Get CAEX instance path var intElemPath = intElem.CAEXPath(); Debug.Assert("GUID1".Equals(intElemPath), nameof(intElemPath) + " is not correct"); // Create a new role requirement var roleReq = intElem.RoleRequirements.Append(); roleReq.RefBaseRoleClassPath = roleClass.GetFullNodePath(); // Create a new attribute var att = intElem.Attribute.Append(); att.Name = "Weight"; att.Value = "20"; att.Unit = "t"; // Check if attribute exists att = intElem.Attribute.FirstOrDefault(x => "Weight".Equals(x.Name)); Debug.Assert(att != null, nameof(att) + " != null"); // Set attribute values intElem.SetAttributeValue("Weight", "21"); intElem.SetAttributeValue("Mass1", "11"); // Check if attribute value set var attValue = att.Value; Debug.Assert("21".Equals(attValue), nameof(attValue) + " != 21"); var massAtt = intElem.Attribute["Mass1"]; var massAttValue = massAtt.Value; Debug.Assert("11".Equals(massAttValue), nameof(attValue) + " != 11"); // Create a new InternalElement intElem2 var intElem2 = insHierarchy.InternalElement.Append(); intElem2.Name = "IE2"; var att2 = intElem2.Attribute.Append(); att2.Name = "Color"; att2.Value = "Yellow"; // Delete the new attribute att2.Remove(); Debug.Assert(!intElem2.Attribute.Contains(att2), nameof(att2) + " exists"); // Create a new InternalElement IE5 var intElem5 = intElem2.InternalElement.Append(); intElem5.Name = "IE5"; // Delete the InternalElement IE5 intElem5.Remove(); // Set source document information var sourceDocInfo = _myDoc.CAEXFile.SourceDocumentInformation[0]; sourceDocInfo.OriginName = "WriterName"; sourceDocInfo.OriginID = "WriterID"; sourceDocInfo.OriginVendor = "WriterVendor"; sourceDocInfo.OriginVendorURL = "www.writervendor.com"; sourceDocInfo.OriginVersion = "WriterVersion"; sourceDocInfo.OriginRelease = "WriterRelease"; sourceDocInfo.OriginProjectID = "WriterProjectID"; sourceDocInfo.OriginProjectTitle = "WriterProjectTitle"; sourceDocInfo.LastWritingDateTime = DateTime.Now; // Create revision element var rev = intElem.New_Revision(DateTime.Now, "Peter Mustermann"); Debug.Assert(rev != null, nameof(rev) + " != null"); rev.RevisionDate = DateTime.Now; rev.AuthorName = "Ender"; rev.NewVersion = "1.2"; rev.OldVersion = "1.1"; rev.Comment = "A comment"; // ******************************************** // ******** Navigation specific AML operations // ******************************************** // Creates a CAEX element from an XElement node var caexElement = new InternalElementType(intElem.Node); Debug.Assert(Equals(caexElement, intElem), nameof(caexElement) + " != " + nameof(intElem)); // Another way of creating a CAEX element, without type information var abstractElement = intElem.Node.CreateCAEXWrapper(); Debug.Assert(Equals(abstractElement, intElem), nameof(abstractElement) + " != " + nameof(intElem)); // Finding the first ancestor of a specific type var firstAncestor = intElem.FirstAncestor <InstanceHierarchyType>(); Debug.Assert(Equals(firstAncestor, insHierarchy), nameof(firstAncestor) + " != " + nameof(insHierarchy)); // Gathering the name of the parent var parentName = intElem.GetParent <InstanceHierarchyType>().Name; Debug.Assert(Equals("MyHierarchy", parentName), nameof(parentName) + " != MyHierarchy "); // Finding element with the id var internalElementFromId = _myDoc.CAEXFile.FindCaexObjectFromId <InternalElementType>("GUID1"); Debug.Assert(Equals(internalElementFromId, intElem), nameof(internalElementFromId) + " != " + nameof(intElem)); // Finding element with the id without type information var elementFromId = _myDoc.FindByID("GUID1"); Debug.Assert(Equals(elementFromId, intElem), nameof(elementFromId) + " != " + nameof(intElem)); // Gathering descendants var descendantIntElem = insHierarchy.Descendants <InternalElementType>().FirstOrDefault(x => "GUID1".Equals(x.ID)); Debug.Assert(Equals(descendantIntElem, intElem), nameof(descendantIntElem) + " != " + nameof(intElem)); // Finding element with the path (is an ID for an instance) var intElementFromPath = _myDoc.CAEXFile.FindCaexObjectFromId <InternalElementType>(intElemPath); Debug.Assert(Equals(intElementFromPath, intElem), nameof(intElementFromPath) + " != " + nameof(intElem)); // Finding element with the path without type information var abstractElemFromPath = _myDoc.FindByID(intElemPath); Debug.Assert(Equals(abstractElemFromPath, intElem), nameof(abstractElemFromPath) + " != " + nameof(intElem)); ShowMyTree(CAEXTreeView, _myDoc); }
public Frame(InternalElementType model, IAmlProvider provider) : base(provider) { _internalElement = model; Initialize(); }
public Kinematic(InternalElementType model, IAmlProvider provider) : base(model, provider) { Initialize(); //AddElements(model); }
public KinematicLink(InternalElementType model, IAmlProvider provider) : base(model, provider) { Initialize(); }
/// <summary> /// Adds a new aml class as a systemUnitClass to a systemUnitClass library. The aml class is created /// using an existing aml object as a template. /// </summary> /// <param name="guid">The unique identifier for the new aml class.</param> /// <param name="amlObjectTemplate">The aml object, used as a template.</param> /// <returns></returns> internal static SystemUnitFamilyType AddAmlClassFromAMLObjectTemplate(string guid, InternalElementType amlObjectTemplate) { var amlDocument = amlObjectTemplate.CAEXDocument(); // first, we need a class library to insert a systemUnitClass var classLib = amlDocument.CAEXFile.SystemUnitClassLib.FirstOrDefault() ?? amlDocument.CAEXFile.SystemUnitClassLib.Append("AMLClassLib"); var amlClass = classLib.SystemUnitClass.Insert(amlObjectTemplate.CreateSystemUnitClass()); amlClass.ID = guid; // the already existing internal element children should not be included in the class amlClass.InternalElement.Remove(); return(amlClass); }
// // Important Methods // public virtual void PopulateFromAml(string Name, InternalElementType ie, MtpDataSourceSubscriber subscriber) { }
public void Parse(InternalElementType ie) { x = MtpAmlHelper.FindAttributeValueByNameFromDouble(ie.Attribute, "X"); y = MtpAmlHelper.FindAttributeValueByNameFromDouble(ie.Attribute, "Y"); refID = MtpAmlHelper.FindAttributeValueByName(ie.Attribute, "RefID"); }
// Construct public override void PopulateFromAml(string Name, InternalElementType ie, MtpDataSourceSubscriber subscriber) { this.TagName = "" + Name; }
/// <summary> /// Create a new amlx file using <paramref name="newInterface"/> /// </summary> /// <param name="newInterface">the object to create</param> /// <param name="isEdit">true if an amlx file get update, false if a new file will be created</param> /// <returns></returns> public string CreateInterface(MWInterface newInterface, bool isEdit) { // Anlegen des AML / XML's // Siehe TINF17C/software-engineering-1/modelling-wizard/modellingwizardplugin#25 AutomationMLContainer amlx = null; CAEXDocument document = null; // init the filepath string fileName = newInterface.numberOfInterface + "-V.1.0-" + DateTime.Now.Date.ToShortDateString(); string amlFilePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\modellingwizard\\" + newInterface.numberOfInterface + ".amlx"; FileInfo file = new FileInfo(amlFilePath); file.Directory.Create(); // Init new CAEX Document if (isEdit) { // Load the amlx file amlx = new AutomationMLContainer(amlFilePath, FileMode.Open); IEnumerable <PackagePart> rootParts = amlx.GetPartsByRelationShipType(AutomationMLContainer.RelationshipType.Root); // We expect the aml to only have one root part if (rootParts.First() != null) { PackagePart part = rootParts.First(); // load the aml file as an CAEX document document = CAEXDocument.LoadFromStream(part.GetStream()); } else { // the amlx contains no aml file document = CAEXDocument.New_CAEXDocument(); } } else { // create a new CAEX document document = CAEXDocument.New_CAEXDocument(); amlx = new AutomationMLContainer(amlFilePath, FileMode.Create); } // Init the default Libs AutomationMLBaseRoleClassLibType.RoleClassLib(document); AutomationMLInterfaceClassLibType.InterfaceClassLib(document); SystemUnitFamilyType systemUnitClass = null; // Create the SystemUnitClass for our device if (!isEdit) { systemUnitClass = document.CAEXFile.SystemUnitClassLib.Append("ComponentSystemUnitClassLib").SystemUnitClass.Append(newInterface.numberOfInterface.ToString()); } else { bool foundSysClassLib = false; foreach (var sysclasslib in document.CAEXFile.SystemUnitClassLib) { if (sysclasslib.Name.Equals("ComponentSystemUnitClassLib")) { bool foundSysClass = false; foreach (var sysclass in sysclasslib.SystemUnitClass) { if (sysclass.Name.Equals(newInterface.numberOfInterface.ToString())) { foundSysClass = true; systemUnitClass = sysclass; break; } } if (!foundSysClass) { sysclasslib.SystemUnitClass.Append(newInterface.numberOfInterface.ToString()); } foundSysClassLib = true; } } if (!foundSysClassLib) { systemUnitClass = document.CAEXFile.SystemUnitClassLib.Append("ComponentSystemUnitClassLib").SystemUnitClass.Append(newInterface.numberOfInterface.ToString()); } } // create the DeviceIdentification InternalElement InternalElementType ie = null; foreach (var internalelement in systemUnitClass.InternalElement) { if (internalelement.Name.Equals("DeviceIdentification")) { ie = internalelement; break; } } if (ie == null) { ie = systemUnitClass.InternalElement.Append("DeviceIdentification"); } // make sure that the attributes are initialized initCAEXAttribute("InterfaceNumber", "xs:integer", ie); initCAEXAttribute("Description", "xs:string", ie); initCAEXAttribute("ConnectorType", "xs:string", ie); initCAEXAttribute("PinCount", "xs:integer", ie); // special handling for the pinlist AttributeType pinlistAtt = null; if (ie.Attribute.GetCAEXAttribute("PinAttributes") == null) { pinlistAtt = ie.Attribute.Append("PinAttributes"); } else { pinlistAtt = ie.Attribute.GetCAEXAttribute("PinAttributes"); pinlistAtt.Attribute.Remove(); } // assign the values for the pinlist foreach (MWPin pin in newInterface.pinList) { pinlistAtt.Attribute.Append(pin.pinNumber.ToString()).Value = pin.attribute; } // assign the values for the 'normal' attributes writeIfNotNull(ie.Attribute.GetCAEXAttribute("InterfaceNumber"), newInterface.numberOfInterface); writeIfNotNull(ie.Attribute.GetCAEXAttribute("Description"), newInterface.interfaceDescription); writeIfNotNull(ie.Attribute.GetCAEXAttribute("ConnectorType"), newInterface.connectorType); writeIfNotNull(ie.Attribute.GetCAEXAttribute("PinCount"), newInterface.amountPins); // create the aml package part Uri partUri = PackUriHelper.CreatePartUri(new Uri("/" + fileName + "-root.aml", UriKind.Relative)); // create a temp file with the new aml string path = Path.GetTempFileName(); document.SaveToFile(path, true); if (isEdit) { // delete the old aml file amlx.Package.DeletePart(partUri); } // copy the new aml file into the package PackagePart root = amlx.AddRoot(path, partUri); amlx.Save(); amlx.Close(); if (isEdit) { return("Sucessfully updated interface!\nFilepath " + amlFilePath); } else { return("Sucessfully created interface!\nFilepath " + amlFilePath); } }
public AssemblyViewModel(InternalElementType model, IAmlProvider provider) : base(model, provider) { Initialize(); }
/// <summary> /// Create the AMLX File with the correct AML File and optional pictures /// </summary> /// <param name="device">The device which will be created</param> /// <param name="isEdit">true if an amlx file get update, false if a new file will be created</param> /// <returns></returns> public string CreateDevice(MWDevice device, bool isEdit) { Uri manuPart = null; Uri deviceIconPart = null; Uri devicePicPart = null; CAEXDocument document = null; AutomationMLContainer amlx = null; // Init final .amlx Filepath string fileName = device.vendorName + "-" + device.deviceName + "-V.1.0-" + DateTime.Now.Date.ToShortDateString(); string amlFilePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\modellingwizard\\" + fileName + ".amlx"; FileInfo file = new FileInfo(amlFilePath); // Create directory if it's not existing file.Directory.Create(); // Init CAEX Document if (isEdit) { // Load the amlx file amlx = new AutomationMLContainer(amlFilePath, FileMode.Open); IEnumerable <PackagePart> rootParts = amlx.GetPartsByRelationShipType(AutomationMLContainer.RelationshipType.Root); // We expect the aml to only have one root part if (rootParts.First() != null) { PackagePart part = rootParts.First(); // load the aml file as an CAEX document document = CAEXDocument.LoadFromStream(part.GetStream()); } else { // the amlx contains no aml file document = CAEXDocument.New_CAEXDocument(); } } else { // create a new CAEX document document = CAEXDocument.New_CAEXDocument(); amlx = new AutomationMLContainer(amlFilePath, FileMode.Create); } // Init the default Libs AutomationMLBaseRoleClassLibType.RoleClassLib(document); AutomationMLInterfaceClassLibType.InterfaceClassLib(document); SystemUnitFamilyType systemUnitClass = null; // Create the SystemUnitClass for our device if (!isEdit) { systemUnitClass = document.CAEXFile.SystemUnitClassLib.Append("ComponentSystemUnitClassLib").SystemUnitClass.Append(device.deviceName); } else { // check if our format is given in the amlx file if not: create it bool foundSysClassLib = false; foreach (var sysclasslib in document.CAEXFile.SystemUnitClassLib) { if (sysclasslib.Name.Equals("ComponentSystemUnitClassLib")) { bool foundSysClass = false; foreach (var sysclass in sysclasslib.SystemUnitClass) { if (sysclass.Name.Equals(device.deviceName)) { foundSysClass = true; systemUnitClass = sysclass; break; } } if (!foundSysClass) { systemUnitClass = sysclasslib.SystemUnitClass.Append(device.deviceName); } foundSysClassLib = true; } } if (!foundSysClassLib) { systemUnitClass = document.CAEXFile.SystemUnitClassLib.Append("ComponentSystemUnitClassLib").SystemUnitClass.Append(device.deviceName); } } // Convert picture paths to relativ package paths (if they are given) // Convert vendorLogo path if (device.vendorLogo != null && !device.vendorLogo.Equals("")) { try { // Create File Paths manuPart = createPictureRef(device.vendorLogo, "ManufacturerIcon", "ExternalDataConnector", systemUnitClass); } catch (Exception) { // No vendor Logo } } // Convert deviceIcon if (device.deviceIcon != null && !device.deviceIcon.Equals("")) { try { deviceIconPart = createPictureRef(device.deviceIcon, "ComponentIcon", "ExternalDataReference", systemUnitClass); } catch (Exception) { // No Device Icon } } // Convert devicePicture if (device.devicePicture != null && !device.devicePicture.Equals("")) { try { devicePicPart = createPictureRef(device.devicePicture, "ComponentPicture", "ExternalDataReference", systemUnitClass); } catch (Exception) { // No device Picture } } // Create the internalElement DeviceIdentification InternalElementType ie = null; foreach (var internalelement in systemUnitClass.InternalElement) { if (internalelement.Name.Equals("DeviceIdentification")) { ie = internalelement; break; } } if (ie == null) { ie = systemUnitClass.InternalElement.Append("DeviceIdentification"); } // Init the Attributes for our format and set the correct DataTypes initCAEXattributes(ie); // Set the correct values for the Attributes setCAEXattribute(ie, device); // create the PackageUri for the root aml file Uri partUri = PackUriHelper.CreatePartUri(new Uri("/" + fileName + "-root.aml", UriKind.Relative)); // tcreate the aml file as a temporary file string path = Path.GetTempFileName(); document.SaveToFile(path, true); if (isEdit) { // delete the old aml file amlx.Package.DeletePart(partUri); } // write the new aml file into the package PackagePart root = amlx.AddRoot(path, partUri); if (!isEdit) { // copy the images from disk into the package if (manuPart != null) { amlx.AddAnyContent(root, device.vendorLogo, manuPart); } if (deviceIconPart != null) { amlx.AddAnyContent(root, device.deviceIcon, deviceIconPart); } if (devicePicPart != null) { amlx.AddAnyContent(root, device.devicePicture, devicePicPart); } } amlx.Save(); amlx.Close(); if (isEdit) { return("Sucessfully updated device!\nFilepath " + amlFilePath); } else { return("Sucessfully created device!\nFilepath " + amlFilePath); } }