Generating complete stage and saving to yaml

 1from ceed.shape import CeedPaintCanvasBehavior, CeedPaintCircle, \
 2    CeedPaintEllipse, CeedPaintPolygon
 3from ceed.function import FunctionFactoryBase, register_all_functions, \
 4    register_external_functions
 5from ceed.function.plugin import ConstFunc
 6from ceed.stage import StageFactoryBase, register_all_stages, \
 7    register_external_stages, CeedStage
 8from ceed.storage.controller import CeedDataWriterBase
 9from typing import Type
10
11# create shape/function/stage factory
12shape_factory = CeedPaintCanvasBehavior()
13function_factory = FunctionFactoryBase()
14stage_factory = StageFactoryBase(
15    function_factory=function_factory, shape_factory=shape_factory)
16
17# now we need to register all the builtin and external functions and stage
18# plugins
19register_all_functions(function_factory)
20register_all_stages(stage_factory)
21# if you have plugins in an external packages, you need to register it as well.
22# See the functions for details and how to make the plugin available in the GUI
23# register_external_functions(function_factory, 'my_package.function')
24# register_external_stages(stage_factory, 'my_package.stage')
25
26# create the shapes and name them. We use the Shape classes imported from Ceed
27ellipse = CeedPaintEllipse.create_shape(
28    center=(250, 450), radius_x=200, radius_y=400, name='ellipse')
29circle = CeedPaintCircle.create_shape(
30    center=(700, 300), radius=200, name='circle')
31polygon = CeedPaintPolygon.create_shape(
32    points=[275, 300, 700, 300, 500, 800], name='polygon')
33
34# add the shapes to factory
35shape_factory.add_shape(ellipse)
36shape_factory.add_shape(circle)
37shape_factory.add_shape(polygon)
38
39# create group, name it, and add shapes to it
40group = shape_factory.add_group()
41group.name = 'shapes'
42group.add_shape(ellipse)
43group.add_shape(polygon)
44
45# create a function. We get it from the factory because that's where Ceed gets
46# it from, but we use the type hint to help the IDE type it correctly (not
47# required by python though)
48func_cls: Type[ConstFunc] = function_factory.get('ConstFunc')
49func = func_cls(
50    function_factory=function_factory, name='stable', duration=1, a=0.5)
51
52# create a stage. We get it from the factory for the same reason as the function
53stage_cls: Type[CeedStage] = stage_factory.get('CeedStage')
54stage = stage_cls(
55    function_factory=function_factory, stage_factory=stage_factory,
56    shape_factory=shape_factory, name='best stage')
57
58# now add the shape, group, and function to the stage
59stage.add_shape(circle)
60stage.add_shape(group)
61stage.add_func(func)
62
63# we do need to add the stage to the factory, but we don't need to do it for
64# the function because we don't need it in the global function list
65stage_factory.add_stage(stage)
66
67# save it to disk for import later
68CeedDataWriterBase.save_config_to_yaml(
69    'config.yml', shape_factory=shape_factory,
70    function_factory=function_factory, stage_factory=stage_factory)