示例#1
0
    def __init__(self, app, parent=None):
        """Constructor for main class.

        Keyword arguments:
        app -- the application

        """
        super(ChEsher, self).__init__(parent)
        self._app = app
        
        # setup user interface of main window
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        # variables
        self.directory = ""

        # setup instance of module DXF2BK
        self.moduleDXF2BK = WrapDXF2BK(self.directory)
        self.widgetDXF2BK = self.moduleDXF2BK.widget
        self.ui.stackedWidget.insertWidget(0, self.widgetDXF2BK)        

        # setup instance of module BK2DXF
        self.moduleBK2DXF = WrapBK2DXF(self.directory)
        self.widgetBK2DXF = self.moduleBK2DXF.widget
        self.ui.stackedWidget.insertWidget(1, self.widgetBK2DXF)   

        # setup instance of module Mesh
        self.moduleMesh = WrapMesh(self.directory)
        self.widgetMesh = self.moduleMesh.widget
        self.ui.stackedWidget.insertWidget(2, self.widgetMesh)   

        # setup instance of module LandXML
        self.moduleLandXML = WrapLandXML(self.directory)
        self.widgetLandXML = self.moduleLandXML.widget
        self.ui.stackedWidget.insertWidget(3, self.widgetLandXML)   
        
        # setup instance of module ScalarDXF
        self.moduleScalarDXF = WrapScalarDXF(self.directory)
        self.widgetScalarDXF = self.moduleScalarDXF.widget
        self.ui.stackedWidget.insertWidget(4, self.widgetScalarDXF)  

        # setup instance of module VectorDXF
        self.moduleVectorDXF = WrapVectorDXF(self.directory)
        self.widgetVectorDXF = self.moduleVectorDXF.widget
        self.ui.stackedWidget.insertWidget(5, self.widgetVectorDXF)  

        # setup instance of module CS
        self.moduleCS = WrapCS(self.directory)
        self.widgetCS = self.moduleCS.widget
        self.ui.stackedWidget.insertWidget(6, self.widgetCS)  

        # setup instance of module 2DM2BK
        self.module2DM2BK = Wrap2DM2BK(self.directory)
        self.widget2DM2BK = self.module2DM2BK.widget
        self.ui.stackedWidget.insertWidget(7, self.widget2DM2BK)  

        # setup instance of module Cont2DXF
        self.moduleCont2DXF = WrapCont2DXF(self.directory)
        self.widgetCont2DXF = self.moduleCont2DXF.widget
        self.ui.stackedWidget.insertWidget(8, self.widgetCont2DXF)  
        
        # setup instance of module Tube
        self.moduleTube = WrapTube(self.directory)
        self.widgetTube = self.moduleTube.widget
        self.ui.stackedWidget.insertWidget(9, self.widgetTube)  

        # setup instance of module XYZ2Profiles
        self.moduleXYZ2Profiles = WrapXYZ2Profiles(self.directory)
        self.widgetXYZ2Profiles = self.moduleXYZ2Profiles.widget
        self.ui.stackedWidget.insertWidget(10, self.widgetXYZ2Profiles)    

        # setup instance of module ProfilesDXF
        self.moduleProfilesDXF = WrapProfilesDXF(self.directory)
        self.widgetProfilesDXF = self.moduleProfilesDXF.widget
        self.ui.stackedWidget.insertWidget(11, self.widgetProfilesDXF)   
        
        # setup instance of module HEC2DXF
        self.moduleHEC2DXF = WrapHEC2DXF(self.directory)
        self.widgetHEC2DXF = self.moduleHEC2DXF.widget
        self.ui.stackedWidget.insertWidget(12, self.widgetHEC2DXF)  
        
        # setup instance of module XYZ2DXF
        self.moduleXYZ2DXF = WrapXYZ2DXF(self.directory)
        self.widgetXYZ2DXF = self.moduleXYZ2DXF.widget
        self.ui.stackedWidget.insertWidget(13, self.widgetXYZ2DXF)                

        # setup instance of module HyDesign
        self.moduleHyDesign = WrapHyDesign()
        self.widgetHyDesign = self.moduleHyDesign.widget
        self.ui.stackedWidget.insertWidget(14, self.widgetHyDesign)
        
        # actions in menu
        self.fileSetDirectory = self.createAction("Set working directory", slot=self.setDirectory)
        self.fileQuitAction = self.createAction("Close", slot=self.close, \
            shortcut="Ctrl+Q")
        self.fileSetExamples = self.createAction("Initialize examples", slot=self.initializeModules)
        self.helpAction = self.createAction("Help", slot=self.help, shortcut="F1")
        self.setDXFtoBKAction = self.createAction("DXF2BK", slot=self.setDXF2BK)
        self.setBK2DXFAction = self.createAction("BK2DXF", slot=self.setBK2DXF)
        self.setMeshAction = self.createAction("Mesh", slot=self.setMesh)
        self.setXMLAction = self.createAction("LandXML", slot=self.setLandXML)
        self.setScalarAction = self.createAction("ScalarDXF", slot=self.setScalarDXF)
        self.setVectorAction = self.createAction("VectorDXF", slot=self.setVectorDXF)
        self.setCSAction = self.createAction("CS", slot=self.setCS)
        self.set2DMAction = self.createAction("2DM2BK", slot=self.set2DM2BK)
        self.setCont2DXFAction = self.createAction("Cont2DXF", slot=self.setCont2DXF)
        self.setTubeAction = self.createAction("Tube", slot=self.setTube)
        self.setProfilesAction = self.createAction("XYZ2Profiles", slot=self.setXYZ2Profiles)
        self.setProfilesDXFAction = self.createAction("ProfilesDXF", slot=self.setProfilesDXF)
        self.setHEC2DXFAction = self.createAction("HEC2DXF", slot=self.setHEC2DXF)
        self.setXYZ2DXFAction = self.createAction("XYZ2DXF", slot=self.setXYZ2DXF)        
        self.setHyDesignAction = self.createAction("HyDesign", slot=self.setHyDesign)
        
        self.helpAboutAction = self.createAction("&About", \
            self.helpAbout)
        
        # create menu
        self.fileMenu = self.menuBar().addMenu("ChEsher")
        self.moduleMenu = self.menuBar().addMenu("Module")
        self.helpMenu = self.menuBar().addMenu("Help")
        
        # add actions to menu
        self.addActions(self.fileMenu, ( \
            self.fileSetDirectory, 
            self.fileSetExamples, 
            None, 
            self.fileQuitAction
            ))
            
        self.addActions(self.moduleMenu, ( \
            self.setDXFtoBKAction, \
            self.setBK2DXFAction,
            self.setMeshAction, 
            self.setXMLAction, 
            self.setScalarAction, 
            self.setVectorAction, 
            self.setCSAction, 
            self.set2DMAction,
            self.setCont2DXFAction,
            self.setTubeAction,
            self.setProfilesAction,
            self.setProfilesDXFAction,
            self.setHEC2DXFAction,
            self.setXYZ2DXFAction,
            self.setHyDesignAction
            ))
            
        self.addActions(self.helpMenu, (self.helpAction, None, self.helpAboutAction))

#        self.setDXF2BK()
#        self.setCont2DXF()
#        self.setTube()
#        self.setHEC2DXF()
#        self.setXYZ2Profiles()
        self.setProfilesDXF()
        self.initialize()
示例#2
0
class ChEsher(QtGui.QMainWindow):
    """Main class.

    Create menubar, toolbar, actions.
    Translate the application.
    Switch between module ENGINEERING and EDUCATION.

    """
    def __init__(self, app, parent=None):
        """Constructor for main class.

        Keyword arguments:
        app -- the application

        """
        super(ChEsher, self).__init__(parent)
        self._app = app
        
        # setup user interface of main window
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        # variables
        self.directory = ""

        # setup instance of module DXF2BK
        self.moduleDXF2BK = WrapDXF2BK(self.directory)
        self.widgetDXF2BK = self.moduleDXF2BK.widget
        self.ui.stackedWidget.insertWidget(0, self.widgetDXF2BK)        

        # setup instance of module BK2DXF
        self.moduleBK2DXF = WrapBK2DXF(self.directory)
        self.widgetBK2DXF = self.moduleBK2DXF.widget
        self.ui.stackedWidget.insertWidget(1, self.widgetBK2DXF)   

        # setup instance of module Mesh
        self.moduleMesh = WrapMesh(self.directory)
        self.widgetMesh = self.moduleMesh.widget
        self.ui.stackedWidget.insertWidget(2, self.widgetMesh)   

        # setup instance of module LandXML
        self.moduleLandXML = WrapLandXML(self.directory)
        self.widgetLandXML = self.moduleLandXML.widget
        self.ui.stackedWidget.insertWidget(3, self.widgetLandXML)   
        
        # setup instance of module ScalarDXF
        self.moduleScalarDXF = WrapScalarDXF(self.directory)
        self.widgetScalarDXF = self.moduleScalarDXF.widget
        self.ui.stackedWidget.insertWidget(4, self.widgetScalarDXF)  

        # setup instance of module VectorDXF
        self.moduleVectorDXF = WrapVectorDXF(self.directory)
        self.widgetVectorDXF = self.moduleVectorDXF.widget
        self.ui.stackedWidget.insertWidget(5, self.widgetVectorDXF)  

        # setup instance of module CS
        self.moduleCS = WrapCS(self.directory)
        self.widgetCS = self.moduleCS.widget
        self.ui.stackedWidget.insertWidget(6, self.widgetCS)  

        # setup instance of module 2DM2BK
        self.module2DM2BK = Wrap2DM2BK(self.directory)
        self.widget2DM2BK = self.module2DM2BK.widget
        self.ui.stackedWidget.insertWidget(7, self.widget2DM2BK)  

        # setup instance of module Cont2DXF
        self.moduleCont2DXF = WrapCont2DXF(self.directory)
        self.widgetCont2DXF = self.moduleCont2DXF.widget
        self.ui.stackedWidget.insertWidget(8, self.widgetCont2DXF)  
        
        # setup instance of module Tube
        self.moduleTube = WrapTube(self.directory)
        self.widgetTube = self.moduleTube.widget
        self.ui.stackedWidget.insertWidget(9, self.widgetTube)  

        # setup instance of module XYZ2Profiles
        self.moduleXYZ2Profiles = WrapXYZ2Profiles(self.directory)
        self.widgetXYZ2Profiles = self.moduleXYZ2Profiles.widget
        self.ui.stackedWidget.insertWidget(10, self.widgetXYZ2Profiles)    

        # setup instance of module ProfilesDXF
        self.moduleProfilesDXF = WrapProfilesDXF(self.directory)
        self.widgetProfilesDXF = self.moduleProfilesDXF.widget
        self.ui.stackedWidget.insertWidget(11, self.widgetProfilesDXF)   
        
        # setup instance of module HEC2DXF
        self.moduleHEC2DXF = WrapHEC2DXF(self.directory)
        self.widgetHEC2DXF = self.moduleHEC2DXF.widget
        self.ui.stackedWidget.insertWidget(12, self.widgetHEC2DXF)  
        
        # setup instance of module XYZ2DXF
        self.moduleXYZ2DXF = WrapXYZ2DXF(self.directory)
        self.widgetXYZ2DXF = self.moduleXYZ2DXF.widget
        self.ui.stackedWidget.insertWidget(13, self.widgetXYZ2DXF)                

        # setup instance of module HyDesign
        self.moduleHyDesign = WrapHyDesign()
        self.widgetHyDesign = self.moduleHyDesign.widget
        self.ui.stackedWidget.insertWidget(14, self.widgetHyDesign)
        
        # actions in menu
        self.fileSetDirectory = self.createAction("Set working directory", slot=self.setDirectory)
        self.fileQuitAction = self.createAction("Close", slot=self.close, \
            shortcut="Ctrl+Q")
        self.fileSetExamples = self.createAction("Initialize examples", slot=self.initializeModules)
        self.helpAction = self.createAction("Help", slot=self.help, shortcut="F1")
        self.setDXFtoBKAction = self.createAction("DXF2BK", slot=self.setDXF2BK)
        self.setBK2DXFAction = self.createAction("BK2DXF", slot=self.setBK2DXF)
        self.setMeshAction = self.createAction("Mesh", slot=self.setMesh)
        self.setXMLAction = self.createAction("LandXML", slot=self.setLandXML)
        self.setScalarAction = self.createAction("ScalarDXF", slot=self.setScalarDXF)
        self.setVectorAction = self.createAction("VectorDXF", slot=self.setVectorDXF)
        self.setCSAction = self.createAction("CS", slot=self.setCS)
        self.set2DMAction = self.createAction("2DM2BK", slot=self.set2DM2BK)
        self.setCont2DXFAction = self.createAction("Cont2DXF", slot=self.setCont2DXF)
        self.setTubeAction = self.createAction("Tube", slot=self.setTube)
        self.setProfilesAction = self.createAction("XYZ2Profiles", slot=self.setXYZ2Profiles)
        self.setProfilesDXFAction = self.createAction("ProfilesDXF", slot=self.setProfilesDXF)
        self.setHEC2DXFAction = self.createAction("HEC2DXF", slot=self.setHEC2DXF)
        self.setXYZ2DXFAction = self.createAction("XYZ2DXF", slot=self.setXYZ2DXF)        
        self.setHyDesignAction = self.createAction("HyDesign", slot=self.setHyDesign)
        
        self.helpAboutAction = self.createAction("&About", \
            self.helpAbout)
        
        # create menu
        self.fileMenu = self.menuBar().addMenu("ChEsher")
        self.moduleMenu = self.menuBar().addMenu("Module")
        self.helpMenu = self.menuBar().addMenu("Help")
        
        # add actions to menu
        self.addActions(self.fileMenu, ( \
            self.fileSetDirectory, 
            self.fileSetExamples, 
            None, 
            self.fileQuitAction
            ))
            
        self.addActions(self.moduleMenu, ( \
            self.setDXFtoBKAction, \
            self.setBK2DXFAction,
            self.setMeshAction, 
            self.setXMLAction, 
            self.setScalarAction, 
            self.setVectorAction, 
            self.setCSAction, 
            self.set2DMAction,
            self.setCont2DXFAction,
            self.setTubeAction,
            self.setProfilesAction,
            self.setProfilesDXFAction,
            self.setHEC2DXFAction,
            self.setXYZ2DXFAction,
            self.setHyDesignAction
            ))
            
        self.addActions(self.helpMenu, (self.helpAction, None, self.helpAboutAction))

#        self.setDXF2BK()
#        self.setCont2DXF()
#        self.setTube()
#        self.setHEC2DXF()
#        self.setXYZ2Profiles()
        self.setProfilesDXF()
        self.initialize()

    def setType(self):
        self.calcDischarge()
        self.updateUi()
  
    def initializeModules(self):
        answer = QMessageBox.question(self, "Initialize examples", "Do you really want to overwrite all inputs to initialize examples?", QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
        if answer == QtGui.QMessageBox.Yes:
            self.initialize()
        elif answer == QtGui.QMessageBox.No:
            return
        
    def initialize(self):
        
        def makedir(dir):
            if not os.path.exists(dir):
                os.makedirs(dir)
        
        abs_path = os.path.abspath('.')
        self.directory = os.path.join(abs_path, 'examples/').replace('\\', '/')

        makedir(self.directory + "example_01/output/")
        makedir(self.directory + "example_02/output/")  
        makedir(self.directory + "example_03/output/")
        makedir(self.directory + "example_04/output/")
        makedir(self.directory + "example_05/output/")
        makedir(self.directory + "example_06/output/")
        makedir(self.directory + "example_07/output/")
        makedir(self.directory + "example_08/output/")
        makedir(self.directory + "example_09/output/")
        makedir(self.directory + "example_10/output/")
        makedir(self.directory + "example_12/output/")
        makedir(self.directory + "example_13/output/")
        
        self.moduleDXF2BK.initialize()
        self.moduleBK2DXF.initialize()
        self.moduleMesh.initialize()
        self.moduleLandXML.initialize()
        self.moduleScalarDXF.initialize()
        self.moduleVectorDXF.initialize()   
        self.moduleCS.initialize()
        self.module2DM2BK.initialize()
        self.moduleCont2DXF.initialize()
        self.moduleTube.initialize()
        self.moduleXYZ2Profiles.initialize()
        self.moduleHEC2DXF.initialize()
        self.moduleProfilesDXF.initialize()
        
    def setDXF2BK(self):
        self.ui.labelModule.setText("~   Module DXF2BK   ~")
        self.ui.stackedWidget.setCurrentIndex(0)

    def setBK2DXF(self):
        self.ui.labelModule.setText("~   Module BK2DXF   ~")
        self.ui.stackedWidget.setCurrentIndex(1)

    def setMesh(self):
        self.ui.labelModule.setText("~   Module Mesh   ~")
        self.ui.stackedWidget.setCurrentIndex(2)

    def setLandXML(self):
        self.ui.labelModule.setText("~   Module LandXML   ~")
        self.ui.stackedWidget.setCurrentIndex(3)
        
    def setScalarDXF(self):
        self.ui.labelModule.setText("~   Module ScalarDXF   ~")
        self.ui.stackedWidget.setCurrentIndex(4)
 
    def setVectorDXF(self):
        self.ui.labelModule.setText("~   Module VectorDXF   ~")
        self.ui.stackedWidget.setCurrentIndex(5)
        
    def setCS(self):
        self.ui.labelModule.setText("~   Module CS   ~")
        self.ui.stackedWidget.setCurrentIndex(6)
        
    def set2DM2BK(self):
        self.ui.labelModule.setText("~   Module 2DM2BK   ~")
        self.ui.stackedWidget.setCurrentIndex(7)

    def setCont2DXF(self):
        self.ui.labelModule.setText("~   Module Cont2DXF   ~")
        self.ui.stackedWidget.setCurrentIndex(8)

    def setTube(self):
        self.ui.labelModule.setText("~   Module Tube   ~")
        self.ui.stackedWidget.setCurrentIndex(9)

    def setXYZ2Profiles(self):
        self.ui.labelModule.setText("~   Module XYZ2Profiles   ~")
        self.ui.stackedWidget.setCurrentIndex(10)
        
    def setProfilesDXF(self):
        self.ui.labelModule.setText("~   Module ProfilesDXF   ~")
        self.ui.stackedWidget.setCurrentIndex(11)
        
    def setHEC2DXF(self):
        self.ui.labelModule.setText("~   HEC2DXF   ~")
        self.ui.stackedWidget.setCurrentIndex(12)
        
    def setXYZ2DXF(self):
        self.ui.labelModule.setText("~   XYZ2DXF   ~")
        self.ui.stackedWidget.setCurrentIndex(13)
 
    def setHyDesign(self):
        self.ui.labelModule.setText("~   Module HyDesign   ~")
        self.ui.stackedWidget.setCurrentIndex(14)

    def setDirectory(self):
        
        dir = QFileDialog.getExistingDirectory(self, "Select directory", self.directory)
        
        if dir != "":
            
            self.moduleDXF2BK.setDir(dir)
            self.moduleBK2DXF.setDir(dir)
            self.moduleMesh.setDir(dir)
            self.moduleLandXML.setDir(dir)
            self.moduleScalarDXF.setDir(dir)
            self.moduleVectorDXF.setDir(dir)
            self.moduleCS.setDir(dir)
            self.module2DM2BK.setDir(dir)
            self.moduleCont2DXF.setDir(dir)
            self.moduleTube.setDir(dir)
            self.moduleProfiles.setDir(dir)
            self.moduleHEC2DXF.setDir(dir)
            self.moduleProfilesDXF.setDir(dir)

            self.directory = dir

        else:
            return

#    def interpolatePoint(self, xa, ya, za, xb, yb, zb, xc, yc, zc, xp, yp):
#        dot1 = (yb - ya)*(xp - xa) + (-xb + xa)*(yp - ya)
#        dot2 = (yc - yb)*(xp - xb) + (-xc + xb)*(yp - yb)
#        dot3 = (ya - yc)*(xp - xc) + (-xa + xc)*(yp - yc)
#
#        zp = 0.0
#        counter = 0 
#        if dot1 <= 0.0 and dot2 <= 0.0 and dot3 <= 0.0:
#
#            #Determine two vectors from the points:
#            v1 = [xc - xa, yc - ya, zc - za]
#            v2 = [xb - xa, yb - ya, zb - za]
#
#            #Determine the cross product of the two vectors:
#            cp = [v1[1] * v2[2] - v1[2] * v2[1],
#                  v1[2] * v2[0] - v1[0] * v2[2],
#                  v1[0] * v2[1] - v1[1] * v2[0]]
#
#            #A plane can be described using a simple equation ax + by + cz = d. The three coefficients from the cross product are a, b and c, and d can be solved by substituting a known point, for example the first:
#            a, b, c = cp
#            d = a * xa + b * ya + c * za
#
#            #Determine the z value at x, y. Re-arrange the simple equation, and solve for z:
#            zp = (d - a * xp - b * yp) / float(c)            
#            counter = 1
#        else:
#            counter = 0
#        return zp, counter
#    
#    def insideBoundingBox(self, xa, ya, xb, yb, xc, yc, xp, yp):
#
#        xMin = min([xa, xb, xc])
#        xMax = max([xa, xb, xc])
#        yMin = min([ya, yb, yc])
#        yMax = max([ya, yb, yc])
#
#        if xp >= xMin and xp <= xMax and yp >= yMin and yp <= yMax:
#            return True
#        else:
#            return False
#
#    def getTriangles(self, mesh, nodesMajor, nodesMinor):
#
#        x = []
#        y = []
#        zMajor = []
#        zMinor = []
#        
#        triangles = []
#        for nID in nodesMajor:
#            x.append(nodesMajor[nID][0])
#            y.append(nodesMajor[nID][1])
#            zMajor.append(nodesMajor[nID][2])
#            if nodesMinor is not None:
#                zMinor.append(nodesMinor[nID][2])
# 
#        for eID in mesh:
#            n1 = mesh[eID][0]-1
#            n2 = mesh[eID][1]-1
#            n3 = mesh[eID][2]-1
#            triangles.append([n1,n2,n3])
#              
#        return x, y, zMajor, zMinor, triangles
    
    def createAction(self, text="", slot=None, shortcut=None, icon=None,
                     tip=None, checkable=False, signal="triggered()"):
        """Create action out of keyword arguments. Return action.

        Keyword arguments:
        text -- User visible text (default "")
        slot -- function to call (default None)
        shortcut -- Key sequence (default None)
        icon -- Name of icon file (default None)
        tip -- Tooltip (default None)
        checkable -- Should action be checkable (default None)
        signal -- Signal to emit (default "triggered()")

        """
        action = QAction(text, self)
        if icon is not None:
            action.setIcon(QIcon(":/resource/{0}.png".format(icon)))
        if shortcut is not None:
            action.setShortcut(shortcut)
        if tip is not None:
            action.setToolTip(tip)
            action.setStatusTip(tip)
        if slot is not None:
            self.connect(action, SIGNAL(signal), slot)
        if checkable:
            action.setCheckable(True)
        return action

    def addActions(self, target, actions):
        """Add action or separator to menu.

        Keyword arguments:
        target -- name of menu
        actions -- tuple with names of actions

        """
        for action in actions:
            if action is None:
                target.addSeparator()
            else:
                target.addAction(action)

    def help(self):
        
        abs_path = os.path.abspath('.')
        filename = os.path.join(abs_path, 'documentation/00_index.html')
        webbrowser.open(filename)

    def helpAbout(self):
        """Setup the About-dialog."""
        msg = u"""<p><b>ChEsher</b> V 1.0</p>
                    <p>Additional tool to <a href="http://www.nrc-cnrc.gc.ca/eng/solutions/advisory/blue_kenue_index.html">Blue Kenue&trade;</a> that is a pre and post processing software for the <a href="http://www.opentelemac.org/">open TELEMAC-MASCARET</a> system - an integrated suite of solvers for use in the field of free-surface flow of hydraulic modeling. </p>
                    <p>Copyright \u00A9 2016 <a href="mailto:[email protected]?subject=ChEsher">Reinhard Flei\xdfner</a></p>
                    <hr/>
                    <p>Python {0} - Qt {1} - PyQt {2} - {3}</p>""".format(
                    platform.python_version(),
                    QT_VERSION_STR,
                    PYQT_VERSION_STR,
                    platform.system()
                    )
        QMessageBox.about(self, "About ChEsher", msg)