Ejemplo n.º 1
0
 public void StampXbimApplication(IfcSchemaVersion schemaVersion)
 {
     FileDescription = new StepFileDescription("2;1");
     FileName        = new StepFileName(DateTime.Now)
     {
         PreprocessorVersion =
             string.Format("Xbim File Processor version {0}",
                           Assembly.GetExecutingAssembly().GetName().Version),
         OriginatingSystem =
             string.Format("Xbim version {0}",
                           Assembly.GetExecutingAssembly().GetName().Version),
     };
     FileSchema = new StepFileSchema(schemaVersion);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creat the federated file
        /// </summary>
        /// <param name="author">Author name</param>
        /// <param name="organisation">Orgsnisation Name</param>
        /// <param name="prjName">Project Name</param>
        /// <param name="ifcVersion">Ifc schema version</param>
        /// <param name="storage">Type of xbim file store</param>
        public void Create(string author, string organisation, string prjName = null,
                           IfcSchemaVersion ifcVersion = IfcSchemaVersion.Ifc4, XbimStoreType storage = XbimStoreType.InMemoryModel
                           )
        {
            var creds = new XbimEditorCredentials
            {
                ApplicationIdentifier     = "xBIM",
                ApplicationDevelopersName = "xBIM Team",
                EditorsFamilyName         = author,
                EditorsOrganisationName   = organisation,
                ApplicationVersion        = "1.0"
            };

            _fedModel = IfcStore.Create(creds, ifcVersion, storage); //create in memory
            using (var txn = _fedModel.BeginTransaction())
            {
                var project = _fedModel.Instances.New <IfcProject>();
                project.Name = prjName ?? "Undefined";
                txn.Commit();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Writes the Input to an IFC file
        ///
        /// The Input can be one model
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_Click(object sender, RoutedEventArgs e)
        {
            if (InputPorts[0].Data != null)
            {
                PropertyTranformDelegate semanticFilterIFC2x3 = (property, parentObject) =>
                {
                    return(property.PropertyInfo.GetValue(parentObject, null));
                };
                PropertyTranformDelegate semanticFilterIFC4 = (property, parentObject) =>
                {
                    return(property.PropertyInfo.GetValue(parentObject, null));
                };

                var newModelIfc2x3 = IfcStore.Create(IfcSchemaVersion.Ifc2X3, XbimStoreType.InMemoryModel);

                var newModelIfc4 = IfcStore.Create(IfcSchemaVersion.Ifc4, XbimStoreType.InMemoryModel);

                IfcSchemaVersion ifcVersion = IfcSchemaVersion.Unsupported;

                // Check the IFC Version
                IfcVersionType = InputPorts[0].Data.GetType();
                if (IfcVersionType.Name == "ModelInfoIFC2x3")
                {
                    var modelid        = ((ModelInfoIFC2x3)(InputPorts[0].Data)).ModelId;
                    var elementIdsList = ((ModelInfoIFC2x3)(InputPorts[0].Data)).ElementIds;
                    var res            = new HashSet <Xbim.Ifc2x3.UtilityResource.IfcGloballyUniqueId>(elementIdsList);

                    xModel     = DataController.Instance.GetModel(modelid);
                    ifcVersion = xModel.IfcSchemaVersion;

                    List <Xbim.Ifc2x3.Kernel.IfcProduct> elements = xModel.Instances.OfType <Xbim.Ifc2x3.Kernel.IfcProduct>().ToList();

                    using (var txn = newModelIfc2x3.BeginTransaction())
                    {
                        var copied = new XbimInstanceHandleMap(xModel, newModelIfc2x3);
                        foreach (var element in elements)
                        {
                            if (res.Contains(element.GlobalId))
                            {
                                newModelIfc2x3.InsertCopy(element, copied, semanticFilterIFC2x3, false, false);
                            }
                        }
                        txn.Commit();
                    }
                }
                else if (IfcVersionType.Name == "ModelInfoIFC4")
                {
                    var modelid        = ((ModelInfoIFC4)(InputPorts[0].Data)).ModelId;
                    var elementIdsList = ((ModelInfoIFC4)(InputPorts[0].Data)).ElementIds;
                    var res            = new HashSet <Xbim.Ifc4.UtilityResource.IfcGloballyUniqueId>(elementIdsList);

                    xModel     = DataController.Instance.GetModel(modelid);
                    ifcVersion = xModel.IfcSchemaVersion;

                    List <Xbim.Ifc4.Kernel.IfcProduct> elements = xModel.Instances.OfType <Xbim.Ifc4.Kernel.IfcProduct>().ToList();

                    using (var txn = newModelIfc4.BeginTransaction())
                    {
                        var copied = new XbimInstanceHandleMap(xModel, newModelIfc4);
                        foreach (var element in elements)
                        {
                            if (res.Contains(element.GlobalId))
                            {
                                newModelIfc4.InsertCopy(element, copied, semanticFilterIFC4, false, false);
                            }
                        }
                        txn.Commit();
                    }
                }

                // Write the new IFC file to the selected Path
                SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                saveFileDialog1.Filter = "IfcFile |*.ifc";
                saveFileDialog1.Title  = "Save an IFC File";
                saveFileDialog1.ShowDialog();
                if (saveFileDialog1.FileName != "")
                {
                    if (ifcVersion == IfcSchemaVersion.Ifc2X3)
                    {
                        newModelIfc2x3.SaveAs(saveFileDialog1.FileName);
                        newModelIfc2x3.Close();
                        if (File.Exists(saveFileDialog1.FileName))
                        {
                            MessageBox.Show("File saved", "My Application", MessageBoxButton.OK);
                        }
                        else
                        {
                            MessageBox.Show("There was an Error \n Please Try again", "My Application", MessageBoxButton.OK);
                        }
                    }
                    else if (ifcVersion == IfcSchemaVersion.Ifc4)
                    {
                        newModelIfc4.SaveAs(saveFileDialog1.FileName);
                        newModelIfc4.Close();
                        if (File.Exists(saveFileDialog1.FileName))
                        {
                            MessageBox.Show("File saved", "My Application", MessageBoxButton.OK);
                        }
                        else
                        {
                            MessageBox.Show("There was an Error \n Please Try again", "My Application", MessageBoxButton.OK);
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Please Connect a Model", "My Application", MessageBoxButton.OK);
            }
        }
Ejemplo n.º 4
0
 public StepFileSchema(IfcSchemaVersion schemaVersion)
 {
     _schemas.Add(schemaVersion.ToString().ToUpper());
     Init();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Merge two IFC files with the same IFC Version to a new IFC File.
        /// </summary>
        public override void Calculate()
        {
            if (InputPorts[0].Data == null)
            {
                return;
            }
            if (InputPorts[1].Data == null)
            {
                return;
            }

            // Check for same IFC Version
            IfcVersionTypeModel1 = InputPorts[0].Data.GetType();
            IfcVersionTypeModel2 = InputPorts[1].Data.GetType();

            if (IfcVersionTypeModel1 != IfcVersionTypeModel2)
            {
                MessageBox.Show("The IFC Versions are not the same!", "My Application", MessageBoxButton.OK);
                return;
            }

            PropertyTranformDelegate propTransform = delegate(ExpressMetaProperty prop, object toCopy)
            {
                var value = prop.PropertyInfo.GetValue(toCopy, null);
                return(value);
            };

            // Important for new IFC File
            var newModelIfc2x3 = IfcStore.Create(IfcSchemaVersion.Ifc2X3, XbimStoreType.InMemoryModel);
            var newModelIfc4   = IfcStore.Create(IfcSchemaVersion.Ifc4, XbimStoreType.InMemoryModel);

            var txnIfc2x3 = newModelIfc2x3.BeginTransaction();
            var txnIfc4   = newModelIfc4.BeginTransaction();

            // List of elements - Important, that no element exist twice in the new file
            HashSet <Xbim.Ifc2x3.UtilityResource.IfcGloballyUniqueId> buildingElementsIFC2x3 = new HashSet <Xbim.Ifc2x3.UtilityResource.IfcGloballyUniqueId>();
            HashSet <Xbim.Ifc4.UtilityResource.IfcGloballyUniqueId>   buildingElementsIFC4   = new HashSet <Xbim.Ifc4.UtilityResource.IfcGloballyUniqueId>();

            IfcSchemaVersion ifcVersion = IfcSchemaVersion.Unsupported;

            XbimInstanceHandleMap copied = null;

            var label1 = ControlElements[1] as Label;

            label1.Content = "";

            // Loop over both IFC files
            for (var i = 0; i < 2; i++)
            {
                if (IfcVersionTypeModel1.Name == "ModelInfoIFC2x3")
                {
                    var modelid        = ((ModelInfoIFC2x3)(InputPorts[i].Data)).ModelId;
                    var res            = new HashSet <Xbim.Ifc2x3.UtilityResource.IfcGloballyUniqueId>();
                    var elementIdsList = ((ModelInfoIFC2x3)(InputPorts[i].Data)).ElementIds;
                    foreach (var elementID in elementIdsList)
                    {
                        res.Add(elementID);
                    }

                    var xModel = DataController.Instance.GetModel(modelid);
                    ifcVersion = xModel.IfcSchemaVersion;
                    List <Xbim.Ifc2x3.Kernel.IfcProduct> elements = xModel.Instances.OfType <Xbim.Ifc2x3.Kernel.IfcProduct>().ToList();
                    copied = new XbimInstanceHandleMap(xModel, newModelIfc2x3);

                    foreach (var element in elements)
                    {
                        if (res.Contains(element.GlobalId) && !buildingElementsIFC2x3.Contains(element.GlobalId))
                        {
                            newModelIfc2x3.InsertCopy(element, copied, propTransform, false, false);
                            buildingElementsIFC2x3.Add(element.GlobalId);
                        }
                    }
                }
                else if (IfcVersionTypeModel1.Name == "ModelInfoIFC4")
                {
                    var modelid        = ((ModelInfoIFC4)(InputPorts[i].Data)).ModelId;
                    var elementIdsList = ((ModelInfoIFC4)(InputPorts[i].Data)).ElementIds;
                    var res            = new HashSet <Xbim.Ifc4.UtilityResource.IfcGloballyUniqueId>(elementIdsList);

                    var xModel = DataController.Instance.GetModel(modelid);
                    ifcVersion = xModel.IfcSchemaVersion;
                    List <Xbim.Ifc4.Kernel.IfcProduct> elements = xModel.Instances.OfType <Xbim.Ifc4.Kernel.IfcProduct>().ToList();
                    copied = new XbimInstanceHandleMap(xModel, newModelIfc4);

                    foreach (var element in elements)
                    {
                        if (res.Contains(element.GlobalId) && !buildingElementsIFC4.Contains(element.GlobalId))
                        {
                            newModelIfc4.InsertCopy(element, copied, propTransform, false, false);
                            buildingElementsIFC4.Add(element.GlobalId);
                        }
                    }
                }
            }

            // Safe new IFC File
            Random zufall = new Random();
            int    number = zufall.Next(1, 1000);

            string result   = Path.GetTempPath();
            string copyFile = result + "copy" + number + ".ifc";

            while (File.Exists(copyFile))
            {
                number   = zufall.Next(1, 1000);
                copyFile = result + "copy" + number + ".ifc";
            }


            if (ifcVersion == IfcSchemaVersion.Ifc2X3)
            {
                txnIfc2x3.Commit();
                newModelIfc2x3.SaveAs(copyFile);
                newModelIfc2x3.Close();

                ModelInfoIFC2x3 modelInfo = new ModelInfoIFC2x3(copyFile);
                foreach (var id in buildingElementsIFC2x3)
                {
                    modelInfo.AddElementIds(id);
                }
                OutputIfc2x3 = modelInfo;

                var xModel = IfcStore.Open(copyFile);
                DataController.Instance.AddModel(copyFile, xModel);
                xModel.Close();
            }
            else if (ifcVersion == IfcSchemaVersion.Ifc4)
            {
                txnIfc4.Commit();
                newModelIfc4.SaveAs(copyFile);
                newModelIfc4.Close();

                ModelInfoIFC4 modelInfo = new ModelInfoIFC4(copyFile);
                foreach (var id in buildingElementsIFC4)
                {
                    modelInfo.AddElementIds(id);
                }
                OutputIfc4 = modelInfo;

                var xModel = IfcStore.Open(copyFile);
                DataController.Instance.AddModel(copyFile, xModel);
                xModel.Close();
            }

            if (IfcVersionTypeModel1.Name == "ModelInfoIFC2x3")
            {
                label1.Content      = "Merge Complete!";
                OutputPorts[0].Data = OutputIfc2x3;
            }
            else if (IfcVersionTypeModel1.Name == "ModelInfoIFC4")
            {
                label1.Content      = "Merge Complete!";
                OutputPorts[0].Data = OutputIfc4;
            }
        }