From 0ed535214e908dddb4b6804fe602a1f0423c3b1d Mon Sep 17 00:00:00 2001
From: Bill Currie <bill@taniwha.org>
Date: Sun, 16 Sep 2012 12:57:17 +0900
Subject: [PATCH] Import leak points files.

---
 tools/io_qfmap/__init__.py   | 13 +++++++++++++
 tools/io_qfmap/import_map.py | 24 ++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/tools/io_qfmap/__init__.py b/tools/io_qfmap/__init__.py
index 7b369e100..c67158aff 100644
--- a/tools/io_qfmap/__init__.py
+++ b/tools/io_qfmap/__init__.py
@@ -244,6 +244,18 @@ class QFECPanel(bpy.types.Panel):
         row.prop(scene.qfmap, "script")
         row.operator("scene.parse_entity_classes", text="", icon="FILE_REFRESH")
 
+class ImportPoints(bpy.types.Operator, ImportHelper):
+    '''Load a Quake points File'''
+    bl_idname = "import_mesh.quake_points"
+    bl_label = "Import points"
+
+    filename_ext = ".pts"
+    filter_glob = StringProperty(default="*.pts", options={'HIDDEN'})
+
+    def execute(self, context):
+        keywords = self.as_keywords (ignore=("filter_glob",))
+        return import_map.import_pts(self, context, **keywords)
+
 class ImportMap(bpy.types.Operator, ImportHelper):
     '''Load a Quake map File'''
     bl_idname = "import_mesh.quake_map"
@@ -275,6 +287,7 @@ class ExportMap(bpy.types.Operator, ExportHelper):
 
 def menu_func_import(self, context):
     self.layout.operator(ImportMap.bl_idname, text="Quake map (.map)")
+    self.layout.operator(ImportPoints.bl_idname, text="Quake points (.pts)")
 
 def menu_func_export(self, context):
     self.layout.operator(ExportMap.bl_idname, text="Quake map (.map)")
diff --git a/tools/io_qfmap/import_map.py b/tools/io_qfmap/import_map.py
index 8ff695108..7d22912a0 100644
--- a/tools/io_qfmap/import_map.py
+++ b/tools/io_qfmap/import_map.py
@@ -227,3 +227,27 @@ def import_map(operator, context, filepath):
         process_entity(ent, wads)
     bpy.context.user_preferences.edit.use_global_undo = True
     return {'FINISHED'}
+
+def import_pts(operator, context, filepath):
+    bpy.context.user_preferences.edit.use_global_undo = False
+
+    for obj in bpy.context.scene.objects:
+        obj.select = False
+
+    lines = open(filepath, "rt").readlines()
+    verts = [None] * len(lines)
+    edges = [None] * (len(lines) - 1)
+    for i, line in enumerate(lines):
+        if i:
+            edges[i - 1] = (i - 1, i)
+        v = line.split(" ")
+        verts[i] = tuple(map(lambda x: float(x), v))
+    mesh = bpy.data.meshes.new("leak points")
+    mesh.from_pydata(verts, edges, [])
+    mesh.update()
+    obj = bpy.data.objects.new("leak points", mesh)
+    bpy.context.scene.objects.link(obj)
+    bpy.context.scene.objects.active=obj
+    obj.select = True
+    bpy.context.user_preferences.edit.use_global_undo = True
+    return {'FINISHED'}