Exemplo n.º 1
0
    def __init__(self):
        Section.__init__(self)

        self.hydraulics = HydraulicsOptions()
        """HydraulicsOptions: Hydraulics options"""

        self.quality = QualityOptions()
        """QualityOptions: Water quality options"""

        self.map = ""
        """str: Name of a file containing coordinates of the network's nodes, not written if not set"""
Exemplo n.º 2
0
class Options(Section):
    """EPANET Options"""

    SECTION_NAME = "[OPTIONS]"

    section_comments = (";; Hydraulics", ";; Water Quality")

    def __init__(self):
        Section.__init__(self)

        self.hydraulics = HydraulicsOptions()
        """HydraulicsOptions: Hydraulics options"""

        self.quality = QualityOptions()
        """QualityOptions: Water quality options"""

        self.map = ""
        """str: Name of a file containing coordinates of the network's nodes, not written if not set"""

    def get_text(self):
        """Contents of this item formatted for writing to file"""
        text_list = [self.SECTION_NAME]
        if self.map:
            text_list.append(" MAP                \t" + self.map)
        if self.hydraulics is not None:
            text_list.append(Options.section_comments[0])
            text_list.append(self.hydraulics.get_text())
        if self.quality is not None:
            text_list.append(Options.section_comments[1])
            text_list.append(self.quality.get_text())
        return '\n'.join(text_list)

    def set_text(self, new_text):
        """Read properties from text.
            Args:
                new_text (str): Text to parse into properties.
        """
        self.__init__()
        # Skip the comments we insert automatically
        for comment in Options.section_comments:
            new_text = new_text.replace(comment + '\n', '')
        self.hydraulics.set_text(new_text)
        self.quality.set_text(new_text)
        for line in new_text.splitlines():
            line_list = line.split()
            if line_list:
                if str(line_list[0]).strip().upper() == "MAP":
                    self.map = ' '.join(line_list[1:])
Exemplo n.º 3
0
 def read(new_text):
     hydraulics_options = HydraulicsOptions()
     for line in new_text.splitlines():
         try:
             line = line.strip()
             if not line.startswith((';', '[')):
                 lower_line = line.lower()
                 if lower_line:
                     for meta_item in hydraulics_options.metadata:
                         key = meta_item.input_name.lower()
                         if len(lower_line) > len(key):
                             if lower_line.startswith(key) and lower_line[
                                     len(key)] in (' ', '\t'):
                                 if meta_item.attribute == "unbalanced_continue":
                                     fields = line.split()
                                     hydraulics_options.unbalanced = Unbalanced[
                                         fields[1].upper()]
                                     if len(fields) > 2:
                                         hydraulics_options.unbalanced_continue = fields[
                                             2]
                                 else:
                                     attr_value = line[len(key) +
                                                       1:].strip()
                                     hydraulics_options.setattr_keep_type(
                                         meta_item.attribute, attr_value)
         except:
             print("HydraulicsOptions skipping input line: " + line)
     return hydraulics_options