def make_drawer_box(dx, dy, dz, separator_offsets): """Makes a box to contain simple drawers. Args: dx (float): The total outer width of the drawer box dy (float): The total outer depth of the drawer box dz (float): The total outer height of the drawer box separator_offsets (List[float]): The distance from the outer bottom of the drawer box to the top of each drawer separator. Returns: A TopoDS_Compound representing the drawer box. """ pieces = [ _make_side(dx, dy, dz, separator_offsets, True), _make_side(dx, dy, dz, separator_offsets, False), _make_topbottom(dx, dy, dz, True), _make_topbottom(dx, dy, dz, False), _make_back(dx, dy, dz) ] for separator_offset in separator_offsets: pieces.append(_make_separator(dx, dy, separator_offset)) builder = TopoDS_Builder() compound = TopoDS_Compound() builder.MakeCompound(compound) for piece in pieces: builder.Add(compound, piece) return compound
def _combine(*components): builder = TopoDS_Builder() compound = TopoDS_Compound() builder.MakeCompound(compound) for c in components: builder.Add(compound, c) return compound
def make_drawers(dx, dy, dz, arrangement): air_space = 0.05 available_z_space = dz - THICKNESS_0 * (len(arrangement) + 1) drawer_space_height = available_z_space / len(arrangement) drawer_depth = dy - BACK_INSET - THICKNESS_1 offsets = [] for i in range(len(arrangement) - 1): offsets.append(THICKNESS_0 + (i + 1) * (drawer_space_height + THICKNESS_0)) drawer_box = make_drawer_box(dx, dy, dz, offsets) drawers = [] for level, num_drawers in enumerate(arrangement): drawer_width = (dx - THICKNESS_0 * 2 - (num_drawers + 1) * air_space) / float(num_drawers) z_pos = dz - (level + 1) * (THICKNESS_0 + drawer_space_height) + air_space for drawer_index in range(num_drawers): drawer = make_drawer(drawer_width, drawer_depth, drawer_space_height - 2 * air_space) _move( drawer, THICKNESS_0 + air_space + (air_space + drawer_width) * drawer_index, 0, z_pos) drawers.append(drawer) builder = TopoDS_Builder() compound = TopoDS_Compound() builder.MakeCompound(compound) builder.Add(compound, drawer_box) for drawer in drawers: builder.Add(compound, drawer) return compound
def extrudeLinearWithRotation(cls, outerWire, innerWires, vecCenter, vecNormal, angleDegrees): """ Creates a 'twisted prism' by extruding, while simultaneously rotating around the extrusion vector. Though the signature may appear to be similar enough to extrudeLinear to merit combining them, the construction methods used here are different enough that they should be separate. At a high level, the steps followed are: (1) accept a set of wires (2) create another set of wires like this one, but which are transformed and rotated (3) create a ruledSurface between the sets of wires (4) create a shell and compute the resulting object :param outerWire: the outermost wire, a cad.Wire :param innerWires: a list of inner wires, a list of cad.Wire :param vecCenter: the center point about which to rotate. the axis of rotation is defined by vecNormal, located at vecCenter. ( a cad.Vector ) :param vecNormal: a vector along which to extrude the wires ( a cad.Vector ) :param angleDegrees: the angle to rotate through while extruding :return: a cad.Solid object """ # make straight spine straight_spine_e = Edge.makeLine(vecCenter, vecCenter.add(vecNormal)) straight_spine_w = Wire.combine([ straight_spine_e, ]).wrapped # make an auxliliary spine pitch = 360. / angleDegrees * vecNormal.Length radius = 1 aux_spine_w = Wire.makeHelix(pitch, vecNormal.Length, radius, center=vecCenter, dir=vecNormal).wrapped # extrude the outer wire outer_solid = cls._extrudeAuxSpine(outerWire.wrapped, straight_spine_w, aux_spine_w) # extrude inner wires inner_solids = [ cls._extrudeAuxSpine(w.wrapped, straight_spine_w.aux_spine_w) for w in innerWires ] # combine dthe inner solids into compund inner_comp = TopoDS_Compound() comp_builder = TopoDS_Builder() comp_builder.MakeCompound(inner_comp) # TODO this could be not needed for i in inner_solids: comp_builder.Add(inner_comp, i) # subtract from the outer solid return cls(BRepAlgoAPI_Cut(outer_solid, inner_comp).Shape())
def makeShell(cls, listOfFaces): shell_wrapped = TopoDS_Shell() shell_builder = TopoDS_Builder() shell_builder.MakeShell(shell_wrapped) for face in listOfFaces: shell_builder.Add(face.wrapped) return cls(shell_wrapped)
def testTopoDS_byref_arguments(self): ''' Test byref pass arguments to TopoDS ''' cyl1 = BRepPrimAPI_MakeCylinder(10., 10.).Shape() cyl2 = BRepPrimAPI_MakeCylinder(100., 50.).Shape() c = TopoDS_Compound() bb = TopoDS_Builder() bb.MakeCompound(c) for child in [cyl1, cyl2]: bb.Add(c, child)
def compound(topo): """ accumulate a bunch of TopoDS_* in list `topo` to a TopoDS_Compound @param topo: list of TopoDS_* instances """ bd = TopoDS_Builder() comp = TopoDS_Compound() bd.MakeCompound(comp) for i in topo: bd.Add(comp, i) return comp
def makeCompound(cls, listOfShapes): """ Create a compound out of a list of shapes """ comp = TopoDS_Compound() comp_builder = TopoDS_Builder() comp_builder.MakeCompound(comp) # TODO this could be not needed for s in listOfShapes: comp_builder.Add(comp, s.wrapped) return cls(comp)
def make_drawer(dx, dy, dz): pieces = [ _make_side(dx, dy, dz, True), _make_side(dx, dy, dz, False), _make_end(dx, dy, dz, True), _make_end(dx, dy, dz, False), _make_bottom(dx, dy) ] builder = TopoDS_Builder() compound = TopoDS_Compound() builder.MakeCompound(compound) for piece in pieces: builder.Add(compound, piece) return compound
def GenerateStruct(self, ChordFactor, ScaleFactor): from OCC.TopoDS import TopoDS_Builder, TopoDS_Compound, TopoDS_Shape, TopoDS_HShape x0 = [ChordFactor, ScaleFactor] SectionRibs, RibFace = self._BuildRibs(*x0) LSparLEFullWing, LSparTEFullWing, LSparMIDFullWing, StringerUpFullWing, StringerDownFullWing, PointsFullwingUp, PointsFullWingDown = self._BuildSpars( *x0) PanelUp, PanelDown = self._BuildPanels(*x0) builder = TopoDS_Builder() # Add Ribs Ribs = TopoDS_Compound() builder.MakeCompound(Ribs) for g in RibFace: builder.Add(Ribs, g) self.AddComponent(Ribs, 'Ribs') ##Add Spars Spars = TopoDS_Compound() builder.MakeCompound(Spars) SparsLEMIDTE = LSparLEFullWing + LSparMIDFullWing + LSparTEFullWing for h in SparsLEMIDTE: builder.Add(Spars, h) self.AddComponent(Spars, 'Spars') #Add Stringers Stringers = TopoDS_Compound() builder.MakeCompound(Stringers) for p in xrange(self.NoStiffners * self.SegmentNoLoft): p1 = StringerUpFullWing[p] p2 = StringerDownFullWing[p] builder.Add(Stringers, p1) builder.Add(Stringers, p2) self.AddComponent(Stringers, 'Stringers') #Add Panels Panels = TopoDS_Compound() builder.MakeCompound(Panels) for h in xrange(len(PanelUp)): h1 = PanelUp[h] h2 = PanelDown[h] builder.Add(Panels, h1) builder.Add(Panels, h2) self.AddComponent(Panels, 'Panels') vec = gp_Vec(gp_Pnt(-0.5, 0., 0.), self.ApexPoint) self.TranslateComponents(vec) return None
def test_default_constructor_DEFINE_STANDARD_ALLOC(self): ''' OCE classes the defines standard alllocator can be instanciated if they're not abstract nor define any protected or private constructor ''' BRep_Builder() TopoDS_Builder() ShapeAnalysis_Curve()
def testProtectedConstructor(self): ''' test if the classes with protected constructors can be created ''' print 'Test: protected constructor' # 1st, class with no subclass from OCC.TopoDS import TopoDS_Builder tds_builder = TopoDS_Builder() self.assertTrue(hasattr(tds_builder, "MakeCompound"))
def _make_table(): builder = TopoDS_Builder() compound = TopoDS_Compound() builder.MakeCompound(compound) table_top = _box(SPECS.length, SPECS.width, TABLE_THICKNESS) _move(table_top, 0, 0, PEDESTAL_HEIGHT) builder.Add(compound, table_top) for i in range(4): pedestal = _box(SPECS.pedestal_thickness, SPECS.pedestal_width, PEDESTAL_HEIGHT) if i < 2: x = SPECS.pedestal_inset else: x = SPECS.length - SPECS.pedestal_inset - SPECS.pedestal_thickness if i % 2 == 0: y = (SPECS.width + SPECS.pedestal_gap) / 2 else: y = (SPECS.width - SPECS.pedestal_gap) / 2 - SPECS.pedestal_width _move(pedestal, x, y, 0.) builder.Add(compound, pedestal) return compound
def testProtectedConstructor(self): """ Test: protected constructor """ # 1st, class with no subclass from OCC.TopoDS import TopoDS_Builder tds_builder = TopoDS_Builder() self.assertTrue(hasattr(tds_builder, "MakeCompound"))
def GenerateLiftingSurface(self, ChordFactor, ScaleFactor): from OCC.TopoDS import TopoDS_Builder, TopoDS_Compound, TopoDS_Shape, TopoDS_HShape """Builds a lifting surface (wing, tailplane, etc.) with the Chord and Scale factors defined in inputs If OptimizeChordScale was specified on construction of this LiftingSurface class, an optimized ChordFactor and ScaleFactor is found instead, with the local search started from the two given values. Parameters ---------- ChordFactor : scalar The scaling factor to apply in the chordwise direction ScaleFactor : scalar the scaling factor to apply uniformly in all directions Returns ------- None Notes ----- Called on initialisation of a lifting surface class. Adds a ('Surface': Shape) key value pair to self. :Example: >>> Wing = liftingsurface.LiftingSurface(P, mySweepAngleFunction, myDihedralFunction, myTwistFunction, myChordFunction, myAirfoilFunction) >>> Surface = Wing['Surface'] See Also -------- airconics.examples.wing_example_transonic_airliner """ x0 = [ChordFactor, ScaleFactor] LS, ActualSemiSpan, LSP_area, AR, WingTip = \ self._BuildLS(*x0) PointsSurfUp, PointsSurfDown = self._BuildSurfacePoints(*x0) # Update instance components: self.AddComponent(LS, 'SurfaceLoft') builder = TopoDS_Builder() PointsUp = TopoDS_Compound() builder.MakeCompound(PointsUp) PointsDown = TopoDS_Compound() builder.MakeCompound(PointsDown) for g in PointsSurfUp: builder.Add(PointsUp, g) self.AddComponent(PointsUp, 'PointsSurfUp') for gg in PointsSurfDown: builder.Add(PointsDown, gg) self.AddComponent(PointsDown, 'PointsSurfDown') # Position the Components at the apex: vec = gp_Vec(gp_Pnt(0., 0., 0.), self.ApexPoint) self.TranslateComponents(vec) return None