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

  1. /*
  2.  *        オブジェクト制御制御
  3.  *
  4.  *        1994.8.13
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <assert.h>
  10. #include <string.h>
  11.  
  12. #include "lib.h"
  13. #include "alloc.h"
  14. #include "poly.h"
  15.  
  16. #include "color.h"
  17. #include "reader.h"
  18.  
  19. ObjectStruct *ObjData ;
  20. int            ObjCurrent ;
  21. int            ObjSize ;
  22. int            ObjLast ;
  23.  
  24. /*
  25.  *    オブジェクトの初期化
  26.  */
  27. void    ObjInit( size )
  28. int        size ;
  29. {
  30.     int        i ;
  31.  
  32.     ObjData = MemoryAlloc( size * sizeof( ObjectStruct ) );
  33.     ObjSize = size ;
  34.     ObjLast = 0 ;
  35.     ObjCurrent = 0 ;
  36.  
  37.     for( i = 0 ; i < size ; i++ )
  38.         ObjData[i].flag = FALSE ;
  39.  
  40. #if    0
  41.     ObjAppend( "default" );
  42.     strcpy( ObjData[0].fname, "default.suf" );
  43. #endif
  44. }
  45.  
  46. void    ObjExit()
  47. {
  48.     MemoryFree( ObjData );
  49. }
  50.  
  51.  
  52. /*    追加    */
  53. int        ObjAppend( name )
  54. char    *name ;
  55. {
  56.     int        i ;
  57.  
  58.     for( i = 0 ; i < ObjSize ; i++ )
  59.     {
  60.         if ( ObjData[i].flag == FALSE )
  61.         {
  62.             ObjData[i].flag = TRUE ;
  63.             ObjData[i].edit = FALSE ;
  64.             strncpy( ObjData[i].name, name, OBJ_NAME_LEN );
  65.             ObjData[i].name[OBJ_NAME_LEN] = '\0' ;
  66.             ObjData[i].fname[0] = '\0' ;
  67.             if ( ObjLast < i )
  68.                 ObjLast = i ;
  69.             return i ;
  70.         }
  71.     }
  72.     MessageError( "オブジェクトバッファがオーバーフローしました" );
  73.     return -1 ;
  74. }
  75.  
  76. /*    検索    */
  77. int        ObjSearch( name )
  78. char    *name ;
  79. {
  80.     int        i ;
  81.  
  82.     for( i = 0 ; i <= ObjLast ; i++ )
  83.     {
  84.         if ( ObjData[i].flag && strncmp( ObjData[i].name, name, OBJ_NAME_LEN ) == 0 )
  85.             return i ;
  86.     }
  87.     return -1 ;
  88. }
  89.  
  90. /*
  91.  *    検索&追加
  92.  */
  93. int        ObjSearchOrAppend( name )
  94. char    *name ;
  95. {
  96.     int        n ;
  97.  
  98.     n = ObjSearch( name );
  99.     if ( n == -1 )
  100.         return ObjAppend( name );
  101.     else
  102.         return n ;
  103. }
  104.  
  105. /*
  106.  *    セレクトされているオブジェクトを変更する
  107.  */
  108. void    ObjChange( objno )
  109. int        objno ;
  110. {
  111.     Polygon    *poly ;
  112.  
  113.     assert( objno <= ObjLast );
  114.     ObjData[objno].edit = TRUE ;
  115.  
  116.     poly = PolyTop();
  117.     while( poly != NULL )
  118.     {
  119.         if ( poly->select )
  120.         {
  121.             ObjData[poly->obj].edit = TRUE ;
  122.             poly->obj = objno ;
  123.         }
  124.         poly = PolyNext( poly );
  125.     }
  126. }
  127.  
  128. /*    オブジェクトの有効チェック    */
  129. void    ObjValid()
  130. {
  131.     int        i ;
  132.     Polygon    *poly ;
  133.  
  134.     for( i = 0 ; i <= ObjLast ; i++ )
  135.         ObjData[i].flag = FALSE ;
  136.  
  137.     poly = PolyTop();
  138.     while( poly != NULL )
  139.     {
  140.         ObjData[poly->obj].flag = TRUE ;
  141.         poly = PolyNext( poly );
  142.     }
  143. }
  144.  
  145. int    ObjDelete( int objno )
  146. {
  147.     int i;
  148.     Polygon    *poly ;
  149.  
  150.     poly = PolyTop();
  151.     while( poly != NULL )
  152.     {
  153.         if ( poly->obj == objno ) {
  154.             return FALSE;
  155.         }
  156.         poly = PolyNext( poly );
  157.     }
  158.     poly = PolyTop();
  159.     while( poly != NULL )
  160.     {
  161.         if ( poly->obj > objno ) {
  162.             poly->obj--;
  163.         }
  164.         poly = PolyNext( poly );
  165.     }
  166.     for (i = objno; i < ObjLast; ++i) {
  167.         ObjData[i] = ObjData[i+1];
  168.     }
  169.     ObjData[ObjLast].flag = FALSE;
  170.     ObjLast--;
  171.     if (ObjLast >= 0 && ObjCurrent > ObjLast) {
  172.         ObjCurrent = ObjLast;
  173.     }
  174.     return TRUE;
  175. }
  176.