// TSheetEdJig.cpp: implementation of the TSheetEdJig class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" //#include //#include #include "TSheetEdJig.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// TSheetEdJig::TSheetEdJig() { m_nOperCode=TSheetEdJig::kNone; m_TextDlg = NULL; m_iOldToRow = 0; m_iOldToCol = 0; m_bNeedPlus = FALSE; } TSheetEdJig::~TSheetEdJig() { if(m_TextDlg){ m_TextDlg->DestroyWindow(); delete m_TextDlg; m_TextDlg = NULL; } } // 转换成ADS代码 int TSheetEdJig::GetRetCode(int retCode, int *kwordId) const { int ret = retCode; if (ret == AcEdJig::kCancel) ret = RTCAN; else if(ret == AcEdJig::kNull) ret = RTNONE; else if (ret <= 0) ret = RTNORM; else { if(kwordId) *kwordId = ret-1; ret = RTKWORD; } return ret; } AcDbObjectId TSheetEdJig::GetHitRow(int &nRowFrom) const { ASSERT(m_nOperCode==TSheetEdJig::kSingleRow); AcDbObjectId id=m_idSheet; if(!!id) { OPENOBJ_BEGIN(id, AcDb::kForRead, TDbSheet, pSheet); ASSERT(pSheet); int nRow=pSheet->HitTestOnRow(m_ptResult); if(nRow<0) { id=AcDbObjectId::kNull; } else { nRowFrom=nRow; } OPENOBJ_END(); } return id; } AcDbObjectId TSheetEdJig::GetHitColumn(int &nColFrom) const { ASSERT(m_nOperCode==TSheetEdJig::kSingleCol); AcDbObjectId id=m_idSheet; if(!!id) { OPENOBJ_BEGIN(id, AcDb::kForRead, TDbSheet, pSheet); ASSERT(pSheet); int nCol=pSheet->HitTestOnColumn(m_ptResult); if(nCol<0) { id=AcDbObjectId::kNull; } else { nColFrom=nCol; } OPENOBJ_END(); } return id; } BOOL TSheetEdJig::GetHitCells(const TDbSheet *pSheet, int &nRowFrom, int &nColFrom, int &nRowTo, int &nColTo) const { int nColMin1, nRowMin1, nColMin2, nRowMin2; const TGridCell *pCell1=pSheet->HitTestOnCell(m_ptInput, &nRowMin1, &nColMin1); const TGridCell *pCell2=pSheet->HitTestOnCell(m_ptResult, &nRowMin2, &nColMin2); if(!pCell1 || !pCell2) return FALSE; int nColMax1=pCell1->IsRange()? pCell1->GetRange()->GetCoordMax(FALSE) : nColMin1; int nRowMax1=pCell1->IsRange()? pCell1->GetRange()->GetCoordMax(TRUE) : nRowMin1; int nColMax2=pCell2->IsRange()? pCell2->GetRange()->GetCoordMax(FALSE) : nColMin2; int nRowMax2=pCell2->IsRange()? pCell2->GetRange()->GetCoordMax(TRUE) : nRowMin2; nRowFrom = min(nRowMin1, nRowMin2); nRowTo = max(nRowMax1, nRowMax2); nColFrom = min(nColMin1, nColMin2); nColTo = max(nColMax1, nColMax2); if(nColFrom != nColTo) // SR ADD 2003/1/24 保证只在某一列中选 return FALSE; return TRUE; } // 开始执行拖动 int TSheetEdJig::DoIt(int *keyIndex) { int nRetCode=0; setDispPrompt(m_sPrompt); if(!!m_sKeyword && keyIndex) { INITGET_BEG(-1, m_sKeyword); try { nRetCode = drag(); } catch(...) { nRetCode=AcEdJig::kCancel; } INITGET_END(); } else { try { nRetCode = drag(); } catch(...) { nRetCode=AcEdJig::kCancel; } } nRetCode=GetRetCode(nRetCode, keyIndex); return nRetCode; } // 反馈 AcEdJig::DragStatus TSheetEdJig::sampler() { DragStatus stat; setUserInputControls((UserInputControls) (AcEdJig::kAccept3dCoordinates|AcEdJig::kNullResponseAccepted)); if (!!m_sKeyword) setKeywordList(m_sKeyword); else setKeywordList(NULL); XPoint ptTemp; stat = acquirePoint(ptTemp); if(stat == AcEdJig::kNormal) { if (ptTemp.Distance2d(m_ptResult)>_distSnap) { m_ptResult=ptTemp; } else return AcEdJig::kNoChange; } return stat; } void TSheetEdJig::UpdateRegion(XPoint ptTopLeft, double nWidth, double nHeight, double nAng) { XPoint ptBotLeft, ptBotRight, ptTopRight; ads_polar(ptTopLeft, nAng-PI/2, nHeight, ptBotLeft); ads_polar(ptBotLeft, nAng, nWidth, ptBotRight); ads_polar(ptTopLeft, nAng, nWidth, ptTopRight); m_entDraw.setPointAt(0, ptTopLeft); m_entDraw.setPointAt(1, ptBotLeft); m_entDraw.setPointAt(3, ptBotRight); m_entDraw.setPointAt(2, ptTopRight); } // 更新实体数据 Adesk::Boolean TSheetEdJig::update() { Adesk::Boolean bRet=Adesk::kTrue; if(m_nOperCode==TSheetEdJig::kSingleRow) { //单行选择 m_idSheet = GetHitSheet(m_ptResult); if(!!m_idSheet) { OPENOBJ_BEGIN(m_idSheet, AcDb::kForRead, TDbSheet, pSheet); ASSERT(pSheet); int nRow=pSheet->HitTestOnRow(m_ptResult); if(nRow>=0) { XPoint ptTopLeft=pSheet->GetRowPoint(nRow); double nHeight=pSheet->GetRowHeight(nRow, FALSE); double nWidth=pSheet->GetSheetWidth(FALSE); double nAng=pSheet->GetRotation(); UpdateRegion(ptTopLeft, nWidth, nHeight, nAng); } OPENOBJ_END(); } } else if(m_nOperCode==TSheetEdJig::kSingleCell) { //点选单元格 m_idSheet = GetHitSheet(m_ptResult); if(!!m_idSheet) { OPENOBJ_BEGIN(m_idSheet, AcDb::kForRead, TDbSheet, pSheet); int nRow, nCol; const TGridCell *pCell = pSheet->HitTestOnCell(m_ptResult, &nRow, &nCol); if(pCell) { XPoint ptTopLeft=pSheet->GetCellPoint(nRow, nCol); XPoint szCell=pSheet->GetCellSize(nRow, nCol, FALSE); XPoint ptBotLeft, ptBotRight, ptTopRight; double nAng=pSheet->GetRotation(); UpdateRegion(ptTopLeft, szCell.x, szCell.y, nAng); } OPENOBJ_END(); } } else if(m_nOperCode==TSheetEdJig::kSingleCol) { //单列选择 m_idSheet = GetHitSheet(m_ptResult); if(!!m_idSheet) { OPENOBJ_BEGIN(m_idSheet, AcDb::kForRead, TDbSheet, pSheet); int nCol = pSheet->HitTestOnColumn(m_ptResult); if(nCol>=0) { double nWidth=pSheet->GetColumnWidth(nCol, FALSE); double nHeight=pSheet->GetSheetHeight(FALSE, FALSE); XPoint ptTopLeft=pSheet->GetColumnPoint(nCol); double nAng=pSheet->GetRotation(); UpdateRegion(ptTopLeft, nWidth, nHeight, nAng); } OPENOBJ_END(); } } else if(m_nOperCode==TSheetEdJig::kMultCell) {//窗选单元格 ASSERT(!!m_idSheet); OPENOBJ_BEGIN(m_idSheet, AcDb::kForRead, TDbSheet, pSheet); ASSERT(pSheet); int nColFrom, nColTo, nRowFrom, nRowTo; if(GetHitCells(pSheet, nRowFrom, nColFrom, nRowTo, nColTo)) { double nWidth=pSheet->GetColumnsWidth(nColFrom, nColTo, FALSE); double nHeight=pSheet->GetRowsHeight(nRowFrom, nRowTo, FALSE); XPoint ptTopLeft=pSheet->GetCellPoint(nRowFrom, nColFrom); double nAng=pSheet->GetRotation(); UpdateRegion(ptTopLeft, nWidth, nHeight, nAng); int nRow, nCol; const TGridCell *pCell = pSheet->HitTestOnCell(m_ptInput, &nRow, &nCol); pSheet->HitTestOnCell(m_ptResult, &nRow, &nCol); SHORT nStateShift = GetKeyState(VK_SHIFT); BOOL bShift = (nStateShift&256)!=0; if((nRow != m_iOldToRow || nCol != m_iOldToCol) && !bShift && m_bNeedPlus){ m_iOldToRow = nRow; m_iOldToCol = nCol; CString csText = pCell->GetText(); int len = abs(nRowTo - nRowFrom); SHORT nStateCtrl = GetKeyState(VK_CONTROL); BOOL bCtrl = (nStateCtrl&256)!=0; CString csText2; if(bCtrl) csText2 = PlusString(csText, len, FALSE); else csText2 = PlusString(csText, len, TRUE); DList lstInfo; CBlockStruct *pInfo = new CBlockStruct(); pInfo->m_csRecord = csText; pInfo->m_csDesName = csText2; lstInfo.Append(pInfo); if(m_TextDlg) { m_TextDlg->DestroyWindow(); delete m_TextDlg; m_TextDlg = NULL; } if(!m_TextDlg){ XPoint ptSize = pSheet->GetCellSize(m_iOldToRow, m_iOldToCol); XPoint ptStart = pSheet->GetCellPoint(m_iOldToRow, m_iOldToCol); ptStart.x += (ptSize.x*DocGetPScale()); m_TextDlg = new CTipWnd(); CPoint ptDwgView; int cvport=0; VERIFY(xg_getvar(_T("CVPORT"), &cvport)==RTNORM); acedCoordFromWorldToPixel(cvport, ptStart, ptDwgView); m_TextDlg->Create(lstInfo, ptDwgView.x, ptDwgView.y, acedGetAcadDwgView()); } } } OPENOBJ_END(); } else { bRet=Adesk::kFalse; } return bRet; } AcDbEntity* TSheetEdJig::entity() const { return (AcDbEntity *)(&m_entDraw); }