- UID
- 377508
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2006-1-5
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
这个程序主要实现的是实体关联拖动,但次程序是先要对实体进行3D渲染,我理解好象是一定要渲染后,才能调用Intermediary.h中的worlddraw()函数,但具体是怎么调用的我不太清楚。请各位朋友看一下,3D渲染和Intermediary.h是一个什么关系,我想不用3D渲染实现同样的功能,该如何修改?有劳各位朋友了!
//****Jig3dcmd.cpp****//
#include "stdafx.h"
#include "acdb.h"
#include "acgs.h"
#include "gs.h"
#include "acedads.h"
#include "acgsmanager.h"
#include "dbmain.h"
#include "acestext.h"
#include "acdocman.h"
#include "adscodes.h"
#include "dbsymtb.h"
#include "dbents.h"
#include "gemat3d.h"
#include "acgi.h"
#include "geassign.h"
#include <math.h>
#include "dbjig.h"
#include "cmdexception.h"
#include "intermediary.h"
#include "dbapserv.h"
#include "aced.h"
#include "dbxutil.h"
#if _MSC_VER > 1200
#pragma warning(push)
#endif
#pragma warning(disable:4290)
#pragma warning(disable:4310)
static AcDbObjectId GetModelSpaceBlockID (void)
{
AcDbObjectId ObjectId;
AcDbBlockTable * pBlockTable;
Acad::ErrorStatus status;
status = acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead);
if (status != Acad::eOk)
return false;
status = pBlockTable->getAt(ACDB_MODEL_SPACE, ObjectId);
pBlockTable->close();
return ObjectId;
}
class Jig3d : public AcEdJig
{
protected:
AcDbPolyline m_dummy;
AcGsModel* m_pModel;
AcGePoint3d m_refPoint;
double m_elev;
Intermediary m_int;
AcGeMatrix3d m_xform;
AcGeMatrix3d m_xformTemp;
AcGePoint3d m_LastPoint;
AcDbObjectId m_MSBObjectID;
enum Mode {kMove=0, kRotateX, kRotateY, kRotateZ} m_mode;
void apply() throw(CmdException);
public:
Jig3d()
:m_pModel(0),m_LastPoint(0.0,0.0,0.0)
{ }
~Jig3d();
//This sample uses AcEdJig in a slightly unconventional way.
//The following two overrides are usually concerned with
//updating the display. They are dummies in this sample
//since we are updating the display ourselves.
virtual Adesk::Boolean update()
{
return Adesk::kFalse;
}
virtual AcDbEntity* entity() const
{
return const_cast<AcDbPolyline*>(&m_dummy);
}
virtual DragStatus sampler();
void engage(void)throw(CmdException);
void init(const AcDbObjectId& idEntity,const AcGePoint3d& refPoint,int viewportNumber) throw(CmdException);
};
Jig3d::~Jig3d()
{
if (m_pModel)
{
m_pModel->onErased (&m_int, m_MSBObjectID.asOldId());
}
}
AcEdJig::DragStatus Jig3d::sampler()
{
setSpecialCursorType(AcEdJig::kRubberBand); //¹â±ê
AcGePoint3d pt,temp;
AcEdJig::DragStatus status;
double angle;
if (m_mode == kMove){
setKeywordList("Base X Y Z Exit"); //¹Ø¼ü×Ö
status = acquirePoint(pt,m_refPoint);
acdbWcs2Ucs(asDblArray(pt),asDblArray(pt),Adesk::kFalse);
pt.z = m_elev;
acdbUcs2Wcs(asDblArray(pt),asDblArray(pt),Adesk::kFalse);
} else {
setKeywordList("Exit");
status = acquirePoint(pt,m_refPoint);
acdbWcs2Ucs(asDblArray(pt),asDblArray(pt),Adesk::kFalse);
pt.z = m_elev;
acdbUcs2Wcs(asDblArray(pt),asDblArray(pt),Adesk::kFalse);
angle = acutAngle(asDblArray(pt),asDblArray(m_refPoint)); //
}
if (pt == m_LastPoint) // if there is no work to be done,
return status; // exit early!
m_LastPoint = pt;
if (status == AcEdJig::kNormal){
switch (m_mode)
{
case kMove:
m_xformTemp = AcGeMatrix3d::translation(pt-m_refPoint);
m_int.setTransform(m_xformTemp*m_xform);
break;
case kRotateX:
m_xformTemp = AcGeMatrix3d::rotation(angle,AcGeVector3d::kXAxis,m_refPoint);
m_int.setTransform(m_xformTemp*m_xform);
break;
case kRotateY:
m_xformTemp = AcGeMatrix3d::rotation(angle,AcGeVector3d::kYAxis,m_refPoint);
m_int.setTransform(m_xformTemp*m_xform);
break;
case kRotateZ:
m_xformTemp = AcGeMatrix3d::rotation(angle,AcGeVector3d::kZAxis,m_refPoint);
m_int.setTransform(m_xformTemp*m_xform);
break;
}
m_pModel->onModified(&m_int, m_MSBObjectID.asOldId());
}
return status;
}
void Jig3d::apply() throw(CmdException)
{
m_xform = m_xformTemp*m_xform;
AcDbEntity* pE;
if (acdbOpenObject(pE,m_int.m_idEntity,AcDb::kForWrite)==Acad::eOk)
{
Acad::ErrorStatus es;
if ((es=pE->transformBy(m_xform))!=Acad::eOk)
throw CmdException(es,"Transformation cannot be applied to object");
pE->close();
}
}
void Jig3d::init(const AcDbObjectId& idEntity,const AcGePoint3d& refPoint,int viewportNumber) throw(CmdException)
{
m_int.m_idEntity = idEntity;
m_refPoint = refPoint;
AcGsManager * pMan = acgsGetGsManager();
if (pMan==NULL)
throw CmdException("Cannot get Gs manager");
AcGsView * pView = acgsGetGsView (viewportNumber, false);
if (pView==0)
throw CmdException("Perform this command in a 3d View. Use the shademode command to activate one.");
m_MSBObjectID = GetModelSpaceBlockID();
if (m_MSBObjectID.asOldId() == 0)
throw CmdException("Unable to retrieve modelspace block ID");
m_pModel = pMan->getDBModel();
if (m_pModel==NULL)
throw CmdException("Unable to retrieve AcDb AcGsModel");
AcGePoint3d pt(refPoint);
acdbWcs2Ucs(asDblArray(pt),asDblArray(pt),Adesk::kFalse);
m_elev = pt.z;
m_pModel->onAdded (&m_int, m_MSBObjectID.asOldId());
m_mode = kMove;
}
void Jig3d::engage(void) throw(CmdException)
{
char* prompt = "\nSpecify displacement or [Base point/X/Y/Z/Exit]:";
AcEdJig::DragStatus status;
do
{
setDispPrompt(prompt);
status = drag();
switch (status)
{
case AcEdJig::kKW1:
if (m_mode == kMove)
{
acedGetPoint(asDblArray(m_refPoint),"Specify base point:",asDblArray(m_refPoint));
acdbUcs2Wcs(asDblArray(m_refPoint),asDblArray(m_refPoint),Adesk::kFalse);
}
else {
apply();
status = AcEdJig::kCancel;
}
break;
case AcEdJig::kKW2:
assert(m_mode == kMove);
m_mode = kRotateX;
prompt = "Specify rotation around X axis or [Exit]:";
break;
case AcEdJig::kKW3:
assert(m_mode == kMove);
m_mode = kRotateY;
prompt = "Specify rotation around Y axis [Exit]:";
break;
case AcEdJig::kKW4:
assert(m_mode == kMove);
m_mode = kRotateZ;
prompt = "Specify rotation around Z axis [Exit]:";
break;
case AcEdJig::kKW5:
apply();
status = AcEdJig::kCancel;
break;
default:
m_xform = m_xformTemp*m_xform;
if (m_mode == kMove)
m_refPoint+=m_xformTemp.translation();
m_mode = kMove;
prompt = "\nSpecify displacement or [Base point/X/Y/Z/Exit]:";
break;
}
}
while (status != AcEdJig::kCancel);
}
void jig3d()
{
try
{
struct resbuf rb;
acedGetVar("cvport", &rb);
if (rb.resval.rint==1)
throw CmdException("3djig cannot be used in layout mode");
ads_name ename;
ads_point pt;
int rt;
if ((rt = acedEntSel("Select object:",ename,pt))==RTCAN)
return;
if (rt!=RTNORM)
throw CmdException(Acad::eInvalidInput,"Invalid selection. Try again!");
AcDbObjectId id;
acdbGetObjectId(id,ename);
Jig3d jig;
acdbUcs2Wcs(pt,pt,Adesk::kFalse);
jig.init(id, asPnt3d(pt), rb.resval.rint);
jig.engage();
}
catch(CmdException e)
{
const char* strDesc = e.description();
if (strDesc == NULL)
strDesc = "No description.";
acutPrintf("ERROR:%s (es=%s)",strDesc,acadErrorStatusText(e.errorStatus()));
}
}
#if _MSC_VER > 1200
#pragma warning(pop)
#endif
相关的两个头文件:
//***CmdException.h**********
#if !defined(_CMDEXCEPTION_H)
#define _CMDEXCEPTION_H
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CmdException
{
const char* m_strDesc;
const Acad::ErrorStatus m_Es;
public:
CmdException(const Acad::ErrorStatus es,const char* strDesc=NULL)
:m_strDesc(strDesc),m_Es(es)
{}
CmdException(const char* strDesc)
:m_strDesc(strDesc),m_Es(Acad::eInvalidInput)
{}
const char* description() const
{
return m_strDesc;
}
const Acad::ErrorStatus errorStatus() const
{
return m_Es;
}
};
#endif
//***Intermediary.h*****
#if !defined(_INTERMEDIARY_H)
#define _INTERMEDIARY_H
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "drawable.h"
#include "gemat3d.h"
class Intermediary : public AcGiDrawable
{
AcGsNode* m_pNode;
AcGeMatrix3d m_mat;
public:
AcDbObjectId m_idEntity;
void setTransform(const AcGeMatrix3d& mat)
{
m_mat = mat;
}
virtual Adesk::UInt32 setAttributes (AcGiDrawableTraits * traits)
{
return kDrawableIsCompoundObject;
}
virtual Adesk::Boolean worldDraw (AcGiWorldDraw * wd)
{
wd->geometry().pushModelTransform(m_mat);
AcDbEntity* pE;
if (acdbOpenObject(pE,m_idEntity,AcDb::kForRead)==Acad::eOk)
{
wd->geometry().draw(pE);
pE->close();
}
wd->geometry().popModelTransform();
return Adesk::kTrue;
}
virtual void viewportDraw (AcGiViewportDraw * vd)
{
return;
}
virtual Adesk::Boolean isPersistent (void) const
{
return Adesk::kFalse;
};
virtual AcDbObjectId id (void) const
{
return AcDbObjectId::kNull;
}
virtual void setGsNode (AcGsNode * gsnode)
{
m_pNode = gsnode;
}
virtual AcGsNode* gsNode (void) const
{
return m_pNode;
}
};
#endif |
|