Skip to content

Commit

Permalink
Merge pull request #1557 from UV-CDAT/1446_portrait_mode
Browse files Browse the repository at this point in the history
Fix view rotation when rendering in background mode
  • Loading branch information
doutriaux1 committed Sep 29, 2015
2 parents ba78d8d + 93683bf commit a5d16ac
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 11 deletions.
14 changes: 7 additions & 7 deletions Packages/vcs/Lib/Canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# landscape (width exceeding height), portrait (height exceeding#
# width), or full-screen mode. #
# #
# Version: 4.0 #
# Version: 2.4 #
# #
###############################################################################

Expand Down Expand Up @@ -4462,21 +4462,21 @@ def landscape(self, width=-99, height=-99, x=-99, y=-99, clear=0):
if (self.orientation() == 'landscape'):
return

if (((not isinstance(width, IntType))) or ((not isinstance(height, IntType))) or
((not isinstance(x, IntType))) or ((not isinstance(y, IntType))) or
if (((not isinstance(width, int))) or ((not isinstance(height, int))) or
((not isinstance(x, int))) or ((not isinstance(y, int))) or
((width != -99) and (width < 0)) or ((height != -99) and (height < 0)) or
((x != -99) and (x < 0)) or ((y != -99) and (y < 0))):
raise ValueError(
'If specified, width, height, x, and y must be integer values greater than or equal to 0.')
if (((not isinstance(clear, IntType))) and (clear not in [0, 1])):
if (((not isinstance(clear, int))) and (clear not in [0, 1])):
raise ValueError(
"clear must be: 0 - 'the default value for not clearing the canvas' or 1 - 'for clearing the canvas'.")

if ((width == -99) and (height == -99)
and (x == -99) and (y == -99) and (clear == 0)):
cargs = ()
try:
dict = self.canvas.canvasinfo(*cargs)
dict = self.canvasinfo(*cargs)
except:
dict = {}
height = dict.get('width', -99)
Expand All @@ -4486,7 +4486,7 @@ def landscape(self, width=-99, height=-99, x=-99, y=-99, clear=0):
self.flush() # update the canvas by processing all the X events

args = (width, height, x, y, clear)
l = self.canvas.landscape(*args)
l = self.backend.landscape(*args)

return l

Expand Down Expand Up @@ -4657,7 +4657,7 @@ def portrait(self, width=-99, height=-99, x=-99, y=-99, clear=0):
and (x == -99) and (y == -99) and (clear == 0)):
cargs = ()
try:
dict = self.canvas.canvasinfo(*cargs)
dict = self.canvasinfo(*cargs)
except:
dict = {}
height = dict.get('width', -99)
Expand Down
19 changes: 15 additions & 4 deletions Packages/vcs/Lib/VTKPlots.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,18 @@ def canvasinfo(self):
return info

def orientation(self, *args, **kargs):
if self.renWin is None:
return "landscape"
w, h = self.renWin.GetSize()
canvas_info = self.canvasinfo()
w = canvas_info["width"]
h = canvas_info["height"]
if w > h:
return "landscape"
else:
return "portrait"

def portrait(self, W, H, x, y, clear):
def resize_or_rotate_window(self, W=-99, H=-99, x=-99, y=-99, clear=0):
# Resize and position window to the provided arguments except when the
# values are default and negative. In the latter case, it should just
# rotate the window.
if clear:
self.clear()
if self.renWin is None:
Expand All @@ -404,6 +407,14 @@ def portrait(self, W, H, x, y, clear):
self.canvas.bgY = W
else:
self.renWin.SetSize(W, H)
self.canvas.bgX = W
self.canvas.bgY = H

def portrait(self, W=-99, H=-99, x=-99, y=-99, clear=0):
self.resize_or_rotate_window(W, H, x, y, clear)

def landscape(self, W=-99, H=-99, x=-99, y=-99, clear=0):
self.resize_or_rotate_window(W, H, x, y, clear)

def initialSize(self):
# Gets user physical screen dimensions
Expand Down
4 changes: 4 additions & 0 deletions testing/vcs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ cdat_add_test(vcs_test_dump_json
${cdat_SOURCE_DIR}/testing/vcs/test_dump_json.py
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_dump_json.json
)
cdat_add_test(vcs_test_background_mode_rotate
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_background_mode_rotate.py
)

# Some vector plot testing
FOREACH(angle -180 -135 -90 -45 0 45 135 90 135 )
Expand Down
44 changes: 44 additions & 0 deletions testing/vcs/test_background_mode_rotate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import vcs
import numpy

data = numpy.sin(numpy.arange(100))
data = numpy.reshape(data, (10, 10))

x = vcs.init()
x.plot(data, bg=1)
assert x.orientation() == "landscape", "Default canvas orientation failed"
c = x.canvasinfo()
assert c['width'] == 814, "Default canvas width failed"
assert c['height'] == 606, "Default canvas height failed"

x.clear()
x.portrait()
x.plot(data, bg=1)
assert x.orientation() == "portrait", "Portrait canvas orientation failed"
c = x.canvasinfo()
assert c['width'] == 606, "Portrait canvas width failed"
assert c['height'] == 814, "Portrait canvas height failed"

x.clear()
x.landscape()
x.plot(data, bg=1)
assert x.orientation() == "landscape", "Landscape canvas orientation failed"
c = x.canvasinfo()
assert c['width'] == 814, "Landscape canvas width failed"
assert c['height'] == 606, "Landscape canvas height failed"

x.clear()
x.landscape()
x.plot(data, bg=1)
assert x.orientation() == "landscape", "Landscape canvas orientation failed"
c = x.canvasinfo()
assert c['width'] == 814, "Landscape canvas width failed"
assert c['height'] == 606, "Landscape canvas height failed"

x.clear()
x.portrait()
x.plot(data, bg=1)
assert x.orientation() == "portrait", "Portrait canvas orientation failed"
c = x.canvasinfo()
assert c['width'] == 606, "Portrait canvas width failed"
assert c['height'] == 814, "Portrait canvas height failed"

0 comments on commit a5d16ac

Please sign in to comment.