ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ccLog.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include <pybind11/native_enum.h>
9 #include <pybind11/pybind11.h>
10 #include <pybind11/stl.h>
11 #include <pybind11/stl_bind.h>
12 
13 #include "../casters.h"
14 
15 #include <CVLog.h>
16 
17 namespace py = pybind11;
18 using namespace pybind11::literals;
19 
20 void define_ccLog(py::module &m)
21 {
22  py::class_<CVLog> PyccLog(m, "ccLog", R"pbdoc(
23  Class to log messages in ACloudViewer's console.
24 
25  Use one of the static method to log a message
26 )pbdoc");
27  PyccLog.def_static("TheInstance", &CVLog::TheInstance, py::return_value_policy::reference);
28  PyccLog.def_static("LogMessage", &CVLog::LogMessage, "message"_a, "level"_a, R"pbdoc(
29  Logs a message with the given level.
30 
31  Parameters
32  ----------
33  message: str
34  The message to log
35  level: pycc.CVLog.MessageLevelFlags
36  The severity level of the message
37 
38  Example
39  -------
40 
41  >>> import pycc
42  >>> pycc.CVLog.LogMessage("Hello, world", pycc.CVLog.MessageLevelFlags.LOG_STANDARD)
43 )pbdoc");
44  PyccLog.def_static(
45  "Print", static_cast<bool (*)(const QString &)>(&CVLog::Print), "message"_a, R"pbdoc(
46  Logs a message with standard severity level.
47 
48  Parameters
49  ----------
50  message: str
51  The message to log
52 
53  Example
54  -------
55 
56  >>> import pycc
57  >>> pycc.CVLog.Print("Hello, world")
58  True
59 )pbdoc");
60  PyccLog.def_static(
61  "Warning", static_cast<bool (*)(const QString &)>(&CVLog::Warning), "message"_a, R"pbdoc(
62  Logs a warning message
63 
64  Parameters
65  ----------
66  message: str
67  The message to log
68 
69  Example
70  -------
71 
72  >>> import pycc
73  >>> pycc.CVLog.Warning("Oops something bad happenned")
74  False
75 )pbdoc");
76  PyccLog.def_static(
77  "Error", static_cast<bool (*)(const QString &)>(&CVLog::Error), "message"_a, R"pbdoc(
78  Logs an error message
79 
80  This will also display a dialog
81 
82  Parameters
83  ----------
84  message: str
85  The message to log
86 
87  Example
88  -------
89 
90  >>> import pycc
91  >>> pycc.CVLog.Error("Oops something even worse happenned")
92  False
93 )pbdoc");
94 
95  py::native_enum<CVLog::MessageLevelFlags>(
96  PyccLog, "MessageLevelFlags", "enum.Enum", "CVLog::MessageLevelFlags.")
97  .value("LOG_VERBOSE", CVLog::MessageLevelFlags::LOG_VERBOSE)
98  .value("LOG_STANDARD", CVLog::MessageLevelFlags::LOG_STANDARD)
99  .value("LOG_IMPORTANT", CVLog::MessageLevelFlags::LOG_IMPORTANT)
100  .value("LOG_WARNING", CVLog::MessageLevelFlags::LOG_WARNING)
101  .value("LOG_ERROR", CVLog::MessageLevelFlags::LOG_ERROR)
102  .export_values()
103  .finalize();
104 }
void define_ccLog(py::module &m)
Definition: ccLog.cpp:20
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
Definition: CVLog.cpp:133
static bool Print(const char *format,...)
Prints out a formatted message in console.
Definition: CVLog.cpp:113
static void LogMessage(const QString &message, int level)
Static shortcut to CVLog::logMessage.
Definition: CVLog.cpp:64
static CVLog * TheInstance()
Returns the static and unique instance.
Definition: CVLog.cpp:53
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Definition: CVLog.cpp:143