[Bf-extensions-cvs] [42b976e] dxf_import: Cleanup (mostly, bust check logic out of draw code into update callbacks).

Bastien Montagne noreply at git.blender.org
Fri Aug 15 12:38:31 CEST 2014


Commit: 42b976e605a271b88dad8836811b96ed7f41552a
Author: Bastien Montagne
Date:   Thu Aug 14 20:41:10 2014 +0200
Branches: dxf_import
https://developer.blender.org/rBA42b976e605a271b88dad8836811b96ed7f41552a

Cleanup (mostly, bust check logic out of draw code into update callbacks).

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

M	io_import_dxf/__init__.py

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

diff --git a/io_import_dxf/__init__.py b/io_import_dxf/__init__.py
index ff0f4c8..d206fa0 100644
--- a/io_import_dxf/__init__.py
+++ b/io_import_dxf/__init__.py
@@ -37,7 +37,7 @@ bl_info = {
     "name": "Import AutoCAD DXF Format (.dxf)",
     "author": "Lukas Treyer, Manfred Moitzi (support + dxfgrabber library)",
     "version": (0, 8, 4),
-    "blender": (2, 7, 0),
+    "blender": (2, 7, 1),
     "location": "File > Import > AutoCAD DXF",
     "description": "Import files in the Autocad DXF format (.dxf)",
     "wiki_url": "https://bitbucket.org/treyerl/io_import_scene_dxf/overview",
@@ -102,9 +102,8 @@ RELEASE_TEST = False
 DEBUG = False
 
 
-def is_ref_scene():
-    scn = bpy.context.scene
-    return "latidute" in scn and "longitude" in scn
+def is_ref_scene(scene):
+    return "latitude" in scene and "longitude" in scene
 
 
 def read(report, filename, obj_merge=BY_LAYER, import_text=True, import_light=True, export_acis=True, merge_lines=True,
@@ -117,14 +116,12 @@ def read(report, filename, obj_merge=BY_LAYER, import_text=True, import_light=Tr
     errors = do.entities(os.path.basename(filename).replace(".dxf", ""), new_scene)
 
     # display errors
-    if len(errors) > 0:
-        for error in errors:
-            report('ERROR', error)
+    for error in errors:
+        report('ERROR', error)
 
     # inform the user about the sat/sab files
     if len(do.acis_files) > 0:
-        bpy.ops.error.message('INFO',
-                              "Exported %d NURBS objects to sat/sab files next to your DXF file" % len(do.acis_files))
+        report('INFO', "Exported %d NURBS objects to sat/sab files next to your DXF file" % len(do.acis_files))
 
 
 def display_groups_in_outliner():
@@ -160,7 +157,8 @@ class IMPORT_OT_dxf(bpy.types.Operator):
             default=T_Merge,
             )
 
-    merge_options = EnumProperty(name="Merge",
+    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")],
@@ -203,19 +201,52 @@ class IMPORT_OT_dxf(bpy.types.Operator):
             default=T_Bbox
             )
 
-    block_options = EnumProperty(name="Blocks As",
+    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',
             )
 
+    def _update_use_scene_srid(self, context):
+        if not self.create_new_scene:
+            scene = context.scene
+            # Try to get Scene SRID (ESPG) data from current scene.
+            srid = scene.get("SRID", None)
+            if srid is not None:
+                self.internal_using_scene_srid = True
+                if srid == 'TMERC':
+                    self.proj_scene = 'TMERC'
+                    self.merc_scene_lat = scene.get('latitude', 0)
+                    self.merc_scene_lon = scene.get('longitude', 0)
+                else:
+                    self.proj_scene = 'USER'
+                    self.epsg_scene_user = srid
+            else:
+                self.internal_using_scene_srid = False
+    use_scene_srid = BoolProperty(
+            name="Use SRID From Scene",
+            description="Try to use SRID property value from current Scene, if available",
+            default=True,
+            update=_update_use_scene_srid,
+            )
+
+    def _update_create_new_scene(self, context):
+        self._update_use_scene_srid(self, context)
+        self._update_recenter(self, context)
     create_new_scene = BoolProperty(
             name="Import DXF to new scene",
             description="Creates a new scene with the name of the imported file",
-            default=T_CreateNewScene
+            default=T_CreateNewScene,
+            update=_update_create_new_scene,
             )
 
+    def _update_recenter(self, context):
+        scene = context.scene
+        if self.dxf_indi == 'SPHERICAL' or self.proj_scene == 'TMERC' or \
+           (not self.create_new_scene and is_ref_scene(scene)):
+            self.recenter = False
     recenter = BoolProperty(
             name="Center Geometry",
             description="Moves geometry to the center of the scene",
@@ -241,20 +272,30 @@ class IMPORT_OT_dxf(bpy.types.Operator):
             description="Indicated spherical or euclidian coordinates",
             items=[('EUCLIDEAN', "Euclidean", "Coordinates in x/y"),
                    ('SPHERICAL', "Spherical", "Coordinates in lat/lon")],
-            default='EUCLIDEAN'
-    )
+            default='EUCLIDEAN',
+            update=_update_recenter,
+            )
 
+    # XXX This looks very suspicious to me, why not use usual FloatProperty???
     dxf_scale = StringProperty(  # string = the floating point precision is handled by python: float(dxf_scale)
             name="Unit Scale",
             description="Coordinates are assumed to be in meters; deviation must be indicated here",
             default="1.0"
-    )
+            )
 
+    def _update_proj_scene(self, context):
+        # make sure scene EPSG is not None if DXF EPSG is not None
+        if self.proj_scene == 'NONE' and self.proj_dxf != 'NONE':
+            self.proj_scene = self.proj_dxf
+        self._update_recenter(self, context)
+    # XXX proj_epsg_items even if not PYPROJ?
+    pitems = proj_none_items + proj_user_items + proj_epsg_items
     proj_dxf = EnumProperty(
             name="DXF SRID",
             description="The coordinate system for the DXF file (check http://epsg.io)",
-            items=proj_none_items + proj_user_items + proj_epsg_items,
+            items=pitems,
             default='NONE',
+            update=_update_proj_scene,
             )
 
     epsg_dxf_user = StringProperty(name="EPSG-Code", default="EPSG")
@@ -263,178 +304,152 @@ class IMPORT_OT_dxf(bpy.types.Operator):
 
     pitems = proj_none_items + ((proj_user_items + proj_tmerc_items + proj_epsg_items) if PYPROJ else proj_tmerc_items)
     proj_scene = EnumProperty(
-        name="Scn SRID",
-        description="The coordinate system for the Scene (check http://epsg.io)",
-        items=pitems,
-        default='NONE',
-        )
+            name="Scn SRID",
+            description="The coordinate system for the Scene (check http://epsg.io)",
+            items=pitems,
+            default='NONE',
+            update=_update_proj_scene,
+            )
 
     epsg_scene_user = StringProperty(name="EPSG-Code", default="EPSG")
     merc_scene_lat = FloatProperty(name="Geo-Reference Latitude", default=0.0)
     merc_scene_lon = FloatProperty(name="Geo-Reference Longitude", default=0.0)
 
+    # internal use only!
+    internal_using_scene_srid = BoolProperty(default=False, options={'HIDDEN'})
+
     def draw(self, context):
+        layout = self.layout
+        scene = context.scene
+
         # merge options
-        self.layout.label("Merge Options:")
-        col = self.layout.box().column()
-        col.prop(self, "block_options")
-        col.prop(self, "do_bbox")
-        col.prop(self, "merge")
-        if self.merge:
-            col.prop(self, "merge_options")
-        col.prop(self, "merge_lines")
+        layout.label("Merge Options:")
+        box = layout.box()
+        box.prop(self, "block_options")
+        box.prop(self, "do_bbox")
+        box.prop(self, "merge")
+        sub = box.row()
+        sub.enabled = self.merge
+        sub.prop(self, "merge_options")
+        box.prop(self, "merge_lines")
 
         # general options
-        self.layout.label("Line thickness and width:")
-        col = self.layout.box().column()
-        col.prop(self, "thickness_and_width")
-        if not self.thickness_and_width and self.merge:
-            col.prop(self, "but_group_by_att")
+        layout.label("Line thickness and width:")
+        box = layout.box()
+        box.prop(self, "thickness_and_width")
+        sub = box.row()
+        sub.enabled = (not self.thickness_and_width and self.merge)
+        sub.prop(self, "but_group_by_att")
 
         # optional objects
-        self.layout.label("Optional Objects:")
-        col = self.layout.box().column()
-        col.prop(self, "import_text")
-        col.prop(self, "import_light")
-        col.prop(self, "export_acis")
+        layout.label("Optional Objects:")
+        box = layout.box()
+        box.prop(self, "import_text")
+        box.prop(self, "import_light")
+        box.prop(self, "export_acis")
 
         # view options
-        self.layout.label("View Options:")
-        box = self.layout.box()
-        col = box.column()
-        box.row().prop(self, "outliner_groups")
-        box.row().prop(self, "create_new_scene")
-
-        if self.dxf_indi == 'SPHERICAL' or self.proj_scene == 'TMERC' or (not self.create_new_scene and is_ref_scene()):
-            row = box.row()
-            row.enabled = False
-            self.recenter = False
-            row.prop(self, "recenter")
-        else:
-            box.row().prop(self, "recenter")
-        if not self.create_new_scene and self.recenter:
-            if "latitude" in bpy.context.scene and "longitude" in bpy.context.scene:
-                box.row().label("", icon='ERROR')
-                box.row().label("Current scene has geo reference!")
-                box.row().label("You should not center the import!")
+        layout.label("View Options:")
+        box = layout.box()
+        box.prop(self, "outliner_groups")
+        box.prop(self, "create_new_scene")
+        sub = box.row()
+        sub.enabled = not (self.dxf_indi == 'SPHERICAL' or self.proj_scene == 'TMERC' or
+                           (not self.create_new_scene and is_ref_scene(scene)))
+        sub.prop(self, "recenter")
 
         # geo referencing
-        self.layout.label("Geo Referencing:")
-  

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list