Unexpected results! worldDraw() question!

Unexpected results! worldDraw() question!

Anonymous
Not applicable
267 Views
1 Reply
Message 1 of 2

Unexpected results! worldDraw() question!

Anonymous
Not applicable
I have created a test entity, mjbSmiley. It simply a happy face with a
center an a diameter member variable. Now I was able to save this but when I
opened it, the mouth and eyes were missing. I created the features in
worldDraw(). Now, I thought worldDraw was responsible for drawing the
object. Here is my code:

//*******************************************
Adesk::Boolean mjbSmiley::worldDraw(AcGiWorldDraw* mode)
{
assertReadEnabled();

double dOffset = (m_dia / 1) / 5;
AcGeVector3d vecVert(0.0, dOffset, 0.0);
AcGeVector3d vecHorz(dOffset, 0.0, 0.0);

AcGePoint3d leftEye, rightEye, leftCorner, bottom, rightCorner;
leftEye = (m_center - vecHorz) + vecVert;
rightEye = (m_center + vecHorz) + vecVert;
leftCorner = m_center - vecHorz;
bottom = m_center - vecVert;
rightCorner = m_center + vecHorz;

mode->subEntityTraits().setColor(4);
mode->geometry().circle(m_center, m_dia / 2, AcGeVector3d(0.0, 0.0, 1.0));
mode->subEntityTraits().setColor(3);
mode->geometry().circle(leftEye, m_dia / 10, AcGeVector3d(0.0, 0.0, 1.0));
mode->geometry().circle(rightEye, m_dia / 10, AcGeVector3d(0.0, 0.0, 1.0));
mode->subEntityTraits().setColor(1);
if(!Adesk::kFalse == mode->geometry().circularArc(leftCorner, bottom,
rightCorner, kAcGiArcSimple))
printf("Mouth unsuccessful!");

return AcDbEntity::worldDraw(mode);
}

Acad::ErrorStatus mjbSmiley::dwgInFields(AcDbDwgFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es;

// Call dwgInFields from AcDbEntity
if ((es = AcDbEntity::dwgInFields(pFiler)) != Acad::eOk) {
return es;
}

// Read version number.
Adesk::UInt16 version;
pFiler->readItem(&version);
if (version > VERSION_MJBSMILEY)
return Acad::eMakeMeProxy;

// Read the data members.
switch (version)
{
case (1):
pFiler->readPoint3d(&m_center);
pFiler->readDouble(&m_dia);
break;
}


return pFiler->filerStatus();
}

Acad::ErrorStatus mjbSmiley::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es;

// Call dwgOutFields from AcDbEntity
if ((es = AcDbEntity::dwgOutFields(pFiler)) != Acad::eOk) {
return es;
}

// Write version number.
pFiler->writeItem((Adesk::UInt16) VERSION_MJBSMILEY);
pFiler->writePoint3d(m_center);
pFiler->writeDouble(m_dia);

return pFiler->filerStatus();
}
/********************************************

Now, why did worldDraw not draw the eyes and mouth of my mjbSmiley entity?

Mike B
0 Likes
268 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Hi Mike,

I tested your code for fun and didn't have any problems... I changed the
class name and added the code to the AcGi traits sample... The complete
entity code is pasted below. I suspect that the problem has to do with the
initialization of the m_center and m_dia variables. You might try steping
through the code to make sure these values are always populated with correct
numbers.

Here's the code I tested. You can build it just by replacing the
.\docsamps\acgismps\traits\traits.cpp with the code below.

#include
#include
#include
#include
#include "aced.h"
#include "dbsymtb.h"
#include "dbapserv.h"
#include "acgi.h"

// function prototypes
//
// THE FOLLOWING CODE APPEARS IN THE SDK DOCUMENT.

static Acad::ErrorStatus
getLinetypeIdFromString(const char* str, AcDbObjectId& id); static
Acad::ErrorStatus getLayerIdFromString(const char* str, AcDbObjectId& id);

// END CODE APPEARING IN SDK DOCUMENT.


class AsdkTraitsSamp: public AcDbEntity
{
public:

ACRX_DECLARE_MEMBERS(AsdkTraitsSamp);
virtual Adesk::Boolean worldDraw(AcGiWorldDraw *);
Acad::ErrorStatus transformBy(const AcGeMatrix3d &);
Acad::ErrorStatus dwgOutFields(AcDbDwgFiler* pFiler) const;
Acad::ErrorStatus dwgInFields(AcDbDwgFiler* pFiler);

double m_dia;
AcGePoint3d m_center;

};


ACRX_DXF_DEFINE_MEMBERS(AsdkTraitsSamp,AcDbEntity,
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, 0,\
ASDKTRAITSSAMP,AsdkTraits Sample);

Acad::ErrorStatus AsdkTraitsSamp::transformBy(
const AcGeMatrix3d &xfm)
{
return Acad::eOk;
}


//*******************************************
Adesk::Boolean AsdkTraitsSamp::worldDraw(AcGiWorldDraw* mode)
{
assertReadEnabled();

double dOffset = (m_dia / 1) / 5;
AcGeVector3d vecVert(0.0, dOffset, 0.0);
AcGeVector3d vecHorz(dOffset, 0.0, 0.0);

AcGePoint3d leftEye, rightEye, leftCorner, bottom, rightCorner; leftEye =
(m_center - vecHorz) + vecVert; rightEye = (m_center + vecHorz) + vecVert;
leftCorner = m_center - vecHorz; bottom = m_center - vecVert; rightCorner
= m_center + vecHorz;

mode->subEntityTraits().setColor(4);
mode->geometry().circle(m_center, m_dia / 2, AcGeVector3d(0.0, 0.0, 1.0));
mode->subEntityTraits().setColor(3);
mode->geometry().circle(leftEye, m_dia / 10, AcGeVector3d(0.0, 0.0, 1.0));
mode->geometry().circle(rightEye, m_dia / 10, AcGeVector3d(0.0, 0.0, 1.0));
mode->subEntityTraits().setColor(1);
if(!Adesk::kFalse == mode->geometry().circularArc(leftCorner, bottom,
rightCorner, kAcGiArcSimple))
printf("Mouth unsuccessful!");

return AcDbEntity::worldDraw(mode);
}

Acad::ErrorStatus AsdkTraitsSamp::dwgInFields(AcDbDwgFiler* pFiler) {

assertWriteEnabled(); Acad::ErrorStatus es;

// Call dwgInFields from AcDbEntity
if ((es = AcDbEntity::dwgInFields(pFiler)) != Acad::eOk) {
return es;
}

// Read version number.
Adesk::UInt16 version;
pFiler->readItem(&version);
if (version > 1.0)
return Acad::eMakeMeProxy;

// Read the data members.
switch (version)
{
case (1):
pFiler->readPoint3d(&m_center);
pFiler->readDouble(&m_dia);
break;
}


return pFiler->filerStatus();
}

Acad::ErrorStatus AsdkTraitsSamp::dwgOutFields(AcDbDwgFiler* pFiler) const {

assertReadEnabled(); Acad::ErrorStatus es;

// Call dwgOutFields from AcDbEntity
if ((es = AcDbEntity::dwgOutFields(pFiler)) != Acad::eOk) {
return es;
}

// Write version number.
pFiler->writeItem((Adesk::UInt16) 1.0); pFiler->writePoint3d(m_center);
pFiler->writeDouble(m_dia);

return pFiler->filerStatus();
}
//********************************************


void
addAsdkTraitsSampObject()
{
AsdkTraitsSamp *pNewObj = new AsdkTraitsSamp;

pNewObj->m_center = AcGePoint3d(0.0,0.0,0.0);
pNewObj->m_dia = 10.0;

AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTable, AcDb::kForRead);

AcDbBlockTableRecord *pBlock;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlock,
AcDb::kForWrite);

AcDbObjectId objId;
pBlock->appendAcDbEntity(objId, pNewObj);

pBlockTable->close();
pBlock->close();
pNewObj->close();
}

static void initAsdkTraitsSamp()
{
AsdkTraitsSamp::rxInit();
acrxBuildClassHierarchy();

acedRegCmds->addCommand("ASDK_TRAITS_SAMP",
"ASDKTRAITSSAMP",
"TRAITSSAMP",
ACRX_CMD_TRANSPARENT,
addAsdkTraitsSampObject);
}

extern "C" AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* appId)
{
switch(msg) {
case AcRx::kInitAppMsg:
acrxDynamicLinker->unlockApplication(appId);
acrxDynamicLinker->registerAppMDIAware(appId);
initAsdkTraitsSamp();
break;
case AcRx::kUnloadAppMsg:
acedRegCmds->removeGroup("ASDK_TRAITS_SAMP");
deleteAcRxClass(AsdkTraitsSamp::desc());
}
return AcRx::kRetOK;
}



"Mike B" wrote in message
news:7B0C737280ED923191B164F25D12A3B1@in.WebX.maYIadrTaRb...
> I have created a test entity, mjbSmiley. It simply a happy face with a
> center an a diameter member variable. Now I was able to save this but when
I
> opened it, the mouth and eyes were missing. I created the features in
> worldDraw(). Now, I thought worldDraw was responsible for drawing the
> object. Here is my code:
>
> //*******************************************
> Adesk::Boolean mjbSmiley::worldDraw(AcGiWorldDraw* mode)
> {
> assertReadEnabled();
>
> double dOffset = (m_dia / 1) / 5;
> AcGeVector3d vecVert(0.0, dOffset, 0.0);
> AcGeVector3d vecHorz(dOffset, 0.0, 0.0);
>
> AcGePoint3d leftEye, rightEye, leftCorner, bottom, rightCorner;
> leftEye = (m_center - vecHorz) + vecVert;
> rightEye = (m_center + vecHorz) + vecVert;
> leftCorner = m_center - vecHorz;
> bottom = m_center - vecVert;
> rightCorner = m_center + vecHorz;
>
> mode->subEntityTraits().setColor(4);
> mode->geometry().circle(m_center, m_dia / 2, AcGeVector3d(0.0, 0.0,
1.0));
> mode->subEntityTraits().setColor(3);
> mode->geometry().circle(leftEye, m_dia / 10, AcGeVector3d(0.0, 0.0,
1.0));
> mode->geometry().circle(rightEye, m_dia / 10, AcGeVector3d(0.0, 0.0,
1.0));
> mode->subEntityTraits().setColor(1);
> if(!Adesk::kFalse == mode->geometry().circularArc(leftCorner, bottom,
> rightCorner, kAcGiArcSimple))
> printf("Mouth unsuccessful!");
>
> return AcDbEntity::worldDraw(mode);
> }
>
> Acad::ErrorStatus mjbSmiley::dwgInFields(AcDbDwgFiler* pFiler)
> {
> assertWriteEnabled();
> Acad::ErrorStatus es;
>
> // Call dwgInFields from AcDbEntity
> if ((es = AcDbEntity::dwgInFields(pFiler)) != Acad::eOk) {
> return es;
> }
>
> // Read version number.
> Adesk::UInt16 version;
> pFiler->readItem(&version);
> if (version > VERSION_MJBSMILEY)
> return Acad::eMakeMeProxy;
>
> // Read the data members.
> switch (version)
> {
> case (1):
> pFiler->readPoint3d(&m_center);
> pFiler->readDouble(&m_dia);
> break;
> }
>
>
> return pFiler->filerStatus();
> }
>
> Acad::ErrorStatus mjbSmiley::dwgOutFields(AcDbDwgFiler* pFiler) const
> {
> assertReadEnabled();
> Acad::ErrorStatus es;
>
> // Call dwgOutFields from AcDbEntity
> if ((es = AcDbEntity::dwgOutFields(pFiler)) != Acad::eOk) {
> return es;
> }
>
> // Write version number.
> pFiler->writeItem((Adesk::UInt16) VERSION_MJBSMILEY);
> pFiler->writePoint3d(m_center);
> pFiler->writeDouble(m_dia);
>
> return pFiler->filerStatus();
> }
> /********************************************
>
> Now, why did worldDraw not draw the eyes and mouth of my mjbSmiley entity?
>
> Mike B
>
>
>
0 Likes