示例#1
0
    def s_open_matlib(self):
        """Open the GUI to Edit the Material library

        Parameters
        ----------
        self :
            A P_LamParam object

        Returns
        -------

        """
        self.mat_win = DMatLib(self.matlib, self.c_mat_type.currentIndex())
        self.mat_win.accepted.connect(self.set_matlib)
        self.mat_win.show()
示例#2
0
    def setUp(self):
        """Run at the begining of every test to setup the gui"""
        mat_lib = list()
        mat_lib.append(Material())
        mat_lib[0].name = "test_material_1"
        mat_lib[0].is_isotropic = True
        mat_lib[0].elec.rho = 0.11
        mat_lib[0].mag = MatMagnetics(mur_lin=0.12, Wlam=0.13)
        mat_lib[0].struct.rho = 0.14
        mat_lib[0].struct.Ex = 0.15
        mat_lib[0].struct.Ey = 0.152
        mat_lib[0].struct.Ez = 0.153
        mat_lib[0].struct.nu_xy = 0.16
        mat_lib[0].struct.nu_yz = 0.162
        mat_lib[0].struct.nu_xz = 0.163
        mat_lib[0].struct.Gxy = 0.17
        mat_lib[0].struct.Gyz = 0.172
        mat_lib[0].struct.Gxz = 0.173
        mat_lib[0].HT.lambda_x = 0.18
        mat_lib[0].HT.lambda_y = 0.182
        mat_lib[0].HT.lambda_z = 0.183
        mat_lib[0].HT.Cp = 0.19
        mat_lib[0].HT.alpha = 0.20
        mat_lib[0].eco.cost_unit = 0.21

        mat_lib.append(Material(name="test_material_2"))
        mat_lib.append(Material(name="test_material_3"))
        mat_lib.append(Material(name="test_material_4"))
        mat_lib.append(Material(name="test_material_5"))
        mat_lib.append(Material(name="test_material_6"))
        mat_lib.append(Material(name="test_material_7"))

        self.widget = DMatLib(matlib=mat_lib)
示例#3
0
class WMatSelect(Ui_WMatSelect, QWidget):
    """Setup of a WMatSelect Main parameters"""

    # Signal to W_MachineSetup to know that the save popup is needed
    saveNeeded = pyqtSignal()

    def __init__(self, parent=None):
        """Initialize the widget
        """

        # Build the interface according to the .ui file
        QWidget.__init__(self, parent)
        self.setupUi(self)

        # Create the property of the widget
        self.mat_win = None  # DMatLib widget
        self.mat = Material()  # Current material
        self.matlib = list()  # Matlib
        self.matlib_path = ""  # Path to save the matlib
        self.def_mat = "M400-50A"  # Default material

        # Connect the
        self.c_mat_type.currentIndexChanged.connect(self.set_mat_type)
        self.b_matlib.clicked.connect(self.s_open_matlib)

    def update(self, mat, matlib=list(), matlib_path=""):
        self.c_mat_type.blockSignals(True)

        # Set material combobox according to matlib names
        self.mat = mat
        self.matlib = matlib
        self.matlib_path = matlib_path

        # Update the list of materials
        self.c_mat_type.clear()
        self.c_mat_type.addItems([mat.name for mat in matlib])

        if mat is None or mat.name is None:
            # Default lamination material: M400-50A
            index = self.c_mat_type.findText(self.def_mat)
            if index != -1:
                self.mat = Material(init_dict=self.matlib[index].as_dict())
        else:
            index = self.c_mat_type.findText(mat.name)
        self.c_mat_type.setCurrentIndex(index)
        self.c_mat_type.blockSignals(False)

    def setText(self, txt):
        self.in_mat_type.setText(txt)

    def set_mat_type(self, index):
        """Signal to update the value of mat_name according to the combobox

        Parameters
        ----------
        self :
            A P_LamParam object
        index :
            Current index of the combobox

        Returns
        -------

        """
        self.mat.__init__(init_dict=self.matlib[index].as_dict())
        # Notify the machine GUI that the machine has changed
        self.saveNeeded.emit()

    def s_open_matlib(self):
        """Open the GUI to Edit the Material library

        Parameters
        ----------
        self :
            A P_LamParam object

        Returns
        -------

        """
        self.mat_win = DMatLib(self.matlib, self.c_mat_type.currentIndex())
        self.mat_win.accepted.connect(self.set_matlib)
        self.mat_win.show()

    def set_matlib(self):
        """Update the matlib with the new value

        Parameters
        ----------
        self :
            A P_Lam_Param object

        Returns
        -------

        """
        # Empty and fill the list to keep the same object
        # (to change it everywhere)
        del self.matlib[:]
        self.matlib.extend(self.mat_win.matlib)
        # Update the material
        index = int(self.mat_win.nav_mat.currentItem().text()[:3]) - 1
        mat_dict = (self.mat_win.matlib[index]).as_dict()
        self.mat.__init__(init_dict=mat_dict)
        # Clear the window
        self.mat_win = None
        # Update the widget
        # Avoid trigger signal currentIndexChanged
        self.c_mat_type.blockSignals(True)

        self.c_mat_type.clear()
        self.c_mat_type.addItems([mat.name for mat in self.matlib])

        index = self.c_mat_type.findText(self.mat.name)
        self.c_mat_type.setCurrentIndex(index)

        self.c_mat_type.blockSignals(False)
示例#4
0
class WMatSelect(Ui_WMatSelect, QWidget):
    """
    Material related widget including a Label, a Combobox to select a material 
    and a Button to edit a material libary.  
    WMatSelect is instantiated to empty material data, so it has to be referenced
    to actual material data with the update method prior to its first usage.
    """

    # Signal to W_MachineSetup to know that the save popup is needed
    saveNeeded = pyqtSignal()

    def __init__(self, parent=None):
        """
        Set a reference to a material libray and material data path, 
        updates the Combobox by the material names of the libary 
        and set a referenced material by name.

        Parameters
        ----------
        self :
            A WMatSelect object
        parent :
            A reference to the widgets parent
        
        Returns
        -------

        """

        # Build the interface according to the .ui file
        QWidget.__init__(self, parent)
        self.setupUi(self)

        # Create the property of the widget
        self.mat_win = None  # DMatLib widget
        self.obj = None  # object that has a material attribute
        self.mat_attr_name = ""  # material attribute name
        self.matlib = list()  # Matlib
        self.matlib_path = ""  # Path to save the matlib
        self.def_mat = "M400-50A"  # Default material

        # Connect the
        self.c_mat_type.currentIndexChanged.connect(self.set_mat_type)
        self.b_matlib.clicked.connect(self.s_open_matlib)

    def update(self, obj, mat_attr_name, matlib=list(), matlib_path=""):
        """
        Set a reference to a material libray and material data path, 
        updates the Combobox by the material names of the libary 
        and set a referenced material by name.

        Parameters
        ----------
        self :
            A WMatSelect object
        obj :
            A pyleecan object that has a material attribute
        mat_attr_name :
            A string of the material attribute name
        matlib :
            A material libary, i.e. a list of Material objects
        matlib_path :
            A string containing the path of material data

        Returns
        -------

        """
        self.c_mat_type.blockSignals(True)

        # Set material combobox according to matlib names
        self.obj = obj
        self.mat_attr_name = mat_attr_name
        self.matlib = matlib
        self.matlib_path = matlib_path

        # Update the list of materials
        self.c_mat_type.clear()
        self.c_mat_type.addItems([mat.name for mat in matlib])

        mat = getattr(self.obj, mat_attr_name, None)
        if mat is None or mat.name is None:
            # Default lamination material: M400-50A
            index = self.c_mat_type.findText(self.def_mat)
            if index != -1:
                # self.mat.__init__(init_dict=self.matlib[index].as_dict())
                setattr(self.obj, self.mat_attr_name, self.matlib[index])
        else:
            index = self.c_mat_type.findText(mat.name)
        self.c_mat_type.setCurrentIndex(index)
        self.c_mat_type.blockSignals(False)

    def setText(self, txt):
        """
        Set the Label's text

        Parameters
        ----------
        self :
            A WMatSelect object
        txt :
            A text string 
        
        Returns
        -------

        """
        self.in_mat_type.setText(txt)

    def set_mat_type(self, index):
        """
        Signal to set the referenced material from the material libary
        by the selected Combobox index 

        Parameters
        ----------
        self :
            A WMatSelect object
        index :
            Current index of the combobox

        Returns
        -------

        """
        setattr(self.obj, self.mat_attr_name, self.matlib[index])
        # Notify the machine GUI that the machine has changed
        self.saveNeeded.emit()

    def s_open_matlib(self):
        """
        Open the GUI (DMatLib widget) to Edit the Material library

        Parameters
        ----------
        self :
            A WMatSelect object

        Returns
        -------

        """
        self.mat_win = DMatLib(self.matlib, self.c_mat_type.currentIndex())
        self.mat_win.accepted.connect(self.set_matlib)
        self.mat_win.show()

    def set_matlib(self):
        """Update the matlib with the new value

        Parameters
        ----------
        self :
            A WMatSelect object

        Returns
        -------

        """
        # Empty and fill the list to keep the same object (to change it everywhere)
        # del self.matlib[:]
        # self.matlib.extend(self.mat_win.matlib)
        # Update the material
        index = int(self.mat_win.nav_mat.currentItem().text()[:3]) - 1

        # not needed if machine materials are "connected" properly
        # mat_dict = (self.mat_win.matlib[index]).as_dict()
        # self.mat.__init__(init_dict=mat_dict)

        # Do not clear for now to keep editor (DMatLib) open
        # # Clear the window
        # self.mat_win.deleteLater()
        # self.mat_win = None

        # Update the widget
        # Avoid trigger signal currentIndexChanged
        self.c_mat_type.blockSignals(True)

        self.c_mat_type.clear()
        self.c_mat_type.addItems([mat.name for mat in self.matlib])
        index = self.c_mat_type.findText(
            getattr(self.obj, self.mat_attr_name).name)
        self.c_mat_type.setCurrentIndex(index)

        self.c_mat_type.blockSignals(False)
示例#5
0
                      matlib_path=MATLIB_DIR)

    if EXT_GUI:
        # Setup extended GUI with sub windows
        icon = dirname(__file__) + "/GUI/Resources/images/icon/pyleecan_64.png"
        window = SidebarWindow()
        window.setWindowIcon(QIcon(icon))

        update_step = lambda: c.set_nav(c.nav_step.currentRow())
        window.addSubWindow("Design", c, update_step)
        window.DesignWidget = c

        plt_widget = MachinePlotWidget(window)
        window.addSubWindow("Plot", plt_widget, plt_widget.update)

        mat_widget = DMatLib(window.DesignWidget.matlib, selected=0)
        mat_widget.installEventFilter(window)
        window.addSubWindow("MatLib", mat_widget, mat_widget.update_mat_list)

        tree = TreeView()
        tree_fcn = lambda: tree.generate(getattr(c, "machine"))
        window.addSubWindow("TreeView", tree, tree_fcn)

        window.show()

    else:
        # "Normal" GUI
        c.show()

    exit(a.exec_())
示例#6
0
    translator = QTranslator()
    translator.load(translationFile, "GUI//i18n")
    a.installTranslator(translator)

    # Machine Setup Widget
    c = DMachineSetup(machine_path=join(DATA_DIR, "Machine"),
                      matlib_path=matlib_path)

    if EXT_GUI:
        # Setup extended GUI with sub windows
        icon = dirname(__file__) + "/GUI/Resources/images/icon/pyleecan_64.png"
        window = SidebarWindow()
        window.setWindowIcon(QIcon(icon))

        window.addSubWindow("Design", c)
        window.DesignWidget = c

        plt_widget = MachinePlotWidget(window)
        window.addSubWindow("Plot", plt_widget, plt_widget.update)

        mat_widget = DMatLib(window.DesignWidget.matlib, selected=0)
        window.addSubWindow("MatLib", mat_widget)

        window.show()

    else:
        # "Normal" GUI
        c.show()

    exit(a.exec_())