Guest User

Untitled

a guest
Nov 15th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 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)
  80.  
  81. import bpy
  82. from bpy.props import StringProperty, EnumProperty
  83.  
  84. class ImportDataBaseConnection(bpy.types.Operator):
  85. bl_idname = "importgis.database_connection"
  86. bl_description = 'Import Geometry Data'
  87. bl_label = "Geometry"
  88.  
  89. host = StringProperty(options={'HIDDEN'})
  90. port = StringProperty(options={'HIDDEN'})
  91. database = StringProperty(options={'HIDDEN'})
  92. username = StringProperty(options={'HIDDEN'})
  93. password = StringProperty(options={'HIDDEN'})
  94.  
  95. def item_callback(self, context):
  96. return (
  97. ('NONE', 'None', "Flat geometry"),
  98. ('GEOM', 'Geometry', "Use z value from shape geometry if exists"),
  99. ('FIELD', 'Field', "Extract z elevation value from an attribute field"),
  100. ('OBJ', 'Object', "Get z elevation value from an existing ground mesh"),
  101. )
  102.  
  103. geo_type = EnumProperty(
  104. items=item_callback,
  105. name="Geometry Type",
  106. description="choose a geometry",
  107. default=None,
  108. options={'ANIMATABLE'},
  109. update=None,
  110. get=None,
  111. set=None)
  112.  
  113. def execute(self, context):
  114. message = "Connection"
  115. self.report({'INFO'}, message)
  116. return {'FINISHED'}
  117.  
  118. def invoke(self, context, event):
  119. wm = context.window_manager
  120. return wm.invoke_props_dialog(self, width=500)
  121.  
  122.  
  123. def register():
  124. bpy.utils.register_class(ImportDataBaseConnection)
  125.  
  126.  
  127. def unregister():
  128. bpy.utils.unregister_class(ImportDataBaseConnection)
  129.  
  130.  
  131. if __name__ == "__main__":
  132. register()
  133.  
  134. # test call
  135. bpy.ops.importgis.database_connection('INVOKE_DEFAULT')
Add Comment
Please, Sign In to add comment