コード例 #1
0
def import_file(p, s, w, m, t, j, file_name=''):
    if len(file_name) == 0:
        file_name = QtWidgets.QFileDialog.getOpenFileName(w, \
            'Import INP/UNV file', j.dir, \
            'INP (*.inp);;UNV (*.unv)')[0]

    if file_name is not None and len(file_name):
        w.textEdit.clear()

        # Rename job before tree regeneration
        # A new logger's handler is created here
        j.__init__(p, s, w, m, file_name[:-4] + '.inp')

        w.stop_stdout_readers()

        # Convert UNV to INP
        if file_name.lower().endswith('.unv'):
            j.convert_unv()
            if not os.path.isfile(j.inp):
                logging.error('Can not convert\n' + j.unv)
                return

        # Show model name in window's title
        w.setWindowTitle('CalculiX Advanced Environment - ' + j.name)

        # Generate new KOM without implementations
        m.KOM = model.kom.KOM(p, s)

        # Parse INP and enrich KOM with parsed objects
        logging.info('Loading model\n{}'.format(j.inp))
        lines = file_tools.read_lines(j.inp)
        import_inp(s, lines, m.KOM)  # pass whole INP-file to the parser

        # Add parsed implementations to the tree
        t.generateTreeView(m)

        # Parse mesh
        m.Mesh = model.parsers.mesh.Mesh(INP_file=j.inp)

        # Open a new non-empty model in CGX
        if not s.start_cgx_by_default:
            logging.warning('"Settings -> Start CGX by default" is unchecked.')
            return
        if not len(m.Mesh.nodes):
            logging.warning('Empty mesh, CGX will not start!')
            return

        # gui.cgx.kill(w)
        has_nodes = len(m.Mesh.nodes)
        gui.cgx.open_inp(w, j.inp, has_nodes)
コード例 #2
0
ファイル: mesh.py プロジェクト: yibaohu-outlook/cae
    def __init__(self, INP_file=None, inp_code=None, old=None):
        self.nodes = {}  # all mesh nodes with coordinates
        self.nsets = {}  # node sets
        self.elements = {}  # all mesh elements composition
        self.elsets = {}  # element sets
        self.surfaces = {}  # with corresponding nodes and element faces

        # Mesh being reparsed
        self.old = old
        if not old:
            self.old = self

        # Get lines from INP source
        if INP_file and not inp_code:
            # Open and read whole the .inp-file
            lines = file_tools.read_lines(INP_file)
        elif inp_code and not INP_file:
            # Parse some piece of INP code
            lines = inp_code
        else:
            logging.warning('Nothing to parse!')
            return

        # Call parse methods for everything
        msg_text = 'Mesh parser:'
        for attrName, attrValue in self.__dict__.items():
            if type(attrValue) == dict:
                try:
                    getattr(self, 'parse_' + attrName)(lines)
                    msg_text += '\n{} {}'.format(len(attrValue), attrName)
                    # msg_text += str([v.name for v in attrValue.values()])
                    # for k,v in attrValue.items():
                    #     msg_text += '<br/>\n{0}: {1}'.format(k, v)
                except:
                    msg = 'Can\'t parse {}\n'.format(attrName) \
                        + traceback.format_exc()
                    logging.error(msg)
        logging.info(msg_text)
コード例 #3
0
    h = tests.myHandler(log_file)
    logging.getLogger().addHandler(h)
    logging.getLogger().setLevel(logging.WARNING)

    limit = 3000  # how many files to process
    examples_dir = '../../examples/ccx/test'
    # examples_dir = '../../examples/abaqus/eif'
    counter = 0
    kom_xml = '../config/kom.xml'

    print(log_file, 'IMPORTER (KEYWORDS PARSER) TEST\n\n')
    examples = tests.scan_all_files_in(examples_dir, '.inp', limit)
    for file_name in examples:
        counter += 1
        relpath = os.path.relpath(file_name, start=os.getcwd())
        print(log_file, '\n{} {}'.format(counter, relpath))
        inp_doc = file_tools.read_lines(file_name)

        # Build new clean/empty keyword object model
        k = model.kom.KOM(None, None, kom_xml)

        try:
            # Parse inp_doc end enrich existing KOM
            k = import_inp(None, inp_doc, k)
        except:
            logging.error(traceback.format_exc())

    print(log_file,
          '\nTotal {:.1f} seconds.'.format(time.perf_counter() - start_time))
    clean.cache()
コード例 #4
0
ファイル: importer.py プロジェクト: solerzhuxy/cae
    def import_file(self, file_name):
        if file_name is None and \
            (self.w is None or self.j is None):
            raise SystemExit

        if file_name is None:
            file_name = QtWidgets.QFileDialog.getOpenFileName(self.w, \
                'Import INP/UNV file', self.j.dir, \
                'INP (*.inp);;UNV (*.unv)')[0]

        if file_name is not None and len(file_name):
            self.w.textEdit.clear()

            # Rename job before tree regeneration
            # A new logger's handler is created here
            self.j.__init__(self.p, self.s, self.w,
                self.m, file_name[:-4] + '.inp')

            self.w.stop_stdout_readers()

            # Convert UNV to INP
            if file_name.lower().endswith('.unv'):
                self.j.convert_unv()
                if not os.path.isfile(self.j.inp):
                    logging.error('Can not convert\n' + self.j.unv)
                    return

            # Show model name in window's title
            self.w.setWindowTitle('CalculiX Advanced Environment - ' \
                + self.j.name)

            # Generate new KOM without implementations
            self.m.KOM = model.kom.KOM(self.p, self.s)

            # Get INP code and split it on blocks
            logging.info('Loading model\n{}'.format(self.j.inp))
            inp_doc = file_tools.read_lines(self.j.inp)
            self.split_on_blocks(inp_doc) # fill keyword_blocks

            # Parse INP and enrich KOM with parsed objects
            self.import_inp()

            # Add parsed implementations to the tree
            self.t.generateTreeView(self.m)

            # Parse mesh
            self.m.Mesh = model.parsers.mesh.Mesh(blocks=self.keyword_blocks)

            # Open a new non-empty model in CGX
            if not self.s.start_cgx_by_default:
                msg = '"Settings -> Start CGX by default" is unchecked.'
                logging.warning(msg)
                return
            if not len(self.m.Mesh.nodes):
                msg = 'Empty mesh, CGX will not start!'
                logging.warning(msg)
                return

            # gui.cgx.kill(w)
            has_nodes = len(self.m.Mesh.nodes)
            gui.cgx.open_inp(self.w, self.j.inp, has_nodes)