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 >
Wrap
C/C++ Source or Header
|
1996-02-23
|
3KB
|
176 lines
/*
* オブジェクト制御制御
*
* 1994.8.13
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "lib.h"
#include "alloc.h"
#include "poly.h"
#include "color.h"
#include "reader.h"
ObjectStruct *ObjData ;
int ObjCurrent ;
int ObjSize ;
int ObjLast ;
/*
* オブジェクトの初期化
*/
void ObjInit( size )
int size ;
{
int i ;
ObjData = MemoryAlloc( size * sizeof( ObjectStruct ) );
ObjSize = size ;
ObjLast = 0 ;
ObjCurrent = 0 ;
for( i = 0 ; i < size ; i++ )
ObjData[i].flag = FALSE ;
#if 0
ObjAppend( "default" );
strcpy( ObjData[0].fname, "default.suf" );
#endif
}
void ObjExit()
{
MemoryFree( ObjData );
}
/* 追加 */
int ObjAppend( name )
char *name ;
{
int i ;
for( i = 0 ; i < ObjSize ; i++ )
{
if ( ObjData[i].flag == FALSE )
{
ObjData[i].flag = TRUE ;
ObjData[i].edit = FALSE ;
strncpy( ObjData[i].name, name, OBJ_NAME_LEN );
ObjData[i].name[OBJ_NAME_LEN] = '\0' ;
ObjData[i].fname[0] = '\0' ;
if ( ObjLast < i )
ObjLast = i ;
return i ;
}
}
MessageError( "オブジェクトバッファがオーバーフローしました" );
return -1 ;
}
/* 検索 */
int ObjSearch( name )
char *name ;
{
int i ;
for( i = 0 ; i <= ObjLast ; i++ )
{
if ( ObjData[i].flag && strncmp( ObjData[i].name, name, OBJ_NAME_LEN ) == 0 )
return i ;
}
return -1 ;
}
/*
* 検索&追加
*/
int ObjSearchOrAppend( name )
char *name ;
{
int n ;
n = ObjSearch( name );
if ( n == -1 )
return ObjAppend( name );
else
return n ;
}
/*
* セレクトされているオブジェクトを変更する
*/
void ObjChange( objno )
int objno ;
{
Polygon *poly ;
assert( objno <= ObjLast );
ObjData[objno].edit = TRUE ;
poly = PolyTop();
while( poly != NULL )
{
if ( poly->select )
{
ObjData[poly->obj].edit = TRUE ;
poly->obj = objno ;
}
poly = PolyNext( poly );
}
}
/* オブジェクトの有効チェック */
void ObjValid()
{
int i ;
Polygon *poly ;
for( i = 0 ; i <= ObjLast ; i++ )
ObjData[i].flag = FALSE ;
poly = PolyTop();
while( poly != NULL )
{
ObjData[poly->obj].flag = TRUE ;
poly = PolyNext( poly );
}
}
int ObjDelete( int objno )
{
int i;
Polygon *poly ;
poly = PolyTop();
while( poly != NULL )
{
if ( poly->obj == objno ) {
return FALSE;
}
poly = PolyNext( poly );
}
poly = PolyTop();
while( poly != NULL )
{
if ( poly->obj > objno ) {
poly->obj--;
}
poly = PolyNext( poly );
}
for (i = objno; i < ObjLast; ++i) {
ObjData[i] = ObjData[i+1];
}
ObjData[ObjLast].flag = FALSE;
ObjLast--;
if (ObjLast >= 0 && ObjCurrent > ObjLast) {
ObjCurrent = ObjLast;
}
return TRUE;
}