Example #1
0
    def __init__(self, obj):

        self.obj = obj
        analysis_obj = CfdTools.getParentAnalysisObject(obj)
        solver_obj = CfdTools.getSolver(analysis_obj)
        material_objs = CfdTools.getMaterials(analysis_obj)

        self.boundaryWidget = CfdBoundaryWidget(obj, None, solver_obj,
                                                material_objs)
        # fill the table in each variable tab, saved from the previous setup, existing case if BC name, done in each widget

        # geometry selection widget, only face is needed as boundary for CFD
        # GeometryElementsSelection(ref, eltypes=[], multigeom=True)  # allow_multiple_geom_types = multigeom
        self.selectionWidget = FemSelectionWidgets.GeometryElementsSelection(
            obj.References, ['Face'], False)
        # check references, has to be after initialization of selectionWidget
        try:
            self.selectionWidget.has_equal_references_shape_types(
            )  # boundarySelector has no such method
        except:
            print(
                '`selectionWidget.has_equal_references_shape_types()` is only available in FreeCAD 0.18+'
            )

        #the magic to have two widgets in one taskpanel
        self.form = [self.selectionWidget, self.boundaryWidget]
        if True:  # todo: check if solver is 'OpenFOAM'
            from CfdFoamTools import getVariableList
            solverSettings = CfdTools.getSolverSettings(
                solver_obj)  # physical_model
            variable_list = getVariableList(solverSettings)

            # TODO: if boundary_settings is empty dict, default setting for each variable could be provided
            if "FoamBoundarySettings" in self.obj.PropertiesList and self.obj.FoamBoundarySettings:
                self.foam_boundary_conditions = self.obj.FoamBoundarySettings
            else:
                print("debug print: variable_list", variable_list)
                self.foam_boundary_conditions = {
                    var: {}
                    for var in variable_list
                }  # {varible: bc_dict, ...}

            from FoamCaseBuilder.FoamBoundaryWidget import FoamBoundaryWidget
            s = {"variables": self.foam_boundary_conditions}
            self.foamWidget = FoamBoundaryWidget(s)
            self.form.append(self.foamWidget)
    def __init__(self, obj):

        self.obj = obj
        analysis_obj = CfdTools.getParentAnalysisObject(obj)
        solver_obj = CfdTools.getSolver(analysis_obj)
        material_objs = CfdTools.getMaterials(analysis_obj)

        from CfdBoundaryWidget import CfdBoundaryWidget
        self.boundaryWidget = CfdBoundaryWidget(obj, None, solver_obj, material_objs)
        # fill the table in each variable tab, saved from the previous setup, existing case if BC name, done in each widget

        # geometry selection widget, only face is needed as boundary
        self.selectionWidget = FemSelectionWidgets.BoundarySelector()
        self.selectionWidget.setReferences(obj.References)
        # check references, has to be after initialisation of selectionWidget
        try:
            self.selectionWidget.has_equal_references_shape_types()
        except:
            RuntimeError('this function only works for FreeCAD 0.18')

        #the magic to have two widgets in one taskpanel
        self.form = [self.selectionWidget, self.boundaryWidget]
        if True:  # todo: check if solver is 'OpenFOAM'
            from CfdFoamTools import getVariableList
            solverSettings = CfdTools.getSolverSettings(solver_obj)  # physical_model
            variable_list = getVariableList(solverSettings)

            # build a parameterTabWidget, with each tab has a tableView
            # TODO: if boundary_settings is empty dict, default setting for each variable could be provided
            if not self.obj.FoamBoundarySettings:
                self.foam_boundary_conditions = {'U': {"key": "value"}, 'p':{"key": "value"}}  # {varible: bc_dict, ...}
            else:
                self.foam_boundary_conditions = self.obj.FoamBoundarySettings
            from FoamCaseBuilder.FoamBoundaryWidget import FoamBoundaryWidget
            self.foamWidget = FoamBoundaryWidget(self.foam_boundary_conditions)
            self.form.append(self.foamWidget)
Example #3
0
class _TaskPanelCfdFluidBoundary:
    '''The editmode TaskPanel for CfdFluidBoundary objects'''
    def __init__(self, obj):

        self.obj = obj
        analysis_obj = CfdTools.getParentAnalysisObject(obj)
        solver_obj = CfdTools.getSolver(analysis_obj)
        material_objs = CfdTools.getMaterials(analysis_obj)

        self.boundaryWidget = CfdBoundaryWidget(obj, None, solver_obj,
                                                material_objs)
        # fill the table in each variable tab, saved from the previous setup, existing case if BC name, done in each widget

        # geometry selection widget, only face is needed as boundary for CFD
        # GeometryElementsSelection(ref, eltypes=[], multigeom=True)  # allow_multiple_geom_types = multigeom
        self.selectionWidget = FemSelectionWidgets.GeometryElementsSelection(
            obj.References, ['Face'], False)
        # check references, has to be after initialization of selectionWidget
        try:
            self.selectionWidget.has_equal_references_shape_types(
            )  # boundarySelector has no such method
        except:
            print(
                '`selectionWidget.has_equal_references_shape_types()` is only available in FreeCAD 0.18+'
            )

        #the magic to have two widgets in one taskpanel
        self.form = [self.selectionWidget, self.boundaryWidget]
        if True:  # todo: check if solver is 'OpenFOAM'
            from CfdFoamTools import getVariableList
            solverSettings = CfdTools.getSolverSettings(
                solver_obj)  # physical_model
            variable_list = getVariableList(solverSettings)

            # TODO: if boundary_settings is empty dict, default setting for each variable could be provided
            if "FoamBoundarySettings" in self.obj.PropertiesList and self.obj.FoamBoundarySettings:
                self.foam_boundary_conditions = self.obj.FoamBoundarySettings
            else:
                print("debug print: variable_list", variable_list)
                self.foam_boundary_conditions = {
                    var: {}
                    for var in variable_list
                }  # {varible: bc_dict, ...}

            from FoamCaseBuilder.FoamBoundaryWidget import FoamBoundaryWidget
            s = {"variables": self.foam_boundary_conditions}
            self.foamWidget = FoamBoundaryWidget(s)
            self.form.append(self.foamWidget)

    # ********* leave task panel *********
    def accept(self):
        if self.selectionWidget.has_equal_references_shape_types():
            self.obj.BoundarySettings = self.boundaryWidget.boundarySettings()
            self.obj.FoamBoundarySettings = self.foamWidget.boundarySettings()
            self.obj.References = self.selectionWidget.references
            self.recompute_and_set_back_all()
            return True

    def reject(self):
        #
        self.recompute_and_set_back_all()
        return True

    def recompute_and_set_back_all(self):
        doc = FreeCADGui.getDocument(self.obj.Document)
        doc.Document.recompute()
        self.selectionWidget.setback_listobj_visibility(
        )  # BoundarySelector has no such method
        if self.selectionWidget.sel_server:
            FreeCADGui.Selection.removeObserver(
                self.selectionWidget.sel_server)
        doc.resetEdit()

    # ********* check or validation? *********
    def clear_setup(self):
        pass

    def check_setup(self):
        pass
class _TaskPanelCfdFluidBoundary:
    '''The editmode TaskPanel for CfdFluidBoundary objects'''

    def __init__(self, obj):

        self.obj = obj
        analysis_obj = CfdTools.getParentAnalysisObject(obj)
        solver_obj = CfdTools.getSolver(analysis_obj)
        material_objs = CfdTools.getMaterials(analysis_obj)

        from CfdBoundaryWidget import CfdBoundaryWidget
        self.boundaryWidget = CfdBoundaryWidget(obj, None, solver_obj, material_objs)
        # fill the table in each variable tab, saved from the previous setup, existing case if BC name, done in each widget

        # geometry selection widget, only face is needed as boundary
        self.selectionWidget = FemSelectionWidgets.BoundarySelector()
        self.selectionWidget.setReferences(obj.References)
        # check references, has to be after initialisation of selectionWidget
        try:
            self.selectionWidget.has_equal_references_shape_types()
        except:
            RuntimeError('this function only works for FreeCAD 0.18')

        #the magic to have two widgets in one taskpanel
        self.form = [self.selectionWidget, self.boundaryWidget]
        if True:  # todo: check if solver is 'OpenFOAM'
            from CfdFoamTools import getVariableList
            solverSettings = CfdTools.getSolverSettings(solver_obj)  # physical_model
            variable_list = getVariableList(solverSettings)

            # build a parameterTabWidget, with each tab has a tableView
            # TODO: if boundary_settings is empty dict, default setting for each variable could be provided
            if not self.obj.FoamBoundarySettings:
                self.foam_boundary_conditions = {'U': {"key": "value"}, 'p':{"key": "value"}}  # {varible: bc_dict, ...}
            else:
                self.foam_boundary_conditions = self.obj.FoamBoundarySettings
            from FoamCaseBuilder.FoamBoundaryWidget import FoamBoundaryWidget
            self.foamWidget = FoamBoundaryWidget(self.foam_boundary_conditions)
            self.form.append(self.foamWidget)
        
    # ********* leave task panel *********
    def accept(self):
        if self.selectionWidget.has_equal_references_shape_types():
            self.obj.BoundarySettings = self.boundaryWidget.boundarySettings()
            self.obj.FoamBoundarySettings = self.foamWidget.boundarySettings()
            print(self.obj.FoamBoundarySettings)
            self.obj.References = self.selectionWidget.references
            self.recompute_and_set_back_all()
            return True

    def reject(self):
        #
        self.recompute_and_set_back_all()
        return True

    def recompute_and_set_back_all(self):
        doc = FreeCADGui.getDocument(self.obj.Document)
        doc.Document.recompute()
        self.selectionWidget.setback_listobj_visibility()
        if self.selectionWidget.sel_server:
            FreeCADGui.Selection.removeObserver(self.selectionWidget.sel_server)
        doc.resetEdit()

    # ********* check or validation? *********
    def clear_setup(self):
        pass

    def check_setup(self):
        pass