
    pjJ                     F    d dl Z d dlmZ d dlmZ d dlmZ  G d de      Zy)    N)simple)vtkSMTransferFunctionManager)vtkWebProtocolc                   >    e Zd Zd Zd Zd Zd Zd Zd Zd
dZ	d	 Z
y)ParaViewWebProtocolc                 <    d | _         d| _        d| _        i | _        y )NF )core_server
multi_rootbase_directorybase_directory_map)selfs    ^/DATA/.local/lib/python3.12/site-packages/trame_vtk/modules/paraview/protocols/web_protocol.py__init__zParaViewWebProtocol.__init__
   s!     "$    c                     	 t        |      }|dk  ryt        j                  j	                  t        j                  j
                  j                  j                  |            S # t        $ r Y yw xY w)zs
        Maps global-id for a proxy to the proxy instance. May return None if the
        id is not valid.
        Nr   )int
ValueErrorr   servermanager_getPyProxyActiveConnectionSessionGetRemoteObject)r   ids     r   map_id_to_proxyz#ParaViewWebProtocol.map_id_to_proxy   si    
	RB 7##//  1199II"M
 	
	  		s   A# #	A/.A/c                 t    | j                  |      }|st        j                         }|st        d|       |S )z
        Returns the view for a given view ID, if vid is None then return the
        current active view.
        :param vid: The view ID
        :type vid: str
        zno view provided: )r   r   GetActiveView	Exception)r   vidviews      r   get_viewzParaViewWebProtocol.get_view   s@     ##C('')D0677r   c                 4    | j                   rt        |       y y N)
debug_modeprint)r   msgs     r   debugzParaViewWebProtocol.debug0   s    ??#J r   c                    d | _         d| _        i | _        d| _        |j	                  d      dk  r|j	                  d      dk\  rH|j                  d      }t        j                  j                  |d         r|d   | _        |d   | _         n|| _        t        j                  j                  | j                        | _        y |j                  d      }|D ]h  }|j                  d      }t        j                  j                  |d         s7t        j                  j                  |d         | j                  |d   <   j t        | j                        }t        |      dk(  rFt        j                  j                  | j                  |d            | _        |d   | _         i | _        y t        |      dkD  rd| _        y y )Nr	   F|r   =   T)override_data_dir_keyr   r   r   findsplitospathexistsnormpathlistlen)r   	base_path	base_pair	base_dirsbase_dirbd_keyss         r   set_base_directoryz&ParaViewWebProtocol.set_base_directory4   s{   %)" "$>>#"~~c"a'%OOC0	77>>)A,/*3A,D'1:1D.&/#"$''"2"243F3F"GD!,I%$NN3/	77>>)A,/<>GG<L<L!!=D++IaL9 & 4223G7|q &(gg&6&6++GAJ7'# .5QZ**,'W!"& "r   c                 "   d }| j                   rW|j                  dd      j                  d      }| j                  |d      }t	        j
                  j                  |g|dd   }n*t        j
                  j                  | j                  |      }t        j
                  j                  |      }| j                   r8| j                  j                         D ]  \  }}|j                  |      s|c S  y |j                  | j                        r|S y )N\/r   r+   )r   replacer.   r   r/   r0   joinr   r2   items
startswith)r   relative_pathabsolute_pathrel_path_partsreal_base_pathcleaned_pathkeyvalues           r   get_absolute_pathz%ParaViewWebProtocol.get_absolute_pathW   s    ??*224=CCCHN!44^A5FGNGGLLM.:LMMGGLL)<)<mLMww''6 ??"55;;=
U**51'' >  $$T%8%89r   Nc                 z    |xs | j                  d      }t               }|j                  |j                  |       y)z
        Manage scalarbar state

            view:
                A view proxy or the current active view will be used.

            mode:
                HIDE_UNUSED_SCALAR_BARS = 0x01,
                SHOW_USED_SCALAR_BARS = 0x02
        N)r!   r   UpdateScalarBarsSMProxy)r   r    modevlut_mgrs        r   update_scalar_barsz&ParaViewWebProtocol.update_scalar_barsm   s3     %DMM"%.0  D1r   c                 V    | j                   r| j                   j                  ||       y y r#   )r
   publish)r   topicevents      r   rS   zParaViewWebProtocol.publish|   s&    $$UE2 r   )Nr+   )__name__
__module____qualname__r   r   r!   r'   r:   rI   rQ   rS    r   r   r   r   	   s+    %
"!'F,23r   r   )r/   paraviewr   paraview.servermanagerr   ,trame_vtk.modules.vtk.protocols.web_protocolr   r   rY   r   r   <module>r]      s    	  ? Gu3. u3r   