Exemplo n.º 1
0
static int qimage(Object o)
{
    int n;
    Array a;
    char *s;
    
    /* an image has got to be a field or a composite field */
    if (DXGetObjectClass(o) != CLASS_FIELD) {
	if (DXGetObjectClass(o) != CLASS_GROUP)
	    return 0;
	if (DXGetGroupClass((Group)o) != CLASS_COMPOSITEFIELD)
	    return 0;
	o = DXGetEnumeratedMember((Group)o, 0, NULL);
    }

    /* check to see if it's the right shape, etc */

    /* check positions */
    a = (Array) DXGetComponentValue((Field)o, "positions");
    if (!a || !DXQueryGridPositions(a, &n, NULL, NULL, NULL) || n!=2)
	return 0;
    
    /* check connections */
    a = (Array) DXGetComponentValue((Field)o, "connections");
    if (!a || !DXQueryGridConnections(a, &n, NULL) || n!=2)
	return 0;

    /* is there a colors component */
    a = (Array) DXGetComponentValue((Field)o, "colors");
    if (!a)
	return 0;

    /* check dep */
    s = DXGetString((String)DXGetAttribute((Object)a, "dep"));
    if (s && strcmp(s, "positions"))
	return 0;
    
    return 1;
}
Exemplo n.º 2
0
static
uint32 computeStringRecipe (String a)
{
    uint32 		crc;
    unsigned char	*p;

    crc = 0xFFFFFFFF;

    p = (unsigned char *) DXGetString (a);

    if (p)
    {
	int32		size;

	size = strlen ((char *)p);
	crc = _dxf_ExCRCByteV (crc, p, 1, size);
    }
    else
    {
	crc = _dxf_ExCRCInt (crc, 0);
    }

    return (EXTAG (crc));
}
Exemplo n.º 3
0
/*
 * recursively generate the recipes for a node in the graph
 */
void _dxf_ExComputeRecipes(Program *p, int funcInd)
{
    gfunc	*n = FETCH_LIST(p->funcs, funcInd);
    int		i, j, size, ntags, macro_tags=0, extra_tags, async_tags=0;
    gvar	*gv;
    uint32 	tcrc;
    gvar	*out;
    uint32 	*inTags, staticTags[STATIC_TAGS];
    int		varInd, *varIndp;
    int		varInd2;
    ProgramVariable *pv, *inpv, *pv_key;
    MacroRef 	*mr;
    AsyncVars 	*avars;
    _excache    fcache;
    _excache    pvcache;
    Program     *subP=NULL;
    int  tag_changed = FALSE;
    uint32 crc = 0xFFFFFFFF;
    char 	*async_name=NULL, *name;
    int		passthru = FALSE;
    char mod_cache_str[ MAX_PATH_STR_LEN ], *mod;
    
    /*  Get module path string  */
    mod = _dxf_ExGFuncPathToCacheString( n );
    if ( strlen(mod) > sizeof(mod_cache_str)-1 )
    _dxf_ExDie("Module path is too long");
    strcpy( mod_cache_str, mod );

check_async:
    if(n->flags & (MODULE_ASYNC | MODULE_ASYNCLOCAL)) {
        if(p->loopctl.first && (n->flags & MODULE_ASYNCLOCAL)) {
            if(strcmp(n->name, "GetLocal") == 0)
                DXReadyToRunNoExecute(mod_cache_str);
        }
        varInd = *FETCH_LIST(n->inputs, n->nin - 2);
        pv = FETCH_LIST(p->vars, varInd);
        if(!pv->gv)
            _dxf_ExDie("Cannot compute a cache tag from a NULL gvar");
        if(n->flags & MODULE_ASYNCNAMED) {
            varInd2 = *FETCH_LIST(n->inputs, n->rerun_index);
            pv_key = FETCH_LIST(p->vars, varInd2);
            if(pv_key->gv && pv_key->gv->obj) {
                if(pv->gv->obj)
                    DXDelete(pv->gv->obj);
                pv->gv->obj = DXReference(pv_key->gv->obj);    
            }
        }
        if(!pv->gv->obj)
            _dxf_ExDie("Cannot compute a cache tag from a NULL gvar");
        /* Put an extra reference on this input, we don't want this gvar
           to be deleted until the current graph finishes executing. This
           is incase the results were thrown out of cache and because of
           a switch need to run again. If this is in a loop it will get
           an extra ref each time through the loop which isn't needed but
           will get cleaned up ok in the end.
        */
        ExReference(pv->gv);
        pv->refs++;
        async_name = DXGetString((String)pv->gv->obj);
        varInd = *FETCH_LIST(n->inputs, n->nin - 1);
        pv = FETCH_LIST(p->vars, varInd);
        gv = (gvar *)_dxf_ExGlobalVariableSearch(async_name);
        if(gv) {
            if(gv != pv->gv) {
                _dxf_ExUndefineGvar(pv->gv);
                _dxf_ExDefineGvar(pv->gv, gv->obj);
            }
            ExDelete(gv);
        }
        else {
            Object value;
            value = (Object) _dxfExNewInteger (0);
            _dxf_ExDefineGvar(pv->gv, (Object)_dxfExNewInteger(0));
            _dxf_ExUpdateGlobalDict (async_name, value, 0);
        }
        /* Put an extra reference on this input, we don't want this gvar
           to be deleted until the current graph finishes executing. This
           is incase the results were thrown out of cache and because of
           a switch need to run again. If this is in a loop it will get
           an extra ref each time through the loop which isn't needed but
           will get cleaned up ok in the end.
         */
         ExReference(pv->gv);
         pv->refs++;
    }

    if(n->ftype == F_MACRO) {
        subP = n->func.subP;
        macro_tags = SIZE_LIST(subP->macros);
        async_tags = SIZE_LIST(subP->async_vars);
        extra_tags = macro_tags + async_tags;
    }
    else if(n->flags & MODULE_LOOP) {
        /* to cause the cache tag of loop modules to change even though */
        /* their inputs don't change, use the counter for the loop */
        extra_tags = 1;
    }
    else extra_tags = 0;
    ntags = n->nin+extra_tags;

    if(ntags > STATIC_TAGS)
        inTags = (uint32 *)DXAllocate(ntags*sizeof(uint32));
    else inTags = staticTags;

    /* add the crc of all of the module inputs to the total crc */
    for (i = 0; i < SIZE_LIST(n->inputs); i++)
    {
	varIndp = FETCH_LIST(n->inputs, i);
        if(varIndp == NULL)
            _dxf_ExDie("Executive Inconsistency: _dxf_ExComputeRecipes");
        varInd = *varIndp;
      
        inTags[i] = computeRecipe(p, varInd);
	ExDebug ("1", "Cache value for input %s.%d = 0x%08x ",
			    n->name, i, inTags[i]);
    }

    if(n->ftype == F_MACRO) {
        for (j = 0; j < macro_tags; j++, i++)
        {
            crc = 0xFFFFFFFF;
            mr = FETCH_LIST(subP->macros, j);
            inTags[i] = _dxf_ExCRCInt(crc, mr->index);
        }
        for (j = 0; j < async_tags; j++, i++) {
            avars = FETCH_LIST(subP->async_vars, j);
            pv = FETCH_LIST(p->vars, avars->nameindx);
            if(!pv->gv || !pv->gv->obj)
                _dxf_ExDie("Cannot compute a cache tag from a NULL async name");
            name = DXGetString((String)pv->gv->obj);
            pv = FETCH_LIST(p->vars, avars->valueindx);
            gv = (gvar *)_dxf_ExGlobalVariableSearch(name);
            if(gv) {
                if(gv != pv->gv) {
                    _dxf_ExUndefineGvar(pv->gv);
                    _dxf_ExDefineGvar(pv->gv, gv->obj);
                }
                ExDelete(gv);
            }
            else {
                Object value;
                value = (Object) _dxfExNewInteger (0);
                _dxf_ExDefineGvar(pv->gv, (Object)_dxfExNewInteger(0));
                _dxf_ExUpdateGlobalDict (name, value, 0);
            }
            inTags[i] = computeRecipe(p, avars->valueindx);
        }
    }
    else if(n->flags & MODULE_LOOP) {
        /* to cause the cache tag of loop modules to change even though */
        /* their inputs don't change, use the counter for the loop */
        crc = 0xFFFFFFFF;
        inTags[i] = _dxf_ExCRCInt(crc, p->loopctl.counter);
    }

    if((n->flags & MODULE_PASSTHRU) && (n->nin == n->nout+1))
        passthru = TRUE;
        
    if(n->flags & (MODULE_CONTAINS_STATE | MODULE_CHANGES_STATE))
    {
        Object new_tag_obj, old_tag_obj;
        uint32 oldtag, newtag;

        newtag = _dxf_ExGenCacheTag (n->name,0,ntags,inTags);
        new_tag_obj = (Object)DXMakeInteger(newtag);
        old_tag_obj = DXGetCacheEntry(mod_cache_str, ntags, 0);
        if(!old_tag_obj) {
            DXSetCacheEntry(new_tag_obj, CACHE_PERMANENT, mod_cache_str, ntags, 0);
        }
        else {
            /* we don't want an extra reference on this */
            DXDelete(old_tag_obj); 
            if(!DXExtractInteger(old_tag_obj, (int *)&oldtag))
                oldtag = 0;
            /* this means we just caused a DXReadyToRun so we know */
            /* this macro will run this time, save the new cache tag */
            if(oldtag == 0) {
                DXSetCacheEntry(new_tag_obj,CACHE_PERMANENT,mod_cache_str,ntags,0);
                DXDelete(old_tag_obj);
            }
            else if(oldtag != newtag) {
                /* An input has changed since last time, we need to */ 
                /* cause execution of this macro and we need to recompute */
                /* the cache tag. */
                DXReadyToRunNoExecute(async_name);
                DXDelete(new_tag_obj);
                new_tag_obj = (Object)DXMakeInteger(0);
                DXSetCacheEntry(new_tag_obj,CACHE_PERMANENT,mod_cache_str,ntags,0);
                DXDelete(old_tag_obj);
                goto check_async;
            }
            else DXDelete(new_tag_obj);
        }
    }

    /* generate the recipes for all of the outputs from this module */
    /* Update the pathtag table if module cache attribute is "cache last" */
    n->tag_changed = FALSE;
    for (i = 0; i < SIZE_LIST(n->outputs); i++)
    {
	varIndp = FETCH_LIST(n->outputs, i);
        if(varIndp == NULL)
            _dxf_ExDie("Executive Inconsistency: _dxf_ExComputeRecipes");
        varInd = *varIndp;
	pv = FETCH_LIST(p->vars, varInd);
        pv->is_output = TRUE;
	out = pv->gv;

	if (out->reccrc == 0 || 
	    (n->required != -1 && (!IsSwitch(n) || !IsFastSwitch(n)))) {
            /* This code is currently just intended for macrostart */
            if(passthru) {
	        varInd2 = *FETCH_LIST(n->inputs, i+1);
		if (varInd2 != -1) {
                    inpv = FETCH_LIST(p->vars, varInd2);
                    tcrc = inpv->gv->reccrc;
		} else
	            tcrc = _dxf_ExGenCacheTag (n->name,i,n->nin+extra_tags,inTags);
            }
            else
	        tcrc = _dxf_ExGenCacheTag (n->name,i,n->nin+extra_tags,inTags);
            if(out->reccrc != 0 && tcrc != out->reccrc)
                _dxf_ExUndefineGvar(out);
            pv->reccrc = out->reccrc = tcrc;
	    /* make process group name part of cache tag */
	    if(n->procgroupid) {
		size = strlen (n->procgroupid);
		out->reccrc = EXTAG(_dxf_ExCRCByteV(out->reccrc & 0x7fffffff,
		    (unsigned char *) n->procgroupid, 1, size));
	    }
	    ExDebug ("1", "Cache value for %s.%d = 0x%08x ",
			    n->name, i, out->reccrc);
	}
        
        pvcache = pv->excache;
        fcache  = n->excache;
       
        if((n->flags & (MODULE_ASYNC | MODULE_ASYNCLOCAL)) && 
           (pvcache == CACHE_ALL)) 
            pvcache = pv->excache = CACHE_LAST;
  
        /* I don't think we allow the user to turn off cacheing for */
        /* macros that have state in them. */
        if(n->flags & MODULE_CHANGES_STATE)
            pvcache = pv->excache = CACHE_LAST_PERM;
        if(n->flags & MODULE_CONTAINS_STATE)
            pvcache = pv->excache = CACHE_LAST;

        /* object lvl cache attribute overrides function lvl cache attribute */ 
        
        if (pvcache == CACHE_LAST || pvcache == CACHE_LAST_PERM) 
            tag_changed = _dxf_ExManageCacheTable(&n->mod_path, out->reccrc, i);
        else 
            if(fcache == CACHE_LAST && !pv->cacheattr) 
                tag_changed = _dxf_ExManageCacheTable(&n->mod_path, out->reccrc, i);
        n->tag_changed = tag_changed;
    }

    if(n->nout == 0 && !(n->flags & MODULE_SIDE_EFFECT)) {
        tcrc = _dxf_ExGenCacheTag (n->name, 0, n->nin+extra_tags, inTags);
        n->tag_changed = _dxf_ExManageCacheTable(&n->mod_path, tcrc, 0);
    }

    if(ntags > STATIC_TAGS)
        DXFree(inTags);
}
Exemplo n.º 4
0
Error m_SXEnum( Object *in, Object*out){
/*
*+
*  Name:
*     SXEnum

*  Purpose:
*     enumerating the positions or connections in a field

*  Language:
*     ANSI C

*  Syntax:
*     output = SXEnum( input, name, dep );

*  Classification:
*     Realisation

*  Description:
*     The SXEnum module creates the component specified by "name", and adds
*     it to the "output" field. The values in the new component start at zero
*     and increment by one for each position or connection in the field.
*
*     The new component is in one-to-one correspondance with either the
*     "positions" or "connections" component, dependant on "dep".

*  Parameters:
*     input = field (Given)
*        input field [none]
*     name = string (Given)
*        name of component to store the enumeration ["data"]
*     dep = string (Given)
*        object to be enumerated; "positions" or "connections" ["positions"]
*     output = field (Returned)
*        output field

*  Components:
*     Adds a component with the given "name", deleting any existing
*     component. All other components are copied from the "input" field.

*  Examples:
*     In this example, the 17th frame is extracted from a data set
*     containing scattered data, and a field created holding only those
*     positions with offsets between 10 and 20.
*
*        input = Import("/usr/lpp/dx/samples/data/CO2.general");
*        frame17 = Select(input,17);
*        enum = SXEnum(frame17,"index","positions");
*        marked = Mark(enum,"index");
*        included = Include(marked,10,20,1);
*        subset = Unmark(included,"index");

*  Returned Value:
*     OK, unless an error occurs in which case ERROR is returned and the
*     DX error code is set.

*  Copyright:
*     Copyright (C) 1995 Central Laboratory of the Research Councils.
*     All Rights Reserved.

*  Licence:
*     This program is free software; you can redistribute it and/or
*     modify it under the terms of the GNU General Public License as
*     published by the Free Software Foundation; either version 2 of
*     the License, or (at your option) any later version.
*
*     This program is distributed in the hope that it will be
*     useful,but WITHOUT ANY WARRANTY; without even the implied
*     warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
*     PURPOSE. See the GNU General Public License for more details.
*
*     You should have received a copy of the GNU General Public License
*     along with this program; if not, write to the Free Software
*     Foundation, Inc., 51 Franklin Street,Fifth Floor, Boston, MA
*     02110-1301, USA

*  Authors:
*     DSB: David Berry (STARLINK)
*     {enter_new_authors_here}

*  History:
*     25-SEP-1995 (DSB):
*        Original version
*     {enter_further_changes_here}

*  Bugs:
*     {note_any_bugs_here}

*-
*/

/*  Local Variables. */

      char   *dep;
      char   *name;
      Object  o=NULL;


/*  Check that the "input" object has been supplied. */

      if( !in[0] ){
         DXSetError( ERROR_BAD_PARAMETER, "missing parameter \"input\".");
         goto error;
      }


/*  Get a value for the "name" object. */

      if( !in[1] ){
         name = "data";

      } else {
         name = DXGetString( (String) in[1] );
         if( !name ){
            DXSetError( ERROR_BAD_PARAMETER, "unable to get string parameter \"name\".");
            goto error;
         }
      }


/*  Get a value for the "dep" object. */

      if( !in[2] ){
         dep = "positions";

      } else {
         dep = DXGetString( (String) in[2] );
         if( !dep ){
            DXSetError( ERROR_BAD_PARAMETER, "unable to get string parameter \"dep\".");
            goto error;
         }

         if( strcmp( dep, "positions" ) && strcmp( dep, "connections" ) ){
            DXSetError( ERROR_BAD_PARAMETER, "bad value (\"%s\") obtained for parameter \"dep\".",dep );
            goto error;
         }

      }


/*  Get a modifiable copy of the "input" object. */

      o = (Object) DXCopy( in[0], COPY_STRUCTURE );
      if( !o ) goto error;


/*  Enumerate it. */

      if( !DoSXEnum( o, name, dep ) ) goto error;


/*  Return the output object. */

      out[0] = o;
      return( OK );

error:
      DXDelete( o );
      return( ERROR );

}
Exemplo n.º 5
0
static void
CaptionKeyStruck(void *data, DXKeyPressEvent *event)
{
    CaptionData sdata = (CaptionData)data;
    ModuleInput min[2];
    ModuleOutput mout[1];
    Object caption, strattr, posattr;
    Object postion;
    float *xyz;
    int i, oldl, n, *ptr;
    char *oldstr;
    char *newstr;
    Object obType = NULL;
    int x = event->x;
    int y = event->y;
    char c = event->key;

    if (sdata->label == NULL)
	return;

    caption = DXGetMember((Group)sdata->obj, sdata->label);
    if (caption)
    {
	/*
	 * If there was already a member by that name, make sure its
	 * an appropriate object and get its state attributes.
	 */
	obType = DXGetAttribute(caption, "object type");
	if (!obType || strcmp(DXGetString((String)obType), "caption"))
	    return;

	strattr = DXGetAttribute(caption, "string");
	posattr = DXGetAttribute(caption, "position");
    }
    else
    {
	/*
	 * Otherwise, we'll initialize the state.  We'll need an object
	 * type attribute to put on the result (We re-use the one on the
	 * input if there already was a caption)
	 */
	obType = (Object)DXNewString("caption");

	/*
	 * Initial state is an empty string at the current mouse
	 * position.
	 */
	strattr = (Object)DXNewString("");
	posattr = (Object)DXNewArray(TYPE_FLOAT, CATEGORY_REAL, 1, 3);
	DXAddArrayData((Array)posattr, 0, 1, NULL);
	xyz = (float *)DXGetArrayData((Array)posattr);
	xyz[0] = ((float)x)/sdata->w;
	xyz[1] = ((float)(sdata->h - y))/sdata->w;
	xyz[2] = 0.0;
    }

    DXExtractString(strattr, &oldstr);

    /*
     * Update the string.
     */
    oldl = strlen(oldstr);

    if (c == 0x8 /* BACKSPACE */)
    {
	if (oldl > 0)
	{
	    newstr = (char *)DXAllocate(oldl + 1);
	    for (i = 0; i < oldl-1; i++)
		newstr[i] = oldstr[i];
	    newstr[oldl-1] = '\0';
	}
    }
    else
    {
	newstr = (char *)DXAllocate(oldl + 2);
	for (i = 0; i < oldl; i++)
	    newstr[i] = oldstr[i];
	newstr[oldl] = c;
	newstr[oldl+1] = '\0';
    }

    strattr = (Object)DXNewString(newstr);
	
    DXReference(strattr);
    DXReference(posattr);

    /*
     * Use CallModule to call the Caption module.  This creates the
     * new caption object.
     */
    DXModSetObjectInput(min+0, "string", strattr);
    DXModSetObjectInput(min+1, "position", posattr);
    DXModSetObjectOutput(mout+0, "caption", &caption);
    DXCallModule("Caption", 2, min, 1, mout);

    /*
     * Replace attributes onto caption
     */
    DXSetAttribute(caption, "string", strattr);
    DXSetAttribute(caption, "position", posattr);
    DXSetAttribute(caption, "object type", obType);

    /* 
     * Replace it into scene object group
     */
    DXSetMember((Group)sdata->obj, sdata->label, caption);

    DXDelete(strattr);
    DXDelete(posattr);

    return;
}
Exemplo n.º 6
0
static void 
CaptionMouseButton(void *data, DXMouseEvent *event)
{
    Object caption;
    Object obType;
    CaptionData sdata = (CaptionData)data;
    int b = WHICH_BUTTON(event);
    int x, y;

    x = event->x;
    y = event->y;

    if (sdata->label == NULL)
	return;

    /*
     * Get the member by name.  If no caption by this name exists,
     * there's nothing to move, so we return.
     */
    caption = DXGetMember((Group)sdata->obj, sdata->label);
    if (! caption)
	return;
    
    /*
     * Make sure its an appropriate object 
     */
    obType = DXGetAttribute(caption, "object type");
    if (!obType || strcmp(DXGetString((String)obType), "caption"))
	return;

    /*
     * Only should see left buttons, but check anyway.
     */
    if (b == 0)
    {
	ModuleInput min[2];
	ModuleOutput mout[1];
	Object strattr, posattr;
	float *xyz;

	/*
	 * If its a caption object, it better have these attributes.
	 * A little error checking might be called for.
	 */
	strattr = DXGetAttribute(caption, "string");
	posattr = (Object)DXNewArray(TYPE_FLOAT, CATEGORY_REAL, 1, 3);
	DXAddArrayData((Array)posattr, 0, 1, NULL);
	xyz = (float *)DXGetArrayData((Array)posattr);

	/*
	 * Move to the current position (0-1 space requires the division 
	 * by the screen width in pixels.
	 */
	xyz[0] = ((float)x)/sdata->w;
	xyz[1] = ((float)(sdata->h - y))/sdata->w;
	xyz[2] = 0.0;

	DXReference(strattr);
	DXReference(posattr);

	/*
	 * Use CallModule to call the Caption module.  This creates the
	 * new caption object.
	 */
	DXModSetObjectInput(min+0, "string", strattr);
	DXModSetObjectInput(min+1, "position", posattr);
	DXModSetObjectOutput(mout+0, "caption", &caption);
	DXCallModule("Caption", 2, min, 1, mout);

	/*
	 * Replace attributes onto caption
	 */
	DXSetAttribute(caption, "string", strattr);
	DXSetAttribute(caption, "position", posattr);
	DXSetAttribute(caption, "object type", obType);

	/* 
	 * Replace it into scene object group
	 */
	DXSetMember((Group)sdata->obj, sdata->label, caption);

	DXDelete(strattr);
	DXDelete(posattr);
    }

    return;
}
Exemplo n.º 7
0
static void
Slide2DEndStroke(void *data, DXMouseEvent *event)
{
    Slide2DData sdata = (Slide2DData)data;
    int b = WHICH_BUTTON(event);
    int dx, dy;
    Object member;
    char *name;
    Point corners[8];
    int i;

    if (!sdata)
	return;

    sdata = (Slide2DData)data;
    if (! sdata)
	return;
    
    dx = sdata->buttonPosition[b].x - event->x;
    dy = -(sdata->buttonPosition[b].y - event->y);

    sdata->buttonPosition[b].x = event->x;
    sdata->buttonPosition[b].y = event->y;

    sdata->strokeStart = 1;
    
    /*
     * End stroke.  If its the left button or up'n'downish right button,
     * we operate on a member of the scene group.  If its a left'n'right
     * middle button, we operate on the camera
     */
    if (b == 0 || ((b == 1) && (abs(dy) > abs(dx))))
    {
	Group og = (Group)sdata->obj, ng;

	/*
	 * Can't do anything if we don't have a scene object group or an 
	 * arg telling us what member to operate on
	 */
	if ((sdata->label == NULL && sdata->index == -1) || !sdata->obj)
	    return;

	/*
	 * Create a new group header.
	 */
	ng = (Group)DXCopy(sdata->obj, COPY_ATTRIBUTES);
	if (! ng)
	    return;

	/*
	 * Loop through the scene object group.  For each member NOT matching
	 * the argument, just copy it into the new group.  Otherwise, twiddle
	 * its transform matrix and put it there.
	 */
	i = 0;
	while (NULL != (member = DXGetEnumeratedMember((Group)og, i++, &name)))
	{
	    if ((sdata->label && !strcmp(name, sdata->label)) 
		    || ((i-1) == sdata->index))
	    {
		Object attr;

		/* 
		 * This is the one to manipulate.  It better be a 
		 * 'transformed object' type.
		 */

		attr = DXGetAttribute(member, "object type");
		if (! attr)
		    continue;
		
		if (strcmp(DXGetString((String)attr), "transformed object"))
		    continue;

		if (b == 0)
		{
		    Vector x;
		    Xform oldx = (Xform)member;
		    Matrix oldm, newm;
		    Object xchild;

		    /*
		     * Its the left button.  Determine the world space
		     * vector corresponding to the screen-space stroke, and
		     * concatenate it onto the matrix already associated with
		     * the object, and create a new DX Transform object with
		     * the old transforms child and the concatenated matrices.
		     */

		    x.x = -(dx * sdata->gt);
		    x.y = -(dy * sdata->gt);
		    x.z = 0.0;

		    DXGetXformInfo(oldx, &xchild, &oldm);

		    newm = DXTranslate(x);
		    newm = DXConcatenate(oldm, newm);
		    member = (Object)DXNewXform(xchild, newm);
		    DXSetAttribute(member, "object type", attr);
		}
		else if (DXBoundingBox(member, corners))
		{
		    Angle r;
		    Xform oldx = (Xform)member;
		    Matrix oldm, newm;
		    Object xchild;
		    Vector center;

		    /*
		     * Then its an up'n'down middle button stroke. Create
		     * a matrix that transforms the object back to the origin,
		     * rotates it, and then back to where it was.
		     */


		    DXGetXformInfo(oldx, &xchild, &oldm);

		    /*
		     * Move the object so its center is at the origin
		     */
		    center.x = -(corners[0].x + corners[7].x) / 2.0;
		    center.y = -(corners[0].y + corners[7].y) / 2.0;
		    center.z = -(corners[0].z + corners[7].z) / 2.0;
		    newm = DXTranslate(center);
		    oldm = DXConcatenate(oldm, newm);


		    /*
		     * Rotate
		     */
		    r = dy * sdata->gr * (2*3.14159);
		    newm = DXRotateZ(r);
		    oldm = DXConcatenate(oldm, newm);

		    /*
		     * Move the object back to its original location
		     */
		    center.x = -center.x;
		    center.y = -center.y;
		    center.z = -center.z;
		    newm = DXTranslate(center);
		    oldm = DXConcatenate(oldm, newm);

		    member = (Object)DXNewXform(xchild, oldm);
		    DXSetAttribute(member, "object type", attr);
		}
	    }
	    DXSetMember(ng, name, member);
	}

	DXDelete(sdata->obj);
	sdata->obj = DXReference((Object)ng);


    }
    else if ((b == 1) && (abs(dx) > abs(dy)))
    {
	/*
	 * Its a left'n'right middle button.  Alter the camera's width
	 * parameter based on a scaled stroke dx.
	 */
	sdata->width += (sdata->width * dx)/sdata->w;
    }

    return;

}
Exemplo n.º 8
0
static void *
Slide2DInitMode(Object args, int w, int h, int *mask)
{
    Slide2DData sdata = (Slide2DData)DXAllocateZero(sizeof(struct slide2DData));
    if (! sdata)
	return NULL;

    /* 
     * Parse the argument.  It better be a string or an integer.
     */
    if (! args)
    {
        DXWarning("Slide2D: argument required (index 0 used)");
	sdata->label = NULL;
	sdata->index = 0;
    }
    else if (DXGetObjectClass(args) == CLASS_STRING)
    {
	sdata->args = DXReference(args);
	sdata->label = DXGetString((String)args);
    }
    else if (DXGetObjectClass(args) == CLASS_ARRAY)
    {
	Type t;

	DXGetArrayInfo((Array)args, NULL, &t, NULL, NULL, NULL);
	if (t == TYPE_INT)
	{
	    sdata->args = DXReference(args);
	    sdata->index = *(int *)DXGetArrayData((Array)args);
	    sdata->label = NULL;
	}
	else if (t == TYPE_UBYTE ||
		 t == TYPE_BYTE  ||
		 t == TYPE_STRING)
	{
	    sdata->args = DXReference(args);
	    sdata->label = (char *)DXGetArrayData((Array)args);
	    sdata->index = -1;
	}
	else
	{
	    DXWarning("Slide2D: argument must be string or int (index 0 used)");
	    sdata->label = NULL;
	    sdata->index = 0;
	}

    }

    /*
     * Save the window width and height for scaling purposes
     */
    sdata->w = w;
    sdata->h = h;

    /*
     * Initially, the button is up
     */
    sdata->strokeStart = 1;

    /* 
     * Pay attention to only the left and middle buttons
     */
    *mask = DXEVENT_LEFT | DXEVENT_MIDDLE;
	
    return (void *)sdata;
}
Exemplo n.º 9
0
Error 
_dxfValidate(Field f)
{
    Array current = NULL;
    Array target = NULL;
    char *tname, *cname;
    int ncurrent, ntarget, *ip;
    int index;
    unsigned char *cp;
    int i, j, lim, nitems;
    Type type, ref_type;
    Category cat;
    String s = NULL;
    Object o = NULL;
    int rank, shape[MAXRANK];
    int counts[MAXRANK];

    for (i=0; (current=(Array)DXGetEnumeratedComponentValue(f, i, &cname)); i++) {

	/* dep */
	if ((s = (String)DXGetAttribute((Object)current, "dep")) != NULL) {
	    /* make sure number of items matches number of items in dep */
	    if ((DXGetObjectClass((Object)s) != CLASS_STRING) ||
	        ((tname = DXGetString(s)) == NULL)) {
		DXSetError(ERROR_DATA_INVALID, 
			 Err_MustBeString, "dep", cname);
		return ERROR;
	    }
	    
	    if ((target = (Array)DXGetComponentValue(f, tname)) == NULL) {
		DXSetError(ERROR_DATA_INVALID, 
			 Err_MissingComp, tname, "dep", cname);
		return ERROR;
	    }
	    
	    if (DXGetObjectClass((Object)target) != CLASS_ARRAY) {
		DXSetError(ERROR_DATA_INVALID,
			 Err_NotArray, tname, "dep", cname);
		return ERROR;
	    }
	    
	    if (!DXGetArrayInfo(current, &nitems, &type, &cat, &rank, shape))
		return ERROR;
	    
	    ncurrent = nitems;

	    if (!DXGetArrayInfo(target, &nitems, &type, &cat, &rank, shape))
		return ERROR;
	    
	    ntarget = nitems;
	    
	    if (ncurrent != ntarget) {
		DXSetError(ERROR_DATA_INVALID,
			 Err_DiffCount, "dep",
			 ncurrent, cname, ntarget, tname);
		return ERROR;
	    }

	} /* end of if (has dep) */


	/* ref */
	if ((s = (String)DXGetAttribute((Object)current, "ref")) != NULL) {
	    if ((DXGetObjectClass((Object)s) != CLASS_STRING) ||
	        ((tname = DXGetString(s)) == NULL)) {
		DXSetError(ERROR_DATA_INVALID, 
			   Err_MustBeString, "ref", cname);
		return ERROR;
	    }
	    
	    if ((target = (Array)DXGetComponentValue(f, tname)) == NULL) {
		DXSetError(ERROR_DATA_INVALID,
			   Err_MissingComp, tname, "ref", cname);
		return ERROR;
	    }
	    
	    if (DXGetObjectClass((Object)target) != CLASS_ARRAY) {
		DXSetError(ERROR_DATA_INVALID, 
			   Err_NotArray, tname, "ref", cname);
		return ERROR;
	    }
	    
	    if (!DXGetArrayInfo(current, &nitems, &type, &cat, &rank, shape))
		return ERROR;
	    
	    if ( !( type == TYPE_INT || type == TYPE_UBYTE ) ) {
		DXSetError(ERROR_DATA_INVALID, Err_RefNotInt, cname);
		return ERROR;
	    }
	    ref_type = type;
	    
	    ncurrent = nitems;
	    for (j=0; j<rank; j++)
	        ncurrent *= shape[j];
	    
	    if (ncurrent > 0) {
                
		if (!DXGetArrayInfo(target, &nitems, &type, &cat, &rank, shape))
		    return ERROR;
		
		ntarget = nitems;
                
                /* only do this if they are already irregular */
                if (DXGetArrayClass(current) == CLASS_ARRAY) {
                    if ((ip = (int *)DXGetArrayData(current)) == NULL)
                        return ERROR;
		    cp = (unsigned char *) ip;
                    
		    /* neighbors can have -1's as indicies */
                    lim = strcmp(cname, "neighbors") ? 0 : -1;

		    for (j=0; j < ncurrent; j++) {
			if (ref_type == TYPE_INT) index = *(ip++);
			else                      index = *(cp++);

			if (index < lim || index >= ntarget) {
			    DXSetError(ERROR_DATA_INVALID, Err_OutOfRange,
				j+1, ending(j+1), cname, index, lim, ntarget-1);
			    return ERROR;
			}
		    }

                } else if (DXQueryGridConnections(current, &rank, counts)) {
		    for (j=0, ncurrent=1; j<rank; j++)
			ncurrent *= counts[j];
                    if (ncurrent > ntarget) {
                        DXSetError(ERROR_DATA_INVALID,
                                 Err_DiffCount, "ref",
                                 ncurrent, cname, ntarget, tname);
                        return ERROR;
                    }
                } else {
                    /* mesh array of mixed path and irregular arrays. */
                    /* have to handle the terms separately */
                }
	    }
	} /* end of if (has ref) */


        /* der - can be string lists here */
	if ((o = DXGetAttribute((Object)current, "der")) != NULL) {

	    if (DXExtractString(o, &tname)) {    /* simple string? */
		if ((target = (Array)DXGetComponentValue(f, tname)) == NULL) {
		    DXSetError(ERROR_DATA_INVALID,
			       Err_MissingComp, tname, "der", cname);
		    return ERROR;
		}
		
		if (DXGetObjectClass((Object)target) != CLASS_ARRAY) {
		    DXSetError(ERROR_DATA_INVALID,
			       Err_NotArray, tname, "der", cname);
		    return ERROR;
		}
	    } else if (DXExtractNthString(o, 0, &tname)) {  /* string list? */
		for (j=0; DXExtractNthString(o, j, &tname); j++) {
		    
		    if ((target = (Array)DXGetComponentValue(f, tname)) == NULL) {
			DXSetError(ERROR_DATA_INVALID,
				   Err_MissingComp, tname, "der", cname);
			return ERROR;
		    }
		    
		    if (DXGetObjectClass((Object)target) != CLASS_ARRAY) {
			DXSetError(ERROR_DATA_INVALID,
				   Err_NotArray, tname, "der", cname);
			return ERROR;
		    }
		}
	    } else {  /* neither string or string list */
		DXSetError(ERROR_DATA_INVALID, 
			   Err_MustBeStringList, "der", cname);
		return ERROR;
	    }
	    
	} /* end of if (has der) */

        /* element type */
	if ((s = (String)DXGetAttribute((Object)current, "element type")) != NULL) {
	    if ((DXGetObjectClass((Object)s) != CLASS_STRING) ||
	        ((tname = DXGetString(s)) == NULL)) {
		DXSetError(ERROR_DATA_INVALID, 
			 Err_MustBeString, "element type", cname);
		return ERROR;
	    }
	    
	    if (!strcmp(cname, "connections") && 
		DXQueryGridConnections(current, &rank, counts)) {

		if (!elemtypecheck(rank, tname))
		    return ERROR;
	    }

	} /* end of if (has element type) */

    }  /* for each component in the field */

    /* check for missing positions component if the field has more than
     *  one component.
     */
    if (i > 1 && !DXGetComponentValue(f, "positions"))
	DXWarning("importing a field with no `positions' component");

    return OK;
}
Exemplo n.º 10
0
static int
doLeaf(Object *in, Object *out)
{
    int i, result=0;
    Array array;
    Field field;
    Pointer *in_data[2], *out_data[1];
    int in_knt[2], out_knt[1];
    Type type;
    Category category;
    int rank, shape;
    Object attr, src_dependency_attr = NULL;
    char *src_dependency = NULL;
    /*
     * Irregular positions info
     */
    int p_knt, p_dim;
    float *p_positions;
    int c_knt = -1;

    /* User-added declarations */
    float *scratch, *in_ptr, size;
    Point inpoint, *out_pos_ptr;
    ArrayHandle handle;
    Array connections;
    Line *conn_ptr;

    /*
     * positions and/or connections are required, so the first must
     * be a field.
     */
    if (DXGetObjectClass(in[0]) != CLASS_FIELD)
    {
        DXSetError(ERROR_DATA_INVALID,
                   "positions and/or connections unavailable in array object");
        goto error;
    }
    else
    {

        field = (Field)in[0];

        if (DXEmptyField(field))
            return OK;

        /*
         * Determine the dependency of the source object's data
         * component.
         */
        src_dependency_attr = DXGetComponentAttribute(field, "data", "dep");
        if (! src_dependency_attr)
        {
            DXSetError(ERROR_MISSING_DATA, "\"input\" data component is missing a dependency attribute");
            goto error;
        }

        if (DXGetObjectClass(src_dependency_attr) != CLASS_STRING)
        {
            DXSetError(ERROR_BAD_CLASS, "\"input\" dependency attribute");
            goto error;
        }

        src_dependency = DXGetString((String)src_dependency_attr);

        array = (Array)DXGetComponentValue(field, "positions");
        if (! array)
        {
            DXSetError(ERROR_BAD_CLASS, "\"input\" contains no positions component");
            goto error;
        }

        /* change to doLeaf so that regular positions are not expanded */

        if (!(handle = DXCreateArrayHandle(array)))
            goto error;

        scratch = DXAllocate(3*sizeof(float));
        if (!scratch)
            goto error;

        DXGetArrayInfo(array, &p_knt, NULL, NULL, NULL, &p_dim);


    }

    /* New User code starts here */

    /* Make the new positions array for the output */
    array = DXNewArray(TYPE_FLOAT, CATEGORY_REAL, 1, 3);
    if (! array)
        goto error;


    /* Check that the positions are three dimensional: */
    if (p_dim != 3) {
        DXSetError(ERROR_DATA_INVALID,"input positions must be 3-dimensional");
        goto error;
    }
    /* Allocate space in the new positions array */
    if (! DXAddArrayData(array, 0, 4*p_knt, NULL))
        goto error;

    /* Get a pointer to the output positions */
    out_pos_ptr  = (Point *)DXGetArrayData(array);


    /* Make a connections component for the output */
    connections = DXNewArray(TYPE_INT, CATEGORY_REAL, 1, 2);

    /* Allocate space in the new connections array */
    if (! DXAddArrayData(connections, 0, 2*p_knt, NULL))
        goto error;
    DXSetAttribute((Object)connections, "element type",
                   (Object)DXNewString("lines"));
    /* Get a pointer to the new connections */
    conn_ptr = (Line *)DXGetArrayData(connections);

    /* Now "draw" the x's */
    for (i=0; i< p_knt; i++) {
        /* the following line accesses the position via the
         * array handling routines
         */
        in_ptr = (float *)DXIterateArray(handle, i, in_ptr, scratch);
        inpoint = DXPt(in_ptr[0], in_ptr[1], in_ptr[2]);
        DXExtractFloat(in[1], &size);
        out_pos_ptr[4*i]   = DXPt(inpoint.x - size, inpoint.y, inpoint.z);
        out_pos_ptr[4*i+1] = DXPt(inpoint.x + size, inpoint.y, inpoint.z);
        out_pos_ptr[4*i+2] = DXPt(inpoint.x, inpoint.y - size, inpoint.z);
        out_pos_ptr[4*i+3] = DXPt(inpoint.x, inpoint.y + size, inpoint.z);

        conn_ptr[2*i] = DXLn(4*i, 4*i+1);
        conn_ptr[2*i+1] = DXLn(4*i+2, 4*i+3);
    }

    /* Clean up; we're about to significantly modify the positions and connections
     */
    DXChangedComponentStructure((Field)out[0],"positions");
    DXChangedComponentStructure((Field)out[0],"connections");

    /* Now place the new positions and connections in the output field */
    DXSetComponentValue((Field)out[0], "positions", (Object)array);
    DXSetComponentValue((Field)out[0], "connections", (Object)connections);

    /* Finalize the field */
    DXEndField((Field)out[0]);

    /* Delete scratch and handle */
    DXFree((Pointer)scratch);
    DXFreeArrayHandle(handle);

    /* return */
    return OK;
error:

    /* Delete scratch and handle */
    DXFree((Pointer)scratch);
    DXFreeArrayHandle(handle);
    return ERROR;


}
Exemplo n.º 11
0
static Error sayclass(Object o, char *intro, int descend)
{
    int count;

    switch (DXGetObjectClass(o)) {
	
      case CLASS_GROUP:
	if (!DXGetMemberCount((Group)o, &count))
	    return ERROR;
	
	switch(DXGetGroupClass((Group)o)) {
	    
	  case CLASS_GROUP:
	    DescribeMsg("%s %s Group which contains %d member%s.\n", 
		      intro, IS, count, (count==1 ? "" : "s"));
	    break;
	    
	  case CLASS_COMPOSITEFIELD:
	    DescribeMsg("%s %s Partitioned Field which contains %d partition%s.\n", 
		      intro, IS, count, (count==1 ? "" : "s"));
	    break;
	    
	  case CLASS_MULTIGRID:
	    DescribeMsg("%s %s Multigrid Group which contains %d member%s.\n", 
		      intro, IS, count, (count==1 ? "" : "s"));
	    break;
	    
	  case CLASS_SERIES:
	    DescribeMsg("%s %s Series Group which contains %d series member%s.\n", 
		      intro, IS, count, (count==1 ? "" : "s"));
	    DescribeMsg("To work with one member at a time use the `Select' module\n");

	    break;
	
	  default:
	    DescribeMsg("%s %s Group Object but of unrecognized Group Type.\n",
		      intro, IS);
	    break;
	}
	
	if (descend)
	    saymembers((Group)o);
	break;
	
      case CLASS_FIELD:
        DescribeMsg("%s %s Field, the basic data carrying structure in DX.\n", 
		  intro, IS);
        break;

      case CLASS_ARRAY:
	DescribeMsg("%s %s Array Object, containing a list of data values.\n",
		  intro, IS_V);

	switch (DXGetArrayClass((Array)o)) {
	    
	  case CLASS_ARRAY:
	    break;

	  case CLASS_PRODUCTARRAY:
	  case CLASS_MESHARRAY:
	  case CLASS_PATHARRAY:
	  case CLASS_CONSTANTARRAY:
	  case CLASS_REGULARARRAY:
	    DescribeMsg("These values are stored in a compact format to save space.\n");
	    break;
	
	  default:
	    DescribeMsg("The Array is of an unrecognized type.\n");
	    break;
	}

	/* ??? add code here ??? - print the first N values? */
	break;
	
      case CLASS_STRING:
	DescribeMsg("%s %s String, a list of character values\n",
		  intro, IS);
	DescribeMsg("It contains the value `%s'\n", DXGetString((String)o));
	break;
	
      case CLASS_CAMERA:
	DescribeMsg("%s %s Camera, used to set the viewpoint for Rendering.\n",
		  intro, IS);
	break;

      case CLASS_XFORM:
	DescribeMsg("%s %s Transformed object, meaning that a transformation will be applied to the final object before rendering.\n",
		  intro, IS);
	/* sayclass of xformed obj? */
	break;

      case CLASS_OBJECT:
	DescribeMsg("%s %s Generic Object, of unrecognized type.\n", intro, IS);
	break;

      case CLASS_LIGHT:
	DescribeMsg("%s %s Light, used to set the Lighting parameters for Rendering.\n",
		  intro, IS);
	break;
	
      case CLASS_CLIPPED:
	DescribeMsg("%s %s Clipped Object, which means that at Rendering time part of the object will be invisible.\n",
		    intro, IS);
	/* sayclass of clipped obj? */
	break;
	
      case CLASS_INTERPOLATOR:
	DescribeMsg("%s %s Interpolator. Internal use only.\n", intro, IS);
	break;
	
      case CLASS_SCREEN:
	DescribeMsg("%s %s Screen Object, meaning this object stays aligned with the screen.\n", 
		  intro, IS);
	/* say something about the screen obj? */
	break;
	
      case CLASS_MAX:
	DescribeMsg("Unrecognized Object.  Object type above Class Max.\n");
	break;
	
      case CLASS_MIN:
	DescribeMsg("Unrecognized Object.  Object type below Class Min.\n");
	break;

      case CLASS_PRIVATE:
	DescribeMsg("%s %s Private object, defined by a user.\n", intro, IS);
	break;

      case CLASS_DELETED:
	DescribeMsg("%s %s Deleted Object. Should not happen.\n", intro, IS);
	break;

      default:
	DescribeMsg("%s %s Unrecognized object.  Bad return from GetObjectType().\n",
		  intro, IS);
	break;
    }

    return OK;
}