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.
324 lines
7.6 KiB
C++
324 lines
7.6 KiB
C++
#include "StdAfx.h"
|
|
#include ".\itemeditcurvecentername.h"
|
|
#include "SigmaDoc.h"
|
|
#include "SigmaView.h"
|
|
#include "ActionBackupItem.h"
|
|
#include "DrawOperator\CurveForInName.h"
|
|
|
|
#define TRACKER_SOLID 1
|
|
#define TRACKER_RECT 2
|
|
#define TRACKER_CIRCLE 4
|
|
#define TRACKER_NO_EDIT TRACKER_SOLID | TRACKER_CIRCLE
|
|
|
|
CItemEditCurveCenterName::CItemEditCurveCenterName(CSigmaDoc * ppDoc)
|
|
: CItemFocusRect(ppDoc)
|
|
{
|
|
this->SetType(ITEM_CURVE_CENTER_NAME);
|
|
|
|
m_pXyNameRange=NULL;
|
|
m_posCurEdit=NULL;
|
|
m_pBakCurCurve=NULL;
|
|
|
|
m_nDrawMode=-1;
|
|
|
|
m_nUndoStep=0;
|
|
m_nRedoStep=0;
|
|
}
|
|
|
|
CItemEditCurveCenterName::~CItemEditCurveCenterName(void)
|
|
{
|
|
Clear();
|
|
GetDoc()->Invalidate();
|
|
}
|
|
|
|
void NItem::CItemEditCurveCenterName::Clear(void)
|
|
{
|
|
if(m_pXyNameRange) delete m_pXyNameRange;
|
|
m_pXyNameRange=NULL;
|
|
if(m_pBakCurCurve) delete m_pBakCurCurve;
|
|
m_pBakCurCurve=NULL;
|
|
m_posCurEdit=NULL;
|
|
}
|
|
|
|
void NItem::CItemEditCurveCenterName::ActionBackup(POSITION posDoc, UINT nID)
|
|
{
|
|
CPositionList select;
|
|
select.AddTail(posDoc);
|
|
GetDoc()->SetActionItem(new CAtionBackupEditCurveInName(GetDoc(),nID,select));
|
|
|
|
m_nUndoStep++;
|
|
m_nRedoStep=0;
|
|
}
|
|
|
|
void CItemEditCurveCenterName::BeginEdit(void)
|
|
{
|
|
Clear();
|
|
m_pXyNameRange=new CXy;
|
|
AfxGetPublicFunction()->EnableCurveCenterNameEditState(TRUE);
|
|
AfxGetPublicFunction()->m_pXyCurveEmbellish=GetXY();
|
|
AfxGetPublicFunction()->EnableJudgeRange(FALSE);
|
|
GetDoc()->GetDraw()->Draw(*GetDC());
|
|
AfxGetPublicFunction()->EnableJudgeRange(TRUE);
|
|
AfxGetPublicFunction()->m_pXyCurveEmbellish=NULL;
|
|
AfxGetPublicFunction()->EnableCurveCenterNameEditState(FALSE);
|
|
//GetDoc()->Invalidate();
|
|
}
|
|
|
|
//重新生成一条曲线内部名称的范围线
|
|
void CItemEditCurveCenterName::RecreateCenterName(POSITION posDoc)
|
|
{
|
|
AfxGetPublicFunction()->EnableCurveCenterNameEditState(TRUE);
|
|
AfxGetPublicFunction()->m_pXyCurveEmbellish=m_pXyNameRange;
|
|
AfxGetPublicFunction()->EnableJudgeRange(FALSE);
|
|
COne* pOne=GetDoc()->GetDraw()->GetAt(posDoc);
|
|
pOne->Draw(*GetDC()); //重画当前曲线的内部名称,生成新的名称范围线
|
|
AfxGetPublicFunction()->EnableJudgeRange(TRUE);
|
|
AfxGetPublicFunction()->m_pXyCurveEmbellish=NULL;
|
|
AfxGetPublicFunction()->EnableCurveCenterNameEditState(FALSE);
|
|
}
|
|
|
|
//根据指针删除其列表名称范围线
|
|
int CItemEditCurveCenterName::DeleteCenterNameCurve(CCurveEx* pParentCurve, CCurveForInName* pNameCurve)
|
|
{
|
|
//删除当前曲线内部名称的范围线
|
|
CCurveForInName* pc;
|
|
POSITION pos,pt;
|
|
COne* pOne;
|
|
int index=-1;
|
|
int count=0;
|
|
|
|
CPtrList* plist=GetXY()->GetValueList();
|
|
pos=plist->GetHeadPosition();
|
|
while(pos)
|
|
{
|
|
pt=pos;
|
|
pOne=(COne*)plist->GetNext(pos);
|
|
if(pOne->GetType()!=DOUBLEFOX_CURVE)continue;
|
|
pc=(CCurveForInName*)pOne->GetValue();
|
|
if(pParentCurve==pc->m_pParentCurve)
|
|
{
|
|
if(pc==pNameCurve)
|
|
index=count;
|
|
|
|
plist->RemoveAt(pt);
|
|
delete pOne;
|
|
count++;
|
|
}
|
|
}
|
|
return index;
|
|
}
|
|
|
|
//根据偏移重新设置曲线的修饰(由类别修饰变为了个性修饰)
|
|
int CItemEditCurveCenterName::ResetCurveCenterName(POSITION posDoc, int nCurveNameIndex, double ox, double oy)
|
|
{
|
|
if(posDoc==NULL) return 0;
|
|
if(nCurveNameIndex==-1) return 0;
|
|
|
|
//如果之前为类别修饰,将之改变为个性修饰
|
|
BOOL bOneNew=FALSE;
|
|
COne* pOne=GetDoc()->GetDraw()->GetAt(posDoc);
|
|
if(pOne->HowToViewCurve==NULL)
|
|
{
|
|
if(pOne->GetLayer()->HowToViewCurve) //层修饰
|
|
{
|
|
pOne->HowToViewCurve=new CHowToViewCurve;
|
|
*(pOne->HowToViewCurve)=*(pOne->GetLayer()->HowToViewCurve);
|
|
bOneNew=TRUE;
|
|
}
|
|
}
|
|
if(pOne->HowToViewCurve==NULL) return 0;
|
|
|
|
//重画当前曲线的内部名称
|
|
int count=0;
|
|
CCurveCenterName* pCenterName;
|
|
CCurveView *c;
|
|
for(int i=0;i<pOne->HowToViewCurve->GetCount();++i)
|
|
{
|
|
c=pOne->HowToViewCurve->GetAt(i);
|
|
switch(c->GetType())
|
|
{
|
|
case CurveCenterName:
|
|
pCenterName=(CCurveCenterName*)c;
|
|
if(count==nCurveNameIndex)
|
|
{
|
|
pCenterName->m_szOffset.cx+=ox;
|
|
pCenterName->m_szOffset.cy+=oy;
|
|
}
|
|
count++;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
if(count==0 && bOneNew)
|
|
{
|
|
delete pOne->HowToViewCurve;
|
|
pOne->HowToViewCurve=NULL;
|
|
}
|
|
return count;
|
|
}
|
|
|
|
void CItemEditCurveCenterName::OnDraw(CXyDC* pXyDC, CDC* pDC)
|
|
{
|
|
pXyDC->Create(pDC);
|
|
int od= pXyDC->GetDC()->SetROP2(R2_NOTXORPEN);
|
|
if (GetXY())
|
|
{
|
|
GetXY()->Draw(*pXyDC);
|
|
}
|
|
pXyDC->GetDC()->SetROP2(od);
|
|
|
|
DrawCurrentCurveHandle(pXyDC);
|
|
}
|
|
|
|
void CItemEditCurveCenterName::OnLButtonDown(CDC *pDC, UINT nFlags, CPoint point, int vk)
|
|
{
|
|
c_down=GetDC()->GetReal(point);
|
|
if(m_posCurEdit)
|
|
{
|
|
CCurveForInName* pCurve=(CCurveForInName*)GetXY()->GetAtValue(m_posCurEdit);
|
|
CPoint2D pt=GetDC()->GetReal(point);
|
|
if(pCurve->IsInside(pt.x0,pt.y0))
|
|
{
|
|
CItemFocusRect::OnLButtonDown(pDC, nFlags, point, vk);
|
|
}
|
|
}
|
|
}
|
|
|
|
void CItemEditCurveCenterName::OnLButtonUp(CDC* pDC,UINT nFlags, CPoint point, int vk)
|
|
{
|
|
if(!IsCaptureState())
|
|
{
|
|
//选择名称
|
|
CPoint2D pt=GetDC()->GetReal(point);
|
|
CRect8 rt=GetDoc()->GetSelectedRect(pt);
|
|
DrawCurrentCurveHandle(GetDC());
|
|
m_posCurEdit=GetXY()->IsInRange(rt);
|
|
//COne * pOne = GetDoc()->GetDraw()->GetAt(m_posCurEdit);
|
|
//int type = pOne->GetType();
|
|
DrawCurrentCurveHandle(GetDC());
|
|
SelectCurve(m_posCurEdit);
|
|
}
|
|
else
|
|
{
|
|
CItemFocusRect::OnLButtonUp(pDC, nFlags, point, vk);
|
|
}
|
|
}
|
|
|
|
int CItemEditCurveCenterName::OnMouseMove(CDC *pDC, UINT nFlags, CPoint point)
|
|
{
|
|
if(IsCaptureState())
|
|
{
|
|
//CItemFocusRect::OnMouseMove(nFlags, point, NULL);
|
|
|
|
//DrawCurrentCurve(GetDC());
|
|
//CCurveForInName* pCurve=(CCurveForInName*)GetXY()->GetAtValue(m_posCurEdit);
|
|
//*pCurve=*m_pBakCurCurve;
|
|
//pCurve->Offset(c_last.x0-c_down.x0, c_last.y0-c_down.y0);
|
|
//DrawCurrentCurve(GetDC());
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
BOOL CItemEditCurveCenterName::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
|
|
{
|
|
//GetDoc()->GetCursor().SetCursor(CursorMove4Way);
|
|
//return GetDoc()->GetCursor().SetCursor();
|
|
return TRUE;
|
|
}
|
|
|
|
void CItemEditCurveCenterName::DoLButtonUp(void)
|
|
{
|
|
if(m_posCurEdit==NULL) return;
|
|
|
|
CCurveForInName* pCurve=(CCurveForInName*)GetXY()->GetAtValue(m_posCurEdit);
|
|
POSITION posDoc=FindCurve(pCurve->m_pParentCurve);
|
|
if(posDoc==NULL) return;
|
|
|
|
//for redo/undo
|
|
ActionBackup(posDoc, IDS_EMBELLISH_CURVE_INNAME_ANY);
|
|
|
|
//删除备份曲线
|
|
SelectCurve(NULL);
|
|
//根据指针删除其列表范围线,并获得被修改的名字的索引号
|
|
int i=DeleteCenterNameCurve(pCurve->m_pParentCurve, pCurve);
|
|
//修改曲线中心名字的偏移距
|
|
ResetCurveCenterName(posDoc, i, c_last.x0-c_down.x0, c_last.y0-c_down.y0);
|
|
//刷新当前曲线的中心名称范围线
|
|
RecreateCenterName(posDoc);
|
|
|
|
CRect8 rt=GetDoc()->GetSelectedRect(c_last);
|
|
m_posCurEdit=GetXY()->IsInRange(rt);
|
|
SelectCurve(m_posCurEdit);
|
|
|
|
GetDoc()->Invalidate();
|
|
GetDoc()->Modified();
|
|
}
|
|
|
|
void CItemEditCurveCenterName::DrawCurrentCurve(CXyDC* pDC)
|
|
{
|
|
if(m_posCurEdit==NULL) return;
|
|
int od=pDC->GetDC()->SetROP2(R2_NOTXORPEN);
|
|
COne* pOne=GetXY()->GetAt(m_posCurEdit);
|
|
pOne->Draw(*GetDC());
|
|
pDC->GetDC()->SetROP2(od);
|
|
}
|
|
|
|
void CItemEditCurveCenterName::DrawCurrentCurveHandle(CXyDC* pDC)
|
|
{
|
|
if(m_posCurEdit)
|
|
{
|
|
CCurveEx* pCurve=(CCurveEx*)GetXY()->GetAtValue(m_posCurEdit);
|
|
DrawCurveHandle(pDC, pCurve, RGB(255,255,255), TRACKER_NO_EDIT, FALSE);
|
|
}
|
|
}
|
|
|
|
void CItemEditCurveCenterName::SelectCurve(POSITION pos)
|
|
{
|
|
m_posCurEdit=pos;
|
|
if(m_posCurEdit)
|
|
{
|
|
if(m_pBakCurCurve==NULL)
|
|
m_pBakCurCurve=new CCurveForInName;
|
|
|
|
CCurveForInName* pCurve=(CCurveForInName*)GetXY()->GetAtValue(m_posCurEdit);
|
|
*m_pBakCurCurve=*pCurve;
|
|
}
|
|
else
|
|
{
|
|
delete m_pBakCurCurve;
|
|
m_pBakCurCurve=NULL;
|
|
}
|
|
}
|
|
|
|
CXy* NItem::CItemEditCurveCenterName::GetXY(void)
|
|
{
|
|
return m_pXyNameRange;
|
|
}
|
|
|
|
BOOL NItem::CItemEditCurveCenterName::IsCanRedo(void)
|
|
{
|
|
return m_nRedoStep>0 ? TRUE:FALSE;
|
|
}
|
|
|
|
BOOL NItem::CItemEditCurveCenterName::IsCanUndo(void)
|
|
{
|
|
return m_nUndoStep>0 ? TRUE:FALSE;
|
|
}
|
|
|
|
void NItem::CItemEditCurveCenterName::Undo(void)
|
|
{
|
|
m_nUndoStep--;
|
|
m_nRedoStep++;
|
|
//GetDrawUndoManager()->Undo(GetDoc());
|
|
BeginEdit();
|
|
}
|
|
|
|
void NItem::CItemEditCurveCenterName::Redo(void)
|
|
{
|
|
m_nRedoStep--;
|
|
m_nUndoStep++;
|
|
//GetDrawUndoManager()->Redo(GetDoc());
|
|
BeginEdit();
|
|
}
|