/***************************************************************************
 *   Copyright (C) 2009 by Juergen Thies                                   *
 *   layout@juergenthies.de                                                *
 *                                                                         *
 ***************************************************************************/
#include "schematic/schematic.h"
#include "schematic/sheet.h"

void macro::sheetHandler_registerKeywords(keywords **keyword_){
  *keyword_= new keywords(*keyword_);
 (*keyword_)->keyword="sheet";
 (*keyword_)->type=type;
 (*keyword_)->typeHandler=&macro::sheetHandler_typeHandler;
}

void macro::sheetHandler_typeHandler(int *counter,keywords **keyword_,bool single){
generalTypeProcessing(counter,keyword_,ptrSheet,ptrSheet,single);
}

returnValue macro::sheetHandler_classHandler(int *counter, keywords *keyword_,returnValue* r,bool left){
 QString s;
 returnValue ret;
 parserValue p;
 if (r->type==ptrSheet){
   if (checkClassPointer(counter)) {
   }
   else { 
   	if (left) { compute(r,counter,keyword_);return ret;}
     	else return *r;
	}
   }
 sheet *l= r->getSheet();
 p=next(counter);
;
 // variables
 if ((p.type==keyword)&&(p.value=="sheetName")){
 		returnValue r2;
		r2.type=varString;
		r2.deleteAfter=false;
		r2.s=&(l->sheetName);
		r2=stringHandler_classHandler(counter,keyword_,&r2,left);
		return r2;}
 else if ((p.type==keyword)&&(p.value=="firstElement")){
 		returnValue r2;
		r2.setType(ptrSElementList);
		r2.deleteAfter=false;
		r2.SElementlist=(l->firstElement);
		r2=sElementListHandler_classHandler(counter,keyword_,&r2,left);
		return r2;}

else if ((p.type==keyword)&&(p.value=="getDevice")){ testParenOpen(counter);
	returnValue p1=calculate(counter,keyword_);
	testParenClose(counter);
	ret.setPtrSElement(l->getDevice(p1.getString()));
	ret=sElementHandler_classHandler(counter,keyword_,&ret,false);}
else if ((p.type==keyword)&&(p.value=="existsDevicename")){
 		testParenOpen(counter);
		returnValue p1=calculate(counter,keyword_);
		testParenClose(counter);
		ret.setBool(l->existsDevicename(p1.getString()));
 	}
 else {
  	error->addItem(tr("Class sheet has no member ")+p.value,1,message((*counter)));
	throw 1;
 	}
 if (left)  if (!checkSemicolon(counter)) {throw 15;}  
 return ret;
}

