You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
3.5 KiB
C++

//////////////////////////////////////////////////////////////////////////////
//文件 ActionItem.h
//主要功能:
//
//程序编写: 2006-12-07
/////////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "SigmaDoc.h"
#include "SigmaView.h"
#include ".\ActionItem.h"
//#include "MainFrm.h"
using namespace NAction;
CActionItem::CActionItem(CSigmaDoc * ppDoc, UINT actionType)
: CAction(ppDoc,actionType)
{
}
CActionItem::~CActionItem(void)
{
}
void CActionItem::Undo(void)
{
CAction::Undo();
// regain the input focus
// GetView()->SetFocus();
// GetDoc()->Modified();
}
void CActionItem::Redo(void)
{
CAction::Redo();
// regain the input focus
// GetView()->SetFocus();
GetDoc()->Modified();
}
void CActionItem::Do(void)
{
CAction::Do();
Finish();
////If an action has inform the operation target to add itsleft to stack, the earlier One should be finshed.
//if (GetDoc()->GetActionItem())
//{
// if(GetDoc()->GetActionItem()->done ==false)
// GetDoc()->GetActionItem()->Do();
// GetDoc()->GetActionItem()->Finish();
//}
}
CSigmaDoc* CActionItem::GetDoc(void)
{
return (CSigmaDoc*)actionTarget;
}
//CDFDrawProView* CActionItem::GetView(void)
//{
// return pView;
//}
CSigmaView* CActionItem::GetView(void)
{
ASSERT(GetDoc()!=NULL);
return (CSigmaView*)GetDoc()->GetView();
//return (CDFDrawProView*)(GetDC()->pDC->GetWindow());
}
BOOL CActionItem::RemoveAt(COne* pOne)
{
CXy* pxy=GetDoc()->m_pXy;
if(pxy==NULL) return FALSE;
return pxy->RemoveAtNoClear(pOne);
}
BOOL NAction::CActionItem::RemoveAtNoClear(const std::vector<COne*>& pOnes)
{
CXy* pxy=GetDoc()->m_pXy;
if (pxy == NULL)
{
return FALSE;
}
std::unordered_set<COne*> pOneSet(pOnes.begin(), pOnes.end());
CPtrList& values = *(pxy->GetValueList());
// 反向遍历删除(带提前终止)
POSITION pos = values.GetTailPosition();
while (pos != nullptr && !pOneSet.empty())
{
// 保存当前位置
POSITION currentPos = pos;
COne* pValue = reinterpret_cast<COne*>(values.GetPrev(pos));
// 检查并删除
auto it = pOneSet.find(pValue);
if (it != pOneSet.end())
{
values.RemoveAt(currentPos);
pOneSet.erase(it); // 从待删除集合中移除
}
}
return 0;
}
void CActionItem::Clear(CPtrList& value)
{
COne *pOne;
POSITION p=value.GetHeadPosition();
while(p)
{
pOne=(COne *)(value.GetNext(p));
if (pOne)
{
if (::AfxIsValidAddress(pOne, sizeof(COne))) {
if (::AfxIsValidAddress(pOne->m_pLayer, sizeof(CLayer)))
{
delete pOne;
}
}
pOne = NULL;
}
}
value.RemoveAll();
}
void CActionItem::Invalidate(CRect8& range)
{
//CRect rt=GetDoc()->GetDC().GetScreen(range);
//rt.NormalizeRect();
//rt.InflateRect(GetDoc()->GetHandleSize());
//GetDoc()->Invalidate(&rt);
}
void CActionItem::Remember(const CPositionList& list)
{
if(list.GetCount()==0) return;
COne* pOne;
POSITION pt;
POSITION pos = list.GetHeadPosition();
while (pos != NULL)
{
pt = list.GetNext(pos);
pOne=GetDoc()->GetDraw()->GetAt(pt);
value.AddTail(pOne);
}
}
void NAction::CActionItem::ReflashLayer(void)
{
//CMainFrame* pmf = (CMainFrame*)GetDoc()->GetMainFrame();
//if(pmf)
// pmf->LoadLayer(NULL);
}
BOOL NAction::CActionItem::ReflashMarkLibrary(void)
{
//CMainFrame* pmf = (CMainFrame*)GetDoc()->GetMainFrame();
//if(pmf==NULL) return FALSE;
//if(pmf->m_paneMarkManager.GetSafeHwnd()==NULL) return FALSE;
//if(pmf->m_paneMarkManager.m_treeList.GetCurLoadMode()!=LOAD_MODE_MARK)
// return FALSE;
//if(pmf->m_paneMarkManager.m_treeList.Tree_IsCurrentItem()) //是否是当前文档的符号显示
// pmf->m_paneMarkManager.ReflashList();
return TRUE;
}