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.

214 lines
4.7 KiB
C++

#include "stdafx.h"
#include "HTrackerBound.h"
#include "SigmaDoc.h"
HTrackerBound::HTrackerBound()
:m_pDoc(NULL)
{
}
//눼쉔朞嶝섞暠禱棍관앤近
bool HTrackerBound::CreateBoundRect(CSigmaDoc * pDoc, CPositionList & selectionSet, CRect & boundRectOut)
{
if (selectionSet.IsEmpty())
return false;
m_pDoc = pDoc;
CopySelectionSet(selectionSet);
m_boundRect.SetRect(0, 0, 0, 0);
//GetDoc()->GetTracker().Clear();
if (m_selectionSet.IsEmpty())
return false;
CArray<CPathItem*, CPathItem*> arrayPath;
POSITION pos, pt;
pos = m_selectionSet.GetHeadPosition();
while (pos != NULL)
{
Gdiplus::GraphicsPath path;
pt = m_selectionSet.GetNext(pos);
GetCOnePath(pt, path);
//CClientDC dc(GetView());
CalculateBoundRect(path, arrayPath);
}
boundRectOut = m_boundRect;
return true;
}
bool HTrackerBound::ReCreateBoundRect(CRect & boundRectOut)
{
CPositionList selectionSet;
selectionSet.AddTail(&m_selectionSet);
return CreateBoundRect(m_pDoc, m_selectionSet, boundRectOut);
}
void HTrackerBound::CopySelectionSet(CPositionList & selectionSet)
{
m_selectionSet.RemoveAll();
m_selectionSet.AddTail(&selectionSet);
}
void HTrackerBound::GetCOnePath(POSITION pos, Gdiplus::GraphicsPath & pathOut)
{
if (pos == NULL) return;
COne* pOne;
pOne = (COne*)m_pDoc->GetDraw()->GetAt(pos);
GetCOnePath(pOne, pathOut);
}
void HTrackerBound::GetCOnePath(COne* pOne, Gdiplus::GraphicsPath & pathOut)
{
if (pOne == NULL) return;
//Gdiplus::GraphicsPath path;
//path.Reset();
switch (pOne->GetType())
{
case DOUBLEFOX_CURVE:
LoadCurvePath(pathOut, (CCurveEx*)pOne->GetValue());
break;
case DOUBLEFOX_CIRCLE:
case DOUBLEFOX_ELLIPSE:
{
//CEllipse* pCircle = (CEllipse*)pOne->GetValue();
//CRect8 range = pOne->GetRect();
//CRect rt = GetDC()->GetScreen(range); rt.NormalizeRect();
//pathOut.AddEllipse(rt.left, rt.top, rt.Width(), rt.Height());
}
break;
case DOUBLEFOX_FRAME:
{
NBase::CRect8 posRect = pOne->GetRect();
posRect.NormalizeRect();
LoadRectPath(pathOut, posRect);
}
break;
case DOUBLEFOX_ARC:
LoadCurvePath(pathOut, ((CArc*)pOne->GetValue())->GetCurve());
break;
case DOUBLEFOX_XYZ:
case DOUBLEFOX_POINT:
{
NBase::CRect8 posRect = pOne->GetRect();
LoadRectPath(pathOut, posRect);
}
break;
default:
{
NBase::CRect8 posRect = pOne->GetRect();
LoadRectPath(pathOut, posRect);
}
break;
}
//CClientDC dc(GetView());
//GetDoc()->GetTracker().AddPath(path);
}
//삿돤朞嶝섞櫓돨杰唐혓窟。쉥혓窟돨
void HTrackerBound::LoadRectPath(Gdiplus::GraphicsPath& path, CRect8 rect)
{
CCurveEx* pCurve = new CCurveEx(5);
pCurve->CreateCurveFromRect(&rect);
LoadCurvePath(path, pCurve);
delete pCurve;
}
void HTrackerBound::LoadCurvePath(Gdiplus::GraphicsPath& path, CCurveEx* pc)
{
//(164,141),(296,141),(296,189),(164,189),(164,141)
if (pc == NULL)
return;
Gdiplus::Point * pt = new Gdiplus::Point[pc->num];
CPoint point;
for (int i = 0; i < pc->num; i++)
{
point = m_pDoc->GetDC().GetScreen(pc->x[i], pc->y[i]);
pt[i].X = point.x;
pt[i].Y = point.y;
}
path.AddCurve(pt, pc->num, 0);
delete[] pt;
}
void HTrackerBound::CalculateBoundRect(Gdiplus::GraphicsPath & pathIn, CArray<HTrackerBound::CPathItem*, HTrackerBound::CPathItem*> & arrayPathIn)
{
CPathItem* pItem = new CPathItem;
if (pItem->Load(pathIn))
{
arrayPathIn.Add(pItem);
//m_bLoaded = TRUE;
if (arrayPathIn.GetCount() > 1)
{
CRect rt = arrayPathIn[0]->m_rect;
for (int i = 1; i < arrayPathIn.GetCount(); i++)
rt |= arrayPathIn[i]->m_rect;
//Load(rt, TRUE, NULL);
m_boundRect = rt;
m_boundRect.NormalizeRect();
}
else
//Load(pItem->m_rect, TRUE, NULL);
{
m_boundRect = pItem->m_rect;
m_boundRect.NormalizeRect();
}
}
else
delete pItem;
}
HTrackerBound::CPathItem::CPathItem()
{
m_pGraphicsPath = NULL;
m_pPathPoints = NULL;
m_pPathTypes = NULL;
}
HTrackerBound::CPathItem::~CPathItem()
{
Clear();
}
BOOL HTrackerBound::CPathItem::Load(Gdiplus::GraphicsPath& path)
{
Clear();
m_pGraphicsPath = path.Clone();
if (!m_pGraphicsPath) return FALSE;
int n = path.GetPointCount();
if (n > 0)
{
// Reserve space for path points...
m_pPathPoints = new POINT[n];
// ... and for point types
m_pPathTypes = new BYTE[n];
// Get the point types. We'll retrieve the points in OnUpdate().
if (m_pPathTypes)
path.GetPathTypes(m_pPathTypes, n);
if (m_pPathPoints == NULL || m_pPathTypes == NULL)
{
Clear();
return FALSE;
}
}
Gdiplus::Rect rt;
path.GetBounds(&rt);
m_rect.SetRect(rt.GetLeft(), rt.GetTop(), rt.GetRight(), rt.GetBottom());
m_rect.NormalizeRect();
return TRUE;
}
void HTrackerBound::CPathItem::Clear()
{
if (m_pGraphicsPath) delete m_pGraphicsPath;
m_pGraphicsPath = NULL;
if (m_pPathPoints) delete[] m_pPathPoints;
m_pPathPoints = NULL;
if (m_pPathTypes) delete[] m_pPathTypes;
m_pPathTypes = NULL;
}