[CONNECT C++] DgnElementSetTool: Query Elements in Reference Attachments

My query tool inherits from DgnElementSetTool.  It works fine for elements in the active model, but what should I do to enable it to locate elements in a reference?

Currently the tool shows a pop-up Element in reference that is not currently active or Element is in a ReadOnly ref.  

  • I answered my own question.  The solution is to add mdlLocate_allowLocked() in the _OnPostInstall event...

    void    QueryTool::_OnPostInstall ()
    {
        //Enable picking of elements
        _BeginPickElements ();
        mdlAutoLocate_setComplexComponentMode (ComponentMode::Innermost); //NOTE: Must be called after BeginPickElements!
        __super::_OnPostInstall ();
        //Permit location of elements in references -- not required: use the overridden method mentioned below
        mdlLocate_allowLocked ();
    }
    

    Note that mdlLocate_allowLocked() must be called after __super::_OnPostInstall ().

    I was initially put off using mdlLocate_allowLocked() because of this note in MicroStationAPI help...

    Obsolete enum; here only to help convert code

    Is that note irrelevant?


    Yongan's response below is a better solution.  It uses the DgnElementSetTool base class methods rather than introduce MDL functions.

     
    Regards, Jon Summers
    LA Solutions

    Answer Verified By: Jon Summers 

  • Hello Jon,

    Apologize a long time not in this English forum because there is always a lot Chinese posts on ChinaFirst Programming forum.

    A formal and simpler approach to do this is to override _IsModifiedOriginal member function and return false.

    virtual bool _IsModifyOriginal () override {return false;}



  • Another recommendation:
    mdlAutoLocate_setComplexComponentMode can normally be called in _SetupAndPromptForNextAction where _BeginPickElements has been called.



  • Unknown said:
    Apologize a long time not in this English forum

    Good to hear from you again!

    Unknown said:
    virtual bool _IsModifyOriginal () override {return false;}

    Thanks!  The documentation is a little ambiguous about that method  8-)

     
    Regards, Jon Summers
    LA Solutions

  • Hello Jon,

    It works for me. As an example, after I add this line in C:\Program Files\Bentley\MicroStationCONNECTSDK\examples\Elements\exampletool\ExampleModifyTool.cpp as below, it can accept linestring in reference.

    Maybe other staffs  in your code prevents it work.



  • Unknown said:
    Maybe other staffs stuff  in your code prevents it work

    Yes!  I have a base class that does exactly what you say.  Unfortunately I had a derived class that did something different.  In response to your hint I have adopted William Bushnell Stout's maxim: simplicate and add lightness. Now, it all works fine.

     
    Regards, Jon Summers
    LA Solutions

  • Good to know your code works fine and thank you pointing me out my English word error (staff or stuff).

    In Chinese, there are a lots of very similiar words as well.For example,戌 and 戍, 士 and 土. :)



  • Just wanted to add a couple things that probably aren't obvious.

    DgnElementSetTool establishes the locate criteria in _SetLocateCriteria (which is called from _BeginPickElements for pick and _BuildAgenda for fences and selection sets). This is the place to add any tool specific locate criteria as opposed to _OnPostInstall.

    Returning false from _IsModifyOriginal allows locked/reference elements to be selected as it puts DgnElementSetTool into copy mode. For a query only tool this can have the undesirable side-effect of cloning styles, etc. from the source to the destination.

    To avoid this, a query tool should override _OnPreElementModify. If you return SUCCESS without calling super, _OnElementModify will still be called if that's were you want to have your logic to extract information from the selected elements.

    virtual StatusInt _OnElementModify (EditElementHandleR eeh) override {return ERROR;} // Query tool doesn't modify elements...
    virtual StatusInt _OnPreElementModify (EditElementHandleR eeh) override {return SUCCESS;} // Don't copy styles, etc. from reference to active...
    virtual bool _IsModifyOriginal () override {return false;} // Allow selection of locked/reference elements

    HTH

    -B