Python CAD Tutorial 09 - Workspace class

View/Download Code


Figure 1: workspace class

The workspace class below is a management class. It will contain various methods for working with the visible objects. It will also manage our layers. For now we will add simple functions, for example 'append' (which will add objects to a layer).In the main file, you can see that our new polygon is contained and updated through the shape class. Later on we will attach this to our GUI so we can dynamically add primitives as we need them.

from cad.point import createpoint
from OpenGL.GL import *
from OpenGL.arrays import vbo
from numpy import array

#lets create a dict object we can name our layers from here
class workspace(dict):
    selected_shape = 'workspace'
    selected_part = None

    def reset(self):
	for k in self.keys():
	self['workspace'] = shape.createshape()

    def create(self, item, name=None):
	if name is not None:
	    self.selected_part = name
	if self.selected_part is not None:
	    if not self.get(self.selected_part):
		self[self.selected_part] = shape.createshape()
	    self.selected_shape = self[self.selected_part].count()

    def append(self, item, name=None):

    def objects_iter(self):
	for layer in self.keys():
	    for shape in self[layer]:
		yield shape

    def set(self, name, value):
	for layer in self.values():
	    for item in layer.primitives:
		item.display_color = value
		self.color = value

    #handle drawing our shapes here
    def draw(self):
	for item in self.values():