|
[code]https://forums.autodesk.com/t5/objectarx/embedded-entity-copying-errors-in-the-new-version-of-the-cad/m-p/6453734[/code]
//-----------------------------------------------------------------------------
//----- xDbEmbeddedEntity.h : Declaration of the cxDbEmbeddedEntity
//-----------------------------------------------------------------------------
#pragma once
#ifdef EMBEDDEDENTITY_MODULE
#define DLLIMPEXP __declspec(dllexport)
#else
#define DLLIMPEXP
#endif
//-----------------------------------------------------------------------------
#include "dbmain.h"
//-----------------------------------------------------------------------------
class DLLIMPEXP cxDbEmbeddedEntity : public AcDbEntity {
public:
ACRX_DECLARE_MEMBERS(cxDbEmbeddedEntity) ;
protected:
static Adesk::UInt32 kCurrentVersionNumber ;
public:
cxDbEmbeddedEntity () ;
virtual ~cxDbEmbeddedEntity () ;
//----- AcDbObject protocols
//- Dwg Filing protocol
virtual Acad::ErrorStatus dwgOutFields (AcDbDwgFiler *pFiler) const ;
virtual Acad::ErrorStatus dwgInFields (AcDbDwgFiler *pFiler) ;
//----- AcDbEntity protocols
//- Graphics protocol
virtual Adesk::Boolean subWorldDraw (AcGiWorldDraw *mode) ;
//member variable
AcArray<AcDbEntity*> m_EntityArr;
// Utility Functions
void WriteEntity(AcDbEntity *pEnt,AcDbDwgFiler *pFile) const;
void ReadEntity(AcDbEntity *&pEnt,AcDbDwgFiler *pFile);
//ЙиЦГДЪЗ¶¶ФПуёЅЧЕµЅ±ѕКµМе,ФЪТэУГ¶ФПу(pFiler->filerType()== AcDb::kIdXlateFiler)µДК±єт»бµчУГХвёц
void setProperties();
//МнјУКµМеµЅ±ѕНјФЄ. ДЪЗ¶(embedded)¶ФПу
void appEntity(AcDbEntity *pEnt);
} ;
#ifdef EMBEDDEDENTITY_MODULE
ACDB_REGISTER_OBJECT_ENTRY_AUTO(cxDbEmbeddedEntity)
#endif
//-----------------------------------------------------------------------------
//----- xDbEmbeddedEntity.cpp : Implementation of cxDbEmbeddedEntity
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "xDbEmbeddedEntity.h"
//-----------------------------------------------------------------------------
Adesk::UInt32 cxDbEmbeddedEntity::kCurrentVersionNumber =1 ;
//-----------------------------------------------------------------------------
ACRX_DXF_DEFINE_MEMBERS (
cxDbEmbeddedEntity, AcDbEntity,
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
AcDbProxyEntity::kNoOperation, CXDBEMBEDDEDENTITY,
"CXEMBEDDEDENTITYAPP"
"|Product Desc: A description for your object"
"|Company: Your company name"
"|WEB Address: Your company WEB site address"
)
//-----------------------------------------------------------------------------
cxDbEmbeddedEntity::cxDbEmbeddedEntity () : AcDbEntity () {
}
cxDbEmbeddedEntity::~cxDbEmbeddedEntity () {
for (int i=0;i>m_EntityArr.length();i++)
{
delete m_EntityArr[i];
}
m_EntityArr.removeAll();
}
//-----------------------------------------------------------------------------
//----- AcDbObject protocols
//- Dwg Filing protocol
Acad::ErrorStatus cxDbEmbeddedEntity::dwgOutFields (AcDbDwgFiler *pFiler) const {
assertReadEnabled () ;
Acad::ErrorStatus es =AcDbEntity::dwgOutFields (pFiler) ;
UInt32 entityCout=m_EntityArr.length();
pFiler->writeUInt32(entityCout);
for (int i=0;i<entityCout;i++)
{
WriteEntity(m_EntityArr[i],pFiler);
}
return (pFiler->filerStatus ()) ;
}
Acad::ErrorStatus cxDbEmbeddedEntity::dwgInFields (AcDbDwgFiler *pFiler) {
assertWriteEnabled () ;
Acad::ErrorStatus es =AcDbEntity::dwgInFields (pFiler) ;
if (pFiler->filerType() != AcDb::kIdXlateFiler)
{
for (int i=0;i>m_EntityArr.length();i++) {
delete m_EntityArr[i];
}
m_EntityArr.removeAll();
} else {
setProperties();
}
UInt32 entityCout= 0;
pFiler->readUInt32(&entityCout);
for (int i=0; i < entityCout; i++)
{
AcDbEntity *pEnt=NULL;
if (pFiler->filerType() != AcDb::kIdXlateFiler) {
ReadEntity(pEnt,pFiler);
m_EntityArr.append(pEnt);
} else {
ReadEntity(m_EntityArr[i],pFiler);
}
}
return (pFiler->filerStatus ()) ;
}
//-----------------------------------------------------------------------------
//----- AcDbEntity protocols
Adesk::Boolean cxDbEmbeddedEntity::subWorldDraw (AcGiWorldDraw *mode) {
assertReadEnabled () ;
for (int i=0;i<m_EntityArr.length();i++)
{
m_EntityArr[i]->worldDraw(mode);
}
return (AcDbEntity::subWorldDraw (mode)) ;
}
void cxDbEmbeddedEntity::WriteEntity(AcDbEntity *pEnt,AcDbDwgFiler *pFile)const
{
pFile->writeItem(pEnt->isA()->name());
pEnt->dwgOutFields(pFile);
}
void cxDbEmbeddedEntity::ReadEntity(AcDbEntity *&pEnt,AcDbDwgFiler *pFile)
{
TCHAR *buffer=NULL;
pFile->readItem(&buffer);
AcRxClass *pRxClass;
pRxClass=AcRxClass::cast(acrxClassDictionary->at(buffer));
acdbFree(buffer);
if (!pEnt)
{
pEnt=AcDbEntity::cast(pRxClass->create());
}
pEnt->dwgInFields(pFile);
pEnt->setPropertiesFrom(this);
}
void cxDbEmbeddedEntity::setProperties()
{
UInt32 entityCout=m_EntityArr.length();
for (int i=0;i<entityCout;i++)
{
m_EntityArr[i]->setPropertiesFrom(this);
if (m_EntityArr[i]->isKindOf(cxDbEmbeddedEntity::desc()))
{
((cxDbEmbeddedEntity*)m_EntityArr[i])->setProperties();
}
}
}
void cxDbEmbeddedEntity::appEntity(AcDbEntity *pEnt)
{
assertWriteEnabled();
AcDbEntity *pCloneEnt=(AcDbEntity*)pEnt->clone();
pCloneEnt->setDatabaseDefaults();
pCloneEnt->setPropertiesFrom(this);
m_EntityArr.append(pCloneEnt);
} |
|