使用本模块中的提供类读取DgnModel中各类实体对象时,可按如下两种方式使用:
(1)直接基于DgnPlatformNET.Elements.Element对象等价创建
在SDK中,有许多类都包含一个名为 CreateFromElement 的静态函数。凡是拥有这种静态函数的类,都可以使用类型等价的Element来创建SDK中对应类对象的实例,有了类的实例,即可访问其中的属性和方法。但这样做的前提是所传入Element所代表CIF类对象的类型必须与SDK中类的类型相匹配。下表给出CIF中类与SDK中类的对照表:
SDK类名称
CIF类名称
CIF类所在命名空间
Alignment
LinearEntity2dInPlan
Bentley.CifNET.GeometryModel
PointEntity2d
Profile
ProfileEntity
StationEquation
Stationing
StationEntity
LinearEntity3d
LongSectionSpace
SuperElevationSpace
TerrainSurface
DTMEntity
Surface
SurfaceEntity
CorridorSurface
MeshSurfaceEntity
ScalableMeshSurface
ScalableMeshEntity
Corridor
Bentley.CifNET.GeometryModel.RoadwayDesigner
SuperElevationSection
SuperElevationSectionNamedEntity
Bentley.CifNET.GeometryModel.SuperElevation
SuperElevation
SuperElevationNamedEntity
SuperElevationTransition
SuperTransitionEntity
FeatureDefinition
ObjectSettings
Bentley.CifNET.GeometryModel.ContentManagement
ApplicationObjectSettings
GeometryPresentation
GeometryAspect
LinearGeometryPresentation
LinearGeometryAspect
PointGeometryPresentation
PointGeometryAspect
AnnotationDefinition
Annotation
AnnotationProcessingGroup
RoleSetOverrides
AnnotationGroupReference
Role
AnnotationGroup
SurveyPoint
Bentley.SurveyToolsNET
SurveyChain
FeaturizedEntity
Bentley.CifNET.Model
XSectionNamedBoundary
ProfileNamedBoundary
PlanNamedBoundary
例如,假设我们在OpenRoads Designer中选择了一条平面曲线,则可以通过如下代码将其转换为SDK中的Alignment对象(C++/CLI语法):
由此可见,此方式非常适合于使用SDK提供的API现场提取特定Element中的数据。但此方法显而易见的缺点就是:并不是所有SDK都有对应的Element,所以,在这种情况下,可以使用第2种方法顺序扫描。
(2)通过连接到DgnModel的方式进行顺序扫描
此方法的使用流程为:
a.调用ConsensusConnection::Create()建立一个与给定DgnModel的连接:
b.通过建立的连接先获取其下包含的对象,然后依次调用所获取对象的属性或方法,最终得到需要的信息。例如,下面的代码先通过已建立的连接获取激活的GeometricModel,然后从GeometricModel中的Alignments集合中获取首个Alignment,然后从Alignment中分别获取了Alignment中包含的平面曲线LinearElement以及纵断面曲线ProfileElement:
c.完成对DgnModel的扫描后,关闭连接:
下面的代码片段完整演示了如何通过SDK中的API提取路线平曲线和竖曲线上的PI信息: