519 lines
10 KiB
C++
519 lines
10 KiB
C++
//-------------------------------------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, SH Software Co. Ltd.
|
|
// = FileName : XImageBufList 类
|
|
// = Version : ver2.0
|
|
// = Author : zjq
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: XImageBufList 定义
|
|
// = Maintainers:
|
|
//
|
|
//-------------------------------------------------------------------------------------------------------+
|
|
#include "StdAfx.h"
|
|
#include "XImageBufList.h"
|
|
#include "XStaticBuffer.h"
|
|
#include "XSlideLib.h"
|
|
#include "io.h"
|
|
#include "XPrivateGlobalFunc.h"
|
|
|
|
XImageBufList::XImageBufList()
|
|
{
|
|
|
|
}
|
|
|
|
XImageBufList::~XImageBufList()
|
|
{
|
|
|
|
}
|
|
|
|
XImageBufList & XImageBufList::operator = (XImageBufList &src)
|
|
{
|
|
Reset();
|
|
for (int i = 0; i < src.Length(); i++)
|
|
{
|
|
Append(new XImageBuf(*src[i]));
|
|
}
|
|
|
|
for (int i = 0; i < src.m_lstSolid.Length(); i++)
|
|
{
|
|
m_lstSolid.Append(new XColorSolid(*src.m_lstSolid[i]));
|
|
}
|
|
|
|
return *this;
|
|
}
|
|
|
|
void XImageBufList::Transform(ads_matrix mat)
|
|
{
|
|
for (int i = 0; i < Length(); i++)
|
|
{
|
|
XImageBuf &img = *(*this)[i];
|
|
|
|
XPoint pt = img.GetStartPoint();
|
|
AT_xformpt(mat, pt, img.StartPoint());
|
|
|
|
pt = img.GetEndPoint();
|
|
AT_xformpt(mat, pt, img.EndPoint());
|
|
}
|
|
|
|
for (int i = 0; i < m_lstSolid.Length(); i++)
|
|
{
|
|
XColorSolid &ln = *m_lstSolid[i];
|
|
ln.TransUCS(mat);
|
|
}
|
|
}
|
|
|
|
void XImageBufList::AppendSolid(int nColor, const XPoly &poly)
|
|
{
|
|
m_lstSolid.Append(new XColorSolid(nColor, poly));
|
|
}
|
|
|
|
void XImageBufList::Reset()
|
|
{
|
|
DList<XImageBuf>::Reset();
|
|
m_lstSolid.Reset();
|
|
}
|
|
|
|
void XImageBufList::WcsToDcs(int m_nSizeX, int m_nSizeY, int m_nOffset)
|
|
{
|
|
m_nSizeX -= m_nOffset * 2;
|
|
m_nSizeY -= m_nOffset * 2;
|
|
|
|
XPoint ptLow, ptUp;
|
|
if (GetExtend(ptLow, ptUp) != RTNORM)
|
|
{
|
|
return;
|
|
}
|
|
|
|
XPoint m_ptOrg = ptLow;
|
|
ads_real m_nModelX = ptUp.x - ptLow.x;
|
|
ads_real m_nModelY = ptUp.y - ptLow.y;
|
|
|
|
ads_real nScaleX = m_nModelX > 1.0E-6 ? m_nSizeX / m_nModelX : 1.0,
|
|
nScaleY = m_nModelY > 1.0E-6 ? m_nSizeY / m_nModelY : 1.0;
|
|
ads_real nMoveX = 0, nMoveY = 0; // 平移到中心的距离
|
|
|
|
nScaleX = nScaleY = min(nScaleX, nScaleY);
|
|
nMoveX = (m_nSizeX - nScaleX * m_nModelX) / 2.0;
|
|
nMoveY = (m_nSizeY - nScaleY * m_nModelY) / 2.0;
|
|
|
|
XImageBufList &lstMe = *this;
|
|
for (int i = 0; i < lstMe.Length(); i++)
|
|
{
|
|
XImageBuf &ln = *lstMe[i];
|
|
for (int j = 0; j < 2; j++)
|
|
{
|
|
XPoint &ptModel = j ? ln.EndPoint() : ln.StartPoint();
|
|
XPoint ptImage;
|
|
ptImage.x = (ptModel.x - m_ptOrg.x) * nScaleX;
|
|
ptImage.y = (ptModel.y - m_ptOrg.y) * nScaleY;
|
|
ptImage.x += m_nOffset + nMoveX;
|
|
ptImage.y += m_nOffset + nMoveY;
|
|
|
|
// Y翻转
|
|
ptImage.y = (m_nSizeY + 2 * m_nOffset) - ptImage.y;
|
|
ptModel = ptImage;
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < m_lstSolid.Length(); i++)
|
|
{
|
|
XColorSolid &ln = *m_lstSolid[i];
|
|
for (int j = 0; j < ln.Length(); j++)
|
|
{
|
|
XPoint &ptModel = *ln[j];
|
|
XPoint ptImage;
|
|
ptImage.x = (ptModel.x - m_ptOrg.x) * nScaleX;
|
|
ptImage.y = (ptModel.y - m_ptOrg.y) * nScaleY;
|
|
ptImage.x += m_nOffset + nMoveX;
|
|
ptImage.y += m_nOffset + nMoveY;
|
|
|
|
// Y翻转
|
|
ptImage.y = (m_nSizeY + 2 * m_nOffset) - ptImage.y;
|
|
ptModel = ptImage;
|
|
}
|
|
}
|
|
}
|
|
|
|
int XImageBufList::GetExtend(XPoint &ptLow, XPoint &ptUp)
|
|
{
|
|
XImageBufList &lstDispBuf = *this;
|
|
if (!lstDispBuf && !m_lstSolid)
|
|
{
|
|
return RTERROR;
|
|
}
|
|
|
|
BOOL bInit = FALSE;
|
|
for (int i = 0; i < lstDispBuf.Length(); i++)
|
|
{
|
|
XImageBuf &buf = *lstDispBuf[i];
|
|
XPoint pt1, pt2;
|
|
buf.GetExtend(pt1, pt2);
|
|
|
|
if (!bInit)
|
|
{
|
|
ptLow = pt1;
|
|
ptUp = pt2;
|
|
bInit = TRUE;
|
|
}
|
|
else
|
|
{
|
|
ptLow = Min(pt1, ptLow);
|
|
ptUp = Max(pt2, ptUp);
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < m_lstSolid.Length(); i++)
|
|
{
|
|
XColorSolid &buf = *m_lstSolid[i];
|
|
XPoint pt1, pt2;
|
|
buf.GetExtend(pt1, pt2);
|
|
|
|
if (!bInit)
|
|
{
|
|
ptLow = pt1;
|
|
ptUp = pt2;
|
|
bInit = TRUE;
|
|
}
|
|
else
|
|
{
|
|
ptLow = Min(pt1, ptLow);
|
|
ptUp = Max(pt2, ptUp);
|
|
}
|
|
}
|
|
|
|
return RTNORM;
|
|
}
|
|
|
|
int XImageBufList::FromSlide(const TCHAR *pszSlide)
|
|
{
|
|
TCHAR szSlb[256] = _T(""), szSld[256] = _T("");
|
|
char *pBuf = NULL;
|
|
unsigned nLen = 0;
|
|
|
|
if (SplitSlbName(pszSlide, szSlb, szSld) != RTNORM)
|
|
{
|
|
if (!FindFile(pszSlide, szSld))
|
|
{
|
|
return RTERROR;
|
|
}
|
|
|
|
//acutPrintf(_T("\nsld = %s"),szSld);
|
|
|
|
FILE *fp = _tfopen(szSld, _T("rb"));
|
|
if (!fp)
|
|
{
|
|
return RTERROR;
|
|
}
|
|
|
|
nLen = (unsigned) _filelength(_fileno(fp));
|
|
pBuf = new char [nLen];
|
|
|
|
fread(pBuf,sizeof(char),nLen,fp);
|
|
fclose(fp);
|
|
}
|
|
else
|
|
{
|
|
TCHAR *pExt = tstrchr_new(szSlb, '.');
|
|
|
|
if (!pExt)
|
|
{
|
|
_tcscat(szSlb, _T(".SLB"));
|
|
}
|
|
|
|
TCHAR szSlbPath[256] = _T("");
|
|
if (!FindFile(szSlb, szSlbPath))
|
|
{
|
|
return RTERROR;
|
|
}
|
|
|
|
XSlideLib slb(szSlbPath, _ios::binary|_ios::in);
|
|
if (!slb)
|
|
{
|
|
return RTERROR;
|
|
}
|
|
|
|
pBuf = slb.ReadItem(szSld, &nLen);
|
|
if (!pBuf)
|
|
{
|
|
return RTERROR;
|
|
}
|
|
}
|
|
|
|
XStaticBuffer iBuffer(pBuf, nLen);
|
|
|
|
#define SLIDE_MAXSLDRLEN 31
|
|
#define SLIDE_TEST_NUMBER 0x1234
|
|
#define SLIDE_ACADSLIDE "AutoCAD Slide"
|
|
#define SLIDE_OFFSETVECTOR '\xFB'
|
|
#define SLIDE_ENDOFFILE '\xFC'
|
|
#define SLIDE_SOLIDFILL '\xFD'
|
|
#define SLIDE_COMMONENDVECTOR '\xFE'
|
|
#define SLIDE_NEWCOLOR '\xFF'
|
|
|
|
char cvalue[1];
|
|
double pt[20],
|
|
lst[2];
|
|
short tvalue[1],
|
|
nverts[1];
|
|
char String[SLIDE_MAXSLDRLEN * 2 + 1],
|
|
*cp1;
|
|
short fi1,
|
|
color;
|
|
XPoint ptt[2];
|
|
double ar1,
|
|
ar2;
|
|
long aspect;
|
|
POINT *points = NULL;
|
|
BOOL testflag;
|
|
|
|
iBuffer.Read(String,SLIDE_MAXSLDRLEN);
|
|
if (_strnicmp(String,SLIDE_ACADSLIDE,strlen(SLIDE_ACADSLIDE) != 0)
|
|
|| String[18] < 1
|
|
|| String[18] > 2)
|
|
{
|
|
return RTERROR;
|
|
}
|
|
|
|
cp1 = (char *)(&fi1);
|
|
*(cp1) = *((char *)(String + 29));
|
|
*(cp1 + 1) = *((char *)(String + 30));
|
|
|
|
testflag = (SLIDE_TEST_NUMBER == fi1) ? FALSE : TRUE;
|
|
|
|
if (testflag)
|
|
{
|
|
cp1 = (char *)(&fi1);
|
|
*(cp1 + 1) = *((char *)(String + 19));
|
|
*(cp1) = *((char *)(String + 20));
|
|
}
|
|
else
|
|
{
|
|
fi1 = *((short *)(String + 19));
|
|
}
|
|
|
|
ar1 = fi1;
|
|
|
|
if (testflag)
|
|
{
|
|
cp1 = (char *)(&fi1);
|
|
*(cp1 + 1) = *((char *)(String + 21));
|
|
*(cp1) = *((char *)(String + 22));
|
|
}
|
|
else
|
|
{
|
|
fi1 = *((short *)(String + 21));
|
|
}
|
|
|
|
ar2 = fi1;
|
|
|
|
aspect = *((long *)(String + 23));
|
|
|
|
for (;;)
|
|
{
|
|
iBuffer.Read(String,2);
|
|
switch(String[(testflag) ? 0 : 1])
|
|
{
|
|
case SLIDE_OFFSETVECTOR:
|
|
iBuffer.Read(String + 2, 3);
|
|
|
|
memcpy(cvalue,String + ((testflag) ? 1 : 0),sizeof(char));
|
|
pt[0] = lst[0] + (double)cvalue[0];
|
|
|
|
memcpy(cvalue,String + 2,sizeof(char));
|
|
pt[1] = lst[1] + (double)cvalue[0];
|
|
|
|
memcpy(cvalue,String + 3,sizeof(char));
|
|
pt[2] = lst[0] + (double)cvalue[0];
|
|
|
|
memcpy(cvalue,String + 4,sizeof(char));
|
|
pt[3] = lst[1] + (double)cvalue[0];
|
|
|
|
// 保存最后一点
|
|
lst[0] = pt[0];
|
|
lst[1] = pt[1];
|
|
|
|
Append(new XImageBuf(XPoint(pt[0], pt[1]), XPoint(pt[2],pt[3]),color));
|
|
|
|
break;
|
|
case SLIDE_ENDOFFILE:
|
|
goto err;
|
|
case SLIDE_SOLIDFILL:
|
|
iBuffer.Read(String,4);
|
|
if (testflag)
|
|
{
|
|
cp1 = (char *)(&fi1);
|
|
*(cp1 + 1) = *((char *)(String + 1));
|
|
*(cp1) = *((char *)(String));
|
|
|
|
nverts[0] = (short)cp1;
|
|
}
|
|
else
|
|
{
|
|
memcpy(nverts,String,sizeof(short));
|
|
}
|
|
|
|
if (testflag)
|
|
{
|
|
cp1 = (char *)(&fi1);
|
|
*(cp1 + 1) = *((char *)(String + 3));
|
|
*(cp1) = *((char *)(String + 2));
|
|
|
|
tvalue[0] = (short)cp1;
|
|
}
|
|
else
|
|
{
|
|
memcpy(tvalue,String + 2,sizeof(short));
|
|
}
|
|
|
|
if (nverts[0] > 1 && (2 * nverts[0]) <= sizeof(pt) / sizeof(pt[0]) && tvalue[0] < 0)
|
|
{
|
|
if ((points = (POINT *)calloc(nverts[0],sizeof(POINT))) == NULL)
|
|
{
|
|
ASSERT(false);
|
|
goto err;
|
|
}
|
|
|
|
for (fi1 = 0; fi1 < nverts[0]; ++fi1)
|
|
{
|
|
iBuffer.Read(String,2);
|
|
if (String[(testflag) ? 0 : 1] != SLIDE_SOLIDFILL)
|
|
{
|
|
goto err;
|
|
}
|
|
|
|
iBuffer.Read(String,4);
|
|
|
|
if (testflag)
|
|
{
|
|
cp1 = (char *)(&fi1);
|
|
*(cp1 + 1) = *((char *)(String + 1));
|
|
*(cp1) = *((char *)(String));
|
|
|
|
tvalue[0] = (short)cp1;
|
|
}
|
|
else
|
|
{
|
|
memcpy(tvalue,String,sizeof(short));
|
|
}
|
|
|
|
pt[fi1 * 2] = tvalue[0];
|
|
|
|
if (testflag)
|
|
{
|
|
cp1 = (char *)(&fi1);
|
|
*(cp1 + 1) = *((char *)(String + 1));
|
|
*(cp1) = *((char *)(String));
|
|
|
|
tvalue[0] = (short)cp1;
|
|
}
|
|
else
|
|
{
|
|
memcpy(tvalue,String + 2,sizeof(short));
|
|
}
|
|
|
|
pt[fi1 * 2 + 1] = tvalue[0];
|
|
|
|
if (pt[fi1 * 2 + 1] < 0)
|
|
{
|
|
if (fi1 != nverts[0] - 1)
|
|
{
|
|
ASSERT(false);
|
|
goto err;
|
|
}
|
|
|
|
nverts[0]--;
|
|
}
|
|
|
|
points[fi1].x = (long)pt[fi1 * 2];
|
|
points[fi1].y = (long)pt[fi1 * 2 + 1];
|
|
}
|
|
|
|
XPoly poly;
|
|
for (int kk = 0; kk < *nverts; kk++)
|
|
{
|
|
poly.Append(new XPoint(points[kk].x, points[kk].y));
|
|
}
|
|
|
|
AppendSolid(color, poly);
|
|
|
|
free(points);
|
|
points = NULL;
|
|
}
|
|
break;
|
|
case SLIDE_COMMONENDVECTOR:
|
|
iBuffer.Read(String + 2, 1);
|
|
pt[0] = lst[0];
|
|
pt[1] = lst[1];
|
|
|
|
memcpy(cvalue, String + ((testflag) ? 1 : 0), sizeof(char));
|
|
lst[0] = pt[2] = pt[0] + (double)cvalue[0];
|
|
memcpy(cvalue,String + 2,sizeof(char));
|
|
lst[1] = pt[3] = pt[1] + (double)cvalue[0];
|
|
|
|
Append(new XImageBuf(XPoint(pt[0], pt[1]), XPoint(pt[2], pt[3]), color));
|
|
break;
|
|
case SLIDE_NEWCOLOR:
|
|
color = String[(testflag) ? 1 : 0];
|
|
if (color < 0)
|
|
{
|
|
color = 256 + color;
|
|
}
|
|
|
|
if (color > 255 || color < 0)
|
|
{
|
|
color = 7;
|
|
}
|
|
|
|
break;
|
|
default:
|
|
if (String[(testflag) ? 0 : 1] < 0)
|
|
{
|
|
goto err;
|
|
}
|
|
|
|
if (testflag)
|
|
{
|
|
memcpy((char *)tvalue, String + 1, sizeof(char));
|
|
memcpy((char *)tvalue + 1, String, sizeof(char));
|
|
}
|
|
else
|
|
{
|
|
memcpy(tvalue, String, sizeof(short));
|
|
}
|
|
|
|
pt[0] = (double)tvalue[0];
|
|
for (fi1 = 1; fi1 < 4; ++fi1)
|
|
{
|
|
iBuffer.Read(String,2);
|
|
|
|
if (testflag)
|
|
{
|
|
memcpy((char *)tvalue, String + 1, sizeof(char));
|
|
memcpy((char *)tvalue + 1, String, sizeof(char));
|
|
}
|
|
else
|
|
{
|
|
memcpy(tvalue, String, sizeof(short));
|
|
}
|
|
|
|
pt[fi1] = (double)tvalue[0];
|
|
}
|
|
|
|
lst[0] = pt[0];
|
|
lst[1] = pt[1];
|
|
|
|
ptt[0][0] = pt[0];
|
|
ptt[0][1] = pt[1];
|
|
ptt[1][0] = pt[2];
|
|
ptt[1][1] = pt[3];
|
|
|
|
Append(new XImageBuf(XPoint(pt[0], pt[1]), XPoint(pt[2], pt[3]), color));
|
|
break;
|
|
}
|
|
}
|
|
|
|
err:
|
|
ASSERT(!points);
|
|
|
|
return RTNORM;
|
|
}
|