prop_pragma#
project: PropPragma.etp
pragma
# Copyright (C) 2023 - 2024 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""
Example for the basic functions of ansys.scade.apitools.prop.pragma.
* find_pragma
* get_pragma_text
* remove_pragma
* set_pragma_text
Project: ./PropPragma.etp
"""
from scade import output
from scade.model.suite import get_roots as get_sessions
from ansys.scade.apitools.prop import find_pragma, get_pragma_text, remove_pragma, set_pragma_text
# load the Scade model
model = get_sessions()[0].model
# retrieve the sensor sandbox
sensor = model.get_object_from_path('P::sandbox/')
# create a pragma 'any' to initialize the test
set_pragma_text(sensor, 'any', 'some text')
# retrieve the pragma
pragma = find_pragma(sensor, 'any')
# its text shall be identical to the value returned by get_pragma_text
assert pragma.text == get_pragma_text(sensor, 'any')
output('pragma any for %s: %s\n' % (sensor.name, pragma.text))
for _ in range(2):
found = remove_pragma(sensor, 'any')
output('pragma any deleted for %s: %s\n' % (sensor.name, found))
Output:
pragma any for sandbox: some text
pragma any deleted for sandbox: True
pragma any deleted for sandbox: False
pragma_json
# Copyright (C) 2023 - 2024 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""
Example for the 'json' functions of ansys.scade.apitools.prop.pragma.
* get_pragma_json
* set_pragma_json
Project: ./PropPragma.etp
"""
from scade import output
from scade.model.suite import get_roots as get_sessions
from ansys.scade.apitools.prop import (
find_pragma,
get_pragma_json,
get_pragma_text,
set_pragma_json,
)
# load the Scade model
model = get_sessions()[0].model
# retrieve the sensor sandbox
sensor = model.get_object_from_path('P::sandbox/')
# create a pragma 'any' using json serialization
set_pragma_json(sensor, 'any', {'bool': True, 'text': 'some text'})
# check the serialization
text = get_pragma_text(sensor, 'any')
output('pragma any for %s: %s\n' % (sensor.name, text))
# retrieve the value as a Python object
value = get_pragma_json(sensor, 'any')
output('pragma any for %s: %s\n' % (sensor.name, value))
# remove the pragma
set_pragma_json(sensor, 'any', {})
assert not find_pragma(sensor, 'any')
Output:
pragma any for sandbox: {"bool": true, "text": "some text"}
pragma any for sandbox: {'bool': True, 'text': 'some text'}
pragma_tool
# Copyright (C) 2023 - 2024 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""
Example for the 'tool' functions of ansys.scade.apitools.prop.pragma.
* find_pragma_tool
* get_pragma_tool_text
* remove_pragma_tool
* set_pragma_tool_text
Project: ./PropPragma.etp
"""
from scade import output
from scade.model.suite import get_roots as get_sessions
from ansys.scade.apitools.prop import (
find_pragma_tool,
get_pragma_tool_text,
remove_pragma_tool,
set_pragma_tool_text,
)
# load the Scade model
model = get_sessions()[0].model
# retrieve the sensor sandbox
sensor = model.get_object_from_path('P::sandbox/')
# set the pragma 'kcg C:name'
set_pragma_tool_text(sensor, 'kcg', 'C:name', 'c_name')
# retrieve and delete the pragma name for the target languages C and Ada
for language in 'C', 'Ada':
key = language + ':name'
pragma = find_pragma_tool(sensor, 'kcg', key)
output('pragma kcg %s found for %s: %s\n' % (key, sensor.name, pragma is not None))
text = get_pragma_tool_text(sensor, 'kcg', key)
output('pragma kcg %s for %s: %s\n' % (key, sensor.name, text))
modified = set_pragma_tool_text(sensor, 'kcg', key, 'c_new_name')
output('pragma kcg %s modified for %s: %s\n' % (key, sensor.name, modified))
found = remove_pragma_tool(sensor, 'kcg', key)
output('pragma kcg %s deleted for %s: %s\n' % (key, sensor.name, found))
Output:
pragma kcg C:name found for sandbox: True
pragma kcg C:name for sandbox: c_name
pragma kcg C:name modified for sandbox: True
pragma kcg C:name deleted for sandbox: True
pragma kcg Ada:name found for sandbox: False
pragma kcg Ada:name for sandbox: None
pragma kcg Ada:name modified for sandbox: True
pragma kcg Ada:name deleted for sandbox: True