#include "stdafx.h" #include "AcGiUtil.h" #include "dbobjptr.h" static int CompareRange(const TGridRange *p1, const void *p2) { return (p1!=p2); } #define LSF_DEFAULT 0.4 Acad::ErrorStatus CalInsertParameters(const AcDbBlockReference *pBlkSrc, XPoint &ptNewBase, double *nRotation, double *nSx, double *nSy, double *nSz,TBlockGeomInfo info) { ads_matrix matRotOld, matMove, matScale, matRotNew, matTransform; double nSizeX, nSizeY, nSizeZ, nRot; XPoint ptBase, ptCen, ptNewCen; VERIFY(GetBlockRefSizeInfo(pBlkSrc, ptBase, &nRot, ptCen, &nSizeX, &nSizeY, &nSizeZ)==RTNORM); ptNewCen = info.m_ptCen; ptNewCen.z += info.m_nSizeZ/2.0; // 绕旧中心旋转-nRotOld -> 绕旧中心Scale -> 平移到新中心 -> 旋转 RotNew // or // 绕旧中心旋转-nRotOld -> 绕旧中心Scale -> 旋转 RotNew -> 平移到新中心 (Current Method) AcGeScale3d bScale = pBlkSrc->scaleFactors(); double sx=1, sy=1, sz=1; if(fabs(nSizeX)>1.0E-6) bScale[0] *= (sx = info.m_nSizeX/nSizeX); if(fabs(nSizeY)>1.0E-6) bScale[1] *= (sy = info.m_nSizeY/nSizeY); if(fabs(nSizeZ)>1.0E-6) bScale[2] *= (sz = info.m_nSizeZ/nSizeZ); ptCen.GetRotationMatrix(-nRot, matRotOld); ptCen.GetScaleMatrix(sx, sy, sz, matScale); ptCen.GetRotationMatrix(info.m_nRotation, matRotNew); ptCen.GetMoveMatrix(ptNewCen, matMove); MatrixMultiply(matTransform, matMove, matRotNew, matScale, matRotOld, NULL); ptNewBase = ptBase.TransformAs(matTransform); //换算新的基点位置 *nRotation = info.m_nRotation; *nSx = bScale[0]; *nSy = bScale[1]; *nSz = bScale[2]; return Acad::eOk; } void UpdateInsert(AcDbBlockReference *pInsert,TBlockGeomInfo info,BOOL bUniScale) { XPoint ptNewBase; double nNewRot; AcGeScale3d scale; if(CalInsertParameters(pInsert, ptNewBase, &nNewRot, &scale[0], &scale[1], &scale[2],info)!=Acad::eOk) return; pInsert->setPosition(ptNewBase); pInsert->setRotation(nNewRot); if(bUniScale) { double dScale = min(scale[0], scale[1]); pInsert->setScaleFactors(AcGeScale3d(dScale,dScale,dScale)); } else { pInsert->setScaleFactors(scale); } } //////////////////////////////////////////// // 方格的样式 //TArch5\6,1;TArch7,2 const Adesk::UInt8 TGridStyle::g_nVersion=2; TGridStyle::TGridStyle() { m_nOverride=0; //override parent's style (none) m_nHorMode = AcDb::kTextLeft; // Specifies the horizontal text alignment m_nVerMode = AcDb::kTextBase; // AcDbHardPointerId m_idTextStyle; // Font m_nTextColor=0; //Controls the foreground(Text) color m_bTextWrap=true; // Word wraps cell text when true m_nLineSpaceFactor=LSF_DEFAULT; //自动换行时的行距系数(行距=系数*字高) m_nTextHeight=3.0; m_nTextDirection=kRight; } TGridStyle::TGridStyle(const TGridStyle &src) { *this = src; } TGridStyle & TGridStyle::operator = (const TGridStyle &src) { CopyObject(src, *this); return *this; } Acad::ErrorStatus TGridStyle::dwgInFields (AcDbDwgFiler* pFiler) { Adesk::UInt8 nVer=0; pFiler->readItem(&nVer); if(nVer>g_nVersion) // Version is too new return Acad::eMakeMeProxy; pFiler->readItem(&m_nOverride); if(m_nOverride&OF_HORMODE) { Adesk::UInt8 align; pFiler->readItem(&align); m_nHorMode=(AcDb::TextHorzMode)align; } if(m_nOverride&OF_VERMODE) { Adesk::UInt8 align; pFiler->readItem(&align); m_nVerMode=(AcDb::TextVertMode)align; } if(m_nOverride&OF_TEXTSTYLE) { pFiler->readItem(&m_idTextStyle); } if(m_nOverride&OF_TEXTCOLOR) { pFiler->readItem(&m_nTextColor); } if(m_nOverride&OF_TEXTWRAP) { pFiler->readItem(&m_bTextWrap); } if(m_nOverride&OF_LINESPACE) { pFiler->readItem(&m_nLineSpaceFactor); } if(m_nOverride&OF_TEXTHEIGHT) { pFiler->readItem(&m_nTextHeight); } if(nVer>1) { Adesk::UInt8 nDirection; pFiler->readItem(&nDirection); m_nTextDirection=(TextDirection)nDirection; } return pFiler->filerStatus(); } Acad::ErrorStatus TGridStyle::dwgOutFields(AcDbDwgFiler* pFiler) const { if(g_nSaveTArchVer<7) pFiler->writeItem((Adesk::UInt8)1); else pFiler->writeItem(g_nVersion); pFiler->writeItem(m_nOverride); if(m_nOverride&OF_HORMODE) pFiler->writeItem((Adesk::UInt8)m_nHorMode); if(m_nOverride&OF_VERMODE) pFiler->writeItem((Adesk::UInt8)m_nVerMode); if(m_nOverride&OF_TEXTSTYLE) pFiler->writeItem(m_idTextStyle); if(m_nOverride&OF_TEXTCOLOR) pFiler->writeItem(m_nTextColor); if(m_nOverride&OF_TEXTWRAP) pFiler->writeItem(m_bTextWrap); if(m_nOverride&OF_LINESPACE) pFiler->writeItem(m_nLineSpaceFactor); if(m_nOverride&OF_TEXTHEIGHT) pFiler->writeItem(m_nTextHeight); if(g_nSaveTArchVer>6) pFiler->writeItem((Adesk::UInt8)m_nTextDirection); return pFiler->filerStatus(); } void TGridStyle::SetOverrideAll(BOOL bTrue) { if(bTrue) m_nOverride=(OF_HORMODE|OF_VERMODE|OF_TEXTSTYLE|OF_TEXTCOLOR| OF_TEXTWRAP|OF_LINESPACE|OF_TEXTHEIGHT); else m_nOverride=0; } void TGridStyle::SetFlagBit(int nFlag, BOOL bSet) { if(bSet) { m_nOverride |= nFlag; } else { m_nOverride &= ~nFlag; } } void TGridStyle::SetTextStyleId(AcDbObjectId id) { m_idTextStyle=id; } void TGridStyle::SetTextColor(Adesk::UInt16 nColor) { m_nTextColor=nColor; } void TGridStyle::SetTextWrap(BOOL bTrue) { m_bTextWrap=bTrue; } void TGridStyle::SetLineSpaceFactor(double nFactor) { m_nLineSpaceFactor=nFactor; } void TGridStyle::SetTextHeight(double h) { m_nTextHeight=h; } BOOL TGridStyle::TestFlagBit(int nFlag) const { return ((m_nOverride&nFlag)!=0); } AcDbObjectId TGridStyle::GetTextStyleId() const { return m_idTextStyle; } Adesk::UInt16 TGridStyle::GetTextColor() const { return m_nTextColor; } BOOL TGridStyle::IsTextWrap() const { return m_bTextWrap; } double TGridStyle::GetLineSpaceFactor() const { return m_nLineSpaceFactor; } double TGridStyle::GetTextHeight() const { return m_nTextHeight; } void TGridStyle::SetVerMode(AcDb::TextVertMode nVerMode) { m_nVerMode=nVerMode; } void TGridStyle::SetHorMode(AcDb::TextHorzMode nHorMode) { m_nHorMode=nHorMode; } AcDb::TextHorzMode TGridStyle::GetHorMode() const { return m_nHorMode; } AcDb::TextVertMode TGridStyle::GetVerMode() const { return m_nVerMode; } ///////////////////////////////////// // 分割线样式 const Adesk::UInt8 TDividerStyle::g_nVersion=1; TDividerStyle::TDividerStyle() { m_nFlag=kParent; m_nColor=0; //AcDbHardPointerId m_idLineType; //线型 m_nLineWidth=0.0; //线宽 } TDividerStyle::TDividerStyle(const TDividerStyle &src) { *this = src; } TDividerStyle & TDividerStyle::operator= (const TDividerStyle &src) { CopyObject(src, *this); return *this; } Acad::ErrorStatus TDividerStyle::dwgInFields (AcDbDwgFiler* pFiler) { Adesk::UInt8 nVer=0; pFiler->readItem(&nVer); if(nVer>g_nVersion) // Version is too new return Acad::eMakeMeProxy; Adesk::UInt8 nTemp; pFiler->readItem(&nTemp); m_nFlag=(TDividerFlag)nTemp; if(m_nFlag==TDividerStyle::kLocal) { pFiler->readItem(&m_nColor); pFiler->readItem(&m_idLineType); pFiler->readItem(&m_nLineWidth); } return pFiler->filerStatus(); } Acad::ErrorStatus TDividerStyle::dwgOutFields(AcDbDwgFiler* pFiler) const { pFiler->writeItem(g_nVersion); pFiler->writeItem((Adesk::UInt8 )m_nFlag); if(m_nFlag==TDividerStyle::kLocal) { pFiler->writeItem(m_nColor); pFiler->writeItem(m_idLineType); pFiler->writeItem(m_nLineWidth); } return pFiler->filerStatus(); } TDividerStyle::TDividerFlag TDividerStyle::GetDividerFlag() const { return m_nFlag; } double TDividerStyle::GetLineWidth() const { return m_nLineWidth; } AcDbObjectId TDividerStyle::GetLineTypeId() const { return m_idLineType; } Adesk::UInt16 TDividerStyle::GetColor() const { return m_nColor; } void TDividerStyle::SetDividerFlag(TDividerFlag flag) { m_nFlag=flag; } void TDividerStyle::SetLineWidth(double nWidth) { m_nLineWidth=nWidth; } void TDividerStyle::SetLineTypeId(AcDbObjectId id) { m_idLineType=id; } void TDividerStyle::SetColor(Adesk::UInt16 nColor) { m_nColor=nColor; } //////////////////////////////// // 列定义 const Adesk::UInt8 TSheetColumn::g_nVersion=1; TSheetColumn::TSheetColumn() { //m_gridStyle.m_nOverride = 0; m_divider.m_nFlag=TDividerStyle::kParent; // Divider style for right column border m_bAllowSizing=true; // Enables interactive resizing for a column m_nWidth=0.0; //in Paper Unit } TSheetColumn::TSheetColumn(const TSheetColumn &src) { *this=src; } TSheetColumn & TSheetColumn::operator= (const TSheetColumn &src) { CopyObject(src, *this); return *this; } BOOL TSheetColumn::IsValid() const { return (m_nWidth>0.0); } Acad::ErrorStatus TSheetColumn::dwgInFields (AcDbDwgFiler* pFiler) { Adesk::UInt8 nVer=0; pFiler->readItem(&nVer); if(nVer>g_nVersion) // Version is too new return Acad::eMakeMeProxy; Acad::ErrorStatus es=m_gridStyle.dwgInFields(pFiler); if(es!=Acad::eOk) return es; es=m_divider.dwgInFields(pFiler); if(es!=Acad::eOk) return es; pFiler->readItem(&m_bAllowSizing); pFiler->readItem(&m_nWidth); return pFiler->filerStatus(); } Acad::ErrorStatus TSheetColumn::dwgOutFields(AcDbDwgFiler* pFiler) const { pFiler->writeItem(g_nVersion); VERIFY(m_gridStyle.dwgOutFields(pFiler)==Acad::eOk); VERIFY(m_divider.dwgOutFields(pFiler)==Acad::eOk); pFiler->writeItem(m_bAllowSizing); pFiler->writeItem(m_nWidth); return pFiler->filerStatus(); } //图纸单位 double TSheetColumn::GetWidth() const { return m_nWidth; } //图纸单位 void TSheetColumn::SetWidth(double w) { m_nWidth=w; } const TDividerStyle & TSheetColumn::GetDividerStyle() const { return m_divider; } TDividerStyle & TSheetColumn::GetDividerStyle() { return m_divider; } const TGridStyle & TSheetColumn::GetGridStyle() const { return m_gridStyle; } TGridStyle & TSheetColumn::GetGridStyle() { return m_gridStyle; } BOOL TSheetColumn::AllowSizing() const { return m_bAllowSizing; } void TSheetColumn::SetAllowSizing(BOOL bTrue) { m_bAllowSizing=bTrue; } void TSheetColumn::SetDividerStyle(const TDividerStyle &style) { CopyObject(style, m_divider); } void TSheetColumn::SetGridStyle(const TGridStyle &style) { CopyObject(style, m_gridStyle); } /////////////////////////////// // 行定义 const Adesk::UInt8 TSheetRow::g_nVersion=1; TSheetRow::TSheetRow() { m_divider.m_nFlag=TDividerStyle::kParent; // Divider style for right column border m_nHeightFlag=TSheetRow::kParent; // Disable interactive resizing for row m_nHeight=0.0; //in Paper Unit m_nVerMode=AcDb::kTextBase; } TSheetRow::TSheetRow(const TSheetRow &src) { *this = src; } TSheetRow & TSheetRow::operator= (const TSheetRow &src) { CopyObject(src, *this); return *this; } double TSheetRow::GetHeight() const { return m_nHeight; } void TSheetRow::SetHeight(double h) { m_nHeight = h; } TSheetRow::TRowHeightStyle TSheetRow::GetRowHeightStyle() const { return m_nHeightFlag; } void TSheetRow::SetRowHeightStyle(TSheetRow::TRowHeightStyle st) { m_nHeightFlag=st; } const TDividerStyle & TSheetRow::GetDividerStyle() const { return m_divider; } TDividerStyle & TSheetRow::GetDividerStyle() { return m_divider; } void TSheetRow::SetDividerStyle(const TDividerStyle &src) { CopyObject(src, m_divider); } Acad::ErrorStatus TSheetRow::dwgInFields (AcDbDwgFiler* pFiler) { Adesk::UInt8 nVer=0; pFiler->readItem(&nVer); if(nVer>g_nVersion) // Version is too new return Acad::eMakeMeProxy; Acad::ErrorStatus es=m_divider.dwgInFields(pFiler); if(es!=Acad::eOk) return es; Adesk::UInt8 nTemp; pFiler->readItem(&nTemp); m_nHeightFlag=(TRowHeightStyle)nTemp; pFiler->readItem(&m_nHeight); pFiler->readItem(&nTemp); m_nVerMode=(AcDb::TextVertMode)nTemp; return pFiler->filerStatus(); } Acad::ErrorStatus TSheetRow::dwgOutFields(AcDbDwgFiler* pFiler) const { pFiler->writeItem(g_nVersion); VERIFY(m_divider.dwgOutFields(pFiler)==Acad::eOk); pFiler->writeItem((Adesk::UInt8)m_nHeightFlag); pFiler->writeItem(m_nHeight); pFiler->writeItem((Adesk::UInt8)m_nVerMode); return pFiler->filerStatus(); } AcDb::TextVertMode TSheetRow::GetVerMode() const { return m_nVerMode; } void TSheetRow::SetVerMode(AcDb::TextVertMode nVerMode) { m_nVerMode=nVerMode; } /////////////////////////////////// // 单元格的定义 //TArch6:1,TArch7:2 const Adesk::UInt8 TGridCell::g_nVersion=2; TGridCell::TGridCell() { //m_gridStyle.m_nOverride=0; m_pRange=NULL; //m_sText; } TGridCell::TGridCell(const TGridCell &src) { *this = src; } TGridCell & TGridCell::operator = (const TGridCell &src) { CopyObject(src.m_gridStyle, m_gridStyle); m_sText=src.m_sText; m_idBlock=src.m_idBlock; m_pRange=src.m_pRange; return *this; } Acad::ErrorStatus TGridCell::dwgInFields (AcDbDwgFiler* pFiler, const DList *ranges) { Adesk::UInt8 nVer=0; pFiler->readItem(&nVer); if(nVer>g_nVersion) // Version is too new return Acad::eMakeMeProxy; Adesk::UInt16 nRange=0; pFiler->readItem(&nRange); if(nRange==0 || !ranges) { m_pRange=NULL; Acad::ErrorStatus es=m_gridStyle.dwgInFields(pFiler); if(es!=Acad::eOk) return es; ReadString(pFiler, m_sText); } else { DList *pRangeList=(DList *)ranges; m_pRange=(*pRangeList)[nRange-1]; } if(nVer>1) pFiler->readItem(&m_idBlock); return pFiler->filerStatus(); } Acad::ErrorStatus TGridCell::dwgOutFields(AcDbDwgFiler* pFiler, const DList *ranges) const { if(g_nSaveTArchVer<7) pFiler->writeItem((Adesk::UInt8)1); else pFiler->writeItem(g_nVersion); Adesk::UInt16 nRange=0; if(m_pRange && ranges) { DList *pRangeList=(DList *)ranges; if(pRangeList->FindNode(m_pRange, CompareRange)) { nRange = pRangeList->CurPosition()+1; } } pFiler->writeItem(nRange); if(nRange==0) { VERIFY(m_gridStyle.dwgOutFields(pFiler)==Acad::eOk); pFiler->writeString(m_sText); } if(g_nSaveTArchVer>6) pFiler->writeItem(m_idBlock); return pFiler->filerStatus(); } BOOL TGridCell::IsRange() const { return (m_pRange!=NULL); } const TGridStyle & TGridCell::GetGridStyle() const { if(m_pRange) return m_pRange->GetGridStyle(); return m_gridStyle; } TGridStyle & TGridCell::GetGridStyle() { if(m_pRange) return m_pRange->GetGridStyle(); return m_gridStyle; } const TCHAR *TGridCell::GetText() const { if(m_pRange) return m_pRange->GetText(); return (const TCHAR *)m_sText; } void TGridCell::SetText(const TCHAR *szText) { if(m_pRange) m_pRange->SetText(szText); m_sText=szText; TCellBlockInsert insert; if(insert.ParserDesc(m_sText)) m_idBlock=InitBlock(insert.m_sBlockName); else m_idBlock=AcDbObjectId::kNull; } const TGridRange * TGridCell::GetRange() const { return m_pRange; } void TGridCell::SetGridStyle(const TGridStyle &style) { if(m_pRange) m_pRange->SetGridStyle(style); CopyObject(style, m_gridStyle); } void TGridCell::SetRange(TGridRange *pRange) { m_pRange=pRange; } /////////////////////////////////// // 合并单元格的定义 // Modify on 2003/6/24,8位整数上升到16位整数 const Adesk::UInt8 TGridRange::g_nVersion=2; TGridRange::TGridRange() { //m_gridStyle.m_nOverride=0; m_nRow = m_nColumn = -1; m_nRowMax = m_nColumnMax = -1; //m_sText; } TGridRange::TGridRange(const TGridRange &src) { *this = src; } TGridRange & TGridRange::operator = (const TGridRange &src) { CopyObject(src, *this); SetRange((TGridRange *)src.GetRange()); return *this; } BOOL TGridRange::IsValid() const { BOOL bRet=(m_nRow>=0 && m_nColumn>=0); bRet = (bRet && (m_nRowMax>=m_nRow && m_nColumnMax>=m_nColumn)); return bRet; } BOOL TGridRange::IsCellar() const { return (m_nRow==m_nRowMax && m_nColumn==m_nColumnMax); } Acad::ErrorStatus TGridRange::dwgInFields (AcDbDwgFiler* pFiler) { Acad::ErrorStatus es=TGridCell::dwgInFields(pFiler); if(es!=Acad::eOk) return es; Adesk::UInt8 nVer=0; pFiler->readItem(&nVer); if(nVer>g_nVersion) // Version is too new return Acad::eMakeMeProxy; //Acad::ErrorStatus es=m_gridStyle.dwgInFields(pFiler); //if(es!=Acad::eOk) // return es; //ReadString(pFiler, m_sText); if(nVer<2) { Adesk::UInt8 a1=0, a2=0, a3=0, a4=0; pFiler->readItem(&a1); pFiler->readItem(&a2); pFiler->readItem(&a3); pFiler->readItem(&a4); m_nRow=a1; m_nColumn=a2; m_nRowMax=a3; m_nColumnMax=a4; } else { pFiler->readItem(&m_nRow); pFiler->readItem(&m_nColumn); pFiler->readItem(&m_nRowMax); pFiler->readItem(&m_nColumnMax); } return pFiler->filerStatus(); } Acad::ErrorStatus TGridRange::dwgOutFields(AcDbDwgFiler* pFiler) const { VERIFY(TGridCell::dwgOutFields(pFiler)==Acad::eOk); //VERIFY(m_gridStyle.dwgOutFields(pFiler)==Acad::eOk); //pFiler->writeString(m_sText); if(g_nSaveTArchVer==5) { ASSERT(m_nRowMax<=256 && m_nColumnMax<=256); pFiler->writeItem((Adesk::UInt8)1); pFiler->writeItem((Adesk::UInt8)m_nRow); pFiler->writeItem((Adesk::UInt8)m_nColumn); pFiler->writeItem((Adesk::UInt8)m_nRowMax); pFiler->writeItem((Adesk::UInt8)m_nColumnMax); } else { pFiler->writeItem(g_nVersion); pFiler->writeItem(m_nRow); pFiler->writeItem(m_nColumn); pFiler->writeItem(m_nRowMax); pFiler->writeItem(m_nColumnMax); } return pFiler->filerStatus(); } /* const TCHAR *TGridRange::GetText() const { return (const TCHAR *)m_sText; } */ int TGridRange::GetCoord(BOOL bIsRow) const { return (bIsRow? m_nRow : m_nColumn); } int TGridRange::GetCoordMax(BOOL bIsRow) const { return (bIsRow? m_nRowMax : m_nColumnMax); } /* void TGridRange::SetText(const TCHAR *szText) { m_sText=szText; } */ void TGridRange::SetCoord(int nRow, int nCol) { m_nRow=nRow; m_nColumn=nCol; } void TGridRange::SetCoordMax(int nRow, int nCol) { m_nRowMax=nRow; m_nColumnMax=nCol; } BOOL TGridRange::Include(int nRow, int nCol) const { BOOL bRet=(nRow>=m_nRow && nRow<=m_nRowMax && nCol>=m_nColumn && nCol<=m_nColumnMax); return bRet; } //////////////////////////////////// // 标题的定义 const Adesk::UInt8 TSheetTitle::g_nVersion=1; TSheetTitle::TSheetTitle() { //XString m_sText; m_gridStyle.SetFlagBit(OF_HORMODE|OF_TEXTHEIGHT, TRUE); m_gridStyle.SetHorMode(AcDb::kTextCenter); SetVerMode(AcDb::kTextVertMid); m_bVisibility=TRUE; //m_gridStyle.m_nOverride=0; } TSheetTitle::TSheetTitle(const TSheetTitle &src) { *this = src; } TSheetTitle & TSheetTitle::operator = (const TSheetTitle &src) { CopyObject(src, *this); return *this; } BOOL TSheetTitle::IsVisible() const { return (m_bVisibility!=0); } void TSheetTitle::SetVisible(BOOL bTrue) { m_bVisibility=bTrue; } Acad::ErrorStatus TSheetTitle::dwgInFields (AcDbDwgFiler* pFiler) { Acad::ErrorStatus es=TSheetRow::dwgInFields(pFiler); if(es!=Acad::eOk) return es; es=TGridCell::dwgInFields(pFiler); if(es!=Acad::eOk) return es; Adesk::UInt8 nVer=0; pFiler->readItem(&nVer); if(nVer>g_nVersion) // Version is too new return Acad::eMakeMeProxy; //VERIFY(m_gridStyle.dwgInFields(pFiler)==Acad::eOk); //ReadString(pFiler, m_sText); pFiler->readItem(&m_bVisibility); return pFiler->filerStatus(); } Acad::ErrorStatus TSheetTitle::dwgOutFields(AcDbDwgFiler* pFiler) const { VERIFY(TSheetRow::dwgOutFields(pFiler)==Acad::eOk); VERIFY(TGridCell::dwgOutFields(pFiler)==Acad::eOk); pFiler->writeItem(g_nVersion); //VERIFY(m_gridStyle.dwgOutFields(pFiler)==Acad::eOk); //pFiler->writeString(m_sText); pFiler->writeItem(m_bVisibility); return pFiler->filerStatus(); } ///////////////////////////////////////////////////////////// // 表格对象类 ///////////////////////////////////////////////////////////// // TArch5, T6Bet2:ver=2;T6B3:nVer=3, nVer=4 const Adesk::UInt8 TDbSheet::g_nVersion = 4; ACRX_DXF_DEFINE_MEMBERS(ATSSheet, ATSEntity, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, 1, ATS_SHEET, "ATS_SHEET图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com"); IMPLEMENT_TENTBASE(TDbSheet); TDbSheet::TDbSheet() { m_rowHeightStyle=TSheetRow::kFixed; m_gridStyle.SetOverrideAll(TRUE); //标准方格样式 m_border.m_nFlag=TDividerStyle::kLocal; //表格外框的分割线样式 m_rowDivider.m_nFlag=TDividerStyle::kLocal; //表格内部分割线样式 m_colDivider.m_nFlag=TDividerStyle::kLocal; //TSheetTitle m_title; //标题 //DList m_columns; //列 //DList m_rows; //行 //DList m_ranges; //单元格 m_pCells=NULL; m_nRowHeight=0.0; //标准行高 //表格本身的定位方式, 左上, 右上, 左下, 右下, 中间 m_nAlignment=XExplodeDraw::kTopLeft; //XPoint m_ptLocation; //定位点 m_nRotation=0.0; } TDbSheet::~TDbSheet() { if(m_pCells) delete [] m_pCells; } void TDbSheet::InitSheet(int nRow, int nCol, double nRowHeight, double nColWidth) { ASSERT(nRow>0 && nCol>0); if(m_pCells) delete [] m_pCells; m_pCells = new TGridCell[nRow*nCol]; m_columns.Reset(); m_rows.Reset(); m_ranges.Reset(); m_nRowHeight=nRowHeight; for(int i=0; iSetWidth(nColWidth); pCol->SetGridStyle(m_gridStyle); //pCol->SetDividerStyle(m_colDivider); m_columns.Append(pCol); } for(i=0; iSetHeight(nRowHeight); pRow->SetVerMode(m_gridStyle.GetVerMode()); //pRow->SetDividerStyle(m_rowDivider); m_rows.Append(pRow); } } BOOL TDbSheet::IsValid() const { BOOL bRet=TDbEntity::IsValid(); if(!bRet) return bRet; bRet=(m_nRowHeight>0.0 && m_rows.Length() && m_columns.Length()); return bRet; } // 提供对格式刷的支持 void TDbSheet::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag) { assertWriteEnabled(); TDbEntity::CopyPropertiesFrom(pSrcEntity, gMatchFlag); TDbSheet *pSrc=TDbSheet::cast(pSrcEntity); if(pSrc) { m_gridStyle=pSrc->m_gridStyle; //标准方格样式 m_border=pSrc->m_border; //表格外框的分割线样式 m_rowDivider=pSrc->m_rowDivider; //行分割线样式 m_colDivider=pSrc->m_colDivider; //列分割线样式 m_nRowHeight=pSrc->m_nRowHeight; //标准行高 //表格本身的定位方式, 左上, 右上, 左下, 右下, 中间 m_nAlignment=pSrc->m_nAlignment; // TArch6 m_rowHeightStyle=pSrc->m_rowHeightStyle; } } Acad::ErrorStatus TDbSheet::DownGradeSave(int nDrawMode, AcDbVoidPtrArray &entSet, BOOL *bErase) { //add by whl on 060223 if(g_nSaveTArchVer<7)//7.0开始才有圆圈文字 { BOOL bHasCircle=FALSE; long num=GetSubTextNum(); for(long i=0;iGetText(); delete pSubText; if(sText.Find(_T("^C"))!=-1) { bHasCircle=TRUE; break; } } } if(bHasCircle) { Acad::ErrorStatus es=Acad::eOk; XPushMemVar vTemp(XExplodeStream::m_bFullExplode, TRUE);//完全分解 XExplodeStream dc(entSet); if(!OnExplodeOrDraw(dc)) return es; dc.SetPropertiesFrom(this); if(nDrawMode==DRAW_2D) es=ExplodeOrDraw2d(dc); else es=ExplodeOrDraw3d(dc); if(bErase) *bErase=TRUE; return es; } } if(g_nSaveTArchVer==5) { if(GetRowNum()>256 || GetColumnNum()>256) { XExplodeStream dc(entSet); if(!OnExplodeOrDraw(dc)) return Acad::eOk; dc.SetPropertiesFrom(this);//add by whl on 060404 Acad::ErrorStatus es=ExplodeOrDraw2d(dc); if(bErase) *bErase=TRUE; return es; } } return TDbEntity::DownGradeSave(nDrawMode,entSet,bErase); } Acad::ErrorStatus TDbSheet::subGetClassID(CLSID* pClsid) const { return Acad::eOk; } // 从DWG读入数据: Acad::ErrorStatus TDbSheet::dwgInFields (AcDbDwgFiler* pFiler) { assertWriteEnabled(); Acad::ErrorStatus es = TDbEntity::dwgInFields(pFiler); if(es != Acad::eOk) return es; Adesk::UInt8 nVer; pFiler->readItem(&nVer); if(nVer>g_nVersion) {// Version is too new return Acad::eMakeMeProxy; } es=m_gridStyle.dwgInFields(pFiler); if(es!=Acad::eOk) return es; es=m_border.dwgInFields(pFiler); if(es!=Acad::eOk) return es; es=m_rowDivider.dwgInFields(pFiler); if(es!=Acad::eOk) return es; if(nVer>1) { es=m_colDivider.dwgInFields(pFiler); if(es!=Acad::eOk) return es; } es=m_title.dwgInFields(pFiler); if(es!=Acad::eOk) return es; Adesk::UInt16 nColNum=0; m_columns.Reset(); if(nVer>2) { pFiler->readItem(&nColNum); } else { Adesk::UInt8 nTemp=0; pFiler->readItem(&nTemp); nColNum=nTemp; } for(Adesk::UInt16 iCol=0; iColdwgInFields(pFiler); if(es!=Acad::eOk) { delete pCol; return es; } m_columns.Append(pCol); } m_rows.Reset(); Adesk::UInt16 nRowNum=0; if(nVer>2) { pFiler->readItem(&nRowNum); } else { Adesk::UInt8 nTemp=0; pFiler->readItem(&nTemp); nRowNum = nTemp; } for(Adesk::UInt16 iRow=0; iRowdwgInFields(pFiler); if(es!=Acad::eOk) { delete pRow; return es; } m_rows.Append(pRow); } // 合并格 m_ranges.Reset(); Adesk::UInt16 nRangeNum; pFiler->readItem(&nRangeNum); for(Adesk::UInt16 iRange=0; iRangedwgInFields(pFiler); if(es!=Acad::eOk) { delete pRange; return es; } m_ranges.Append(pRange); } //单元格 if(m_pCells) delete [] m_pCells; ASSERT(nRowNum>0 && nColNum>0); Adesk::UInt16 nCellNum=nRowNum*nColNum; m_pCells=new TGridCell[nCellNum]; for(Adesk::UInt16 iCell=0; iCellreadItem(&m_nRowHeight); Adesk::UInt8 nAlign; pFiler->readItem(&nAlign); m_nAlignment=(XExplodeDraw::TextAlignment)nAlign; pFiler->readItem((AcGePoint3d *)&m_ptLocation); m_ptLocation.z=0; pFiler->readItem(&m_nRotation); if(nVer>=4) { Adesk::UInt8 nTemp; pFiler->readItem(&nTemp); m_rowHeightStyle=(TSheetRow::TRowHeightStyle)nTemp; } return pFiler->filerStatus(); } Acad::ErrorStatus TDbSheet::dwgOutFields(AcDbDwgFiler* pFiler) const { assertReadEnabled(); Acad::ErrorStatus es = TDbEntity::dwgOutFields(pFiler); if(es != Acad::eOk) return es; if(g_nSaveTArchVer==5) pFiler->writeItem((Adesk::UInt8)2); else pFiler->writeItem(g_nVersion); VERIFY(m_gridStyle.dwgOutFields(pFiler)==Acad::eOk); VERIFY(m_border.dwgOutFields(pFiler)==Acad::eOk); VERIFY(m_rowDivider.dwgOutFields(pFiler)==Acad::eOk); VERIFY(m_colDivider.dwgOutFields(pFiler)==Acad::eOk); VERIFY(m_title.dwgOutFields(pFiler)==Acad::eOk); Adesk::UInt16 nColNum=m_columns.Length(); if(g_nSaveTArchVer==5) { ASSERT(nColNum<=256); pFiler->writeItem((Adesk::UInt8)nColNum); } else pFiler->writeItem(nColNum); for(Adesk::UInt16 iCol=0; iColwriteItem((Adesk::UInt8)nRowNum); } else pFiler->writeItem(nRowNum); for(Adesk::UInt16 iRow=0; iRowwriteItem(nRangeNum); for(Adesk::UInt16 iRange=0; iRangewriteItem(m_nRowHeight); pFiler->writeItem((Adesk::UInt8)m_nAlignment); pFiler->writeItem((const AcGePoint3d &)m_ptLocation); pFiler->writeItem(m_nRotation); if(g_nSaveTArchVer!=5) { pFiler->writeItem((Adesk::UInt8)m_rowHeightStyle); } return pFiler->filerStatus(); } Acad::ErrorStatus TDbSheet::dxfInFields (AcDbDxfFiler* pFiler) { assertWriteEnabled(); Acad::ErrorStatus es = TDbEntity::dxfInFields(pFiler); if(es!=Acad::eOk) return es; if (!pFiler->atSubclassData(_T("TDbSheet"))) { return Acad::eBadDxfSequence; } pFiler->writePoint2d(AcDb::kDxfXCoord, m_ptLocation.AsAcGePoint2d()); pFiler->writeString(AcDb::kDxfText, (const TCHAR *)GetTitleText()); pFiler->writeDouble(AcDb::kDxfReal, m_nRowHeight); pFiler->writeDouble(AcDb::kDxfAngle, m_nRotation); pFiler->writeInt16(AcDb::kDxfInt16, (Adesk::Int16)GetRowNum()); pFiler->writeInt16(AcDb::kDxfInt16+1, (Adesk::Int16)GetColumnNum()); pFiler->writeInt16(AcDb::kDxfInt16+2, (Adesk::Int16)m_nAlignment); int fieldsFlags=0; XPoint pt; XString sText; double nHeight, nRot; int nAlign; resbuf rb; while ((es == Acad::eOk) && ((es = pFiler->readResBuf(&rb)) == Acad::eOk)) { switch (rb.restype) { case AcDb::kDxfXCoord: pt=rb.resval.rpoint; fieldsFlags |= 0x01; break; case AcDb::kDxfText: sText=rb.resval.rstring; fieldsFlags |= 0x02; break; case AcDb::kDxfReal: nHeight=rb.resval.rreal; fieldsFlags |= 0x04; break; case AcDb::kDxfAngle: nRot=rb.resval.rreal; fieldsFlags |= 0x08; break; case AcDb::kDxfInt16: fieldsFlags |= 0x10; break; case AcDb::kDxfInt16+1: fieldsFlags |= 0x20; break; case AcDb::kDxfInt16+2: fieldsFlags |= 0x40; nAlign = rb.resval.rint; break; //fall through intentional default: // An unrecognized group. Push it back so that // the subclass can read it again. pFiler->pushBackItem(); es = Acad::eEndOfFile; break; } } if (es != Acad::eEndOfFile) return Acad::eInvalidResBuf; if(fieldsFlags&0x01) m_ptLocation=pt; if(fieldsFlags&0x02) SetTitleText(sText); if(fieldsFlags&0x04) m_nRowHeight=nHeight; if(fieldsFlags&0x08) m_nRotation=nRot; if(fieldsFlags&0x40) m_nAlignment=(XExplodeDraw::TextAlignment)nAlign; return pFiler->filerStatus(); } Acad::ErrorStatus TDbSheet::dxfOutFields(AcDbDxfFiler* pFiler) const { assertReadEnabled(); Acad::ErrorStatus es=TDbEntity::dxfOutFields(pFiler); assert(es == Acad::eOk); es = pFiler->writeItem(AcDb::kDxfSubclass,_T("TDbSheet")); assert(es == Acad::eOk); pFiler->writePoint2d(AcDb::kDxfXCoord, m_ptLocation.AsAcGePoint2d()); pFiler->writeString(AcDb::kDxfText, (const TCHAR *)GetTitleText()); pFiler->writeDouble(AcDb::kDxfReal, m_nRowHeight); pFiler->writeDouble(AcDb::kDxfAngle, m_nRotation); pFiler->writeInt16(AcDb::kDxfInt16, (Adesk::Int16)GetRowNum()); pFiler->writeInt16(AcDb::kDxfInt16+1, (Adesk::Int16)GetColumnNum()); pFiler->writeInt16(AcDb::kDxfInt16+2, (Adesk::Int16)m_nAlignment); return es; } // ----------------------------------------------------------------------- // Overriden functions for edit // to do: // 允许通过夹点改变边界 Acad::ErrorStatus TDbSheet::subGetGripPoints(AcGePoint3dArray& gripPoints, AcDbIntArray& osnapModes, AcDbIntArray& geomIds) const { assertReadEnabled(); gripPoints.append(m_ptLocation); //0 XPoint ptTopLeft=GetTopLeft(FALSE); XPoint ext=GetExtents(FALSE, FALSE); XPoint ptBotRight; double nRotWcs=Layout2Wcs(m_nRotation); ads_polar(ptTopLeft, nRotWcs-PI/2, ext.y, ptBotRight); ads_polar(XPoint(ptBotRight), nRotWcs, ext.x, ptBotRight); gripPoints.append(ptBotRight); //1 int nColNum=GetColumnNum(); for(int iCol=0; iCol1) { m_ptLocation += vtOffset; return Acad::eOk; } double nRotWcs=Layout2Wcs(m_nRotation); int idx = indices[0]; if(idx==0) { m_ptLocation += vtOffset; } else if(idx==1) { XVector3D vtRight(cos(nRotWcs), sin(nRotWcs)); XVector3D vtBot(cos(nRotWcs-PI/2), sin(nRotWcs-PI/2)); double nWidthInc=(vtRight&vtOffset); double nHeightInc=(vtBot&vtOffset); BOOL bIncTitle=m_title.IsVisible(); XPoint ptTopLeft=GetTopLeft(bIncTitle); XPoint ext=GetExtents(bIncTitle, FALSE); double xRatio = nWidthInc/ext.x + 1.0; double yRatio = nHeightInc/ext.y + 1.0; int nColNum=GetColumnNum(); for(int iCol=0; iColGetGridStyle(), gridStyle); pCell->m_gridStyle.m_nTextHeight *= yRatio; //pCell->SetGridStyle(gridStyle); } } for(int n=0; nm_gridStyle.m_nTextHeight *= yRatio; m_nRowHeight *= yRatio; m_title.m_nHeight *= yRatio; m_title.m_gridStyle.m_nTextHeight *= yRatio; } else { XVector3D vt(cos(nRotWcs), sin(nRotWcs)); double nWidth = (vt&vtOffset); int nColNum=GetColumnNum(); int iVert=1; for(int iCol=0; iColGetRowHeight(TRUE)) row.SetHeight(h); else row.SetHeight(GetRowHeight(TRUE)); } else row.SetHeight(h); } return Acad::eOk; } } } } return Acad::eOk; } // 功能: 夹点操作 Acad::ErrorStatus TDbSheet::subMoveStretchPointsAt( const AcDbIntArray& indices, const AcGeVector3d& offset) { return subMoveGripPointsAt(indices, offset); } // 取得夹点说明 Acad::ErrorStatus TDbSheet::GetGripText(int i, CString &cs) const { Acad::ErrorStatus es=Acad::eOk; if(i==0) { cs=_T("移动表格"); } else if(i==1) { cs=_T("角点缩放"); } else { int nColNum=GetColumnNum(); int iVert=1; for(int iCol=0; iColm_sText, sText, pData); if(nRet==RTERROR) nCode=nRet; else if(nRet==RTNORM) cell->m_sText=sText; } return nCode; } // 返回发现的位置,同时posStart往前移动(以便继续找下一个使用), TTextPosition TDbSheet::FindSubText(const TCHAR *sSubText, TTextPosition &posStart, TTextRange *pRange) const { TTextPosition pos; if(!sSubText || !sSubText[0]) return pos; TTextPosition posNext=posStart; while(1) { if((int)posNext.m_nCookies>=(GetRowNum()*GetColumnNum()+m_ranges.Length()+1)) break; TDbText *pText=GetText(posNext.m_nCookies); TTextPosition posFind; if(pText) { posFind=pText->FindSubText(sSubText, posNext, pRange); delete pText; } if(!posFind) { posNext.m_nCookies++; posNext.m_nTextPos=0; } else { posStart=posNext; if(!posStart) { posStart.m_nCookies++; posStart.m_nTextPos=0; } posFind.m_nCookies=posNext.m_nCookies; pos=posFind; break; } } return pos; } // 返回下一次查找的开始位置 TTextPosition TDbSheet::ReplaceSubText(const TTextPosition &posRep, const TCHAR *sRepText, TTextRange *pRange) { assertWriteEnabled(); TTextPosition posNext; TDbText *pText=GetText(posRep.m_nCookies); if(!pText) return posNext; posNext=pText->ReplaceSubText(posRep, sRepText, pRange); int cookies=posRep.m_nCookies; if(cookies==0) { SetTitleText(pText->GetText()); } else { cookies--; int nRowNum=GetRowNum(); int nColNum=GetColumnNum(); if(cookiesSetText(pText->GetText()); } else { cookies -= nRowNum*nColNum; if(cookiesSetText(pText->GetText()); } } delete pText; if(!posNext) { posNext.m_nCookies=posRep.m_nCookies+1; posNext.m_nTextPos=0; } return posNext; } /* * * * * * * * * * 取 动 态 属 性 显 示 数 据 的 函 数 * * * * * * * * * */ void TDbSheet::GetTips(DList &lstInfo) const { lstInfo.Append(new TObjInfoUnit(_T("对象类型"), _T("表格"))); const TCHAR *pszTitle=m_title.IsVisible()? _T("标题") : _T("标题(隐藏)"); lstInfo.Append(new TObjInfoUnit(pszTitle, m_title.GetText())); XPoint ext=GetExtents(m_title.IsVisible() && m_title.GetDividerStyle().GetDividerFlag()!=TDividerStyle::kNone); XString sHeight, sWidth, sRowHeight; ftoa(ext.x, 1, sWidth); ftoa(ext.y, 1, sHeight); ftoa(GetRowHeight(),1, sRowHeight); sHeight << _T("P"); sWidth << _T("P"); sRowHeight << _T("P"); lstInfo.Append(new TObjInfoUnit(_T("标准行高"), sRowHeight)); lstInfo.Append(new TObjInfoUnit(_T("表格宽度"), sWidth)); lstInfo.Append(new TObjInfoUnit(_T("表格高度"), sHeight)); lstInfo.Append(new TObjInfoUnit(_T("行数"), XString(_T("%d"),GetRowNum()))); lstInfo.Append(new TObjInfoUnit(_T("列数"), XString(_T("%d"), GetColumnNum()))); } Acad::ErrorStatus TDbSheet::ExplodeOrDraw2d(XExplodeDraw &dc) const { //TPushProperty vProp(this, dc); //add on 20161017 图层关闭,不进行相关绘制,解决表格对象内有图块,当表格图层关闭,打印显示图块的问题。 AcDbLayerTableRecordPointer player(this->layerId(), AcDb::kForRead); if (player.openStatus() == Acad::eOk && player->isOff())//对图层为空时,进行保护 { return Acad::eOk; } //end add assertReadEnabled(); int nGsMarker=1; if(!objectId() && _tcsicmp(dc.Desc(), XAcGiViewDraw::Descriptor())==0) nGsMarker=0; DrawBorder(dc, nGsMarker); DrawTitle(dc, nGsMarker); XPoint ptBase=GetTopLeft(FALSE); DrawRowDivider(ptBase, dc, nGsMarker); DrawColumnDivider(ptBase, dc, nGsMarker); if(!!objectId()) DrawCellText(ptBase, dc, nGsMarker); return Acad::eOk; } //////////////////////////////////////////////////////////////////// // 绘制表格的方法 // 绘制表格的外框 void TDbSheet::DrawBorder(XExplodeDraw &dc, int &nGsMarker) const { AcDbPolyline pline; XPoly2D polyBorder(1); GetBorder(polyBorder); PolyConvert(polyBorder, pline); pline.setPropertiesFrom(this); if(nGsMarker) { dc.SetSelectionMarker(nGsMarker); nGsMarker ++ ; //捕捉加速 INT_PTR nQuickMarker=GetQuickMarker(); if(nQuickMarker && nQuickMarker<(nGsMarker-4) || nQuickMarker>=nGsMarker) //用于捕捉时加速 return; } int nOldColor=dc.GetColor(); switch(m_border.m_nFlag) { case TDividerStyle::kLocal: if(!!m_border.m_idLineType) pline.setLinetype(m_border.m_idLineType); if(m_border.m_nLineWidth>0.0 && !!objectId()) pline.setConstantWidth(m_border.m_nLineWidth*GetPScale()); if(m_border.m_nColor>0) { dc.SetColor(m_border.GetColor()); pline.setColorIndex(m_border.GetColor()); } dc.Polyline(pline); break; case TDividerStyle::kParent: dc.Polyline(pline); break; case TDividerStyle::kNone: default: break; } dc.SetColor(nOldColor); } // 当Wrap和一行容纳不下时采用MText void TDbSheet::InitTextInBox(TDbText &text, XPoint ptTopLeft, double nBoxWidth, double nBoxHeight, double nOffset, AcDb::TextHorzMode nHorMode, AcDb::TextVertMode nVerMode) const { BOOL bMText=text.isKindOf(TDbMText::desc()); XPoint ptAlign=ptTopLeft; if(!bMText) { XExplodeDraw::TextAlignment align=XExplodeDraw::GetTextAlignment(nHorMode, nVerMode); switch(nHorMode) { case AcDb::kTextLeft: ptAlign.x += nOffset; break; case AcDb::kTextCenter: case AcDb::kTextMid: ptAlign.x += nBoxWidth/2; break; case AcDb::kTextRight: ptAlign.x += nBoxWidth; ptAlign.x -= nOffset; break; default: ptAlign.x += nOffset; break; } switch(nVerMode) { case AcDb::kTextBase: case AcDb::kTextBottom: ptAlign.y -= nBoxHeight; ptAlign.y += nOffset; if(align==XExplodeDraw::kTextFit || align==XExplodeDraw::kUnknown) align=XExplodeDraw::kLeft; break; case AcDb::kTextVertMid: ptAlign.y -= nBoxHeight/2; if(align==XExplodeDraw::kTextFit || align==XExplodeDraw::kUnknown) align=XExplodeDraw::kMiddleLeft; break; case AcDb::kTextTop: ptAlign.y -= nOffset; if(align==XExplodeDraw::kTextFit || align==XExplodeDraw::kUnknown) align=XExplodeDraw::kTopLeft; break; default: ASSERT(0); } text.SetAlignment(align); text.SetLocation(ptAlign); } else { XExplodeDraw::TextAlignment align; ptAlign.x += nOffset; switch(nHorMode) { case AcDb::kTextLeft: align = XExplodeDraw::kLeft; break; case AcDb::kTextCenter: case AcDb::kTextMid: align = XExplodeDraw::kCenter; break; case AcDb::kTextRight: align = XExplodeDraw::kRight; break; case AcDb::kTextFit: align = XExplodeDraw::kTextFit; break; default: ASSERT(0); } text.SetAlignment(align); XPoint ext=text.GetExtents(); switch(nVerMode) { case AcDb::kTextBase: case AcDb::kTextBottom: ptAlign.y -= nBoxHeight; ptAlign.y += nOffset+ext.y; break; case AcDb::kTextVertMid: ptAlign.y -= nBoxHeight/2; ptAlign.y += ext.y/2; break; case AcDb::kTextTop: ptAlign.y -= nOffset; break; default: ASSERT(0); } text.SetLocation(ptAlign); } } // 绘制标题, 包括文字和横线 // ptBase -- 标题上(IN)下(OUT)的第一左上角 void TDbSheet::DrawTitle(XExplodeDraw &dc, int &nGsMarker) const { if(!m_title.IsVisible()) return; BOOL bIncludeTitle=(m_title.m_divider.m_nFlag!=TDividerStyle::kNone); double nTitleHeight = GetTitleHeight(FALSE); double nTitleWidth = GetSheetWidth(FALSE); double nRotWcs=Layout2Wcs(m_nRotation); //左上角为ptBase XPoint ptBase=GetTopLeft(bIncludeTitle); if(!bIncludeTitle) ads_polar(XPoint(ptBase), nRotWcs+PI/2, nTitleHeight, ptBase); INT_PTR nQuickMarker=GetQuickMarker(); BOOL bDrawText=TRUE; if(nGsMarker) { dc.SetSelectionMarker(nGsMarker); nGsMarker++; //捕捉时加速 if(nQuickMarker && (nGsMarker-1)!=nQuickMarker) bDrawText=FALSE; else bDrawText=TRUE; } else { bDrawText=FALSE; } ads_matrix mat; ptBase.GetRotationMatrix(nRotWcs, mat); if(bDrawText && !!m_title.m_sText) { //绘制文字 double nOffset=GetTitleLineSpace(FALSE); double nTextHeight=GetTitleTextHeight(TRUE); AcDbObjectId idTextStyle=GetTitleTextStyle(); TDbText textLine; textLine.setPropertiesFrom(this); textLine.SetHeight(nTextHeight); textLine.SetStyleId(idTextStyle); textLine.SetText(m_title.m_sText); const TCHAR *bHardMText=_tcschr(m_title.GetText(), _T('\n')); TDbText *pDbText=NULL; if(bHardMText || (textLine.GetExtents().x + nOffset*2 > nTitleWidth && IsTitleWrapEnabled()) ) { TDbMText *pTextSeg=new TDbMText; pDbText=pTextSeg; pDbText->setPropertiesFrom(this); TDbMText &textSeg=*pTextSeg; textSeg.SetLineSpace(nOffset, FALSE); textSeg.SetPageWidth(nTitleWidth-2*nOffset, FALSE); } else { pDbText=new TDbText; pDbText->setPropertiesFrom(this); } Adesk::UInt16 nColor=GetTitleTextColor(); int nOldColor=dc.GetColor(); if(nColor>0) { pDbText->setColorIndex(nColor); dc.SetColor(nColor); } pDbText->SetHeight(nTextHeight); pDbText->SetStyleId(idTextStyle); pDbText->SetText(m_title.m_sText); InitTextInBox(*pDbText, ptBase, nTitleWidth, nTitleHeight, nOffset, GetTitleHorMode(), GetTitleVerMode()); XPoint ptLoc=pDbText->GetLocation(); ptLoc.TransformBy(mat); pDbText->SetLocation(ptLoc); pDbText->SetRotation(m_nRotation); if(dc.IsFullExplode()) pDbText->ExplodeOrDraw2d(dc); else dc.DrawEntity(*pDbText); delete pDbText; if(nColor>0) dc.SetColor(nOldColor); } ads_polar(XPoint(ptBase), nRotWcs-PI/2, nTitleHeight, ptBase); XPoint ptRight; ads_polar(ptBase, nRotWcs, nTitleWidth, ptRight); if(nGsMarker) { dc.SetSelectionMarker(nGsMarker); nGsMarker++; //捕捉加速 if(nQuickMarker && (nGsMarker-1)!=nQuickMarker) return; } int nOldColor=dc.GetColor(); AcDbPolyline pline; pline.addVertexAt(0, ptBase); pline.addVertexAt(1, ptRight); pline.setPropertiesFrom(this); const TDividerStyle ÷r=m_title.m_divider; switch(divider.m_nFlag) { case TDividerStyle::kLocal: case TDividerStyle::kParent: if(!!m_title.m_divider.m_idLineType) pline.setLinetype(m_title.m_divider.m_idLineType); if(m_title.m_divider.m_nLineWidth>0.0 && !!objectId()) pline.setConstantWidth(m_title.m_divider.m_nLineWidth*GetPScale()); if(m_title.m_divider.m_nColor>0) { dc.SetColor(m_title.m_divider.m_nColor); pline.setColorIndex(m_title.m_divider.m_nColor); } dc.Polyline(pline); break; case TDividerStyle::kNone: default: break; } dc.SetColor(nOldColor); } // 绘制表格的行分割线 void TDbSheet::DrawRowDivider(int nRow, XPoint ptLeft, XExplodeDraw &dc) const { AcDbPolyline pline; if(!InitRowDivider(pline, nRow)) return; DList lstSegments; int nColNum=m_columns.Length(); double nScale=GetPScale(); XLine lnSeg; XPoint ptFrom=ptLeft; XPoint ptStart; BOOL bStartValid=FALSE; double nRotWcs=Layout2Wcs(m_nRotation); for(int nCol=0; nColStartPoint()); pline.addVertexAt(1, pLine->EndPoint()); } else { pline.setPointAt(0, pLine->StartPoint()); pline.setPointAt(1, pLine->EndPoint()); } dc.Polyline(pline); } } // 绘制行分割线 void TDbSheet::DrawRowDivider(XPoint ptBase, XExplodeDraw &dc, int &nGsMarker) const { int nRowNum=m_rows.Length(); XPoint ptLeft=ptBase; INT_PTR nQuickMarker=GetQuickMarker(); double nRotWcs=Layout2Wcs(m_nRotation); for(int n=0; n lstSegments; int nRowNum=m_rows.Length(); double nScale=GetPScale(); XLine lnSeg; XPoint ptFrom=ptTop; XPoint ptStart; BOOL bStartValid=FALSE; for(int nRow=0; nRowStartPoint()); pline.addVertexAt(1, pLine->EndPoint()); } else { pline.setPointAt(0, pLine->StartPoint()); pline.setPointAt(1, pLine->EndPoint()); } dc.Polyline(pline); } } // 绘制表格列分割线 void TDbSheet::DrawColumnDivider(XPoint ptBase, XExplodeDraw &dc, int &nGsMarker) const { double nRotWcs=Layout2Wcs(m_nRotation); int nColNum=m_columns.Length(); XPoint ptTop=ptBase; INT_PTR nQuickMarker=GetQuickMarker(); for(int n=0; n=0 && range.m_nRow<=range.m_nRowMax && range.m_nColumn>=0 && range.m_nColumn<=range.m_nColumnMax && range.m_nRowMaxm_sName, (const TCHAR *)p2); } BOOL TCellBlockInsert::OutputDesc(XString &sDescOut) const { if(!m_sBlockName) return FALSE; XString sDesc(2048); sDesc << _T("^B{"); sDesc << _T("BLOCK=") << m_sBlockName << _T(";"); sDesc << _T("FLAG=") << m_nControlFlag << _T(";"); if(!(m_nControlFlag&CBF_AUTOSIZE)) { sDesc << _T("X=") << m_xValue << _T(";") << _T("Y=") << m_yValue << _T(";") << _T("Z=") << m_zValue << _T(";"); } sDesc << _T("}"); if(m_nControlFlag&CBF_SHOW_ATTR) { sDesc << _T("{"); for(int i=0; i4 && nCharNum<2048) ; else return FALSE; if(pszText[0]==_T('^') && pszText[1]==_T('B') && pszText[2]==_T('{')) ; else return FALSE; const TCHAR *pEndBlock=_tcschr(pszText, _T('}')); if(!pEndBlock) return FALSE; XString sBlockInfo(2048); StrCpy(sBlockInfo, &pszText[3], pEndBlock); //取图块描述 // 分析图块描述 TCHAR *pBegStat=sBlockInfo; while(pBegStat && *pBegStat) { XString sStatement(2048); TCHAR *pEndStat=_tcschr(pBegStat, _T(';')); if(!pEndStat) break; StrCpy(sStatement, pBegStat, pEndStat); TCHAR *pEqual=_tcschr(sStatement, _T('=')); if(!pEqual) return FALSE; XString sLeftValue(2048), sRightValue(2048); StrCpy(sLeftValue, sStatement, pEqual); StrCpy(sRightValue, pEqual+1, NULL); if(_tcsicmp(sLeftValue, _T("BLOCK"))==0) m_sBlockName=sRightValue; else if(_tcsicmp(sLeftValue, _T("FLAG"))==0) m_nControlFlag=_ttoi(sRightValue); else if(_tcsicmp(sLeftValue, _T("X"))==0) m_xValue = _tstof(sRightValue); else if(_tcsicmp(sLeftValue, _T("Y"))==0) m_yValue = _tstof(sRightValue); else if(_tcsicmp(sLeftValue, _T("Z"))==0) m_zValue = _tstof(sRightValue); pBegStat=pEndStat+1; } m_lstAttribs.Reset(); const TCHAR *pBegAttr=_tcschr(pEndBlock, _T('{')); if(!pBegAttr) return TRUE; const TCHAR *pEndAttr=_tcschr(pBegAttr, _T('}')); if(!pEndAttr) return FALSE; XString sAttrInfo(2048); StrCpy(sAttrInfo, pBegAttr+1, pEndAttr); pBegStat=sAttrInfo; while(pBegStat && *pBegStat) { XString sStatement(2048); TCHAR *pEndStat=_tcschr(pBegStat, _T(';')); if(!pEndStat) break; StrCpy(sStatement, pBegStat, pEndStat); TCHAR *pEqual=_tcschr(sStatement, _T('=')); if(!pEqual) return FALSE; XString sLeftValue(2048), sRightValue(2048); StrCpy(sLeftValue, sStatement, pEqual); StrCpy(sRightValue, pEqual+1, NULL); m_lstAttribs.Append(new TAttribValue(sLeftValue, sRightValue)); pBegStat=pEndStat+1; } return TRUE; } /* static BOOL IsBlockInsert(const TCHAR *pszText, AcDbObjectId &idBlock, XPoint &sizeBlock) { if(!pszText) return FALSE; int nCharNum=strlen(pszText); if(nCharNum>2 && nCharNum<256) { if(pszText[0]==_T('^') && pszText[1]==_T('B')) { TCHAR szBlockInfo[256]=_T(""); _tcscpy(szBlockInfo, &pszText[2]); TCHAR *pSep=_tcschr(szBlockInfo, _T(':')); TCHAR szBlockName[256]=_T(""), szSizeX[256]=_T(""), szSizeY[256]=_T(""); if(pSep) { StrCpy(szBlockName, szBlockInfo, pSep); pSep++; TCHAR *pSep1=_tcschr(pSep, _T(':')); if(pSep1) { StrCpy(szSizeX, pSep, pSep1); StrCpy(szSizeY, pSep1+1, NULL); } } double nSizeX=_tstof(szSizeX), nSizeY=_tstof(szSizeY); if(nSizeX<_DIST_SNAP || nSizeY<_DIST_SNAP) return FALSE; idBlock=InitBlock(szBlockName); if(!idBlock) return FALSE; sizeBlock.x=nSizeX; sizeBlock.y=nSizeY; return TRUE; } } return FALSE; } */ // Modify on 2003/2/28 // 增加图块的插入 void TDbSheet::DrawCellText(const TCHAR *pszText, double w, double h, int nRow, int nCol, XPoint ptBase, XExplodeDraw &dc) const { //if(!pszText && pszText[0])//modified by whl on 070206 if(pszText==NULL||_tcslen(pszText)==0) return; ads_matrix mat; double nRotWcs=Layout2Wcs(m_nRotation); ptBase.GetRotationMatrix(nRotWcs, mat); AcDbObjectId idBlock; //XPoint sizeBlock; TCellBlockInsert insert; if(insert.ParserDesc(pszText)) idBlock=InitBlock(insert.m_sBlockName,database()); if(idBlock.isValid()) { XPoint ptAlign=ptBase; double nOffset=GetCellLineSpace(nRow, nCol, FALSE); AcDb::TextHorzMode nHorMode=GetCellHorMode(nRow, nCol); AcDb::TextVertMode nVerMode=GetCellVerMode(nRow, nCol); XExplodeDraw::TextAlignment align=XExplodeDraw::GetTextAlignment( nHorMode, nVerMode); switch(nHorMode) { case AcDb::kTextLeft: ptAlign.x += nOffset; break; case AcDb::kTextCenter: case AcDb::kTextMid: ptAlign.x += w/2; break; case AcDb::kTextRight: ptAlign.x += w; ptAlign.x -= nOffset; break; default: ptAlign.x += w/2; break; } switch(nVerMode) { case AcDb::kTextBase: case AcDb::kTextBottom: ptAlign.y -= h; ptAlign.y += nOffset; break; case AcDb::kTextVertMid: ptAlign.y -= h/2; break; case AcDb::kTextTop: ptAlign.y -= h; break; default: ptAlign.y -= h/2; } // ptInsert-单元格中心点 XPoint ptInsert=ptAlign; ptInsert.TransformBy(mat); ads_polar(ptBase, nRotWcs, w/2.0, ptInsert); ads_polar(XPoint(ptInsert), nRotWcs-PI/2, h/2.0, ptInsert); AcDbBlockReference blkInsert(ptInsert, idBlock); TBlockGeomInfo info; if(insert.m_nControlFlag&CBF_AUTOSIZE) { info.m_nSizeX=max(w-2*nOffset, nOffset); info.m_nSizeY=max(h-2*nOffset, nOffset); if(insert.m_nControlFlag&CBF_EQUAL_SIDE) info.m_nSizeX=info.m_nSizeY=min(info.m_nSizeX, info.m_nSizeY); } else if(insert.m_nControlFlag&CBF_INPUT_SCALE) { info.SetFromInsert(&blkInsert); info.m_nSizeX *= insert.m_xValue; info.m_nSizeY *= insert.m_yValue; info.m_nSizeZ *= insert.m_zValue; } else { info.m_nSizeX=insert.m_xValue; info.m_nSizeY=insert.m_yValue; info.m_nSizeZ=insert.m_zValue; } info.m_ptCen=ptInsert; info.m_nRotation=nRotWcs; blkInsert.setPropertiesFrom(this); //modify by xlc on 071101 //info.UpdateInsert(&blkInsert); UpdateInsert(&blkInsert,info,insert.m_nControlFlag&CBF_UNISCALE); if(insert.m_nControlFlag&CBF_UNISCALE) { //del by xlc on 071101 //AcGeScale3d factors=blkInsert.scaleFactors(); //double nScale=min(factors[0], factors[1]); //factors[0]=factors[1]=factors[2]=nScale; //blkInsert.setScaleFactors(factors); info.SetFromInsert(&blkInsert); info.m_ptCen=ptInsert; info.UpdateInsert(&blkInsert); } Adesk::UInt16 nColor=GetCellTextColor(nRow, nCol); blkInsert.setColorIndex(nColor); //blkInsert.setScaleFactors(scales); BOOL bAcGi=false; if(g_nAcadVer>15.0001) bAcGi=(_tcscmp(dc.Desc(), XAcGiViewDraw::Descriptor())==0); if(bAcGi) { OPENOBJ_BEGIN(idBlock, AcDb::kForRead, AcDbBlockTableRecord, pBlock); if(pBlock) { AcGiSubEntityTraits &traits=((XAcGiViewDraw &)dc).GetCommonDraw()->subEntityTraits(); AcDbObjectId idLayer = traits.layerId(); Adesk::UInt16 nColorOld = traits.color(); AcDbObjectId idLineType = traits.lineTypeId(); AcGeMatrix3d matTrans=BlockTransform(&blkInsert); if(nColor>0 && nColor<256) traits.setColor(nColor); AcGiGeometry *geom=((XAcGiViewDraw &)dc).GetCommonDraw()->rawGeometry(); geom->pushModelTransform(matTrans); geom->draw(pBlock); geom->popModelTransform(); traits.setLayer(idLayer); traits.setColor(nColorOld); traits.setLineType(idLineType); } OPENOBJ_END(); } else { int nOldColor=dc.GetColor(); dc.SetColor(nColor); dc.DrawEntity(blkInsert); dc.SetColor(nOldColor); } // 输出属性 AcGeMatrix3d matBlock=BlockTransform(&blkInsert); OPENOBJ_BEGIN(idBlock, AcDb::kForRead, AcDbBlockTableRecord, pBlock); if(pBlock) { AcDbBlockTableRecordIterator *pIter=NULL; if(pBlock->newIterator(pIter)==Acad::eOk && pIter) { for(pIter->start(); !pIter->done(); pIter->step()) { AcDbObjectId idAtt; pIter->getEntityId(idAtt); OPENOBJ_BEGIN(idAtt, AcDb::kForRead, AcDbAttributeDefinition, pAttr); if(pAttr) { TCHAR *pTag=pAttr->tag(); if(pTag) { TAttribValue *pFind=insert.m_lstAttribs.FindNode(pTag, TAttribValue::FindByName); if(pFind) { TDbText text; text.setPropertiesFrom(this); text.ConvertFrom(pAttr); text.SetText(pFind->m_sValue); text.setColorIndex(nColor); XPoint ptLoc=text.GetLocation(); XPoint ptHeight; ads_polar(ptLoc, nRotWcs+PI/2, text.GetHeight(FALSE), ptHeight); ptHeight.TransformBy(matBlock); ptLoc.TransformBy(matBlock); text.SetLocation(ptLoc); text.SetHeight(ptLoc.Distance2d(ptHeight), FALSE); text.ExplodeOrDraw2d(dc); } delete [] pTag; } } OPENOBJ_END(); } delete pIter; } } OPENOBJ_END(); } else { //绘制文字 double nOffset=GetCellLineSpace(nRow, nCol, FALSE); double nTextHeight=GetCellTextHeight(nRow, nCol, TRUE); AcDbObjectId idTextStyle=GetCellTextStyle(nRow, nCol); TDbText textLine; textLine.setPropertiesFrom(this); //Add this line on 2002/11/18 textLine.SetHeight(nTextHeight); textLine.SetStyleId(idTextStyle); textLine.SetText(pszText); TDbText *pCellText=NULL; const TCHAR *bHardMText=_tcschr(pszText, _T('\n')); XPoint ptMyExt=textLine.GetExtents(); BOOL bOverWidth= (ptMyExt.x + nOffset*2.0 > w); BOOL bWrapEnabled=IsCellWrapEnabled(nRow, nCol); if(bHardMText || (bOverWidth && bWrapEnabled)) { pCellText=new TDbMText; pCellText->setPropertiesFrom(this); TDbMText &textSeg=*(TDbMText *)pCellText; textSeg.SetLineSpace(nOffset, FALSE); textSeg.SetPageWidth(w-2*nOffset, FALSE); } else { pCellText=new TDbText; pCellText->setPropertiesFrom(this); } Adesk::UInt16 nColor=GetCellTextColor(nRow, nCol); int nOldColor=dc.GetColor(); if(nColor>0) { pCellText->setColorIndex(nColor); dc.SetColor(nColor); } pCellText->SetHeight(nTextHeight); pCellText->SetStyleId(idTextStyle); pCellText->SetText(pszText); InitTextInBox(*pCellText, ptBase, w, h, nOffset, GetCellHorMode(nRow, nCol), GetCellVerMode(nRow, nCol)); XPoint ptLoc=pCellText->GetLocation(); ptLoc.TransformBy(mat); pCellText->SetLocation(ptLoc); pCellText->SetRotation(m_nRotation); if(dc.IsFullExplode()) pCellText->ExplodeOrDraw2d(dc); else dc.DrawEntity(*pCellText); if(nColor>0) dc.SetColor(nOldColor); delete pCellText; } } // 绘制单元格文本 void TDbSheet::DrawCellText(XPoint ptTopLeft, XExplodeDraw &dc, int &nGsMarker) const { int nRowNum=GetRowNum(); int nColNum=GetColumnNum(); INT_PTR nQuickMarker=GetQuickMarker(); for(int iRow=0; iRow=0&&col=0&&row=0&&colIsRange()) { ((DList&)m_ranges).FindNode(pCell->GetRange(), CompareRange); return GetSubText(GetRowNum()*GetColumnNum()+1+m_ranges.CurPosition()); } else return GetSubText(row*GetColumnNum()+col+1); } return NULL; } TSubText* TDbSheet::GetSubText(long iText)const { extern BOOL g_bExplodeSubText; XPushMemVar vTemp(TchGeLib::g_bExplodeSubText,TRUE); TDbText* pText=GetText(iText); if(pText==NULL) return NULL; TSubText*pSubText= new TSubText(objectId(),pText,iText); pSubText->SetMultiLine(true); if(iText!=0)//cell pSubText->SetMenuType(5); return pSubText; } void TDbSheet::SetSubText(long i,CString sText) { if(i==0) SetTitleText(sText); else { i--; assertWriteEnabled(); if(iSetText(sText); } else { i-=GetRowNum()*GetColumnNum(); m_ranges[i]->SetText(sText); } } } long TDbSheet::GetNextSubTextIndex(long i,bool bVert,bool bPre)const { if(GetRowNum()==0||GetColumnNum()==0) return i; long trueRowNum=GetRowNum()+m_title.IsVisible(); long curRow,curCol,curRowMax,curColMax; long nextRow,nextCol; if(i==0) { curRow=curRowMax=0; curCol=curColMax=0; } else { i--; if(iGetCoord(TRUE)+m_title.IsVisible(); curCol=pRange->GetCoord(FALSE); curRowMax=pRange->GetCoordMax(TRUE)+m_title.IsVisible(); curColMax=pRange->GetCoordMax(FALSE); } } if(bVert) { if(bPre) nextRow=(curRow-1+trueRowNum)%trueRowNum; else nextRow=(curRowMax+1)%trueRowNum; nextCol=curCol; } else { if(bPre) nextCol=(curCol-1+GetColumnNum())%GetColumnNum(); else nextCol=(curColMax+1)%GetColumnNum(); nextRow=curRow; } if(m_title.IsVisible()) { if(nextRow==0) return 0; else nextRow--; } const TGridCell* pCell=(*this)(nextRow,nextCol); if(pCell->IsRange()) { ((DList&)m_ranges).FindNode(pCell->GetRange(), CompareRange); return GetRowNum()*GetColumnNum()+1+m_ranges.CurPosition(); } else return nextRow*GetColumnNum()+nextCol+1; } // cookies--0,标题 // 接着是正常的单元格 // 然后是合并单元格 TDbText * TDbSheet::GetText(Adesk::UInt32 cookies) const { TDbText *pDbText=NULL; if(cookies==0) //title { if(!m_title.m_sText&&!g_bExplodeSubText) return NULL; BOOL bIncludeTitle=(m_title.m_divider.m_nFlag!=TDividerStyle::kNone); double nTitleHeight = GetTitleHeight(FALSE); double nTitleWidth = GetSheetWidth(FALSE); //左上角为ptBase XPoint ptBase=GetTopLeft(bIncludeTitle); if(!bIncludeTitle) ads_polar(XPoint(ptBase), Layout2Wcs(m_nRotation)+PI/2, nTitleHeight, ptBase); ads_matrix mat; ptBase.GetRotationMatrix(Layout2Wcs(m_nRotation), mat); double nOffset=GetTitleLineSpace(FALSE); double nTextHeight=GetTitleTextHeight(TRUE); AcDbObjectId idTextStyle=GetTitleTextStyle(); TDbText textLine; textLine.setPropertiesFrom(this); textLine.SetHeight(nTextHeight); textLine.SetStyleId(idTextStyle); textLine.SetText(m_title.m_sText); TCHAR *bHardMText=(TCHAR*)_tcschr(m_title.GetText(), _T('\n')); if(bHardMText || (textLine.GetExtents().x + nOffset*2 > nTitleWidth && IsTitleWrapEnabled()) ) { TDbMText *pTextSeg=new TDbMText; pDbText=pTextSeg; pDbText->setPropertiesFrom(this); TDbMText &textSeg=*pTextSeg; textSeg.SetLineSpace(nOffset, FALSE); textSeg.SetPageWidth(nTitleWidth-2*nOffset, FALSE); } else { pDbText=new TDbText; pDbText->setPropertiesFrom(this); } Adesk::UInt16 nColor=GetTitleTextColor(); if(nColor>0) pDbText->setColorIndex(nColor); pDbText->SetHeight(nTextHeight); pDbText->SetStyleId(idTextStyle); pDbText->SetText(m_title.m_sText); InitTextInBox(*pDbText, ptBase, nTitleWidth, nTitleHeight, nOffset, GetTitleHorMode(), GetTitleVerMode()); XPoint ptLoc=pDbText->GetLocation(); ptLoc.TransformBy(mat); pDbText->SetLocation(ptLoc); pDbText->SetRotation(m_nRotation); } else { cookies--; int nRowNum=GetRowNum(); int nColNum=GetColumnNum(); XPoint ptTopLeft=GetTopLeft(FALSE); if((int)cookies w && IsCellWrapEnabled(nRow, nCol))) { pDbText=new TDbMText; pDbText->setPropertiesFrom(this); TDbMText &textSeg=*(TDbMText *)pDbText; textSeg.SetLineSpace(nOffset, FALSE); textSeg.SetPageWidth(w-2*nOffset, FALSE); } else { pDbText=new TDbText; pDbText->setPropertiesFrom(this); } Adesk::UInt16 nColor=GetCellTextColor(nRow, nCol); if(nColor>0) pDbText->setColorIndex(nColor); pDbText->SetHeight(nTextHeight); pDbText->SetStyleId(idTextStyle); pDbText->SetText(pszText); InitTextInBox(*pDbText, ptBase, w, h, nOffset, GetCellHorMode(nRow, nCol), GetCellVerMode(nRow, nCol)); XPoint ptLoc=pDbText->GetLocation(); ptLoc.TransformBy(mat); pDbText->SetLocation(ptLoc); pDbText->SetRotation(m_nRotation); } else //ranges { cookies -= nRowNum*nColNum; if((int)cookies>=m_ranges.Length()) return NULL; const TGridRange &range=m_ranges[cookies]; const TCHAR *pszText=range.GetText(); if(!pszText[0]&&!g_bExplodeSubText) return NULL; double x=GetColumnsWidth(0, range.m_nColumn-1, FALSE); double y=GetRowsHeight(0, range.m_nRow-1, FALSE); double w, h; w=GetColumnsWidth(range.m_nColumn, range.m_nColumnMax, FALSE); h=GetRowsHeight(range.m_nRow, range.m_nRowMax, FALSE); //左上角为ptBase XPoint ptBase; ads_polar(ptTopLeft, Layout2Wcs(m_nRotation), x, ptBase); ads_polar(XPoint(ptBase), Layout2Wcs(m_nRotation)-PI/2, y, ptBase); ads_matrix mat; ptBase.GetRotationMatrix(Layout2Wcs(m_nRotation), mat); int nRow=range.m_nRow; int nCol=range.m_nColumn; // 与正常单元格一样的处理方法 double nOffset=GetCellLineSpace(nRow, nCol, FALSE); double nTextHeight=GetCellTextHeight(nRow, nCol, TRUE); AcDbObjectId idTextStyle=GetCellTextStyle(nRow, nCol); TDbText textLine; textLine.setPropertiesFrom(this); textLine.SetHeight(nTextHeight); textLine.SetStyleId(idTextStyle); textLine.SetText(pszText); TCHAR *bHardMText=(TCHAR*)_tcschr(pszText, _T('\n')); if(bHardMText || (textLine.GetExtents().x + nOffset*2.0 > w && IsCellWrapEnabled(nRow, nCol))) { pDbText=new TDbMText; pDbText->setPropertiesFrom(this); TDbMText &textSeg=*(TDbMText *)pDbText; textSeg.SetLineSpace(nOffset, FALSE); textSeg.SetPageWidth(w-2*nOffset, FALSE); } else { pDbText=new TDbText; pDbText->setPropertiesFrom(this); } Adesk::UInt16 nColor=GetCellTextColor(nRow, nCol); if(nColor>0) pDbText->setColorIndex(nColor); pDbText->SetHeight(nTextHeight); pDbText->SetStyleId(idTextStyle); pDbText->SetText(pszText); InitTextInBox(*pDbText, ptBase, w, h, nOffset, GetCellHorMode(nRow, nCol), GetCellVerMode(nRow, nCol)); XPoint ptLoc=pDbText->GetLocation(); ptLoc.TransformBy(mat); pDbText->SetLocation(ptLoc); pDbText->SetRotation(m_nRotation); } } return pDbText; } // 对某一行初始化分割线的属性, 如果没有分割线则返回FALSE BOOL TDbSheet::InitRowDivider(AcDbPolyline &pline, int nRow) const { const TSheetRow &row=m_rows[nRow]; if(row.m_divider.m_nFlag==TDividerStyle::kNone) return FALSE; const TDividerStyle ÷r=row.m_divider.m_nFlag==TDividerStyle::kLocal ? row.m_divider : m_rowDivider; BOOL bRet=TRUE; pline.setPropertiesFrom(this); switch(divider.m_nFlag) { case TDividerStyle::kLocal: if(!!divider.m_idLineType) pline.setLinetype(divider.m_idLineType); if(divider.m_nLineWidth>0.0 && !!objectId()) pline.setConstantWidth(divider.m_nLineWidth*GetPScale()); if(divider.m_nColor>0) pline.setColorIndex(divider.m_nColor); break; case TDividerStyle::kParent: break; case TDividerStyle::kNone: default: bRet=FALSE; break; } return bRet; } // 对某一列初始化分割线的属性, 如果没有分割线则返回FALSE BOOL TDbSheet::InitColumnDivider(AcDbPolyline &pline, int nCol) const { const TSheetColumn &column=m_columns[nCol]; if(column.m_divider.m_nFlag==TDividerStyle::kNone) return FALSE; const TDividerStyle ÷r=column.m_divider.m_nFlag==TDividerStyle::kLocal ? column.m_divider : m_colDivider; BOOL bRet=TRUE; pline.setPropertiesFrom(this); switch(divider.m_nFlag) { case TDividerStyle::kLocal: if(!!divider.m_idLineType) pline.setLinetype(divider.m_idLineType); if(divider.m_nLineWidth>0.0 && !!objectId()) pline.setConstantWidth(divider.m_nLineWidth*GetPScale()); if(divider.m_nColor>0) pline.setColorIndex(divider.m_nColor); break; case TDividerStyle::kParent: break; case TDividerStyle::kNone: default: bRet=FALSE; break; } return bRet; } /////////////////////////////////////////////// // Helper Method // 强制下级继承上级属性 void TDbSheet::DescInheritGridStyle() { assertWriteEnabled(); int nRowNum=GetRowNum(); int nColNum=GetColumnNum(); for(int iRow=0; iRowm_nVerMode=AcDb::kTextBase; } for(int iCol=0; iColm_gridStyle.SetOverrideAll(FALSE); } for(iRow=0; iRowGetGridStyle(); grid.SetOverrideAll(FALSE); } } } // 下属行继承特性 void TDbSheet::DescInheritRowDivider(bool bIncludeRowHeight) { assertWriteEnabled(); int nRowNum=GetRowNum(); for(int iRow=0; iRowm_divider.SetDividerFlag(TDividerStyle::kParent); if(bIncludeRowHeight) { pRow->SetHeight(m_nRowHeight); pRow->SetRowHeightStyle(TSheetRow::kParent); } } } void TDbSheet::DescInheritColDivider() { assertWriteEnabled(); int nColNum=GetColumnNum(); for(int iCol=0; iColm_divider.SetDividerFlag(TDividerStyle::kParent); } } void TDbSheet::DescInheritColGridStyle(int iCol) { assertWriteEnabled(); int nRowNum=GetRowNum(); for(int iRow=0; iRowGetGridStyle(); BOOL bOver=grid.TestFlagBit(OF_VERMODE); grid.SetOverrideAll(FALSE); if(bOver) { grid.SetFlagBit(OF_VERMODE, TRUE); } } } void TDbSheet::DescInheritRowGridStyle(int iRow) { assertWriteEnabled(); int nColNum=GetColumnNum(); for(int iCol=0; iColGetGridStyle(); grid.SetFlagBit(OF_VERMODE, FALSE); } } XPoint TDbSheet::Align2Base(XPoint ptAlign, XPoint ext) const { XPoint ptBase=XExplodeDraw::Align2Base(m_nAlignment, ptAlign, ext); ads_matrix mat; ptAlign.GetRotationMatrix(Layout2Wcs(m_nRotation), mat); ptBase.TransformBy(mat); return ptBase; } XPoint TDbSheet::Base2Align(XPoint ptBase, XPoint ext) const { XPoint ptAlign=XExplodeDraw::Base2Align(m_nAlignment, ptBase, ext); ads_matrix mat; ptBase.GetRotationMatrix(Layout2Wcs(m_nRotation), mat); ptAlign.TransformBy(mat); return ptAlign; } // 按行列取得单元格 TGridCell * TDbSheet::operator () (int nRow, int nCol) { return &m_pCells[nRow*GetColumnNum()+nCol]; } // 按行列取得单元格 const TGridCell * TDbSheet::operator () (int nRow, int nCol) const { TDbSheet *pThis=(TDbSheet *)this; return (*pThis)(nRow, nCol); } int TDbSheet::HitTestOnColumn(XPoint pt) const { pt.z=0; int nColNum=m_columns.Length(); XPoint ptTopLeft=GetTopLeft(FALSE); double nColWidth=0.0; double nRotWcs=Layout2Wcs(m_nRotation); for(int n=0; nGetRange()) return FALSE; const TGridRange *pRange=pCell->GetRange(); for(int iRow=pRange->GetCoord(TRUE); iRow<=pRange->GetCoordMax(TRUE); iRow++) { for(int iCol=pRange->GetCoord(FALSE); iCol<=pRange->GetCoordMax(FALSE); iCol++) { TGridCell *pCell0=(*this)(iRow, iCol); if(pCell0) { CopyObject(*(TGridCell *)pRange, *pCell0); pCell0->SetRange(NULL); } } } int nRanNum=m_ranges.Length(); for(int i=0; iIsRange()) { pRange=(TGridRange *)pMaster->GetRange(); ASSERT(pRange->GetCoord(TRUE)==nRowFrom && pRange->GetCoord(FALSE)==nColFrom); ASSERT(pRange->GetCoordMax(TRUE)<=nRowTo); ASSERT(pRange->GetCoordMax(FALSE)<=nColTo); pRange->SetCoord(nRowFrom, nColFrom); pRange->SetCoordMax(nRowTo, nColTo); } else { pRange=new TGridRange; CopyObject(pMaster->m_gridStyle, pRange->m_gridStyle); pRange->m_gridStyle.SetFlagBit(OF_HORMODE); pRange->m_gridStyle.SetFlagBit(OF_VERMODE); pRange->m_gridStyle.SetHorMode(AcDb::kTextCenter); pRange->m_gridStyle.SetVerMode(AcDb::kTextVertMid); pRange->SetText(pMaster->GetText()); pRange->SetCoord(nRowFrom, nColFrom); pRange->SetCoordMax(nRowTo, nColTo); m_ranges.Append(pRange); } for(int iRow=nRowFrom; iRow<=nRowTo; iRow++) { for(int iCol=nColFrom; iCol<=nColTo; iCol++) { TGridCell *pSlaver=(*this)(iRow, iCol); if(pSlaver->IsRange()) { //其他的合并单元格,则予以删除 const TGridRange *pSlaverRange=pSlaver->GetRange(); if(pSlaverRange!=pRange) { if(m_ranges.FindNode(pSlaverRange, CompareRange)) m_ranges.Remove(); } } pSlaver->SetRange(pRange); } } } void TDbSheet::CalculateRowHeight(int nRowFrom, int nRowTo) { assertWriteEnabled(); for(int i=nRowFrom; i<=nRowTo; i++) CalculateRowHeight(i); } //当行的文字改变时, 重新计算行高 void TDbSheet::CalculateRowHeight(int nRow) { assertWriteEnabled(); TSheetRow *row=m_rows[nRow]; if(row->GetRowHeightStyle()==TSheetRow::kAutomatic) { int nColNum=GetColumnNum(); XPoint ptTopLeft=GetTopLeft(FALSE); double nSizeHeight=0.0; //row->GetHeight()*GetPScale(); for(int iCol=0; iColGetText(); /* AcDbObjectId idBlock; XPoint sizeBlock; if(IsBlockInsert(szText, idBlock, sizeBlock)) { if(nSizeHeight<1.0E-3) nSizeHeight= sizeBlock.y+nOffset*2.0; else nSizeHeight = max(nSizeHeight, sizeBlock.y+nOffset*2.0); continue; }*/ AcDbVoidPtrArray entSet; XExplodeStream dc(entSet); DrawCellText(nRow, iCol, ptTopLeft, dc); int nCount=entSet.length(); if(nCount>0) { AcDbEntity *pEnt=(AcDbEntity *)entSet[0]; if(pEnt->isKindOf(TDbText::desc())) { TDbText *pText=(TDbText *)pEnt; XPoint ext=pText->GetExtents(); if(nSizeHeight<1.0E-3) nSizeHeight= ext.y+nOffset*2.0; else nSizeHeight = max(nSizeHeight, ext.y+nOffset*2.0); } /*else if(pEnt->isKindOf(AcDbBlockReference::desc())) { TBlockGeomInfo info; info.SetFromInsert(AcDbBlockReference::cast(pEnt)); double nOffset=GetCellLineSpace(nRow, iCol, FALSE); if(nSizeHeight<1.0E-3) nSizeHeight= info.GetSizeY()+nOffset*2.0; else nSizeHeight = max(nSizeHeight, info.GetSizeY()+nOffset*2.0); }*/ } } if(nSizeHeight>1.0E-3) row->SetHeight(nSizeHeight/GetPScale()); } } // 复制行内容和属性(包括单元格) BOOL TDbSheet::CopyRow(int nSrc, int nDest) { //add by whl on 060223 if(nSrc<0||nSrc>=GetRowNum()|| nDest<0||nDest>=GetRowNum()) return FALSE; assertWriteEnabled(); TSheetRow *rowSrc=m_rows[nSrc]; TSheetRow *rowDest=m_rows[nDest]; CopyObject(*rowSrc, *rowDest); int nColNum=GetColumnNum(); //add by xlc on 071224 Array nPosArray; //记录合并单元格的位置数组 for(int i=0; iGetRange(); const TGridRange *pRangeSrc=cellSrc->GetRange(); const TGridCell *pSrc=pRangeSrc? (const TGridCell *)pRangeSrc : (const TGridCell *)cellSrc; if(pRange) CopyObject(*pSrc, *(TGridCell *)pRange); else CopyObject(*pSrc, *cellDest); //add by xlc on 071224 if(pRangeSrc) { TGridRange *pRange1=(TGridRange *)pRangeSrc; int colIndexMin=pRange1->GetCoord(FALSE); int colIndexMax=pRange1->GetCoordMax(FALSE); int nNum=nPosArray.GetLength(); if(nNum < 1 || colIndexMin > nPosArray[nNum-1]) { nPosArray.AddTail(colIndexMin); nPosArray.AddTail(colIndexMax); } } } //add by xlc on 071224 //合并单元格 for(i=0;i=0; i--) { TGridCell *cellSrc=(*this)(i, nSrc); TGridCell *cellDest=(*this)(i, nDest); const TGridRange *pRangeSrc=cellSrc->GetRange(); const TGridRange *pRangeDest=cellDest->GetRange(); TGridCell cellTemp; if(pRangeSrc) { CopyObject(*(const TGridCell *)pRangeSrc, cellTemp); if(pRangeDest) { if(i==pRangeSrc->GetCoord(TRUE)) CopyObject(*(const TGridCell*)pRangeDest, *(TGridCell *)pRangeSrc); if(i==pRangeDest->GetCoord(TRUE)) CopyObject(cellTemp, *(TGridCell *)pRangeDest); } else { if(i==pRangeSrc->GetCoord(TRUE)) CopyObject(*cellDest, *(TGridCell *)pRangeSrc); CopyObject(cellTemp, *cellDest); } } else { CopyObject(*cellSrc, cellTemp); if(pRangeDest) { CopyObject(*(const TGridCell*)pRangeDest, *cellSrc); if(i==pRangeDest->GetCoord(TRUE)) CopyObject(cellTemp, *(TGridCell *)pRangeDest); } else { CopyObject(*cellDest, *cellSrc); CopyObject(cellTemp, *cellDest); } } cellSrc->SetRange((TGridRange *)pRangeSrc); cellDest->SetRange((TGridRange *)pRangeDest); } return TRUE; } // 交换行 BOOL TDbSheet::SwapRow(int nSrc, int nDest) { assertWriteEnabled(); TSheetRow *rowSrc=m_rows[nSrc]; TSheetRow *rowDest=m_rows[nDest]; TchPrivate::Exchange(*rowSrc, *rowDest); int nColNum=GetColumnNum(); for(int i=nColNum-1; i>=0; i--) { TGridCell *cellSrc=(*this)(nSrc, i); TGridCell *cellDest=(*this)(nDest, i); const TGridRange *pRangeSrc=cellSrc->GetRange(); const TGridRange *pRangeDest=cellDest->GetRange(); TGridCell cellTemp; if(pRangeSrc) { CopyObject(*(const TGridCell *)pRangeSrc, cellTemp); if(pRangeDest) { if(i==pRangeSrc->GetCoord(FALSE)) CopyObject(*(const TGridCell*)pRangeDest, *(TGridCell *)pRangeSrc); if(i==pRangeDest->GetCoord(FALSE)) CopyObject(cellTemp, *(TGridCell *)pRangeDest); } else { if(i==pRangeSrc->GetCoord(FALSE)) CopyObject(*cellDest, *(TGridCell *)pRangeSrc); CopyObject(cellTemp, *cellDest); } } else { CopyObject(*cellSrc, cellTemp); if(pRangeDest) { CopyObject(*(const TGridCell*)pRangeDest, *cellSrc); if(i==pRangeDest->GetCoord(FALSE)) CopyObject(cellTemp, *(TGridCell *)pRangeDest); } else { CopyObject(*cellDest, *cellSrc); CopyObject(cellTemp, *cellDest); } } cellSrc->SetRange((TGridRange *)pRangeSrc); cellDest->SetRange((TGridRange *)pRangeDest); } return TRUE; } // 排序 //-1代表最后一列 void TDbSheet::SortByColumn(int nKeyCol, BOOL bSortAscend, int nRowFrom, int nRowTo) { if(nRowTo<0) nRowTo=GetRowNum()-1; for(int i=nRowFrom; i<=nRowTo; i++) { for(int j=nRowFrom; jGetText(), pCell2->GetText()); if((bSortAscend && nCmp>0) || (!bSortAscend && nCmp<0)) SwapRow(i, j); } } } //-1代表最后一列 void TDbSheet::SortByColumns(const DList &lstKeyCol, BOOL bSortAscend, int nRowFrom, int nRowTo) { if(nRowTo<0) nRowTo=GetRowNum()-1; int nColNum=lstKeyCol.Length(); for(int i=nRowFrom; i<=nRowTo; i++) { for(int j=nRowFrom; jGetText(), pCell2->GetText()); if(nCmp1!=0) { nCmp=nCmp1; break; } } if((bSortAscend && nCmp>0) || (!bSortAscend && nCmp<0)) SwapRow(i, j); } } } // 删除列 void TDbSheet::RemoveColumn(int nCol) { assertWriteEnabled(); ASSERT(m_pCells); int nRowNum=GetRowNum(); int nColNum=GetColumnNum(); if(nColNum<=1) return; TGridCell *pCellArray=new TGridCell[nRowNum*(nColNum-1)]; for(int iCol=0; iColGetCoord(FALSE)==pRange->GetCoordMax(FALSE) && pRange->GetCoord(FALSE)==nCol) { //整个单元格在列内 m_ranges.Remove(); nRanNum--; iRan--; } else if(pRange->GetCoord(FALSE)>nCol) { //单元格在右边 ASSERT(pRange->GetCoordMax(FALSE)>nCol); pRange->SetCoord(pRange->GetCoord(TRUE), pRange->GetCoord(FALSE)-1); pRange->SetCoordMax(pRange->GetCoordMax(TRUE), pRange->GetCoordMax(FALSE)-1); } else if(pRange->GetCoord(FALSE)<=nCol && pRange->GetCoordMax(FALSE)>=nCol) { // 跨越列 pRange->SetCoordMax(pRange->GetCoordMax(TRUE), pRange->GetCoordMax(FALSE)-1); if(pRange->IsCellar()) { // 合并单元格退化为单元格 (*this)(pRange->GetCoord(TRUE), pRange->GetCoord(FALSE))->SetRange(NULL); //add by whl on 040902,解决bug:删除列时原先的合并单元退化时丢文字 (*this)(pRange->GetCoord(TRUE), pRange->GetCoord(FALSE))->SetText(pRange->GetText()); m_ranges.Remove(); nRanNum--; iRan--; } } else { ASSERT(pRange->GetCoordMax(FALSE)GetCoord(FALSE)=nRowNum) return; TGridCell *pCellArray=new TGridCell[(nRowNum-1)*nColNum]; for(int iRow=0; iRowGetCoord(TRUE)==pRange->GetCoordMax(TRUE) && pRange->GetCoord(TRUE)==nRow) { //单元范围在此行内 m_ranges.Remove(); nRanNum--; iRan--; } else if(pRange->GetCoord(TRUE)>nRow) { //单元格在下边 ASSERT(pRange->GetCoordMax(TRUE)>nRow); pRange->SetCoord(pRange->GetCoord(TRUE)-1, pRange->GetCoord(FALSE)); pRange->SetCoordMax(pRange->GetCoordMax(TRUE)-1, pRange->GetCoordMax(FALSE)); } else if(pRange->GetCoord(TRUE)<=nRow && pRange->GetCoordMax(TRUE)>=nRow) { // 跨越列 pRange->SetCoordMax(pRange->GetCoordMax(TRUE)-1, pRange->GetCoordMax(FALSE)); if(pRange->IsCellar()) { // 合并单元格退化为单元格 (*this)(pRange->GetCoord(TRUE), pRange->GetCoord(FALSE))->SetRange(NULL); //add by whl on 040902,解决bug:删除行时原先的合并单元退化时丢文字 (*this)(pRange->GetCoord(TRUE), pRange->GetCoord(FALSE))->SetText(pRange->GetText()); m_ranges.Remove(); nRanNum--; iRan--; } } else { ASSERT(pRange->GetCoordMax(TRUE)GetCoord(TRUE)=0 && i=0); int nRowNum=GetRowNum(); int nColNum=GetColumnNum(); if(nColNum<1) return FALSE; TSheetRow *pRow=new TSheetRow; VERIFY(CopyObject(row, *pRow)); if(iGetCoord(TRUE)>=i) { //在新增行后面 //if(pRange->GetCoord(TRUE)>i) pRange->SetCoord(pRange->GetCoord(TRUE)+1, pRange->GetCoord(FALSE)); pRange->SetCoordMax(pRange->GetCoordMax(TRUE)+1, pRange->GetCoordMax(FALSE)); } else if(pRange->GetCoordMax(TRUE)>=i) { //跨越新增的行 pRange->SetCoordMax(pRange->GetCoordMax(TRUE)+1, pRange->GetCoordMax(FALSE)); for(int idx=pRange->GetCoord(FALSE); idx<=pRange->GetCoordMax(FALSE); idx++) { (*this)(i, idx)->SetRange(pRange); } } } return TRUE; } // 增加第i列 BOOL TDbSheet::AddColumnAt(int i) { TSheetColumn col; int nColNum=GetColumnNum(); if(i>=0 && i=0); int nRowNum=GetRowNum(); int nColNum=GetColumnNum(); if(nRowNum<=1) return FALSE; TSheetColumn *pCol=new TSheetColumn; VERIFY(CopyObject(column, *pCol)); if(iGetCoord(FALSE)>=i) { //单元格在新增列后面 pRange->SetCoord(pRange->GetCoord(TRUE), pRange->GetCoord(FALSE)+1); pRange->SetCoordMax(pRange->GetCoordMax(TRUE), pRange->GetCoordMax(FALSE)+1); } else if(pRange->GetCoordMax(FALSE)>=i) { //单元格跨越新增的列 pRange->SetCoordMax(pRange->GetCoordMax(TRUE), pRange->GetCoordMax(FALSE)+1); for(int idx=pRange->GetCoord(TRUE); idx<=pRange->GetCoordMax(TRUE); idx++) { (*this)(idx, i)->SetRange(pRange); } } } return TRUE; } //add by whl on 040903 void TDbSheet::Merge(TDbSheet*pSheet,bool bRowMerge) { assertWriteEnabled(); TDbSheet*pSheet1=(TDbSheet*)(pSheet->clone()); DList &m_columns1=pSheet1->m_columns; DList &m_rows1=pSheet1->m_rows; DList &m_ranges1=pSheet1->m_ranges; TGridCell *m_pCells1=pSheet1->m_pCells; if(bRowMerge) { long newRowNum=GetRowNum()+pSheet->GetRowNum(),newColNum=max(GetColumnNum(),pSheet->GetColumnNum()); //复制单元格 TGridCell *pNewCells=new TGridCell[newRowNum*newColNum]; for(long i=0;iGetRowNum();i++) for(long j=0;jGetColumnNum();j++) pNewCells[(i+GetRowNum())*newColNum+j]=m_pCells1[i*pSheet->GetColumnNum()+j]; delete[] m_pCells; m_pCells=pNewCells; //加列 for(i=GetColumnNum();iSetCoord(pRange->GetCoord(TRUE)+GetRowNum(),pRange->GetCoord(FALSE)); pRange->SetCoordMax(pRange->GetCoordMax(TRUE)+GetRowNum(),pRange->GetCoordMax(FALSE)); } m_ranges<GetRowNum()),newColNum=GetColumnNum()+pSheet->GetColumnNum(); //复制单元格 TGridCell *pNewCells=new TGridCell[newRowNum*newColNum]; for(long i=0;iGetRowNum();i++) for(long j=0;jGetColumnNum();j++) pNewCells[i*newColNum+j+GetColumnNum()]=m_pCells1[i*pSheet->GetColumnNum()+j]; delete[] m_pCells; m_pCells=pNewCells; //加行 for(i=GetRowNum();iSetCoord(pRange->GetCoord(TRUE),pRange->GetCoord(FALSE)+GetColumnNum()); //modify by xlc on 071220 //pRange->SetCoordMax(pRange->GetCoordMax(TRUE)+GetRowNum(),pRange->GetCoordMax(FALSE)+GetColumnNum()); pRange->SetCoordMax(pRange->GetCoordMax(TRUE),pRange->GetCoordMax(FALSE)+GetColumnNum()); } m_ranges<=0); TSheetColumn *pCol=m_columns[i]; VERIFY(CopyObject(column, *pCol)); return TRUE; } // 增加地i行 BOOL TDbSheet::SetRowAt(int i, const TSheetRow &row) { assertWriteEnabled(); ASSERT(i>=0); TSheetRow *pRow=m_rows[i]; VERIFY(CopyObject(row, *pRow)); return TRUE; } void TDbSheet::GetBorder(XPoly2D &polyBorder) const { double nRotWcs=Layout2Wcs(m_nRotation); BOOL bIncludeTitle=(m_title.IsVisible() && m_title.GetDividerStyle().GetDividerFlag()!=TDividerStyle::kNone); XPoint ptUpLeft=GetTopLeft(bIncludeTitle); XPoint ext=GetExtents(bIncludeTitle, FALSE); XPoint ptLowRight, ptUpRight, ptLowLeft; ads_polar(ptUpLeft, nRotWcs-PI/2, ext.y, ptLowLeft); ads_polar(ptLowLeft, nRotWcs, ext.x, ptLowRight); ads_polar(ptLowRight, nRotWcs+PI/2, ext.y, ptUpRight); polyBorder.Reset(); polyBorder.AppendNode(ptLowLeft); polyBorder.AppendNode(ptLowRight); polyBorder.AppendNode(ptUpRight); polyBorder.AppendNode(ptUpLeft); polyBorder.SetFlag(1); //polyBorder.SetElevation(0.0); } // 取得表格大小 XPoint TDbSheet::GetExtents(BOOL bIncludeTitle, BOOL bAsPaperUnit) const { double nWidth=GetSheetWidth(bAsPaperUnit); double nHeight=GetSheetHeight(bIncludeTitle, bAsPaperUnit); return XPoint(nWidth, nHeight); } // 取得表格的高度 double TDbSheet::GetSheetHeight(BOOL bIncludeTitle, BOOL bAsPaperUnit) const { int nRowNum=m_rows.Length(); double nHeight=GetRowsHeight(0, nRowNum-1, TRUE); if(bIncludeTitle) nHeight += m_title.GetHeight(); if(!bAsPaperUnit) { double nScale=GetPScale(); nHeight *= nScale; } return nHeight; } // 取得表格的宽度 double TDbSheet::GetSheetWidth(BOOL bAsPaperUnit) const { double nWidth=0.0; int nColNum=m_columns.Length(); for(int i=0; i=m_rows.Length()) return 0.0; const TSheetRow &row=m_rows[nRow]; double nHeight=0.0; if(row.m_nHeightFlag==TSheetRow::kParent && m_rowHeightStyle==TSheetRow::kFixed) nHeight=m_nRowHeight; else nHeight=row.m_nHeight; if(!bAsPaperUnit) nHeight *= GetPScale(); return nHeight; } // 取得某列的宽度 double TDbSheet::GetColumnWidth(int nCol, BOOL bAsPaperUnit) const { ASSERT(nColIsRange()) { nRow=pCell->GetRange()->GetCoord(TRUE); nCol=pCell->GetRange()->GetCoord(FALSE); } double x=GetColumnsWidth(0, nCol-1, FALSE); double y=GetRowsHeight(0, nRow-1, FALSE); XPoint ptTopLeft=GetTopLeft(FALSE); XPoint ptDest; ads_polar(ptTopLeft, Layout2Wcs(m_nRotation), x, ptDest); ads_polar(XPoint(ptDest), Layout2Wcs(m_nRotation)-PI/2, y, ptDest); return ptDest; } // 判断某单元格是否有底线 BOOL TDbSheet::HasRowDivider(int nRow, int nCol) const { const TGridCell *pCell=(*this)(nRow, nCol); if(!pCell) return TRUE; //没有内容的单元格, 作为空的单元格, 有底线 BOOL bRet=TRUE; if(pCell->IsRange() && nRowGetRange()->m_nRowMax) bRet=FALSE; return bRet; } // 判断某单元格是否有右线 BOOL TDbSheet::HasColumnDivider(int nRow, int nCol) const { const TGridCell *pCell=(*this)(nRow, nCol); if(!pCell) //没有内容的单元格, 作为空的单元格, 有边线 return TRUE; BOOL bRet=TRUE; if(pCell->IsRange() && nColGetRange()->m_nColumnMax) bRet=FALSE; return bRet; } // 求单元格最终有效的属性样式 const TGridStyle * TDbSheet::GetCellGridStyle(int nRow, int nCol, int nOverFlag, BOOL *bLocal) const { const TGridCell &cell=*(*this)(nRow, nCol); const TGridStyle &rStyle=cell.IsRange()? cell.GetRange()->m_gridStyle : cell.m_gridStyle; return GetCellGridStyle(rStyle, nCol, nOverFlag, bLocal); } // 取得单元格最终的有效样式 const TGridStyle * TDbSheet::GetCellGridStyle(const TGridStyle &rStyle, int nCol, int nOverFlag, BOOL*bLocal) const { const TGridStyle *pGridStyle=NULL; if(rStyle.m_nOverride&nOverFlag) { pGridStyle=&rStyle; if(bLocal) *bLocal=TRUE; } else { if(bLocal) *bLocal=FALSE; const TSheetColumn &column=m_columns[nCol]; if(column.m_gridStyle.m_nOverride&nOverFlag) pGridStyle=&column.m_gridStyle; else if(m_gridStyle.m_nOverride&nOverFlag) pGridStyle=&m_gridStyle; } return pGridStyle; } // 取得单元格的水平对齐方式 AcDb::TextHorzMode TDbSheet::GetCellHorMode(int nRow, int nCol, BOOL *bLocal) const { const TGridStyle *style=GetCellGridStyle(nRow, nCol, OF_HORMODE, bLocal); ASSERT(style); return style->m_nHorMode; } // 取得单元格的垂直对齐方式, 继承方式不同于其它 AcDb::TextVertMode TDbSheet::GetCellVerMode(int nRow, int nCol, BOOL *bLocal) const { const TGridCell &cell=*(*this)(nRow, nCol); const TGridStyle &rStyle=cell.IsRange()? cell.GetRange()->m_gridStyle : cell.m_gridStyle; AcDb::TextVertMode nVerMode; if(rStyle.m_nOverride&OF_VERMODE) { nVerMode=rStyle.m_nVerMode; if(bLocal) *bLocal=TRUE; } else { nVerMode=m_rows[nRow].m_nVerMode; if(nVerMode==AcDb::kTextBase) { //继承 nVerMode=m_gridStyle.GetVerMode(); } if(bLocal) *bLocal=FALSE; } return nVerMode; } //取得单元格的文本行间距 double TDbSheet::GetCellLineSpace(int nRow, int nCol, BOOL bAsPaperUnit) const { const TGridStyle *style1=GetCellGridStyle(nRow, nCol, OF_LINESPACE); const TGridStyle *style2=GetCellGridStyle(nRow, nCol, OF_TEXTHEIGHT); ASSERT(style1 && style2); double nVal=style1->m_nLineSpaceFactor * style2->m_nTextHeight; if(!bAsPaperUnit) nVal *= GetPScale(); return nVal; } //取得单元格的文本行间距 double TDbSheet::GetCellLineSpaceFactor(int nRow, int nCol, BOOL *bLocal) const { const TGridStyle *style=GetCellGridStyle(nRow, nCol, OF_LINESPACE, bLocal); ASSERT(style); double nLineSpaceFactor=style->m_nLineSpaceFactor; return nLineSpaceFactor; } // 取得单元格的文本高度 double TDbSheet::GetCellTextHeight(int nRow, int nCol, BOOL bAsPaperUnit, BOOL *bLocal) const { const TGridStyle *style=GetCellGridStyle(nRow, nCol, OF_TEXTHEIGHT, bLocal); ASSERT(style); double nHeight=style->m_nTextHeight; if(!bAsPaperUnit) nHeight *= GetPScale(); return nHeight; } // 取得单元格的文字样式 AcDbObjectId TDbSheet::GetCellTextStyle(int nRow, int nCol, BOOL *bLocal) const { const TGridStyle *style=GetCellGridStyle(nRow, nCol, OF_TEXTSTYLE, bLocal); ASSERT(style); AcDbObjectId idStyle=style->m_idTextStyle; if(!idStyle) idStyle=m_gridStyle.GetTextStyleId(); return idStyle; } // 取得单元格的文字颜色 Adesk::UInt16 TDbSheet::GetCellTextColor(int nRow, int nCol, BOOL *bLocal) const { const TGridStyle *style=GetCellGridStyle(nRow, nCol, OF_TEXTCOLOR, bLocal); ASSERT(style); return style->m_nTextColor; } // 单元格文字是否自动换行 BOOL TDbSheet::IsCellWrapEnabled(int nRow, int nCol, BOOL *bLocal) const { const TGridStyle *style=GetCellGridStyle(nRow, nCol, OF_TEXTWRAP, bLocal); ASSERT(style); return style->m_bTextWrap; } ////////////////////////////////////////////////////////////////// // 标题的属性 // 标题的属性为局部, 不继承 // 求标题最终有效的属性样式 const TGridStyle * TDbSheet::GetTitleGridStyle(int nOverFlag, BOOL *bLocal) const { const TGridStyle *pGridStyle=NULL; pGridStyle=&m_title.m_gridStyle; if(bLocal) *bLocal=TRUE; /* if(m_title.m_gridStyle.m_nOverride&nOverFlag) { pGridStyle=&m_title.m_gridStyle; if(bLocal) *bLocal=TRUE; } else if(m_gridStyle.m_nOverride&nOverFlag) { pGridStyle=&m_gridStyle; if(bLocal) *bLocal=FALSE; }*/ return pGridStyle; } // 标题的高度 double TDbSheet::GetTitleHeight(BOOL bAsPaperUnit) const { double nHeight=m_title.m_nHeight; if(!bAsPaperUnit) nHeight *= GetPScale(); return nHeight; } // 标题文字的水平对齐方式 AcDb::TextHorzMode TDbSheet::GetTitleHorMode( BOOL *bLocal) const { const TGridStyle *style=GetTitleGridStyle(OF_HORMODE, bLocal); ASSERT(style); return style->m_nHorMode; } // 取得单元格的垂直对齐方式 AcDb::TextVertMode TDbSheet::GetTitleVerMode( BOOL *bLocal) const { const TGridStyle *style=GetTitleGridStyle(OF_VERMODE, bLocal); ASSERT(style); return style->GetVerMode(); } // 标题的文字行间距 double TDbSheet::GetTitleLineSpace(BOOL bAsPaperUnit) const { double nTextHeight=GetTitleTextHeight(bAsPaperUnit); const TGridStyle *style=GetTitleGridStyle(OF_LINESPACE); double nLineSpaceFactor=(style? style->m_nLineSpaceFactor : LSF_DEFAULT); return (nTextHeight*nLineSpaceFactor); } // 标题的文字行间距 double TDbSheet::GetTitleLineSpaceFactor(BOOL *bLocal) const { const TGridStyle *style=GetTitleGridStyle(OF_LINESPACE, bLocal); double nLineSpaceFactor=(style? style->m_nLineSpaceFactor : LSF_DEFAULT); return nLineSpaceFactor; } // 标题的文字高度 double TDbSheet::GetTitleTextHeight(BOOL bAsPaperUnit, BOOL *bLocal) const { const TGridStyle *style=GetTitleGridStyle(OF_TEXTHEIGHT, bLocal); ASSERT(style); double nHeight=style->m_nTextHeight; if(!bAsPaperUnit) nHeight *= GetPScale(); return nHeight; } // 标题的文字样式 AcDbObjectId TDbSheet::GetTitleTextStyle(BOOL *bLocal) const { const TGridStyle *style=GetTitleGridStyle(OF_TEXTSTYLE, bLocal); ASSERT(style); AcDbObjectId idStyle=style->m_idTextStyle; if(!idStyle) idStyle=m_gridStyle.GetTextStyleId(); return idStyle; } Adesk::UInt16 TDbSheet::GetTitleTextColor(BOOL *bLocal) const { const TGridStyle *style=GetTitleGridStyle(OF_TEXTCOLOR, bLocal); ASSERT(style); return style->GetTextColor(); } // 标题文字是否自动换行 BOOL TDbSheet::IsTitleWrapEnabled(BOOL *bLocal) const { const TGridStyle *style=GetTitleGridStyle(OF_TEXTWRAP, bLocal); ASSERT(style); return style->m_bTextWrap; } // 取得标题文本 const TCHAR *TDbSheet::GetTitleText() const { return (const TCHAR *)m_title.m_sText; } // 设置标题文本 void TDbSheet::SetTitleText(const TCHAR *szText) { assertWriteEnabled(); m_title.m_sText = szText; } void TDbSheet::SetTitleHeight(double h, BOOL bAsPaperUnit) { assertWriteEnabled(); if(!bAsPaperUnit) h /= GetPScale(); m_title.SetHeight(h); } void TDbSheet::SetTitleGridStyle(const TGridStyle &gridStyle) { assertWriteEnabled(); m_title.SetGridStyle(gridStyle); } const TSheetTitle & TDbSheet::GetTitle() const { return m_title; } TSheetTitle& TDbSheet::GetTitle() { return m_title; } const TCHAR* TDbSheet::GetDefaultLayer()const { return LAY_SHEET; } void InitDbSheet(BOOL bTrue) { if(bTrue) { TDbSheet::rxInit(); acrxBuildClassHierarchy(); TDbSheet::InitMatchProtocol(TRUE); } else { TDbSheet::InitMatchProtocol(FALSE); deleteAcRxClass(TDbSheet::desc()); } }