144 lines
4.7 KiB
C++
144 lines
4.7 KiB
C++
#include "stdafx.h"
|
|
#include "MaterialStructCtrl.h"
|
|
//GEOAPI AcDbHatch * NewHatchFromPoly2D(const XPoly2D &poly, const TCHAR *pszPattern, double nScl);
|
|
|
|
CMaterialStructCtrl::CMaterialStructCtrl()
|
|
: CGsPreviewCtrl(6),m_dbPreview(true, true)
|
|
{
|
|
m_nMaterialLen=1000; //构件长度,默认1000
|
|
m_nRotation=0; //转角,水平0,垂直90
|
|
m_nScale=30; //填充比例,默认100
|
|
m_nColorFrame=2; //结构的颜色,默认2
|
|
m_nColorLeader=3;
|
|
|
|
AcDbTextStyleTable *pStyleTab=NULL;
|
|
VERIFY(m_dbPreview.getSymbolTable(pStyleTab, AcDb::kForRead)==Acad::eOk);
|
|
AcDbTextStyleTableRecord *pRec=NULL;
|
|
VERIFY(pStyleTab->getAt(_T("STANDARD"), pRec, AcDb::kForWrite)==Acad::eOk);
|
|
pStyleTab->close();
|
|
pRec->setBigFontFileName(_T("HZTXT.SHX"));
|
|
m_idStyle=pRec->objectId();
|
|
pRec->close();
|
|
}
|
|
|
|
void CMaterialStructCtrl::UpdateView()
|
|
{
|
|
if(!m_lstMaters)
|
|
return;
|
|
int nCount=m_idArray.length();
|
|
for(int n=0; n<nCount; n++) {
|
|
AcDbObjectId id=m_idArray[n];
|
|
OPENOBJ_BEGIN(id, AcDb::kForWrite, AcDbEntity, pEnt);
|
|
if(pEnt)
|
|
pEnt->erase();
|
|
OPENOBJ_END();
|
|
}
|
|
while(m_idArray.length())
|
|
m_idArray.removeLast();
|
|
|
|
AcDbBlockTable *pBlockTab=NULL;
|
|
VERIFY(m_dbPreview.getSymbolTable(pBlockTab, AcDb::kForRead)==Acad::eOk);
|
|
AcDbBlockTableRecord *pMspace=NULL;
|
|
VERIFY(pBlockTab->getAt(ACDB_MODEL_SPACE, pMspace, AcDb::kForWrite)==Acad::eOk);
|
|
pBlockTab->close();
|
|
XPoint ptLowLeft;
|
|
double nTotalWidth=0;
|
|
XString sTotalText(1024);
|
|
int nMatNum=m_lstMaters.Length();
|
|
for(int i=0; i<nMatNum; i++) {
|
|
TMaterialStruct *pMater=m_lstMaters[i];
|
|
if(i!=0)
|
|
sTotalText << _T("\n");
|
|
sTotalText << pMater->sName;
|
|
pMater=m_lstMaters[nMatNum-1-i];
|
|
nTotalWidth += pMater->nWidth;
|
|
XPoint ptLowRight, ptUpRight, ptUpLeft;
|
|
ads_polar(ptLowLeft, m_nRotation, m_nMaterialLen, ptLowRight);
|
|
ads_polar(ptLowRight, m_nRotation+PI/2, pMater->nWidth, ptUpRight);
|
|
ads_polar(ptUpRight, m_nRotation+PI, m_nMaterialLen, ptUpLeft);
|
|
XPoly2D polyRect(1);
|
|
polyRect.AppendNode(ptLowLeft); polyRect.AppendNode(ptLowRight);
|
|
polyRect.AppendNode(ptUpRight); polyRect.AppendNode(ptUpLeft);
|
|
AcDbHatch *pHatch=NewHatchFromPoly2D(polyRect, pMater->sPattern, m_nScale);
|
|
if(pHatch) {
|
|
pHatch->setColorIndex(pMater->nColor);
|
|
AcDbObjectId idNew;
|
|
if(pMspace->appendAcDbEntity(idNew, pHatch)==Acad::eOk) {
|
|
m_idArray.append(idNew);
|
|
pHatch->close();
|
|
} else
|
|
delete pHatch;
|
|
}
|
|
AcDbPolyline *pline=new AcDbPolyline;
|
|
PolyConvert(polyRect, *pline);
|
|
pline->setColorIndex(m_nColorFrame);
|
|
AcDbObjectId idNew;
|
|
if(pMspace->appendAcDbEntity(idNew, pline)==Acad::eOk) {
|
|
m_idArray.append(idNew);
|
|
pline->close();
|
|
} else
|
|
delete pline;
|
|
ptLowLeft=ptUpLeft;
|
|
}
|
|
|
|
XPoint pt1, pt2;
|
|
double nTempDist=(m_nRotation<PI/4? m_nMaterialLen/10.0 : m_nMaterialLen*9/10.0);
|
|
|
|
ads_polar(XPoint(), m_nRotation, nTempDist, pt1);
|
|
ads_polar(pt1, m_nRotation-PI/2, m_nMaterialLen/5.0, pt2);
|
|
ads_polar(XPoint(pt1), m_nRotation+PI/2, nTotalWidth, pt1);
|
|
|
|
//绘制材料清单
|
|
TDbSymbComposing *pText=new TDbSymbComposing;
|
|
pText->setDatabaseDefaults(&m_dbPreview);
|
|
pText->SetStartPoint(pt1);
|
|
pText->SetTurnPoint(pt2);
|
|
pText->SetText(sTotalText);
|
|
pText->SetTextStyleId(m_idStyle);
|
|
pText->SetSideText(FALSE);
|
|
pText->SetTextBaseLen(pText->GetDefaultTextBaseLen());
|
|
pText->SetPScale(m_nScale);
|
|
|
|
AcDbVoidPtrArray entSet;
|
|
pText->explode(entSet);
|
|
delete pText;
|
|
int num=entSet.length();
|
|
int idx=0;
|
|
for(n=0; n<num; n++) {
|
|
AcDbEntity *pEnt=(AcDbEntity *)entSet[n];
|
|
if(pEnt->isA()==TDbText::desc()) {
|
|
if(idx<m_lstMaters.Length())
|
|
pEnt->setColorIndex(m_lstMaters[idx]->nColor);
|
|
idx++;
|
|
} else {
|
|
pEnt->setColorIndex(m_nColorLeader);
|
|
}
|
|
|
|
AcDbObjectId idNew;
|
|
if(pMspace->appendAcDbEntity(idNew, pEnt)==Acad::eOk) {
|
|
m_idArray.append(idNew);
|
|
pEnt->close();
|
|
} else
|
|
delete pEnt;
|
|
}
|
|
|
|
clearAll();
|
|
init(true);
|
|
XPoint ptTar;
|
|
ads_polar(XPoint(), m_nRotation, m_nMaterialLen/2, ptTar);
|
|
XPoint position(ptTar);
|
|
position.z = 1;
|
|
AcGsView* pView = view();
|
|
pView->setView(position, ptTar,
|
|
AcGeVector3d(0.0, 1.0, 0.0), // upvector
|
|
m_nMaterialLen*1.2, m_nMaterialLen*1.2);
|
|
|
|
AcGsModel *pModel=model();
|
|
pView->add(pMspace, pModel);
|
|
pMspace->close();
|
|
|
|
Invalidate();
|
|
}
|
|
|
|
|