Core: Generation of python bindings for Assembly (#22574)

* adding XML, CmakeLists, and interfaces.

* removing Dict, List from typing imports.

* Normalizing imports.
This commit is contained in:
Ian Abreu
2025-08-04 11:36:22 -04:00
committed by GitHub
parent 837ccef6f4
commit 0e4dbbe8d2
9 changed files with 343 additions and 64 deletions

View File

@@ -0,0 +1,23 @@
from typing import Final
from Base.Metadata import export
from App.Part import Part
@export(
Father="PartPy",
Name="AssemblyLinkPy",
Twin="AssemblyLink",
TwinPointer="AssemblyLink",
Include="Mod/Assembly/App/AssemblyLink.h",
Namespace="Assembly",
FatherInclude="App/PartPy.h",
FatherNamespace="App",
)
class AssemblyLinkPy(Part):
"""
This class handles document objects in Assembly
"""
Joints: Final[list]
"""A list of all joints this assembly link has."""

View File

@@ -0,0 +1,158 @@
from typing import Any, Final
from Base.Metadata import constmethod, export
from App.Part import Part
@export(
Father="PartPy",
Name="AssemblyObjectPy",
Twin="AssemblyObject",
TwinPointer="AssemblyObject",
Include="Mod/Assembly/App/AssemblyObject.h",
Namespace="Assembly",
FatherInclude="App/PartPy.h",
FatherNamespace="App",
)
class AssemblyObjectPy(Part):
"""
This class handles document objects in Assembly
"""
@constmethod
def solve(self) -> Any:
"""Solve the assembly and update part placements.
solve(enableRedo=False) -> int
Args:
enableRedo: Whether the solve save the initial position of parts
to enable undoing it even without a transaction.
Defaults to `False` ie the solve cannot be undone if called
outside of a transaction.
Returns:
0 in case of success, otherwise the following codes in this order of
priority:
-6 if no parts are fixed.
-4 if over-constrained,
-3 if conflicting constraints,
-5 if malformed constraints
-1 if solver error,
-2 if redundant constraints."""
...
@constmethod
def generateSimulation(self) -> Any:
"""Generate the simulation.
solve(simulationObject) -> int
Args:
simulationObject: The simulation Object.
Returns:
0 in case of success, otherwise the following codes in this order of
priority:
-6 if no parts are fixed.
-4 if over-constrained,
-3 if conflicting constraints,
-5 if malformed constraints
-1 if solver error,
-2 if redundant constraints."""
...
@constmethod
def updateForFrame(self) -> Any:
"""Update entire assembly to frame number specified.
updateForFrame(index)
Args: index of frame.
Returns: None"""
...
@constmethod
def numberOfFrames(self) -> Any:
"""numberOfFrames()
Args: None
Returns: Number of frames"""
...
@constmethod
def undoSolve(self) -> Any:
"""Undo the last solve of the assembly and return part placements to their initial position.
undoSolve()
Returns: None"""
...
@constmethod
def ensureIdentityPlacements(self) -> Any:
"""Makes sure that LinkGroups or sub-assemblies have identity placements.
ensureIdentityPlacements()
Returns: None"""
...
@constmethod
def clearUndo(self) -> Any:
"""Clear the registered undo positions.
clearUndo()
Returns: None"""
...
@constmethod
def isPartConnected(self) -> Any:
"""Check if a part is connected to the ground through joints.
isPartConnected(obj) -> bool
Args: document object to check.
Returns: True if part is connected to ground"""
...
@constmethod
def isJointConnectingPartToGround(self) -> Any:
"""Check if a joint is connecting a part to the ground.
isJointConnectingPartToGround(joint, propName) -> bool
Args:
- joint: document object of the joint to check.
- propName: string 'Part1' or 'Part2' of the joint.
Returns: True if part is connected to ground"""
...
@constmethod
def isPartGrounded(self) -> Any:
"""Check if a part has a grounded joint.
isPartGrounded(obj) -> bool
Args:
- obj: document object of the part to check.
Returns: True if part has grounded joint"""
...
@constmethod
def exportAsASMT(self) -> Any:
"""Export the assembly in a text format called ASMT.
exportAsASMT(fileName:str)
Args:
fileName: The name of the file where the ASMT will be exported."""
...
Joints: Final[list]
"""A list of all joints this assembly has."""

View File

@@ -16,158 +16,158 @@
<Methode Name="solve" Const="true">
<Documentation>
<UserDocu>
Solve the assembly and update part placements.
Solve the assembly and update part placements.
solve(enableRedo=False) -> int
solve(enableRedo=False) -> int
Args:
enableRedo: Whether the solve save the initial position of parts
to enable undoing it even without a transaction.
Defaults to `False` ie the solve cannot be undone if called
outside of a transaction.
Args:
enableRedo: Whether the solve save the initial position of parts
to enable undoing it even without a transaction.
Defaults to `False` ie the solve cannot be undone if called
outside of a transaction.
Returns:
0 in case of success, otherwise the following codes in this order of
priority:
-6 if no parts are fixed.
-4 if over-constrained,
-3 if conflicting constraints,
-5 if malformed constraints
-1 if solver error,
-2 if redundant constraints.
Returns:
0 in case of success, otherwise the following codes in this order of
priority:
-6 if no parts are fixed.
-4 if over-constrained,
-3 if conflicting constraints,
-5 if malformed constraints
-1 if solver error,
-2 if redundant constraints.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="generateSimulation" Const="true">
<Documentation>
<UserDocu>
Generate the simulation.
Generate the simulation.
solve(simulationObject) -> int
solve(simulationObject) -> int
Args:
simulationObject: The simulation Object.
Args:
simulationObject: The simulation Object.
Returns:
0 in case of success, otherwise the following codes in this order of
priority:
-6 if no parts are fixed.
-4 if over-constrained,
-3 if conflicting constraints,
-5 if malformed constraints
-1 if solver error,
-2 if redundant constraints.
Returns:
0 in case of success, otherwise the following codes in this order of
priority:
-6 if no parts are fixed.
-4 if over-constrained,
-3 if conflicting constraints,
-5 if malformed constraints
-1 if solver error,
-2 if redundant constraints.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="updateForFrame" Const="true">
<Documentation>
<UserDocu>
Update entire assembly to frame number specified.
Update entire assembly to frame number specified.
updateForFrame(index)
updateForFrame(index)
Args: index of frame.
Args: index of frame.
Returns: None
Returns: None
</UserDocu>
</Documentation>
</Methode>
<Methode Name="numberOfFrames" Const="true">
<Documentation>
<UserDocu>
numberOfFrames()
numberOfFrames()
Args: None
Args: None
Returns: Number of frames
Returns: Number of frames
</UserDocu>
</Documentation>
</Methode>
<Methode Name="undoSolve" Const="true">
<Documentation>
<UserDocu>
Undo the last solve of the assembly and return part placements to their initial position.
Undo the last solve of the assembly and return part placements to their initial position.
undoSolve()
undoSolve()
Returns: None
Returns: None
</UserDocu>
</Documentation>
</Methode>
<Methode Name="ensureIdentityPlacements" Const="true">
<Documentation>
<UserDocu>
Makes sure that LinkGroups or sub-assemblies have identity placements.
Makes sure that LinkGroups or sub-assemblies have identity placements.
ensureIdentityPlacements()
ensureIdentityPlacements()
Returns: None
Returns: None
</UserDocu>
</Documentation>
</Methode>
<Methode Name="clearUndo" Const="true">
<Documentation>
<UserDocu>
Clear the registered undo positions.
Clear the registered undo positions.
clearUndo()
clearUndo()
Returns: None
Returns: None
</UserDocu>
</Documentation>
</Methode>
<Methode Name="isPartConnected" Const="true">
<Documentation>
<UserDocu>
Check if a part is connected to the ground through joints.
Check if a part is connected to the ground through joints.
isPartConnected(obj) -> bool
isPartConnected(obj) -> bool
Args: document object to check.
Args: document object to check.
Returns: True if part is connected to ground
Returns: True if part is connected to ground
</UserDocu>
</Documentation>
</Methode>
<Methode Name="isJointConnectingPartToGround" Const="true">
<Documentation>
<UserDocu>
Check if a joint is connecting a part to the ground.
Check if a joint is connecting a part to the ground.
isJointConnectingPartToGround(joint, propName) -> bool
isJointConnectingPartToGround(joint, propName) -> bool
Args:
- joint: document object of the joint to check.
- propName: string 'Part1' or 'Part2' of the joint.
Args:
- joint: document object of the joint to check.
- propName: string 'Part1' or 'Part2' of the joint.
Returns: True if part is connected to ground
Returns: True if part is connected to ground
</UserDocu>
</Documentation>
</Methode>
<Methode Name="isPartGrounded" Const="true">
<Documentation>
<UserDocu>
Check if a part has a grounded joint.
Check if a part has a grounded joint.
isPartGrounded(obj) -> bool
isPartGrounded(obj) -> bool
Args:
- obj: document object of the part to check.
Args:
- obj: document object of the part to check.
Returns: True if part has grounded joint
Returns: True if part has grounded joint
</UserDocu>
</Documentation>
</Methode>
<Methode Name="exportAsASMT" Const="true">
<Documentation>
<UserDocu>
Export the assembly in a text format called ASMT.
Export the assembly in a text format called ASMT.
exportAsASMT(fileName:str)
exportAsASMT(fileName:str)
Args:
fileName: The name of the file where the ASMT will be exported.
Args:
fileName: The name of the file where the ASMT will be exported.
</UserDocu>
</Documentation>
</Methode>

View File

@@ -0,0 +1,18 @@
from Base.Metadata import export
from App.DocumentObjectGroup import DocumentObjectGroup
@export(
Father="DocumentObjectGroupPy",
Name="BomGroupPy",
Twin="BomGroup",
TwinPointer="BomGroup",
Include="Mod/Assembly/App/BomGroup.h",
Namespace="Assembly",
FatherInclude="App/DocumentObjectGroupPy.h",
FatherNamespace="App",
)
class BomGroupPy(DocumentObjectGroup):
"""
This class is a group subclass for boms.
"""

View File

@@ -0,0 +1,17 @@
from Base.Metadata import export
from Spreadsheet.Sheet import Sheet
@export(
Father="SheetPy",
Name="BomObjectPy",
Twin="BomObject",
TwinPointer="BomObject",
Include="Mod/Assembly/App/BomObject.h",
Namespace="Assembly",
FatherInclude="Mod/Spreadsheet/App/SheetPy.h",
FatherNamespace="Spreadsheet",
)
class BomObjectPy(Sheet):
"""
This class is the BOM object of assemblies, it derives from Spreadsheet::Sheet.
"""

View File

@@ -22,6 +22,15 @@ generate_from_xml(JointGroupPy)
generate_from_xml(ViewGroupPy)
generate_from_xml(SimulationGroupPy)
generate_from_py_(AssemblyObjectPy)
generate_from_py_(AssemblyLinkPy)
generate_from_py_(BomObjectPy)
generate_from_py_(BomGroupPy)
generate_from_py_(JointGroupPy)
generate_from_py_(ViewGroupPy)
generate_from_py_(SimulationGroupPy)
SET(Python_SRCS
AssemblyObjectPy.xml
AssemblyObjectPyImp.cpp

View File

@@ -0,0 +1,18 @@
from Base.Metadata import export
from App.DocumentObjectGroup import DocumentObjectGroup
@export(
Father="DocumentObjectGroupPy",
Name="JointGroupPy",
Twin="JointGroup",
TwinPointer="JointGroup",
Include="Mod/Assembly/App/JointGroup.h",
Namespace="Assembly",
FatherInclude="App/DocumentObjectGroupPy.h",
FatherNamespace="App",
)
class JointGroupPy(DocumentObjectGroup):
"""
This class is a group subclass for joints.
"""

View File

@@ -0,0 +1,18 @@
from Base.Metadata import export
from App.DocumentObjectGroup import DocumentObjectGroup
@export(
Father="DocumentObjectGroupPy",
Name="SimulationGroupPy",
Twin="SimulationGroup",
TwinPointer="SimulationGroup",
Include="Mod/Assembly/App/SimulationGroup.h",
Namespace="Assembly",
FatherInclude="App/DocumentObjectGroupPy.h",
FatherNamespace="App",
)
class SimulationGroupPy(DocumentObjectGroup):
"""
This class is a group subclass for joints.
"""

View File

@@ -0,0 +1,18 @@
from Base.Metadata import export
from App.DocumentObjectGroup import DocumentObjectGroup
@export(
Father="DocumentObjectGroupPy",
Name="ViewGroupPy",
Twin="ViewGroup",
TwinPointer="ViewGroup",
Include="Mod/Assembly/App/ViewGroup.h",
Namespace="Assembly",
FatherInclude="App/DocumentObjectGroupPy.h",
FatherNamespace="App",
)
class ViewGroupPy(DocumentObjectGroup):
"""
This class is a group subclass for joints.
"""