A multi-line style contains a specification of lines, named named elements, that are defined in sequence with an offset, color, linetype. The offset specifies the displacement of an element relative to the base track along which parallel segments are drawn. A zero offset defines the base line relative to where other elements are justified. Elements with a positive offset are displaced in a direction perpendicular to the segment axis vector where the perpendicular direction is set counterclockwise, that is, if the segment axis is left-to-right or bottom-to-up, elements are displaced up or to the left. Elements with a negative offset are displaced in a direction perpendicular to the segment axis vector, where the perpendicular directions is set clockwise, that is, if the segment axis is left-to-right or bottom-to-up, elements are displaced down or to the right. Each element can have an individual color and individual linetype. The specification of lines stores the object ID of the associated linetype. The multi-line style can contain from 1 to 16 elements (the number is defined by MLINE_MAX_ELEMENTS). The multi-line sorts its own elements by the offset value and enumerates them beginning at zero, that is, the element with most the positive offset has the index zero, the element with an offset less than the first has index one, element with an offset less than the first and second has the index two, etc. The element with the most negative offset has an index that equals the number of elements minus one.
The multi-line style object provides methods for getting the number of elements, getting the offsets, colors, and linetypes of elements, adding a new element to the multi-line style, modifying a selected element, and deleting an existing element from the multi-line. In the following examples, the pMLStyle variable stores a pointer to the multi-line style object.
The multi-line style object stores the number of elements which are enumerated at zero. The first element has the number 0. The last element has a number that is the number of elements minus one. The multi-line style does not contain elements by default.
To get the number of elements, use the numElements() method which does not have arguments and returns an Integer value. For example:
OdInt16 count = pMLStyle->numElements();
odPrintConsoleString(L"\nElements = %d", count);
Each element is defined with an offset, color, and linetype. The offset is a Double value. The color is an instance of the OdCmColor type. The linetype is an object ID associated with the linetype record object stored in the linetype table object.
To get an element, use the getElementAt() method which requires the element index as the first argument of the Integer type, requires a reference to the variable of the Double type in which the element offset must be saved as the second argument, requires a reference to a variable of the OdCmColor type in which the element color must be saved as the third argument, requires a reference to the variable of the OdDbObjectId type in which the element linetype ID must be saved as the fourth argument, and returns the element parameters through arguments. For example:
double offset; // variable to save an offset
OdCmColor color; // variable to save a color
OdDbObjectId idLT; // variable to save a linetype
OdString sLT; // linetype name
OdInt16 index, count = pMLine->numElements();
for(index = 0 ; index < count ; index++)
{
pMLStyle->getElementAt( index, offset, color, idLT );
sLT = ((!idLT.isNull()) ? ((OdDbSymbolTableRecord*) idLT.safeOpenObject().get()->getName()) : L"kNull");
odPrintConsoleString(L"\n(%d) offset = %g, color = [%x], linetype = %s", index, offset, color.color(), sLT.c_str());
}
The multi-line style object adds an element in the container and automatically re-sorts all stored elements by offset, so that the new element can obtain an index. The element with the most positive offset obtains a zero index. The element with the most negative offset obtains an index equal to the number of elements minus one. The number of elements increases by one.
To add an element to the multi-line style, use the addElement() method which requires the element offset as the first argument of the Double type, requires the element color as the second argument of the OdCmColor type, requires the element linetype as the third argument of the OdDbObjectId type, and returns an index of a new element as an Integer value. For example:
// Add first element
double offset;
OdCmColor color;
OdDbObjectId idLT;
offset = 0.5;
color.setRGB(48, 24, 12);
idLT = pMLStyle->database()->getLinetypeContinuousId();
pMLStyle->addElement( offset, color, idLT );
// Add second element
pMLStyle->addElement( -0.5, OdCmColor(OdCmEntityColor::kForeground), pMLStyle->database()->getLinetypeByLayerId() );
The multi-line style object modifies an element by index and automatically re-sorts all stored elements by offset. The number of elements is not changed.
To modify an element in the multi-line style, use the setElement() method which requires the element index as the first argument of the Integer type, requires the element offset as the second argument of the Double type, requires the element color as the third argument of the OdCmColor type, requires the element linetype as the fourth argument of the OdDbObjectId type, and does not return a value. For example:
pMLStyle->setElement( 0, 1.5, OdCmColor(OdCmEntityColor::kByLayer), pMLStyle->database()->getLinetypeByLayerId() );
pMLStyle->setElement( 1, -1.5, OdCmColor(OdCmEntityColor::kByBlock), pMLStyle->database()->getLinetypeByBlockId() );
The following example changes the offsets and colors to opposite values and linetypes to solid lines for all elements of the multi-line style:
double offset;
OdCmColor color;
OdDbObjectId idLT;
OdInt16 index, count = pMLine->numElements();
for(index = 0 ; index < count ; index++)
{
pMLStyle->getElementAt( index, offset, color, idLT );
offset = -offset;
color.setRGB( 255 - color.red(), 255 - color.green(), 255 - color.blue() );
idLT = pMLStyle->database()->getLinetypeContinuousId();
pMLStyle->setElement( index, offset, color, idLT );
}
The multi-line style object deletes an element by index and automatically re-sorts all stored elements by offset after deletion. The number of elements decreases by one.
To delete an element from the multi-line style, use the removeElementAt() method which requires the element index as an argument of the Integer type and does not return a value. For example:
OdInt16 index = 1;
pMLStyle->removeElementAt( index );
Note: The removeElementAt(), getElementAt(), and setElement() methods must get the index in the accessible range 0 to numElements()–1, otherwise errors occur.
Working with Multi-Line Styles
Specific Multi-Line Style Properties
Example of Working with the Multi-Line Style Object
Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.
|