Exemplo n.º 1
0
    def create(self):
        
        info = ""
        rows = self.ui.tableWidget.rowCount()
        if rows > 0:
            for row in range(rows):
                combobox = self.ui.tableWidget.cellWidget(row, 0)

                filename = self.ui.tableWidget.item(row, 1).text()
                layer = combobox.itemText(combobox.currentIndex())
                type = filename.split(".")[-1]

                nodes = {}
                strings = {}

                if type == "i2s":
                    try:
                        nodes, strings = fh.readDXF(self.dxf, layer)
                        fh.writeI2S(nodes, strings, filename)
                        info += " - {0} object(s) from type *.i2s converted to file \n\t{1}\n".format(len(strings), filename)
                    except Exception, e:
                        QMessageBox.critical(self.widget, "Module DXF2BK", 'Type *.i2s: ' + str(e))
                elif type == "i3s":
                    try:
                        nodes, strings = fh.readDXF(self.dxf, layer)
                        fh.writeI3S(nodes, strings, filename)
                        info += " - {0} object(s) from type *.i3s converted to file \n\t{1}\n".format(len(strings), filename)
                    except Exception, e:
                        QMessageBox.critical(self.widget, "Module DXF2BK", 'Type *.i3s: ' + str(e))
Exemplo n.º 2
0
    def create(self):

#        try:
        SMS_elements, \
            SMS_nodes,\
            SMS_strings,\
            SMS_materials,\
            SMS_bc_nodes,\
            SMS_bc_strings_1,\
            SMS_bc_strings_2,\
            SMS_bc_strings_3,\
            SMS_bc_strings_4,\
            SMS_bc_strings_5,\
            SMS_bc_strings_6,\
            SMS_bc_strings_7 = fh.read2DM(self.ui.lineEditInput.text())
#        except:
#            QMessageBox.critical(self.widget, "Error", "Not able to load file!\nCheck filename or content!")
#            return

        # BK_materials = {BK_node_id: strickler's value}
        BK_materials = {}
        
        # MAP_node_id = {SMS_node_id: BK_node_id}
        MAP_node_id = {}
        
        # BK_nodes = {BK_node_id: [x, y, z]}
        BK_nodes = {}        
        
        # BK_elements = {element_id: [BK_node_id, BK_node_id, BK_node_id (, BK_node_id), SMS_material_id]}
        BK_elements = {}
        
        # map BK nodes to SMS nodes
        i = 0
        for key in SMS_nodes:
            i += 1
            BK_nodes[i] = SMS_nodes[key]
            MAP_node_id[key] = i

        # convert SMS mesh to BK mesh
        i = 0
        impermeableMaterialID = self.ui.spinBoxImpermeable.value()
        material_added = False

        for key in SMS_elements:
            if len(SMS_elements[key]) == 4:
                node_0 = SMS_elements[key][0]
                node_1 = SMS_elements[key][1]
                node_2 = SMS_elements[key][2]
                material = SMS_elements[key][3]
                
                if material_added is False:
                    if material not in SMS_materials:
                        SMS_materials[material] = 0.0
                        material_added = True
                    
                BK_materials[MAP_node_id[node_0]] = SMS_materials[material]
                BK_materials[MAP_node_id[node_1]] = SMS_materials[material]
                BK_materials[MAP_node_id[node_2]] = SMS_materials[material]
                
                if self.ui.checkBoxImpermeable.isChecked():
                    if material != impermeableMaterialID:
                        i += 1
                        BK_elements[i] = [MAP_node_id[node_0], MAP_node_id[node_1], MAP_node_id[node_2]]
                else:
                    i += 1
                    BK_elements[i] = [MAP_node_id[node_0], MAP_node_id[node_1], MAP_node_id[node_2]]
                        
            elif len(SMS_elements[key]) == 5:
                node_0 = SMS_elements[key][0]
                node_1 = SMS_elements[key][1]
                node_2 = SMS_elements[key][2]
                node_3 = SMS_elements[key][3]
                material = SMS_elements[key][4]
                
                if material_added is False:
                    if material not in SMS_materials:
                        SMS_materials[material] = 0.0
                        material_added = True
                        
                BK_materials[MAP_node_id[node_0]] = SMS_materials[material]
                BK_materials[MAP_node_id[node_1]] = SMS_materials[material]
                BK_materials[MAP_node_id[node_2]] = SMS_materials[material]
                BK_materials[MAP_node_id[node_3]] = SMS_materials[material]
                
                if self.ui.checkBoxImpermeable.isChecked():
                    if material != impermeableMaterialID:
                        i += 1
                        BK_elements[i] = [MAP_node_id[node_0], MAP_node_id[node_1], MAP_node_id[node_2]]
                        i += 1
                        BK_elements[i] = [MAP_node_id[node_0], MAP_node_id[node_2], MAP_node_id[node_3]]
                else:
                    i += 1
                    BK_elements[i] = [MAP_node_id[node_0], MAP_node_id[node_1], MAP_node_id[node_2]]
                    i += 1
                    BK_elements[i] = [MAP_node_id[node_0], MAP_node_id[node_2], MAP_node_id[node_3]]
                        
        def getStrings(allstrings, strings):
            i = 1
            profiles = {}
            bk_profiles = {}
            for key in strings:
                profiles[i] = allstrings[key]
                bk_profiles[i] = []
                i += 1
            for pID in profiles:
                for nID in profiles[pID]:
                    bk_profiles[pID].append(MAP_node_id[nID])

            return bk_profiles
        
        info = ""
    
        if self.ui.checkBoxBottom.isChecked():
            try:
                fh.writeT3S(BK_nodes, BK_elements, self.ui.lineEditBottom.text())
                info += " - Bottom mesh created with {0} nodes and {1} elements.\n".format(len(BK_nodes), len(BK_elements)) 
            except:
                info += " - ERROR: Not able to write bottom mesh!\n"

        if self.ui.lineEditInputData.text() != "":
            SMS_wsf = fh.readDAT(self.ui.lineEditInputData.text())
            BK_nodes_wsf = {}
            BK_nodes_dpth = {}
            for key in SMS_nodes:
                wsf = 0.0
                if SMS_wsf[MAP_node_id[key]] <= 0.000001:
                    wsf = SMS_nodes[key][2]
                else:
                    wsf = SMS_wsf[MAP_node_id[key]]
                BK_nodes_wsf[key] = [SMS_nodes[key][0], SMS_nodes[key][1], wsf]    
                BK_nodes_dpth[key] = [SMS_nodes[key][0], SMS_nodes[key][1], wsf-SMS_nodes[key][2]] 
            try:
                fh.writeT3S(BK_nodes_wsf, BK_elements, self.ui.lineEditWaterSurface.text())
                info += " - Water surface mesh created with {0} nodes and {1} elements.\n".format(len(BK_nodes_wsf), len(BK_elements)) 
            except:
                info += " - ERROR: Not able to write water surface mesh!\n"
  
            try:
                fh.writeT3S(BK_nodes_dpth, BK_elements, self.ui.lineEditWaterDepth.text())
                info += " - Water depth mesh created with {0} nodes and {1} elements.\n".format(len(BK_nodes_dpth), len(BK_elements)) 
            except:
                info += " - ERROR: Not able to write water depth mesh!\n"
                  
        if self.ui.checkBoxBottomFriction.isChecked():
            BK_nodes_mat = {}
            for key in BK_nodes:
                if key in BK_materials:
                    BK_nodes_mat[key] = [BK_nodes[key][0], BK_nodes[key][1], BK_materials[key]]
                else:
                    BK_nodes_mat[key] = [BK_nodes[key][0], BK_nodes[key][1], 0.0]                    
            try:
                fh.writeT3S(BK_nodes_mat, BK_elements, self.ui.lineEditBottomFriction.text())
                info += " - Bottom friction mesh created with {0} nodes and {1} elements.\n".format(len(BK_nodes_mat), len(BK_elements)) 
            except:
                info += " - ERROR: Not able to write bottom friction mesh!\n"

        if self.ui.checkBoxCulvertHeight.isChecked():
            # convert SMS boundary condition nodes to BK points
            BK_bcNodes = {}
            for key in SMS_bc_nodes:
                height = SMS_bc_nodes[key] - SMS_nodes[key][2]
                BK_bcNodes[key] = [SMS_nodes[key][0], SMS_nodes[key][1], height]

            try:
                fh.writeXYZ(BK_bcNodes, self.ui.lineEditCulvertHeight.text())
                info += " - Culverts created with {0} nodes.\n".format(len(BK_bcNodes))
            except:
                info += " - ERROR: Not able to write culvert nodes!\n"
                                                                                        
        if self.ui.checkBoxNS1.isChecked():
            profiles = getStrings(SMS_strings, SMS_bc_strings_1)
            try:
                fh.writeI2S(BK_nodes, profiles, self.ui.lineEditNS1.text())
                info += " - Node string 1 created with {0} strings.\n".format(len(profiles)) 
            except:
                info += " - ERROR: Not able to write node string 1!\n"

        if self.ui.checkBoxNS2.isChecked():
            profiles = getStrings(SMS_strings, SMS_bc_strings_2)
            try:
                fh.writeI2S(BK_nodes, profiles, self.ui.lineEditNS2.text())
                info += " - Node string 2 created with {0} strings.\n".format(len(profiles)) 
            except:
                info += " - ERROR: Not able to write node string 2!\n"                               

        if self.ui.checkBoxNS3.isChecked():
            profiles = getStrings(SMS_strings, SMS_bc_strings_3)
            try:
                fh.writeI2S(BK_nodes, profiles, self.ui.lineEditNS3.text())
                info += " - Node string 3 created with {0} strings.\n".format(len(profiles)) 
            except:
                info += " - ERROR: Not able to write node string 3!\n"
                
        if self.ui.checkBoxNS4.isChecked():
            profiles = getStrings(SMS_strings, SMS_bc_strings_4)
            try:
                fh.writeI2S(BK_nodes, profiles, self.ui.lineEditNS4.text())
                info += " - Node string 4 created with {0} strings.\n".format(len(profiles)) 
            except:
                info += " - ERROR: Not able to write node string 4!\n"

        if self.ui.checkBoxNS5.isChecked():
            profiles = getStrings(SMS_strings, SMS_bc_strings_5)
            try:
                fh.writeI2S(BK_nodes, profiles, self.ui.lineEditNS5.text())
                info += " - Node string 5 created with {0} strings.\n".format(len(profiles)) 
            except:
                info += " - ERROR: Not able to write node string 5!\n"
                
        if self.ui.checkBoxNS6.isChecked():
            profiles = getStrings(SMS_strings, SMS_bc_strings_6)
            try:
                fh.writeI2S(BK_nodes, profiles, self.ui.lineEditNS6.text())
                info += " - Node string 6 created with {0} strings.\n".format(len(profiles)) 
            except:
                info += " - ERROR: Not able to write node string 6!\n"
                         
        if self.ui.checkBoxNS7.isChecked():
            profiles = getStrings(SMS_strings, SMS_bc_strings_7)
            try:
                fh.writeI2S(BK_nodes, profiles, self.ui.lineEditNS7.text())
                info += " - Node string 7 created with {0} strings.\n".format(len(profiles)) 
            except:
                info += " - ERROR: Not able to write node string 7!\n"

        QMessageBox.information(self.widget, "Module 2DM2BK", info)