home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / POLYEDIT.LZH / MODEL / OBJLIB.C < prev    next >
C/C++ Source or Header  |  1996-02-23  |  6KB  |  256 lines

  1. /*
  2.  *    オブジェクトデータ制御
  3.  *
  4.  *        Copyright T.Kobayashi    1994.8.13
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <assert.h>
  11.  
  12. #include "matrix.h"
  13. #include "vector.h"
  14. #include "matclass.h"
  15. #include "strclass.h"
  16. #include "ml.h"
  17.  
  18. #include "poly.h"
  19. #include "menu.h"
  20.  
  21. static    int        StringClassID ;
  22.  
  23. static    int        FuncObjCurrent( int, int, DataStruct* );
  24. static    int        FuncObjects( int, int, DataStruct* );
  25. static    int        FuncObjAppend( int, int, DataStruct* );
  26. static    int        FuncObjSearch( int, int, DataStruct* );
  27. static    int        FuncObjChange( int, int, DataStruct* );
  28. static    int        FuncObjName( int, int, DataStruct* );
  29. static    int        FuncObjFile( int, int, DataStruct* );
  30. static    int        FuncObjEdit( int, int, DataStruct* );
  31. static    int        FuncObjDelete( int, int, DataStruct* );
  32. static    int        FuncObjPolygons( int, int, DataStruct* );
  33.  
  34. void    ObjLibInit()
  35. {
  36.     StringClassID = ClassName( "String" );
  37.  
  38.     NewFunction( 0,                "ObjCurrent", FuncObjCurrent );
  39.     NewFunction( 0,                "Objects", FuncObjects );
  40.     NewFunction( StringClassID,    "ObjAppend", FuncObjAppend );
  41.     NewFunction( StringClassID,    "ObjSearch", FuncObjSearch );
  42.     NewFunction( 0,                "ObjChange", FuncObjChange );
  43.     NewFunction( 0,                "ObjName", FuncObjName );
  44.     NewFunction( 0,                "ObjFile", FuncObjFile );
  45.     NewFunction( 0,                "ObjEdit", FuncObjEdit );
  46.     NewFunction( 0,                "ObjDelete", FuncObjDelete );
  47.     NewFunction( 0,                "ObjPolygons", FuncObjPolygons );
  48. }
  49.  
  50. /*    カレントオブジェクトを得る    */
  51. static    int        FuncObjCurrent( ident, args, buf )
  52. int        ident ;
  53. int        args ;
  54. DataStruct    *buf ;
  55. {
  56.     if (args == 0) {
  57.         StackPushInt( ObjCurrent );
  58.     } else {
  59.         int oldcurrent;
  60.         ArgCheck( "ObjCurrent", args, buf, TYPE_INT, TYPE_NOASN );
  61.         oldcurrent = ObjCurrent;
  62.         if (buf[0].id.i >= 0 && buf[0].id.i <= ObjLast) {
  63.             ObjCurrent = buf[0].id.i;
  64.             if (oldcurrent != ObjCurrent) {
  65.                 DrawObjSelect();
  66.             }
  67.             StackPushInt( oldcurrent );
  68.         } else {
  69.             StackPushInt( -1 );
  70.         }
  71.     }
  72.     return RETURN_RETURN ;
  73. }
  74.  
  75. /*    オブジェクト数を得る    */
  76. static    int        FuncObjects( ident, args, buf )
  77. int        ident ;
  78. int        args ;
  79. DataStruct    *buf ;
  80. {
  81.     StackPushInt( ObjLast + 1 );
  82.     return RETURN_RETURN ;
  83. }
  84.  
  85. /*    オブジェクトの追加    */
  86. static    int        FuncObjAppend( ident, args, buf )
  87. int        ident ;
  88. int        args ;
  89. DataStruct    *buf ;
  90. {
  91.     int        n ;
  92.  
  93.     ArgCheck( "ObjAppend", args, buf, TYPE_OBJECT, TYPE_OBJECT, TYPE_NOASN );
  94.  
  95.     n = ObjAppend( ((StringClass*)buf[0].od.ptr)->str );
  96.     strcpy( ObjData[n].fname, ((StringClass*)buf[1].od.ptr)->str );
  97.     StackPushInt( n );
  98.     return RETURN_RETURN ;
  99. }
  100.  
  101. /*    検索    */
  102. static    int        FuncObjSearch( ident, args, buf )
  103. int        ident ;
  104. int        args ;
  105. DataStruct    *buf ;
  106. {
  107.     StackPushInt( ObjSearch( ((StringClass*)buf[0].od.ptr)->str ) );
  108.     return RETURN_RETURN ;
  109. }
  110.  
  111. /*    セレクトされているオブジェクトを変更する    */
  112. static    int        FuncObjChange( ident, args, buf )
  113. int        ident ;
  114. int        args ;
  115. DataStruct    *buf ;
  116. {
  117.     ArgCheck( "ObjChange", args, buf, TYPE_INT, TYPE_NOASN );
  118.     ObjChange( buf[0].id.i );
  119.     return RETURN_VOID ;
  120. }
  121.  
  122. /*    オブジェクト名を得る    */
  123. static    int        FuncObjName( ident, args, buf )
  124. int        ident ;
  125. int        args ;
  126. DataStruct    *buf ;
  127. {
  128.     int        n ;
  129.     char    *name ;
  130.  
  131.     if ( args == 1 )
  132.     {
  133.         ArgCheck( "ObjFile", args, buf, TYPE_INT, TYPE_NOASN );
  134.         n = buf[0].id.i ;
  135.     }
  136.     else
  137.     {
  138.         ArgCheck( "ObjFile", args, buf, TYPE_INT, TYPE_OBJECT, TYPE_NOASN );
  139.         n = buf[0].id.i ;
  140.         if ( ObjectCheck( &buf[1], StringClassID ) == FALSE )
  141.             ExecError( "%d番目の引数の型不正です(ObjName)", 2 );
  142.         name = ((StringClass*)buf[1].od.ptr)->str ;
  143.         if ( strcmp( name, "" ) == 0 )
  144.             ObjData[n].flag = FALSE ;
  145.         strcpy( ObjData[n].name, name );
  146.     }
  147.  
  148.     buf = StackAlloc( 1 );
  149.     if ( ObjData[n].flag )
  150.         StringToObject( buf, ObjData[n].name );
  151.     else
  152.         StringToObject( buf, "" );
  153.     return RETURN_RETURN ;
  154. }
  155.  
  156. /*    オブジェクトのファイル名を得る    */
  157. static    int        FuncObjFile( ident, args, buf )
  158. int        ident ;
  159. int        args ;
  160. DataStruct    *buf ;
  161. {
  162.     int        n ;
  163.  
  164.     if ( args == 1 )
  165.     {
  166.         ArgCheck( "ObjFile", args, buf, TYPE_INT, TYPE_NOASN );
  167.         n = buf[0].id.i ;
  168.     }
  169.     else
  170.     {
  171.         ArgCheck( "ObjFile", args, buf, TYPE_INT, TYPE_OBJECT, TYPE_NOASN );
  172.         n = buf[0].id.i ;
  173.         if ( ObjectCheck( &buf[1], StringClassID ) == FALSE )
  174.             ExecError( "%d番目の引数の型不正です(ObjFile)", 2 );
  175.         strcpy( ObjData[n].fname, ((StringClass*)buf[1].od.ptr)->str );
  176.     }
  177.  
  178.     buf = StackAlloc( 1 );
  179.     StringToObject( buf, ObjData[n].fname );
  180.     return RETURN_RETURN ;
  181. }
  182.  
  183. /*    エディットフラグを得る    */
  184. static    int        FuncObjEdit( ident, args, buf )
  185. int        ident ;
  186. int        args ;
  187. DataStruct    *buf ;
  188. {
  189.     int        n ;
  190.  
  191.     if ( args == 1 )
  192.     {
  193.         ArgCheck( "ObjEdit", args, buf, TYPE_INT, TYPE_NOASN );
  194.         n = buf[0].id.i ;
  195.     }
  196.     else
  197.     {
  198.         ArgCheck( "ObjEdit", args, buf, TYPE_INT, TYPE_INT|TYPE_BOOLEAN, TYPE_NOASN );
  199.         n = buf[0].id.i ;
  200.         ObjData[n].edit = buf[1].id.i ;
  201.     }
  202.  
  203.     StackPushInt( ObjData[n].edit );
  204.     return RETURN_RETURN ;
  205. }
  206.  
  207. /*    オブジェクトを削除する    */
  208. static    int        FuncObjDelete( ident, args, buf )
  209. int        ident ;
  210. int        args ;
  211. DataStruct    *buf ;
  212. {
  213.     ArgCheck( "ObjDelete", args, buf, TYPE_INT, TYPE_NOASN );
  214.     if (buf[0].id.i >= 0 && buf[0].id.i <= ObjLast) {
  215.         StackPushBoolean( ObjDelete( buf[0].id.i ) );
  216.     } else {
  217.         StackPushBoolean( FALSE );
  218.     }
  219.     return RETURN_RETURN ;
  220. }
  221.  
  222.  
  223. /*    ポリゴン数を数える    */
  224. static    int        FuncObjPolygons( ident, args, buf )
  225. int        ident ;
  226. int        args ;
  227. DataStruct    *buf ;
  228. {
  229.     int n = 0;
  230.     Polygon    *poly ;
  231.     poly = PolyTop();
  232.     if ( args >= 1 )
  233.     {
  234.         int objno;
  235.         ArgCheck( "ObjPolygons", args, buf, TYPE_INT, TYPE_NOASN );
  236.         objno = buf[0].id.i;
  237.         while( poly != NULL )
  238.         {
  239.             if (poly->obj == objno) {
  240.                 n++;
  241.             }
  242.             poly = PolyNext( poly );
  243.         }
  244.     } else {
  245.         while( poly != NULL )
  246.         {
  247.             n++;
  248.             poly = PolyNext( poly );
  249.         }
  250.     }
  251.     StackPushInt( n );
  252.     return RETURN_RETURN ;
  253. }
  254.  
  255.  
  256.