Skip to content

Commit

Permalink
Merge pull request #1262 from UV-CDAT/update_master
Browse files Browse the repository at this point in the history
Update master
  • Loading branch information
aashish24 committed May 2, 2015
2 parents 54259b8 + cdf05a4 commit df355f9
Show file tree
Hide file tree
Showing 14 changed files with 167 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Packages/cdms2/Src/Cdunifmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ PyCdunifFile_Open(char *filename, char *mode)
if (mode[0] == 'w') {
Py_BEGIN_ALLOW_THREADS;
acquire_Cdunif_lock();
ncmode = NC_CLOBBER;
ncmode = NC_CLOBBER|NC_64BIT_OFFSET;
#ifndef NONC4
if ((cdms_shuffle!=0) || (cdms_deflate!=0)) {
ncmode = NC_CLOBBER|NC_NETCDF4;
Expand Down
6 changes: 5 additions & 1 deletion Packages/vcs/Lib/VTKPlots.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,10 @@ def plot2D(self,data1,data2,tmpl,gm,vtk_backend_grid=None,vtk_backend_geo=None):
mapper.SetScalarModeToUseCellData()
mappers.append([mapper,])
else:
if isinstance(gm,vcs.meshfill.Gfm):
doCellPointForScalar = True
else:
doCellPointForScalar = False
for j,color in enumerate(COLS[i]):
mapper = vtk.vtkPolyDataMapper()
lut = vtk.vtkLookupTable()
Expand All @@ -1047,7 +1051,7 @@ def plot2D(self,data1,data2,tmpl,gm,vtk_backend_grid=None,vtk_backend_geo=None):
lut.SetTableValue(0,r/100.,g/100.,b/100.)
mapper.SetLookupTable(lut)
mapper.SetScalarRange(l[j],l[j+1])
luts.append([lut,[l[j],l[j+1],False]])
luts.append([lut,[l[j],l[j+1],doCellPointForScalar]])
## Store the mapper only if it's worth it?
## Need to do it with the whole slab min/max for animation purposes
if not(l[j+1]<wmn or l[j]>wmx):
Expand Down
4 changes: 0 additions & 4 deletions Packages/vcs/Lib/editors/marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,6 @@ def detach(self):
self.tooltip.detach()

def delete(self):
del self.marker.x[self.index]
del self.marker.y[self.index]
del self.marker.type[self.index]
del self.marker.color[self.index]
self.actor.SetVisibility(0)
self.configurator.deactivate(self)

Expand Down
2 changes: 1 addition & 1 deletion Packages/vcs/Lib/vtk_ui/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def add_widget(self, widget):
def remove_widget(self, widget):
if widget in self.widgets:
self.widgets.remove(widget)
del widget.manager
widget.manager = None
if len(self.widgets) == 0:
del ui_managers[self.interactor]
self.detach()
Expand Down
3 changes: 2 additions & 1 deletion Packages/vcs/Lib/vtk_ui/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ def place(self):
pass

def render(self):
self.manager.queue_render()
if self.manager:
self.manager.queue_render()

def in_bounds(self, x, y):
if x < 1 and y < 1:
Expand Down
6 changes: 4 additions & 2 deletions Packages/vcs/Lib/vtk_ui/textbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,10 @@ def stop_editing(self):
self.cursor.hide()
if self.blank:
self.text = ""
self.on_editing_end(self)
self.text = " "
if self.on_editing_end:
self.on_editing_end(self)
if self.blank:
self.text = " "

def place(self):
super(Textbox, self).place()
Expand Down
6 changes: 6 additions & 0 deletions Packages/vcs/Lib/vtk_ui/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ def __init__(self, interactor, widget):
self.widget = widget
self.widget.SetInteractor(interactor)
self.repr = widget.GetRepresentation()
# By default, VTK will map the 'i' key to activating a widget.
# This was doing weird things and making buttons disappear.
self.widget.SetKeyPressActivation(False)
self.subscriptions = {}
self.manager = get_manager(interactor)
self.manager.add_widget(self)
Expand Down Expand Up @@ -98,6 +101,9 @@ def GetRenderer(self):
def GetCurrentRenderer(self):
return self._ren

def SetKeyPressActivation(self, value):
pass

def SetCurrentRenderer(self, renderer):
"""
The main cause of all this hubbub; need to use the actor_renderer.
Expand Down
6 changes: 6 additions & 0 deletions testing/vcs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,11 @@ cdat_add_test(vcs_test_taylor_2_quads
${BASELINE_DIR}/test_vcs_issue_960_labels_1.png
${BASELINE_DIR}/test_vcs_issue_960_labels_2.png
)
cdat_add_test(vcs_test_animate_meshfill
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_animate_meshfill.py
${BASELINE_DIR}
)
cdat_add_test(vcs_test_animate_isofill
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_animate_isofill.py
Expand Down Expand Up @@ -636,3 +641,4 @@ cdat_add_test(vcs_test_colorpicker_appearance
${BASELINE_DIR}/test_vcs_colorpicker_appearance.png
)
add_subdirectory(vtk_ui)
add_subdirectory(editors)
7 changes: 7 additions & 0 deletions testing/vcs/editors/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(BASELINE_DIR "${UVCDAT_GIT_TESTDATA_DIR}/baselines/vcs/editors")
set(TEST_DIR "${cdat_SOURCE_DIR}/testing/vcs/editors")

cdat_add_test(vcs_test_editor_marker_delete
"${PYTHON_EXECUTABLE}"
${TEST_DIR}/test_vcs_editor_marker_delete.py
)
57 changes: 57 additions & 0 deletions testing/vcs/editors/test_vcs_editor_marker_delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import vcs
import sys

x = vcs.init()
x.open()

m = x.createmarker()
m.x = .1,
m.y = .1,

# enable the configurator
x.configure()

# plot in the background
dp = x.plot(m)

# Grab the initialized configurator
c = x.configurator

# Make sure the displays are current
c.update()

w, h = x.bgX, x.bgY

# Retrieve the actor at the specified point
c.interactor.SetEventInformation(int(.1 * w), int(.1 * h))
c.click(None, None)
c.release(None, None)

# Make sure we've got the correct editor
editor = c.target
if editor is None:
print "Did not activate an editor"
sys.exit(1)
print "Editor activated"
if type(editor) != vcs.editors.marker.MarkerEditor:
print "Did not activate a marker editor"
sys.exit(1)
print "Editor is a marker editor"
if editor.marker != m:
print "Did not activate the correct marker editor, expected", m.name, "received", editor.marker.name
sys.exit(1)
print "Marker editor is editing the correct marker"

# Simulate a right click on the marker
editor.right_release()

# Make sure the editor has been deactivated
if c.target == editor:
print "Did not deactivate editor"
sys.exit(1)
print "Marker editor deactivated"
# Make sure the marker was deleted
if len(m.x) != len(m.y) != len(m.type) != len(m.color) != 0:
print "Did not delete all attributes on marker"
sys.exit(1)
print "Deleted all attributes on marker"
45 changes: 45 additions & 0 deletions testing/vcs/test_animate_meshfill.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import vcs
import cdms2
import os
import sys
import MV2

pth = os.path.join(os.path.dirname(__file__),"..")
sys.path.append(pth)
import checkimage

f=cdms2.open(os.path.join(vcs.prefix,"sample_data","sampleCurveGrid4.nc"))
s=f("sample")
print s.shape

s2=MV2.resize(s,(4,32,48))
t=cdms2.createAxis(range(4))
t.units="months since 2015"
t.id="time"
t.designateTime()
s2.setAxis(0,t)
s2.setAxis(1,s.getAxis(0))
s2.setAxis(2,s.getAxis(1))
s2.setGrid(s.getGrid())
for i in range(4):
s2[i]=s2[i]*(1+float(i)/10.)
x=vcs.init()
x.drawlogooff()
x.setbgoutputdimensions(1200,1091,units="pixels")

gm=x.createmeshfill()
x.plot(s2,gm,bg=1)
x.animate.create()
prefix= os.path.split(__file__)[1][:-3]
x.animate.save("%s.mp4"%prefix)
pngs = x.animate.close(preserve_pngs = True) # so we can look at them again
src_pth = sys.argv[1]
pth = os.path.join(src_pth,prefix)
ret = 0
for p in pngs:
print "Checking:",p
ret += checkimage.check_result_image(p,os.path.join(pth,os.path.split(p)[1]),checkimage.defaultThreshold)
if ret == 0:
os.removedirs(os.path.split(p)[0])
os.remove("%s.mp4" % prefix)
sys.exit(ret)
5 changes: 5 additions & 0 deletions testing/vcs/vtk_ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,8 @@ add_test(test_vtk_ui_white_or_black
"${PYTHON_EXECUTABLE}"
${TEST_DIR}/test_vtk_ui_white_or_black.py
)

add_test(test_vtk_ui_textbox_blank_text
"${PYTHON_EXECUTABLE}"
${TEST_DIR}/test_vtk_ui_textbox_blank_text.py
)
22 changes: 22 additions & 0 deletions testing/vcs/vtk_ui/test_vtk_ui_textbox_blank_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Test that text stays the same when you start/stop editing
"""
import vcs.vtk_ui
import vtk

from vtk_ui_test import vtk_ui_test


class test_vtk_ui_textbox_blank_text(vtk_ui_test):
def do_test(self):
self.win.SetSize(130, 130)

textbox = vcs.vtk_ui.Textbox(self.inter, "Test String")
textbox.show()
textbox.start_editing()
textbox.stop_editing()
if textbox.text == "Test String":
self.passed = 0

if __name__ == "__main__":
test_vtk_ui_textbox_blank_text().test()
6 changes: 6 additions & 0 deletions testing/vcs/vtk_ui/vtk_ui_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def click_event(self, x, y):
self.inter.LeftButtonPressEvent()
self.inter.LeftButtonReleaseEvent()

def key_event(self, keycode, control=False, shift=False):
self.win.Render()
self.inter.SetKeyEventInformation(keycode, control, shift)
self.inter.KeyPressEvent()
self.inter.KeyReleaseEvent()

def do_test(self):
raise NotImplementedError("Implement do_test to execute a test.")

Expand Down

0 comments on commit df355f9

Please sign in to comment.