Beispiel #1
0
def flow_and_framework_tofile(filename, comflow, fmt="ascii"):
    'writes flow.CommandFlow object to xml file'
    cb = comflow.interface.ask_for_callback()
    cb1 = cb.subcallback(0, 3)

    cb1.pycall("Writing command flow", "", 0, 0)
    # write everithing except geometry data data
    r = _root_xml()
    write_command_flow(comflow, r)
    st = ET.SubElement(r.find('FLOW'), "STATE")
    write_framework(comflow.receiver, st)
    cb1.pycall("Writing command flow", "", 0.8, 0)
    writexml(r, filename, False)
    cb1.pycall("Writing command flow", "Done", 1, 1)

    # add geometry data and write to file
    doc, root = 0, 0
    try:
        cb2 = cb.subcallback(1, 3)
        doc, root = hmxml.open_doc(filename)
        [nd] = hmxml.query(root, "FLOW/STATE", required="=1")
        natex.export_all(doc, nd, comflow.receiver, fmt, cb2)
    except:
        raise
    finally:
        cb3 = cb.subcallback(2, 3)
        cb3.pycall("Write to file", "", 0.0, 0)
        hmxml.doc_to_file(doc, filename)
        hmxml.close_doc(doc, [root, nd])
        cb3.pycall("Write to file", "Done", 1, 1)
Beispiel #2
0
def export_all_tofile(fname, framework, fmt, cb=None):
    doc, root = 0, 0
    try:
        doc, root = hmxml.new_doc()
        export_all(doc, root, framework, fmt, cb)
        hmxml.doc_to_file(doc, fname)
    except:
        raise
    finally:
        hmxml.close_doc(doc, [root])
Beispiel #3
0
 def _init_read(self):
     doc, root = 0, 0
     try:
         cb = self.ask_for_callback()
         doc, root = hmxml.open_doc(self.get_option('filename'))
         self.__c2, self.__g2, self.__s3, self.__g3,\
             self._c2names, self._g2names, self._s3names, self._g3names =\
             natim.all_geom(doc, root, cb)
     except Exception:
         raise
     finally:
         hmxml.close_doc(doc, [root])
Beispiel #4
0
def flow_and_framework_fromfile(filename, flow, cb=None):
    doc, root, statenodes = 0, 0, []
    try:
        cb.pycall("Loading commands", "Reading xml", 0, 0)
        doc, root = hmxml.open_doc(filename)
        pstring = hmxml.purged_string(doc)
        pyside_root = ET.fromstring(pstring)
        pyside_flownode = pyside_root.findall('FLOW')
        if len(pyside_flownode) == 0:
            raise Exception('No proper data in xml file')
        else:
            pyside_flownode = pyside_flownode[0]

        # load commands
        cb.pycall("Loading commands", "Parsing", 0.5, 0)
        _load_command_flow(flow, pyside_flownode)
        cb.pycall("Loading commands", "Done", 1, 1)

        # state
        statenodes = hmxml.query(root, "FLOW/STATE")
        pyside_statenode = pyside_flownode.findall('STATE')
        if len(statenodes) > 0:
            statenode = statenodes[0]
            pyside_statenode = pyside_statenode[0]
        else:
            statenode = None
            pyside_statenode = None

        data = framework.Framework()
        if statenode is not None:
            # load boundary types
            _load_btypes(data, pyside_statenode)

            # load data
            c, g, s3, g3, cn, gn, s3n, g3n =\
                native_import.all_geom(doc, statenode, cb)
            for k, v in zip(cn, c):
                data.append_contour2(Contour2(v), k)
            for k, v in zip(gn, g):
                data.append_grid2(Grid2(v), k)
            for k, v in zip(s3n, s3):
                data.append_surface3(Surface3(v), k)
            for k, v in zip(g3n, g3):
                data.append_grid3(Grid3(v), k)
        flow.set_receiver(data)
    except:
        raise
    finally:
        hmxml.close_doc(doc, [root] + statenodes)
Beispiel #5
0
def cont2_tofile(fname, conts, names, fmt, cb=None):
    if cb is None:
        cb = SilentCallbackCancel2()
    doc, root = 0, 0
    try:
        doc, root = hmxml.new_doc()
        n = min(len(conts), len(names))
        for i in range(n):
            cb1 = cb.subcallback(i, n)
            cont2(doc, root, conts[i], names[i], fmt, cb1)
        hmxml.doc_to_file(doc, fname)
    except:
        raise
    finally:
        hmxml.close_doc(doc, [root])
Beispiel #6
0
 def _read_grid3(self):
     doc, root = 0, 0
     try:
         cb = self.ask_for_callback()
         doc, root = hmxml.open_doc(self.get_option('filename'))
         if self.get_option('all'):
             g3, self._g3names = natim.all_grids3(doc, root, cb)
         else:
             g3, self._g3names = natim.grid3(doc, root,
                                             self.get_option('gridname'),
                                             cb)
             g3, self._g3names = [g3], [self._g3names]
         return g3
     except Exception:
         raise
     finally:
         hmxml.close_doc(doc, [root])
Beispiel #7
0
 def _read_surf3(self):
     doc, root = 0, 0
     try:
         cb = self.ask_for_callback()
         doc, root = hmxml.open_doc(self.get_option('filename'))
         if self.get_option('all'):
             s3, self._s3names = natim.all_surfaces3(doc, root, cb)
         else:
             s3, self._s3names = natim.surface3(doc, root,
                                                self.get_option('srfname'),
                                                cb)
             s3, self._s3names = [s3], [self._s3names]
         return s3
     except Exception:
         raise
     finally:
         hmxml.close_doc(doc, [root])
Beispiel #8
0
 def _read_cont2(self):
     doc, root = 0, 0
     try:
         cb = self.ask_for_callback()
         doc, root = hmxml.open_doc(self.get_option('filename'))
         if self.get_option('all'):
             c2, self._c2names = natim.all_contours2(doc, root, cb)
         else:
             c2, self._c2names = natim.contour2(doc, root,
                                                self.get_option('contname'),
                                                cb)
             c2, self._c2names = [c2], [self._c2names]
         return c2
     except Exception:
         raise
     finally:
         hmxml.close_doc(doc, [root])