File: algfactory.py

package info (click to toggle)
qgis 3.40.10%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,183,672 kB
  • sloc: cpp: 1,595,771; python: 372,544; xml: 23,474; sh: 3,761; perl: 3,664; ansic: 2,257; sql: 2,137; yacc: 1,068; lex: 577; javascript: 540; lisp: 411; makefile: 161
file content (647 lines) | stat: -rw-r--r-- 24,311 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
"""
***************************************************************************
    algfactory.py
    ---------------------
    Date                 : November 2018
    Copyright            : (C) 2018 by Nathan Woodrow
    Email                : woodrow dot nathan at gmail dot com
***************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
***************************************************************************
"""

__author__ = "Nathan Woodrow"
__date__ = "November 2018"
__copyright__ = "(C) 2018, Nathan Woodrow"

from collections import OrderedDict
from functools import partial

from qgis.PyQt.QtCore import QCoreApplication
from qgis.PyQt.QtGui import QIcon
from qgis.core import (
    QgsProcessingParameterDefinition,
    QgsProcessingAlgorithm,
    QgsProcessingParameterString,
    QgsProcessingParameterAuthConfig,
    QgsProcessingParameterNumber,
    QgsProcessingParameterDistance,
    QgsProcessingParameterDuration,
    QgsProcessingParameterFeatureSource,
    QgsProcessingParameterFeatureSink,
    QgsProcessingParameterFileDestination,
    QgsProcessingParameterFolderDestination,
    QgsProcessingParameterRasterDestination,
    QgsProcessingParameterVectorDestination,
    QgsProcessingParameterPointCloudDestination,
    QgsProcessingParameterBand,
    QgsProcessingParameterBoolean,
    QgsProcessingParameterCrs,
    QgsProcessingParameterEnum,
    QgsProcessingParameterExpression,
    QgsProcessingParameterExtent,
    QgsProcessingParameterField,
    QgsProcessingParameterFile,
    QgsProcessingParameterMapLayer,
    QgsProcessingParameterMatrix,
    QgsProcessingParameterMultipleLayers,
    QgsProcessingParameterPoint,
    QgsProcessingParameterGeometry,
    QgsProcessingParameterRange,
    QgsProcessingParameterRasterLayer,
    QgsProcessingParameterVectorLayer,
    QgsProcessingParameterMeshLayer,
    QgsProcessingParameterColor,
    QgsProcessingParameterScale,
    QgsProcessingParameterLayout,
    QgsProcessingParameterLayoutItem,
    QgsProcessingParameterDateTime,
    QgsProcessingParameterMapTheme,
    QgsProcessingParameterProviderConnection,
    QgsProcessingParameterDatabaseSchema,
    QgsProcessingParameterDatabaseTable,
    QgsProcessingParameterCoordinateOperation,
    QgsProcessingParameterPointCloudLayer,
    QgsProcessingParameterAnnotationLayer,
    QgsProcessingOutputString,
    QgsProcessingOutputBoolean,
    QgsProcessingOutputFile,
    QgsProcessingOutputFolder,
    QgsProcessingOutputHtml,
    QgsProcessingOutputLayerDefinition,
    QgsProcessingOutputMapLayer,
    QgsProcessingOutputMultipleLayers,
    QgsProcessingOutputNumber,
    QgsProcessingOutputRasterLayer,
    QgsProcessingOutputVectorLayer,
    QgsProcessingOutputPointCloudLayer,
    QgsMessageLog,
    QgsApplication,
)


def _log(*args, **kw):
    """
    Log messages to the QgsMessageLog viewer
    """
    QgsMessageLog.logMessage(" ".join(map(str, args)), "Factory")


def _make_output(**args):
    """
    Create a processing output class type.
    :param args: 'cls' The class object type.
                 'name' the name of the output
                 'description' The description used on the output
    :return:
    """
    cls = args["cls"]
    del args["cls"]
    newargs = {
        "name": args["name"],
        "description": args["description"],
    }
    return cls(**newargs)


class ProcessingAlgFactoryException(Exception):
    """
    Exception raised when using @alg on a function.
    """

    def __init__(self, message):
        super().__init__(message)


class AlgWrapper(QgsProcessingAlgorithm):
    """
    Wrapper object used to create new processing algorithms from @alg.
    """

    def __init__(
        self,
        name=None,
        display=None,
        group=None,
        group_id=None,
        inputs=None,
        outputs=None,
        func=None,
        help=None,
        icon=None,
    ):
        super().__init__()
        self._inputs = OrderedDict(inputs or {})
        self._outputs = OrderedDict(outputs or {})
        self._icon = icon
        self._name = name
        self._group = group
        self._group_id = group_id
        self._display = display
        self._func = func
        self._help = help

    def _get_parent_id(self, parent):
        """
        Return the id of the parent object.
        """
        if isinstance(parent, str):
            return parent
        else:
            raise NotImplementedError()

    # Wrapper logic
    def define(
        self,
        name,
        label,
        group,
        group_label,
        help=None,
        icon=QgsApplication.iconPath("processingScript.svg"),
    ):
        self._name = name
        self._display = label
        self._group = group_label
        self._group_id = group
        self._help = help
        self._icon = icon

    def end(self):
        """
        Finalize the wrapper logic and check for any invalid config.
        """
        if not self.has_outputs:
            raise ProcessingAlgFactoryException(
                "No outputs defined for '{}' alg"
                "At least one must be defined. Use @alg.output"
            )

    def add_output(self, type, **kwargs):
        parm = self._create_param(type, output=True, **kwargs)
        self._outputs[parm.name()] = parm

    def add_help(self, helpstring, *args, **kwargs):
        self._help = helpstring

    def add_input(self, type, **kwargs):
        parm = self._create_param(type, **kwargs)
        self._inputs[parm.name()] = parm

    @property
    def inputs(self):
        return self._inputs

    @property
    def outputs(self):
        return self._outputs

    def _create_param(self, type, output=False, **kwargs):
        name = kwargs["name"]
        if name in self._inputs or name in self._outputs:
            raise ProcessingAlgFactoryException(f"{name} already defined")

        parent = kwargs.get("parent")
        if parent:
            parentname = self._get_parent_id(parent)
            if parentname == name:
                raise ProcessingAlgFactoryException(
                    "{} can't depend on itself. "
                    "We know QGIS is smart but it's not that smart".format(name)
                )
            if parentname not in self._inputs and parentname not in self._outputs:
                raise ProcessingAlgFactoryException(
                    f"Can't find parent named {parentname}"
                )

        kwargs["description"] = kwargs.pop("label", "")
        kwargs["defaultValue"] = kwargs.pop("default", None)
        advanced = kwargs.pop("advanced", False)
        help_str = kwargs.pop("help", "")
        try:
            if output:
                try:
                    make_func = output_type_mapping[type]
                except KeyError:
                    raise ProcessingAlgFactoryException(
                        f"{type} is a invalid output type"
                    )
            else:
                try:
                    make_func = input_type_mapping[type]
                except KeyError:
                    raise ProcessingAlgFactoryException(
                        f"{type} is a invalid input type"
                    )
            parm = make_func(**kwargs)
            if advanced:
                parm.setFlags(
                    parm.flags() | QgsProcessingParameterDefinition.Flag.FlagAdvanced
                )
            if not output:
                parm.setHelp(help_str)
            return parm
        except KeyError as ex:
            raise NotImplementedError(f"{str(type)} not supported")

    def set_func(self, func):
        self._func = func
        # Only take the help from the function if it hasn't already been set.
        if self._func and not self._help:
            self._help = self._func.__doc__.strip()

    @property
    def has_outputs(self):
        """
        True if this alg wrapper has outputs defined.
        """
        dests = [p for p in self._inputs.values() if p.isDestination()]
        return bool(self._outputs) or bool(dests)

    @property
    def has_inputs(self):
        """
        True if this alg wrapper has outputs defined.
        """
        return bool(self._inputs)

    def _get_parameter_value(self, parm, parameters, name, context):
        """
        Extract the real value from the parameter.
        """
        if isinstance(
            parm, (QgsProcessingParameterString, QgsProcessingParameterAuthConfig)
        ):
            value = self.parameterAsString(parameters, name, context)
            return value
        elif isinstance(parm, QgsProcessingParameterNumber):
            if parm.dataType() == QgsProcessingParameterNumber.Type.Integer:
                value = self.parameterAsInt(parameters, name, context)
                return value
            if parm.dataType() == QgsProcessingParameterNumber.Type.Double:
                value = self.parameterAsDouble(parameters, name, context)
                return value

    # Overloads
    def name(self):
        return self._name

    def displayName(self):
        return self._display

    def group(self):
        return self._group

    def groupId(self):
        return self._group_id

    def processAlgorithm(self, parameters, context, feedback):
        values = {}
        for parm in self._inputs.values():
            name = parm.name()
            values[name] = self._get_parameter_value(parm, parameters, name, context)

        output = self._func(self, parameters, context, feedback, values)
        if output is None:
            return {}
        return output

    def createInstance(self):
        return AlgWrapper(
            self._name,
            self._display,
            self._group,
            self._group_id,
            inputs=self._inputs,
            outputs=self._outputs,
            func=self._func,
            help=self._help,
            icon=self._icon,
        )

    def initAlgorithm(self, configuration=None, p_str=None, Any=None, *args, **kwargs):
        for parm in self._inputs.values():
            self.addParameter(parm.clone())

        for parm in self._outputs.values():
            clsname = parm.__class__.__name__
            klass = globals()[clsname]
            clone = klass(parm.name(), parm.description())
            self.addOutput(clone)

    def shortHelpString(self):
        return self._help

    def icon(self):
        return QIcon(self._icon)


class ProcessingAlgFactory:
    STRING = ("STRING",)
    INT = ("INT",)
    NUMBER = ("NUMBER",)
    DISTANCE = ("DISTANCE",)
    SINK = "SINK"
    SOURCE = "SOURCE"
    FILE = ("FILE",)
    FOLDER = ("FOLDER",)
    HTML = ("HTML",)
    LAYERDEF = ("LAYERDEF",)
    MAPLAYER = ("MAPLAYER",)
    MULTILAYER = ("MULTILAYER",)
    RASTER_LAYER = ("RASTER_LAYER",)
    VECTOR_LAYER = ("VECTOR_LAYER",)
    MESH_LAYER = ("MESH_LAYER",)
    POINT_CLOUD_LAYER = ("POINT_CLOUD_LAYER",)
    FILE_DEST = ("FILE_DEST",)
    FOLDER_DEST = ("FOLDER_DEST",)
    RASTER_LAYER_DEST = ("RASTER_LAYER_DEST",)
    VECTOR_LAYER_DEST = ("VECTOR_LAYER_DEST",)
    POINTCLOUD_LAYER_DEST = ("POINTCLOUD_LAYER_DEST",)
    BAND = ("BAND",)
    BOOL = ("BOOL",)
    CRS = ("CRS",)
    ENUM = ("ENUM",)
    EXPRESSION = ("EXPRESSION",)
    EXTENT = ("EXTENT",)
    FIELD = ("FIELD",)
    MATRIX = ("MATRIX",)
    POINT = ("POINT",)
    GEOMETRY = ("GEOMETRY",)
    RANGE = ("RANGE",)
    AUTH_CFG = "AUTH_CFG"
    SCALE = "SCALE"
    COLOR = "COLOR"
    LAYOUT = "LAYOUT"
    LAYOUT_ITEM = "LAYOUT_ITEM"
    DATETIME = "DATETIME"
    DATE = "DATE"
    TIME = "TIME"
    MAP_THEME = "MAP_THEME"
    PROVIDER_CONNECTION = "PROVIDER_CONNECTION"
    DATABASE_SCHEMA = "DATABASE_SCHEMA"
    DATABASE_TABLE = "DATABASE_TABLE"
    COORDINATE_OPERATION = "COORDINATE_OPERATION"
    POINTCLOUD_LAYER = "POINTCLOUD_LAYER"
    ANNOTATION_LAYER = "ANNOTATION_LAYER"

    def __init__(self):
        self._current = None
        self.instances = []

    def tr(self, string):
        """
        Returns a translatable string with the self.tr() function.
        """
        return QCoreApplication.translate("Processing", string)

    @property
    def current(self):
        return self._current

    @property
    def current_defined(self):
        return self._current is not None

    def __call__(self, *args, **kwargs):
        return self._define(*args, **kwargs)

    def _initnew(self):
        self._current = AlgWrapper()

    def _pop(self):
        self.instances.append(self.current)
        self._current = None

    def _define(self, *args, **kwargs):
        self._initnew()
        self.current.define(*args, **kwargs)

        def dec(f):
            self.current.set_func(f)
            self.current.end()
            self._pop()
            return f

        return dec

    def output(self, type, *args, **kwargs):
        """
        Define a output parameter for this algorithm using @alg.output.
        Apart from `type` this method will take all arguments and pass them though to the correct `QgsProcessingOutputDefinition ` type.

        Types:
            str: QgsProcessingOutputString
            int: QgsProcessingOutputNumber
            float: QgsProcessingOutputNumber
            alg.NUMBER: QgsProcessingOutputNumber
            alg.DISTANCE: QgsProcessingOutputNumber
            alg.INT: QgsProcessingOutputNumber
            alg.STRING: QgsProcessingOutputString
            alg.FILE: QgsProcessingOutputFile
            alg.FOLDER: QgsProcessingOutputFolder
            alg.HTML: QgsProcessingOutputHtml
            alg.LAYERDEF:  QgsProcessingOutputLayerDefinition
            alg.MAPLAYER:  QgsProcessingOutputMapLayer
            alg.MULTILAYER:  QgsProcessingOutputMultipleLayers
            alg.RASTER_LAYER: QgsProcessingOutputRasterLayer
            alg.VECTOR_LAYER: QgsProcessingOutputVectorLayer
            alg.POINTCLOUD_LAYER: QgsProcessingOutputPointCloudLayer
            alg.BOOL: QgsProcessingOutputBoolean

        :param type: The type of the input. This should be a type define on `alg` like alg.STRING, alg.DISTANCE
        :keyword label: The label of the output. Will convert into `description` arg.
        :keyword parent: The string ID of the parent parameter. Parent parameter must be defined before its here.
        """

        def dec(f):
            return f

        self.current.add_output(type, *args, **kwargs)
        return dec

    def help(self, helpstring, *args, **kwargs):
        """
        Define the help for the algorithm using @alg.help. This method will
        be used instead of the doc string on the function as the help in the processing dialogs.

        :param helpstring: The help text. Use QCoreApplication.translate() for translation support.
        """

        def dec(f):
            return f

        self.current.add_help(helpstring, *args, **kwargs)

        return dec

    def input(self, type, *args, **kwargs):
        """
        Define a input parameter for this algorithm using @alg.input.
        Apart from `type` this method will take all arguments and pass them though to the correct `QgsProcessingParameterDefinition` type.

        Types:

            str: QgsProcessingParameterString
            int: QgsProcessingParameterNumber
            float: QgsProcessingParameterNumber
            bool: QgsProcessingParameterBoolean
            alg.NUMBER: QgsProcessingParameterNumber
            alg.INT: QgsProcessingParameterNumber
            alg.STRING: QgsProcessingParameterString
            alg.DISTANCE: QgsProcessingParameterDistance
            alg.SINK: QgsProcessingParameterFeatureSink
            alg.SOURCE: QgsProcessingParameterFeatureSource
            alg.FILE_DEST: QgsProcessingParameterFileDestination
            alg.FOLDER_DEST: QgsProcessingParameterFolderDestination
            alg.RASTER_LAYER: QgsProcessingParameterRasterLayer
            alg.RASTER_LAYER_DEST: QgsProcessingParameterRasterDestination
            alg.VECTOR_LAYER_DEST: QgsProcessingParameterVectorDestination
            alg.POINTCLOUD_LAYER_DEST: QgsProcessingParameterPointCloudDestination
            alg.BAND: QgsProcessingParameterBand
            alg.BOOL: QgsProcessingParameterBoolean
            alg.CRS: QgsProcessingParameterCrs
            alg.ENUM: QgsProcessingParameterEnum
            alg.EXPRESSION: QgsProcessingParameterExpression
            alg.EXTENT: QgsProcessingParameterExtent
            alg.FIELD: QgsProcessingParameterField
            alg.FILE: QgsProcessingParameterFile
            alg.MAPLAYER: QgsProcessingParameterMapLayer
            alg.MATRIX: QgsProcessingParameterMatrix
            alg.MULTILAYER: QgsProcessingParameterMultipleLayers
            alg.POINT: QgsProcessingParameterPoint
            alg.GEOMETRY: QgsProcessingParameterGeometry
            alg.RANGE: QgsProcessingParameterRange
            alg.VECTOR_LAYER: QgsProcessingParameterVectorLayer
            alg.AUTH_CFG: QgsProcessingParameterAuthConfig
            alg.MESH_LAYER: QgsProcessingParameterMeshLayer
            alg.SCALE: QgsProcessingParameterScale
            alg.LAYOUT: QgsProcessingParameterLayout
            alg.LAYOUT_ITEM: QgsProcessingParameterLayoutItem
            alg.COLOR: QgsProcessingParameterColor
            alg.DATETIME: QgsProcessingParameterDateTime(type=QgsProcessingParameterDateTime.Type.DateTime)
            alg.DATE: QgsProcessingParameterDateTime(type=QgsProcessingParameterDateTime.Type.Date)
            alg.TIME: QgsProcessingParameterDateTime(type=QgsProcessingParameterDateTime.Type.Time)
            alg.MAP_THEME: QgsProcessingParameterMapTheme
            alg.PROVIDER_CONNECTION: QgsProcessingParameterProviderConnection
            alg.DATABASE_SCHEMA: QgsProcessingParameterDatabaseSchema
            alg.DATABASE_TABLE: QgsProcessingParameterDatabaseTable
            alg.COORDINATE_OPERATION: QgsProcessingParameterCoordinateOperation
            alg.POINTCLOUD_LAYER: QgsProcessingParameterPointCloudLayer
            alg.ANNOTATION_LAYER: QgsProcessingParameterAnnotationLayer

        :param type: The type of the input. This should be a type define on `alg` like alg.STRING, alg.DISTANCE
        :keyword label: The label of the output. Translates into `description` arg.
        :keyword parent: The string ID of the parent parameter. Parent parameter must be defined before its here.
        :keyword default: The default value set for that parameter. Translates into `defaultValue` arg.
        """

        def dec(f):
            return f

        self.current.add_input(type, *args, **kwargs)

        return dec


input_type_mapping = {
    str: QgsProcessingParameterString,
    int: partial(
        QgsProcessingParameterNumber, type=QgsProcessingParameterNumber.Type.Integer
    ),
    float: partial(
        QgsProcessingParameterNumber, type=QgsProcessingParameterNumber.Type.Double
    ),
    bool: QgsProcessingParameterBoolean,
    ProcessingAlgFactory.NUMBER: partial(
        QgsProcessingParameterNumber, type=QgsProcessingParameterNumber.Type.Double
    ),
    ProcessingAlgFactory.INT: partial(
        QgsProcessingParameterNumber, type=QgsProcessingParameterNumber.Type.Integer
    ),
    ProcessingAlgFactory.STRING: QgsProcessingParameterString,
    ProcessingAlgFactory.DISTANCE: QgsProcessingParameterDistance,
    ProcessingAlgFactory.SINK: QgsProcessingParameterFeatureSink,
    ProcessingAlgFactory.SOURCE: QgsProcessingParameterFeatureSource,
    ProcessingAlgFactory.FILE_DEST: QgsProcessingParameterFileDestination,
    ProcessingAlgFactory.FOLDER_DEST: QgsProcessingParameterFolderDestination,
    ProcessingAlgFactory.RASTER_LAYER: QgsProcessingParameterRasterLayer,
    ProcessingAlgFactory.RASTER_LAYER_DEST: QgsProcessingParameterRasterDestination,
    ProcessingAlgFactory.VECTOR_LAYER_DEST: QgsProcessingParameterVectorDestination,
    ProcessingAlgFactory.POINTCLOUD_LAYER_DEST: QgsProcessingParameterPointCloudDestination,
    ProcessingAlgFactory.BAND: QgsProcessingParameterBand,
    ProcessingAlgFactory.BOOL: QgsProcessingParameterBoolean,
    ProcessingAlgFactory.CRS: QgsProcessingParameterCrs,
    ProcessingAlgFactory.ENUM: QgsProcessingParameterEnum,
    ProcessingAlgFactory.EXPRESSION: QgsProcessingParameterExpression,
    ProcessingAlgFactory.EXTENT: QgsProcessingParameterExtent,
    ProcessingAlgFactory.FIELD: QgsProcessingParameterField,
    ProcessingAlgFactory.FILE: QgsProcessingParameterFile,
    ProcessingAlgFactory.MAPLAYER: QgsProcessingParameterMapLayer,
    ProcessingAlgFactory.MATRIX: QgsProcessingParameterMatrix,
    ProcessingAlgFactory.MULTILAYER: QgsProcessingParameterMultipleLayers,
    ProcessingAlgFactory.POINT: QgsProcessingParameterPoint,
    ProcessingAlgFactory.GEOMETRY: QgsProcessingParameterGeometry,
    ProcessingAlgFactory.RANGE: QgsProcessingParameterRange,
    ProcessingAlgFactory.VECTOR_LAYER: QgsProcessingParameterVectorLayer,
    ProcessingAlgFactory.AUTH_CFG: QgsProcessingParameterAuthConfig,
    ProcessingAlgFactory.MESH_LAYER: QgsProcessingParameterMeshLayer,
    ProcessingAlgFactory.SCALE: QgsProcessingParameterScale,
    ProcessingAlgFactory.LAYOUT: QgsProcessingParameterLayout,
    ProcessingAlgFactory.LAYOUT_ITEM: QgsProcessingParameterLayoutItem,
    ProcessingAlgFactory.COLOR: QgsProcessingParameterColor,
    ProcessingAlgFactory.DATETIME: partial(
        QgsProcessingParameterDateTime,
        type=QgsProcessingParameterDateTime.Type.DateTime,
    ),
    ProcessingAlgFactory.DATE: partial(
        QgsProcessingParameterDateTime, type=QgsProcessingParameterDateTime.Type.Date
    ),
    ProcessingAlgFactory.TIME: partial(
        QgsProcessingParameterDateTime, type=QgsProcessingParameterDateTime.Type.Time
    ),
    ProcessingAlgFactory.MAP_THEME: QgsProcessingParameterMapTheme,
    ProcessingAlgFactory.PROVIDER_CONNECTION: QgsProcessingParameterProviderConnection,
    ProcessingAlgFactory.DATABASE_SCHEMA: QgsProcessingParameterDatabaseSchema,
    ProcessingAlgFactory.DATABASE_TABLE: QgsProcessingParameterDatabaseTable,
    ProcessingAlgFactory.COORDINATE_OPERATION: QgsProcessingParameterCoordinateOperation,
    ProcessingAlgFactory.POINTCLOUD_LAYER: QgsProcessingParameterPointCloudLayer,
    ProcessingAlgFactory.ANNOTATION_LAYER: QgsProcessingParameterAnnotationLayer,
}

output_type_mapping = {
    str: partial(_make_output, cls=QgsProcessingOutputString),
    int: partial(_make_output, cls=QgsProcessingOutputNumber),
    float: partial(_make_output, cls=QgsProcessingOutputNumber),
    ProcessingAlgFactory.NUMBER: partial(_make_output, cls=QgsProcessingOutputNumber),
    ProcessingAlgFactory.DISTANCE: partial(_make_output, cls=QgsProcessingOutputNumber),
    ProcessingAlgFactory.INT: partial(_make_output, cls=QgsProcessingOutputNumber),
    ProcessingAlgFactory.STRING: partial(_make_output, cls=QgsProcessingOutputString),
    ProcessingAlgFactory.FILE: partial(_make_output, cls=QgsProcessingOutputFile),
    ProcessingAlgFactory.FOLDER: partial(_make_output, cls=QgsProcessingOutputFolder),
    ProcessingAlgFactory.HTML: partial(_make_output, cls=QgsProcessingOutputHtml),
    ProcessingAlgFactory.LAYERDEF: partial(
        _make_output, cls=QgsProcessingOutputLayerDefinition
    ),
    ProcessingAlgFactory.MAPLAYER: partial(
        _make_output, cls=QgsProcessingOutputMapLayer
    ),
    ProcessingAlgFactory.MULTILAYER: partial(
        _make_output, cls=QgsProcessingOutputMultipleLayers
    ),
    ProcessingAlgFactory.RASTER_LAYER: partial(
        _make_output, cls=QgsProcessingOutputRasterLayer
    ),
    ProcessingAlgFactory.VECTOR_LAYER: partial(
        _make_output, cls=QgsProcessingOutputVectorLayer
    ),
    ProcessingAlgFactory.POINTCLOUD_LAYER: partial(
        _make_output, cls=QgsProcessingOutputPointCloudLayer
    ),
    ProcessingAlgFactory.BOOL: partial(_make_output, cls=QgsProcessingOutputBoolean),
}