ObjectARX, AutoCAD. Среда программирования библиотеки C++

       

Пример заказного режима объектной привязки


Следующий пример демонстрирует создание заказных режимов объектной привязки:

#include "rxobject.h"

#include "ads.h"

#include "adslib.h"

#include "dbmain.h"

#include "dbents.h"

#include "dbosnap.h"

#include "acedinpt.h"

// Socket Osnap mode protocol extension class.

//

class AcmeSocketInfo : public AcDbCustomOsnapInfo {

public:

ACRX_DECLARE_MEMBERS(AcmeSocketInfo);

virtual Acad::ErrorStatus

getOsnapInfo(

AcDbEntity* pickedObject,

int gsSelectionMark,

const AcGePoint3d& pickPoint,

const AcGePoint3d& lastPoint,

const AcGeMatrix3d& viewXform,

AcArray<AcGePoint3d>& snapPoints,

AcArray<int>& geomIdsForPts,

AcArray<AcGeCurve3d>& snapCurves,

AcArray<int>& geomIdsForLines)

};

// This class is registered with AcRx, to be used by the host

// application to look up entity class-specific implementations.

//

ACRX_NO_CONS_DEFINE_MEMBERS(AcmeSocketInfo,AcDbCustomOsnapInfo);

Acad::ErrorStatus

AcmeSocketInfo::getOsnapInfo(

AcDbEntity*,

int,

const AcGePoint3d&,

const AcGePoint3d&,

const AcGePoint3d&,

AcArray<AcGePoint3d>& snapPoints,

AcArray<int>& geomIdsForPts,

AcArray<AcGeCurve3d>& snapCurves,

AcArray<int>& geomIdsForLines)

{

// Associate with AcDbEntity to define default behavior.

//

snapPoints.setLogicalLength(0);

geomIdsForPts.setLogicalLength(0);

snapLiness.setLogicalLength(0);

geomIdsForLines.setLogicalLength(0);

}

// Socket Osnap mode protocol extension object for AcDbLine.

//

class AcmeSocketForLine : public AcmeSocketInfo {

public:

virtual Acad::ErrorStatus

getOsnapInfo(

AcDbEntity* pickedObject,

int gsSelectionMark,

const AcGePoint3d& pickPoint,

const AcGePoint3d& lastPoint,

const AcGeMatrix3d& viewXform,

AcArray<AcGePoint3d>& snapPoints,

AcArray<int>& geomIdsForPts,

AcArray<AcGeCurve3d>& snapCurves,


// If this ASSERT fails, then the pixel size is really position-
// dependent.
//
ASSERT(!vportDrawContext->viewport()->isPerspective());
vportDrawContext->viewport()->getNumPixelsInUnitSquare(AcGePoint3d::kOrigin, pixelArea);
double halfGlyphSizeInDCS =
acdbCustomOsnapManager->osnapGlyphSize() * pixelArea.x / 2.0;
// Draw an asterisk with 4 segments.
//
sSegmentPoints[0].set(
mCurDCSLoc.x-halfGlyphSizeInDCS,
mCurDCSLoc.y-halfGlyphSizeInDCS, 0.0);
sSegmentPoints[1].set(
mCurDCSLoc.x+halfGlyphSizeInDCS,
mCurDCSLoc.y+halfGlyphSizeInDCS, 0.0);
vportDrawContext->geometry().polylineDc( 2, &(sSegmentPoints[0]));
sSegmentPoints[0].set(
mCurDCSLoc.x-halfGlyphSizeInDCS,
mCurDCSLoc.y+halfGlyphSizeInDCS, 0.0);
sSegmentPoints[1].set(
mCurDCSLoc.x+halfGlyphSizeInDCS,
mCurDCSLoc.y-halfGlyphSizeInDCS, 0.0);
vportDrawContext->geometry().polylineDc( 2, &(sSegmentPoints[0]));
sSegmentPoints[0].set(
mCurDCSLoc.x-halfGlyphSizeInDCS,
mCurDCSLoc.y, 0.0);
sSegmentPoints[1].set(
mCurDCSLoc.x+halfGlyphSizeInDCS,
mCurDCSLoc.y, 0.0);
vportDrawContext->geometry().polylineDc( 2, &(sSegmentPoints[0]));
sSegmentPoints[0].set(
mCurDCSLoc.x,
mCurDCSLoc.y-halfGlyphSizeInDCS, 0.0);
sSegmentPoints[1].set(
mCurDCSLoc.x,
mCurDCSLoc.y+halfGlyphSizeInDCS, 0.0);
vportDrawContext->geometry().polylineDc( 2, &(sSegmentPoints[0]));
};
AcmeSocketGlyph* pSocketGlyph = NULL;
// Master object for the socket custom Osnap mode.
//
class AcmeSocketMode : public AcDbCustomOsnapMode {
public:
virtual const char*
localModeString() const {return "SOCket"};
virtual const char*
globalModeString() const {return "SOCket"};
virtual const AcRxClass*
entityOsnapClass() const {return AcmeSocketInfo::desc());
virtual AcGiGlyph*
glyph() const {return pSocketGlyph;);
virtual const char*
tooltipString() const {return "Socket to Me?" };
};
static AcmeSocketMode* pSocketMode = NULL;


/* ================ ObjectARX application interface ============ */
AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void*)
{
switch(msg) {
case AcRx::kInitAppMsg:
// Register the class.
//
AcmeSocketInfo::rxInit();
acrxBuildClassHierarchy();
pDefaultSocketInfo = new AcmeSocketInfo;
AcDbEntity::desc()->addX(AcmeSocketInfo::desc(),
pDefaultSocketInfo);
pSocketForLine = new AcmeSocketForLine;
AcDbLine::desc()->addX(AcmeSocketInfo::desc(), pSocketForLine);
//-- };
// Create the glyph object to be returned by the socket
// mode object.
//
pSocketGlyph = new AcmeSocketGlyph;
// Create and register the custom Osnap Mode
pSocketMode = new AcmeSocketMode;
acdbCustomOsnapManager->addCustomOsnapMode(pSocketMode);
// The SOCket Osnap mode is now plugged in and ready to use.
//
break;
case AcRx::kUnloadAppMsg:
// Clean up.
acdbCustomOsnapManager->removeCustomOsnapMode(pSocketMode);
delete pSocketMode;
// Unregister, then delete the protocol extension object.
//
AcDbEntity::desc()->delX(AcmeSocketInfo::desc());
delete pDefaultSocketInfo;
AcDbLine::desc()->delX(AcmeSocketInfo::desc());
delete pSocketForLine;
// Remove the protocol extension class definition.
//
acrxClassDictionary->remove("AcmeSocketInfo");
break;
default:
// Between the initialization and termination of the
// application, all registered objects will be directly
// invoked as needed. No commands or AutoLISP
// expressions are necessary.
//
break;
}
return AcRx::kRetOK;
}

Содержание раздела