Small updates on pinkified theme for some object types, background gradient and other...
[blender-addons-contrib.git] / io_scene_fpx / fpx_ui.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20
21 ###############################################################################
22 #234567890123456789012345678901234567890123456789012345678901234567890123456789
23 #--------1---------2---------3---------4---------5---------6---------7---------
24
25
26 # ##### BEGIN COPYRIGHT BLOCK #####
27 #
28 # initial script copyright (c)2013 Alexander Nussbaumer
29 #
30 # ##### END COPYRIGHT BLOCK #####
31
32
33 #import python stuff
34
35
36 # import io_scene_fpx stuff
37 from io_scene_fpx.fpx_strings import (
38         fpx_str,
39         )
40 #from io_scene_fpx.fpx_spec import ()
41 from io_scene_fpx.fpx_utils import (
42         FpxUtilities,
43         )
44
45
46 #import blender stuff
47 from bpy.utils import (
48         register_class,
49         unregister_class,
50         )
51 from bpy_extras.io_utils import (
52         ImportHelper,
53         )
54 from bpy.props import (
55         BoolProperty,
56         CollectionProperty,
57         EnumProperty,
58         FloatProperty,
59         FloatVectorProperty,
60         IntProperty,
61         StringProperty,
62         PointerProperty,
63         )
64 from bpy.types import (
65         Operator,
66         PropertyGroup,
67         Panel,
68         Object,
69         UIList,
70         )
71 from bpy.app import (
72         debug,
73         )
74
75
76 from addon_utils import (
77         check,
78         )
79
80
81 class FpxUI:
82     VERBOSE_MODE_NONE = 'NONE'
83     VERBOSE_MODE_NORMAL = 'NORMAL'
84     VERBOSE_MODE_MAXIMAL = 'MAXIMAL'
85
86     VERBOSE_NONE = {}
87     VERBOSE_NORMAL = { VERBOSE_MODE_NORMAL, VERBOSE_MODE_MAXIMAL, }
88     VERBOSE_MAXIMAL = { VERBOSE_MODE_MAXIMAL, }
89
90     DEFAULT_VERBOSE = VERBOSE_MODE_NONE
91
92     ###########################################################################
93     PROP_DEFAULT_RESOLUTION_WIRE_BEVEL = 8
94     PROP_DEFAULT_RESOLUTION_WIRE = 8
95     PROP_DEFAULT_RESOLUTION_RUBBER_BEVEL = 8
96     PROP_DEFAULT_RESOLUTION_RUBBER = 8
97     PROP_DEFAULT_RESOLUTION_SHAPE = 8
98     PROP_DEFAULT_CONVERT_TO_MESH = False
99     PROP_DEFAULT_USE_HERMITE_HANDLE = True
100
101     ###########################################################################
102     ICON_OPTIONS = 'LAMP'
103     ICON_EXTERNAL_DATA = 'EXTERNAL_DATA'
104     ICON_ERROR = 'ERROR'
105     ICON_MODEL = "OBJECT_DATA"
106     ICON_TABLE = "IMPORT"
107
108     ###########################################################################
109     PROP_DEFAULT_VERBOSE = DEFAULT_VERBOSE
110
111     PROP_DEFAULT_SCENE = False
112     PROP_DEFAULT_ALL_MODELS = False
113     PROP_DEFAULT_MODEL_ADJUST_FPM = False
114     PROP_DEFAULT_MODEL_ADJUST_FPL = True
115     PROP_DEFAULT_MODEL_ADJUST_FPT = True
116     PROP_DEFAULT_NAME_EXTRA = None
117
118     PROP_DEFAULT_LIBRARIES_PATH = "C:\\Games\\Future Pinball\\Libraries"
119     PROP_DEFAULT_DMDFONTS_PATH = "C:\\Games\\Future Pinball\\DmdFonts"
120     PROP_DEFAULT_TABLES_PATH = "C:\\Games\\Future Pinball\\Tables"
121
122     USE_MODEL_FILTER_SECONDARY = 'SECONDARY'
123     USE_MODEL_FILTER_REFLECTION = 'REFLECTION'
124     USE_MODEL_FILTER_MASK = 'MASK'
125     USE_MODEL_FILTER_COLLISION = 'COLLISION'
126     #PROP_DEFAULT_USE_MODEL_FILTER = { USE_MODEL_FILTER_SECONDARY, USE_MODEL_FILTER_REFLECTION, USE_MODEL_FILTER_MASK, USE_MODEL_FILTER_COLLISION, }
127     #PROP_DEFAULT_USE_MODEL_FILTER = { USE_MODEL_FILTER_MASK, }
128     PROP_DEFAULT_USE_MODEL_FILTER = set()
129
130     USE_LIBRARY_FILTER_DMDFONT = 'DMDFONT'
131     USE_LIBRARY_FILTER_GRAPHIC = 'GRAPHIC'
132     USE_LIBRARY_FILTER_MODEL = 'MODEL'
133     USE_LIBRARY_FILTER_MUSIC = 'MUSIC'
134     USE_LIBRARY_FILTER_SCRIPT = 'SCRIPT'
135     USE_LIBRARY_FILTER_SOUND = 'SOUND'
136     #PROP_DEFAULT_USE_LIBRARY_FILTER = { USE_LIBRARY_FILTER_DMDFONT, USE_LIBRARY_FILTER_GRAPHIC, USE_LIBRARY_FILTER_MODEL, USE_LIBRARY_FILTER_MUSIC, USE_LIBRARY_FILTER_SCRIPT, USE_LIBRARY_FILTER_SOUND, }
137     #PROP_DEFAULT_USE_LIBRARY_FILTER = { USE_LIBRARY_FILTER_GRAPHIC, USE_LIBRARY_FILTER_MODEL, }
138     PROP_DEFAULT_USE_LIBRARY_FILTER = { USE_LIBRARY_FILTER_MODEL, }
139
140     PROP_DEFAULT_ALL_LIBRARIES = False
141
142     PROP_DEFAULT_KEEP_TEMP = False
143
144 def NotImplemented(layout):
145     box = layout.box()
146     box.label(fpx_str['LABEL_NAME_NOT_IMPLEMENTED'], icon='ERROR')
147     flow = box.column_flow()
148     flow.label(fpx_str['LABEL_NAME_NOT_IMPLEMENTED_1'])
149     flow.label(fpx_str['LABEL_NAME_NOT_IMPLEMENTED_2'])
150
151 ###############################################################################
152 class FptEmptyItemProperties(PropertyGroup):
153     prop = StringProperty(
154             default="",
155             #options={'HIDDEN', },
156             )
157     model = StringProperty(
158             default="",
159             #options={'HIDDEN', },
160             )
161
162 class FptEmptyProperties(PropertyGroup):
163     name = StringProperty(
164             name=fpx_str['PROP_NAME_EMPTY_PROP_NAME'],
165             description=fpx_str['PROP_DESC_EMPTY_PROP_NAME'],
166             default="",
167             #options={'HIDDEN', },
168             )
169
170     id = StringProperty(
171             name=fpx_str['PROP_NAME_EMPTY_PROP_ID'],
172             description=fpx_str['PROP_DESC_EMPTY_PROP_ID'],
173             default="",
174             #options={'HIDDEN', },
175             )
176
177     models = CollectionProperty(
178             type=FptEmptyItemProperties,
179             #options={'HIDDEN', },
180             )
181
182     selected_model_index = IntProperty(
183             default=-1,
184             min=-1,
185             options={'HIDDEN', 'SKIP_SAVE', },
186             )
187
188     def add_model(self, prop, model):
189         selected_model_index = len(self.models)
190         item = self.models.add()
191         item.prop = prop
192         item.model = model
193
194
195 class FptEmptyUILise(UIList):
196     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
197         if self.layout_type in {'DEFAULT', 'COMPACT', }:
198             layout.label(text=item.model, icon_value=icon)
199         elif self.layout_type in {'GRID', }:
200             layout.alignment = 'CENTER'
201             layout.label(text="", icon_value=icon)
202
203 class FptEmptyPanel(Panel):
204     bl_label = fpx_str['LABEL_EMPTY_PANEL']
205     bl_space_type = 'PROPERTIES'
206     bl_region_type = 'WINDOW'
207     bl_context = 'data'
208
209     @classmethod
210     def poll(cls, blender_context):
211         return (blender_context
212                 and blender_context.object.type in {'EMPTY', }
213                 and blender_context.object.fpt is not None
214                 and blender_context.object.fpt.name
215                 )
216
217     def draw_header(self, blender_context):
218         layout = self.layout
219         layout.label(icon='PLUGIN')
220
221     def draw(self, blender_context):
222         import bpy
223         layout = self.layout
224         custom_data = blender_context.object.fpt
225
226         col = layout.column()
227         col.prop(custom_data, 'name', icon='SCENE_DATA', text="")
228         col.prop(custom_data, 'id', icon='OBJECT_DATA', text="")
229         col.template_list(
230                 listtype_name='FptEmptyUILise',
231                 dataptr=custom_data,
232                 propname='models',
233                 active_dataptr=custom_data,
234                 active_propname='selected_model_index',
235                 rows=2,
236                 type='DEFAULT',
237                 )
238         layout.enabled = False
239
240
241
242 ###############################################################################
243 class FpmImportOperator(Operator, ImportHelper):
244     """ Load a Future Pinball Model FPM File """
245     bl_idname = 'import_scene.fpm'
246     bl_label = fpx_str['BL_LABEL_IMPORTER_FPM']
247     bl_description = fpx_str['BL_DESCRIPTION_IMPORTER_FPM']
248     bl_options = {'PRESET', }
249     bl_space_type = 'PROPERTIES'
250     bl_region_type = 'WINDOW'
251
252     filepath = StringProperty(
253             subtype='FILE_PATH',
254             options={'HIDDEN', }
255             )
256
257
258     verbose = EnumProperty(
259             name=fpx_str['PROP_NAME_VERBOSE'],
260             description=fpx_str['PROP_DESC_VERBOSE'],
261             items=( (FpxUI.VERBOSE_MODE_NONE,
262                             fpx_str['ENUM_VERBOSE_NONE_1'],
263                             fpx_str['ENUM_VERBOSE_NONE_2'],
264                             ),
265                     (FpxUI.VERBOSE_MODE_NORMAL,
266                             fpx_str['ENUM_VERBOSE_NORMAL_1'],
267                             fpx_str['ENUM_VERBOSE_NORMAL_2'],
268                             ),
269                     (FpxUI.VERBOSE_MODE_MAXIMAL,
270                             fpx_str['ENUM_VERBOSE_MAXIMALIMAL_1'],
271                             fpx_str['ENUM_VERBOSE_MAXIMALIMAL_2'],
272                             ),
273                     ),
274             default=FpxUI.PROP_DEFAULT_VERBOSE,
275             )
276
277     keep_temp = BoolProperty(
278             name=fpx_str['PROP_NAME_KEEP_TEMP'],
279             description=fpx_str['PROP_DESC_KEEP_TEMP'],
280             default=FpxUI.PROP_DEFAULT_KEEP_TEMP,
281             )
282
283
284     use_all_models_of_folder = BoolProperty(
285             name=fpx_str['PROP_NAME_ALL_MODELS'],
286             description=fpx_str['PROP_DESC_ALL_MODELS'],
287             default=FpxUI.PROP_DEFAULT_ALL_MODELS,
288             )
289
290     use_scene_per_model = BoolProperty(
291             name=fpx_str['PROP_NAME_SCENE'],
292             description=fpx_str['PROP_DESC_SCENE'],
293             default=FpxUI.PROP_DEFAULT_SCENE,
294             )
295
296     name_extra = StringProperty(
297             #options={'HIDDEN', },
298             )
299
300
301     use_model_filter = EnumProperty(
302             name=fpx_str['PROP_NAME_USE_MODEL_FILTER'],
303             description=fpx_str['PROP_DESC_USE_MODEL_FILTER'],
304             items=(
305                     (FpxUI.USE_MODEL_FILTER_SECONDARY,
306                             fpx_str['PROP_NAME_MODEL_SECONDARY'],
307                             fpx_str['PROP_DESC_MODEL_SECONDARY'],
308                             'MESH_CUBE',
309                             1,
310                             ),
311                     (FpxUI.USE_MODEL_FILTER_REFLECTION,
312                             fpx_str['PROP_NAME_MODEL_REFLECTION'],
313                             fpx_str['PROP_DESC_MODEL_REFLECTION'],
314                             'MOD_MIRROR',
315                             2,
316                             ),
317                     (FpxUI.USE_MODEL_FILTER_MASK,
318                             fpx_str['PROP_NAME_MODEL_MASK'],
319                             fpx_str['PROP_DESC_MODEL_MASK'],
320                             'MOD_MASK',
321                             4,
322                             ),
323                     (FpxUI.USE_MODEL_FILTER_COLLISION,
324                             fpx_str['PROP_NAME_MODEL_COLLISION'],
325                             fpx_str['PROP_DESC_MODEL_COLLISION'],
326                             'MOD_PHYSICS',
327                             8,
328                             ),
329                     ),
330             default=FpxUI.PROP_DEFAULT_USE_MODEL_FILTER,
331             options={'ENUM_FLAG', },
332             )
333
334     use_model_adjustment = BoolProperty(
335             name=fpx_str['PROP_NAME_MODEL_ADJUST'],
336             description=fpx_str['PROP_DESC_MODEL_ADJUST'],
337             default=FpxUI.PROP_DEFAULT_MODEL_ADJUST_FPM,
338             )
339
340
341     filename_ext = fpx_str['FILE_EXT_FPM']
342
343     filter_glob = StringProperty(
344             default=fpx_str['FILE_FILTER_FPM'],
345             options={'HIDDEN', }
346             )
347
348     # check add-on dependency
349     @classmethod
350     def poll(cls, blender_context):
351         loaded_default, loaded_state = check("io_scene_ms3d")
352         return loaded_state
353
354     # draw the option panel
355     def draw(self, blender_context):
356         layout = self.layout
357
358         box = layout.box()
359         box.label(fpx_str['LABEL_NAME_OPTIONS'], icon=FpxUI.ICON_OPTIONS)
360         flow = box.column_flow()
361         flow.prop(self, 'verbose', icon='SPEAKER')
362         flow = box.column_flow()
363         flow.prop(self, 'keep_temp', icon='GHOST')
364         flow.prop(self, 'use_all_models_of_folder', icon='FILE_FOLDER')
365         flow.prop(self, 'use_scene_per_model', icon='SCENE_DATA')
366         flow.prop(self, 'name_extra', icon='TEXT', text="")
367
368         FpmImportOperator.draw_model_options(self, layout)
369
370     # entrypoint for FPM -> blender
371     def execute(self, blender_context):
372         """ start executing """
373
374         FpxUtilities.set_scene_to_default(blender_context.scene)
375
376         from io_scene_fpx.fpx_import import (FpmImporter, )
377         FpmImporter(
378                 report=self.report,
379                 verbose=self.verbose,
380                 keep_temp=self.keep_temp,
381                 use_all_models_of_folder=self.use_all_models_of_folder,
382                 use_scene_per_model=self.use_scene_per_model,
383                 name_extra=self.name_extra,
384                 use_model_filter=self.use_model_filter,
385                 use_model_adjustment=self.use_model_adjustment,
386                 ).read(
387                         blender_context,
388                         self.filepath,
389                         )
390
391         FpxUtilities.set_scene_to_metric(blender_context)
392
393         for scene in blender_context.blend_data.scenes:
394             scene.layers = (True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False)
395             scene.update()
396
397         return {"FINISHED"}
398
399     def invoke(self, blender_context, event):
400         blender_context.window_manager.fileselect_add(self)
401         return {'RUNNING_MODAL', }
402
403     @staticmethod
404     def menu_func(cls, blender_context):
405         cls.layout.operator(
406                 FpmImportOperator.bl_idname,
407                 text=fpx_str['TEXT_OPERATOR_FPM'],
408                 )
409
410     @staticmethod
411     def draw_model_options(cls, layout):
412         box = layout.box()
413         box.label(fpx_str['LABEL_NAME_MODEL_OPTIONS'], icon=FpxUI.ICON_MODEL)
414         if FpxUI.USE_MODEL_FILTER_COLLISION in cls.use_model_filter:
415             NotImplemented(box)
416         flow = box.column_flow()
417         flow.prop(cls, 'use_model_filter', icon='FILTER')
418         flow = box.column_flow()
419         flow.prop(cls, 'use_model_adjustment', icon='MODIFIER')
420
421 ###############################################################################
422 class FplImportOperator(Operator, ImportHelper):
423     """ Load a Future Pinball Library FPL File """
424     bl_idname = 'import_scene.fpl'
425     bl_label = fpx_str['BL_LABEL_IMPORTER_FPL']
426     bl_description = fpx_str['BL_DESCRIPTION_IMPORTER_FPL']
427     bl_options = {'PRESET', }
428     bl_space_type = 'PROPERTIES'
429     bl_region_type = 'WINDOW'
430
431     filepath = StringProperty(
432             subtype='FILE_PATH',
433             options={'HIDDEN', }
434             )
435
436
437     verbose = EnumProperty(
438             name=fpx_str['PROP_NAME_VERBOSE'],
439             description=fpx_str['PROP_DESC_VERBOSE'],
440             items=( (FpxUI.VERBOSE_MODE_NONE,
441                             fpx_str['ENUM_VERBOSE_NONE_1'],
442                             fpx_str['ENUM_VERBOSE_NONE_2'],
443                             ),
444                     (FpxUI.VERBOSE_MODE_NORMAL,
445                             fpx_str['ENUM_VERBOSE_NORMAL_1'],
446                             fpx_str['ENUM_VERBOSE_NORMAL_2'],
447                             ),
448                     (FpxUI.VERBOSE_MODE_MAXIMAL,
449                             fpx_str['ENUM_VERBOSE_MAXIMALIMAL_1'],
450                             fpx_str['ENUM_VERBOSE_MAXIMALIMAL_2'],
451                             ),
452                     ),
453             default=FpxUI.PROP_DEFAULT_VERBOSE,
454             )
455
456     keep_temp = BoolProperty(
457             name=fpx_str['PROP_NAME_KEEP_TEMP'],
458             description=fpx_str['PROP_DESC_KEEP_TEMP'],
459             default=FpxUI.PROP_DEFAULT_KEEP_TEMP,
460             )
461
462
463     use_all_libraries_of_folder = BoolProperty(
464             name=fpx_str['PROP_NAME_ALL_LIBRARIES'],
465             description=fpx_str['PROP_DESC_ALL_LIBRARIES'],
466             default=FpxUI.PROP_DEFAULT_ALL_LIBRARIES,
467             )
468
469     use_library_filter = EnumProperty(
470             name=fpx_str['PROP_NAME_USE_LIBRARY_FILTER'],
471             description=fpx_str['PROP_DESC_USE_LIBRARY_FILTER'],
472             items=(
473                     (FpxUI.USE_LIBRARY_FILTER_MODEL,
474                             fpx_str['ENUM_USE_LIBRARY_FILTER_MODEL_1'],
475                             fpx_str['ENUM_USE_LIBRARY_FILTER_MODEL_2'],
476                             'FILE_BLEND',
477                             1,
478                             ),
479                     (FpxUI.USE_LIBRARY_FILTER_GRAPHIC,
480                             fpx_str['ENUM_USE_LIBRARY_FILTER_GRAPHIC_1'],
481                             fpx_str['ENUM_USE_LIBRARY_FILTER_GRAPHIC_2'],
482                             'FILE_IMAGE',
483                             2,
484                             ),
485                     (FpxUI.USE_LIBRARY_FILTER_DMDFONT,
486                             fpx_str['ENUM_USE_LIBRARY_FILTER_DMDFONT_1'],
487                             fpx_str['ENUM_USE_LIBRARY_FILTER_DMDFONT_2'],
488                             'FILE_FONT',
489                             4,
490                             ),
491                     (FpxUI.USE_LIBRARY_FILTER_SOUND,
492                             fpx_str['ENUM_USE_LIBRARY_FILTER_SOUND_1'],
493                             fpx_str['ENUM_USE_LIBRARY_FILTER_SOUND_2'],
494                             'FILE_SOUND',
495                             8,
496                             ),
497                     (FpxUI.USE_LIBRARY_FILTER_MUSIC,
498                             fpx_str['ENUM_USE_LIBRARY_FILTER_MUSIC_1'],
499                             fpx_str['ENUM_USE_LIBRARY_FILTER_MUSIC_2'],
500                             'FILE_MOVIE',
501                             16,
502                             ),
503                     (FpxUI.USE_LIBRARY_FILTER_SCRIPT,
504                             fpx_str['ENUM_USE_LIBRARY_FILTER_SCRIPT_1'],
505                             fpx_str['ENUM_USE_LIBRARY_FILTER_SCRIPT_2'],
506                             'FILE_SCRIPT',
507                             32,
508                             ),
509                     ),
510             default=FpxUI.PROP_DEFAULT_USE_LIBRARY_FILTER,
511             options={'ENUM_FLAG', },
512             )
513
514     use_model_filter = EnumProperty(
515             name=fpx_str['PROP_NAME_USE_MODEL_FILTER'],
516             description=fpx_str['PROP_DESC_USE_MODEL_FILTER'],
517             items=(
518                     (FpxUI.USE_MODEL_FILTER_SECONDARY,
519                             fpx_str['PROP_NAME_MODEL_SECONDARY'],
520                             fpx_str['PROP_DESC_MODEL_SECONDARY'],
521                             'MESH_CUBE',
522                             1,
523                             ),
524                     (FpxUI.USE_MODEL_FILTER_REFLECTION,
525                             fpx_str['PROP_NAME_MODEL_REFLECTION'],
526                             fpx_str['PROP_DESC_MODEL_REFLECTION'],
527                             'MOD_MIRROR',
528                             2,
529                             ),
530                     (FpxUI.USE_MODEL_FILTER_MASK,
531                             fpx_str['PROP_NAME_MODEL_MASK'],
532                             fpx_str['PROP_DESC_MODEL_MASK'],
533                             'MOD_MASK',
534                             4,
535                             ),
536                     (FpxUI.USE_MODEL_FILTER_COLLISION,
537                             fpx_str['PROP_NAME_MODEL_COLLISION'],
538                             fpx_str['PROP_DESC_MODEL_COLLISION'],
539                             'MOD_PHYSICS',
540                             8,
541                             ),
542                     ),
543             default=FpxUI.PROP_DEFAULT_USE_MODEL_FILTER,
544             options={'ENUM_FLAG', },
545             )
546
547     use_model_adjustment = BoolProperty(
548             name=fpx_str['PROP_NAME_MODEL_ADJUST'],
549             description=fpx_str['PROP_DESC_MODEL_ADJUST'],
550             default=FpxUI.PROP_DEFAULT_MODEL_ADJUST_FPL,
551             )
552
553
554     filename_ext = fpx_str['FILE_EXT_FPL']
555
556     filter_glob = StringProperty(
557             default=fpx_str['FILE_FILTER_FPL'],
558             options={'HIDDEN', }
559             )
560
561     # check add-on dependency
562     @classmethod
563     def poll(cls, blender_context):
564         loaded_default, loaded_state = check("io_scene_ms3d")
565         return loaded_state
566
567     # draw the option panel
568     def draw(self, blender_context):
569         layout = self.layout
570
571         box = layout.box()
572         box.label(fpx_str['LABEL_NAME_OPTIONS'], icon=FpxUI.ICON_OPTIONS)
573         flow = box.column_flow()
574         flow.prop(self, 'verbose', icon='SPEAKER')
575         flow = box.column_flow()
576         flow.prop(self, 'keep_temp', icon='GHOST')
577         flow.prop(self, 'use_all_libraries_of_folder', icon='FILE_FOLDER')
578
579         FplImportOperator.draw_library_options(self, layout)
580         FpmImportOperator.draw_model_options(self, layout)
581
582     # entrypoint for FPL -> blender
583     def execute(self, blender_context):
584         """ start executing """
585
586         FpxUtilities.set_scene_to_default(blender_context.scene)
587
588         from io_scene_fpx.fpx_import import (FplImporter, )
589         FplImporter(
590                 report=self.report,
591                 verbose=self.verbose,
592                 keep_temp=self.keep_temp,
593                 use_all_libraries_of_folder=self.use_all_libraries_of_folder,
594                 use_library_filter=self.use_library_filter,
595                 use_model_filter=self.use_model_filter,
596                 use_model_adjustment=self.use_model_adjustment,
597                 ).read(
598                         blender_context,
599                         self.filepath,
600                         )
601
602         FpxUtilities.set_scene_to_metric(blender_context)
603
604         for scene in blender_context.blend_data.scenes:
605             scene.layers = (True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False)
606             scene.update()
607
608         return {"FINISHED"}
609
610     def invoke(self, blender_context, event):
611         blender_context.window_manager.fileselect_add(self)
612         return {'RUNNING_MODAL', }
613
614     @staticmethod
615     def menu_func(cls, blender_context):
616         cls.layout.operator(
617                 FplImportOperator.bl_idname,
618                 text=fpx_str['TEXT_OPERATOR_FPL'],
619                 )
620
621     @staticmethod
622     def draw_library_options(cls, layout):
623         box = layout.box()
624         box.label(fpx_str['LABEL_NAME_LIBRARYL_OPTIONS'], icon='IMPORT')
625         if FpxUI.USE_LIBRARY_FILTER_DMDFONT in cls.use_library_filter \
626                 or FpxUI.USE_LIBRARY_FILTER_SOUND in cls.use_library_filter \
627                 or FpxUI.USE_LIBRARY_FILTER_MUSIC in cls.use_library_filter \
628                 or FpxUI.USE_LIBRARY_FILTER_SCRIPT in cls.use_library_filter:
629             NotImplemented(box)
630         flow = box.column_flow()
631         flow.prop(cls, 'use_library_filter', icon='FILTER')
632
633
634 ###############################################################################
635 class FptImportOperator(Operator, ImportHelper):
636     """ Load a Future Pinball Table FPT File """
637     bl_idname = 'import_scene.fpt'
638     bl_label = fpx_str['BL_LABEL_IMPORTER_FPT']
639     bl_description = fpx_str['BL_DESCRIPTION_IMPORTER_FPT']
640     bl_options = {'PRESET', }
641     bl_space_type = 'PROPERTIES'
642     bl_region_type = 'WINDOW'
643
644     filepath = StringProperty(
645             subtype='FILE_PATH',
646             options={'HIDDEN', }
647             )
648
649
650     verbose = EnumProperty(
651             name=fpx_str['PROP_NAME_VERBOSE'],
652             description=fpx_str['PROP_DESC_VERBOSE'],
653             items=( (FpxUI.VERBOSE_MODE_NONE,
654                             fpx_str['ENUM_VERBOSE_NONE_1'],
655                             fpx_str['ENUM_VERBOSE_NONE_2'],
656                             ),
657                     (FpxUI.VERBOSE_MODE_NORMAL,
658                             fpx_str['ENUM_VERBOSE_NORMAL_1'],
659                             fpx_str['ENUM_VERBOSE_NORMAL_2'],
660                             ),
661                     (FpxUI.VERBOSE_MODE_MAXIMAL,
662                             fpx_str['ENUM_VERBOSE_MAXIMALIMAL_1'],
663                             fpx_str['ENUM_VERBOSE_MAXIMALIMAL_2'],
664                             ),
665                     ),
666             default=FpxUI.PROP_DEFAULT_VERBOSE,
667             )
668
669     keep_temp = BoolProperty(
670             name=fpx_str['PROP_NAME_KEEP_TEMP'],
671             description=fpx_str['PROP_DESC_KEEP_TEMP'],
672             default=FpxUI.PROP_DEFAULT_KEEP_TEMP,
673             )
674
675
676     path_libraries = StringProperty(
677             name=fpx_str['PROP_NAME_LIBRARIES_PATH'],
678             description=fpx_str['PROP_DESC_LIBRARIES_PATH'],
679             default=FpxUI.PROP_DEFAULT_LIBRARIES_PATH,
680             #subtype = 'DIR_PATH',
681             #options={'HIDDEN', },
682             )
683
684     path_dmdfonts = StringProperty(
685             name=fpx_str['PROP_NAME_DMDFONTS_PATH'],
686             description=fpx_str['PROP_DESC_DMDFONTS_PATH'],
687             default=FpxUI.PROP_DEFAULT_DMDFONTS_PATH,
688             #subtype = 'DIR_PATH',
689             #options={'HIDDEN', },
690             )
691
692     path_tables = StringProperty(
693             name=fpx_str['PROP_NAME_TABLES_PATH'],
694             description=fpx_str['PROP_DESC_TABLES_PATH'],
695             default=FpxUI.PROP_DEFAULT_TABLES_PATH,
696             #subtype = 'DIR_PATH',
697             #options={'HIDDEN', },
698             )
699
700
701     convert_to_mesh = BoolProperty(
702             name=fpx_str['PROP_NAME_CONVERT_TO_MESH'],
703             description=fpx_str['PROP_DESC_CONVERT_TO_MESH'],
704             default=FpxUI.PROP_DEFAULT_CONVERT_TO_MESH,
705             )
706
707     resolution_wire_bevel = IntProperty(
708             name=fpx_str['PROP_NAME_RESOLUTION_WIRE_BEVEL'],
709             description=fpx_str['PROP_DESC_RESOLUTION_WIRE_BEVEL'],
710             default=FpxUI.PROP_DEFAULT_RESOLUTION_WIRE_BEVEL,
711             min=2,
712             max=16,
713             )
714
715     resolution_wire = IntProperty(
716             name=fpx_str['PROP_NAME_RESOLUTION_WIRE'],
717             description=fpx_str['PROP_DESC_RESOLUTION_WIRE'],
718             default=FpxUI.PROP_DEFAULT_RESOLUTION_WIRE,
719             min=2,
720             max=16,
721             )
722
723     resolution_rubber_bevel = IntProperty(
724             name=fpx_str['PROP_NAME_RESOLUTION_RUBBER_BEVEL'],
725             description=fpx_str['PROP_DESC_RESOLUTION_RUBBER_BEVEL'],
726             default=FpxUI.PROP_DEFAULT_RESOLUTION_RUBBER_BEVEL,
727             min=2,
728             max=16,
729             )
730
731     resolution_rubber = IntProperty(
732             name=fpx_str['PROP_NAME_RESOLUTION_RUBBER'],
733             description=fpx_str['PROP_DESC_RESOLUTION_RUBBER'],
734             default=FpxUI.PROP_DEFAULT_RESOLUTION_RUBBER,
735             min=2,
736             max=16,
737             )
738
739     resolution_shape = IntProperty(
740             name=fpx_str['PROP_NAME_RESOLUTION_SHAPE'],
741             description=fpx_str['PROP_DESC_RESOLUTION_SHAPE'],
742             default=FpxUI.PROP_DEFAULT_RESOLUTION_SHAPE,
743             min=2,
744             max=16,
745             )
746
747     use_hermite_handle = BoolProperty(
748             name=fpx_str['PROP_NAME_USE_HERMITE_HANDLE'],
749             description=fpx_str['PROP_DESC_USE_HERMITE_HANDLE'],
750             default=FpxUI.PROP_DEFAULT_USE_HERMITE_HANDLE,
751             )
752
753
754     use_library_filter = EnumProperty(
755             name=fpx_str['PROP_NAME_USE_LIBRARY_FILTER'],
756             description=fpx_str['PROP_DESC_USE_LIBRARY_FILTER'],
757             items=(
758                     (FpxUI.USE_LIBRARY_FILTER_MODEL,
759                             fpx_str['ENUM_USE_LIBRARY_FILTER_MODEL_1'],
760                             fpx_str['ENUM_USE_LIBRARY_FILTER_MODEL_2'],
761                             'FILE_BLEND',
762                             1,
763                             ),
764                     (FpxUI.USE_LIBRARY_FILTER_GRAPHIC,
765                             fpx_str['ENUM_USE_LIBRARY_FILTER_GRAPHIC_1'],
766                             fpx_str['ENUM_USE_LIBRARY_FILTER_GRAPHIC_2'],
767                             'FILE_IMAGE',
768                             2,
769                             ),
770                     (FpxUI.USE_LIBRARY_FILTER_DMDFONT,
771                             fpx_str['ENUM_USE_LIBRARY_FILTER_DMDFONT_1'],
772                             fpx_str['ENUM_USE_LIBRARY_FILTER_DMDFONT_2'],
773                             'FILE_FONT',
774                             4,
775                             ),
776                     (FpxUI.USE_LIBRARY_FILTER_SOUND,
777                             fpx_str['ENUM_USE_LIBRARY_FILTER_SOUND_1'],
778                             fpx_str['ENUM_USE_LIBRARY_FILTER_SOUND_2'],
779                             'FILE_SOUND',
780                             8,
781                             ),
782                     (FpxUI.USE_LIBRARY_FILTER_MUSIC,
783                             fpx_str['ENUM_USE_LIBRARY_FILTER_MUSIC_1'],
784                             fpx_str['ENUM_USE_LIBRARY_FILTER_MUSIC_2'],
785                             'FILE_MOVIE',
786                             16,
787                             ),
788                     (FpxUI.USE_LIBRARY_FILTER_SCRIPT,
789                             fpx_str['ENUM_USE_LIBRARY_FILTER_SCRIPT_1'],
790                             fpx_str['ENUM_USE_LIBRARY_FILTER_SCRIPT_2'],
791                             'FILE_SCRIPT',
792                             32,
793                             ),
794                     ),
795             default=FpxUI.PROP_DEFAULT_USE_LIBRARY_FILTER,
796             options={'ENUM_FLAG', },
797             )
798
799     use_model_filter = EnumProperty(
800             name=fpx_str['PROP_NAME_USE_MODEL_FILTER'],
801             description=fpx_str['PROP_DESC_USE_MODEL_FILTER'],
802             items=(
803                     (FpxUI.USE_MODEL_FILTER_SECONDARY,
804                             fpx_str['PROP_NAME_MODEL_SECONDARY'],
805                             fpx_str['PROP_DESC_MODEL_SECONDARY'],
806                             'MESH_CUBE',
807                             1,
808                             ),
809                     (FpxUI.USE_MODEL_FILTER_REFLECTION,
810                             fpx_str['PROP_NAME_MODEL_REFLECTION'],
811                             fpx_str['PROP_DESC_MODEL_REFLECTION'],
812                             'MOD_MIRROR',
813                             2,
814                             ),
815                     (FpxUI.USE_MODEL_FILTER_MASK,
816                             fpx_str['PROP_NAME_MODEL_MASK'],
817                             fpx_str['PROP_DESC_MODEL_MASK'],
818                             'MOD_MASK',
819                             4,
820                             ),
821                     (FpxUI.USE_MODEL_FILTER_COLLISION,
822                             fpx_str['PROP_NAME_MODEL_COLLISION'],
823                             fpx_str['PROP_DESC_MODEL_COLLISION'],
824                             'MOD_PHYSICS',
825                             8,
826                             ),
827                     ),
828             default=FpxUI.PROP_DEFAULT_USE_MODEL_FILTER,
829             options={'ENUM_FLAG', },
830             )
831
832     use_model_adjustment = BoolProperty(
833             name=fpx_str['PROP_NAME_MODEL_ADJUST'],
834             description=fpx_str['PROP_DESC_MODEL_ADJUST'],
835             default=FpxUI.PROP_DEFAULT_MODEL_ADJUST_FPT,
836             )
837
838
839     filename_ext = fpx_str['FILE_EXT_FPT']
840
841     filter_glob = StringProperty(
842             default=fpx_str['FILE_FILTER_FPT'],
843             options={'HIDDEN', }
844             )
845
846     # check add-on dependency
847     @classmethod
848     def poll(cls, blender_context):
849         loaded_default, loaded_state = check("io_scene_ms3d")
850         return loaded_state
851
852     # draw the option panel
853     def draw(self, blender_context):
854         layout = self.layout
855
856         box = layout.box()
857         box.label(fpx_str['LABEL_NAME_OPTIONS'], icon=FpxUI.ICON_OPTIONS)
858         flow = box.column_flow()
859         flow.prop(self, 'verbose', icon='SPEAKER')
860         flow = box.column_flow()
861         flow.prop(self, 'keep_temp', icon='GHOST')
862
863         box.label(fpx_str['LABEL_NAME_EXTERNAL_DATA'], icon=FpxUI.ICON_EXTERNAL_DATA)
864         flow = box.column_flow()
865         flow.prop(self, 'path_libraries', icon='FILESEL', text="")
866         flow.prop(self, 'path_dmdfonts', icon='IMASEL', text="")
867         flow.prop(self, 'path_tables', icon='FILE_FOLDER', text="")
868
869         box = layout.box()
870         box.label(fpx_str['LABEL_NAME_TABLE_OPTIONS'], icon=FpxUI.ICON_MODEL)
871         if self.convert_to_mesh:
872             NotImplemented(box)
873         flow = box.column_flow()
874         flow.prop(self, 'convert_to_mesh', icon='MOD_TRIANGULATE')
875         flow = box.column_flow()
876         flow.prop(self, 'resolution_wire_bevel', icon='MOD_REMESH')
877         flow.prop(self, 'resolution_wire', icon='MOD_REMESH')
878         flow.prop(self, 'resolution_rubber_bevel', icon='MOD_REMESH')
879         flow.prop(self, 'resolution_rubber', icon='MOD_REMESH')
880         flow.prop(self, 'resolution_shape', icon='MOD_REMESH')
881         flow = box.column_flow()
882         flow.prop(self, 'use_hermite_handle', icon='CURVE_BEZCURVE')
883
884         FplImportOperator.draw_library_options(self, layout)
885         FpmImportOperator.draw_model_options(self, layout)
886
887     # entrypoint for FPT -> blender
888     def execute(self, blender_context):
889         """ start executing """
890
891         FpxUtilities.set_scene_to_default(blender_context.scene)
892
893         from io_scene_fpx.fpx_import import (FptImporter, )
894         FptImporter(
895                 report = self.report,
896                 verbose = self.verbose,
897                 keep_temp = self.keep_temp,
898                 path_libraries = self.path_libraries,
899                 convert_to_mesh = self.convert_to_mesh,
900                 resolution_wire_bevel = self.resolution_wire_bevel,
901                 resolution_wire = self.resolution_wire,
902                 resolution_rubber_bevel = self.resolution_rubber_bevel,
903                 resolution_rubber = self.resolution_rubber,
904                 resolution_shape = self.resolution_shape,
905                 use_hermite_handle = self.use_hermite_handle,
906                 use_library_filter = self.use_library_filter,
907                 use_model_filter = self.use_model_filter,
908                 use_model_adjustment = self.use_model_adjustment,
909                 ).read(
910                         blender_context,
911                         self.filepath,
912                         )
913
914         FpxUtilities.set_scene_to_metric(blender_context)
915
916         for scene in blender_context.blend_data.scenes:
917             scene.layers = (True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False)
918             scene.update()
919
920         return {"FINISHED"}
921
922     def invoke(self, blender_context, event):
923         blender_context.window_manager.fileselect_add(self)
924         return {'RUNNING_MODAL', }
925
926     @staticmethod
927     def menu_func(cls, blender_context):
928         cls.layout.operator(
929                 FptImportOperator.bl_idname,
930                 text=fpx_str['TEXT_OPERATOR_FPT'],
931                 )
932
933
934 ###############################################################################
935 def register():
936     register_class(FptEmptyItemProperties)
937     register_class(FptEmptyProperties)
938     inject_properties()
939
940 def unregister():
941     delete_properties()
942     unregister_class(FptEmptyProperties)
943     unregister_class(FptEmptyItemProperties)
944
945 def inject_properties():
946     Object.fpt = PointerProperty(type=FptEmptyProperties)
947
948 def delete_properties():
949     del Object.fpt
950
951 ###############################################################################
952
953
954 ###############################################################################
955 #234567890123456789012345678901234567890123456789012345678901234567890123456789
956 #--------1---------2---------3---------4---------5---------6---------7---------
957 # ##### END OF FILE #####