home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
VPR_DATA
/
DOGA
/
SOURCES
/
POLYEDIT.LZH
/
MODEL
/
ATRLIB.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-04-15
|
15KB
|
507 lines
/*
* アトリビュートデータ制御
*
* Copyright T.Kobayashi 1994.7.9
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "matrix.h"
#include "vector.h"
#include "reader.h"
#include "matclass.h"
#include "strclass.h"
#include "ml.h"
#include "poly.h"
#include "menu.h"
static int FuncAttrCurrent( int, int, DataStruct* );
static int FuncAttrAppend( int, int, DataStruct* );
static int FuncAttrSearch( int, int, DataStruct* );
static int FuncAttrChange( int, int, DataStruct* );
static int FuncAttrs( int, int, DataStruct* );
static int FuncAttrName( int, int, DataStruct* );
static int FuncAttrFile( int, int, DataStruct* );
static int FuncAttrCode( int, int, DataStruct* );
static int FuncAttrReadFile( int, int, DataStruct* );
static int FuncAttrDelete( int, int, DataStruct* );
static int FuncAttrPolygons( int, int, DataStruct* );
static int FuncAttrWriteFile( int, int, DataStruct* );
static int FuncAttrParameter( int, int, DataStruct* );
static int FuncAttrMapType( int, int, DataStruct* );
static int FuncAttrMapFile( int, int, DataStruct* );
static int FuncAttrMap( int, int, DataStruct* );
static int StringClassID ;
static int ColID, AmbID, DifID, SpcID, SizeID, RefID, TraID, RfrID, AttID;
static int GetWindID, GetViewID, GetSizeID;
static int SetWindID, SetViewID, SetSizeID;
void AttrLibInit()
{
StringClassID = ClassName( "String" );
NewFunction( 0, "AttrCurrent", FuncAttrCurrent );
NewFunction( 0, "Attrs", FuncAttrs );
NewFunction( StringClassID, "AttrAppend", FuncAttrAppend );
NewFunction( StringClassID, "AttrSearch", FuncAttrSearch );
NewFunction( 0, "AttrChange", FuncAttrChange );
NewFunction( 0, "AttrName", FuncAttrName );
NewFunction( 0, "AttrFile", FuncAttrFile );
NewFunction( 0, "AttrCode", FuncAttrCode );
NewFunction( StringClassID, "AttrReadFile", FuncAttrReadFile );
NewFunction( 0, "AttrDelete", FuncAttrDelete );
NewFunction( 0, "AttrPolygons", FuncAttrPolygons );
NewFunction( StringClassID, "AttrWriteFile", FuncAttrWriteFile );
ColID = NewFunction( 0, "AttrCol", FuncAttrParameter );
AmbID = NewFunction( 0, "AttrAmb", FuncAttrParameter );
DifID = NewFunction( 0, "AttrDif", FuncAttrParameter );
SpcID = NewFunction( 0, "AttrSpc", FuncAttrParameter );
SizeID = NewFunction( 0, "AttrSize", FuncAttrParameter );
RefID = NewFunction( 0, "AttrRef", FuncAttrParameter );
TraID = NewFunction( 0, "AttrTra", FuncAttrParameter );
RfrID = NewFunction( 0, "AttrRfr", FuncAttrParameter );
AttID = NewFunction( 0, "AttrAtt", FuncAttrParameter );
NewFunction( 0, "AttrMap", FuncAttrMapType );
NewFunction( 0, "AttrMapFile", FuncAttrMapFile);
GetWindID = NewFunction( 0, "GetAttrMapWind", FuncAttrMap);
GetViewID = NewFunction( 0, "GetAttrMapView", FuncAttrMap);
GetSizeID = NewFunction( 0, "GetAttrMapSize", FuncAttrMap);
SetWindID = NewFunction( 0, "SetAttrMapWind", FuncAttrMap);
SetViewID = NewFunction( 0, "SetAttrMapView", FuncAttrMap);
SetSizeID = NewFunction( 0, "SetAttrMapSize", FuncAttrMap);
}
/* カレントアトリビュートを得る */
static int FuncAttrCurrent( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
if (args == 0) {
StackPushInt( AttrCurrent );
} else {
int oldcurrent;
ArgCheck( "AttrCurrent", args, buf, TYPE_INT, TYPE_NOASN );
oldcurrent = AttrCurrent;
if (buf[0].id.i >= 0 && buf[0].id.i <= AttrLast) {
AttrCurrent = buf[0].id.i;
if (oldcurrent != AttrCurrent) {
DrawAttrSelect();
}
StackPushInt( oldcurrent );
} else {
StackPushInt( -1 );
}
}
return RETURN_RETURN ;
}
/* アトリビュート数を得る */
static int FuncAttrs( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
StackPushInt( AttrLast + 1 );
return RETURN_RETURN ;
}
/* アトリビュートの追加 */
static int FuncAttrAppend( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int n ;
char *name = NULL;
if (args <= 2) {
ArgCheck( "AttrAppend", args, buf, TYPE_OBJECT, TYPE_INT, TYPE_NOASN );
} else {
ArgCheck( "AttrAppend", args, buf, TYPE_OBJECT, TYPE_INT, TYPE_OBJECT, TYPE_NOASN );
if (ObjectCheck(&buf[2], StringClassID) == FALSE) {
ExecError( "%d番目の引数の型不正です(AttrAppend)", 3 );
}
name = ((StringClass*)buf[2].od.ptr)->str ;
}
n = AttrAppend( ((StringClass*)buf[0].od.ptr)->str );
AttrData[n].code = buf[1].id.i ;
AttrData[n].col.r = (buf[1].id.i & 2) ? COLOR_UNIT : 0;
AttrData[n].col.g = (buf[1].id.i & 4) ? COLOR_UNIT : 0;
AttrData[n].col.b = (buf[1].id.i & 1) ? COLOR_UNIT : 0;
if (name != NULL) {
strcpy( AttrData[n].fname, name);
} else {
AttrData[n].fname[0] = '\0';
}
StackPushInt( n );
return RETURN_RETURN ;
}
/* アトリビュートの検索 */
static int FuncAttrSearch( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
StackPushInt( AttrSearch( ((StringClass*)buf[0].od.ptr)->str ) );
return RETURN_RETURN ;
}
/* セレクトされているアトリビュートを変更する */
static int FuncAttrChange( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
ArgCheck( "AttrChange", args, buf, TYPE_INT, TYPE_NOASN );
AttrChange( buf[0].id.i );
return RETURN_VOID ;
}
/* アトリビュート名を得る */
static int FuncAttrName( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int n ;
if ( args < 1 )
ExecError( "引数の数が不正です(AttrName)" );
if ( buf[0].type != TYPE_INT )
ExecError( "%d番目の引数の型不正です(AttrName)", 1 );
n = buf[0].id.i ;
if ( args >= 2 )
{
if ( buf[1].type != TYPE_OBJECT || ObjectCheck( &buf[1], StringClassID ) == FALSE )
ExecError( "%d番目の引数の型不正です(AttrName)", 2 );
strcpy( AttrData[n].name, ((StringClass*)buf[1].od.ptr)->str );
}
buf = StackAlloc( 1 );
StringToObject( buf, AttrData[n].name );
return RETURN_RETURN ;
}
/* アトリビュートのファイル名を得る */
static int FuncAttrFile( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int n ;
if ( args == 1 )
{
ArgCheck( "AttrFile", args, buf, TYPE_INT, TYPE_NOASN );
n = buf[0].id.i ;
if (n < 0 || n > AttrLast) {
return RETURN_VOID;
}
}
else
{
ArgCheck( "AttrFile", args, buf, TYPE_INT, TYPE_OBJECT, TYPE_NOASN );
n = buf[0].id.i ;
if ( ObjectCheck( &buf[1], StringClassID ) == FALSE )
ExecError( "%d番目の引数の型不正です(ObjFile)", 2 );
if (n < 0 || n > AttrLast) {
return RETURN_VOID;
}
strcpy( AttrData[n].fname, ((StringClass*)buf[1].od.ptr)->str );
}
buf = StackAlloc( 1 );
StringToObject( buf, AttrData[n].fname );
return RETURN_RETURN ;
}
/* アトリビュートのコードを得る */
static int FuncAttrCode( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int n ;
if ( args < 1 )
ExecError( "引数の数が不正です(AttrCode)" );
if ( buf[0].type != TYPE_INT )
ExecError( "%d番目の引数の型不正です(AttrCode)", 1 );
n = buf[0].id.i ;
if ( args >= 2 )
{
if ( buf[1].type != TYPE_INT )
ExecError( "%d番目の引数の型不正です(AttrCode)", 2 );
AttrData[n].code = buf[1].id.i ;
/*
AttrData[n].col.r = (buf[1].id.i & 2) ? COLOR_UNIT : 0;
AttrData[n].col.g = (buf[1].id.i & 4) ? COLOR_UNIT : 0;
AttrData[n].col.b = (buf[1].id.i & 1) ? COLOR_UNIT : 0;
*/
}
StackPushInt( AttrData[n].code );
return RETURN_RETURN ;
}
/* アトリビュートをファイルから読み込む */
static int FuncAttrReadFile( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int mode = FILE_APPEND;
if (args > 1) {
ArgCheck( "AttrReadFile", args, buf, TYPE_OBJECT, TYPE_INT|TYPE_BOOLEAN,TYPE_NOASN );
mode = buf[1].id.i;
} else {
ArgCheck( "AttrReadFile", args, buf, TYPE_OBJECT, TYPE_NOASN );
}
StackPushInt(AttrReadFile( ((StringClass*)buf[0].od.ptr)->str, mode ));
return RETURN_RETURN;
}
/* アトリビュートを削除する */
static int FuncAttrDelete( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
ArgCheck( "AttrDelete", args, buf, TYPE_INT, TYPE_NOASN );
StackPushBoolean( AttrDelete( buf[0].id.i ) );
return RETURN_RETURN ;
}
/* ポリゴン数を数える */
static int FuncAttrPolygons( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int n = 0;
Polygon *poly ;
poly = PolyTop();
if ( args >= 1 )
{
int atrno;
ArgCheck( "Polygons", args, buf, TYPE_INT, TYPE_NOASN );
atrno = buf[0].id.i;
while( poly != NULL )
{
if (poly->atr == atrno) {
n++;
}
poly = PolyNext( poly );
}
} else {
while( poly != NULL )
{
n++;
poly = PolyNext( poly );
}
}
StackPushInt( n );
return RETURN_RETURN ;
}
/* アトリビュートファイルを書き出す */
static int FuncAttrWriteFile( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int atrno, mode;
char *fname;
if ( args <= 2 )
{
ArgCheck( "AttrWriteFile", args, buf, TYPE_OBJECT, TYPE_INT, TYPE_NOASN );
mode = FILE_OVERWRITE ;
}
else
{
ArgCheck( "AttrWriteFile", args, buf, TYPE_OBJECT, TYPE_INT, TYPE_INT, TYPE_NOASN );
mode = buf[2].id.i ;
}
fname = ((StringClass*)buf[0].od.ptr)->str;
atrno = buf[1].id.i;
StackPushInt( AttrWriteFile( fname, atrno, mode ) );
return RETURN_RETURN ;
}
/* パラメータを設定する。 */
static int FuncAttrParameter( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int pos;
Color *c;
VectorClass *v = NULL;
if (args <= 1) {
ArgCheck( "AttrParameter", args, buf, TYPE_INT, TYPE_NOASN );
} else {
ArgCheck( "AttrParameter", args, buf, TYPE_INT, TYPE_OBJECT, TYPE_NOASN );
if (ObjectCheck(&buf[1], ClassName("Vector")) == FALSE) {
ExecError( "1番目の引数の型が不正です(AttrParameter)" );
}
v = (VectorClass*)buf[1].od.ptr;
}
pos = buf[0].id.i;
if (pos < 0 || pos > AttrLast) {
return RETURN_VOID;
}
if (ident == ColID) c = &AttrData[pos].col;
else if (ident == AmbID) c = &AttrData[pos].amb;
else if (ident == DifID) c = &AttrData[pos].dif;
else if (ident == SpcID) c = &AttrData[pos].spc;
else if (ident == SizeID) c = &AttrData[pos].size;
else if (ident == RefID) c = &AttrData[pos].ref;
else if (ident == TraID) c = &AttrData[pos].tra;
else if (ident == RfrID) c = &AttrData[pos].rfr;
else if (ident == AttID) c = &AttrData[pos].att;
else assert(("Unknown Identifier", FALSE));
if (args == 1) {
v = (VectorClass*)ObjectAlloc( sizeof( VectorClass ), VectorClassID );
v->vec.x = (double)c->r / (double)(1 << COLOR_SHIFT);
v->vec.y = (double)c->g / (double)(1 << COLOR_SHIFT);
v->vec.z = (double)c->b / (double)(1 << COLOR_SHIFT);
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)v ;
return RETURN_RETURN;
} else {
c->r = (int)(v->vec.x * (double)(1 << COLOR_SHIFT));
c->g = (int)(v->vec.y * (double)(1 << COLOR_SHIFT));
c->b = (int)(v->vec.z * (double)(1 << COLOR_SHIFT));
return RETURN_VOID;
}
}
/* マッピングを設定する */
static int FuncAttrMapType( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int pos;
if (args <= 1) {
ArgCheck( "AttrMap", args, buf, TYPE_INT, TYPE_NOASN );
pos = buf[0].id.i;
if (pos < 0 || pos > AttrLast) {
return RETURN_VOID;
}
StackPushBoolean(AttrData[pos].maptype == MAP_NO ? FALSE : TRUE);
return RETURN_RETURN;
} else {
ArgCheck( "AttrMap", args, buf, TYPE_INT, TYPE_INT | TYPE_BOOLEAN, TYPE_NOASN );
pos = buf[0].id.i;
if (pos < 0 || pos > AttrLast) {
return RETURN_VOID;
}
AttrData[pos].maptype = buf[1].id.i ? MAP_COLOR : MAP_NO;
return RETURN_VOID;
}
}
/* マッピングを設定する */
static int FuncAttrMapFile( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int n ;
if ( args < 1 )
ExecError( "引数の数が不正です(AttrName)" );
if ( buf[0].type != TYPE_INT )
ExecError( "%d番目の引数の型不正です(AttrName)", 1 );
n = buf[0].id.i ;
if (n < 0 || n > AttrLast) {
return RETURN_VOID;
}
if ( args >= 2 )
{
if ( buf[1].type != TYPE_OBJECT || ObjectCheck( &buf[1], StringClassID ) == FALSE )
ExecError( "%d番目の引数の型不正です(AttrName)", 2 );
strcpy( AttrData[n].colorfile, ((StringClass*)buf[1].od.ptr)->str );
}
buf = StackAlloc( 1 );
StringToObject( buf, AttrData[n].colorfile );
return RETURN_RETURN ;
}
/* パラメータを設定する。 */
static int FuncAttrMap( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int pos;
int (*map)[2];
DataStruct *buf1, *buf2;
extern double ToDouble( DataStruct* );
ArgCheck( "AttrMapView", args, buf, TYPE_INT, TYPE_ARRAY, TYPE_ARRAY, TYPE_NOASN );
if ( buf[1].ad.size < 2 || buf[2].ad.size < 2)
ExecError( "引数配列のサイズが不正です。(AttrMapView)" );
pos = buf[0].id.i;
buf1 = buf[1].ad.ary;
buf2 = buf[2].ad.ary;
if (pos < 0 || pos > AttrLast) {
return RETURN_VOID;
}
if (ident == GetSizeID || ident == SetSizeID) map = AttrData[pos].mapsize;
else if (ident == GetViewID || ident == SetViewID) map = AttrData[pos].mapview;
else if (ident == GetWindID || ident == SetWindID) map = AttrData[pos].mapwind;
else assert(("Unknown Identifier", FALSE));
if (ident == SetSizeID || ident == SetViewID || ident == SetWindID) {
if ((buf1[0].type & (TYPE_INT | TYPE_REAL)) == 0
|| (buf1[1].type & (TYPE_INT | TYPE_REAL)) == 0
|| (buf2[0].type & (TYPE_INT | TYPE_REAL)) == 0
|| (buf2[1].type & (TYPE_INT | TYPE_REAL)) == 0) {
ExecError( "引数配列の型が不正です。( GetMapView )" );
}
map[0][0] = (int)(ToDouble(&buf1[0]) * 65536.0);
map[0][1] = (int)(ToDouble(&buf1[1]) * 65536.0);
map[1][0] = (int)(ToDouble(&buf2[0]) * 65536.0);
map[1][1] = (int)(ToDouble(&buf2[1]) * 65536.0);
} else {
if (buf1[0].type == TYPE_OBJECT) ObjectFree(buf1[0].od.ptr);
if (buf1[1].type == TYPE_OBJECT) ObjectFree(buf1[1].od.ptr);
if (buf2[0].type == TYPE_OBJECT) ObjectFree(buf2[0].od.ptr);
if (buf2[1].type == TYPE_OBJECT) ObjectFree(buf2[1].od.ptr);
buf1[0].type = buf1[1].type = buf2[0].type = buf2[1].type = TYPE_REAL;
buf1[0].rd.r = (double)map[0][0] / 65536.0;
buf1[1].rd.r = (double)map[0][1] / 65536.0;
buf2[0].rd.r = (double)map[1][0] / 65536.0;
buf2[1].rd.r = (double)map[1][1] / 65536.0;
}
return RETURN_VOID;
}