Skip to content

Commit 2a57f1d

Browse files
committed
Improve attach_arrow
1 parent 24ebde1 commit 2a57f1d

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

vpython/vpython.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ class standardAttributes(baseObj):
543543
['v0', 'v1', 'v2', 'v3'] ],
544544
'attach_arrow': [ [ 'color', 'attrval'],
545545
[],
546-
['shaftwidth', 'scale', 'obj', 'attr'],
546+
['shaftwidth', 'round', 'scale', 'obj', 'attr'],
547547
[] ],
548548
'attach_trail': [ ['color'],
549549
[],
@@ -612,6 +612,7 @@ def setup(self, args):
612612
self._pickable = True
613613
self._save_oldaxis = None # used in linking axis and up
614614
self._save_oldup = None # used in linking axis and up
615+
self._round = False
615616
_special_clone = None
616617
if '_cloneid' in args: # text, extrusion, or compound is being cloned
617618
_special_clone = args['_cloneid']
@@ -1287,17 +1288,27 @@ class attach_arrow(standardAttributes):
12871288
def __init__(self, obj, attr, **args):
12881289
attrs = ['pos', 'size', 'axis', 'up', 'color']
12891290
args['_default_size'] = None
1291+
a = getattr(obj, attr) # This raises an error if obj does not have attr
1292+
if not isinstance(a, vector): raise AttributeError('The attach_arrow attribute "'+attr+ '" is not a vector.')
12901293
self.obj = args['obj'] = obj.idx
12911294
self.attr = args['attr'] = attr # could be for example "velocity"
12921295
self.attrval = args['attrval'] = getattr(baseObj.object_registry[self.obj], attr)
12931296
args['_objName'] = "attach_arrow"
12941297
self._last_val = None
12951298
self._scale = 1
12961299
self._shaftwidth = 0
1300+
self._round = False
12971301
super(attach_arrow, self).setup(args)
12981302
# Only if the attribute is a user attribute do we need to add to attach_arrows:
12991303
if attr not in attrs: baseObj.attach_arrows.append(self)
13001304

1305+
@property
1306+
def round(self):
1307+
return self._round
1308+
@round.setter
1309+
def round(self,value):
1310+
raise AttributeError('Cannot change the "round" attribute of an attach_arrow.')
1311+
13011312
@property
13021313
def scale(self):
13031314
return self._scale

vpython/vpython_libraries/glow.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vpython/vpython_libraries/glowcomm.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@
544544
for (var d in data) {
545545
for (var i in data[d]) console.log(i, JSON.stringify(data[d][i]))
546546
}
547-
*/
547+
*/
548548

549549
if (data.cmds !== undefined && data.cmds.length > 0) handle_cmds(data.cmds)
550550
if (data.methods !== undefined && data.methods.length > 0) handle_methods(data.methods)
@@ -731,15 +731,15 @@
731731
//$("<div id='fps'/>").appendTo(glowObjs[idx].title)
732732
}
733733
case 'attach_arrow': {
734-
var attrs = ['pos', 'size', 'axis', 'up', 'color']
734+
var attrs = ['pos', 'size', 'axis', 'up', 'color']
735735
var o = glowObjs[cfg['obj']]
736736
delete cfg['obj']
737737
var attr = cfg['attr']
738738
delete cfg['attr']
739-
var val = cfg['attrval']
740-
delete cfg['attrval']
741-
if (attrs.indexOf(attr) < 0) attr = '_attach_arrow'
742-
o.attr = val
739+
var val = cfg['attrval']
740+
delete cfg['attrval']
741+
if (attrs.indexOf(attr) < 0) attr = '_attach_arrow'
742+
o.attr = val
743743
glowObjs[idx] = attach_arrow( o, attr, cfg )
744744
break
745745
}
@@ -962,4 +962,4 @@
962962

963963
</script>
964964
</div>
965-
</body>
965+
</body>

vpython/vpython_libraries/glowcomm.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -794,10 +794,10 @@ function handle_cmds(dcmds) {
794794
delete cfg['obj']
795795
var attr = cfg['attr']
796796
delete cfg['attr']
797-
var val = cfg['attrval']
798-
delete cfg['attrval']
799-
if (attrs.indexOf(attr) < 0) attr = '_attach_arrow'
800-
o.attr = val
797+
var val = cfg['attrval']
798+
delete cfg['attrval']
799+
if (attrs.indexOf(attr) < 0) attr = '_attach_arrow'
800+
o.attr = val
801801
glowObjs[idx] = attach_arrow( o, attr, cfg )
802802
break
803803
}

0 commit comments

Comments
 (0)