Ejemplo n.º 1
0
 def on_ok(self):
     """ Applies the current dialog data onto the main data structure. """
     Case.the(
     ).constants.lattice_bound = self.lattice_input.currentIndex() + 1
     Case.the(
     ).constants.lattice_fluid = self.lattice2_input.currentIndex() + 1
     Case.the().constants.gravity = [
         float(self.gravityx_input.text()),
         float(self.gravityy_input.text()),
         float(self.gravityz_input.text())
     ]
     Case.the().constants.rhop0 = float(self.rhop0_input.text())
     Case.the().constants.hswl = float(self.hswl_input.text())
     Case.the().constants.hswl_auto = self.hswlauto_chk.isChecked()
     Case.the().constants.gamma = float(self.gamma_input.text())
     Case.the().constants.speedsystem = float(self.speedsystem_input.text())
     Case.the(
     ).constants.speedsystem_auto = self.speedsystemauto_chk.isChecked()
     Case.the().constants.coefsound = float(self.coefsound_input.text())
     Case.the().constants.speedsound = float(self.speedsound_input.text())
     Case.the(
     ).constants.speedsound_auto = self.speedsoundauto_chk.isChecked()
     Case.the().constants.coefh = float(self.coefh_input.text())
     Case.the().constants.cflnumber = float(self.cflnumber_input.text())
     Case.the().constants.h = float(self.h_input.text())
     Case.the().constants.h_auto = self.hauto_chk.isChecked()
     Case.the().constants.b = float(self.b_input.text())
     Case.the().constants.b_auto = self.bauto_chk.isChecked()
     log("Constants changed")
     self.accept()
 def on_cancel():
     log(__("Stopping simulation"))
     if process:
         process.kill()
     run_dialog.hide_all()
     Case.the().info.is_simulation_done = True
     self.simulation_cancelled.emit()
        def on_dsph_sim_finished(exit_code):
            """ Simulation finish handler. Defines what happens when the process finishes."""

            # Reads output and completes the progress bar
            output = str(process.readAllStandardOutput().data(), encoding='utf-8')

            run_dialog.set_detail_text(str(output))
            run_dialog.run_complete()

            run_fs_watcher.removePath(Case.the().path + "/" + Case.the().name + "_out/")

            if exit_code == 0:
                # Simulation went correctly
                Case.the().info.is_simulation_done = True
                Case.the().info.needs_to_run_gencase = False
                self.simulation_complete.emit(True)
            else:
                # In case of an error
                Case.the().info.needs_to_run_gencase = True
                if "exception" in str(output).lower():
                    log("There was an error on the execution. Opening an error dialog for that.")
                    run_dialog.hide()
                    self.simulation_complete.emit(False)
                    error_dialog(__("An error occurred during execution. Make sure that parameters exist and are properly defined. "
                                    "You can also check your execution device (update the driver of your GPU). Read the details for more information."), str(output))
            save_case(Case.the().path, Case.the())
Ejemplo n.º 4
0
def selection_monitor(properties_widget, designsphysics_dock):
    """ Watches and fixes unwanted changes in the current selection. """
    time.sleep(2.0)
    while True:
        try:
            if not valid_document_environment():
                log("Invalid document environment found. Disabling case-related tools."
                    )
                designsphysics_dock.adapt_to_no_case()
                time.sleep(1.0)
                continue

            if not FreeCADGui.Selection.getSelection():
                properties_widget.configure_to_no_selection()

            enforce_case_limits_restrictions(Case.the().mode3d)
            enforce_fillbox_restrictions()

            # Adjust damping properties when freecad related properties change
            for name, damping_zone in Case.the().damping_zones.items():
                if FreeCAD.ActiveDocument:
                    damping_group = FreeCAD.ActiveDocument.getObject(name)
                    if len(damping_group.OutList) == 2:
                        damping_zone.overlimit = damping_group.OutList[
                            1].Length.Value / DIVIDER

            time.sleep(0.5)
        except AttributeError:
            time.sleep(1.0)
Ejemplo n.º 5
0
def prompt_close_all_documents(prompt: bool = True) -> bool:
    """ Shows a dialog to close all the current documents.
        If accepted, close all the current documents and return True, else returns False. """
    if prompt:
        user_selection = ok_cancel_dialog(APP_NAME,
                                          "All documents will be closed")
    if not prompt or user_selection == QtGui.QMessageBox.Ok:
        # Close all current documents.
        log(__("Closing all current documents"))
        for doc in FreeCAD.listDocuments().keys():
            FreeCAD.closeDocument(doc)
        return True
    return False
Ejemplo n.º 6
0
 def on_cancel(self):
     """ Closes the dialog rejecting it. """
     log("Constants not changed")
     self.reject()
Ejemplo n.º 7
0
def boot():
    """ Boots the application. """
    print_license()
    check_compatibility()

    try:
        master_branch_version = str(
            urlopen(GITHUB_MASTER_CONSTANTS_URL).read()).split(
                "VERSION = \"")[-1].split("\"")[0]
        if VERSION < master_branch_version and NOTIFY_ON_OUTDATED_VERSION:
            info_dialog(
                __("Your version of DesignSPHyiscs is outdated. Please go to the Addon Manager and update it. New versions include bug fixes, new features and new DualSPHysics executables, among other things."
                   ),
                __("The version you're using is {} while the version that you can update to is {}"
                   ).format(VERSION, master_branch_version))
    except URLError:
        log("No network connection or Git repo is down. Skipping version check."
            )

    if document_count() > 0:
        success = prompt_close_all_documents()
        if not success:
            debug(
                "User chose not to close the currently opened documents. Aborting startup"
            )
            quit()

    # Tries to delete docks created by a previous execution of DesignSPHysics
    delete_existing_docks()

    designsphysics_dock = DesignSPHysicsDock(get_fc_main_window())
    properties_widget = PropertiesDockWidget(parent=get_fc_main_window())

    get_fc_main_window().addDockWidget(QtCore.Qt.RightDockWidgetArea,
                                       designsphysics_dock)
    get_fc_main_window().addDockWidget(QtCore.Qt.LeftDockWidgetArea,
                                       properties_widget)

    # Subscribe the FreeCAD Objects tree to the item selection change function.
    # This helps FreeCAD notify DesignSPHysics for the deleted and changed objects to get updated correctly.
    fc_object_tree: QtGui.QTreeWidget = get_fc_main_window().findChildren(
        QtGui.QSplitter)[0].findChildren(QtGui.QTreeWidget)[0]
    fc_object_tree.itemSelectionChanged.connect(
        lambda p=properties_widget, d=designsphysics_dock:
        on_tree_item_selection_change(p, d))
    debug(
        "Subscribing selection change monitor handler to freecad object tree item changed."
    )

    properties_widget.need_refresh.connect(
        lambda p=properties_widget, d=designsphysics_dock:
        on_tree_item_selection_change(p, d))
    designsphysics_dock.need_refresh.connect(
        lambda p=properties_widget, d=designsphysics_dock:
        on_tree_item_selection_change(p, d))

    # Launch a monitor thread that ensures some things are not changed.
    monitor_thread = threading.Thread(
        target=lambda p=properties_widget, d=designsphysics_dock:
        selection_monitor(p, d))
    monitor_thread.start()

    FreeCADGui.activateWorkbench(DEFAULT_WORKBENCH)
    log(__("Initialization finished for {} v{}").format(APP_NAME, VERSION))
    def on_ok(self):
        """ Applies the data from the dialog onto the main data structure. """
        Case.the().execution_parameters.saveposdouble = int(
            self.saveposdouble_input.currentIndex())
        Case.the().execution_parameters.boundary = int(
            self.boundary_input.currentIndex() + 1)
        Case.the().execution_parameters.stepalgorithm = int(
            self.stepalgorithm_input.currentIndex() + 1)
        Case.the().execution_parameters.verletsteps = int(
            self.verletsteps_input.text())
        Case.the().execution_parameters.kernel = int(
            self.kernel_input.currentIndex() + 1)
        Case.the().execution_parameters.viscotreatment = int(
            self.viscotreatment_input.currentIndex() + 1)
        Case.the().execution_parameters.visco = float(self.visco_input.text())
        Case.the().execution_parameters.viscoboundfactor = int(
            self.viscoboundfactor_input.text())
        Case.the().execution_parameters.densitydt_type = int(
            self.densitydt_type_input.currentIndex())
        Case.the().execution_parameters.densitydt_value = float(
            self.densitydt_input.text())
        Case.the().execution_parameters.shifting = int(
            self.shifting_input.currentIndex())
        Case.the().execution_parameters.shiftcoef = float(
            self.shiftcoef_input.text())
        Case.the().execution_parameters.shifttfs = float(
            self.shifttfs_input.text())
        Case.the().execution_parameters.rigidalgorithm = int(
            self.rigidalgorithm_input.currentIndex() + 1)
        Case.the().execution_parameters.ftpause = float(
            self.ftpause_input.text())
        Case.the().execution_parameters.coefdtmin = float(
            self.coefdtmin_input.text())
        Case.the().execution_parameters.dtini = float(self.dtini_input.text())
        Case.the(
        ).execution_parameters.dtini_auto = self.dtiniauto_chk.isChecked()
        Case.the().execution_parameters.dtmin = float(self.dtmin_input.text())
        Case.the(
        ).execution_parameters.dtmin_auto = self.dtminauto_chk.isChecked()
        Case.the().execution_parameters.dtfixed = str(
            self.dtfixed_input.text())
        Case.the().execution_parameters.dtallparticles = int(
            self.dtallparticles_input.text())
        Case.the().execution_parameters.timemax = float(
            self.timemax_input.text())
        Case.the().execution_parameters.timeout = float(
            self.timeout_input.text())
        Case.the().execution_parameters.partsoutmax = float(
            self.partsoutmax_input.text()) / 100
        Case.the().execution_parameters.rhopoutmin = int(
            self.rhopoutmin_input.text())
        Case.the().execution_parameters.rhopoutmax = int(
            self.rhopoutmax_input.text())

        Case.the().periodicity = Periodicity()
        Case.the().periodicity.x_periodicity = PeriodicityInfo(
            self.period_x_chk.isChecked(),
            float(self.period_x_inc_x_input.text()),
            float(self.period_x_inc_y_input.text()),
            float(self.period_x_inc_z_input.text()))

        Case.the().periodicity.y_periodicity = PeriodicityInfo(
            self.period_y_chk.isChecked(),
            float(self.period_y_inc_x_input.text()),
            float(self.period_y_inc_y_input.text()),
            float(self.period_y_inc_z_input.text()))

        Case.the().periodicity.z_periodicity = PeriodicityInfo(
            self.period_z_chk.isChecked(),
            float(self.period_z_inc_x_input.text()),
            float(self.period_z_inc_y_input.text()),
            float(self.period_z_inc_z_input.text()))

        if self.simdomain_chk.isChecked():
            Case.the().domain.enabled = True
            # IncZ must be 0 in simulations with specified domain
            Case.the().execution_parameters.incz = 0

            Case.the().domain.posmin_x = SDPositionProperty(
                self.simdomain_posminx_combobox.currentIndex(),
                float(self.simdomain_posminx_line_edit.text()))
            Case.the().domain.posmin_y = SDPositionProperty(
                self.simdomain_posminy_combobox.currentIndex(),
                float(self.simdomain_posminy_line_edit.text()))
            Case.the().domain.posmin_z = SDPositionProperty(
                self.simdomain_posminz_combobox.currentIndex(),
                float(self.simdomain_posminz_line_edit.text()))

            Case.the().domain.posmax_x = SDPositionProperty(
                self.simdomain_posmaxx_combobox.currentIndex(),
                float(self.simdomain_posmaxx_line_edit.text()))
            Case.the().domain.posmax_y = SDPositionProperty(
                self.simdomain_posmaxy_combobox.currentIndex(),
                float(self.simdomain_posmaxy_line_edit.text()))
            Case.the().domain.posmax_z = SDPositionProperty(
                self.simdomain_posmaxz_combobox.currentIndex(),
                float(self.simdomain_posmaxz_line_edit.text()))
        else:
            Case.the().domain.enabled = False
            Case.the().reset_simulation_domain()

        log("Execution Parameters changed")
        self.accept()
 def on_cancel(self):
     """ Canceles the dialog rejecting it. """
     log("Execution Parameters not changed")
     self.reject()