3.ChinaSDK AnnotationSDK关键用法详解


 

1.       MyAnnotationProvider类的作用

      此类最主要的功能就是注册与反注册。注册具体实现以下函数:

void MyAnnotationProvider::Initialize()

    {

    if (!m_isRegistered)

        {

            Bentley::Cif::Annotation::AnnotationManager::GetManager().RegisterBinder(GeometryPresentation::GetAnnotationResolver());

        Bentley::Cif::Annotation::AnnotationManager::GetManager().RegisterProvider(*this);

 

        ECN::SchemaNameClassNamePair pair;

 

        pair = ECN::SchemaNameClassNamePair(L"Civil", L"AligmentUser");

        AnnotationManager::GetManager().SetPreviewDgnForTargetType(L"PlanGeometry", pair);

 

        m_isRegistered = true;

        }

}

 

    我们对MyAnnotationProvider类实例化的时候再构造函数中设置m_isRegistered变量为false,第一次注册时判断m_isRegistered变量的值,然后通过AnnotationManager中的RegisterProvider函数注册此Provider类。注册后m_isRegistered设置为true,又因为MyAnnotationProvider已经单例化,从而防止注册函数再次注册此类。

 

    另外此类中实现了虚函数_GetPrimaryClasses,如下。此函数的作用是对自定义的Annotation可以在添加到哪一种类型的Annotation Group中添加此类自定义Annotation

void         MyAnnotationEnabler::_GetPrimaryClasses(bvector<ECN::SchemaNameClassNamePair>& clasSchemaPairs) const

    {

    clasSchemaPairs.push_back(ECN::SchemaNameClassNamePair(L"Civil", ALIGNMENT_CLASSNAME));

    }

   以上代码的运行效果如下图所示:此函数的作用是设定我们可以在哪种Annotatio GroupManage Annotatios界面中去添加AnnotationDefinition

  

2.     MyAnnotationEvaluator类的作用

          此类的作用是获取被标注元素的信息、绘制标注元素。

          此类中主要是virtual StatusInt _Draw(AnnotationDrawingContextCR context) override虚函数的实现。此函数在Manage Annotatios界面的预览时或者我们标注被标注元素时调用此函数。

 

         在标注被标注对象时,我们可以获取我们在AnnotationDefinition中所定义的标注参数,比如间隔、标注线绘制长度。此类属性都在MyAnnotationEnabler类中进行了存储。

 

        我们获取被标注元素时(假设标注的对象是Alignment),我们调用了以下函数

Alignment::CreateFromDgnElementECInstance(GetAnnotatedInstance());

GetAnnotatedInstance()在基类中实现,即在基类中已经给我设定好了要标注的实例。

        我们在获取标注参数值的时候,比如获取长度值时我们需要做以下的比例转换,

context.GetScaleDefinition().DesignScaleUorsFromMaster(GetLineLength());

      

3.       MyAnnotationEnabler类的作用

对属性的存储:示例代码如下,

void MyAnnotationEnabler::_AddProperties() const

    {

    int priority = 1000;

    int category = 1000;

 

    ……………………………………………….

 

    // LINE

    cat = L"LINE";

    category--;

    AddDoubleProperty(cat.c_str(), category, priority--, L"Length", L"Length", 0.01);

 

    AddDoubleProperty(cat.c_str(), category, priority--, L"Interval", L"Interval", 10);

}

      此段代码的最主要作用是存储值并且在属性栏中显示相应值。

      另外把"Length"的值存储以后,我们可以在想要用到的地方,譬如在MyAnnotationEvaluator中可以调用以下函数把我们所存储的值取出。

    double GetLineLength()

        {

        double val;

        if (SUCCESS == GetDoubleValueParameter(val, L"Length"))

            return val;

        return 0.0;

        }

 

     MyAnnotationEvaluator的基类中已经实现了GetDoubleValueParameter函数。同样的包括boolint string等变量的存取,基类中都做了相应的实现。

 

        AnnotationDefinition名称的存储,实现原理是我们在派生类中实现了虚函数GetECClassDisplayName,此函数的作用是设定Manage Annotatios时添加的AnnotationDefinition的显示名称。如下图所示:

WString MyAnnotationEnabler::_GetECClassDisplayName() const

    {

    return L"My Aligment";

    }