예제 #1
0
    def parse(self, loader, chunk=None):
        chunk = FIGModelObject.parse(self, loader, chunk)
        s = figlib.unpack(self._frm32, chunk)
        data = dict(zip(self._names32, s))
        self.__dict__.update(data)

        if self.forward_arrow:
            fa = FIGFArrow()
            fa.parse(loader)
            self.childs.append(fa)
        if self.backward_arrow:
            fb = FIGBArrow()
            fb.parse(loader)
            self.childs.append(fb)
        if self.sub_type == fig_const.T_PIC_BOX:
            picture = FIGPicture()
            picture.parse(loader)
            self.childs.append(picture)

        self.points = []
        while len(self.points) < self.npoints:
            line = loader.readln()
            if line is None:
                raise Exception('Line is corrupted')
            data = line.split()
            items = ([int(x), int(y)] for x, y in figlib.list_chunks(data, 2))
            self.points.extend(items)
예제 #2
0
    def parse(self, loader, chunk=None):
        chunk = FIGModelObject.parse(self, loader, chunk)
        s = figlib.unpack(self._frm32, chunk)
        data = dict(zip(self._names32, s))
        self.__dict__.update(data)
        self.sub_type = figlib.spline_sub_type(self.sub_type, loader.version)

        if self.forward_arrow:
            fa = FIGFArrow()
            fa.parse(loader)
            self.childs.append(fa)
        if self.backward_arrow:
            fb = FIGBArrow()
            fb.parse(loader)
            self.childs.append(fb)

        self.points = []
        while len(self.points) < self.npoints:
            line = loader.readln()
            if line is None:
                raise Exception('Line is corrupted')
            data = line.split()
            items = ([int(x), int(y)] for x, y in figlib.list_chunks(data, 2))
            self.points.extend(items)

        if self.sub_type in fig_const.T_INTERPOLATED:
            self.control_points = []
            ncontrols = self.npoints * 2
            while len(self.control_points) < ncontrols:
                line = loader.readln()
                if line is None:
                    raise Exception('Line is corrupted')
                data = line.split()
                items = ([float(x), float(y)]
                         for x, y in figlib.list_chunks(data, 2))
                self.control_points.extend(items)
        elif self.sub_type in fig_const.T_XSPLINE:
            self.control_points = []
            while len(self.control_points) < self.npoints:
                line = loader.readln()
                if line is None:
                    raise Exception('Line is corrupted')
                items = map(float, line.split())
                self.control_points.extend(items)
예제 #3
0
 def save(self, saver):
     FIGModelObject.save(self, saver)
     data = [getattr(self, name) for name in self._names32]
     line = figlib.pack(data, self._frm32)
     saver.write('%s\n' % line)
     for item in self.childs:
         item.save(saver)
     for chunk in figlib.list_chunks(self.points, 6):
         flat_list = [str(int(item)) for items in chunk for item in items]
         line = ' '.join(flat_list)
         saver.write('\t %s\n' % line)
예제 #4
0
    def save(self, saver):
        FIGModelObject.save(self, saver)
        data = [getattr(self, name) for name in self._names32]
        line = figlib.pack(data, self._frm32)
        saver.write('%s\n' % line)
        for item in self.childs:
            item.save(saver)

        for chunk in figlib.list_chunks(self.points, 6):
            flat_list = [str(int(item)) for items in chunk for item in items]
            line = ' '.join(flat_list)
            saver.write('\t %s\n' % line)
        if self.sub_type in fig_const.T_INTERPOLATED:
            for chunk in figlib.list_chunks(self.control_points, 4):
                flat_list = ['{:1.2f} {:1.2f}'.format(*item) for item in chunk]
                line = ' '.join(flat_list)
                saver.write('\t %s\n' % line)
        elif self.sub_type in fig_const.T_XSPLINE:
            for chunk in figlib.list_chunks(self.control_points, 8):
                flat_list = ['%1.3f' % item for item in chunk]
                line = ' '.join(flat_list)
                saver.write('\t %s\n' % line)