add SketchWidget.solve(); Window.update_sketch_status()

This commit is contained in:
Josh Holtrop 2011-09-08 14:21:39 -04:00
parent 8066327ad9
commit f9d9d9ebfb
2 changed files with 27 additions and 2 deletions

View File

@ -8,6 +8,7 @@ from OpenGL.GL import *
from PointRef import PointRef
from shapes import *
from constraints import *
from Sketch import *
class SketchWidget:
def __init__(self, sketch, window):
@ -26,6 +27,7 @@ class SketchWidget:
'crosshair': gtk.gdk.Cursor(gtk.gdk.CROSSHAIR),
}
self.hover_snap_ptref = None
self.solved = False
# Configuration parameters
self.line_width = 1.5
@ -88,6 +90,8 @@ class SketchWidget:
gldrawable.gl_end()
self.solve()
def reshape(self, glarea, event):
# get GLContext and GLDrawable
glcontext = glarea.get_gl_context()
@ -553,3 +557,23 @@ class SketchWidget:
if self.hover_snap_ptref is not None:
self.hover_snap_ptref = None
self.queue_redraw()
def solve(self):
if not self.solved:
result = self.sketch.solve()
self.solved = True
valid = False
text = '%d/%d' % (self.sketch.num_constraints,
self.sketch.num_variables)
if result == SOLVED:
valid = True
elif result == NO_SOLUTION:
text = 'No Solution'
elif result == OVERCONSTRAINED:
text += ' - Overconstrained'
elif result == UNDERCONSTRAINED:
text += ' - Underconstrained'
else:
sys.stderr.write(__name__ +
':solve(): Unknown Sketch.solve() result\n')
self.window.update_sketch_status(valid, text)

View File

@ -18,8 +18,6 @@ class Window:
ss = SampleSketch()
ss.solve()
self.sw = SketchWidget(ss, self)
self.toolbar = gtk.Toolbar()
@ -95,3 +93,6 @@ class Window:
self.mode_names_to_buttons[mode].set_active(True)
else:
raise ValueError('Unknown mode')
def update_sketch_status(self, valid, text):
self.sketch_status_text.set_text(text)