Coverage for tatlin/lib/model/stl/loader.py: 90%

20 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-03-20 05:56 +0000

1# -*- coding: utf-8 -*- 

2# Copyright (C) 2024 Denis Kobozev 

3# 

4# This program is free software; you can redistribute it and/or modify 

5# it under the terms of the GNU General Public License as published by 

6# the Free Software Foundation; either version 2 of the License, or 

7# (at your option) any later version. 

8# 

9# This program is distributed in the hope that it will be useful, 

10# but WITHOUT ANY WARRANTY; without even the implied warranty of 

11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

12# GNU General Public License for more details. 

13# 

14# You should have received a copy of the GNU General Public License 

15# along with this program; if not, write to the Free Software Foundation, 

16# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 

17 

18from tatlin.lib.gl.stlmodel import StlModel 

19from tatlin.lib.ui.stl import StlPanel 

20 

21from ..baseloader import BaseModelLoader, ModelFileError 

22from .parser import StlParseError, StlParser 

23 

24 

25class STLModelLoader(BaseModelLoader): 

26 def load(self, config, scene, progress_dlg): 

27 with open(self.path, "rb") as stlfile: 

28 parser = StlParser(stlfile) 

29 parser.load(stlfile) 

30 try: 

31 progress_dlg.stage("Reading file...") 

32 data = parser.parse(progress_dlg.step) 

33 

34 progress_dlg.stage("Loading model...") 

35 model = StlModel() 

36 model.load_data(data, progress_dlg.step) 

37 

38 scene.add_model(model) 

39 scene.mode_2d = False 

40 

41 return model, StlPanel 

42 except StlParseError as e: 

43 # rethrow as generic file error 

44 raise ModelFileError(f"Parsing error: {e}")