def print_license(): """ Prints this software license. """ licpath = "{}{}".format(path.abspath(__file__).split("mod")[0], "LICENSE") if path.isfile(licpath) and ApplicationSettings.the().verbose_enabled: with open(licpath, encoding="utf-8") as licfile: FreeCAD.Console.PrintMessage(licfile.read()) FreeCAD.Console.PrintMessage("\n\n")
def __init__(self, parent=None): super().__init__(parent=parent) self.setWindowTitle(__("Special")) self.setMinimumWidth(200) self.sp_window_layout = QtGui.QVBoxLayout() self.sp_damping_button = QtGui.QPushButton(__("Damping Zone")) self.sp_inlet_button = QtGui.QPushButton(__("Inlet/Outlet")) self.sp_chrono_button = QtGui.QPushButton(__("Project Chrono")) self.sp_multilayeredmb_button = QtGui.QPushButton( __("Multi-layered Piston")) self.sp_multilayeredmb_menu = QtGui.QMenu() self.sp_multilayeredmb_menu.addAction(__("1 Dimension")) self.sp_multilayeredmb_menu.addAction(__("2 Dimensions")) self.sp_multilayeredmb_button.setMenu(self.sp_multilayeredmb_menu) self.sp_relaxationzone_button = QtGui.QPushButton( __("Relaxation Zone")) self.sp_relaxationzone_menu = QtGui.QMenu() self.sp_relaxationzone_menu.addAction(__("Regular waves")) self.sp_relaxationzone_menu.addAction(__("Irregular waves")) self.sp_relaxationzone_menu.addAction(__("External Input")) self.sp_relaxationzone_menu.addAction(__("Uniform velocity")) self.sp_relaxationzone_button.setMenu(self.sp_relaxationzone_menu) self.sp_accinput_button = QtGui.QPushButton(__("Acceleration Inputs")) self.sp_moorings_button = QtGui.QPushButton(__("Moorings")) self.sp_damping_button.clicked.connect(self.on_damping_option) self.sp_inlet_button.clicked.connect(self.on_inlet_option) self.sp_chrono_button.clicked.connect(self.on_chrono_option) self.sp_multilayeredmb_menu.triggered.connect( self.on_multilayeredmb_menu) self.sp_relaxationzone_menu.triggered.connect( self.on_relaxationzone_menu) self.sp_accinput_button.clicked.connect(self.on_accinput_button) self.sp_moorings_button.clicked.connect(self.on_moorings_button) # Add buttons to the special window self.sp_window_layout.addWidget(self.sp_inlet_button) self.sp_window_layout.addWidget(self.sp_accinput_button) self.sp_window_layout.addWidget(self.sp_chrono_button) self.sp_window_layout.addWidget(self.sp_moorings_button) self.sp_window_layout.addWidget(self.sp_damping_button) self.sp_window_layout.addWidget(self.sp_multilayeredmb_button) self.sp_window_layout.addWidget(self.sp_relaxationzone_button) self.setLayout(self.sp_window_layout) if not Case.the().executable_paths.supports_chrono(): self.sp_chrono_button.hide() if not Case.the().executable_paths.supports_moorings( ) and not ApplicationSettings.the().force_moordyn_support_enabled: self.sp_moorings_button.hide() self.exec_()
def on_ok(self): """ Dumps the data from the dialog onto the main case data structure. """ Case.the().executable_paths.gencase = self.gencasepath_input.text() Case.the().executable_paths.dsphysics = self.dsphpath_input.text() Case.the().executable_paths.partvtk = self.partvtkpath_input.text() Case.the( ).executable_paths.computeforces = self.computeforces_input.text() Case.the( ).executable_paths.floatinginfo = self.floatinginfo_input.text() Case.the().executable_paths.measuretool = self.measuretool_input.text() Case.the().executable_paths.isosurface = self.isosurface_input.text() Case.the().executable_paths.boundaryvtk = self.boundaryvtk_input.text() Case.the().executable_paths.flowtool = self.flowtool_input.text() Case.the().executable_paths.paraview = self.paraview_input.text() Case.the().executable_paths.check_and_filter() ApplicationSettings.the( ).debug_enabled = self.use_debug_check.isChecked() ApplicationSettings.the( ).verbose_enabled = self.use_verbose_check.isChecked() ApplicationSettings.the( ).notify_on_outdated_version_enabled = self.use_version_check.isChecked( ) ApplicationSettings.the( ).force_moordyn_support_enabled = self.force_moordyn_support_check.isChecked( ) ApplicationSettings.the().persist() self.accept()
def __init__(self, parent=None): super().__init__(parent=parent) self.setWindowTitle("DesignSPHysics Setup") self.ok_button = QtGui.QPushButton("OK") self.cancel_button = QtGui.QPushButton("Cancel") self.defaults_button = QtGui.QPushButton(__("Load defaults")) self.feature_support_button = QtGui.QPushButton( __("Feature support report")) # GenCase path self.gencasepath_layout = QtGui.QHBoxLayout() self.gencasepath_label = QtGui.QLabel("GenCase Path: ") self.gencasepath_input = QtGui.QLineEdit() self.gencasepath_input.setText(Case.the().executable_paths.gencase) self.gencasepath_input.setPlaceholderText("Put GenCase path here") self.gencasepath_browse = QtGui.QPushButton("...") self.gencasepath_layout.addWidget(self.gencasepath_label) self.gencasepath_layout.addWidget(self.gencasepath_input) self.gencasepath_layout.addWidget(self.gencasepath_browse) # DualSPHyisics path self.dsphpath_layout = QtGui.QHBoxLayout() self.dsphpath_label = QtGui.QLabel("DualSPHysics Path: ") self.dsphpath_input = QtGui.QLineEdit() self.dsphpath_input.setText(Case.the().executable_paths.dsphysics) self.dsphpath_input.setPlaceholderText("Put DualSPHysics path here") self.dsphpath_browse = QtGui.QPushButton("...") self.dsphpath_layout.addWidget(self.dsphpath_label) self.dsphpath_layout.addWidget(self.dsphpath_input) self.dsphpath_layout.addWidget(self.dsphpath_browse) # PartVTK path self.partvtkpath_layout = QtGui.QHBoxLayout() self.partvtkpath_label = QtGui.QLabel("PartVTK Path: ") self.partvtkpath_input = QtGui.QLineEdit() self.partvtkpath_input.setText(Case.the().executable_paths.partvtk) self.partvtkpath_input.setPlaceholderText("Put PartVTK path here") self.partvtkpath_browse = QtGui.QPushButton("...") self.partvtkpath_layout.addWidget(self.partvtkpath_label) self.partvtkpath_layout.addWidget(self.partvtkpath_input) self.partvtkpath_layout.addWidget(self.partvtkpath_browse) # ComputeForces path self.computeforces_layout = QtGui.QHBoxLayout() self.computeforces_label = QtGui.QLabel("ComputeForces Path: ") self.computeforces_input = QtGui.QLineEdit() self.computeforces_input.setText( Case.the().executable_paths.computeforces) self.computeforces_input.setPlaceholderText( "Put ComputeForces path here") self.computeforces_browse = QtGui.QPushButton("...") self.computeforces_layout.addWidget(self.computeforces_label) self.computeforces_layout.addWidget(self.computeforces_input) self.computeforces_layout.addWidget(self.computeforces_browse) # FloatingInfo path self.floatinginfo_layout = QtGui.QHBoxLayout() self.floatinginfo_label = QtGui.QLabel("FloatingInfo Path: ") self.floatinginfo_input = QtGui.QLineEdit() self.floatinginfo_input.setText( Case.the().executable_paths.floatinginfo) self.floatinginfo_input.setPlaceholderText( "Put FloatingInfo path here") self.floatinginfo_browse = QtGui.QPushButton("...") self.floatinginfo_layout.addWidget(self.floatinginfo_label) self.floatinginfo_layout.addWidget(self.floatinginfo_input) self.floatinginfo_layout.addWidget(self.floatinginfo_browse) # MeasureTool path self.measuretool_layout = QtGui.QHBoxLayout() self.measuretool_label = QtGui.QLabel("MeasureTool Path: ") self.measuretool_input = QtGui.QLineEdit() self.measuretool_input.setText(Case.the().executable_paths.measuretool) self.measuretool_input.setPlaceholderText("Put MeasureTool path here") self.measuretool_browse = QtGui.QPushButton("...") self.measuretool_layout.addWidget(self.measuretool_label) self.measuretool_layout.addWidget(self.measuretool_input) self.measuretool_layout.addWidget(self.measuretool_browse) # IsoSurface path self.isosurface_layout = QtGui.QHBoxLayout() self.isosurface_label = QtGui.QLabel("IsoSurface Path: ") self.isosurface_input = QtGui.QLineEdit() self.isosurface_input.setText(Case.the().executable_paths.isosurface) self.isosurface_input.setPlaceholderText("Put IsoSurface path here") self.isosurface_browse = QtGui.QPushButton("...") self.isosurface_layout.addWidget(self.isosurface_label) self.isosurface_layout.addWidget(self.isosurface_input) self.isosurface_layout.addWidget(self.isosurface_browse) # BoundaryVTK path self.boundaryvtk_layout = QtGui.QHBoxLayout() self.boundaryvtk_label = QtGui.QLabel("BoundaryVTK Path: ") self.boundaryvtk_input = QtGui.QLineEdit() self.boundaryvtk_input.setText(Case.the().executable_paths.boundaryvtk) self.boundaryvtk_input.setPlaceholderText("Put BoundaryVTK path here") self.boundaryvtk_browse = QtGui.QPushButton("...") self.boundaryvtk_layout.addWidget(self.boundaryvtk_label) self.boundaryvtk_layout.addWidget(self.boundaryvtk_input) self.boundaryvtk_layout.addWidget(self.boundaryvtk_browse) # FlowTool path self.flowtool_layout = QtGui.QHBoxLayout() self.flowtool_label = QtGui.QLabel("FlowTool Path: ") self.flowtool_input = QtGui.QLineEdit() self.flowtool_input.setText(Case.the().executable_paths.flowtool) self.flowtool_input.setPlaceholderText("Put FlowTool path here") self.flowtool_browse = QtGui.QPushButton("...") self.flowtool_layout.addWidget(self.flowtool_label) self.flowtool_layout.addWidget(self.flowtool_input) self.flowtool_layout.addWidget(self.flowtool_browse) # ParaView path self.paraview_layout = QtGui.QHBoxLayout() self.paraview_label = QtGui.QLabel("ParaView Path: ") self.paraview_input = QtGui.QLineEdit() self.paraview_input.setText(Case.the().executable_paths.paraview) self.paraview_input.setPlaceholderText("Put ParaView path here") self.paraview_browse = QtGui.QPushButton("...") self.paraview_layout.addWidget(self.paraview_label) self.paraview_layout.addWidget(self.paraview_input) self.paraview_layout.addWidget(self.paraview_browse) self.defaults_button.clicked.connect(self.on_set_defaults) self.feature_support_button.clicked.connect(self.on_feature_support) self.ok_button.clicked.connect(self.on_ok) self.cancel_button.clicked.connect(self.on_cancel) self.gencasepath_browse.clicked.connect( lambda: self.browse("GenCase", self.gencasepath_input)) self.dsphpath_browse.clicked.connect( lambda: self.browse("DualSPHysics", self.dsphpath_input)) self.partvtkpath_browse.clicked.connect( lambda: self.browse("PartVTK", self.partvtkpath_input)) self.computeforces_browse.clicked.connect( lambda: self.browse("ComputeForces", self.computeforces_input)) self.floatinginfo_browse.clicked.connect( lambda: self.browse("FloatingInfo", self.floatinginfo_input)) self.measuretool_browse.clicked.connect( lambda: self.browse("MeasureTool", self.measuretool_input)) self.boundaryvtk_browse.clicked.connect( lambda: self.browse("BoundaryVTK", self.boundaryvtk_input)) self.flowtool_browse.clicked.connect( lambda: self.browse("FlowTool", self.flowtool_input)) self.isosurface_browse.clicked.connect( lambda: self.browse("IsoSurface", self.isosurface_input)) self.paraview_browse.clicked.connect(self.on_paraview_browse) # Executables definition and composition. self.executables_layout = QtGui.QVBoxLayout() self.executables_layout.addLayout(self.gencasepath_layout) self.executables_layout.addLayout(self.dsphpath_layout) self.executables_layout.addLayout(self.partvtkpath_layout) self.executables_layout.addLayout(self.computeforces_layout) self.executables_layout.addLayout(self.floatinginfo_layout) self.executables_layout.addLayout(self.measuretool_layout) self.executables_layout.addLayout(self.isosurface_layout) self.executables_layout.addLayout(self.boundaryvtk_layout) self.executables_layout.addLayout(self.flowtool_layout) self.executables_layout.addLayout(self.paraview_layout) self.executables_layout.addStretch(1) # General settings self.settings_layout = QtGui.QFormLayout() self.use_debug_check = QtGui.QCheckBox(__("Show debug messages")) self.use_debug_check.setChecked( ApplicationSettings.the().debug_enabled) self.use_verbose_check = QtGui.QCheckBox( __("Show verbose log messages")) self.use_verbose_check.setChecked( ApplicationSettings.the().verbose_enabled) self.use_version_check = QtGui.QCheckBox( __("Look for updates at startup")) self.use_version_check.setChecked( ApplicationSettings.the().notify_on_outdated_version_enabled) self.force_moordyn_support_check = QtGui.QCheckBox( "Force MoorDyn Support") self.force_moordyn_support_check.setChecked( ApplicationSettings.the().force_moordyn_support_enabled) self.settings_layout.addRow(self.use_debug_check) self.settings_layout.addRow(self.use_verbose_check) self.settings_layout.addRow(self.use_version_check) self.settings_layout.addRow(self.force_moordyn_support_check) # Tab widget composition self.tab_widget = QtGui.QTabWidget() self.executable_setup_widget = QtGui.QWidget() self.executable_setup_widget.setLayout(self.executables_layout) self.settings_setup_widget = QtGui.QWidget() self.settings_setup_widget.setLayout(self.settings_layout) self.tab_widget.addTab(self.executable_setup_widget, "Executables") self.tab_widget.addTab(self.settings_setup_widget, "Settings") # Button layout definition self.button_layout = QtGui.QHBoxLayout() self.button_layout.addWidget(self.defaults_button) self.button_layout.addWidget(self.feature_support_button) self.button_layout.addStretch(1) self.button_layout.addWidget(self.ok_button) self.button_layout.addWidget(self.cancel_button) self.main_layout = QtGui.QVBoxLayout() self.main_layout.addWidget(self.tab_widget) self.main_layout.addLayout(self.button_layout) self.setLayout(self.main_layout) self.ok_button.setFocus() self.resize(600, 400) self.exec_()
def debug(message): """ Prints a debug message in the default output""" if ApplicationSettings.the().debug_enabled: caller = getframeinfo(stack()[1][0]) FreeCAD.Console.PrintWarning("[DEBUG][{}] {}:{} -> {}\n".format( APP_NAME, path.basename(caller.filename), caller.lineno, message))
def error(message): """ Prints an error in the default output.""" if ApplicationSettings.the().verbose_enabled: caller = getframeinfo(stack()[1][0]) FreeCAD.Console.PrintError("[ERROR][{}] {}:{} -> {}\n".format( APP_NAME, path.basename(caller.filename), caller.lineno, message))
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 ApplicationSettings.the( ).notify_on_outdated_version_enabled: 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))