Example #1
0
	def create_module( self, parent_id = 0 ):
		""" Adds a module to the interface as a sub-module of
			of the module of the given id.
		"""
		mod = Module()
		self.__opts['modules'].append(mod)
		mod.index = len(self.__opts['modules']) - 1
		return self.__opts['modules'][parent_id].add_element(mod)
Example #2
0
		def insert(event=None):
			global tex_index
			module = Module()
			module.body_color([ int(0.7*255), int(0.2*255), int(0.1*255),255])
			module.__elements__[0]['surface_color'] = [.3,.3,.3,1]
			module.scale(16,16,16)
			shape_factory.cache = False
			module.add_element(shape_factory.gen_shape(choice.get()))
			try:
				module.__elements__[-1].__elements__[0] = module.__elements__[0]
			except: pass
			# hacky but we'll fix later
			if module.__elements__[-1].id[0] == 'Sphere':
				# SphereGenerator.texture_sphere(module.__elements__[-1],
					# texture[tex_index])
				tex_index += 1
				if tex_index == len(texture): tex_index = -tex_index
			elif module.__elements__[-1].id[0] == 'Xwing':
				module.__elements__[-2].scale(.02,.02,.02)

			shape_factory.cache = False
			module.__elements__[-1].invisible = True
			module.id[0] = module.__elements__[-1].id[0]

			self.canvas.config('modules')[0].add_element(module)
			self.canvas.update_idletasks()
Example #3
0
	def _subdivide( self ):
		faces = []
		mesh = Module()
		for face in self.polygons:
			
			a = self._getMidpoint( face[0], face[1])
			b = self._getMidpoint( face[1], face[2] )
			c = self._getMidpoint( face[0], face[2] )
			
			faces.append( [face[0],a,c] )
			faces.append( [face[1],b,a] )
			faces.append( [face[2],c,b] )
			faces.append( [a,b,c])

		self.polygons = faces
		for face in faces:
			mesh.add_shape(self._gen_poly(face,face))

		self.mesh =  mesh
Example #4
0
	def __create_cylinder( width=1, height=1, sides=50, x0=0, y0=0, z0=0,
			color = [0,0,200,0] ):
		""" Returns a cylinder shape.
			
			The class of the cylinder will be "Module", and will be treated
			as a module generated through manual module construction.
		"""
		cylinder = Module()
		
		mx = 255 // sides
				
		for i in range(sides):
			part1 = i * pi * 2 / sides
			part2 = (i+1)%sides * pi * 2 / sides
			x1 = cos(part1) * width
			z1 = sin(part1) * height
			x2 = cos(part2) * width
			z2 = sin(part2) * height
			x1a = cos(part1) * 120 + 120
			z1a = sin(part1) * 120 + 120
			x2a = cos(part2) * 120 + 120
			z2a = sin(part2) * 120 + 120			
			
			cylinder.add_shape(Polygon(nparray([ [x1,1,z1,1], [x2,1,z2,1],
				[0,1,0,1] ] ),color=color,normals=nparray([[0,1,0,1]for i in range(4)]),
				anchor=nparray([[0,i*mx,-1,-1],[0,(i+1)*mx,-1,-1],
				[255,i*mx,-1,-1],[255,(i+1)*255,-1,-1]]).flatten().astype(int))) 
					
			cylinder.add_shape(Polygon(nparray([ [x1,0,z1,1], [x2,0,z2,1],
				[0,0,0,1]] ),color=color,normals=nparray([[0,-1,0,1]for i in range(4)]),
				anchor=nparray([[0,i*mx,-1,-1],[0,(i+1)*mx,-1,-1],
				[255,i*mx,-1,-1],[255,(i+1)*255,-1,-1]]).flatten().astype(int))) 

			cylinder.add_shape( Polygon(nparray(\
			[	[x1,0,z1,1], [x2,0,z2,1], [x2,1,z2,1], [x1,1,z1,1]  ] ),
			color=color,normals=nparray([[x1,0,z1,1],[x2,0,z1,1],[x2,0,z1,1],[x1,0,z1,1]]),
				anchor=nparray([[i*mx,0,-1,-1],[(i+1)*mx,0,-1,-1],
				[i*mx,255,-1,-1],[(i+1)*mx,255,-1,-1]]).flatten().astype(int))) 
		
		cylinder.id[0] = 'Cylinder'
		return cylinder
Example #5
0
	def build_mesh(self):
		""" Builds the xwing mesh """
		cylinder = lambda sides : ShapeFactory().gen_shape('cylinder')
		box = lambda : ShapeFactory().gen_shape('box')
		
		# engine
		engine = Module()
		engine.scale( 1.3, 6, 1.3 )
		engine.rotate( 0, 1, 'x' )
		engine.add_element( cylinder(sides=10) )
		engine.scale(.8,.8,1.1)
		engine.body_color(Colors.FLAME)
		# engine.body_color(Colors.WHITE)
		engine.add_element( cylinder(sides=10) )
		
		# laser
		laser = Module()
		laser.scale(.5,5,.5)
		laser.rotate(0,1,'x')
		laser.add_element( cylinder(sides=6) )
		laser.scale(0.4,0.4,1)
		laser.translate(0,0,4.5)
		laser.body_color(Colors.OFF_RED)
		# laser.body_color(Colors.WHITE)
		laser.add_element( cylinder(sides=10) )
		
		# wing
		wing = Module()
		poly = Polygon( nparray( [[0,0,0,1],[0,0,5,1],[15,0,3,1],[15,0,0,1]] ),
			normals=nparray([[0,-1,0,1]for i in range(4)]))
		wing.add_shape( poly )
		wing.translate(0,.5,0)
		Polygon( nparray( [[0,0,0,1],[0,0,5,1],[15,0,3,1],[15,0,0,1]] ),
			normals=nparray([[0,1,0,1]for i in range(4)]))
		wing.add_shape( poly )
		wing.identity()
		wing.translate( 3, 1.6, -1 )
		wing.add_element( engine )
		wing.identity()
		
		poly = Polygon( nparray( [[15,0,3,1],[15,0,0,1],[15,.5,0,1],[15,.5,3,1]] ),
			normals= nparray([[1,0,0,1]for i in range(4)]))
		wing.add_shape( poly )
		poly = Polygon( nparray( [[15,0,0,1],[0,0,0,1],[0,.5,0,1],[15,.5,0,1]] ),
			normals= nparray([[0,0,-1,1]for i in range(4)]))
		wing.add_shape( poly )
		poly = Polygon( nparray( [[15,0,3,1],[15,0.5,3,1],[0,.5,5,1],[0,0,5,1]] ),
			normals= nparray([[2,0,15,1]for i in range(4)]))
		wing.add_shape( poly )
		
		wing.translate( 15, .25, 0 )
		wing.add_element( laser )
		
		# 4 Wings
		wings = Module()
		wings.body_color( Colors.GREY )
		# wings.body_color(Colors.WHITE)
		wings.rotate( cos(.3),sin(.3), 'z' )
		wings.translate( body_width, 0, 0 )
		wings.add_element(wing)
		
		wings.identity()
		wings.scale(1,-1,1)
		wings.rotate(cos(-.3),sin(-.3),'z')
		wings.translate(body_width,0,0)
		wings.add_element(wing)
		
		wings.identity()
		wings.scale(-1,1,1)
		wings.rotate(cos(-.3),sin(-.3),'z')
		wings.translate(-body_width,0,0)
		wings.add_element(wing)
		
		wings.identity()
		wings.scale(-1,-1,1)
		wings.rotate(cos(.3),sin(.3),'z')
		wings.translate(-body_width,0,0)
		wings.add_element(wing)
		
		# body
		body = Module()
		body.surface_color(Colors.DARK)
		body.body_color(Colors.GRAY)
		# body.body_color(Colors.FLAME)
		# body.body_color(Colors.WHITE)
		body.add_element(wings)
		body.scale(body_width,body_width,8)
		body.translate(0,0,4)
		body.add_element( box() )
		
		body.identity()
		# body.body_color(Colors.FLAME)
		body.body_color(Colors.GRAY)
		poly = Polygon( nparray([
			[body_width,body_width,12,1],
			[body_width,-body_width,12,1],
			[body_width*.5,-body_width*.3,35,1],
			[body_width*.5,body_width*.3,35,1]]),
			normals= nparray([[23,0,.5*body_width,1]for i in range(4)]))
		body.add_shape( poly )
		
		poly = Polygon( nparray([
			[-body_width,body_width,12,1],
			[-body_width,-body_width,12,1],
			[-body_width*.5,-body_width*.3,35,1],
			[-body_width*.5,body_width*.3,35,1]]),
			normals= nparray([[-23,0,.5*body_width,1]for i in range(4)]))
		body.add_shape(poly)
		
		poly = Polygon( nparray([
			[-body_width,body_width,12,1],
			[body_width,body_width,12,1],
			[body_width*.5,body_width*.3,35,1],
			[-body_width*.5,body_width*.3,35,1]]),
			normals= nparray([[0,23,.5*body_width,1]for i in range(4)]))
		body.add_shape(poly)
			
		poly = Polygon( nparray([
			[-body_width,-body_width,12,1],
			[body_width,-body_width,12,1],
			[body_width*.5,-body_width*.3,35,1],
			[-body_width*.5,-body_width*.3,35,1]]),
			normals= nparray([[0,-23,.5*body_width,1]for i in range(4)]))
		body.add_shape(poly)
		
		poly = Polygon( nparray([
			[-body_width*.5, body_width*.3,35,1],
			[ body_width*.5, body_width*.3,35,1],
			[ body_width*.5,-body_width*.3,35,1],
			[-body_width*.5,-body_width*.3,35,1]]),
			normals= nparray([[0,0,1,1]for i in range(4)]))
		body.add_shape(poly)

		body.id[0] = 'Xwing'
		self.mesh = body
Example #6
0
	def __create_box( width=1, height=1, depth=1, x0=0, y0=0, z0=0,
			color = [[200,200,0,0] for i in range(6)] ):
		""" Returns a box shape.
			
			The class of the square will be "Module", and will be treated
			as a module generated through manual module construction.
		"""
		box = Module()
		(w,h,d) = (width,height,depth) # for conciseness
		
		# Back
		vertices = nparray([ [-w+x0,-h+y0,-d+z0,1],[-w+x0,h+y0,z0-d,1],[w+x0,h+y0,z0-d,1],
			[w+x0,-h+y0,z0-d,1] ] )
		box.add_shape( Polygon(vertices, color = color[0], normals=nparray([0,0,-1,0]),
			anchor=nparray([[0,255,-1,-1], [0,0,-1,-1], [255,0,-1,-1], [255,255,-1,-1]]).flatten().astype(int)) ) 
		
		# Front
		vertices = nparray([ [-w+x0,-h+y0,d+z0,1],[-w+x0,h+y0,z0+d,1],[w+x0,h+y0,z0+d,1],
			[w+x0,-h+y0,z0+d,1] ] )
		box.add_shape(Polygon( vertices, color = color[1], normals=nparray([0,0,1,0]),
			anchor=nparray([[0,255,-1,-1], [0,0,-1,-1], [255,0,-1,-1], [255,255,-1,-1]]).flatten().astype(int)) ) 

		
		# Left
		vertices = nparray([ [-w+x0,-h+y0,d+z0,1], 
			[-w+x0,-h+y0,z0-d,1], [-w+x0,h+y0,z0-d,1], [-w+x0,h+y0,z0+d,1] ] )
		box.add_shape( Polygon( vertices, color = color[2],normals=nparray([-1,0,0,0]),
			anchor=nparray([[0,0,-1,-1], [255,0,-1,-1], [255,255,-1,-1], [0,255,-1,-1]]).flatten().astype(int)) ) 
		
		# Right
		vertices = nparray([ [w+x0,-h+y0,d+z0,1], [w+x0,-h+y0,z0-d,1], [w+x0,h+y0,z0-d,1], 
			[w+x0,h+y0,z0+d,1] ] )
		box.add_shape( Polygon( vertices, color = color[3],normals=nparray([1,0,0,0]),
			anchor=nparray([[0,0,-1,-1], [255,0,-1,-1], [255,255,-1,-1], [0,255,-1,-1]]).flatten().astype(int)) )
		
		# Top
		vertices = nparray([ [-w+x0,h+y0,d+z0,1], [-w+x0,h+y0,z0-d,1], [w+x0,h+y0,z0-d,1],
			[w+x0,h+y0,z0+d,1] ] )
		box.add_shape( Polygon( vertices, color = color[4],normals=nparray([0,1,0,0]),
			anchor=nparray([ [0,0,-1,-1],[0,255,-1,-1], [255,255,-1,-1], [255,0,-1,-1]]).flatten().astype(int)) )
		
		# Bottom
		vertices = nparray([ [-w+x0,-h+y0,d+z0,1],[-w+x0,-h+y0,z0-d,1],[w+x0,-h+y0,z0-d,1],
			[w+x0,-h+y0,z0+d,1] ] )
		box.add_shape( Polygon( vertices, color = color[5],normals=nparray([0,-1,0,0]),
			anchor=nparray([ [0,0,-1,-1],[0,255,-1,-1], [255,255,-1,-1], [255,0,-1,-1]]).flatten().astype(int)) )
		box.id[0] = 'Box'
		return box
Example #7
0
	def __create_bezier():
		
		curve = Module()
		points = normals = genCurve()
		curve.add_shape(Polygon(points,normals=points))
		return curve
Example #8
0
# importa dependĂȘncias
from Compiler import Compiler
from Module.Module import Module # Modulo (Geral)
from Module.Adapter.Adapter import Adapter # Adapter (Core)
from Module.Entity.Entity import Entity # Entity (MVC)
from Module.Entity.Entity import Atributo # Entity (MVC)

# Adaptador de Banco de Dados
adapter = Adapter('localhost', 'testebd', 'root', '')

# Modulo Core
core = Module('Core')
core.addFiles(adapter)

# Modulo Carros
entCarro = Entity('Carro')
entCarro.addAtributos(
	Atributo('id', Atributo.TYPE_INT, None, True, True, True, False),
	Atributo('nome', Atributo.TYPE_VARCHAR, 180),
	Atributo('modelo', Atributo.TYPE_VARCHAR, 100),
	Atributo('marca', Atributo.TYPE_VARCHAR, 100),
	Atributo('placa', Atributo.TYPE_VARCHAR, 100),
	Atributo('cor', Atributo.TYPE_VARCHAR, 100)
)
entCarro.createModel()
entCarro.generateCreateTable()

modCarros = Module('Carros')
modCarros.addFiles(entCarro)

# Compila o resultado
Example #9
0
from Module.Entity.Entity import Entity
from Module.Metodo.Metodo import Metodo

entCarro = Entity('Carro')
entCarro.addAtributos(
	Atributo('id', Atributo.TYPE_INT, None, True, True, True, False),
	Atributo('nome', Atributo.TYPE_VARCHAR, 180),
	Atributo('modelo', Atributo.TYPE_VARCHAR, 100),
	Atributo('marca', Atributo.TYPE_VARCHAR, 100),
	Atributo('placa', Atributo.TYPE_VARCHAR, 100),
	Atributo('cor', Atributo.TYPE_VARCHAR, 100)
)
entCarro.createModel(
	metodos = [
		Metodo('buscarPorNomeMarca', ['nome', 'marca'], \
			"return $this->buscar(\"nome = '{$nome}'\", \"marca = '{$marca}'\")[0];\
return $this->buscar(\"nome = '{$nome}'\", \"marca = '{$marca}'\")[0];\
return $this->buscar(\"nome = '{$nome}'\", \"marca = '{$marca}'\")[0];\
return $this->buscar(\"nome = '{$nome}'\", \"marca = '{$marca}'\")[0];\
return $this->buscar(\"nome = '{$nome}'\", \"marca = '{$marca}'\")[0];", True)
	]
)

modCarros = Module('Carros')
modCarros.addFiles(entCarro)

comp = Compiler('teste_model')
comp.addModules(modCarros)
comp.generate()

print('Compilado')