#pragma once
#include "McDbPlotSettings.h"
#include "McDbEntity.h"

class McDbLayoutImp;

// -------------------------------------------------------------------------
// Summary:
// 		一个McDbLayout对象储存每个图纸空间布局的属性。布局对象储存在McDbLayoutDictionary对象中，允许简单的遍历和索引
// Remarks:
// 		例如:得到控件所有的布局函数
// 		<code>
// 			bool GetAllLayoutName(McDbDatabase* pDatabase,
// 								  std::vector<MxString>& allLayoutName)
// 			{
// 				if(pDatabase == NULL)
// 				{
// 					if(Mx::mcdbHostApplicationServices() != NULL)
// 						pDatabase =  Mx::mcdbHostApplicationServices()->workingDatabase();
// 				}
// 
// 				if(pDatabase == NULL)
// 				{
// 
// 					return false;
// 				}
// 
// 				McDbDictionary* pDict = NULL;
// 				if(pDatabase->getLayoutDictionary(pDict,McDb::kForRead) != Mcad::eOk)
// 				{
// 
// 					return false;
// 				}
// 
// 				McDbDictionaryIterator* pIter = pDict->newIterator();
// 				for(;!pIter->done();pIter->next() )
// 				{
// 					McDbObjectPointer<McDbLayout> spLayout(pIter->objectId(),McDb::kForRead);
// 					if(spLayout.openStatus() != Mcad::eOk)
// 						continue;
// 
// 					LPCMSTR pszLayoutName = NULL;
// 					spLayout->getLayoutName(pszLayoutName);
// 
// 					MxString sTmpLayoutName(pszLayoutName);
// 
// 					allLayoutName.push_back(sTmpLayoutName);
// 				}
// 
// 				pDict->close();
// 				delete pIter;
// 
// 				return true;
// 			}
// 		</code>
//		设置当前布局名的代码调用，该调用最好在命令中进行
// 		<code>
// 			if(Mx::mcdbHostApplicationServices()->layoutManager()->setCurrentLayout(sLayoutName)
// 			   == Mcad::eOk)
// 			{
// 				return TRUE;
// 			}
// 			else
// 			{
// 				return FALSE;
// 			}
// 		</code>
// -------------------------------------------------------------------------
class ARXDLL McDbLayout : public McDbPlotSettings
{
	// -------------------------------------------------------------------------
	// Summary:
	// 		申明类型信息
	// -------------------------------------------------------------------------
	MCDB_DECLARE_MEMBERS(McDbLayout);
public:
	// -------------------------------------------------------------------------
	// Summary:
	// 		构造函数
	// -------------------------------------------------------------------------
	McDbLayout(void);

	// -------------------------------------------------------------------------
	// Summary:
	// 		析构函数
	// -------------------------------------------------------------------------
	virtual ~McDbLayout(void);

	// -------------------------------------------------------------------------
	// Summary:
	// 		返回布局里显示的块记录对象id
	// -------------------------------------------------------------------------
	McDbObjectId      
		getBlockTableRecordId   () const;

	// -------------------------------------------------------------------------
	// Summary:
	// 		设置布局里显示的块记录对象id
	// Parameters:
	// 		blockTableRecordId	-	块记录对象id
	// Returns:
	// 		如果成功返回Mcad::eOk，如果传递的数据非法则返回Mcad::eInvalidInput
	// -------------------------------------------------------------------------
	virtual Mcad::ErrorStatus 
		setBlockTableRecordId   (McDbObjectId blockTableRecordId);

	// -------------------------------------------------------------------------
	// Summary:
	// 		把一个新的布局对象增加到数据库中
	// Parameters:
	// 		towhichDb			-	数据库对象
	//		blockTableRecordId	-	布局里显示的块记录对象id
	// Returns:
	// 		如果成功返回Mcad::eOk
	// -------------------------------------------------------------------------
	virtual Mcad::ErrorStatus 
		addToLayoutDict         (McDbDatabase *towhichDb,
		McDbObjectId blockTableRecordId);

	// -------------------------------------------------------------------------
	// Summary:
	// 		返回布局对象名称
	// -------------------------------------------------------------------------
	Mcad::ErrorStatus 
		getLayoutName           (MxString& pszLayoutName) const;


	// -------------------------------------------------------------------------
	// Summary:
	// 		设置布局对象名称
	// Parameters:
	// 		layoutName	-	布局对象名称
	// Returns:
	// 		如果成功返回Mcad::eOk，如果传递的数据非法则返回Mcad::eInvalidInput
	// -------------------------------------------------------------------------
	virtual Mcad::ErrorStatus 
		setLayoutName           (LPCMSTR layoutName);

	// -------------------------------------------------------------------------
	// Summary:
	// 		当前布局是否在模型空间
	// Remarks:
	// 		例如:判断当前是否处在模型空间
	// 		<code>
	// 			BOOL IsModelSpace()
	// 			{
	// 				McDbObjectPointer<McDbLayout> spLayout(Mx::mcdbHostApplicationServices()->layoutManager()->currentLayoutId(),McDb::kForRead);
	// 				if(spLayout.openStatus() != Mcad::eOk)
	// 					return FALSE;
	// 
	// 				if(spLayout->IsModelSpace() )
	// 				{
	// 					return TRUE ;
	// 				}
	// 
	// 				return FALSE;
	// 			}
	// 		</code>
	// -------------------------------------------------------------------------
	bool IsModelSpace() const;

	// -------------------------------------------------------------------------
	// Summary:
	// 		返回当前的视口对象id.
	// -------------------------------------------------------------------------

	McDbObjectId activeViewportId() const;

	//:Ignore



	virtual  Mcad::ErrorStatus dwgInFields (McDbDwgFiler* pFiler);

	virtual  Mcad::ErrorStatus dwgOutFields(McDbDwgFiler* pFiler) const;


	const McGePoint2d& getLIMMIN() const;

	void setLIMMIN(
		const McGePoint2d& limMin);


	const McGePoint2d& getLIMMAX() const;

	void setLIMMAX(
		const McGePoint2d& limMax);


	const McGePoint3d& getEXTMIN() const;


	void setEXTMIN(
		const McGePoint3d& extMin);


	const McGePoint3d& getEXTMAX() const;


	void setEXTMAX(
		const McGePoint3d& extMax);


	const McGePoint3d& getINSBASE() const;


	void setINSBASE(
		const McGePoint3d& insBase);


	bool getLIMCHECK() const;


	void setLIMCHECK(
		bool limCheck);


	bool getPSLTSCALE() const;


	void setPSLTSCALE(
		bool psLtScale);


	int
		getTabOrder() const;

	void
		setTabOrder(int newOrder);

	bool
		getTabSelected() const;

	void
		setTabSelected(Mdesk::Boolean tabSelected);

	McDbObjectIdArray
		getViewportArray() const;

	bool
		annoAllVisible() const;

	Mcad::ErrorStatus
		setAnnoAllVisible(bool newVal);

public:
	

	inline McDbLayoutImp* getLayoutImp() const {
		return (McDbLayoutImp*)m_pImp;
	}

	//:End Ignore
};


class ARXDLL McDbDwgBackground : public McDbEntity
{
public:
	struct stuDwgData {
		McDbDatabase* pDatabase;
		McGeMatrix3d*  pMatrix;
		McCmColor*      pColor;
		bool                  isShow;
		std::set<McDbObjectId>* pSetVisibilityEntity;
		stuDwgData() {
			pDatabase = 0;
			pMatrix = 0;
			pColor = 0;
			isShow = true;
			pSetVisibilityEntity = 0;
		}
	};

	MCDB_DECLARE_MEMBERS(McDbDwgBackground);
	McDbDwgBackground(void);
	virtual ~McDbDwgBackground(void);
	virtual Mdesk::Boolean		worldDraw(McGiWorldDraw * wd);
	bool clearAll();
	bool addDwg(const MxString& sDwg, const McGeMatrix3d* pMat = 0);
	bool clearDwg(const MxString& sDwg);
	bool isEmpty();
	bool setDwgReplaceColor(const MxString& sDwg, const McCmColor* pColor);
	bool setDwgReplaceColor(McDbDatabase* pDatabase, const McCmColor* pColor);
	bool setVisibilityEntitys(McDbDatabase* pDatabase,std::set<McDbObjectId>* pSetVisibilityEntity);

	McDbDatabase* getDatabase(const MxString& sDwg);

	void setShow(const MxString& sDwg, bool isShow);

	stuDwgData* getData(McDbDatabase* pDatabase);

	bool isShow(const MxString& sDwg);
private:
	std::map<MxString, stuDwgData*> m_mapData;
};