/// <summary>
        /// Validate Model Object Foe Errors
        /// </summary>
        /// <param name="trans"></param>
        /// <returns></returns>
        public String Validate(XbimReadWriteTransaction trans)
        {
            var sw     = new StringWriter();
            var errors = Model.Validate(trans.Modified(), sw);

            return(errors > 0 ? sw.ToString() : null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add the IfcConstructionProductResource to the Model object
        /// </summary>
        /// <param name="cOBieSheet">COBieSheet of COBieSpareRow to read data from</param>
        public void SerialiseSpare(COBieSheet <COBieSpareRow> cOBieSheet)
        {
            using (XbimReadWriteTransaction trans = Model.BeginTransaction("Add Spare"))
            {
                try
                {
                    int count = 1;
                    IfcTypeObjects = Model.FederatedInstances.OfType <IfcTypeObject>();

                    ProgressIndicator.ReportMessage("Starting Spares...");
                    ProgressIndicator.Initialise("Creating Spares", cOBieSheet.RowCount);
                    for (int i = 0; i < cOBieSheet.RowCount; i++)
                    {
                        BumpTransaction(trans, count);
                        count++;
                        ProgressIndicator.IncrementAndUpdate();
                        COBieSpareRow row = cOBieSheet[i];
                        AddSpare(row);
                    }
                    ProgressIndicator.Finalise();
                    trans.Commit();
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Set up the Model Object
        /// </summary>
        private void ModelSetUp()
        {
            using (XbimReadWriteTransaction trans = Model.BeginTransaction("Model initialization"))
            {
                Assembly        assembly = Assembly.GetExecutingAssembly();
                FileVersionInfo fvi      = FileVersionInfo.GetVersionInfo(assembly.Location);
                string          version  = fvi.ProductVersion;

                Model.DefaultOwningApplication.ApplicationIdentifier     = fvi.Comments;
                Model.DefaultOwningApplication.ApplicationDeveloper.Name = fvi.CompanyName;
                Model.DefaultOwningApplication.ApplicationFullName       = fvi.ProductName;
                Model.DefaultOwningApplication.Version = fvi.ProductVersion;
                //TODO add correct IfcPersonAndOrganization to DefaultOwningUser
                Model.DefaultOwningUser.ThePerson.FamilyName = "Unknown";
                Model.DefaultOwningUser.TheOrganization.Name = "Unknown";
                if (Model.Header == null)
                {
                    Model.Header = new IfcFileHeader(IfcFileHeader.HeaderCreationMode.InitWithXbimDefaults);
                }
                Model.Header.FileDescription.Description.Clear();
                Model.Header.FileDescription.Description.Add("ViewDefinition[CoordinationView]");
                Model.Header.FileName.Name = Path.GetFileName(FileName);
                Model.Header.FileName.AuthorName.Add("4Projects");
                Model.Header.FileName.AuthorizationName = "4Projects";
                IfcProject project = Model.Instances.New <IfcProject>();
                //set world coordinate system
                XBimContext.WCS = Model.Instances.New <IfcAxis2Placement3D>();
                XBimContext.WCS.SetNewDirectionOf_XZ(1, 0, 0, 0, 0, 1);
                XBimContext.WCS.SetNewLocation(0, 0, 0);
                trans.Commit();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Performs the grouping of elements of the model according to the rules defined in the XML pointed by <paramref name="XMLfileName"/>
        /// </summary>
        /// <param name="XMLfileName">Name of the xml file defining the grouping rules.</param>
        /// <returns></returns>
        public bool GroupElements(string XMLfileName, IfcGroup rootGroup = null)
        {
            if (string.IsNullOrEmpty(XMLfileName))
            {
                throw new ArgumentNullException("File name cannot be null or empty.");
            }
            _xmlDoc = new XmlDocument();
            _xmlDoc.Load(XMLfileName);


            using (XbimReadWriteTransaction trans = _model.BeginTransaction())
            {
                if (rootGroup != null)
                {
                    if (((IPersistIfcEntity)rootGroup).ModelOf != _model)
                    {
                        throw new Exception("Model of the group is different than model to be used.");
                    }
                    _rootGroup = rootGroup;
                }
                else
                {
                    _rootGroup = _model.Instances.New <IfcGroup>(g => g.Name = "Root group");
                }

                bool result = PerformGrouping();
                trans.Commit();
                return(result);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Add Properties back to component and type objects
 /// </summary>
 /// <param name="cOBieSheet">COBieSheet of COBieAttributeRow to read data from</param>
 public void SerialiseAttribute(COBieSheet <COBieAttributeRow> cOBieSheet)
 {
     using (XbimReadWriteTransaction trans = Model.BeginTransaction("Add Attribute"))
     {
         try
         {
             int count      = 1;
             var sortedRows = cOBieSheet.Rows.OrderBy(r => r.SheetName).ThenBy(r => r.RowName);
             ProgressIndicator.ReportMessage("Starting Attributes...");
             ProgressIndicator.Initialise("Creating Attributes", cOBieSheet.RowCount);
             foreach (COBieAttributeRow row in sortedRows)
             {
                 BumpTransaction(trans, count);
                 count++;
                 ProgressIndicator.IncrementAndUpdate();
                 AddAttribute(row);
             }
             ProgressIndicator.Finalise();
             trans.Commit();
         }
         catch (Exception)
         {
             //TODO: Catch with logger?
             throw;
         }
     }
 }
Exemplo n.º 6
0
        //sample to show how to create a model from scratch

        static void Main(string[] args)
        {
            Logger.Debug("Creating Model...");
            XbimModel model = CreateModel("NewModel");

            if (model != null)
            {
                using (XbimReadWriteTransaction txn = model.BeginTransaction()) //start a readwrite transaction
                {
                    try
                    {
                        IfcProject project = model.Instances.New <IfcProject>(); //Project Created

                        txn.Commit();                                            //commit the changes if nothing went wrong
                    }
                    catch (Exception e)
                    {
                        Logger.DebugFormat("Error {0}\nRolling back changes.....", e.Message);
                    }
                }
                model.SaveAs("NewModel.ifc", XbimStorageType.IFC); //export as an Ifc File
                model.Close();                                     //close the model and release all resources and handles
            }

            Logger.Debug("Model Created Ended...");
            Console.ReadLine();
            // CreateProject
        }
Exemplo n.º 7
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
        }
Exemplo n.º 8
0
        public bool GroupElements(XmlDocument document, IfcGroup rootGroup)
        {
            if (document == null)
            {
                throw new ArgumentNullException("XML document must be specified");
            }
            _xmlDoc = document;

            if (rootGroup != null)
            {
                if (((IPersistIfcEntity)rootGroup).ModelOf != _model)
                {
                    throw new Exception("Model of the group is different than model to be used.");
                }
                _rootGroup = rootGroup;
            }
            else
            {
                _rootGroup = _model.Instances.New <IfcGroup>(g => g.Name = "Root group");
            }


            using (XbimReadWriteTransaction trans = _model.BeginTransaction("Elements to groups"))
            {
                bool result = PerformGrouping();
                trans.Commit();
                return(result);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Create and setup objects held in the Component COBieSheet
        /// </summary>
        /// <param name="cOBieSheet">COBieSheet of COBieComponentRow to read data from</param>
        public void SerialiseComponent(COBieSheet <COBieComponentRow> cOBieSheet)
        {
            using (XbimReadWriteTransaction trans = Model.BeginTransaction("Add Component"))
            {
                try
                {
                    int count = 1;
                    IfcTypeObjects     = Model.Instances.OfType <IfcTypeObject>();
                    IfcSpaces          = Model.Instances.OfType <IfcSpace>();
                    IfcBuildingStoreys = Model.Instances.OfType <IfcBuildingStorey>();
                    ProgressIndicator.ReportMessage("Starting Components...");
                    ProgressIndicator.Initialise("Creating Components", cOBieSheet.RowCount);
                    for (int i = 0; i < cOBieSheet.RowCount; i++)
                    {
                        BumpTransaction(trans, count);
                        count++;
                        ProgressIndicator.IncrementAndUpdate();
                        COBieComponentRow row = cOBieSheet[i];
                        AddComponent(row);
                    }

                    ProgressIndicator.Finalise();
                    trans.Commit();
                }
                catch (Exception)
                {
                    //TODO: Catch with logger?
                    throw;
                }
            }
        }
Exemplo n.º 10
0
        static private IfcBuilding CreateBuilding(XbimModel model, HndzBuilding hndzBuilding)
        {
            using (XbimReadWriteTransaction txn = model.BeginTransaction("Create Building"))
            {
                var building = model.Instances.New <IfcBuilding>();
                building.Name = hndzBuilding.Name;
                building.OwnerHistory.OwningUser        = model.DefaultOwningUser;
                building.OwnerHistory.OwningApplication = model.DefaultOwningApplication;
                building.ElevationOfRefHeight           = hndzBuilding.RefHeight;
                building.CompositionType = IfcElementCompositionEnum.ELEMENT;

                building.ObjectPlacement = model.Instances.New <IfcLocalPlacement>();
                var localPlacement = building.ObjectPlacement as IfcLocalPlacement;

                if (localPlacement != null && localPlacement.RelativePlacement == null)
                {
                    localPlacement.RelativePlacement = model.Instances.New <IfcAxis2Placement3D>();
                    var placement = localPlacement.RelativePlacement as IfcAxis2Placement3D;
                    placement.SetNewLocation(0.0, 0.0, 0.0);
                }

                model.IfcProject.AddBuilding(building);
                //validate and commit changes
                if (model.Validate(txn.Modified(), Console.Out) == 0)
                {
                    txn.Commit();
                    return(building);
                }
            }
            return(null);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Create and setup objects held in the Issue COBieSheet
        /// </summary>
        /// <param name="cOBieSheet">COBieSheet of COBieIssueRow to read data from</param>
        public void SerialiseIssue(COBieSheet <COBieIssueRow> cOBieSheet)
        {
            using (XbimReadWriteTransaction trans = Model.BeginTransaction("Add Issue"))
            {
                try
                {
                    int count = 1;
                    ProgressIndicator.ReportMessage("Starting Issues...");
                    ProgressIndicator.Initialise("Creating Issues", cOBieSheet.RowCount);
                    for (int i = 0; i < cOBieSheet.RowCount; i++)
                    {
                        BumpTransaction(trans, count);
                        count++;
                        ProgressIndicator.IncrementAndUpdate();
                        COBieIssueRow row = cOBieSheet[i];
                        AddIssue(row);
                    }

                    ProgressIndicator.Finalise();
                    trans.Commit();
                }
                catch (Exception)
                {
                    //TODO: Catch with logger?
                    throw;
                }
            }
        }
Exemplo n.º 12
0
 public void CreateGroups(XmlDocument xmlDocument)
 {
     _xmlDoc = xmlDocument;
     using (XbimReadWriteTransaction trans = _model.BeginTransaction())
     {
         Process();
         trans.Commit();
     }
 }
Exemplo n.º 13
0
        public static XbimModel CreateandInitModel()
        {
            var model = XbimModel.CreateTemporaryModel();;  //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

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

                //create a building
                var building = model.Instances.New <IfcBuilding>();
                building.Name = "Building";
                building.OwnerHistory.OwningUser        = model.DefaultOwningUser;
                building.OwnerHistory.OwningApplication = model.DefaultOwningApplication;
                //building.ElevationOfRefHeight = elevHeight;
                building.CompositionType = IfcElementCompositionEnum.ELEMENT;

                building.ObjectPlacement = model.Instances.New <IfcLocalPlacement>();
                var localPlacement = building.ObjectPlacement as IfcLocalPlacement;

                if (localPlacement != null && localPlacement.RelativePlacement == null)
                {
                    localPlacement.RelativePlacement = model.Instances.New <IfcAxis2Placement3D>();
                }
                if (localPlacement != null)
                {
                    var placement = localPlacement.RelativePlacement as IfcAxis2Placement3D;
                    placement.SetNewLocation(0.0, 0.0, 0.0);
                }

                model.IfcProject.AddBuilding(building);

                //validate and commit changes
                Assert.IsTrue(model.Validate(txn.Modified(), Console.Out) == 0, "Invalid Model");
                txn.Commit();
            }
            return(model);
        }
Exemplo n.º 14
0
        private static IfcBeam CreateBeam(XbimModel model, HndzStructuralElement genericProducthndz)
        {
            using (XbimReadWriteTransaction txn = model.BeginTransaction("Create" + genericProducthndz.ToString()))
            {
                IfcBeam genericProductIfc        = model.Instances.New <IfcBeam>();
                IfcExtrudedAreaSolid body        = model.Instances.New <IfcExtrudedAreaSolid>();
                IfcBeamType          elementType = model.Instances.New <IfcBeamType>();
                elementType.PredefinedType = IfcBeamTypeEnum.BEAM;


                if (genericProducthndz.Profile is HndzRectangularProfile)
                {
                    HndzRectangularProfile genericProfilehndz = genericProducthndz.Profile as HndzRectangularProfile;

                    IfcRectangleProfileDef ifcGenericProfile = AssignRectangularProfile(model, genericProducthndz, genericProductIfc, elementType, genericProfilehndz);

                    //model as a swept area solid
                    body.SweptArea = ifcGenericProfile;
                }

                if (genericProducthndz.Profile is HndzISectionProfile)
                {
                    HndzISectionProfile genericProfilehndz = genericProducthndz.Profile as HndzISectionProfile;

                    IfcIShapeProfileDef ifcGenericProfile = AssignIProfile(model, genericProducthndz, genericProductIfc, elementType, genericProfilehndz);


                    //model as a swept area solid
                    body.SweptArea = ifcGenericProfile;
                }
                if (genericProducthndz.Profile is HndzCSectionProfile)
                {
                    HndzCSectionProfile genericProfilehndz = genericProducthndz.Profile as HndzCSectionProfile;
                    IfcCShapeProfileDef ifcGenericProfile  = AssignCsectionProfile(model, genericProducthndz, genericProductIfc, elementType, genericProfilehndz);


                    //model as a swept area solid
                    body.SweptArea = ifcGenericProfile;
                }

                AdjustExtrusion(model, body, genericProducthndz, genericProductIfc);

                if (model.Validate(txn.Modified(), Console.Out) == 0)
                {
                    txn.Commit();
                    return(genericProductIfc);
                }

                return(null);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Validate Model Object Foe Errors
        /// </summary>
        /// <param name="trans"></param>
        /// <returns></returns>
        public String Validate(XbimReadWriteTransaction trans)
        {
            StringWriter sw     = new StringWriter();
            int          errors = Model.Validate(trans.Modified(), sw);

            if (errors > 0)
            {
                return(sw.ToString());
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Add some properties to the wall,
        /// </summary>
        /// <param name="model">XbimModel</param>
        private void AddPropertiesToWall(XbimModel model, IfcWallStandardCase wall)
        {
            using (XbimReadWriteTransaction txn = model.BeginTransaction("Create Wall"))
            {
                IfcOwnerHistory ifcOwnerHistory = model.IfcProject.OwnerHistory; //we just use the project owner history for the properties, saves creating one
                CreateElementQuantity(model, wall, ifcOwnerHistory);
                CreateSimpleProperty(model, wall, ifcOwnerHistory);

                //if (model.Validate(txn.Modified(), Console.Out) == 0)
                //{
                txn.Commit();
                //}
                var xx = model.Instances.OfType <IfcPropertyReferenceValue>();
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// This sample demonstrates the minimum steps to create a compliant IFC model that contains a single standard case wall
        /// </summary>
        /// <param name="args"></param>
        public void Run()
        {
            //first create and initialise a model called Hello Wall
            Console.WriteLine("Initialising the IFC Project....");
            XbimModel model = CreateandInitModel("HelloWall");

            if (model != null)
            {
                IfcBuilding building = CreateBuilding(model, "Default Building", 2000);


                IfcWallStandardCase wall = CreateWall(model, 4000, 300, 2400);
                if (wall != null)
                {
                    AddPropertiesToWall(model, wall);
                }
                using (XbimReadWriteTransaction txn = model.BeginTransaction("Add Wall"))
                {
                    building.AddElement(wall);
                    txn.Commit();
                }

                if (wall != null)
                {
                    try
                    {
                        Console.WriteLine("Standard Wall successfully created....");
                        //write the Ifc File
                        model.SaveAs("HelloWall.ifc", XbimStorageType.IFC);
                        Console.WriteLine("HelloWall.ifc has been successfully written");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Failed to save HelloWall.ifc");
                        Console.WriteLine(e.Message);
                    }
                }
            }
            else
            {
                Console.WriteLine("Failed to initialise the model");
            }

            Console.WriteLine("Press any key to exit....");
            Console.ReadKey();
        }
Exemplo n.º 18
0
        /// <summary>
        /// Create and setup objects held in the System COBieSheet
        /// </summary>
        /// <param name="cOBieSheet">COBieSheet of COBieSystemRow to read data from</param>
        public void SerialiseSystem(COBieSheet <COBieSystemRow> cOBieSheet)
        {
            using (XbimReadWriteTransaction trans = Model.BeginTransaction("Add System"))
            {
                try
                {
                    int count = 1;
                    ProgressIndicator.ReportMessage("Starting Systems...");
                    ProgressIndicator.Initialise("Creating Systems", cOBieSheet.RowCount);
                    for (int i = 0; i < cOBieSheet.RowCount; i++)
                    {
                        BumpTransaction(trans, count);
                        count++;
                        ProgressIndicator.IncrementAndUpdate();
                        COBieSystemRow row = cOBieSheet[i];
                        if (ValidateString(row.Name))
                        {
                            if ((IfcSystemObj == null) ||
                                (row.Name.ToLower() != IfcSystemObj.Name.ToString().ToLower())
                                )
                            {
                                AddSystem(row);
                                AddProducts(row);
                                SystemProdutIndex = 1;
                            }
                            else
                            {
                                AddProducts(row);
                            }
                        }
                    }

                    ProgressIndicator.Finalise();
                    trans.Commit();
                }
                catch (Exception)
                {
                    //TODO: Catch with logger?
                    throw;
                }
            }
        }
Exemplo n.º 19
0
        private void Process()
        {
            if (_xmlDoc == null)
            {
                errLog.WriteLine("No input XML data.");
                return;
            }

            //get all groups nodes
            XmlNodeList groups = _xmlDoc.GetElementsByTagName("my:groups");

            if (groups == null || groups.Count == 0)
            {
                errLog.WriteLine("No groups in the XML document - not even root element.");
                return;
            }

            //start xbim transaction
            using (XbimReadWriteTransaction transaction = _model.BeginTransaction())
            {
                foreach (XmlNode group in groups)
                {
                    string   className = (group as XmlElement).GetAttribute("my:classificationName");
                    IfcGroup root      = CreateGroup(className, "", null);

                    //create group for all non-grouped elements
                    CreateGroup("No group", "", root);

                    XmlNodeList groupList = group.ChildNodes;
                    if (groupList.Count == 0)
                    {
                        errLog.WriteLine("No groups in the XML document");
                        continue;
                    }
                    ProcessGroups(groupList, root);
                }

                transaction.Commit();
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Add the IfcTask to the Model object
        /// </summary>
        /// <param name="cOBieSheet">COBieSheet of COBieResourceRow to read data from</param>
        public void SerialiseJob(COBieSheet <COBieJobRow> cOBieSheet)
        {
            using (XbimReadWriteTransaction trans = Model.BeginTransaction("Add Job"))
            {
                try
                {
                    int count = 1;
                    IfcTypeObjects = Model.Instances.OfType <IfcTypeObject>();
                    IfcConstructionEquipmentResources = Model.Instances.OfType <IfcConstructionEquipmentResource>();

                    ProgressIndicator.ReportMessage("Starting Jobs...");
                    ProgressIndicator.Initialise("Creating Jobs", (cOBieSheet.RowCount * 2));
                    for (int i = 0; i < cOBieSheet.RowCount; i++)
                    {
                        BumpTransaction(trans, count);
                        count++;
                        ProgressIndicator.IncrementAndUpdate();
                        COBieJobRow row = cOBieSheet[i];
                        AddJob(row);
                    }
                    //we need to assign IfcRelSequence relationships, but we need all tasks implemented, so loop rows again
                    IfcTasks = Model.Instances.OfType <IfcTask>(); //get new tasks
                    for (int i = 0; i < cOBieSheet.RowCount; i++)
                    {
                        BumpTransaction(trans, count);
                        ProgressIndicator.IncrementAndUpdate();
                        COBieJobRow row = cOBieSheet[i];
                        SetPriors(row);
                        count++;
                    }
                    ProgressIndicator.Finalise();

                    trans.Commit();
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Add the IfcPersonAndOrganizations to the Model object
        /// </summary>
        /// <param name="cOBieSheet"></param>
        public void SerialiseAssembly(COBieSheet <COBieAssemblyRow> cOBieSheet)
        {
            using (XbimReadWriteTransaction trans = Model.BeginTransaction("Add Assembly"))
            {
                try
                {
                    int count = 1;
                    IfcElements       = Model.FederatedInstances.OfType <IfcElement>();
                    IfcTypeObjects    = Model.FederatedInstances.OfType <IfcTypeObject>();
                    IfcMaterialLayers = Model.FederatedInstances.OfType <IfcMaterialLayer>();

                    ProgressIndicator.ReportMessage("Starting Assemblies...");
                    ProgressIndicator.Initialise("Creating Assemblies", cOBieSheet.RowCount);
                    for (int i = 0; i < cOBieSheet.RowCount; i++)
                    {
                        BumpTransaction(trans, count);
                        count++;
                        ProgressIndicator.IncrementAndUpdate();
                        COBieAssemblyRow row     = cOBieSheet[i];
                        string           objType = row.ExtObject.ToLower().Trim();
                        if (objType.Contains("ifcmaterial"))
                        {
                            AddMaterial(row);
                        }
                        else
                        {
                            AddAssembly(row);
                        }

                        LastRow = row;
                    }
                    ProgressIndicator.Finalise();
                    trans.Commit();
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Exemplo n.º 22
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
        }
Exemplo n.º 23
0
        /// <summary>
        /// Add the IfcPersonAndOrganizations to the Model object
        /// </summary>
        /// <param name="cOBieSheet"></param>
        public void SerialiseContacts(COBieSheet <COBieContactRow> cOBieSheet)
        {
            using (XbimReadWriteTransaction trans = Model.BeginTransaction("Add Contacts"))
            {
                try
                {
                    int count = 1;
                    SetEmailUser(Constants.DEFAULT_EMAIL); //add [email protected] PersonAndOrganization to use for nulls
                    SetDefaultUser();
                    ProgressIndicator.ReportMessage("Starting Contacts...");
                    ProgressIndicator.Initialise("Creating Contacts", cOBieSheet.RowCount);
                    for (int i = 0; i < cOBieSheet.RowCount; i++)
                    {
                        BumpTransaction(trans, count);
                        count++;
                        ProgressIndicator.IncrementAndUpdate();
                        COBieContactRow row = cOBieSheet[i];
                        CreatePersonAndOrganization(row);
                    }
                    ProgressIndicator.Finalise();
                    trans.Commit();
                }
                catch (Exception)
                {
                    throw;
                }
            }

            //IfcPersonAndOrganization thisContact = new IfcPersonAndOrganization();
            //XbimMemoryModel model = _model as XbimMemoryModel;
            //if (model != null)
            //{
            //    model.Instances.Add(thisContact);
            //}
            //IEnumerable<IfcPersonAndOrganization> ifcPersonAndOrganizations = Model.Instances.OfType<IfcPersonAndOrganization>();
            //string xxx = ifcPersonAndOrganizations.First().ThePerson.GivenName;
        }
Exemplo n.º 24
0
        /// <summary>
        /// Create and setup objects held in the Type COBieSheet
        /// </summary>
        /// <param name="cOBieSheet">COBieSheet of COBieTypeRow to read data from</param>
        public void SerialiseType(COBieSheet <COBieTypeRow> cOBieSheet)
        {
            using (XbimReadWriteTransaction trans = Model.BeginTransaction("Add Type"))
            {
                try
                {
                    int count = 1;
                    ProgressIndicator.ReportMessage("Starting Types...");
                    ProgressIndicator.Initialise("Creating Types", cOBieSheet.RowCount);
                    for (int i = 0; i < cOBieSheet.RowCount; i++)
                    {
                        BumpTransaction(trans, count);
                        count++;
                        ProgressIndicator.IncrementAndUpdate();
                        COBieTypeRow row = cOBieSheet[i];
                        if ((ValidateString(row.ExtObject)) &&
                            (row.ExtObject.ToLower().Contains("ifcmaterial"))
                            )
                        {
                            AddMaterial(row);
                        }
                        else
                        {
                            AddType(row);
                        }
                    }

                    ProgressIndicator.Finalise();
                    trans.Commit();
                }
                catch (Exception)
                {
                    //TODO: Catch with logger?
                    throw;
                }
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Create and setup objects held in the Facility COBieSheet
        /// </summary>
        /// <param name="cOBieSheet">COBieSheet of COBieFacilityRows to read data from</param>
        public void SerialiseFacility(COBieSheet <COBieFacilityRow> cOBieSheet)
        {
            using (XbimReadWriteTransaction trans = Model.BeginTransaction("Add Facility"))
            {
                try
                {
                    ProgressIndicator.ReportMessage("Starting Facility...");
                    ProgressIndicator.Initialise("Creating Facility", 3);

                    //Assume we have only one site and one building to a project
                    COBieFacilityRow row = cOBieSheet[0];
                    ProgressIndicator.IncrementAndUpdate();
                    SetUpProject(row);

                    ProgressIndicator.IncrementAndUpdate();
                    CreateSite(row);

                    ProgressIndicator.IncrementAndUpdate();
                    CreateBuilding(row);

                    //set up relationships
                    GetSite().AddBuilding(GetBuilding());
                    Model.IfcProject.AddSite(GetSite());

                    ProgressIndicator.Finalise();


                    trans.Commit();
                }
                catch (Exception)
                {
                    //TODO: Catch with logger?
                    throw;
                }
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// This creates a wall and it's geometry, many geometric representations are possible and extruded rectangular footprint is chosen as this is commonly used for standard case walls
        /// </summary>
        /// <param name="model"></param>
        /// <param name="length">Length of the rectangular footprint</param>
        /// <param name="width">Width of the rectangular footprint (width of the wall)</param>
        /// <param name="height">Height to extrude the wall, extrusion is vertical</param>
        /// <returns></returns>
        private IfcWallStandardCase CreateWall(XbimModel model, double length, double width, double height)
        {
            //
            //begin a transaction
            using (XbimReadWriteTransaction txn = model.BeginTransaction("Create Wall"))
            {
                IfcWallStandardCase wall = model.Instances.New <IfcWallStandardCase>();
                wall.Name = "A Standard rectangular wall";

                // required parameters for IfcWall
                wall.OwnerHistory.OwningUser        = model.DefaultOwningUser;
                wall.OwnerHistory.OwningApplication = model.DefaultOwningApplication;

                //represent wall as a rectangular profile
                IfcRectangleProfileDef rectProf = model.Instances.New <IfcRectangleProfileDef>();
                rectProf.ProfileType = IfcProfileTypeEnum.AREA;
                rectProf.XDim        = width;
                rectProf.YDim        = length;

                IfcCartesianPoint insertPoint = model.Instances.New <IfcCartesianPoint>();
                insertPoint.SetXY(0, 400); //insert at arbitrary position
                rectProf.Position          = model.Instances.New <IfcAxis2Placement2D>();
                rectProf.Position.Location = insertPoint;

                //model as a swept area solid
                IfcExtrudedAreaSolid body = model.Instances.New <IfcExtrudedAreaSolid>();
                body.Depth             = height;
                body.SweptArea         = rectProf;
                body.ExtrudedDirection = model.Instances.New <IfcDirection>();
                body.ExtrudedDirection.SetXYZ(0, 0, 1);

                //parameters to insert the geometry in the model
                IfcCartesianPoint origin = model.Instances.New <IfcCartesianPoint>();
                origin.SetXYZ(0, 0, 0);
                body.Position          = model.Instances.New <IfcAxis2Placement3D>();
                body.Position.Location = origin;

                //Create a Definition shape to hold the geometry
                IfcShapeRepresentation shape = model.Instances.New <IfcShapeRepresentation>();
                shape.ContextOfItems           = model.IfcProject.ModelContext();
                shape.RepresentationType       = "SweptSolid";
                shape.RepresentationIdentifier = "Body";
                shape.Items.Add_Reversible(body);

                //Create a Product Definition and add the model geometry to the wall
                IfcProductDefinitionShape rep = model.Instances.New <IfcProductDefinitionShape>();
                rep.Representations.Add_Reversible(shape);
                wall.Representation = rep;

                //now place the wall into the model
                IfcLocalPlacement   lp   = model.Instances.New <IfcLocalPlacement>();
                IfcAxis2Placement3D ax3d = model.Instances.New <IfcAxis2Placement3D>();
                ax3d.Location     = origin;
                ax3d.RefDirection = model.Instances.New <IfcDirection>();
                ax3d.RefDirection.SetXYZ(0, 1, 0);
                ax3d.Axis = model.Instances.New <IfcDirection>();
                ax3d.Axis.SetXYZ(0, 0, 1);
                lp.RelativePlacement = ax3d;
                wall.ObjectPlacement = lp;


                // Where Clause: The IfcWallStandard relies on the provision of an IfcMaterialLayerSetUsage
                IfcMaterialLayerSetUsage ifcMaterialLayerSetUsage = model.Instances.New <IfcMaterialLayerSetUsage>();
                IfcMaterialLayerSet      ifcMaterialLayerSet      = model.Instances.New <IfcMaterialLayerSet>();
                IfcMaterialLayer         ifcMaterialLayer         = model.Instances.New <IfcMaterialLayer>();
                ifcMaterialLayer.LayerThickness = 10;
                ifcMaterialLayerSet.MaterialLayers.Add_Reversible(ifcMaterialLayer);
                ifcMaterialLayerSetUsage.ForLayerSet             = ifcMaterialLayerSet;
                ifcMaterialLayerSetUsage.LayerSetDirection       = IfcLayerSetDirectionEnum.AXIS2;
                ifcMaterialLayerSetUsage.DirectionSense          = IfcDirectionSenseEnum.NEGATIVE;
                ifcMaterialLayerSetUsage.OffsetFromReferenceLine = 150;

                // Add material to wall
                IfcMaterial material = model.Instances.New <IfcMaterial>();
                material.Name = "some material";
                IfcRelAssociatesMaterial ifcRelAssociatesMaterial = model.Instances.New <IfcRelAssociatesMaterial>();
                ifcRelAssociatesMaterial.RelatingMaterial = material;
                ifcRelAssociatesMaterial.RelatedObjects.Add_Reversible(wall);

                ifcRelAssociatesMaterial.RelatingMaterial = ifcMaterialLayerSetUsage;

                // IfcPresentationLayerAssignment is required for CAD presentation in IfcWall or IfcWallStandardCase
                IfcPresentationLayerAssignment ifcPresentationLayerAssignment = model.Instances.New <IfcPresentationLayerAssignment>();
                ifcPresentationLayerAssignment.Name = "some ifcPresentationLayerAssignment";
                ifcPresentationLayerAssignment.AssignedItems.Add(shape);


                // linear segment as IfcPolyline with two points is required for IfcWall
                IfcPolyline       ifcPolyline = model.Instances.New <IfcPolyline>();
                IfcCartesianPoint startPoint  = model.Instances.New <IfcCartesianPoint>();
                startPoint.SetXY(0, 0);
                IfcCartesianPoint endPoint = model.Instances.New <IfcCartesianPoint>();
                endPoint.SetXY(4000, 0);
                ifcPolyline.Points.Add_Reversible(startPoint);
                ifcPolyline.Points.Add_Reversible(endPoint);

                IfcShapeRepresentation shape2d = model.Instances.New <IfcShapeRepresentation>();
                shape2d.ContextOfItems           = model.IfcProject.ModelContext();
                shape2d.RepresentationIdentifier = "Axis";
                shape2d.RepresentationType       = "Curve2D";
                shape2d.Items.Add_Reversible(ifcPolyline);
                rep.Representations.Add_Reversible(shape2d);


                //validate write any errors to the console and commit if ok, otherwise abort

                if (model.Validate(txn.Modified(), Console.Out) == 0)
                {
                    txn.Commit();
                    return(wall);
                }
            }
            return(null);
        }
        /// <summary>
        /// Create and setup Bounding Box's
        /// </summary>
        /// <param name="cOBieSheet">COBieSheet of COBieCoordinateRow to read data from</param>
        public void SerialiseCoordinate(COBieSheet <COBieCoordinateRow> cOBieSheet)
        {
            using (XbimReadWriteTransaction trans = Model.BeginTransaction("Add Coordinate"))
            {
                try
                {
                    int count = 1;
                    ProgressIndicator.ReportMessage("Starting Coordinates...");
                    ProgressIndicator.Initialise("Creating Coordinates", cOBieSheet.RowCount);
                    var rows = cOBieSheet.Rows.OrderBy(a => a.SheetName == "Component").ThenBy(a => a.SheetName == "Space").ThenBy(a => a.SheetName == "Floor"); //order into Floor,Space,Component, needed to build object placements

                    for (int i = 0; i < cOBieSheet.RowCount; i++)
                    {
                        COBieCoordinateRow row     = rows.ElementAt(i);// cOBieSheet[i];
                        COBieCoordinateRow rowNext = null;
                        BumpTransaction(trans, count);
                        count++;

                        //do floor placement point
                        if ((ValidateString(row.Category)) &&
                            (row.Category.ToLower() == "point")
                            )
                        {
                            ProgressIndicator.IncrementAndUpdate();

                            AddFloorPlacement(row);
                            continue; //work done, next loop please
                        }
                        //do bounding box items
                        if ((ValidateString(row.Category)) &&
                            (row.Category.Contains("box-"))
                            )
                        {
                            i++;                             //set to get next row

                            if (i < cOBieSheet.RowCount)     //get next row if still in range
                            {
                                rowNext = rows.ElementAt(i); //cOBieSheet[i];
                            }
                            if ((rowNext != null) &&
                                (ValidateString(rowNext.Category)) &&
                                (rowNext.Category.Contains("box-")) &&
                                (ValidateString(row.SheetName)) &&
                                //(ValidateString(row.RowName)) &&
                                (ValidateString(rowNext.SheetName)) &&
                                //(ValidateString(rowNext.RowName)) &&
                                (row.SheetName == rowNext.SheetName) &&
                                (row.RowName == rowNext.RowName)
                                )
                            {
                                ProgressIndicator.IncrementAndUpdate();

                                AddBoundingBoxAsExtrudedAreaSolid(row, rowNext);

                                ProgressIndicator.IncrementAndUpdate(); //two row processed here

//#if DEBUG
//                                Console.WriteLine("{0} : {1} == {2} : {3} ", row.SheetName, row.RowName, rowNext.SheetName, rowNext.RowName);
//#endif
                            }
                            else
                            {
#if DEBUG
                                if (rowNext == null)
                                {
                                    Console.WriteLine("Failed to find pair {0} : {1} != {2} : {3} ", row.SheetName, row.RowName, "Null", "Null");
                                }
                                else
                                {
                                    Console.WriteLine("Failed to find pair {0} : {1} != {2} : {3} ", row.SheetName, row.RowName, rowNext.SheetName, rowNext.RowName);
                                }
#endif
                                i--; //set back in case next is point, as two box points failed
                            }
                        }
                    }
                    ProgressIndicator.Finalise();

                    trans.Commit();
                }
                catch (Exception)
                {
                    //TODO: Catch with logger?
                    throw;
                }
            }
        }
Exemplo n.º 28
0
        private static IfcBeam CreatePurlin(XbimModel model, HndzPurlin genericProducthndz)
        {
            using (XbimReadWriteTransaction txn = model.BeginTransaction("Create Purlin"))
            {
                IfcBeam beam = model.Instances.New <IfcBeam>();
                IfcExtrudedAreaSolid body = model.Instances.New <IfcExtrudedAreaSolid>();
                body.Depth = genericProducthndz.ExtrusionLine.RhinoLine.Length;

                IfcBeamType elementType = model.Instances.New <IfcBeamType>();
                elementType.PredefinedType = IfcBeamTypeEnum.USERDEFINED;

                IfcMaterial material = model.Instances.New <IfcMaterial>();
                material.Name = "STEEL";
                beam.SetMaterial(material);
                IfcCartesianPoint insertPoint = model.Instances.New <IfcCartesianPoint>();

                insertPoint.SetXY(genericProducthndz.ExtrusionLine.baseNode.Point.X, genericProducthndz.ExtrusionLine.baseNode.Point.Y); //insert at arbitrary position//****************Need Revision

                if (genericProducthndz.Profile is HndzRectangularProfile)
                {
                    HndzRectangularProfile recProfile = genericProducthndz.Profile as HndzRectangularProfile;

                    #region Type & Material &Tags

                    string typeText = "HANDAZ-Column-Rectangular " + (int)recProfile.Rectangle.Width + " x "
                                      + (int)recProfile.Rectangle.Height + " mm";

                    elementType.Tag  = typeText;
                    elementType.Name = typeText;
                    IfcLabel columnLabel = new IfcLabel(typeText);
                    elementType.ElementType          = columnLabel;
                    elementType.ApplicableOccurrence = columnLabel;



                    beam.Tag         = typeText;
                    beam.Name        = typeText;
                    beam.Description = typeText;
                    beam.SetDefiningType(elementType, model);

                    #endregion

                    //represent column as a rectangular profile
                    IfcRectangleProfileDef MyPurlinPofile = model.Instances.New <IfcRectangleProfileDef>();
                    MyPurlinPofile.ProfileType           = IfcProfileTypeEnum.AREA;
                    MyPurlinPofile.XDim                  = recProfile.Rectangle.Height;
                    MyPurlinPofile.YDim                  = recProfile.Rectangle.Width;
                    MyPurlinPofile.Position              = model.Instances.New <IfcAxis2Placement2D>();
                    MyPurlinPofile.Position.RefDirection = model.Instances.New <IfcDirection>();
                    MyPurlinPofile.Position.RefDirection.SetXY(recProfile.OrientationInPlane.X, recProfile.OrientationInPlane.Y);
                    //MyColumnPofile.Position.Location = insertPoint;

                    //model as a swept area solid
                    body.SweptArea = MyPurlinPofile;
                }
                if (genericProducthndz.Profile is HndzISectionProfile)
                {
                    HndzISectionProfile Iprofile = genericProducthndz.Profile as HndzISectionProfile;

                    #region Type & Material &Tags

                    string typeText = "HANDAZ-Purlin-I beam (flange " + Iprofile.I_Section.b_f + " x " + Iprofile.I_Section.t_fTop + " and web "
                                      + Iprofile.I_Section.d + " x " + Iprofile.I_Section.t_w + " mm";


                    elementType.Tag  = typeText;
                    elementType.Name = typeText;
                    IfcLabel columnLabel = new IfcLabel(typeText);
                    elementType.ElementType          = columnLabel;
                    elementType.ApplicableOccurrence = columnLabel;



                    beam.Tag         = typeText;
                    beam.Name        = typeText;
                    beam.Description = typeText;
                    beam.SetDefiningType(elementType, model);

                    #endregion
                    // IfcPolyline pl = model.Instances.New<IfcPolyline>();

                    //List<Point3d> tempPoints= Iprofile.ConvertItoPoints();
                    // foreach (Point3d point in tempPoints)
                    // {
                    //     IfcCartesianPoint tempPoint = model.Instances.New<IfcCartesianPoint>();
                    //     tempPoint.SetXYZ(point.X, point.Y, point.Z);
                    //     pl.Points.Add(tempPoint);
                    // }

                    IfcIShapeProfileDef MyPurlinPofile = model.Instances.New <IfcIShapeProfileDef>();
                    MyPurlinPofile.FlangeThickness = Iprofile.I_Section.tf;
                    MyPurlinPofile.WebThickness    = Iprofile.I_Section.t_w;
                    MyPurlinPofile.OverallWidth    = Iprofile.I_Section.b_f;
                    MyPurlinPofile.OverallDepth    = Iprofile.I_Section.d;
                    MyPurlinPofile.FilletRadius    = 10;

                    MyPurlinPofile.Position = model.Instances.New <IfcAxis2Placement2D>();
                    MyPurlinPofile.Position.RefDirection = model.Instances.New <IfcDirection>();
                    MyPurlinPofile.Position.RefDirection.SetXY(Iprofile.OrientationInPlane.X, Iprofile.OrientationInPlane.Y);
                    //MyColumnPofile.Position.Location = insertPoint;

                    //model as a swept area solid
                    body.SweptArea = MyPurlinPofile;
                }
                if (genericProducthndz.Profile is HndzCSectionProfile)
                {
                    HndzCSectionProfile Cprofile = genericProducthndz.Profile as HndzCSectionProfile;

                    #region Type & Material &Tags

                    string typeText = "HANDAZ-Purlin-C-Chanel (flange " + Cprofile.C_Section.b_f + " x " + Cprofile.C_Section.t_f + " and web "
                                      + Cprofile.C_Section.d + " x " + Cprofile.C_Section.t_w + " mm";


                    elementType.Tag  = typeText;
                    elementType.Name = typeText;
                    IfcLabel columnLabel = new IfcLabel(typeText);
                    elementType.ElementType          = columnLabel;
                    elementType.ApplicableOccurrence = columnLabel;


                    beam.Tag         = typeText;
                    beam.Name        = typeText;
                    beam.Description = typeText;
                    beam.SetDefiningType(elementType, model);

                    #endregion

                    IfcCShapeProfileDef MyPurlinPofile = model.Instances.New <IfcCShapeProfileDef>();
                    MyPurlinPofile.WallThickness = Cprofile.C_Section.t_f;
                    //MyColumnPofile.WebThickness = Iprofile.C_Section.t_w; //ToDo:purlin web and flange thickness are the same!!!!
                    MyPurlinPofile.Width = Cprofile.C_Section.b_f;
                    MyPurlinPofile.Depth = Cprofile.C_Section.d;
                    MyPurlinPofile.InternalFilletRadius = 10;

                    MyPurlinPofile.Position = model.Instances.New <IfcAxis2Placement2D>();
                    MyPurlinPofile.Position.RefDirection = model.Instances.New <IfcDirection>();
                    MyPurlinPofile.Position.RefDirection.SetXY(Cprofile.OrientationInPlane.X, Cprofile.OrientationInPlane.Y);


                    //model as a swept area solid
                    body.SweptArea = MyPurlinPofile;
                }
                body.ExtrudedDirection = model.Instances.New <IfcDirection>();
                body.ExtrudedDirection.SetXYZ(0, 0, 1);
                //body.ExtrudedDirection.SetXYZ(Hndzcol.ExtrusionLine.RhinoLine.Direction.X, Hndzcol.ExtrusionLine.RhinoLine.Direction.Y, Hndzcol.ExtrusionLine.RhinoLine.Direction.Z);


                //parameters to insert the geometry in the model
                IfcCartesianPoint origin = model.Instances.New <IfcCartesianPoint>();
                origin.SetXYZ(genericProducthndz.ExtrusionLine.baseNode.Point.X, genericProducthndz.ExtrusionLine.baseNode.Point.Y, genericProducthndz.ExtrusionLine.baseNode.Point.Z);

                body.Position = model.Instances.New <IfcAxis2Placement3D>();
                //body.Position.Location = origin;

                body.Position.RefDirection = model.Instances.New <IfcDirection>();
                body.Position.RefDirection.SetXYZ(1, 0, 0);

                //Create a Definition shape to hold the geometry
                IfcShapeRepresentation shape = model.Instances.New <IfcShapeRepresentation>();
                shape.ContextOfItems           = model.IfcProject.ModelContext();
                shape.RepresentationType       = "SweptSolid";
                shape.RepresentationIdentifier = "Body";
                shape.Items.Add(body);

                //Create a Product Definition and add the model geometry to the column
                IfcProductDefinitionShape rep = model.Instances.New <IfcProductDefinitionShape>();
                rep.Representations.Add(shape);

                beam.Representation = rep;

                //now place the column into the model
                IfcLocalPlacement   lp   = model.Instances.New <IfcLocalPlacement>();
                IfcAxis2Placement3D ax3d = model.Instances.New <IfcAxis2Placement3D>();
                ax3d.Location = origin;

                Vector3d perpendicularVector = new Vector3d(genericProducthndz.Profile.OrientationInPlane.X, genericProducthndz.Profile.OrientationInPlane.Y, 0);

                Plane extrusionPlane;
                bool  aa = genericProducthndz.ExtrusionLine.RhinoLine.TryGetPlane(out extrusionPlane);
                if (aa)
                {
                    perpendicularVector = extrusionPlane.ZAxis;
                }



                ax3d.RefDirection = model.Instances.New <IfcDirection>();
                ax3d.RefDirection.SetXYZ(perpendicularVector.X, perpendicularVector.Y, perpendicularVector.Z);
                ax3d.Axis = model.Instances.New <IfcDirection>();
                ax3d.Axis.SetXYZ(genericProducthndz.ExtrusionLine.RhinoLine.Direction.X, genericProducthndz.ExtrusionLine.RhinoLine.Direction.Y, genericProducthndz.ExtrusionLine.RhinoLine.Direction.Z);

                lp.RelativePlacement = ax3d;
                beam.ObjectPlacement = lp;

                #region Owner Data
                beam.OwnerHistory.OwningUser        = model.DefaultOwningUser;
                beam.OwnerHistory.OwningApplication = model.DefaultOwningApplication;
                #endregion

                //validate write any errors to the console and commit if OK, otherwise abort
                string temp = Path.GetTempPath();
                //if (model.Validate(txn.Modified(), File.CreateText("E:\\Column" + column.GlobalId + "Errors.txt")) == 0)
                // if (model.Validate(txn.Modified(), File.CreateText(temp + "Column" + column.GlobalId + "Errors.txt")) == 0)
                if (model.Validate(txn.Modified(), Console.Out) == 0)
                {
                    txn.Commit();
                    return(beam);
                }

                return(null);
            }
        }
Exemplo n.º 29
0
        private static void CreateStorey(XbimModel model, IfcBuilding building, float levelHeight, List <List <IfcProduct> > productsLists)
        {
            using (XbimReadWriteTransaction txn = model.BeginTransaction("Create Storey"))
            {
                int floorNumber = 0;
                if (productsLists != null)
                {
                    foreach (List <IfcProduct> ProductsStorey in productsLists)
                    {
                        var storey = model.Instances.New <IfcBuildingStorey>();
                        storey.Name = "Level " + ++floorNumber;
                        storey.OwnerHistory.OwningUser        = model.DefaultOwningUser;
                        storey.OwnerHistory.OwningApplication = model.DefaultOwningApplication;
                        storey.Elevation       = levelHeight;
                        storey.CompositionType = IfcElementCompositionEnum.ELEMENT;
                        //storey.GlobalId = new Xbim.Ifc2x3.UtilityResource.IfcGloballyUniqueId();

                        storey.ObjectPlacement = model.Instances.New <IfcLocalPlacement>();
                        var localPlacement = storey.ObjectPlacement as IfcLocalPlacement;

                        if (localPlacement != null && localPlacement.RelativePlacement == null)
                        {
                            localPlacement.RelativePlacement = model.Instances.New <IfcAxis2Placement3D>();
                            var placement = localPlacement.RelativePlacement as IfcAxis2Placement3D;
                            placement.SetNewLocation(0.0, 0.0, floorNumber * levelHeight);
                        }


                        IfcRelContainedInSpatialStructure RelationSpatial = model.Instances.New <IfcRelContainedInSpatialStructure>();


                        foreach (IfcProduct item in ProductsStorey)
                        {
                            //storey.AddElement(item);
                            RelationSpatial.RelatedElements.Add(item);
                            ///=============================
                            //IfcRelContainedInSpatialStructure RelationSpatial = model.Instances.New<IfcRelContainedInSpatialStructure>();
                            //RelationSpatial.RelatedElements.Add(item);
                            //RelationSpatial.RelatingStructure = storey;
                        }

                        RelationSpatial.RelatingStructure = storey;

                        building.AddToSpatialDecomposition(storey);
                    }
                }

                //validate and commit changes
                if (model.Validate(txn.Modified(), Console.Out) == 0)
                {
                    txn.Commit();
                }
                else
                {
                    using (StreamWriter str = new StreamWriter("E:\\storey " + floorNumber + " Errors"))
                    {
                        model.Validate(txn.Modified(), str);
                    }
                }
            }
        }