def on_mkgroup_change(self, value): """ Defines what happens when MKGroup is changed. """ new_value: int = value old_value: int = self.last_mk_value # First we do what the user want Case.the().get_simulation_object( FreeCADGui.Selection.getSelection()[0].Name).obj_mk = new_value self.last_mk_value = new_value # Then we check that it is sensible orphan_mkbasedproperties: list = Case.the( ).get_orphan_mkbasedproperties() if orphan_mkbasedproperties: response = ok_cancel_dialog( __("Changing MK value"), __("By doing this you will loose all MK configuration for the previous MK: {}. Are you sure you want to do this?" ).format(old_value)) if response == QtGui.QMessageBox.Ok: debug( "Changing from mk {} to {} caused orphan mkbasedproperties. Deleting..." .format(old_value, new_value)) Case.the().delete_orphan_mkbasedproperties() else: self.mkgroup_prop.setValue(old_value)
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
def on_relaxationzone_menu(self, action): """ Defines Relaxation Zone menu behaviour.""" # Check which type of relaxationzone it is if action.text() == __("Regular waves"): if Case.the().relaxation_zone is not None: if not isinstance(Case.the().relaxation_zone, RelaxationZoneRegular): overwrite_warn = ok_cancel_dialog( __("Relaxation Zone"), __("There's already another type of Relaxation Zone defined. Continuing will overwrite it. Are you sure?" )) if overwrite_warn == QtGui.QMessageBox.Cancel: return Case.the().relaxation_zone = RelaxationZoneRegular() config_dialog = RelaxationZoneRegularConfigDialog( Case.the().relaxation_zone, parent=get_fc_main_window()) # Set the relaxation zone. Can be an object or be None Case.the().relaxation_zone = config_dialog.relaxationzone if action.text() == __("Irregular waves"): if Case.the().relaxation_zone is not None: if not isinstance(Case.the().relaxation_zone, RelaxationZoneIrregular): overwrite_warn = ok_cancel_dialog( __("Relaxation Zone"), __("There's already another type of Relaxation Zone defined. Continuing will overwrite it. Are you sure?" )) if overwrite_warn == QtGui.QMessageBox.Cancel: return Case.the().relaxation_zone = RelaxationZoneIrregular() config_dialog = RelaxationZoneIrregularConfigDialog( Case.the().relaxation_zone, parent=get_fc_main_window()) # Set the relaxation zone. Can be an object or be None Case.the().relaxation_zone = config_dialog.relaxationzone if action.text() == __("External Input"): if Case.the().relaxation_zone is not None: if not isinstance(Case.the().relaxation_zone, RelaxationZoneFile): overwrite_warn = ok_cancel_dialog( __("Relaxation Zone"), __("There's already another type of Relaxation Zone defined. Continuing will overwrite it. Are you sure?" )) if overwrite_warn == QtGui.QMessageBox.Cancel: return Case.the().relaxation_zone = RelaxationZoneFile() config_dialog = RelaxationZoneFileConfigDialog( Case.the().relaxation_zone, parent=get_fc_main_window()) # Set the relaxation zone. Can be an object or be None Case.the().relaxation_zone = config_dialog.relaxationzone if action.text() == __("Uniform velocity"): if Case.the().relaxation_zone is not None: if not isinstance(Case.the().relaxation_zone, RelaxationZoneUniform): overwrite_warn = ok_cancel_dialog( __("Relaxation Zone"), __("There's already another type of Relaxation Zone defined. Continuing will overwrite it. Are you sure?" )) if overwrite_warn == QtGui.QMessageBox.Cancel: return Case.the().relaxation_zone = RelaxationZoneUniform() config_dialog = RelaxationZoneUniformConfigDialog( Case.the().relaxation_zone, parent=get_fc_main_window()) # Set the relaxation zone. Can be an object or be None Case.the().relaxation_zone = config_dialog.relaxationzone self.accept()
def on_multilayeredmb_menu(self, action): """ Defines MLPiston menu behaviour""" # Get currently selected object try: selection = FreeCADGui.Selection.getSelection()[0] except IndexError: error_dialog(__("You must select an object")) return # Check if object is in the simulation if not Case.the().is_object_in_simulation(selection.Name): error_dialog( __("The selected object must be added to the simulation")) return # Check if it is fluid and warn the user. if Case.the().get_simulation_object( selection.Name).type == ObjectType.FLUID: error_dialog( __("You can't apply a piston movement to a fluid.\nPlease select a boundary and try again" )) return # Get selection mk selection_obj = Case.the().get_simulation_object(selection.Name) selection_mk: int = selection_obj.obj_mk mk_properties: MKBasedProperties = Case.the().get_mk_based_properties( selection_obj.type, selection_mk) # Check that this mk has no other motions applied if mk_properties.has_movements(): # MK has motions applied. Warn the user and delete them motion_delete_warning = ok_cancel_dialog( APP_NAME, __("This mk already has motions applied. Setting a Multi-layered piston will delete all of its movement. Are you sure?" )) if motion_delete_warning == QtGui.QMessageBox.Cancel: return mk_properties.remove_all_movements() # 1D or 2D piston if __("1 Dimension") in action.text(): if mk_properties.mlayerpiston and not isinstance( mk_properties.mlayerpiston, MLPiston1D): overwrite_warn = ok_cancel_dialog( APP_NAME, __("You're about to overwrite a previous coupling movement for this mk. Are you sure?" )) if overwrite_warn == QtGui.QMessageBox.Cancel: return config_dialog = MLPiston1DConfigDialog(selection_mk, mk_properties.mlayerpiston, parent=get_fc_main_window()) if config_dialog.result() == QtGui.QDialog.Accepted: warning_dialog( __("All changes have been applied for mk = {}").format( selection_mk)) mk_properties.mlayerpiston = config_dialog.mlpiston1d if __("2 Dimensions") in action.text(): # Check that there's no other multilayered piston for this mk if mk_properties.mlayerpiston and not isinstance( mk_properties.mlayerpiston, MLPiston2D): overwrite_warn = ok_cancel_dialog( APP_NAME, __("You're about to overwrite a previous coupling movement for this mk. Are you sure?" )) if overwrite_warn == QtGui.QMessageBox.Cancel: return config_dialog = MLPiston2DConfigDialog(selection_mk, mk_properties.mlayerpiston, parent=get_fc_main_window()) if config_dialog.result() == QtGui.QDialog.Accepted: warning_dialog( __("All changes have been applied for mk = {}").format( selection_mk)) mk_properties.mlayerpiston = config_dialog.mlpiston2d self.accept()