Guest User

Untitled

a guest
Nov 13th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. class IMPORT_DATABASE(Operator):
  2.  
  3. bl_idname = "importgis.database" # important since its how bpy.ops.import.shapefile is constructed (allows calling operator from python console or another script)
  4. # bl_idname rules: must contain one '.' (dot) charactere, no capital letters, no reserved words (like 'import')
  5. bl_description = 'Import data from postgis database'
  6. bl_label = "Import database"
  7.  
  8. host = bpy.props.StringProperty(name="Host:", default="localhost")
  9. port = bpy.props.StringProperty(name="Port:", default="5432")
  10. database = bpy.props.StringProperty(name="Database:", default="scans")
  11. user = bpy.props.StringProperty(name="Username:",default="postgres")
  12. password = bpy.props.StringProperty(name="Password:",default="postgres")
  13.  
  14. def execute(self, context):
  15. bpy.ops.importgis.database_connection('INVOKE_DEFAULT', password=self.password, username=self.user, database=self.database, port=self.port, host=self.host)
  16. return {'FINISHED'}
  17.  
  18. def invoke(self, context, event):
  19. wm = context.window_manager
  20. return wm.invoke_props_dialog(self)
  21.  
  22. class IMPORT_DATABASE_CONNECTION(Operator):
  23. bl_idname = "importgis.database_connection" # important since its how bpy.ops.import.shapefile is constructed (allows calling operator from python console or another script)
  24. # bl_idname rules: must contain one '.' (dot) charactere, no capital letters, no reserved words (like 'import')
  25. bl_description = 'Geometry'
  26. bl_label = "Geometry"
  27.  
  28. host = StringProperty(options={'HIDDEN'})
  29. port = StringProperty(options={'HIDDEN'})
  30. database = StringProperty(options={'HIDDEN'})
  31. username = StringProperty(options={'HIDDEN'})
  32. password = StringProperty(options={'HIDDEN'})
  33.  
  34. num = EnumProperty(
  35. items=get_items(),
  36. name="Geometry",
  37. description="choose a geometry",
  38. default=None,
  39. options={'ANIMATABLE'},
  40. update=None,
  41. get=None,
  42. set=None)
  43.  
  44.  
  45.  
  46. def get_items(self):
  47. # condata = "dbname='%s' user='%s' host='%s' password='%s'" %
  48. # (self.database, self.user, self.host, self.password)
  49. # try:
  50. # conn = psycopg2.connect(condata)
  51. # except:
  52. # print ("I am unable to connect to the database")
  53. # cur = conn.cursor()
  54. # cur.execute("""SELECT * FROM public.geometry_columns""")
  55. # rows = cur.fetchall()
  56. # items = []
  57. # for row in rows:
  58. # geomItems = geomItems+row[0]+"//"+row[1]+"//"+row[2]+"#"
  59. # geomItems = geomItems + row[0] + "#"
  60. # items.append(row[0],row[1],row[2])
  61.  
  62. items = [
  63. ('NONE', 'None', "Flat geometry"),
  64. ('GEOM', 'Geometry', "Use z value from shape geometry if exists"),
  65. ('FIELD', 'Field', "Extract z elevation value from an attribute field"),
  66. ('OBJ', 'Object', "Get z elevation value from an existing ground mesh")
  67. ]
  68. return items
  69.  
  70. def execute(self, context):
  71. message = "Connection"
  72. self.report({'INFO'}, message)
  73. return {'FINISHED'}
  74.  
  75. def invoke(self, context, event):
  76. print("Invoke")
  77. self.pretty_print()
  78. wm = context.window_manager
  79. return wm.invoke_props_dialog(self)
Add Comment
Please, Sign In to add comment