/*!\file KML_Icon.cpp
 * \brief: implementation of the kml_feature abstract object
 */

/*Headers:*/
/*{{{*/
#ifdef HAVE_CONFIG_H
	#include <config.h>
#else
#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
#endif

#include <stdio.h>
#include <string.h>
#include "../objects.h"
#include "../../../shared/shared.h"
#include "../../../io/io.h"
#include "../../../Container/Container.h"
#include "../../../include/include.h"
/*}}}*/

/*Constructors/destructor/copy*/
/*FUNCTION KML_Icon::KML_Icon(){{{*/
KML_Icon::KML_Icon(){

	strcpy(href      ,"");
	strcpy(refmode   ,"onChange");
	refint    = 4.;
	strcpy(vrefmode  ,"never");
	vreftime  = 4.;
	vboundsc  = 1.;
	strcpy(vformat   ,"");
	strcpy(hquery    ,"");

}
/*}}}*/
/*FUNCTION KML_Icon::~KML_Icon(){{{*/
KML_Icon::~KML_Icon(){

	;

}
/*}}}*/

/*Other*/
/*FUNCTION KML_Icon::Echo {{{*/
void  KML_Icon::Echo(){

	bool  flag=true;

	if(flag) _pprintLine_("KML_Icon:");
	KML_Object::Echo();

	if(flag) _pprintLine_("          href: \"" << href << "\"");
	if(flag) _pprintLine_("       refmode: \"" << refmode << "\"");
	if(flag) _pprintLine_("        refint: " << refint);
	if(flag) _pprintLine_("      vrefmode: \"" << vrefmode << "\"");
	if(flag) _pprintLine_("      vreftime: " << vreftime);
	if(flag) _pprintLine_("      vboundsc: " << vboundsc);
	if(flag) _pprintLine_("       vformat: \"" << vformat << "\"");
	if(flag) _pprintLine_("        hquery: \"" << hquery << "\"");

	return;
}
/*}}}*/
/*FUNCTION KML_Icon::DeepEcho {{{*/
void  KML_Icon::DeepEcho(){

	char  indent[81]="";

	KML_Icon::DeepEcho(indent);

	return;
}
/*}}}*/
/*FUNCTION KML_Icon::DeepEcho {{{*/
void  KML_Icon::DeepEcho(const char* indent){

	bool  flag=true;

	if(flag) _pprintLine_(indent << "KML_Icon:");
	KML_Object::DeepEcho(indent);

	if(flag) _pprintLine_(indent << "          href: \"" << href << "\"");
	if(flag) _pprintLine_(indent << "       refmode: \"" << refmode << "\"");
	if(flag) _pprintLine_(indent << "        refint: " << refint);
	if(flag) _pprintLine_(indent << "      vrefmode: \"" << vrefmode << "\"");
	if(flag) _pprintLine_(indent << "      vreftime: " << vreftime);
	if(flag) _pprintLine_(indent << "      vboundsc: " << vboundsc);
	if(flag) _pprintLine_(indent << "       vformat: \"" << vformat << "\"");
	if(flag) _pprintLine_(indent << "        hquery: \"" << hquery << "\"");

	return;
}
/*}}}*/
/*FUNCTION KML_Icon::Write {{{*/
void  KML_Icon::Write(FILE* filout,const char* indent){

	fprintf(filout,"%s<Icon",indent);
	WriteAttrib(filout," ");
	fprintf(filout,">\n");
	WriteCommnt(filout,indent);

	KML_Object::Write(filout,indent);

	if (href     && strlen(href))
		fprintf(filout,"%s  <href>%s</href>\n",indent,href);
	if (refmode  && strlen(refmode))
		fprintf(filout,"%s  <refreshMode>%s</refreshMode>\n",indent,refmode);
	fprintf(filout,"%s  <refreshInterval>%g</refreshInterval>\n",indent,refint);
	if (vrefmode && strlen(vrefmode))
		fprintf(filout,"%s  <viewRefreshMode>%s</viewRefreshMode>\n",indent,vrefmode);
	fprintf(filout,"%s  <viewRefreshTime>%g</viewRefreshTime>\n",indent,vreftime);
	fprintf(filout,"%s  <viewBoundScale>%g</viewBoundScale>\n",indent,vboundsc);
	if (vformat  && strlen(vformat))
		fprintf(filout,"%s  <viewFormat>%s</viewFormat>\n",indent,vformat);
	if (hquery   && strlen(hquery))
		fprintf(filout,"%s  <httpQuery>%s</httpQuery>\n",indent,hquery);

	fprintf(filout,"%s</Icon>\n",indent);

	return;
}
/*}}}*/
/*FUNCTION KML_Icon::Read {{{*/
void  KML_Icon::Read(FILE* fid,char* kstr){

	char*        kstri;
	int          ncom=0;
	char**       pcom=NULL;

/*  get object attributes and check for solo tag  */

	if (KMLFileTagAttrib(this,
						 kstr))
		return;

/*  loop over and process fields within opening and closing tags  */

	while (kstri=KMLFileToken(fid,
							  &ncom,&pcom)) {
		if      (!strncmp(kstri,"</Icon", 6)) {
			xfree((void**)&kstri);
			break;
		}
		else if (!strncmp(kstri,"</",2))
		  {_error2_("KML_Icon::Read -- Unexpected closing tag " << kstri << ".\n");}
		else if (strncmp(kstri,"<",1))
		  {_error2_("KML_Icon::Read -- Unexpected field \"" << kstri << "\".\n");}

		else if (!strcmp(kstri,"<href>"))
			KMLFileTokenParse( href      ,NULL,KML_ICON_HREF_LENGTH, kstri, fid);
		else if (!strcmp(kstri,"<refreshMode>"))
			KMLFileTokenParse( refmode   ,NULL,KML_ICON_REFMODE_LENGTH, kstri, fid);
		else if (!strcmp(kstri,"<refreshInterval>"))
			KMLFileTokenParse(&refint    , kstri, fid);
		else if (!strcmp(kstri,"<viewRefreshMode>"))
			KMLFileTokenParse( vrefmode  ,NULL,KML_ICON_VREFMODE_LENGTH, kstri, fid);
		else if (!strcmp(kstri,"<viewRefreshTime>"))
			KMLFileTokenParse(&vreftime  , kstri, fid);
		else if (!strcmp(kstri,"<viewBoundScale>"))
			KMLFileTokenParse(&vboundsc  , kstri, fid);
		else if (!strcmp(kstri,"<viewFormat>"))
			KMLFileTokenParse( vformat   ,NULL,KML_ICON_VFORMAT_LENGTH, kstri, fid);
		else if (!strcmp(kstri,"<httpQuery>"))
			KMLFileTokenParse( hquery    ,NULL,KML_ICON_HQUERY_LENGTH, kstri, fid);

		else if (!strncmp(kstri,"<",1))
			KML_Object::Read(fid,kstri);

		xfree((void**)&kstri);
	}

	this->AddCommnt(ncom,pcom);

	for (ncom; ncom>0; ncom--)
		xfree((void**)&(pcom[ncom-1]));
	xfree((void**)&pcom);

	return;
}
/*}}}*/
