//返回List<RuleDetail>, 用作真正检查 public List <RuleDetail> parseDeliveryDetail() { Initialize(); int firstClass = 0; int secondClass = 0; int thirdClass = 0; RuleDetail curFirstRule = null; RuleDetail curSecondRule = null; List <RuleDetail> allRules = new List <RuleDetail>(); do { //对于每一行 while (excelInfo.Read()) { //跳过第一列有值的行 if (excelInfo.GetValue(0) != null) { continue; } //如果第二列有值 if (excelInfo.GetValue(1) != null) { firstClass++; secondClass = 0; curFirstRule = new RuleDetail(); curFirstRule.Entity = excelInfo.GetValue(1).ToString(); try { curFirstRule.EntityIfd = excelInfo.GetValue(8).ToString(); } catch (Exception ex) { //如果出现nullptr的exception,代表用户没有填写IFD } } //如果第三列有值 if (excelInfo.GetValue(2) != null) { secondClass++; thirdClass = 0; string name = excelInfo.GetValue(2).ToString(); curSecondRule = new RuleDetail(); if (name == "属性") { curSecondRule.type = RuleType.Property; } else if (name == "组成结构") { curSecondRule.type = RuleType.Structure; } else if (name == "几何") { curSecondRule.type = RuleType.Geometry; } else { //规则类别错误 throw new Exception("规则类别错误"); } } //如果第四列有值 if (excelInfo.GetValue(3) != null) { thirdClass++; string name = firstClass.ToString() + '.' + secondClass.ToString() + '.' + thirdClass.ToString() + ':' + excelInfo.GetValue(3).ToString(); var thirdRule = new RuleDetail(); //处理基本信息 thirdRule.No = firstClass.ToString() + '.' + secondClass.ToString() + '.' + thirdClass.ToString(); thirdRule.Entity = curFirstRule.Entity; thirdRule.EntityIfd = curFirstRule.EntityIfd; thirdRule.type = curSecondRule.type; //根据类别处理内容 if (thirdRule.type == RuleType.Structure) { try { thirdRule.content = excelInfo.GetValue(8).ToString(); thirdRule.Descript = thirdRule.Entity + "的组成结构包含" + excelInfo.GetValue(3).ToString(); } catch { //用户没有写IFD编码 } } else { thirdRule.content = excelInfo.GetValue(3).ToString(); if (thirdRule.type == RuleType.Property) { thirdRule.Descript = thirdRule.Entity + "的属性包括" + thirdRule.content; } if (thirdRule.type == RuleType.Geometry) { thirdRule.Descript = thirdRule.Entity + "的几何表达形式为" + thirdRule.content; } } CheckLog.Logger(thirdRule.ToString()); //把合理的Rule放入返回列表 if (thirdRule.isValidate()) { thirdRule.IFDtoIFC(); allRules.Add(thirdRule); } } } } while (excelInfo.NextResult()); return(allRules); }
/// <summary> /// 检查一个规则 /// </summary> /// <param name="file">过滤后的IFC文件信息</param> /// <param name="rule">某个规则</param> private ResultRow CheckSingleRule(IFCFile file, RuleDetail rule) { IfcStore model = _parentWindow.Model; //获取检查的实体是哪一个 var targetEntities = file.Elements.Where(i => i.TYPE.ToUpper() == rule.EntityIfd.ToUpper()); //bool result = true; int ErrorCount = 0; ResultRow Result = new ResultRow(); Result.Item = rule.No; Result.PassStatus = "通过"; Result.ErrorEntityLabels = new List <int>(); Result.ItemContent = rule.Descript; Result.EntityCheckCount = targetEntities.Count().ToString(); //如果是属性检查 if (rule.type == RuleType.Property) { Result.ErrorType = "属性检查"; foreach (var Entity in targetEntities) { //存在实体并不含有这个属性或值为空 if (!Entity.properties.ContainsKey(rule.content) || string.IsNullOrWhiteSpace(Entity.properties[rule.content])) { Result.PassStatus = "不通过"; ErrorCount++; Result.ErrorEntityLabels.Add(Entity.LABEL); } } } else if (rule.type == RuleType.Geometry) { Result.ErrorType = "几何检查"; foreach (var Entity in targetEntities) { //几何不对 if (!Entity.properties["Representation"].ToUpper().Contains(rule.content.ToUpper())) { Result.PassStatus = "不通过"; ErrorCount++; Result.ErrorEntityLabels.Add(Entity.LABEL); } } } else if (rule.type == RuleType.Structure) { Result.ErrorType = "空间检查"; SortedDictionary <int, List <int> > relContain = file.Rels["isContaining"]; //空间检查需要注意Ifcwall的多种形式 if (rule.content.ToUpper() == "IFCWALL" || rule.content.ToUpper() == "IFCWALLSTANDARDCASE" || rule.content.ToUpper() == "IFCWALLELMENTEDCASE") { foreach (var Entity in targetEntities) { if (!judgeRelContainsHelper(Entity.LABEL, "IFCWALL", relContain, model) && !judgeRelContainsHelper(Entity.LABEL, "IFCWALLSTANDARDCASE", relContain, model) && !judgeRelContainsHelper(Entity.LABEL, "IFCWALLELMENTEDCASE", relContain, model)) { Result.PassStatus = "不通过"; ErrorCount++; Result.ErrorEntityLabels.Add(Entity.LABEL); } } } else { foreach (var Entity in targetEntities) { if (!judgeRelContainsHelper(Entity.LABEL, rule.content, relContain, model)) { Result.PassStatus = "不通过"; ErrorCount++; Result.ErrorEntityLabels.Add(Entity.LABEL); } } } } Result.ErrorCount = ErrorCount.ToString(); return(Result); }