Пример #1
0
        internal static ThreeMfModel LoadXml(XElement root, Package package)
        {
            var model = new ThreeMfModel();

            model.ParseModelUnits(root.Attribute(UnitAttributeName)?.Value);
            var requiredNamespaces = (root.Attribute(RequiredExtensionsAttributeName)?.Value ?? string.Empty)
                                     .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                     .Select(prefix => root.GetNamespaceOfPrefix(prefix).NamespaceName);

            foreach (var rns in requiredNamespaces)
            {
                if (!KnownExtensionNamespaces.Contains(rns))
                {
                    throw new ThreeMfParseException($"The required namespace '{rns}' is not supported.");
                }
            }

            // metadata
            model.Title            = GetMetadataValue(root, Metadata_Title);
            model.Designer         = GetMetadataValue(root, Metadata_Designer);
            model.Description      = GetMetadataValue(root, Metadata_Description);
            model.Copyright        = GetMetadataValue(root, Metadata_Copyright);
            model.LicenseTerms     = GetMetadataValue(root, Metadata_LicenseTerms);
            model.Rating           = GetMetadataValue(root, Metadata_Rating);
            model.CreationDate     = GetMetadataValue(root, Metadata_CreationDate);
            model.ModificationDate = GetMetadataValue(root, Metadata_ModificationDate);

            var resourceMap = model.ParseResources(root.Element(ResourcesName), package);

            model.ParseBuild(root.Element(BuildName), resourceMap);

            return(model);
        }
Пример #2
0
        public static ThreeMfFile Load(Package package)
        {
            var file = new ThreeMfFile();

            foreach (var modelRelationship in package.GetRelationshipsByType(ModelRelationshipType))
            {
                var modelUri  = modelRelationship.TargetUri;
                var modelPart = package.GetPart(modelUri);
                using (var modelStream = modelPart.GetStream())
                {
                    var document = XDocument.Load(modelStream);
                    var model    = ThreeMfModel.LoadXml(document.Root, package);
                    file.Models.Add(model);
                }
            }

            return(file);
        }