Skip to content

Commit f5e8bc8

Browse files
committed
Added ascii art
1 parent fb76e34 commit f5e8bc8

1 file changed

Lines changed: 41 additions & 28 deletions

File tree

ocaf_python.py

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,21 @@ def get_entry(label):
2828
entry = entry_str.ToCString()
2929
return entry
3030

31-
def get_name(label):
32-
"""Return name of label"""
33-
return label.GetLabelName()
34-
35-
36-
# Create an application and document with empty root_label
31+
# Create a document
3732
title = "Main document"
3833
doc = TDocStd_Document(TCollection_ExtendedString(title))
39-
app = XCAFApp_Application_GetApplication()
40-
app.NewDocument(TCollection_ExtendedString("MDTV-XCAF"), doc)
41-
shape_tool = XCAFDoc_DocumentTool_ShapeTool(doc.Main())
42-
color_tool = XCAFDoc_DocumentTool_ColorTool(doc.Main())
43-
# type(doc.Main()) = <class 'OCC.Core.TDF.TDF_Label'>
44-
# 0:1 doc.Main().EntryDumpToString()
45-
# 0:1:1 shape_tool is at this label entry
46-
# 0:1:2 color_tool at this entry
47-
# 0:1:1:1 create root_label at this entry
48-
root = shape_tool.NewShape()
49-
name = "Top" # name for root_label
50-
TDataStd_Name.Set(root, TCollection_ExtendedString(name))
34+
root = doc.Main()
35+
print(f"root entry : [{doc.Main().EntryDumpToString()}]")
36+
print(f"doc_root entry: [{doc.Main().Root().EntryDumpToString()}]")
5137

5238
# Tag
5339

5440
# Creating child labels using random delivery of tags
5541
child1 = TDF_TagSource.NewChild(root)
5642
child2 = TDF_TagSource.NewChild(root)
57-
print(get_entry(root)) # 0:1:1:1
58-
print(get_entry(child1)) # 0:1:1:1:1
59-
print(get_entry(child2)) # 0:1:1:1:2
43+
print(get_entry(root)) # 0:1
44+
print(get_entry(child1)) # 0:1:1
45+
print(get_entry(child2)) # 0:1:2
6046

6147
# Creation of a child label by user delivery from a tag
6248
a_child = root.FindChild(27, True) # new label is created
@@ -73,20 +59,44 @@ def get_name(label):
7359

7460
# Label creation
7561
root_label_depth = root.Depth()
76-
print(f"\n{root_label_depth = }") # 3
77-
print(f"root label entry is {get_entry(root)}\n") # 0:1:1:1
62+
print(f"\n{root_label_depth = }") # 1
63+
print(f"root label entry is {get_entry(root)}\n") # 0:1
7864

7965

8066
# Creating child labels
8167

82-
# creating a label with tag 10 at Root
83-
lab1 = doc.Main().Root().FindChild(10)
68+
# 0 : ( doc.Root() )
69+
# |
70+
# 0 : 1 (root)
71+
# | |
72+
# 0 : 1 : 1
73+
# | |
74+
# 0 : 1 : 2
75+
# | |
76+
# 0 : 1 : 3
77+
# | |
78+
# 0 : 1 : 27
79+
# |
80+
# 0 : 8 (lab1)
81+
# | |
82+
# 0 : 8 : 7 (lab2)
83+
# | |
84+
# 0 : 8 : 2 (lab3)
85+
# |
86+
# 0 : 3 (level1)
87+
# | |
88+
# 0 : 3 : 7 (level2)
89+
#
8490

85-
# creating labels 7 and 2 on label 10
91+
# creating a label with tag 8 at Root
92+
lab1 = doc.Main().Root().FindChild(8)
93+
print(f"Entry of lab1: {get_entry(lab1)}")
94+
95+
# creating labels 7 and 2 on label 8
8696
lab2 = lab1.FindChild(7)
8797
lab3 = lab1.FindChild(2)
8898

89-
level1 = root .FindChild(3)
99+
level1 = root.FindChild(3)
90100
level2 = level1.FindChild(1)
91101

92102
# Retrieving child labels
@@ -95,7 +105,7 @@ def get_name(label):
95105
print("Entries of children of root:")
96106
while itl.More():
97107
a_child = itl.Value()
98-
print(f"\t{get_name(a_child)} [{get_entry(a_child)}]")
108+
print(f"\t[{get_entry(a_child)}]")
99109
itl.Next()
100110

101111
# Retrieving the father label
@@ -146,3 +156,6 @@ def get_name(label):
146156
# Test again the attachment to a label
147157
nb_att = current.NbAttributes()
148158
print(f"The label has {nb_att} attribute(s) attached")
159+
160+
print(f"{get_entry(doc.Main()) = }")
161+
print(f"{get_entry(doc.Main().Root()) = }")

0 commit comments

Comments
 (0)