示例#1
0
        public IfcProject AddProject(string name, string description)
        {
            var p = new IfcProject(IfcGuid.IfcGuid.ToIfcGuid(Guid.NewGuid()));

            p.Name        = name;
            p.Description = description;
            storage.AddInstance(p);
            return(p);
        }
示例#2
0
        /// <summary>
        /// Create a Model given a STEP file.
        /// </summary>
        /// <param name="STEPfilePath">The path to the STEP file.</param>
        /// <returns>A Model.</returns>
        /// <exception cref="FileNotFoundException">The specified file path does not exist.</exception>
        public Document(string STEPfilePath, IStorageProvider storage, out IList <STEPError> errors)
        {
            if (!File.Exists(STEPfilePath))
            {
                throw new FileNotFoundException($"The specified IFC STEP file does not exist: {STEPfilePath}.");
            }

            this.storage = storage;

            using (FileStream fs = new FileStream(STEPfilePath, FileMode.Open))
            {
                var input  = new AntlrInputStream(fs);
                var lexer  = new STEP.STEPLexer(input);
                var tokens = new CommonTokenStream(lexer);

                var parser = new STEP.STEPParser(tokens);
                parser.BuildParseTree = true;

                var tree   = parser.file();
                var walker = new ParseTreeWalker();

                var listener = new STEP.STEPListener();
                walker.Walk(listener, tree);

                var err = new List <STEPError>();
                foreach (var data in listener.InstanceData)
                {
                    if (data.Value.ConstructedGuid != null && storage.InstanceById(data.Value.ConstructedGuid) != null)
                    {
                        // Instance may have been previously constructed as the result
                        // of another construction.
                        continue;
                    }

                    var instance = ConstructRecursive(data.Value, listener.InstanceData, data.Key, err);
                    storage.AddInstance(instance);
                }
                errors = err;
            }
        }