#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
# generated by wxGlade 0.6.3 on Sun Sep 25 12:33:47 2011

import wx

# begin wxGlade: extracode
# end wxGlade


def Get_Paths():
    
    '''
    Create paths to working folder, html and png file
    in standalone version script opens visum file with selected path via COM
    '''
    
    Paths={}
    Paths["MainVisum"] = Visum.GetWorkingFolder()
    Paths["ScriptFolder"] = Paths["MainVisum"] + "\\AddIns\\Aggregator"
    Paths["Logo"]=Paths["ScriptFolder"] + "\\help\\i2_logo.png"
    Paths["Icon"]=Paths["ScriptFolder"] + "\\help\\i2_icon.png"
    Paths["Help"]=Paths["ScriptFolder"] + "\\help\\help.htm"
    
    return Paths




def Visum_Init(path=None):
        import win32com.client        
        Visum=win32com.client.Dispatch('Visum.Visum')
        if path!=None: Visum.LoadVersion(path)
        return Visum

#try: 
#    Visum
#except: 
#    Visum=Init()



class MyDialog(wx.Frame):
    def __init__(self,V, *args, **kwds):
        global Inputs
        global Visum
        global Paths
        
        Visum=V
        Paths=Get_Paths()
        self.DoUsuniecia=[]
        Inputs=[0,0,0,0,0,0,0,0]
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, None, -1)
        self.label_1 = wx.StaticText(self, -1, "Spatial data aggregator by", style=wx.ALIGN_RIGHT)
        self.logo_copy = wx.StaticBitmap(self, -1, wx.Bitmap(Paths["Logo"], wx.BITMAP_TYPE_ANY))
        self.label_2 = wx.StaticText(self, -1, "Active:")
        self.label_2_copy = wx.StaticText(self, -1, "Object:")
        self.label_2_copy_1 = wx.StaticText(self, -1, "Attribute:")
        self.label_2_copy_2 = wx.StaticText(self, -1, "Weight:")
        self.c1 = wx.CheckBox(self, -1, "")
        self.co1 = wx.ComboBox(self, -1, choices=["Zone", "MainZone", "Node", "StopPoint", "StopArea", "Stop", "Territory"], style=wx.CB_DROPDOWN)
        self.h1 = wx.Button(self, -1, "Attr")
        self.w1 = wx.TextCtrl(self,-1,"1")
        self.c2 = wx.CheckBox(self, -1, "")
        self.co2 = wx.ComboBox(self, -1, choices=["Zone", "MainZone", "Node", "StopPoint", "StopArea", "Stop", "Territory"], style=wx.CB_DROPDOWN)
        self.h2 = wx.Button(self, -1, "Attr")
        self.w2 = wx.TextCtrl(self,-1,"1")
        self.c3 = wx.CheckBox(self, -1, "")
        self.co3 = wx.ComboBox(self, -1, choices=["Zone", "MainZone", "Node", "StopPoint", "StopArea", "Stop", "Territory"], style=wx.CB_DROPDOWN)
        self.h3 = wx.Button(self, -1, "Attr")
        self.w3 = wx.TextCtrl(self,-1,"1")
        self.c4 = wx.CheckBox(self, -1, "")
        self.co4 = wx.ComboBox(self, -1, choices=["Zone", "MainZone", "Node", "StopPoint", "StopArea", "Stop", "Territory"], style=wx.CB_DROPDOWN)
        self.h4 = wx.Button(self, -1, "Attr")
        self.w4 = wx.TextCtrl(self,-1,"1")
        self.c5 = wx.CheckBox(self, -1, "")
        self.co5 = wx.ComboBox(self, -1, choices=["Zone", "MainZone", "Node", "Stop Point", "StopArea", "Stop", "Territory"], style=wx.CB_DROPDOWN)
        self.h5 = wx.Button(self, -1, "Attr")
        self.w5 = wx.TextCtrl(self,-1,"1")
        self.c6 = wx.CheckBox(self, -1, "")
        self.co6 = wx.ComboBox(self, -1, choices=["Zone", "MainZone", "Node", "StopPoint", "StopArea", "Stop", "Territory"], style=wx.CB_DROPDOWN)
        self.h6 = wx.Button(self, -1, "Attr")
        self.w6 = wx.TextCtrl(self,-1,"1")
        self.c7 = wx.CheckBox(self, -1, "")
        self.co7 = wx.ComboBox(self, -1, choices=["Zone", "MainZone", "Node", "StopPoint", "StopArea", "Stop", "Territory"], style=wx.CB_DROPDOWN)
        self.h7 = wx.Button(self, -1, "Attr")
        self.w7 = wx.TextCtrl(self,-1,"1")
        self.sizer_8_staticbox = wx.StaticBox(self, -1, "Select data to aggregate")
        self.label_3_copy_1 = wx.StaticText(self, -1, "a) target element:")
        self.tc1 = wx.ComboBox(self, -1, choices=["Zone", "MainZone", "Territory"], style=wx.CB_DROPDOWN)
        self.label_3_copy_copy_copy = wx.StaticText(self, -1, "b) separate sums for attributes?")
        self.checkbox_1 = wx.CheckBox(self, -1, "")
        self.label_3_copy_copy_copy_1 = wx.StaticText(self, -1, "c) or sum aggregated to one Attr?")
        self.ta1 = wx.Button(self, -1, "Attr")
        self.sizer_7_staticbox = wx.StaticBox(self, -1, "2. Specify output:")
        self.HelpBtn = wx.Button(self, -1, "Help")
        self.logo = wx.Panel(self, -1)
        self.Aggregate_Btn = wx.Button(self, -1, "Aggregate")
        self.CancelBtn = wx.Button(self, -1, "Cancel")

        self.__set_properties()
        self.__do_layout()
        self.Bind(wx.EVT_CLOSE, self.CleanUp)
        self.Bind(wx.EVT_BUTTON, self.ha1, self.h1)
        self.Bind(wx.EVT_BUTTON, self.ha2, self.h2)
        self.Bind(wx.EVT_BUTTON, self.ha3, self.h3)
        self.Bind(wx.EVT_BUTTON, self.ha4, self.h4)
        self.Bind(wx.EVT_BUTTON, self.ha5, self.h5)
        self.Bind(wx.EVT_BUTTON, self.ha6, self.h6)
        self.Bind(wx.EVT_BUTTON, self.ha7, self.h7)
        self.Bind(wx.EVT_BUTTON, self.Attr_Choose_Handler, self.ta1)
        self.Bind(wx.EVT_BUTTON, self.HelpClick, self.HelpBtn)
        self.Bind(wx.EVT_BUTTON, self.Aggregate_Handler, self.Aggregate_Btn)
        self.Bind(wx.EVT_BUTTON, self.Cancel_Click, self.CancelBtn)
        # end wxGlade
        self.AddedAttrs=[]

    def __set_properties(self):
        # begin wxGlade: Aggregator.__set_properties
        self.SetTitle("Spatial Aggregator by i2")
        self.SetBackgroundColour(wx.Colour(240, 240, 240))
        self.SetSize((500, 600))
        self.label_1.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.logo_copy.SetMinSize((80, 20))
        self.co1.SetMinSize((70, 21))
        self.co1.SetSelection(0)
        self.h1.SetMinSize((-1, -1))
        self.w1.SetMinSize((50, 24))
        self.co2.SetMinSize((70, 21))
        self.co2.SetSelection(0)
        self.h2.SetMinSize((-1, -1))
        self.w2.SetMinSize((50, 24))
        self.co3.SetMinSize((70, 21))
        self.co3.SetSelection(0)
        self.h3.SetMinSize((-1, -1))
        self.w3.SetMinSize((50, 24))
        self.co4.SetMinSize((70, 21))
        self.co4.SetSelection(0)
        self.h4.SetMinSize((-1, -1))
        self.w4.SetMinSize((50, 24))
        self.co5.SetMinSize((70, 21))
        self.co5.SetSelection(0)
        self.h5.SetMinSize((-1, -1))
        self.w5.SetMinSize((50, 24))
        self.co6.SetMinSize((70, 21))
        self.co6.SetSelection(0)
        self.h6.SetMinSize((-1, -1))
        self.w6.SetMinSize((50, 24))
        self.co7.SetMinSize((70, 21))
        self.co7.SetSelection(0)
        self.h7.SetMinSize((-1, -1))
        self.w7.SetMinSize((50, 24))
        self.tc1.SetMinSize((70, 21))
        self.tc1.SetSelection(0)
        self.checkbox_1.SetMinSize((-1, -1))
        self.checkbox_1.SetValue(1)
        self.ta1.SetMinSize((-1, -1))
        self.HelpBtn.SetMinSize((87, -1))
        self.logo.SetMinSize((80, 20))
        self.Aggregate_Btn.SetMinSize((-1, -1))
        self.CancelBtn.SetMinSize((87, -1))
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: Aggregator.__do_layout
        sizer_10 = wx.BoxSizer(wx.VERTICAL)
        sizer_5 = wx.BoxSizer(wx.HORIZONTAL)
        self.sizer_7_staticbox.Lower()
        sizer_7 = wx.StaticBoxSizer(self.sizer_7_staticbox, wx.HORIZONTAL)
        grid_sizer_2 = wx.GridSizer(3, 2, 0, 0)
        self.sizer_8_staticbox.Lower()
        sizer_8 = wx.StaticBoxSizer(self.sizer_8_staticbox, wx.HORIZONTAL)
        grid_sizer_1 = wx.GridSizer(8, 4, 0, 0)
        sizer_4 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_4.Add(self.label_1, 2, wx.ALL | wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, 10)
        sizer_4.Add(self.logo_copy, 3, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 10)
        sizer_10.Add(sizer_4, 30, wx.EXPAND, 0)
        grid_sizer_1.Add(self.label_2, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.label_2_copy, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.label_2_copy_1, 2, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.label_2_copy_2, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.c1, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.co1, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.h1, 2, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.w1, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 5)
        grid_sizer_1.Add(self.c2, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.co2, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.h2, 2, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.w2, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 5)
        grid_sizer_1.Add(self.c3, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.co3, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.h3, 2, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.w3, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 5)
        grid_sizer_1.Add(self.c4, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.co4, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.h4, 2, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.w4, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 5)
        grid_sizer_1.Add(self.c5, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.co5, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.h5, 2, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.w5, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 5)
        grid_sizer_1.Add(self.c6, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.co6, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.h6, 2, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.w6, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 5)
        grid_sizer_1.Add(self.c7, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.co7, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.h7, 2, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_1.Add(self.w7, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 5)
        sizer_8.Add(grid_sizer_1, 1, wx.EXPAND, 0)
        sizer_10.Add(sizer_8, 120, wx.EXPAND, 0)
        grid_sizer_2.Add(self.label_3_copy_1, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
        grid_sizer_2.Add(self.tc1, 0, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 5)
        grid_sizer_2.Add(self.label_3_copy_copy_copy, 1, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
        grid_sizer_2.Add(self.checkbox_1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer_2.Add(self.label_3_copy_copy_copy_1, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
        grid_sizer_2.Add(self.ta1, 0, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 5)
        sizer_7.Add(grid_sizer_2, 50, wx.EXPAND, 0)
        sizer_10.Add(sizer_7, 50, wx.EXPAND, 0)
        sizer_5.Add(self.HelpBtn, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 10)
        sizer_5.Add(self.logo, 3, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 10)
        sizer_5.Add(self.Aggregate_Btn, 0, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 10)
        sizer_5.Add(self.CancelBtn, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 10)
        sizer_10.Add(sizer_5, 20, wx.ALL | wx.EXPAND, 10)
        self.SetSizer(sizer_10)
        self.Layout()
        # end wxGlade

    def get_object(self,cbox):
        selection=cbox.GetSelection()
        
        if selection==0: container=Visum.Net.Zones
        if selection==1: container=Visum.Net.MainZones
        if selection==2: container=Visum.Net.Nodes
        if selection==3: container=Visum.Net.StopPoints
        if selection==4: container=Visum.Net.StopAreas
        if selection==5: container=Visum.Net.Stops
        if selection==6: container=Visum.Net.Territories         
        return container
        
    def Attr_Choose_Handler(self, event): # wxGlade: MyDialog.<event_handler>
        selection=self.tc1.GetSelection()
        
        if selection==0: container=Visum.Net.Zones
        if selection==1: container=Visum.Net.MainZones
        if selection==2: container=Visum.Net.Territories
        Inputs[7]=[container, container.AskAttribute(specialFirstEntry="1.0"), self.tc1.GetValue()]
        

    def HelpClick(self, event): # wxGlade: MyDialog.<event_handler>
        import os
        os.startfile(Paths["Help"])

    def Aggregate_Handler(self, event): # wxGlade: MyDialog.<event_handler>
        def Generate_10():
            containers=[]
            containers.append(Visum.Net.Zones)
            containers.append(Visum.Net.MainZones)
            containers.append(Visum.Net.Nodes)
            containers.append(Visum.Net.StopPoints)
            containers.append(Visum.Net.StopAreas)
            containers.append(Visum.Net.Stops)
            containers.append(Visum.Net.Territories) 
            for container in containers:
                try:
                    container.AddUserDefinedAttribute("i2_10", "i2_10", "i2_10", vt=1,  defval=1)
                    self.AddedAttrs.append([container,"i2_10"])
                except:
                    pass
        
        def Get_checked():        
            Get_Checked=[0,0,0,0,0,0,0]
            Weights=[1,1,1,1,1,1,1]
            if self.c1.IsChecked():                
                Get_Checked[0]=1
                try:
                    Weights[0]=float(self.w1.GetValue())                     
                except:
                    self.ErrMsg("Please make sure weights are numbers with decimal - i.e. 1.3") 
                    return
            if self.c2.IsChecked():
                Get_Checked[1]=1
                try:
                    Weights[1]=float(self.w2.GetValue())
                except:
                    self.ErrMsg("Please make sure weights are numbers with decimal - i.e. 1.3") 
                    return
            if self.c3.IsChecked():
                Get_Checked[2]=1
                try:
                    Weights[2]=float(self.w3.GetValue())
                except:
                    self.ErrMsg("Please make sure weights are numbers with decimal - i.e. 1.3") 
                    return
            if self.c4.IsChecked():
                Get_Checked[3]=1
                try:
                    Weights[3]=float(self.w4.GetValue())
                except:
                    self.ErrMsg("Please make sure weights are numbers with decimal - i.e. 1.3") 
                    return
            if self.c5.IsChecked():
                Get_Checked[4]=1
                try:
                    Weights[4]=float(self.w5.GetValue())
                except:
                    self.ErrMsg("Please make sure weights are numbers with decimal - i.e. 1.3") 
                    return
            if self.c6.IsChecked():
                Get_Checked[5]=1
                try:
                    Weights[5]=float(self.w6.GetValue())
                except:
                    self.ErrMsg("Please make sure weights are numbers with decimal - i.e. 1.3") 
                    return
            if self.c7.IsChecked():
                Get_Checked[6]=1
                try:
                    Weights[6]=float(self.w7.GetValue())
                except:
                    self.ErrMsg("Please make sure weights are numbers with decimal - i.e. 1.3") 
                    return
            if max(Get_Checked)==0:
               self.ErrMsg("Mark at least one parameter to aggregate") 
               return
            if self.checkbox_1.IsChecked(): 
                if max(Weights)>1 or min(Weights)<1:
                    self.ErrMsg("Weights are included only while aggregating values to single attribute \n weights will not be used")
            return [Get_Checked,Weights]       
        
        
        #1 Create UDA for counting cases 1.0        
        Generate_10() 
        #2 See what is checked and what needs to be counted      
        [Get_Checked,Weights]=Get_checked()
        #3 If mode decomposition is selected: get target object
        if self.checkbox_1.IsChecked():
            selection=self.tc1.GetSelection() #get target object
            if selection==0: container=Visum.Net.Zones
            if selection==1: container=Visum.Net.MainZones
            if selection==2: container=Visum.Net.Territories
            Inputs[7]=[container, 0, self.tc1.GetValue()]                 
        try:
            target_obj=Inputs[7][0] #Check if target atribute was defined for AGR mode
        except:
            self.ErrMsg("Please define target attribute")
            return
        #4 If mode decomposition is selected: create mirror UDA for Target Object
        if self.checkbox_1.IsChecked(): 
            for i,c in enumerate(Get_Checked):
                if c:
                    try:
                        target_obj.AddUserDefinedAttribute(Inputs[i][1],Inputs[i][1],Inputs[i][1],2,10)                        
                    except:
                        pass
        #5 Get Target
        target_obj=Inputs[7][0]                
        target_attr=Inputs[7][1] 
        target_obj_name=Inputs[7][2] 
        #6 Check if there's at least one object of target
        size=len(Inputs[7][0].GetMultiAttValues("No"))  
        if size==0:
            self.ErrMsg("At least one target atrribute needs to be defined in network")    
            return
        #7 Add dummy aggregate UDA for object target object
        try: 
            target_obj.GetMultiAttValues('dummy_aggreg')  #check if UDAs exists
        except:    
            target_obj.AddUserDefinedAttribute('dummy_aggreg', 'dummy_aggreg', 'dummy_aggreg', 2,10) #else create UDAs
            self.AddedAttrs.append([target_obj,'dummy_aggreg'])            
        
        for i in range(len(Get_Checked)):
            if Get_Checked[i]:
                #Add new intersect operation
                
                Operations=Visum.Procedures.Operations.GetAll    
                for Operation in Operations:
                    Operation.SetAttValue("Active",0)
                Visum.Procedures.Operations.AddOperation(1)
                Oper=Visum.Procedures.Operations.ItemByKey(1)
                Oper.SetAttValue("OperationType", 74)
                Oper=Visum.Procedures.Operations.ItemByKey(1) 
                  
                Oper.IntersectAttributeParameters.SetAttValue("SourceNetObjectType", Inputs[i][2])
                Oper.IntersectAttributeParameters.SetAttValue("SourceAttrName", Inputs[i][1])
                Oper.IntersectAttributeParameters.SetAttValue("DestNetObjectType", target_obj_name)
                #If moge AGR: append to dummy variable, else to mirror variable
                if self.checkbox_1.IsChecked():
                    Oper.IntersectAttributeParameters.SetAttValue("DestAttrName", Inputs[i][1])
                else:
                    Oper.IntersectAttributeParameters.SetAttValue("DestAttrName", 'dummy_aggreg')
                Visum.Procedures.Execute()
                if self.checkbox_1.IsChecked():
                    Inputs[i].append(Inputs[7][0].GetMultiAttValues(Inputs[i][1]))
                else:
                    Inputs[i].append(Inputs[7][0].GetMultiAttValues("dummy_aggreg"))
        
        if not self.checkbox_1.IsChecked():
            #weight aggregated sum
            sum=[0,0,0,0,0,0,0]                   
            for i in range(len(Get_Checked)):            
                if Get_Checked[i]:
                    dummy=Inputs[i][-1]                
                    sum[i]=[]
                    for el in dummy: 
                        sum[i].append(el[1]*Weights[i])                        
            input=[]
            for j in range(len(sum[0])):
                s=0
                for i in range(len(Get_Checked)):
                    if Get_Checked[i]:
                        s=s+sum[i][j]
                input.append((j+1,s))    
            print target_obj 
            print target_attr          
            target_obj.SetMultiAttValues(target_attr,input)
        
        

    def Cancel_Click(self, event): # wxGlade: MyDialog.<event_handler>
        for el in self.AddedAttrs:
            el[0].DeleteUserDefinedAttribute(str(el[1])) 
        
        self.Destroy()

    def ha1(self, event): # wxGlade: MyDialog.<event_handler>
        container=self.get_object(self.co1)
        attr_=container.AskAttribute(specialFirstEntry="1.0",numericOnly=True)
        self.h1.SetLabel(str(attr_))
        if attr_=="1.0":
            attr_="i2_10"            
        Inputs[0]=[container, attr_, self.co1.GetValue()]

    def ha2(self, event): # wxGlade: MyDialog.<event_handler>
        container=self.get_object(self.co2)
        attr_=container.AskAttribute(specialFirstEntry="1.0",numericOnly=True)
        self.h2.SetLabel(str(attr_))
        if attr_=="1.0":
            attr_="i2_10" 
        Inputs[1]=[container, attr_, self.co2.GetValue()]

    def ha3(self, event): # wxGlade: MyDialog.<event_handler>
        container=self.get_object(self.co3)
        attr_=container.AskAttribute(specialFirstEntry="1.0",numericOnly=True)
        self.h3.SetLabel(str(attr_))
        if attr_=="1.0":
            attr_="i2_10" 
        Inputs[2]=[container, attr_, self.co3.GetValue()]
        

    def ha4(self, event): # wxGlade: MyDialog.<event_handler>
        container=self.get_object(self.co4)
        attr_=container.AskAttribute(specialFirstEntry="1.0",numericOnly=True)
        self.h4.SetLabel(str(attr_))
        if attr_=="1.0":
            attr_="i2_10" 
        Inputs[3]=[container, attr_, self.co4.GetValue()]
        
    def ha5(self, event): # wxGlade: MyDialog.<event_handler>
        container=self.get_object(self.co5)
        attr_=container.AskAttribute(specialFirstEntry="1.0",numericOnly=True)
        self.h5.SetLabel(str(attr_))
        if attr_=="1.0":
            attr_="i2_10" 
        Inputs[4]=[container, attr_, self.co5.GetValue()]

    def ha6(self, event): # wxGlade: MyDialog.<event_handler>
        container=self.get_object(self.co6)
        attr_=container.AskAttribute(specialFirstEntry="1.0",numericOnly=True)
        self.h6.SetLabel(str(attr_))
        if attr_=="1.0":
            attr_="i2_10" 
        Inputs[5]=[container, attr_, self.co6.GetValue()]

    def ha7(self, event): # wxGlade: MyDialog.<event_handler>
        container=self.get_object(self.co7)
        attr_=container.AskAttribute(specialFirstEntry="1.0",numericOnly=True)
        self.h7.SetLabel(str(attr_))
        if attr_=="1.0":
            attr_="i2_10" 
        Inputs[6]=[container, attr_, self.co7.GetValue()]        

    def ErrMsg(self,message):
        """
        ###
        i2 Spatial Data Aggregator
        (c) 2012 Rafal Kucharski info@intelligent-infrastructure.eu
        ####
        Main function to create error message box
        """
        wx.MessageBox(message,"i2 Spatial Aggregator Error", style=wx.OK|wx.ICON_ERROR)
# end of class MyDialog

    def CleanUp(self,event):
        for el in self.AddedAttrs:
            el[0].DeleteUserDefinedAttribute(str(el[1])) 
            
        self.Destroy()

    
