home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************/
-
- #include "std.h"
- #include "megatyp.h"
- #include "megacad.h"
- #include "megapar.h"
-
- /**********************************************************************/
-
- int FAR PASCAL WEP (
- int nParameter)
- {
- return (1);
- }
-
- /**********************************************************************/
-
- int _far PASCAL LibMain (
- HANDLE hInstance,
- WORD wDataSeg,
- WORD wHeapSize,
- LPSTR lpszCmdLine)
- {
- return(1);
- }
-
- /***********************************************************************/
-
- typedef void (_far _pascal _export *t_MegaCAD_IF)(
- t_MegaPars _far*,
- ushort,
- uint);
-
- static t_MegaCAD_IF MegaCAD_IF = NULL;
- static uint MegaCAD_ptr = 0;
-
- extern short main(char*,char*);
-
- /***********************************************************************/
- /* This function is called by MegaCAD after loading the DLL. */
- /* It saves the pointer to the MegaCAD entry function and an */
- /* additional parameter to be passed to this function. */
- /* Then calls the main function of the DLL. */
- /***********************************************************************/
-
- void _far _pascal _export MegaCAD_Init(
- t_MegaCAD_IF if_func, // entry function within MegaCAD
- char *filename, // filename of the DLL
- char *args, // argument line
- uint if_ptr ) // parameter to be passed to MegaCAD_IF
- {
- MegaCAD_IF = if_func;
- MegaCAD_ptr = if_ptr;
- main(filename,args);
- }
-
- /***********************************************************************/
- /* This function is called by MegaCAD whenever MegaCAD has to call a */
- /* callback function within the DLL. */
- /* So only this function has be '_export'. */
- /***********************************************************************/
-
- int _far _pascal _export MegaCAD_Call(
- tCallBack func,
- void _far *data )
- {
- return(func(data));
- }
-
- /***********************************************************************/
- /* Local function, that calls the MegaCAD entry function. */
- /***********************************************************************/
-
- static int _near _pascal CallMegaCAD(
- void *params,
- ushort funcnum )
- {
- if ( MegaCAD_IF ) // safety first
- {
- MegaCAD_IF((t_MegaPars*)params,funcnum,MegaCAD_ptr);
- return(TRUE);
- }
- return(FALSE);
- }
-
- /***********************************************************************/
- /* Function codes. */
- /***********************************************************************/
-
- #define GET_PNT_INV 1
- #define DRAW_INV 2
- #define DLG_INPUT 3
- #define GET_FILENAME 4
- #define STORE_MULTIPLE 5
- #define MEGA_CMD 6
- #define MESSAGE 7
- #define MOUSE_HELP 8
- #define GET_PNT 9
- #define SAVECOUNT 10
- #define SET_FUNC_TEXT 11
- #define CREATE_ENTITY 12
- #define GET_TEXT_VAL 13
- #define READ_TXT_FILE 14
- #define ADD_POLYLN_PT 15
- #define ERASE_INV 16
- #define GET_DIM_VAL 17
- #define PRINT_DIM_VAL 18
- #define CLICK_ENTITY 19
- #define EX_CHANGE_ENTITY 20
- #define BLINK 21
- #define ENTITY_LOOP 22
- #define DRAW_ENTITIES 23
- #define STRING_INPUT 24
- #define SELECT_INIT 25
- #define SELECT_LOOP 26
- #define INSERT_MAC 27
-
- /***********************************************************************/
- /* The functions of the MegaCAD interface. */
- /***********************************************************************/
-
- short GetPntInv( // Get point and draw something with mouse move
- double *pkt, // point to be filled in
- short setinc, // incremental point to be set ?
- tCallBack func, // callback function
- void *para) // data pointer for callback function
- {
- t_GetPntInv params;
-
- params.pkt = pkt ;
- params.setinc = setinc;
- params.func = func ;
- params.para = para ;
-
- CallMegaCAD(¶ms,GET_PNT_INV);
- return((short)params.retval);
- }
-
- /***********************************************************************/
-
- void DrawInv( // draw and save a temporary object
- ushort type, // type of entity to be drawn
- void *ptr, // data of entity
- ushort lmode, // line attributes (see LMODE)
- ushort atype) // type to get attributes from
- {
- t_DrawInv params;
-
- params.type = type ;
- params.ptr = ptr ;
- params.lmode = lmode;
- params.atype = atype;
-
- CallMegaCAD(¶ms,DRAW_INV);
- }
-
- /***********************************************************************/
-
- short DlgInput( // input some values by dialog
- ushort num, // number of fields (1 - 10)
- char *title, // title string
- t_dlgdta *dta) // array of field descriptors
- {
- t_DlgInput params;
-
- params.num = num ;
- params.title = title;
- params.dta = dta ;
-
- CallMegaCAD(¶ms,DLG_INPUT);
- return((short)params.retval);
- }
-
- /***********************************************************************/
-
- short GetFilename( // let the user select a filename
- char *title, // title string
- char *fname) // filename; must be initialized with path
- {
- t_GetFilename params;
-
- params.title = title;
- params.fname = fname;
-
- CallMegaCAD(¶ms,GET_FILENAME);
- return((short)params.retval);
- }
-
- /***********************************************************************/
-
- void StoreMultiple( // store an entity (maybe multiple)
- double *data, // entity data
- ushort type) // entity type (may be or'ed with DO_SAVCNT)
- {
- t_StoreMultiple params;
-
- params.data = data;
- params.type = type;
-
- CallMegaCAD(¶ms,STORE_MULTIPLE);
- }
-
- /***********************************************************************/
-
- void MegaCMD( // call MegaCAD command
- char *cmd) // command string (+ arguments)
- {
- t_MegaCMD params;
-
- params.cmd = cmd;
-
- CallMegaCAD(¶ms,MEGA_CMD);
- }
-
- /***********************************************************************/
-
- short Message( // message box
- char *str1, // 1st line of text
- char *str2, // 2nd line of text
- char *but1, // 1st button (may be NULL)
- char *but2, // 2nd button (may be NULL)
- char *but3, // 3rd button
- short defbut) // number of default button (1-3)
- {
- t_Message params;
-
- params.str1 = str1 ;
- params.str2 = str2 ;
- params.but1 = but1 ;
- params.but2 = but2 ;
- params.but3 = but3 ;
- params.defbut = defbut;
-
- CallMegaCAD(¶ms,MESSAGE);
- return((short)params.retval);
- }
-
- /***********************************************************************/
-
- void MouseHelp( // help text for mouse buttons
- char *str1, // help text for left mouse button
- char *str2, // help text for right mouse button
- ushort inv) // colour (beep) for 1st text (see HLP_INV)
- {
- t_MouseHelp params;
-
- params.str1 = str1;
- params.str2 = str2;
- params.inv = inv ;
-
- CallMegaCAD(¶ms,MOUSE_HELP);
- }
-
- /***********************************************************************/
-
- short GetPnt( // Get point
- double *pkt, // point to be filled in
- short setinc) // incremental point to be set ?
- {
- t_GetPnt params;
-
- params.pkt = pkt ;
- params.setinc = setinc;
-
- CallMegaCAD(¶ms,GET_PNT);
- return((short)params.retval);
- }
-
- /***********************************************************************/
-
- void savecount( // End of operation
- void) // must be called after creation of entities
- {
- t_savecount params;
-
- CallMegaCAD(¶ms,SAVECOUNT);
- }
-
- /***********************************************************************/
-
- void SetFuncText( // set name of current function
- char *text) // function text
- {
- t_SetFuncText params;
-
- params.text = text;
-
- CallMegaCAD(¶ms,SET_FUNC_TEXT);
- }
-
- /***********************************************************************/
-
- ulong CreateEntity( // store an entity (not multiple), returns ID
- ushort type, // entity type
- t_attribs *attr, // entity attributes (may be NULL)
- void *data) // entity data
- {
- t_CreateEntity params;
-
- params.type = type;
- params.attr = attr;
- params.data = data;
-
- CallMegaCAD(¶ms,CREATE_ENTITY);
- return((ulong)params.retval);
- }
-
- /***********************************************************************/
-
- void GetTextVal( // retrieve text attributes
- ushort type, // line or block
- ushort init, // initialize (or just calculate box)
- t_text *txt) // text data
- {
- t_GetTextVal params;
-
- params.type = type;
- params.init = init;
- params.txt = txt ;
-
- CallMegaCAD(¶ms,GET_TEXT_VAL);
- }
-
- /***********************************************************************/
-
- ushort ReadTxtFile( // read in a text file
- char *fname, // filename
- char *buf, // buffer to be filled in
- uint bufsiz) // size of buffer
- {
- t_ReadTxtFile params;
-
- params.fname = fname ;
- params.buf = buf ;
- params.bufsiz = bufsiz;
-
- CallMegaCAD(¶ms,READ_TXT_FILE);
- return((ushort)params.retval);
- }
-
- /***********************************************************************/
-
- ushort AddPolylnPt( // add a polyline point
- t_polyln *polyln, // polyline structure
- double *mpd, // may be NULL
- double px, // x-coordinate of point
- double py) // y-coordinate of point
- {
- t_AddPolylnPt params;
-
- params.polyln = polyln;
- params.mpd = mpd ;
- params.px = px ;
- params.py = py ;
-
- CallMegaCAD(¶ms,ADD_POLYLN_PT);
- return((ushort)params.retval);
- }
-
- /***********************************************************************/
-
- void EraseInv( // delete temporary objects
- void)
- {
- t_EraseInv params;
-
- CallMegaCAD(¶ms,ERASE_INV);
- }
-
- /***********************************************************************/
-
- void GetDimVal( // retrieve dimension attributes
- ushort type, // type of dimension
- ushort init, // initialize (or just calculate box)
- t_dimension *dim) // dimension data
- {
- t_GetDimVal params;
-
- params.type = type;
- params.init = init;
- params.dim = dim ;
-
- CallMegaCAD(¶ms,GET_DIM_VAL);
- }
-
- /***********************************************************************/
-
- void PrintDimVal( // print dimension text
- double value, // measured value
- char *str, // string buffer to fill
- char *tol1, // tolerance string 1
- char *tol2) // tolerance string 2
- {
- t_PrintDimVal params;
-
- params.value = value;
- params.str = str ;
- params.tol1 = tol1 ;
- params.tol2 = tol2 ;
-
- CallMegaCAD(¶ms,PRINT_DIM_VAL);
- }
-
- /***********************************************************************/
-
- short ClickEntity( // let the user click a single entity
- ulong filter, // allowed entity types
- double *pnt, // point where entity was clicked
- t_entity *ent, // entity data to be filled in
- void *edta, // data ptr of variable length entities
- ushort esiz) // size of data buffer
- {
- t_ClickEntity params;
-
- params.filter = filter;
- params.pnt = pnt ;
- params.ent = ent ;
- params.edta = edta ;
- params.esiz = esiz ;
-
- CallMegaCAD(¶ms,CLICK_ENTITY);
- return((short)params.retval);
- }
-
- /***********************************************************************/
-
- ulong ExChangeEntity( // exchange an entity, returns new ID
- t_entity *ent) // new entity data, old id
- {
- t_ExChangeEntity params;
-
- params.ent = ent;
-
- CallMegaCAD(¶ms,EX_CHANGE_ENTITY);
- return((ulong)params.retval);
- }
-
- /***********************************************************************/
-
- short Blink( // draw something blinking
- tCallBack func, // callback function
- void *para) // data pointer for callback function
- {
- t_Blink params;
-
- params.func = func;
- params.para = para;
-
- CallMegaCAD(¶ms,BLINK);
- return((short)params.retval);
- }
-
- /***********************************************************************/
-
- void EntityLoop( // loop through all entities
- ulong filter, // allowed entity types
- tCallBack func, // callback function
- void *para, // data pointer for callback function
- void *edta, // data ptr of variable length entities
- ushort esiz) // size of data buffer
- {
- t_EntityLoop params;
-
- params.filter = filter;
- params.func = func ;
- params.para = para ;
- params.edta = edta ;
- params.esiz = esiz ;
-
- CallMegaCAD(¶ms,ENTITY_LOOP);
- }
-
- /***********************************************************************/
-
- void DrawEntities( // draw array of entity-id's
- ulong *pid, // array of entity-id's
- ushort num) // number of id's
- {
- t_DrawEntities params;
-
- params.pid = pid;
- params.num = num;
-
- CallMegaCAD(¶ms,DRAW_ENTITIES);
- }
-
- /***********************************************************************/
-
- short StringInput( // input a line of text
- char *title, // title string
- char *buf, // string buffer to be filled in
- ushort buflen) // size of buffer
- {
- t_StringInput params;
-
- params.title = title ;
- params.buf = buf ;
- params.buflen = buflen;
-
- CallMegaCAD(¶ms,STRING_INPUT);
- return((short)params.retval);
- }
-
- /***********************************************************************/
-
- void SelectInit( // set select filter
- ulong filter) // allowed entity types
- {
- t_SelectInit params;
-
- params.filter = filter;
-
- CallMegaCAD(¶ms,SELECT_INIT);
- }
-
- /***********************************************************************/
-
- void SelectLoop( // select entities
- tCallBack func, // callback function
- void *para, // data pointer for callback function
- void *edta, // data ptr of variable length entities
- ushort esiz) // size of data buffer
- {
- t_SelectLoop params;
-
- params.func = func;
- params.para = para;
- params.edta = edta;
- params.esiz = esiz;
-
- CallMegaCAD(¶ms,SELECT_LOOP);
- }
-
- /***********************************************************************/
-
- ushort InsertMac( // insert macro-file
- char *fname, // macro filename
- tCallBack func, // callback function
- void *para, // data pointer for callback function
- void *edta, // data ptr of variable length entities
- ushort esiz) // size of data buffer
- {
- t_InsertMac params;
-
- params.fname = fname;
- params.func = func;
- params.para = para;
- params.edta = edta;
- params.esiz = esiz;
-
- CallMegaCAD(¶ms,INSERT_MAC);
- return((ushort)params.retval);
- }
-
- /***********************************************************************/
- #if defined ( _WIN32 )
- /***********************************************************************/
-
- int _matherr(
- struct _exception *err )
- {
- err->retval = 0.0;
- return(1);
- }
-
- /***********************************************************************/
- #endif
- /***********************************************************************/
-