You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By studying the details of the data framework, one can get a pretty good idea how the "Nuts & Bolts" of the OCAF document works.
By using OCAF, apparently one can get access to lots of built-in functionality:
A built-in structure for managing the CAD model assembly structure
Undo / Redo
STEP file Load / Save
The ability to Copy / Paste chunks of the assembly structure
The ability to manage the evolution of shapes within the model
Native file format Load / Save
Create an empty document so we have something to work with
Start by importing some modules we will need
Then create an application and document with an empty label at root
fromOCC.Core.TCollectionimport (TCollection_AsciiString,
TCollection_ExtendedString)
fromOCC.Core.TDataStdimportTDataStd_Name, TDataStd_IntegerfromOCC.Core.TDocStdimportTDocStd_DocumentfromOCC.Core.TDFimport (TDF_Tool, TDF_TagSource,
TDF_ChildIterator,)
fromOCC.Core.XCAFAppimportXCAFApp_Application_GetApplicationfromOCC.Core.XCAFDocimport (XCAFDoc_DocumentTool_ColorTool,
XCAFDoc_DocumentTool_ShapeTool,)
# Create an application and document with empty root_labeltitle="Main document"doc=TDocStd_Document(TCollection_ExtendedString(title))
app=XCAFApp_Application_GetApplication()
app.NewDocument(TCollection_ExtendedString("MDTV-XCAF"), doc)
shape_tool=XCAFDoc_DocumentTool_ShapeTool(doc.Main())
color_tool=XCAFDoc_DocumentTool_ColorTool(doc.Main())
# type(doc.Main()) = <class 'OCC.Core.TDF.TDF_Label'># 0:1 doc.Main().EntryDumpToString()# 0:1:1 shape_tool is at this label entry# 0:1:2 color_tool at this entry# 0:1:1:1 create root_label at this entryroot=shape_tool.NewShape()
name="Top"# name for root_labelTDataStd_Name.Set(root, TCollection_ExtendedString(name))
This is where actual C++ code examples start to be presented.
Here is the corresponding Python code
# Tag# Creating child labels using random delivery of tagschild1=TDF_TagSource.NewChild(root)
child2=TDF_TagSource.NewChild(root)
print(get_entry(root)) # 0:1:1:1print(get_entry(child1)) # 0:1:1:1:1print(get_entry(child2)) # 0:1:1:1:2# Creation of a child label by user delivery from a taga_child=root.FindChild(27, True) # new label is createdifnota_child.IsNull():
tag=a_child.Tag()
print(f"{tag=}")
a_child=root.FindChild(27, False) # new label is not createdifnota_child.IsNull():
a_tag=a_child.Tag()
print(f"{a_tag=}") # But it is still found
# Label# Label creationroot_label_depth=root.Depth()
print(f"\n{root_label_depth=}") # 3print(f"root label entry is {get_entry(root)}\n") # 0:1:1:1# Creating child labels# creating a label with tag 10 at Rootlab1=doc.Main().Root().FindChild(10)
# creating labels 7 and 2 on label 10lab2=lab1.FindChild(7)
lab3=lab1.FindChild(2)
level1=root .FindChild(3)
level2=level1.FindChild(1)
# Retrieving child labelsitl=TDF_ChildIterator()
itl.Initialize(root)
print("Entries of children of root:")
whileitl.More():
a_child=itl.Value()
print(f"\t{get_name(a_child)} [{get_entry(a_child)}]")
itl.Next()
# Retrieving the father labelfather=lab3.Father()
print(f"father of lab3 is {get_entry(father)}")
isroot=father.IsRoot()
print(f"father is root: {isroot}")
father=lab1.Father()
print(f"father of lab1 is {get_entry(father)}")
isroot=father.IsRoot()
print(f"father is root: {isroot}")
# Attribute# Retrieving an attribute from a labelcurrent=level1INT=TDataStd_Integer()
ifcurrent.FindAttribute(TDataStd_Integer.GetID(), INT):
print("Found it")
else:
print("Didn't find it")
# Identifying an attribute using a GUIDguid=INT.ID()
print(f"{current=}") # <class 'TDF_Label'>print(f"{INT=}") # <class 'TDataStd_Integer'>print(f"{guid=}") # <class 'Standard_GUID'># Attaching an attribute to a labelcurrent.AddAttribute(INT)
attach=INT.Label()
print(f"{attach=}") # <class 'TDF_Label'># Try again to retrieve an attribute from a labelifcurrent.FindAttribute(TDataStd_Integer.GetID(), INT):
print("Found it")
else:
print("Didn't find it")
# Testing the attachment to a labelifcurrent.HasAttribute():
nb_att=current.NbAttributes()
print(f"The label has {nb_att} attribute(s) attached")
# Removing an attribute from a labelcurrent.ForgetAttribute(guid)
# Test again the attachment to a labelnb_att=current.NbAttributes()
print(f"The label has {nb_att} attribute(s) attached")
What's next?
Keep going...
Eventually, I want to learn how to use TNaming_NamedShape (instead of how I am currently doing it with doc.replace_shape())
I am thinking that the bottle build would be a nice project to practice this on.