Example #1
0
static int explorer_apply(ExplorerUI *ui, void *caller)
{
    TreeItemList items;
    int count, i, res = RETURN_SUCCESS;

    int gpcount = 0;
    GProject **gplist;
    
    if (caller && !ToggleButtonGetState(ui->instantupdate)) {
        return RETURN_FAILURE;
    }
    
    TreeGetHighlighted(ui->tree, &items);
    count = items.count;

    if (!count) {
        xfree(items.items);
        return RETURN_FAILURE;
    }

    gplist = xmalloc(gapp->gpcount*sizeof(GProject));
    if (!gplist) {
        return RETURN_FAILURE;
    }

    for (i = 0; i < count && res == RETURN_SUCCESS; i++) {
        Quark *q = TreeGetQuark(items.items[i]);

        add_to_list(gplist, &gpcount, gproject_from_quark(q));

        if (count == 1 && (!caller || caller == ui->idstr)) {
            char *s = TextGetString(ui->idstr);
            quark_idstr_set(q, s);
            xfree(s);
        }

        switch (quark_fid_get(q)) {
        case QFlavorProject:
            if (set_project_data(ui->project_ui, q, caller) != RETURN_SUCCESS) {
                res = RETURN_FAILURE;
            }
            break;
        case QFlavorSSD:
            if (set_ssd_data(ui->ssd_ui, q, caller) != RETURN_SUCCESS) {
                res = RETURN_FAILURE;
            }
            break;
        case QFlavorFrame:
            if (set_frame_data(ui->frame_ui, q, caller) != RETURN_SUCCESS) {
                res = RETURN_FAILURE;
            }
            break;
        case QFlavorGraph:
            if (graph_set_data(ui->graph_ui, q, caller) != RETURN_SUCCESS) {
                res = RETURN_FAILURE;
            }
            break;
        case QFlavorSet:
            if (set_set_data(ui->set_ui, q, caller) != RETURN_SUCCESS) {
                res = RETURN_FAILURE;
            }
            break;
        case QFlavorAGrid:
            if (set_axisgrid_data(ui->axisgrid_ui, q, caller) != RETURN_SUCCESS) {
                res = RETURN_FAILURE;
            }
            break;
        case QFlavorAxis:
            if (set_axis_data(ui->axis_ui, q, caller) != RETURN_SUCCESS) {
                res = RETURN_FAILURE;
            }
            break;
        case QFlavorDObject:
            if (set_object_data(ui->object_ui, q, caller) != RETURN_SUCCESS) {
                res = RETURN_FAILURE;
            }
            break;
        case QFlavorAText:
            if (set_atext_data(ui->atext_ui, q, caller) != RETURN_SUCCESS) {
                res = RETURN_FAILURE;
            }
            break;
        case QFlavorRegion:
            if (set_region_data(ui->region_ui, q, caller) != RETURN_SUCCESS) {
                res = RETURN_FAILURE;
            }
            break;
        default:
            res = RETURN_FAILURE;
            break;
        }
    }
    xfree(items.items);

    for (i = 0; i < gpcount; i++) {
        explorer_snapshot(gapp, gplist[i], FALSE);
    }
    xfree(gplist);

    return res;
}
Example #2
0
/** Set a value
	\verbatim gl('set',id,property,value) \endverbatim
 **/
void cmex_set(int nlhs, mxArray *plhs[], /**< () */
				int nrhs, const mxArray *prhs[]) /**< (object_id,property_name,value) */
{
	if (nlhs>0)
		output_error("set does not return a value");
	else if (nrhs==1 && mxIsStruct(prhs[0]))
		set_object_data(prhs[0]);
	else if (nrhs!=3)
		output_error("set requires either a structure, or object id, property name and value");
	else if (!mxIsChar(prhs[0]))
		output_error("object id (arg 0) must be a string");
	else if (mxIsChar(prhs[1]))
	{
		char value[1024];
		PROPERTY* prop;
		OBJECT *obj=NULL;
		GLOBALVAR *var=NULL;
		if (mxGetString(prhs[0],value,sizeof(value))!=0)
			output_error("object name (arg 0) too long");
		else if (strcmp(value,"global")==0)
		{
			if (!mxIsChar(prhs[1]))
				output_error("global variable name is not a string");
			else if (!mxIsChar(prhs[2]))
				output_error("global value is not is not a string");
			else
			{
				char name[32], value[1024];
				mxGetString(prhs[1],name,sizeof(name));
				mxGetString(prhs[2],value,sizeof(value));
				if (global_setvar(name,value)!=SUCCESS)
					output_error("unable to set global '%s' to '%s'", name,value);
			}
		}
		else if (convert_to_object(value,&obj,NULL)==0)
			output_error("object (arg 0) %s not found",value);
		else if (mxGetString(prhs[1],value,sizeof(value))!=0)
			output_error("property name (arg 1) too long");
		else if ((prop=object_get_property(obj,value))==NULL)
			output_error("property name (arg 1) %s not found in object %s:%d", value,obj->oclass->name, obj->id);
		else if (mxIsChar(prhs[2]))
		{
			if (mxGetString(prhs[2],value,sizeof(value))!=0)
				output_error("value (arg 2) is too long");
			else if (object_set_value_by_name(obj,prop->name,value)==0)
				output_error("unable to set %s:%d/%s to %s", obj->oclass->name, obj->id, prop->name, value);
			else
				return; /* ok */
		}
		else if (mxIsDouble(prhs[2]) && prop->ptype==PT_double)
		{
			double v = *mxGetPr(prhs[2]);
			if (prop->ptype==PT_double && object_set_double_by_name(obj,prop->name,v)==0)
				output_error("unable to set %s:%d/%s to %lg", obj->oclass->name, obj->id, prop->name, v);
		}
		else if (mxIsComplex(prhs[2]) || mxIsDouble(prhs[2]))
		{
			sprintf(value,"%lg%+lgi",*mxGetPr(prhs[2]),mxIsComplex(prhs[2])?*mxGetPi(prhs[2]):0);
			if (object_set_value_by_name(obj,prop->name,value)==0)
				output_error("unable to set %s:%d/%s to %s", obj->oclass->name, obj->id, prop->name, value);
		}
		else 
			output_error("value (arg 2) has an unsupported data type");
	}
	else
		output_error("property or data (arg 1) type is not valid");
}