You are on page 1of 33

Chapter MDL programming basic methods .....................................................................

1.1 The basic concepts ............................................... ................................... 5


1.1.1 MDL program structure ........................................... ............................. 5
1.1.2 Notes .............................................. ................................... 5
1.1.3 include files ............................................. ................................ 5
1.1.4 Variable Description ............................................. ................................ 7
1.1.5 Variable Types ............................................. ................................ 7
1.1.6 Variable scope ............................................. ................................ 7
1.1.7 MDL internal variables ............................................ .............................. 8
1.2 MDL function ............................................... .................................... 8
1.2.1 Display Information ............................................. ................................ 9
1.3 Structure and joint .............................................. ................................. 10
1.3.1 Elements of the Joint ............................................ .............................. 11
1.4 pointer ................................................ ..................................... 13
1.4.1 passed by reference ............................................ ............................ 13
1.4.2 are passed by value ............................................ .............................. 14
1.5 Micro Station - state machine ............................................ ....................... 15
1.6 Resources ................................................ ..................................... 16
1.6.1 Command Table ............................................. ................................. 16
l.7 state control function ............................................ ................................. 17
1.7.1 User-Defined Functions ............................................. ............................... 17
1.8 Elements Function ............................................... .................................. 19
1.8.1 element generating function ............................................ ............................ 20
1.8.2 element extraction function ............................................ ............................ 21
1.9 Chapter Summary .............................................. .................................. 29
Chapter II compiled MDL programs ............................................ .................................. 30

2.1 preprocessor directives .............................................. ................................. 30


2.1.1 Conditional Compilation ............................................. ............................... 30
2.1.2 compiler directive - # pragma ......................................... ...................... 31
2.2 Development Process ............................................... .................................. 32
2.2.1 Development Process Overview ............................................ ............................ 32
2.2.2 build MDL Applications ............................................ ............................. 33
2.2.3 to compile MDL Applications ............................................ ............................. 33
2.2.4 Build the application command table ........................................... .........................33

2.2.5 Information Sheet (Messagelist) .......................................... ....................... 35


2.2.6 to compile resources ............................................. ............................... 36
2.2.7 Link MDL Applications ............................................ ............................. 37
2.2.8 the use of resources management program ........................................................ 37
2.3 bmake Utilities .............................................. .............................. 38
2.3.1 Production file (Makefile) format ........................................ .................... 38
2.3.2 bmake macro command ............................................ ............................. 38
2.3.3 Related (Dependencies) ........................................... ....................... 39
2.3.4 Inference Rules ............................................. ............................... 40
2.3.5 pre-defined rules of inference .......................................... .......................... 40
2.3.6 Conditional Compilation ............................................. ............................... 40
2.3.7 the implementation of bmake ............................................. .............................. 43
2.4 The implementation of the MDL Applications .......................................................... 46
2.5 Debugger ............................................... .................................. 47
2.5.1 Establishment of debugging ............................................ .............................. 47
2.5.2 a debug build .......................................... ........................ 48
2.6 use a debugger .............................................. ............................... 48
2.6.1 installation program ............................................ ............................ 48
2.6.2 display variable content ............................................ ........................... 49
2.7 Error Message ............................................... .................................. 50
2.8 Chapter Summary ............................................. .................................. 50
Chapter III of the MDL dialog box ............................................. ................................... 51
3.1 Development Process ............................................... ................................... 51
3.2 Dialogue Manager .............................................. ................................ 52
3.2.1 Design of the dialog box ............................................ .............................. 52
3.3 Build dialog resources ............................................. .............................. 54
3.3.1 Dialog Box Entry ............................................ .............................. 55
3.3.2 Common Resources for Fields .......................................... .......................... 56
3.3.3 Text Entry dialog ............................................ ............................ 56
3.3.4 Options button entries ........................................... ............................. 57
3.3.5 Button Entry ............................................. ............................... 58
3.3.6 Button (ToggleButton) entries ......................................... ................. 58
3.4 Dialog generic function ............................................. .............................. 59
3.4.1 dialog hook function ............................................ .............................. 60
3.4.2 Dialog Communications ............................................ .............................. 60
3.5 Resource Management ............................................... .................................. 62
3.5.1 User preferences resources ........................................... ......................... 63
3.5.2 Storage Resource ............................................ ................................ 63
3.6 C expression .............................................. .................................... 64
3.6.1 Type Generator ............................................ .............................. 65
3.6.2 C Expression Function ........................................... .............................. 65
3.6.3 Graphics Group ............................................. ................................. 66
Chapter IV elements of the search and operation ........................................................ 75
4.1 Elements search ............................................... .................................. 75
4.1.1 Element Positioning Function ............................................ ............................ 75
4.1.2 Elements editing functions ............................................ ............................ 76
4.1.3 The choice set function ............................................ .............................. 76
4.2 Activate Settings ............................................... .................................. 78
4.3 Element Location Search .............................................. ............................... 84
4.3.1 Scanning Function ............................................. ............................... 84
4.4 fence searching .............................................. .................................... 90
Chapter V element descriptor ............................................ .................................. 101
5.1 element descriptor function ............................................. ............................. 101
5.2 The operation of the complex elements ................................................................. 107

5.3 Working Paper ............................................... ................................. 109


5.4 isolation unit ............................................... ................................. 114
Chapter VI of the mathematics and geometric operations ........... ............................... 119

6.1 Floating-point constants .............................................. .................................. 119


6.2 Vector Geometry ............................................... ................................. 120
6.3 Vector operations function .............................................. .............................. 121
6.4 The current transformation ............................................... ................................. 123
6.5 Data Format ............................................... ................................. 131
6.6 Rotation matrix function .............................................. ............................... 136
Chapter VII of the Advanced dialog
box ............................................ .................................. 143
7.1 Dialogue entries ............................................... ................................. 144
7.1.1 Options button entries ........................................... ............................ 144
7.2 Senior Dialogue hook function ............................................. ............................. 151
7.3 Element Position ............................................... ................................. 154
7.4 View Function ............................................... ................................. 156
7.5 View hook function .............................................. ................................. 172
Chapter 7.6 Summary ............................................. ................................ 175
Chapter VIII of the input queue ............................................. ................................... 177
8.1 work ............................................... .................................. 177
8.2 input queue function .............................................. .............................. 177
8.3 Queue Element ............................................... ................................. 178
8.4 Command Filter .............................................. ................................ 179
8.5 MDL application automatically ............................................ ........................... 180
8.6 Cancel command categories .............................................. .............................. 182
8.7 system function ............................................... ................................. 184
8.8 demo program ............................................... .................................. 186
Chapter IX into NativeCode World ........................................... ........................... 189
9.1 Build NativeCode program .............................................. ........................ 189
9.1.1 Installation Bentley MFC Application Wizard .......................................... ....... 189
9.1.2 the establishment of a NativeCode project ...................................... .................. 189

9.1.3 compiler generated DLL and MA ......................................... link ....................... 191


9.1.4 In the Micro Station running ........................................... .................... 194
9.2 NativeCode program structure analysis ........................................... ..................... 194

9.2.1 MDL production of documents and resources File Analysis............. .................. 195

9.2.2 MDL main program file analysis .......................................... ........................ 196


9.2.3 MFC program file analysis ........................................... ......................... 196
9.3 Debugging NativeCode program .............................................. ........................ 197
9.3.1 Production debug version of the NativeCode program ........................ .............. 197
9.3.2 the establishment of the project for Micro Station and set the debug to debug
parameters ..................................... .. 198
9.3.3 start debugging process ............................................ ........................... 199
9.4 NativeCode Programming Considerations ............................................. .....................
199
9.4.1 Memory Management ............................................. .............................. 199
9.4.2 wait for the message to complete ............................................ ...........................
200
9.4.3 the use of TCB variables ............................................ ............................ 200
First chapter the basic method MDL Programming

As the MDL language to C programming language, therefore, we take a look at


C programming language the basic methods and how to use them side MDL
Law. This chapter does not want to teach you how to use C language programming,
there are a lot about this book. We assume that the reader already has C language
Programming capabilities, it only involves a number of MDL needed C functions. Here
we discuss the basic method MDL programming.

1.1 The basic concept


MDL language is a structured programming language, which has let us build an
application of the standard commands, functions and objectives. If
Fruit We would like to briefly describe the MDL, can say:
MDL is such a language, it uses C structure, with its own run-time libraries, compiler,
linker, library management process
Sequence, and Micro Station environments.
In this book you read, you will find beyond a programming language MDL. It is a house
to develop into the Micro Station
Application tools. Before we begin the preparation of MDL code, we should put some
terminology, standards and conventions clear.

1.1.1 MDL program structure


MDL procedure is an MDL language in accordance with the rules of combining
a collection of statements. Program statements include the following:

● Control structure or description (declaration) statements


● Assignment Statements
● function / procedure call statement
● pre-processing directives
● Notes
By these statements combined into the MDL program is a text file, using the
extension ". Mc". We write an MDL program, with the
It is a string to draw a box around the same time, extending from the box on a lead. We
will see it as a typical MDL program
Example. Then, we will use the new elements in place to make a unit. The program
name is plbox.mc (see Figure 1.1). Can
With the many ways to write this program, while you read this book you will note there
are many changes in this program, complete the procedures listed in this chapter
Final. We will learn it step by step.

1.1.2 Notes
Note the meaning of the reader to understand the procedure, but also to enable
programmers to modify the program to understand the procedure functions. With the
forward slash and asterisk (/ *)
Note that the start; while with the opposite sign (* /) that the comment ended. Compiler
will not deal with annotations. MDL does not support nested comments.
In Micro Station V8, of course, can also be used double slash (/ /) on a single line for
comments.

1.1.3 Contains the file


Contains the file is such a file that is included in the compile-time pre-processing
program read into the program for use of the MDL source code. Sometimes also called
the header include file
Documents, because they are the beginning of the source.
We can put the common constants in a separate document, then you can make several
different programs include this file in order to ensure that these
Constant coherent manner. There are two definitions include file method:
# include <mdl. h>
Figure 1.1 PLBOX the results of running
The convention is to use ". H" as containing the file extension. If you use the angle
brackets, pre-processing program attempts MDL contains mesh Recorded...

Bentley \ Program \ Micro Station \ mdl \ include and going to find <mdl. h> file.
Or, we can put the file name in quotation marks, it informed the pretreatment program to
contain the file that contains the file description statements directory to find package
with the file.
# include "plbox.h" / * Generated by "rcomp-h plbox.r" * /

How do we know which one to use with documents? All the file names are listed in the
<<MDL 手册> "in the. For example, when we use
mdlText_extractShape time, it must contain <mselems. h> file. These documents can be
included within Micro Station
In the ... Bentley \ Program \ Micro Station \ mdl \ include directory to find.

In the Plbox. mc program, will use the following include files:

/*----------------------------------------------------------------------
+
︱ Include Files ︱
+----------------------------------------------------------------------
*/
#include <mdl.h> /*system include files*/
#include <global.h>
#include <mselems.h>
#include <userfnc.h>
#include <rscdefs.h>
#include <tcb.h>
#include <plbox.h> /*Generated by rcomp -h plbox.r" */

Final an include file plbox.h should arouse attention because It consists resource file
compiled betrayals. We went second chapter further discussion
Resource file.
In Micro Station V8 in introduced new file type ". Fdf", they are function definition file
(Function Definition
File). These documents contain certain category MDL function prototypes definitions,
while another right include files reference Therefore, V8 programming
You will see we often simply procedures beginning contains these. Fdf document do.

1.1.4 Variable Description


We use a variable before you must first define it. In most cases, at the
beginning of program design before we will not know will Which variables used. In this
section we assume that already know what variables need to use. MDL There are many
definitions of variables approach, we From the basic concept for discussion.

Definition of variables
The term "variable" so the name and memory address linked. The amount of
memory needed to store the variable depends on the variable type. The term "address"
Is a variable storage address. For example, the value of an integer variable count is 20,
its address is given by the & count. That is, "&" symbol
No. Back to count the address, rather than count the value of, this is a very important
concept. Many programmers to understand the variables and due to an error
It addresses the meaning of the program generated many problems.
MDL is a language-sensitive pairs of uppercase and lowercase letters. When you define
a variable or function names should be firmly borne in mind. For example, the variable
linePts with LinePts different.

1.1.5 Variable Types


How variable the variable type definitions for storage and which operate it. The basic
variable types are short, int, float,doublet, and char.

The following table defines the various MDL variable types:

Type of storage values


short integer - 3 2, 678 ~ 3 2, 767

unsigned short integer 0 ~ 65,535

int integer - 3 2, 678 ~ 3 2, 767

long int integer -2,147,483,648 ~ 2, 147,483,647

unsigned int integer 0 ~ 65,535

unsigned long int integer 0 ~ 4,294,967,265

float by d o u b l e-type treatment

double with 6 or 7 significant digits of the floating-point

char ASCII character value, or integer -127 ~ 128

unsigned char integer 0 ~ 255

1.1.6 Variable scope

Variable description of the scope of the definition of variables for which part of
the program. In order to determine the scope of variables, an MDL program source code
according to the level Divided into many pieces.
A block can be a program or a function. The entire file can be considered as a
block. - Blocks can be nested in other blocks , So a block in the external variables are
defined by all nested blocks recognition. An internal block defined in the variable name
with an external block
Variable the same name.
In this case, the internal block variable will replace the external block variables,
but this is only limited in-house within the scope of the block.
In this case, the internal block variable is considered local variables. Their values and
their presence only by those who explain the function of the commitments that they
Recognition. Global variable was MDL program for your recognition of all the functions.
Static variables and automatic variables
Variable has a storage type. Categories decide how to store a variable storage, how
long it lives, as well as in the program where the variable names can be
Be referred to. If we described the function of a variable not do special treatment, it is an
automatic variable. This means that when we tune
With a function, this variable is automatically generated, when we leave this function
when it is abandoned. Sometimes, the need to retain the function assigned to local
variables
The final value of the static modifier static compiler directives stored from a call to the
next call to a local variable's value. Default
Variable is automatically variable. Global variables may be static (in the MDL source
module called by any recognized, but not by other source modules used).

If a global variable is not describe the static, it can also be used by other source
modules.In our Example PLBOX, we need to define two functions for all of our global
variables, we need to Can accommodate 128 to define a string variable textin, it is
noteworthy because the "type" buffer of 128 characters.

They define variables pntP to hold the data points.

/*------------------------------------------------------------+
│ Private Global variables │
+------------------------------------------------------------*/
static char textin[128];
Dpoint3d pntP[2];

1.1.7 MDL internal variables


MDL provides global variable for our programs. As they loaded in the
compilation process, so we can make without going through the definition of a direct
With these variables. Many internal variable is the structure or joint. For example, the
variable * tcb is a design document that contains all the current information in a knot
Structure. If an internal variable with a simple type, such as int, which contains the
header files do not have to. However, if the internal type is a structure or union
Or a structure or union pointer points to, then it must include the appropriate header
files. Details on the header files please refer to Appendix.

Type Variable Description


short dgnbuf [] containing the dgnbuf all the information in the
current element. All Element or elements through the positioning operation commands
into the buffer

MSStateData statedata containing the current state of the function, all of


the information, in the <global. h> is defined in
Tcb * tcb current DGN file that contains all the information in
the <tcb. h> is defined in
Mgds_modes mgds_modes contains information on Micro Station current means
of implementation, in the <global. h> in the
definition of

byte cmplx-hdr [] If the element is a complex head, compared to TRUE. For


example, The following is true: cmplx_ hdr [CELL_TYPE]
char mgdsPrompt [35] contains the prompt character, the default is "nStn>"

short element-drawn [s] is an element of each type of office it is a bit mask,


If the element is to display the bit is set

short msversion Micro Station current version number, 16 hex

short database connected to the database, compared to true

int mdlErrno a variety of MDL function, the error message number

MSGraphConfig graphConfig contains graphics configuration, defined in


<global.h>

Int error number a variety of operating systems functions

Long mdlCommandNumber start MDL application that contains


the most recent order number

1.2 MDL function


There are two kinds of function types, pre-defined functions, and we are generating
functions. In order to use a function, you can access it must be set before the
Meaning it. In order to use the predefined function, must be the beginning of our
consultation document have the correct include files. MDL offers two different sets of
pre-defined Function, namely, the standard C function and MDL-specific functions (with
prefix mdl).

In this book does not include the interpretation of the standard C function. You can, in
many C language tutorial to find them. MDL supports the following standard C function:

File operations, input and output: fclose, leof, ferror, fflush, fSetc, fgets, fopen, fprintf,
fputc,fputs, fread, freopen, fscanf, fwrite, fseek, ftell, getc, printf, putc, remove, rename,
rewind,sscanf, setbuf, setvbuf, sprintf, tmpfile, tmpnam, ungetc, unlink, vfprintf, vprintf,
vsprintf.

In this book does not include the interpretation of the standard C function. You can, in
many C language tutorial to find them. MDL supports character classification and
conversion:
isalmum, isalpha, iscntrl, isdigit, isgraph, islowcr, isprint, ispuct, isspace,
isupper, isxdigit, toascii, tolower. toupper.
String Manipulation: strcat, strchr, strcmp, strcmpi, strcpy, strcspn, strlen, strlwr, strncat,
strncmp, strncpy, strpbrk, strrchr, strspn, strstr, strok, strupr.

Cuncun allocation, buffer management and data conversion: atof, atoi, atol, calloc, exit,
free, getenv,malloc, memchr, memcmp, memcpy, memmove, memset, rand, realloc,
srand, strlod, strol, strloul.

Math: acos, asin, atan, atan2, ceil, cos, cosh, exp, labs, flooy, fmod, frexp, log, log1O,
ldexp, ntodf, pow, sin, sinh, sqrt, tan, tanh.

Date and time: sctime, ctime, difftime, gmtime, localtime, strftime, time.

Variables: va_arg, va_end, va_start. MDL supports ANSI and K & R control variable
approach.

main function

Although not an MDL program must contain a main function, but there is no main
function of the situation is very few. In the MDL proceedings main function is to serve
three kinds of purposes:

Main is the initial entry.


It is essentially an initial function.
When the main return to Micro Station when, MDL program still resides (except for this
program to uninstall MDL).

Main ()
{
RscFileltandle rfHandle;
/*load our command table */
if(mdlparse_loadCommandTable (NULL)= NULL)
mdloutput_error ("Unable to load command table.”);
mdlResource_openFile (&rfHandle,NULL, FALSE);
mdloutput_prompt ("Key-in in place BOX to execute");
}

Main function will load the command table Micro Station. The next chapter we will
discuss the order form and resource file.

1.2.1 Display Information

Micro Station command window can display the information is divided into six
areas
These six areas is wrong information domain (er-ror), prompted the domain
(prompt), the command field (command); type the domain (keyin), information field
(message), and the status field (status).
If the tcb-> control.inh_msg Set to a non-zero value, we can ban all the information sent
to these domains.
If the tcb-> cont, such as rol.inh__err set to a non-zero value, letter Number of
mdlOutput__error will not display information.

Information function are summarized as follows:

mdlOutput_ error In the command window to display information


within the designated areas

mdlOutput_ prompt

mdlOutput_ command

mdlOutput_ keyin

mdlOutput_ status

mdlOutput_ errorU In the command window to display


information
within the designated areas, these functions ignore the ban-bit

mdlOutput_ promptU

mdlOutput_ commandU

mdlOutput_ keyinU

mdlOutput_ messageU

mdlOutput_ statusU

mdlOutput_ printf According to parameters MSG_MESSAGE,MSG_


ERROR,MSG_PROMPt,MSG_STATUS,
MSG_COMMAND And MSG_KEYIN
In any one field as specified in the command window to display information

mdlOutput_ vprintf As above, but according to format string to display


information

mdlOutput_ rscPrintf In the command window displays Messagelist within the


Resource Information

mdlOutput_ rscvPrintf As above, but according to format string to display


information

1.3 Structure and joint

Structure allows us to value different types of relevant combined. As we will see


MDL include file, due to ease of use, the structure has been widely used. The following
examples, we have defined a structure called the elm_ hdr, and generates a type ELm_
hdr. Here preprocessor directive # if, # else and # endif in the following chapter.

/*----------------------------------------------------------------+
│ ELement Header structure-common to all Micro Station elements │
+ ---------------------------------------------------------------*/
typedef struct elm_hdr
{
UInt16 type; /* element type */
#if !defined (BITFIELDS_REVERSED)
UInt16 reserved:6; /* reserved for future flags - always 0 */
UInt16 archive:3; /* modified or added and not yet committed to history;
or conflict*/
UInt16 deletedCmplxHdr:1; /* deleted complex by header */
UInt16 nonModel:1; /* true if this element is file-specific and does not
belong in any model */
UInt16 locked:1; /* element is locked */
UInt16 isGraphics:1; /* element is a graphics element, has Dsp_hdr */
UInt16 isComplexHeader:1; /* is a complex header, must have number of
elements following its header */
UInt16 complex:1; /* this element is part of a complex element */
UInt16 deleted:1; /* this element is deleted */
#else
UInt16 deleted:1; /* this element is deleted */
UInt16 complex:1; /* this element is part of a complex element */
UInt16 isComplexHeader:1; /* is a complex header, must have number of
elements following its header */
UInt16 isGraphics:1; /* element is a graphics element, has Dsp_hdr */
UInt16 locked:1; /* element is locked */
UInt16 nonModel:1; /* true if this element is file-specific and does not
belong in any model */
UInt16 deletedCmplxHdr:1; /* deleted complex by header */
UInt16 archive:3; /* modified or added and not yet committed to history;
or conflict */
UInt16 reserved:6; /* reserved for future flags - always 0 */
#endif
UInt32 elementSize; /* number of words in element */
UInt32 attrOffset; /* offset (in words) from start of element to
attributes */
UInt32 level; /* element level */
ElementID uniqueId; /* unique ID of element */
double lastModified; /* last time this element was changed */
} Elm_hdr;
In order to use this structure, we must define the variable type ELm_ hdr, and use the
dot operator to access it.

For example, we define the type ELm_ hdr variable hdr:

ELm_ hdr hdr;

In order to change elements of the layer, we will use statement:

hdr.level=3

1.3.1 Elements of the Joint


The joint is a special structure, which allows a variable to store multiple types of
values. However, there is only one value at any time can take this variable, which in the
Fortran language, the equivalent of "equivalence." TCB variables UCBYT, UCWRD and
UCASC are examples of the concept of a joint.

Joint is a kind of allows us a relatively easy way to deal with a powerful means of data.
Consider the following elements of the joint msELementUnion. In this joint, we might add
DGNBUF written into every one within the Micro Station element. A fixed element of the
first ELm_ hdr is also within the joint.

/
*-----------------------------------------------------------------------
-------+
| name element_unio - union of all element types |
+-----------------------------------------------------------------------
--------*/
typedef union msELementUnion
{
Elm_hdr ehdr;
Header hdr; /* NOTE: hdr.dhdr is not valid unless ehdr.isGraphics is set
*/
Cell_2d cell_2d;
Cell_3d cell_3d;
Line_2d line_2d;
Line_3d line_3d;
Line_String_2d line_string_2d;
Line_String_3d line_string_3d;
Text_node_2d text_node_2d;
Text_node_3d text_node_3d;
Complex_string complex_string;
Ellipse_2d ellipse_2d;
Ellipse_3d ellipse_3d;
Arc_2d arc_2d;
Arc_3d arc_3d;
Text_2d text_2d;
Text_3d text_3d;
Point_string_2d point_string_2d;
Point_string_3d point_string_3d;
Cone_3d cone_3d;
Surface surf;
Bspline_pole_2d bspline_pole_2d;
Bspline_pole_3d bspline_pole_3d;
Bspline_curve bspline_curve;
Bspline_surface bspline_surface;
Bspline_weight bspline_weight;
Bspline_knot bspline_knot;
Bsurf_boundary bsurf_boundary;
Raster_hdr raster_hdr;
Raster _comp raster_comp;
ApplicationElm applicationElm;
ColorTable colorTable;
ReferenceFileElm referenceFileElm;
Int16 t mp[MAX_ELEMENT_WORDS];
Int16 buf[MAX_INTERNAL_ELEM_WORDS];
} MSELementUnion, MSELement;
In this way, we can define MSELementUnion types of variables el:

MSELementUnion el;

When we read one element, we can not determine what elements. The use of
elements of the joint, we can test the elements of a fixed head el.ehdr. In the example
below, we can examine a line element, the use of joint that we can access el.line_2d in
the same data.

if(el.ehdr.type=LINE_ELM
{
el.Line_2d.start.x +=100;
el.Line_2d.start.y +=100;
}

Please note that we are a joint member how to use to extract data from the joint, and
use another member to operate information. In this example, we have made a 2D line
from the right move to move 100 units 100 units.

1.4 pointers
In the MDL pointer in the right understanding of many errors that may arise. And
the use of variables, we can use int, float, double and char to illustrate the pointer.
Consider the MDL in the ordinary usage of the pointer.

Note: The parameter table * PString the definition of variables, in this book, we have to
use the ANSI method parameter list defines the type of argument, this method has the
advantages of checking the type argument.

private void parselnputstring(char * pString)


{
char*pResult;
if(pResult=strtok(pString.""))!=NULL)
{
strncpy(oldstring.pResult.sizeof(newString));
if((pResult = strtok(NULL""))! = NULL)
STRRCPY(newString.pResult.sizeof(oldstring));
}
}

In the above example, we see two characters pointers * pString and * pResult. An
asterisk (*) tell the program to store the pointer pString within the memory address to
find the string value.

1.4.1 Passed by reference

There are two ways to pass parameters, namely, passed by value and passed by
reference. When we come to passing parameters by reference, we give the address of
variables to receive parameters. Therefore, the argument is called the program to
change the call to any change in the value of program variables, because both share the
same memory address. We have to pass a string by reference. We can address by
using a pointer pointing to a string to achieve a string of passes, when a string is aAn
array of characters when we do not need to use &, and MDL are used in all references
to pass an array.

For example, the note tells us that the string must be treated as a pointer to it passed to
the parselnputstring。

Char string [20]; /*definition of string on main program*/


.
.
.
parseInputstring(string);/*pass the string into our function*/
.
.
.
Private void parselnputString(pstring) /*pass itby reference*/
char *pstring; /*define as a pointer*/
Back to look at our main function, structure, rfHandle as a pointer to pass. Character (&)
is the address operator. It returned to the memory address of a variable, rather than the
variable value.

mdlResource_OpenFile(&rfHandle,NULL,FALSE);

Program mdlResouce_openFile is a predefined function. When we find it in the MDL


manuals, we can see the first one variable must be
Shall be a pointer. By using the & symbol in front of rfHandle, we have provided the
correct format to the function variables.

1.4.2 passing by value

We can also pass variables by value. Means that this variable has been assigned
the same time, this value is copied to the receiver parameters. Is called the program
variables change is local. When the program is the end of its value will be lost. See the
following examples, the process should be placed in view, a 2-arc. Which, viewNumber
passed by value. Whether we have done right to receive parameters, when we complete
the call, the variable is not changed.

..
vieWNumber=2;
placeArcbyCenter(viewNumber)
.
.
Private void placeArcbyCenter (int view)
{
MSELementUnion arc;
Dpoint3d arcp[3];
double origin;
arcp[0].x=25.; /*start point*/
arcp[0].y=35.;
arcp[0].Z=fc_zero; /*floating point constant*/
arcp[1].X=55.; /*center point*/
arcp[1].y=35.;
arcp[1].Z=fc_zero; /*floating point constant*/
arcp[2].X=85.; /*end point*/
arcp[2].y=35.;
arcp[2].Z=fc_zero; /*floating point constant*/
origin=55.0;
if(mdlArc_createByCenter(&arc,Null,arcpt,True,origin,view)==success)
{
mdlELement_display(&arc,NORMALDRAW);
mdlELement_add(&arc);
}
}
Note: MDL array of in line with C language conventions, from 0. For example, in the
above definition of Dpoint3darcP [3], the array subscript is arcp [0], arcp [1], and arcp [2].

Function pointer
In the MDL, we can put the address of the function as an argument to pass.
Therefore, the program can reference the value of a pointer to call this function

Function pointer is widely used in MDL. For example, the function


mdlState_startPrimitive ask the former two variables are pointing to a function pointer.

mdlstate_ startPrimitive(placeBOX_ FirStPOint, placeBOX_


start,1,2):

Function PlaceBox_ firstPoint and placeBox_ Start appear to be references to their


previous. We can start in the program where the definition of the function name to meet
this requirement; or call the function it had previously appeared with complete (this is the
usage throughout the book).

1.5 Micro Station - state machine

Micro Station is a event-driven machine. That is, at any point, an incident Micro
Station into a given state, and a state of the handler to process its input. We can call to
place online orders and PLACELINE the first demonstration of a point. When we move
the cursor, the second point, like pulling a rubber band, like moving across the screen,
we will choose WINDOWAREA the command and select the new window, rather than
the second given data points. In the Windows update, this line have been eliminated? As
a state machine, Micro Station command state can be distinguished. View the
command-line commands and put a different state. Therefore, we can assume that this
line is still active, press reset button so that we exit the view command and returns to
place the command line.
Figure 1.2 Micro Station input process

We can write an MDL program to deal with the establishment of a state function or type
of information, such as data points such as input information. In this way we can enter
the Micro Station basic (primitive) level. We write any of MDL applications, there will be
more convenient, and does not require additional programming.

Micro Station programming other tools, such as the UCM and MicroCSL, is to line up
Micro Station commands. By Figure 1. 3 we can see, UCM, and MicroCSL in the input
queue, task distribution, and circulation between the external applications. Therefore, the
state ordered the distribution layer applications will be out of control.

1.6 Resources
Resource is a group called the resource file being stored in the data. A typical
data set is a string, an error message, raster icons and order form. The use of resources
purpose of the paper is to separate the data and application source code. Using this
method has many advantages:

To reduce the overall memory requirements, because only the data required for the
installation.
Multiple applications can share the same resource.
Easy maintenance. Tips and information on the changes without changes to the
application. Example, you can integrate applications into other languages, such as
French.
In later chapters, we will discuss the resources and the generation method.

1.6.1 Command Table

Bottom of the main program from the resource file to install the application
command table. Command table defines a command language. For exercise, we
assume that the main will command PLACEBOX into Micro Station. In later chapters, we
would also like to discuss the order form.

main ()
{
RscFileHandle rfHandle;
if(mdlParse_loadcommandTable(NULL)=NULL)
mdloutput_error(“Unable to load command table.”);
mdlResource_openFile(&rfHandle,NULL,FALSE);
mdloutput_prompt(“key-in PLACE BOX to execute”);
}

Here we tell Micro Station, our application order merely exist, we do not have
enforcement procedures. This is the strength of the MDL. It allows application
developers to enter the Micro Station "basic" level. We now define a group called
PLACEBOX the basic commands.

In order to activate our MDL process, we should uStn> prompt, type PLACE BOX.
Microsration a word by word analysis of our typing. Therefore, only type PLACE will
have a vague command. Micro Station can not distinguish it PLACELINE. Generate a
named PLACEBOX basic commands will not be able to use the command table,
because the command is not level, so that the command can not be classified.
Command category is very important, it allows Micro Station decisions or the allocation
of the current state of the application. In our application to generate the command
PLACEBOX table, we need to discuss this issue in detail.

When the Micro Station successfully analyze the user's typed message, it generates an
order number. An application with the command the task of linking the ID and the
command ID is used to determine the application of the implementation of this command
and call this function. In the following program, cmdNumber to function placeBox_start
and a command number combination. When we type PLACEBOX time, MDL began
PlaceBox_ start implementation.

cmdName placeBOX_start()
cmdNUmber CMD_PLACE_BOX
{
mdlstate_startPrimitive(placeBox_firstpoint,placeBox_start,1,2);
}
Program mdlState_startPrimitive state function will be established in order to use a data
point to activate PLaceBOx_firstpoint, a rest will loop implementation placeBOx_start. At
the same time, it will generate information form number from 0 to 1, information, and it
appears in the command field, while the No. 2 information displayed in the prompt field.
In the second chapter we will discuss the interest rate table and its generation method.

1.7 state control function

Micro Station command sequence composed of an application, another


application in the implementation of its final prior to the end of a command. PLACELINE
in the implementation of the command, the implementation of a user command to open
the window, it should be clear tips: WINDOW AREA. Write an event-driven applications
as the MDL procedure does not make this application to be suspended. Determine the
number of functions to control the incident. In this section we will discuss the state of
different control functions, these functions are the core of MDL programming. There are
four Micro Station command state.

1. Basic commands used to generate, modify and delete elements. Start a basic
command will terminate on the one basic commands, and the basic commands in
another one to replace it until the order has been in active. Start a basic command must
be called about the command:
mdlstate_ startPrimitive Start a only basic commands used to generate the
elements
mdlstate_ startModifyCommand Start one for the place and modify the elements of
basic commands

mdlstate_ startFenceCommand The establishment of a basic commands used to


operate a function of the fence

2. View Order Status


View command is used to modify or update the view. We have to start calling
mdlState_startViewCommand view command. Start a view command will hang a basic
command, when the view control at the end, hanging up the basic commands continues
to work. If the user enters reset, the end of the view that we must
mdlState_exitViewCommand life mdlState_startViewCommand command to start a
view out of the view mdlState_exitViewCommand command.

3.Direct order status


Direct command is used to modify the settings (such as changing the capture
state, or type WT =). Do not call the direct orders of the state function, it does not affect
the basic order or view order status.

4. Utility Command Status


Practical non-interactive command execution functions such as COMPRESS. In
the end we need to use command called practical

mdlState_ startDefaultCommand。
The rest of the state control function is as follows:

mdlState_clear Reset command state, so that no command was activated

mdlState_checkSingleShot Check whether a command operations (SingleShot)


mode operation

mdlState_ dynamicUpdate The function using a simple dynamic operation of


the provisions of

mdlState_ registerStringIds Provides a basic command to start using the tips of


information
mdlState_ restartCurrentComman The current basic commands to restart the

mdlState_ setFunction According to the requirement to use a function of


the incident

mdlState_ setKeyinPrompt Provisions of the string for the type area, the default
value is "nSTN>"

mdlState_ startDefaultCommand After the end of the current


command to
start the default command

1.7.1 User-Defined Functions


When certain events occur in the Micro Station when, MDL with the function
pointer to specify the users to perform functions. Function pointer to make programming
easy and effective. For example, when certain events occur, the function mdlState_
startModifyCommand the user to perform five functions. These events include user input
reset, input data points, or dynamic display. The remaining two parameters display or
cleared, is used to display in the DGNBUF been modified elements. Paired with the
display and the regular use of clearance in order to clear the display can be restored to
its previous function. We can deliver to these arguments are NULL.

The following is a list of user functions: Note: The function name in italics is not a
function of the real name. Please use your program to use the function name you use to
replace them.

userState_ clean function to modify the function of


userState_ CommandCleanUp in another command need to be cleared before the
start of the function to use
userState_ complexDynamicUpdate for complex dynamic display function
userState_ datapoint in the input data points the function is called when the
userState_ dynamicUpdate dynamic display function for simple
userState_ fenceContent a function for processing the contents of the fence
userState_ fenceOutline used to re-display function of the boundary fence
userState_ Keyin Functions for handling the user typed
userState_ reset for handling reset (reset) function
userState_ Show When you modify the command used to display elements
when the load DGNBUF a function of

Back to look at our PLBOX example, we need to build the basic commands to place the
box. When the user send data points, the first parameter placeBox-firstPoint is to
perform the function pointer. The second parameter is called when a user enters reset
function. In this case, we start recycling and re-placed the box of the basic commands.
The final two parameters used to define the information on the screen. We will discuss
the information table in the second chapter.

cmdName placeBOx()
cmdNUmber CMD_ PLACE_ BOX
{
mdlOutput_rscprintf(MSG_RPOMPT,NULL.0,2)
mdlState_StartPrimitive(P1aceBOX_firStPoint,placeBOX_start,1,2);
}
Event Type Let's look at the function placeBox-firstPoint, it needs to
mdlState_startPrimitive coming from a data point. According to information received from
the user, we will store the point and the establishment of the state function to be called.
Function mdlState-setFunction need two variables. The first is the type of event, and the
second one is to perform the function pointer. Event types possible values are:

STATE_ DATAPOINT When a user enters a data point


STATE_ RESET when the user input when the reset
STATE_ KEYIN When the user key person
STATE_ COMPLEX_ DYNAMICS generate dynamic display, see below
STATE_ COMMAND_ CLEANUP cleared in another order before the start of the current
Command

MDL provides the elements to provide a dynamic operation. When the element
generation, movement and change can be seen on the screen display of the same
rubber band. We need a single element in the dynamic display using a simple dynamic.
Complex dynamic is used to display more than one element. mdlState_dynamicUpdate
is used for simple and dynamic functions.

For complex dynamic that we have to use mdlState_setFunction. Show a dynamic


manner in order to determine, MDL implementation of the user function generatelmage,
and to high-brightness display element. Therefore, only a display element, rather than
Save. We will discuss the use of PLBOX dynamic display, you will see how this function
works.

Private void placeBox_firstpoint


(
Dpoint3d *pt,
int view
)
{
/*save first point*/
pntP[0]=*pt;
/*set the datapoint state function for the second point.*/
mdlstate_setFunction(STATE_KEYIN,keyinText);
mdlstate_setFunction(STATE_DATAPOINT,placeBox_secondpoint);
mdlstate_setFunction(STATE_RESET,placeBox_done);
mdloutput_rscPrintf(MSG_PRCMPT,NULL,0,3);
mdlstate_setFunction(STATE_COMPLEX_DYNAMICS,generatelmage);
}
As we have seen from the placeBox_firstpoint function, for every possible event that we
have established the phaseShould be a state function. Program KeylnText characters
were obtained from the input queue and put it in there is a variable textin.

Private void keyin Text()


{
if (!*statedata.cmdstring)
return;
strncpy(textin,statedata,cmdstring,sizeof(textin));
}

Should pay special attention to the function generatelmage, because it is every time we
move the cursor when the procedure is called. In the downlink, we tell the MDL in a
dynamic operation, use this function.

mdlState_setFunction(STATE_COMPLEX_DYNANICS.generatelmage)

generate lmage will be placed on this string and a box, and to build the line and the box
in a corner alignment.

1.8 Elements Function


Here's how a single element of the common elements of function, we will discuss
in subsequent chapters of the operation of complex element

mdl Element _ add add an element of the document

mdl Element _ append an element attached to the file

mdlElement_appendAttributes of an existing element of additional attribute data

mdl Element _ display in all views display elements

mdlElement_displaylnSelectedView appear within the specified elements in the view

mdlElement_extractAttributes extract elements from existing attribute data

mdlElement_getFilepos Returns the element file location


mdlElement_getProperties Returns the element attribute information

mdlElement_getSymbology Returns the element's display line breaks

mdlElement_getType Returns the type of element number

If the element is filled mdlElement_isFilled returns TRUE

mdlElement_offset to move some distance away from elements

mdlElement_read to an element of the buffer read from the design


document

mdlElement_rewrite rewrite an existing element

mdlElement_setFilePos file location to establish the elements

mdl Element _ set Properties to establish the element attribute


information
mdl Element _ set Sympology to establish elements of the display line breaks

mdl Element _ size number of bytes returned element size

mdl Element _ strip Attributes remove an existing element in all of the


attribute information

mdlElement_stroke By an element into a series of vectors to deal with


an element of

mdlElement_transform through the transformation matrix to transform an


element of

mdlElement_undoableDelete delete a
With the UNDO command to restore elements of

1.8.1 Elements generating function

MDL provides some generating function of Micro Station elements can be


displayed. These elements are generated in memory. Therefore, the use of the function
mdlELement_add The elements written in the document is very important. Elements of
the structure <mselems. h> is defined.

To use these functions generate the elements, the encoding and the
subsequent separation of the elements of the format change is a good work habits. For
the two Micro Station New - size and multi-line, which is clear, <mselems. h> elements
of the structure is not detailed.
Generating function of the elements listed below:
mdlArc_ create an arc element is generated
mdlArc_ createByCenter through the center and two endpoints generate an arc
mdlArc_ createByPoint generate an arc by 3 points
mdlCell_ create the first element of generating units
mdlCircle_ createBy3Pts generated using 3-point circle, oval
mdlCone_create generate a cone element
mdlCone_createRightCylinder generate a positive cylindrical element
mdlCone_create generate a curve element
mdlEllipse_create generate an elliptical element
mdlLine_create generate a line element
mdlLineString_create generate a line string, outline or curve elements
mdlPointString_create generate a point string element
mdlText_create generate a text element
mdlTextNode_create generates a text node elements

We will use mdlText_create generated string. Our approach is not generating any
particular string, but is displayed, the need to consider the use of dynamic display.
Graphical
When we use mdlELement_display displayed on the screen one element may be
drawing method is:

Graphical implications

NORMALDRAW using ordinary color picture elements


ERASE erased from the screen
HILITE with high-brightness color painting element in

Provisional elements of painting TEMPDRAW

TEMPERASE wipe temporary graphics


TEMPROTATE use "different" operation or semi-color
XORDRAW use "different" operation

This dynamic program temporary plotted on the screen of our images, and when we
move the cursor when you erase it. When we take
Closed the second location of the point, the function placeBox-secondpoint be activated,
because this state has been established previously State

privatevoid placeBox_secondpoint
(
Dpoint3d*pt
int view
)
{
generatelmage(pt,view,NORMALDRAW);
}
Function placeBox_ Secondpoint direct calls generatelmage, and passes to it a
ORMALDRAW option. We will use PLBOX elements generates an isolated unit. Call
Mdlcell_begin will generate the type 2 unit head. Since then placed on each element will
be a part of this module. In generate mage, we can see that NORMALDRAW elements
will be added to DGN document.

/*createText in dgnBuffor Micro Station Dynamicsto display*/


mdlText_create(&el,NULL,textin,&pntp[l],NULL,NULL,NULL,NULL);
mdlELement_display(&el,drawMode);
if (drawMode==NORMALDRAW)
{
CellFilepos=mdlCell_ begin(” plbox”,&origin,NULL,NULL,O);
mdlELement_ add(&el);
}

1.8.2 Element extraction function


When we generate a string, it is still in the DGNBUF. Only when we call
mdlELement_add, it was only added to the DGN file. Next, we place a rectangle around
the string; we can use an element capture function to remove the element of information.
These functions allow programmers to retrieve the elements of the information without
having to understand the elements of the storage format. The best programmers use
these functions, in order to protect their proceedings are not to because the elements of
the format is changed.

The following is a list element extraction function


mdlArc_ extract extract arc or elliptical elements
mdlCell_ extract header information extraction unit
mdlCone_extract cone element information extracted
mdlLinear_extract from a line, line string, contour-shaped, cone-shaped,
curve, Polyline or curve to extract coordinate array B
mdlLinear_getClosestSegment from a point close to a linear element to find a line
segment near the point
mdl Shared Cell _ extract extract the shared cell instance or its definition of
information
mdl T ext _ extract extract text element information
mdlText_ extractShape extract the smallest element of the border around the text
mdlText_ extractString element extracted from the text string
mdlTextNode_ extract extract the text node elements
mdlTextNode_ extractShape returns a text node around the smallest border

We should mdlText_ extractShape be rectangular 5-point (the first point and last point
coincide). The fourth variable is set to TRUE, in accordance with the current precision to
enable the border to capture a greater extent (and SETLOCATE of typing the same). We
do not read from the DGN file string because it's an operation to make DGNBUF already
have this string.

mdlText_ extractshape(Shapep.NULL, &el,TRUE,view)


mdlShape_Create(&el.NULL,Shapep,5,-1);
mdlElement_disPlay(&el, drawMode);
if(drawMode==NORMALDRAW)
mdlELement_add(&el);
The next step in our program is to lead targeting box of the iceberg. Figure 1.3 The point
underlined that if we get two points entered by the user will need to draw the line. With
this simple geometric method, according to the first quadrant of a point where it is easy
to determine the endpoint this line in the rectangular of a suitable corner.

Figure 1.3 leads to place

The following is to calculate a new endpoint:


if (pntP[0].x < origin.x)
{
if (pntP[0].y < origin.y)
{
pntm[1].x=shapep [0].x;
pntP[1].y=shapep [0].y;
}
Else
{
pntP[1].x=shapep [3].x;
pntm[1].y=shapep [3].y;
}
}
else
{
if (pntP[0].y < origin.y)
{
pntm[1].x=shapep [1].x;
pntP[1].y=shapep [1].y;
}
else
{
pntP[1].x=shapep [2].x;
pntP[1].y=shapep[2].y;
}
}

Once the calculation of a new endpoint, we can use mdlLine_create to place this line. By
calling mdlCell_end to close the unit, it uses descriptors to form the elements of number
and the correct file pointer changes to unit head

/ * place the modified leader line * /


mdlLine_Create(&el, NULL, pnpt);
mdlELement_display(&et,drawMode);
if (drawMode = NORMALDRAW)
{
mdlELement_add(&el);
mdlCell_end (cellFilePos):
We learn from the first MDL program plbox.mc full is as follows:

+-----------------------------------------------------------------------
----+
| Example MDL function to place a box around |
| a text string with a leader line. |
+-----------------------------------------------------------------------
---*/
/
*-----------------------------------------------------------------------
---+
| Include Files |
+-----------------------------------------------------------------------
---*/
#include <cmdlist.h>
#include <toolsubs.h>
#include <string.h>
#include <msrsrc.fdf>
#include <msparse.fdf>
#include <msoutput.fdf>
#include <mselemen.fdf>
#include <msvar.fdf>
#include <msstate.fdf>
#include <mssystem.fdf>
#include <msdialog.fdf>
#include <mscell.fdf>
#include <mselmdsc.fdf>
#include "PlaceBox.h"
#include "PlaceBoxcmd.h"
static char textin [128];
Dpoint3d pntP[2];
/
*-----------------------------------------------------------------------
---+
| name generateImage – dynamic function for box. |
+-----------------------------------------------------------------------
---*/
Private int generateImage
(
Dpoint3d*pt,
int view,
int drawMode
)
{
MSElementUnion el;
Dpoint3d origin;
Dpoint3d shapeP[5];
MSElementDescr * pDescr = NULL;
pntP[1]=origin=*pt;
mdlCell_create (&el, "BOX", &pntP[0], FALSE);
mdlElmdscr_new (&pDescr,NULL,&el);
/*create Text in dgnBuf for Micro Station Dymamics to display */
mdlText_create (&el,NULL,textin,&pntP[1],NULL,NULL,NULL,NULL);
mdlElement_display(&el,drawMode);
mdlElmdscr_appendElement(pDescr,&el);
mdlText_extractShape(shapeP,NULL,&el,TRUE,view);
mdlShape_create(&el, NULL, shapeP, 5, -1);
mdlElement_display(&el, drawMode);
mdlElmdscr_appendElement(pDescr,&el);
if (pntP[0].x < origin.x)
{
if (pntP[0].y < origin.y)
{
pntP [1] .x=shapeP [0] .x;
pntP[ 1] .y=shapeP[0] .y;
} else {
pntP[1] .x=shapeP [3].x;
pntP [1] .y=shapeP [3].y;
}
}else {
if (pntP[0].y < origin.y)
{
pntP[1] .x=shapeP[1] .x;
pntP[1].y=shapeP[1].y;
} else {
pntP[1] .x=shapeP[2] .x;
pntP [1] .y=shapeP[2] .y;
}
}
/* Place the modified leader line */
mdlLine_create(&el, NULL, pntP);
mdlElement_display (&el, drawMode);
mdlElmdscr_appendElement(pDescr,&el);
if (drawMode==NORMALDRAW)
{
mdlElmdscr_add(pDescr);
}
mdlElmdscr_freeAll(&pDescr);
return SUCCESS;
}
/
*-----------------------------------------------------------------------
---+
| name keyinText |
+-----------------------------------------------------------------------
---*/
Private void keyinText(char *cmdStringP)
{
strcpy(textin,cmdStringP);
}
/
*-----------------------------------------------------------------------
---+
| name placeBox_done |
+-----------------------------------------------------------------------
---*/
Private void placeBox_done()
{
mdlOutput_rscPrintf(MSG_PROMPT,NULL,0,4);
mdlState_restartCurrentCommand();
}
/
*-----------------------------------------------------------------------
---+
| name placeBox_seconPoint |
+-----------------------------------------------------------------------
---*/
Private void placeBox_secondpoint
(
Dpoint3d *pt,
int view
)
{
generateImage(pt,view,NORMALDRAW);
}
/
*-----------------------------------------------------------------------
---+
| name placeBox_firstPoint |
+-----------------------------------------------------------------------
---*/
Private void placeBox_firstpoint
(
Dpoint3d*pt,
int view
)
{
pntP[0]=*pt;
/*Set the datapoint state function for the second point.*/
mdlState_setKeyinPrompt ("KEY IN TEXT:");
mdlState_setFunction (STATE_KEYIN,keyinText);
mdlState_setFunction (STATE_DATAPOINT,placeBox_secondpoint);
mdlState_setFunction (STATE_RESET,placeBox_done);
mdlOutput_rscPrintf (MSG_PROMPT,NULL,0,3);
/*Setup Rubber Banding function*/
mdlState_setFunction (STATE_COMPLEX_DYNAMICS,generateImage);
}
/
*-----------------------------------------------------------------------
---+
| name placeBox_start |
+-----------------------------------------------------------------------
---*/
void placeBox_start()
cmdNumber CMD_PLACE_BOX
{
mdlState_startPrimitive(placeBox_firstpoint,placeBox_start,1,2);
}
/
*-----------------------------------------------------------------------
----------**//**
* @description PlaceBox_unloadFunction
* @param unloadType Reason for the unload of the app
* @return SUCCESS to allow the unload; ERROR to disallow the unload
* @bsimethod BSI 06/03
+---------------+---------------+---------------+---------------
+---------------+------*/
Private int PlaceBox_unloadFunction
(
int unloadType
)
{
BoolInt disallow = FALSE;
/*------------------------------------------------------------------
| If the value of unloadType is negative, then Micro Station ignores
| the return value of this function. In this case, we can assume
| that Micro Station is shutting down or was terminated so this
| function should not attempt to abort the unload.
+------------------------------------------------------------------*/
if (unloadType < 0)
{
return FALSE;
}
/*
** Your processing, which may include setting the disallow flag to TRUE
*/
return (disallow ? ERROR : SUCCESS);
}
/
*-----------------------------------------------------------------------
----------**//**
* Dialog/Item Hooks; Command Numbers and Command Names
+---------------+---------------+---------------+---------------
+----------------*/

typedef void (*Handler)(char *);


typedef void (*Hook)();
/
*-----------------------------------------------------------------------
----------**//**
* @description MdlMain
* @param argc Count of arguments into the function
* @param argv Array of arguments
* @return Return code from the application
* @bsimethod BSI 06/03
+---------------+---------------+---------------+---------------
+----------------*/
Public int main
(
int argc,
char *argv[]
)
{
RscFileHandle rscFileH;
/
*-----------------------------------------------------------------------
mdlResource_openFile:
This function opens a resource file, thus making its contents
available to the application. In this case, we need to open
treexmpl.ma as a resource file so that we have access to the the
string lists for our messages.
-----------------------------------------------------------------------
*/
if (SUCCESS != mdlResource_openFile (&rscFileH, NULL, 0))
{
mdlOutput_rscPrintf (MSG_ERROR, 0l, MESSAGELISTID_Messages,
MESSAGEID_ResourceLoadError);
/* unload the application */
mdlDialog_cmdNumberQueue (FALSE, CMD_MDL_UNLOAD,
mdlSystem_getCurrTaskID (), TRUE);
}
/* --- Set up function to get called at unload time --- */
mdlSystem_setFunction (SYSTEM_UNLOAD_PROGRAM, PlaceBox_unloadFunction);
mdlState_registerStringIds(MESSAGELISTID_Commands,
MESSAGELISTID_Commands);
mdlParse_loadCommandTable (NULL);
mdlOutput_prompt("Key-in PLACE BOX to execute");
return 0;
}
1.9 Chapter Summary
To learn a new programming language is often very difficult. We believe that the
best way is to look at an example. If you find it difficult at this stage, do not despair; Just
remember the following points:

MDL is based on the C language.


Micro Station is a state machine. Take advantage of this, MDL can enter the basic layer
of Micro Station to use it.
State machine means that the command is not necessarily carried out sequentially, but
according to the events within the active part of the Micro Station commands.
The user commands and MicroCSL procedures Micro Station commands in sequence.
MDL can also do so, but its real power is that it can change according to the state to
provide a function call.

You might also like