コード例 #1
0
        /// <summary>
        /// Sets up the basic parameters any model must provide, units, ownership etc
        /// </summary>
        /// <param name="projectName">Name of the project</param>
        /// <returns></returns>
        private XbimModel CreateandInitModel(string projectName)
        {
            XbimModel model = XbimModel.CreateModel(projectName + ".xBIM");;  //create an empty model

            //Begin a transaction as all changes to a model are transacted
            using (XbimReadWriteTransaction txn = model.BeginTransaction("Initialise Model"))
            {
                //do once only initialisation of model application and editor values
                model.DefaultOwningUser.ThePerson.GivenName              = "John";
                model.DefaultOwningUser.ThePerson.FamilyName             = "Bloggs";
                model.DefaultOwningUser.TheOrganization.Name             = "Department of Building";
                model.DefaultOwningApplication.ApplicationIdentifier     = "Construction Software inc.";
                model.DefaultOwningApplication.ApplicationDeveloper.Name = "Construction Programmers Ltd.";
                model.DefaultOwningApplication.ApplicationFullName       = "Ifc sample programme";
                model.DefaultOwningApplication.Version = "2.0.1";

                //set up a project and initialise the defaults

                IfcProject project = model.Instances.New <IfcProject>();
                project.Initialize(ProjectUnits.SIUnitsUK);
                project.Name = "testProject";
                project.OwnerHistory.OwningUser        = model.DefaultOwningUser;
                project.OwnerHistory.OwningApplication = model.DefaultOwningApplication;

                //validate and commit changes
                if (model.Validate(txn.Modified(), Console.Out) == 0)
                {
                    txn.Commit();
                    return(model);
                }
            }
            return(null); //failed so return nothing
        }
コード例 #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        public COBieXBimSerialiser(string fileName, ReportProgressDelegate progressHandler)
        {
            string fileNameDB = Path.ChangeExtension(fileName, ".xBIM");

            XBimContext         = new COBieXBimContext(XbimModel.CreateModel(fileNameDB), progressHandler);
            XBimContext.IsMerge = false;
            FileName            = fileName;
            MergeGeometryOnly   = true;
        }
コード例 #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="fileName">.xBIM file name and path</param>
        public COBieXBimSerialiser(string fileName)
        {
            string fileNameDB = Path.ChangeExtension(fileName, ".xBIM");

            XBimContext         = new COBieXBimContext(XbimModel.CreateModel(fileNameDB));
            XBimContext.IsMerge = false;
            FileName            = fileName;
            MergeGeometryOnly   = true;
        }
コード例 #4
0
        public void ExtractIfcGeometryEntitiesTest()
        {
            using (var source = new XbimModel())
            {
                PropertyTranformDelegate propTransform = delegate(IfcMetaProperty prop, object toCopy)
                {
                    if (typeof(IfcProduct).IsAssignableFrom(toCopy.GetType()))
                    {
                        if (prop.PropertyInfo.Name == "ObjectPlacement" || prop.PropertyInfo.Name == "Representation")
                        {
                            return(null);
                        }
                    }
                    if (typeof(IfcTypeProduct).IsAssignableFrom(toCopy.GetType()))
                    {
                        if (prop.PropertyInfo.Name == "RepresentationMaps")
                        {
                            return(null);
                        }
                    }
                    return(prop.PropertyInfo.GetValue(toCopy, null));//just pass through the value
                };

                //source.Open("BIM Logo-LetterM.xBIM");
                //source.SaveAs("WithGeometry.ifc");
                string modelName     = @"4walls1floorSite";
                string xbimModelName = Path.ChangeExtension(modelName, "xbim");

                source.CreateFrom(Path.ChangeExtension(modelName, "ifc"), null, null, true);

                using (var target = XbimModel.CreateModel(Path.ChangeExtension(modelName + "_NoGeom", "xbim")))
                {
                    target.AutoAddOwnerHistory = false;
                    using (var txn = target.BeginTransaction())
                    {
                        var copied = new XbimInstanceHandleMap(source, target);

                        foreach (var item in source.Instances.OfType <IfcRoot>())
                        {
                            target.InsertCopy(item, copied, txn, propTransform, false);
                        }
                        txn.Commit();
                    }

                    target.SaveAs(Path.ChangeExtension(modelName + "_NoGeom", "ifc"));
                    target.Close();
                }

                source.Close();
                // XbimModel.Compact(Path.ChangeExtension(modelName + "_NoGeom", "xbim"), Path.ChangeExtension(modelName + "_NoGeom_Compacted", "xbim"));
                //the two files should be the same
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: bangush/xBim-Toolkit
 private static XbimModel CreateModel(string name)
 {
     try
     {
         return(XbimModel.CreateModel(name, XbimDBAccess.ReadWrite)); //create and open a model for readwrite
     }
     catch (Exception e)
     {
         Logger.Error("Failed to create Database", e);
         return(null);
     }
 }
コード例 #6
0
        /// <summary>
        /// Creat the federated file
        /// </summary>
        /// <param name="file">FileInfo for the xbimf file</param>
        /// <param name="author">Author name</param>
        /// <param name="organisation">Orgsnisation Name</param>
        /// <param name="prjName">Project Name</param>
        public void Create(FileInfo file, string author, string organisation, string prjName = null)
        {
            FileNameXbimf = file;
            //_fedModel = XbimModel.CreateTemporaryModel();
            _fedModel = XbimModel.CreateModel(file.FullName, XbimDBAccess.ReadWrite);

            _fedModel.Initialise(author, organisation, "xBIM", "xBIM Team", ""); //"" is version, but none to grab as yet

            using (var txn = _fedModel.BeginTransaction())
            {
                _fedModel.IfcProject.Name = (prjName != null) ? prjName : string.Empty;
                _fedModel.Header          = new IfcFileHeader(IfcFileHeader.HeaderCreationMode.InitWithXbimDefaults);
                txn.Commit();
            }
        }
コード例 #7
0
        static private XbimModel CreateandInitModel(HndzProject hndzProject)
        {
            //IfcRelAggregates
            //Crashes here.....Fixed in this update :D

            XbimModel model = XbimModel.CreateModel(hndzProject.Name + "No." + hndzProject.GlobalId + ".xBIM", Xbim.XbimExtensions.XbimDBAccess.ReadWrite); //create an empty model

            if (model != null)
            {
                //Begin a transaction as all changes to a model are transacted
                using (XbimReadWriteTransaction txn = model.BeginTransaction("Initialize Model"))
                {
                    //do once only initialization of model application and editor values
                    model.DefaultOwningUser.ThePerson.GivenName              = hndzProject.Owner.Name;
                    model.DefaultOwningUser.ThePerson.FamilyName             = hndzProject.Owner.LastName;
                    model.DefaultOwningUser.TheOrganization.Name             = hndzProject.Owner.Organization;
                    model.DefaultOwningApplication.ApplicationIdentifier     = IFCFileResources.ApplicationIdentifier;
                    model.DefaultOwningApplication.ApplicationDeveloper.Name = IFCFileResources.ApplicationDevelopers;
                    model.DefaultOwningApplication.ApplicationFullName       = IFCFileResources.ApplicationFullName;
                    model.DefaultOwningApplication.Version = IFCFileResources.CurrentApplicationVersion;

                    //set up a project and initialize the defaults

                    var project = model.Instances.New <IfcProject>();
                    project.Initialize(ProjectUnits.SIUnitsUK);
                    project.Name = hndzProject.Name;
                    project.OwnerHistory.OwningUser        = model.DefaultOwningUser;
                    project.OwnerHistory.OwningApplication = model.DefaultOwningApplication;

                    //validate and commit changes
                    if (model.Validate(txn.Modified(), Console.Out) == 0)
                    {
                        txn.Commit();
                        return(model);
                    }
                }
            }
            return(null); //failed so return nothing
        }
コード例 #8
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("No Ifc or xBim file specified");
                return;
            }
            var fileName = args[0];

            Console.WriteLine("Reading " + fileName);

            using (var model = GetModel(fileName))
            {
                if (model != null)
                {
                    var context = new Xbim3DModelContext(model);
                    context.CreateContext(geomStorageType: XbimGeometryType.PolyhedronBinary);
                    var wexBimFilename = Path.ChangeExtension(fileName, "wexBIM");
                    using (var wexBiMfile = new FileStream(wexBimFilename, FileMode.Create, FileAccess.Write))
                    {
                        using (var wexBimBinaryWriter = new BinaryWriter(wexBiMfile))
                        {
                            Console.WriteLine("Creating " + wexBimFilename);
                            context.Write(wexBimBinaryWriter);
                            wexBimBinaryWriter.Close();
                        }
                        wexBiMfile.Close();
                    }
                    //now do the DPoW files
                    var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
                    var fileDirectoryName        = Path.GetDirectoryName(fileName);
                    var facilities = new List <Facility>();
                    var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(model, facilities);
                    facilities = ifcToCoBieLiteUkExchanger.Convert();

                    var facilityNumber = 0;

                    foreach (var facility in facilities)
                    {
                        var dpow = "DPoW";
                        if (facilities.Count > 1)
                        {
                            dpow += ++facilityNumber;
                        }
                        // ReSharper disable AssignNullToNotNullAttribute
                        var dPoWFile = Path.Combine(fileDirectoryName, fileNameWithoutExtension + "_" + dpow);
                        // ReSharper restore AssignNullToNotNullAttribute
                        dPoWFile = Path.ChangeExtension(dPoWFile, "json");
                        Console.WriteLine("Creating " + dPoWFile);

                        facility.WriteJson(dPoWFile);
                        string cobieFile = Path.ChangeExtension(dPoWFile, "Xlsx");
                        Console.WriteLine("Creating " + cobieFile);
                        string error;
                        facility.WriteCobie(cobieFile, out error);
                        if (!string.IsNullOrWhiteSpace(error))
                        {
                            Console.WriteLine("COBie Errors: " + error);
                        }

                        dPoWFile = Path.ChangeExtension(dPoWFile, "xml");
                        Console.WriteLine("Creating " + dPoWFile);
                        // facility.WriteXml(dPoWFile);
                        var req                 = Facility.ReadJson(@"..\..\Tests\ValidationFiles\Lakeside_Restaurant-stage6-COBie.json");
                        var validator           = new FacilityValidator();
                        var result              = validator.Validate(req, facility);
                        var verificationResults = Path.ChangeExtension(dPoWFile, "verified.xlsx");
                        Console.WriteLine("Creating " + verificationResults);
                        //create report
                        using (var stream = File.Create(verificationResults))
                        {
                            var report = new ExcelValidationReport();
                            report.Create(result, stream, ExcelValidationReport.SpreadSheetFormat.Xlsx);
                            stream.Close();
                        }

                        facility.ValidateUK2012(Console.Out, true);
                        string cobieValidatedFile = Path.ChangeExtension(dPoWFile, "Validated.Xlsx");
                        facility.WriteCobie(cobieValidatedFile, out error);
                        dPoWFile = Path.ChangeExtension(dPoWFile, "xbim");
                        Console.WriteLine("Creating " + dPoWFile);
                        using (var ifcModel = XbimModel.CreateModel(dPoWFile))
                        {
                            ifcModel.Initialise("Xbim Tester", "XbimTeam", "Xbim.Exchanger", "Xbim Development Team", "3.0");
                            ifcModel.ReloadModelFactors();
                            using (var txn = ifcModel.BeginTransaction("Convert from COBieLiteUK"))
                            {
                                var coBieLiteUkToIfcExchanger = new CoBieLiteUkToIfcExchanger(facility, ifcModel);
                                coBieLiteUkToIfcExchanger.Convert();
                                txn.Commit();
                                //var err = model.Validate(model.Instances, Console.Out);
                            }
                            dPoWFile = Path.ChangeExtension(dPoWFile, "ifc");
                            Console.WriteLine("Creating " + dPoWFile);
                            ifcModel.SaveAs(dPoWFile, XbimStorageType.IFC);
                            ifcModel.Close();
                        }
                    }
                    model.Close();
                }
            }
            Console.WriteLine("Press any key to exit");
            Console.Read();
        }