#=============================================================================
#
#  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)
        pvsimple.LoadPlugin("$<TARGET_FILE:smtkMeshSessionPlugin>", 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__':
    smtk.testing.process_arguments()
    unittest.main()
