# Path: pymicro/view/vtk_utils.py
# def set_opacity(assembly, opacity):
#     collection = vtk.vtkPropCollection()
#     assembly.GetActors(collection)
#     for i in range(collection.GetNumberOfItems()):
#         collection.GetItemAsObject(i).GetProperty().SetOpacity(opacity)


import vtk
import os
import numpy as np
from pymicro.view.vtk_utils import set_opacity
        from pymicro.crystal.microstructure import Orientation
        vtkAnimation.post_execute(self, iren, event)


class vtkSetVisibility(vtkAnimation):
    def __init__(self, t, actor, visible=1, max_opacity=1, gradually=False):
        vtkAnimation.__init__(self, t)
        self.actor = actor
        self.visible = visible
        self.gradually = gradually
        self.max_opacity = max_opacity

    def execute(self, iren, event):
        do = vtkAnimation.pre_execute(self)
        if not do: return
        if not self.gradually:
            self.actor.SetVisibility(self.visible)
            set_opacity(self.actor, 1)
        else:
            t1 = self.time_anim_starts
            t2 = self.time_anim_ends
            if self.scene.timer_count >= t1 and self.scene.timer_count <= t2:  # useless to test this (do == 1 here)
                if self.actor.GetVisibility() == 0:
                    self.actor.SetVisibility(1)  # make the actor visible
                if self.visible:
                    opacity = self.max_opacity * (1 - (t2 - self.scene.timer_count) / float(t2 - t1))
                else:
                    opacity = self.max_opacity * (t2 - self.scene.timer_count) / float(t2 - t1)
                if self.verbose:
                    print('opacity=', opacity)
                # change the opacity for each actor in the assembly

# Path: pymicro/view/vtk_utils.py
# def set_opacity(assembly, opacity):
#     collection = vtk.vtkPropCollection()
#     assembly.GetActors(collection)
#     for i in range(collection.GetNumberOfItems()):
#         collection.GetItemAsObject(i).GetProperty().SetOpacity(opacity)


# Path: pymicro/view/vtk_anim.py
import vtk
import os
import numpy as np
from pymicro.view.vtk_utils import set_opacity
        from pymicro.crystal.microstructure import Orientation

        vtkAnimation.post_execute(self, iren, event)


class vtkSetVisibility(vtkAnimation):
    def __init__(self, t, actor, visible=1, max_opacity=1, gradually=False):
        vtkAnimation.__init__(self, t)
        self.actor = actor
        self.visible = visible
        self.gradually = gradually
        self.max_opacity = max_opacity

    def execute(self, iren, event):
        do = vtkAnimation.pre_execute(self)
        if not do: return
        if not self.gradually:
            self.actor.SetVisibility(self.visible)
            set_opacity(self.actor, 1)
        else:
            t1 = self.time_anim_starts
            t2 = self.time_anim_ends
            if self.scene.timer_count >= t1 and self.scene.timer_count <= t2:  # useless to test this (do == 1 here)
                if self.actor.GetVisibility() == 0:
                    self.actor.SetVisibility(1)  # make the actor visible
                if self.visible:
                    opacity = self.max_opacity * (1 - (t2 - self.scene.timer_count) / float(t2 - t1))
                else:
                    opacity = self.max_opacity * (t2 - self.scene.timer_count) / float(t2 - t1)
                if self.verbose:
                    print('opacity=', opacity)
                # change the opacity for each actor in the assembly

                set_opacity(self.actor, opacity)