Beispiel #1
0
        protected override void BeforeSaveInternal(Stack <ObjectModel> objectModels)
        {
            base.BeforeSaveInternal(objectModels);

            MochaClassLibraryObjectModel mcl = (objectModels.Pop() as MochaClassLibraryObjectModel);
            MarkupObjectModel            mom = new MarkupObjectModel();

            objectModels.Push(mom);
        }
        protected override void BeforeSaveInternal(Stack<ObjectModel> objectModels)
        {
            base.BeforeSaveInternal(objectModels);

            LightingObjectModel lighting = (objectModels.Pop() as LightingObjectModel);
            MarkupObjectModel mom = new MarkupObjectModel();

            objectModels.Push(mom);
        }
Beispiel #3
0
        protected override void BeforeSaveInternal(Stack <ObjectModel> objectModels)
        {
            base.BeforeSaveInternal(objectModels);

            ThemeObjectModel  theme = (objectModels.Pop() as ThemeObjectModel);
            MarkupObjectModel mom   = new MarkupObjectModel();



            objectModels.Push(mom);
        }
Beispiel #4
0
            protected override void BeforeSaveInternal(Stack <ObjectModel> objectModels)
            {
                ModelObjectModel   model   = (objectModels.Pop() as ModelObjectModel);
                PackageObjectModel package = new PackageObjectModel();

                MarkupObjectModel momDocument = CreateDocument(model);

                File file = package.FileSystem.AddFile("model/document.xml");

                file.SetObjectModel <MarkupObjectModel>(new XMLDataFormat(), momDocument);

                objectModels.Push(package);

                base.BeforeSaveInternal(objectModels);
            }
        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);
            }
        }
        protected override void BeforeSaveInternal(Stack<ObjectModel> objectModels)
        {
            base.BeforeSaveInternal(objectModels);

            ThemeObjectModel theme = (objectModels.Pop() as ThemeObjectModel);
            MarkupObjectModel mom = new MarkupObjectModel();

            objectModels.Push(mom);
        }
Beispiel #7
0
        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);
                }
            }
        }
Beispiel #8
0
        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);
                }
            }
        }
Beispiel #9
0
            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);
            }