[CONNECT .NET] DgnTool tool settings

What is the purpose of DgnTool.PopulateToolSettings()?  Where and how does it find the list of dialog items with which to populate MicroStation's tool settings dialog?  What does its Boolean return value signify?

Parents
  • Hi Jon,

    What is the purpose of DgnTool.PopulateToolSettings()?

    The method is described in MicroStation API documentation for DgnTool Struct: Called to populate the tool tool settings for this tool.

    ... which I agree is not very descriptive and clear ;-)

    But based on return values explanation I guess it's used by engine, when processing the tool object, to check whether the tool will take care about the tool settings (e.g. it attach WinForm or WPF to Tool Settings dialog) or MicroStation shoul load the definition from resources.

    Where and how does it find the list of dialog items with which to populate MicroStation's tool settings dialog?

    In my opinion a question here is whether it's possible or if it's just a consequence of wrapping native DgnTool class.

    My assumption is that it's the same process how XCommands can be utilized in .NET AddIns: It's about how project is compiled to let MicroStation know that rsc file should be loaded together with managed AddIn.

    I am not aware of any such example :-(

    What does its Boolean return value signify?

    true if handled by tool,
    false populate the tool settings by command number/command item list id. 

    By default (when the method is not overriden), false is returned.

    With regards,

      Jan

  • What does its Boolean return value signify?

    Populate the tool settings by command number/command item list id

    So how is that list ID specified? In a .NET project, where is that list?

    It seems to me that DgnTool is an incomplete wrapper around the C++ class.  There are loose ends regarding access to MicroStation resource data (e.g. message lists, dialog item lists) that need to be completed and documented. 

    Right now the MstnPlatformNet is not a complete and robust alternative to the MicroStationAPI.  That's disappointing after 2 years as a Release Candidate and subsequently 4 years as a commercial product (MicroStation CONNECT was release in August 2015).

     
    Regards, Jon Summers
    LA Solutions

  • FYI. Per this thread, I have asked development review and recommendation on the topic of this thread. We will provide an update as soon as available.

    Thank you,
    Bob



  •   the DgnTool.PopulateToolSettings do nothing but return false and is waiting for the derived user tools to override it. However I don't find any tool in the CE internal tools, and SDK examples which override and implement it. The return bool value means whether or not it populate tool settings successfully, but I don't know how to populate it.

      if you just want to design a .Net tool with tool settings, we provide a more preferable way as following, using WPF VMMV manner. Then in the .Net tool, you can access the tool setting properties in your view model flexibly.

    1. design your own setting controls in a xaml

    <UserControl x:Class="ReplaceContentToolSettings">

    ...

    </UserControl>

    1. design your ViewModle to communicate with your tool setting UserControl

    public class ReplaceContentVm : DisposableViewModelBase

    {

    ...

    }

    1. bind your view model to the setting controls in your UserControl

    public partial class ReplaceContentToolSettings : UserControl

    { 

    ...

    internal ReplaceContentVm ViewModel

    {

    get { return DataContext as ReplaceContentVm; }

    set { DataContext = value; }

    }

    ...

    }

    1. design your ToolSettingsHost

    internal class ReplaceContentToolSettingsHost : ToolSettingsHost

    {

    internal ReplaceContentToolSettings Settings { get; private set; }

    internal ReplaceContentToolSettingsHost()

    {

    Settings = new ReplaceContentToolSettings();

    Settings.ViewModel = new ReplaceContentVm();

    Content = Settings;//key point to display your setting controls in the tool setting host dialog

    SizeToContent = SizeToContent.WidthAndHeight;

    Title = Properties.Resources.ToolSettingsTitle_ReplaceContent

    }

    }

    1. design your .Net tool and attach ToolSettingsHost

    internal class ReplaceContentTool : DgnElementSetTool

    {

    private ReplaceContentToolSettingsHost SettingsHost { get; set; }

    internal ReplaceContentToolSettings Settings { get { return SettingsHost.Settings; } }

    private ReplaceContentVm ViewModel { get { return Settings.ViewModel; } }

    internal ReplaceContentTool() : base(0, 0)

    {

    SettingsHost = new ReplaceContentToolSettingsHost();

    }

    protected override void OnPostInstall()

    {

    SettingsHost.Attach(PCMAddIn.Instance); // key point to attach the wpf tool setting dialog to your tool and show the dialog

    base.OnPostInstall();

    }

    protected override void OnCleanup()

    { 

    SettingsHost.Detach();

    SettingsHost.Dispose();

    }

    ...

    }

  • I don't find any tool in the CE internal tools, and SDK examples which override and implement it. The return bool value means whether or not it populate tool settings successfully, but I don't know how to populate it

    That was my question.

    If you just want to design a .Net tool with tool settings, we provide a more preferable way as following, using WPF VMMV

    Thanks, but that seems excessively convoluted.  I'll wait for an example to show up in the SDK.

    Meanwhile, I'll stick with the MicroStationAPI and CommandTable resources: they work well, are documented, and plenty of examples exist.

     
    Regards, Jon Summers
    LA Solutions

  • Thanks, but that seems excessively convoluted

    I agree that for simple dialogs with just a few items to implement MVVM (Model-View-ViewModel) pattern is just overkill.

    On the other hand, MVVM was invented specifically for WPF and it's "core" of WPF stack, so it's great it's supported also in MicroStation API. My experience is when GUI patterns like MVC (quite common), MVP (WinForms) or MVVM (WPF) are used, other styles with no clear functional split become unclear and dirty ;-)

    Regards,

      Jan

  • Hi Jon,

    There is an example in the "WPFDemo" Project provided with the Bentley SDK.

    I disagree about dorlig na's example being convoluted. This is object oriented programming after all. If your tool gets big, you will wish you did it that way.

    Cheers,

    Rich

  • There is an example in the "WPFDemo" Project provided with the Bentley SDK

    Yes: the SDK examples are my first port of call.  However, WPFDemo doesn't include the subject of this question: PopulateToolSettings.

    I disagree about dorlig na's example being convoluted. This is object oriented programming after all

    Are you able to answer my question: Where and how does DgnTool.PopulateToolSettings find the list of dialog items with which to populate MicroStation's tool settings dialog?

     
    Regards, Jon Summers
    LA Solutions

  • Looks like it is a virtual. So I believe it is something you would need to implement when you inherit from their interface and can override it.

    Rich

  • Hi  ,

    Sorry I cannot provide a full answer and code example (for the SDK) at this time, but maybe some additional information from various pieces/paths other (internal) developers have taken may help.  The first and third approaches may be the most simple to construct and test, where the second approach (what you are asking) will likely take more time/effort to break out into a working example:

    1. DgnTool create a custom WPF ToolSettingsHost as ToolSettings (See WPFDemo Example):

      C:\Program Files\Bentley\MicroStationCONNECTSDK\examples>s ToolSettingsHost *.cs
      WPF\WPFDemo\MyToolSettings.cs:20:        class MyToolSettings : ToolSettingsHost
      WPF\WPFDemo\MyToolSettings.cs:34:        public ToolSettingsHost ToolSettingsHost { get; private set; }
      WPF\WPFDemo\MyToolSettings.cs:38:            ToolSettingsHost = new MyToolSettings (this);
      WPF\WPFDemo\MyToolSettings.cs:45:            ToolSettingsHost.Attach (WPFDemoApp.Instance);
      WPF\WPFDemo\MyToolSettings.cs:50:            ToolSettingsHost.Detach ();
      WPF\WPFDemo\MyToolSettings.cs:51:            ToolSettingsHost.Dispose ();
      WPF\WPFDemo\MyToolSettings.cs:52:            ToolSettingsHost = null;
      C:\Program Files\Bentley\MicroStationCONNECTSDK\examples>s ToolSettingsHost *.cs
      WPF\WPFDemo\MyToolSettings.cs:20:        class MyToolSettings : ToolSettingsHost
      WPF\WPFDemo\MyToolSettings.cs:34:        public ToolSettingsHost ToolSettingsHost { get; private set; }
      WPF\WPFDemo\MyToolSettings.cs:38:            ToolSettingsHost = new MyToolSettings (this);
      WPF\WPFDemo\MyToolSettings.cs:45:            ToolSettingsHost.Attach (WPFDemoApp.Instance);
      WPF\WPFDemo\MyToolSettings.cs:50:            ToolSettingsHost.Detach ();
      WPF\WPFDemo\MyToolSettings.cs:51:            ToolSettingsHost.Dispose ();
      WPF\WPFDemo\MyToolSettings.cs:52:            ToolSettingsHost = null;


    2. DgnTool create a custom ToolSettingsHost passing a ViewModel of control items as ToolSettings:

      TODO: Identify and/or Provide a code snip/example passing a ViewModel based on a custom WPF .xaml.cs
    3. DgnTool create a custom Bentley.MstnPlatformNET.WinForms.Adapter to use as ToolSettings:

      protected override void OnPostInstall()
      {
      	base.OnPostInstall();
      	ToolSettings = new MyToolSettingForm();
      	ToolSettings.AttachToToolSettings(AddIn.App);
      }
      
      protected override void OnCleanup()
      {
      	ToolSettings.DetachFromMicroStation();
      	base.OnCleanup();
      }

       public partial class MyToolSettingForm : Bentley.MstnPlatformNET.WinForms.Adapter
          // public partial class MyToolSettingForm : Form
          {
              private bool allowEntered = true;
      
              public MyToolSettingForm()
              {
                  InitializeComponent();
                  this.textBoxColor.Text = "MyTextItem";
                  ...


    4. DgnTool [C++] populate ToolSettings using existing CMDID resources as ToolSettings:

      bool MyTool::_PopulateToolSettings ()
          {
          DgnTool::PopulateToolSettingsByCommandNumber (CMD_MYCOMMAND, GetMdlDesc ());
          return true;
          }

    HTH,
    Bob



  • Looks like _PopulateToolSettings is a virtual. So I believe it is something you would need to implement

    You're quoting the C++ MicroStationAPI documentation.  This question is about .NET.

    It is something you would need to implement

    The MicroStationAPI documentation is clear: return false to let the MicroStation engine populate the tool settings.  That's a well-established way to implement a command with custom tool settings.  The dialog items for tool settings are defined in a command item list (CmdItemListRsc) stored in a resource (*.r) file.  It's been available in MDL for decades and more recently improved in the C++ MicroStationAPI.  My question is: How do I achieve the same using .NET?

     
    Regards, Jon Summers
    LA Solutions

  • Hi Jon,

    The C++ MicroStation API reference is pretty much the same. Isn't the .NET API built off of the C++ API?

    I was referring to .NET though. It says the same thing in the Visual Studio Object Browser when you look at the DgnTool Class. You would create an override in your command just like you would for an OnCleanup() event. Then, define what you want it to do when the command calls it. Guessing you already know how to do all this though and I was not fully understanding your question.

            protected override bool PopulateToolSettings()
            {
                //Do Stuff
                //return true;//The .NET Tool will attach a User Control
                return false;//Who knows? Maybe there is a way to define it in
                             //the commands.xml for the command. 
            }
    
            protected override void OnCleanup()
            {
                Settings.Detach();
                Settings.Dispose();
                Settings = null;
    
                //MessageBox.Show("OnCleanUp");
            }

    I am not sure how to tie a list of controls to the tool settings for a command in .NET like you could in the C++ API. They are so different. It probably isn't even possible and I am not sure it makes sense to make it possible. It is pretty easy to create a WPF User Control and attach it as a ToolSettingsHost.

    Maybe they can implement some clever way for us to define the controls for a Command Tool Settings window when we define the key-in in the command.xml file. There'd need to be some way to bind the control's value to a property defined in the command too. Just like you could do in the C++ API with access strings.

    Rich

Reply
  • Hi Jon,

    The C++ MicroStation API reference is pretty much the same. Isn't the .NET API built off of the C++ API?

    I was referring to .NET though. It says the same thing in the Visual Studio Object Browser when you look at the DgnTool Class. You would create an override in your command just like you would for an OnCleanup() event. Then, define what you want it to do when the command calls it. Guessing you already know how to do all this though and I was not fully understanding your question.

            protected override bool PopulateToolSettings()
            {
                //Do Stuff
                //return true;//The .NET Tool will attach a User Control
                return false;//Who knows? Maybe there is a way to define it in
                             //the commands.xml for the command. 
            }
    
            protected override void OnCleanup()
            {
                Settings.Detach();
                Settings.Dispose();
                Settings = null;
    
                //MessageBox.Show("OnCleanUp");
            }

    I am not sure how to tie a list of controls to the tool settings for a command in .NET like you could in the C++ API. They are so different. It probably isn't even possible and I am not sure it makes sense to make it possible. It is pretty easy to create a WPF User Control and attach it as a ToolSettingsHost.

    Maybe they can implement some clever way for us to define the controls for a Command Tool Settings window when we define the key-in in the command.xml file. There'd need to be some way to bind the control's value to a property defined in the command too. Just like you could do in the C++ API with access strings.

    Rich

Children
No Data