
/** \file AppMain.cpp
	\brief implementace třídy CAppMain
*/

#include "StdAfx.h"
#include "AppMain.h"


CAppMain::CAppMain(void)
{
	//MR tady chybí nulování proměnných, popřípadě jejich nastavení
	TRACE("Entering CAppMain constuctor\n");
}

CAppMain::~CAppMain(void)
{
	TRACE("Leaving  CAppMain destructor\n");
}
 
//Metody rozhranni kamery
void CAppMain::SetCamera(int width, int height, int distanceO)
{
	m_camera.SetSize(width, height);
	m_camera.SetDistanceO(distanceO);
	m_camera.SetReady(true);
}


CPrimitiveBase* CAppMain::CreateLayer(CPrimitiveBase* pPB)
{
	if (pPB == NULL)
	{
	 TRACE("ERRORR - not add NULL object to layer \n");
	}
	else
	{
	TRACE("Add object to layer %s\n",pPB->GetName() );

	m_patternManager.AddLayer(pPB);
	}
	return pPB;
}

//Metody rozhranni predlohy
/*MR
CPrimitiveBase* CAppMain::CreateLayer(const char* title, int distance, CStructures::fPoint center, int radius, CStructures::ARGBPixel Object, CStructures::ARGBPixel Env)
{
	TRACE("Circle\n");

	CPrimitiveBase* pPB=NULL;
			
	pPB = new CCircle(distance, center, radius, Object, Env, title);
	m_patternManager.AddLayer(pPB);
	
	return pPB;
}

CPrimitiveBase* CAppMain::CreateLayer(const char* title, int distance, CStructures::iPoint begin, CStructures::iPoint end, int thick, CStructures::ARGBPixel Object, CStructures::ARGBPixel Env)
{
	TRACE("Line\n");

	CPrimitiveBase* pPB=NULL;

	pPB = new CLine(distance, begin, end, thick, Object, Env, title);
	m_patternManager.AddLayer(pPB);
	
	return pPB;
}
*/
/*//MRXXX
void CAppMain::RegisterLayer(CPrimitiveBase *pLayer, int index)
{
	m_patternManager.RegisterLayer(pLayer, index);
}

void CAppMain::RegisterLayer()
{
//MRXXX	m_patternManager.RegisterAll();
}*/
/*MRXXX
int CAppMain::LayerPreview(int width, int height, bool useFile, const char* fileName)
{
	if(m_camera.IsReady())
	{
		m_patternManager.SetProjDistance(m_camera.GetDistanceToO());
		m_patternManager.SetResolution(width, height);
		return (m_patternManager.BuildMasterImage(true, useFile, fileName));
	}
	else
	{
		TRACE("\nNejsou nastaveny paramety kamery!\n");
		return 3;
	}

	

}
*/
void CAppMain::RegisterLayer(int posFrom, int posTo)
{
	if(posTo == -1)
		posTo = m_patternManager.GetCountCreated();

	if(posFrom >= 0)
	{
		m_patternManager.RegisterLayer(m_patternManager.GetLayerCreated(posFrom), posTo);
	}
	
}
/*MRXXX
void CAppMain::RemoveRegistredLayer(int index)
{
	m_patternManager.UnregisterLayer(index);
}

void CAppMain::RemoveRegistredLayer()
{
	m_patternManager.UnregisterAll();
}

void CAppMain::RotateLayer(double angleX, double angleY, double angleZ, int layerPos)
{	
	CPrimitiveBase* pBase;

	pBase = m_patternManager.GetLayerCreated(layerPos);

	if(pBase != NULL)
	{
		//rotace v rovive vrstvy
		if(angleZ != 0)
			pBase->Rotate(angleZ);

		//rotace  v prostoru
		pBase->RotXY(angleX, angleY);
	}
	else
	{
		TRACE("Layer not found\n");
	}
}

void CAppMain::TranslateLayer(int dx, int dy, int layerPos)
{
	CPrimitiveBase* pBase;

	pBase = m_patternManager.GetLayerCreated(layerPos);

	if(pBase != NULL)
	{
		pBase->Translate(dx, dy);
	}
	else
	{
		TRACE("Layer not found\n");
	}

}
void CAppMain::LayerXRepetition(int period, int cycles, int layerPos)
{
	CPrimitiveBase* pBase;

	pBase = m_patternManager.GetLayerCreated(layerPos);

	if(pBase != NULL)
	{
		pBase->SetXRepetition(period, cycles);
	}
	else
	{
		TRACE("Layer not found\n");
	}
}
void CAppMain::LayerYRepetition(int period, int cycles, int layerPos)
{
	CPrimitiveBase* pBase;

	pBase = m_patternManager.GetLayerCreated(layerPos);

	if(pBase != NULL)
	{
		pBase->SetYRepetition(period, cycles);
	}
	else
	{
		TRACE("Layer not found\n");
	}
}

void CAppMain::MoveUpLayer(int index)
{
	m_patternManager.MoveUp(index);
}
void CAppMain::MoveDownLayer(int index)
{
	m_patternManager.MoveDown(index);
}
*/
//Metody rozhranni filtru
CFilterBase* CAppMain::CreateFilter(int type, const char* title, double param, bool bSave, bool bDisplay)
{
	CFilterBase* pFB=NULL;

	switch (type)
	{
		case IDF_CAMERA:
			TRACE("Camera\n");
			pFB = new CFilterCamera(0, 0, title);
			pFB->Save(bSave);
			pFB->Display(bDisplay);
			m_filterManager.AddFilter(pFB);
		break;

		case IDF_BARREL:
			TRACE("Barrel\n");
			pFB = new CFilterBarrel(0, 0, title, param);
			pFB->Save(bSave);
			pFB->Display(bDisplay);
			m_filterManager.AddFilter(pFB);
		break;

		case IDF_LIGHTNESS:
			TRACE("Lightness\n");
			pFB = new CFilterLightness(0, 0, title, param);
			pFB->Save(bSave);
			pFB->Display(bDisplay);
			m_filterManager.AddFilter(pFB);
		break;
/*MRXXX
		case IDF_ALIAS:
			TRACE("Alias\n");
			pFB = new CFilterAlias(0, 0, title);
			pFB->Save(bSave);
			pFB->Display(bDisplay);
			m_filterManager.AddFilter(pFB);
		break;
*/
		default:
			pFB = NULL;
			TRACE("Neni vybran typ zkresleni\n");

	}
	
	return pFB;
}


void CAppMain::RegisterFilter(int posFrom, int posTo)
{
	if(posTo == -1)
		posTo = m_filterManager.GetCountCreated();

	if(posFrom >= 0)
	{
		m_filterManager.RegisterFilter(m_filterManager.GetFilterCreated(posFrom), posTo);
	}

}
/*MRXXX
void CAppMain::RegisterFilter()
{
	m_filterManager.RegisterAll();
}
void CAppMain::RemoveRegistredFilter(int index)
{
	m_filterManager.UnregisterFilter(index);
}

void CAppMain::RemoveRegistredFilter()
{
	m_filterManager.UnregisterAll();
}
void CAppMain::MoveUpFilter(int index)
{
	m_filterManager.MoveUp(index);
}
void CAppMain::MoveDownFilter(int index)
{
	m_filterManager.MoveDown(index);
}

//Metoda pro spusteni simulace
int CAppMain::RunSimulation(bool useFile, const char* fileName)
{
	//musi byt nastavena kamera
	if(m_camera.IsReady())
	{//pokracovani simulace


		//vypocet rozmeru vsech filtru
		cout << "Preparing filters...\n";
		if(!m_filterManager.PrepareFilters(&m_camera, &m_patternManager))
			TRACE("\nNejsou vybrany filtry pro vypocet\n");


		//vyber predlohy
		{
			m_patternManager.SetProjDistance(m_camera.GetDistanceToO());	//vzdalenost projekcni roviny = vzdalenost kamery od pocatku
 			m_patternManager.BuildMasterImage(false, useFile, fileName);	//vytvoreni predlohy
			m_filterManager.LoadPattern(m_patternManager.GetPattern());		//predani predlohy filtrum
		}

	
		//spusteni vypoctu
		cout << "Processing...\n";
		if(m_filterManager.StartProcess())
			return 0;
		else
			return 1;
	}
	else
	{
		TRACE("\nNejsou nastaveny paramety kamery!\n"); 
		return 3;
	}
	return 0;
}
*/

//MR nové metody pro vytvoření vzoru
int CAppMain::RunSimulationNew(bool useFile, const char* fileName)
{
	//musi byt nastavena kamera
	if(m_camera.IsReady())
	{//pokracovani simulace


		//vypocet rozmeru vsech filtru
		cout << "Preparing filters...\n";
		if(!m_filterManager.PrepareFilters(&m_camera, &m_patternManager))
			TRACE("\nNejsou vybrany filtry pro vypocet\n");


		//vyber predlohy
		{
			//MR - tady by se měly připravit předlohy - transformace předloh, vzorů a kamer

			//MR - tohle asi nebude potřeba - zahrnuto v předchozím kroku
			m_patternManager.SetProjDistance(m_camera.GetDistanceToO());	//vzdalenost projekcni roviny = vzdalenost kamery od pocatku

			//MR parametry nastavení bude nutné získat z filtermanageru
			CStructures::iPoint rozmer = m_camera.GetSize();
			m_patternManager.SetSize(rozmer.X,rozmer.Y,1,1);
			//MR tohle je nutné nastavovat z appmain
			m_patternManager.Save(true);
			//MR vytváření bude nutné udělat znovu			
			//MR tohle je nutné nastavovat z appmain
			m_patternManager.SetOutputName("kamera.bmp");
 			m_patternManager.BuildMasterImage(false, useFile, fileName);	//vytvoreni predlohy

			m_filterManager.LoadPattern(m_patternManager.GetPattern());		//predani predlohy filtrum
		}

	
		//spusteni vypoctu
		cout << "Processing...\n";
		if(m_filterManager.StartProcess())
			return 0;
		else
			return 1;
	}
	else
	{
		TRACE("\nNejsou nastaveny paramety kamery!\n"); 
		return 3;
	}
	return 0;
}


/*MRXXX
//Metody pro ukladani a nahravani projektu
void CAppMain::Save(const char *pFileName)
{
	TRACE("\n------------------- Saving project -------------------\n");

	TiXmlDocument doc;
	TiXmlDeclaration* decl = new TiXmlDeclaration("1.0","","");
	doc.LinkEndChild(decl);

	TiXmlElement* root = new TiXmlElement("Project"); //Nazev muze byt nahrazen jmenem ukladaneho projektu
	doc.LinkEndChild(root);

	//blok: Settings
	{
		TiXmlElement* settings = new TiXmlElement("Settings");
		root->LinkEndChild(settings);

		TiXmlElement* path = new TiXmlElement("SavePath");
		path->LinkEndChild(new TiXmlText(m_savePath));
		settings->LinkEndChild(path);

		TiXmlElement* fileType = new TiXmlElement("File");
		settings->LinkEndChild(fileType);
		fileType->SetAttribute("type", ".jpg");

	}
	
	//blok: Camera
	{
		CStructures::Point size;
		size = m_camera.GetSize();

		TiXmlElement* camera = new TiXmlElement("Camera");
		root->LinkEndChild(camera);
		camera->SetAttribute("width", size.X);
		camera->SetAttribute("height", size.Y);
		camera->SetAttribute("distanceO", m_camera.GetDistanceToO());
	}

	//blok: Pattern
	{
		int i, type;
		int atPosition = -1;
		CStructures::ARGBPixel pixel;
		CStructures::CenterPoint layerCenter;
		CStructures::Point point;
		CStructures::Angle angles = {0,0,0};
		CPrimitiveBase* pPB;
		bool bUse;



		//<Pattern>
		TiXmlElement* PatternNode = new TiXmlElement("Pattern");
		root->LinkEndChild(PatternNode);
		PatternNode->SetAttribute("name", m_patternManager.GetName());
		PatternNode->SetAttribute("display", m_patternManager.Display());
		PatternNode->SetAttribute("save", m_patternManager.Save());


		
		int count = m_patternManager.GetCountCreated();
		for(i=0; i < count; i++)
		{
			pPB = m_patternManager.GetLayerCreated(i);
			
			//<layer type="" title="" use="" atPosition="">
			TiXmlElement* layerNode = new TiXmlElement("layer");
			PatternNode->LinkEndChild(layerNode);

			type = pPB->GetType();
			bUse = pPB->Use();
			layerNode->SetAttribute("type", type);
			layerNode->SetAttribute("title", pPB->GetName());
			layerNode->SetAttribute("use", bUse);

			if(bUse)
			{
				atPosition++;
				layerNode->SetAttribute("atPosition", atPosition);
			}
			else
			{
				layerNode->SetAttribute("atPosition", -1);
			}
				
				//<distance d =""/>
				TiXmlElement* distance = new TiXmlElement("distance");
				layerNode->LinkEndChild(distance);
				distance->SetDoubleAttribute("d", pPB->GetDistanceToCamera());

				switch (type)
				{
					case IDL_CIRCLE:
						
					{
						//<center x="" y=""/>
						TiXmlElement* center = new TiXmlElement("center");
						layerNode->LinkEndChild(center);
						layerCenter = pPB->GetCenter();
						center->SetDoubleAttribute("x", layerCenter.X);
						center->SetDoubleAttribute("y", layerCenter.Y);

						//<radius r=""/>
						TiXmlElement* radius = new TiXmlElement("radius");
						layerNode->LinkEndChild(radius);
						radius->SetAttribute("r", pPB->GetRadius());
					}
					break;

					case IDL_LINE:
					{
						//<begin x="" y=""/>
						TiXmlElement* begin = new TiXmlElement("begin");
						layerNode->LinkEndChild(begin);
						point = pPB->PointBegin();
						begin->SetAttribute("x", point.X);
						begin->SetAttribute("y", point.Y);

						//<end x="" y=""/>
						TiXmlElement* end = new TiXmlElement("end");
						layerNode->LinkEndChild(end);
						point = pPB->PointEnd();
						end->SetAttribute("x", point.X);
						end->SetAttribute("y", point.Y);

						//<thickness t=""/>
						TiXmlElement* thickness = new TiXmlElement("thickness");
						layerNode->LinkEndChild(thickness);
						thickness->SetAttribute("t", pPB->Thickness());
					}
					break;
				}
				
				//<angle alfa="" beta="" gama="">
				TiXmlElement* angle = new TiXmlElement("angle");
				layerNode->LinkEndChild(angle);
				angles = pPB->GetAngle();
				angle->SetAttribute("alfa", angles.alfa);
				angle->SetAttribute("beta", angles.beta);
				angle->SetAttribute("gama", angles.gama);

				//<color>
				TiXmlElement* colorNode = new TiXmlElement("color");
				layerNode->LinkEndChild(colorNode);

					//<object A="" R="" G="" B=""/>
					TiXmlElement* object = new TiXmlElement("object");
					colorNode->LinkEndChild(object);
					pixel = pPB->GetObjectColor(true);
					object->SetAttribute("A", pixel.A);
					object->SetAttribute("R", pixel.R);
					object->SetAttribute("G", pixel.G);
					object->SetAttribute("B", pixel.B);

					//<env A="" R="" G="" B=""/>
					TiXmlElement* env = new TiXmlElement("env");
					colorNode->LinkEndChild(env);
					pixel = pPB->GetObjectColor(false);
					env->SetAttribute("A", pixel.A);
					env->SetAttribute("R", pixel.R);
					env->SetAttribute("G", pixel.G);
					env->SetAttribute("B", pixel.B);
				//</color>

				//<period>
					TiXmlElement* periodNode = new TiXmlElement("period");
					layerNode->LinkEndChild(periodNode);

					//<repeat x="" y=""/>
					TiXmlElement* repeat = new TiXmlElement("repeat");
					periodNode->LinkEndChild(repeat);
					repeat->SetAttribute("x", pPB->m_XRepeatPeriod);
					repeat->SetAttribute("y", pPB->m_YRepeatPeriod);

					//<count x="" y=""/>
					TiXmlElement* count = new TiXmlElement("count");
					periodNode->LinkEndChild(count);
					count->SetAttribute("x", pPB->m_XPeriodCount);
					count->SetAttribute("y", pPB->m_YPeriodCount);

						
				//</period>
			//</layer>
		//</Pattern>

		}
	}

	//blok: Filtry
	{
		TiXmlElement* FiltersNode = new TiXmlElement("Filters");
		root->LinkEndChild(FiltersNode);

		int i;
		CFilterBase* pFB;
		bool bUse;
		int atPosition = -1;
		int count = m_filterManager.GetCountCreated();

		for(i=0; i < count; i++)
		{
			pFB = m_filterManager.GetFilterCreated(i);

			TiXmlElement* filter = new TiXmlElement("filter");
			FiltersNode->LinkEndChild(filter);
			bUse = pFB->Use();
			filter->SetAttribute("type", pFB->GetType());
			filter->SetAttribute("title", pFB->GetName());
			filter->SetDoubleAttribute("param", pFB->GetParam());
			filter->SetAttribute("save", pFB->Save());
			filter->SetAttribute("display", pFB->Display());
			filter->SetAttribute("use", bUse);

			if(bUse)
			{
				atPosition++;
				filter->SetAttribute("atPosition", atPosition);
			}
			else
			{
				filter->SetAttribute("atPosition", -1);
			}
		}
		
	}

	doc.SaveFile(pFileName);
	
	TRACE("------------------- Saving project succeeded -------------------\n\n");

}

void CAppMain::Save()
{
	FILE* pFile;
	string fileName;

	fileName = m_savePath + m_projName + "\\" + m_projName + ".xml";

	pFile = fopen(fileName.c_str(), "w");
	
}

int CAppMain::Load(const char *pFileName)
{
	TRACE("\n------------------- Loading project -------------------\n");
	TiXmlDocument doc(pFileName);
	if(!doc.LoadFile()) return 1;

	//vyprazdneni vsech seznamu pro nove nacteni
	m_filterManager.Empty();
	m_patternManager.Empty();

	TiXmlHandle hDoc(&doc);
	TiXmlElement* pElem;
	TiXmlHandle hRoot(0);

	pElem = hDoc.FirstChildElement().Element();
	if (!pElem) return 2;

	//m_name = pElem->Value(); //nazev ulozeneho projektu

	hRoot = TiXmlHandle(pElem);

	//blok: Settings
	{
		cout << "\tSettings...\n";
		const char* path;

		pElem = hRoot.FirstChild("Settings").FirstChild().Element();
		if (!pElem) return 2;

		path = pElem->GetText();
		if( path == 0)
		{
			m_savePath = "";
		}
		else
		{
			m_savePath = path;
		}
		
		
		pElem = hRoot.FirstChild("Settings").Child("File",0).Element();
		if (!pElem) return 2;
		m_fileType =  pElem->Attribute("type");
	}

	//blok: Camera
	{
		cout << "\tCamera...\n";
		CStructures::Point size;
		int distanceO;

		pElem = hRoot.FirstChild("Camera").Element();
		if (!pElem) return 2;
		
			pElem->QueryIntAttribute("width", &size.X);
			pElem->QueryIntAttribute("height", &size.Y);
			m_camera.SetSize(size.X, size.Y);

			pElem->QueryIntAttribute("distanceO", &distanceO);
			m_camera.SetDistanceO(distanceO);
			m_camera.SetReady(true);
		
		TRACE("Camera...\n");
		TRACE("width: %d\nheight: %d\ndistanceToOrigin: %d\n", size.X, size.Y, distanceO);
		
	}

	//blok: Patterns
	{
		
		TRACE("\nPatterns...\n");

		CPrimitiveBase* pPB;
		int type, radius, thickness;
		int bUse = 0;
		int atPosition = -1;
		int bDisplay = 1;
		int bSave = 0;
		double distance;
		CStructures::ARGBPixel objColor, envColor;
		CStructures::CenterPoint centerPoint;
		CStructures::Point begin, end;
		CStructures::Angle angles = {0,0,0};
		const char* pTitle;
		const char* pName;
		TiXmlHandle hLayer(0);
		TiXmlHandle hColor(0);
		TiXmlHandle hPeriod(0);

		//<pattern name="" display="" save="">
		TiXmlElement* pPattern = hRoot.FirstChild("Pattern").Element();
		if (pPattern != NULL)
		{
			cout << "\tPatterns...\n";

			pName = pPattern->Attribute("name");
			pPattern->QueryIntAttribute("display", &bDisplay);
			pPattern->QueryIntAttribute("save", &bSave);

			m_patternManager.Rename(pName);
			m_patternManager.Display(bDisplay);
			m_patternManager.Save(bSave);


			TiXmlElement* pLayerNode = hRoot.FirstChild("Pattern").FirstChild().Element();
			if (!pLayerNode) return 2;
			//pro vsechny elementy <layer type="" title="" use=""/>
			for(pLayerNode; pLayerNode; pLayerNode=pLayerNode->NextSiblingElement())
			{
				hLayer = TiXmlHandle(pLayerNode);

				pLayerNode->QueryIntAttribute("type", &type);
				pTitle = pLayerNode->Attribute("title");
				pLayerNode->QueryIntAttribute("use", &bUse);
				pLayerNode->QueryIntAttribute("atPosition", &atPosition);

				//<distance d=""/>
				pElem = hLayer.FirstChild("distance").Element();
				if (!pElem) return 2;
				pElem->QueryDoubleAttribute("d", &distance);

				switch (type)
				{
					case IDL_CIRCLE:
						{
						//<center x="" y=""/>
						pElem = hLayer.FirstChild("center").Element();
						if (!pElem) return 2;
						pElem->QueryFloatAttribute("x", &centerPoint.X);
						pElem->QueryFloatAttribute("y", &centerPoint.Y);

						//<radius r=""/>
						pElem = hLayer.FirstChild("radius").Element();
						if (!pElem) return 2;
						pElem->QueryIntAttribute("r", &radius);
						}
					break;

					case IDL_LINE:
						{
						//<begin x="" y=""/>
						pElem = hLayer.FirstChild("begin").Element();
						if (!pElem) return 2;
						pElem->QueryIntAttribute("x", &begin.X);
						pElem->QueryIntAttribute("y", &begin.Y);

						//<end x="" y=""/>
						pElem = hLayer.FirstChild("end").Element();
						if (!pElem) return 2;
						pElem->QueryIntAttribute("x", &end.X);
						pElem->QueryIntAttribute("y", &end.Y);

						//<thickness t=""/>
						pElem = hLayer.FirstChild("thickness").Element();
						if (!pElem) return 2;
						pElem->QueryIntAttribute("t", &thickness);
						}
					break;
				}

				//<angle alfa="" beta="" gama="">
				pElem = hLayer.FirstChild("angle").Element();
				if (!pElem) return 2;
				pElem->QueryFloatAttribute("alfa", &angles.alfa);
				pElem->QueryFloatAttribute("beta", &angles.beta);
				pElem->QueryFloatAttribute("gama", &angles.gama);

				//<color>
				pElem = hLayer.FirstChild("color").Element();
				if (!pElem) return 2;
				hColor = TiXmlHandle(pElem);

					//<object A="" R="" G="" B=""/>
					pElem = hColor.FirstChild("object").Element();
					if (!pElem) return 2;
					pElem->QueryFloatAttribute("A", &objColor.A);
					pElem->QueryFloatAttribute("R", &objColor.R);
					pElem->QueryFloatAttribute("G", &objColor.G);
					pElem->QueryFloatAttribute("B", &objColor.B);

					//<env A="" R="" G="" B=""/>
					pElem = hColor.FirstChild("env").Element();
					if (!pElem) return 2;
					pElem->QueryFloatAttribute("A", &envColor.A);
					pElem->QueryFloatAttribute("R", &envColor.R);
					pElem->QueryFloatAttribute("G", &envColor.G);
					pElem->QueryFloatAttribute("B", &envColor.B);

				switch (type)
				{
					case IDL_CIRCLE:
						pPB = CreateLayer(pTitle, distance, centerPoint, radius, objColor, envColor);
					break;
					case IDL_LINE:
						pPB = CreateLayer(pTitle, distance, begin, end, thickness, objColor, envColor);
					break;
				}

				//natoceni vzoru
				if(angles.gama != 0)
					pPB->Rotate(angles.gama);
				if(angles.alfa != 0 || angles.beta != 0)
					pPB->RotXY(angles.alfa, angles.beta);

				//Zarazeni vrstvy do vzoru
				if((bool)bUse && pPB!=NULL)
					m_patternManager.RegisterLayer(pPB, atPosition);
				
				
				pElem = hLayer.FirstChild("period").Element();
				if (!pElem) return 2;
				hPeriod = TiXmlHandle(pElem);
					
					pElem = hPeriod.FirstChild("repeat").Element();
					if (!pElem) return 2;
					pElem->QueryIntAttribute("x", &pPB->m_XRepeatPeriod);
					pElem->QueryIntAttribute("y", &pPB->m_YRepeatPeriod);

					pElem = hPeriod.FirstChild("count").Element();
					if (!pElem) return 2;
					pElem->QueryIntAttribute("x", &pPB->m_XPeriodCount);
					pElem->QueryIntAttribute("y", &pPB->m_YPeriodCount);
			}//end if(pPattern != NULL)
		}
		
	}

	//blok: Filtry
	{
		
		TRACE("Filters...\n");

		CFilterBase* pFB;
		int type;
		const char* pTitle;
		double param = 0;
		int bSave,bDisplay;
		int bUse = 0;
		int atPosition = -1;
		int xRatio = 1;
		int yRatio = 1;
		CStructures::Supersample supersample;

		TiXmlElement* pFiltersNode = hRoot.FirstChild("Filters").FirstChild().Element();
		if (pFiltersNode != NULL)
		{
			cout << "\tFilters...\n";

			for(pFiltersNode; pFiltersNode; pFiltersNode=pFiltersNode->NextSiblingElement())
			{
				pFiltersNode->QueryIntAttribute("type", &type);
				pTitle = pFiltersNode->Attribute("title");
				pFiltersNode->QueryDoubleAttribute("param",&param);
				pFiltersNode->QueryIntAttribute("save", &bSave);
				pFiltersNode->QueryIntAttribute("display", &bDisplay);
				pFiltersNode->QueryIntAttribute("use", &bUse);
				pFiltersNode->QueryIntAttribute("atPosition", &atPosition);

				switch(type)
				{
					case IDF_CAMERA:
					case IDF_BARREL:
					case IDF_LIGHTNESS:
						pFB = CreateFilter(type, pTitle, param, bSave, bDisplay);
					break;

					case IDF_ALIAS:
						pFiltersNode->QueryIntAttribute("xRatio", &xRatio);
						pFiltersNode->QueryIntAttribute("yRatio", &yRatio);
						supersample.X = xRatio;
						supersample.Y = yRatio;
						pFB = CreateFilter(type, pTitle, param, bSave, bDisplay);
						if(pFB != NULL && bUse)
						{
							pFB->SetSupersample(supersample);
							m_patternManager.SetSupersample(supersample); //Nastaveni prevzorkovani pro predlohu
						}
					break;
				};
				

				if((bool)bUse && pFB !=NULL)
					m_filterManager.RegisterFilter(pFB, atPosition);
			}
		}
		
	}

	TRACE("------------------- Project load succeeded -------------------\n\n");
	return 0;
	
}
*/