home *** CD-ROM | disk | FTP | other *** search
/ Chip 1996 December / CHIP_CD_1996_12_PL.iso / software / trial / megacad.pl / cc / megaif.c_ / megaif.c
Encoding:
C/C++ Source or Header  |  1996-07-12  |  16.2 KB  |  569 lines

  1. /**********************************************************************/
  2.  
  3. #include "std.h"
  4. #include "megatyp.h"
  5. #include "megacad.h"
  6. #include "megapar.h"
  7.  
  8. /**********************************************************************/
  9.  
  10. int FAR PASCAL WEP (
  11.         int nParameter)
  12. {
  13.     return (1);
  14. }
  15.  
  16. /**********************************************************************/
  17.  
  18. int _far PASCAL LibMain (
  19.         HANDLE hInstance,
  20.         WORD   wDataSeg,
  21.         WORD   wHeapSize,
  22.         LPSTR  lpszCmdLine)
  23. {
  24.     return(1);
  25. }
  26.  
  27. /***********************************************************************/
  28.  
  29. typedef void (_far _pascal _export *t_MegaCAD_IF)(
  30.         t_MegaPars _far*,
  31.         ushort,
  32.         uint);
  33.  
  34. static t_MegaCAD_IF MegaCAD_IF  = NULL;
  35. static uint         MegaCAD_ptr = 0;
  36.  
  37. extern short main(char*,char*);
  38.  
  39. /***********************************************************************/
  40. /* This function is called by MegaCAD after loading the DLL.           */
  41. /* It saves the pointer to the MegaCAD entry function and an           */
  42. /* additional parameter to be passed to this function.                 */
  43. /* Then calls the main function of the DLL.                            */
  44. /***********************************************************************/
  45.  
  46. void _far _pascal _export MegaCAD_Init(
  47.         t_MegaCAD_IF if_func,       // entry function within MegaCAD
  48.         char         *filename,     // filename of the DLL
  49.         char         *args,         // argument line
  50.         uint         if_ptr )       // parameter to be passed to MegaCAD_IF
  51. {
  52.     MegaCAD_IF  = if_func;
  53.     MegaCAD_ptr = if_ptr;
  54.     main(filename,args);
  55. }
  56.  
  57. /***********************************************************************/
  58. /* This function is called by MegaCAD whenever MegaCAD has to call a   */
  59. /* callback function within the DLL.                                   */
  60. /* So only this function has be '_export'.                             */
  61. /***********************************************************************/
  62.  
  63. int _far _pascal _export MegaCAD_Call(
  64.         tCallBack func,
  65.         void      _far *data )
  66. {
  67.     return(func(data));
  68. }
  69.  
  70. /***********************************************************************/
  71. /* Local function, that calls the MegaCAD entry function.              */
  72. /***********************************************************************/
  73.  
  74. static int _near _pascal CallMegaCAD(
  75.         void   *params,
  76.         ushort funcnum )
  77. {
  78.     if ( MegaCAD_IF )             // safety first
  79.     {
  80.         MegaCAD_IF((t_MegaPars*)params,funcnum,MegaCAD_ptr);
  81.         return(TRUE);
  82.     }
  83.     return(FALSE);
  84. }
  85.  
  86. /***********************************************************************/
  87. /* Function codes.                                                     */
  88. /***********************************************************************/
  89.  
  90. #define GET_PNT_INV       1
  91. #define DRAW_INV          2
  92. #define DLG_INPUT         3
  93. #define GET_FILENAME      4
  94. #define STORE_MULTIPLE    5
  95. #define MEGA_CMD          6
  96. #define MESSAGE           7
  97. #define MOUSE_HELP        8
  98. #define GET_PNT           9
  99. #define SAVECOUNT        10
  100. #define SET_FUNC_TEXT    11
  101. #define CREATE_ENTITY    12
  102. #define GET_TEXT_VAL     13
  103. #define READ_TXT_FILE    14
  104. #define ADD_POLYLN_PT    15
  105. #define ERASE_INV        16
  106. #define GET_DIM_VAL      17
  107. #define PRINT_DIM_VAL    18
  108. #define CLICK_ENTITY     19
  109. #define EX_CHANGE_ENTITY 20
  110. #define BLINK            21
  111. #define ENTITY_LOOP      22
  112. #define DRAW_ENTITIES    23
  113. #define STRING_INPUT     24
  114. #define SELECT_INIT      25
  115. #define SELECT_LOOP      26
  116. #define INSERT_MAC       27
  117.  
  118. /***********************************************************************/
  119. /* The functions of the MegaCAD interface.                             */
  120. /***********************************************************************/
  121.  
  122. short GetPntInv(          // Get point and draw something with mouse move
  123.         double    *pkt,   // point to be filled in
  124.         short     setinc, // incremental point to be set ?
  125.         tCallBack func,   // callback function
  126.         void      *para)  // data pointer for callback function
  127. {
  128.     t_GetPntInv params;
  129.  
  130.     params.pkt    = pkt   ;
  131.     params.setinc = setinc;
  132.     params.func   = func  ;
  133.     params.para   = para  ;
  134.  
  135.     CallMegaCAD(¶ms,GET_PNT_INV);
  136.     return((short)params.retval);
  137. }
  138.  
  139. /***********************************************************************/
  140.  
  141. void DrawInv(             // draw and save a temporary object
  142.         ushort type,      // type of entity to be drawn
  143.         void   *ptr,      // data of entity
  144.         ushort lmode,     // line attributes (see LMODE)
  145.         ushort atype)     // type to get attributes from
  146. {
  147.     t_DrawInv params;
  148.  
  149.     params.type  = type ;
  150.     params.ptr   = ptr  ;
  151.     params.lmode = lmode;
  152.     params.atype = atype;
  153.  
  154.     CallMegaCAD(¶ms,DRAW_INV);
  155. }
  156.  
  157. /***********************************************************************/
  158.  
  159. short DlgInput(           // input some values by dialog
  160.         ushort   num,     // number of fields (1 - 10)
  161.         char     *title,  // title string
  162.         t_dlgdta *dta)    // array of field descriptors
  163. {
  164.     t_DlgInput params;
  165.  
  166.     params.num   = num  ;
  167.     params.title = title;
  168.     params.dta   = dta  ;
  169.  
  170.     CallMegaCAD(¶ms,DLG_INPUT);
  171.     return((short)params.retval);
  172. }
  173.  
  174. /***********************************************************************/
  175.  
  176. short GetFilename(        // let the user select a filename
  177.         char *title,      // title string
  178.         char *fname)      // filename; must be initialized with path
  179. {
  180.     t_GetFilename params;
  181.  
  182.     params.title = title;
  183.     params.fname = fname;
  184.  
  185.     CallMegaCAD(¶ms,GET_FILENAME);
  186.     return((short)params.retval);
  187. }
  188.  
  189. /***********************************************************************/
  190.  
  191. void StoreMultiple(       // store an entity (maybe multiple)
  192.         double *data,     // entity data
  193.         ushort type)      // entity type (may be or'ed with DO_SAVCNT)
  194. {
  195.     t_StoreMultiple params;
  196.  
  197.     params.data = data;
  198.     params.type = type;
  199.  
  200.     CallMegaCAD(¶ms,STORE_MULTIPLE);
  201. }
  202.  
  203. /***********************************************************************/
  204.  
  205. void MegaCMD(             // call MegaCAD command
  206.         char *cmd)        // command string (+ arguments)
  207. {
  208.     t_MegaCMD params;
  209.  
  210.     params.cmd = cmd;
  211.  
  212.     CallMegaCAD(¶ms,MEGA_CMD);
  213. }
  214.  
  215. /***********************************************************************/
  216.  
  217. short Message(            // message box
  218.         char  *str1,      // 1st line of text
  219.         char  *str2,      // 2nd line of text
  220.         char  *but1,      // 1st button (may be NULL)
  221.         char  *but2,      // 2nd button (may be NULL)
  222.         char  *but3,      // 3rd button
  223.         short defbut)     // number of default button (1-3)
  224. {
  225.     t_Message params;
  226.  
  227.     params.str1   = str1  ;
  228.     params.str2   = str2  ;
  229.     params.but1   = but1  ;
  230.     params.but2   = but2  ;
  231.     params.but3   = but3  ;
  232.     params.defbut = defbut;
  233.  
  234.     CallMegaCAD(¶ms,MESSAGE);
  235.     return((short)params.retval);
  236. }
  237.  
  238. /***********************************************************************/
  239.  
  240. void MouseHelp(           // help text for mouse buttons
  241.         char   *str1,     // help text for left mouse button
  242.         char   *str2,     // help text for right mouse button
  243.         ushort inv)       // colour (beep) for 1st text (see HLP_INV)
  244. {
  245.     t_MouseHelp params;
  246.  
  247.     params.str1 = str1;
  248.     params.str2 = str2;
  249.     params.inv  = inv ;
  250.  
  251.     CallMegaCAD(¶ms,MOUSE_HELP);
  252. }
  253.  
  254. /***********************************************************************/
  255.  
  256. short GetPnt(             // Get point
  257.         double *pkt,      // point to be filled in
  258.         short  setinc)    // incremental point to be set ?
  259. {
  260.     t_GetPnt params;
  261.  
  262.     params.pkt    = pkt   ;
  263.     params.setinc = setinc;
  264.  
  265.     CallMegaCAD(¶ms,GET_PNT);
  266.     return((short)params.retval);
  267. }
  268.  
  269. /***********************************************************************/
  270.  
  271. void savecount(           // End of operation
  272.         void)             // must be called after creation of entities
  273. {
  274.     t_savecount params;
  275.  
  276.     CallMegaCAD(¶ms,SAVECOUNT);
  277. }
  278.  
  279. /***********************************************************************/
  280.  
  281. void SetFuncText(         // set name of current function
  282.         char *text)       // function text
  283. {
  284.     t_SetFuncText params;
  285.  
  286.     params.text = text;
  287.  
  288.     CallMegaCAD(¶ms,SET_FUNC_TEXT);
  289. }
  290.  
  291. /***********************************************************************/
  292.  
  293. ulong CreateEntity(       // store an entity (not multiple), returns ID
  294.         ushort    type,   // entity type
  295.         t_attribs *attr,  // entity attributes (may be NULL)
  296.         void      *data)  // entity data
  297. {
  298.     t_CreateEntity params;
  299.  
  300.     params.type = type;
  301.     params.attr = attr;
  302.     params.data = data;
  303.  
  304.     CallMegaCAD(¶ms,CREATE_ENTITY);
  305.     return((ulong)params.retval);
  306. }
  307.  
  308. /***********************************************************************/
  309.  
  310. void GetTextVal(          // retrieve text attributes
  311.         ushort type,      // line or block
  312.         ushort init,      // initialize (or just calculate box)
  313.         t_text *txt)      // text data
  314. {
  315.     t_GetTextVal params;
  316.  
  317.     params.type = type;
  318.     params.init = init;
  319.     params.txt  = txt ;
  320.  
  321.     CallMegaCAD(¶ms,GET_TEXT_VAL);
  322. }
  323.  
  324. /***********************************************************************/
  325.  
  326. ushort ReadTxtFile(       // read in a text file
  327.         char *fname,      // filename
  328.         char *buf,        // buffer to be filled in
  329.         uint bufsiz)      // size of buffer
  330. {
  331.     t_ReadTxtFile params;
  332.  
  333.     params.fname  = fname ;
  334.     params.buf    = buf   ;
  335.     params.bufsiz = bufsiz;
  336.  
  337.     CallMegaCAD(¶ms,READ_TXT_FILE);
  338.     return((ushort)params.retval);
  339. }
  340.  
  341. /***********************************************************************/
  342.  
  343. ushort AddPolylnPt(       // add a polyline point
  344.         t_polyln *polyln, // polyline structure
  345.         double   *mpd,    // may be NULL
  346.         double   px,      // x-coordinate of point
  347.         double   py)      // y-coordinate of point
  348. {
  349.     t_AddPolylnPt params;
  350.  
  351.     params.polyln = polyln;
  352.     params.mpd    = mpd   ;
  353.     params.px     = px    ;
  354.     params.py     = py    ;
  355.  
  356.     CallMegaCAD(¶ms,ADD_POLYLN_PT);
  357.     return((ushort)params.retval);
  358. }
  359.  
  360. /***********************************************************************/
  361.  
  362. void EraseInv(            // delete temporary objects
  363.         void)
  364. {
  365.     t_EraseInv params;
  366.  
  367.     CallMegaCAD(¶ms,ERASE_INV);
  368. }
  369.  
  370. /***********************************************************************/
  371.  
  372. void GetDimVal(           // retrieve dimension attributes
  373.         ushort      type, // type of dimension
  374.         ushort      init, // initialize (or just calculate box)
  375.         t_dimension *dim) // dimension data
  376. {
  377.     t_GetDimVal params;
  378.  
  379.     params.type = type;
  380.     params.init = init;
  381.     params.dim  = dim ;
  382.  
  383.     CallMegaCAD(¶ms,GET_DIM_VAL);
  384. }
  385.  
  386. /***********************************************************************/
  387.  
  388. void PrintDimVal(         // print dimension text
  389.         double value,     // measured value
  390.         char   *str,      // string buffer to fill
  391.         char   *tol1,     // tolerance string 1
  392.         char   *tol2)     // tolerance string 2
  393. {
  394.     t_PrintDimVal params;
  395.  
  396.     params.value = value;
  397.     params.str   = str  ;
  398.     params.tol1  = tol1 ;
  399.     params.tol2  = tol2 ;
  400.  
  401.     CallMegaCAD(¶ms,PRINT_DIM_VAL);
  402. }
  403.  
  404. /***********************************************************************/
  405.  
  406. short ClickEntity(        // let the user click a single entity
  407.         ulong    filter,  // allowed entity types
  408.         double   *pnt,    // point where entity was clicked
  409.         t_entity *ent,    // entity data to be filled in
  410.         void     *edta,   // data ptr of variable length entities
  411.         ushort   esiz)    // size of data buffer
  412. {
  413.     t_ClickEntity params;
  414.  
  415.     params.filter = filter;
  416.     params.pnt    = pnt   ;
  417.     params.ent    = ent   ;
  418.     params.edta   = edta  ;
  419.     params.esiz   = esiz  ;
  420.  
  421.     CallMegaCAD(¶ms,CLICK_ENTITY);
  422.     return((short)params.retval);
  423. }
  424.  
  425. /***********************************************************************/
  426.  
  427. ulong ExChangeEntity(     // exchange an entity, returns new ID
  428.         t_entity *ent)    // new entity data, old id
  429. {
  430.     t_ExChangeEntity params;
  431.  
  432.     params.ent = ent;
  433.  
  434.     CallMegaCAD(¶ms,EX_CHANGE_ENTITY);
  435.     return((ulong)params.retval);
  436. }
  437.  
  438. /***********************************************************************/
  439.  
  440. short Blink(              // draw something blinking
  441.         tCallBack func,   // callback function
  442.         void      *para)  // data pointer for callback function
  443. {
  444.     t_Blink params;
  445.  
  446.     params.func = func;
  447.     params.para = para;
  448.  
  449.     CallMegaCAD(¶ms,BLINK);
  450.     return((short)params.retval);
  451. }
  452.  
  453. /***********************************************************************/
  454.  
  455. void EntityLoop(          // loop through all entities
  456.         ulong     filter, // allowed entity types
  457.         tCallBack func,   // callback function
  458.         void      *para,  // data pointer for callback function
  459.         void      *edta,  // data ptr of variable length entities
  460.         ushort    esiz)   // size of data buffer
  461. {
  462.     t_EntityLoop params;
  463.  
  464.     params.filter = filter;
  465.     params.func   = func  ;
  466.     params.para   = para  ;
  467.     params.edta   = edta  ;
  468.     params.esiz   = esiz  ;
  469.  
  470.     CallMegaCAD(¶ms,ENTITY_LOOP);
  471. }
  472.  
  473. /***********************************************************************/
  474.  
  475. void DrawEntities(        // draw array of entity-id's
  476.         ulong  *pid,      // array of entity-id's
  477.         ushort num)       // number of id's
  478. {
  479.     t_DrawEntities params;
  480.  
  481.     params.pid = pid;
  482.     params.num = num;
  483.  
  484.     CallMegaCAD(¶ms,DRAW_ENTITIES);
  485. }
  486.  
  487. /***********************************************************************/
  488.  
  489. short StringInput(        // input a line of text
  490.         char   *title,    // title string
  491.         char   *buf,      // string buffer to be filled in
  492.         ushort buflen)    // size of buffer
  493. {
  494.     t_StringInput params;
  495.  
  496.     params.title  = title ;
  497.     params.buf    = buf   ;
  498.     params.buflen = buflen;
  499.  
  500.     CallMegaCAD(¶ms,STRING_INPUT);
  501.     return((short)params.retval);
  502. }
  503.  
  504. /***********************************************************************/
  505.  
  506. void SelectInit(          // set select filter
  507.         ulong filter)     // allowed entity types
  508. {
  509.     t_SelectInit params;
  510.  
  511.     params.filter = filter;
  512.  
  513.     CallMegaCAD(¶ms,SELECT_INIT);
  514. }
  515.  
  516. /***********************************************************************/
  517.  
  518. void SelectLoop(          // select entities
  519.         tCallBack func,   // callback function
  520.         void      *para,  // data pointer for callback function
  521.         void      *edta,  // data ptr of variable length entities
  522.         ushort    esiz)   // size of data buffer
  523. {
  524.     t_SelectLoop params;
  525.  
  526.     params.func = func;
  527.     params.para = para;
  528.     params.edta = edta;
  529.     params.esiz = esiz;
  530.  
  531.     CallMegaCAD(¶ms,SELECT_LOOP);
  532. }
  533.  
  534. /***********************************************************************/
  535.  
  536. ushort InsertMac(             // insert macro-file
  537.         char        *fname,   // macro filename
  538.         tCallBack   func,     // callback function
  539.         void        *para,    // data pointer for callback function
  540.         void        *edta,    // data ptr of variable length entities
  541.         ushort      esiz)     // size of data buffer
  542. {
  543.     t_InsertMac params;
  544.  
  545.     params.fname = fname;
  546.     params.func  = func;
  547.     params.para  = para;
  548.     params.edta  = edta;
  549.     params.esiz  = esiz;
  550.  
  551.     CallMegaCAD(¶ms,INSERT_MAC);
  552.     return((ushort)params.retval);
  553. }
  554.  
  555. /***********************************************************************/
  556. #if defined ( _WIN32 )
  557. /***********************************************************************/
  558.  
  559. int _matherr(
  560.         struct _exception *err )
  561. {
  562.     err->retval = 0.0;
  563.     return(1);
  564. }
  565.  
  566. /***********************************************************************/
  567. #endif
  568. /***********************************************************************/
  569.