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.

553 lines
11 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "StdAfx.h"
#include ".\item.h"
#include "SigmaDoc.h"
#include "SigmaView.h"
#include "ItemTracker.h"
#include "ActionAdditem.h"
#include ".\itemselect.h"
#include "StatusDefine.h"
namespace NItem
{
CItem::CItem(CSigmaDoc * ppDoc)
: CItemBase(ppDoc)
, bUpdatePropertyGrid(true)
, m_nCurHandleIndex(-1)
, m_bModifiedFlag(FALSE)
{
position=NULL;
if(GetDoc() && GetDoc()->GetDraw())
{
m_unitMode.SetTransform(GetDoc()->GetDraw()->m_dScaleFactor, GetDoc()->GetDraw()->m_unit.cx);
m_unitMode.m_nMode = GetDoc()->m_nUnitMode;
}
m_pItemOwner = this;
m_pStatusText = new char[1024];
ClearStatus();
m_bNestItem = FALSE;
}
CItem::~CItem(void)
{
delete[] m_pStatusText;
position=NULL;
m_pStatusText = nullptr;
}
bool CItem::IsEditState(void)
{
if(position) return true;
return false;
}
void CItem::SetPos(POSITION pos)
{
position=pos;
}
POSITION CItem::GetPos(void)
{
return position;
}
POSITION CItem::AddElement(void* pValue, int type, bool bUpdateView, bool bWithUndo)
{
POSITION pos=GetDoc()->GetDraw()->AddElement(pValue,type);
if(pos && bUpdateView)
GetDoc()->Invalidate(pos);
GetDoc()->Modified();
// Redo/Undo surport
if(bWithUndo)
{
COne* pOne = GetDoc()->GetDraw()->GetAt(pos);
GetDoc()->SetActionItem(new CActionAddItem(GetDoc(), IDS_STRING_ACTION_ADD, pOne));
//GetView()->ActionAdd(pOne);
}
return pos;
}
POSITION CItem::AddTailOne(COne* pOne)
{
return GetDoc()->GetDraw()->AddTailOne(pOne);
}
POSITION CItem::InsertElementBefore(POSITION pos, COne* pNewOne, BOOL bUpdateView)//COne* pNewOne
{
POSITION p=GetDoc()->GetDraw()->InsertElementBefore(pos,pNewOne);
if(p && bUpdateView)
GetDoc()->Invalidate(pos);
GetDoc()->Modified();
return p;
}
POSITION CItem::InsertElementAfter(POSITION pos, void * pElement, int nType, BOOL bUpdateView)//COne* pNewOne
{
POSITION p = GetDoc()->GetDraw()->InsertElementAfter(pos, pElement, nType);
if (p && bUpdateView)
GetDoc()->Invalidate(pos);
GetDoc()->Modified();
return p;
}
void CItem::DeleteElement(POSITION pos)
{
if(pos==NULL) return;
CList<POSITION,POSITION> select;
select.AddTail(pos);
GetDoc()->InvalidateDelete(select);
}
int CItem::GetStatusCode() const
{
return m_nStatusCode;
}
const char *CItem::GetStatusText() const
{
return m_pStatusText;
}
void CItem::SetStatusCode(int code)
{
m_nStatusCode = code;
}
void CItem::SetStatusText(const char * pText)
{
strcpy_s(m_pStatusText, 1024, pText);
}
void CItem::ClearStatus()
{
m_nStatusCode = STATUS_CODE_SUCCESS;
memset(m_pStatusText, 0, 1024);
}
/*
BOOL CItem::InitPropertyGrid(CXTPPropertyGrid& grid)
{
if(!this->IsEditState()) return FALSE;
COne* pOne=(COne*)GetDoc()->GetDraw()->GetAt(GetPos());
CPropertyGridItemAdd ItemAdd(NULL);
CXTPPropertyGridItem* pItem=grid.AddCategory(IDS_STRING_Other);
ItemAdd.SetItem(pItem); pItem->Expand();
CString layer=GetGridItemComboLayer();
pItem=ItemAdd.AddItemCombo(IDS_STRING_PANE_LAYER_MANAGER, layer, pOne->GetLayer()->GetPathName());
ItemAdd.AddItemHyperlink(IDS_STRING_HYPERLINK, &pOne->pHyperlink);
//pItem->SetReadOnly(TRUE);
return TRUE;
}
*/
CString CItem::GetGridItemComboLayer(void)
{
CString layer=_T("");
CLayer *value;
CLayerList* lc;
POSITION pos=GetDoc()->GetDraw()->GetClassList()->GetHeadPosition();
while(pos)
{
lc=GetDoc()->GetDraw()->GetClassList()->GetNext(pos);
CPtrList *pList=lc->GetPtrList();
POSITION p,pos;
p=pList->GetHeadPosition();
while(p)
{
pos=p;
value=(CLayer*)(pList->GetNext(p));
if(!layer.IsEmpty()) layer+="|";
layer+=lc->GetPathName(pos);
}
}
return layer;
}
CSigmaDoc * CItem::GetDoc(void)
{
return (CSigmaDoc*)GetDrawDoc();
}
/*
BOOL CItem::OnGridItemChangeValue(CXTPPropertyGridItem* pItem)
{
if(!this->IsEditState()) return FALSE;
COne* pOne=(COne*)GetDoc()->GetDraw()->GetAt(GetPos());
BOOL bUpdate=FALSE;
switch(pItem->GetID())
{
case 0:
break;
case IDS_STRING_PANE_LAYER_MANAGER:
GetDoc()->GetDraw()->SetElementLayer(GetPos(), pItem->GetValue());
bUpdate=TRUE;
break;
case IDS_STRING_HYPERLINK:
{
CString str=pItem->GetValue();
if(!str.IsEmpty())
{
if(pOne->pHyperlink==NULL)
pOne->pHyperlink=new CHyperlinkMulti;
pOne->pHyperlink->hyperlink=str;
pOne->pHyperlink->SetParent(pOne);
}
else
{
if(pOne->pHyperlink) delete pOne->pHyperlink;
pOne->pHyperlink=NULL;
}
}
bUpdate=TRUE;
break;
}
return bUpdate;
}
BOOL CItem::InitPropertyGridMul(CXTPPropertyGrid& grid)
{
CItemSelect* pSelect=GetDoc()->GetSelectItem();
if(pSelect==NULL) return FALSE;
CPropertyGridItemAdd ItemAdd(NULL);
CXTPPropertyGridItem* pItem=grid.AddCategory(IDS_STRING_Other);
ItemAdd.SetItem(pItem); pItem->Expand();
CString cmd;
CString layer;
CLayer *value;
CLayerList* lc;
POSITION pos=GetDoc()->GetDraw()->GetClassList()->GetHeadPosition();
while(pos)
{
lc=GetDoc()->GetDraw()->GetClassList()->GetNext(pos);
CPtrList *pList=lc->GetPtrList();
POSITION p,pos;
p=pList->GetHeadPosition();
while(p)
{
pos=p;
value=(CLayer*)(pList->GetNext(p));
if(!layer.IsEmpty()) layer+="|";
layer+=lc->GetPathName(pos);
}
}
pItem=ItemAdd.AddItemCombo(IDS_STRING_PANE_LAYER_MANAGER, layer, m_strLayerMul, &m_strLayerMul);
ItemAdd.AddItemHyperlink(IDS_STRING_HYPERLINK, &m_pHyperlinkMul);
//pItem->SetReadOnly(TRUE);
return TRUE;
}
*/
CString CItem::m_strLayerMul=_T(""); //Ϊ<>˶<EFBFBD><CBB6><EFBFBD><EFBFBD><EFBFBD>ͬԪ<CDAC>صIJ<D8B5><C4B2><EFBFBD>
CHyperlinkMulti* CItem::m_pHyperlinkMul=NULL;
void CItem::InitializationMul(void)
{
CItem::m_strLayerMul=_T(""); //Ϊ<>˶<EFBFBD><CBB6><EFBFBD><EFBFBD><EFBFBD>ͬԪ<CDAC>صIJ<D8B5><C4B2><EFBFBD>
if(CItem::m_pHyperlinkMul)
delete CItem::m_pHyperlinkMul;
CItem::m_pHyperlinkMul=NULL;
}
/*
BOOL CItem::OnGridItemChangeValueMul(CXTPPropertyGridItem* pItem)
{
CItemSelect* pSelect=GetDoc()->GetSelectItem();
if(pSelect==NULL) return FALSE;
BOOL bUpdate=FALSE;
switch(pItem->GetID())
{
case 0:
break;
case IDS_STRING_HYPERLINK:
{
CString str=pItem->GetValue();
if(!str.IsEmpty())
{
if(CItem::m_pHyperlinkMul==NULL)
CItem::m_pHyperlinkMul=new CHyperlinkMulti;
CItem::m_pHyperlinkMul->hyperlink=str;
CItem::m_pHyperlinkMul->SetParent(NULL);
}
else
{
if(CItem::m_pHyperlinkMul) delete CItem::m_pHyperlinkMul;
CItem::m_pHyperlinkMul=NULL;
}
}
bUpdate=TRUE;
break;
}
CPositionList* pList=&(pSelect->m_selection);
COne* pOne;
POSITION pos,pt;
pos=pList->GetHeadPosition();
while(pos)
{
pt=pList->GetNext(pos);
pOne=GetDoc()->GetDraw()->GetAt(pt);
switch(pItem->GetID())
{
case 0:
break;
case IDS_STRING_PANE_LAYER_MANAGER:
GetDoc()->GetDraw()->SetElementLayer(pt, m_strLayerMul);
bUpdate=TRUE;
break;
case IDS_STRING_HYPERLINK:
pOne->CopySetHyperlink(CItem::m_pHyperlinkMul);
bUpdate=TRUE;
break;
}
}
return bUpdate;
}
*/
void CItem::Invalidate(void)
{
if(GetPos())
GetDoc()->Invalidate(GetPos());
else
GetDoc()->Invalidate();
}
/*
CXTPPropertyGridItem* CItem::FindItem(CXTPPropertyGridItem* pItem, UINT nID)
{
if(pItem==NULL || nID==0) return NULL;
return ((CXTPPropertyGridView*)(pItem->GetGrid()))->GetPropertyGrid()->FindItem(nID);
}
*/
bool CItem::IsUpdatePropertyGrid(void)
{
return bUpdatePropertyGrid;
}
void CItem::SetUpdatePropertyGridState(bool bUpdate)
{
bUpdatePropertyGrid=bUpdate;
}
int CItem::GetHandleIndex(void)
{
return m_nCurHandleIndex;
}
void CItem::SetHandleIndex(int nIndex)
{
m_nCurHandleIndex=nIndex;
}
BOOL CItem::IsModified(void)
{
return m_bModifiedFlag;
}
void CItem::SetModifiedFlag(BOOL bModified)
{
m_bModifiedFlag=bModified;
}
int CItem::GetSelectSubMenu(void)
{
return 5;
}
/*
//(0=Close, 1=Show, 2=Hide)
int CItem::ShowPropertyPane(int bShow)
{
CMainFrame* pmf = (CMainFrame*)GetDoc()->GetMainFrame();
if(pmf==NULL) return 0;
BOOL IsVisible(CWnd* pWnd);
int br=0;
if(IsVisible(&pmf->m_panePropertyGrid)) br=1;
if(pmf->GetDockingPaneManager()->IsPaneHidden(COMMAND_BAR_PROPERTIES)) br=2;
switch(bShow)
{
case 0:
if(br!=0) pmf->ClosePane(COMMAND_BAR_PROPERTIES);
break;
case 1:
if(br!=1) pmf->ShowPane(COMMAND_BAR_PROPERTIES);
break;
case 2:
if(br!=2) pmf->GetDockingPaneManager()->HidePane(COMMAND_BAR_PROPERTIES);
break;
}
return br;
}
*/
void CItem::DrawCurveHandle(CXyDC* pDC, CCurveEx* pCurve, COLORREF color, int nMode, BOOL bDrawLine, int penWidth)
{
if(pCurve==NULL) return;
CPen pen;
CPen * pOldPen = 0;
CRect rt;
if(bDrawLine)
{
pen.CreatePen(PS_SOLID, penWidth, color);
pOldPen=pDC->GetDC()->SelectObject(&pen);
pDC->MoveTo(pCurve->x[0],pCurve->y[0]);
}
int i;
CItemTracker tracker;
for(i=1;i<pCurve->num;i++)
{
if(bDrawLine)
pDC->LineTo(pCurve->x[i],pCurve->y[i]);
//draw handle
rt = tracker.GetHandleRect(pDC->GetSX(pCurve->x[i-1]),pDC->GetSY(pCurve->y[i-1]));
tracker.DrawHandle(GetDC()->GetDC(),rt,nMode);
}
//draw handle
rt= tracker.GetHandleRect(pDC->GetSX(pCurve->x[i-1]),pDC->GetSY(pCurve->y[i-1]));
tracker.DrawHandle(GetDC()->GetDC(),rt,nMode);
if(bDrawLine)
pDC->GetDC()->SelectObject(pOldPen);
}
dfPoint CItem::GetShiftDownPoint(double begin_x, double begin_y, double end_x, double end_y)
{
dfPoint dd; dd.x0 = end_x; dd.y0 = end_y;
double angle = AfxGetPublicFunction()->GetAngle(begin_x, begin_y, end_x, end_y);
if( (angle>=60.0 && angle<=120.0) ||
(angle<=-60.0&& angle>=-120.0) )
{
dd.x0 = begin_x;
dd.y0 = end_y;
}
else if( fabs(angle)<=30.0 || fabs(angle)>=150.0 )
{
dd.x0 = end_x;
dd.y0 = begin_y;
}
else
{
double dx = end_x-begin_x;
double dy = end_y-begin_y;
double fx = fabs(dx)/dx;
double fy = fabs(dy)/dy;
double max = fabs(dx);
if(max<fabs(dy)) max = fabs(dy);
dd.x0 = begin_x+max*fx;
dd.y0 = begin_y+max*fy;
}
return dd;
}
POSITION CItem::FindCurve(CCurveEx* pCurve) //<2F><><EFBFBD><EFBFBD>GetDoc()->GetDraw()<29>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>
{
CPtrList* plist=GetDoc()->GetDraw()->GetValueList();
POSITION pos,pt;
COne* pOne;
pos=plist->GetHeadPosition();
while(pos)
{
pt=pos;
pOne=(COne*)plist->GetNext(pos);
if(pOne->GetType()!=DOUBLEFOX_CURVE)continue;
if(((CCurveEx*)pOne->GetValue())==pCurve)
return pt;
}
return NULL;
}
int CItem::GetUnit() //<2F><><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><C7B0>ʾ<EFBFBD><CABE>λ
{
return GetUnitMode().GetShowUnit();
}
CUnitTransform& CItem::GetUnitMode()
{
return m_unitMode;
}
///////////////////////////////////////////////////////////////////////////////////
CItemViewEx::CItemViewEx(void)
: CItemView()
{
}
CItemViewEx::CItemViewEx(CSigmaDoc * ppDoc)
: CItemView(ppDoc)
{
}
CItemViewEx::~CItemViewEx(void)
{
}
BOOL CItemViewEx::GetViewRange(CRect8& rect) //<2F><><EFBFBD><EFBFBD>Ҫȫͼ<C8AB><CDBC>ʾ<EFBFBD>ķ<EFBFBD>Χ
{
if(CItemView::GetViewRange(rect))
return TRUE;
CSigmaDoc * pDoc = GetDrawDoc();
//if(pDoc->m_pItemMakeMark)
//{
// //rect=pDoc->m_pItemMakeMark->m_rect; //***Ҫʵ<D2AA><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD>
// //rect.InflateRect(rect.Width()*0.1, rect.Height()*0.1);
//}
//else
{
CRect m_window=GetClientRect();
if(m_window.Width()<100) m_window.SetRect(0,0,640,480);
rect.SetRect(m_window.left,m_window.bottom,m_window.right,m_window.top);
}
return TRUE;
}
CItemPrintEx::CItemPrintEx(CSigmaDoc * ppDoc)
: CItemPrint(ppDoc)
{
}
CItemPrintEx::~CItemPrintEx(void)
{
}
void CItemPrintEx::AfterEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
//<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD>˱<EFBFBD><CBB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡԤ<D3A1><D4A4>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>ͬ
//BOOL bSetCurScale=::GetPreferences().OtherPrint.m_bSetScale;
BOOL bSetCurScale = TRUE;
if(bSetCurScale)
{
CSigmaDoc * pDoc = (CSigmaDoc*)GetDrawDoc();
CItemSelect* pItem = pDoc->GetSelectItem();
if(pItem)pItem->ReloadTrackerPath();
}
}
}//namespace