1410 lines
42 KiB
C++
1410 lines
42 KiB
C++
#include "stdafx.h"
|
|
#include "resource.h"
|
|
#include "cameradlg.h"
|
|
#include "setcameradlg.h"
|
|
#include "pathvideodlg.h" //已经有 #include "writeavi.h"
|
|
#include "linevideodlg.h" //已经有 #include "writeavi.h"
|
|
#if ADS<17
|
|
#include "avlib.h" //render api
|
|
#endif
|
|
#include "acestext.h"
|
|
#if ADS<17
|
|
#include "TgAs.h"
|
|
#include "materialrecord.h"
|
|
#endif
|
|
|
|
GEOAPI BOOL arxWBlock(PickSet &ss, const TCHAR* szFileName, XPoint ptIns);
|
|
extern TARCH_IMPEXP double g_nWalkDistStep, g_nWalkAngleStep;
|
|
extern TARCH_IMPEXP XStringList g_lstFileRemove;
|
|
// extern TARCH_IMPEXP void MdiOpenDwgFile(const TCHAR *pszFile, const TCHAR *pszInitCmd);
|
|
static int g_nKey = 0;
|
|
static void InitHook(BOOL bTrue);
|
|
|
|
// 拖曳显示点
|
|
class TCameraEdJig : public AcEdJig
|
|
{
|
|
public:
|
|
TCameraEdJig(TDbCamera *pCam, const TCHAR *pszPrompt, const TCHAR *pszKeyword=NULL);
|
|
void doIt();
|
|
virtual DragStatus sampler();
|
|
virtual Adesk::Boolean update();
|
|
virtual AcDbEntity* entity() const;
|
|
|
|
int GetRetCode(int *kwordId=NULL) const;
|
|
int m_nRetCode; //返回码
|
|
const TCHAR *m_pszPrompt; //提示信息
|
|
const TCHAR *m_pszKeyword; //关键字
|
|
TDbCamera *m_pDrawEnt; //临时实体
|
|
|
|
XPoint m_ptTo;
|
|
};
|
|
|
|
|
|
// 转换成ADS代码
|
|
int TCameraEdJig::GetRetCode(int *kwordId) const
|
|
{
|
|
int ret = m_nRetCode;
|
|
if (ret == AcEdJig::kCancel)
|
|
ret = RTCAN;
|
|
else if (ret == AcEdJig::kNull)
|
|
ret = RTNONE;
|
|
else if (ret <= 0)
|
|
ret = RTNORM;
|
|
else {
|
|
if (kwordId) *kwordId = ret;
|
|
ret = RTKWORD;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
|
|
TCameraEdJig::TCameraEdJig(TDbCamera *pCam, const TCHAR *pszPrompt, const TCHAR *pszKeyword)
|
|
:m_pDrawEnt(pCam), m_pszPrompt(pszPrompt), m_pszKeyword(pszKeyword), m_nRetCode(0)
|
|
{
|
|
m_ptTo=pCam->GetTarget();
|
|
}
|
|
|
|
|
|
// 开始执行拖动
|
|
void TCameraEdJig::doIt()
|
|
{
|
|
setDispPrompt(m_pszPrompt);
|
|
try {
|
|
m_nRetCode = drag();
|
|
} catch(...) {
|
|
m_nRetCode=AcEdJig::kCancel;
|
|
}
|
|
}
|
|
|
|
// 反馈
|
|
AcEdJig::DragStatus TCameraEdJig::sampler()
|
|
{
|
|
DragStatus stat;
|
|
|
|
setUserInputControls((UserInputControls)
|
|
(AcEdJig::kAccept3dCoordinates));
|
|
|
|
if (m_pszKeyword) setKeywordList(m_pszKeyword);
|
|
XPoint ptTemp;
|
|
XPoint ptCam;
|
|
ptCam=(AcGePoint3d &)m_pDrawEnt->GetCamera();
|
|
stat = acquirePoint(ptTemp, ptCam);
|
|
if (stat == AcEdJig::kNormal) {
|
|
ptCam=Wcs2Ucs(ptCam);
|
|
ptTemp=Wcs2Ucs(ptTemp);
|
|
if (ptTemp.Distance2d(Wcs2Ucs(m_pDrawEnt->GetTarget()))>_DIST_SNAP) {
|
|
ptTemp.z = ptCam.z;
|
|
m_ptTo=Ucs2Wcs(ptTemp);
|
|
} else
|
|
return AcEdJig::kNoChange;
|
|
}
|
|
|
|
return stat;
|
|
}
|
|
|
|
// 更新实体数据
|
|
Adesk::Boolean TCameraEdJig::update()
|
|
{
|
|
m_pDrawEnt->SetTarget(m_ptTo);
|
|
return Adesk::kTrue;
|
|
}
|
|
|
|
AcDbEntity* TCameraEdJig::entity() const
|
|
{
|
|
return m_pDrawEnt;
|
|
}
|
|
|
|
|
|
|
|
// Command:编辑相机
|
|
int EditCamera(AcDbObjectId id)
|
|
{
|
|
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbCamera, pCam);
|
|
if (!pCam)
|
|
return RTERROR;
|
|
while(1) {
|
|
const TCHAR *szPrompt1=_T("\n选择 [对话框(D)/焦距(N)/标高(E)/方位角(G)/俯仰角(H)/拍照(T)/透视(P)/联动(A)/前裁剪(F)/后裁剪(B)]<退出>:");
|
|
XString sKeyword;
|
|
int nRet=0;
|
|
INITGET_BEG(0, _T("D N P E G H T A F B L"));
|
|
nRet=ads_getkword(szPrompt1, sKeyword);
|
|
INITGET_END();
|
|
|
|
if (nRet!=RTNORM)
|
|
break;
|
|
TCHAR cKey=sKeyword[0];
|
|
if (cKey==_T('T')) {
|
|
if (ads_getpoint(NULL, _T("\n点取观察视口<当前视口>:"), XPoint())==RTCAN)
|
|
break;
|
|
int nVp=0;
|
|
VERIFY(xg_getvar(_T("CVPORT"), &nVp)==RTNORM);
|
|
if (pCam->upgradeOpen()!=Acad::eOk)
|
|
return RTERROR;
|
|
pCam->SetAssociateViewport(nVp);
|
|
pCam->downgradeOpen();
|
|
if (pCam->IsActive())
|
|
pCam->TakePhoto(FALSE);
|
|
} else if (cKey==_T('D')) {
|
|
CAcModuleResourceOverride vTemp;
|
|
CCameraDlg dlg(acedGetAcadFrame());
|
|
dlg.Obj2Dlg(pCam);
|
|
if (dlg.DoModal() == IDOK) {
|
|
if (pCam->upgradeOpen()!=Acad::eOk)
|
|
return RTERROR;
|
|
dlg.Dlg2Obj(pCam);
|
|
pCam->downgradeOpen();
|
|
if (pCam->IsActive()) {
|
|
pCam->draw();
|
|
pCam->TakePhoto(FALSE);
|
|
}
|
|
}
|
|
} else if (cKey==_T('N')) {
|
|
double nLens=pCam->GetLens();
|
|
nRet=GetReal(_T("\n焦距"), nLens);
|
|
if (nRet==RTCAN)
|
|
break;
|
|
if (nRet==RTNORM) {
|
|
if (pCam->upgradeOpen()!=Acad::eOk)
|
|
return RTERROR;
|
|
pCam->SetLens(nLens);
|
|
pCam->downgradeOpen();
|
|
if (pCam->IsActive())
|
|
pCam->TakePhoto(FALSE);
|
|
}
|
|
} else if (cKey==_T('E')) {
|
|
double h=pCam->GetElevation(TRUE);
|
|
nRet=GetReal(_T("\n相机高度"), h);
|
|
if (nRet==RTCAN)
|
|
break;
|
|
double hT=pCam->GetElevation(FALSE);
|
|
int nRet1=GetReal(_T("\n目标高度"), hT);
|
|
if (nRet1==RTCAN)
|
|
break;
|
|
if (nRet==RTNORM || nRet1==RTNORM) {
|
|
if (pCam->upgradeOpen()!=Acad::eOk)
|
|
return RTERROR;
|
|
if (nRet==RTNORM)
|
|
pCam->SetElevation(h, TRUE);
|
|
if (nRet1==RTNORM)
|
|
pCam->SetElevation(hT, FALSE);
|
|
pCam->downgradeOpen();
|
|
if (pCam->IsActive()) {
|
|
pCam->draw();
|
|
pCam->TakePhoto(FALSE);
|
|
}
|
|
}
|
|
} else if (cKey==_T('G')) {
|
|
double nLong=pCam->GetLongitude();
|
|
XVector3D vt(cos(nLong), sin(nLong));
|
|
vt = Wcs2Ucs(vt, TRUE);
|
|
adsout << _T("\n方位角(0 ~ 360)<") << Angle2Str(ads_angle(XPoint(), vt)*180/PI) << _T(">:");
|
|
XPoint ptBase=Wcs2Ucs(pCam->GetCamera());
|
|
nRet=ads_getangle(ptBase, _T(""), &nLong);
|
|
if (nRet==RTCAN)
|
|
break;
|
|
if (nRet==RTNORM) {
|
|
XVector3D vtNew(cos(nLong), sin(nLong));
|
|
vtNew = Ucs2Wcs(vtNew, TRUE);
|
|
nLong = ads_angle(XPoint(), vtNew);
|
|
if (pCam->upgradeOpen()!=Acad::eOk)
|
|
return RTERROR;
|
|
pCam->SetLongitude(nLong);
|
|
pCam->downgradeOpen();
|
|
if (pCam->IsActive()) {
|
|
pCam->draw();
|
|
pCam->TakePhoto(FALSE);
|
|
}
|
|
}
|
|
} else if (cKey==_T('H')) {
|
|
double h=pCam->GetLatitude()/PI*180;
|
|
LAB_ERR_LATITUDE:
|
|
nRet=GetReal(_T("\n俯仰角(-90 ~ 90)"), h);
|
|
if (nRet==RTCAN)
|
|
break;
|
|
if (nRet==RTNORM) {
|
|
if (h>90.000001 || h<-90.000001) {
|
|
adsout << _T("\n请正确输入俯仰角!");
|
|
goto LAB_ERR_LATITUDE;
|
|
}
|
|
if (pCam->upgradeOpen()!=Acad::eOk)
|
|
return RTERROR;
|
|
pCam->SetLatitude(h*PI/180);
|
|
pCam->downgradeOpen();
|
|
if (pCam->IsActive()) {
|
|
pCam->draw();
|
|
pCam->TakePhoto(FALSE);
|
|
}
|
|
}
|
|
} else if (cKey==_T('A')) {
|
|
BOOL bActive=!pCam->IsActive();
|
|
if (bActive)
|
|
adsout << _T("\n相机当前处于联动状态!");
|
|
else
|
|
adsout << _T("\n相机当前处于不联动状态!");
|
|
|
|
if (pCam->upgradeOpen()!=Acad::eOk)
|
|
return RTERROR;
|
|
pCam->SetActive(bActive);
|
|
pCam->downgradeOpen();
|
|
} else if (cKey==_T('P')) {
|
|
BOOL bTrue=!pCam->IsPerspective();
|
|
if (bTrue)
|
|
adsout << _T("\n相机当前处于透视状态!");
|
|
else
|
|
adsout << _T("\n相机当前处于平行投影状态!");
|
|
|
|
if (pCam->upgradeOpen()!=Acad::eOk)
|
|
return RTERROR;
|
|
pCam->SetPerspective(bTrue);
|
|
pCam->downgradeOpen();
|
|
if (pCam->IsActive())
|
|
pCam->TakePhoto(FALSE);
|
|
} else if (cKey==_T('F')) {
|
|
int bActive=pCam->IsFrontClipOn()? Q_YES : Q_NO;
|
|
bActive=YesNoQuestion(_T("\n是否开启前裁剪平面"), bActive);
|
|
int nChDist=RTNORM;
|
|
XPoint ptClip;
|
|
if (bActive) {
|
|
XPoint ptCam=Wcs2Ucs(pCam->GetCamera());
|
|
nChDist=ads_getpoint(ptCam, _T("\n前裁剪位置<锁定在相机位置>: "), ptClip);
|
|
}
|
|
if (nChDist!=RTCAN) {
|
|
if (pCam->upgradeOpen()!=Acad::eOk)
|
|
return RTERROR;
|
|
pCam->SetFrontClipOn(bActive);
|
|
if (bActive) {
|
|
pCam->SetFrontClipAtEye(nChDist==RTNONE);
|
|
if (nChDist==RTNORM)
|
|
pCam->SetFrontClipPoint(ptClip);
|
|
}
|
|
pCam->downgradeOpen();
|
|
if (pCam->IsActive())
|
|
pCam->TakePhoto(FALSE);
|
|
}
|
|
} else if (cKey==_T('B')) {
|
|
int bActive=pCam->IsBackClipOn()? Q_YES : Q_NO;
|
|
bActive=YesNoQuestion(_T("\n是否开启后裁剪平面"), bActive);
|
|
int nChDist=RTNORM;
|
|
XPoint ptClip;
|
|
if (bActive) {
|
|
XPoint ptTar=Wcs2Ucs(pCam->GetTarget());
|
|
nChDist=XGetPoint(ptTar, _T("\n后裁剪位置"), ptClip);
|
|
}
|
|
if (nChDist!=RTCAN && nChDist!=RTNONE) {
|
|
if (pCam->upgradeOpen()!=Acad::eOk)
|
|
return RTERROR;
|
|
pCam->SetBackClipOn(bActive);
|
|
if (bActive)
|
|
pCam->SetBackClipPoint(ptClip);
|
|
pCam->downgradeOpen();
|
|
if (pCam->IsActive())
|
|
pCam->TakePhoto(FALSE);
|
|
}
|
|
} else if (sKeyword[0]==_T('L')) {
|
|
pCam->list();
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
TDbCamera::ResetIdArray();
|
|
return RTNORM;
|
|
}
|
|
|
|
|
|
|
|
|
|
// Command: 新建相机
|
|
void Camera()
|
|
{
|
|
InitLayer(LAY_VIEW);
|
|
static double nLens=26, nElev=1600;
|
|
static BOOL bActive=TRUE, bPerspective=TRUE;
|
|
|
|
XPoint ptCamera;
|
|
if (XGetPoint(NULL, _T("\n相机位置"), ptCamera)==RTNORM) {
|
|
ptCamera=Ucs2Wcs(ptCamera);
|
|
TDbCamera *pCam= new TDbCamera;
|
|
XVector3D vtNormal=Ucs2Wcs(XVector3D(0,0,1));
|
|
BOOL bWcs=(vtNormal.AsAcGeVector3d() == AcGeVector3d(0,0,1));
|
|
if (bWcs)
|
|
ptCamera.z=nElev;
|
|
|
|
pCam->SetCamera(ptCamera);
|
|
pCam->SetTarget(ptCamera);
|
|
pCam->SetLens(nLens);
|
|
pCam->SetActive(bActive);
|
|
pCam->SetPerspective(bPerspective);
|
|
if (!pCam->SetDefaultBlock()) {
|
|
adsout << _T("\n不能设置缺省的相机图块!");
|
|
delete pCam;
|
|
return;
|
|
}
|
|
|
|
TCameraEdJig jig(pCam, _T("\n输入目标位置<退出>: "), _T("D"));
|
|
LAB_GET_TARGET:
|
|
INITGET_BEG(-1, _T("D"));
|
|
jig.doIt();
|
|
INITGET_END();
|
|
int nKeyword;
|
|
int nRet=jig.GetRetCode(&nKeyword);
|
|
if (nRet==RTKWORD) {
|
|
CAcModuleResourceOverride vTemp;
|
|
CCameraDlg dlg(acedGetAcadFrame());
|
|
dlg.Obj2Dlg(pCam);
|
|
dlg.m_bEdit=FALSE;
|
|
if (dlg.DoModal() == IDOK)
|
|
dlg.Dlg2Obj(pCam);
|
|
goto LAB_GET_TARGET;
|
|
} else if (nRet!=RTNORM) {
|
|
delete pCam;
|
|
return;
|
|
}
|
|
|
|
nLens=pCam->GetLens();
|
|
if (bWcs)
|
|
nElev=pCam->GetElevation(TRUE);
|
|
bActive=pCam->IsActive();
|
|
bPerspective=pCam->IsActive();
|
|
|
|
if (ads_getpoint(NULL, _T("\n点取观察视口<当前视口>:"), XPoint())==RTCAN) {
|
|
delete pCam;
|
|
return;
|
|
}
|
|
int nVp=0;
|
|
VERIFY(xg_getvar(_T("CVPORT"), &nVp)==RTNORM);
|
|
pCam->SetAssociateViewport(nVp);
|
|
AcDbObjectId id=pCam->AddToMSpace(Adesk::kTrue);
|
|
if (!!id) {
|
|
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbCamera, pCam1);
|
|
pCam1->draw();
|
|
pCam1->TakePhoto(FALSE);
|
|
OPENOBJ_END();
|
|
}
|
|
TDbCamera::ResetIdArray();
|
|
}
|
|
}
|
|
|
|
|
|
// Command: 新建相机定位器
|
|
void CamLocator()
|
|
{
|
|
InitLayer(LAY_VIEW);
|
|
|
|
XPoint ptLeft, ptRight;
|
|
if (XGetPoint(NULL, _T("\n左位置"), ptLeft)==RTNORM &&
|
|
ads_getpoint(ptLeft, _T("\n右位置<退出>:"), ptRight)==RTNORM) {
|
|
ptLeft=Ucs2Wcs(ptLeft);
|
|
ptRight=Ucs2Wcs(ptRight);
|
|
XPoint ptTarget, ptCamera;
|
|
Midpoint(ptLeft, ptRight, ptTarget);
|
|
ptTarget.z=0;
|
|
double nAng=ads_angle(ptLeft, ptRight);
|
|
ads_polar(ptTarget, nAng-PI/2, 500.0, ptCamera);
|
|
|
|
TDbCamera *pCam= new TDbCamera;
|
|
pCam->SetCamera(ptCamera);
|
|
pCam->SetTarget(ptTarget);
|
|
pCam->SetLocator(TRUE);
|
|
pCam->SetActive(TRUE);
|
|
pCam->SetDefaultBlock();
|
|
|
|
if (ads_getpoint(NULL, _T("\n点取观察视口<当前视口>:"), XPoint())==RTCAN) {
|
|
delete pCam;
|
|
return;
|
|
}
|
|
int nVp=0;
|
|
VERIFY(xg_getvar(_T("CVPORT"), &nVp)==RTNORM);
|
|
pCam->SetAssociateViewport(nVp);
|
|
AcDbObjectId id=pCam->AddToMSpace(Adesk::kTrue);
|
|
if (!!id) {
|
|
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbCamera, pCam1);
|
|
pCam1->draw();
|
|
pCam1->TakePhoto(FALSE);
|
|
OPENOBJ_END();
|
|
}
|
|
TDbCamera::ResetIdArray();
|
|
}
|
|
}
|
|
#if ADS<17
|
|
void WalkVideo()
|
|
{
|
|
XPushMemVar<BOOL> vMem(g_bMakingVideo, TRUE);
|
|
CAcModuleResourceOverride vTemp;
|
|
CLineVideoDlg dlg;
|
|
if (dlg.m_bInit)
|
|
dlg.DoModal();
|
|
}
|
|
|
|
void PathVideo()
|
|
{
|
|
XPushMemVar<BOOL> vMem(g_bMakingVideo, TRUE);
|
|
CAcModuleResourceOverride vTemp;
|
|
CPathVideoDlg dlg;
|
|
if (dlg.m_bInit)
|
|
dlg.DoModal();
|
|
}
|
|
#endif/* ADS<17*/
|
|
|
|
static BOOL MyHook(MSG* msg)
|
|
{
|
|
BOOL bRet=FALSE;
|
|
|
|
switch(msg->message) {
|
|
case WM_KEYDOWN: {
|
|
|
|
if (msg->wParam == VK_LEFT){
|
|
g_nKey = VK_LEFT;
|
|
acedPostCommand(_T(" "));
|
|
bRet = TRUE;
|
|
}
|
|
else if (msg->wParam == VK_RIGHT){
|
|
g_nKey = VK_RIGHT;
|
|
acedPostCommand(_T(" "));
|
|
bRet = TRUE;
|
|
}
|
|
else if (msg->wParam == VK_UP){
|
|
g_nKey = VK_UP;
|
|
acedPostCommand(_T(" "));
|
|
bRet = TRUE;
|
|
}
|
|
else if (msg->wParam == VK_DOWN){
|
|
g_nKey = VK_DOWN;
|
|
acedPostCommand(_T(" "));
|
|
bRet = TRUE;
|
|
}
|
|
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return bRet;
|
|
}
|
|
|
|
CRect GetVPRect(int cvport);
|
|
void GetRectBmpFromBmp( CWnd *pWnd ,CRect rectClient, CBitmap &bitmap);
|
|
|
|
|
|
void VRCamera()
|
|
{
|
|
extern TARCH_IMPEXP int g_bDisableHook;
|
|
XPushMemVar<BOOL> vHook(g_bDisableHook, TRUE);
|
|
|
|
if (g_nArchType==4) {//学习版
|
|
adsout << _T("\n学习版不支持,欢迎购买正式版!");
|
|
return;
|
|
}
|
|
SHORT nStateCtrl, nStateShift;
|
|
double nStepLen = g_nWalkDistStep;
|
|
double nLatitude = g_nWalkAngleStep*180.0/PI;
|
|
double nLongitude = g_nWalkAngleStep*180.0/PI;
|
|
double nStepHeight = g_nWalkDistStep;
|
|
//录像
|
|
XPushMemVar<BOOL> vMem(g_bMakingVideo, TRUE);
|
|
|
|
CBitmap bitmap;
|
|
CAVIFile fileAvi;
|
|
BOOL m_bHasInitAvi = FALSE;
|
|
|
|
|
|
Entity id;
|
|
RBList rbMask(RTDXF0, _T("TCH_CAMERA"), NULL);
|
|
PickSet ss(SS_FREE);
|
|
if (ss.Get(_T("X"), NULL, NULL, rbMask)!=RTNORM) {
|
|
adsout << _T("\n请用相机透视建立一相机!");
|
|
return;
|
|
}
|
|
if (ss.Length()==1L)
|
|
id=ss[0L];
|
|
else if (SelectEntity(_T("\n请选择上华照相机<退出>:"), id, rbMask)!=RTNORM)
|
|
return;
|
|
|
|
XString sKeyword;
|
|
int nKey, ret;
|
|
InitHook(TRUE);
|
|
|
|
//dlg
|
|
CSetCameraDlg SetCameraDlg(acedGetAcadFrame());
|
|
{
|
|
CAcModuleResourceOverride vTemp;
|
|
SetCameraDlg.Create(IDD_SETCAMERA, acedGetAcadFrame());
|
|
}
|
|
SetCameraDlg.m_entity = id;
|
|
SetCameraDlg.m_nLatitude = AS_INT(nLatitude);
|
|
SetCameraDlg.m_nLongitude = AS_INT(nLongitude);
|
|
SetCameraDlg.m_nStepHeight = AS_INT(nStepHeight);
|
|
SetCameraDlg.m_nStepLen = AS_INT(nStepLen);
|
|
|
|
SetCameraDlg.UpdateData(FALSE);
|
|
|
|
SetCameraDlg.ShowWindow(SW_SHOW);
|
|
acedGetAcadDwgView()->SetFocus();
|
|
|
|
int cvport=0;
|
|
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbCamera, pCam);
|
|
if (pCam) {
|
|
CString str;
|
|
str.Format(_T("方位角:%.2f"), pCam->GetLongitude() * 180.0 / PI);
|
|
SetCameraDlg.m_csLongitude = str;
|
|
str.Format(_T("俯仰角:%.2f"), pCam->GetLatitude() * 180.0 / PI);
|
|
SetCameraDlg.m_csLatitude= str;
|
|
SetCameraDlg.UpdateData(FALSE);
|
|
cvport = pCam->GetAssociateViewport();
|
|
//设定当前视口为照相机绑定视口,目的是指定摄像视口
|
|
//VERIFY(xg_setvar(_T("CVPORT"), cvport)==RTNORM);
|
|
}
|
|
OPENOBJ_END();
|
|
CRect rectVP = GetVPRect(cvport);
|
|
|
|
Lab:
|
|
ret = ads_getint(_T(""), &nKey);
|
|
if (ret == RTNONE && g_nKey == 0) {
|
|
goto Lab;
|
|
}
|
|
if (ret == RTCAN) {
|
|
InitHook(FALSE);
|
|
if (::IsWindow(SetCameraDlg.m_hWnd))
|
|
SetCameraDlg.DestroyWindow();
|
|
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbCamera, pCam);
|
|
if (pCam) {
|
|
pCam->draw();
|
|
pCam->TakePhoto(FALSE); //重新生成
|
|
}
|
|
OPENOBJ_END();
|
|
TDbCamera::ResetIdArray();
|
|
return;
|
|
}
|
|
nStateShift = GetKeyState(VK_SHIFT);
|
|
BOOL bShift = (nStateShift&256)!=0;
|
|
nStateCtrl = GetKeyState(VK_CONTROL);
|
|
BOOL bCtrl = (nStateCtrl&256)!=0;
|
|
|
|
if (ret == RTNONE && g_nKey != 0) {
|
|
SetCameraDlg.UpdateData(TRUE);
|
|
nLatitude = SetCameraDlg.m_nLatitude;
|
|
nLongitude = SetCameraDlg.m_nLongitude;
|
|
nStepHeight = SetCameraDlg.m_nStepHeight;
|
|
nStepLen = SetCameraDlg.m_nStepLen;
|
|
|
|
OPENOBJ_BEGIN(id, AcDb::kForWrite, TDbCamera, pCam);
|
|
if (!pCam){
|
|
InitHook(FALSE);
|
|
SetCameraDlg.DestroyWindow();
|
|
return;
|
|
} else if (g_nKey == VK_UP){
|
|
if (!bShift && !bCtrl){
|
|
AcGeMatrix3d mat;
|
|
double longitude = pCam->GetLongitude();
|
|
mat.setToTranslation(AcGeVector3d(nStepLen*cos(longitude), nStepLen*sin(longitude), 0));
|
|
pCam->transformBy(mat);
|
|
}
|
|
else if (bCtrl){
|
|
pCam->SetElevation(pCam->GetElevation(TRUE) + nStepHeight, TRUE);
|
|
pCam->SetElevation(pCam->GetElevation(FALSE) + nStepHeight, FALSE);
|
|
}
|
|
else {
|
|
double n = pCam->GetLatitude() * 180.0 / PI;
|
|
pCam->SetLatitude((n + nLatitude) * PI / 180.0);
|
|
}
|
|
} else if (g_nKey == VK_DOWN) {
|
|
|
|
if (!bShift && !bCtrl){
|
|
AcGeMatrix3d mat;
|
|
double longitude = pCam->GetLongitude();
|
|
mat.setToTranslation(AcGeVector3d(-nStepLen*cos(longitude), -nStepLen*sin(longitude), 0));
|
|
pCam->transformBy(mat);
|
|
}
|
|
else if (bCtrl){
|
|
pCam->SetElevation(pCam->GetElevation(TRUE) - nStepHeight, TRUE);
|
|
pCam->SetElevation(pCam->GetElevation(FALSE) - nStepHeight, FALSE);
|
|
}
|
|
else {
|
|
double n = pCam->GetLatitude() * 180.0 / PI;
|
|
pCam->SetLatitude((n - nLatitude) * PI / 180.0);
|
|
}
|
|
} else if (g_nKey == VK_LEFT) {
|
|
if (!bShift && !bCtrl){
|
|
AcGeMatrix3d mat;
|
|
double longitude = pCam->GetLongitude();
|
|
mat.setToTranslation(AcGeVector3d(nStepLen*cos(longitude + PI/2), nStepLen*sin(longitude + PI/2), 0));
|
|
pCam->transformBy(mat);
|
|
}
|
|
else if (bCtrl){
|
|
pCam->SetLongitude(pCam->GetLongitude() + PI / 2);
|
|
}
|
|
else{
|
|
double n = pCam->GetLongitude() * 180.0 / PI;
|
|
pCam->SetLongitude((n + nLongitude) * PI / 180.0);
|
|
}
|
|
} else if (g_nKey == VK_RIGHT) {
|
|
if (!bShift && !bCtrl){
|
|
AcGeMatrix3d mat;
|
|
double longitude = pCam->GetLongitude();
|
|
mat.setToTranslation(AcGeVector3d(nStepLen*cos(longitude - PI/2), nStepLen*sin(longitude - PI/2), 0));
|
|
pCam->transformBy(mat);
|
|
}
|
|
else if (bCtrl){
|
|
pCam->SetLongitude(pCam->GetLongitude() - PI / 2);
|
|
}
|
|
else{
|
|
double n = pCam->GetLongitude() * 180.0 / PI;
|
|
pCam->SetLongitude((n - nLongitude) * PI / 180.0);
|
|
}
|
|
}
|
|
if (pCam->downgradeOpen()==Acad::eOk) {
|
|
if (SetCameraDlg.m_bStart && !m_bHasInitAvi){
|
|
fileAvi.Init(SetCameraDlg.m_csAviFile,
|
|
rectVP.Width(), rectVP.Height(),
|
|
SetCameraDlg.m_nRate);
|
|
m_bHasInitAvi = TRUE;
|
|
}
|
|
|
|
if (SetCameraDlg.m_bStart){
|
|
GetRectBmpFromBmp(acedGetAcadDwgView(), rectVP, bitmap);
|
|
fileAvi.AddFrame(bitmap);
|
|
}
|
|
CString str;
|
|
str.Format(_T("方位角:%.2f"), pCam->GetLongitude() * 180.0 / PI);
|
|
SetCameraDlg.m_csLongitude = str;
|
|
str.Format(_T("俯仰角:%.2f"), pCam->GetLatitude() * 180.0 / PI);
|
|
SetCameraDlg.m_csLatitude= str;
|
|
|
|
SetCameraDlg.UpdateData(FALSE);
|
|
pCam->draw();
|
|
pCam->TakePhoto(TRUE);
|
|
pCam->upgradeOpen();
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
}
|
|
g_nKey = 0;
|
|
ads_printf(_T("%c"),8);
|
|
goto Lab;
|
|
InitHook(FALSE);
|
|
SetCameraDlg.DestroyWindow();
|
|
}
|
|
|
|
void InitHook(BOOL bTrue)
|
|
{
|
|
static BOOL bMsgHook=FALSE;
|
|
if (bTrue) {
|
|
if (!bMsgHook)
|
|
bMsgHook=acedRegisterFilterWinMsg(MyHook);
|
|
} else {
|
|
if (bMsgHook) {
|
|
acedRemoveFilterWinMsg(MyHook);
|
|
bMsgHook=FALSE;
|
|
g_nKey = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
CPoint Lcs2Mcs(XPoint point, BOOL bVector=FALSE)
|
|
{
|
|
CRect rect;
|
|
CPoint pt;
|
|
acedGetAcadDwgView()->GetClientRect(&rect);
|
|
|
|
pt.x = AS_INT(point.x*rect.Width());
|
|
if (!bVector) {
|
|
pt.y = rect.bottom - AS_INT(point.y*rect.Height());
|
|
} else {
|
|
pt.y = - AS_INT(point.y*rect.Height());
|
|
}
|
|
|
|
return pt;
|
|
}
|
|
|
|
void GetRectBmpFromBmp( CWnd *pWnd ,CRect rectClient, CBitmap &bitmap)
|
|
{
|
|
CClientDC dc(pWnd);
|
|
CDC memDC;
|
|
CRect rect;
|
|
//CBitmap bitmap, bmp;
|
|
memDC.CreateCompatibleDC(&dc);
|
|
pWnd->GetWindowRect(rect);
|
|
bitmap.CreateCompatibleBitmap(&dc, rectClient.Width(), rectClient.Height());
|
|
|
|
CBitmap* pOldBitmap = memDC.SelectObject(&bitmap);
|
|
memDC.BitBlt(0, 0, rectClient.Width(),rectClient.Height(), &dc, rectClient.left,rectClient.top,SRCCOPY);
|
|
memDC.SelectObject(pOldBitmap);
|
|
// bmp.CreateCompatibleBitmap(&memDC, rectClient.Width(), rectClient.Height());
|
|
|
|
}
|
|
|
|
CRect GetVPRect(int cvport)
|
|
{
|
|
//ads_point lowerpt, upperpt;
|
|
//CPoint pt1,pt2;
|
|
CWnd* pWndAcadView;
|
|
CRect rectVP;
|
|
//int cvport = 0;
|
|
//VERIFY(xg_getvar(_T("CVPORT"), &cvport)==RTNORM);
|
|
|
|
//AT_ScrCorner(lowerpt, upperpt);
|
|
//acedCoordFromWorldToPixel(cvport, lowerpt, pt1);
|
|
//acedCoordFromWorldToPixel(cvport, upperpt, pt2);
|
|
pWndAcadView = acedGetAcadDwgView();
|
|
CRect rect;
|
|
//pWndAcadView->GetWindowRect(rect);
|
|
pWndAcadView->GetClientRect(rect);
|
|
DList<TViewportInfo> ss;
|
|
ReadVports(ss);
|
|
long lCount = ss.Length();
|
|
for(long i=0L; i<lCount; i++) {
|
|
|
|
TViewportInfo &ent=*ss[i];
|
|
if (ent.VpID == cvport) {
|
|
XRectAngle box(ent.ptLeft, ent.ptRight);
|
|
XPoint ptCorners[4];
|
|
CPoint ptCorners2[4];
|
|
ptCorners[0]=box.GetLowLeft();
|
|
ptCorners[1]=box.GetLowRight();
|
|
ptCorners[2]=box.GetUpRight();
|
|
ptCorners[3]=box.GetUpLeft();
|
|
for(int n=0; n<4; n++) {
|
|
ptCorners2[n]=Lcs2Mcs(ptCorners[n]);
|
|
}
|
|
CRect rect2(ptCorners2[3], ptCorners2[1]);
|
|
rectVP = rect2;
|
|
if (rectVP.Width()>4 && rectVP.Height()>4)
|
|
rectVP.DeflateRect(2,2,2,2);
|
|
return rectVP;
|
|
}
|
|
|
|
}
|
|
VERIFY(xg_getvar(_T("CVPORT"), &cvport)==RTNORM);
|
|
return GetVPRect(cvport);
|
|
}
|
|
|
|
static void charcopy(char *to, const char *src)
|
|
{
|
|
if (!to || !src) exit(0);
|
|
if (!src) {*to=0; return;}
|
|
|
|
char sDup[1000];
|
|
strcpy(sDup, src);
|
|
char *p=sDup;
|
|
while(*p==_T(' ') || *p==_T('\t')) p++;
|
|
|
|
char *q=&sDup[strlen(sDup)]; // pointer EOS
|
|
while(q!=p) {
|
|
q--;
|
|
if (*q==_T(' ') || *p==_T('\t')) *q=0;
|
|
else break;
|
|
}
|
|
strcpy(to, p);
|
|
}
|
|
|
|
struct MaterByLayer {
|
|
XString sLayer, sMater;
|
|
};
|
|
|
|
#if ADS<17
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
// 简单渲染
|
|
|
|
//***********************************************************************************
|
|
// 平行光源 (单色)
|
|
//***********************************************************************************
|
|
// 设置太阳光
|
|
void SetSunLight()
|
|
{
|
|
GEOAPI void InitView(AcDbViewTableRecord &view);
|
|
|
|
AvLightParam pLightParam;
|
|
pLightParam.mode = AvLightListAll;
|
|
pLightParam.flags = 0;
|
|
BOOL bSun=FALSE, bEye=FALSE;
|
|
if (av_light(&pLightParam)== AvRetNorm) {
|
|
for(resbuf *rb=pLightParam.stringList; rb!=NULL; rb=rb->rbnext) {
|
|
if (rb->restype==RTSTR) {
|
|
if (stricmp(rb->resval.rstring, _T("sun"))==0)
|
|
bSun=TRUE;
|
|
else if (stricmp(rb->resval.rstring, _T("eye"))==0)
|
|
bEye=TRUE;
|
|
}
|
|
if (bSun&&bEye)
|
|
break;
|
|
}
|
|
if (pLightParam.stringList) {
|
|
ads_relrb(pLightParam.stringList);
|
|
pLightParam.stringList=NULL;
|
|
}
|
|
}
|
|
|
|
if (!bSun) {
|
|
pLightParam.type = AvLightDistant; // 平行光
|
|
pLightParam.mode = AvLightNewDistant; // 新建光源
|
|
pLightParam.name = _T("sun");
|
|
|
|
pLightParam.intensity = 0.9; // 光强度
|
|
|
|
AvColor LightColor; // 颜色
|
|
LightColor.system = AvRGB;
|
|
LightColor.color[0] = 1; // red
|
|
LightColor.color[1] = 1; // green
|
|
LightColor.color[2] = 1; // blue
|
|
pLightParam.color = LightColor;
|
|
|
|
pLightParam.shadows = 16; // 阴影设置
|
|
pLightParam.shadowmapSize = 0; // 打开“阴影大小/光线跟踪的阴影”
|
|
pLightParam.shadowSoftness =1;
|
|
|
|
// 时间、时区
|
|
pLightParam.month=9;
|
|
pLightParam.day=10;
|
|
pLightParam.hour=11;
|
|
pLightParam.minute=0;
|
|
pLightParam.latitude=39.90;
|
|
pLightParam.longitude=-116.00;
|
|
pLightParam.timezone=-8; // 时区 8为PST -8 为PRC
|
|
|
|
pLightParam.flags = AvLightIntensity | AvLightColor | AvLightName |
|
|
AvLightShadowmap | AvLightShadows | AvLightMonth | AvLightDay | AvLightHour |
|
|
AvLightMinute | AvLightLatitude | AvLightLongitude | AvLightTimezone;
|
|
|
|
if (av_light(&pLightParam) != AvRetNorm)
|
|
{
|
|
//acutPrintf(_T("SET Light \n error: %s"), av_errorstr(retval));
|
|
}
|
|
}
|
|
|
|
ads_command(RTSTR, _T(".CAMERA"), RTSTR, _T(""), RTSTR, _T(""), RTNONE);
|
|
|
|
XPoint ptCam, ptTar, vtView;
|
|
AcDbViewTableRecord view;
|
|
InitView(view);
|
|
ptTar=view.target();
|
|
vtView = view.viewDirection();
|
|
ptCam = ptTar+vtView;
|
|
|
|
if (!bEye) {
|
|
pLightParam.type = AvLightPoint; // 点光
|
|
pLightParam.mode = AvLightNewPoint; // 新建光源
|
|
pLightParam.name = _T("eye");
|
|
ptCam > pLightParam.from;
|
|
|
|
pLightParam.intensity = 0.4; // 光强度
|
|
pLightParam.attenuation = AvAttenuationNone;
|
|
|
|
AvColor LightColor; // 颜色
|
|
LightColor.system = AvRGB;
|
|
LightColor.color[0] = 1; // red
|
|
LightColor.color[1] = 1; // green
|
|
LightColor.color[2] = 1; // blue
|
|
pLightParam.color = LightColor;
|
|
|
|
|
|
pLightParam.flags = AvLightIntensity | AvLightColor | AvLightName | AvLightFrom|AvLightAttenuation ;
|
|
|
|
AvErrorCode retval= av_light(&pLightParam);
|
|
if (retval != AvRetNorm)
|
|
{
|
|
acutPrintf(_T("SET Light \n error: %s"), av_errorstr(retval));
|
|
}
|
|
} else {
|
|
pLightParam.mode = AvLightModify; // 改光源
|
|
pLightParam.name = _T("eye");
|
|
ptCam > pLightParam.from;
|
|
pLightParam.flags = AvLightName | AvLightFrom ;
|
|
|
|
AvErrorCode retval= av_light(&pLightParam);
|
|
if (retval != AvRetNorm)
|
|
{
|
|
acutPrintf(_T("SET Light \n error: %s"), av_errorstr(retval));
|
|
}
|
|
}
|
|
}
|
|
|
|
//***********************************************************************************
|
|
// 材质 //不知道如果输入globle名称
|
|
//***********************************************************************************
|
|
void SetMaterial()
|
|
{
|
|
ASSERT(sizeof(AvRmatParam)==sizeof(CAvRmatParam));
|
|
|
|
XString sMatLibFile, sTchMat;
|
|
if (FindFile(_T("tch.mat"), sTchMat) && FindFile(_T("上华标准材质.tml"), sMatLibFile)) {
|
|
CMaterialRecord matRec;
|
|
if (!matRec.Open(sMatLibFile))
|
|
return;
|
|
|
|
DList<MaterByLayer> lstMaterByLay;
|
|
XStringList lstMaters;
|
|
FILE *fp=fopen(sTchMat, _T("r"));
|
|
if (fp) {
|
|
XString sLine;
|
|
while(!feof(fp) && fgets(sLine, 255, fp)) {
|
|
char *p=strchr(sLine, _T(','));
|
|
if (p) {
|
|
XString s1, s2;
|
|
StrCpy(s1, sLine, p);
|
|
char *pTail=strchr(p, _T('\n'));
|
|
StrCpy(s2, p+1, pTail);
|
|
MaterByLayer *pMat=new MaterByLayer;
|
|
charcopy(pMat->sLayer, s1);
|
|
charcopy(pMat->sMater, s2);
|
|
if (lstMaters.Index(pMat->sMater, FALSE)<0)
|
|
lstMaters.Append(strnew(pMat->sMater));
|
|
|
|
if (!XSymbolTable(_T("LAYER"), pMat->sLayer)) {
|
|
delete pMat;
|
|
} else {
|
|
lstMaterByLay.Append(pMat);
|
|
}
|
|
}
|
|
}
|
|
fclose(fp);
|
|
}
|
|
|
|
|
|
|
|
// 赋材质
|
|
for(int i=0; i<lstMaterByLay.Length(); i++) {
|
|
AvRmatParam rmatPara;
|
|
rmatPara.mode=AvRmatShowMat;
|
|
rmatPara.layerName=lstMaterByLay[i]->sLayer;
|
|
rmatPara.flags = AvRmatLayerName;
|
|
rmatPara.name = NULL;
|
|
AvErrorCode retCode=av_rmat(&rmatPara);
|
|
if (retCode!=AvRetNorm || !rmatPara.name) { //没有赋过材质
|
|
rmatPara.mode=AvRmatAttach;
|
|
rmatPara.name=lstMaterByLay[i]->sMater;
|
|
rmatPara.attachment=AvRmatByLayer;
|
|
rmatPara.flags =
|
|
AvRmatName|AvRmatLayerName|AvRmatAttachment;
|
|
int nIndex=lstMaters.Index(rmatPara.name);
|
|
if (nIndex>=0) {
|
|
lstMaters.Remove(nIndex); //下次不在调入
|
|
for(matRec.MoveFirst(); !matRec.IsEOF(); matRec.MoveNext()) {
|
|
if (strcmp(matRec.m_sItem, rmatPara.name)==0) {
|
|
CAvRmatParam rmat1;
|
|
matRec.ConvertTo(rmat1);
|
|
rmat1.mode = AvRmatNew;
|
|
av_rmat(&rmat1);
|
|
//matRec.AvNew(); //在服务程序端执行,导致Acad2004崩溃
|
|
break;
|
|
}
|
|
}
|
|
/*
|
|
AvMatlibParam matLibPara;
|
|
matLibPara.mode = AvMatlibImport;
|
|
matLibPara.libraryName=sMatLibFile;
|
|
matLibPara.flags = AvMatlibLibrary|AvMatlibMaterial;
|
|
matLibPara.materialName=rmatPara.name;
|
|
retCode=av_matlib(&matLibPara);
|
|
*/
|
|
}
|
|
|
|
retCode=av_rmat(&rmatPara);
|
|
} else {
|
|
free(rmatPara.name);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//***********************************************************************************
|
|
// 渲染设置
|
|
//***********************************************************************************
|
|
|
|
void SetRenderConfig()
|
|
{
|
|
AvErrorCode retval;
|
|
AvRprefParam pRpref;
|
|
pRpref.mode = AvRprefSet; // 设置
|
|
pRpref.renderType = AvRprefRenderRaytrace; // 渲染类型
|
|
pRpref.destination = AvRprefDestFramebuffer; // 视口
|
|
//pRpref.antiAlias = AvRprefAntiAliasHigh;
|
|
//pRpref.palette = AvRprefFoldPalette;
|
|
AvRprefToggleParam Toggle; // 渲染选项
|
|
Toggle.AvRprefSmoothToggle = TRUE; // 平滑着色
|
|
Toggle.AvRprefShadowToggle = TRUE; // 阴影 true
|
|
Toggle.AvRprefFinishToggle = TRUE;
|
|
//Toggle.AvRprefMergeToggle = TRUE;
|
|
//Toggle.AvRprefSkipRdlgToggle = 0; // 跳过渲染对话框
|
|
//Toggle.AvRprefCropwindowToggle = 0; // 修剪窗口
|
|
Toggle.flags= AvRprefSmooth
|
|
| AvRprefShadow
|
|
| AvRprefFinish;
|
|
//| AvRprefMerge
|
|
//| AvRprefSkipRdlg
|
|
//| AvRprefCropwindow;
|
|
|
|
pRpref.toggle = Toggle;
|
|
pRpref.flags = AvRprefDestination
|
|
| AvRprefRenderType
|
|
//| AvRprefAntiAlias
|
|
//| AvRprefPalette
|
|
| AvRprefToggle;
|
|
if ((retval = av_rpref(&pRpref)) != AvRetNorm)
|
|
{
|
|
acutPrintf(_T("\n error: %s"), av_errorstr(retval));
|
|
}
|
|
|
|
pRpref.mode = AvRprefRopt;
|
|
pRpref.antiAlias = AvRprefAntiAliasMedium;
|
|
pRpref.renderType = AvRprefRenderRaytrace;
|
|
pRpref.flags = AvRprefRenderType|AvRprefAntiAlias;
|
|
if ((retval = av_rpref(&pRpref)) != AvRetNorm)
|
|
{
|
|
acutPrintf(_T("\n error: %s"), av_errorstr(retval));
|
|
}
|
|
|
|
}
|
|
|
|
//***********************************************************************************
|
|
// 渲 染
|
|
//***********************************************************************************
|
|
void RayTrace()
|
|
{
|
|
AvErrorCode retval;
|
|
AvRenderParam pRenderParam;
|
|
pRenderParam.mode= AvRender;
|
|
pRenderParam.flags=0;
|
|
if ((retval = av_render(&pRenderParam)) != AvRetNorm)
|
|
{
|
|
acutPrintf(_T("\n error: %s"), av_errorstr(retval));
|
|
}
|
|
}
|
|
|
|
// Command: 简单渲染
|
|
void QuickRender()
|
|
{
|
|
|
|
extern GEOAPI BOOL g_bExplodeMesh;
|
|
extern TARCH_IMPEXP BOOL g_bExpOtherDb;
|
|
|
|
AvErrorCode retval;
|
|
static int sbInitialized = FALSE;
|
|
|
|
int dbMod=0, dwgTitled=0;
|
|
VERIFY(xg_getvar(_T("DBMOD"), &dbMod)==RTNORM &&
|
|
xg_getvar(_T("DWGTITLED"), &dwgTitled)==RTNORM);
|
|
XPushVarStr vvv(_T("CLAYER"), _T("0"));
|
|
|
|
|
|
//***********************************************************************************
|
|
// 初始设置
|
|
//***********************************************************************************
|
|
|
|
if (!sbInitialized) {
|
|
retval = av_loadlib();
|
|
if (retval != AvRetNorm) {
|
|
acdbFail(_T("Library initialization failed.\n"));
|
|
return;
|
|
}
|
|
sbInitialized = TRUE;
|
|
}
|
|
av_initialize(); // Add on 2004/6/10,对所有文档都需要做初始化
|
|
|
|
SetSunLight();
|
|
|
|
//***********************************************************************************
|
|
// 背景 (单色)
|
|
//***********************************************************************************
|
|
/*
|
|
AvBackgroundParam pBackGroundParam;
|
|
pBackGroundParam.mode = AvBackgroundSolid;
|
|
pBackGroundParam.flags = AvBackgroundSolidColor;
|
|
// 背景颜色
|
|
AvColor color;
|
|
color.system = AvRGB;
|
|
color.color[0] = 0.48; // red
|
|
color.color[1] = 0.59; // green
|
|
color.color[2] = 0.25; // blue
|
|
|
|
pBackGroundParam.solid = color;
|
|
if ((retval = av_background(&pBackGroundParam)) != AvRetNorm)
|
|
{
|
|
acutPrintf(_T("Change Background \n error: %s"), av_errorstr(retval));
|
|
}
|
|
*/
|
|
|
|
/*
|
|
AvRmatParam rmatParam;
|
|
rmatParam.name = _T("*");
|
|
rmatParam.mode = AvRmatModify;
|
|
rmatParam.matType = AvRmatStandardMaterial;
|
|
AvRmatStandard standard;
|
|
standard.colorWeight = 1.0;
|
|
standard.flags = AvStandardColorWeight;
|
|
rmatParam.matParams.standard = standard;
|
|
|
|
rmatParam.flags = AvRmatName | AvRmatMatType | AvRmatMatParams;
|
|
if ((retval = av_rmat(&rmatParam)) != AvRetNorm)
|
|
{
|
|
acutPrintf("Modify Mat \n error: %s", av_errorstr(retval));
|
|
} */
|
|
SetMaterial();
|
|
|
|
//static int nQuestion=Q_YES;
|
|
//int nAns=YesNoQuestion("\n启动临时分解后的图形进行渲染", nQuestion);
|
|
//static int nChoice=0;
|
|
adsout << _T("\n选择 [本图着色(S)/本图渲染(R)/临时分解后渲染(E)]<退出>:");
|
|
XString sKey;
|
|
int nRet;
|
|
INITGET_BEG(0, _T("S R E"));
|
|
nRet=ads_getkword(_T(""), sKey);
|
|
INITGET_END();
|
|
if (nRet!=RTNORM)
|
|
return;
|
|
if (sKey[0]==_T('E')) {
|
|
extern TARCH_IMPEXP BOOL g_bWblockMaterial;
|
|
XPushMemVar<BOOL> vTemp0(g_bWblockMaterial, TRUE);
|
|
XString sTempFile;
|
|
sTempFile=GetTempFileName(_T(".dwg"));
|
|
#if (ADS>15)
|
|
if (!dwgTitled) {
|
|
XString sFileName;
|
|
xg_getvar(_T("DWGPREFIX"), sFileName);
|
|
if (GetFileDia(sFileName, 1, _T("dwg"), _T("当前图还未命名,请输入文件名"))!=RTNORM)
|
|
return;
|
|
remove(sFileName);
|
|
if (FindFile(sFileName))
|
|
return;
|
|
if (ads_command(RTSTR, _T(".SAVEAS"), RTSTR, _T("2004"), RTSTR, (const TCHAR *)sFileName, RTNONE)!=RTNORM)
|
|
return;
|
|
} else if (dbMod) {
|
|
int nAns=YesNoQuestion(_T("\n是否保存当前图"), Q_YES);
|
|
if (nAns==RTCAN)
|
|
return;
|
|
if (nAns!=Q_NO)
|
|
ads_command(RTSTR, _T(".QSAVE"), RTNONE);
|
|
}
|
|
XString sDwgPrefix, sDwgName;
|
|
if (xg_getvar(_T("DWGPREFIX"), sDwgPrefix)==RTNORM && xg_getvar(_T("DWGNAME"), sDwgName)==RTNORM) {
|
|
sDwgPrefix << sDwgName;
|
|
CopyFile(sDwgPrefix, sTempFile, TRUE);
|
|
g_lstFileRemove.Append(strnew(sTempFile));
|
|
XString sCmd;
|
|
sCmd << _T("(C:") << GetFullCmdName(_T("_IRender")) << _T(")\n");
|
|
MdiOpenDwgFile(sTempFile, sCmd);
|
|
|
|
}
|
|
#else
|
|
AcDbDatabase *pNewDb=NULL;
|
|
if (acdbCurDwg()->wblock(pNewDb)==Acad::eOk) {
|
|
if (pNewDb->saveAs(sTempFile)==Acad::eOk) {
|
|
delete pNewDb;
|
|
g_lstFileRemove.Append(strnew(sTempFile));
|
|
XString sCmd;
|
|
sCmd << _T("(C:") << GetFullCmdName(_T("_IRender")) << _T(")\n");
|
|
MdiOpenDwgFile(sTempFile, sCmd);
|
|
} else {
|
|
delete pNewDb;
|
|
}
|
|
}
|
|
#endif
|
|
} else if (sKey[0]==_T('R')) {
|
|
//nQuestion=nAns;
|
|
SetRenderConfig();
|
|
RayTrace();
|
|
} else if (sKey[0]==_T('S')) {
|
|
acedPostCommand(_T("Shade\n"));
|
|
}
|
|
}
|
|
|
|
extern BOOL Select3DFacesByLayer(AcDbVoidPtrArray &entSet, AcDbVoidPtrArray &faceSet, TCHAR *szLayer);
|
|
// [2010-3-16 14:13 wubo] 移植到新Geo库
|
|
// extern GEOAPI XPface * ConstructPolyFace(const AcDbVoidPtrArray &entSet);
|
|
void IRender()
|
|
{
|
|
extern GEOAPI BOOL g_bExplodeMesh;
|
|
extern TARCH_IMPEXP BOOL g_bExpOtherDb;
|
|
|
|
XPushMemVar<BOOL> tVar1(g_bExplodeMesh, TRUE);
|
|
XPushMemVar<BOOL> vTemp(XExplodeStream::m_bFullExplode, TRUE);
|
|
XPushMemVar<BOOL> vTemp1(XExplodeStream::m_bExportTch4, FALSE);
|
|
|
|
PickSet ssAll(SS_FREE); //ss--上华对象, ssAll--AutoCAD对象
|
|
RBList mask(RTDXF0, _T("TCH_*"), NULL);
|
|
int nRet=ssAll.Get(_T("X"), NULL, NULL, mask);
|
|
if (nRet!=RTNORM)
|
|
return;
|
|
|
|
//AcDbVoidPtrArray entitySet;
|
|
int nDrawMode=DocGetDrawMode();
|
|
DocSetDrawMode(DRAW_3D);
|
|
long lCount=ssAll.Length();
|
|
for(long i=0L; i<lCount; i++) {
|
|
Entity ent=ssAll[i];
|
|
TCHAR szLay[256]=_T("");
|
|
ent.GetData(8, szLay);
|
|
|
|
XDbObject obj(ent, AcDb::kForRead);
|
|
if (!obj) continue;
|
|
AcDbVoidPtrArray entSet0;
|
|
((AcDbEntity *)obj.m_pObject)->explode(entSet0);
|
|
AcDbVoidPtrArray entSet;
|
|
TCHAR szLayer[256]=_T("");
|
|
while(Select3DFacesByLayer(entSet0, entSet, szLayer)) {
|
|
if (strcmp(szLayer, _T("0"))==0)
|
|
strcpy(szLayer, szLay);
|
|
int nLen=entSet.length();
|
|
XPface *pMesh=ConstructPolyFace(entSet);
|
|
if (pMesh) {
|
|
pMesh->Make(szLayer);
|
|
delete pMesh;
|
|
ReleaseEntSet(entSet);
|
|
} else {
|
|
for(int n=0; n<nLen; n++) {
|
|
AcDbEntity *pEnt=(AcDbEntity *)entSet[n];
|
|
AddToModelSpace(pEnt, Adesk::kTrue);
|
|
}
|
|
}
|
|
}
|
|
int nLen=entSet0.length();
|
|
for(int n=0; n<nLen; n++) {
|
|
AcDbEntity *pEnt=(AcDbEntity *)entSet0[n];
|
|
AddToModelSpace(pEnt, Adesk::kTrue);
|
|
}
|
|
|
|
}
|
|
|
|
// 分解pNewDb中的块表
|
|
AcDbBlockTable *pNewBlockTab=NULL;
|
|
VERIFY(acdbCurDwg()->getSymbolTable(pNewBlockTab, AcDb::kForRead)==Acad::eOk);
|
|
ASSERT(pNewBlockTab);
|
|
AcDbBlockTableIterator *pIterator=NULL;
|
|
Acad::ErrorStatus es1=pNewBlockTab->newIterator(pIterator);
|
|
pNewBlockTab->close();
|
|
if (es1==Acad::eOk && pIterator) {
|
|
XPushMemVar<BOOL> vTemp2(g_bExpOtherDb, TRUE);
|
|
for(pIterator->start(); !pIterator->done(); pIterator->step()) {
|
|
AcDbBlockTableRecord *pRec=NULL;
|
|
if (pIterator->getRecord(pRec, AcDb::kForWrite)==Acad::eOk && pRec) {
|
|
if (!pRec->isFromExternalReference() && !pRec->isLayout()) {
|
|
AcDbBlockTableRecordIterator *pRecIter=NULL;
|
|
if (pRec->newIterator(pRecIter)==Acad::eOk && pRecIter) {
|
|
//对块表记录中的对象进行分解
|
|
AcDbVoidPtrArray entSetNew;
|
|
for(pRecIter->start(); !pRecIter->done(); pRecIter->step()) {
|
|
AcDbEntity *pEnt=NULL;
|
|
if (pRecIter->getEntity(pEnt, AcDb::kForWrite)==Acad::eOk) {
|
|
ASSERT(pEnt);
|
|
if (pEnt->isKindOf(TDbEntity::desc()) ||
|
|
pEnt->isKindOf(TDbCurveEntity::desc()) ||
|
|
pEnt->isKindOf(TDbBlockInsert::desc())) {
|
|
//分解对象
|
|
pEnt->explode(entSetNew);
|
|
}
|
|
pEnt->close();
|
|
}
|
|
}
|
|
//对块表中的上华对象进行删除
|
|
for(pRecIter->start(); !pRecIter->done(); pRecIter->step()) {
|
|
AcDbEntity *pEnt=NULL;
|
|
if (pRecIter->getEntity(pEnt, AcDb::kForWrite)==Acad::eOk) {
|
|
ASSERT(pEnt);
|
|
if (pEnt->isKindOf(TDbEntity::desc()) ||
|
|
pEnt->isKindOf(TDbCurveEntity::desc()) ||
|
|
pEnt->isKindOf(TDbBlockInsert::desc())) {
|
|
pEnt->erase(); //删除对象
|
|
}
|
|
pEnt->close();
|
|
}
|
|
}
|
|
//加入新转换的对象
|
|
int num=entSetNew.length();
|
|
for(int n=0; n<num; n++) {
|
|
AcDbEntity *pNewEnt=(AcDbEntity *)entSetNew[n];
|
|
VERIFY(pRec->appendAcDbEntity(pNewEnt)==Acad::eOk);
|
|
pNewEnt->close();
|
|
}
|
|
|
|
delete pRecIter;
|
|
}
|
|
}
|
|
pRec->close();
|
|
}
|
|
}
|
|
|
|
delete pIterator;
|
|
}
|
|
|
|
ssAll.Erase();
|
|
DocSetDrawMode(nDrawMode);
|
|
|
|
SetRenderConfig();
|
|
RayTrace();
|
|
}
|
|
|
|
//测试新建材质
|
|
void NewMater()
|
|
{
|
|
av_loadlib();
|
|
av_initialize(); // Add on 2004/6/10,对所有文档都需要做初始化
|
|
|
|
|
|
AvMatlibParam matLibPara;
|
|
matLibPara.mode = AvMatlibDelete;
|
|
matLibPara.flags = AvMatlibMaterial;
|
|
matLibPara.materialName = strdup(_T("浅绿皮纹"));
|
|
AvErrorCode retCode = av_matlib(&matLibPara);
|
|
if (retCode!=AvRetNorm) {
|
|
adsout << av_errorstr(retCode);
|
|
AfxMessageBox(XString(_T("删除材质%s失败!"), matLibPara.materialName));
|
|
}
|
|
free(matLibPara.materialName);
|
|
return;
|
|
|
|
AvColor color;
|
|
color.system=AvRGB;
|
|
color.color[0]=color.color[1]=color.color[2]=0.5;
|
|
|
|
AvRmatParam rmat;
|
|
rmat.mode = AvRmatNew;
|
|
rmat.name = _T("塑料-金色");
|
|
rmat.matType = AvRmatStandardMaterial;
|
|
|
|
rmat.matParams.standard.ambient=color;
|
|
rmat.matParams.standard.color=color;
|
|
rmat.matParams.standard.ambWeight= 0.2;
|
|
rmat.matParams.standard.colorWeight=0.6;
|
|
rmat.matParams.standard.transparency = 0.0;
|
|
rmat.matParams.standard.flags = AvStandardColor|AvStandardColorWeight|AvStandardAmbient|AvStandardAmbWeight|AvStandardTransparency;
|
|
|
|
rmat.reflMirror=FALSE;
|
|
rmat.reflColor=color;
|
|
rmat.reflWeight=0.3;
|
|
rmat.roughness=0.7;
|
|
|
|
rmat.flags = AvRmatMatType|AvRmatName|AvRmatMatParams
|
|
|AvRmatReflMirror|AvRmatReflColor|AvRmatReflWeight|AvRmatRoughness;
|
|
|
|
AvErrorCode retval=av_rmat(&rmat);
|
|
if (retval != AvRetNorm) {
|
|
acutPrintf(_T("\n error: %s"), av_errorstr(retval));
|
|
}
|
|
|
|
XString sMatLibFile, sTchMat;
|
|
if (FindFile(_T("tch.mat"), sTchMat) && FindFile(_T("上华标准材质.tml"), sMatLibFile)) {
|
|
CMaterialRecord matRec;
|
|
if (!matRec.Open(sMatLibFile))
|
|
return;
|
|
BOOL bFind=FALSE;
|
|
for(matRec.MoveFirst(); !matRec.IsEOF(); matRec.MoveNext()) {
|
|
if (strcmp(matRec.m_sItem,_T("塑料-黄色"))==0) {
|
|
bFind=TRUE;
|
|
break;
|
|
}
|
|
}
|
|
//matRec.Close();
|
|
if (bFind) {
|
|
AvRmatParam rmat1;
|
|
matRec.ConvertTo(rmat1);
|
|
rmat1.mode = AvRmatNew;
|
|
AvErrorCode retval=av_rmat(&rmat1);
|
|
if (retval != AvRetNorm) {
|
|
acutPrintf(_T("\n error: %s"), av_errorstr(retval));
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
#endif/*ADS<17*/
|