A visual style is an object that is a set of properties used during rendering to determine how to draw various graphics primitives. Visual styles control output graphics in detail. For example, isolines can be displayed instead of wireframes on top of shaded objects, or face and edge colors can be modified, etc. The images below show some of the predefined visual styles.
Realistic
Hidden
Conceptual
Visual style objects are stored in the Visual Styles sub-dictionary of the root drawing dictionary.
To create an instance of the visual style object, use the createObject() method of the OdDbVisualStyle class that is the static pseudo-constructor. For example:
OdDbVisualStylePtr pVStyle = OdDbVisualStyle::createObject();
The pseudo-constructor initializes the properties of a new instance using default values. After creation, the new visual style instance must be added in the visual style dictionary using the setAt() method. In the following examples, the pDb variable stores a pointer to the database object. For example:
// Open a visual style dictionary
OdDbDictionaryPtr pVSDic = pDb->getVisualStyleDictionaryId().safeOpenObject(OdDb::kForWrite);
// Add visual style in the visual style dictionary
OdDbObjectId vsId = pVSDic->setAt("VisualStyle1", pVStyle);
The OdDbVisualStyle class is derived from the OdDbObject class, therefore the OdDbVisualStyle class also inherits the general properties of objects. A pointer to a visual style object can be converted to a base class object. For example:
OdDbObjectPtr pObject = pVStyle;
To verify an instance, use the isKindOf() and desc() methods. For example:
// Accurate comparing
if(pObject->isA() == OdDbVisualStyle::desc())
odPrintConsoleString(L"\nObject is the visual style");
// Check on belonging
if(pObject->isKindOf(OdDbVisualStyle::desc()))
odPrintConsoleString(L"\nEntity is derived from the visual style object");
Visual styles can be associated with entities, including viewports. Each simple entity may optionally contain up to three pointers to visual style objects for face-related, edge-related and display-related properties (use links in "See Also" section for details). And each viewport must contain a pointer to a visual style object.
Each viewport has its own visual style associated with it by default. But it is possible to change the default visual style using, for example, this kind of code:
OdDbViewportTablePtr pVportTable = pDb->getViewportTableId().safeOpenObject(OdDb::kForWrite);
OdDbObjectId vpID = pVportTable->getActiveViewportId();
OdDbViewportTableRecordPtr vportRec = vpID.safeOpenObject(OdDb::kForWrite);
vportRec->setVisualStyle(vsId);
To associate a created visual style with some entity use the setVisualStyle() entity's method. If there is no any visual style associated with an entity - it will be drawn using visual style associated with a viewport object. In the example below a visual style is applied to a sphere entity:
/**********************************************************************/
/* Create a Sphere */
/**********************************************************************/
OdDb3dSolidPtr pSphere = OdDb3dSolid::createObject();
pSphere->createSphere(1.);
pSphere->setDatabaseDefaults(pDb);
/**********************************************************************/
/* Add Sphere in the model space */
/**********************************************************************/
OdDbBlockTableRecordPtr pModel = pDb->getModelSpaceId().safeOpenObject(OdDb::kForWrite);
pModel->appendOdDbEntity(pSphere);
/**********************************************************************/
/* Associate the Visual Style with the Sphere */
/**********************************************************************/
pSphere->setVisualStyle(vsId);
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.
|