jps services
  • Home Page
  • GIS Training Courses
    • QGIS Training Courses
    • ArcGIS Training Courses
    • MapInfo Pro Training Courses >
      • MapBasic Training Course
  • About
  • Blog

Updating MapBasic legacy code, which contains enable/disable menu/button features, to a ribbon interface

3/2/2017

1 Comment

 
The Mask application developed by TWIA.NL enables the user to create a mask around one or more selected polygons. The program is menu driven and also has a button and menu options which are enabled when one or more polygons are selected. When this program is run in the new MapInfo Pro ribbon interface the code is displayed under a legacy tab as shown in the following screen shot.
Picture
​The following screen shot shows how the button containing a mask image is disabled whilst there are no polygons selected.
Picture
Once a map has been opened and polygons selected the button and menu options are enabled as shown in the following screen shot.
Picture
Clicking on the enabled Mask button brings up a dialogue box where the user can choose various options when creating a mask. Once selected the mask is created and automatically saved to the table and location chosen by the user as shown in the following screen shot.  
Picture
Once the various options have been chosen the mask is created as in the following screen shot.
Picture
As the previous screen shots show the program works well under a legacy tab. However, this program offers an opportunity to upgrade the code so that the program is brought up to date with the new ribbon interface.

If you look at the original MapBasic code for this application you will note that it is all contained within a single program which can be compiled to an .mbx executable file.
 The Mask code consists of a Main and seven other sub procedures:-

CreateMask

This is the code to create the mask

SetTablePath

Selects the tablepath chosen by the user

SelChangedHandler

A reserved procedure, called automatically when the set of selected rows changes.

WinFocusChangedHandler

A reserved procedure, called automatically when the window focus changes

WinClosedHandler

A reserved procedure, called automatically when a Map, Browse, Graph, Layout, Layout Designer, Redistricting, Legend, Legend Designer, or MapBasicwindow is closed.

About

Dialogue box with instructions on how to use the application

End_Program

Procedure to check whether the use wishes to end the application

For more information on the SelChangedHandler, WinFocusChangedHandler and WinClosed Handler please look in the MapBasic Help section where you can also find example code.

The Main procedure contains the code to create a menu and a button which can be enabled if the user selects a polygon or polygons. The first step in creating a new ribbon based version is to change the Main procedure to reflect the new ribbon interface. This is shown in the following screen shots.​

Picture
Picture
The first part of the code follows a similar pattern to the code in my last blog. This code creates a new ribbon tab and group. This new code also adds a toggle button in addition to a standard button. We use the toggle button to show whether the user has selected a polygon. If the user has not selected a polygon then the button is shown as red. When the user selects the polygon this enables the button which then is toggled to green. I created the graphics for these two buttons in the Paint program. The two images were then saved to the Images file within the folders set up for this application. Again, the set up for creating ribbon based applications is explained in the previous blog.
As previously mentioned, because of the various modules needed within a ribbon based application this program was developed as a series of linked modules in order to create the final .mbx executable. Here is a screen shot of the .mbp project file for this program:-
Picture
Each of the sub procedures taken from the original Mask application were compiled into separate MBO's and then linked in a project file. Some of the procedures such as the CreateMask and SetTablePath needed no further modification for the new ribbon based version other than creating the MBO's.  However, as already shown the Main procedure and all the other modules needed modifications.  

​In addition we need to create a definition file as shown in the following screen shot:-
Picture
The About procedure was modified as the following screen shot shows:-
Picture
The SelChangedHandler module is also modified to respond to a ribbon based interface as shown in the following screen shot. Note that this module is only modified from the section of the code which starts with:-

If WindowInfo(FrontWindow), WIN_INFO_TYPE) = WIN_MAPPER Then:-

Picture
Picture
The other two procedures WinClosedHandler and WinChangedFocusHandler are also updated using this same section of code.
​
The other additional procedure is called RibbonMaskSwitchDisplay as shown in the following code:-
Picture
When the all the modules are compiled and linked the ribbon version of the Mask program is available as shown in the following screen shot:-
Picture
When a map is opened and a polygon selected the Ribbon Mask button switches to green to indicate that the mask option is available as shown in the following screen shows:-
Picture
Deselect the polygon and the Mask button switches back to Red as shown in the following screen shot:-
Picture
If another polygon is then selected and the Ribbon Mask button is now pressed the dialogue box appears for creating the mask. This is shown as seen in the following screen shot:-
Picture
When the dialogue box is accepted the mask is created based on the style and translucency selected by the user as shown in the following shot:-

Picture
Choosing the Info button brings up the modified dialogue box as shown in the following screen shot:-

Picture
Clicking on the Exit button brings up the dialogue box as shown in the next screen short:-

Picture
Choosing the Yes option will remove the application from MapInfo Pro including the Ribbon Mask App ribbon tab.

This code is based on the slide presentation given in November 2016 by Peter Horsbøll Møller. This presentation gives an overview of the features used in this current application and should be studied in conjunction with this blog to understand how how the application works.

1 Comment
Peter Horsbøll Møller
21/3/2017 12:13:19 pm

Nice use of changing the icon on a control to depict whether it can be used or not

Reply

Your comment will be posted after it is approved.


Leave a Reply.

    Author

    Joe Short BSc has been involved with various mapping solutions for over twenty years.  If you are considering implementing a GIS  or have ArcGIS Pro, MapInfo Pro or QGIS training requirements, jps services would be happy to be of assistance to your organisation. 

    Archives

    April 2020
    March 2020
    October 2019
    September 2019
    August 2019
    July 2019
    March 2019
    November 2018
    October 2018
    August 2018
    July 2018
    November 2017
    October 2017
    September 2017
    July 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    May 2016
    February 2016
    September 2015
    August 2015
    April 2015
    February 2015
    November 2014
    October 2014
    July 2014
    June 2014
    May 2014
    March 2014
    February 2014
    December 2013
    November 2013
    October 2013
    September 2013
    August 2013
    June 2013
    May 2013
    April 2013
    February 2013
    December 2012
    October 2012
    September 2012
    August 2012
    July 2012

    Categories

    All
    Arc Gis
    Arcview
    Autodesk
    Cad
    Gis Training
    Local Government
    Mapbasic
    Mapinfo
    Quantum Gis
    Relational Databases
    Saga Gis

    RSS Feed