def accept(self):
        aDirLE                      = self.findChild(QLineEdit,"StudyDirName")
        aNameLE                     = self.findChild(QLineEdit,"StudyLineEdit")
        aCaseLE                     = self.findChild(QLineEdit,"CaseLineEdit")
        CreateOption                = self.findChild(QCheckBox,"checkBoxCreate")
        Neptune                     = self.findChild(QRadioButton,"radioButtonNeptune")
        Saturne                     = self.findChild(QRadioButton,"radioButtonSaturne")
        self.CaseNames              = str(self.findChild(QLineEdit,"CaseLineEdit").text())
        self.CopyFromOption         = self.findChild(QCheckBox, "checkBoxCopyFrom").isChecked()
        self.CouplingSaturneSyrthes = self.findChild(QCheckBox, "checkBoxCouplingSaturneSyrthes").isChecked()
        self.Nprocs                 = str(self.findChild(QLineEdit,"NprocsLineEdit").text())
        if  aNameLE.text() == "" :
            mess = cfdstudyMess.trMessage(self.tr("LOCATION_DLG_ERROR_MESS"),[])
            cfdstudyMess.criticalMessage(mess)
            return False

        # check study directory
        aStudyDir = str(aDirLE.text())
        # Load from study dir + study name
        if aNameLE.text() != aNameLE.text():
            raise ValueError("Names must not contain special characters.")

        aStudyDirName = str(aNameLE.text())
        self.StudyPath = os.path.join(aStudyDir, aStudyDirName)
        self.StudyName = aStudyDirName

        if Neptune.isChecked():
            self.code = "NEPTUNE_CFD"
        else:
            self.code = "Code_Saturne"

        if self.checkBoxLoad.isChecked():
            if self.StudyName == '':
                mess = cfdstudyMess.trMessage(self.tr("LOCATION_DLG_ERROR_MESS"),[])
                cfdstudyMess.criticalMessage(mess)
                self.reinit()
                return False
            if not CFDSTUDYGUI_Commons.isaSaturneSyrthesCouplingStudy(self.StudyPath):
                if not CFDSTUDYGUI_Commons.isaCFDStudy(self.StudyPath):
#                   search if the cfd study directory self.StudyPath is in fact a cfd case directory: by calling  method isaCFDCase
                    if not CFDSTUDYGUI_Commons.isaCFDCase(self.StudyPath):
                        mess = cfdstudyMess.trMessage(self.tr("NOT_A_STUDY_OR_CASE_DIRECTORY"),[self.StudyPath,"CFD","SYRTHES"])
                        cfdstudyMess.criticalMessage(mess)
                        self.reinit()
                        return False
        # ckeck case name
        if self.checkBoxCreate.isChecked() :
            if self.StudyName == '':
                mess = cfdstudyMess.trMessage(self.tr("LOCATION_DLG_ERROR_MESS"),[aStudyDir])
                cfdstudyMess.criticalMessage(mess)
                return False
            self.CaseNames = str(aCaseLE.text())
            self.CreateOption = True
            if self.CouplingSaturneSyrthes :
                self.SyrthesCase = str(self.findChild(QLineEdit,"syrthesCase").text())
                if self.SyrthesCase == "":
                    mess = cfdstudyMess.trMessage(self.tr("EMPTY_SYRTHES_CASENAME_MESS"),[])
                    cfdstudyMess.criticalMessage(mess)
                    return False
        SetTreeLocationDialog.accept(self)
    def slotUpdateData(self):
        log.debug("slotUpdateData")
        self.ActivateBtn.setEnabled(True)
        self.FileCB.clear()

        if self.CaseCB.currentText() == None:
            self.FileCheckBox.setEnabled(False)
            self.FileCB.setEnabled(False)
        else:
            self.FileCheckBox.setEnabled(True)
            self.FileCB.clear()

            # current case
            aCaseName = str(self.CaseCB.currentText())
            if aCaseName == "":
                self.ActivateBtn.setEnabled(False)
                return

            aCase = None
            aCases =  CFDSTUDYGUI_DataModel.GetCaseList(self.CurrentStudy)
            for c in aCases:
                if c.GetName() == aCaseName:
                    aCase = c
                    break

            if aCase == None:
                self.ActivateBtn.setEnabled(False)
                return

            # object of DATA folder
            aChildList = CFDSTUDYGUI_DataModel.ScanChildren(aCase, "DATA")
            if not len(aChildList) == 1:
                self.ActivateBtn.setEnabled(False)
                return
            aDataObj =  aChildList[0]

            #fill File combo-box
            if self.xmlfile == "" :
                aFileList = CFDSTUDYGUI_DataModel.ScanChildNames(aDataObj, ".*\.xml$")
                if len(aFileList) == 0:
                    self.FileCheckBox.setEnabled(False);

                for i in aFileList:
                    self.FileCB.addItem(i)

                self.FileCB.setEnabled(self.FileCheckBox.isChecked())
            else :
                self.FileCB.addItem(self.xmlfile)
                self.FileCB.setEnabled(self.FileCheckBox.isChecked())

            #check for activation file SaturneGUI or NeptuneGUI
            if not CFDSTUDYGUI_DataModel.checkCaseLaunchGUI(aCase):
                #Warning message
                if CFD_Code() == CFD_Saturne:
                    mess = cfdstudyMess.trMessage(self.tr("ICSACTIVATE_DLG_BAD_CASE_MESS"),[])
                elif CFD_Code() == CFD_Neptune:
                    mess = cfdstudyMess.trMessage(self.tr("IPBACTIVATE_DLG_BAD_CASE_MESS"),[])
                cfdstudyMess.warningMessage(mess)
                self.ActivateBtn.setEnabled(False)
 def accept(self):
     iok, mess = CheckCFD_CodeEnv(CFD_Code())
     if iok:
         if mess != "" :
             mess = cfdstudyMess.trMessage(self.tr("CFDSTUDY_INVALID_ENV"),[]) + mess
             cfdstudyMess.criticalMessage(mess)
         else :
             InfoDialog.accept(self)
     else:
         mess = cfdstudyMess.trMessage(self.tr("INFO_DLG_INVALID_ENV"),[]) + mess
         cfdstudyMess.criticalMessage(mess)
Exemplo n.º 4
0
    def slotCopyFrom(self):
        """
        Call into ui_SetTreeLocationDialog.py from setTreeLocationDialog.ui built with qtdesigner
        for option --copy-from
        """

        if not self.findChild(QCheckBox, "checkBoxCopyFrom").isChecked():
            self.findChild(QWidget, "copyFromCase_widget").hide()
            return

        CopyFromCasePath = ""
        if self.findChild(QLineEdit, "StudyDirName").text() != "":
            CopyFromCasePath = QFileDialog.getExistingDirectory(
                None, ObjectTR.tr("SET_CASE_LOCATION_BROWSE_CAPTION"))

            if CopyFromCasePath == None or str(CopyFromCasePath) == "":
                self.findChild(QCheckBox, "checkBoxCopyFrom").setChecked(False)
                return

        self.CaseRefName = os.path.abspath(str(CopyFromCasePath))
        # check if it is a case directory
        if not self.isCfdCaseDir(self.CaseRefName):
            mess = cfdstudyMess.trMessage(self.tr("CASE_DLG_ERROR_MESS"),
                                          [self.CaseRefName])
            cfdstudyMess.aboutMessage(mess)
            self.findChild(QWidget, "copyFromCase_widget").hide()
            self.findChild(QCheckBox, "checkBoxCopyFrom").setChecked(False)
            return
        CaseRefDATAPath = os.path.join(self.CaseRefName, "DATA")
        if "NeptuneGUI" in os.listdir(CaseRefDATAPath) and self.findChild(
                QRadioButton, "radioButtonSaturne").isChecked():
            mess = cfdstudyMess.trMessage(
                self.tr("CASE_COPYFROM_NEPTUNE_DLG_ERROR_MESS"), [])
            cfdstudyMess.aboutMessage(mess)
            self.findChild(QWidget, "copyFromCase_widget").hide()
            self.findChild(QCheckBox, "checkBoxCopyFrom").setChecked(False)
            return
        if "SaturneGUI" in os.listdir(CaseRefDATAPath) and self.findChild(
                QRadioButton, "radioButtonNeptune").isChecked():
            mess = cfdstudyMess.trMessage(
                self.tr("CASE_COPYFROM_SATURNE_DLG_ERROR_MESS"), [])
            cfdstudyMess.aboutMessage(mess)
            self.findChild(QWidget, "copyFromCase_widget").hide()
            self.findChild(QCheckBox, "checkBoxCopyFrom").setChecked(False)
            return

        self.findChild(QWidget, "copyFromCase_widget").show()
        self.findChild(QLineEdit, "copyFromCase").setText(self.CaseRefName)
        self.findChild(QDialogButtonBox, "buttonBox").button(
            QDialogButtonBox.Ok).setEnabled(True)
Exemplo n.º 5
0
def isaSaturneSyrthesCouplingStudy(theStudyPath):
    log.debug("isaSaturneSyrthesCouplingStudy")
    iok = False
    hasCFDCase     = False
    hasSyrthesCase = False
    if not os.path.isdir(theStudyPath):
        mess = cfdstudyMess.trMessage(ObjectTR.tr("MUST_BE_A_DIRECTORY"),[theStudyPath])
        cfdstudyMess.criticalMessage(mess)
        return False
    # TODO replace by a more robust test, using a query function of the
    # main code_saturne command or subcommand (to be added)
    dirList = os.listdir(theStudyPath)
    if not (dirList.count("RESU_COUPLING") and dirList.count("run.cfg")):
        return False
    for i in dirList:
        ipath = os.path.join(theStudyPath,i)
        if os.path.isdir(ipath):
            if i not in ["MESH", "RESU_COUPLING"]:
                if isaCFDCase(ipath):
                    hasCFDCase = True
                if isSyrthesCase(ipath):
                    hasSyrthesCase = True
    if hasCFDCase and hasSyrthesCase:
        iok = True
    return iok
Exemplo n.º 6
0
def isaSaturneSyrthesCouplingStudy(theStudyPath):
    log.debug("isaSaturneSyrthesCouplingStudy")
    iok = False
    hasCFDCase = False
    hasSyrthesCase = False
    if not os.path.isdir(theStudyPath):
        mess = cfdstudyMess.trMessage(ObjectTR.tr("MUST_BE_A_DIRECTORY"),
                                      [theStudyPath])
        cfdstudyMess.criticalMessage(mess)
        return False
    dirList = os.listdir(theStudyPath)
    if not (dirList.count("MESH") and dirList.count("RESU_COUPLING")
            and dirList.count("coupling_parameters.py")
            and dirList.count("runcase")):
        return False
    for i in dirList:
        ipath = os.path.join(theStudyPath, i)
        if os.path.isdir(ipath):
            if i not in ["MESH", "RESU_COUPLING"]:
                if isaCFDCase(ipath):
                    hasCFDCase = True
                if isSyrthesCase(ipath):
                    hasSyrthesCase = True
    if hasCFDCase and hasSyrthesCase:
        iok = True
    return iok
def activate():
    """
    This method is called when GUI module is being activated.

    @rtype: C{True} or C{False}
    @return: C{True} only if the activation is successful.
    """
    log.debug("activate")
    dsk = sgPyQt.getDesktop()
    dsk.setTabPosition(Qt.RightDockWidgetArea,QTabWidget.South)
    dsk.setTabPosition(Qt.LeftDockWidgetArea,QTabWidget.South)

    ActionHandler = _DesktopMgr.getActionHandler(dsk)

    env_saturne, msg = CheckCFD_CodeEnv(CFD_Saturne)

    log.debug("activate -> env_saturne = %s" % env_saturne)

    if not env_saturne:
        QMessageBox.critical(ActionHandler.dskAgent().workspace(),
                             "Error", msg, QMessageBox.Ok, 0)
        return False

    if msg != "":
        mess = cfdstudyMess.trMessage(ObjectTR.tr("CFDSTUDY_INVALID_ENV"),[]) + " ; "+ msg
        cfdstudyMess.aboutMessage(msg)
        return False
    else:
        ActionHandler.DialogCollector.InfoDialog.setCode(env_saturne)

    ActionHandler._SalomeSelection.currentSelectionChanged.connect(ActionHandler.updateActions)

    ActionHandler.connectSolverGUI()

    # Hide the Python Console window layout
    for dock in sgPyQt.getDesktop().findChildren(QDockWidget):
        dockTitle = dock.windowTitle()
        log.debug("activate -> QDockWidget: %s" % dockTitle)
        if "Object Browser" in str(dockTitle):
            dock.raise_()
            dock.show()
            if dsk.dockWidgetArea(dock) == 0:
                dsk.addDockWidget(Qt.LeftDockWidgetArea,dock)
        if dockTitle in ("Python Console", "Console Python",  "Message Window"):
            dock.setVisible(False)
            dock.hide()
    return True
Exemplo n.º 8
0
def CheckCFD_CodeEnv(code):
    """
    This method try to found the config file of the CFD I{code}.

    @param code: name of the searching code (CFD_Saturne or CFD_Neptune).
    @type theType: C{String}
    @rtype: C{True} or C{False}
    @return: C{True} if the searching code is found.
    """
    mess = ""
    prefix = ""
    bindir = ""

    if code not in [CFD_Saturne, CFD_Neptune]:
        mess = cfdstudyMess.trMessage(ObjectTR.tr("CFDSTUDY_INVALID_SOLVER_NAME"),[code,CFD_Saturne,CFD_Neptune])
        iok= False
        return iok,mess

    if code == CFD_Saturne:
        try:
            from code_saturne.cs_package import package
            iok = True
        except ImportError as e:
            mess = cfdstudyMess.trMessage(ObjectTR.tr("INFO_DLG_INVALID_ENV"),[code]) + e.__str__()
            if "cs_package" in e.__str__():
                mess = mess + cfdstudyMess.trMessage(ObjectTR.tr("CHECK_CODE_PACKAGE"),["cs_package",code])
            elif "code_saturne" in e.__str__():
                mess = mess + cfdstudyMess.trMessage(ObjectTR.tr("CHECK_PYTHON_PATH"),[])
            iok = False
    elif code == CFD_Neptune:
        try:
            from neptune_cfd.nc_package import package
            iok = True
        except ImportError as e:
            mess = cfdstudyMess.trMessage(ObjectTR.tr("INFO_DLG_INVALID_ENV"),[code]) + e.__str__()
            if "nc_package" in e.__str__():
                mess = mess + cfdstudyMess.trMessage(ObjectTR.tr("CHECK_CODE_PACKAGE"),["nc_package",code])
            elif "neptune_cfd" in e.__str__():
                mess = mess + cfdstudyMess.trMessage(ObjectTR.tr("CHECK_PYTHON_PATH"),[])
            iok = False
    else:
        raise ValueError("Invalid name of solver!")

    if iok:
        pkg = package()
        prefix = pkg.get_dir('prefix')
        log.debug("CheckCFD_CodeEnv -> prefix = %s" % (prefix))

        bindir = pkg.get_dir('bindir')
        log.debug("CheckCFD_CodeEnv -> prefix = %s" % (bindir))

        if not os.path.exists(prefix):
            mess = cfdstudyMess.trMessage(ObjectTR.tr("ENV_DLG_INVALID_DIRECTORY"),[prefix])
            iok = False
        else:
            if not os.path.exists(bindir):
                mess = cfdstudyMess.trMessage(ObjectTR.tr("ENV_DLG_INVALID_DIRECTORY"),[bindir])
                iok = False

    log.debug("CheckCFD_CodeEnv -> %s = %s" % (code, iok))
    log.debug("CheckCFD_CodeEnv -> %s: %s" % (code, mess))
    return iok, mess
Exemplo n.º 9
0
def activate():
    """
    This method is called when GUI module is being activated.

    @rtype: C{True} or C{False}
    @return: C{True} only if the activation is successful.
    """
    log.debug("activate")
    global d_activation, studyId
    dsk = sgPyQt.getDesktop()
    studyId = sgPyQt.getStudyId()
    dsk.setTabPosition(Qt.RightDockWidgetArea, QTabWidget.South)
    dsk.setTabPosition(Qt.LeftDockWidgetArea, QTabWidget.South)

    if salome_version.getVersion() <= '7.4.0':
        if salome.myStudy.FindComponent(__MODULE_NAME__) == None:
            CFDSTUDYGUI_SolverGUI._c_CFDGUI.cleanAllDock(sgPyQt.getDesktop())
            log.debug(
                "activate ->  CFDSTUDYGUI_SolverGUI._c_CFDGUI.d_CfdCases = %s"
                % CFDSTUDYGUI_SolverGUI._c_CFDGUI.d_CfdCases)
    # instance of the CFDSTUDYGUI_ActionsHandler class for the current desktop
    ActionHandler = _DesktopMgr.getActionHandler(dsk)

    if studyId not in list(d_activation.keys()):
        d_activation[studyId] = 1

    if d_activation[studyId] == 1:
        d_activation[studyId] = 0
        env_saturne, mess1 = CheckCFD_CodeEnv(CFD_Saturne)
        env_neptune, mess2 = CheckCFD_CodeEnv(CFD_Neptune)

        log.debug("activate -> env_saturne = %s" % env_saturne)
        log.debug("activate -> env_neptune = %s" % env_neptune)

        if not env_saturne and not env_neptune:
            QMessageBox.critical(ActionHandler.dskAgent().workspace(), "Error",
                                 mess1, QMessageBox.Ok, 0)
            QMessageBox.critical(ActionHandler.dskAgent().workspace(), "Error",
                                 mess2, QMessageBox.Ok, 0)
            d_activation[studyId] = 1
            return False

        if env_neptune:
            if mess2 != "":
                mess = cfdstudyMess.trMessage(
                    ObjectTR.tr("CFDSTUDY_INVALID_ENV"), []) + " ; " + mess2
                cfdstudyMess.aboutMessage(mess)
                d_activation[studyId] = 1
                return False
            else:
                ActionHandler.DialogCollector.InfoDialog.setCode(
                    env_saturne, env_neptune)

        elif env_saturne:
            if mess1 != "":
                mess = cfdstudyMess.trMessage(
                    ObjectTR.tr("CFDSTUDY_INVALID_ENV"), []) + " ; " + mess2
                cfdstudyMess.aboutMessage(mess)
                d_activation[studyId] = 1
                return False
            else:
                ActionHandler.DialogCollector.InfoDialog.setCode(
                    env_saturne, False)

    ActionHandler._SalomeSelection.currentSelectionChanged.connect(
        ActionHandler.updateActions)

    ActionHandler.connectSolverGUI()
    ActionHandler.updateObjBrowser()

    # Hide the Python Console window layout
    for dock in sgPyQt.getDesktop().findChildren(QDockWidget):
        dockTitle = dock.windowTitle()
        log.debug("activate -> QDockWidget: %s" % dockTitle)
        if dockTitle in ("Python Console", "Console Python", "Message Window"):
            dock.setVisible(False)

    return True
Exemplo n.º 10
0
def CheckCFD_CodeEnv(code):
    """
    This method try to found the config file of the CFD I{code}.

    @param code: name of the searching code (CFD_Saturne or CFD_Neptune).
    @type theType: C{String}
    @rtype: C{True} or C{False}
    @return: C{True} if the searching code is found.
    """
    mess = ""
    prefix = ""
    bindir = ""

    if code not in [CFD_Saturne, CFD_Neptune]:
        mess = cfdstudyMess.trMessage(ObjectTR.tr("CFDSTUDY_INVALID_SOLVER_NAME"),
                                      [code,CFD_Saturne,CFD_Neptune])
        iok= False
        return iok, mess

    else:
        iok = False
        _solver_name = getCFDSolverName(code);
        try:
            from code_saturne.cs_package import package
            pkg = package(name = _solver_name)
            b = os.path.join(pkg.get_dir('bindir'),
                             _solver_name+pkg.config.shext)
            if os.path.isfile(b):
                iok = True
            else:
                mess = cfdstudyMess.trMessage(ObjectTR.tr("INFO_DLG_INVALID_ENV"),
                                              [code]) + e.__str__()
                mess += cfdstudyMess.trMessage(ObjectTR.tr("CHECK_CODE_INSTALLATION"),
                                               [_solver_name,code])

        except:
            mess = cfdstudyMess.trMessage(ObjectTR.tr("INFO_DLG_INVALID_ENV"),
                                          [code]) + e.__str__()
            if "cs_package" in e.__str__():
                mess += cfdstudyMess.trMessage(ObjectTR.tr("CHECK_CODE_PACKAGE"),
                                               ["cs_package",code])
            elif _solver_name in e.__str__():
                mess += cfdstudyMess.trMessage(ObjectTR.tr("CHECK_CODE_PACKAGE"),
                                               [_solver_name,code])

    if iok:
        _solver_name = getCFDSolverName(code);
        pkg = package(name = _solver_name)
        prefix = pkg.get_dir('prefix')
        log.debug("CheckCFD_CodeEnv -> prefix = %s" % (prefix))

        bindir = pkg.get_dir('bindir')
        log.debug("CheckCFD_CodeEnv -> prefix = %s" % (bindir))

        if not os.path.exists(prefix):
            mess = cfdstudyMess.trMessage(ObjectTR.tr("ENV_DLG_INVALID_DIRECTORY"),
                                          [prefix])
            iok = False
        else:
            if not os.path.exists(bindir):
                mess = cfdstudyMess.trMessage(ObjectTR.tr("ENV_DLG_INVALID_DIRECTORY"),
                                              [bindir])
                iok = False

    log.debug("CheckCFD_CodeEnv -> %s = %s" % (code, iok))
    log.debug("CheckCFD_CodeEnv -> %s: %s" % (code, mess))
    return iok, mess