#pragma once
#include "McDbEntity.h"

class McDbRasterImageImp;
// -------------------------------------------------------------------------
// Summary:
// 		光栅图片类，该类用于在CAD中显示光栅图形
// Remarks:
// 		例如:插入一个光栅图的例程代码
// 		<code>
// 			void CDrawCommand::InsertImage()
// 			{
// 				CFileDialog openDlg(TRUE,_T("jpg"),NULL,
// 					OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
// 					_T("jpg(*.jpg) | *.jpg|bmp(*.bmp) | *.bmp|tif(*.tif) | *.tif||"),
// 					MxDraw::GetMxDrawWnd(MxDraw::GetCurOcxHandle() ) );
// 
// 				MxString sInitialDir = AfxGetApp()->GetProfileString(_T("MxDraw"),
// 					_T("InsertImager"),Mx::GetAppPath() );
// 
// 				MxString sFileName;
// 				openDlg.m_ofn.lpstrInitialDir= sInitialDir; //设置打开文件的缺省路径
// 				if(openDlg.DoModal() == IDOK)
// 				{
// 					sFileName = openDlg.GetPathName();
// 				}
// 				else
// 				{
// 					return;
// 				}
// 
// 				int iFindPos = sFileName.ReverseFind('\\');
// 				if(iFindPos >= 0)
// 				{
// 					MxString sPath = sFileName.Left(iFindPos + 1);
// 					AfxGetApp()->WriteProfileString(_T("MxDraw"),_T("InsertImager"),sPath);
// 				}
// 
// 				double dW = 10;
// 				double dH = 10;
// 
// 				{
// 					// 得到相关图片消息
// 					Gdiplus::Image tmpImage(sFileName);
// 					if(tmpImage.GetLastStatus() != Gdiplus::Ok)
// 					{
// 						acutPrintf(_T("\n 图片文件不能打开"));
// 						return;
// 					}
// 					dW =  tmpImage.GetWidth() / 10.0;
// 					dH =  tmpImage.GetHeight() / 10.0;
// 				}
// 
// 				// 得到插入点。
// 				mds_point apt;
// 				int iRet = Mx::mcedGetPoint(NULL,_T("\n 指定插入点:"),apt);
// 				if(iRet  != RTNORM)
// 					return;
// 
// 				MxString sName = sFileName;
// 				{
// 					sName = MxT::AnalyzeFileName(sFileName,FALSE);	
// 				}
// 				if(sName.IsEmpty() )
// 				{
// 					MXASSERT(0);
// 					return;
// 				}
// 
// 				// 在字典对对象中创建图片定义对象。
// 				McDbDatabase* pDatabase = Mx::mcdbHostApplicationServices()->workingDatabase();
// 				McDbDictionary* pDict = NULL;
// 				pDatabase->getNamedObjectsDictionary(pDict,McDb::kForWrite);
// 				if(pDict == NULL)
// 					return;
// 				//
// 
// 
// 				McDbObjectId imageDictId;
// 				if(pDict->getAt(MCAD_IMAGE_DICT_NAME,imageDictId) != Mcad::eOk)
// 				{
// 					// 创建该字典.
// 					McDbDictionary* pImageDict = new McDbDictionary;
// 					if(pDict->setAt(MCAD_IMAGE_DICT_NAME,
// 						pImageDict,imageDictId) != Mcad::eOk)
// 					{
// 						MXASSERT(0);
// 						delete pImageDict;
// 						pImageDict = NULL;
// 					}
// 					else
// 					{
// 						pImageDict->close();
// 					}
// 				}
// 
// 				pDict->close();
// 
// 				McDbObjectId imageDefId;
// 				if(!imageDictId.isNull() )
// 				{
// 					McDbObjectPointer<McDbDictionary> spImageDict(imageDictId,McDb::kForWrite);
// 					if(spImageDict.openStatus() == Mcad::eOk)
// 					{
// 						if(spImageDict->getAt(sName,imageDefId) != Mcad::eOk)
// 						{
// 							// 添加图象定义.
// 							McDbRasterImageDef* pNewImageDef = new McDbRasterImageDef;
// 							pNewImageDef->setSourceFileName(sFileName );
// 
// 							if(spImageDict->setAt(sName,
// 								pNewImageDef,imageDefId) != Mcad::eOk)
// 							{
// 								MXASSERT(0);
// 								delete pNewImageDef;
// 								pNewImageDef = NULL;
// 							}
// 							else
// 							{
// 								pNewImageDef->close();
// 							}
// 						}
// 					}
// 				}
// 
// 				if(!imageDefId.isNull() )
// 				{
// 					// 创建Ｉmage实例。
// 					McDbRasterImage* pImage = new McDbRasterImage;
// 					McGeVector3d uCorner  = McGeVector3d::kXAxis * dW;
// 					McGeVector3d vOnPlane = McGeVector3d::kYAxis * dH;
// 
// 					pImage->setOrientation(	asPnt3d(apt),uCorner,vOnPlane);
// 					pImage->setImageDefId(imageDefId);
// 
// 					MrxDbgUtils::addToCurrentSpaceAndClose(pImage);
// 				}
// 			}
// 		</code>
// -------------------------------------------------------------------------
class ARXDLL McDbRasterImage : public McDbEntity
{
public:
	// -------------------------------------------------------------------------
	// Summary:
	// 		申明类型信息
	// -------------------------------------------------------------------------
	MCDB_DECLARE_MEMBERS(McDbRasterImage);

	// -------------------------------------------------------------------------
	// Summary:
	// 		构造函数
	// -------------------------------------------------------------------------
	McDbRasterImage(void);

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

	//:Ignore
	enum ImageDisplayOpt
	{
		kShow          = 1,
		kShowUnAligned = 2,
		kClip          = 4,
		kTransparent   = 8 
	};
	//:End Ignore

	// -------------------------------------------------------------------------
	// Summary:
	// 		设置光栅图的显示位置和缩放比例
	// Parameters:
	// 		origin     	-	光栅图的左下角位置
	//		uCorner   	-	光栅图的宽度方向显示向量，用于确定光栅图的宽度，和旋转角度
	//		vOnPlane  	-	光栅图的高度方向显示向量，该向量必须垂直vConer，确定光栅图的高度
	// Returns:
	// 		成功返回Mdesk:kTrue
	// -------------------------------------------------------------------------
	Mdesk::Boolean		setOrientation(
		const McGePoint3d&	origin,
		const McGeVector3d&	uCorner,
		const McGeVector3d&	vOnPlane);	

	// -------------------------------------------------------------------------
	// Summary:
	// 		返回光栅图的显示位置和缩放比例
	// Parameters:
	//		origin     	-	光栅图的左下角位置
	//		uCorner   	-	光栅图的宽度方向显示向量，用于确定光栅图的宽度，和旋转角度
	//		vOnPlane  	-	光栅图的高度方向显示向量，该向量必须垂直vConer，确定光栅图的高度
	// -------------------------------------------------------------------------
	void				getOrientation(
		McGePoint3d&		origin,
		McGeVector3d&	u,
		McGeVector3d&	v) const;	


	// -------------------------------------------------------------------------
	// Summary:
	// 		设置光栅图形定义对象ID
	// Parameters:
	// 		imageId	-	光栅图形定义对象ID
	// Returns:
	// 		如果成功返回Mcad::eOk，如果传递的数据非法则返回Mcad::eInvalidInput
	// -------------------------------------------------------------------------
	Mcad::ErrorStatus	setImageDefId(McDbObjectId imageId);

	// -------------------------------------------------------------------------
	// Summary:
	// 		返回光栅图形定义对象ID
	// -------------------------------------------------------------------------
	McDbObjectId		imageDefId() const;

	//:Ignore

	virtual Mdesk::Boolean worldDraw(McGiWorldDraw* mode);

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

	virtual Mcad::ErrorStatus   getGeomExtents(McDbExtents& extents, bool roughCalculation = true) const;

	virtual Mcad::ErrorStatus   getOsnapPoints(
		McDb::OsnapMode     osnapMode,
		int                 gsSelectionMark,
		const McGePoint3d&  pickPoint,
		const McGePoint3d&  lastPoint,
		const McGeMatrix3d& viewXform,
		McGePoint3dArray&   snapPoints,
		McDbIntArray&       geomIds) const;

	enum ClipBoundaryType
	{
		kInvalid,
		kRect,
		kPoly
	};

	virtual Mcad::ErrorStatus   setClipBoundary(
		ClipBoundaryType type,
		const McGePoint2dArray&
		);
	virtual const McGePoint2dArray&  clipBoundary() const;
	virtual ClipBoundaryType	clipBoundaryType() const;
	void  setClipBoundaryType(McDbRasterImage::ClipBoundaryType type);

	Mdesk::Boolean				isClipped() const;



	void setDisplayOpt(
		ImageDisplayOpt optionIndex, 
		bool value);


	bool isSetDisplayOpt(
		ImageDisplayOpt option) const;

	void setBrightness( 
		int brightness );


	int brightness() const;


	void setContrast( 
		int contrast );


	int contrast() const;


	void setFade( 
		int fade );

	void setVertices(McGePoint3dArray& vertices);

	const McGePoint3dArray& getVertices() const;


	const McGeVector2d& getImageSize();

	void setImageSize(const McGeVector2d& size);

	int fade() const;

	virtual Mcad::ErrorStatus   transformBy(const McGeMatrix3d& xform);

	virtual Mcad::ErrorStatus   getGripPoints(
		McGePoint3dArray&  gripPoints,
		McGeIntArray&  osnapModes,
		McGeIntArray&  geomIds) const;

	virtual Mcad::ErrorStatus moveGripPointsAt(const McGeIntArray& indices,
		const McGeVector3d& offset);

public:
	//:End Ignore
};


class ARXDLL McDbWipeout : public McDbRasterImage
{
public:
	MCDB_DECLARE_MEMBERS(McDbWipeout);
	McDbWipeout(void);
	virtual ~McDbWipeout(void);
	virtual Mdesk::Boolean worldDraw(McGiWorldDraw* mode);
	virtual Mcad::ErrorStatus   getGeomExtents(McDbExtents& extents, bool roughCalculation = true) const;


	Mcad::ErrorStatus   getGripPoints(
		McGePoint3dArray&  gripPoints,
		McGeIntArray&  osnapModes,
		McGeIntArray&  geomIds) const override;

	Mcad::ErrorStatus moveGripPointsAt(const McGeIntArray& indices,
		const McGeVector3d& offset) override;

};




class McDbOle2FrameImp;
class McRectangle3d
{
public:
	McGePoint3d upLeft;
	McGePoint3d upRight;
	McGePoint3d lowLeft;
	McGePoint3d lowRight;
};


class ARXDLL McDbOle2Frame : public McDbEntity
{
public:
	MCDB_DECLARE_MEMBERS(McDbOle2Frame);
	McDbOle2Frame(void);
	virtual ~McDbOle2Frame(void);

	virtual Mdesk::Boolean  worldDraw(McGiWorldDraw * wd);

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

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

	Mdesk::Int32 unhandled_unknown0() const;

	Mdesk::UInt8 unhandled_unknown1() const;

	Mdesk::UInt8 unhandled_unknown2() const;

	void unhandled_setUnknown(Mdesk::Int32 unk0 = 0, Mdesk::UInt8 unk1 = 0x80, Mdesk::UInt8 unk2 = 0x55);

	Mdesk::UInt16 unhandled_himetricWidth() const;

	Mdesk::UInt16 unhandled_himetricHeight() const;

	void unhandled_setHimetricSize(Mdesk::UInt16 w, Mdesk::UInt16 h);

	void position(McRectangle3d& rect) const;

	void setPosition(const McRectangle3d& rect);

	LPCMSTR getUserType() const;

	void    setUserType(LPCMSTR sType);

	enum Type
	{
		kUnknown = 0,
		kLink = 1,
		kEmbedded = 2,
		kStatic = 3
	};

	Type getType() const;

	void setType(Type val);

	LPCMSTR getLinkName() const;

	void    setLinkName(LPCMSTR sName);

	LPCMSTR getLinkPath() const;

	void    setLinkPath(LPCMSTR sPath);


	enum PlotQuality
	{
		kMonochrome = 0,
		kLowGraphics = 1,
		kHighGraphics = 2
	};

	PlotQuality outputQuality() const;

	void setOutputQuality(
		PlotQuality  quality);


	void getCompoundDocument(
		byte** ppData, long* pSize) const;

	void setCompoundDocument(
		byte* pData,
		long size);

	enum DvAspect
	{
		kContent = 1,
		kThumbnail = 2,
		kIcon = 4,
		kDocPrint = 8
	};

	DvAspect drawAspect() const;

	void setDrawAspect(DvAspect drawAspect);

	bool monikerAssigned() const;

	void setMonikerAssigned(bool assigned);

	Mdesk::UInt32 itemId() const;

	void setItemId(Mdesk::UInt32 nId);

	DvAspect adviseType() const;

	void setAdviseType(DvAspect at);


	virtual void*        GetInnerAryBinData() const;

	virtual void         SetInnerAryBinData(void*);
#ifdef MXUSEMFC
	CBitmap* GetBitmap(double dBitmapImageSizeRefLong = -1.0, double dOleImageSize = -1.0);
#endif
private:
};
