0

I need to create a class library based on an EXPRESS schema. The EXPRESS schema has types and entities looking like the following:

ENTITY IfcRoot
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcObjectDefinition
    ,IfcPropertyDefinition
    ,IfcRelationship));
    GlobalId : IfcGloballyUniqueId;
    OwnerHistory : OPTIONAL IfcOwnerHistory;
    Name : OPTIONAL IfcLabel;
    Description : OPTIONAL IfcText;
 UNIQUE
    UR1 : GlobalId;
END_ENTITY;

In here GlobalId, OwnerHistory, Name, and Description are all properties of the class IfcRoot. The property type of for example "Name" is IfcLabel, which is given as a TYPE in the EXPRESS schema looking like this:

TYPE IfcLabel = STRING(255);
END_TYPE;

This type is of the type String or well string array. In my approach, I implemented all the entities in the schema and all the types in the schema as classes in chsharp. Therefore I wrote a string-reader, that reads the schema and creates the entities (~800) and the types (~400) based on that. IfcLabel in my implementation looks like this:

public class IfcLabel
{
   public string _value { get; set; }
}

It all works completely fine, but when I want to use my class library it is really laborious due to the fact that each attribute type is a class itself. Meaning I have to create an object of the IfcLabel-Class first and assign the _value property and then create my IfcRoot-object and assign the Name-property as the IfcLabel-object. Does anyone have an idea, how I can implement that in a smarter way? There is one more thing to add: all types need to have a method and inherit from a class called IfcBase so that still needs to be possible. I am also not allowed to directly change the property type from IfcLabel to string, which it actually is in the end anyway.

Jaimesh
  • 841
  • 4
  • 25
  • 41
FlixFix
  • 63
  • 9
  • [factory pattern?](https://www.google.com/search?q=factory+pattern&ie=utf-8&oe=utf-8&client=firefox-b) – TaW Jul 11 '17 at 07:37
  • 1
    I haven't heard bout that before, but from what I quickly read it looks like a possible solution to my problem. I'll look more into it, thanks! – FlixFix Jul 11 '17 at 08:04
  • I'm not sure about it but i think that the `express` tag isn't the good one since it doesn't look like a nodeJs framework implementation here – mJehanno Jul 11 '17 at 08:54
  • I just put that because that's the type of the schema is called. What else would you recommend? – FlixFix Jul 11 '17 at 08:55
  • just edited my tags, hoping to get an answer. Cheers for the heads-up! – FlixFix Jul 13 '17 at 07:19
  • If you aren't aware of the subject of design patterns, I would suggest you take the time to read about the ones you find either [here](http://www.dofactory.com/net/design-patterns) or [here](https://sourcemaking.com/design_patterns). There are not very many and you don't need to know them by heart, just that they exist, and then you can look them up when needed and see how they're usually implemented. – s.m. Jul 13 '17 at 07:23
  • okay, I got it, gonna read the documentations in the links, thank you very much for providing them! – FlixFix Jul 13 '17 at 07:29

2 Answers2

1

To simplify the IfcLabel you might want to use implicit operator overloading so you can treat IfcLabel as a String, without having Name._value through your code.

If this is more than an educational project, it might be worth looking at how others have tackled this. E.g. the Xbim project has C# libraries to read & write IFC files. For reference here's their implementation of IfcRoot and IfcLabel:

https://github.com/xBimTeam/XbimEssentials/blob/master/Xbim.Ifc4/Kernel/IfcRoot.cs#L58 https://github.com/xBimTeam/XbimEssentials/blob/master/Xbim.Ifc4/MeasureResource/IfcLabel.cs

If you actually have a need to work with IFC EXPRESS files commercially I can recommend looking at battle-hardened library, like XBim, or IfcOpenShell as it's a complex domain to be writing your own from the ground up.

Andy Ward
  • 324
  • 2
  • 7
  • Hey Andy, thank you very much for your answer! I am only a civil engineering student writing my bachelor's thesis which consists of programming an ifc export plugin for Autodesk Civil 3D. However, I had no programming knowledge whatsoever since two months ago. My AddIn is written in C-Sharp and therefore I needed to create an CSharp early Binding (well at least that was the easiest way for me to do it). My implementation surely is completely basic and not 100% correct in some parts, but it works and I can export my .dwg drawing to an .ifc file now and open it with the ifc engine viewer. – FlixFix Jul 17 '17 at 05:31
  • I posted some more code in my answer, which I couldn't do in a comment. Just so you can see my implementation. – FlixFix Jul 17 '17 at 05:39
0

still not nice, but at least a little better, because I can fold the whole object declaration making it look a bit clearer in Visual Studio, I did this:

IfcAlignment2DVerSegLine ifcVerSegLine = new IfcAlignment2DVerSegLine()
{
   m_StartDistAlong = new IfcLengthMeasure()
  {
     _value = verTangent.StartStation
  },
   m_HorizontalLength = new IfcPositiveLengthMeasure()
  {
     _value = new IfcLengthMeasure()
     {
        _value = verTangent.Length
     }
  },
   m_StartGradient = new IfcRatioMeasure()
  {
     _value = verTangent.Grade
  },
   m_StartHeight = new IfcLengthMeasure()
  {
     _value = verTangent.StartElevation
  }
};

folds to:

IfcAlignment2DVerSegLine ifcVerSegLine = new IfcAlignment2DVerSegLine()...;

So that works for my purpose at the moment. Surely if this product should ever become commercial, I will have to rewrite my early binding.

FlixFix
  • 63
  • 9