from time import sleep

import axipy
from axipy import provider_manager, Layer, Map, view_manager, Style, Feature, Workspace, Rect, Text

from createFromSelection.ui.tools.factoryObject import FactoryGeometry
from createFromSelection.ui.tools.map_tools import getEditableTable
str_mi_style=style='Pen (1, 2, 0) Brush (1, 16777215, 16777215)'
style=Style.from_mapinfo(str_mi_style)
path_tab=r"E:\Support\AxiomaTesting\CreateObj\TestPoints.tab"
path_ws=r"E:\Support\AxiomaTesting\CreateObj\test_points1.mws"
path_ws=r"E:\Support\AxiomaTesting\CreateObj\test_obj1.mws"
#Workspace().load_file(path_ws)
axipy.mainwindow.load_workspace(path_ws)
map_view= view_manager.mapviews[0]
map=map_view.map
layer=map.layers[0]
tab=layer.data_object
editable_tab=getEditableTable(map)
list_geometry=[]
for ft in tab.items():
    list_geometry.append(ft.geometry)
cls_factory=FactoryGeometry()
count_points=cls_factory.prepare_points(list_geometry)
#geo_obj=cls_factory.createGeometry(axipy.GeometryType.LineString,tab.coordsystem)
geo_obj=cls_factory.createGeometry(axipy.GeometryType.Polygon,tab.coordsystem)
bound=geo_obj.bounds
rect=Rect(bound.xmin,bound.ymin,bound.xmax,bound.ymax)
geo_text=Text("Пример Text",rect =rect,cs=tab.coordsystem)
#ft_new=Feature({},geo_obj,style=style)
ft_new=Feature({},geo_text)
ft_new_geo=Feature({},geo_obj,style=style)
editable_tab.insert([ft_new,ft_new_geo])
print("End")
