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.
kev/Drawer/Module/GeoSigmaDraw/ActionLayerDragDropItem.cpp

118 lines
2.8 KiB
C++

#include "stdafx.h"
#include "ActionLayerDragDropItem.h"
#include "SigmaDoc.h"
#include "SigmaView.h"
#include "Util.h"
#include "Visitor.h"
NAction::CActionLayerDragDropItem::CActionLayerDragDropItem()
: CActionItem(nullptr, 0)
{
}
NAction::CActionLayerDragDropItem::CActionLayerDragDropItem(CSigmaDoc* ppDoc, const CLayerLocation &oldLocation, const CLayerLocation &newLocation)
: CActionItem(ppDoc, ActionTypeLayerDragDrop),
m_oldLocation(oldLocation),
m_newLocation(newLocation)
{
}
void NAction::CActionLayerDragDropItem::Undo()
{
Move(m_newLocation, m_oldLocation);
}
POSITION NAction::CActionLayerDragDropItem::GetFirstChildLayerPosition(CString layerName)
{
auto pred = [&layerName](CLayer* pLayer)
{
CLayerName targetLayerName(layerName);
CString name = pLayer->GetName();
return targetLayerName.IsChild(name);
};
return GetMatchPosition(layerName, pred);
}
POSITION CActionLayerDragDropItem::GetLayerPosition(CString layerName)
{
auto isMatchingLayer = [&layerName](CLayer* pLayer)
{
CString currentName = pLayer->GetName();
CLayerName targetLayerName(layerName);
return targetLayerName == currentName;
};
return GetMatchPosition(layerName, isMatchingLayer);
}
POSITION CActionLayerDragDropItem::GetMatchPosition(CString strLayer, std::function<bool(CLayer*)> pred)
{
CLayerName layerName(strLayer);
CLayerList* pClass = GetDoc()->GetDraw()->GetClass(layerName.GetClassName());
if (pClass == nullptr)
{
return nullptr;
}
CListForEach(pos, *pClass)
{
CLayer *pLayer = pClass->GetAt(pos);
if (pred(pLayer))
{
return pos;
}
}
return nullptr;
}
void NAction::CActionLayerDragDropItem::Move(const CLayerLocation& oldLocation, const CLayerLocation& newLocation)
{
CString oldLayer = oldLocation.layer;
CString oldParent = GetParentLayerPath(oldLayer);
CString oldPrev = oldLocation.prevLayer;
CString newLayer = newLocation.layer;
CString newParent = GetParentLayerPath(newLayer);
CString newPrev = newLocation.prevLayer;
if (oldParent == newParent) // ֻ<>ǽ<EFBFBD><C7BD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD>ƶ<EFBFBD>
{
if (newPrev.IsEmpty())
{
POSITION pos = GetFirstChildLayerPosition(newParent);
GetDoc()->GetDraw()->MoveLayerInSameClassSeries(oldLayer, TRUE, pos, 0);
}
else
{
POSITION pos = GetLayerPosition(newPrev);
GetDoc()->GetDraw()->MoveLayerInSameClassSeries(oldLayer, TRUE, pos, 1);
}
}
else // <20><><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>
{
if (newPrev.IsEmpty())
{
POSITION pos = GetFirstChildLayerPosition(newParent);
GetDoc()->GetDraw()->MoveLayer(oldLayer, newParent, TRUE, pos, 0);
}
else
{
POSITION pos = GetLayerPosition(newPrev);
GetDoc()->GetDraw()->MoveLayer(oldLayer, newParent, TRUE, pos, 1);
}
}
}
void NAction::CActionLayerDragDropItem::Redo()
{
Move(m_oldLocation, m_newLocation);
}
void NAction::CActionLayerDragDropItem::accept(CActionVisitor& visitor)
{
visitor.visit(*this);
}