#=============================================================================
#
#  Copyright (c) Kitware, Inc.
#  All rights reserved.
#  See LICENSE.txt for details.
#
#  This software is distributed WITHOUT ANY WARRANTY; without even
#  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
#  PURPOSE.  See the above copyright notice for more information.
#
#=============================================================================

""" openSMTKFileInParaView.py:

Test the ParaView plugins generated by SMTK for opening .smtk files.

"""

import os
import sys
import unittest

import vtk

from paraview import simple as pvsimple

import smtk
import smtk.common
import smtk.testing


class OpenSMTKFileInParaView(smtk.testing.TestCase):

    def setUp(self):
        pvsimple.LoadPlugin("$<TARGET_FILE:smtkPVServerExtPlugin>", True)
        pvsimple.LoadPlugin("$<TARGET_FILE:smtkPQComponentsPlugin>", True)
        pvsimple.LoadPlugin("$<TARGET_FILE:smtkPolygonSessionPlugin>", True)

    def testOpenSMTKFile(self):
        reader = pvsimple.OpenDataFile(os.path.join(smtk.testing.DATA_DIR,
                                       'model', '2d', 'smtk', 'epic-trex-drummer.smtk'))
        # TODO: construct an instance of vtkSMTKWrapper and pass it to the
        #       reader, which derives from vtkSMTKResource

        pvsimple.Show()
        displayProperties = pvsimple.GetDisplayProperties()
        displayProperties.MapScalars = 0
        displayProperties.PointSize = 6

        if self.haveVTK() and self.haveVTKExtension():
            import vtk
            self.startRenderTest()
            cmpFile = os.path.join(smtk.testing.DATA_DIR,
                                   'baseline', 'smtk', 'paraview', 'epic-trex-drummer.png')
            smtk.testing.compare_image(pvsimple.Render().GetRenderer().GetVTKWindow(), cmpFile)
            if self.interactive():
                self.interact()


if __name__ == '__main__':
    print(
        'This test has been disabled until smtk/extension/paraview/server is\n'
        'python-wrapped. To do so, smtk/extension/paraview/server will need to\n'
        'become a vtk module, and we must use vtk\'s python wrapping protocol to\n'
        'expose vtkSMTKResource and vtkSMTKWrapper. This could be tricky because\n'
        'these classes comprise the server plugin, and there is currently no\n'
        'example where a vtk module is used as a paraview plugin.')
    sys.exit(125)

    smtk.testing.process_arguments()
    unittest.main()
