Introduction

A MicroStation DGN file is a container: it contains one or more DGN models. A DGN model is also a container: it contains DGN elements, reference attachments and other objects. XML files delivered with MicroStation define multiple schemas, known as ECSchemas, that define DGN element, model, file and other classes and properties.

LASolutions NameSpace

The classes we describe below live in the LASolutions namespace. That helps to distinguish them from the ECClass and other EC classes provided by the MicroStationAPI.

EcDgnClass Class

EC LineElement class inheritance

The LASolutions::EcDgnClass is a base class we use for DGN EC classes such as the LASolutions::EcSegments class.

The EcInheritanceChecker is used to test whether an ECClass inherits from some other base class in the ECClass hierarchy. They both live in the LASolutions namespace. EcDgnClass provides methods common to many EC elements. EcInheritanceChecker lets us check that the instance we have inherits from a particular EC class. For example, the classes that have Segments inherit from EC class MstnLineSegments. If that condition is true, then we know that it's safe to search for Segments in a class instance.

struct EcDgnClass
{
  WCharCP              className_;
  ECN::IECInstancePtr  instance_;
  WCharCP    Name  ()  {   return className_;  }
  ///  Construct a class with the given name.
  EcDgnClass  (WCharCP name) : className_ (name) {}
  EcDgnClass  (WCharCP name, ECN::IECInstancePtr  instance) :
    className_ (name)
  {
    ValidateInstance (instance);
  }
  virtual ~EcDgnClass () {}
  ///  Verify that an ECInstance is valid and matches this class's name.
  ///  param name='instance': An ECInstance pointer.
  ///  Returns: True if instance is valid and has the same name as this class.
  bool            ValidateInstance    (ECN::IECInstancePtr  instance)  const;
  virtual bool    Assign              (ECN::IECInstancePtr  instance);
  bool            TestECObjectsStatus (WCharCP         caller,
                                       WCharCP         name,
                                       ECN::ECValueCR  value,
                                       ECN::ECObjectsStatus status)  const;
  bool            GetProperty          (ECN::ECValueR  value,
                                       WCharCP         propName) const;
  bool            GetProperty          (double&        value,
                                       WCharCP         propName) const;
  bool            GetProperty          (int&           value,
                                       WCharCP         propName) const;
  bool            GetProperty          (DPoint3dR      point,
                                       WCharCP         propName) const;
};

And the EcInheritanceChecker class …

struct EcInheritanceChecker
{
  WCharCP    baseClassName_;
  EcInheritanceChecker (WCharCP  baseClassName) : baseClassName_ (baseClassName) {}
  ///  Determine whether a class is derived from a name EC base class.
  ///  For example, LineElement, LineStringElement and ShapeElement all inherit from MstnLineSegments.
  bool    HasBaseClass          (ECN::IECInstancePtr  instance)  const;
  ///  Verify that an ECInstance is valid and matches this class's name.
  ///  Param name='instance': An ECInstance pointer.
  ///  Returns: True if instance is valid and has the same name as this class or one of its base classes.
  bool    ValidateBaseClass        (ECN::IECInstancePtr  instance)  const;

};

You can guess the implementation of most of the above, but I'll mention EcInheritanceChecker::HasBaseClass. Although we're writing C++, we can use a technique rather like C# reflection to find the base EC classes of a given EC class.

bool      EcInheritanceChecker::HasBaseClass  (ECN::IECInstancePtr  instance)  const
{
  bool    found  {false};
  ECN::ECBaseClassesList const&  classes = instance->GetClass ().GetBaseClasses ();
  for  (ECClassCP ecClass :  classes)
  {
    found = 0 == ecClass->GetName().CompareToI (baseClassName_);
    if (found)
      break;
  }
  return found;
}

Read about the EcSegments class.

Questions

Post questions about C# and C++ to the MicroStation Programming Forum.