#pragma once
#include "INKSDoc.h"
#include "INKS.h"
#include "TreeBar.h"

class CElementContainer
{
	friend class CINKSDoc;
	friend class CINKSApp;
	friend class CTreeBar;
	friend class CSideBar;

public:
	CElementContainer();
	~CElementContainer();
	void ClearParsedContent();
	TiXmlDocument* GetDoc(CString strFilename);
	bool OpenProject(CString strProject);
	bool OpenProjectSpecific(CString strElementName, CString strProjectPath); // reads project specific element and stores to container
	void OpenProjectSpecific(CString strProjectPath, int nWhich); // nWhich 0-all, 1-gates, 2-blocks
	bool OpenProjectSpecific(CString strFilename); // parses specific file to project
	void OpenAppSpecific(CString strAppPath, int nWhich); // nWhich 0-all, 1-gates, 2-blocks
	
	bool OpenAppSpecific(CString strElemName); // reads app specific element and stores to container

	bool ContainsElement(CString strElementName);
	bool CanContainElement(CString strElementName);
	bool CanAppContainElement(CString strElementName);
	bool CanProContainElement(CString strElementName);
	CString AssociateFile(CString strElementName, CString strPath); // tries to find file that describe strElementName in strPath path
	bool OpenFile(CString strFilename, CString strPath);
	CCommonObject *GetCommonObject(CString strElement);

private:
	void ParseDir(CString strPath);
	void ParseFile(CString strFile);

public:

private:
	// variable content
	CString m_strFileToParse;
	CString m_strFileToParsePath;

	CString m_strFilename;
	CString m_strFilePath;
	CString m_strDisplayName;
	CString m_strOrigin;
	CString m_strType;
	int m_nType;
	//CString m_strOriginF;

	int m_nParsedOK;
	int m_nParsedNOK;

	int m_nIn;
	int m_nOut;
	bool *m_bInvIn;
	bool *m_bInvOut;
	CRect *m_RectIn;
	CRect *m_RectOut;
	CString *m_strIns;
	CString *m_strOuts;
	// constant content;
	CMap<CString, LPCTSTR, CCommonObject*, CCommonObject*> m_GateMap; // key+pobject
	CMap<CString, LPCTSTR, CCommonObject*, CCommonObject*> m_BlockMap; // key+filename
	CMap<CString, LPCTSTR, CCommonObject*, CCommonObject*> m_OthersMap; // key+filename

	CStringList m_slGateNames;
	CStringList m_slWireNames;
	CStringList m_slBlockNames;
	CStringList m_slOtherNames;

	int m_nGatesCount;
	int m_nWiresCount;
	int m_nBlocksCount;
	int m_nOthersCount;

	GraphicsPath m_gPath;
	GraphicsPath m_gPathText;

};
