dwgOutFields - filing out pointer to custom class

dwgOutFields - filing out pointer to custom class

christineweiss86
Contributor Contributor
477 Views
2 Replies
Message 1 of 3

dwgOutFields - filing out pointer to custom class

christineweiss86
Contributor
Contributor

Hello everyone,

 

I have another issue filing out data of my custom entities.

So I have a custom entity deriving from AcDbBlockReference that saves a pointer to another custom class that derives from AcDbCurve and two enum classes (lage and FmaArt).

 

class DLLIMPEXP PProFmaKomponente : public AcDbBlockReference {

(...)

protected:
	 static Adesk::UInt32 kCurrentVersionNumber ;

private:
	 PProGeoKante* m_pGeo;
lage m_lage;
FmaArt m_fmaArt; (...) //----- AcDbObject protocols //- Dwg Filing protocol virtual Acad::ErrorStatus dwgOutFields (AcDbDwgFiler *pFiler) const ; virtual Acad::ErrorStatus dwgInFields (AcDbDwgFiler *pFiler) ; //- Dxf Filing protocol virtual Acad::ErrorStatus dxfOutFields (AcDbDxfFiler *pFiler) const ; virtual Acad::ErrorStatus dxfInFields (AcDbDxfFiler *pFiler) ; //----- AcDbEntity protocols //- Graphics protocol protected: virtual Adesk::Boolean subWorldDraw (AcGiWorldDraw *mode) ; (...) } ;

Now I am trying to file out these pointers using the following code and it crashes.

 

//- Dwg Filing protocol
Acad::ErrorStatus PProFmaKomponente::dwgOutFields (AcDbDwgFiler *pFiler) const {
	 assertReadEnabled () ;
	 //----- Save parent class information first.
	 Acad::ErrorStatus es =AcDbBlockReference::dwgOutFields (pFiler) ;
	 if ( es != Acad::eOk )
		  return (es) ;
	 //----- Object version number needs to be saved first
	 if ( (es =pFiler->writeUInt32 (PProFmaKomponente::kCurrentVersionNumber)) != Acad::eOk )
		  return (es) ;
	 
	 //----- Output params
	 pFiler->writeAddress(m_pGeo);
	 pFiler->writeAddress(&m_lage);
	 pFiler->writeAddress(&m_fmaArt);

	 return (pFiler->filerStatus ()) ;
}

meldung.PNG

so my questions are now:

 

1) can you even file out custom datatypes like enum classes and custom classes?

 

2) if you can do it how does it work?

 

0 Likes
478 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Hi,

 

for enums use something like this:

 

template<class _Ty>
inline
Acad::ErrorStatus dwgReadEnum(AcDbDwgFiler* filer, _Ty & Other)
  {
  assert(sizeof(_Ty) <= sizeof(Adesk::Int32));

  Adesk::Int32 iOther(0);
  filer->readInt32(&iOther);
  Other = static_cast<_Ty>(iOther);

 return filer->filerStatus();
 }

template<class _Ty>
inline 
Acad::ErrorStatus dwgWriteEnum(AcDbDwgFiler* filer, _Ty Other)
  {
  assert(sizeof(_Ty) <= sizeof(Adesk::Int32));

  filer->writeInt32(static_cast<Adesk::Int32>(Other));

  return filer->filerStatus();
}

for custom subclasses each subclass needs its own dwgIn/dwgOut function

 

m_pGeo->dwgOutFields(filer)

HTH

Arnold

0 Likes
Message 3 of 3

Anonymous
Not applicable

Hi!

 

You shouldn't use writeAddress.

For saving/restoring enums - use writeInt32/readInt32 (ie, as in reply above).

For saving/restoring "pointer" to your custom object - you should write/read it objectId.

If your custom object (PProGeoKante) is not added to acad database and have not objectId, then you should write/read it field by field.

0 Likes