// AG_MDAView.h : interface of the CAG_MDAView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_AG_MDAVIEW_H__6E03C99D_0E9B_4CC1_9AA2_9842F10C20C1__INCLUDED_)
#define AFX_AG_MDAVIEW_H__6E03C99D_0E9B_4CC1_9AA2_9842F10C20C1__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


typedef enum{
	OPE_NONE = 0,
	OPE_ADD_STATE_INIT = 1,
	OPE_ADD_STATE_FINISH = 2,
	OPE_ADD_STATE_ACTION = 3,
	OPE_ADD_STATE_SUB = 4,
	OPE_ADD_STATE_SYNCH = 5,
	OPE_ADD_TRANS_EDGE = 6,
	OPE_ADD_SWIMLANE = 7,
	OPE_SEL = 8,
	OPE_DEL = 9
}OperationType;

class CAG_MDAView : public CView
{
protected: // create from serialization only
	CAG_MDAView();
	DECLARE_DYNCREATE(CAG_MDAView)

// Attributes
public:
	CAG_MDADoc* GetDocument();
	OperationType m_OperationType;
	CPoint m_DownPoint;
	ShapeElement *m_pSelElement;
	ShapeTransEdge *m_pForAddTransEdge;

	//用于测试的数据
	typedef CPtrTempl< CString *> TESTCASE;          //一个执行轨迹
	typedef CPtrTempl< TESTCASE *> TESTCASESET;      //一个执行轨迹的列表
	typedef CObjTempl<int> INDEX;         //一个整数的索引
//	TESTCASESET failedTestCaseSet;

	TESTCASESET testCaseSet;    //轨迹的集合
    TESTCASE testCaseInput;     //输入的集合，与上面的对应

	INDEX index;       //结果中的用例的索引
	INDEX errorIndex;  //错误用例的索引

	INDEX pathIndex;  //路径覆盖中run的索引
	INDEX pathErrorIndex;//路径覆盖中错误run的索引

	typedef CPtrTempl< ShapeElement* > SHAPEVECOTR;
	SHAPEVECOTR currentPosition;

	double activityCoverage;  //覆盖率
	double edgeCoverage;

	//下面的数据结构用于路径覆盖
	typedef CPtrTempl< ShapeActivity *> CURRENTSTATE;
	typedef CPtrTempl< ShapeTransEdge *> USEDEDGESOFCURRENTSTATE;
	CPtrStack< CURRENTSTATE* > DFSStack; //DFS stack
	CPtrStack< USEDEDGESOFCURRENTSTATE* > DFSStack_usededges;

    typedef CPtrTempl< ShapeActivity *> AGTRACE; //记住状态图的每个run
	AGTRACE currentTrace;
	CPtrTempl<AGTRACE *> allTrace;

	typedef CPtrTempl< ShapeActivity *> AGLOOP;//记住状态图的每个圈
	CPtrTempl<AGLOOP *> allLoop;
	



	
	// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAG_MDAView)
	public:
	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	protected:
	virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
	virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
	virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
	//}}AFX_VIRTUAL

// Implementation
public:
	BOOL CheckTestCase(int i);
	BOOL testCaseIsAPath(int i);
	int traceNum;
	void CompareTestCaseWithAllPath();
	void ResetAfterPathCoverage( );
	void DisplayPathCoverageResult( );
	void GetNextStateWhenDeleteSynchElement(CURRENTSTATE *cs, ShapeActivity *sa, CURRENTSTATE *ncs);
	void GetNextStateWhenAddSynchElement( CURRENTSTATE * cs ,ShapeActivity * sa,CURRENTSTATE * ncs);
	BOOL TestJoin(ShapeActivity * sa);
	void RecordCurrentTrace( );
	void CurrentStateWithMoreThanOneElement( CURRENTSTATE * cs,USEDEDGESOFCURRENTSTATE * cs_usededges);
	void CurrentStateWithOneElement(CURRENTSTATE * cs,USEDEDGESOFCURRENTSTATE * cs_usededges);
	void DFS( );
	void ResultColor( );
	void ResotreColor( );
	void RemoveAllSynTags( );
	void ClearAllTags();
	BOOL CheckSyncActivity( ShapeActivity *sa);
	BOOL CheckSyncActivityOutEdges( ShapeActivity * sa);
	BOOL CheckSyncActivityInEdges( ShapeActivity * sa);
	BOOL PreViewChangeCurrentPositionWith( CString * nodeName );
	void ClearTestCaseInput( );
	BOOL ChangeCurrentPositionWith( CString * nodeName );

	//利用头节点以及后继的路径遍历活动图，如果preView为true则不用设定遍历状态
	BOOL ForwardWithTheTrace(int id, ShapeElement * head, BOOL preView);

	BOOL ActivityDiagramAllCoverd( );
	BOOL UseTestCase( int i );
	BOOL ReadATestCase(CFile& file);
	void ResetTestResult( );
	void WriteTestResultToFile( );
	void ReadTestCaseFromFile( CString filePath);
	void ClearFailedTestCaseSet( );
	void ClearTestCaseSet( );
	void ClearTestCase();
	void DelSel(CPoint pt);
	void AppendLog(CString txt );
	void AddSwimlane(CPoint pt);
	void AddStateSynch(CPoint pt);
	ShapeElement* FindSel(CPoint pt );
	void AddTransEdge(CPoint pt );
	void AddStateSub(CPoint pt);
	void AddStateAction(CPoint pt );
	void AddStateFinish(CPoint pt);
	void AddStateInit(CPoint pt );
	void SetAGButtons( int id );
	virtual ~CAG_MDAView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	//{{AFX_MSG(CAG_MDAView)
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnButtonStateAction();
	afx_msg void OnUpdateButtonStateAction(CCmdUI* pCmdUI);
	afx_msg void OnButtonStateFinish();
	afx_msg void OnUpdateButtonStateFinish(CCmdUI* pCmdUI);
	afx_msg void OnButtonStateInit();
	afx_msg void OnUpdateButtonStateInit(CCmdUI* pCmdUI);
	afx_msg void OnButtonStateSub();
	afx_msg void OnUpdateButtonStateSub(CCmdUI* pCmdUI);
	afx_msg void OnButtonTransEdge();
	afx_msg void OnUpdateButtonTransEdge(CCmdUI* pCmdUI);
	afx_msg void OnButtonSel();
	afx_msg void OnUpdateButtonSel(CCmdUI* pCmdUI);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnButtonStateSynch();
	afx_msg void OnUpdateButtonStateSynch(CCmdUI* pCmdUI);
	afx_msg void OnButtonSwimlane();
	afx_msg void OnUpdateButtonSwimlane(CCmdUI* pCmdUI);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnFileSave();
	afx_msg void OnFileOpen();
	afx_msg void OnButtonDel();
	afx_msg void OnButtonActivityDiagramTest();
	afx_msg void OnUpdateButtonActivityDiagramTest(CCmdUI* pCmdUI);
	afx_msg void OnButtonPathCoverageTest();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG  // debug version in AG_MDAView.cpp
inline CAG_MDADoc* CAG_MDAView::GetDocument()
   { return (CAG_MDADoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_AG_MDAVIEW_H__6E03C99D_0E9B_4CC1_9AA2_9842F10C20C1__INCLUDED_)
