Beispiel #1
0
static int compare_property(OBJECT *obj, char *propname, FINDOP op, void *value)
{
	/** @todo comparisons should type based and not using string representation (ticket #20) */
	char *propval = object_property_to_string(obj,propname);
	if (propval==NULL) return 0;
	return compare_string(propval,op,(char*)value);
}
Beispiel #2
0
int kml_document(FILE *fp)
{
	CLASS *oclass, *openclass=NULL;
	MODULE *mod;
	char buffer[1024];
	time_t now = time(NULL);
	kml_write("%s","  <Document>\n");
	kml_write("    <name>%s</name>\n", global_modelname);
	kml_write("    <description>GridLAB-D results for %s</description>\n",
		convert_from_timestamp(global_clock,buffer,sizeof(buffer))?buffer:"unknown date/time");

	/* for each module */
	for (mod=module_get_first(); mod!=NULL; mod=mod->next)
	{
		if (mod->kmldump)
			mod->kmldump(kml_write,NULL); /* dump styles */
	}

	/* scan each class in the model */
	for (oclass=class_get_first_class(); oclass!=NULL; oclass=oclass->next)
	{
		OBJECT *obj;

		/* scan each object in the model */
		for (obj=object_get_first(); obj!=NULL; obj=obj->next)
		{
			int has_location = !(isnan(obj->latitude) || isnan(obj->longitude));
			MODULE *mod;

			/* class does not match current object */
			if (obj->oclass!=oclass)
				continue;

			/* first instance of this class needs folder */
			else if (openclass==NULL)
			{
				kml_write("  <Folder><name>Class %s</name>\n", oclass->name);
				kml_write("    <description>Module %s",oclass->module->name);
				if (oclass->module->minor!=0 || oclass->module->major!=0)
					kml_write(" (V%d.%02d)",oclass->module->major,oclass->module->minor);
				kml_write("</description>\n",oclass->module->name);
				openclass=oclass;
			}			

			/* module overrides KML output */
			mod = (MODULE*)(obj->oclass->module);
			if (mod->kmldump!=NULL)
				(*(mod->kmldump))(kml_write,obj);
			else if (has_location)
			{
				/* basic KML output of published variables */
				PROPERTY *prop;
				kml_write("    <Placemark>\n");
				if (obj->name)
					kml_write("      <name>%s</name>\n", obj->name);
				else
					kml_write("      <name>%s %d</name>\n", obj->oclass->name, obj->id);
				kml_write("      <description>\n");
				kml_write("        <![CDATA[\n");
				kml_write("          <TABLE><TR>\n");
				for (prop=oclass->pmap;prop!=NULL && prop->oclass==oclass; prop=prop->next)
				{
					char *value = object_property_to_string(obj,prop->name, buffer, 1023);
					if (value!=NULL)
						kml_write("<TR><TH ALIGN=LEFT>%s</TH><TD ALIGN=RIGHT>%s</TD></TR>",
							prop->name, value);
				}
				kml_write("          </TR></TABLE>\n");
				kml_write("        ]]>\n");
				kml_write("      </description>\n");
				kml_write("      <Point>\n");
				kml_write("        <coordinates>%f,%f</coordinates>\n",obj->longitude,obj->latitude);
				kml_write("      </Point>\n");
				kml_write("    </Placemark>\n");
			}
		}

		/* close folder if any */
		if (openclass!=NULL)
		{
			kml_write("  </Folder>\n");
			openclass=NULL;
		}
	}

	kml_write("  </Document>\n");
	return 0;
}
int module_saveobj_xml(FILE *fp, MODULE *mod){ /**< the stream to write to */
	unsigned count = 0;
	char buffer[1024];
	PROPERTY *prop = NULL;
	OBJECT *obj;
	CLASS *oclass=NULL;
	CLASS *pclass = NULL;

	for(obj = object_get_first(); obj != NULL; obj = obj->next){
		char32 oname = "(unidentified)";
		if(obj->oclass->module != mod){
			continue;
		}

		if(obj->name != NULL){
			strcpy(oname, obj->name);
		} else {
			sprintf(oname, "%s:%i", obj->oclass->name, obj->id);
		}
		if ((oclass == NULL) || (obj->oclass != oclass))
			oclass = obj->oclass;
		count += fprintf(fp,"\t\t<object type=\"%s\" id=\"%i\" name=\"%s\">\n", obj->oclass->name, obj->id, oname);

		/* dump internal properties */
		if (obj->parent!=NULL){
			if(obj->parent->name != NULL){
				strcpy(oname, obj->parent->name);
			} else {
				sprintf(oname, "%s:%i", obj->parent->oclass->name, obj->parent->id);
			}
			count += fprintf(fp,"\t\t\t<parent>%s</parent>\n", oname);
		} else {
			count += fprintf(fp,"\t\t\t<parent>root</parent>\n");
		}
		count += fprintf(fp,"\t\t\t<rank>%d</rank>\n", obj->rank);
		count += fprintf(fp,"\t\t\t<clock>\n", obj->clock);
		count += fprintf(fp,"\t\t\t\t <timestamp>%s</timestamp>\n", convert_from_timestamp(obj->clock,buffer,sizeof(buffer))>0?buffer:"(invalid)");
		count += fprintf(fp,"\t\t\t</clock>\n");
		/* why do latitude/longitude have 2 values?  I currently only store as float in the schema... -dc */
		if (!isnan(obj->latitude))
			count += fprintf(fp,"\t\t\t<latitude>%s</latitude>\n", convert_from_latitude(obj->latitude,buffer,sizeof(buffer))?buffer:"(invalid)");
		else
			count += fprintf(fp, "\t\t\t<latitude>NONE</latitude>\n");
		if (!isnan(obj->longitude))
			count += fprintf(fp,"\t\t\t<longitude>%s</longitude>\n",convert_from_longitude(obj->longitude,buffer,sizeof(buffer))?buffer:"(invalid)");
		else
			count += fprintf(fp,"\t\t\t<longitude>NONE</longitude>\n");

		/* dump properties */
		for (prop=oclass->pmap;prop!=NULL && prop->oclass==oclass;prop=prop->next)
		{
			char *value = NULL;
			if((prop->access != PA_PUBLIC) && (prop->access != PA_REFERENCE))
				continue;
			value = object_property_to_string(obj,prop->name);
			if (value!=NULL){
				count += fprintf(fp, "\t\t\t<%s>%s</%s>\n", prop->name, value, prop->name);
			}
		}
		pclass = oclass->parent;
		while(pclass != NULL){ /* inherited properties */
			for (prop=pclass->pmap;prop!=NULL && prop->oclass==pclass;prop=prop->next){
				char *value = object_property_to_string(obj,prop->name);
				if (value!=NULL){
					count += fprintf(fp, "\t\t\t<%s>%s</%s>\n", prop->name, value, prop->name);
				}
			}
			pclass = pclass->parent;
		}
		count += fprintf(fp,"\t\t</object>\n");
	}
	return count;
}