Comments (2)
Hi @iwacky , Validate is not there because we didn't find a way to generate all the where
functions from the schema. See this article about new and lost features in xBIM4: https://xbimteam.github.io/xbim-4/xbim-4-release-notes.html Page is still work in progress but it should give you some idea.
It is still possible to validate mandatory fields and number of items in lists. This code should do that at least:
using System;
using System.Collections;
using System.Linq;
using Xbim.Common;
namespace BasicValidation
{
public class Validator
{
public static void Validate(IModel model)
{
var errCount = 0;
foreach (var instance in model.Instances)
{
var type = instance.ExpressType;
//check mandatory attributes
var mProps = type.Properties.Where(p => p.Value.EntityAttribute.IsMandatory);
foreach (var prop in mProps)
{
var property = prop.Value;
var index = prop.Key;
var val = property.PropertyInfo.GetValue(instance);
var expVal = val as IExpressValueType;
if (val == null || (expVal != null && expVal.Value == null) )
{
errCount++;
Console.WriteLine($"#{instance.EntityLabel}={type.ExpressNameUpper}: missing attribute {property.Name} (no. {index})");
}
}
//check required number of items in lists
var colProps = type.Properties.Where(p => p.Value.EnumerableType != null);
foreach (var prop in colProps)
{
var property = prop.Value;
var index = prop.Key;
var min = property.EntityAttribute.MinCardinality;
var max = property.EntityAttribute.MaxCardinality;
if (min > 0 || max > 0)
{
var value = property.PropertyInfo.GetValue(instance) as IList;
var count = value.Count;
//if it is uninitialized optional set continue
var optionalList = value as IOptionalItemSet;
if (optionalList != null && optionalList.Initialized == false)
continue;
if (min > 0 && count < min)
{
errCount++;
Console.WriteLine($"#{instance.EntityLabel}={type.ExpressNameUpper}: too few items in {property.Name} (no. {index}). Minimal count is {min}.");
}
if (max > 0 && count > max)
{
errCount++;
Console.WriteLine($"#{instance.EntityLabel}={type.ExpressNameUpper}: too many items in: {property.Name} (no. {index}). Maximum count is {max}.");
}
}
}
}
if (errCount == 0)
Console.WriteLine("No errors found.");
else
Console.WriteLine($"{errCount} errors found.");
}
}
}
from xbimessentials.
Helpful answer, thank you.
from xbimessentials.
Related Issues (20)
- InverseProperty performance HOT 2
- PredefinedType in IIfcBuildingElementProxy not updatable HOT 3
- Non-canonical matrix-vector product HOT 3
- Model instances filter from interfaces HOT 10
- ManageOwnerHistory
- setting object colour for item exported from autocad HOT 1
- Support for IFC 4x3 HOT 4
- Reading STEP files HOT 2
- Provide means of accessing PredefinedType values from super-classes/interfaces
- Getting correct world coordinates of the element
- Geometry Store is empty on latest XbimEssentials 6.0.443-develop HOT 10
- Possibility of splitting IFC file into a few pieces HOT 2
- Exception ("Out of table cursors") from Xbim.IO.Esent-6.0.445 , While processing IFC files with size > 150 MB HOT 2
- Changing color of IfcBuildingElementProxy HOT 4
- how to create Space from objects such as wall, windows, doors, etc HOT 1
- IFCXml File with empty header throws exception HOT 2
- Windows, Doors, .. HOT 3
- Layers & Elements? HOT 1
- Move PDBs from NuGet packages to symbol packages
- IFC file with single backslash in STRING (HEADER:FILENAME) fails to load. HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xbimessentials.