Drawings SDK Developer Guide > Working with .dwg Files > Working with Colors > Overview of Classes that Implement Color and Transparency
Overview of Classes that Implement Color and Transparency

The C++ platform has OdCm-classes for working with colors and transparencies of various objects. To work with colors and transparencies, use the following:

  • OdCmColorBase abstract class
  • OdCmEntityColor class
  • OdCmColor class
  • OdCmTransparency class
  • Macros

OdCmColorBase abstract class

The OdCmColorBase abstract class provides the virtual base interface for classes representing colors. This class is used only for deriving color classes. Developers can not create instances of this class. Its pure virtual methods do not have an implementation and are the declaration of the color interface. Classes derived from the OdCmColorBase class must redefine its methods for working with colors. You can either implement these methods in the class that you derive or you can use the ready-to-use OdCmColor and OdCmEntityColor classes.

OdCmEntityColor class

The OdCmEntityColor class is a ready-to-use color object that works with a color as a 32-bit packed integer value. This value stores the color method and color components together. The composition of color components depends on the color method. The OdCmEntityColor class is not a successor of the OdCmColorBase class and has static methods for working with color methods and color components.

OdCmColor class

The OdCmColor class is a ready-to-use color object that works with named and unnamed colors. This class represents a color as an object of the drawing database. The named color is represented by a name of a book that stores information about how to display the color. The unnamed color is represented by a 32-bit packed integer value that stores the color method and color components. The OdCmColor class is the successor of the OdCmColorBase class and inherits its methods. The OdCmColor class implements the pure virtual methods for working with database colors. Additionally, the OdCmColor class defines the dwgIn(), dwgOut(), dxfIn(), and dxfOut() methods that convert the color information in or from the .dwg or .dxf files. The OdCmColor class also defines the entityColor() method that converts the database color to the instance of the OdCmEntityColor class.

Color interface

The color interface declares the following specific methods and operators

For working with a color method:

  • colorMethod() virtual/static method — Returns the color method.
  • setColorMethod() virtual/static method — Sets the color method.
  • isNone() virtual/static method — Checks whether the color method is None.
  • isByACI() virtual/static method — Checks whether the color method is byACI.
  • isByColor() virtual/static method — Checks whether the color method is byColor.
  • isByLayer() virtual/static method — Checks whether the color method is byLayer.
  • isByBlock() virtual/static method — Checks whether the color method is byBlock.
  • isByDgnIndex() virtual/static method — Checks whether the color method is byDgnIndex.
  • isByForeground() virtual/static method — Checks whether the color method is Foreground.

For working with a color as an RGB-value:

  • red() virtual/static method — Returns the red component value in the scope 0 to 255.
  • green() virtual/static method — Returns the green component value in the scope 0 to 255.
  • blue() virtual/static method — Returns the blue component value in the scope 0 to 255.
  • setRed() virtual/static method — Sets the red component by the specified value.
  • setGreen() virtual/static method — Sets the green component by the specified value.
  • setBlue() virtual/static method — Sets the blue component by the specified value.
  • setRGB() virtual/static method — Sets the red, green, and blue components together.

For working with a color as an ACI-value:

  • colorIndex() virtual/static method — Returns the color index in the scope 0 to 255.
  • setColorIndex() virtual/static method — Sets the color index by the specified value.

For working with an unnamed color:

  • color() virtual/static method — Returns the color as an integer value.
  • setColor() virtual/static method — Sets the color by the specified integer value.
  • (==) and (!=) operators — Compares the colors as integer values.

For working with a named color:

  • bookName() virtual method — Returns the book name.
  • colorName() virtual method — Returns the color name in the book.
  • colorNameForDisplay() virtual method — Returns the display color name.
  • setNames() virtual method — Sets the color name and book name.
  • (==) and (!=) operators — Compares the colors as string values and integer values taking into account color name, book name, color method, and color components.

Note: The OdCmEntityColor class has static methods. The OdCmColor class has virtual methods. You can derive a new color class from the OdCmColor class.

OdCmTransparency class

The OdCmTransparency class is a ready-to-use transparency object that works with transparency as a 32-bit packed integer value. This value stores the transparency method and transparency components together. The composition of transparency components depends on the transparency method. It declares the following specific methods and operators.

For working with a transparency method:

  • method() method — Returns the transparency method.
  • setMethod() method — Sets the transparency method.
  • isByAlpha() method — Checks whether the transparency method is byAlpha.
  • isByLayer() method — Checks whether the transparency method is byLayer.
  • isByBlock() method — Checks whether the transparency method is byBlock.

For working with a transparency as an alpha value:

  • alpha() method — Returns the alpha component value in the scope 0 to 255.
  • alphaPercent() method — Returns the alpha component value in the scope 0 to 100%.
  • setAlpha() method — Sets the alpha component by the specified value.
  • setAlphaPercent() method — Sets the alpha component by the specified value as a percent.
  • isClear() method — Checks whether the transparency is limpid.
  • isSolid() method — Checks whether the transparency is filled.

For working with a transparency as an integer value:

  • serializeIn() method — Returns the transparency as an integer value.
  • serializeOut() method — Sets the transparency by the specified integer value.
  • (==) and (!=) operators — Compares the transparencies as integer values.

Macros

Macros work with 32-bits integer values as with RGB-values and perform packing and extracting of color components. The ODRGB(red, green, blue) macro packs three specified color components in a RGB-value. The ODRGBA(red, green, blue, alpha) macro packs three color specified components and transparency alpha value in a 32-bit integer value. The ODGETRED(rgb) macro extracts the red component value from the specified RGB-value. The ODGETGREEN(rgb) macro extracts the green component value from the specified RGB-value. The ODGETBLUE(rgb) macro extracts the blue component value from the specified RGB-value. The ODGETALPHA(rgba) macro extracts the alpha component value from the specified RGB-value. Use these macros when you work with colors as integer values.

The OdCm-classes allow you to manipulate the color and transparency of various objects using the represented interfaces.

See Also

Working with Colors and Transparencies

Methods of the Color Definition

Methods of the Transparency Definition

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