コード例 #1
0
ファイル: model.py プロジェクト: GVallicrosa/FabQtV2
 def load(self, fname): # from source, returns vtkPolydata and actor
     self.name = fname.split('/')[-1] # filename with extension
     logger.log('Importing model: ' + self.name)
     extension = fname.split('.')[1]
     extension = extension.lower()
     if extension == 'stl': 
         importer = vtk.vtkSTLReader()
         importer.SetFileName(str(fname))
         vtkPolyData = importer.GetOutput()
         self.setPolyData(vtkPolyData)
         mapper = vtk.vtkPolyDataMapper()
         mapper.SetInput(vtkPolyData)
         actor = vtk.vtkActor()
         actor.SetMapper(mapper)
         actor.GetProperty().SetColor(random.random(), random.random(), random.random()) # Colorizes randomly
         actor.GetProperty().SetOpacity(0.5) # Some transparency
         self.setActor(actor)
     #if extension == '3ds':
         #importer = vtk.vtk3DSImporter()
         #importer.ComputeNormalsOn()
         #importer.SetFileName(str(fname))
         #importer.Read()
         #importer.GeneratePolyData()
     if extension == 'gcode':
         logger.log('Reading GCode...')
         ok, layers = readGcode(str(fname))
         if ok:
             self.setLayers(layers)
             logger.log('GCode correctly readed')
             self.layerValues = list()
             for layer in layers:
                 if layer.hasModelPaths():
                     z = layer.getModelPaths()[0].read()[0].z
                 elif layer.hasBasePaths():
                     z = layer.getBasePaths()[0].read()[0].z
                 elif layer.hasSupportPaths():
                     z = layer.getSupportPaths()[0].read()[0].z
                 else: # to future erase
                     z = layer.getModelPaths()[0].read()[0].z
                 self.layerValues.append(z)
             self.pathHeight = float(layers[1].getModelPaths()[0].read()[0].z) - float(layers[0].getModelPaths()[0].read()[0].z)
         else:
             logger.log('Error importing GCode')
         self.generatePaths(layers)
     else:
         logger.log('No valid file extension for model import')
コード例 #2
0
ファイル: model.py プロジェクト: GVallicrosa/FabQtV2
 def Slice(self): # calls skeinforge
     self.save()
     export.writeOutput('temp.stl')
     logger.log('Creating GCode...')
     os.remove('temp.stl')
     ok, layers = readGcode('temp_export.gcode') 
     logger.log('Reading GCode...')
     #os.remove('temp_export.gcode')
     if ok:
         self.setLayers(layers)
         logger.log('GCode correctly readed')
         self.layerValues = list()
         for layer in layers:
             if layer.hasModelPaths():
                 z = layer.getModelPaths()[0].read()[0].z
             elif layer.hasBasePaths():
                 z = layer.getBasePaths()[0].read()[0].z
             elif layer.hasSupportPaths():
                 z = layer.getSupportPaths()[0].read()[0].z
             self.layerValues.append(z)
     else:
         logger.log('Error importing GCode')
     self.generatePaths(layers)