home *** CD-ROM | disk | FTP | other *** search
/ Enter 1998 December / ENTER12_1.iso / Dema / Cad_Proj.ekt / Mega48t / CC / MEGAIF.C_ / MEGAIF.C
Encoding:
C/C++ Source or Header  |  1997-10-13  |  31.3 KB  |  1,040 lines

  1. /**********************************************************************/
  2.  
  3. #include "std.h"
  4. #include "megatyp.h"
  5. #include "megacad.h"
  6. #include "megapar.h"
  7.  
  8. /**********************************************************************/
  9.  
  10. typedef ulong (_far _pascal _export *t_MegaCadIF)(t_MegaPars _far*,uint,uint);
  11.  
  12. typedef union
  13. {
  14.     struct
  15.     {
  16.         t_MegaCadIF fnIF;
  17.         uint        para;
  18.     } tp;
  19.     struct
  20.     {
  21.         char        _far *file;
  22.         char        _far *args;
  23.     } sm;
  24.     struct
  25.     {
  26.         tCallBack   func;
  27.         void        _far *data;
  28.     } cb;
  29. } t_para;
  30.  
  31. #define MI_CALLBACK   1
  32. #define MI_GETVERSION 2
  33. #define MI_TAKEPARA   3
  34. #define MI_STARTMAIN  4
  35.  
  36. /**********************************************************************/
  37.  
  38. static ulong _far _pascal IF_Dummy(
  39.         t_MegaPars _far *pars,
  40.         uint       megaptr,
  41.         uint       funcnum )
  42. {
  43.     if ( pars || megaptr || funcnum )
  44.         return(0L);
  45.     return(0L);
  46. }
  47.  
  48. /**********************************************************************/
  49.  
  50. static t_MegaCadIF MegaCAD_IF  = IF_Dummy;
  51. static uint        MegaCAD_ptr = 0;
  52.  
  53. extern short MegaMain(char*,char*);
  54.  
  55. #ifdef _WIN32
  56.     __declspec(dllexport) short __stdcall MegaCAD_Entry();
  57. #endif
  58.  
  59. /**********************************************************************/
  60. /* This function is the entry point that MegaCAD searches for, when   */
  61. /* having loaded the DLL.                                             */
  62. /**********************************************************************/
  63.  
  64. short _far _pascal _export MegaCAD_Entry(
  65.         uint   fCode,
  66.         t_para *par )
  67. {
  68.     static char mFile[256];
  69.     static char mArgs[256];
  70.  
  71.     switch ( fCode )
  72.     {
  73.         case MI_CALLBACK   :
  74.             // call the 'tCallBack' function with the given data pointer;
  75.             // this indirect way assures that only this function has to
  76.             // be '_export', not all the callback functions within the DLL.
  77.             return( par->cb.func(par->cb.data) );
  78.  
  79.         case MI_GETVERSION :
  80.             // return the version number of the MegaCAD interface
  81.             // the number must match the number of the MegaCAD .EXE
  82.             return( MI_VERSION );
  83.  
  84.         case MI_TAKEPARA   :
  85.             // save the MegaCAD entry function and parameter
  86.             MegaCAD_IF  = par->tp.fnIF;
  87.             MegaCAD_ptr = par->tp.para;
  88.             return(1);
  89.  
  90.         case MI_STARTMAIN  :
  91.             // call the 'MegaMain()' function of the DLL
  92.             par->sm.file = strcpy(mFile,par->sm.file);
  93.             if ( par->sm.args )
  94.                 par->sm.args = strcpy(mArgs,par->sm.args);
  95.             return( MegaMain(par->sm.file,par->sm.args) );
  96.     }
  97.     return(-1);
  98. }
  99.  
  100. /**********************************************************************/
  101. /* Local function, that calls the MegaCAD entry function.             */
  102. /**********************************************************************/
  103.  
  104. #if _MSC_VER >= 700 && _MSC_VER <= 800
  105.     #define _pSTACK _based(_segname("_STACK"))
  106. #else
  107.     #define _pSTACK
  108. #endif
  109.  
  110. static ulong _near _fastcall CallMegaCAD(
  111.         t_MegaPars _pSTACK *params,
  112.         uint       funcnum )
  113. {
  114.     return( MegaCAD_IF(params,MegaCAD_ptr,funcnum) );
  115. }
  116.  
  117. /**********************************************************************/
  118. #if defined ( _WIN32 )
  119. /**********************************************************************/
  120. /* In 32 bit DLL's there has to be an extra _matherr function!!!      */
  121. /* Especially 'atan2()' would produce floating point errors with two  */
  122. /* identical points.                                                  */
  123. /**********************************************************************/
  124.  
  125. int _matherr(
  126.         struct _exception *err )
  127. {
  128.     err->retval = 0.0;
  129.     return(1);
  130. }
  131.  
  132. /**********************************************************************/
  133. #endif   // _WIN32
  134. /**********************************************************************/
  135. /*--------------------------------------------------------------------*/
  136. /**********************************************************************/
  137. /* Function codes.                                                    */
  138. /**********************************************************************/
  139.  
  140. #define GET_PNT_INV            1
  141. #define DRAW_INV               2
  142. #define DLG_INPUT              3
  143. #define GET_FILENAME           4
  144. #define STORE_MULTIPLE         5
  145. #define MEGA_CMD               6
  146. #define MESSAGE                7
  147. #define MOUSE_HELP             8
  148. #define GET_PNT                9
  149. #define SAVECOUNT             10
  150. #define SET_FUNC_TEXT         11
  151. #define CREATE_ENTITY         12
  152. #define GET_TEXT_VAL          13
  153. #define READ_TXT_FILE         14
  154. #define ADD_POLYLN_PT         15
  155. #define ERASE_INV             16
  156. #define GET_DIM_VAL           17
  157. #define PRINT_DIM_VAL         18
  158. #define CLICK_ENTITY          19
  159. #define EX_CHANGE_ENTITY      20
  160. #define BLINK                 21
  161. #define ENTITY_LOOP           22
  162. #define DRAW_ENTITIES         23
  163. #define STRING_INPUT          24
  164. #define SELECT_INIT           25
  165. #define SELECT_LOOP           26
  166. #define INSERT_MACRO          27
  167. #define CALC_PATTERN          28
  168. #define DELETE_ENTITY         29
  169. #define GET_ENTITY            30
  170. #define SET_INC_PNT           31
  171. #define INFO_LOOP             32
  172. #define GET_INFO              33
  173. #define STORE_INFO            34
  174. #define EX_CHANGE_INFO        35
  175. #define GET_ATTRIBUTES        36
  176. #define GET_LAY_GRP_BITS      37
  177. #define GET_LAYER_NAMES       38
  178. #define GET_GROUP_NAMES       39
  179. #define GET_GRID_SETS         40
  180. #define SET_ATTRIBUTES        41
  181. #define SET_LAY_GRP_BITS      42
  182. #define SET_LAYER_NAMES       43
  183. #define SET_GROUP_NAMES       44
  184. #define SET_GRID_SETS         45
  185. #define GET_CURRENT_FILE      46
  186. #define CREATE_MACRO          47
  187. #define MACRO_LOOP            48
  188. #define CLICK_MACRO           49
  189. #define ENTITY_LEN            50
  190. #define PART_LIST             51
  191. #define GET_PATTERN_VAL       52
  192. #define GET_EXPRESSION        53
  193. #define DELETE_MACRO          54
  194. #define GET_MACRO_INFO        55
  195. #define SET_MACRO_INFO        56
  196. #define GET_PNT_SYMBOL        57
  197.  
  198. /**********************************************************************/
  199. /* The functions of the MegaCAD interface.                            */
  200. /**********************************************************************/
  201.  
  202. short GetPntInv(              // get point and draw something with mouse move
  203.         double      *pkt,     // point to be filled in
  204.         short       setinc,   // incremental point to be set ?
  205.         tCallBack   func,     // callback function
  206.         void        *para)    // data pointer for callback function
  207. {
  208.     t_MegaPars params;
  209.  
  210.     params.m_GetPntInv.pkt    = pkt   ;
  211.     params.m_GetPntInv.setinc = setinc;
  212.     params.m_GetPntInv.func   = func  ;
  213.     params.m_GetPntInv.para   = para  ;
  214.  
  215.     return( (short) CallMegaCAD(¶ms,GET_PNT_INV) );
  216. }
  217.  
  218. /**********************************************************************/
  219.  
  220. void DrawInv(                 // draw and save a temporary object
  221.         ushort      type,     // type of entity to be drawn
  222.         void        *ptr,     // data of entity
  223.         ushort      lmode,    // line attributes (see LMODE)
  224.         ushort      atype)    // type to get attributes from
  225. {
  226.     t_MegaPars params;
  227.  
  228.     params.m_DrawInv.type  = type ;
  229.     params.m_DrawInv.ptr   = ptr  ;
  230.     params.m_DrawInv.lmode = lmode;
  231.     params.m_DrawInv.atype = atype;
  232.  
  233.     CallMegaCAD(¶ms,DRAW_INV);
  234. }
  235.  
  236. /**********************************************************************/
  237.  
  238. short DlgInput(               // input some values by dialog
  239.         ushort      num,      // number of fields (1 - 10)
  240.         char        *title,   // title string
  241.         t_dlgdta    *dta)     // array of field descriptors
  242. {
  243.     t_MegaPars params;
  244.  
  245.     params.m_DlgInput.num   = num  ;
  246.     params.m_DlgInput.title = title;
  247.     params.m_DlgInput.dta   = dta  ;
  248.  
  249.     return( (short) CallMegaCAD(¶ms,DLG_INPUT) );
  250. }
  251.  
  252. /**********************************************************************/
  253.  
  254. short GetFilename(            // let the user select a filename
  255.         char        *title,   // title string
  256.         char        *fname)   // filename; must be initialized with path
  257. {
  258.     t_MegaPars params;
  259.  
  260.     params.m_GetFilename.title = title;
  261.     params.m_GetFilename.fname = fname;
  262.  
  263.     return( (short) CallMegaCAD(¶ms,GET_FILENAME) );
  264. }
  265.  
  266. /**********************************************************************/
  267.  
  268. void StoreMultiple(           // store an entity (maybe multiple)
  269.         double      *data,    // entity data
  270.         ushort      type)     // entity type (may be or'ed with DO_SAVCNT)
  271. {
  272.     t_MegaPars params;
  273.  
  274.     params.m_StoreMultiple.data = data;
  275.     params.m_StoreMultiple.type = type;
  276.  
  277.     CallMegaCAD(¶ms,STORE_MULTIPLE);
  278. }
  279.  
  280. /**********************************************************************/
  281.  
  282. void MegaCMD(                 // call MegaCAD command
  283.         char        *cmd)     // command string (+ arguments)
  284. {
  285.     t_MegaPars params;
  286.  
  287.     params.m_MegaCMD.cmd = cmd;
  288.  
  289.     CallMegaCAD(¶ms,MEGA_CMD);
  290. }
  291.  
  292. /**********************************************************************/
  293.  
  294. short Message(                // message box
  295.         char        *str1,    // 1st line of text
  296.         char        *str2,    // 2nd line of text
  297.         char        *but1,    // 1st button (may be NULL)
  298.         char        *but2,    // 2nd button (may be NULL)
  299.         char        *but3,    // 3rd button
  300.         short       defbut)   // number of default button (1-3)
  301. {
  302.     t_MegaPars params;
  303.  
  304.     params.m_Message.str1   = str1  ;
  305.     params.m_Message.str2   = str2  ;
  306.     params.m_Message.but1   = but1  ;
  307.     params.m_Message.but2   = but2  ;
  308.     params.m_Message.but3   = but3  ;
  309.     params.m_Message.defbut = defbut;
  310.  
  311.     return( (short) CallMegaCAD(¶ms,MESSAGE) );
  312. }
  313.  
  314. /**********************************************************************/
  315.  
  316. void MouseHelp(               // help text for mouse buttons
  317.         char        *str1,    // help text for left mouse button
  318.         char        *str2,    // help text for right mouse button
  319.         ushort      inv)      // colour (beep) for 1st text (see HLP_INV)
  320. {
  321.     t_MegaPars params;
  322.  
  323.     params.m_MouseHelp.str1 = str1;
  324.     params.m_MouseHelp.str2 = str2;
  325.     params.m_MouseHelp.inv  = inv ;
  326.  
  327.     CallMegaCAD(¶ms,MOUSE_HELP);
  328. }
  329.  
  330. /**********************************************************************/
  331.  
  332. short GetPnt(                 // get point
  333.         double      *pkt,     // point to be filled in
  334.         short       setinc)   // incremental point to be set ?
  335. {
  336.     t_MegaPars params;
  337.  
  338.     params.m_GetPnt.pkt    = pkt   ;
  339.     params.m_GetPnt.setinc = setinc;
  340.  
  341.     return( (short) CallMegaCAD(¶ms,GET_PNT) );
  342. }
  343.  
  344. /**********************************************************************/
  345.  
  346. void savecount(               // end of operation
  347.         void )                // must be called after creation of entities
  348. {
  349.     t_MegaPars params;
  350.  
  351.     CallMegaCAD(¶ms,SAVECOUNT);
  352. }
  353.  
  354. /**********************************************************************/
  355.  
  356. void SetFuncText(             // set name of current function
  357.         char        *text)    // function text
  358. {
  359.     t_MegaPars params;
  360.  
  361.     params.m_SetFuncText.text = text;
  362.  
  363.     CallMegaCAD(¶ms,SET_FUNC_TEXT);
  364. }
  365.  
  366. /**********************************************************************/
  367.  
  368. ulong CreateEntity(           // store an entity (not multiple), returns ID
  369.         ushort      type,     // entity type
  370.         t_attribs   *attr,    // entity attributes (may be NULL)
  371.         void        *data)    // entity data
  372. {
  373.     t_MegaPars params;
  374.  
  375.     params.m_CreateEntity.type = type;
  376.     params.m_CreateEntity.attr = attr;
  377.     params.m_CreateEntity.data = data;
  378.  
  379.     return( (ulong) CallMegaCAD(¶ms,CREATE_ENTITY) );
  380. }
  381.  
  382. /**********************************************************************/
  383.  
  384. void GetTextVal(              // retrieve text attributes
  385.         ushort      type,     // line or block
  386.         ushort      init,     // initialize (or just calculate box)
  387.         t_text      *txt)     // text data
  388. {
  389.     t_MegaPars params;
  390.  
  391.     params.m_GetTextVal.type = type;
  392.     params.m_GetTextVal.init = init;
  393.     params.m_GetTextVal.txt  = txt ;
  394.  
  395.     CallMegaCAD(¶ms,GET_TEXT_VAL);
  396. }
  397.  
  398. /**********************************************************************/
  399.  
  400. ushort ReadTxtFile(           // read in a text file
  401.         char        *fname,   // filename
  402.         char        *buf,     // buffer to be filled in
  403.         uint        bufsiz)   // size of buffer
  404. {
  405.     t_MegaPars params;
  406.  
  407.     params.m_ReadTxtFile.fname  = fname ;
  408.     params.m_ReadTxtFile.buf    = buf   ;
  409.     params.m_ReadTxtFile.bufsiz = bufsiz;
  410.  
  411.     return( (ushort) CallMegaCAD(¶ms,READ_TXT_FILE) );
  412. }
  413.  
  414. /**********************************************************************/
  415.  
  416. ushort AddPolylnPt(           // add a polyline point
  417.         t_polyln    *polyln,  // polyline structure
  418.         double      *mpd,     // may be NULL
  419.         double      px,       // x-coordinate of point
  420.         double      py)       // y-coordinate of point
  421. {
  422.     t_MegaPars params;
  423.  
  424.     params.m_AddPolylnPt.polyln = polyln;
  425.     params.m_AddPolylnPt.mpd    = mpd   ;
  426.     params.m_AddPolylnPt.px     = px    ;
  427.     params.m_AddPolylnPt.py     = py    ;
  428.  
  429.     return( (ushort) CallMegaCAD(¶ms,ADD_POLYLN_PT) );
  430. }
  431.  
  432. /**********************************************************************/
  433.  
  434. void EraseInv(                // delete temporary objects
  435.         void ) 
  436. {
  437.     t_MegaPars params;
  438.  
  439.     CallMegaCAD(¶ms,ERASE_INV);
  440. }
  441.  
  442. /**********************************************************************/
  443.  
  444. void GetDimVal(               // retrieve dimension attributes
  445.         ushort      type,     // type of dimension
  446.         ushort      init,     // initialize (or just calculate box)
  447.         t_dimension *dim)     // dimension data
  448. {
  449.     t_MegaPars params;
  450.  
  451.     params.m_GetDimVal.type = type;
  452.     params.m_GetDimVal.init = init;
  453.     params.m_GetDimVal.dim  = dim ;
  454.  
  455.     CallMegaCAD(¶ms,GET_DIM_VAL);
  456. }
  457.  
  458. /**********************************************************************/
  459.  
  460. void PrintDimVal(             // print dimension text
  461.         double      value,    // measured value
  462.         char        *str,     // string buffer to fill
  463.         char        *tol1,    // tolerance string 1
  464.         char        *tol2)    // tolerance string 2
  465. {
  466.     t_MegaPars params;
  467.  
  468.     params.m_PrintDimVal.value = value;
  469.     params.m_PrintDimVal.str   = str  ;
  470.     params.m_PrintDimVal.tol1  = tol1 ;
  471.     params.m_PrintDimVal.tol2  = tol2 ;
  472.  
  473.     CallMegaCAD(¶ms,PRINT_DIM_VAL);
  474. }
  475.  
  476. /**********************************************************************/
  477.  
  478. short ClickEntity(            // let the user click a single entity
  479.         ulong       filter,   // allowed entity types
  480.         double      *pnt,     // point where entity was clicked
  481.         t_entity    *ent,     // entity data to be filled in
  482.         void        *edta,    // data ptr of variable length entities
  483.         ushort      esiz,     // size of data buffer
  484.         uchar       fModify)  // entity to be modified?
  485. {
  486.     t_MegaPars params;
  487.  
  488.     params.m_ClickEntity.filter  = filter ;
  489.     params.m_ClickEntity.pnt     = pnt    ;
  490.     params.m_ClickEntity.ent     = ent    ;
  491.     params.m_ClickEntity.edta    = edta   ;
  492.     params.m_ClickEntity.esiz    = esiz   ;
  493.     params.m_ClickEntity.fModify = fModify;
  494.  
  495.     return( (short) CallMegaCAD(¶ms,CLICK_ENTITY) );
  496. }
  497.  
  498. /**********************************************************************/
  499.  
  500. ulong ExChangeEntity(         // exchange an entity, returns new ID
  501.         t_entity    *ent)     // new entity data, old id
  502. {
  503.     t_MegaPars params;
  504.  
  505.     params.m_ExChangeEntity.ent = ent;
  506.  
  507.     return( (ulong) CallMegaCAD(¶ms,EX_CHANGE_ENTITY) );
  508. }
  509.  
  510. /**********************************************************************/
  511.  
  512. short Blink(                  // draw something blinking
  513.         tCallBack   func,     // callback function
  514.         void        *para)    // data pointer for callback function
  515. {
  516.     t_MegaPars params;
  517.  
  518.     params.m_Blink.func = func;
  519.     params.m_Blink.para = para;
  520.  
  521.     return( (short) CallMegaCAD(¶ms,BLINK) );
  522. }
  523.  
  524. /**********************************************************************/
  525.  
  526. void EntityLoop(              // loop through all entities
  527.         ulong       filter,   // allowed entity types
  528.         tCallBack   func,     // callback function
  529.         void        *para,    // data pointer for callback function
  530.         void        *edta,    // data ptr of variable length entities
  531.         ushort      esiz)     // size of data buffer
  532. {
  533.     t_MegaPars params;
  534.  
  535.     params.m_EntityLoop.filter = filter;
  536.     params.m_EntityLoop.func   = func  ;
  537.     params.m_EntityLoop.para   = para  ;
  538.     params.m_EntityLoop.edta   = edta  ;
  539.     params.m_EntityLoop.esiz   = esiz  ;
  540.  
  541.     CallMegaCAD(¶ms,ENTITY_LOOP);
  542. }
  543.  
  544. /**********************************************************************/
  545.  
  546. void DrawEntities(            // draw array of entity-id's
  547.         ulong       *pid,     // array of entity-id's
  548.         ushort      num)      // number of id's
  549. {
  550.     t_MegaPars params;
  551.  
  552.     params.m_DrawEntities.pid = pid;
  553.     params.m_DrawEntities.num = num;
  554.  
  555.     CallMegaCAD(¶ms,DRAW_ENTITIES);
  556. }
  557.  
  558. /**********************************************************************/
  559.  
  560. short StringInput(            // input a line of text
  561.         char        *title,   // title string
  562.         char        *buf,     // string buffer to be filled in
  563.         ushort      buflen)   // size of buffer
  564. {
  565.     t_MegaPars params;
  566.  
  567.     params.m_StringInput.title  = title ;
  568.     params.m_StringInput.buf    = buf   ;
  569.     params.m_StringInput.buflen = buflen;
  570.  
  571.     return( (short) CallMegaCAD(¶ms,STRING_INPUT) );
  572. }
  573.  
  574. /**********************************************************************/
  575.  
  576. void SelectInit(              // set select filter
  577.         ulong       filter)   // allowed entity types
  578. {
  579.     t_MegaPars params;
  580.  
  581.     params.m_SelectInit.filter = filter;
  582.  
  583.     CallMegaCAD(¶ms,SELECT_INIT);
  584. }
  585.  
  586. /**********************************************************************/
  587.  
  588. void SelectLoop(              // select entities
  589.         tCallBack   func,     // callback function
  590.         void        *para,    // data pointer for callback function
  591.         void        *edta,    // data ptr of variable length entities
  592.         ushort      esiz,     // size of data buffer
  593.         uchar       fModify)  // entities to be modified?
  594. {
  595.     t_MegaPars params;
  596.  
  597.     params.m_SelectLoop.func    = func   ;
  598.     params.m_SelectLoop.para    = para   ;
  599.     params.m_SelectLoop.edta    = edta   ;
  600.     params.m_SelectLoop.esiz    = esiz   ;
  601.     params.m_SelectLoop.fModify = fModify;
  602.  
  603.     CallMegaCAD(¶ms,SELECT_LOOP);
  604. }
  605.  
  606. /**********************************************************************/
  607.  
  608. ushort InsertMacro(           // insert macro-file
  609.         char        *fname,   // macro filename
  610.         tCallBack   func,     // callback function
  611.         void        *para,    // data pointer for callback function
  612.         void        *edta,    // data ptr of variable length entities
  613.         ushort      esiz,     // size of data buffer
  614.         t_placemac  *pmac)    // how (and where) to place the macro
  615. {
  616.     t_MegaPars params;
  617.  
  618.     params.m_InsertMacro.fname = fname;
  619.     params.m_InsertMacro.func  = func ;
  620.     params.m_InsertMacro.para  = para ;
  621.     params.m_InsertMacro.edta  = edta ;
  622.     params.m_InsertMacro.esiz  = esiz ;
  623.     params.m_InsertMacro.pmac  = pmac ;
  624.  
  625.     return( (ushort) CallMegaCAD(¶ms,INSERT_MACRO) );
  626. }
  627.  
  628. /**********************************************************************/
  629.  
  630. ushort CalcPattern(           // calc perimeter, area, pt. of gravity
  631.         ushort      which,    // PERIM, AREA, GRAVITY
  632.         ushort      cnt,      // cnt of polyline points
  633.         t_polypt    *ppt,     // maybe NULL
  634.         double      *result)  // value vs. point
  635. {
  636.     t_MegaPars params;
  637.  
  638.     params.m_CalcPattern.which  = which ;
  639.     params.m_CalcPattern.cnt    = cnt   ;
  640.     params.m_CalcPattern.ppt    = ppt   ;
  641.     params.m_CalcPattern.result = result;
  642.  
  643.     return( (ushort) CallMegaCAD(¶ms,CALC_PATTERN) );
  644. }
  645.  
  646. /**********************************************************************/
  647.  
  648. ushort DeleteEntity(          // delete an entity
  649.         ulong       id)       // ID of entity
  650. {
  651.     t_MegaPars params;
  652.  
  653.     params.m_DeleteEntity.id = id;
  654.  
  655.     return( (ushort) CallMegaCAD(¶ms,DELETE_ENTITY) );
  656. }
  657.  
  658. /**********************************************************************/
  659.  
  660. ushort GetEntity(             // get entity data
  661.         ulong       id,       // ID of entity
  662.         t_entity    *ent,     // entity
  663.         void        *edta,    // data ptr of variable length entities
  664.         ushort      esiz)     // size of data buffer
  665. {
  666.     t_MegaPars params;
  667.  
  668.     params.m_GetEntity.id   = id  ;
  669.     params.m_GetEntity.ent  = ent ;
  670.     params.m_GetEntity.edta = edta;
  671.     params.m_GetEntity.esiz = esiz;
  672.  
  673.     return( (ushort) CallMegaCAD(¶ms,GET_ENTITY) );
  674. }
  675.  
  676. /**********************************************************************/
  677.  
  678. void SetIncPnt(               // set incremental point
  679.         double      *pnt)     // new incremental point
  680. {
  681.     t_MegaPars params;
  682.  
  683.     params.m_SetIncPnt.pnt = pnt;
  684.  
  685.     CallMegaCAD(¶ms,SET_INC_PNT);
  686. }
  687.  
  688. /**********************************************************************/
  689.  
  690. void InfoLoop(                // loop through all entity infos
  691.         tCallBack   func,     // callback function
  692.         t_entinfo   *inf )    // info buffer
  693. {
  694.     t_MegaPars params;
  695.  
  696.     params.m_InfoLoop.func = func;
  697.     params.m_InfoLoop.inf  = inf ;
  698.  
  699.     CallMegaCAD(¶ms,INFO_LOOP);
  700. }
  701.  
  702. /**********************************************************************/
  703.  
  704. ushort GetInfo(               // get entity info data
  705.         ushort      iID,      // info ID
  706.         t_entinfo   *inf )    // info buffer
  707. {
  708.     t_MegaPars params;
  709.  
  710.     params.m_GetInfo.iID  = iID ;
  711.     params.m_GetInfo.inf  = inf ;
  712.  
  713.     return( (ushort) CallMegaCAD(¶ms,GET_INFO) );
  714. }
  715.  
  716. /**********************************************************************/
  717.  
  718. ushort StoreInfo(             // store entity info
  719.         t_entinfo   *inf )    // info buffer
  720. {
  721.     t_MegaPars params;
  722.  
  723.     params.m_StoreInfo.inf  = inf ;
  724.  
  725.     return( (ushort) CallMegaCAD(¶ms,STORE_INFO) );
  726. }
  727.  
  728. /**********************************************************************/
  729.  
  730. ushort ExChangeInfo(          // exchange entity info data
  731.         t_entinfo   *inf )    // info buffer
  732. {
  733.     t_MegaPars params;
  734.  
  735.     params.m_ExChangeInfo.inf  = inf ;
  736.  
  737.     return( (ushort) CallMegaCAD(¶ms,EX_CHANGE_INFO) );
  738. }
  739.  
  740. /**********************************************************************/
  741.  
  742. void GetAttributes(           // get attributes (stl,col...)
  743.         ushort      type,     // entity type
  744.         t_attribs   *attr)    // buffer to be filled in
  745. {
  746.     t_MegaPars params;
  747.  
  748.     params.m_GetAttributes.type = type;
  749.     params.m_GetAttributes.attr = attr;
  750.  
  751.     CallMegaCAD(¶ms,GET_ATTRIBUTES);
  752. }
  753.  
  754. /**********************************************************************/
  755.  
  756. void GetLayGrpBits(           // retrieve active/inactive layers
  757.         uchar       *bits)    // buffer of 256 bytes !!!
  758. {
  759.     t_MegaPars params;
  760.  
  761.     params.m_GetLayGrpBits.bits = bits;
  762.  
  763.     CallMegaCAD(¶ms,GET_LAY_GRP_BITS);
  764. }
  765.  
  766. /**********************************************************************/
  767.  
  768. void GetLayerNames(           // retrieve layer names
  769.         t_laygrp    *lg)      // buffer of 256 * 64 bytes
  770. {
  771.     t_MegaPars params;
  772.  
  773.     params.m_GetLayerNames.lg = lg;
  774.  
  775.     CallMegaCAD(¶ms,GET_LAYER_NAMES);
  776. }
  777.  
  778. /**********************************************************************/
  779.  
  780. void GetGroupNames(           // retrieve group names
  781.         t_laygrp    *lg)      // buffer of 256 * 64 bytes
  782. {
  783.     t_MegaPars params;
  784.  
  785.     params.m_GetGroupNames.lg = lg;
  786.  
  787.     CallMegaCAD(¶ms,GET_GROUP_NAMES);
  788. }
  789.  
  790. /**********************************************************************/
  791.  
  792. void GetGridSets(             // retrieve grid settings
  793.         t_gridsets  *grid)    // buffer to be filled in
  794. {
  795.     t_MegaPars params;
  796.  
  797.     params.m_GetGridSets.grid = grid;
  798.  
  799.     CallMegaCAD(¶ms,GET_GRID_SETS);
  800. }
  801.  
  802. /**********************************************************************/
  803.  
  804. void SetAttributes(           // alter attributes (stl,col...)
  805.         ushort      type,     // entity type
  806.         t_attribs   *attr)    // new attributes
  807. {
  808.     t_MegaPars params;
  809.  
  810.     params.m_SetAttributes.type = type;
  811.     params.m_SetAttributes.attr = attr;
  812.  
  813.     CallMegaCAD(¶ms,SET_ATTRIBUTES);
  814. }
  815.  
  816. /**********************************************************************/
  817.  
  818. void SetLayGrpBits(           // set active/inactive layers
  819.         uchar       *bits)    // new bits (256 bytes !!!)
  820. {
  821.     t_MegaPars params;
  822.  
  823.     params.m_SetLayGrpBits.bits = bits;
  824.  
  825.     CallMegaCAD(¶ms,SET_LAY_GRP_BITS);
  826. }
  827.  
  828. /**********************************************************************/
  829.  
  830. void SetLayerNames(           // set layer names
  831.         t_laygrp    *lg)      // buffer of 256 * 64 Bytes
  832. {
  833.     t_MegaPars params;
  834.  
  835.     params.m_SetLayerNames.lg = lg;
  836.  
  837.     CallMegaCAD(¶ms,SET_LAYER_NAMES);
  838. }
  839.  
  840. /**********************************************************************/
  841.  
  842. void SetGroupNames(           // set group names
  843.         t_laygrp    *lg)      // buffer of 256 * 64 Bytes
  844. {
  845.     t_MegaPars params;
  846.  
  847.     params.m_SetGroupNames.lg = lg;
  848.  
  849.     CallMegaCAD(¶ms,SET_GROUP_NAMES);
  850. }
  851.  
  852. /**********************************************************************/
  853.  
  854. void SetGridSets(             // alter grid settings
  855.         t_gridsets  *grid)    // new settings
  856. {
  857.     t_MegaPars params;
  858.  
  859.     params.m_SetGridSets.grid = grid;
  860.  
  861.     CallMegaCAD(¶ms,SET_GRID_SETS);
  862. }
  863.  
  864. /**********************************************************************/
  865.  
  866. short GetCurrentFile(         // get name of currently loaded file
  867.         uchar       *fname)   // name buffer to be filled in
  868. {
  869.     t_MegaPars params;
  870.  
  871.     params.m_GetCurrentFile.fname = fname;
  872.  
  873.     return( (short) CallMegaCAD(¶ms,GET_CURRENT_FILE) );
  874. }
  875.  
  876. /**********************************************************************/
  877.  
  878. ulong CreateMacro(            // create and insert a macro
  879.         t_macro     *mac,     // macro data
  880.         t_mkmacro   *mkm,     // entities to be created
  881.         ushort      cnt,      // number of entries
  882.         t_placemac  *pmac)    // how (and where) to place the macro
  883. {
  884.     t_MegaPars params;
  885.  
  886.     params.m_CreateMacro.mac  = mac ;
  887.     params.m_CreateMacro.mkm  = mkm ;
  888.     params.m_CreateMacro.cnt  = cnt ;
  889.     params.m_CreateMacro.pmac = pmac;
  890.  
  891.     return( (ulong) CallMegaCAD(¶ms,CREATE_MACRO) );
  892. }
  893.  
  894. /**********************************************************************/
  895.  
  896. void MacroLoop(               // loop through all macros
  897.         ulong       filter,   // allowed entity types
  898.         ulong       start,    // start ID (if 0L => all macros)
  899.         tCallBack   func,     // callback function
  900.         void        *para,    // data pointer for callback function
  901.         void        *edta,    // data ptr of variable length entities
  902.         ushort      esiz)     // size of data buffer
  903. {
  904.     t_MegaPars params;
  905.  
  906.     params.m_MacroLoop.filter = filter;
  907.     params.m_MacroLoop.start  = start ;
  908.     params.m_MacroLoop.func   = func  ;
  909.     params.m_MacroLoop.para   = para  ;
  910.     params.m_MacroLoop.edta   = edta  ;
  911.     params.m_MacroLoop.esiz   = esiz  ;
  912.  
  913.     CallMegaCAD(¶ms,MACRO_LOOP);
  914. }
  915.  
  916. /**********************************************************************/
  917.  
  918. short ClickMacro(             // let the user click a macro
  919.         double      *pnt,     // point where macro was clicked
  920.         t_entity    *ent,     // macro data to be filled in
  921.         void        *edta,    // data ptr of variable length entities
  922.         ushort      esiz)     // size of data buffer
  923. {
  924.     t_MegaPars params;
  925.  
  926.     params.m_ClickMacro.pnt  = pnt ;
  927.     params.m_ClickMacro.ent  = ent ;
  928.     params.m_ClickMacro.edta = edta;
  929.     params.m_ClickMacro.esiz = esiz;
  930.  
  931.     return( (short) CallMegaCAD(¶ms,CLICK_MACRO) );
  932. }
  933.  
  934. /**********************************************************************/
  935.  
  936. short EntityLen(              // retrieve the length of an entity
  937.         t_entity    *ent,     // entity to get length of
  938.         double      *len)     // resulting length
  939. {
  940.     t_MegaPars params;
  941.  
  942.     params.m_EntityLen.ent = ent;
  943.     params.m_EntityLen.len = len;
  944.  
  945.     return( (short) CallMegaCAD(¶ms,ENTITY_LEN) );
  946. }
  947.  
  948. /**********************************************************************/
  949.  
  950. short PartList(               // create a part list
  951.         uchar       *fmt,     // name of format file
  952.         uchar       *out,     // name of output file (maybe NULL)
  953.         uchar       flags)    // flags (PART_....)
  954. {
  955.     t_MegaPars params;
  956.  
  957.     params.m_PartList.fmt   = fmt  ;
  958.     params.m_PartList.out   = out  ;
  959.     params.m_PartList.flags = flags;
  960.  
  961.     return( (short) CallMegaCAD(¶ms,PART_LIST) );
  962. }
  963.  
  964. /**********************************************************************/
  965.  
  966. void GetPatternVal(           // retrieve current pattern settings
  967.         t_pattern   *pat)     // pattern data
  968. {
  969.     t_MegaPars params;
  970.  
  971.     params.m_GetPatternVal.pat = pat;
  972.  
  973.     CallMegaCAD(¶ms,GET_PATTERN_VAL);
  974. }
  975.  
  976. /**********************************************************************/
  977.  
  978. short GetExpression(          // evaluate expression
  979.         uchar       *expr,    // expression to be evaluated
  980.         double      *retval)  // result
  981. {
  982.     t_MegaPars params;
  983.  
  984.     params.m_GetExpression.expr   = expr  ;
  985.     params.m_GetExpression.retval = retval;
  986.  
  987.     return( (short) CallMegaCAD(¶ms,GET_EXPRESSION) );
  988. }
  989.  
  990. /**********************************************************************/
  991.  
  992. short DeleteMacro(            // delete a whole macro
  993.         ulong       id)       // ID of macro entity
  994. {
  995.     t_MegaPars params;
  996.  
  997.     params.m_DeleteMacro.id = id;
  998.  
  999.     return( (short) CallMegaCAD(¶ms,DELETE_MACRO) );
  1000. }
  1001.  
  1002. /**********************************************************************/
  1003.  
  1004. short GetMacroInfo(           // retrieve info of current macro file
  1005.         t_macinfo   *macinfo) // buffer to be filled in
  1006. {
  1007.     t_MegaPars params;
  1008.  
  1009.     params.m_GetMacroInfo.macinfo = macinfo;
  1010.  
  1011.     return( (short) CallMegaCAD(¶ms,GET_MACRO_INFO) );
  1012. }
  1013.  
  1014. /**********************************************************************/
  1015.  
  1016. short SetMacroInfo(           // set info of current macro file
  1017.         t_macinfo   *macinfo) // data to be set
  1018. {
  1019.     t_MegaPars params;
  1020.  
  1021.     params.m_SetMacroInfo.macinfo = macinfo;
  1022.  
  1023.     return( (short) CallMegaCAD(¶ms,SET_MACRO_INFO) );
  1024. }
  1025.  
  1026. /**********************************************************************/
  1027.  
  1028. void GetPntSymbol(            // get current symbol settings
  1029.         t_symbol    *sym)     // data to be filled in
  1030. {
  1031.     t_MegaPars params;
  1032.  
  1033.     params.m_GetPntSymbol.sym = sym;
  1034.  
  1035.     CallMegaCAD(¶ms,GET_PNT_SYMBOL);
  1036. }
  1037.  
  1038. /**********************************************************************/
  1039.  
  1040.