Blender  V3.3
Macros | Functions | Variables
bpy_utils_units.c File Reference
#include <Python.h>
#include <structmember.h>
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "bpy_utils_units.h"
#include "../generic/py_capi_utils.h"
#include "BKE_unit.h"

Go to the source code of this file.

Macros

#define PY_SSIZE_T_CLEAN
 

Functions

 BLI_STATIC_ASSERT (ARRAY_SIZE(bpyunits_ucategories_items)==B_UNIT_TYPE_TOT+1, "`bpyunits_ucategories_items` should match `B_UNIT_` enum items in `BKE_units.h`")
 
static PyObject * py_structseq_from_strings (PyTypeObject *py_type, PyStructSequence_Desc *py_sseq_desc, const char **str_items)
 
static bool bpyunits_validate (const char *usys_str, const char *ucat_str, int *r_usys, int *r_ucat)
 
 PyDoc_STRVAR (bpyunits_to_value_doc, ".. method:: to_value(unit_system, unit_category, str_input, str_ref_unit=None)\n" "\n" " Convert a given input string into a float value.\n" "\n" " :arg unit_system: The unit system, from :attr:`bpy.utils.units.systems`.\n" " :type unit_system: string\n" " :arg unit_category: The category of data we are converting (length, area, rotation, " "etc.),\n" " from :attr:`bpy.utils.units.categories`.\n" " :type unit_category: string\n" " :arg str_input: The string to convert to a float value.\n" " :type str_input: string\n" " :arg str_ref_unit: A reference string from which to extract a default unit, if none is " "found in ``str_input``.\n" " :type str_ref_unit: string or None\n" " :return: The converted/interpreted value.\n" " :rtype: float\n" " :raises ValueError: if conversion fails to generate a valid python float value.\n")
 
static PyObject * bpyunits_to_value (PyObject *UNUSED(self), PyObject *args, PyObject *kw)
 
 PyDoc_STRVAR (bpyunits_to_string_doc, ".. method:: to_string(unit_system, unit_category, value, precision=3, " "split_unit=False, compatible_unit=False)\n" "\n" " Convert a given input float value into a string with units.\n" "\n" " :arg unit_system: The unit system, from :attr:`bpy.utils.units.systems`.\n" " :type unit_system: string\n" " :arg unit_category: The category of data we are converting (length, area, " "rotation, etc.),\n" " from :attr:`bpy.utils.units.categories`.\n" " :type unit_category: string\n" " :arg value: The value to convert to a string.\n" " :type value: float\n" " :arg precision: Number of digits after the comma.\n" " :type precision: int\n" " :arg split_unit: Whether to use several units if needed (1m1cm), or always only " "one (1.01m).\n" " :type split_unit: bool\n" " :arg compatible_unit: Whether to use keyboard-friendly units (1m2) or nicer " "utf-8 ones (1m²).\n" " :type compatible_unit: bool\n" " :return: The converted string.\n" " :rtype: str\n" " :raises ValueError: if conversion fails to generate a valid python string.\n")
 
static PyObject * bpyunits_to_string (PyObject *UNUSED(self), PyObject *args, PyObject *kw)
 
 PyDoc_STRVAR (bpyunits_doc, "This module contains some data/methods regarding units handling.")
 
PyObject * BPY_utils_units (void)
 

Variables

static PyTypeObject BPyUnitsSystemsType
 
static PyTypeObject BPyUnitsCategoriesType
 
static const char * bpyunits_usystem_items []
 
static const char * bpyunits_ucategories_items []
 
static PyStructSequence_Desc bpyunits_categories_desc
 
static PyMethodDef bpyunits_methods []
 
static struct PyModuleDef bpyunits_module
 

Detailed Description

This file defines a singleton py object accessed via 'bpy.utils.units', which exposes various data and functions useful in units handling.

Definition in file bpy_utils_units.c.

Macro Definition Documentation

◆ PY_SSIZE_T_CLEAN

#define PY_SSIZE_T_CLEAN

Definition at line 11 of file bpy_utils_units.c.

Function Documentation

◆ BLI_STATIC_ASSERT()

BLI_STATIC_ASSERT ( ARRAY_SIZE(bpyunits_ucategories_items = B_UNIT_TYPE_TOT + 1,
"`bpyunits_ucategories_items` should match `B_UNIT_` enum items in `BKE_units.h`"   
)

Definition at line 55 of file bpy_utils_units.c.

References ARRAY_SIZE.

◆ BPY_utils_units()

PyObject* BPY_utils_units ( void  )

◆ bpyunits_to_string()

static PyObject* bpyunits_to_string ( PyObject *  UNUSEDself,
PyObject *  args,
PyObject *  kw 
)
static

◆ bpyunits_to_value()

static PyObject* bpyunits_to_value ( PyObject *  UNUSEDself,
PyObject *  args,
PyObject *  kw 
)
static

◆ bpyunits_validate()

static bool bpyunits_validate ( const char *  usys_str,
const char *  ucat_str,
int *  r_usys,
int *  r_ucat 
)
static

◆ py_structseq_from_strings()

static PyObject* py_structseq_from_strings ( PyTypeObject *  py_type,
PyStructSequence_Desc *  py_sseq_desc,
const char **  str_items 
)
static

Simple utility function to initialize #PyStructSequence_Desc

Definition at line 83 of file bpy_utils_units.c.

References BLI_assert, NULL, and pos.

Referenced by BPY_utils_units().

◆ PyDoc_STRVAR() [1/3]

PyDoc_STRVAR ( bpyunits_doc  ,
"This module contains some data/methods regarding units handling."   
)

◆ PyDoc_STRVAR() [2/3]

PyDoc_STRVAR ( bpyunits_to_string_doc  ,
".. method:: to_string(unit_system, unit_category, value, precision=3, " "split_unit=False, compatible_unit=False)\n" "\n" " Convert a given input float value into a string with units.\n" "\n" " :arg unit_system: The unit  system,
from :attr:`bpy.utils.units.systems`.\n" " :type unit_system:string\n" " :arg unit_category:The category of data we are   convertinglength, area, " "rotation, etc.,
\n" " from :attr:`bpy.utils.units.categories`.\n" " :type unit_category:string\n" " :arg value:The value to convert to a string.\n" " :type value:float\n" " :arg precision:Number of digits after the comma.\n" " :type precision:int\n" " :arg split_unit:Whether to use several units if   needed1m1cm,
or always only " "one(1.01m).\n" " :type split_unit:bool\n" " :arg compatible_unit:Whether to use keyboard-friendly units(1m2) or nicer " "utf-8 ones(1m²).\n" " :type compatible_unit:bool\n" " :return:The converted string.\n" " :rtype:str\n" " :raises ValueError:if conversion fails to generate a valid python string.\n"   
)

◆ PyDoc_STRVAR() [3/3]

PyDoc_STRVAR ( bpyunits_to_value_doc  ,
".. method:: to_value(unit_system, unit_category, str_input, str_ref_unit=None)\n" "\n" " Convert a given input string into a float value.\n" "\n" " :arg unit_system: The unit  system,
from :attr:`bpy.utils.units.systems`.\n" " :type unit_system:string\n" " :arg unit_category:The category of data we are   convertinglength, area, rotation, " "etc.,
\n" " from :attr:`bpy.utils.units.categories`.\n" " :type unit_category:string\n" " :arg str_input:The string to convert to a float value.\n" " :type str_input:string\n" " :arg str_ref_unit:A reference string from which to extract a default  unit,
if none is " "found in ``str_input``.\n" " :type str_ref_unit:string or None\n" " :return:The converted/interpreted value.\n" " :rtype:float\n" " :raises ValueError:if conversion fails to generate a valid python float value.\n"   
)

Variable Documentation

◆ bpyunits_categories_desc

PyStructSequence_Desc bpyunits_categories_desc
static
Initial value:
= {
"bpy.utils.units.categories",
"This named tuple contains all predefined unit names",
bpyunits_categories_fields,
ARRAY_SIZE(bpyunits_categories_fields) - 1,
}
#define ARRAY_SIZE(arr)

Definition at line 73 of file bpy_utils_units.c.

Referenced by BPY_utils_units().

◆ bpyunits_methods

PyMethodDef bpyunits_methods[]
static
Initial value:
= {
{"to_value",
(PyCFunction)bpyunits_to_value,
METH_VARARGS | METH_KEYWORDS,
bpyunits_to_value_doc},
{"to_string",
(PyCFunction)bpyunits_to_string,
METH_VARARGS | METH_KEYWORDS,
bpyunits_to_string_doc},
{NULL, NULL, 0, NULL},
}
static PyObject * bpyunits_to_string(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
static PyObject * bpyunits_to_value(PyObject *UNUSED(self), PyObject *args, PyObject *kw)

Definition at line 323 of file bpy_utils_units.c.

◆ bpyunits_module

struct PyModuleDef bpyunits_module
static
Initial value:
= {
PyModuleDef_HEAD_INIT,
"bpy.utils.units",
bpyunits_doc,
-1,
}
static PyMethodDef bpyunits_methods[]

Definition at line 335 of file bpy_utils_units.c.

Referenced by BPY_utils_units().

◆ bpyunits_ucategories_items

const char* bpyunits_ucategories_items[]
static
Initial value:
= {
"NONE",
"LENGTH",
"AREA",
"VOLUME",
"MASS",
"ROTATION",
"TIME",
"TIME_ABSOLUTE",
"VELOCITY",
"ACCELERATION",
"CAMERA",
"POWER",
"TEMPERATURE",
}

Definition at line 38 of file bpy_utils_units.c.

Referenced by BPY_utils_units(), and bpyunits_validate().

◆ bpyunits_usystem_items

const char* bpyunits_usystem_items[]
static
Initial value:
= {
"NONE",
"METRIC",
"IMPERIAL",
}

Definition at line 31 of file bpy_utils_units.c.

Referenced by BPY_utils_units(), and bpyunits_validate().

◆ BPyUnitsCategoriesType

PyTypeObject BPyUnitsCategoriesType
static

Definition at line 28 of file bpy_utils_units.c.

Referenced by BPY_utils_units().

◆ BPyUnitsSystemsType

PyTypeObject BPyUnitsSystemsType
static

Definition at line 27 of file bpy_utils_units.c.

Referenced by BPY_utils_units().