Exemple #1
0
	def CreateShape(self):
		endcap1 = occprim.BRepPrimAPI_MakeSphere(gp_Pnt(0,0,0),self.radius).Shape()
		endcap2 = occprim.BRepPrimAPI_MakeSphere(gp_Pnt(0,0,self.length),self.radius).Shape()
		body = occprim.BRepPrimAPI_MakeCylinder(self.radius,self.length).Shape()
		self.occ_shape = occalgo.BRepAlgoAPI_Fuse(endcap1,body).Shape()
		self.occ_shape = occalgo.BRepAlgoAPI_Fuse(self.occ_shape,endcap2).Shape()
		T = gp_Trsf()
		T.SetTranslation(gp_Vec(0,0,-self.length/2))
		self.occ_shape = occbuild.BRepBuilderAPI_Transform(self.occ_shape,T,False).Shape()
		self.OrientShape()
Exemple #2
0
	def CreateShape(self):
		self.occ_shape = self.elements[0].occ_shape
		if self.elements[0].complement:
			print('ERROR: complementary shape cannot be first in list')
			exit(1)
		for s in self.elements:
			if s.occ_shape!=self.occ_shape:
				if s.complement:
					self.occ_shape = occalgo.BRepAlgoAPI_Cut(self.occ_shape,s.occ_shape).Shape()
				else:
					self.occ_shape = occalgo.BRepAlgoAPI_Common(self.occ_shape,s.occ_shape).Shape()
		self.OrientShape()
Exemple #3
0
    def makeSection2(self, cuttingPlane, shapeToSection, zLevel):
        """
            Uses BrepSection Algo. this generally returns a list of wires, not a face      
        """
        #section is certainly faster, but produces only edges.
        #those have to be re-organized into wires, probably
        #using ShapeAnalysis_WireOrder

        face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(cuttingPlane).Shape()
        # Computes Shape/Plane intersection
        section = BRepAlgoAPI.BRepAlgoAPI_Section(self.solid.shape, face)
        #section = BRepAlgo.BRepAlgo_Section(self.solid.shape,face);
        section.Build()
        if section.IsDone():
            #Topology.dumpTopology(section.Shape());

            #what we got back was a compound of edges
            t = Topo(section.Shape())
            wb = OCCUtil.MultiWireBuilder()
            for e in t.edges():
                wb.addEdge(e)
            wires = wb.getWires()
            print wires
            for w in wires:
                Topology.dumpTopology(w)
            return wires
        else:
            raise Exception("Could not compute Section!")
Exemple #4
0
def drillWithHoles(shape):
    "returns a shape with a bunch of spheres removed from it"
    box = Bnd.Bnd_Box()
    b = BRepBndLib.BRepBndLib()
    b.Add(shape, box)

    cShape = shape
    (xMin, yMin, zMin, xMax, yMax, zMax) = box.Get()

    d = 0.05 * ((xMax - xMin))
    di = 4.0 * d
    c = 0

    #drill holes in a rectangular grid
    for x in frange6(xMin, xMax, di):
        for y in frange6(yMin, yMax, di):
            for z in frange6(zMin, zMax, di):
                c += 1
                print "Inter %d " % c
                #make a sphere
                center = gp.gp_Pnt(x, y, z)
                hole = BRepPrimAPI.BRepPrimAPI_MakeSphere(center, d).Shape()
                cut = BRepAlgoAPI.BRepAlgoAPI_Cut(cShape, hole)
                cut.SetOperation(3)
                #3 is cut21
                tmp = cut.Shape()
                #store the newly cut shape
                if cut.ErrorStatus() != 0:
                    print "Error %d cutting" % cut.ErrorStatus()
                else:
                    print "Success!"
                    cShape = tmp
    return cShape
Exemple #5
0
 def CreateShape(self):
     self.occ_shape = self.elements[0].occ_shape
     for s in self.elements:
         if s.occ_shape != self.occ_shape:
             self.occ_shape = occalgo.BRepAlgoAPI_Fuse(
                 self.occ_shape, s.occ_shape).Shape()
     self.OrientShape()
Exemple #6
0
	def CreateShape(self):
		outer = occprim.BRepPrimAPI_MakeCylinder(self.outer_radius,self.length).Shape()
		inner = occprim.BRepPrimAPI_MakeCylinder(self.inner_radius,self.length).Shape()
		self.occ_shape = occalgo.BRepAlgoAPI_Cut(outer,inner).Shape()
		T = gp_Trsf()
		T.SetTranslation(gp_Vec(0,0,-self.length/2))
		self.occ_shape = occbuild.BRepBuilderAPI_Transform(self.occ_shape,T,False).Shape()
		self.OrientShape()
Exemple #7
0
    def _makeSlice(self, shapeToSlice, zLevel):

        s = Slice()

        #used to determine if a slice is identical to others.
        s.hatchDir = self.hatchReversed
        s.fillWidth = self.options.filling.fillWidth

        #change if layers are variable thickness
        s.sliceHeight = self.options.layerHeight
        s.zLevel = zLevel

        #make a cutting plane
        p = gp.gp_Pnt(0, 0, zLevel)

        origin = gp.gp_Pnt(0, 0, zLevel - 1)
        csys = gp.gp_Ax3(p, gp.gp().DZ())
        cuttingPlane = gp.gp_Pln(csys)
        bff = BRepBuilderAPI.BRepBuilderAPI_MakeFace(cuttingPlane)
        face = bff.Face()

        #odd, a halfspace is faster than a box?
        hs = BRepPrimAPI.BRepPrimAPI_MakeHalfSpace(face, origin)
        hs.Build()
        halfspace = hs.Solid()

        #make the cut
        bc = BRepAlgoAPI.BRepAlgoAPI_Cut(shapeToSlice, halfspace)
        cutShape = bc.Shape()

        foundFace = False
        for face in Topo(cutShape).faces():
            if self._isAtZLevel(zLevel, face):
                foundFace = True
                log.debug("Face is at zlevel" + str(zLevel))
                s.addFace(face)
                #TestDisplay.display.showShape(face);

                log.debug("Face" + str(face))

        if self.options.useSliceFactoring:
            mySum = s.getCheckSum()
            #print 'Slice Created, Checksum is',mySum;
            for otherSlice in self.slices:
                #print "Slice Checksum=",otherSlice.getCheckSum();
                if mySum == otherSlice.getCheckSum():
                    log.info(
                        "This slice matches another one exactly. using that so we can save time."
                    )
                    return otherSlice.copyToZ(zLevel)

        if not foundFace:
            log.warn("No faces found after slicing at zLevel " + str(zLevel) +
                     " !. Skipping This layer completely")
            return None
        else:
            return s
Exemple #8
0
def fuse_shapes(shapeList):
    s1 = shapeList[0]
    _builders = []
    for s2 in shapeList[1:]:
        fuse = BRepAlgoAPI.BRepAlgoAPI_Fuse(s1, s2)
        _builders.append(fuse)
        s1 = fuse.Shape()
    s1._builders = _builders
    return s1
    def _makeSlice(self, shapeToSlice, zLevel):
        s = Slice()

        #change if layers are variable thickness
        s.sliceHeight = self.sliceHeight
        s.zLevel = zLevel

        #make a cutting plane
        p = gp.gp_Pnt(0, 0, zLevel)

        origin = gp.gp_Pnt(0, 0, zLevel - 1)
        csys = gp.gp_Ax3(p, gp.gp().DZ())
        cuttingPlane = gp.gp_Pln(csys)
        bff = BRepBuilderAPI.BRepBuilderAPI_MakeFace(cuttingPlane)
        face = bff.Face()

        #odd, a halfspace is faster than a box?
        hs = BRepPrimAPI.BRepPrimAPI_MakeHalfSpace(face, origin)
        hs.Build()
        halfspace = hs.Solid()

        #make the cut
        bc = BRepAlgoAPI.BRepAlgoAPI_Cut(shapeToSlice, halfspace)
        cutShape = bc.Shape()

        #search the shape for faces at the specified zlevel
        texp = TopExp.TopExp_Explorer()
        texp.Init(cutShape, TopAbs.TopAbs_FACE)
        foundFace = False
        while (texp.More()):
            face = ts.Face(texp.Current())
            if self._isAtZLevel(zLevel, face):
                foundFace = True
                logging.debug("Face is at zlevel" + str(zLevel))
                s.addFace(face, self.saveSliceFaces)
            texp.Next()

        #free memory
        face.Nullify()
        bc.Destroy()
        texp.Clear()
        texp.Destroy()

        if not foundFace:
            logging.warn("No faces found after slicing at zLevel " +
                         str(zLevel) + " !. Skipping This layer completely")
            return None
        else:
            return s
Exemple #10
0
def intersection(a, b):

    if set([a.ShapeType(), b.ShapeType()]) <= set([TopAbs.TopAbs_WIRE, TopAbs.TopAbs_EDGE]):
        # TODO: check if the computed point is within the bounded part of
        # the curves
        l = []
        for c0 in subshapes(a, TopAbs.TopAbs_EDGE):
            c0_ = BRep_Tool.Curve(c0)[0]
            for c1 in subshapes(b, TopAbs.TopAbs_EDGE):
                c1_ = BRep_Tool.Curve(c1)[0]
                # TODO: use IntTools_EdgeEdge
                #  or IntTools_BeanBeanIntersector
                u = GeomAPI_ExtremaCurveCurve(c0_, c1_)
                par = u.LowerDistanceParameters()[0]
                pnt = c0_.GetObject().Value(par)
                l.append(BRepBuilderAPI_MakeVertex(pnt).Vertex())
        return l

    c = BRepAlgoAPI.BRepAlgoAPI_Common(a, b).Shape()
    comp = TopoDS.topods_Compound(c)
    # get the subshape of the compound:
    types = set([a.ShapeType(), b.ShapeType()])
    # compound = 0
    # compsolid = 1
    # solid = 2
    # shell = 3
    # face = 4
    # wire = 5
    # edge = 6
    # vertex = 7
    # shape = 8
    if types == set([TopAbs.TopAbs_FACE]):
        return [subshapes(comp, TopAbs.TopAbs_FACE)[0]]
    elif types == set([TopAbs.TopAbs_FACE, TopAbs.TopAbs_SOLID]):
        return [subshapes(comp, TopAbs.TopAbs_SHELL)[0]]
    elif types == set([TopAbs.TopAbs_SOLID]):
        return [subshapes(comp, TopAbs.TopAbs_SOLID)[0]]
    elif types == set([TopAbs.TopAbs_SHELL]):
        return [subshapes(comp, TopAbs.TopAbs_EDGE)[0]]
    else:
        raise ConstructionError()
Exemple #11
0
    def makeSection(self, cuttingPlane, shapeToSection, zLevel):
        """
            Uses halfspaces to make a cut.
        """
        bff = BRepBuilderAPI.BRepBuilderAPI_MakeFace(cuttingPlane)
        face = bff.Face()
        origin = gp.gp_Pnt(0, 0, zLevel - 1)

        #odd, a halfspace is faster than a box?
        hs = BRepPrimAPI.BRepPrimAPI_MakeHalfSpace(face, origin)
        hs.Build()
        halfspace = hs.Solid()

        #make the cut
        bc = BRepAlgoAPI.BRepAlgoAPI_Cut(self.solid.shape, halfspace)
        cutShape = bc.Shape()

        ff = []
        for face in Topo(cutShape).faces():
            if OCCUtil.isFaceAtZLevel(zLevel, face):
                ff.append(face)
        return ff
Exemple #12
0
def drillWithHolesFaster(shape):
    "returns a shape with a bunch of spheres removed from it"
    box = Bnd.Bnd_Box()
    b = BRepBndLib.BRepBndLib()
    b.Add(shape, box)

    (xMin, yMin, zMin, xMax, yMax, zMax) = box.Get()

    d = 0.05 * ((xMax - xMin))
    di = 3.0 * d
    vec = gp.gp_Vec(gp.gp_Pnt(0, 0, 0), gp.gp_Pnt(0, 0, d))
    cp = None
    compound = TopoDS.TopoDS_Compound()
    builder = BRep.BRep_Builder()
    builder.MakeCompound(compound)
    #drill holes in a rectangular grid
    for x in frange6(xMin, xMax, di):
        for y in frange6(yMin, yMax, di):
            for z in frange6(zMin, zMax, di):
                #make a sphere
                center = gp.gp_Pnt(x, y, z)
                hole = BRepPrimAPI.BRepPrimAPI_MakeSphere(center, d).Shape()
                #lets see if a square hole is faster!
                #w = squareWire(center,d );
                #hb = BRepPrimAPI.BRepPrimAPI_MakePrism(w,vec,False,True);
                #hb.Build();
                #hole = hb.Shape();
                builder.Add(compound, hole)

    display.DisplayShape(compound)
    q = time.clock()
    cut = BRepAlgoAPI.BRepAlgoAPI_Cut(shape, compound)
    if cut.ErrorStatus() == 0:
        print "Cut Took %0.3f sec." % (time.clock() - q)
        return cut.Shape()
    else:
        print "Error Cutting: %d" % cut.ErrorStatus()
        return shape
Exemple #13
0
def make_OAP(EFL, diameter, height, centre, direction, x_axis):
    FL = EFL/2. #focal length
    radius = diameter/2.
    outside = EFL + radius
    inside = EFL - radius
    length = (outside**2)/(4.*FL) - FL + height
    
    #pbl_shape = make_true_para(FL, 5.0, outside+1)
    pbl_shape = make_interp_parabola(FL, inside-1, outside+1)
    
    ax3 = gp.gp_Ax2(gp.gp_Pnt(EFL,0,-height), #origin
                   gp.gp_Dir(0.,0.,1.), #main direction is X
                   gp.gp_Dir(0.,1.,0.)) #X Direction is Y
    cyl_solid = BRepPrimAPI.BRepPrimAPI_MakeCylinder(ax3, radius, length)
    
    
    cut = BRepAlgoAPI.BRepAlgoAPI_Cut(cyl_solid.Shape(), 
                                      pbl_shape)
        
    loc= position_shape(toshape(cut), centre, 
                          direction, x_axis)
    #nurbs = BRepBuilderAPI.BRepBuilderAPI_NurbsConvert(loc)
    return loc #toshape(nurbs)
Exemple #14
0
    def ScaleZ(self, val):
        v = self.Value(3, 3)
        self.SetValue(3, 3, val * v)

    def Translate(self, dx, dy, dz):
        self.SetTranslationPart(gp.gp_XYZ(dx, dy, dz))


t = GTransform()
t.ScaleZ(2.0)

trans = BRepBuilderAPI.BRepBuilderAPI_GTransform(sphere.Shape(), t)

box = BRepPrimAPI.BRepPrimAPI_MakeBox(100, 100, 100)

cut = BRepAlgoAPI.BRepAlgoAPI_Cut(box.Shape(), trans.Shape())

view(cut.Shape())

#step_export = STEPControl.STEPControl_Writer()
#step_export.Transfer(trans.Shape(), STEPControl.STEPControl_AsIs)
#step_export.Write("/home/bryan/test_ellipse.stp")

#el = gp.gp_Elips(gp.gp_Ax2(gp.gp_Pnt(0,0,0), gp.gp_Dir(1,0,0)), 10, 5)
#EL = Geom.Geom_Ellipse(el)
#handle = Geom.Handle_Geom_Ellipse(EL)
#revolve = BRepPrimAPI.BRepPrimAPI_MakeRevolution(handle, 180)
#nurbs =
#view(revolve.Shape())
sys.exit(0)

cut_tool = BRepPrimAPI.BRepPrimAPI_MakeBox(gp.gp_Pnt(6, 6, 6), 5., 5.,
                                           5.).Shape()

#tool_label = ts.NewChild(root)
#ns_builder = TNaming.TNaming_Builder(tool_label)
#ns_builder.Generated(cut_tool)
#
#topo = Topo(cut_tool)
#for edge in topo.edges():
#    sub_label = ts.NewChild(tool_label)
#    ns_builder = TNaming.TNaming_Builder(sub_label)
#    ns_builder.Generated(edge)

bop = BRepAlgoAPI.BRepAlgoAPI_Cut(box, cut_tool)
cut_shape = bop.Shape()

cut_label = ts.NewChild(root)
ns_builder = TNaming.TNaming_Builder(cut_label)
ns_builder.Modify(box, cut_shape)

#if bop.HasModified():
#    mod_label = ts.NewChild(cut_label)
#    ns_builder = TNaming.TNaming_Builder(mod_label)
#    for edge in Topo(cut_shape).edges():
#        modified = bop.Modified(edge)
#        itr = TopTools.TopTools_ListIteratorOfListOfShape(modified)
#        while itr.More():
#            this = itr.Value()
#            ns_builder.Modify(edge, modified)
Exemple #16
0
def copy(shape):
    """Return a copy of the shape that does not reference the original shape"""
    new = BRepAlgoAPI.BRepAlgoAPI_Common(shape, cube).Shape()
    comp = TopoDS.TopoDS_Compound(new)
    return subshapes(comp, shape.ShapeType())[0]
Exemple #17
0
length = (outside**2) / (4. * FL)

ax2 = gp.gp_Ax2(
    gp.gp_Pnt(0, 0, 0),  #origin
    gp.gp_Dir(0., 0., 1.),  #main direction is X
    gp.gp_Dir(1., 0., 0.))  #X Direction is Z

pbl_shape = BRepPrimAPI.BRepPrimAPI_MakeRevolution(ax2, h_para, 1.0, outside)

ax3 = gp.gp_Ax2(
    gp.gp_Pnt(EFL, 0, 0),  #origin
    gp.gp_Dir(0., 0., 1.),  #main direction is X
    gp.gp_Dir(0., 1., 0.))  #X Direction is Y
cyl_solid = BRepPrimAPI.BRepPrimAPI_MakeCylinder(ax3, radius, length)

nurb = BRepBuilderAPI.BRepBuilderAPI_NurbsConvert(pbl_shape.Shape())

cut = BRepAlgoAPI.BRepAlgoAPI_Cut(cyl_solid.Shape(), nurb.Shape())

#view(wire.Shape(), cyl_solid.Shape(), pbl_shape.Shape())
#view(cyl_solid.Shape(), pbl_shape.Shape())

view(cut.Shape())

exportList = [nurb.Shape()]

step_export = STEPControl.STEPControl_Writer()
for shape in exportList:
    step_export.Transfer(shape, STEPControl.STEPControl_AsIs)
#step_export.Write("/home/bryan/ParabolicMirror.step")