This example demonstrates working with the layer record object for displaying and modifying its properties. This example uses a console menu that represents getting and setting the following: lock status [L], plot status [A], on-off status [O], freeze status [F], hidden status [H], lineweight [W], description [D], color [C], color index [I], transparency [T], linetype [Y], and material [M].
The PrintLayerProperties() function displays the listed properties of the passed layer and requires the pointer to an existing layer record object. This function uses the description() method for displaying a description, lineWeight() method and AboutLineWeight() function for displaying the specified lineweight, linetypeObjectId() method and AboutDbObject() function for displaying information about the associated linetype record object, materialId() method and AboutDbObject() function for displaying information about the associated material object, color() method and AboutColor() function for displaying information about the specified color, transparency() method and AboutTransparency() function for displaying information about the specified transparency, and isInUse(), isFrozen(), isOff(), isLocked(), isPlottable(), and isHidden() methods for displaying the layer status.
The PrintLayerProperties() function has the following implementation:
void PrintLayerProperties(OdDbLayerTableRecord* pLayer)
{
wcout << L"\nH=" << pLayer->handle().ascii()
<< L"\n Name = \"" << pLayer->getName() << L"\""
<< L"\n Status: " << ((pLayer->isErased()) ? L"erased" : L"unerased")
<< ((pLayer->isDBRO()) ? L",resident" : L"")
<< ((pLayer->isModified()) ? L",modified" : L"")
<< ((pLayer->isDependent()) ? L",XRef-dependent" : L"")
<< L"\n Description: \"" << pLayer->description() << L"\""
<< L"\n Layer_Status: " << ((pLayer->isInUse()) ? L"InUse" : L"Unused")
<< ((pLayer->isFrozen()) ? L", Frozen" : L", Thawed")
<< ((pLayer->isOff()) ? L", OFF" : L", ON")
<< ((pLayer->isLocked()) ? L", Locked" : L", Unlocked")
<< ((pLayer->isPlottable()) ? L", Plotable" : L", Unplottable")
<< ((pLayer->isHidden()) ? L", Hidden" : L", Shown")
<< L"\n Lineweight: " << AboutLineWeight(pLayer->lineWeight())
<< L"\n Linetype: " << AboutDbObject(pLayer->linetypeObjectId())
<< L"\n Material: " << AboutDbObject(pLayer->materialId())
<< L"\n Color: " << AboutColor(pLayer->color())
<< L"\n Transparency: " << AboutTransparency(pLayer->transparency());
}
The ModifyLayerProperties() function requires a pointer to an existing layer record object and implements the console menu for the listed operations. The function creates a loop that inquires about the operation code and uses the switch statement to select whether the case must be performed. The ModifyLayerProperties() function processes user actions in the loop until the user selects the [Q] operation.
When the user selects [P], the function displays the specific properties of the specified layer record object using the PrintLayerProperties() function.
When the user selects [D], the function inquires about the new description string using the getline() method and the comment variable declared as a wide-char buffer. Then the function calls the setDescription() method and passes it the entered value to set the new comments for the layer.
When the user selects [L], the function inquires about the new lock status and prompts: L-lock or U-unlock. The function calls the setIsLocked() method and passes to it a True value if a user enters the 'L' letter (status is locked) or a False value if the user enters the 'U' letter (status is unlocked). After setting, the function checks and displays the current lock status using the isLocked() method.
When the user selects [A], the function inquires about the new plot status and prompts: P-plot or U-unplot. The function calls the setIsPlottable() method and passes to it a True value if the user enters the 'P' letter (status is plottable) or a False value if the user enters the 'U' letter (status is unplottable). After setting, the function checks and displays the current plot status using the isPlottable() method.
When the user selects [O], the function inquires about the new on-off status and prompts: F-turn off or N-turn on. The function calls the setIsOff() method and passes to it a True value if the user enters the 'F' letter (status is off) or a False value if the user enters the 'N' letter (status is on). After setting, the function checks and displays the current on-off status using the isOff() method.
When the user selects [F], the function inquires about the new freeze status and prompts: F-freeze or T-thaw. The function calls the setIsFrozen() method and passes to it a True value if the user enters the 'F' letter (status is frozen) or a False value if the user enters the 'T' letter (status is thawed). After setting, the function checks and displays the current freeze status using the isFrozen() method.
When the user selects [H], the function inquires about the new hidden status and prompts: H-hide or S-show. The function calls the setIsHidden() method and passes to it a True value if the user enters the 'H' letter (status is hidden) or a False value if the user enters the 'S' letter (status is shown). After setting, the function checks and displays the current hidden status using the isHidden() method.
When the user selects [I], the function displays the current color index using the colorIndex() method and inquires about the new index as a positive integer value. If an entered value is incorrect, the function displays an error message and breaks to the console menu. If an entered value is correct, the function calls the setColorIndex() method and passes it the entered value to set the new color value for the layer. The setColorIndex() method sets the byACI color method.
When the user selects [C], the function gets the current color specified for the layer as an OdCmColor instance using the color() method. Then the ModifyLayerProperties() function calls the EntryColorValue() function for color entry and passes to it the obtained color instance as a default value for entering and a False value to lock the selection of the color method. The EntryColorValue() function organizes its own console menu for specifying the red, green, and blue color components or color index. This function returns True and passes the color instance modified by the user, or returns False if the user cancels entry. If entry is successfully, the function calls the setColor() method and passes it the returned color value to set it for the layer. The function uses the AboutColor() function for displaying information about the specified color.
When the user selects [T], the function gets the current transparency specified for the layer as an OdCmTransparency instance using the transparency() method. Then the ModifyLayerProperties() function calls the EntryTransparencyValue() function for entering a transparency and passes to it the obtained transparency instance as a default value for entering and a False value to lock the selection of the transparency method. The EntryTransparencyValue() function organizes its own console menu for specifying the alpha or percent. The function returns True and passes the transparency instance modified by the user, or returns False if the user cancels entry. After entry, the function calls the setTransparency() method and passes it the returned transparency value to set it for the layer. The function uses the AboutTransparency() function for displaying information about the specified transparency.
When the user selects [Y], the function gets the Object ID of the current linetype record object specified for the layer using the linetypeObjectId() method and gets the Object ID of the linetype table object of the database using the database() and getLinetypeTableId() methods. Then the ModifyLayerProperties() function calls the EntryTableRecordObject() function for selecting a linetype from the linetype table. The EntryTableRecordObject() function requires the Object ID of the table object from which the linetype must be selected and the Object ID of the record object which is used as a default value. Both arguments are OdDbObjectId instances. The EntryTableRecordObject() function organizes its own console menu for selecting a linetype and returns the Object ID of the linetype record object selected by the user or the Object ID of the default linetype if the user cancels entry. After selection, the function calls the setLinetypeObjectId() method and passes it the returned Object ID to set the new linetype for the layer. The function uses the AboutDbObject() function for displaying information about the specified linetype.
When the user selects [M], the function gets the Object ID of the current material object specified for the layer using the materialId() method and gets the the Object ID of the dictionary object containing materials of the database using the database() and getMaterialDictionaryId() methods. Then the ModifyLayerProperties() function calls the EntryDictionaryObject() function for selecting a material from the material dictionary. The EntryDictionaryObject() function requires the Object ID of the dictionary object from which the material must be selected and the Object ID of the material object which is used as a default value. Both arguments are OdDbObjectId instances. The EntryDictionaryObject() function organizes its own console menu for selecting a material and returns the Object ID of the material object selected by the user or the Object ID of the default material if the user cancels entry. After selection, the function calls the setMaterialId() method and passes to it the returned Object ID to set the new material for the layer. The function uses the AboutDbObject() function for displaying information about the specified material.
When the user selects [Q], the function ends the loop and returns in the calling function.
The ModifyLayerProperties() function has the following implementation:
#include "..\Common\DemoMain.h"
#include "DbLayerTable.h"
#include "DbLayerTableRecord.h"
#include <iostream>
using namespace std;
OdString AboutColor(OdCmColor color);
bool EntryColorValue(OdCmColor& refColor, bool isAnyMethod = true);
OdString AboutTransparency(OdCmTransparency clarity);
bool EntryTransparencyValue(OdCmTransparency& refClarity, bool isAnyMethod = true);
OdString AboutDbObject(OdDbObjectId idObject);
OdDbObjectId EntryDictionaryObject(OdDbObjectId idOwner, OdDbObjectId idObject = OdDbObjectId::kNull);
OdDbObjectId EntryTableRecordObject(OdDbObjectId idTable, OdDbObjectId idRecord = OdDbObjectId::kNull);
void ModifyLayerProperties(OdDbLayerTableRecord* pLayer)
{
wchar_t comment[64], ch = L'\0';
OdInt16 index;
OdCmColor color;
OdCmTransparency clarity;
wcout << L"\nStart modifying of the layer properties";
do {
switch(ch)
{
case L'P': // Print the specific properties
case L'p':
PrintLayerProperties(pLayer);
wcout << L"\n";
break;
case L'W': // Set the lineweight
case L'w':
pLayer->setLineWeight(EntryLineWeightValue(pLayer->lineWeight()));
wcout << L"Lineweight is set to: " << AboutLineWeight(pLayer->lineWeight()) << L"\n";
break;
case L'D': // Set the description
case L'd':
wcin.sync();
wcout << L"\nDescription:>";
wcin.getline(comment, 64, 10);
pLayer->setDescription(comment);
wcout << L"Description is set to: \"" << pLayer->description() << L"\"\n";
break;
case L'L': // Set the lock status
case L'l':
wcout << "\nEntry the Lock status [L-lock|U-unlock]:>";
wcin >> ch;
if(ch == L'L' || ch == L'l') pLayer->setIsLocked(true);
else if(ch == L'U' || ch == L'u') pLayer->setIsLocked(false);
wcout << L"Status is set to: " << ((pLayer->isLocked()) ? L"Locked" : L"Unlocked") << L"\n";
break;
case L'A': // Set the plot status
case L'a':
wcout << "\nEntry the Plot status [P-plot|U-unplot]:>";
wcin >> ch;
if(ch == L'P' || ch == L'p') pLayer->setIsPlottable(true);
else if(ch == L'U' || ch == L'u') pLayer->setIsPlottable(false);
wcout << L"Status is set to: " << ((pLayer->isPlottable()) ? L"Plottable" : L"Unplottable") << L"\n";
break;
case L'O': // Set the on-off status
case L'o':
wcout << "\nEntry the On-Off status [F-turn off|N-turn on]:>";
wcin >> ch;
if(ch == L'F' || ch == L'f') pLayer->setIsOff(true);
else if(ch == L'N' || ch == L'n') pLayer->setIsOff(false);
wcout << L"Status is set to: " << ((pLayer->isOff()) ? L"OFF" : L"ON") << L"\n";
break;
case L'F': // Set the freeze status
case L'f':
wcout << "\nEntry the Freeze status [F-freeze|T-thaw]:>";
wcin >> ch;
if(ch == L'F' || ch == L'f') pLayer->setIsFrozen(true);
else if(ch == L'T' || ch == L't') pLayer->setIsFrozen(false);
wcout << L"Status is set to: " << ((pLayer->isFrozen()) ? L"Frozen" : L"Thawed") << L"\n";
break;
case L'H': // Set the hidden status
case L'h':
wcout << "\nEntry the Hidden status [H-hide|S-show]:>";
wcin >> ch;
if(ch == L'H' || ch == L'h') pLayer->setIsHidden(true);
else if(ch == L'S' || ch == L's') pLayer->setIsHidden(false);
wcout << L"Status is set to: " << ((pLayer->isHidden()) ? L"Hidden" : L"Shown") << L"\n";
break;
case L'R': // Set the reconcile status
case L'r':
wcout << "\nEntry the Reconcile status [R-reconcile|U-Unreconcile]:>";
wcin >> ch;
if(ch == L'R' || ch == L'r') pLayer->setIsReconciled(true);
else if(ch == L'U' || ch == L'u') pLayer->setIsReconciled(false);
wcout << L"Status is set to: " << ((pLayer->isReconciled()) ? L"Reconciled" : L"Unreconciled") << L"\n";
break;
case L'C': // Set the color value
case L'c':
color = pLayer->color();
if(EntryColorValue(color, false))
{
pLayer->setColor(color);
wcout << L"Color is set to: " << AboutColor(pLayer->color()) << L"\n";
}
break;
case L'I': // Set the color index
case L'i':
wcout << "\nCurrent color index: " << pLayer->colorIndex()
<< "\nEntry a new color index [1...255]:>";
wcin >> index;
if(!wcin.fail() && wcin.peek() == 10)
if(index >= 1 && index <= 255)
{
pLayer->setColorIndex(index);
wcout << L"Color is set to: " << AboutColor(pLayer->color()) << L"\n";
}
else wcout << L"Index is outside the scope 1...255\n";
else { wcin.clear(); wcout << L"Invalid entered index\n"; wcin.sync(); }
break;
case L'Y': // Set the linetype object
case L'y':
pLayer->setLinetypeObjectId( EntryTableRecordObject( pLayer->database()->getLayerTableId(),
pLayer->linetypeObjectId()) );
wcout << L"Linetype is set to: " << AboutDbObject(pLayer->linetypeObjectId()) << L"\n";
break;
case L'M': // Set the material object
case L'm':
pLayer->setMaterialId( EntryDictionaryObject( pLayer->database()->getMaterialDictionaryId(),
pLayer->materialId()) );
wcout << L"Material is set to: " << AboutDbObject(pLayer->materialId()) << L"\n";
break;
case L'T': // Set the transparency value
case L't':
clarity = pLayer->transparency();
if(EntryTransparencyValue(clarity, false))
{
pLayer->setTransparency(clarity, false);
wcout << L"Transparency is set to: " << AboutTransparency(pLayer->transparency()) << L"\n";
}
break;
case L'\0': // Skip an action
break;
default:
wcout << L"Incorrect operation\n";
}
wcout << L"\nSelected layer: \"" << pLayer->getName() << L"\"";
wcout << L"\nW. Set the lineweight";
wcout << L"\nD. Set the description";
wcout << L"\nL. Set the lock status";
wcout << L"\nA. Set the plot status";
wcout << L"\nO. Set the on-off status";
wcout << L"\nF. Set the freeze status";
wcout << L"\nH. Set the hidden status";
wcout << L"\nR. Set the reconcile status";
wcout << L"\nC. Set the color value";
wcout << L"\nI. Set the color index";
wcout << L"\nY. Set the linetype object";
wcout << L"\nM. Set the material object";
wcout << L"\nT. Set the transparency value";
wcout << L"\nP. Print the specific properties";
wcout << L"\nQ. Quit";
wcout << L"\nSelect operation:>";
wcin >> ch;
}
while(ch != L'Q' && ch != L'q');
wcout << L"Stop modifying of the layer properties\n";
}
Testing gives the following results:
Start modifying of the layer properties
Selected layer: "BasePlan"
W. Set the lineweight
D. Set the description
L. Set the lock status
A. Set the plot status
O. Set the on-off status
F. Set the freeze status
H. Set the hidden status
R. Set the reconcile status
C. Set the color value
I. Set the color index
Y. Set the linetype object
M. Set the material object
T. Set the transparency value
P. Print the specific properties
Q. Quit
Select operation:>
When the operation is P-"Print the specific properties":
H=3F
Name = "BasePlan"
Status: unerased,resident
Description: ""
Layer_Status: InUse, Thawed, ON, Unlocked, Plotable, Shown
Lineweight: [kLnWtByLwDefault]
Linetype: [16-"Continuous"-Linetype]
Material: [2E-"Global"-Material]
Color: [Foreground]
Transparency: [byAlpha=100.0%]
When the operation is D-"Set the description":
Description:>Base Plan of the Manufacture
Description is set to: "Base Plan of the Manufacture"
When the operation is W-"Set the lineweight":
Current lineweight value: kLnWtByLwDefault]
kLnWt000 = 0
kLnWt005 = 5
kLnWt009 = 9
kLnWt013 = 13
kLnWt015 = 15
kLnWt018 = 18
kLnWt020 = 20
kLnWt025 = 25
kLnWt030 = 30
kLnWt035 = 35
kLnWt040 = 40
kLnWt050 = 50
kLnWt053 = 53
kLnWt060 = 60
kLnWt070 = 70
kLnWt080 = 80
kLnWt090 = 90
kLnWt100 = 100
kLnWt106 = 106
kLnWt120 = 120
kLnWt140 = 140
kLnWt158 = 158
kLnWt200 = 200
kLnWt211 = 211
kLnWtByLayer = -1
kLnWtByBlock = -2
kLnWtByLwDefault = -3
Entry the line weight value:>20
Lineweight is set to: [kLnWt020=0.2mm]
When the operation is L-"Set the lock status":
Entry the Lock status [L-lock|U-unlock]:>L
Status is set to: Locked
When the operation is A-"Set the plot status":
Entry the Plot status [P-plot|U-unplot]:>U
Status is set to: Unplottable
When the operation is O-"Set the on-off status":
Entry the On-Off status [F-turn off|N-turn on]:>F
Status is set to: OFF
When the operation is F-"Set the freeze status":
Entry the Freeze status [F-freeze|T-thaw]:>F
Status is set to: Frozen
When the operation is H-"Set the hidden status":
Entry the Hidden status [H-hide|S-show]:>S
Status is set to: Shown
When the operation is I-"Set the color index":
Current color index: 7
Entry a new color index [1...255]:>15
Color is set to: [byACI=15]
When the operation is C-"Set the color value":
Start modifying of the color properties
Current color value: [C300000f] = [byACI=15]
R. Entry the RED color component
G. Entry the GREEN color component
B. Entry the BLUE color component
I. Entry the color INDEX
Q. Quit without saving
S. Save and Exit
Select operation:>R
Entry the RED component value [0...255]:>25
Current color value: [C2190000] = [byRGB(25,0,0)]
Select operation:>G
Entry the GREEN component value [0...255]:>36
Current color value: [C2192400] = [byRGB(25,36,0)]
Select operation:>B
Entry the BLUE component value [0...255]:>84
Current color value: [C2192454] = [byRGB(25,36,84)]
Select operation:>S
Stop modifying of the color properties
Color is set to: [byRGB(25,36,84)]
When the operation is T-"Set the transparency value":
Start modifying of the transparency properties
Current transparency value: [20000ff] = [byAlpha=100.0%]
A. Entry the Alpha value
P. Entry the Percent value
Q. Quit without saving
S. Save and Exit
Select operation:>T
Entry a value of transparency [0...255]:>128
Current transparency value: [2000080] = [byAlpha=50.2%]
Select operation:>S
Stop modifying of the transparency properties
Transparency is set to: [byAlpha=50.2%]
When the operation is Y-"Set the linetype object":
Select the Layer object:
14-"ByBlock"
15-"ByLayer"
16-"Continuous"
17-"DashDot"
Current: [16-"Continuous"]
Entry the name to be selected (or [?]-null/[:]-quit):>DashDot
Linetype is set to: [17-"DashDot"-Linetype]
When the operation is M-"Set the material object":
SList of the objects:
2C-"ByLayer"
2D-"ByBlock"
2E-"Global"
2F-"Stone"
30-"Tree"
Current: [3E-"Global"]
Entry the name to be selected (or [?]-null/[:]-quit):>Stone
Linetype is set to: [2F-"Stone"-Material]
When the operation is P-"Print the specific properties":
H=3F
Name = "BasePlan"
Status: unerased,resident,modified
Description: "Base Plan of the Manufacture"
Layer_Status: InUse, Frozen, OFF, Locked, Unplottable, Shown
Lineweight: [kLnWt020=0.2mm]
Linetype: [17-"DashDot"-Linetype]
Material: [2F-"Stone"-Material]
Color: [byRGB(25,36,84)]
Transparency: [byAlpha=50.2%]
Use the Q-"Quit" operation to exit:
Stop modifying of the layer properties
Example of Working with the Layer Table Object
Example of Using the Record-Table Interface for Selecting Objects
Example of Using the Dictionary Interface for Selecting Objects
Example of Using the Record–Table and Dictionary Interfaces for Getting Information about Objects
Example of Entering and Displaying for Color Objects
Example of Entering and Displaying for Transparency Objects
Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.
|