viktor.views
DataGroup
- class viktor.views.DataGroup(*args, **kwargs)
Bases:
OrderedDict
Container for DataItems, maximum number = 100. They can be added with or without a keyword argument, but they should be equal for all DataItems in the same DataGroup. Keywords are necessary when you want to use a DataItem in the summary (for lookup).
The following two use cases are valid:
d1 = DataGroup( DataItem('item1',0), DataItem('item2',1), ) d2 = DataGroup( a=DataItem('item1',0), b=DataItem('item2',1), )
- Parameters:
- Raises:
TypeError when positional- and keyword arguments are used together
AttributeError when more than 100 DataItems are used
- classmethod from_data_groups(groups)
Constructs a combined DataGroup object from a list of individual DataGroup entries.
Note that is not possible to have multiple DataGroups that share a specific key for a DataItem, e.g. the following will result in an error:
d1 = DataGroup(output_a=DataItem(...)) d2 = DataGroup(output_a=DataItem(...)) d3 = DataGroup.from_data_groups([d1, d2])
- Return type:
DataItem
- class viktor.views.DataItem(label, value, subgroup=None, *, prefix='', suffix='', number_of_decimals=None, status=DataStatus.INFO, status_message='', explanation_label='')
-
Constructs an entry that can be used as input of a DataGroup, to fill the data view with results.
The data view is dynamic, which means that a DataItem itself can consist of another DataGroup as subgroup. Both examples are demonstrated below.
Example single entry:
result = "I am a great result" item = DataItem('output 1', result)
Example subgroup:
result = "I am a great result" item = DataItem('output 1', result, subgroup=DataGroup( output11=DataItem('output 1.1', "I can also be a numeric result"), output12=DataItem('output 1.2', 123) ))
The prefix / suffix can potentially change with every call. However, when the result is used in the Summary, the prefix / suffix of the DataItem should be equal to the prefix / suffix of the SummaryItem to maintain a consistent database.
- Parameters:
label (
str
) – Description of the value which is shown. e.g: ‘Uc bending’value (
Union
[str
,float
,None
]) – Value of the data. e.g: 0.9subgroup (
DataGroup
) – Optional DataItems grouped together in a DataGroup underneath this DataItem. Maximum depth = 3prefix (
str
) – E.g: €. Should be equal to the prefix of the SummaryItem if linked.suffix (
str
) – E.g: N. Should be equal to the suffix of the SummaryItem if linked.number_of_decimals (
int
) – Number of decimals with which the value is rounded for display.status (
DataStatus
) –Status of value. This controls the formatting of the status_message:
status=DataStatus.INFO: black text
status=DataStatus.SUCCESS: green text
status=DataStatus.WARNING: orange text
status=DataStatus.ERROR: red text
status_message (
str
) – Message which will be shown underneath the value. Color can be formatted with status.explanation_label (
str
) – Optional text which is placed between the label and the value. Could for instance be used for a calculation.
- Raises:
TypeError – if number_of_decimals is used on a non-numeric value.
DataResult
DataStatus
- class viktor.views.DataStatus(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
Enumeration of statuses to annotate a DataItem.
- INFO:
DataStatus
= 'info'
- SUCCESS:
DataStatus
= 'success'
- WARNING:
DataStatus
= 'warning'
- ERROR:
DataStatus
= 'error'
- INFO:
DataView
- class viktor.views.DataView(label, duration_guess=None, *, description=None, update_label=None, **kwargs)
Bases:
View
Function decorator to instruct the controller method to return a data view that contains calculation result.
Example usage:
@DataView("Cost breakdown") def get_data_view(self, params, **kwargs): # calculate data ... return DataResult(data_group)
(new in v14.15.0) The ‘duration_guess’ argument is now optional.
- Parameters:
label (
str
) – Name which is shown on tab in interface. e.g: ‘3D Representation’duration_guess (
int
) – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time (defaults to 1).description (
str
) – Show more information to the user through a tooltip on hover (max. 200 characters).update_label (
str
) – Name which is shown on the update button in case of a slow view (max. 30 characters).
GeoJSONAndDataResult
- class viktor.views.GeoJSONAndDataResult(geojson, data, labels=None, legend=None, *, interaction_groups=None)
Bases:
_ViewResult
Container with the GeoJSON data and result data that should be visualized in a GeoJSONAndDataView. Optionally a legend and map labels can be included.
- Parameters:
geojson (
dict
) – GeoJSON dictionary.data (
DataGroup
) – Result data.labels (
List
[MapLabel
]) – Labels that should be placed on the map.legend (
MapLegend
) – Map legend.interaction_groups (
Dict
[str
,Sequence
[Union
[int
,str
,MapFeature
]]]) – create named groups that can be referred to in a map interactionNew in v13.2.0
- property geojson: dict
GeoJSONAndDataView
- class viktor.views.GeoJSONAndDataView(label, duration_guess=None, *, description=None, update_label=None, **kwargs)
Bases:
View
Function decorator to instruct the controller method to return a combined view consisting of a GeoJSON and data.
Example usage:
@GeoJSONAndDataView("Map / Data") def get_geojson_data_view(self, params, **kwargs): ... return GeoJSONAndDataResult(...)
(new in v14.15.0) The ‘duration_guess’ argument is now optional.
- Parameters:
label (
str
) – Name which is shown on tab in interface. e.g: ‘3D Representation’duration_guess (
int
) – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time (defaults to 1).description (
str
) – Show more information to the user through a tooltip on hover (max. 200 characters).update_label (
str
) – Name which is shown on the update button in case of a slow view (max. 30 characters).
GeoJSONResult
- class viktor.views.GeoJSONResult(geojson, labels=None, legend=None, *, interaction_groups=None)
Bases:
_ViewResult
Container with the GeoJSON data that should be visualized in a GeoJSONView. Optionally a legend and map labels can be included.
The following geojson properties are supported that can be used for styling of the map elements:
icon (geometry type ‘Point’ only): icon to be shown (default: “pin”). For a complete list of all available markers, see
MapPoint
marker-color: the color of a marker [*]
description: text to show when this item is clicked
stroke: the color of a line as part of a polygon, polyline, or multigeometry *
fill: the color of the interior of a polygon *
To enable interaction, the map feature identifiers can be defined within the geojson dict by adding an “id” attribute to a feature as follows:
{ "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": ..., "geometry": ... "id": "my identifier", ...
- Parameters:
geojson (
dict
) – GeoJSON dictionary.labels (
List
[MapLabel
]) – Labels that should be placed on the map.legend (
MapLegend
) – Map legend.interaction_groups (
Dict
[str
,Sequence
[Union
[int
,str
,MapFeature
]]]) – create named groups that can be referred to in a map interactionNew in v13.2.0
- property geojson: dict
GeoJSONView
- class viktor.views.GeoJSONView(label, duration_guess=None, *, description=None, update_label=None, **kwargs)
Bases:
View
Function decorator to instruct the controller method to return a GeoJSON (geographic data) view.
Example usage:
@GeoJSONView("Map") def get_geojson_view(self, params, **kwargs): ... return GeoJSONResult(...)
(new in v14.15.0) The ‘duration_guess’ argument is now optional.
- Parameters:
label (
str
) – Name which is shown on tab in interface. e.g: ‘3D Representation’duration_guess (
int
) – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time (defaults to 1).description (
str
) – Show more information to the user through a tooltip on hover (max. 200 characters).update_label (
str
) – Name which is shown on the update button in case of a slow view (max. 30 characters).
GeometryAndDataResult
- class viktor.views.GeometryAndDataResult(geometry, data, labels=None, *, geometry_type='gltf')
Bases:
_ViewResult
Container with the results that should be visualized in a GeometryAndDataView. This consists of three-dimensional geometry object(s) with optional text labels and data.
Please have a look at GeometryResult for examples.
- Parameters:
geometry (
Union
[TransformableObject
,Sequence
[TransformableObject
],File
]) – TransformableObject(s) that contain the geometric objects, or a geometry file such as glTF/GLB (v2.0) (https://en.wikipedia.org/wiki/GlTF).geometry_type (
str
) – Type of loader that should be used to render the geometry (“gltf”, “3dm”)New in v14.4.0.data (
DataGroup
) – Result data.labels (
List
[Label
]) – Text labels that can be used to provide additional information.
GeometryAndDataView
- class viktor.views.GeometryAndDataView(label, duration_guess=None, *, description=None, update_label=None, view_mode='3D', default_shadow=False, up_axis='Z', x_axis_to_right=None)
Bases:
View
Function decorator to instruct the controller method to return a combined view consisting of geometries and data.
Example usage:
@GeometryAndDataView("Model / Cost") def get_geometry_data_view(self, params, **kwargs): ... return GeometryAndDataResult(...)
(new in v14.15.0) The ‘duration_guess’ argument is now optional.
- Parameters:
label (
str
) – SeeView
.duration_guess (
int
) – SeeView
.description (
str
) – SeeView
.update_label (
str
) – SeeView
.view_mode (
Literal
['2D'
,'3D'
]) –Sets the view mode:
’3D’: Camera is free to move and user can choose between orthographic and perspective view.
’2D’: Camera is fixed on the xy-plane and view is orthographic.
default_shadow (
bool
) – Show shadow when editor is opened. User can still switch it off.up_axis (
Literal
['Y'
,'Z'
]) – (view_mode=’3D’ only) Upwards pointing axis. Possible options: ‘Y’, ‘Z’ (default: ‘Z’)x_axis_to_right (
bool
) – (view_mode=’3D’ and up_axis=’Y’ only) X-axis pointing to the right in the initial viewNew in v14.8.0
GeometryResult
- class viktor.views.GeometryResult(geometry, labels=None, *, geometry_type='gltf')
Bases:
_ViewResult
Container with the results that should be visualized in a GeometryView. This consists of three-dimensional geometry object(s) and optional text labels.
To enable a geometric object for interaction, the object must be named using the ‘identifier’ argument. In case of a glTF/GLB-file, the objects name can be provided on the “name” key within a node. If none of the objects in the GeometryResult have a name assigned, default names are assigned to all of them (enabling them for interaction). Note: if there are multiple objects with the same name, a number will automatically be appended to enforce uniqueness.
Example viktor.geometry TransformableObject(s):
geometry = Sphere(Point(0, 0), 10, identifier="MySphere") GeometryResult(geometry) # or [obj1, obj2, ...] in case of multiple objects
By specifying the geometry_type you can render 3D geometry files either by providing a path, URL, or dynamically created (e.g. using trimesh). Currently supported geometry types are: “gltf”, “3dm”.
Example static geometry file from path:
geometry = File.from_path(Path(__file__).parent / "my_model.gltf") GeometryResult(geometry, geometry_type="gltf")
Example static geometry file from a URL:
geometry = File.from_url("https://github.com/KhronosGroup/glTF-Sample-Models/tree/main/2.0/CesiumMilkTruck/glTF-Binary/CesiumMilkTruck.glb") GeometryResult(geometry, geometry_type="gltf")
Example dynamic geometry file (e.g. using trimesh):
sphere = trimesh.creation.uv_sphere(10) scene = trimesh.Scene(geometry={'sphere': sphere}) geometry = File() with geometry.open_binary() as w: w.write(trimesh.exchange.gltf.export_glb(scene)) GeometryResult(geometry, geometry_type="gltf")
- Parameters:
geometry (
Union
[TransformableObject
,Sequence
[TransformableObject
],File
]) – TransformableObject(s) that contain the geometric objects, or a geometry file such as glTF/GLB (v2.0) (https://en.wikipedia.org/wiki/GlTF).geometry_type (
str
) – Type of loader that should be used to render the geometry (“gltf”, “3dm”)New in v14.4.0.labels (
List
[Label
]) – Text labels that can be used to provide additional information.
GeometryView
- class viktor.views.GeometryView(label, duration_guess=None, *, description=None, update_label=None, view_mode='3D', default_shadow=False, up_axis='Z', x_axis_to_right=None)
Bases:
View
Function decorator to instruct the controller method to return a geometry view (2D / 3D).
Example usage:
@GeometryView("3D model") def get_geometry_view(self, params, **kwargs): ... return GeometryResult(...) @GeometryView("2D model", view_mode='2D') def get_geometry_view_2d(self, params, **kwargs): ... return GeometryResult(...)
(new in v14.15.0) The ‘duration_guess’ argument is now optional.
See
GeometryResult
for example implementations.- Parameters:
label (
str
) – SeeView
.duration_guess (
int
) – SeeView
.description (
str
) – SeeView
.update_label (
str
) – SeeView
.view_mode (
Literal
['2D'
,'3D'
]) –Sets the view mode:
’3D’: Camera is free to move and user can choose between orthographic and perspective view.
’2D’: Camera is fixed on the xy-plane and view is orthographic.
default_shadow (
bool
) – Show shadow when editor is opened. User can still switch it off.up_axis (
Literal
['Y'
,'Z'
]) – (view_mode=’3D’ only) Upwards pointing axis. Possible options: ‘Y’, ‘Z’ (default: ‘Z’)x_axis_to_right (
bool
) – (view_mode=’3D’ and up_axis=’Y’ only) X-axis pointing to the right in the initial viewNew in v14.8.0
IFCAndDataResult
- class viktor.views.IFCAndDataResult(ifc, data)
Bases:
_ViewResult
New in v14.6.0Container with the results that should be visualized in an IFCAndDataView.
Please have a look at IFCResult for examples.
- Parameters:
ifc (
Union
[File
,FileResource
]) – IFC geometry file.data (
DataGroup
) – Result data.
IFCAndDataView
- class viktor.views.IFCAndDataView(label, duration_guess=None, *, description=None, update_label=None, **kwargs)
Bases:
View
New in v14.6.0Function decorator to instruct the controller method to return a combined view consisting of an IFCView and a DataView.
Example usage:
@IFCAndDataView("IFC and data view") def get_ifc_and_data_view(self, params, **kwargs): ifc = File.from_path(Path(__file__).parent / 'sample.ifc') data = ... return IFCAndDataResult(ifc, data)
(new in v14.15.0) The ‘duration_guess’ argument is now optional.
- Parameters:
label (
str
) – Name which is shown on tab in interface. e.g: ‘3D Representation’duration_guess (
int
) – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time (defaults to 1).description (
str
) – Show more information to the user through a tooltip on hover (max. 200 characters).update_label (
str
) – Name which is shown on the update button in case of a slow view (max. 30 characters).
IFCResult
- class viktor.views.IFCResult(ifc)
Bases:
_ViewResult
New in v14.6.0IFC to be visualized in an IFCView.
Example static geometry file from path:
ifc = File.from_path(Path(__file__).parent / 'sample.ifc') IFCResult(ifc)
Example static geometry file from a URL:
ifc = File.from_url("https://github.com/IFCjs/test-ifc-files/raw/main/Others/haus.ifc") IFCResult(ifc)
(new in v14.6.1) In order to improve performance it is possible to use the value of a FileField (i.e. FileResource) directly:
IFCResult(params.file_field)
- Parameters:
ifc (
Union
[File
,FileResource
]) – IFC geometry file.
IFCView
- class viktor.views.IFCView(label, duration_guess=None, *, description=None, update_label=None, **kwargs)
Bases:
View
New in v14.6.0Function decorator to instruct the controller method to return an IFCView.
Example usage:
@IFCView("IFC view") def get_ifc_view(self, params, **kwargs): ifc = File.from_path(Path(__file__).parent / 'sample.ifc') return IFCResult(ifc)
(new in v14.15.0) The ‘duration_guess’ argument is now optional.
- Parameters:
label (
str
) – Name which is shown on tab in interface. e.g: ‘3D Representation’duration_guess (
int
) – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time (defaults to 1).description (
str
) – Show more information to the user through a tooltip on hover (max. 200 characters).update_label (
str
) – Name which is shown on the update button in case of a slow view (max. 30 characters).
ImageAndDataResult
- class viktor.views.ImageAndDataResult(image, data)
Bases:
_ViewResult
New in v13.7.0Container with the image and result data that should be visualized in a ImageAndDataView.
Supported image types are ‘svg’, ‘jpeg’, ‘png’, ‘gif’.
ImageAndDataView
- class viktor.views.ImageAndDataView(label, duration_guess=None, *, description=None, update_label=None, **kwargs)
Bases:
View
New in v13.7.0Function decorator to instruct the controller method to return a combined view consisting of an image and data.
Supported image types are ‘svg’, ‘jpeg’, ‘png’, ‘gif’.
Example usage:
@ImageAndDataView("Image View") def get_image_data_view(self, params, **kwargs): ... return ImageAndDataResult(image, data_group)
(new in v14.15.0) The ‘duration_guess’ argument is now optional.
- Parameters:
label (
str
) – Name which is shown on tab in interface. e.g: ‘3D Representation’duration_guess (
int
) – Estimation of view calculation in seconds. This will be used to add a manual refresh button for long-running tasks (larger than 3s). This estimation does not need to be very precise, but the performance will be better if this is close to the real maximum computation time (defaults to 1).description (
str
) – Show more information to the user through a tooltip on hover (max. 200 characters).update_label (
str
) – Name which is shown on the update button in case of a slow view (max. 30 characters).