====== Editor ====== Editor is returned by :func:`ua.Model:edit` method. It is used to edit the address space. It has same interface as browser with additional methods to add new nodes to the model. To save changes to the model you should call :func:`editor.save` method. Without saving changes are not committed to the model. Objects returned from the following methods **editor.addXXX()** have same interface as objects returned from :func:`ua.Model:browse` method plus additional methods to edit the node. All changes made to them are saved in the editor and will be committed to the model when you call :func:`editor.save` method. .. function:: editor.addObject(browseName, objectType, nodeId, refType) Add an object to the model under ObjectsFolder node. :browseName: :ref:`QualifiedName` or :ref:`String` Name of the object. :objectType: :ref:`NodeId` | :ref:`ObjectType` object. Object type which will be used as a template for the new object. The hierarchy of object type will be expanded. :nodeId: Node ID for the new object. If not provided, then new Node ID is generated. :refType: Reference type of the object. Can be: * :ref:`NodeId` of the reference type * :ref:`String` with name of the reference type * :ref:`Reference Type` object * **nil** - then HasComponent reference type is used. Example: .. literalinclude:: ../examples/server/server_add_object.lua :language: lua :linenos: :lines: 6-7 :emphasize-lines: 1 `Full source <../_static/server/server_add_object.lua>`__ .. function:: editor.addObjectType(browseName) Add an object type to the model. :browseName: :ref:`QualifiedName` or :ref:`String` Name of the object. :returns: :ref:`ObjectType` Example: .. literalinclude:: ../examples/server/server_add_object_type.lua :language: lua :linenos: :lines: 30-36,74-76 :emphasize-lines: 3 `Full source <../_static/server/server_add_object_type.lua>`__ .. function:: editor.addVariableType(browseName) Add a variable type to the model. :returns: :ref:`VariableType` Example: .. literalinclude:: ../examples/server/server_add_object_type.lua :language: lua :linenos: :lines: 26-29,43-45 :emphasize-lines: 4 `Full source <../_static/server/server_add_object_type.lua>`__ .. function:: editor.addReferenceType(browseName) Add a reference type to the model. :returns: :ref:`Reference Type` .. function:: editor.addEnum(browseName, values, nodeId) Add an enum to the model. :values: Array of string. Each value is a name of the enum value, values are assigned in the order they are defined. :returns: :ref:`Enum`. Example: .. literalinclude:: ../examples/server/server_add_object_type.lua :language: lua :linenos: :lines: 13-18 :emphasize-lines: 2 `Full source <../_static/server/server_add_object_type.lua>`__ .. function:: editor.addStructure(browseName, nodeId) Add a structure to the model. :browseName: :ref:`QualifiedName` or :ref:`String` Name of the structure. :nodeId: Node ID for the new structure. If not provided, then new Node ID is generated. :returns: :ref:`Structure` That can be used to add fields to the structure. Example: .. literalinclude:: ../examples/server/server_add_object_type.lua :language: lua :linenos: :lines: 20-24 :emphasize-lines: 2 `Full source <../_static/server/server_add_object_type.lua>`__ .. function:: editor.save() Save the model. :returns: nil Example: .. literalinclude:: ../examples/server/server_add_object_type.lua :language: lua :linenos: :lines: 11,75-81 :emphasize-lines: 8 `Full source <../_static/server/server_add_object_type.lua>`__ .. function:: editor.objectsFolder() Returns 'ObjectsFolder'. :returns: :ref:`Object` that can be used for editing objects under ObjectsFolder. Example: .. literalinclude:: ../examples/server/server_add_nodes.lua :language: lua :linenos: :lines: 11-15 :emphasize-lines: 3 `Full source <../_static/server/server_add_nodes.lua>`__ Object ------ .. function:: object.addProperty(browseName, propertyType, nodeId, refType) Add a property to the object. :browseName: :ref:`QualifiedName` | :ref:`String` Name of the property. :propertyType: (optional) :ref:`NodeId` | DataType. Property type which will be used as a template for the new property. :nodeId: (optional) Node ID for the new property. If not provided, then new Node ID is generated. :refType: (optional) Reference type of the property. :returns: :ref:`Variable` object. Example: .. literalinclude:: ../examples/server/server_add_object.lua :language: lua :linenos: :lines: 14-17 :emphasize-lines: 2-4 `Full source <../_static/server/server_add_object.lua>`__ .. function:: object.addVariable(browseName, value, variableType, nodeId, refType) Add a variable to the object. :browseName: (:ref:`String` or :ref:`QualifiedName`) Name of the variable. :value: (:ref:`DataValue` or :ref:`Variant` or nil) Value of the variable. :variableType: (:ref:`NodeId` or :ref:`VariableType` or nil) Variable type which will be used as a template for the new variable. The hierarchy of variable type will be expanded. If not provided, then BaseDataVariableType is used. :nodeId: (:ref:`NodeId` or nil) Node ID for the new variable. If not provided, then new Node ID is generated. :refType: (:ref:`NodeId` or :ref:`String` or :ref:`Reference Type` or nil) Reference type of the variable. If not provided, then HasComponent reference type is used. :returns: :ref:`Variable` object. Example: .. literalinclude:: ../examples/server/server_add_object.lua :language: lua :linenos: :lines: 4-7 :emphasize-lines: 4 `Full source <../_static/server/server_add_object.lua>`__ .. function:: object.addObject(browseName, objectType, nodeId, refType) Add an sub-object to the object. :browseName: :ref:`QualifiedName` or :ref:`String` Name of the object. :objectType: :ref:`NodeId` | :ref:`ObjectType` object. Object type which will be used as a template for the new object. The hierarchy of object type will be expanded. :nodeId: Node ID for the new object. If not provided, then new Node ID is generated. :refType: Reference type of the object. Can be: * :ref:`NodeId` of the reference type * :ref:`String` with name of the reference type * :ref:`Reference Type` object * **nil** - then HasComponent reference type is used. :returns: :ref:`Object` Example: .. literalinclude:: ../examples/server/server_add_object.lua :language: lua :linenos: :lines: 4-7,15-16 :emphasize-lines: 5 `Full source <../_static/server/server_add_object.lua>`__ .. function:: object.addFolder(browseName) Add Folder which stores other nodes (like 'ObjectsFolder') :returns: :ref:`Object` with newly created folder .. literalinclude:: ../examples/server/server_add_nodes.lua :language: lua :linenos: :lines: 12-15 :emphasize-lines: 4 `Full source <../_static/server/server_add_nodes.lua>`__ .. function:: object.addMethod(browseName, func, inputArguments, outputArguments, nodeId) Add a method to the Object. :func: Function to be called when the method is called by client. :inputArguments: Array with description of input arguments. Each argument is a table with following fields: * Name * DataType * ValueRank (optional) * ArrayDimensions (optional) * Description (optional) :outputArguments: Array with description of output arguments. Each argument is a table with following fields: * Name * DataType * ValueRank * ArrayDimensions * Description :nodeId: (optional) Node ID for the new method. If not provided, then new Node ID is generated. Example: .. literalinclude:: ../examples/server/server_add_object.lua :language: lua :linenos: :lines: 19-40 :emphasize-lines: 20-21 `Full source <../_static/server/server_add_object.lua>`__ :returns: :ref:`Method` .. function:: object.getProperty(browseName) Get a property from the object. :returns: :ref:`Variable` .. function:: object.getVariable(browseName) Get a variable from the object. :returns: :ref:`Variable` .. function:: object.getComponent(browseName) Get a component from the object. :returns: :ref:`Object` .. function:: object.getMethod(browseName) Get a method from the object. :returns: :ref:`Method` .. function:: object.path(names) Resolve node by path relative to current object. :throws: Error if path is not found. :returns: Node corresponding to the path. ObjectType ---------- .. function:: objectType.addProperty(browseName, value, variableType, nodeId, refType) Add a property to the object. :browseName: :ref:`QualifiedName` | :ref:`String` Name of the property. :propertyType: (optional) :ref:`NodeId` | DataType. Property type which will be used as a template for the new property. :nodeId: (optional) Node ID for the new property. If not provided, then new Node ID is generated. :refType: (optional) Reference type of the property. :returns: :ref:`Variable` object. Example: .. literalinclude:: ../examples/server/server_add_object_type.lua :language: lua :linenos: :lines: 30-34 :emphasize-lines: 4-5 `Full source <../_static/server/server_add_object_type.lua>`__ .. function:: objectType.addVariable(browseName, value, variableType, nodeId, refType) Add a variable to the object. :browseName: (:ref:`String` or :ref:`QualifiedName`) Name of the variable. :value: (:ref:`DataValue` or :ref:`Variant` or nil) Value of the variable. If not provided, then nil is used. :variableType: (:ref:`NodeId` or :ref:`VariableType` or nil) Variable type which will be used as a template for the new variable. The hierarchy of variable type will be expanded. If not provided, then BaseDataVariableType is used. :nodeId: (:ref:`NodeId` or nil) Node ID for the new variable. If not provided, then new Node ID is generated. :refType: (:ref:`NodeId` or :ref:`String` or :ref:`Reference Type` or nil) Reference type of the variable. If not provided, then HasComponent reference type is used. :returns: :ref:`Variable` object. Example: .. literalinclude:: ../examples/server/server_add_object_type.lua :language: lua :linenos: :lines: 30-33,43-45 :emphasize-lines: 5 `Full source <../_static/server/server_add_object_type.lua>`__ .. function:: objectType.addObject(browseName, objectType, nodeId, refType) Add an sub-object to the object. :browseName: :ref:`QualifiedName` or :ref:`String` Name of the object. :objectType: :ref:`NodeId` | :ref:`ObjectType` object. Object type which will be used as a template for the new object. The hierarchy of object type will be expanded. :nodeId: Node ID for the new object. If not provided, then new Node ID is generated. :refType: Reference type of the object. Can be: * :ref:`NodeId` of the reference type * :ref:`String` with name of the reference type * :ref:`Reference Type` object * **nil** - then HasComponent reference type is used. :returns: :ref:`Object` Example: .. literalinclude:: ../examples/server/server_add_object_type.lua :language: lua :linenos: :lines: 31-33,47-49 :emphasize-lines: 5 `Full source <../_static/server/server_add_object_type.lua>`__ .. function:: objectType.addFolder(browseName) Add Folder which stores other nodes (like 'ObjectsFolder') Parameters are the same as for :func:`object.addFolder`. :returns: :ref:`Object` with newly created folder Example: .. literalinclude:: ../examples/server/server_add_object_type.lua :language: lua :linenos: :lines: 30-31,51-55 :emphasize-lines: 3 `Full source <../_static/server/server_add_object_type.lua>`__ .. function:: objectType.addMethod(browseName, func, inputArguments, outputArguments[, nodeId]) Add a method to the object type. :func: Function to be called when the method is called by client. :inputArguments: Array with description of input arguments of a method. Each argument is a table with following fields: * Name * DataType * ValueRank (optional) * ArrayDimensions (optional) * Description (optional) :outputArguments: Array with description of output arguments of a method. Each argument is a table with following fields: * Name * DataType * ValueRank * ArrayDimensions * Description :throws: Error in case of errors. :returns: :ref:`Method` Example: .. literalinclude:: ../examples/server/server_add_object_type.lua :language: lua :linenos: :lines: 31-33,57-73 :emphasize-lines: 18 `Full source <../_static/server/server_add_object_type.lua>`__ .. function:: objectType.getProperty(browseName) Get a property from the object. :returns: :ref:`Variable` .. function:: objectType.getVariable(browseName) Get a variable from the object. :returns: :ref:`Variable` .. function:: objectType.getComponent(browseName) Get a component from the object. :returns: :ref:`Object` .. function:: objectType.getMethod(browseName) Get a method from the object. :returns: :ref:`Method` .. function:: objectType.path(names) Resolve node by path relative to current object. :returns: Node corresponding to the path. Variable -------- .. function:: variable.addVariable(browseName, value, variableType, nodeId, refType) Add a variable to the object. :browseName: (:ref:`String` or :ref:`QualifiedName`) Name of the variable. :value: (:ref:`DataValue` or :ref:`Variant` or nil) Value of the variable. :variableType: (:ref:`NodeId` or :ref:`VariableType` or nil) Variable type which will be used as a template for the new variable. The hierarchy of variable type will be expanded. If not provided, then BaseDataVariableType is used. :nodeId: (:ref:`NodeId` or nil) Node ID for the new variable. If not provided, then new Node ID is generated. :refType: (:ref:`NodeId` or :ref:`String` or :ref:`Reference Type` or nil) Reference type of the variable. If not provided, then HasComponent reference type is used. :returns: :ref:`Variable` object. Example: .. literalinclude:: ../examples/server/server_add_variable.lua :language: lua :linenos: :lines: 10-18 :emphasize-lines: 5-6,8-9 `Full source <../_static/server/server_add_variable.lua>`__ .. function:: variable.getVariable(browseName) Get a chile node variable by name. :returns: :ref:`Variable` .. function:: variable.path(names) Resolve node by path relative to current variable. :returns: Node corresponding to the path. VariableType ------------ Variable type is a type of variable. It is used to describe the type of variable. When create a variable the variable type is used as a template for the new variable. If variable is structured then VariableType is used as a template for the new variable and its underlying hierarchy. For example variable type BuildInfoType represents a structure with the following fields: - **ProductUri** - **ManufacturerName** - **ProductName** - **SoftwareVersion** After creating a variable with type BuildInfoType, the variable will have the same fields as the variable type. Root node will single structured value. For convinience, editor will expand hierarchy with fields in the underlying hierarchy. For each field fill be created separate variable node with the same type as the field. - BuildInfo - Structured value - ProductUri - String - ManufacturerName - String - ProductName - String - SoftwareVersion - String .. function:: variableType.addVariable(browseName, value, variableType, nodeId, refType) Add a variable to the object. :browseName: (:ref:`String` or :ref:`QualifiedName`) Name of the variable. :value: (:ref:`DataValue` or :ref:`Variant` or nil) Value of the variable. :variableType: (:ref:`NodeId` or :ref:`VariableType` or nil) Variable type which will be used as a template for the new variable. The hierarchy of variable type will be expanded. If not provided, then BaseDataVariableType is used. :nodeId: (:ref:`NodeId` or nil) Node ID for the new variable. If not provided, then new Node ID is generated. :refType: (:ref:`NodeId` or :ref:`String` or :ref:`Reference Type` or nil) Reference type of the variable. If not provided, then HasComponent reference type is used. :returns: :ref:`Variable` object. Example: .. literalinclude:: ../examples/server/server_add_variable_type.lua :language: lua :linenos: :lines: 10-17 :emphasize-lines: 4,7 `Full source <../_static/server/server_add_variable_type.lua>`__ .. function:: variableType.getVariable(browseName) Get a chile node variable by name. :returns: :ref:`Variable` .. function:: variableType.path(names) Resolve node by path relative to current variable type. :throws: Error if path is not found. :returns: Node corresponding to the path relative to current variable type. Enum ---- .. function:: enum.setValues(values) Set values for the enum. :values: Array of string. Each value is a name of the enum value, values are assigned in the order they are defined. :returns: nil Example: .. literalinclude:: ../examples/server/server_add_enum.lua :language: lua :linenos: :lines: 20-26 :emphasize-lines: 7 `Full source <../_static/server/server_add_enum.lua>`__ .. function:: enum.getValues() Get values for the enum. :returns: Array of string. Each value is a name of the enum value, values are assigned in the order they are defined. Example: .. literalinclude:: ../examples/server/server_add_enum.lua :language: lua :linenos: :lines: 20-23 :emphasize-lines: 1 `Full source <../_static/server/server_add_enum.lua>`__ Structure --------- Structure is a complex data type. It is a collection of fields. Structure types describes how to encode and decode the structure. Fileds are encoded in the order they are defined. .. function:: structure.setFields(fields) Set fields for the structure. :fields: Array of tables with description of fields. Each field is a table with following fields: * Name * DataType * ValueRank * ArrayDimensions * Description :returns: nil Example: .. literalinclude:: ../examples/server/server_add_structure.lua :language: lua :linenos: :lines: 21-44 :emphasize-lines: 24 `Full source <../_static/server/server_add_structure.lua>`__ .. function:: structure.getFields() Get fields for the structure. :returns: Array of fields. Each field is a table with following fields: * Name * DataType * ValueRank * ArrayDimensions * Description Example: .. literalinclude:: ../examples/server/server_add_structure.lua :language: lua :linenos: :lines: 16-19 :emphasize-lines: 1 `Full source <../_static/server/server_add_structure.lua>`__ .. function:: structure.getField(fieldName) Get field for the structure. :fieldName: Name of the field. :returns: Field. Example: .. literalinclude:: ../examples/server/server_add_structure.lua :language: lua :linenos: :lines: 46-47 :emphasize-lines: 1 `Full source <../_static/server/server_add_structure.lua>`__ Method ------ .. function:: method.setInputArguments(inputArguments) Set **input** arguments for the method. :inputArguments: Array with description of input arguments. Each argument is a table with following fields: :returns: nil Example: .. literalinclude:: ../examples/server/server_add_method.lua :language: lua :linenos: :lines: 33-37 :emphasize-lines: 5 `Full source <../_static/server/server_add_method.lua>`__ .. function:: method.setOutputArguments(outputArguments) Set **output** arguments for the method. :outputArguments: Array with description of output arguments. Each argument is a table with following fields: :returns: nil Example: .. literalinclude:: ../examples/server/server_add_method.lua :language: lua :linenos: :lines: 39-43 :emphasize-lines: 5 `Full source <../_static/server/server_add_method.lua>`__ Reference Type -------------- Reference type represents a kind of a reference between nodes. .. function:: referenceType.path(names) Resolve node by path relative to current reference type.