Drawings SDK Developer Guide > Working with .dwg Files > Working with Entities > Creating a Custom Entity > Implementing Exploding Functions
Implementing Exploding Functions

Usually, a custom entity object consists of simple entities such as lines, circles, arcs, etc. These simple entities are processed as a single whole. In some tasks it is necessary to explode a custom entity into more simple entities. For example, a window object can be exploded into a window sill, window frame, double glass, and vent light. Each entity defines how to explode itself into simple objects. To explode a custom entity into simple entities, you must override the explode() function.


virtual OdResult OdDbEntity::explode( OdRxObjectPtrArray& entitySet ) const;

The explode() function hands over the array of smart pointers array for entity objects. Simple entities are created using the createObject() function. This function returns the smart pointer of the object. Each simple entity class has a smart pointer type. The type name contains the name of the class and a 'Ptr' suffix. You must use the type of smart pointer that corresponds to the simple entity class.

Additional objects in the array are realized using the append() function. To get a pointer of an entity, it is necessary to call the get() function of the smart pointer type.

A simple entity uses the setPropertiesFrom() function to copy the properties from a specified entity to this entity. You must use this function to set the default properties for a created entity.

For example, the smiley entity implements the following:


OdResult AsdkSmiley::explode( OdRxObjectPtrArray& entitySet) const
{
  assertReadEnabled();

  OdDbCirclePtr pFace = OdDbCircle::createObject();         // Create circle for face

  pFace->setPropertiesFrom(this);
  pFace->setNormal( normal() );
  pFace->setRadius( radius() );
  pFace->setCenter( center() );
  entitySet.append( pFace.get() );

  OdDbCirclePtr pLeftEye = OdDbCircle::createObject();      // Create circle for left eye

  pLeftEye->setPropertiesFrom( this );
  pLeftEye->setNormal( normal() );
  pLeftEye->setRadius( eyeSize() );
  pLeftEye->setCenter( leftEyeCenter() );
  entitySet.append( pLeftEye.get() );

  OdDbCirclePtr pRightEye = OdDbCircle::createObject();     // Create circle for right eye
  
  pRightEye->setPropertiesFrom( this );
  pRightEye->setNormal( normal() );
  pRightEye->setRadius( eyeSize() );
  pRightEye->setCenter( rightEyeCenter() );
  entitySet.append( pRightEye.get() );

  OdDbLinePtr pLine = OdDbLine::createObject();             // Create arc chord for mouth
  
  pLine->setPropertiesFrom( this );
  pLine->setNormal( normal() );
  pLine->setStartPoint( mouthLeft() );
  pLine->setEndPoint( mouthRight() );
  entitySet.append( pLine.get() );
                                     
  OdGeVector3d normvec( 1, 0, 0 );
  double dStartAngle = 2 * kPi - (mouthLeft() - mouthCenter()).angleTo( normvec );
  double dEndAngle = 2 * kPi - (mouthRight() - mouthCenter()).angleTo( normvec );

  OdDbArcPtr pArc = OdDbArc::createObject();                // Create arc for mouth
  
  pArc->setPropertiesFrom( this );
  pArc->setNormal( normal() );
  pArc->setRadius( mouthRadius() );
  pArc->setCenter( mouthCenter() );
  pArc->setStartAngle( dStartAngle );
  pArc->setEndAngle( dEndAngle );
  entitySet.append( pArc.get() );

  return eOk;
}

The explode() function should break the entity down into less complex entities. If the resulting entities are not native entities, the function will return eExplodeAgain.

See Also

Creating a Custom Entity

Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.