summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorfenn <fennetic.net>2009-08-08 19:01:54 -0500
committerfenn <fennetic.net>2009-08-08 19:01:54 -0500
commit6df2c40961610fbcf4429b0798cadba66da352a4 (patch)
tree717d5d3d6a4d91fee2a93610bf827fbca6ac1caa /packages
parent965f834520c0bd46511dc796c7ed1be01cbcca46 (diff)
downloadskdb-6df2c40961610fbcf4429b0798cadba66da352a4.tar.gz
skdb-6df2c40961610fbcf4429b0798cadba66da352a4.zip
lego feature grammar works now
Diffstat (limited to 'packages')
-rw-r--r--packages/lego/data.yaml43
-rw-r--r--packages/lego/grammar.yaml120
-rw-r--r--packages/lego/interfaces.py52
-rw-r--r--packages/lego/lego.py6
-rw-r--r--packages/lego/metadata.yaml3
5 files changed, 126 insertions, 98 deletions
diff --git a/packages/lego/data.yaml b/packages/lego/data.yaml
index 7c610a3..2d58603 100644
--- a/packages/lego/data.yaml
+++ b/packages/lego/data.yaml
@@ -18,78 +18,67 @@ parts:
- !lego_feature
part: *wah
point: [-8.0, 0.0, -8.0]
- type: StudCup
- complement: AntiStudCup #todo: deleteme
+ type: stud cup
x_vec: [-1.0, 0.0, 0.0]
y_vec: [-0.0, -0.0, -1.0]
- !lego_feature
part: *wah
point: [-4.0, 0.0, -4.0]
- complement: Stud #todo: deleteme
- type: AntiStud
+ type: anti stud
x_vec: [-1.0, 0.0, 0.0]
y_vec: [-0.0, -0.0, -1.0]
- !lego_feature
part: *wah
point: [-12.0, 0.0, -4.0]
- complement: Stud #todo: deleteme
- type: AntiStud
+ type: anti stud
x_vec: [-1.0, 0.0, 0.0]
y_vec: [-0.0, -0.0, -1.0]
- !lego_feature
part: *wah
point: [-12.0, 0.0, -12.0]
- complement: Stud #todo: deleteme
- type: AntiStud
+ type: anti stud
x_vec: [-1.0, 0.0, 0.0]
y_vec: [-0.0, -0.0, -1.0]
- !lego_feature
part: *wah
point: [-4.0, 0.0, -12.0]
- complement: Stud #todo: deleteme
- type: AntiStud
+ type: anti stud
x_vec: [-1.0, 0.0, 0.0]
y_vec: [-0.0, -0.0, -1.0]
- !lego_feature
part: *wah
point: [-12.0, 9.5999999999999996, -4.0]
- type: Stud
- complement: AntiStud #todo: deleteme
+ type: stud
x_vec: [-1.0, 0.0, -0.0]
y_vec: [-0.0, -0.0, 1.0]
- !lego_feature
part: *wah
point: [-4.0, 9.5999999999999996, -4.0]
- type: Stud
- complement: AntiStud #todo: deleteme
+ type: stud
x_vec: [-1.0, 0.0, -0.0]
y_vec: [-0.0, -0.0, 1.0]
- !lego_feature
part: *wah
point: [-4.0, 9.5999999999999996, -12.0]
- type: Stud
- complement: AntiStud #todo: deleteme
+ type: stud
x_vec: [-1.0, 0.0, -0.0]
y_vec: [-0.0, -0.0, 1.0]
- !lego_feature
part: *wah
point: [-12.0, 9.5999999999999996, -12.0]
- type: Stud
- complement: AntiStud #todo: deleteme
+ type: stud
x_vec: [-1.0, 0.0, -0.0]
y_vec: [-0.0, -0.0, 1.0]
- !lego_feature
part: *wah
point: [-8.0, 9.5999999999999996, -8.0]
- type: AntiStudCup
- complement: StudCup #todo: deleteme
+ type: anti stud cup
x_vec: [-1.0, 0.0, -0.0]
y_vec: [-0.0, -0.0, 1.0]
- !lego_feature
part: *wah
point: [-8.0, 9.5999999999999996, -8.0]
- type: AntiStudCup
- complement: Stud #todo: deleteme
+ type: anti stud cup
x_vec: [-1.0, 0.0, -0.0]
y_vec: [-0.0, -0.0, 1.0]
@@ -106,7 +95,7 @@ parts:
interfaces:
- !lego_feature
name: peg1
- type: Stud
+ type: stud
geometry: #!cylinder #this is not necessary since a Peg interface should know its geometry
height: 1.7mm
diameter: 5mm
@@ -116,18 +105,18 @@ parts:
- 'models/peg.step'
#point it upwards (of course, Peg should know this too)
- !lego_feature
- type: Stud
+ type: stud
name: peg2
point: [8, 16, 0.85]
- !lego_feature
- type: Stud
+ type: stud
name: peg3
point: [16, 8, 0.85]
- !lego_feature
- type: Stud
+ type: stud
name: peg4
point: [16, 16, 0.85]
- !lego_feature
- type: Stud
+ type: stud
name: hole1
diff --git a/packages/lego/grammar.yaml b/packages/lego/grammar.yaml
index 21e541e..90868b0 100644
--- a/packages/lego/grammar.yaml
+++ b/packages/lego/grammar.yaml
@@ -1,313 +1,313 @@
# this file more or less describes the grammar used for constructing things out of Lego
#for part examples see http://guide.lugnet.com/partsref/search.cgi?q=XXXX
features:
- face: !lego_feature
+ face:
#class edge to refer to the rim around each brick?
complement: [face, tire]
- stud: !lego_feature
+ stud:
complement: [anti stud, stud cup, pin hole]
example: 3005
technique: press_fit #this should be different... somehow
kinematics: revolute
- anti stud: !lego_feature
+ anti stud:
comment: this typically has 3 or 4 contact points, but is not round
complement: stud
example: 3005
technique: press_fit
kinematics: revolute
- stud cup: !lego_feature
+ stud cup:
complement: [stud, anti stud cup]
example: 4073
technique: press_fit
kinematics: revolute
- anti stud cup: !lego_feature
+ anti stud cup:
comment: this occurs when there are 4 studs or technic studs in a square
complement: stud cup
example: 2654
technique: press_fit
kinematics: revolute
- tall stud cup: !lego_feature
+ tall stud cup:
complement: [stud, anti stud cup]
example: '3062a'
technique: press_fit
kinematics: revolute
- technic stud: !lego_feature
+ technic stud:
complement: [anti stud, pin hole, stud cup]
#TODO finish technic
- hollow stud : !lego_feature
+ hollow stud :
#assert isinstance( revolute joint)
complement: [bar, anti stud]
example: '3062b' #4081b
technique: press_fit
kinematics: revolute
- duplo stud: !lego_feature
+ duplo stud:
complement: duplo anti stud
technique: press_fit
kinematics: revolute
- duplo anti stud: !lego_feature
+ duplo anti stud:
complement: duplo stud
technique: press_fit
kinematics: revolute
- bar: !lego_feature
+ bar:
complement: [claw, hollow stud]
example: 3957
technique: [snap_fit, press_fit]
kinematics: revolute
- claw: !lego_feature
+ claw:
complement: bar
example: 6019
technique: snap_fit
kinematics: revolute
- pin: !lego_feature
+ pin:
complement: pin hole
example: 3673
technique: snap_fit
kinematics: revolute
- sticky pin: !lego_feature
+ sticky pin:
#TODO finish
technique: snap_fit
kinematics: revolute
- pin hole: !lego_feature
+ pin hole:
complement: [pin, stud, technic stud, hollow stud]
example: 3700
technique: [snap_fit, press_fit]
kinematics: [revolute, prismatic]
- mini pin: !lego_feature
+ mini pin:
complement: mini pin hole
example: 4488
technique: snap_fit
kinematics: revolute
- mini pin hole: !lego_feature
+ mini pin hole:
complement: mini pin
example: none #find one then!
technique: snap_fit
kinematics: revolute
- short pin: !lego_feature
+ short pin:
complement: plate hole
example: 'that step file pin0 or whatever'
technique: snap_fit
kinematics: revolute
- plate hole: !lego_feature
+ plate hole:
# add something about stacking two plates is compatible with pin
complement: shortpin
example: '3709b'
technique: snap_fit
kinematics: revolute
- tow ball: !lego_feature
+ tow ball:
complement: tow ball socket
example: 3184
technique: snap_fit
kinematics: spherical
- tow ball socket: !lego_feature
+ tow ball socket:
complement: tow ball
example: 3183
technique: snap_fit
kinematics: spherical
- magnet: !lego_feature
+ magnet:
# do magnets have the same stub axle as wheels?
complement: magnet
example: 73092
technique: positioning
kinematics: planar
- wheel holder: !lego_feature
+ wheel holder:
# is this the same as 2607?
complement: wheel axle
example: 8
technique: snap_fit
kinematics: revolute
- wheel axle: !lego_feature # snap fit?
+ wheel axle: # snap fit?
complement: wheel holder
example: 3464
technique: snap_fit
kinematics: revolute
- wheel rim: !lego_feature
+ wheel rim:
complement: tire inner
example: 3464
technique: snap_fit
kinematics: revolute
- tire inner: !lego_feature
+ tire inner:
complement: wheel rim
technique: snap_fit
kinematics: revolute
- tire outer: !lego_feature
+ tire outer:
complement: edge
technique: positioning
kinematics: gear
- swivel top: !lego_feature
+ swivel top:
# is this really a minifig shoulder?
complement: swivel bottom
example: 3679
technique: snap_fit
kinematics: revolute
- swivel bottom: !lego_feature
+ swivel bottom:
# is this really a minifig shoulder hole?
complement: swivel top
example: 3680
technique: snap_fit
kinematics: revolute
- turntable top: !lego_feature
+ turntable top:
complement: turntable bottom
example: 3404
technique: snap_fit
kinematics: revolute
- turntable bottom: !lego_feature
+ turntable bottom:
complement: turntable top
example: 3403
technique: snap_fit
kinematics: revolute
- scissor hinge top: !lego_feature
+ scissor hinge top:
complement: scissor hinge bottom
example: 2430
technique: snap_fit
kinematics: hinge
- scissor hinge bottom: !lego_feature
+ scissor hinge bottom:
complement: scissor hinge top
example: 2429
technique: snap_fit
kinematics: hinge
- elevation hinge holder: !lego_feature
+ elevation hinge holder:
complement: elevation hinge
example: 3937
technique: snap_fit
kinematics: hinge
- elevation hinge: !lego_feature
+ elevation hinge:
complement: elevation hinge holder
example: 3938
technique: snap_fit
kinematics: hinge
- flat hinge2: !lego_feature
+ flat hinge2:
complement: flat hinge3
example: 4276
technique: snap_fit
kinematics: hinge
- flat hinge3: !lego_feature
+ flat hinge3:
complement: flat hinge2
example: 2452
technique: snap_fit
kinematics: hinge
- wide hinge m: !lego_feature
+ wide hinge m:
complement: wide hinge f
example: 4315
technique: snap_fit
kinematics: hinge
- wide hinge f: !lego_feature
+ wide hinge f:
complement: wide hinge m
example: 2872
technique: snap_fit
kinematics: hinge
- trailer hinge m: !lego_feature
+ trailer hinge m:
complement: [trailer hinge f, claw]
example: 3639
technique: snap_fit
kinematics: hinge
- trailer hinge f: !lego_feature
+ trailer hinge f:
complement: [trailer hinge m, bar]
example: 3640
technique: snap_fit
kinematics: hinge
- round hinge 2: !lego_feature
+ round hinge 2:
complement: round hinge 3
example: 6048
technique: snap_fit
kinematics: hinge
- round hinge 3: !lego_feature
+ round hinge 3:
complement: round hinge 2
example: 6217
technique: snap_fit
kinematics: hinge
- locking hinge 1: !lego_feature
+ locking hinge 1:
# sorta iffy on these as i've never seen them
complement: locking hinge 2
example: 30364
technique: snap_fit
kinematics: [hinge, discrete_angle]
angle: 20deg #?
- locking hinge 2: !lego_feature
+ locking hinge 2:
complement: locking hinge 1
example: 30365
technique: snap_fit
kinematics: [hinge, discrete_angle]
angle: 20deg #?
- axle: !lego_feature
+ axle:
complement: [anti axle, pin hole]
example: 3705
technique: [press_fit, positioning]
kinematics: [revolute, prismatic, discrete_angle]
angle: rev/4
- anti axle: !lego_feature
+ anti axle:
complement: axle
example: 32064
technique: press_fit
kinematics: [prismatic, discrete_angle]
angle: rev/4
- toothed joint: !lego_feature
+ toothed joint:
# there are 16 possible mates between two toothed joint interfaces
complement: toothed joint
example: 4263
technique: press_fit
kinematics: discrete_angle
angle: rev/16
- minifig neck: !lego_feature
+ minifig neck:
complement: [minifig neck hole, anti stud]
example: 973
technique: press_fit
kinematics: revolute
- minifig neck hole: !lego_feature
+ minifig neck hole:
complement: [minifig neck, stud]
example: 'standard lego head'
technique: press_fit
kinematics: revolute
- minifig backpack: !lego_feature #not actually a press fit; it's loose
+ minifig backpack: #not actually a press fit; it's loose
complement: minifig torso
example: 'wtf srsly where is it'
technique: positioning
kinematics: discrete_angle
angle: rev/2
- minifig torso: !lego_feature #not actually a press fit; it's loose
+ minifig torso: #not actually a press fit; it's loose
# for backpacks and armor and so on
complement: minifig backpack
example: 3838
technique: positioning
kinematics: discrete_angle
angle: rev/2
- minifig wrist: !lego_feature #is this a snap fit?
+ minifig wrist: #is this a snap fit?
complement: minifig wrist hole
example: 983
technique: snap_fit
kinematics: revolute
- minifig wrist hole: !lego_feature #is this a snap fit?
+ minifig wrist hole: #is this a snap fit?
complement: minifig wrist
example: 976
technique: snap_fit
kinematics: revolute
- minifig shoulder: !lego_feature
+ minifig shoulder:
complement: minifig shoulder hole
example: 976
technique: snap_fit
kinematics: revolute
- minifig shoulder hole: !lego_feature
+ minifig shoulder hole:
complement: minifig shoulder
example: 973
technique: snap_fit
kinematics: revolute
- minifig waist: !lego_feature
+ minifig waist:
complement: minifig hip
example: 973
technique: press_fit
kinematics: revolute
- minifig hip stud: !lego_feature
+ minifig hip stud:
# does this really not interface with anything else?
complement: minifig waist
example: 970
technique: press_fit
kinematics: discrete_angle
angle: rev/4
- minifig leg pin: !lego_feature
+ minifig leg pin:
complement: minifig leg hole
example: 970
technique: snap_fit
kinematics: hinge
- minifig leg hole: !lego_feature
+ minifig leg hole:
complement: minifig leg pin
example: 971
technique: snap_fit
diff --git a/packages/lego/interfaces.py b/packages/lego/interfaces.py
index 8f90d7f..4e736ed 100644
--- a/packages/lego/interfaces.py
+++ b/packages/lego/interfaces.py
@@ -4,7 +4,8 @@ not done. see http://mr-bucket.co.uk/GLIDE/LCD_File_Format.html#Implimentation
for part examples see http://guide.lugnet.com/partsref/search.cgi?q=XXXX
or http://img.lugnet.com/ld/XXXX.gif
'''
-from skdb import Interface
+import os
+import skdb
class Joint:
'''should pull in some kinematics from elsewhere; PyODE?'''
@@ -25,19 +26,56 @@ class Discrete:
'''allows only a certain set of values'''
pass
-grammar = {
- 'Stud':{'complement':['AntiStud', 'Stud'], 'example':'3005'}}
+#class Grammar(skdb.FennObject, dict):
+# yaml_tag='!lego_grammar'
-class Feature(Interface):
+fh = skdb.package_file('lego', 'grammar.yaml')
+grammar = skdb.load(fh)['features']
+
+#stuff values
+for key in grammar.keys():
+ grammar[key]['name'] = key
+
+def dump_grammar_file():
+ '''you probably should pipe through 'grep -v name'''''
+ import yaml
+ return yaml.dump(grammar)
+
+class Feature(skdb.Interface):
yaml_tag='!lego_feature'
- def __repr__(self):
+ yaml_flow_style=False
+ def __init__(self, name=None, type=None, part=None):
+ skdb.Interface.__init__(self, name=name, part=part)
+ self.type=type
+ def post_init_hook(self):
+ try:
+ type = self.type
+ self.overlay(grammar[type])
+ except AttributeError: self.type = None
+
try: part_name = self.part.name
except AttributeError: part_name = None
try: name = self.name
except AttributeError: name = None
+ def compatible(self, other):
+ if other.type in self.complement:
+ assert self.type in other.complement, 'vice versa not fulfilled for "%s" and "%s"' %(self.type, other.type)
+ return True
+ else: return False
+
+ def __repr__(self):
+ return "%s(part=%s,name=%s, type=%s)" % (self.__class__.__name__, self.part_name, self.name, self.type)
+
+ def example_picture(self):
+ '''example should be an ldraw number'''
+ return "http://img.lugnet.com/ld/"+self.example+".gif"
+
+ def example_lugnet(self):
+ return "http://guide.lugnet.com/partsref/search.cgi?q="+self.example
- return "%s(part=%s,name=%s)" % (self.__class__.__name__, part_name, name)
+ def example_peeron(self):
+ return "http://www.peeron.com/inv/parts/"+self.example
class PressFit(Feature):
'''this should probably link up with some other class'''
@@ -49,3 +87,5 @@ class SnapFit(Feature):
class Hinge(RevoluteJoint, SnapFit): pass
+if __name__ == '__main__':
+ print dump_grammar_file() \ No newline at end of file
diff --git a/packages/lego/lego.py b/packages/lego/lego.py
index 5e72256..ea585ff 100644
--- a/packages/lego/lego.py
+++ b/packages/lego/lego.py
@@ -1,7 +1,7 @@
#!/usr/bin/python
from skdb import Part
from string import Template
-from interfaces import Stud, AntiStud
+from interfaces import grammar, Feature
__author__ = "bryan bishop"
__license__ = "GPL2+"
@@ -18,11 +18,11 @@ class Lego(Part):
self.name = name
self.interfaces = []
for each in range(num_holes):
- new_hole = AntiStud(self)
+ new_hole = grammar['anti stud']
new_hole.identifier = len(self.interfaces)
self.interfaces.append(new_hole)
for each in range(num_pegs):
- new_peg = Stud(self)
+ new_peg = grammar['stud']
new_peg.identifier = len(self.interfaces)
self.interfaces.append(new_peg)
def pegs(self):
diff --git a/packages/lego/metadata.yaml b/packages/lego/metadata.yaml
index 71cc26b..65ff087 100644
--- a/packages/lego/metadata.yaml
+++ b/packages/lego/metadata.yaml
@@ -41,8 +41,7 @@ tags:
classes:
lego:
- Lego
- - Stud
- - AntiStud
+ - Feature
source data:
- data.yaml
generated data: