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)
{
//<2F><>ʼ<EFBFBD><CABC>
m_ObjContainer.Clear();
if(ArrayPar.m_bRectArray)
{
RectCreat(ArrayPar);
}
else if(ArrayPar.m_bCircleArray)
{
CircleCreat(ArrayPar);
}
else
{
FillCreat(ArrayPar);
}
//<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
CreatCmd();
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD>ʽ
void CArrayMgr::RectCreat(SArrayPar &ArrayPar)
{
//<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD>ο<EFBFBD>¡һ<C2A1><D2BB>obj <20><>m_ObjContainer <20><>
for(int i=0;i<ArrayPar.m_ArrayCntV;i++)
{
for(int j=0;j<ArrayPar.m_ArrayCntH;j++)
{
//<2F><><EFBFBD>뵱ǰѡ<C7B0><D1A1><EFBFBD><EFBFBD>obj (<28><>ʱΪѡ<CEAA><D1A1>״̬)
gLayer.CloneObj(m_ObjContainer,true);
//<2F>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>λ<EFBFBD><CEBB>--------------------------------------
SObjOperatePar par;
par.OpType = _OP_MOVE;
par.MoveX = ArrayPar.m_ArrayOffsetV*i;
par.MoveY = ArrayPar.m_ArrayOffsetH*j;
m_ObjContainer.OperateObj(par,true);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD>Ϊ<EFBFBD><CEAA>ѡ<EFBFBD><D1A1>״̬
m_ObjContainer.NotSelAllObj();
}
}
}
//Բ<><D4B2><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD>ʽ
void CArrayMgr::CircleCreat(SArrayPar &ArrayPar)
{
//<2F><>X <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Բ<EFBFBD><D4B2>-----------------------------------------------------
//<2F><><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD>ܳ<EFBFBD>
double Perimeter = 2*PI*ArrayPar.m_Radius;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD>
ArrayPar.m_ArrayCntH = 1;//1<><31>
ArrayPar.m_ArrayCntV = ArrayPar.m_ArrayCnt;//1<><31>
ArrayPar.m_ArrayOffsetV = Perimeter*(ArrayPar.m_GapAngle/360);
ArrayPar.m_ArrayOffsetH = 0;
RectCreat(ArrayPar);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD>ĵ<EFBFBD>
DbRect AllCharRect = m_ObjContainer.GetObjRect(false);//<2F><><EFBFBD><EFBFBD>obj <20>ķ<EFBFBD>Χ
//<2F>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD>ĵ<EFBFBD>
Dbxy BottomCenterPt = AllCharRect.GetBottomCenterPt();
Dbxy CenterPt;//Բ<>ĵ<EFBFBD>
CenterPt.x = BottomCenterPt.x;
CenterPt.y = BottomCenterPt.y - ArrayPar.m_Radius;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>תƫ<D7AA>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>ʵ<EFBFBD>λ<EFBFBD><CEBB>
int size = m_ObjContainer.GetSize();
for(int i=0;i<size;i++)
{
DbRect ObjRect = m_ObjContainer.GetObjRect(i);
Dbxy pt = ObjRect.GetBottomCenterPt();
//<2F><>ת<EFBFBD>Ƕ<EFBFBD>(360)
double angle = 360*(BottomCenterPt.x-pt.x)/Perimeter;
//<2F><>ת<EFBFBD><D7AA><EFBFBD>ĵ<EFBFBD>
Dbxy pt2 = RotatoPt(BottomCenterPt,_360ToAngle(angle),CenterPt);
//<2F><><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>
double OffsetX = pt2.x-pt.x;
double OffsetY = pt2.y-pt.y;
//<2F><>ת<EFBFBD>ַ<EFBFBD>
SObjOperatePar par;
par.OpType = _OP_ROTATO;
par.BasePt = ObjRect.GetCenterPt();
par.Angle = angle;
m_ObjContainer.Operate(par,i);
//ƫ<><C6AB><EFBFBD>ַ<EFBFBD>
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;
//<2F><><EFBFBD>뵱ǰѡ<C7B0><D1A1><EFBFBD><EFBFBD>obj (<28><>ʱΪѡ<CEAA><D1A1>״̬)
gLayer.CloneObj(m_ObjContainer,true);
DbRect Rect = m_ObjContainer.GetObjRect(false);//<2F><><EFBFBD><EFBFBD>obj <20>ķ<EFBFBD>Χ
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);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD>Ϊ<EFBFBD><CEAA>ѡ<EFBFBD><D1A1>״̬
m_ObjContainer.NotSelAllObj();
if(flg)
break;
}
}
//<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
void CArrayMgr::CreatCmd()
{
if(!m_ObjContainer.Empty())
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>-------start
CCommandArray *pCmd = new CCommandArray;
gCommandMgr.AddUndoCommand(pCmd,m_ObjContainer.GetObjVec());
CLayer &layer = gLayer;
pCmd->SaveBaseObj(layer.GetObjContainer());
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>-------end
pCmd->Excute();
}
}