svghmi/svghmi.py
branchwxPython4
changeset 3405 fdc12f7d27c8
parent 3379 c3d462118d37
parent 3399 95e0b926a8c3
child 3481 563996733dba
equal deleted inserted replaced
3391:0ae5a15efa18 3405:fdc12f7d27c8
   128         for v in hmi_types_instances:
   128         for v in hmi_types_instances:
   129             path = v["IEC_path"].split(".")
   129             path = v["IEC_path"].split(".")
   130             # ignores variables starting with _TMP_
   130             # ignores variables starting with _TMP_
   131             if path[-1].startswith("_TMP_"):
   131             if path[-1].startswith("_TMP_"):
   132                 continue
   132                 continue
       
   133             vartype = v["vartype"]
       
   134             # ignores external variables
       
   135             if vartype == "EXT":
       
   136                 continue
   133             derived = v["derived"]
   137             derived = v["derived"]
   134             kwargs={}
   138             kwargs={}
   135             if derived == "HMI_NODE":
   139             if derived == "HMI_NODE":
   136                 # TODO : make problem if HMI_NODE used in CONFIG or RESOURCE
   140                 # TODO : make problem if HMI_NODE used in CONFIG or RESOURCE
   137                 name = path[-2]
   141                 name = path[-2]
   138                 kwargs['hmiclass'] = path[-1]
   142                 kwargs['hmiclass'] = path[-1]
   139             else:
   143             else:
   140                 name = path[-1]
   144                 name = path[-1]
   141             new_node = HMITreeNode(path, name, derived, v["type"], v["vartype"], v["C_path"], **kwargs)
   145             new_node = HMITreeNode(path, name, derived, v["type"], vartype, v["C_path"], **kwargs)
   142             placement_result = hmi_tree_root.place_node(new_node)
   146             placement_result = hmi_tree_root.place_node(new_node)
   143             if placement_result is not None:
   147             if placement_result is not None:
   144                 cause, problematic_node = placement_result
   148                 cause, problematic_node = placement_result
   145                 if cause == "Non_Unique":
   149                 if cause == "Non_Unique":
   146                     message = _("HMI tree nodes paths are not unique.\nConflicting variable: {} {}").format(
   150                     message = _("HMI tree nodes paths are not unique.\nConflicting variable: {} {}").format(
   147                         ".".join(problematic_node.path),
   151                         ".".join(problematic_node.path),
   148                         ".".join(new_node.path))
   152                         ".".join(new_node.path))
   149 
   153 
   150                     last_FB = None 
   154                     last_FB = None 
   151                     for v in varlist:
   155                     for _v in varlist:
   152                         if v["vartype"] == "FB":
   156                         if _v["vartype"] == "FB":
   153                             last_FB = v 
   157                             last_FB = _v 
   154                         if v["C_path"] == problematic_node:
   158                         if _v["C_path"] == problematic_node:
   155                             break
   159                             break
   156                     if last_FB is not None:
   160                     if last_FB is not None:
   157                         failing_parent = last_FB["type"]
   161                         failing_parent = last_FB["type"]
   158                         message += "\n"
   162                         message += "\n"
   159                         message += _("Solution: Add HMI_NODE at beginning of {}").format(failing_parent)
   163                         message += _("Solution: Add HMI_NODE at beginning of {}").format(failing_parent)
   185                     "#define heartbeat_index "+str(hmi_tree_hearbeat_index)
   189                     "#define heartbeat_index "+str(hmi_tree_hearbeat_index)
   186                 ]
   190                 ]
   187             if hasattr(node, "iectype"):
   191             if hasattr(node, "iectype"):
   188                 sz = DebugTypesSize.get(node.iectype, 0)
   192                 sz = DebugTypesSize.get(node.iectype, 0)
   189                 variable_decl_array += [
   193                 variable_decl_array += [
   190                     "{&(" + node.cpath + "), " + node.iectype + {
   194                     "HMITREE_ITEM_INITIALIZER(" + node.cpath + ", " + node.iectype + {
   191                         "EXT": "_P_ENUM",
   195                         "EXT": "_P_ENUM",
   192                         "IN":  "_P_ENUM",
   196                         "IN":  "_P_ENUM",
   193                         "MEM": "_O_ENUM",
   197                         "MEM": "_O_ENUM",
   194                         "OUT": "_O_ENUM",
   198                         "OUT": "_O_ENUM",
   195                         "VAR": "_ENUM"
   199                         "VAR": "_ENUM"
   196                     }[node.vartype] + ", " +
   200                     }[node.vartype] + ", " +
   197                     str(buf_index) + ", 0, }"]
   201                     str(buf_index) + ")"]
   198                 buf_index += sz
   202                 buf_index += sz
   199                 item_count += 1
   203                 item_count += 1
   200                 if len(node.path) == 1:
   204                 if len(node.path) == 1:
   201                     extern_variables_declarations += [
   205                     extern_variables_declarations += [
   202                         "extern __IEC_" + node.iectype + "_" +
   206                         "extern __IEC_" + node.iectype + "_" +
   570                 self.ProgressEnd("svg")
   574                 self.ProgressEnd("svg")
   571 
   575 
   572                 # call xslt transform on Inkscape's SVG to generate XHTML
   576                 # call xslt transform on Inkscape's SVG to generate XHTML
   573                 try: 
   577                 try: 
   574                     self.ProgressStart("xslt", "XSLT transform")
   578                     self.ProgressStart("xslt", "XSLT transform")
   575                     result = transform.transform(svgdom)  # , profile_run=True)
   579                     result = transform.transform(
       
   580                         svgdom, instance_name=location_str)  # , profile_run=True)
   576                     self.ProgressEnd("xslt")
   581                     self.ProgressEnd("xslt")
   577                 except XSLTApplyError as e:
   582                 except XSLTApplyError as e:
   578                     self.FatalError("SVGHMI " + svghmi_options["name"] + ": " + e.message)
   583                     self.FatalError("SVGHMI " + svghmi_options["name"] + ": " + e.message)
   579                 finally:
   584                 finally:
   580                     for entry in transform.get_error_log():
   585                     for entry in transform.get_error_log():
   824                         _("Font to remove %s is not in %s\n") % (fontfile,fontdir))
   829                         _("Font to remove %s is not in %s\n") % (fontfile,fontdir))
   825             else:
   830             else:
   826                 self.GetCTRoot().logger.write_error(
   831                 self.GetCTRoot().logger.write_error(
   827                     _("Font file does not exist: %s\n") % fontfile)
   832                     _("Font file does not exist: %s\n") % fontfile)
   828         
   833         
       
   834     def CTNGlobalInstances(self):
       
   835         location_str = "_".join(map(str, self.GetCurrentLocation()))
       
   836         return [("CURRENT_PAGE_"+location_str, "HMI_STRING", "")]
       
   837 
   829     ## In case one day we support more than one heartbeat
   838     ## In case one day we support more than one heartbeat
   830     # def CTNGlobalInstances(self):
       
   831     #     view_name = self.BaseParams.getName()
   839     #     view_name = self.BaseParams.getName()
   832     #     return [(view_name + "_HEARTBEAT", "HMI_INT", "")]
   840     #     return [(view_name + "_HEARTBEAT", "HMI_INT", "")]
   833 
   841 
   834     def GetIconName(self):
   842     def GetIconName(self):
   835         return "SVGHMI"
   843         return "SVGHMI"