<commit_before>"""
Geosoft vox display handling

:Classes:

    ==================== ==========================================================================
    :class:`Vox_display` 3D visualization of a vox, which can be placed `geosoft.gxpy.view.View_3d`
    ==================== ==========================================================================
    
.. seealso:: `geosoft.gxpy.vox.Vox`, `geosoft.gxpy.view.View_3d`, `geosoft.gxapi.GXVOXD`

.. note::

    Regression tests provide usage examples:     
    `vox_display tests <https://github.com/GeosoftInc/gxpy/blob/master/geosoft/gxpy/tests/test_vox_display.py>`_

"""
import os

import geosoft
import geosoft.gxapi as gxapi
from . import gx
from . import view as gxview
from . import group as gxgroup
from . import vox as gxvox
from . import map as gxmap

__version__ = geosoft.__version__


def _t(s):
    return geosoft.gxpy.system.translate(s)


class VoxDisplayException(Exception):
    """
    Exceptions from :mod:`geosoft.gxpy.vox_display`.

    .. versionadded:: 9.2
    """
    pass

ZONE_DEFAULT = 0 #:
ZONE_LINEAR = 1 #:
ZONE_NORMAL = 2 #:
ZONE_EQUALAREA = 3 #:
ZONE_SHADE = 4 #:
ZONE_LOGLINEAR = 5 #:
ZONE_LAST = 6 #:

class Vox_display:
    """
    Creation and handling of vox displays. Vox displays can be placed into a 3D view for display.

    :Constructors:

        ============= =================================
        :meth:`new`:  create a new vox_display
        ============= =================================
        
    .. versionadded:: 9.3.1
    """

    def __repr__(self):
        return "{}({})".format(self.__class__, self.__dict__)

    def __str__(self):
        return self.name

    def __enter__(self):
        return self

    def __exit__(self, type, value, traceback):
        self.__del__()

    def __del__(self):
        if hasattr(self, '_close'):
            self._close()

    def _close(self):
        if hasattr(self, '_open'):
            if self._open:
                gx.pop_resource(self._open)
                self._open = None
                self._gxvoxd = None
                self._vox = None

    def __init__(self, vox, name=None):
        self._gxvoxd = None
        self._vox = vox
        if name is None:
            if vox is not None:
                name = vox.name
        self._name = name
        self._open = gx.track_resource(self.__class__.__name__, name)
        self._vector = False
        self._vector_cone_specs = (1., 4., 0.25, 5000)

    @classmethod
    def new(cls, vox, vector=False, vector_cone_specs=(1., 4., 0.25, 5000)):
        """
        Create a new vox_display from a `geosoft.gxpy.vox.Vox` instance.
        
        :param vox:                 `geosoft.gxpy.vox.Vox` instance
        :param vector:              True to create a vector swarm from a vector voxel
        :param vector_cone_specs:   Vector plotting specs
                                    (scale_cell_ratio, height_base_ratio, base_cell_ratio, max_cones).
                                    Default is (1., 4., 0.25, 5000). See `vector_cone_specs` property.

        .. versionadded:: 9.3.1
        """

        if vector and not vox.is_vectorvox:
            raise VoxDisplayException(_t('vox must be a vectorvoxel to create a vector swarm'))
        voxd = cls(vox)
        color_table = ''
        zone_method = ZONE_DEFAULT
        contour = gxapi.rDUMMY
        voxd._gxvoxd = gxapi.GXVOXD.create(vox.gxvox, color_table, zone_method, contour)
        voxd._vector = vector
        voxd._vector_cone_specs = vector_cone_specs
        return voxd<commit_msg>trivial refactor<commit_after>"""
Geosoft vox display handling

:Classes:

    ==================== ==========================================================================
    :class:`Vox_display` 3D visualization of a vox, which can be placed `geosoft.gxpy.view.View_3d`
    ==================== ==========================================================================
    
.. seealso:: `geosoft.gxpy.vox.Vox`, `geosoft.gxpy.view.View_3d`, `geosoft.gxapi.GXVOXD`

.. note::

    Regression tests provide usage examples:     
    `vox_display tests <https://github.com/GeosoftInc/gxpy/blob/master/geosoft/gxpy/tests/test_vox_display.py>`_

"""
import os

import geosoft
import geosoft.gxapi as gxapi
from . import gx
from . import view as gxview
from . import group as gxgroup
from . import vox as gxvox
from . import map as gxmap

__version__ = geosoft.__version__


def _t(s):
    return geosoft.gxpy.system.translate(s)


class VoxDisplayException(Exception):
    """
    Exceptions from :mod:`geosoft.gxpy.vox_display`.

    .. versionadded:: 9.2
    """
    pass

ZONE_DEFAULT = 0 #:
ZONE_LINEAR = 1 #:
ZONE_NORMAL = 2 #:
ZONE_EQUALAREA = 3 #:
ZONE_SHADE = 4 #:
ZONE_LOGLINEAR = 5 #:
ZONE_LAST = 6 #:

class Vox_display:
    """
    Creation and handling of vox displays. Vox displays can be placed into a 3D view for display.

    :Constructors:

        ============= =================================
        :meth:`new`:  create a new vox_display
        ============= =================================
        
    .. versionadded:: 9.3.1
    """

    def __repr__(self):
        return "{}({})".format(self.__class__, self.__dict__)

    def __str__(self):
        return self.name

    def __enter__(self):
        return self

    def __exit__(self, type, value, traceback):
        self.__del__()

    def __del__(self):
        if hasattr(self, '_close'):
            self._close()

    def _close(self):
        if hasattr(self, '_open'):
            if self._open:
                gx.pop_resource(self._open)
                self._open = None
                self._gxvoxd = None
                self._vox = None

    def __init__(self, vox, name=None):
        self._gxvoxd = None
        self._vox = vox
        if name is None:
            if vox is not None:
                name = vox.name
        self._name = name
        self._vector = False
        self._vector_cone_specs = (1., 4., 0.25, 5000)
        self._open = gx.track_resource(self.__class__.__name__, name)

    @classmethod
    def new(cls, vox, vector=False, vector_cone_specs=None):
        """
        Create a new vox_display from a `geosoft.gxpy.vox.Vox` instance.
        
        :param vox:                 `geosoft.gxpy.vox.Vox` instance
        :param vector:              True to create a vector swarm from a vector voxel
        :param vector_cone_specs:   Vector plotting specs
                                    (scale_cell_ratio, height_base_ratio, base_cell_ratio, max_cones).
                                    Default is (1., 4., 0.25, 5000). See `vector_cone_specs` property.

        .. versionadded:: 9.3.1
        """

        if vector and not vox.is_vectorvox:
            raise VoxDisplayException(_t('vox must be a vectorvoxel to create a vector swarm'))
        voxd = cls(vox)
        color_table = ''
        zone_method = ZONE_DEFAULT
        contour = gxapi.rDUMMY
        voxd._gxvoxd = gxapi.GXVOXD.create(vox.gxvox, color_table, zone_method, contour)
        voxd._vector = vector
        if vector_cone_specs is not None:
            voxd._vector_cone_specs = vector_cone_specs
        return voxd
{'fraction_non_alphanumeric': 0.1708939708939709, 'fraction_numerical': 0.011503811503811504, 'mean_word_length': 2.3391948172142527, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7457694', 'n_tokens_mistral': 2441, 'n_tokens_neox': 2229, 'n_words': 548}