Exemple #1
0
    def _onr_element_name(self, data):
        #field_num = 6
        #datai = data[4 * (field_num - 1) : 4 * (field_num + 1)]
        #assert len(datai) == 8, len(datai)
        #print(4 * (field_num - 1), 4 * (field_num + 1))
        #element_name, = self.struct_8s.unpack(data[24:32])  # changed on 11/30/2015; was this for a long time...

        #self.show_data(data[:28])
        if self.size == 4:
            element_name, = self.struct_8s.unpack(data[20:28])
        else:
            element_name, = self.struct_16s.unpack(data[40:56])
            element_name = reshape_bytes_block(element_name)

        #print("element_name = %s" % (element_name))
        try:
            element_name = element_name.decode('utf-8').strip()  # element name
        except UnicodeDecodeError:
            #self.log.warning("element_name = %s" % str(element_name))
            self.log.warning("element_name - UnicodeDecodeError")
            #self.show_data(data)
            raise
        if element_name.isalnum():
            self.data_code['element_name'] = element_name
        else:
            #print("element_name = %r" % (element_name))
            self.data_code['element_name'] = 'UnicodeDecodeError???'
            self.log.warning('data[20:28]=%r instead of data[24:32]' %
                             data[20:28])
Exemple #2
0
    def _read_gmcurv(self, data, n):
        """
        Word Name Type Description
        1 CURVID       I Curve identification number
        2 GROUP(2) CHAR4 Group of curves/surfaces to which this curve belongs
        4 CIDIN        I Coordinate system identification number for the geometry
        5 CIDBC        I Coordinate system identification number for the constraints
        6 DATA     CHAR4 Geometry evaluator specific data
        """
        size = self.size
        if size == 4:
            struct_i = self.struct_i
            structi = Struct(b'i 8s ii')
        else:
            struct_i = self.struct_q
            structi = Struct(b'q 16s qq')

        ntotal1 = 20 * self.factor
        ntotal2 = 64 * self.factor
        while n < len(data):
            datab = data[n:n+ntotal1]
            curve_id, group_bytes, cid_in, cid_bc = structi.unpack(datab)
            if size == 8:
                group_bytes = reshape_bytes_block(group_bytes)
            group = group_bytes.decode('latin1').rstrip()
            #print(curve_id, group, cid_in, cid_bc)
            assert group in ['MSCGRP0', 'MSCGRP1', 'MSCGRP2'], f'GMCURV: curve_id={curve_id} group={group!r} cid_in={cid_in} cid_bc={cid_bc}'
            n += ntotal1

            databi_bytes = data[n:n+size]
            n += size
            databi = data[n:n+size]
            datab_int, = struct_i.unpack(databi)
            n += size
            while datab_int != -1:
                databi_bytes += databi
                databi = data[n:n+size]
                datab_int, = struct_i.unpack(databi)
                n += size
            datai = databi_bytes.decode('latin1').rstrip()

            data_split = ['        %s\n' % datai[i:i+ntotal2].strip() for i in range(0, len(datai), ntotal2)]
            self.add_gmcurv(curve_id, group, data_split, cid_in=cid_in, cid_bc=cid_bc)
            #print(datai)

        #ints = np.frombuffer(data[n:], dtype=self.idtype).copy()
        #iminus1 = np.where(ints == -1)[0].tolist()
        #i0 = 0
        #for iminus1i in iminus1:
            #curve_id = ints[i0]
            #cid_in, cid_bc = ints[i0+3:i0+5]
            #s0 = n + 4
            #s1 = s0 + 8
            #group = data[s0:s1].decode('latin1').rstrip()
            #print(curve_id, group, cid_in, cid_bc)
            #assert group in ['MSCGRP1', 'MSCGRP2'], f'GMCURV: curve_id={curve_id} group={group!r} cid_in={cid_in} cid_bc={cid_bc}'

            #s2 = s1 + 8
            #s3 = 12 + iminus1i * 4
            #datai = data[s2:s3].decode('latin1').rstrip()
            #print('datai = %r' % datai)
            #i0 = iminus1i + 1
            ## n = s3 + 4
            #n = 12+(iminus1i + 1)*4
            #print('-----------------')
        #return len(data)
        return n