Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix view rotation when rendering in background mode #1557

Merged
merged 10 commits into from
Sep 29, 2015
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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sankhesh this does not work the following snippet demonstrates the problem:

import cdms2
import vcs
import os
f=cdms2.open(os.path.join(vcs.sample_data,"clt.nc"))
s=f("clt")
x=vcs.init()
x.portrait()  # turn page in portrait mode
x.portrait()  # turn page in portrait mode (again but it is already in portrait so it should be doing nothing)
x.plot(s)
x.png("test_portrait_bg")

leads to:
test_portrait_bg

Essentially you rotate twice

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sankhesh you might want to add this as a test too if @aashish24 thinks it is a worthy test 😉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sankhesh I pushed a fix

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sankhesh sorry there is still an issue somewhere:

import vcs
import cdms2
import os

f=cdms2.open(os.path.join(vcs.sample_data,"clt.nc"))
s=f("clt",slice(0,1))
x=vcs.init()
x.plot(s,bg=1)
x.png("landscape")
x.clear()
x.portrait()
x.plot(s,bg=1)
x.png("portrait")

comes out landscape

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"