[Bf-extensions-cvs] [e13b3f1] dxf_import: First cleanup pass.

Bastien Montagne noreply at git.blender.org
Mon Aug 4 19:58:24 CEST 2014


Commit: e13b3f19614507c207378d93c95e9231a1dec616
Author: Bastien Montagne
Date:   Mon Aug 4 19:54:10 2014 +0200
Branches: dxf_import
https://developer.blender.org/rBAe13b3f19614507c207378d93c95e9231a1dec616

First cleanup pass.

pep8 and own codestyle (no dot in tips, capitals in labels, use '' for enum values, and "" everywhere else, etc.).
Also some simplifications/clarifications.

No need for a custom message op, we have the report system!

Still have to recheck the draw func of the op, setting too much values to my taste, but this is rather complex. Imho, some of this logic at least could be handled by prop callbacks, though.

===================================================================

M	io_import_dxf/__init__.py
M	io_import_dxf/transverse_mercator.py

===================================================================

diff --git a/io_import_dxf/__init__.py b/io_import_dxf/__init__.py
index e7ac171..ff0f4c8 100644
--- a/io_import_dxf/__init__.py
+++ b/io_import_dxf/__init__.py
@@ -42,33 +42,41 @@ bl_info = {
     "description": "Import files in the Autocad DXF format (.dxf)",
     "wiki_url": "https://bitbucket.org/treyerl/io_import_scene_dxf/overview",
     "tracker_url": "https://bitbucket.org/treyerl/io_import_scene_dxf/issues?status=new&status=open",
-    "support": "OFFICIAL",
     "category": "Import-Export",
-    }
-
-merc_list = [('None', 'None', 'No Coordinate System is available / will be set'),
-             ('tmerc', 'Transverse Mercator', 'Mercator Projection using a lat/lon coordinate as its geo-reference.')]
-
-epsg_list=[('None', 'None', 'No Coordinate System is available / will be set'),
-           ('user', 'User Defined', 'Define the EPSG code'),
-           ('EPSG:4326', 'WGS84','World Geodetic System 84; default for lat / lon; EPSG:4326'),
-           ('EPSG:3857', 'Spherical Mercator', 'Webbrowser mapping service standard (Google, OpenStreetMap, ESRI); EPSG:3857'),
-           ('EPSG:27700', 'National Grid U.K', 'Ordnance Survey National Grid reference system used in Great Britain; EPSG:27700'),
-           ('EPSG:2154', 'France (Lambert 93)', 'Lambert Projection for France; EPSG:2154'),
-           ('EPSG:5514', 'Czech Republic & Slovakia', 'Coordinate System for Czech Republic and Slovakia; EPSG:5514'),
-           ('EPSG:5243', 'LLC Germany', 'Projection for Germany; EPSG:5243'),
-           ('EPSG:28992', 'Amersfoort Netherlands', 'Amersfoort / RD New -- Netherlands; EPSG:28992'),
-           ('EPSG:21781', 'Swiss CH1903 / LV03', 'Switzerland and Lichtenstein; EPSG:21781'),
-           ('EPSG:5880', 'Brazil Polyconic', 'Cartesian 2D; Central, South America; EPSG:5880 '),
-           ('EPSG:42103', 'LCC USA', 'Lambert Conformal Conic Projection; EPSG:42103'),
-           ('EPSG:3350', 'Russia: Pulkovo 1942 / CS63 zone C0', 'Russian Federation - onshore and offshore; EPSG:3350'),
-           ('EPSG:22293', 'Cape / Lo33 South Africa', 'South Africa; EPSG:22293'),
-           ('EPSG:27200', 'NZGD49 / New Zealand Map Grid', 'NZGD49 / New Zealand Map Grid; EPSG:27200'),
-           ('EPSG:3112', 'GDA94 Australia Lambert', 'GDA94 / Geoscience Australia Lambert; EPSG:3112'),
-           ('EPSG:24378', 'India zone I', 'Kalianpur 1975 / India zone I; EPSG:24378'),
-           ('EPSG:2326', 'Hong Kong 1980 Grid System', 'Hong Kong 1980 Grid System; EPSG:2326'),
-           ('EPSG:3414', 'SVY21 / Singapore TM', 'SVY21 / Singapore TM; EPSG:3414'),
-           ]
+}
+
+
+proj_none_items = (
+    ('NONE', "None", "No Coordinate System is available / will be set"),
+)
+proj_user_items = (
+    ('USER', "User Defined", "Define the EPSG code"),
+)
+proj_tmerc_items = (
+    ('TMERC', "Transverse Mercator", "Mercator Projection using a lat/lon coordinate as its geo-reference"),
+)
+proj_epsg_items = (
+    ('EPSG:4326', "WGS84", "World Geodetic System 84; default for lat / lon; EPSG:4326"),
+    ('EPSG:3857', "Spherical Mercator", "Webbrowser mapping service standard (Google, OpenStreetMap, ESRI); EPSG:3857"),
+    ('EPSG:27700', "National Grid U.K",
+                   "Ordnance Survey National Grid reference system used in Great Britain; EPSG:27700"),
+    ('EPSG:2154', "France (Lambert 93)", "Lambert Projection for France; EPSG:2154"),
+    ('EPSG:5514', "Czech Republic & Slovakia", "Coordinate System for Czech Republic and Slovakia; EPSG:5514"),
+    ('EPSG:5243', "LLC Germany", "Projection for Germany; EPSG:5243"),
+    ('EPSG:28992', "Amersfoort Netherlands", "Amersfoort / RD New -- Netherlands; EPSG:28992"),
+    ('EPSG:21781', "Swiss CH1903 / LV03", "Switzerland and Lichtenstein; EPSG:21781"),
+    ('EPSG:5880', "Brazil Polyconic", "Cartesian 2D; Central, South America; EPSG:5880 "),
+    ('EPSG:42103', "LCC USA", "Lambert Conformal Conic Projection; EPSG:42103"),
+    ('EPSG:3350', "Russia: Pulkovo 1942 / CS63 zone C0", "Russian Federation - onshore and offshore; EPSG:3350"),
+    ('EPSG:22293', "Cape / Lo33 South Africa", "South Africa; EPSG:22293"),
+    ('EPSG:27200', "NZGD49 / New Zealand Map Grid", "NZGD49 / New Zealand Map Grid; EPSG:27200"),
+    ('EPSG:3112', "GDA94 Australia Lambert", "GDA94 / Geoscience Australia Lambert; EPSG:3112"),
+    ('EPSG:24378', "India zone I", "Kalianpur 1975 / India zone I; EPSG:24378"),
+    ('EPSG:2326', "Hong Kong 1980 Grid System", "Hong Kong 1980 Grid System; EPSG:2326"),
+    ('EPSG:3414', "SVY21 / Singapore TM", "SVY21 / Singapore TM; EPSG:3414"),
+)
+
+proj_epsg_dict = {e[0]: e[1] for e in proj_epsg_items}
 
 __version__ = '.'.join([str(s) for s in bl_info['version']])
 
@@ -93,14 +101,16 @@ T_but_group_by_att = True
 RELEASE_TEST = False
 DEBUG = False
 
+
 def is_ref_scene():
     scn = bpy.context.scene
     return "latidute" in scn and "longitude" in scn
 
-def read(filename, obj_merge=BY_LAYER, import_text=True, import_light=True, export_acis=True, merge_lines=True,
+
+def read(report, filename, obj_merge=BY_LAYER, import_text=True, import_light=True, export_acis=True, merge_lines=True,
          do_bbox=True, block_rep=LINKED_OBJECTS, new_scene=None, recenter=False, projDXF=None, projSCN=None,
          thicknessWidth=True, but_group_by_att=True, dxf_unit_scale=1.0):
-    # import dxf and export nurbs types to sat/sab files 
+    # import dxf and export nurbs types to sat/sab files
     # because that's how autocad stores nurbs types in a dxf...
     do = Do(filename, obj_merge, import_text, import_light, export_acis, merge_lines, do_bbox, block_rep, recenter,
             projDXF, projSCN, thicknessWidth, but_group_by_att, dxf_unit_scale)
@@ -109,50 +119,27 @@ def read(filename, obj_merge=BY_LAYER, import_text=True, import_light=True, expo
     # display errors
     if len(errors) > 0:
         for error in errors:
-            bpy.ops.error.message('INVOKE_DEFAULT', message=error)
+            report('ERROR', error)
 
     # inform the user about the sat/sab files
     if len(do.acis_files) > 0:
-        bpy.ops.error.message('INVOKE_DEFAULT',
-                              message="Exported %d NURBS objects to sat/sab files next to your DXF file."
-                                      % len(do.acis_files))
+        bpy.ops.error.message('INFO',
+                              "Exported %d NURBS objects to sat/sab files next to your DXF file" % len(do.acis_files))
+
 
 def display_groups_in_outliner():
     outliners = (a for a in bpy.context.screen.areas if a.type == "OUTLINER")
     for outliner in outliners:
         outliner.spaces[0].display_mode = "GROUPS"
 
-class MessageOperator(bpy.types.Operator):
-    bl_idname = "error.message"
-    bl_label = "Message"
-    message = StringProperty()
- 
-    def execute(self, context):
-        self.report({'INFO'}, self.message)
-        return {'FINISHED'}
- 
-    def invoke(self, context, event):
-        wm = context.window_manager
-        return wm.invoke_props_dialog(self, width=500, height=500)
- 
-    def draw(self, context):
-        print(self.message)
-        lines = []
-        i = 0
-        width = 41
-        while len(self.message) > 0:
-            lines.append(self.message[:width])
-            self.message = self.message[width:]
-        for line in lines:
-            self.layout.label(line)
 
 class IMPORT_OT_dxf(bpy.types.Operator):
     """Import from DXF file format (.dxf)"""
     bl_idname = "import_scene.dxf"
     bl_description = 'Import from DXF file format (.dxf)'
-    bl_label = "Import DXF" + ' v.' + __version__
-    bl_space_type = "PROPERTIES"
-    bl_region_type = "WINDOW"
+    bl_label = "Import DXf v." + __version__
+    bl_space_type = 'PROPERTIES'
+    bl_region_type = 'WINDOW'
     bl_options = {'UNDO'}
 
     filepath = StringProperty(
@@ -174,10 +161,10 @@ class IMPORT_OT_dxf(bpy.types.Operator):
             )
 
     merge_options = EnumProperty(name="Merge",
-            description="Merge multiple DXF entities into one Blender object.",
-            items=[('by_type', 'by Layer AND Dxf-Type','Merge DXF entities by type AND layer.'),
-                   ('by_layer','by Layer', 'Merge DXF entities of a layer to an object.')],
-            default='by_layer',
+            description="Merge multiple DXF entities into one Blender object",
+            items=[('BY_TYPE', "By Layer AND Dxf-Type", "Merge DXF entities by type AND layer"),
+                   ('BY_LAYER', "By Layer", "Merge DXF entities of a layer to an object")],
+            default='BY_LAYER',
             )
 
     merge_lines = BoolProperty(
@@ -200,7 +187,7 @@ class IMPORT_OT_dxf(bpy.types.Operator):
 
     export_acis = BoolProperty(
             name="Export ACIS Entities",
-            description="Export Entities consisting of ACIS code to ACIS .sat/.sab files.",
+            description="Export Entities consisting of ACIS code to ACIS .sat/.sab files",
             default=T_ExportAcis
             )
 
@@ -217,15 +204,15 @@ class IMPORT_OT_dxf(bpy.types.Operator):
             )
 
     block_options = EnumProperty(name="Blocks As",
-            description="Select the representation of DXF blocks: linked objects or group instances. ",
-            items=[('linked_objects', 'linked objects', 'block objects get imported as linked objects'),
-                   ('group_instances', 'group instances', 'block objects get imported as group instances')],
-            default='linked_objects',
+            description="Select the representation of DXF blocks: linked objects or group instances",
+            items=[('LINKED_OBJECTS', "Linked Objects", "Block objects get imported as linked objects"),
+                   ('GROUP_INSTANCES', "Group Instances", "Block objects get imported as group instances")],
+            default='LINKED_OBJECTS',
             )
 
     create_new_scene = BoolProperty(
             name="Import DXF to new scene",
-            description="Creates a new scene with the name of the imported file.",
+            description="Creates a new scene with the name of the imported file",
             default=T_CreateNewScene
             )
 
@@ -243,54 +230,44 @@ class IMPORT_OT_dxf(bpy.types.Operator):
 
     but_group_by

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list