.. this requires reverting to python2 due to lack of python3 vtk packages in debian stretch. pythonocc-core is much more verbose, but it exposes the whole oce API to Python, which means that I'm not stuck when I want to expose something not in occmodel. I hope that it's a better way forward.
81 lines
2.5 KiB
Python
Executable file
81 lines
2.5 KiB
Python
Executable file
#!/usr/bin/python2
|
|
# -*- coding: utf-8 -*-
|
|
# auto-updating viewer of 'poc' modeling program
|
|
# Copyright © 2017 Jeff Epler <jepler@gmail.com>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
from occmodelviewer import Viewer
|
|
import os
|
|
import poctools
|
|
import sys
|
|
import time
|
|
import traceback
|
|
import vtk
|
|
|
|
filename = sys.argv[1]
|
|
|
|
def getmtime(filename):
|
|
try:
|
|
return os.stat(filename).st_mtime
|
|
except os.error:
|
|
return -1
|
|
|
|
class PocViewer(Viewer):
|
|
def __init__(self, filename):
|
|
self.filename = filename
|
|
self.modtime = -2
|
|
self.actor = vtk.vtkActor()
|
|
self.ren = vtk.vtkRenderer()
|
|
self.renWin = vtk.vtkRenderWindow()
|
|
self.renWin.AddRenderer(self.ren)
|
|
|
|
self.iren = vtk.vtkRenderWindowInteractor()
|
|
self.iren.SetRenderWindow(self.renWin)
|
|
|
|
self.ren.AddActor(self.actor)
|
|
self.iren.Initialize()
|
|
self.iren.CreateRepeatingTimer(100)
|
|
self.iren.AddObserver('TimerEvent', self.idle)
|
|
|
|
def Start(self):
|
|
self.reloadModel()
|
|
self.iren.Start()
|
|
|
|
def reloadModel(self, modtime=None):
|
|
self.modtime = modtime or getmtime(self.filename)
|
|
try:
|
|
ns = poctools.execpoc(sys.argv[1:],
|
|
__output__= os.path.splitext(filename)[0] + ".stl")
|
|
poctools.output(ns['__output__'])
|
|
except:
|
|
traceback.print_exc()
|
|
return
|
|
|
|
reader = vtk.vtkSTLReader()
|
|
reader.SetFileName(ns['__output__'])
|
|
|
|
self.mapper = vtk.vtkPolyDataMapper()
|
|
self.mapper.SetInputConnection(reader.GetOutputPort())
|
|
|
|
self.actor.SetMapper(self.mapper)
|
|
|
|
def idle(self, obj, event):
|
|
newmodtime = getmtime(self.filename)
|
|
now = time.time()
|
|
if newmodtime + .1 < now and newmodtime != self.modtime:
|
|
self.reloadModel(newmodtime)
|
|
self.renWin.Render()
|
|
mw = PocViewer(filename)
|
|
mw.Start()
|