Commit 06de2264 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit
Browse files

BUG #13475. Adding API to select/unselect cells.

Adding APU to select/unselect cells in Python. Users can now use SelectCells()
and ClearSelection() to make new selections from Python.

Change-Id: Idfda0824242de3f9617267215ea29cde7cbb4aaa
parent 4a1d587e
......@@ -22,3 +22,10 @@ os._exit(1)
"
RESULT_VARIABLE HAS_NUMPY
)
# Doing the HAS_NUMPY string comparison everytime is annoying. Hence setting up
# this FOUND_NUMPY variable.
set (FOUND_NUMPY FALSE)
if ("1" STREQUAL ${HAS_NUMPY})
set (FOUND_NUMPY TRUE)
endif()
......@@ -40,6 +40,7 @@ ENDIF ()
###############################################################################
# For python scripts for testing.
#
include (TestNumPy)
# Add python script names here.
SET (PY_TESTS
......@@ -56,7 +57,9 @@ SET (PY_TESTS
# SMUndoRedo
# SMCompoundProxyUndoRedo
)
if (FOUND_NUMPY)
list(APPEND PY_TESTS PythonSelection)
endif()
IF (PARAVIEW_DATA_ROOT)
FOREACH (tfile ${PY_TESTS})
......
from paraview.simple import *
import SMPythonTesting
SMPythonTesting.ProcessCommandLineArguments()
filename = SMPythonTesting.DataDir + '/Data/can.ex2'
can_ex2 = OpenDataFile(filename)
Show()
SelectCells("id > 1000")
RenderView1 = Render()
RenderView1.CameraViewUp = [0.0, 0.0, 1.0]
RenderView1.CameraPosition = [0.21706008911132812, 55.740573746856327, -5.1109471321105957]
RenderView1.CameraFocalPoint = [0.21706008911132812, 4.0, -5.1109471321105957]
RenderView1 = Render()
if not SMPythonTesting.DoRegressionTesting(RenderView1.SMProxy):
# This will lead to VTK object leaks.
import sys
sys.exit(1)
......@@ -960,6 +960,34 @@ def GetLayout(view=None):
return layout
return None
def SelectCells(query=None, proxy=None):
"""Select cells satisfying the query. If query is None, then all cells are
selected. If proxy is None, then the active source is used."""
if not proxy:
proxy = GetActiveSource()
if not proxy:
raise RuntimeError, "No active source was found."
if not query:
# This ends up being true for all cells.
query = "id >= 0"
# Note, selSource is not registered with the proxy manager.
selSource = servermanager.sources.SelectionQuerySource()
selSource.FieldType = "CELL"
selSource.QueryString = str(query)
proxy.SMProxy.SetSelectionInput(proxy.Port, selSource.SMProxy, 0)
return selSource
def ClearSelection(proxy=None):
"""Clears the selection on the active source."""
if not proxy:
proxy = GetActiveSource()
if not proxy:
raise RuntimeError, "No active source was found."
proxy.SMProxy.SetSelectionInput(proxy.Port, None, 0)
class ActiveObjects(object):
"""This class manages the active objects (source and view). The active
objects are shared between Python and the user interface. This class
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment