[Bf-extensions-cvs] [f72553f] dxf_import: More logical property names, code cleanup, more complete/correct enabling and setting of dependent properties 'Merge by attributes', 'Center geometry to scene'; fixed a 'max recusrion depth' bug occuring in _set_recenter(): do not call it anymore as a update/set method for the recenter property but whenever a related property is being updated.

Lukas Treyer noreply at git.blender.org
Mon Aug 18 15:03:09 CEST 2014


Commit: f72553fff45860e7b8a664099eb40c510173b84c
Author: Lukas Treyer
Date:   Mon Aug 18 15:02:51 2014 +0200
Branches: dxf_import
https://developer.blender.org/rBAf72553fff45860e7b8a664099eb40c510173b84c

More logical property names, code cleanup, more complete/correct enabling and setting of dependent properties 'Merge by attributes', 'Center geometry to scene'; fixed a 'max recusrion depth' bug occuring in _set_recenter(): do not call it anymore as a update/set method for the recenter property but whenever a related property is being updated.

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

M	io_import_dxf/__init__.py

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

diff --git a/io_import_dxf/__init__.py b/io_import_dxf/__init__.py
index b14d966..47b0f8a 100644
--- a/io_import_dxf/__init__.py
+++ b/io_import_dxf/__init__.py
@@ -33,8 +33,8 @@ except:
 
 bl_info = {
     "name": "Import AutoCAD DXF Format (.dxf)",
-    "author": "Lukas Treyer, Manfred Moitzi (support + dxfgrabber library), Vladimir Elistratov",
-    "version": (0, 8, 4),
+    "author": "Lukas Treyer, Manfred Moitzi (support + dxfgrabber library), Vladimir Elistratov, Bastien Montagne",
+    "version": (0, 8, 5),
     "blender": (2, 7, 1),
     "location": "File > Import > AutoCAD DXF",
     "description": "Import files in the Autocad DXF format (.dxf)",
@@ -94,7 +94,7 @@ T_Bbox = True
 T_CreateNewScene = False
 T_Recenter = False
 T_ThicknessBevel = False
-T_but_group_by_att = True
+T_import_atts = True
 
 RELEASE_TEST = False
 DEBUG = False
@@ -129,36 +129,49 @@ def display_groups_in_outliner():
 
 
 # Update helpers (must be globals to be re-usable).
-def _update_use_scene_srid_do(self, context):
+def _update_use_georeferencing_do(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':
+            if srid.upper() == '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
+                if srid in proj_epsg_items:
+                    self.proj_scene = srid
+                else:
+                    self.proj_scene = 'USER'
+                    self.epsg_scene_user = srid
         else:
             self.internal_using_scene_srid = False
+    else:
+        self.internal_using_scene_srid = False
 
 
-def _update_recenter_do(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
+def _recenter_allowed(self):
+    scene = bpy.context.scene
+    return not (self.use_georeferencing and (self.proj_scene == 'TMERC' \
+                or (not self.create_new_scene and is_ref_scene(scene)))) \
+           or (not PYPROJ and self.dxf_indi == "EUCLIDEAN")
 
+def _set_recenter(self, value):
+    self.recenter = value if _recenter_allowed(self) else False
 
 def _update_proj_scene_do(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
 
+def _update_import_atts_do(self, context):
+    if self.represent_thickness_and_width and self.merge:
+        self.import_atts = True
+    elif not self.merge:
+        self.import_atts = False
+
 
 class IMPORT_OT_dxf(bpy.types.Operator):
     """Import from DXF file format (.dxf)"""
@@ -181,10 +194,13 @@ class IMPORT_OT_dxf(bpy.types.Operator):
             options={'HIDDEN'},
             )
 
+    def _update_merge(self, context):
+        _update_import_atts_do(self, context)
     merge = BoolProperty(
             name="Merged Objects",
             description="Merge DXF entities to Blender objects",
             default=T_Merge,
+            update=_update_merge
             )
 
     merge_options = EnumProperty(
@@ -239,18 +255,11 @@ class IMPORT_OT_dxf(bpy.types.Operator):
             default='LINKED_OBJECTS',
             )
 
-    def _update_use_scene_srid(self, context):
-        _update_use_scene_srid_do(self, context)
-    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):
-        _update_use_scene_srid_do(self, context)
-        _update_recenter_do(self, context)
+        _update_use_georeferencing_do(self, context)
+        _set_recenter(self, self.recenter)
     create_new_scene = BoolProperty(
             name="Import DXF to new scene",
             description="Creates a new scene with the name of the imported file",
@@ -258,39 +267,55 @@ class IMPORT_OT_dxf(bpy.types.Operator):
             update=_update_create_new_scene,
             )
 
-    def _update_recenter(self, context):
-        _update_recenter_do(self, context)
     recenter = BoolProperty(
-            name="Center Geometry",
+            name="Center geometry to scene",
             description="Moves geometry to the center of the scene",
             default=T_Recenter,
-            update=_update_recenter,
             )
 
-    thickness_and_width = BoolProperty(
-            name="Line thickness and width",
+    def _update_thickness_width(self, context):
+        _update_import_atts_do(self, context)
+    represent_thickness_and_width = BoolProperty(
+            name="Represent line thickness/width",
             description="Map thickness and width of lines to Bevel objects and extrusion attribute",
-            default=T_ThicknessBevel
+            default=T_ThicknessBevel,
+            update=_update_thickness_width
             )
 
-    but_group_by_att = BoolProperty(
-            name="But group objects by attributes",
-            description="If thickness and width are not imported and 'Merge objects' is on, "
-                        "the objects can be split by attributes",
-            default=T_but_group_by_att
+    import_atts = BoolProperty(
+            name="Merge by attributes",
+            description="If 'Merge objects' is on but thickness and width are not chosen to be represented, with this "
+                        "option object still can be merged by thickness, with, subd and extrusion attributes "
+                        "(extrusion = transformation matrix of DXF objects)",
+            default=T_import_atts
             )
 
+
     # geo referencing
+
+    def _update_use_georeferencing(self, context):
+        _update_use_georeferencing_do(self, context)
+        _set_recenter(self, self.recenter)
+    use_georeferencing = BoolProperty(
+            name="Geo Referencing",
+            description="Project coordinates to a given coordinate system or reference point",
+            default=True,
+            update=_update_use_georeferencing,
+            )
+
+    def _update_dxf_indi(self, context):
+        _set_recenter(self, self.recenter)
     dxf_indi = EnumProperty(
             name="DXF coordinate type",
-            description="Indicated spherical or euclidian coordinates",
+            description="Indication for spherical or euclidian coordinates",
             items=[('EUCLIDEAN', "Euclidean", "Coordinates in x/y"),
                    ('SPHERICAL', "Spherical", "Coordinates in lat/lon")],
             default='EUCLIDEAN',
-            update=_update_recenter,
+            update=_update_dxf_indi,
             )
 
     # XXX This looks very suspicious to me, why not use usual FloatProperty???
+    # YYY I had it as a FloatProperty but those are not precise enough, i.e. 1.0 becomes 0.999999999. Python is more precise here.
     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",
@@ -299,10 +324,10 @@ class IMPORT_OT_dxf(bpy.types.Operator):
 
     def _update_proj(self, context):
         _update_proj_scene_do(self, context)
-        _update_recenter_do(self, context)
-    # XXX proj_epsg_items even if not PYPROJ?
-    pitems = proj_none_items + proj_user_items + proj_epsg_items
-    proj_dxf = EnumProperty(
+        _set_recenter(self, self.recenter)
+    if 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=pitems,
@@ -348,10 +373,10 @@ class IMPORT_OT_dxf(bpy.types.Operator):
         # general options
         layout.label("Line thickness and width:")
         box = layout.box()
-        box.prop(self, "thickness_and_width")
+        box.prop(self, "represent_thickness_and_width")
         sub = box.row()
-        sub.enabled = (not self.thickness_and_width and self.merge)
-        sub.prop(self, "but_group_by_att")
+        sub.enabled = (not self.represent_thickness_and_width and self.merge)
+        sub.prop(self, "import_atts")
 
         # optional objects
         layout.label("Optional Objects:")
@@ -366,44 +391,38 @@ class IMPORT_OT_dxf(bpy.types.Operator):
         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.enabled = _recenter_allowed(self)
         sub.prop(self, "recenter")
 
         # geo referencing
-        layout.label("Geo Referencing:")
-        self.draw_pyproj(layout.box()) if PYPROJ else self.draw_merc(layout.box())
+        layout.prop(self, "use_georeferencing", text="Geo Referencing:")
+        box = layout.box()
+        box.enabled = self.use_georeferencing
+        self.draw_pyproj(box, context.scene) if PYPROJ else self.draw_merc(box)
 
     def draw_merc(self, box):
         box.label("DXF File:")
         box.prop(self, "dxf_indi")
-        sub = box.row()
-        sub.enabled = (self.dxf_indi == 'EUCLIDEAN')
-        sub.prop(self, "dxf_scale")
+        box.prop(self, "dxf_scale")
 
-        box.label("Geo Reference:")
-        box.prop(self, "merc_scene_lat", text="Lat")
-        box.prop(self, "merc_scene_lon", text="Lon")
+        sub = box.column()
+        sub.enabled = not _recenter_allowed(self)
+        sub.label("Geo Ref

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list