public static IEnumerable <MvdValidationResult> ValidateModel(mvdXML mvd, IModel model) { // MVD validation rules are likely to traverse inverse relations using (model.BeginEntityCaching()) using (model.BeginInverseCaching()) { var engine = new MvdEngine(mvd, model); var objects = model.Instances .OfType <IIfcObject>() .ToList(); var validated = new HashSet <int>(); foreach (var root in engine.ConceptRoots) { var applicable = objects.Where(o => root.AppliesTo(o)); foreach (var item in applicable) { validated.Add(item.EntityLabel); foreach (var concept in root.Concepts) { var passes = concept.Test(item, Concept.ConceptTestMode.Raw); yield return(new MvdValidationResult(item, concept, passes)); } } } // report all IfcObjects which were not checked foreach (var item in objects.Where(o => !validated.Contains(o.EntityLabel))) { yield return(new MvdValidationResult(item, null, ConceptTestResult.DoesNotApply)); } } }
public void DataExtraction1() { const string fileName = @"FromMW\mvdXMLUnitTestsforIFC4_2.mvdxml"; var mvd = mvdXML.LoadFromFile(fileName); var m = IfcStore.Open(@"FromMW\mvdXML_ifc4_unit-test.ifc"); // can instantiate engine on model var engine = new MvdEngine(mvd, m); // data indicators var ind = new DataIndicatorLookup("Set", "Property", "Value", "T_Set", "T_Property", "T_Value"); // simple property data extraction with subtemplates // var templateSingleProp = mvd.GetConceptTemplate("88b4aaa9-0925-447c-b009-fe357b7c754e"); var dataSingleProp = engine.GetAttributes(templateSingleProp, m.Instances[606], ind, ""); CollectionAssert.AreEqual(dataSingleProp.FieldNames, new List <string>() { "Property", "Value" }); Assert.AreEqual(dataSingleProp.Values.Count, 1); Assert.AreEqual(dataSingleProp.Values[0][0].ToString(), "LoadBearing"); Assert.AreEqual(dataSingleProp.Values[0][1].ToString(), "true"); }
public void TestConceptPass() { const string fileName = @"FromNN\Measurement requirements-1-1RCa.mvdxml"; var mvd = mvdXML.LoadFromFile(fileName); var m = IfcStore.Open(@"FromNN\mvdXML test.ifc"); // can instantiate engine on model var engine = new MvdEngine(mvd, m); // m.Open(@"C:\Users\Bonghi\Desktop\str\FILE2015.xBIM"); // var walls = m.Instances.OfType<IfcWallStandardCase>(); // var wall = m.Instances[1973]; var wall = m.Instances.OfType <IfcWallStandardCase>().FirstOrDefault(); // ReSharper disable once UnusedVariable foreach (var view in mvd.Views) { foreach (var conceptRoot in view.Roots) { Debug.Print("ConceptRoot: " + conceptRoot.name); foreach (var concept in conceptRoot.Concepts) { var result = concept.Test(wall, Concept.ConceptTestMode.Raw); Debug.Print(concept.name + " (raw) passes: " + result); } } } m.Close(); }
public void ExpectedValidationResults() { var model = IfcStore.Open(@"FromMW\mvdXML_ifc4_unit-test.ifc"); // syncpoint const string mvdName = @"FromMW\mvdXMLUnitTestsforIFC4_2.mvdxml"; var mvd = mvdXML.LoadFromFile(mvdName); var doc = new MvdEngine(mvd, model); // ReSharper disable once JoinDeclarationAndInitializer bool app; // test 1 // var cr = doc.ConceptRoots.FirstOrDefault(x => x.uuid == "00000023-0000-0000-2000-000000029095"); Assert.IsNotNull(cr, "Did not find expected ConceptRoot"); // ReSharper disable once RedundantAssignment app = cr.AppliesTo(model.Instances[278]); // todo: restore when updated from Matthias // Assert.IsTrue(app, "Applicability not matched"); cr = doc.ConceptRoots.FirstOrDefault(x => x.uuid == "00000023-0000-0000-2000-000000029085"); Assert.IsNotNull(cr, "Did not find expected ConceptRoot"); app = cr.AppliesTo(model.Instances[589]); Assert.IsTrue(app, "Applicability not matched"); model.Close(); }
public void ToleratesMissingFields() { // ConceptTemplate uuid="10000000-0000-0000-0001-000000000008" has problems with the // use of multiple AttributeRule(s) that do not exist in the schema at that level // We want to tolerate the error and ignore it // const string fileName = @"FromMW\mvdXMLUnitTestsforIFC4_2.mvdxml"; var mvd = mvdXML.LoadFromFile(fileName); var m = IfcStore.Open(@"FromMW\mvdXML_ifc4_unit-test.ifc"); // can instantiate engine on model var engine = new MvdEngine(mvd, m); // data indicators var ind = new DataIndicatorLookup("Set", "Property", "Value", "T_Set", "T_Property", "T_Value"); // simple property data extraction with subtemplates // var template = mvd.GetConceptTemplate("10000000-0000-0000-0001-000000000008"); var data = engine.GetAttributes(template, m.Instances[10693], ind, ""); var str = data.ToString(); CollectionAssert.AreEqual(data.FieldNames, new List <string>() { "Set", "Property", "Value" }); Assert.AreEqual(data.Values.Count, 3); }
private void CloseFile(object sender, RoutedEventArgs e) { Doc = null; IfcClassesTree.ItemsSource = null; UpdateDataTable(); ErTree.ItemsSource = null; ConceptRootsTree.ItemsSource = null; // ListResults.ItemsSource = null; TestResults.Clear(); IsFileOpen = false; }
internal void SetParent(ConceptRoot conceptRoot) { ParentConceptRoot = conceptRoot; for (var i = 0; i < Requirements?.Length;) { // removes requirements pointing to non-existing exchangerequirements var success = Requirements[i].SetParent(this); if (!success) { Requirements = Requirements.RemoveAt(i); } else { i++; } } if (ParentConceptRoot?.ParentModelView?.ParentMvdXml == null) { return; } // sets the connection to clear caching event _mvdEngine = ParentConceptRoot.ParentModelView.ParentMvdXml.Engine; if (_mvdEngine != null) { _mvdEngine.RequestClearCache += Engine_RequestClearCache; } // try to set the concept template reference. if (string.IsNullOrEmpty(Template?.@ref)) { return; } ConceptTemplate = ParentConceptRoot.ParentModelView.ParentMvdXml.GetConceptTemplate(Template.@ref); }
// todo: this needs to be reviewed, while trying to ensure a responsive UI. // private void GetReport(object sender, DoWorkEventArgs e) private void GetReport(object sender, // ReSharper disable once UnusedParameter.Local DoWorkEventArgs ea, HashSet <Concept> selectedConcepts, HashSet <ModelViewExchangeRequirement> selectedExchReq, HashSet <ExpressType> selectedIfcClasses, List <IPersistEntity> entities, MvdEngine doc) { var bw = sender as BackgroundWorker; if (bw == null) { return; } // var report = new List<ReportResult>(); var report = TestResults; var entitiesInQueue = entities.Count; double itemsDone = 0; var lastReported = 0; foreach (var entity in entities) { var thisEntityExpressType = entity.ExpressType; if (selectedIfcClasses.Any()) { // if no one of the selected classes contains the element type in the subtypes skip entity var needTest = selectedIfcClasses.Any( classesToTest => classesToTest == thisEntityExpressType || classesToTest.SubTypes.Contains(thisEntityExpressType)); if (!needTest) { continue; } } var todo = new List <RequirementsRequirement>(); var suitableRoots = doc.GetConceptRoots(thisEntityExpressType); foreach (var suitableRoot in suitableRoots) { if (suitableRoot.Concepts == null) { continue; } foreach (var concept in suitableRoot.Concepts) { if (bw.CancellationPending) { return; } if (concept.Requirements == null) { continue; } if (selectedConcepts.Any()) { if (!selectedConcepts.Contains(concept)) { continue; // out of concept loop } } foreach (var requirementsRequirement in concept.Requirements) { if (selectedExchReq.Any()) { if (!selectedExchReq.Contains(requirementsRequirement.GetExchangeRequirement())) { continue; // out of requirementsRequirement loop } } todo.Add(requirementsRequirement); } } } var queueEstimate = --entitiesInQueue * 10 + todo.Count; // assumed 10 req per element on average try { foreach (var requirementsRequirement in todo) { itemsDone++; var thisProgress = Convert.ToInt32(itemsDone / queueEstimate * 100); if (lastReported != thisProgress) { _backgroundTester.ReportProgress(thisProgress); lastReported = thisProgress; } if (bw.CancellationPending) { return; } var result = ReportRequirementRequirement(requirementsRequirement, entity); if (!ConfigShowResult(result)) { continue; } AddOnUi(report, result); } } catch (Exception ex) { Log.Error($"Error processing entity #{entity.EntityLabel}.", ex); } } }
public VisualDiscriminator(MvdEngine document) { _doc = document; }
private void OpenFile(object sender, RoutedEventArgs e) { var openFile = new OpenFileDialog { Filter = @"mvdXML|*.mvdXML;*.xml" }; var res = openFile.ShowDialog(); if (!res.HasValue || res.Value != true) { return; } using (new WaitCursor()) { mvdXML mvd = null; try { var comp = mvdXML.TestCompatibility(openFile.FileName); if (comp == mvdXML.CompatibilityResult.InvalidNameSpace) { var newName = Path.GetTempFileName(); if (mvdXML.FixNamespace(openFile.FileName, newName)) { mvd = mvdXML.LoadFromFile(newName); } else { var msg = $"Attempt to fix namespace in invalid xml file [{openFile.FileName}] failed."; NotifyError(msg, null); } } else { mvd = mvdXML.LoadFromFile(openFile.FileName); } } catch (Exception ex) { var msg = $"Invalid xml file [{openFile.FileName}]."; NotifyError(msg, ex); } if (mvd == null) { return; } try { Doc = new MvdEngine(mvd, Model, AdaptSchema); } catch (Exception ex) { var msg = $"Error creating engine from valid mvdXML [{openFile.FileName}]."; NotifyError(msg, ex); } if (Doc == null) { return; } UpdateUiLists(); IsFileOpen = true; // the following are going to be inverted by the call to UnMatchedToggle and WarnToggle straight after _useAmber = false; _useBlue = false; UnMatchedToggle(null, null); WarnToggle(null, null); ColorGroupChanged(null, null); } }
public void ValidateSimpleLoinTest() { var editor = new XbimEditorCredentials { ApplicationDevelopersName = "CAS", ApplicationFullName = "LOIN Creator", ApplicationIdentifier = "LOIN", ApplicationVersion = "4.0", EditorsFamilyName = "Santini Aichel", EditorsGivenName = "Johann Blasius", EditorsOrganisationName = "Independent Architecture" }; using var loin = Model.Create(editor); using var txn = loin.Internal.BeginTransaction("LOIN creation"); var actor = loin.CreateActor("Client", "Owner of the building"); var milestone = loin.CreateMilestone("Preliminary design", "Preliminary design handover milestone"); var reason = loin.CreatePurpose("Handoved", "Handover of data"); var item = loin.CreateBreakedownItem("Window", "E456.789.12", "Window is a building element used to controll light flow into the space"); var width = loin.CreateSimplePropertyTemplate("Width", "Width of the window", nameof(IfcLengthMeasure)); var height = loin.CreateSimplePropertyTemplate("Height", "Height of the window", nameof(IfcLengthMeasure)); var code = loin.CreateSimplePropertyTemplate("BarCode", "Bar code of the window", nameof(IfcIdentifier)); var requirement = loin.CreatePropertySetTemplate("FM Requirements", "Requirements for Facility Management"); requirement.HasPropertyTemplates.Add(width); requirement.HasPropertyTemplates.Add(height); requirement.HasPropertyTemplates.Add(code); var requirements = loin.CreateRequirementSet("Base requirements", "Base requirements for the window"); requirements.Add(requirement); var context = new IContextEntity[] { actor, milestone, reason, item }; foreach (var contextItem in context) { contextItem.AddToContext(requirements); } txn.Commit(); // get MVD var mvd = loin.GetMvd(XbimSchemaVersion.Ifc4, "en", "LOIN Representation", "Requirements defined using LOIN, represented as validation MVD", "LOIN", "Classification"); mvd.Save("MinimalWindow.mvdXML"); using var model = IfcStore.Create(editor, Xbim.Common.Step21.XbimSchemaVersion.Ifc4, Xbim.IO.XbimStoreType.InMemoryModel); using var creationTxn = model.BeginTransaction(); var i = model.Instances; var clsRel = i.New <IfcRelAssociatesClassification>(r => { r.RelatingClassification = i.New <IfcClassificationReference>(c => { c.Name = "Window"; c.Identification = "E456.789.12"; }); }); var propsRel = i.New <IfcRelDefinesByProperties>(r => { r.RelatingPropertyDefinition = i.New <IfcPropertySet>(pset => { pset.Name = "FM Requirements"; pset.HasProperties.AddRange(new[] { i.New <IfcPropertySingleValue>(p => { p.Name = "Width"; p.NominalValue = new IfcLengthMeasure(12.45); }), i.New <IfcPropertySingleValue>(p => { p.Name = "Height"; p.NominalValue = new IfcLengthMeasure(78.65); }), i.New <IfcPropertySingleValue>(p => { p.Name = "BarCode"; p.NominalValue = new IfcIdentifier("987fsd-54fsdf6456-dsf65464-fs456"); }) }); }); }); var window = i.New <IfcWindow>(w => { w.Name = "Window #1"; }); clsRel.RelatedObjects.Add(window); propsRel.RelatedObjects.Add(window); creationTxn.Commit(); model.SaveAs("MinimalWindow.ifc"); var engine = new MvdEngine(mvd, model); var conceptRoot = engine.ConceptRoots.FirstOrDefault(); Assert.IsTrue(conceptRoot.AppliesTo(window)); foreach (var concept in conceptRoot.Concepts) { var passes = concept.Test(window, Xbim.MvdXml.Concept.ConceptTestMode.Raw); Assert.IsTrue(passes == ConceptTestResult.Pass); } }