示例#1
0
    def load(self):
        """ @brief Loads the current design file
            @details The file is defined by self.directory and self.filename
        """
        self.clear()

        path = os.path.join(self.directory, self.filename)

        if path[-4:] == '.cad':
            with open(path, 'r') as f:
                text = f.read()
                if text.split('\n')[0] == '##    Geometry header    ##':
                    koko.PRIMS.reconstruct(eval(text.split('\n')[1]))
                    koko.PRIMS.undo_stack = [koko.PRIMS.reconstructor()]
                    text = '\n'.join(text.split('\n')[3:])
            koko.EDITOR.text = text
            koko.FRAME.status = 'Loaded .cad file'

            self.mode = 'cad/cam'
            self.first_render = True
            self.savepoint(True)

        elif path[-4:] == '.png':
            self.mode = 'cam'
            img = Image.load(path)
            koko.CANVAS.load_image(img)
            koko.GLCANVAS.load_image(img)
            koko.FAB.set_input(img)
            wx.CallAfter(self.snap_bounds)

        elif path[-4:] == '.stl':
            self.mode = 'cam'
            mesh = Mesh.load(path)
            koko.GLCANVAS.load_mesh(mesh)
            wx.CallAfter(self.snap_bounds)

        elif path[-5:] == '.asdf':
            self.render_mode('3D')
            self.mode = 'cam'

            msg = dialogs.display_message('Loading...', 'Loading ASDF.')
            msg.Raise()
            wx.Yield()

            asdf = ASDF.load(path)
            msg.txt.SetLabel('Triangulating')
            wx.Yield()

            mesh = asdf.triangulate()
            mesh.source = Struct(type=ASDF, file=path, depth=0)
            msg.Destroy()

            koko.GLCANVAS.load_mesh(mesh)
            koko.FAB.set_input(asdf)
示例#2
0
文件: app.py 项目: F3R70/kokopelli
    def load(self):
        """ @brief Loads the current design file
            @details The file is defined by self.directory and self.filename
        """
        self.clear()

        path = os.path.join(self.directory, self.filename)

        if path[-4:] == '.cad':
            with open(path, 'r') as f:
                text = f.read()
                if text.split('\n')[0] == '##    Geometry header    ##':
                    koko.PRIMS.reconstruct(eval(text.split('\n')[1]))
                    koko.PRIMS.undo_stack = [koko.PRIMS.reconstructor()]
                    text = '\n'.join(text.split('\n')[3:])
            koko.EDITOR.text = text
            koko.FRAME.status = 'Loaded .cad file'

            self.mode = 'cad'
            self.first_render = True
            self.savepoint(True)

        elif path[-4:] == '.png':
            self.mode = 'png'
            img = Image.load(path)
            koko.CANVAS.load_image(img)
            koko.GLCANVAS.load_image(img)
            koko.FAB.set_input(img)
            wx.CallAfter(self.snap_bounds)

        elif path[-4:] == '.stl':
            self.mode = 'stl'
            mesh = Mesh.load(path)

            koko.FRAME.get_menu('View', '3D').Check(True)
            self.render_mode('3D')

            koko.GLCANVAS.load_mesh(mesh)
            wx.CallAfter(self.snap_bounds)

        elif path[-5:] == '.asdf':
            self.mode = 'asdf'

            koko.FRAME.status = 'Loading ASDF'
            wx.Yield()

            asdf = ASDF.load(path)
            koko.FRAME.status = 'Triangulating'
            wx.Yield()

            mesh = asdf.triangulate()
            mesh.source = Struct(type=ASDF, file=path, depth=0)
            koko.FRAME.status = ''

            koko.FRAME.get_menu('View', '3D').Check(True)
            self.render_mode('3D')

            koko.GLCANVAS.load_mesh(mesh)
            koko.FAB.set_input(asdf)

        elif path[-4:] == '.vol':
            self.mode = 'vol'
            koko.IMPORT.set_target(self.directory, self.filename)
示例#3
0
    def load(self):
        """ @brief Loads the current design file
            @details The file is defined by self.directory and self.filename
        """
        self.clear()

        path = os.path.join(self.directory, self.filename)

        if path[-3:] == '.ko' or path[-4:] == '.cad':
            with open(path, 'r') as f:
                text = f.read()
                if text.split('\n')[0] == '##    Geometry header    ##':
                    koko.PRIMS.reconstruct(eval(text.split('\n')[1]))
                    koko.PRIMS.undo_stack = [koko.PRIMS.reconstructor()]
                    text = '\n'.join(text.split('\n')[3:])
            koko.EDITOR.text = text
            koko.FRAME.status = 'Loaded design file'

            if path[-4:] == '.cad':
                dialogs.warning("""
This file has a '.cad' extension, which was superceded by '.ko'.  It may use deprecated features or syntax.

If it is an example file, the 'kokopelli/examples' folder may include an updated version with a '.ko' extension"""
                                )

            self.mode = 'cad'
            self.first_render = True
            self.savepoint(True)

        elif path[-4:] == '.png':
            self.mode = 'png'
            img = Image.load(path)
            koko.CANVAS.load_image(img)
            koko.GLCANVAS.load_image(img)
            koko.FAB.set_input(img)
            wx.CallAfter(self.snap_bounds)

        elif path[-4:] == '.stl':
            self.mode = 'stl'
            mesh = Mesh.load(path)

            koko.FRAME.get_menu('View', '3D').Check(True)
            self.render_mode('3D')

            koko.GLCANVAS.load_mesh(mesh)
            wx.CallAfter(self.snap_bounds)

        elif path[-5:] == '.asdf':
            self.mode = 'asdf'

            koko.FRAME.status = 'Loading ASDF'
            wx.Yield()

            asdf = ASDF.load(path)
            koko.FRAME.status = 'Triangulating'
            wx.Yield()

            mesh = asdf.triangulate()
            mesh.source = Struct(type=ASDF, file=path, depth=0)
            koko.FRAME.status = ''

            koko.FRAME.get_menu('View', '3D').Check(True)
            self.render_mode('3D')

            koko.GLCANVAS.load_mesh(mesh)
            koko.FAB.set_input(asdf)

        elif path[-4:] == '.vol':
            self.mode = 'vol'
            koko.IMPORT.set_target(self.directory, self.filename)
示例#4
0
    def load(self):
        """ @brief Loads the current design file
            @details The file is defined by self.directory and self.filename
        """
        self.clear()

        path = os.path.join(self.directory, self.filename)

        if path[-4:] == '.cad':
            with open(path, 'r') as f:
                text = f.read()
                if text.split('\n')[0] == '##    Geometry header    ##':
                    koko.PRIMS.reconstruct(eval(text.split('\n')[1]))
                    koko.PRIMS.undo_stack = [koko.PRIMS.reconstructor()]
                    text = '\n'.join(text.split('\n')[3:])
            koko.EDITOR.text = text
            koko.FRAME.status = 'Loaded .cad file'

            self.mode = 'cad'
            self.first_render = True
            self.savepoint(True)

        elif path[-4:] == '.png':
            self.mode = 'png'
            img = Image.load(path)
            koko.CANVAS.load_image(img)
            koko.GLCANVAS.load_image(img)
            koko.FAB.set_input(img)
            wx.CallAfter(self.snap_bounds)

        elif path[-4:] == '.stl':
            self.mode = 'stl'
            mesh = Mesh.load(path)

            koko.FRAME.get_menu('View', '3D').Check(True)
            self.render_mode('3D')

            koko.GLCANVAS.load_mesh(mesh)
            wx.CallAfter(self.snap_bounds)

        elif path[-5:] == '.asdf':
            self.mode = 'asdf'

            koko.FRAME.status = 'Loading ASDF'
            wx.Yield()

            asdf = ASDF.load(path)
            koko.FRAME.status = 'Triangulating'
            wx.Yield()

            mesh = asdf.triangulate()
            mesh.source = Struct(type=ASDF, file=path, depth=0)
            koko.FRAME.status = ''

            koko.FRAME.get_menu('View', '3D').Check(True)
            self.render_mode('3D')

            koko.GLCANVAS.load_mesh(mesh)
            koko.FAB.set_input(asdf)

        elif path[-4:] == '.vol':
            self.mode = 'vol'
            koko.IMPORT.set_target(self.directory, self.filename)
示例#5
0
    def load(self):
        """ @brief Loads the current design file
            @details The file is defined by self.directory and self.filename
        """
        self.clear()

        path = os.path.join(self.directory, self.filename)

        if path[-3:] == '.ko' or path[-4:] == '.cad':
            with open(path, 'r') as f:
                text = f.read()
                if text.split('\n')[0] == '##    Geometry header    ##':
                    koko.PRIMS.reconstruct(eval(text.split('\n')[1]))
                    koko.PRIMS.undo_stack = [koko.PRIMS.reconstructor()]
                    text = '\n'.join(text.split('\n')[3:])
            koko.EDITOR.text = text
            koko.FRAME.status = 'Loaded design file'

            if path[-4:] == '.cad':
                dialogs.warning("""
This file has a '.cad' extension, which was superceded by '.ko'.  It may use deprecated features or syntax.

If it is an example file, the 'kokopelli/examples' folder may include an updated version with a '.ko' extension""")

            self.mode = 'cad'
            self.first_render = True
            self.savepoint(True)

        elif path[-4:] == '.png':
            self.mode = 'png'
            img = Image.load(path)
            koko.CANVAS.load_image(img)
            koko.GLCANVAS.load_image(img)
            koko.FAB.set_input(img)
            wx.CallAfter(self.snap_bounds)

        elif path[-4:] == '.stl':
            self.mode = 'stl'
            mesh = Mesh.load(path)

            koko.FRAME.get_menu('View', '3D').Check(True)
            self.render_mode('3D')

            koko.GLCANVAS.load_mesh(mesh)
            wx.CallAfter(self.snap_bounds)

        elif path[-5:] == '.asdf':
            self.mode = 'asdf'

            koko.FRAME.status = 'Loading ASDF'
            wx.Yield()

            asdf = ASDF.load(path)
            koko.FRAME.status = 'Triangulating'
            wx.Yield()

            mesh = asdf.triangulate()
            mesh.source = Struct(type=ASDF, file=path, depth=0)
            koko.FRAME.status = ''

            koko.FRAME.get_menu('View', '3D').Check(True)
            self.render_mode('3D')

            koko.GLCANVAS.load_mesh(mesh)
            koko.FAB.set_input(asdf)

        elif path[-4:] == '.vol':
            self.mode = 'vol'
            koko.IMPORT.set_target(self.directory, self.filename)