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.

155 lines
4.5 KiB
C++

#include "StdAfx.h"
#include "ArrayMgr.h"
#include "GlobalFunction.h"
#include "CommandArray.h"
#include "CommandMgr.h"
CArrayMgr::CArrayMgr(void)
{
}
CArrayMgr::~CArrayMgr(void)
{
}
void CArrayMgr::Creat(SArrayPar &ArrayPar)
{
//初始化
m_ObjContainer.Clear();
if(ArrayPar.m_bRectArray)
{
RectCreat(ArrayPar);
}
else if(ArrayPar.m_bCircleArray)
{
CircleCreat(ArrayPar);
}
else
{
FillCreat(ArrayPar);
}
//创建指令
CreatCmd();
}
//矩形阵列方式
void CArrayMgr::RectCreat(SArrayPar &ArrayPar)
{
//按照指定个数每次克隆一个obj 到m_ObjContainer 中
for(int i=0;i<ArrayPar.m_ArrayCntV;i++)
{
for(int j=0;j<ArrayPar.m_ArrayCntH;j++)
{
//导入当前选择的obj (此时为选择状态)
gLayer.CloneObj(m_ObjContainer,true);
//移动到阵列的位置--------------------------------------
SObjOperatePar par;
par.OpType = _OP_MOVE;
par.MoveX = ArrayPar.m_ArrayOffsetV*i;
par.MoveY = ArrayPar.m_ArrayOffsetH*j;
m_ObjContainer.OperateObj(par,true);
//操作完成后变为非选择状态
m_ObjContainer.NotSelAllObj();
}
}
}
//圆形阵列方式
void CArrayMgr::CircleCreat(SArrayPar &ArrayPar)
{
//先X 方向阵列,在偏移旋转成圆形-----------------------------------------------------
//计算圆的周长
double Perimeter = 2*PI*ArrayPar.m_Radius;
//计算阵列间隔
ArrayPar.m_ArrayCntH = 1;//1行
ArrayPar.m_ArrayCntV = ArrayPar.m_ArrayCnt;//1行
ArrayPar.m_ArrayOffsetV = Perimeter*(ArrayPar.m_GapAngle/360);
ArrayPar.m_ArrayOffsetH = 0;
RectCreat(ArrayPar);
//计算出圆心点
DbRect AllCharRect = m_ObjContainer.GetObjRect(false);//所有obj 的范围
//底部中心点
Dbxy BottomCenterPt = AllCharRect.GetBottomCenterPt();
Dbxy CenterPt;//圆心点
CenterPt.x = BottomCenterPt.x;
CenterPt.y = BottomCenterPt.y - ArrayPar.m_Radius;
//依次旋转偏移到合适的位置
int size = m_ObjContainer.GetSize();
for(int i=0;i<size;i++)
{
DbRect ObjRect = m_ObjContainer.GetObjRect(i);
Dbxy pt = ObjRect.GetBottomCenterPt();
//旋转角度(360)
double angle = 360*(BottomCenterPt.x-pt.x)/Perimeter;
//旋转后的点
Dbxy pt2 = RotatoPt(BottomCenterPt,_360ToAngle(angle),CenterPt);
//计算偏移量
double OffsetX = pt2.x-pt.x;
double OffsetY = pt2.y-pt.y;
//旋转字符
SObjOperatePar par;
par.OpType = _OP_ROTATO;
par.BasePt = ObjRect.GetCenterPt();
par.Angle = angle;
m_ObjContainer.Operate(par,i);
//偏移字符
par.OpType = _OP_MOVE;
par.MoveX = OffsetX;
par.MoveY = OffsetY;
m_ObjContainer.Operate(par,i);
}
}
void CArrayMgr::FillCreat(SArrayPar &ArrayPar)
{
for(int k=0;k<=ArrayPar.m_FillCnt;k++)
{
bool flg = false;
//导入当前选择的obj (此时为选择状态)
gLayer.CloneObj(m_ObjContainer,true);
DbRect Rect = m_ObjContainer.GetObjRect(false);//所有obj 的范围
double w = Rect.Width();
{
SObjOperatePar par;
par.OpType = _OP_STRETCH;
par.BasePt = Rect.GetCenterPt();
par.OldSize = Rect.Width();
par.Diff = ArrayPar.m_FillOffset*k;
par.NewSize = par.OldSize + par.Diff;
if(par.NewSize < ArrayPar.m_FillOffset)
flg = true;
par.xy = _X;
m_ObjContainer.OperateObj(par,true);
}
{
SObjOperatePar par;
par.OpType = _OP_STRETCH;
par.BasePt = Rect.GetCenterPt();
par.OldSize = Rect.Height();
par.Diff = ArrayPar.m_FillOffset*k;
par.NewSize = par.OldSize + par.Diff;
if(par.NewSize < ArrayPar.m_FillOffset)
flg = true;
par.xy = _Y;
m_ObjContainer.OperateObj(par,true);
}
//操作完成后变为非选择状态
m_ObjContainer.NotSelAllObj();
if(flg)
break;
}
}
//创建指令
void CArrayMgr::CreatCmd()
{
if(!m_ObjContainer.Empty())
{
//创建撤销指令-------start
CCommandArray *pCmd = new CCommandArray;
gCommandMgr.AddUndoCommand(pCmd,m_ObjContainer.GetObjVec());
CLayer &layer = gLayer;
pCmd->SaveBaseObj(layer.GetObjContainer());
//创建撤销指令-------end
pCmd->Excute();
}
}