250 lines
5.8 KiB
C++
250 lines
5.8 KiB
C++
#include "stdafx.h"
|
||
#include "resource.h"
|
||
#include "ObjPreviewDlg.h"
|
||
|
||
IMPLEMENT_DYNAMIC(CObjPreviewDlg, WGroupDlg)
|
||
CObjPreviewDlg::CObjPreviewDlg(UINT id, CWnd* pParent /*=NULL*/)
|
||
: WGroupDlg(id, pParent)
|
||
{
|
||
m_pDbPreview=NULL;
|
||
}
|
||
CObjPreviewDlg::~CObjPreviewDlg()
|
||
{
|
||
if (m_pDbPreview!=NULL)
|
||
delete m_pDbPreview;
|
||
}
|
||
BOOL CObjPreviewDlg::OnInitDialog()
|
||
{
|
||
WGroupDlg::OnInitDialog();
|
||
|
||
extern GEOAPI double g_nAcadVer;
|
||
m_bUseOldImage=m_bModeless&&//无模式
|
||
(g_nAcadVer>16.99&&g_nAcadVer<17.19);//2007,2008,acad有bug
|
||
|
||
if (!m_bUseOldImage)
|
||
{
|
||
m_pDbPreview=new AcDbDatabase;
|
||
//以下为初始化CGsPreview控件
|
||
m_ctrlPreview.SubclassDlgItem(IDC_PREVIEW,this);
|
||
m_ctrlPreview.SetOrbitFlag(OBF_ZOOM|OBF_PAN|OBF_ORBIT);
|
||
}
|
||
return TRUE;
|
||
}
|
||
BEGIN_MESSAGE_MAP(CObjPreviewDlg, WGroupDlg)
|
||
//{{AFX_MSG_MAP(CObjPreviewDlg)
|
||
ON_WM_PAINT()
|
||
ON_WM_DESTROY()
|
||
//}}AFX_MSG_MAP
|
||
END_MESSAGE_MAP()
|
||
|
||
BOOL CObjPreviewDlg::ValidateData()
|
||
{
|
||
AcDbEntity *pObj = NewObject();
|
||
ASSERT(pObj);
|
||
Dlg2Obj(pObj);
|
||
|
||
BOOL bRet;
|
||
TEntityBase *pEntBase=TEntityBase::Cast(pObj);
|
||
if (pEntBase==NULL)
|
||
bRet=TRUE;
|
||
else
|
||
bRet=pEntBase->IsValid();
|
||
|
||
delete pObj;
|
||
return bRet;
|
||
}
|
||
class TMyDocLock
|
||
{
|
||
protected:
|
||
AcAxDocLock *m_pDocLock;
|
||
public:
|
||
TMyDocLock(AcDbDatabase*pDb)
|
||
{
|
||
m_pDocLock=(acDocManager->isApplicationContext()?
|
||
new AcAxDocLock(pDb) : NULL);
|
||
if (m_pDocLock)
|
||
VERIFY(m_pDocLock->lockStatus()==Acad::eOk);
|
||
}
|
||
~TMyDocLock()
|
||
{
|
||
if (m_pDocLock)
|
||
delete m_pDocLock;
|
||
}
|
||
};
|
||
void CObjPreviewDlg::UpdateImage()
|
||
{
|
||
UpdateData();
|
||
|
||
if (m_bUseOldImage)
|
||
{
|
||
AcDbEntity *pEnt = NewObject();
|
||
TEntityBase *pStep=TEntityBase::Cast(pEnt);
|
||
if (pStep==NULL)
|
||
return;
|
||
|
||
Dlg2Obj(pEnt);
|
||
CWnd *pImageBox=GetDlgItem(IDC_PREVIEW);
|
||
if (pImageBox==NULL)
|
||
return;
|
||
|
||
CRect rect;
|
||
pImageBox->GetClientRect(rect);
|
||
CDC *pDC=pImageBox->GetDC();
|
||
m_image.InitDC(pDC, rect, GetAcadBackColor());
|
||
m_image.Reset();
|
||
if (!pStep->IsValid())
|
||
m_image.PaintSlide(_T("TArch(ErrorInput)"));
|
||
else
|
||
{
|
||
pStep->ExplodeOrDraw2d(m_image);
|
||
m_image.Redraw();
|
||
}
|
||
m_image.SetDC(NULL);
|
||
pImageBox->ReleaseDC(pDC);
|
||
|
||
//modified by whl on090320,解决vista+08崩溃问题
|
||
//delete pStep;
|
||
m_lstEntBuf.Append(pEnt);
|
||
}
|
||
else
|
||
{
|
||
TDocLock lock1;
|
||
TMyDocLock lock2(m_pDbPreview);
|
||
//acDocManager->lockDocument(curDoc());
|
||
|
||
AcDbBlockTable *pBlockTab=NULL;
|
||
if (m_pDbPreview->getSymbolTable(pBlockTab, AcDb::kForWrite)!=Acad::eOk)
|
||
return;
|
||
|
||
AcDbBlockTableRecord *pMspace = new AcDbBlockTableRecord;
|
||
pMspace->setName(_T("*U"));
|
||
pBlockTab->add(pMspace);
|
||
pBlockTab->close();
|
||
//---------------------------
|
||
AcDbEntity *pEnt = NewObject();
|
||
Dlg2Obj(pEnt);
|
||
ASSERT(pEnt);
|
||
AcDbExtents aext;
|
||
pEnt->getGeomExtents(aext);//得到扩展
|
||
XPoint ptMax,ptMin;
|
||
XPoint ptCenter;
|
||
double length,width;
|
||
ptMax=aext.maxPoint();
|
||
ptMin=aext.minPoint();
|
||
ptCenter.x=(ptMin.x+ptMax.x)/2;
|
||
ptCenter.y=(ptMin.y+ptMax.y)/2;
|
||
ptCenter.z = (ptMax.z + ptMin.z) / 2;
|
||
length=(ptMax.x-ptMin.x)*1.3;
|
||
width=(ptMax.y-ptMin.y)*1.3;
|
||
double height=ptMax.z-ptMin.z;
|
||
//包络范围
|
||
double x,y,z;
|
||
x=ptMax.x-ptMin.x;
|
||
y=ptMax.y-ptMin.y;
|
||
z=ptMax.z-ptMin.z;
|
||
TEntityBase *pTEnt=TEntityBase::Cast(pEnt);
|
||
AcDbVoidPtrArray entSet;//需要画的子对象
|
||
if (pTEnt!=NULL)
|
||
{
|
||
XPushMemVar<BOOL> vTemp(XExplodeStream::m_bFullExplode, TRUE);
|
||
pTEnt->Explode(entSet);
|
||
delete pEnt;
|
||
}
|
||
else
|
||
entSet.append(pEnt);
|
||
|
||
for(long i=0;i<entSet.length();i++)
|
||
{
|
||
AcDbEntity *pEnt = (AcDbEntity*)entSet[i];
|
||
|
||
//modify by xlc on 090916 2010平台线型等属性信息导致预览无法显示
|
||
#if ADS<18
|
||
pMspace->appendAcDbEntity(pEnt);
|
||
pEnt->close();
|
||
#else
|
||
AcDbEntity *pClone=(AcDbEntity*)pEnt->clone();
|
||
delete pEnt;
|
||
pClone->setDatabaseDefaults(m_pDbPreview);
|
||
pMspace->appendAcDbEntity(pClone);
|
||
pClone->recordGraphicsModified();
|
||
pClone->close();
|
||
#endif
|
||
}
|
||
|
||
m_ctrlPreview.clearAll();
|
||
m_ctrlPreview.init(true);
|
||
//AcGePoint3d position(ptCenter.x,ptCenter.y,ptMax.z+1);
|
||
|
||
if (IsExplode3D())
|
||
{
|
||
AcGePoint3d position(ptCenter.x-height/2-1,ptCenter.y-height/2-1,ptMax.z+height/2+1);
|
||
length=sqrt(x*x +y*y);
|
||
if (x<z)
|
||
width=2*z;
|
||
else
|
||
width=(x-z)*0.5;
|
||
m_ctrlPreview.view()->setView(position, ptCenter,AcGeVector3d(0,0,1),length,width);
|
||
//modify by xlc on 090806 R18移植
|
||
#if ADS<18
|
||
m_ctrlPreview.view()->setMode(AcGsView::kGouraudShadedWithWireframe);
|
||
#else
|
||
m_ctrlPreview.view()->setVisualStyle(AcGiVisualStyle::kGouraudWithEdges);
|
||
#endif
|
||
}
|
||
else
|
||
{
|
||
AcGePoint3d position(ptCenter.x,ptCenter.y,ptMax.z+100);
|
||
m_ctrlPreview.view()->setView(position, ptCenter,AcGeVector3d(0.0,1.0,0.0),length,width);
|
||
//modify by xlc on 090806 R18移植
|
||
#if ADS<18
|
||
m_ctrlPreview.view()->setMode(AcGsView::k2DOptimized);
|
||
#else
|
||
m_ctrlPreview.view()->setVisualStyle(AcGiVisualStyle::k2DWireframe);
|
||
#endif
|
||
}
|
||
m_ctrlPreview.view()->add(pMspace,m_ctrlPreview.model());
|
||
pMspace->close();
|
||
m_ctrlPreview.Invalidate();
|
||
|
||
//acDocManager->unlockDocument(curDoc());
|
||
}
|
||
}
|
||
|
||
void CObjPreviewDlg::OnPaint()
|
||
{
|
||
WGroupDlg::OnPaint();
|
||
|
||
if (m_bUseOldImage)
|
||
{
|
||
CPaintDC dc(this); // device context for painting
|
||
CWnd *pImageBox=GetDlgItem(IDC_PREVIEW);
|
||
ASSERT(pImageBox);
|
||
CRect rect;
|
||
pImageBox->GetClientRect(rect);
|
||
CDC *pDC=pImageBox->GetDC();
|
||
m_image.InitDC(pDC, rect,GetAcadBackColor());
|
||
m_image.Redraw();
|
||
m_image.SetDC(NULL);
|
||
pImageBox->ReleaseDC(pDC);
|
||
}
|
||
}
|
||
|
||
void CObjPreviewDlg::OnOK()
|
||
{
|
||
// TODO: Add extra validation here
|
||
if (ValidateData())
|
||
WGroupDlg::OnOK();
|
||
else
|
||
AfxMessageBox(_T("对话窗输入的数据不合适,请检查!"));
|
||
}
|
||
// [8/13/2008 nsh]
|
||
//--------------------------
|
||
BOOL CObjPreviewDlg::DestroyWindow()
|
||
{
|
||
m_ctrlPreview.clearAll();
|
||
return WGroupDlg::DestroyWindow();
|
||
}
|
||
void CObjPreviewDlg::DoDataExchange(CDataExchange *pDx)
|
||
{
|
||
WGroupDlg::DoDataExchange(pDx);
|
||
} |