Represents a shape in the system. Wraps TopoDS_Shape.
| 424 | |
| 425 | |
| 426 | class Shape(object): |
| 427 | """ |
| 428 | Represents a shape in the system. Wraps TopoDS_Shape. |
| 429 | """ |
| 430 | |
| 431 | wrapped: TopoDS_Shape |
| 432 | forConstruction: bool |
| 433 | |
| 434 | def __init__(self, obj: TopoDS_Shape) -> None: |
| 435 | self.wrapped = downcast(obj) |
| 436 | |
| 437 | self.forConstruction = False |
| 438 | # Helps identify this solid through the use of an ID |
| 439 | self.label = "" |
| 440 | |
| 441 | def clean(self: T) -> T: |
| 442 | """Experimental clean using ShapeUpgrade""" |
| 443 | |
| 444 | upgrader = ShapeUpgrade_UnifySameDomain(self.wrapped, True, True, True) |
| 445 | upgrader.AllowInternalEdges(False) |
| 446 | upgrader.Build() |
| 447 | |
| 448 | return self.__class__(upgrader.Shape()) |
| 449 | |
| 450 | def fix(self: T) -> T: |
| 451 | """Try to fix shape if not valid""" |
| 452 | if not self.isValid(): |
| 453 | fixed = fix(self.wrapped) |
| 454 | |
| 455 | return self.__class__(fixed) |
| 456 | |
| 457 | return self |
| 458 | |
| 459 | @classmethod |
| 460 | def cast(cls, obj: TopoDS_Shape, forConstruction: bool = False) -> Shape: |
| 461 | "Returns the right type of wrapper, given a OCCT object" |
| 462 | |
| 463 | tr = None |
| 464 | |
| 465 | # define the shape lookup table for casting |
| 466 | constructor_LUT = { |
| 467 | ta.TopAbs_VERTEX: Vertex, |
| 468 | ta.TopAbs_EDGE: Edge, |
| 469 | ta.TopAbs_WIRE: Wire, |
| 470 | ta.TopAbs_FACE: Face, |
| 471 | ta.TopAbs_SHELL: Shell, |
| 472 | ta.TopAbs_SOLID: Solid, |
| 473 | ta.TopAbs_COMPSOLID: CompSolid, |
| 474 | ta.TopAbs_COMPOUND: Compound, |
| 475 | } |
| 476 | |
| 477 | t = shapetype(obj) |
| 478 | # NB downcast is needed to handle TopoDS_Shape types |
| 479 | tr = constructor_LUT[t](downcast(obj)) |
| 480 | tr.forConstruction = forConstruction |
| 481 | |
| 482 | return tr |
| 483 |
no outgoing calls