[每日一码] 如何定义透明的命令,允许在屏幕四个方向分别PAN半个屏幕
问题: 如何定义透明的命令,允许在屏幕四个方向分别PAN半个屏幕解决方案:
The following code defines a transparent pan command for each of the four main
compass directions:
#include "rxregsvc.h"
#include "aced.h"
#include "dbsymtb.h"
#include "adscodes.h"
// Required for AutoCAD 2000
#include "migrtion.h"
// Deal with renaming of function in ObjectARX 2000
#define acdbSetCurrentView acedSetCurrentView
void panleft();
void panright();
void panup();
void pandown();
void
initApp()
{
acedRegCmds->addCommand( "PANNER", // Group name
"panl", // Global function name
"panl", // Local function name
ACRX采用CMD采用TRANSPARENT, // Type
&panleft ); // Function pointer
acedRegCmds->addCommand( "PANNER", // Group name
"panr", // Global function name
"panr", // Local function name
ACRX采用CMD采用TRANSPARENT, // Type
&panright ); // Function pointer
acedRegCmds->addCommand( "PANNER", // Group name
"panu", // Global function name
"panu", // Local function name
ACRX采用CMD采用TRANSPARENT, // Type
&panup ); // Function pointer
acedRegCmds->addCommand( "PANNER", // Group name
"pand", // Global function name
"pand", // Local function name
ACRX采用CMD采用TRANSPARENT, // Type
&pandown ); // Function pointer
}
void
unloadApp()
{
acedRegCmds->removeGroup( "PANNER" );
}
extern "C" AcRx::AppRetCode acrxEntryPoint( AcRx::AppMsgCode msg, void *p )
{
switch (msg)
{
case AcRx::kInitAppMsg:
acrxRegisterAppMDIAware(p);
acrxUnlockApplication(p); // try to allow unloading
initApp();
break;
case AcRx::kUnloadAppMsg:
unloadApp();
break;
default:
break;
}
return AcRx::kRetOK;
}
void
getCurrentView( AcDbViewTableRecord &view )
{
struct resbuf var;
struct resbuf WCS, UCS, DCS;
WCS.restype = RTSHORT;
WCS.resval.rint = 0;
UCS.restype = RTSHORT;
UCS.resval.rint = 1;
DCS.restype = RTSHORT;
DCS.resval.rint = 2;
ads采用getvar("VIEWMODE", &var);
view.setPerspectiveEnabled(var.resval.rint & 1);
view.setFrontClipEnabled(var.resval.rint & 2 ? true : false);
view.setBackClipEnabled(var.resval.rint & 4 ? true : false);
view.setFrontClipAtEye(!(var.resval.rint & 16));
ads采用getvar("BACKZ", &var);
view.setBackClipDistance(var.resval.rreal);
ads采用getvar("VIEWCTR", &var);
ads采用trans(var.resval.rpoint, &UCS, &DCS, NULL, var.resval.rpoint);
view.setCenterPoint(AcGePoint2d(var.resval.rpoint,
var.resval.rpoint));
ads采用getvar("FRONTZ", &var);
view.setFrontClipDistance(var.resval.rreal);
ads采用getvar("LENSLENGTH", &var);
view.setLensLength(var.resval.rreal);
ads采用getvar("TARGET", &var);
ads采用trans(var.resval.rpoint, &UCS, &WCS, NULL, var.resval.rpoint);
view.setTarget(AcGePoint3d(var.resval.rpoint, var.resval.rpoint,
var.resval.rpoint));
ads采用getvar("VIEWDIR", &var);
ads采用trans(var.resval.rpoint, &UCS, &WCS, TRUE, var.resval.rpoint);
view.setViewDirection(AcGeVector3d(var.resval.rpoint,
var.resval.rpoint, var.resval.rpoint));
ads采用getvar("VIEWSIZE", &var);
view.setHeight(var.resval.rreal);
double tst = view.width();
}
void
panleft()
{
AcDbViewTableRecord view;
getCurrentView( view );
AcGePoint2d viewCen = view.centerPoint();
viewCen = viewCen - ( view.width() / 2 );
view.setCenterPoint( viewCen );
acdbSetCurrentView( &view, NULL );
}
void
panright()
{
AcDbViewTableRecord view;
getCurrentView( view );
AcGePoint2d viewCen = view.centerPoint();
viewCen = viewCen + ( view.width() / 2 );
view.setCenterPoint( viewCen );
acdbSetCurrentView( &view, NULL );
}
下面是pandown()和panup()的定义函数
void
pandown()
{
AcDbViewTableRecord view;
getCurrentView( view );
AcGePoint2d viewCen = view.centerPoint();
viewCen = viewCen - ( view.height() / 2 );
view.setCenterPoint( viewCen );
acdbSetCurrentView( &view, NULL );
}
void
panup()
{
AcDbViewTableRecord view;
getCurrentView( view );
AcGePoint2d viewCen = view.centerPoint();
viewCen = viewCen + ( view.height() / 2 );
view.setCenterPoint( viewCen );
acdbSetCurrentView( &view, NULL );
}
页:
[1]