Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions labextension/vpython/src/glowcommlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,22 @@ function send() { // periodically send events and update_canvas and request obje


// *************************************************************************************************** //
// THE REST OF THIS FILE IS IDENTICAL IN glowcomm.html AND glowcomm.js (except for the last few lines) //

// Should eventually have glowcomm.html and glowcom.js both import this common component.
// THE REST OF THIS FILE IS NEARLY IDENTICAL IN glowcomm.html AND glowcomm.js AND glowcommlab.js //

// Should eventually have glowcomm.html, glowcom.js, and glowcommlab.js all import this common component.

window.__GSlang = "vpython"
box = vp_box
sphere = vp_sphere
simple_sphere = vp_simple_sphere
cylinder = vp_cylinder
pyramid = vp_pyramid
cone = vp_cone
helix = vp_helix
ellipsoid = vp_ellipsoid
ring = vp_ring
arrow = vp_arrow
compound = vp_compound

function msclock() {
"use strict";
Expand Down Expand Up @@ -275,6 +288,7 @@ function update_canvas() { // mouse location and other stuff

/*
var request = new XMLHttpRequest()

function send_to_server(data, callback) { // send to HTTP server
var data= JSON.stringify(data)
request.open('get', data, true)
Expand All @@ -287,6 +301,7 @@ function send_to_server(data, callback) { // send to HTTP server
}
request.send()
}

function ok(req) { ; }
*/

Expand Down Expand Up @@ -372,7 +387,7 @@ function process_waitfor(event) {
}

function process_binding(event) { // event associated with a previous bind command
"use strict";
"use strict";
event.bind = true
process(event)
}
Expand Down Expand Up @@ -625,8 +640,6 @@ function handle_cmds(dcmds) {
ptlist.push( o2vec3(val[kk]) )
}
cfg[attr] = ptlist
} else if (attr === "axis" && obj == 'arrow') {
cfg['axis_and_length'] = o2vec3(val)
} else if (vlst.indexOf(attr) !== -1) {
cfg[attr] = o2vec3(val)
} else if (triangle_quad.indexOf(attr) !== -1) {
Expand Down Expand Up @@ -775,7 +788,6 @@ function handle_cmds(dcmds) {
catch(err) {
console.log("glowcomm canvas contextmenu event : ",err.message);
}

break
// Display frames per second and render time:
//$("<div id='fps'/>").appendTo(glowObjs[idx].title)
Expand Down Expand Up @@ -988,17 +1000,6 @@ function handle_attrs(dattrs) {
ptlist.push( val[kk] )
}
obj[attr] = ptlist
} else if (attr === 'axis') {
// For axis and up, Python maintains them to be perpendicular, so avoid
// having GlowScript do it again, which can have bad results.
window.__adjustupaxis = false
if (obj instanceof arrow) attr = 'axis_and_length'
obj[attr] = val
window.__adjustupaxis = true
} else if (attr === 'up') {
window.__adjustupaxis = false
obj[attr] = val
window.__adjustupaxis = true
} else {
obj[attr] = val
}
Expand Down
70 changes: 12 additions & 58 deletions vpython/vpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,25 +629,24 @@ def setup(self, args):
else: raise AttributeError(a+' must be a vector')
del args[a]

vectorInteractions = [ ('size','axis'), ('axis','size'), ('axis','up'), ('up','axis')]

# override defaults for vector attributes with side effects
# Track side effects of modifying size, axis, or up
# For consistency with GlowScript, axis is listed before up in the attrLists,
# so that setting axis may affect up, but then setting up can affect axis afterwards.
attrs = standardAttributes.attrLists[objName][1]
attrs = standardAttributes.attrLists[objName][1] # vector attributes with interactions
for a in attrs:
if a in args:
val = args[a]
if isinstance(val, vector):
setattr(self, a, vector(val)) ## use setter to take care of side effects; copy of val
setattr(self, a, vector(val))
if a not in argsToSend:
argsToSend.append(a)
for vi in vectorInteractions:
if vi[0] == a:
if vi[1] not in argsToSend:
argsToSend.append(vi[1])
elif objName == 'points' and a == 'size': ## in this case size is a scalar
argsToSend.append(a)
if a == 'size':
self._axis = self._axis.norm()*val.x
elif a == 'axis':
self._size.x = mag(val)
self.axis = val # this will have the side effect of modifying up
elif a == 'up':
self.up = val # this will have the side effect of modifying axis
else: raise AttributeError(a+' must be a vector')
del args[a]

Expand Down Expand Up @@ -695,10 +694,8 @@ def setup(self, args):
elif isinstance(aval, vertex):
aval = aval.idx
if objName in nosize and a == 'size': continue # do not send superfluous size
#cmd["attrs"].append({"attr":a, "value": aval})
cmd[a] = aval


# set canvas
if self.canvas is None: ## not specified in constructor
self.canvas = canvas.get_selected()
Expand Down Expand Up @@ -757,8 +754,6 @@ def up(self):
def up(self,value):
self._save_oldup = adjust_axis(self._up, value, self._axis, self._save_oldup) # this sets self._axis and self._up
if not self._constructing:
# must update both axis and up when either is changed
self.addattr('axis')
self.addattr('up')

@property
Expand All @@ -768,14 +763,8 @@ def axis(self):
def axis(self,value):
self._save_oldaxis = adjust_up(self._axis, value, self._up, self._save_oldaxis) # this sets self._axis and self._up
if not self._constructing:
# must update both axis and up when either is changed
self.addattr('axis')
self.addattr('up')
m = value.mag
if abs(self._size._x - m) > 0.0001*self._size._x: # need not update size if very small change
self._size._x = m
if not self._constructing:
self.addattr('size')
self._size._x = value.mag # changing axis length changes size.x

@property
def size(self):
Expand All @@ -788,11 +777,7 @@ def size(self,value):
a = self._axis.norm() * value.x
if mag(self._axis) == 0:
a = vector(value.x,0,0)
v = self._axis
if not v.equals(a):
self._axis.value = a
if not self._constructing:
self.addattr('axis')
self._axis.value = a # changing size changes length of axis

@property
def length(self):
Expand Down Expand Up @@ -1263,37 +1248,6 @@ def __init__(self, **args):

super(arrow, self).setup(args)

@property
def size(self):
return self._size
@size.setter
def size(self,value): # no need to send to browser both arrow.size and arrow.axis
self._size.value = value
if not self._constructing:
self.addattr('size')
a = self._axis.norm() * value.x
if mag(self._axis) == 0:
a = vector(value.x,0,0)
v = self._axis
if not v.equals(a):
self._axis.value = a

@property
def axis(self):
return self._axis
@axis.setter
def axis(self,value): # no need to send to browser both arrow.size and arrow.axis
oldaxis = norm(self._axis)
self._axis.value = value
m = value.mag
if abs(self._size._x - m) > 0.0001*self._size._x: # need not update size if very small change
self._size._x = m
self._save_oldaxis = adjust_up(norm(oldaxis), self._axis, self._up, self._save_oldaxis)
if not self._constructing:
# must update both axis and up when either is changed
self.addattr('axis')
self.addattr('up')

@property
def shaftwidth(self):
return self._shaftwidth
Expand Down
34 changes: 17 additions & 17 deletions vpython/vpython_libraries/glowcomm.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,22 @@
}

// *************************************************************************************************** //
// THE REST OF THIS FILE IS IDENTICAL IN glowcomm.html AND glowcomm.js (except for the last few lines) //

// Should eventually have glowcomm.html and glowcom.js both import this common component.
// THE REST OF THIS FILE IS NEARLY IDENTICAL IN glowcomm.html AND glowcomm.js AND glowcommlab.js //

// Should eventually have glowcomm.html, glowcom.js, and glowcommlab.js all import this common component.

window.__GSlang = "vpython"
box = vp_box
sphere = vp_sphere
simple_sphere = vp_simple_sphere
cylinder = vp_cylinder
pyramid = vp_pyramid
cone = vp_cone
helix = vp_helix
ellipsoid = vp_ellipsoid
ring = vp_ring
arrow = vp_arrow
compound = vp_compound

function msclock() {
"use strict";
Expand Down Expand Up @@ -319,7 +332,7 @@
}

function process_binding(event) { // event associated with a previous bind command
"use strict";
"use strict";
event.bind = true
process(event)
}
Expand Down Expand Up @@ -572,8 +585,6 @@
ptlist.push( o2vec3(val[kk]) )
}
cfg[attr] = ptlist
} else if (attr === "axis" && obj == 'arrow') {
cfg['axis_and_length'] = o2vec3(val)
} else if (vlst.indexOf(attr) !== -1) {
cfg[attr] = o2vec3(val)
} else if (triangle_quad.indexOf(attr) !== -1) {
Expand Down Expand Up @@ -921,17 +932,6 @@
ptlist.push( val[kk] )
}
obj[attr] = ptlist
} else if (attr === 'axis') {
// For axis and up, Python maintains them to be perpendicular, so avoid
// having GlowScript do it again, which can have bad results.
window.__adjustupaxis = false
if (obj instanceof arrow) attr = 'axis_and_length'
obj[attr] = val
window.__adjustupaxis = true
} else if (attr === 'up') {
window.__adjustupaxis = false
obj[attr] = val
window.__adjustupaxis = true
} else {
obj[attr] = val
}
Expand Down
34 changes: 17 additions & 17 deletions vpython/vpython_libraries/glowcomm.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,22 @@ function send() { // periodically send events and update_canvas and request obje
}

// *************************************************************************************************** //
// THE REST OF THIS FILE IS IDENTICAL IN glowcomm.html AND glowcomm.js (except for the last few lines) //

// Should eventually have glowcomm.html and glowcom.js both import this common component.
// THE REST OF THIS FILE IS NEARLY IDENTICAL IN glowcomm.html AND glowcomm.js AND glowcommlab.js //

// Should eventually have glowcomm.html, glowcom.js, and glowcommlab.js all import this common component.

window.__GSlang = "vpython"
box = vp_box
sphere = vp_sphere
simple_sphere = vp_simple_sphere
cylinder = vp_cylinder
pyramid = vp_pyramid
cone = vp_cone
helix = vp_helix
ellipsoid = vp_ellipsoid
ring = vp_ring
arrow = vp_arrow
compound = vp_compound

function msclock() {
"use strict";
Expand Down Expand Up @@ -369,7 +382,7 @@ function process_waitfor(event) {
}

function process_binding(event) { // event associated with a previous bind command
"use strict";
"use strict";
event.bind = true
process(event)
}
Expand Down Expand Up @@ -622,8 +635,6 @@ function handle_cmds(dcmds) {
ptlist.push( o2vec3(val[kk]) )
}
cfg[attr] = ptlist
} else if (attr === "axis" && obj == 'arrow') {
cfg['axis_and_length'] = o2vec3(val)
} else if (vlst.indexOf(attr) !== -1) {
cfg[attr] = o2vec3(val)
} else if (triangle_quad.indexOf(attr) !== -1) {
Expand Down Expand Up @@ -984,17 +995,6 @@ function handle_attrs(dattrs) {
ptlist.push( val[kk] )
}
obj[attr] = ptlist
} else if (attr === 'axis') {
// For axis and up, Python maintains them to be perpendicular, so avoid
// having GlowScript do it again, which can have bad results.
window.__adjustupaxis = false
if (obj instanceof arrow) attr = 'axis_and_length'
obj[attr] = val
window.__adjustupaxis = true
} else if (attr === 'up') {
window.__adjustupaxis = false
obj[attr] = val
window.__adjustupaxis = true
} else {
obj[attr] = val
}
Expand Down