示例#1
0
        public string GetProductId(int selectedLabel)
        {
            IIfcProduct Product = IFCConverter.Products.Where(p => p.EntityLabel == selectedLabel).FirstOrDefault();

            if (Product != null)
            {
                string ProductId = Product.Name.Value.Value.ToString().Split(':')[2];
                return(ProductId);
            }
            else
            {
                IIfcRelDefinesByType relType = IFCConverter.ModelTypes.Where(t => t.RelatingType.EntityLabel == selectedLabel).FirstOrDefault();
                string typeName = relType.RelatingType.Name.ToString();
                return(typeName);
            }
        }
示例#2
0
        public ActionResult GetProductIdsByType(int TypeId)
        {
            IIfcRelDefinesByType relType    = IFCConverter.ModelTypes.Where(t => t.RelatingType.EntityLabel == TypeId).FirstOrDefault();
            List <int>           productIds = new List <int>();

            if (relType != null)
            {
                productIds = relType.RelatedObjects.Select(a => a.EntityLabel).ToList();
            }
            JsonResult result             = new JsonResult();
            var        jsonData           = new { ProductIdList = productIds };
            var        serializerSettings = new JsonSerializerSettings {
                PreserveReferencesHandling = PreserveReferencesHandling.Objects
            };

            return(new JsonResult {
                Data = JsonConvert.SerializeObject(jsonData, Formatting.Indented, serializerSettings), MaxJsonLength = Int32.MaxValue, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
示例#3
0
        private static List <ProductCategory> GetCategories()
        {
            List <IIfcRelDefinesByType> ifcRelDefinesByTypes = Model.Instances.OfType <IIfcRelDefinesByType>().ToList();
            List <ProductCategory>      Categories           = new List <ProductCategory>();

            List <string> list    = Products.Select(a => a.GetType().Name).ToList();
            List <string> newlist = Products.Select(a => a.GetType().Name).ToList().Distinct().ToList();

            newlist.ForEach(a => Categories.Add(new ProductCategory()
            {
                Name = a
            }));


            foreach (var item in Categories)
            {
                List <IIfcProduct> products = Products.Where(p => p.GetType().Name == item.Name).ToList();
                foreach (var product in products)
                {
                    List <string> lst = new List <string>();
                    if (product.Name != null)
                    {
                        lst = product.Name.Value.Value.ToString().Split(':').ToList();
                    }
                    if (lst.Count >= 3)
                    {
                        IIfcRelDefinesByType relType = ifcRelDefinesByTypes.Where(a => a == product.IsTypedBy.FirstOrDefault()).FirstOrDefault();
                        if (item.Families.Where(c => c.Name == lst[0]).Count() == 0)
                        {
                            ProductFamily productFamily = new ProductFamily()
                            {
                                Name = lst[0]
                            };
                            ProductType productType = new ProductType()
                            {
                                Name = lst[1],
                            };
                            if (relType != null)
                            {
                                relType.RelatedObjects.ToList().ForEach(a => productType.Products.Add((IIfcProduct)a));
                                productType.Id = relType.RelatingType.EntityLabel;
                            }
                            else
                            {
                                productType.Products.Add(product);
                                if (product.IsTypedBy.Count() >= 1)
                                {
                                    productType.Id = product.IsTypedBy.FirstOrDefault().EntityLabel;
                                }
                            }
                            productFamily.Types.Add(productType);
                            item.Families.Add(productFamily);
                        }
                        else
                        {
                            ProductFamily existingFamily = item.Families.Where(c => c.Name == lst[0]).FirstOrDefault();
                            if (existingFamily.Types.Where(c => c.Name == lst[1]).Count() == 0)
                            {
                                ProductType productType = new ProductType()
                                {
                                    Name = lst[1]
                                };
                                if (relType != null)
                                {
                                    relType.RelatedObjects.ToList().ForEach(a => productType.Products.Add((IIfcProduct)a));
                                    productType.Id = relType.RelatingType.EntityLabel;
                                }
                                else
                                {
                                    productType.Products.Add(product);
                                    if (product.IsTypedBy.Count() >= 1)
                                    {
                                        productType.Id = product.IsTypedBy.FirstOrDefault().EntityLabel;
                                    }
                                }
                                item.Families.Where(c => c.Name == lst[0]).FirstOrDefault().Types.Add(productType);
                            }
                            else if (existingFamily.Types.Where(c => c.Name == lst[1]).FirstOrDefault().Products.Where(p => p.EntityLabel == product.EntityLabel).Count() == 0)
                            {
                                existingFamily.Types.Where(c => c.Name == lst[1]).FirstOrDefault().Products.Add(product);
                            }
                        }
                    }
                }
            }
            return(Categories);
        }
        private void processSpatialStructureData()
        {
            string currStep = string.Empty;

            DBOperation.beginTransaction();
            string container       = string.Empty;
            int    commandStatus   = -1;
            int    currInsertCount = 0;

            OracleCommand command = new OracleCommand(" ", DBOperation.DBConn);

            try
            {
                IEnumerable <IIfcSpatialStructureElement> spatialStructure = _model.Instances.OfType <IIfcSpatialStructureElement>();
                foreach (IIfcSpatialStructureElement sse in spatialStructure)
                {
                    string SqlStmt;

                    // do something
                    string guid      = sse.GlobalId.ToString();
                    int    IfcLineNo = sse.EntityLabel;

                    string elementtype = sse.GetType().Name.ToUpper();
                    string typeID      = String.Empty;
                    int    typeLineNo  = 0;
                    IEnumerable <IIfcRelDefinesByType> relTyp = sse.IsTypedBy;
                    if (relTyp != null || relTyp.Count() > 0)
                    {
                        IIfcRelDefinesByType typ = relTyp.FirstOrDefault();
                        if (typ != null)
                        {
                            typeID     = typ.RelatingType.GlobalId.ToString();
                            typeLineNo = typ.RelatingType.EntityLabel;
                        }
                    }
                    //if (sse.GetDefiningType() != null)
                    //  {
                    //      typeID = sse.GetDefiningType().GlobalId;
                    //      typeLineNo = sse.GetDefiningType().EntityLabel;
                    //  }
                    string            sseName        = BIMRLUtils.checkSingleQuote(sse.Name);
                    string            sseDescription = BIMRLUtils.checkSingleQuote(sse.Description);
                    string            sseObjectType  = BIMRLUtils.checkSingleQuote(sse.ObjectType);
                    string            sseLongName    = BIMRLUtils.checkSingleQuote(sse.LongName);
                    IIfcRelAggregates relContainer   = sse.Decomposes.FirstOrDefault();
                    if (relContainer == null)
                    {
                        container = string.Empty;
                    }
                    else
                    {
                        container = relContainer.RelatingObject.GlobalId.ToString();
                    }

                    // Keep a mapping between IFC guid used as a key in BIMRL and the IFC line no of the entity
                    _refBIMRLCommon.guidLineNoMappingAdd(BIMRLProcessModel.currModelID, IfcLineNo, guid);

                    SqlStmt = "Insert into " + DBOperation.formatTabName("BIMRL_Element") + "(Elementid, LineNo, ElementType, ModelID, Name, LongName, Description, ObjectType, Container, TypeID) Values ('"
                              + guid + "'," + IfcLineNo + ", '" + elementtype + "', " + BIMRLProcessModel.currModelID.ToString() + ", '" + sseName + "', '" + sseLongName + "','" + sseDescription + "', '" + sseObjectType
                              + "', '" + container + "', '" + typeID + "')";
                    // status = DBOperation.insertRow(SqlStmt);
                    command.CommandText = SqlStmt;
                    currStep            = SqlStmt;
                    commandStatus       = command.ExecuteNonQuery();

                    // Add intormation of the product label (LineNo into a List for the use later to update the Geometry
                    _refBIMRLCommon.insEntityLabelListAdd(Math.Abs(IfcLineNo));
                    currInsertCount++;

                    if (currInsertCount % DBOperation.commitInterval == 0)
                    {
                        //Do commit at interval but keep the long transaction (reopen)
                        DBOperation.commitTransaction();
                    }
                }
            }
            catch (OracleException e)
            {
                string excStr = "%%Error - " + e.Message + "\n\t" + currStep;
                _refBIMRLCommon.StackPushError(excStr);
                command.Dispose();
                throw;
            }

            DBOperation.commitTransaction();
            command.Dispose();
        }