Skip to content

Latest commit

 

History

History
127 lines (79 loc) · 6.48 KB

FlowBasedPlugin.md

File metadata and controls

127 lines (79 loc) · 6.48 KB

Design Steps for Flow Based Plugins

Creating Workspace and Toolbars in Rhino

This section describes how to create a Workspace and Toolbars using Rhino 6.

  1. Create a separate workspace called Flows from Tools > Options > Toolbars

    Flows-Workspace.png

  2. Next step is to add a new toolbar called Sample Flow as shown below

Sample-Flow-Toolbar.png Note: Our goal is to connect the Sample Flow toolbar with a plugin of the same name.

  1. Then several buttons are added to the Sample Flow toolbar. Here each button represents a particular step in the flow.

Sample-Flow-Steps.png

For a detailed description on how to create macros for toolbars go here.

Note: The goal is to connect each step in the Sample Flow toolbar with a command in the plugin with the same name.

Creating C++ SampleFlow Rhino Plugin

  1. Open up the Flows folder in Visual Studio 2017.

  2. Create new project in Visual Studio 2017 File > New > Project

  1. Open the SampleFlow.sln file from Flows/ folder and rename the solution to Flows

  2. Go to the auto generated SampleFlow Visual C++ project and in the stdafx.h file, uncomment line 19 #define RHINO_SDK_MFC. We need to uncomment this line as we would be using the MFC UI functionality.

    Note: Rhino 6 is almost MFC free except for the RhinoUI library which requires MFC as the Rhino Application is based on MFC

  3. Go to file SampleFlowPlugIn.cpp and comment the line 46 so that the plugin compiles. Note that in general delete this line after filling in the appropriate information asked for.

  4. In Visual Studio 2017 go to Project > Properties and then in C/C++ > Language change the C++ Language Standard to ISO C++14Standard (/std:c++14) and apply

CompilerOptions.png

Followed by build, this should compile the SampleFlow Rhino plugin project successfully.

Create Menu and Menu-items in Flows.rui

  1. In the next step go to the Flows.rui workspace and open the Workspace Editor and go to the Menus, then add the Menu and Menu-Item.

  2. To connect the menu item Sample Flow to the plugin we use the Workspace Editor in Rhino to create the corresponding C++ code.

MenuItem-PluginCode.png

  1. Then transfer the code to the SampleFlow plugin project into the following files : FlowsRuiOnUpdateMenuItems.h, FlowsRuiOnUpdateMenuItems.cpp
#include "stdafx.h"
#include "FlowsRuiOnUpdateMenuItems.h"
#include "SampleFlowPlugIn.h"

CFlowsRuiOnUpdateMenuItems::CFlowsRuiOnUpdateMenuItems()
{
    // Register OnUpdateMenuItem callback for this item
    RegisterMenuItem(CSampleFlowPlugIn::m_idFile, CSampleFlowPlugIn::m_idMenuFlows, CSampleFlowPlugIn::m_idMenuItemSampleFlow);
}

void CFlowsRuiOnUpdateMenuItems::OnUpdateMenuItem(CRuiUpdateUi& cmdui)
{
    // Enable menu item
    if (CSampleFlowPlugIn::m_idMenuItemSampleFlow == cmdui.MenuItemUUID())
    {
        cmdui.Enable(true);
    }
}

and the following static const variables are added to SampleFlowPlugIn.cpp

const UUID CSampleFlowPlugIn::m_idFile = { 0x6fbd18ca, 0xbdce, 0x44ae, { 0xba, 0x8f, 0x3c, 0x2c, 0x46, 0x3e, 0x52, 0xf9 } };
const UUID CSampleFlowPlugIn::m_idMenuFlows = { 0x130a9a5b, 0x5620, 0x4588, { 0x96, 0x41, 0x13, 0xd6, 0x7d, 0x4a, 0x19, 0x07 } };
const UUID CSampleFlowPlugIn::m_idMenuItemSampleFlow = { 0x7648b550, 0xb008, 0x42ab, { 0xb2, 0xb3, 0xf1, 0xb8, 0xf4, 0xac, 0xe5, 0x97 } };

Connect a menu item to a toolbar

Now we would like to connect the Menu-item Sample Flow with the corresponding Sample Flow toolbar.

  1. First we open the Workspace Editor for the Flows.ruiand then goto Menus.
  2. Click on Flows > Sample Flow > Item Properties

SampleFlow-ItemProperties.png

  1. After this in the Command section of Item Properties for Sample Flow call the correct commands such that the Toolbar pops up.

    SampleFlowMenu-Command.png

Show / Hide Toolbar

TODO

How to deploy a toolbar with a plugin

The next step would be to connect the Simple Flow toolbar with the plugin with the same name. Create and Deploy Toolbars

Programmatically connect Start Flow to plugin

In this section we will describe the steps to programmatically connect Start Flow button in the Sample Flow Toolbar to the Sample Flow plugin in Rhino. The design is based on the Command pattern.

  1. For the Start Flow button we create a corresponding command cmdStartFlow.cpp in the Flows.sln.

  2. For the Start Flow button we create a new Viewport for our Sample Flow plugin. This is done by using the Command Pattern and creating a separate class called CSampleFlowViewReceiver such that from the class CCommandStartFlow we invoke the action method on a CSampleFlowViewReceiver object.

  3. The next step then is to connect the Start Flow command in the Sample Flow plugin to the Start Flow button Edit-Start-Flow-Button.png Start-Flow-Button-Command.png