// ShapeElement.h: interface for the ShapeElement class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_SHAPEELEMENT_H__BD77AC11_05D5_4D64_9D1A_0FF0BB2FBF3E__INCLUDED_)
#define AFX_SHAPEELEMENT_H__BD77AC11_05D5_4D64_9D1A_0FF0BB2FBF3E__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define MARGIN_Y 2
class ShapeNamespace;

typedef enum{
	SHAPE_NONE = 0 ,
	SHAPE_ACTIVITYDIAGRAM = 1 ,
	SHAPE_CLASSDIAGRAM = 2,
	SHAPE_ACTIVITY = 3,
	SHAPE_CLASS = 4 ,
	SHAPE_TRANSEDGE = 5 ,
	SHAPE_SWIMLANE = 6 ,
	SHAPE_NAMESPACE = 7,
	SHAPE_CONTROLFLOW = 8
}ShapeType;

class ShapeElement  
{
public:
	ShapeElement();
	virtual ~ShapeElement();
	static CPtrTempl<ShapeElement*>m_AllShapes; //所有形状的列表
	static HANDLE m_AccessSem;
	long m_ID;                          //图形的id
	ShapeNamespace *m_pShapeNamespace;
public:
	virtual ShapeNamespace* GetShapeNamespace();
	static ShapeElement* Find( long id);
	virtual void Save(CFile &file ,int &tabnum);
	void RestoreBrush(CDC *pDC );
	void SetTempBrush(CDC *pDC , COLORREF color , int style = -1 );
	void RestorePen(CDC *pDC);
	void SetTempPen(CDC *pDC , int width , COLORREF color , int style=-1);//在Draw中设置领事画笔，用完后一定要用RestorePen恢复
	void RestoreFont(CDC* pDC);
	void SetTempFont(CDC* pDC ,LOGFONT lf);//在Draw中设置临时字体，用完后一定要用RestoreFont

	void DrawTextLeft(CRect r , CString txt ,CDC*pDC , int marginX = 3 );
	CSize GetTextSize(CString str , CDC *pDC );
	void DrawTextCenter(CRect r , CString txt ,CDC *pDC , int marginX = 12 ,int marginY = 2);
	void DrawDefault( CDC *pDC );//间接调用Draw，使用设置的GID设置
	virtual void Draw( CDC *pDC );//绘制函数，外部调用
	virtual ShapeType GetType();

	CRect m_Pos;                   //位置

	COLORREF m_TextColor;//字颜色
	LOGFONT m_TextFont;//字体
	int m_TextBkMode;//背景模式

	long m_LineWidth;//线宽
	long m_LineStyle;//线型
	COLORREF m_LineColor;//线的颜色

	COLORREF m_FillColor;//填充颜色
	long m_FillStyle;//填充模式

	CFont m_TempFont,*m_pTempFont;//临时字体
	CPen m_TempPen,*m_pTempPen;//临时画笔
	CBrush m_TempBrush, *m_pTempBrush;//临时刷子

protected:
	BOOL beUsed;
	virtual BOOL In(CPoint pt );
public:
	void SetBeUsed( BOOL b);
	BOOL GetBeUsed( );
	void WriteAttribute(CFile& file , UMLAttribute att , int &tabnum);
	void WriteParameter(CFile &file , UMLParameter p , int &tabnum);
	long FindActivityGraphID(UMLActivityGraph *p);
	void WritePos(CFile &file , int &tabnum );
	void WriteOperation(CFile &file ,UMLOperation *pOpe , int &tabnum );
	long FindClassID(UMLClass *p);
	void WriteEnter(CFile &file );
	void WriteTab(CFile &file ,int num);
	void WriteContent(CFile& file , CString str);
	void WriteTag(CFile &file , CString str);
	MarkElement* m_pMarkElement;//标记
};

#endif // !defined(AFX_SHAPEELEMENT_H__BD77AC11_05D5_4D64_9D1A_0FF0BB2FBF3E__INCLUDED_)
