+class GUI:
+
+ def _init():
+
+ # Output Format menu
+ output_format = config.output['FORMAT']
+ default_value = outputWriters.keys().index(output_format)+1
+ GUI.outFormatMenu = Draw.Create(default_value)
+ GUI.evtOutFormatMenu = 0
+
+ # Animation toggle button
+ GUI.animToggle = Draw.Create(config.output['ANIMATION'])
+ GUI.evtAnimToggle = 1
+
+ # Join Objects toggle button
+ GUI.joinObjsToggle = Draw.Create(config.output['JOIN_OBJECTS'])
+ GUI.evtJoinObjsToggle = 2
+
+ # Render filled polygons
+ GUI.polygonsToggle = Draw.Create(config.polygons['SHOW'])
+
+ # Shading Style menu
+ shading_style = config.polygons['SHADING']
+ default_value = shadingStyles.keys().index(shading_style)+1
+ GUI.shadingStyleMenu = Draw.Create(default_value)
+ GUI.evtShadingStyleMenu = 21
+
+ GUI.evtPolygonsToggle = 3
+ # We hide the config.polygons['EXPANSION_TRICK'], for now
+
+ # Render polygon edges
+ GUI.showEdgesToggle = Draw.Create(config.edges['SHOW'])
+ GUI.evtShowEdgesToggle = 4
+
+ # Render hidden edges
+ GUI.showHiddenEdgesToggle = Draw.Create(config.edges['SHOW_HIDDEN'])
+ GUI.evtShowHiddenEdgesToggle = 5
+
+ # Edge Style menu
+ edge_style = config.edges['STYLE']
+ default_value = edgeStyles.keys().index(edge_style)+1
+ GUI.edgeStyleMenu = Draw.Create(default_value)
+ GUI.evtEdgeStyleMenu = 6
+
+ # Edge Width slider
+ GUI.edgeWidthSlider = Draw.Create(config.edges['WIDTH'])
+ GUI.evtEdgeWidthSlider = 7
+
+ # Edge Color Picker
+ c = config.edges['COLOR']
+ GUI.edgeColorPicker = Draw.Create(c[0]/255.0, c[1]/255.0, c[2]/255.0)
+ GUI.evtEdgeColorPicker = 71
+
+ # Render Button
+ GUI.evtRenderButton = 8
+
+ # Exit Button
+ GUI.evtExitButton = 9
+
+ def draw():
+
+ # initialize static members
+ GUI._init()
+
+ glClear(GL_COLOR_BUFFER_BIT)
+ glColor3f(0.0, 0.0, 0.0)
+ glRasterPos2i(10, 350)
+ Draw.Text("VRM: Vector Rendering Method script. Version %s." %
+ __version__)
+ glRasterPos2i(10, 335)
+ Draw.Text("Press Q or ESC to quit.")
+
+ # Build the output format menu
+ glRasterPos2i(10, 310)
+ Draw.Text("Select the output Format:")
+ outMenuStruct = "Output Format %t"
+ for t in outputWriters.keys():
+ outMenuStruct = outMenuStruct + "|%s" % t
+ GUI.outFormatMenu = Draw.Menu(outMenuStruct, GUI.evtOutFormatMenu,
+ 10, 285, 160, 18, GUI.outFormatMenu.val, "Choose the Output Format")
+
+ # Animation toggle
+ GUI.animToggle = Draw.Toggle("Animation", GUI.evtAnimToggle,
+ 10, 260, 160, 18, GUI.animToggle.val,
+ "Toggle rendering of animations")
+
+ # Join Objects toggle
+ GUI.joinObjsToggle = Draw.Toggle("Join objects", GUI.evtJoinObjsToggle,
+ 10, 235, 160, 18, GUI.joinObjsToggle.val,
+ "Join objects in the rendered file")
+
+ # Render Button
+ Draw.Button("Render", GUI.evtRenderButton, 10, 210-25, 75, 25+18,
+ "Start Rendering")
+ Draw.Button("Exit", GUI.evtExitButton, 95, 210-25, 75, 25+18, "Exit!")
+
+ # Rendering Styles
+ glRasterPos2i(200, 310)
+ Draw.Text("Rendering Style:")
+
+ # Render Polygons
+ GUI.polygonsToggle = Draw.Toggle("Filled Polygons", GUI.evtPolygonsToggle,
+ 200, 285, 160, 18, GUI.polygonsToggle.val,
+ "Render filled polygons")
+
+ if GUI.polygonsToggle.val == 1:
+
+ # Polygon Shading Style
+ shadingStyleMenuStruct = "Shading Style %t"
+ for t in shadingStyles.keys():
+ shadingStyleMenuStruct = shadingStyleMenuStruct + "|%s" % t.lower()
+ GUI.shadingStyleMenu = Draw.Menu(shadingStyleMenuStruct, GUI.evtShadingStyleMenu,
+ 200, 260, 160, 18, GUI.shadingStyleMenu.val,
+ "Choose the shading style")
+
+
+ # Render Edges
+ GUI.showEdgesToggle = Draw.Toggle("Show Edges", GUI.evtShowEdgesToggle,
+ 200, 235, 160, 18, GUI.showEdgesToggle.val,
+ "Render polygon edges")
+
+ if GUI.showEdgesToggle.val == 1:
+
+ # Edge Style
+ edgeStyleMenuStruct = "Edge Style %t"
+ for t in edgeStyles.keys():
+ edgeStyleMenuStruct = edgeStyleMenuStruct + "|%s" % t.lower()
+ GUI.edgeStyleMenu = Draw.Menu(edgeStyleMenuStruct, GUI.evtEdgeStyleMenu,
+ 200, 210, 160, 18, GUI.edgeStyleMenu.val,
+ "Choose the edge style")
+
+ # Edge size
+ GUI.edgeWidthSlider = Draw.Slider("Width: ", GUI.evtEdgeWidthSlider,
+ 200, 185, 140, 18, GUI.edgeWidthSlider.val,
+ 0.0, 10.0, 0, "Change Edge Width")
+
+ # Edge Color
+ GUI.edgeColorPicker = Draw.ColorPicker(GUI.evtEdgeColorPicker,
+ 342, 185, 18, 18, GUI.edgeColorPicker.val, "Choose Edge Color")
+
+ # Show Hidden Edges
+ GUI.showHiddenEdgesToggle = Draw.Toggle("Show Hidden Edges",
+ GUI.evtShowHiddenEdgesToggle,
+ 200, 160, 160, 18, GUI.showHiddenEdgesToggle.val,
+ "Render hidden edges as dashed lines")
+
+ glRasterPos2i(10, 160)
+ Draw.Text("%s (c) 2006" % __author__)
+
+ def event(evt, val):
+
+ if evt == Draw.ESCKEY or evt == Draw.QKEY:
+ Draw.Exit()
+ else:
+ return
+
+ Draw.Redraw(1)
+
+ def button_event(evt):
+
+ if evt == GUI.evtExitButton:
+ Draw.Exit()
+
+ elif evt == GUI.evtOutFormatMenu:
+ i = GUI.outFormatMenu.val - 1
+ config.output['FORMAT']= outputWriters.keys()[i]
+
+ elif evt == GUI.evtAnimToggle:
+ config.output['ANIMATION'] = bool(GUI.animToggle.val)
+
+ elif evt == GUI.evtJoinObjsToggle:
+ config.output['JOIN_OBJECTS'] = bool(GUI.joinObjsToggle.val)
+
+ elif evt == GUI.evtPolygonsToggle:
+ config.polygons['SHOW'] = bool(GUI.polygonsToggle.val)
+
+ elif evt == GUI.evtShadingStyleMenu:
+ i = GUI.shadingStyleMenu.val - 1
+ config.polygons['SHADING'] = shadingStyles.keys()[i]
+
+ elif evt == GUI.evtShowEdgesToggle:
+ config.edges['SHOW'] = bool(GUI.showEdgesToggle.val)
+
+ elif evt == GUI.evtShowHiddenEdgesToggle:
+ config.edges['SHOW_HIDDEN'] = bool(GUI.showHiddenEdgesToggle.val)
+
+ elif evt == GUI.evtEdgeStyleMenu:
+ i = GUI.edgeStyleMenu.val - 1
+ config.edges['STYLE'] = edgeStyles.keys()[i]
+
+ elif evt == GUI.evtEdgeWidthSlider:
+ config.edges['WIDTH'] = float(GUI.edgeWidthSlider.val)
+
+ elif evt == GUI.evtEdgeColorPicker:
+ config.edges['COLOR'] = [int(c*255.0) for c in GUI.edgeColorPicker.val]
+
+ elif evt == GUI.evtRenderButton:
+ label = "Save %s" % config.output['FORMAT']
+ # Show the File Selector
+ global outputfile
+ Blender.Window.FileSelector(vectorize, label, outputfile)
+
+ else:
+ print "Event: %d not handled!" % evt
+
+ if evt:
+ Draw.Redraw(1)
+ #GUI.conf_debug()
+
+ def conf_debug():
+ from pprint import pprint
+ print "\nConfig"
+ pprint(config.output)
+ pprint(config.polygons)
+ pprint(config.edges)
+
+ _init = staticmethod(_init)
+ draw = staticmethod(draw)
+ event = staticmethod(event)
+ button_event = staticmethod(button_event)
+ conf_debug = staticmethod(conf_debug)
+
+# A wrapper function for the vectorizing process
+def vectorize(filename):
+ """The vectorizing process is as follows:
+
+ - Instanciate the writer and the renderer
+ - Render!
+ """