Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Methods of the Color Definition

The color method defines how a color is defined and what components are used. A color can be defined through an RGB-value (byColor), index (byACI, byDGNIndex), style table (byPen), color of a layer (byLayer), or color of a block (byBlock). A color can also be defined as a foreground (Foreground) or invisible (None). The byColor method defines the color through three integer values that specify the intensities of the red, green, and blue components (RGB-value). The byColor method requires 24 bits for storing components and assigns over 16 million colors to be displayed. The byACI and byDGNIndex methods define the color as an integer value that is an index of a color in a color palette. The color palette stores the fixed set of RGB-values that assign 256 colors to be displayed. The byPen method defines the color through a color mapping table that is the component of a plot style. The byLayer method defines the color through the settings of the layer to which the colored object belongs. The byBlock method defines the color through the settings of the block which the colored object composes. The Foreground method defines the color as a two-color system in which the foreground is used only and the background is limpid. The None method defines the invisible color when the colored object must not be drawn. The color method is stored with 24 to 31 bits, other bits store the color components.

The color defined by the byLayer, byBlock, or None method does not have components and is identified only by the method number. The listed color method is supported both as a database color object and entity color object. The color objects are declared by the following lines:


OdCmEntityColor eColor;
OdCmColor nColor;

To get the color method, use the colorMethod() method that does not have arguments and returns the number of the color method as an integer constant defined by the ColorMethod enumeration. The color method occupies one half-byte in which the most significant half-byte always stores the Ch value and the least significant half-byte stores the method number. Half-bytes together form the following values:  0xC0 – kByLayer, 0xC1 – kByBlock, 0xC2 – kByColor, 0xC3 – kByACI, 0xC4 – kByPen, 0xC5 – kForeground, 0xC7 – kByDgnIndex, 0xC8 – kNone. For example:


PrintAboutColorMethod(eColor.colorMethod());
PrintAboutColorMethod(nColor.colorMethod());

void PrintAboutColorMethod(OdCmEntityColor::ColorMethod method)
{
  odPrintConsoleString(L"\nColor method = %x - is ", method);

  switch(method)
  {
    case OdCmEntityColor::kByLayer:
         odPrintConsoleString(L"by Layer\n");
         break;
    case OdCmEntityColor::kByBlock:
         odPrintConsoleString(L"by Block\n");
         break;
    case OdCmEntityColor::kByColor:
         odPrintConsoleString(L"by RGB\n");
         break;
    case OdCmEntityColor::kByACI:
         odPrintConsoleString(L"by ACI\n");
         break;
    case OdCmEntityColor::kByPen:
         odPrintConsoleString(L"by Pen Table\n");
         break;
    case OdCmEntityColor::kForeground:
         odPrintConsoleString(L"by Foreground\n");
         break;
    case OdCmEntityColor::kByDgnIndex:
         odPrintConsoleString(L"by DGN Pen Table\n");
         break;
    case OdCmEntityColor::kNone:
         odPrintConsoleString(L"None\n");
         break;
  }
}

To specify the color method, use the setColorMethod() method that requires the color method as a value of the ColorMethod enumeration and does not return a value. For example:


eColor.setColorMethod(OdCmEntityColor::kByColor);
nColor.setColorMethod(OdCmEntityColor::kByBlock);

Another example:


int method;

odPrintConsoleString(L"\nMethod: 0-ByLayer, 1-ByBlock, 2-ByRGB, 3-ByACI");
odPrintConsoleString(L"\n\t 4-ByPen, 5-Foreground, 7-ByDgnIndex, 8-None");
odPrintConsoleString(L"\nSpecify the color method:>");
scanf("%d", &method);

if(method == 0 || method == 1 || method == 2 || method == 3 || 
   method == 4 || method == 5 || method == 7 || method == 8)
{
  eColor.setColorMethod((OdCmEntityColor::ColorMethod)(0xC0 | method));
  nColor.setColorMethod((OdCmEntityColor::ColorMethod)(0xC0 | method));
}

To check whether the color method is by layer, use the isByLayer() method that returns True when the color method is set to kByLayer or False otherwise. For example:


odPrintConsoleString(L"\nEntity color method %s byLayer", ((eColor.isByLayer()) ? L"is" : L"is not"));
odPrintConsoleString(L"\nDatabase color method %s byLayer", ((nColor.isByLayer()) ? L"is" : L"is not"));

To check whether the color method is by block, use the isByBlock() method that returns True when the color method is set to kByBlock or False otherwise. For example:


odPrintConsoleString(L"\nEntity color method %s byBlock", ((eColor.isByBlock()) ? L"is" : L"is not"));
odPrintConsoleString(L"\nDatabase color method %s byBlock", ((nColor.isByBlock()) ? L"is" : L"is not"));

To check whether the color method is by RGB-value, use the isByColor() method that returns True when the color method is set to kByColor or False otherwise. For example:


odPrintConsoleString(L"\nEntity color method %s byRGB", ((eColor.isByColor()) ? L"is" : L"is not"));
odPrintConsoleString(L"\nDatabase color method %s byRGB", ((nColor.isByColor()) ? L"is" : L"is not"));

To check whether the color method is by color index, use the isByACI() method that returns True when the color method is set to kByACI or False otherwise. For example:


odPrintConsoleString(L"\nEntity color method %s byACI", ((eColor.isByACI()) ? L"is" : L"is not"));
odPrintConsoleString(L"\nDatabase color method %s byACI", ((nColor.isByACI()) ? L"is" : L"is not"));

To check whether the color method is by dgn-index, use the isByDgnIndex() method that returns True when the color method is set to kByDgnIndex or False otherwise. For example:


odPrintConsoleString(L"\nEntity color method %s byDgnIndex", ((eColor.isByDgnIndex()) ? L"is" : L"is not"));
odPrintConsoleString(L"\nDatabase color method %s byDgnIndex", ((nColor.isByDgnIndex()) ? L"is" : L"is not"));

To check whether the color method is a foreground, use the isForeground() method that returns True when the color method is set to kForeground or False otherwise. For example:


odPrintConsoleString(L"\nEntity color method %s Foreground", ((eColor.isForeground()) ? L"is" : L"is not"));
odPrintConsoleString(L"\nDatabase color method %s Foreground", ((nColor.isForeground()) ? L"is" : L"is not"));

To check whether the color method is none, use the isNone() method that returns True when the color method is set to kNone or False otherwise. For example:


odPrintConsoleString(L"\nEntity color method %s None", ((eColor.isNone()) ? L"is" : L"is not"));
odPrintConsoleString(L"\nDatabase color method %s None", ((nColor.isNone()) ? L"is" : L"is not"));

Note: When the specified color method is set to kForeground, the setColorMethod() automatically changes it to kByACI with the index 7 and the colorMethod() method returns the kByACI value, isByACI() method returns True, and isForeground() method returns True together.

Note: When the specified color method is set to kByDgnIndex, the setColorMethod() generates the eNotApplicable exception. The ByDgnIndex color method is not implemented in the OdCmColor and OdCmEntityColor classes. The OdDgCmColor class derived from the OdCmColor class and OdDgCmEntityColor class derived from the OdCmEntityColor class implement the byDgnIndex color method. The OdDgCmColor and OdDgCmEntityColor classes redefine the colorIndex() and setColorIndex() methods that already work with a dgn-color palette and dgn-color indexes.

See Also

Working with Colors and Transparencies

Color Functionality as an RGB-value

Color Functionality as an ACI-value

Color Functionality as an Integer-value

Color Functionality as a Book Name

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