Esempio n. 1
0
def _unify_solid(proto):
    mkSolid = BRepBuilderAPI_MakeSolid()
    explorer = TopExp_Explorer()

    explorer.Init(proto.Shape(), TopAbs_SHELL)
    while explorer.More():
        mkSolid.Add(_unify_shell(Shape(explorer.Current())).Shell())
        explorer.Next()

    mkSolid.Build()
    return Shape(mkSolid.Shape())
Esempio n. 2
0
      def getShape(self, pos, rotation) :
          import cadquery as cq
          #from OCC.Core.gp import gp_Ax2, gp_Pnt, gp_Dir
          from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakePolygon
          from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeSolid
          from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_Sewing
          from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Cut
          from OCC.Core.TopoDS import topods

          print("Get Shape gPolyhedra")
          x = pos[0]
          y = pos[1]
          z = pos[2]
          
          sewing = BRepBuilderAPI_Sewing()
          # Add top polygon
          print('top polygon')
          top = regPolygon(self.Num, self.Zplanes[0][1], \
                             self.Zplanes[0][2])
          maxR = self.Zplanes[0][1]
          height = self.Zplanes[0][2]
          sewing.Add(makeFace(top))
          n = len(self.Zplanes)
          for i in range(1,n) :
              bot = regPolygon(self.Num, self.Zplanes[i][1], \
                             self.Zplanes[i][2])
              if self.Zplanes[i][1] > maxR :
                 maxR = self.Zplanes[i][1] 
              height = height + self.Zplanes[i][2]   
              for i in range(0, self.Num) :
                  face = makeFace([top[i],top[i+1],bot[i+1],bot[i]])
                  sewing.Add(face)
              top = bot    
          # Add bottom polygon
          print('bottom polygon')
          sewing.Add(makeFace(bot))
          sewing.Perform()
          sewedShape = sewing.SewedShape()
          outer = BRepBuilderAPI_MakeSolid(topods.Shell(sewedShape))

          sewing = BRepBuilderAPI_Sewing()
          # Add top polygon
          print('top polygon')
          top = regPolygon(self.Num, self.Zplanes[0][0], \
                             self.Zplanes[0][2])
          sewing.Add(makeFace(top))
          n = len(self.Zplanes)
          for i in range(1,n) :
              bot = regPolygon(self.Num, self.Zplanes[i][0], \
                             self.Zplanes[i][2])
              for i in range(0, self.Num) :
                  face = makeFace([top[i],top[i+1],bot[i+1],bot[i]])
                  sewing.Add(face)
              top = bot    
          # Add bottom polygon
          print('bottom polygon')
          sewing.Add(makeFace(bot))
          sewing.Perform()
          sewedShape = sewing.SewedShape()
          inner = BRepBuilderAPI_MakeSolid(topods.Shell(sewedShape))
          poly  = BRepAlgoAPI_Cut(outer.Shape(), inner.Shape()).Shape()
          if self.Sector.completeRev() == False :
             print("Need to section")
             if self.Sector.less90() == True :
                print("Common")
                shape = self.Sector.makeCommon(maxR, height, poly) 
             else :
                print("Cut") 
                shape = self.Sector.makeCut(maxR, height, poly)
             if self.Sector.getStart() == 0 :
                return shape
             else :
                return self.Sector.rotate(shape)
          return poly.Shape()