A shared context for modeling. All objects in the same CQ chain share a reference to this same object instance which allows for shared state when needed.
| 71 | |
| 72 | |
| 73 | class CQContext(object): |
| 74 | """ |
| 75 | A shared context for modeling. |
| 76 | |
| 77 | All objects in the same CQ chain share a reference to this same object instance |
| 78 | which allows for shared state when needed. |
| 79 | """ |
| 80 | |
| 81 | pendingWires: List[Wire] |
| 82 | pendingEdges: List[Edge] |
| 83 | firstPoint: Optional[Vector] |
| 84 | tolerance: float |
| 85 | tags: Dict[str, "Workplane"] |
| 86 | |
| 87 | def __init__(self): |
| 88 | self.pendingWires = ( |
| 89 | [] |
| 90 | ) # a list of wires that have been created and need to be extruded |
| 91 | # a list of created pending edges that need to be joined into wires |
| 92 | self.pendingEdges = [] |
| 93 | # a reference to the first point for a set of edges. |
| 94 | # Used to determine how to behave when close() is called |
| 95 | self.firstPoint = None |
| 96 | self.tolerance = 0.0001 # user specified tolerance |
| 97 | self.tags = {} |
| 98 | |
| 99 | def popPendingEdges(self, errorOnEmpty: bool = True) -> List[Edge]: |
| 100 | """ |
| 101 | Get and clear pending edges. |
| 102 | |
| 103 | :raises ValueError: if errorOnEmpty is True and no edges are present. |
| 104 | """ |
| 105 | if errorOnEmpty and not self.pendingEdges: |
| 106 | raise ValueError("No pending edges present") |
| 107 | out = self.pendingEdges |
| 108 | self.pendingEdges = [] |
| 109 | return out |
| 110 | |
| 111 | def popPendingWires(self, errorOnEmpty: bool = True) -> List[Wire]: |
| 112 | """ |
| 113 | Get and clear pending wires. |
| 114 | |
| 115 | :raises ValueError: if errorOnEmpty is True and no wires are present. |
| 116 | """ |
| 117 | if errorOnEmpty and not self.pendingWires: |
| 118 | raise ValueError("No pending wires present") |
| 119 | out = self.pendingWires |
| 120 | self.pendingWires = [] |
| 121 | return out |
| 122 | |
| 123 | |
| 124 | class Workplane(object): |