o
    gc
                     @   s   d dl Z d dlmZ d dlmZ d dlmZmZmZm	Z	 d dl
mZ d dlZeeZdd ZG dd	 d	eZd
Zdd ZG dd deZeegZdd Zdd ZdS )    N)Operator)IntProperty)cossinradianssqrt)Vectorc                 C   sT   t |t |}}| t| t| }| t| t| }| t| }t|||fS N)r   r   r   r   )Rlonlatxyz r   }C:\Users\olivi\AppData\Roaming\Blender Foundation\Blender\3.4\scripts\addons\BlenderGIS-master\operators\mesh_earth_sphere.py
lonlat2xyz   s
   r   c                   @   s>   e Zd ZU dZdZdZddhZedddd	d
ed< dd Z	dS )OBJECT_OT_earth_spherezearth.spherezlonlat to spherez>Transform longitude/latitude data to a sphere like earth globeREGISTERUNDORadiusd   zSphere radius   )namedefaultdescriptionminradiusc                 C   s   t jj}t jj}|s| dhd dhS |D ]W}|jdkr'td|j	 q|j
\}}}|dkr;td|j	 q|dkrItd	|j	 q|j}|j}	|jD ]}
|	|
j }|j|j}}|	 t| j|| |
_qRqd
hS )NINFOzNo selected object	CANCELLEDMESHzObject {} is not a meshih  u#   Longitude of object {} exceed 360°   u"   Latitude of object {} exceed 180°FINISHED)bpycontextsceneselected_objectsreporttypelogwarningformatr   
dimensionsdatamatrix_worldverticescor   r   invertedr   r   )selfr$   scnobjsobjwhZthickmeshmvertexr0   r   r   r   r   r   execute   s0   


zOBJECT_OT_earth_sphere.executeN)
__name__
__module____qualname__	bl_idnamebl_labelbl_description
bl_optionsr   __annotations__r;   r   r   r   r   r      s   
 r   iRa c                 C   s   t td | d  t S )zdelta value for adjusting z across earth curvature
	http://webhelp.infovista.com/Planet/62/Subsystems/Raster/Content/help/analysis/viewshedanalysis.html   )r   EARTH_RADIUS)dr   r   r   	getZDelta;   s   rG   c                   @   s(   e Zd ZdZdZdZddhZdd ZdS )	OBJECT_OT_earth_curvaturezearth.curvaturezEarth curvature correctionz7Apply earth curvature correction for viewsheed analysisr   r   c                 C   s   t jj}t jjjj}|s| dhd dhS |jdkr%| dhd dhS |j}|j	j
}|jD ]}|j|jj j}|jjt| |j_q/dhS )Nr   zNo active objectr   r    zSelection isn't a meshr"   )r#   r$   r%   
view_layerobjectsactiver'   r(   r-   cursorlocationr/   xyr0   lengthr   rG   )r2   r$   r3   r5   r8   Zviewptr:   rF   r   r   r   r;   G   s   

z!OBJECT_OT_earth_curvature.executeN)r<   r=   r>   r?   r@   rA   rB   r;   r   r   r   r   rH   A   s    rH   c                  C   sj   t D ]0} ztj|  W q ty2 } ztd|  tj|  tj|  W Y d }~qd }~ww d S )Nz6{} is already registered, now unregister and retry... )	classesr#   utilsregister_class
ValueErrorr)   r*   r+   unregister_class)clser   r   r   registerb   s   rW   c                  C   s   t D ]} tj|  qd S r	   )rP   r#   rQ   rT   )rU   r   r   r   
unregisterk   s   rX   )r#   	bpy.typesr   	bpy.propsr   mathr   r   r   r   	mathutilsr   logging	getLoggerr<   r)   r   r   rE   rG   rH   rP   rW   rX   r   r   r   r   <module>   s"    
&	