The custom class calls the worldDraw() and viewportDraw() functions to display the entity. The worldDraw() function must be implemented for any class derived from OdDbEntity. The viewportDraw() function is optional.
virtual bool OdDbEntity::worldDraw( OdGiWorldDraw *pWd ) const;
virtual void OdDbEntity::viewportDraw( OdGiViewportDraw *pVd ) const;
The worldDraw() function builds the portion of the entity's graphical representation that can be specified independently of any particular model-space view or paper-space viewport contexts. The viewportDraw() function then builds the view-dependent portion of the entity's graphics. If the entity has not view-dependent graphics, then the worldDraw() function must return true, and the custom entity does not implement the viewportDraw() function. If any of the entity's graphics are view-dependent, the worldDraw() function must return false and the viewportDraw() function must be implemented.
The worldDraw() function takes a pointer to an OdGiWorldDraw object. OdGiWorldDraw is a container class for the OdGiWorldGeometry and OdGiSubEntityTraits objects. The OdGiWorldGeometry object can be accessed from within the worldDraw() function by using the geometry() function, and the OdGiSubEntityTraits object can be accessed by using the subEntityTraits() function.
The OdGiWorldGeometry object writes vectors to refresh memory using its set of drawing primitives. A primitive is the lowest-level instruction used to draw graphical entities. The world geometry object has the following functions for drawing primitives in world coordinates: circle, circularArc , ellipArc, polyline, polygon, mesh, shell, text, xline, ray. For example:
pWd->geometry().circularArc( center, radius, normal, startvec, angle, kOdGiArcChord );
The OdGiSubEntityTraits object sets graphical attribute values using its set of traits functions: color, layer, line type, polygon fill type, selection marker. For example,
pWd->subEntityTraits().setTrueColor( entityColor() );
pWd->subEntityTraits().setFillType( kOdGiFillNever );
The viewportDraw() function takes a pointer to an OdGiViewportDraw object and builds the view-specific representation of an entity. The viewport draw object is also a container object for other objects, which include the following: OdGiViewportGeometry, OdGiSubEntityTraits, AcGiViewport. The viewport object provides functions for querying the viewport's transformation matrices and viewing parameters.
If you use selection markers when implementing a worldDraw()or viewportDraw() function, you must set the first selection marker before making any OdGiWorldGeometry or OdGiViewportGeometry call that generates graphics primitives, including calls to the mesh() and shell() functions. For example:
pWd->subEntityTraits().setSelectionMarker( 1 ); // Give the circle a GS marker of 1
pWd->geometry().circle( center, radius, normal );
If necessary, you may set this first marker to an artificial value such as -1.
OdGiWorldDraw or OdGiViewportDraw objects should not be stored as a global or static variable. Do not save copies of these objects across calls to the worldDraw() and viewportDraw() functions. Once these functions return, the OdGi objects are no longer valid. For example, the smiley entity implements:
bool AsdkSmiley::worldDraw(OdGiWorldDraw *wd) const
{
assertReadEnabled();
OdGeVector3d offset(0,0,0);
// If dragging, don't fill the smiley
if( wd->isDragging() )
{
wd->subEntityTraits().setTrueColor(entityColor());
wd->subEntityTraits().setFillType( kOdGiFillNever );
}
else
wd->subEntityTraits().setFillType( kOdGiFillAlways );
// Drawing circle of face
wd->subEntityTraits().setSelectionMarker( 1 );
wd->geometry().circle( center(), radius(), mnormal );
if( !wd->isDragging() )
wd->subEntityTraits().setTrueColor(mbackcolor);
// Drawing circle of left eye
wd->subEntityTraits().setSelectionMarker( 2 );
wd->geometry().circle( leftEyeCenter(), meyesize, mnormal );
// Drawing circle of right eye
wd->subEntityTraits().setSelectionMarker( 3 );
wd->geometry().circle( rightEyeCenter(), meyesize, mnormal );
// Drawing arc of mouth
OdGePoint3d smilecen( mouthCenter() + offset ),
startpt( mouthLeft() + offset ),
endpt( mouthRight() + offset );
OdGeVector3d startvec = startpt - smilecen,
endvec = endpt - smilecen;
double mouthangle = startvec.angleTo( endvec );
wd->subEntityTraits().setSelectionMarker( 4 );
wd->geometry().circularArc( smilecen, mouthRadius(), mnormal, startvec, mouthangle, kOdGiArcChord );
return true;
}
Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.
|