private MochaAttributeValue LoadAttributeValue(MarkupTagElement tag) { if (tag == null) { return(null); } if (tag.FullName != "attributeValue") { return(null); } MarkupAttribute attInstanceID = tag.Attributes["attributeInstanceId"]; MarkupAttribute attValue = tag.Attributes["value"]; if (attInstanceID == null || attValue == null) { return(null); } MochaAttributeValue item = new MochaAttributeValue(); item.AttributeInstanceID = new Guid(attInstanceID.Value); item.Value = attValue.Value; return(item); }
public static MarkupTagElement ToXML(this PositionVector2 position, string name) { MarkupTagElement tag = new MarkupTagElement(); tag.FullName = name; tag.Attributes.Add("x", position.X.ToString()); tag.Attributes.Add("y", position.Y.ToString()); return(tag); }
public static MarkupTagElement ToXML(this TextureVector2 texture, string name) { MarkupTagElement tag = new MarkupTagElement(); tag.FullName = name; tag.Attributes.Add("u", texture.U.ToString()); tag.Attributes.Add("v", texture.V.ToString()); return(tag); }
public static MarkupTagElement ToXML(this ModelVertex vertex, string name) { MarkupTagElement tagVertex = new MarkupTagElement(); tagVertex.FullName = name; tagVertex.Elements.Add(vertex.Position.ToXML("cr:position")); tagVertex.Elements.Add(vertex.Normal.ToXML("cr:normal")); tagVertex.Elements.Add(vertex.Texture.ToXML("cr:texture")); return(tagVertex); }
protected override void AfterLoadInternal(Stack <ObjectModel> objectModels) { base.AfterLoadInternal(objectModels); MarkupObjectModel mom = objectModels.Pop() as MarkupObjectModel; MochaTenantDefinitionObjectModel tenants = objectModels.Pop() as MochaTenantDefinitionObjectModel; MarkupTagElement tagTenants = mom.FindElementUsingSchema(XMLSchemas.Mocha, "tenants") as MarkupTagElement; if (tagTenants == null) { throw new InvalidDataFormatException(); } foreach (MarkupTagElement tagTenant in tagTenants.Elements.OfType <MarkupTagElement>()) { if (!(tagTenant.Name == "tenant" && tagTenant.XMLSchema == XMLSchemas.Mocha)) { continue; } Tenant tenant = new Tenant(); tenant.Name = tagTenant.Attributes["name"]?.Value; MarkupTagElement tagLibraryReferences = tagTenant.FindElementUsingSchema(XMLSchemas.Mocha, "libraryReferences") as MarkupTagElement; if (tagLibraryReferences != null) { foreach (MarkupTagElement tagLibraryReference in tagLibraryReferences.Elements.OfType <MarkupTagElement>()) { if (tagLibraryReference.Name == "libraryReference" && tagLibraryReference.XMLSchema == XMLSchemas.Mocha) { LibraryReference lref = new LibraryReference(); lref.Path = tagLibraryReference.Attributes["path"]?.Value; tenant.LibraryReferences.Add(lref); } } } tenants.Tenants.Add(tenant); } }
private MochaInstance LoadInstance(IMochaStore library, MarkupTagElement tag) { if (tag == null) { return(null); } if (tag.FullName != "instance") { return(null); } MarkupAttribute attID = tag.Attributes["id"]; if (attID == null) { return(null); } MarkupAttribute attIndex = tag.Attributes["index"]; int? index = null; if (attIndex != null) { if (Int32.TryParse(attIndex.Value, out int index2)) { index = index2; } } MarkupAttribute attClassInstanceId = tag.Attributes["classInstanceId"]; MarkupAttribute attSuperClassId = tag.Attributes["superClassId"]; Guid instanceId = new Guid(attID.Value); MochaInstance inst = library.Instances[instanceId]; if (inst == null) { inst = new MochaInstance(); inst.ID = instanceId; } inst.Index = index; if (inst.Index != null) { // SetIndex(library, inst); } if (attClassInstanceId != null) { if (Guid.TryParse(attClassInstanceId.Value, out Guid classInstanceId)) { SetParentClass(library, inst.ID, classInstanceId); } else { Console.Error.WriteLine("bad guid for classInstanceId: {0}", attClassInstanceId.Value); } } if (attSuperClassId != null) { if (Guid.TryParse(attSuperClassId.Value, out Guid superClassId)) { SetClass(library, inst.ID); SetOwner(library, inst.ID, global::Mocha.Core.KnownInstanceGuids.Users.XQEnvironments); SetSource(library, inst.ID, library.DefaultObjectSourceID); // global::Mocha.Core.KnownInstanceGuids.ObjectSources.System); SetSuperClass(library, inst.ID, superClassId); } else { Console.Error.WriteLine("bad guid for superClassId: {0}", attSuperClassId.Value); } } MarkupTagElement tagAttributeValues = tag.Elements["attributeValues"] as MarkupTagElement; if (tagAttributeValues != null) { for (int i = 0; i < tagAttributeValues.Elements.Count; i++) { MochaAttributeValue attv = LoadAttributeValue(tagAttributeValues.Elements[i] as MarkupTagElement); if (attv == null) { continue; } inst.AttributeValues.Add(attv); } } MarkupTagElement tagRelationships = tag.Elements["relationships"] as MarkupTagElement; if (tagRelationships != null) { for (int i = 0; i < tagRelationships.Elements.Count; i++) { MarkupTagElement tagRelationship = tagRelationships.Elements[i] as MarkupTagElement; if (tagRelationship == null) { continue; } if (tagRelationship.FullName != "relationship") { continue; } MarkupAttribute attRelationshipInstanceId = tagRelationship.Attributes["relationshipInstanceId"]; if (attRelationshipInstanceId == null) { continue; } if (String.IsNullOrEmpty(attRelationshipInstanceId.Value)) { Console.Error.WriteLine("relationshipInstanceId not specified for relationship"); continue; } MochaRelationship rel = new MochaRelationship(); rel.SourceInstanceID = inst.ID; if (Guid.TryParse(attRelationshipInstanceId.Value, out Guid id)) { rel.RelationshipInstanceID = id; } else { Console.Error.WriteLine("bad guid for relationship: relationshipInstanceId='{0}'", attRelationshipInstanceId.Value); } MarkupTagElement tagTargetInstances = tagRelationship.Elements["targetInstances"] as MarkupTagElement; if (tagTargetInstances != null) { for (int j = 0; j < tagTargetInstances.Elements.Count; j++) { MarkupTagElement tagInstanceReference = tagTargetInstances.Elements[j] as MarkupTagElement; if (tagInstanceReference == null) { continue; } if (tagInstanceReference.FullName != "instanceReference") { continue; } MarkupAttribute attInstanceId = tagInstanceReference.Attributes["instanceId"]; if (attInstanceId == null) { continue; } if (Guid.TryParse(attInstanceId.Value, out Guid instId)) { rel.DestinationInstanceIDs.Add(instId); } else { Console.Error.WriteLine("bad guid for instanceReference: instanceId='{0}'", attInstanceId.Value); } } } library.Relationships.Add(rel); } } MarkupTagElement tagTranslations = tag.Elements["translations"] as MarkupTagElement; if (tagTranslations != null) { for (int i = 0; i < tagTranslations.Elements.Count; i++) { MarkupTagElement tagTranslation = (tagTranslations.Elements[i] as MarkupTagElement); if (tagTranslation == null) { continue; } if (tagTranslation.FullName != "translation") { continue; } MarkupAttribute attRelationshipId = tagTranslation.Attributes["relationshipInstanceId"]; if (attRelationshipId == null) { continue; } MarkupTagElement tagTranslationValues = (tagTranslation.Elements["translationValues"] as MarkupTagElement); if (tagTranslationValues == null) { continue; } MochaInstance instTTC = new MochaInstance(); instTTC.ID = Guid.NewGuid(); SetParentClass(library, instTTC.ID, global::Mocha.Core.KnownInstanceGuids.Classes.Translation); MochaRelationship relInstance__has__Translatable_Text_Constant = new MochaRelationship(); relInstance__has__Translatable_Text_Constant.SourceInstanceID = inst.ID; relInstance__has__Translatable_Text_Constant.RelationshipInstanceID = new Guid(attRelationshipId.Value); relInstance__has__Translatable_Text_Constant.DestinationInstanceIDs.Add(instTTC.ID); library.Relationships.Add(relInstance__has__Translatable_Text_Constant); MochaRelationship relTranslatable_Text_Constant__has__Translatable_Text_Constant_Value = new MochaRelationship(); relTranslatable_Text_Constant__has__Translatable_Text_Constant_Value.SourceInstanceID = instTTC.ID; relTranslatable_Text_Constant__has__Translatable_Text_Constant_Value.RelationshipInstanceID = global::Mocha.Core.KnownRelationshipGuids.Translatable_Text_Constant__has__Translatable_Text_Constant_Value; for (int j = 0; j < tagTranslationValues.Elements.Count; j++) { MarkupTagElement tagTranslationValue = (tagTranslationValues.Elements[j] as MarkupTagElement); if (tagTranslationValue == null) { continue; } if (tagTranslationValue.FullName != "translationValue") { continue; } MarkupAttribute attLanguageInstanceID = tagTranslationValue.Attributes["languageInstanceId"]; MarkupAttribute attValue = tagTranslationValue.Attributes["value"]; if (attLanguageInstanceID == null || attValue == null) { continue; } // create a new TTCValue instance MochaInstance instTranslationValue = new MochaInstance(); instTranslationValue.ID = Guid.NewGuid(); SetParentClass(library, instTranslationValue.ID, global::Mocha.Core.KnownInstanceGuids.Classes.TranslatableTextConstantValue); // associate the TTCValue with the Language MochaRelationship relTranslatable_Text_Constant_Value__has__Language = new MochaRelationship(); relTranslatable_Text_Constant_Value__has__Language.SourceInstanceID = instTranslationValue.ID; relTranslatable_Text_Constant_Value__has__Language.RelationshipInstanceID = global::Mocha.Core.KnownRelationshipGuids.Translatable_Text_Constant_Value__has__Language; relTranslatable_Text_Constant_Value__has__Language.DestinationInstanceIDs.Add(new Guid(attLanguageInstanceID.Value)); library.Relationships.Add(relTranslatable_Text_Constant_Value__has__Language); // set the Value attribute of the TTCValue MochaAttributeValue mavValue = new MochaAttributeValue(); mavValue.AttributeInstanceID = global::Mocha.Core.KnownAttributeGuids.Text.Value; mavValue.Value = attValue.Value; instTranslationValue.AttributeValues.Add(mavValue); // add the TTCValue to the instance list library.Instances.Add(instTranslationValue); // add the TTCValue to the TTC.has TTC Value relationship relTranslatable_Text_Constant__has__Translatable_Text_Constant_Value.DestinationInstanceIDs.Add(instTranslationValue.ID); } library.Relationships.Add(relTranslatable_Text_Constant__has__Translatable_Text_Constant_Value); library.Instances.Add(instTTC); } } return(inst); }
private Fill FillFromTag(MarkupTagElement tag) { if (tag == null) return null; MarkupAttribute attFillType = tag.Attributes["Type"]; if (attFillType != null) { switch (attFillType.Value.ToLower()) { case "none": { break; } case "solid": { MarkupAttribute attFillColor = tag.Attributes["Color"]; if (attFillColor != null) { return new SolidFill(attFillColor.Value); } break; } case "lineargradient": { MarkupAttribute attOrientation = tag.Attributes["Orientation"]; if (attOrientation == null) return null; MarkupTagElement tagColorStops = (tag.Elements["ColorStops"] as MarkupTagElement); if (tagColorStops != null) { LinearGradientFill fill = new LinearGradientFill(); switch (attOrientation.Value.ToLower()) { case "horizontal": fill.Orientation = LinearGradientFillOrientation.Horizontal; break; case "vertical": fill.Orientation = LinearGradientFillOrientation.Vertical; break; } foreach (MarkupElement elColorStop in tagColorStops.Elements) { MarkupTagElement tagColorStop = (elColorStop as MarkupTagElement); if (tagColorStop == null) continue; if (tagColorStop.FullName != "ColorStop") continue; MarkupAttribute attPosition = tagColorStop.Attributes["Position"]; if (attPosition == null) continue; MarkupAttribute attColor = tagColorStop.Attributes["Color"]; if (attColor == null) continue; fill.ColorStops.Add(new LinearGradientFillColorStop(attPosition.Value, attColor.Value)); } return fill; } break; } } } return null; }
private Outline OutlineFromTag(MarkupTagElement tag) { if (tag == null) return null; Outline outline = null; MarkupAttribute attOutlineType = tag.Attributes["Type"]; if (attOutlineType != null) { switch (attOutlineType.Value.ToLower()) { case "none": { break; } case "solid": { MarkupAttribute attColor = tag.Attributes["Color"]; if (attColor != null) { SolidOutline realOutline = new SolidOutline(); realOutline.Color = attColor.Value; outline = realOutline; } break; } case "inset": case "outset": { MarkupAttribute attLightColor = tag.Attributes["LightColor"]; MarkupAttribute attDarkColor = tag.Attributes["DarkColor"]; MarkupAttribute attColor = tag.Attributes["Color"]; if ((attLightColor != null && attDarkColor != null) || (attColor != null)) { ThreeDOutline realOutline = new ThreeDOutline(); switch (attOutlineType.Value.ToLower()) { case "inset": { realOutline.Type = ThreeDOutlineType.Inset; break; } case "outset": { realOutline.Type = ThreeDOutlineType.Outset; break; } } if (attLightColor != null && attDarkColor != null) { realOutline.LightColor = attLightColor.Value; realOutline.DarkColor = attDarkColor.Value; } else if (attColor != null) { realOutline.LightColor = attColor.Value; realOutline.DarkColor = attColor.Value; } outline = realOutline; } break; } } MarkupAttribute attOutlineWidth = tag.Attributes["Width"]; if (attOutlineWidth != null && outline != null) { outline.Width = Single.Parse(attOutlineWidth.Value); } } return outline; }
private Outline OutlineFromTag(MarkupTagElement tag) { if (tag == null) { return(null); } Outline outline = null; MarkupAttribute attOutlineType = tag.Attributes["Type"]; if (attOutlineType != null) { switch (attOutlineType.Value.ToLower()) { case "none": { break; } case "solid": { MarkupAttribute attColor = tag.Attributes["Color"]; if (attColor != null) { SolidOutline realOutline = new SolidOutline(); realOutline.Color = attColor.Value; outline = realOutline; } break; } case "inset": case "outset": { MarkupAttribute attLightColor = tag.Attributes["LightColor"]; MarkupAttribute attDarkColor = tag.Attributes["DarkColor"]; MarkupAttribute attColor = tag.Attributes["Color"]; if ((attLightColor != null && attDarkColor != null) || (attColor != null)) { ThreeDOutline realOutline = new ThreeDOutline(); switch (attOutlineType.Value.ToLower()) { case "inset": { realOutline.Type = ThreeDOutlineType.Inset; break; } case "outset": { realOutline.Type = ThreeDOutlineType.Outset; break; } } if (attLightColor != null && attDarkColor != null) { realOutline.LightColor = attLightColor.Value; realOutline.DarkColor = attDarkColor.Value; } else if (attColor != null) { realOutline.LightColor = attColor.Value; realOutline.DarkColor = attColor.Value; } outline = realOutline; } break; } } MarkupAttribute attOutlineWidth = tag.Attributes["Width"]; if (attOutlineWidth != null && outline != null) { outline.Width = Single.Parse(attOutlineWidth.Value); } } return(outline); }
private Fill FillFromTag(MarkupTagElement tag) { if (tag == null) { return(null); } MarkupAttribute attFillType = tag.Attributes["Type"]; if (attFillType != null) { switch (attFillType.Value.ToLower()) { case "none": { break; } case "solid": { MarkupAttribute attFillColor = tag.Attributes["Color"]; if (attFillColor != null) { return(new SolidFill(attFillColor.Value)); } break; } case "lineargradient": { MarkupAttribute attOrientation = tag.Attributes["Orientation"]; if (attOrientation == null) { return(null); } MarkupTagElement tagColorStops = (tag.Elements["ColorStops"] as MarkupTagElement); if (tagColorStops != null) { LinearGradientFill fill = new LinearGradientFill(); switch (attOrientation.Value.ToLower()) { case "horizontal": fill.Orientation = LinearGradientFillOrientation.Horizontal; break; case "vertical": fill.Orientation = LinearGradientFillOrientation.Vertical; break; } foreach (MarkupElement elColorStop in tagColorStops.Elements) { MarkupTagElement tagColorStop = (elColorStop as MarkupTagElement); if (tagColorStop == null) { continue; } if (tagColorStop.FullName != "ColorStop") { continue; } MarkupAttribute attPosition = tagColorStop.Attributes["Position"]; if (attPosition == null) { continue; } MarkupAttribute attColor = tagColorStop.Attributes["Color"]; if (attColor == null) { continue; } fill.ColorStops.Add(new LinearGradientFillColorStop(attPosition.Value, attColor.Value)); } return(fill); } break; } } } return(null); }
private MarkupObjectModel CreateDocument(ModelObjectModel model) { MarkupObjectModel momDocument = new MarkupObjectModel(); MarkupTagElement tagModel = new MarkupTagElement(); tagModel.FullName = "cr:model"; tagModel.Attributes.Add("xmlns:cr", "urn:net.alcetech.schemas.Concertroid.OPC.Model"); MarkupTagElement tagSettings = new MarkupTagElement(); tagSettings.FullName = "cr:settings"; MarkupTagElement tagSettingIgnoreEdgeFlag = new MarkupTagElement(); tagSettingIgnoreEdgeFlag.FullName = "cr:setting"; tagSettingIgnoreEdgeFlag.Attributes.Add("name", "ignoreEdgeFlag"); tagSettingIgnoreEdgeFlag.Attributes.Add("value", model.IgnoreEdgeFlag ? "true" : "false"); tagModel.Elements.Add(tagSettings); MarkupTagElement tagBones = new MarkupTagElement(); tagBones.FullName = "cr:bones"; foreach (ModelBone bone in model.Bones) { MarkupTagElement tagBone = new MarkupTagElement(); tagBone.FullName = "cr:bone"; tagBone.Attributes.Add("id", "b" + model.Bones.IndexOf(bone).ToString()); MarkupTagElement tagAngleLimit = new MarkupTagElement(); tagAngleLimit.FullName = "cr:angleLimit"; tagAngleLimit.Attributes.Add("enabled", bone.AngleLimit.Enabled ? "true" : "false"); tagAngleLimit.Elements.Add(bone.AngleLimit.Lower.ToXML("cr:lower")); tagAngleLimit.Elements.Add(bone.AngleLimit.Upper.ToXML("cr:upper")); tagBone.Elements.Add(tagAngleLimit); tagBone.Attributes.Add("type", BoneTypeToXML(bone.BoneType)); tagBone.Attributes.Add("childId", "b" + model.Bones.IndexOf(bone.ChildBone).ToString()); tagBone.Attributes.Add("ikNumber", bone.IKNumber.ToString()); tagBone.Attributes.Add("name", bone.Name); tagBone.Attributes.Add("parentId", "b" + model.Bones.IndexOf(bone.ParentBone).ToString()); tagBone.Elements.Add(bone.Position.ToXML("cr:position")); tagBone.Elements.Add(bone.Rotation.ToXML("cr:rotation")); tagBone.Elements.Add(bone.Vector3Offset.ToXML("cr:offset")); tagBones.Elements.Add(tagBone); } tagModel.Elements.Add(tagBones); MarkupTagElement tagExpressions = new MarkupTagElement(); tagExpressions.FullName = "cr:expressions"; foreach (ushort u in model.Expressions) { MarkupTagElement tagExpression = new MarkupTagElement(); tagExpression.FullName = "cr:expression"; tagExpression.Attributes.Add("value", u.ToString()); tagExpressions.Elements.Add(tagExpression); } tagModel.Elements.Add(tagExpressions); MarkupTagElement tagJoints = new MarkupTagElement(); tagJoints.FullName = "cr:joints"; foreach (ModelJoint joint in model.Joints) { MarkupTagElement tagJoint = new MarkupTagElement(); tagJoint.FullName = "cr:joint"; MarkupTagElement tagLimits = new MarkupTagElement(); tagLimits.FullName = "cr:limits"; tagLimits.Elements.Add(joint.LimitAngleHigh.ToXML("cr:angleHigh")); tagLimits.Elements.Add(joint.LimitAngleLow.ToXML("cr:angleLow")); tagLimits.Elements.Add(joint.LimitMoveHigh.ToXML("cr:moveHigh")); tagLimits.Elements.Add(joint.LimitMoveLow.ToXML("cr:moveLow")); tagJoint.Elements.Add(tagLimits); tagJoint.Attributes.Add("name", joint.Name); tagJoint.Elements.Add(joint.Position.ToXML("cr:position")); tagJoint.Elements.Add(joint.Rotation.ToXML("cr:rotation")); MarkupTagElement tagSpringConstraint = new MarkupTagElement(); tagSpringConstraint.FullName = "cr:springConstraint"; tagSpringConstraint.Elements.Add(joint.SpringConstraintMovementStiffness.ToXML("cr:movementStiffness")); tagSpringConstraint.Elements.Add(joint.SpringConstraintRotationStiffness.ToXML("cr:rotationStiffness")); tagJoint.Elements.Add(tagSpringConstraint); tagJoints.Elements.Add(tagJoint); } tagModel.Elements.Add(tagJoints); MarkupTagElement tagIKHandles = new MarkupTagElement(); tagIKHandles.FullName = "cr:ikHandles"; foreach (ModelIK ik in model.IK) { MarkupTagElement tagIKHandle = new MarkupTagElement(); tagIKHandle.FullName = "cr:ikHandle"; tagIKHandle.Attributes.Add("effectedBoneId", model.Bones.IndexOf(ik.EffBone).ToString()); tagIKHandle.Attributes.Add("index", ik.Index.ToString()); tagIKHandle.Attributes.Add("limitOnce", ik.LimitOnce.ToString()); tagIKHandle.Attributes.Add("loopCount", ik.LoopCount.ToString()); tagIKHandle.Attributes.Add("targetBoneId", model.Bones.IndexOf(ik.TargetBone).ToString()); MarkupTagElement tagBoneList = new MarkupTagElement(); tagBoneList.FullName = "cr:boneList"; foreach (ModelBone bone in ik.BoneList) { MarkupTagElement tagBone = new MarkupTagElement(); tagBone.FullName = "cr:boneReference"; tagBone.Attributes.Add("boneId", model.Bones.IndexOf(bone).ToString()); tagBoneList.Elements.Add(tagBone); } tagIKHandle.Elements.Add(tagBoneList); } tagModel.Elements.Add(tagIKHandles); MarkupTagElement tagSurfaces = new MarkupTagElement(); tagSurfaces.FullName = "cr:surfaces"; foreach (ModelSurface surf in model.Surfaces) { MarkupTagElement tagSurface = new MarkupTagElement(); tagSurface.FullName = "cr:surface"; MarkupTagElement tagTriangles = new MarkupTagElement(); tagTriangles.FullName = "cr:triangles"; foreach (ModelTriangle tri in surf.Triangles) { MarkupTagElement tagTriangle = new MarkupTagElement(); tagTriangle.FullName = "cr:triangle"; tagTriangle.Elements.Add(tri.Vertex1.ToXML("cr:vertex")); tagTriangle.Elements.Add(tri.Vertex2.ToXML("cr:vertex")); tagTriangle.Elements.Add(tri.Vertex3.ToXML("cr:vertex")); tagTriangles.Elements.Add(tagTriangle); } tagSurface.Elements.Add(tagTriangles); MarkupTagElement tagVertices = new MarkupTagElement(); tagVertices.FullName = "cr:vertices"; foreach (ModelVertex vtx in surf.Vertices) { tagVertices.Elements.Add(vtx.ToXML("cr:vertex")); } tagSurface.Elements.Add(tagVertices); tagSurfaces.Elements.Add(tagSurface); } tagModel.Elements.Add(tagSurfaces); MarkupTagElement tagRigidBodies = new MarkupTagElement(); tagRigidBodies.FullName = "cr:rigidBodies"; foreach (ModelRigidBody rb in model.RigidBodies) { MarkupTagElement tagRigidBody = new MarkupTagElement(); tagRigidBody.FullName = "cr:rigidBody"; tagRigidBody.Attributes.Add("boneId", "b" + model.Bones.IndexOf(rb.Bone).ToString()); tagRigidBody.Elements.Add(rb.BoxSize.ToXML("cr:boxSize")); tagRigidBody.Attributes.Add("boxType", rb.BoxType.ToString()); tagRigidBody.Attributes.Add("friction", rb.Friction.ToString()); tagRigidBody.Attributes.Add("groupId", rb.GroupID.ToString()); tagRigidBody.Attributes.Add("itype", rb.IType.ToString()); tagRigidBody.Attributes.Add("mass", rb.Mass.ToString()); tagRigidBody.Attributes.Add("mode", rb.Mode.ToString()); tagRigidBody.Attributes.Add("name", rb.Name); tagRigidBody.Elements.Add(rb.Position.ToXML("cr:position")); tagRigidBody.Attributes.Add("positionDamping", rb.PositionDamping.ToString()); tagRigidBody.Attributes.Add("restitution", rb.Restitution.ToString()); tagRigidBody.Elements.Add(rb.Rotation.ToXML("cr:rotation")); tagRigidBody.Attributes.Add("rotationDamping", rb.RotationDamping.ToString()); tagRigidBodies.Elements.Add(tagRigidBody); } tagModel.Elements.Add(tagRigidBodies); momDocument.Elements.Add(tagModel); return(momDocument); }
protected override void AfterLoadInternal(Stack <ObjectModel> objectModels) { base.AfterLoadInternal(objectModels); MarkupObjectModel mom = (objectModels.Pop() as MarkupObjectModel); ThemeObjectModel themes = (objectModels.Pop() as ThemeObjectModel); MarkupTagElement tagThemes = (mom.FindElement("AwesomeControls", "Theming", "Themes") as MarkupTagElement); if (tagThemes != null) { foreach (MarkupElement elTheme in tagThemes.Elements) { MarkupTagElement tagTheme = (elTheme as MarkupTagElement); if (tagTheme == null) { continue; } MarkupAttribute attThemeID = tagTheme.Attributes["ID"]; if (attThemeID == null) { continue; } Theme theme = new Theme(); UniversalEditor.Accessors.FileAccessor fa = (this.Accessor as UniversalEditor.Accessors.FileAccessor); if (fa != null) { theme.BasePath = System.IO.Path.GetDirectoryName(fa.FileName); } theme.ID = new Guid(attThemeID.Value); MarkupAttribute attInheritsThemeID = tagTheme.Attributes["InheritsThemeID"]; if (attInheritsThemeID != null) { theme.InheritsThemeID = new Guid(attInheritsThemeID.Value); } MarkupTagElement tagInformation = (tagTheme.Elements["Information"] as MarkupTagElement); if (tagInformation != null) { MarkupTagElement tagInformationTitle = (tagInformation.Elements["Title"] as MarkupTagElement); if (tagInformationTitle != null) { theme.Title = tagInformationTitle.Value; } } MarkupTagElement tagMetrics = (tagTheme.Elements["Metrics"] as MarkupTagElement); if (tagMetrics != null) { foreach (MarkupElement elMetric in tagMetrics.Elements) { MarkupTagElement tagMetric = (elMetric as MarkupTagElement); if (tagMetric == null) { continue; } MarkupAttribute attMetricName = tagMetric.Attributes["Name"]; if (attMetricName == null) { continue; } switch (tagMetric.FullName.ToLower()) { case "paddingmetric": { PaddingMetric metric = new PaddingMetric(); metric.Name = attMetricName.Value; MarkupAttribute attMetricLeft = tagMetric.Attributes["Left"]; if (attMetricLeft != null) { metric.Left = Single.Parse(attMetricLeft.Value); } MarkupAttribute attMetricTop = tagMetric.Attributes["Top"]; if (attMetricTop != null) { metric.Top = Single.Parse(attMetricTop.Value); } MarkupAttribute attMetricBottom = tagMetric.Attributes["Bottom"]; if (attMetricBottom != null) { metric.Bottom = Single.Parse(attMetricBottom.Value); } MarkupAttribute attMetricRight = tagMetric.Attributes["Right"]; if (attMetricRight != null) { metric.Right = Single.Parse(attMetricRight.Value); } theme.Metrics.Add(metric); break; } } } } MarkupTagElement tagColors = (tagTheme.Elements["Colors"] as MarkupTagElement); if (tagColors != null) { foreach (MarkupElement elColor in tagColors.Elements) { MarkupTagElement tagColor = (elColor as MarkupTagElement); if (tagColor == null) { continue; } if (tagColor.FullName != "Color") { continue; } MarkupAttribute attColorID = tagColor.Attributes["ID"]; MarkupAttribute attColorName = tagColor.Attributes["Name"]; if (attColorID == null && attColorName == null) { continue; } MarkupAttribute attColorValue = tagColor.Attributes["Value"]; if (attColorValue == null) { continue; } ThemeColor color = new ThemeColor(); if (attColorID != null) { color.ID = new Guid(attColorID.Value); } if (attColorName != null) { color.Name = attColorName.Value; } if (attColorValue != null) { color.Value = attColorValue.Value; } theme.Colors.Add(color); } } MarkupTagElement tagFonts = (tagTheme.Elements["Fonts"] as MarkupTagElement); if (tagFonts != null) { foreach (MarkupElement elFont in tagFonts.Elements) { MarkupTagElement tagFont = (elFont as MarkupTagElement); if (tagFont == null) { continue; } if (tagFont.FullName != "Font") { continue; } MarkupAttribute attFontName = tagFont.Attributes["Name"]; if (attFontName == null) { continue; } MarkupAttribute attFontValue = tagFont.Attributes["Value"]; if (attFontValue == null) { continue; } ThemeFont font = new ThemeFont(); font.Name = attFontName.Value; font.Value = attFontValue.Value; theme.Fonts.Add(font); } } MarkupTagElement tagStockImages = (tagTheme.Elements["StockImages"] as MarkupTagElement); if (tagStockImages != null) { foreach (MarkupElement elStockImage in tagStockImages.Elements) { MarkupTagElement tagStockImage = (elStockImage as MarkupTagElement); if (tagStockImage == null) { continue; } if (tagStockImage.FullName != "StockImage") { continue; } MarkupAttribute attStockImageName = tagStockImage.Attributes["Name"]; if (attStockImageName == null) { continue; } MarkupAttribute attStockImageFileName = tagStockImage.Attributes["FileName"]; if (attStockImageFileName == null) { continue; } ThemeStockImage stockImage = new ThemeStockImage(); stockImage.Name = attStockImageName.Value; stockImage.ImageFileName = attStockImageFileName.Value; theme.StockImages.Add(stockImage); } } MarkupTagElement tagProperties = (tagTheme.Elements["Properties"] as MarkupTagElement); if (tagProperties != null) { foreach (MarkupElement elProperty in tagProperties.Elements) { MarkupTagElement tagProperty = (elProperty as MarkupTagElement); if (tagProperty == null) { continue; } if (tagProperty.FullName != "Property") { continue; } MarkupAttribute attName = tagProperty.Attributes["Name"]; if (attName == null) { continue; } ThemeProperty property = new ThemeProperty(); property.Name = attName.Value; MarkupAttribute attValue = tagProperty.Attributes["Value"]; if (attValue != null) { property.Value = attValue.Value; } theme.Properties.Add(property); } } MarkupTagElement tagComponents = (tagTheme.Elements["Components"] as MarkupTagElement); if (tagComponents != null) { foreach (MarkupElement elComponent in tagComponents.Elements) { MarkupTagElement tagComponent = (elComponent as MarkupTagElement); if (tagComponent == null) { continue; } if (tagComponent.FullName != "Component") { continue; } MarkupAttribute attComponentID = tagComponent.Attributes["ID"]; if (attComponentID == null) { continue; } ThemeComponent component = new ThemeComponent(); component.ID = new Guid(attComponentID.Value); MarkupAttribute attInheritsComponentID = tagComponent.Attributes["InheritsComponentID"]; if (attInheritsComponentID != null) { component.InheritsComponentID = new Guid(attInheritsComponentID.Value); } MarkupTagElement tagComponentStates = (tagComponent.Elements["States"] as MarkupTagElement); if (tagComponentStates != null) { // if States is specified, only apply to specific states foreach (MarkupElement elState in tagComponentStates.Elements) { MarkupTagElement tagState = (elState as MarkupTagElement); if (tagState == null) { continue; } if (tagState.FullName != "State") { continue; } MarkupAttribute attStateID = tagState.Attributes["ID"]; if (attStateID == null) { continue; } ThemeComponentState state = new ThemeComponentState(); state.ID = new Guid(attStateID.Value); MarkupAttribute attStateName = tagState.Attributes["Name"]; if (attStateName != null) { state.Name = attStateName.Value; } component.States.Add(state); } } MarkupTagElement tagRenderings = (tagComponent.Elements["Renderings"] as MarkupTagElement); if (tagRenderings != null) { foreach (MarkupElement elRendering in tagRenderings.Elements) { MarkupTagElement tagRendering = (elRendering as MarkupTagElement); if (tagRendering == null) { continue; } if (tagRendering.FullName != "Rendering") { continue; } MarkupTagElement tagRenderingActions = (tagRendering.Elements["Actions"] as MarkupTagElement); if (tagRenderingActions == null) { continue; } Rendering rendering = new Rendering(); foreach (MarkupElement elRenderingAction in tagRenderingActions.Elements) { MarkupTagElement tagRenderingAction = (elRenderingAction as MarkupTagElement); if (tagRenderingAction == null) { continue; } switch (tagRenderingAction.FullName) { case "Rectangle": { MarkupAttribute attX = tagRenderingAction.Attributes["X"]; MarkupAttribute attY = tagRenderingAction.Attributes["Y"]; MarkupAttribute attWidth = tagRenderingAction.Attributes["Width"]; MarkupAttribute attHeight = tagRenderingAction.Attributes["Height"]; RectangleRenderingAction item = new RectangleRenderingAction(); item.X = RenderingExpression.Parse(attX.Value); item.Y = RenderingExpression.Parse(attY.Value); item.Width = RenderingExpression.Parse(attWidth.Value); item.Height = RenderingExpression.Parse(attHeight.Value); item.Outline = OutlineFromTag(tagRenderingAction.Elements["Outline"] as MarkupTagElement); item.Fill = FillFromTag(tagRenderingAction.Elements["Fill"] as MarkupTagElement); rendering.Actions.Add(item); break; } case "Line": { LineRenderingAction item = new LineRenderingAction(); MarkupAttribute attX1 = tagRenderingAction.Attributes["X1"]; if (attX1 != null) { item.X1 = RenderingExpression.Parse(attX1.Value); } MarkupAttribute attX2 = tagRenderingAction.Attributes["X2"]; if (attX2 != null) { item.X2 = RenderingExpression.Parse(attX2.Value); } MarkupAttribute attY1 = tagRenderingAction.Attributes["Y1"]; if (attY1 != null) { item.Y1 = RenderingExpression.Parse(attY1.Value); } MarkupAttribute attY2 = tagRenderingAction.Attributes["Y2"]; if (attY2 != null) { item.Y2 = RenderingExpression.Parse(attY2.Value); } item.Outline = OutlineFromTag(tagRenderingAction.Elements["Outline"] as MarkupTagElement); rendering.Actions.Add(item); break; } case "Text": { MarkupAttribute attX = tagRenderingAction.Attributes["X"]; MarkupAttribute attY = tagRenderingAction.Attributes["Y"]; MarkupAttribute attWidth = tagRenderingAction.Attributes["Width"]; MarkupAttribute attHeight = tagRenderingAction.Attributes["Height"]; if (attX == null || attY == null) { continue; } MarkupAttribute attHorizontalAlignment = tagRenderingAction.Attributes["HorizontalAlignment"]; MarkupAttribute attVerticalAlignment = tagRenderingAction.Attributes["VerticalAlignment"]; TextRenderingAction item = new TextRenderingAction(); item.X = RenderingExpression.Parse(attX.Value); item.Y = RenderingExpression.Parse(attY.Value); if (attWidth != null) { item.Width = RenderingExpression.Parse(attWidth.Value); } if (attWidth != null) { item.Height = RenderingExpression.Parse(attHeight.Value); } if (attHorizontalAlignment != null) { switch (attHorizontalAlignment.Value.ToLower()) { case "center": { item.HorizontalAlignment = HorizontalAlignment.Center; break; } case "justify": { item.HorizontalAlignment = HorizontalAlignment.Justify; break; } case "left": { item.HorizontalAlignment = HorizontalAlignment.Left; break; } case "right": { item.HorizontalAlignment = HorizontalAlignment.Right; break; } } } if (attVerticalAlignment != null) { switch (attVerticalAlignment.Value.ToLower()) { case "bottom": { item.VerticalAlignment = VerticalAlignment.Bottom; break; } case "middle": { item.VerticalAlignment = VerticalAlignment.Middle; break; } case "top": { item.VerticalAlignment = VerticalAlignment.Top; break; } } } MarkupAttribute attColor = tagRenderingAction.Attributes["Color"]; if (attColor != null) { item.Color = attColor.Value; } MarkupAttribute attFont = tagRenderingAction.Attributes["Font"]; if (attFont != null) { item.Font = attFont.Value; } MarkupAttribute attValue = tagRenderingAction.Attributes["Value"]; if (attValue != null) { item.Value = attValue.Value; } rendering.Actions.Add(item); break; } } } MarkupTagElement tagRenderingStates = (tagRendering.Elements["States"] as MarkupTagElement); if (tagRenderingStates != null) { // if States is specified, only apply to specific states foreach (MarkupElement elState in tagRenderingStates.Elements) { MarkupTagElement tagState = (elState as MarkupTagElement); if (tagState == null) { continue; } if (tagState.FullName != "State") { continue; } MarkupAttribute attStateID = tagState.Attributes["ID"]; if (attStateID == null) { continue; } ThemeComponentStateReference state = new ThemeComponentStateReference(); state.StateID = new Guid(attStateID.Value); rendering.States.Add(state); } } component.Renderings.Add(rendering); } } theme.Components.Add(component); } } themes.Themes.Add(theme); } } }
protected override void AfterLoadInternal(Stack <ObjectModel> objectModels) { base.AfterLoadInternal(objectModels); MarkupObjectModel mom = (objectModels.Pop() as MarkupObjectModel); MochaClassLibraryObjectModel mcl = (objectModels.Pop() as MochaClassLibraryObjectModel); MarkupTagElement tagMocha = (mom.Elements["mocha"] as MarkupTagElement); if (tagMocha == null) { throw new InvalidDataFormatException("file does not contain top-level 'mocha' tag"); } MarkupTagElement tagLibraries = (tagMocha.Elements["libraries"] as MarkupTagElement); if (tagLibraries != null) { for (int i = 0; i < tagLibraries.Elements.Count; i++) { MochaLibrary library = LoadLibrary(mcl, tagLibraries.Elements[i] as MarkupTagElement); if (library == null) { continue; } mcl.Libraries.Merge(library); } } MarkupTagElement tagTenants = (tagMocha.Elements["tenants"] as MarkupTagElement); if (tagTenants != null) { foreach (MarkupTagElement tagTenant in tagTenants.Elements.OfType <MarkupTagElement>()) { if (tagTenant == null) { continue; } if (tagTenant.FullName != "tenant") { continue; } MarkupAttribute attTenantID = tagTenant.Attributes["id"]; MarkupAttribute attTenantName = tagTenant.Attributes["name"]; if (attTenantID == null || attTenantName == null) { continue; } MochaTenant tenant = new MochaTenant(); tenant.ID = new Guid(attTenantID.Value); tenant.Name = attTenantName.Value; MarkupTagElement tagLibraryReferences = tagTenant.Elements["libraryReferences"] as MarkupTagElement; if (tagLibraryReferences != null) { foreach (MarkupTagElement tagLibraryReference in tagLibraryReferences.Elements.OfType <MarkupTagElement>()) { MarkupAttribute attLibraryId = tagLibraryReference.Attributes["libraryId"]; if (attLibraryId == null) { continue; } tenant.LibraryReferences.Add(new MochaLibraryReference(new Guid(attLibraryId.Value))); } } MarkupTagElement tagInstances = tagTenant.Elements["instances"] as MarkupTagElement; if (tagInstances != null) { foreach (MarkupTagElement tagInstance in tagInstances.Elements.OfType <MarkupTagElement>()) { MochaInstance inst = LoadInstance(tenant, tagInstance); tenant.Instances.Add(inst); } } mcl.Tenants.Add(tenant); } } }
private void LoadManufacturers(MarkupTagElement tag, LightingObjectModel lighting) { foreach (MarkupElement el1 in tag.Elements) { MarkupTagElement tag1 = (el1 as MarkupTagElement); if (tag1 == null) continue; if (tag1.FullName != "Manufacturer") continue; MarkupAttribute attID = tag1.Attributes["ID"]; if (attID == null) continue; Manufacturer item = new Manufacturer(); item.ID = new Guid(attID.Value); MarkupTagElement tagInformation = (tag1.Elements["Information"] as MarkupTagElement); if (tagInformation != null) { MarkupTagElement tagTitle = (tagInformation.Elements["Title"] as MarkupTagElement); if (tagTitle != null) item.Title = tagTitle.Value; } lighting.Manufacturers.Add(item); } }
private MochaLibrary LoadLibrary(MochaClassLibraryObjectModel parent, MarkupTagElement tag) { if (tag == null) { return(null); } if (tag.FullName != "library") { return(null); } MarkupAttribute attGuid = tag.Attributes["id"]; if (attGuid == null) { return(null); } Guid id = new Guid(attGuid.Value); MochaLibrary library = parent.Libraries[id]; if (library == null) { library = new MochaLibrary(); library.ID = id; } MarkupAttribute attDefaultObjectSourceId = tag.Attributes["defaultObjectSourceId"]; if (attDefaultObjectSourceId != null) { library.DefaultObjectSourceID = new Guid(attDefaultObjectSourceId.Value); } else { library.DefaultObjectSourceID = global::Mocha.Core.KnownInstanceGuids.ObjectSources.System; } MarkupTagElement tagMetadata = tag.Elements["metadata"] as MarkupTagElement; if (tagMetadata != null) { for (int i = 0; i < tagMetadata.Elements.Count; i++) { MarkupTagElement tagMetadataItem = tagMetadata.Elements[i] as MarkupTagElement; if (tagMetadataItem == null) { continue; } library.Metadata.Add(new MochaLibraryMetadata(tagMetadataItem.Name, tagMetadataItem.Value)); } } MarkupTagElement tagInstances = tag.Elements["instances"] as MarkupTagElement; if (tagInstances != null) { for (int i = 0; i < tagInstances.Elements.Count; i++) { MochaInstance inst = LoadInstance(library, tagInstances.Elements[i] as MarkupTagElement); if (inst == null) { continue; } library.Instances.Add(inst); } } return(library); }
private void LoadFixtures(MarkupTagElement tag, LightingObjectModel lighting) { foreach (MarkupElement el1 in tag.Elements) { MarkupTagElement tag1 = (el1 as MarkupTagElement); if (tag1 == null) continue; if (tag1.FullName != "Fixture") continue; MarkupAttribute attID = tag1.Attributes["ID"]; if (attID == null) continue; Fixture item = new Fixture(); item.ID = new Guid(attID.Value); MarkupAttribute attManufacturerID = tag1.Attributes["ManufacturerID"]; if (attManufacturerID != null) item.ManufacturerID = new Guid(attManufacturerID.Value); MarkupTagElement tagInformation = (tag1.Elements["Information"] as MarkupTagElement); if (tagInformation != null) { MarkupTagElement tagTitle = (tagInformation.Elements["Title"] as MarkupTagElement); if (tagTitle != null) item.Title = tagTitle.Value; } #region Channels { MarkupTagElement tagChannels = (tag1.Elements["Channels"] as MarkupTagElement); if (tagChannels != null) { foreach (MarkupElement elChannel in tagChannels.Elements) { MarkupTagElement tagChannel = (elChannel as MarkupTagElement); if (tagChannel == null) continue; if (tagChannel.FullName != "Channel") continue; MarkupAttribute attChannelID = tagChannel.Attributes["ID"]; if (attChannelID == null) continue; FixtureChannel channel = new FixtureChannel(); channel.ID = new Guid(attChannelID.Value); MarkupTagElement tagChannelInformation = (tagChannel.Elements["Information"] as MarkupTagElement); if (tagChannelInformation != null) { MarkupTagElement tagChannelTitle = (tagChannelInformation.Elements["Title"] as MarkupTagElement); if (tagChannelTitle != null) channel.Title = tagChannelTitle.Value; } MarkupTagElement tagChannelValues = (tagChannel.Elements["Values"] as MarkupTagElement); if (tagChannelValues != null) { foreach (MarkupElement elChannelValue in tagChannelValues.Elements) { MarkupTagElement tagChannelValue = (elChannelValue as MarkupTagElement); if (tagChannelValue == null) continue; MarkupAttribute attTitle = (tagChannelValue.Attributes["Title"] as MarkupAttribute); string title = null; if (attTitle != null) title = attTitle.Value; switch (tagChannelValue.FullName.ToLower()) { case "range": { FixtureChannelValueRange value = new FixtureChannelValueRange(); MarkupAttribute attStartingValue = tagChannelValue.Attributes["From"]; MarkupAttribute attEndingValue = tagChannelValue.Attributes["Until"]; value.Title = title; value.StartingValue = Byte.Parse(attStartingValue.Value); value.EndingValue = Byte.Parse(attEndingValue.Value); channel.Values.Add(value); break; } case "static": { FixtureChannelValueStatic value = new FixtureChannelValueStatic(); MarkupAttribute attStartingValue = tagChannelValue.Attributes["From"]; MarkupAttribute attEndingValue = tagChannelValue.Attributes["Until"]; value.Title = title; value.StartingValue = Byte.Parse(attStartingValue.Value); value.EndingValue = Byte.Parse(attEndingValue.Value); channel.Values.Add(value); break; } default: { Console.WriteLine("alxml: unknown channel value type '" + tagChannelValue.FullName + "'"); break; } } } } item.Channels.Add(channel); } } } #endregion #region Modes { MarkupTagElement tagModes = (tag1.Elements["Modes"] as MarkupTagElement); if (tagModes != null) { foreach (MarkupElement elMode in tagModes.Elements) { MarkupTagElement tagMode = (elMode as MarkupTagElement); LoadMode(tagMode, item); } } } #endregion lighting.Fixtures.Add(item); } }
private bool LoadMode(MarkupTagElement tag, Fixture fixture) { if (tag == null) return false; if (tag.FullName != "Mode") return false; MarkupAttribute attModeID = tag.Attributes["ID"]; if (attModeID == null) return false; FixtureMode mode = new FixtureMode(); mode.ID = new Guid(attModeID.Value); MarkupAttribute attTitle = tag.Attributes["Title"]; if (attTitle != null) mode.Title = attTitle.Value; MarkupTagElement tagChannels = (tag.Elements["Channels"] as MarkupTagElement); foreach (MarkupElement elChannel in tagChannels.Elements) { MarkupTagElement tagChannel = (elChannel as MarkupTagElement); if (tagChannel == null) continue; if (tagChannel.FullName != "Channel") continue; MarkupAttribute attChannelID = tagChannel.Attributes["ID"]; if (attChannelID == null) continue; MarkupAttribute attRelativeOffset = tagChannel.Attributes["RelativeOffset"]; FixtureModeChannel channel = new FixtureModeChannel(); channel.ChannelID = new Guid(attChannelID.Value); int relativeOffset = 0; if (attRelativeOffset != null && Int32.TryParse(attRelativeOffset.Value, out relativeOffset)) { channel.RelativeOffset = relativeOffset; } mode.Channels.Add(channel); } fixture.Modes.Add(mode); return true; }