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.
444 lines
12 KiB
C++
444 lines
12 KiB
C++
#include "StdAfx.h"
|
|
#include "ItemEditCurveInName.h"
|
|
#include "SigmaDoc.h"
|
|
#include "SigmaView.h"
|
|
#include "ActionBackupItem.h"
|
|
#include ".\itemeditcurveinname.h"
|
|
//#include "DrawLib/TypeDefine.h"
|
|
|
|
CItemEditCurveInName::CItemEditCurveInName(CSigmaDoc * ppDoc)
|
|
: CItemEditCurveCenterName(ppDoc)
|
|
{
|
|
this->SetType(ITEM_CURVE_INNAME);
|
|
a0 = 0;
|
|
begin_l0=-1;
|
|
end_l0=-1;
|
|
isDrag = false;
|
|
}
|
|
|
|
CItemEditCurveInName::~CItemEditCurveInName(void)
|
|
{
|
|
Clear();
|
|
GetDoc()->Invalidate();
|
|
}
|
|
|
|
void CItemEditCurveInName::OnLButtonDblClk(UINT nFlags, CPoint point)
|
|
{
|
|
CPoint2D pt=GetDC()->GetReal(point);
|
|
//POSITION posDoc=GetDoc()->GetSelectedItem(pt, DOUBLEFOX_CURVE);
|
|
POSITION posDoc = GetDoc()->GetSelectedItem(pt);
|
|
if(posDoc==NULL) return;
|
|
COne* pOne=GetDoc()->GetDraw()->GetAt(posDoc);
|
|
if(pOne->GetType()!=DOUBLEFOX_CURVE) return;
|
|
|
|
CCurveEx* pCurve=(CCurveEx*)pOne->GetValue();
|
|
CArray<double,double> listL;
|
|
|
|
double l0;
|
|
double dis=pCurve->PointDistance(pt.x0,pt.y0,l0);
|
|
CSize8 sz=GetDoc()->GetSelectSize();
|
|
int dx=GetDC()->GetScreenWidth(dis);
|
|
int dy=GetDC()->GetScreenHeight(dis);
|
|
if(dx<=sz.cx && dy<=sz.cy && l0<1e100)
|
|
{
|
|
listL.Add(l0);
|
|
|
|
//for redo/undo
|
|
ActionBackup(posDoc, IDS_EMBELLISH_CURVE_INNAME_ANY);
|
|
|
|
//根据指针删除其列表范围线,并获得其桩号
|
|
GetInNameLocation(pCurve, listL, TRUE);
|
|
//重设曲线内部的桩号
|
|
if(ResetOneAnyInName(posDoc, listL)>0)
|
|
{
|
|
//刷新当前曲线的内部名称范围线
|
|
RecreateInName(posDoc);
|
|
GetDoc()->Invalidate(posDoc);
|
|
GetDoc()->Modified();
|
|
}
|
|
}
|
|
}
|
|
|
|
void CItemEditCurveInName::OnLButtonDown(CDC *pDC, UINT nFlags, CPoint point, int vk)
|
|
{
|
|
m_isMoved = false;
|
|
GetDC()->Create(pDC);
|
|
c_down = GetDC()->GetReal(point);
|
|
// 保存上一条曲线
|
|
if (m_posCurEdit !=nullptr)
|
|
{
|
|
CCurveForInName* pCurve = (CCurveForInName*)GetXY()->GetAtValue(m_posCurEdit);
|
|
// 选中的是编辑状态的线
|
|
if (pCurve->IsInside(c_down.x0, c_down.y0)) {
|
|
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);
|
|
pCurve->m_pParentCurve->PointDistance(pt.x0, pt.y0, begin_l0);
|
|
double z0;
|
|
pCurve->m_pParentCurve->GetCoordinate(begin_l0, c_down.x0, c_down.y0, z0);
|
|
|
|
CPoint2D p1, p2;
|
|
pCurve->m_pParentCurve->GetCoordinate(begin_l0 - pCurve->dl*0.5, p1.x0, p1.y0, z0);
|
|
pCurve->m_pParentCurve->GetCoordinate(begin_l0 + pCurve->dl*0.5, p2.x0, p2.y0, z0);
|
|
a0 = AfxGetPublicFunction()->GetAngle(p1.x0, p1.y0, p2.x0, p2.y0);
|
|
}
|
|
return;
|
|
}
|
|
else {
|
|
// 选中的是另外一条线,保存上一条编辑的线
|
|
DrawCurrentCurveHandle(GetDC());
|
|
DoLButtonUp(pDC);
|
|
m_isMoved = TRUE;
|
|
//
|
|
CRect8 rt = GetDoc()->GetSelectedRect(c_down);
|
|
m_posCurEdit = GetXY()->IsInRange(rt);
|
|
if (m_posCurEdit == nullptr) {
|
|
return;
|
|
}
|
|
SelectCurve(m_posCurEdit);
|
|
DrawCurrentCurveHandle(GetDC());
|
|
m_pBakCurCurve->m_pParentCurve->PointDistance(c_down.x0, c_down.y0, end_l0);
|
|
if (end_l0 >= m_pBakCurCurve->m_pParentCurve->l[0] &&
|
|
end_l0 <= m_pBakCurCurve->m_pParentCurve->l[m_pBakCurCurve->m_pParentCurve->num - 1])
|
|
{
|
|
CCurveForInName* pCurve = (CCurveForInName*)GetXY()->GetAtValue(m_posCurEdit);
|
|
*pCurve = *m_pBakCurCurve;
|
|
|
|
pCurve->m_pParentCurve->PointDistance(c_down.x0, c_down.y0, begin_l0);
|
|
pCurve->l0 = end_l0 - begin_l0 + m_pBakCurCurve->l0;
|
|
if (pCurve->l0 < 0)pCurve->l0 = end_l0;
|
|
|
|
CPoint2D p1, p2;
|
|
double z0;
|
|
pCurve->m_pParentCurve->GetCoordinate(begin_l0 - pCurve->dl*0.5, p1.x0, p1.y0, z0);
|
|
pCurve->m_pParentCurve->GetCoordinate(begin_l0 + pCurve->dl*0.5, p2.x0, p2.y0, z0);
|
|
a0 = AfxGetPublicFunction()->GetAngle(p1.x0, p1.y0, p2.x0, p2.y0);
|
|
|
|
pCurve->m_pParentCurve->GetCoordinate(end_l0, c_last.x0, c_last.y0, z0);
|
|
c_down.x0 = c_last.x0;
|
|
c_down.y0 = c_last.y0;
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
CRect8 rt = GetDoc()->GetSelectedRect(c_down);
|
|
m_posCurEdit = GetXY()->IsInRange(rt);
|
|
if (m_posCurEdit == nullptr) {
|
|
return;
|
|
}
|
|
SelectCurve(m_posCurEdit);
|
|
DrawCurrentCurveHandle(GetDC());
|
|
|
|
m_pBakCurCurve->m_pParentCurve->PointDistance(c_down.x0, c_down.y0, end_l0);
|
|
if (end_l0 >= m_pBakCurCurve->m_pParentCurve->l[0] &&
|
|
end_l0 <= m_pBakCurCurve->m_pParentCurve->l[m_pBakCurCurve->m_pParentCurve->num - 1])
|
|
{
|
|
CCurveForInName* pCurve = (CCurveForInName*)GetXY()->GetAtValue(m_posCurEdit);
|
|
*pCurve = *m_pBakCurCurve;
|
|
|
|
pCurve->m_pParentCurve->PointDistance(c_down.x0, c_down.y0, begin_l0);
|
|
pCurve->l0 = end_l0 - begin_l0 + m_pBakCurCurve->l0;
|
|
if (pCurve->l0 < 0)pCurve->l0 = end_l0;
|
|
|
|
CPoint2D p1, p2;
|
|
double z0;
|
|
pCurve->m_pParentCurve->GetCoordinate(begin_l0 - pCurve->dl*0.5, p1.x0, p1.y0, z0);
|
|
pCurve->m_pParentCurve->GetCoordinate(begin_l0 + pCurve->dl*0.5, p2.x0, p2.y0, z0);
|
|
a0 = AfxGetPublicFunction()->GetAngle(p1.x0, p1.y0, p2.x0, p2.y0);
|
|
|
|
pCurve->m_pParentCurve->GetCoordinate(end_l0, c_last.x0, c_last.y0, z0);
|
|
c_down.x0 = c_last.x0;
|
|
c_down.y0 = c_last.y0;
|
|
}
|
|
}
|
|
|
|
int CItemEditCurveInName::OnMouseMove(CDC* pDC, UINT nFlags, CPoint point)
|
|
{
|
|
if (m_pBakCurCurve == NULL|| m_posCurEdit == nullptr)
|
|
return 1;
|
|
|
|
CRect rect = m_client;
|
|
pDC->BitBlt(0, 0, rect.Width(), rect.Height(), m_pBackGroundDC, 0, 0, SRCCOPY);
|
|
|
|
GetDC()->Create(pDC);
|
|
CItemFocusRect::OnMouseMove(pDC, nFlags, point);
|
|
m_pBakCurCurve->m_pParentCurve->PointDistance(c_last.x0, c_last.y0, end_l0);
|
|
if (end_l0 >= m_pBakCurCurve->m_pParentCurve->l[0] &&
|
|
end_l0 <= m_pBakCurCurve->m_pParentCurve->l[m_pBakCurCurve->m_pParentCurve->num - 1])
|
|
{
|
|
DrawCurrentCurve(GetDC());
|
|
|
|
CCurveForInName* pCurve = (CCurveForInName*)GetXY()->GetAtValue(m_posCurEdit);
|
|
*pCurve = *m_pBakCurCurve;
|
|
pCurve->l0 = end_l0 - begin_l0 + m_pBakCurCurve->l0;
|
|
if (pCurve->l0 < 0)pCurve->l0 = end_l0;
|
|
double z0;
|
|
pCurve->m_pParentCurve->GetCoordinate(end_l0, c_last.x0, c_last.y0, z0);
|
|
pCurve->Offset(c_last.x0 - c_down.x0, c_last.y0 - c_down.y0);
|
|
|
|
CPoint2D p1, p2;
|
|
pCurve->m_pParentCurve->GetCoordinate(end_l0 - pCurve->dl*0.5, p1.x0, p1.y0, z0);
|
|
pCurve->m_pParentCurve->GetCoordinate(end_l0 + pCurve->dl*0.5, p2.x0, p2.y0, z0);
|
|
double angle = AfxGetPublicFunction()->GetAngle(p1.x0, p1.y0, p2.x0, p2.y0);
|
|
|
|
angle -= a0;
|
|
pCurve->Rotate(c_last.x0, c_last.y0, angle);
|
|
isDrag = true;
|
|
|
|
DrawCurrentCurve(GetDC());
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
void CItemEditCurveInName::OnLButtonUp(CDC* pDC, UINT nFlags, CPoint point, int vk)
|
|
{
|
|
GetDC()->Create(pDC);
|
|
//if(!IsCaptureState())
|
|
if(!isDrag)
|
|
{
|
|
//CPoint2D pt=GetDC()->GetReal(point);
|
|
//CRect8 rt=GetDoc()->GetSelectedRect(pt);
|
|
//DrawCurrentCurveHandle(GetDC());
|
|
//m_posCurEdit=GetXY()->IsInRange(rt);
|
|
//DrawCurrentCurveHandle(GetDC());
|
|
//SelectCurve(m_posCurEdit);
|
|
}
|
|
else
|
|
{
|
|
CItemFocusRect::OnLButtonUp(pDC, nFlags, point, vk);
|
|
m_isMoved = TRUE;
|
|
isDrag = false;
|
|
}
|
|
}
|
|
|
|
void CItemEditCurveInName::DoLButtonUp(CDC *pDC)
|
|
{
|
|
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);
|
|
|
|
CArray<double,double> listL;
|
|
|
|
//当按下Ctrl键时,复制一个内部名称
|
|
if(::IsKeyDown(VK_CONTROL))
|
|
listL.Add(m_pBakCurCurve->l0);
|
|
|
|
//删除备份曲线
|
|
SelectCurve(NULL);
|
|
//根据指针删除其列表范围线,并获得其桩号
|
|
GetInNameLocation(pCurve->m_pParentCurve, listL, TRUE);
|
|
//重设曲线内部的桩号
|
|
ResetOneAnyInName(posDoc, listL);
|
|
//刷新当前曲线的内部名称范围线
|
|
RecreateInName(posDoc);
|
|
|
|
CRect8 rt=GetDoc()->GetSelectedRect(c_last);
|
|
m_posCurEdit=GetXY()->IsInRange(rt);
|
|
SelectCurve(m_posCurEdit);
|
|
|
|
isDrag = false;
|
|
GetDoc()->Invalidate();
|
|
GetDoc()->Modified();
|
|
}
|
|
|
|
//重新生成一条曲线内部名称的范围线
|
|
void CItemEditCurveInName::RecreateInName(POSITION posDoc)
|
|
{
|
|
AfxGetPublicFunction()->EnableCurveInNameEditState(TRUE);
|
|
AfxGetPublicFunction()->m_pXyCurveEmbellish=GetXY();
|
|
AfxGetPublicFunction()->EnableJudgeRange(FALSE);
|
|
COne* pOne=GetDoc()->GetDraw()->GetAt(posDoc);
|
|
pOne->Draw(*GetDC()); //重画当前曲线的内部名称,生成新的名称范围线
|
|
AfxGetPublicFunction()->EnableJudgeRange(TRUE);
|
|
AfxGetPublicFunction()->m_pXyCurveEmbellish=NULL;
|
|
AfxGetPublicFunction()->EnableCurveInNameEditState(FALSE);
|
|
}
|
|
|
|
//根据指针删除其列表范围线,并获得其桩号
|
|
void CItemEditCurveInName::GetInNameLocation(CCurveEx* pParentCurve, CArray<double,double>& listL, BOOL bDeleteRange)
|
|
{
|
|
//删除当前曲线内部名称的范围线
|
|
CCurveForInName* pc;
|
|
POSITION pos,pt;
|
|
COne* pOne;
|
|
|
|
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)
|
|
{
|
|
listL.Add(pc->l0);
|
|
if(bDeleteRange)
|
|
{
|
|
plist->RemoveAt(pt);
|
|
delete pOne;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
int CItemEditCurveInName::ResetOneAnyInName(POSITION posDoc, CArray<double,double>& listL)
|
|
{
|
|
if(posDoc==NULL) 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;
|
|
CCurveInNameAny* pInNameAny=new CCurveInNameAny();
|
|
CCurveView* pd;
|
|
CCurveView *c;
|
|
for(int i=0;i<pOne->HowToViewCurve->GetCount();++i)
|
|
{
|
|
c=pOne->HowToViewCurve->GetAt(i);
|
|
switch(c->GetType())
|
|
{
|
|
case CurveInName:
|
|
case CurveInNameAny:
|
|
*(CCurveInName*)pInNameAny=*(CCurveInName*)c;
|
|
pInNameAny->SetType(CurveInNameAny);
|
|
pInNameAny->Create((int)listL.GetCount());
|
|
for(int j=0;j<listL.GetCount();j++)
|
|
pInNameAny->l0[j]=listL[j];
|
|
AfxGetPublicFunction()->SortDouble(pInNameAny->m_nameNum, pInNameAny->l0);
|
|
pd=pOne->HowToViewCurve->SetAt(i, pInNameAny);
|
|
if(c->GetType()==CurveInName)
|
|
delete (CCurveInName*)pd;
|
|
else
|
|
delete (CCurveInNameAny*)pd;
|
|
count++;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
if(count==0 && bOneNew)
|
|
{
|
|
delete pOne->HowToViewCurve;
|
|
pOne->HowToViewCurve=NULL;
|
|
}
|
|
return count;
|
|
}
|
|
|
|
BOOL CItemEditCurveInName::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
|
|
{
|
|
switch(nChar)
|
|
{
|
|
case VK_ESCAPE:
|
|
{
|
|
if (m_pScreenDC)
|
|
{
|
|
EndEdit(m_pScreenDC);
|
|
GetDC()->Create(m_pScreenDC);
|
|
DrawCurrentCurve(GetDC());
|
|
}
|
|
|
|
if (m_posCurEdit == 0)
|
|
return TRUE;
|
|
|
|
CCurveForInName* pCurve = (CCurveForInName*)GetXY()->GetAtValue(m_posCurEdit);
|
|
*pCurve = *m_pBakCurCurve;
|
|
if (m_pScreenDC)
|
|
DrawCurrentCurve(GetDC());
|
|
return TRUE;
|
|
}
|
|
break;
|
|
case VK_DELETE:
|
|
if(m_posCurEdit!=NULL)
|
|
{
|
|
DrawCurrentCurve(GetDC());
|
|
DrawCurrentCurveHandle(GetDC());
|
|
CCurveForInName* pCurve=(CCurveForInName*)GetXY()->GetAtValue(m_posCurEdit);
|
|
CCurveEx *pParentCurve=pCurve->m_pParentCurve;
|
|
GetXY()->RemoveAt(m_posCurEdit);
|
|
SelectCurve(NULL);
|
|
|
|
POSITION posDoc=FindCurve(pParentCurve);
|
|
if(posDoc)
|
|
{
|
|
//for redo/undo
|
|
ActionBackup(posDoc, IDS_EMBELLISH_CURVE_INNAME_ANY);
|
|
|
|
CArray<double,double> listL;
|
|
GetInNameLocation(pParentCurve, listL, FALSE);
|
|
ResetOneAnyInName(posDoc, listL);
|
|
GetDoc()->Invalidate(posDoc);
|
|
GetDoc()->Modified();
|
|
}
|
|
return TRUE;
|
|
}
|
|
break;
|
|
}
|
|
return CItemFocusRect::OnKeyUp(nChar, nRepCnt, nFlags);
|
|
}
|
|
|
|
BOOL CItemEditCurveInName::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
|
|
{
|
|
/*
|
|
if(::IsKeyDown(VK_CONTROL))
|
|
GetDoc()->GetCursor().SetCursor(CursorCopy4Way);
|
|
else
|
|
GetDoc()->GetCursor().SetCursor(CursorMove4Way);
|
|
return GetDoc()->GetCursor().SetCursor();
|
|
*/
|
|
return TRUE;
|
|
}
|
|
|
|
void CItemEditCurveInName::BeginEdit(CDC * pDC)
|
|
{
|
|
if (pDC == 0)
|
|
return;
|
|
|
|
Clear();
|
|
m_pXyNameRange=new CXy;
|
|
AfxGetPublicFunction()->EnableCurveInNameEditState(TRUE);
|
|
AfxGetPublicFunction()->m_pXyCurveEmbellish=GetXY();
|
|
AfxGetPublicFunction()->EnableJudgeRange(FALSE);
|
|
// GetDoc()->GetDraw()->Draw(*GetDC());
|
|
CXyDC * xyDC = GetDC();
|
|
xyDC->Create(pDC);
|
|
CXy* pxyMain = GetDoc()->GetDraw();
|
|
pxyMain->Draw(*xyDC);
|
|
AfxGetPublicFunction()->EnableJudgeRange(TRUE);
|
|
AfxGetPublicFunction()->m_pXyCurveEmbellish=NULL;
|
|
AfxGetPublicFunction()->EnableCurveInNameEditState(FALSE);
|
|
//GetDoc()->Invalidate();
|
|
}
|
|
|
|
void CItemEditCurveInName::EndEdit(CDC * pDC)
|
|
{
|
|
Clear();
|
|
//m_pXyNameRange = new CXy;
|
|
AfxGetPublicFunction()->EnableCurveInNameEditState(FALSE);
|
|
AfxGetPublicFunction()->m_pXyCurveEmbellish = GetXY();
|
|
AfxGetPublicFunction()->EnableJudgeRange(FALSE);
|
|
////GetDoc()->GetDraw()->Draw(*GetDC());
|
|
////xyDC->Create(pDC);
|
|
|
|
//CXyDC * xyDC = GetDC();
|
|
//GetDoc()->GetDraw()->Draw(*xyDC);
|
|
} |