def on_add_object_to_sim(self, name=None): """ Defines what happens when "Add object to sim" button is presseed. """ if not name: selection = FreeCADGui.Selection.getSelection() else: selection = list() selection.append(FreeCAD.ActiveDocument.getObject(name)) for each in selection: if each.Name == "Case_Limits" or "_internal_" in each.Name or each.InList: continue if not Case.the().is_object_in_simulation(each.Name): if "fillbox" in each.Name.lower(): mktoput = Case.the().get_first_mk_not_used( ObjectType.FLUID) Case.the().add_object( SimulationObject(each.Name, mktoput, ObjectType.FLUID, ObjectFillMode.SOLID)) else: mktoput = Case.the().get_first_mk_not_used( ObjectType.BOUND) Case.the().add_object( SimulationObject(each.Name, mktoput, ObjectType.BOUND, ObjectFillMode.FULL)) self.need_refresh.emit()
def on_new_case(self, prompt=True): """ Defines what happens when new case is clicked. Closes all documents if possible and creates a FreeCAD document with Case Limits object. """ if document_count() and not prompt_close_all_documents(prompt): return create_dsph_document() Case.the().reset() Case.the().add_object( SimulationObject(CASE_LIMITS_OBJ_NAME, -1, ObjectType.SPECIAL, ObjectFillMode.SPECIAL)) self.case_created.emit() self.update_dp.emit() self.need_refresh.emit()
def on_new_from_freecad_document(self, prompt=True): """ Creates a new case based on an existing FreeCAD document. This is specially useful for CAD users that want to use existing geometry for DesignSPHysics. """ file_name, _ = QtGui.QFileDialog().getOpenFileName( get_fc_main_window(), "Select document to import", Case.the().info.last_used_directory) Case.the().info.update_last_used_directory(file_name) if file_name and document_count( ) and not prompt_close_all_documents(prompt): return create_dsph_document_from_fcstd(file_name) Case.the().reset() Case.the().add_object_to_sim( SimulationObject(CASE_LIMITS_OBJ_NAME, -1, ObjectType.SPECIAL, ObjectFillMode.SPECIAL)) self.update_dp.emit() self.case_created.emit() self.need_refresh.emit()
def adapt_to_simulation_object(self, sim_object: SimulationObject, fc_object): """ Adapts the contents of the property widget to the specifications of the simulation object passed as a parameter. """ self.mkgroup_prop.setValue(sim_object.obj_mk) self.last_mk_value = int(self.mkgroup_prop.value()) self.autofill_prop.setChecked(bool(sim_object.autofill)) self.frdrawmode_prop.setChecked(bool(sim_object.frdrawmode)) debug( "Object {} supports changing type? {}. Its type is {} with mk {}". format(sim_object.name, sim_object.supports_changing_type(), sim_object.type, sim_object.obj_mk)) # Object Type selector adaptation if sim_object.supports_changing_type(): debug( "Changing objtype_prop to {} in PropertiesDockWidget.adapt_to_simulation_object" .format("Fluid" if sim_object.type == ObjectType.FLUID else "Bound")) self.objtype_prop.setEnabled(True) self.objtype_prop.setCurrentIndex(0 if sim_object.type == ObjectType.FLUID else 1) self.set_mkgroup_range(sim_object.type) self.set_mkgroup_text("{} <a href='{}'>?</a>".format( __("MKFluid" if sim_object.type == ObjectType.FLUID else "MKBound"), HelpURL.BASIC_CONCEPTS)) else: # Everything else debug( "Changing objtype_prop to {} in PropertiesDockWidget.adapt_to_simulation_object" .format("Fluid" if sim_object.type == ObjectType.FLUID else "Bound")) self.set_mkgroup_range(ObjectType.BOUND) self.objtype_prop.setCurrentIndex(1) self.objtype_prop.setEnabled(False) # Object Fillmode selector adaptation self.fillmode_prop.setEnabled(False) if sim_object.supports_changing_fillmode(): self.fillmode_prop.setEnabled(True) self.fillmode_prop.setCurrentIndex({ ObjectFillMode.FULL: 0, ObjectFillMode.SOLID: 1, ObjectFillMode.FACE: 2, ObjectFillMode.WIRE: 3 }[sim_object.fillmode]) else: # Object not supported. Put Solid if it's a fillbox or face if not self.fillmode_prop.setCurrentIndex(1 if fc_object.TypeId == FreeCADObjectType.FOLDER else 2) # Object Float State button adaptation if sim_object.supports_floating(): self.floatstate_prop.setEnabled( sim_object.type != ObjectType.FLUID) # Object Initials button adaptation self.initials_prop.setEnabled(sim_object.type == ObjectType.FLUID) # Object Motion button adaptation if sim_object.supports_motion(): self.motion_prop.setEnabled(sim_object.type != ObjectType.FLUID) # Object Material button adaptation self.material_prop.setEnabled(sim_object.type == ObjectType.BOUND) # Is an external object that supports autofill self.autofill_prop.setEnabled(sim_object.autofill is not None) # Is an object that supports frdrawmode self.frdrawmode_prop.setEnabled( fc_object.TypeId in (FreeCADObjectType.BOX, FreeCADObjectType.CYLINDER, FreeCADObjectType.SPHERE))