/// <summary>
 /// Outputs only selected elements
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="routedEventArgs"></param>
 private void button_2_Checked(object sender, RoutedEventArgs routedEventArgs)
 {
     if (IfcVersionType.Name == "ModelInfoIFC2x3" && SelectedProductsIFC2x3 != null)
     {
         var             modelId         = ((ModelInfoIFC2x3)(InputPorts[0].Data)).ModelId;
         ModelInfoIFC2x3 modelInfoIfc2X3 = new ModelInfoIFC2x3(modelId);
         foreach (var item in SelectedProductsIFC2x3)
         {
             modelInfoIfc2X3.AddElementIds(item);
         }
         OutputPorts[0].Data = modelInfoIfc2X3;
     }
     else if (IfcVersionType.Name == "ModelInfoIFC4" && SelectedProductsIFC4 != null)
     {
         var           modelId       = ((ModelInfoIFC4)(InputPorts[0].Data)).ModelId;
         ModelInfoIFC4 modelInfoIfc4 = new ModelInfoIFC4(modelId);
         foreach (var item in SelectedProductsIFC4)
         {
             modelInfoIfc4.AddElementIds(item);
         }
         OutputPorts[0].Data = modelInfoIfc4;
     }
     else
     {
         OutputPorts[0].Data = null;
     }
 }
        protected void OnElementMouseDown_IFC4(object sender, MouseButtonEventArgs e, IfcViewerNode ifcParseGeometryNode, Xbim.Ifc4.Kernel.IfcProduct itemModel)
        {
            if (e.LeftButton != MouseButtonState.Pressed)
            {
                return;
            }

            var element = sender as ModelUIElement3D;

            if (element != null)
            {
                var geometryModel3D = element.Model as GeometryModel3D;
                if (geometryModel3D == null)
                {
                    return;
                }

                if (SelectedProductsIFC4 != null && SelectedProductsIFC4.Contains(itemModel.GlobalId))
                {
                    geometryModel3D.Material = geometryModel3D.BackMaterial;
                    SelectedProductsIFC4.Remove(itemModel.GlobalId);
                }
                else
                {
                    SelectedProductsIFC4.Add(itemModel.GlobalId);
                    geometryModel3D.Material = _selectionMaterial;
                }
            }
            var ifcViewerControl = ControlElements[0] as IFCViewerControl;
            var button_2         = ifcViewerControl.RadioButton_2;

            if (button_2 == null)
            {
                return;
            }

            if ((bool)button_2.IsChecked)
            {
                var           modelId       = ((ModelInfoIFC4)(InputPorts[0].Data)).ModelId;
                ModelInfoIFC4 modelInfoIfc4 = new ModelInfoIFC4(modelId);
                foreach (var item in SelectedProductsIFC4)
                {
                    modelInfoIfc4.AddElementIds(item);
                }
                OutputPorts[0].Data = modelInfoIfc4;
            }

            e.Handled = true;
        }
        /// <summary>
        /// Background Worker
        ///
        /// Open IFC File and read all elements.
        /// Add all elements to the ModelInfoClass
        ///
        /// Safes the new xModel to the DataController
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">Value File is the FilePath</param>
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            // Dublicate the File for multi access

            var    file   = e.Argument.ToString();
            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";
            }


            File.Copy(file, copyFile);
            using (xModel = IfcStore.Open(file))
            {
                if (xModel.IfcSchemaVersion == IfcSchemaVersion.Ifc2X3)
                {
                    ModelInfoIFC2x3 modelInfo = new ModelInfoIFC2x3(copyFile);
                    foreach (var item in xModel.Instances.OfType <Xbim.Ifc2x3.Kernel.IfcProduct>())
                    {
                        modelInfo.AddElementIds(item.GlobalId);
                    }
                    e.Result = modelInfo;
                }
                else
                {
                    ModelInfoIFC4 modelInfo = new ModelInfoIFC4(copyFile);
                    foreach (var item in xModel.Instances.OfType <Xbim.Ifc4.Kernel.IfcProduct>())
                    {
                        modelInfo.AddElementIds(item.GlobalId);
                    }
                    e.Result = modelInfo;
                }
            }
            xModel.Close();

            DataController.Instance.AddModel(copyFile, xModel);
        }
        private void comboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var ifcTypeFilterControl = ControlElements[0] as IfcTypeFilterControl;
            var comboBox             = ifcTypeFilterControl.comboBox;

            if (comboBox == null || comboBox.Items.Count == 0)
            {
                return;
            }

            if (IfcVersionType.Name == "ModelInfoIFC2x3" & comboBox.SelectedItem != null)
            {
                List <Xbim.Ifc2x3.UtilityResource.IfcGloballyUniqueId> searchIDs = ((ComboboxItem)(comboBox.SelectedItem)).ValueIfcGloballyUniqueIds2x3;
                ModelInfoIFC2x3 modelInfoIfc2X3 = new ModelInfoIFC2x3(modelid);
                if (searchIDs != null)
                {
                    foreach (var item in searchIDs)
                    {
                        modelInfoIfc2X3.AddElementIds(item);
                    }
                    OutputPorts[0].Data = modelInfoIfc2X3;
                }
            }
            else if (IfcVersionType.Name == "ModelInfoIFC4" & comboBox.SelectedItem != null)
            {
                List <Xbim.Ifc4.UtilityResource.IfcGloballyUniqueId> searchIDs = ((ComboboxItem)(comboBox.SelectedItem)).ValueIfcGloballyUniqueIds4;
                ModelInfoIFC4 modelInfoIfc4 = new ModelInfoIFC4(modelid);
                if (searchIDs != null)
                {
                    foreach (var item in searchIDs)
                    {
                        modelInfoIfc4.AddElementIds(item);
                    }
                    OutputPorts[0].Data = modelInfoIfc4;
                }
            }
        }
        /// <summary>
        /// Create a list of elements for the first combobox
        /// </summary>
        public override void Calculate()
        {
            var ifcElementPropertyControl = ControlElements[0] as IfcElementPropertyControl;
            var comboBox = ifcElementPropertyControl.ComboBox_IfcProducts;

            ifcElementPropertyControl.ComboBox_IfcPropertySets.Visibility = Visibility.Hidden;
            ifcElementPropertyControl.StackPanel.Visibility = Visibility.Hidden;

            if (InputPorts[0].Data == null)
            {
                return;
            }

            // Check the used IFC Version
            IfcVersionType = InputPorts[0].Data.GetType();

            if (comboBox != null && comboBox.Items.Count > 0)
            {
                comboBox.SelectedItem = -1;
                comboBox.Items.Clear();

                ComboboxItem_IfcProduct preselectedItem = new ComboboxItem_IfcProduct()
                {
                    Text = "Select Element",
                    IfcProduct_IFC2x3 = null
                };
                comboBox.Items.Add(preselectedItem);

                comboBox.SelectedItem = preselectedItem;
            }
            else
            {
                ComboboxItem_IfcProduct preselectedItem = new ComboboxItem_IfcProduct()
                {
                    Text = "Select Element",
                    IfcProduct_IFC2x3 = null
                };
                comboBox.Items.Add(preselectedItem);

                comboBox.SelectedItem = preselectedItem;
            }

            Type ifcVersion = InputPorts[0].Data.GetType();

            if (ifcVersion.Name == "ModelInfoIFC2x3")
            {
                comboBox.Visibility = Visibility.Visible;
                var modelid = ((ModelInfoIFC2x3)(InputPorts[0].Data)).ModelId;
                modelID = modelid;
                var elementIdsList = ((ModelInfoIFC2x3)(InputPorts[0].Data)).ElementIds;
                var res            = new HashSet <Xbim.Ifc2x3.UtilityResource.IfcGloballyUniqueId>(elementIdsList);


                xModel = DataController.Instance.GetModel(modelid);

                OutputInfoIfc2x3 = new ModelInfoIFC2x3(modelid);

                // Filter for selected ElementIDs
                List <Xbim.Ifc2x3.Kernel.IfcProduct> elements = xModel.Instances.OfType <Xbim.Ifc2x3.Kernel.IfcProduct>().ToList();
                foreach (var element in elements)
                {
                    if (res.Contains(element.GlobalId))
                    {
                        OutputInfoIfc2x3.AddElementIds(element.GlobalId);
                        var elementName = element.Name;
                        if (element.Name == "")
                        {
                            elementName = "n.N.";
                        }
                        ComboboxItem_IfcProduct item = new ComboboxItem_IfcProduct()
                        {
                            Text = elementName, IfcProduct_IFC2x3 = element
                        };
                        comboBox.Items.Add(item);
                    }
                }
                OutputPorts[0].Data = OutputInfoIfc2x3;
            }
            else if (ifcVersion.Name == "ModelInfoIFC4")
            {
                comboBox.Visibility = Visibility.Visible;
                var modelid = ((ModelInfoIFC4)(InputPorts[0].Data)).ModelId;
                modelID = modelid;
                var elementIdsList = ((ModelInfoIFC4)(InputPorts[0].Data)).ElementIds;
                var res            = new HashSet <Xbim.Ifc4.UtilityResource.IfcGloballyUniqueId>(elementIdsList);

                xModel = DataController.Instance.GetModel(modelid);

                OutputInfoIfc4 = new ModelInfoIFC4(modelid);

                // Filter for selected ElementIDs
                List <Xbim.Ifc4.Kernel.IfcProduct> elements = xModel.Instances.OfType <Xbim.Ifc4.Kernel.IfcProduct>().ToList();
                foreach (var element in elements)
                {
                    if (res.Contains(element.GlobalId))
                    {
                        OutputInfoIfc4.AddElementIds(element.GlobalId);

                        var elementName = element.Name;
                        if (element.Name == "")
                        {
                            elementName = "n.N.";
                        }
                        ComboboxItem_IfcProduct item = new ComboboxItem_IfcProduct()
                        {
                            Text = elementName, IfcProduct_IFC4 = element
                        };
                        comboBox.Items.Add(item);
                    }
                }
                OutputPorts[0].Data = OutputInfoIfc4;
            }
        }
Beispiel #6
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            if (IfcVersionType.Name == "ModelInfoIFC2x3")
            {
                var ifcPropertyFilterControl = ControlElements[0] as IfcPropertyFilterControl;
                if (ifcPropertyFilterControl == null)
                {
                    return;
                }

                var textBox = ifcPropertyFilterControl.textBox as TextBox;
                if (textBox == null)
                {
                    return;
                }
                var button = ifcPropertyFilterControl.button as Button;
                if (button == null)
                {
                    return;
                }
                var comboBoxPropertySet = ifcPropertyFilterControl.comboBoxPropertySet as ComboBox;
                if (comboBoxPropertySet == null)
                {
                    return;
                }
                var comboBoxProperties = ifcPropertyFilterControl.comboBoxProperties as ComboBox;
                if (comboBoxProperties == null)
                {
                    return;
                }
                if (comboBoxProperties.Items.Count == 0)
                {
                    return;
                }

                var selectedItem = (ComboboxItem)(comboBoxProperties.SelectedItem);
                var property     = selectedItem.Value as Xbim.Ifc2x3.PropertyResource.IfcProperty;
                if (property == null)
                {
                    return;
                }

                var selectedPropertySet = ((ComboboxItem)(comboBoxPropertySet.SelectedItem)).Value as Xbim.Ifc2x3.Kernel.IfcPropertySet;

                var selectedItemIds = ((ModelInfoIFC2x3)(InputPorts[0].Data)).ElementIds;
                if (selectedItemIds == null)
                {
                    return;
                }

                List <double> propertyValueDoubles = new List <double> {
                };
                List <bool> propertyValueBools     = new List <bool> {
                };
                List <string> propertyValueStrings = new List <string> {
                };


                for (int i = 0; i < selectedItemIds.Count; i++)
                {
                    var    selectedProduct = xModel.Instances.OfType <Xbim.Ifc2x3.ProductExtension.IfcElement>().ToList().Find(x => x.GlobalId == selectedItemIds[i]);
                    var    propertySet     = selectedProduct.PropertySets.ToList().Find(x => x.Name == selectedPropertySet.Name);
                    var    oneProperty     = propertySet.HasProperties.ToList().Find(x => x.Name == property.Name);
                    string propertyType    = oneProperty.GetType().ToString();
                    if (propertyType == "Xbim.Ifc2x3.PropertyResource.IfcPropertySingleValue")
                    {
                        var    property2         = oneProperty as Xbim.Ifc2x3.PropertyResource.IfcPropertySingleValue;
                        var    propertyValue     = property2.NominalValue;
                        object propertyValueTrue = property2.NominalValue.Value;
                        string propertyValueType = propertyValue.UnderlyingSystemType.Name;
                        if (propertyValueType == "Double")
                        {
                            double propertyValueDouble = (double)propertyValueTrue;
                            propertyValueDoubles.Add(propertyValueDouble);
                        }
                        if (propertyValueType == "Boolean")
                        {
                            bool propertyValueBool = (bool)propertyValueTrue;
                            propertyValueBools.Add(propertyValueBool);
                        }
                        if (propertyValueType == "String")
                        {
                            string propertyValueString = (string)propertyValueTrue;
                            propertyValueStrings.Add(propertyValueString);
                        }
                    }
                    else
                    {
                        return;
                    }
                }



                List <double> propertyValueDoublesSelected = new List <double> {
                };
                List <bool> propertyValueBoolsSelected     = new List <bool> {
                };
                List <Xbim.Ifc2x3.UtilityResource.IfcGloballyUniqueId> searchIDsSelected = new List <Xbim.Ifc2x3.UtilityResource.IfcGloballyUniqueId> {
                };

                string toDetect = textBox.Text;
                string ss;
                double s;
                if (toDetect.Contains("<"))
                {
                    int j = toDetect.IndexOf("<");
                    ss = toDetect.Substring(j + 1, toDetect.Length - 1);
                    s  = double.Parse(ss);
                    for (int i = 0; i < propertyValueDoubles.Count; i++)
                    {
                        if (propertyValueDoubles[i] < s)
                        {
                            propertyValueDoublesSelected.Add(propertyValueDoubles[i]);
                            searchIDsSelected.Add(selectedItemIds[i]);
                        }
                    }
                }

                if (toDetect.Contains(">"))
                {
                    int j = toDetect.IndexOf(">");
                    ss = toDetect.Substring(j + 1, toDetect.Length - 1);
                    s  = double.Parse(ss);
                    for (int i = 0; i < propertyValueDoubles.Count; i++)
                    {
                        if (propertyValueDoubles[i] > s)
                        {
                            propertyValueDoublesSelected.Add(propertyValueDoubles[i]);
                            searchIDsSelected.Add(selectedItemIds[i]);
                        }
                    }
                }

                if (toDetect.Contains("="))
                {
                    int j = toDetect.IndexOf("=");
                    ss = toDetect.Substring(j + 1, toDetect.Length - 1);
                    s  = double.Parse(ss);
                    for (int i = 0; i < propertyValueDoubles.Count; i++)
                    {
                        if (propertyValueDoubles[i] == s)
                        {
                            propertyValueDoublesSelected.Add(propertyValueDoubles[i]);
                            searchIDsSelected.Add(selectedItemIds[i]);
                        }
                    }
                }

                if (toDetect == "True" || toDetect == "False")
                {
                    for (int i = 0; i < propertyValueBools.Count; i++)
                    {
                        string trueorfalse = propertyValueBools[i].ToString();
                        if (propertyValueBools[i].ToString() == toDetect)
                        {
                            propertyValueBoolsSelected.Add(propertyValueBools[i]);
                            searchIDsSelected.Add(selectedItemIds[i]);
                        }
                    }
                }

                ModelInfoIFC2x3 outputInfo = new ModelInfoIFC2x3(((ModelInfoIFC2x3)(InputPorts[0].Data)).ModelId);
                foreach (var item in searchIDsSelected)
                {
                    outputInfo.AddElementIds(item);
                }
                OutputPorts[0].Data = outputInfo;
            }
            else if (IfcVersionType.Name == "ModelInfoIFC4")
            {
                var ifcPropertyFilterControl = ControlElements[0] as IfcPropertyFilterControl;
                if (ifcPropertyFilterControl == null)
                {
                    return;
                }

                var textBox = ifcPropertyFilterControl.textBox as TextBox;
                if (textBox == null)
                {
                    return;
                }
                var button = ifcPropertyFilterControl.button as Button;
                if (button == null)
                {
                    return;
                }
                var comboBoxPropertySet = ifcPropertyFilterControl.comboBoxPropertySet as ComboBox;
                if (comboBoxPropertySet == null)
                {
                    return;
                }
                var comboBoxProperties = ifcPropertyFilterControl.comboBoxProperties as ComboBox;
                if (comboBoxProperties == null)
                {
                    return;
                }
                if (comboBoxProperties.Items.Count == 0)
                {
                    return;
                }

                var selectedItem = (ComboboxItem)(comboBoxProperties.SelectedItem);
                var property     = selectedItem.Value as Xbim.Ifc4.PropertyResource.IfcProperty;
                if (property == null)
                {
                    return;
                }

                var selectedPropertySet = ((ComboboxItem)(comboBoxPropertySet.SelectedItem)).Value as Xbim.Ifc4.Kernel.IfcPropertySet;

                var selectedItemIds = ((ModelInfoIFC4)(InputPorts[0].Data)).ElementIds;
                if (selectedItemIds == null)
                {
                    return;
                }

                List <double> propertyValueDoubles = new List <double> {
                };
                List <bool> propertyValueBools     = new List <bool> {
                };
                List <string> propertyValueStrings = new List <string> {
                };


                for (int i = 0; i < selectedItemIds.Count; i++)
                {
                    var    selectedProduct = xModel.Instances.OfType <Xbim.Ifc4.ProductExtension.IfcElement>().ToList().Find(x => x.GlobalId == selectedItemIds[i]);
                    var    propertySet     = selectedProduct.PropertySets.ToList().Find(x => x.Name == selectedPropertySet.Name);
                    var    oneProperty     = propertySet.HasProperties.ToList().Find(x => x.Name == property.Name);
                    string propertyType    = oneProperty.GetType().ToString();
                    if (propertyType == "Xbim.Ifc4.PropertyResource.IfcPropertySingleValue")
                    {
                        var    property2         = oneProperty as Xbim.Ifc4.PropertyResource.IfcPropertySingleValue;
                        var    propertyValue     = property2.NominalValue;
                        object propertyValueTrue = property2.NominalValue.Value;
                        string propertyValueType = propertyValue.UnderlyingSystemType.Name;
                        if (propertyValueType == "Double")
                        {
                            double propertyValueDouble = (double)propertyValueTrue;
                            propertyValueDoubles.Add(propertyValueDouble);
                        }
                        if (propertyValueType == "Boolean")
                        {
                            bool propertyValueBool = (bool)propertyValueTrue;
                            propertyValueBools.Add(propertyValueBool);
                        }
                        if (propertyValueType == "String")
                        {
                            string propertyValueString = (string)propertyValueTrue;
                            propertyValueStrings.Add(propertyValueString);
                        }
                    }
                    else
                    {
                        return;
                    }
                }



                List <double> propertyValueDoublesSelected = new List <double> {
                };
                List <bool> propertyValueBoolsSelected     = new List <bool> {
                };
                List <Xbim.Ifc4.UtilityResource.IfcGloballyUniqueId> searchIDsSelected = new List <Xbim.Ifc4.UtilityResource.IfcGloballyUniqueId> {
                };

                string toDetect = textBox.Text;
                string ss;
                double s;
                if (toDetect.Contains("<"))
                {
                    int j = toDetect.IndexOf("<");
                    ss = toDetect.Substring(j + 1, toDetect.Length - 1);
                    s  = double.Parse(ss);
                    for (int i = 0; i < propertyValueDoubles.Count; i++)
                    {
                        if (propertyValueDoubles[i] < s)
                        {
                            propertyValueDoublesSelected.Add(propertyValueDoubles[i]);
                            searchIDsSelected.Add(selectedItemIds[i]);
                        }
                    }
                }

                if (toDetect.Contains(">"))
                {
                    int j = toDetect.IndexOf(">");
                    ss = toDetect.Substring(j + 1, toDetect.Length - 1);
                    s  = double.Parse(ss);
                    for (int i = 0; i < propertyValueDoubles.Count; i++)
                    {
                        if (propertyValueDoubles[i] > s)
                        {
                            propertyValueDoublesSelected.Add(propertyValueDoubles[i]);
                            searchIDsSelected.Add(selectedItemIds[i]);
                        }
                    }
                }

                if (toDetect.Contains("="))
                {
                    int j = toDetect.IndexOf("=");
                    ss = toDetect.Substring(j + 1, toDetect.Length - 1);
                    s  = double.Parse(ss);
                    for (int i = 0; i < propertyValueDoubles.Count; i++)
                    {
                        if (propertyValueDoubles[i] == s)
                        {
                            propertyValueDoublesSelected.Add(propertyValueDoubles[i]);
                            searchIDsSelected.Add(selectedItemIds[i]);
                        }
                    }
                }

                if (toDetect == "True" || toDetect == "False")
                {
                    for (int i = 0; i < propertyValueBools.Count; i++)
                    {
                        string trueorfalse = propertyValueBools[i].ToString();
                        if (propertyValueBools[i].ToString() == toDetect)
                        {
                            propertyValueBoolsSelected.Add(propertyValueBools[i]);
                            searchIDsSelected.Add(selectedItemIds[i]);
                        }
                    }
                }

                ModelInfoIFC4 outputInfo = new ModelInfoIFC4(((ModelInfoIFC4)(InputPorts[0].Data)).ModelId);
                foreach (var item in searchIDsSelected)
                {
                    outputInfo.AddElementIds(item);
                }
                OutputPorts[0].Data = outputInfo;
            }
        }
Beispiel #7
0
        public override void Calculate()
        {
            if (InputPorts[0].Data == null)
            {
                return;
            }
            OutputPorts[0].Data = null;
            IfcVersionType      = InputPorts[0].Data.GetType();
            if (IfcVersionType.Name == "ModelInfoIFC2x3")
            {
                var modelid = ((ModelInfoIFC2x3)(InputPorts[0].Data)).ModelId;

                if (modelid == null)
                {
                    return;
                }
                ModelInfoIFC2x3 outputInfo = new ModelInfoIFC2x3(modelid);
                xModel = DataController.Instance.GetModel(modelid);

                var ifcPropertyFilterControl = ControlElements[0] as IfcPropertyFilterControl;
                if (ifcPropertyFilterControl == null)
                {
                    return;
                }
                var comboBoxPropertySet = ifcPropertyFilterControl.comboBoxPropertySet as ComboBox;
                if (comboBoxPropertySet == null)
                {
                    return;
                }
                comboBoxPropertySet.Items.Clear();
                ComboboxItem preselectedPropertySet = new ComboboxItem()
                {
                    Text = "select Property Set", Value = null
                };
                comboBoxPropertySet.Items.Add(preselectedPropertySet);
                comboBoxPropertySet.SelectedItem = preselectedPropertySet;

                var selectedItemIds = ((ModelInfoIFC2x3)(InputPorts[0].Data)).ElementIds;
                if (selectedItemIds == null)
                {
                    return;
                }

                // MemberInfo info = typeof(Xbim.Ifc2x3.Kernel.IfcProduct).GetMethod("GlobalId");
                // IfcPersistedEntityAttribute attr = (IfcPersistedEntityAttribute)Attribute.GetCustomAttribute(info, typeof(IfcPersistedEntityAttribute));

                /* var mgr = new Definitions<PropertySetDef>(Xbim.Properties.Version.IFC2x3);
                 * mgr.LoadAllDefault();
                 *
                 * List<string> ListofAllProducts = new List<string>();
                 * foreach (var item in xModel.Instances.OfType<Xbim.Ifc2x3.Kernel.IfcProduct>())
                 * {
                 *  Type t = item.GetType();
                 *  var productName = t.Name;
                 *  if (!ListofAllProducts.Contains(productName))
                 *  {
                 *      ListofAllProducts.Add(productName);
                 *  }
                 * }
                 * foreach (var element in ListofAllProducts)
                 * {
                 *  var result = mgr.DefinitionSets.Where(p => p.ApplicableClasses.Any(c => c.ClassName == element));
                 *  foreach (var pSet in result)
                 *  {
                 *      ComboboxItem onePropertySet = new ComboboxItem() { Text = pSet.Name, Value = pSet };
                 *      if (!comboBoxPropertySet.Items.Contains(onePropertySet))
                 *      {
                 *          comboBoxPropertySet.Items.Add(onePropertySet);
                 *      }
                 *  }
                 * }*/


                var selectedProduct = xModel.Instances.OfType <Xbim.Ifc2x3.ProductExtension.IfcElement>().ToList().Find(x => x.GlobalId == selectedItemIds[0]);
                List <Xbim.Ifc2x3.Kernel.IfcPropertySet> PropertySet = new List <Xbim.Ifc2x3.Kernel.IfcPropertySet> {
                };

                List <Xbim.Ifc2x3.UtilityResource.IfcGloballyUniqueId> searchIDs = new List <Xbim.Ifc2x3.UtilityResource.IfcGloballyUniqueId> {
                };



                PropertySet = selectedProduct.PropertySets.ToList();

                for (int i = 0; i < PropertySet.Count(); i++)
                {
                    ComboboxItem onePropertySet = new ComboboxItem()
                    {
                        Text = PropertySet[i].Name.ToString(), Value = PropertySet[i]
                    };
                    comboBoxPropertySet.Items.Add(onePropertySet);
                }

                comboBoxPropertySet.SelectedIndex = 0;
            }
            else if (IfcVersionType.Name == "ModelInfoIFC4")
            {
                var modelid = ((ModelInfoIFC4)(InputPorts[0].Data)).ModelId;

                if (modelid == null)
                {
                    return;
                }
                ModelInfoIFC4 outputInfo = new ModelInfoIFC4(modelid);
                xModel = DataController.Instance.GetModel(modelid);


                var ifcPropertyFilterControl = ControlElements[0] as IfcPropertyFilterControl;
                if (ifcPropertyFilterControl == null)
                {
                    return;
                }
                var comboBoxPropertySet = ifcPropertyFilterControl.comboBoxPropertySet as ComboBox;
                if (comboBoxPropertySet == null)
                {
                    return;
                }
                comboBoxPropertySet.Items.Clear();
                ComboboxItem preselectedPropertySet = new ComboboxItem()
                {
                    Text = "select Property Set", Value = null
                };
                comboBoxPropertySet.Items.Add(preselectedPropertySet);
                comboBoxPropertySet.SelectedItem = preselectedPropertySet;

                var selectedItemIds = ((ModelInfoIFC4)(InputPorts[0].Data)).ElementIds;
                if (selectedItemIds == null)
                {
                    return;
                }

                var selectedProduct = xModel.Instances.OfType <Xbim.Ifc4.ProductExtension.IfcElement>().ToList().Find(x => x.GlobalId == selectedItemIds[0]);



                List <Xbim.Ifc4.Interfaces.IIfcPropertySet> PropertySet = new List <Xbim.Ifc4.Interfaces.IIfcPropertySet> {
                };

                List <Xbim.Ifc4.UtilityResource.IfcGloballyUniqueId> searchIDs = new List <Xbim.Ifc4.UtilityResource.IfcGloballyUniqueId> {
                };



                PropertySet = selectedProduct.PropertySets.ToList();
                for (int i = 0; i < PropertySet.Count(); i++)
                {
                    ComboboxItem onePropertySet = new ComboboxItem()
                    {
                        Text = PropertySet[i].Name.ToString(), Value = PropertySet[i]
                    };
                    comboBoxPropertySet.Items.Add(onePropertySet);
                }

                comboBoxPropertySet.SelectedIndex = 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;
            }
        }