Фильтр Точки ввода и Пример Монитора
Следующий пример демонстрирует использование фильтров точки ввода и мониторов.
#include "adslib.h"
#include "aced.h’
#include "dbmain.h"
#include "acdbabb.h"
#include "adeskabb.h"
#include "rxregsvc.h"
#include "acgi.h"
#include "acdocman.h"
#include "acedinpt.h"
#include "dbapserv.h"
class IPM : public AcEdInputPointMonitor
{
public:
virtual Acad::ErrorStatus
monitorInputPoint(
// Output. If changedTooltipStr is kTrue, newTooltipString
// has the new ToolTip string in it.
//
bool& appendToTooltipStr,
char*& additionalTooltipString,
// Input/Output
//
AcGiViewportDraw* drawContext,
// Input parameters:
//
AcApDocument* document,
bool pointComputed,
int history,
const AcGePoint3d& lastPoint,
const AcGePoint3d& rawPoint,
const AcGePoint3d& grippedPoint,
const AcGePoint3d& cartesianSnappedPoint,
const AcGePoint3d& osnappedPoint,
AcDb::OsnapMask osnapMasks,
// const AcArray<AcDbCustomOsnapMode>& customOsnapModes
const AcArray<AcDbObjectId>& apertureEntities,
const AcArray< AcDbObjectIdArray,
AcArrayObjectCopyReallocator< AcDbObjectIdArray > >&
nestedPickedEntities,
int gsSelectionMark,
const AcArray<AcDbObjectId>& keyPointEntities,
const AcArray<AcGeCurve3d*>& alignmentPaths,
const AcGePoint3d& computedPoint,
const char* tooltipString);
};
Acad::ErrorStatus
IPM::monitorInputPoint(
// Output. If changedTooltipStr is kTrue, then newTooltipString
// has the new ToolTip string in it.
//
bool& appendToTooltipStr,
char*& additionalTooltipString,
// Input/Output
//
AcGiViewportDraw* pDrawContext,
// Input parameters:
//
AcApDocument* document,
bool pointComputed,
int history,
const AcGePoint3d& lastPoint,
const AcGePoint3d& rawPoint,
const AcGePoint3d& grippedPoint,
const AcGePoint3d& cartesianSnappedPoint,
const AcGePoint3d& osnappedPoint,
AcDb::OsnapMask osnapMasks,
// const AcArray<AcDbCustomOsnapMode>& customOsnapModes
const AcArray<AcDbObjectId>& apertureEntities,
const AcArray< AcDbObjectIdArray,
AcArrayObjectCopyReallocator< AcDbObjectIdArray > >&
nestedPickedEntities,
int gsSelectionMark,
const AcArray<AcDbObjectId>& keyPointEntities,
const AcArray<AcGeCurve3d*>& alignmentPaths,
const AcGePoint3d& computedPoint,
const char* tooltipString)
{
acutPrintf("\nhistory: %d\n", history);
if (pointComputed)
{
acutPrintf(
"rawPoint: %.2f, %.2f, %.2f\n",
rawPoint[0],
rawPoint[1],
rawPoint[2]);
if (history & Acad::eGripped)
acutPrintf(
"grippedPoint: %.2f, %.2f, %.2f\n",
grippedPoint[0],
grippedPoint[1],
grippedPoint[2]);
if (history & Acad::eCartSnapped)
acutPrintf(
"cartesianSnappedPoint: %.2f, %.2f, %.2f\n",
cartesianSnappedPoint[0],
cartesianSnappedPoint[1],
cartesianSnappedPoint[2]);
if (history & Acad::eOsnapped)
{
acutPrintf(
"osnappedPoint: %.2f, %.2f, %.2f\n",
osnappedPoint[0],
osnappedPoint[1],
osnappedPoint[2]);
#define OSMASK_CHECK(x) if (osnapMasks & AcDb:: ## x)
acutPrintf("%s ", #x)
OSMASK_CHECK(kOsMaskEnd);
OSMASK_CHECK(kOsMaskMid);
OSMASK_CHECK(kOsMaskCen);
OSMASK_CHECK(kOsMaskNode);
OSMASK_CHECK(kOsMaskQuad);
OSMASK_CHECK(kOsMaskInt);
OSMASK_CHECK(kOsMaskIns);
OSMASK_CHECK(kOsMaskPerp);
OSMASK_CHECK(kOsMaskTan);
OSMASK_CHECK(kOsMaskNear);
OSMASK_CHECK(kOsMaskQuick);
OSMASK_CHECK(kOsMaskApint);
OSMASK_CHECK(kOsMaskImmediate);
OSMASK_CHECK(kOsMaskAllowTan);
OSMASK_CHECK(kOsMaskDisablePerp);
OSMASK_CHECK(kOsMaskRelCartesian);
OSMASK_CHECK(kOsMaskRelPolar);
#undef OSMASK_CHECK
acutPrintf("\n");
}
acutPrintf("%d apertureEntities: ", apertureEntities.length());
for (int i = 0; i < apertureEntities.length(); i++)
acutPrintf("<%x> ", apertureEntities[i].asOldId());
acutPrintf("\n");
}
else {
acutPrintf("No point computed");
if (history & Acad::eCyclingPt)
acutPrintf(", but new cycling osnap: %.2f, %.2f, %.2f\n",
osnappedPoint[0], osnappedPoint[1], osnappedPoint[2]);
else
acutPrintf(".\n");
}
if (NULL != pDrawContext)
{
pDrawContext->subEntityTraits().setColor(2);
pDrawContext->geometry().circle(rawPoint, 1.0,
AcGeVector3d::kZAxis);
}
else
acutPrintf("ViewportDraw is NULL!\n");
if (history & Acad::eNotDigitizer)
acutPrintf("PICK!\n");
if (NULL != tooltipString)
{
acutPrintf("TooltipString: %s\n", tooltipString);
additionalTooltipString = ", anotherString!";
appendToTooltipStr = true;
}
if (history & Acad::eOrtho)
{
acutPrintf("Ortho found at %.2f, %.2f, %.2f\n",
computedPoint[0], computedPoint[1], computedPoint[2]);
}
return Acad::eOk;
}
class IPF : public AcEdInputPointFilter {
public:
Acad::ErrorStatus
processInputPoint(
bool& changedPoint,
AcGePoint3d& newPoint,
bool& changedTooltipStr,
char*& newTooltipString,
bool& retry,
AcGiViewportDraw* pDrawContext,
AcApDocument* document,
bool pointComputed,
int history,
const AcGePoint3d& lastPoint,
const AcGePoint3d& rawPoint,
const AcGePoint3d& grippedPoint,
const AcGePoint3d& cartesianSnappedPoint,
const AcGePoint3d& osnappedPoint,
AcDb::OsnapMask osnapMasks,
// const AcArray<AcDbCustomOsnapMode>& customOsnapModes
const AcArray<AcDbObjectId>& pickedEntities,
const AcArray< AcDbObjectIdArray,
AcArrayObjectCopyReallocator< AcDbObjectIdArray > >&
nestedPickedEntities,
// Of 0th element in pickedEntities.
int gsSelectionMark,
// AutoSnap Info:
const AcArray<AcDbObjectId>& keyPointEntities,
const AcArray<AcGeCurve3d*>& alignmentPaths,
const AcGePoint3d& computedPoint,
const char* tooltipString);
};
Acad::ErrorStatus
IPF::processInputPoint(
bool& changedPoint,
AcGePoint3d& newPoint,
bool& changedTooltipStr,
char*& newTooltipString,
bool& retry,
AcGiViewportDraw* pDrawContext,
AcApDocument* document,
bool pointComputed,
int history,
const AcGePoint3d& lastPoint,
const AcGePoint3d& rawPoint,
const AcGePoint3d& grippedPoint,
const AcGePoint3d& cartesianSnappedPoint,
const AcGePoint3d& osnappedPoint,
// const AcArray<AcDbCustomOsnapMode>& customOsnapModes
const AcArray<AcDbObjectId>& pickedEntities,
const AcArray< AcDbObjectIdArray,
AcArrayObjectCopyReallocator< AcDbObjectIdArray > >&
nestedPickedEntities,
// Of 0th element in pickedEntities.
int gsSelectionMark,
// AutoSnap Info:
const AcArray<AcDbObjectId>& keyPointEntities,
const AcArray<AcGeCurve3d*>& alignmentPaths,
const AcGePoint3d& computedPoint,
const char* tooltipString)
{
// Change the computed point to an offset of (0.2, 0.2, 0.2)
// if the current computed point is an object snap point.
//
if (pointComputed && history & Acad::eOsnapped)
{
changedPoint = true;
newPoint = osnappedPoint + AcGeVector3d(0.2,0.2,0.0);
pDrawContext->geometry().circle(newPoint, 0.1,
AcGeVector3d::kZAxis);
}
return Acad::eOk;
}
// Input point monitor
IPM my_ipm;
// Input point filter
IPF my_ipf;
// Installs an input point monitor.
//
void testipm()
{
curDoc()->inputPointManager()->addPointMonitor(&my_ipm);
}
// Installs an input point filter.
//
void testipf()
{
curDoc()->inputPointManager()->registerPointFilter(&my_ipf);
}
// Turns on forced entity picking.
//
void testfp()
{
curDoc()->inputPointManager()->turnOnForcedPick();
}
// Disables the system cursor graphics.
//
void testcursor()
{
curDoc()->inputPointManager()->disableSystemCursorGraphics();
}
extern "C" __declspec(dllexport)
AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void *p)
{
switch (msg)
{
case AcRx::kInitAppMsg:
acrxRegisterAppMDIAware(p);
acrxUnlockApplication(p);
acedRegCmds->addCommand("mkr", "testipm", "ipm",
ACRX_CMD_TRANSPARENT, testipm);
acedRegCmds->addCommand("mkr", "testipf", "ipf",
ACRX_CMD_TRANSPARENT, testipf);
acedRegCmds->addCommand("mkr", "testfp", "fp",
ACRX_CMD_TRANSPARENT, testfp);
acedRegCmds->addCommand("mkr", "testcursor", "cursor",
ACRX_CMD_TRANSPARENT, testcursor);
break;
case AcRx::kUnloadAppMsg:
acedRegCmds->removeGroup("mkr");
break;
}
return AcRx::kRetOK;
}