1"""! This module defines all necessary functions to
3 - start CASP Block Editor process
4 - create a new block as a project
5 - modify block internal parameters
6 - add block user parameters
8 - save the block to the disk
9 - and finally when every thing is done, close the Block Editor process
11 All functions in this module uses global object \ref _casp_process.casp_be_proc from \ref _casp_process.py module.
17if sys.version_info[:3] < (3,9):
18 from typing
import List
as list
20from _casp_process
import casp_be_proc
21import casp_utils
as utils
22import casp_defs
as defs
24def Init(casp_file: str=
"BlockEditor"):
25 """! Initializes CASP Block Editor subprocess. This is the first function to be called before using any other function in this module.
29 casp_file: Set executable file to be invoked. Set this argument only if the executable file version is different from 'BlockEditor'.
31 casp_be_proc.init(casp_file)
34 """! Opens CASP Python Libraries documentation.
36 response = casp_proc.write(
"casp.help.python")
39 """! Terminates CASP Block Editor subprocess and releases the resources.
43def Open(blk_name: str, visible_title: str, parent_dir_path: str=
"", overwrite_existing: bool=
True) -> bool:
44 """! Creates new block and opens it for further configuration.
48 blk_name: Block name to be created. The block name should follow standard file naming conventions.
50 visible_title: Block visible title text.
52 parent_dir_path: Block location/arent directory path. If empty, the new block will be created in 'casp_user_data/blocks' folder.
54 overwrite_existing: True to overwrite existing block if path matches.
58 Returns True if successful or else False.
60 response = casp_be_proc.write(
"casp.open", [blk_name, visible_title, parent_dir_path, str(int(overwrite_existing))])
61 print(f
"CASP: {response.strip()}")
62 if "Error" in response.strip():
66def AddPort(port_name: str, visible_text: str, output_port: bool=
False, data_type: str=defs.DATA_TYPE_INT32, data_size :int=1) -> bool:
67 """! Adds new port to the block.
71 port_name: Block port name to be added. The port name should follow standard file naming conventions.
73 visible_text: Block port visible text.
75 output_port: True for output port or False for input port
77 data_type: Port data type. Set one of the data type constants from \ref casp_defs.py module.
79 data_size: Port data size. Value should be > 0.
83 Returns True if successful or else False.
85 response = casp_be_proc.write(
"casp.add_port", [port_name, visible_text, str(int(output_port)), data_type, str(data_size)])
86 print(f
"CASP: {response.strip()}")
87 if "Error" in response.strip():
91def AddPara(para_name: str, var_name: str, data_type: str=defs.DATA_TYPE_INT32, para_values :list[str]=[
"None"]) -> bool:
92 """! Adds new parameter to the block.
96 para_name: Block parameter name to be added. The parameter name should follow standard file naming conventions.
98 var_name: Internal variable name of the block parameter. It should be as per C/C++ variable naming conventions.
100 data_type: Parameter value data type. Set one of the data type constants from \ref casp_defs.py module.
102 para_values: Set Parameter values as a string list.
106 Returns True if successful or else False.
108 args = [para_name, var_name, data_type] + para_values
109 response = casp_be_proc.write(
"casp.add_para", args)
110 print(f
"CASP: {response.strip()}")
111 if "Error" in response.strip():
116 """! Set support for other languages such as Python, Fortran and Verilog.
120 lang_type: Set additional languages supported (if any). Set one of the constants from \ref casp_defs.py module.
124 Returns True if successful or else False.
126 response = casp_be_proc.write(
"casp.oth_lang_support", [str(lang_type)])
127 print(f
"CASP: {response.strip()}")
128 if "Error" in response.strip():
133 """! Save block data to disk. This function actually creates the block folder on disk. Should be called only once and at the end of your script.
135 Returns True if successful or else False
137 response = casp_be_proc.write(
"casp.save")
138 print(f
"CASP: {response.strip()}")
139 if "Error" in response.strip():
144 """! Show block folder.
146 response = casp_be_proc.write(
"casp.show_dir")
147 print(f
"CASP: {response.strip()}")
bool AddPara(str para_name, str var_name, str data_type=defs.DATA_TYPE_INT32, list[str] para_values=["None"])
Adds new parameter to the block.
bool SetOtherLangSupport(int lang_type=defs.LANG_PYTHON)
Set support for other languages such as Python, Fortran and Verilog.
Close()
Terminates CASP Block Editor subprocess and releases the resources.
bool Open(str blk_name, str visible_title, str parent_dir_path="", bool overwrite_existing=True)
Creates new block and opens it for further configuration.
HelpPython()
Opens CASP Python Libraries documentation.
Init(str casp_file="BlockEditor")
Initializes CASP Block Editor subprocess.
bool Save()
Save block data to disk.
bool AddPort(str port_name, str visible_text, bool output_port=False, str data_type=defs.DATA_TYPE_INT32, int data_size=1)
Adds new port to the block.
Folder()
Show block folder.