277 lines
7.6 KiB
C++
277 lines
7.6 KiB
C++
#include "stdafx.h"
|
|
#include "WJYLDlg.h"
|
|
#include "dbobjptr.h"
|
|
#include "EarThwormDef.h"
|
|
|
|
extern HINSTANCE _hdllInstance;
|
|
|
|
IMPLEMENT_DYNAMIC(CWJYLDlg, CDialog)
|
|
|
|
CWJYLDlg::CWJYLDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CWJYLDlg::IDD, pParent)
|
|
{
|
|
}
|
|
|
|
CWJYLDlg::~CWJYLDlg()
|
|
{
|
|
::DeleteFile(m_sDwgFile);
|
|
}
|
|
|
|
void CWJYLDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CWJYLDlg, CDialog)
|
|
ON_WM_SIZING()
|
|
END_MESSAGE_MAP()
|
|
|
|
BOOL CWJYLDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
CRect rc;
|
|
GetClientRect(&rc);
|
|
|
|
CRect rcDlg;
|
|
GetWindowRect(rc);
|
|
m_szDlg.cx = rcDlg.Width();
|
|
m_szDlg.cy = rcDlg.Height();
|
|
|
|
//DWORD dwStyle = WS_CHILD | WS_VISIBLE;
|
|
//m_wndPreview.Create(_T("PreView"),dwStyle,rc,this,IDC_STATIC_FR);
|
|
|
|
// 子类化控件对象
|
|
if (!m_wndPreview.SubclassDlgItem(IDC_STATIC_FR, this))
|
|
{
|
|
return FALSE;
|
|
}
|
|
m_wndPreview.mZooming = true;
|
|
m_wndPreview.mbOrbiting = false;
|
|
|
|
CFont* pFont = GetFont();
|
|
if (pFont != NULL)
|
|
{
|
|
m_wndPreview.SetFont(pFont);
|
|
}
|
|
|
|
CFileFind find;
|
|
if (find.FindFile(m_sDwgFile))
|
|
{
|
|
CString sFileName;
|
|
int nPos = m_sDwgFile.ReverseFind(_T('\\'));
|
|
if (nPos != -1)
|
|
{
|
|
sFileName = m_sDwgFile.Mid(nPos + 1);
|
|
}
|
|
|
|
AcDbDatabase *pDb = new AcDbDatabase(false);
|
|
Acad::ErrorStatus es = pDb->readDwgFile(m_sDwgFile);
|
|
if (es != Acad::eOk)
|
|
{
|
|
AfxMessageBox(CString(_T("读取文件失败 \"")) + m_sDwgFile + _T("\""));
|
|
DELETE_PTR(pDb);
|
|
return FALSE;
|
|
}
|
|
|
|
InitDrawingControl(pDb,ACDB_MODEL_SPACE,false);
|
|
|
|
#ifndef ZWCAD
|
|
#if ARX <= 19
|
|
m_wndPreview.mpView->setMode(AcGsView::kGouraudShaded);
|
|
#else
|
|
AcGiVisualStyle style;
|
|
style.setType(AcGiVisualStyle::kGouraudWithEdges);
|
|
m_wndPreview.mpView->setVisualStyle(style);
|
|
#endif
|
|
#else
|
|
#if defined(R24)
|
|
m_wndPreview.mpView->setMode(AcGsView::kGouraudShaded);
|
|
#else
|
|
AcGiVisualStyle style;
|
|
style.setType(AcGiVisualStyle::kGouraudWithEdges);
|
|
#endif
|
|
#endif
|
|
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
Acad::ErrorStatus CWJYLDlg::InitDrawingControl (AcDbDatabase *pDb, const TCHAR *space,bool b3D/* = true*/)
|
|
{
|
|
// have we got a valid drawing
|
|
if (pDb == NULL)
|
|
{
|
|
pDb = acdbCurDwg();
|
|
}
|
|
|
|
AcDbBlockTableRecordPointer spaceRec(space, pDb, AcDb::kForRead);
|
|
// if ok
|
|
if (spaceRec.openStatus() == Acad::eOk)
|
|
{
|
|
// initialize the preview control
|
|
m_wndPreview.init(_hdllInstance,true);
|
|
// set the view to the *Active* AutoCAD view
|
|
AcGeMatrix3d xform;
|
|
SetViewTo(m_wndPreview.mpView, pDb, xform,b3D);
|
|
// tell the view to display this space
|
|
|
|
//不显示当前模型空间记录的现有实体?
|
|
m_wndPreview.view()->add(spaceRec.object(), m_wndPreview.model());
|
|
m_wndPreview.OnZoomExtents(pDb);
|
|
}
|
|
return spaceRec.openStatus();
|
|
}
|
|
|
|
bool CWJYLDlg::GetActiveViewPortInfo (AcDbDatabase *pDb, ads_real &height, ads_real &width, AcGePoint3d &target, AcGeVector3d &viewDir, ads_real &viewTwist, bool getViewCenter)
|
|
{
|
|
// if not ok
|
|
if (pDb == NULL)
|
|
return false;
|
|
|
|
// get the current working database as a backup
|
|
AcDbDatabase *workingDataBase = acdbHostApplicationServices()->workingDatabase();
|
|
|
|
//将导致渲染错误,文件保存,核查错误提示 LFY 2019-6-3
|
|
// now set the working database
|
|
// acdbHostApplicationServices()->setWorkingDatabase(pDb);
|
|
|
|
// make sure the active view port is uptodate
|
|
acedVports2VportTableRecords();
|
|
|
|
// open the view port records
|
|
AcDbViewportTable *pVTable = NULL;
|
|
Acad::ErrorStatus es = pDb->getViewportTable (pVTable, AcDb::kForRead);
|
|
// if we opened them ok
|
|
if (es == Acad::eOk)
|
|
{
|
|
AcDbViewportTableRecord *pViewPortRec = NULL;
|
|
es = pVTable->getAt (_T("*Active"), pViewPortRec, AcDb::kForRead);
|
|
if (es == Acad::eOk)
|
|
{
|
|
// get the height of the view
|
|
height = pViewPortRec->height ();
|
|
// get the width
|
|
width = pViewPortRec->width ();
|
|
// if the user wants the center of the viewport used
|
|
if (getViewCenter == true)
|
|
{
|
|
struct resbuf rb;
|
|
memset (&rb, 0, sizeof (struct resbuf));
|
|
// get the system var VIEWCTR
|
|
acedGetVar (_T("VIEWCTR"), &rb);
|
|
// set that as the target
|
|
target = AcGePoint3d (rb.resval.rpoint[X], rb.resval.rpoint[Y], rb.resval.rpoint[Z]);
|
|
}
|
|
// we want the viewports camera target setting
|
|
else
|
|
{
|
|
// get the target of the view
|
|
target = pViewPortRec->target ();
|
|
}
|
|
|
|
// get the view direction
|
|
viewDir = pViewPortRec->viewDirection ();
|
|
// get the view twist of the viewport
|
|
viewTwist = pViewPortRec->viewTwist ();
|
|
}
|
|
// close after use
|
|
pVTable->close ();
|
|
pViewPortRec->close();
|
|
}
|
|
|
|
// now restore the original working database
|
|
//将导致渲染错误,文件保存,核查错误提示 LFY 2019-6-3
|
|
//acdbHostApplicationServices()->setWorkingDatabase(workingDataBase);
|
|
|
|
return (true);
|
|
}
|
|
|
|
void CWJYLDlg::SetViewTo(AcGsView *pView, AcDbDatabase *pDb, AcGeMatrix3d& viewMat,bool b3D)
|
|
{
|
|
// we are going to set the view to the current view of the drawing
|
|
// The overall approach is to calculate the extents of the database in the coordinate system of the view
|
|
// Calculate the extents in WCS
|
|
// if exmax,exmin too larg or small , view show error!!!!
|
|
AcGePoint3d extMax(500,500,500);// = pDb->extmax();
|
|
AcGePoint3d extMin(-500,-500,-500);// = pDb->extmin();
|
|
|
|
// get the view port information - see parameter list
|
|
ads_real height = 0.0, width = 0.0, viewTwist = 0.0;
|
|
AcGePoint3d targetView;
|
|
AcGeVector3d viewDir;
|
|
GetActiveViewPortInfo (pDb,height, width, targetView, viewDir, viewTwist, true);
|
|
|
|
// we are only interested in the directions of the view, not the sizes, so we normalise.
|
|
// set to -1,-1,1
|
|
if (b3D)
|
|
{
|
|
viewDir.set(-1,-1,1);
|
|
}
|
|
viewDir = viewDir.normal();
|
|
|
|
//**********************************************
|
|
// Our view coordinate space consists of z direction
|
|
// get a perp vector off the z direction
|
|
// Make sure its normalised
|
|
AcGeVector3d viewXDir = viewDir.perpVector ().normal();
|
|
// correct the x angle by applying the twist
|
|
viewXDir = viewXDir.rotateBy (viewTwist, -viewDir);
|
|
// now we can work out y, this is of course perp to the x and z directions. No need to normalise this,
|
|
// as we know that x and z are of unit length, and perpendicular, so their cross product must be on unit length
|
|
AcGeVector3d viewYDir = viewDir.crossProduct (viewXDir);
|
|
|
|
// find a nice point around which to transform the view. We'll use the same point as the center of the view.
|
|
AcGePoint3d boxCenter = extMin + 0.5 * ( extMax - extMin );
|
|
|
|
//**********************************************
|
|
// create a transform from WCS to View space
|
|
// this represents the transformation from WCS to the view space. (Actually not quite since
|
|
// we are keeping the fixed point as the center of the box for convenience )
|
|
viewMat = AcGeMatrix3d::alignCoordSys (boxCenter, AcGeVector3d::kXAxis, AcGeVector3d::kYAxis, AcGeVector3d::kZAxis,
|
|
boxCenter, viewXDir, viewYDir, viewDir).inverse();
|
|
|
|
AcDbExtents wcsExtents(extMin, extMax);
|
|
// now we have the view Extents
|
|
AcDbExtents viewExtents = wcsExtents;
|
|
// transforms the extents in WCS->view space
|
|
viewExtents.transformBy (viewMat);
|
|
|
|
//**********************************************
|
|
// get the extents of the AutoCAD view
|
|
double xMax = fabs(viewExtents.maxPoint ().x - viewExtents.minPoint ().x);
|
|
double yMax = fabs(viewExtents.maxPoint ().y - viewExtents.minPoint ().y);
|
|
|
|
//**********************************************
|
|
// setup the view
|
|
AcGePoint3d eye = boxCenter + viewDir;
|
|
|
|
// upvector
|
|
pView->setView(eye, boxCenter, viewYDir, xMax, yMax);
|
|
// update the gsView
|
|
if (pView != NULL)
|
|
{
|
|
pView->invalidate();
|
|
pView->update();
|
|
}
|
|
}
|
|
|
|
void CWJYLDlg::OnSizing(UINT fwSide, LPRECT pRect)
|
|
{
|
|
int nWidth = pRect->right - pRect->left;
|
|
int nHeight= pRect->bottom- pRect->top;
|
|
|
|
if(nWidth > m_szDlg.cx)
|
|
{
|
|
pRect->right = pRect->left + m_szDlg.cx;
|
|
}
|
|
|
|
if(nHeight > m_szDlg.cy)
|
|
{
|
|
pRect->bottom = pRect->top + m_szDlg.cy;
|
|
}
|
|
|
|
CDialog::OnSizing(fwSide, pRect);
|
|
}
|