Пример #1
0
 def openfile(self):
     "Opens a FCMat file"
     filename = QtGui.QFileDialog.getOpenFileName(QtGui.qApp.activeWindow(),'Open FreeCAD Material file','*.FCMat')
     if filename:
         self.clearEditor()
         import importFCMat
         d = importFCMat.read(filename)
         if d:
             self.updateContents(d)
Пример #2
0
 def openfile(self):
     "Opens a FCMat file"
     filetuple = QtGui.QFileDialog.getOpenFileName(QtGui.QApplication.activeWindow(), 'Open FreeCAD Material file', '*.FCMat')
     filename = filetuple[0]  # a tuple of two empty strings returns True, so use the filename directly
     if filename:
         import importFCMat
         d = importFCMat.read(filename)
         if d:
             self.updateContents(d)
Пример #3
0
def read_cards_from_path(cards_path):
    from os import listdir
    from os.path import isfile, join, basename, splitext
    from importFCMat import read
    only_files = [f for f in listdir(cards_path) if isfile(join(cards_path, f))]
    mat_files = [f for f in only_files if basename(splitext(f)[1]) == '.FCMat' or basename(splitext(f)[1]) == '.fcmat']
    # print(mat_files)
    mat_cards = []
    for f in sorted(mat_files):
        mat_cards.append(read(join(cards_path, f)))
    return mat_cards
Пример #4
0
    def updateContents(self, data):

        '''updates the contents of the editor with the given data, can be:
           - a dictionary, if the editor was called  with data
           - a string, the name of a card, if material is changed in editors combo box
           the material property keys where added to the editor already
           not known material property keys will be added to the user defined group'''

        # print type(data)
        if isinstance(data, dict):
            # a standard material property dict is provided
            model = self.widget.treeView.model()
            root = model.invisibleRootItem()
            for gg in range(root.rowCount() - 1):
                group = root.child(gg, 0)
                for pp in range(group.rowCount()):
                    item = group.child(pp, 0)
                    it = group.child(pp, 1)
                    kk = self.collapseKey(item.text())

                    try:
                        value = data[kk]
                        it.setText(value)
                        del data[kk]
                    except KeyError:
                        it.setText("")

            userGroup = root.child(gg + 1, 0)
            userGroup.setRowCount(0)
            self.customprops = []

            for k, i in data.items():
                k = self.expandKey(k)
                item = QtGui.QStandardItem(k)
                it = QtGui.QStandardItem(i)
                userGroup.appendRow([item, it])
                self.customprops.append(k)

        elif isinstance(data, unicode):
            # a card name is provided, search card, read material data and call
            # this def once more with std material property dict
            k = str(data)
            if k:
                if k in self.cards:

                    from importFCMat import read
                    d = read(self.cards[k])
                    if d:
                        self.updateContents(d)
Пример #5
0
def read_cards_from_path(cards_path):
    from os import listdir
    from os.path import isfile, join, basename, splitext
    from importFCMat import read
    only_files = [
        f for f in listdir(cards_path) if isfile(join(cards_path, f))
    ]
    # to make sure all file lower and upper and mixed endings are found, use upper and .FCMAT
    mat_files = [
        f for f in only_files if basename(splitext(f)[1]).upper() == '.FCMAT'
    ]
    # print(mat_files)
    mat_cards = []
    for f in sorted(mat_files):
        mat_cards.append(read(join(cards_path, f)))
    return mat_cards
Пример #6
0
 def openfile(self):
     "Opens a FCMat file"
     filetuple = QtGui.QFileDialog.getOpenFileName(
         QtGui.QApplication.activeWindow(),
         'Open FreeCAD Material file',
         self.directory,
         '*.FCMat'
     )
     # a tuple of two empty strings returns True, so use the filename directly
     filename = filetuple[0]
     if filename:
         from importFCMat import read
         self.directory = os.path.dirname(filename)
         d = read(filename)
         if d:
             self.updateContents(d)
Пример #7
0
 def chooseMaterial(self, index):
     if index < 0:
         return
     self.card_path = self.widget.ComboMaterial.itemData(index)
     FreeCAD.Console.PrintMessage('choose_material in material editor:\n'
                                  '    {}\n'.format(self.card_path))
     if os.path.isfile(self.card_path):
         from importFCMat import read
         d = read(self.card_path)
         self.updateMatParamsInTree(d)
         # be careful with reading from materials dict
         # the card could be updated the dict not
         self.widget.ComboMaterial.setCurrentIndex(
             index)  # set after tree params
     else:
         FreeCAD.Console.PrintError('material card not found: {}\n'.format(
             self.card_path))
Пример #8
0
    def updateContents(self, data):
        '''updates the contents of the editor with the given data, can be:
           - the name of a card, if material is changed in editors combo box
           - a dictionary, if the editor was called with data.'''

        if isinstance(data, dict):

            # a standard material property dict is provided
            model = self.widget.treeView.model()
            root = model.invisibleRootItem()
            for gg in range(root.rowCount() - 1):
                group = root.child(gg, 0)
                for pp in range(group.rowCount()):
                    item = group.child(pp, 0)
                    it = group.child(pp, 1)
                    kk = self.collapseKey(item.text())

                    try:
                        value = data[kk]
                        it.setText(value)
                        del data[kk]
                    except KeyError:
                        it.setText("")

            userGroup = root.child(gg + 1, 0)
            userGroup.setRowCount(0)
            self.customprops = []

            for k, i in data.items():
                k = self.expandKey(k)
                item = QtGui.QStandardItem(k)
                it = QtGui.QStandardItem(i)
                userGroup.appendRow([item, it])
                self.customprops.append(k)

        elif isinstance(data, unicode):

            # a card name is provided, search card, read material data and call this def once more with std material property dict
            k = str(data)
            if k:
                if k in self.cards:

                    import importFCMat
                    d = importFCMat.read(self.cards[k])
                    if d:
                        self.updateContents(d)
Пример #9
0
    def updateContents(self, data):

        '''updates the contents of the editor with the given data, can be:
           - the name of a card, if material is changed in editors combo box
           - a dictionary, if the editor was called with data.'''

        if isinstance(data, dict):

            model = self.widget.treeView.model()
            root = model.invisibleRootItem()
            for gg in range(root.rowCount() - 1):
                group = root.child(gg, 0)
                for pp in range(group.rowCount()):
                    item = group.child(pp, 0)
                    it = group.child(pp, 1)
                    kk = self.collapseKey(item.text())

                    try:
                        value = data[kk]
                        it.setText(value)
                        del data[kk]
                    except KeyError:
                        it.setText("")

            userGroup = root.child(gg + 1, 0)
            userGroup.setRowCount(0)
            self.customprops = []

            for k, i in data.items():
                k = self.expandKey(k)
                item = QtGui.QStandardItem(k)
                it = QtGui.QStandardItem(i)
                userGroup.appendRow([item, it])
                self.customprops.append(k)

        elif isinstance(data, unicode):

            k = str(data)
            if k:
                if k in self.cards:

                    import importFCMat
                    d = importFCMat.read(self.cards[k])
                    if d:
                        self.updateContents(d)
Пример #10
0
 def updateContents(self,data):
     "updates the contents of the editor with the given data (can be the name of a card or a dictionary)"
     if isinstance(data,dict):
         self.clearEditor()
         for k,i in data.iteritems():
             k = self.expandKey(k)
             slot = self.Editor.findItems(k,QtCore.Qt.MatchRecursive,0)
             if len(slot) == 1:
                 slot = slot[0]
                 slot.setText(1,i)
             else:
                 self.addCustomProperty(k,i)
     elif isinstance(data,QtCore.QString):
         k = str(data)
         if k:
             if k in self.cards:
                 import importFCMat
                 d = importFCMat.read(self.cards[k])
                 if d:
                     self.updateContents(d)
Пример #11
0
 def updateContents(self, data):
     "updates the contents of the editor with the given data (can be the name of a card or a dictionary)"
     if isinstance(data, dict):
         self.clearEditor()
         for k, i in data.iteritems():
             k = self.expandKey(k)
             slot = self.Editor.findItems(k, QtCore.Qt.MatchRecursive, 0)
             if len(slot) == 1:
                 slot = slot[0]
                 slot.setText(1, i)
             else:
                 self.addCustomProperty(k, i)
     elif isinstance(data, QtCore.QString):
         k = str(data)
         if k:
             if k in self.cards:
                 import importFCMat
                 d = importFCMat.read(self.cards[k])
                 if d:
                     self.updateContents(d)
Пример #12
0
 def updateContents(self,data):
     "updates the contents of the editor with the given data (can be the name of a card or a dictionary)"
     #print type(data)
     if isinstance(data,dict):
         self.clearEditor()
         for k,i in data.items():
             k = self.expandKey(k)
             # most material dict keys are hard coded in ui file, not known keys are added to user defined group
             slot = self.widget.Editor.findItems(k,QtCore.Qt.MatchRecursive,0)
             if len(slot) == 1:
                 slot = slot[0]
                 slot.setText(1,i)
             else:
                 self.addCustomProperty(k,i)
     elif isinstance(data,unicode):
         k = str(data)
         if k:
             if k in self.cards:
                 import importFCMat
                 d = importFCMat.read(self.cards[k])
                 if d:
                     self.updateContents(d)
Пример #13
0
def add_cards_from_a_dir(materials, cards, icons, mat_dir, icon):
    # fill materials and icons
    import glob
    from importFCMat import read
    dir_path_list = glob.glob(mat_dir + '/*' + ".FCMat")
    mat_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Material/Cards")
    delete_duplicates = mat_prefs.GetBool("DeleteDuplicates", True)
    # duplicates are indicated on equality of mat dict
    # TODO if the unit is different two cards would be different too
    for a_path in dir_path_list:
        mat_dict = read(a_path)
        card_name = os.path.splitext(os.path.basename(a_path))[0]
        if delete_duplicates is False:
            materials[a_path] = mat_dict
            cards[a_path] = card_name
            icons[a_path] = icon
        else:
            if mat_dict not in materials.values():
                materials[a_path] = mat_dict
                cards[a_path] = card_name
                icons[a_path] = icon

    return (materials, cards, icons)
Пример #14
0
def add_cards_from_a_dir(materials,
                         cards,
                         icons,
                         mat_dir,
                         icon,
                         template=False):
    # fill materials and icons
    import glob
    from importFCMat import read
    dir_path_list = glob.glob(mat_dir + '/*' + ".FCMat")
    mat_prefs = FreeCAD.ParamGet(
        "User parameter:BaseApp/Preferences/Mod/Material/Cards")
    delete_duplicates = mat_prefs.GetBool("DeleteDuplicates", True)
    # duplicates are indicated on equality of mat dict
    # TODO if the unit is different two cards would be different too
    for a_path in dir_path_list:
        try:
            mat_dict = read(a_path)
        except:
            FreeCAD.Console.PrintError(
                'Error on reading card data. The card data will be empty for card:\n{}\n'
                .format(a_path))
            mat_dict = {}
        card_name = os.path.splitext(os.path.basename(a_path))[0]
        if (card_name == 'TEMPLATE') and (template is False):
            continue
        if delete_duplicates is False:
            materials[a_path] = mat_dict
            cards[a_path] = card_name
            icons[a_path] = icon
        else:
            if mat_dict not in materials.values():
                materials[a_path] = mat_dict
                cards[a_path] = card_name
                icons[a_path] = icon

    return (materials, cards, icons)
Пример #15
0
 def updateContents(self, data):
     '''updates the contents of the editor with the given data, can be:
        - the name of a card, if material is changed in editors combo box
        - a dictionary, if the editor was called  with data'''
     # print type(data)
     if isinstance(data, dict):
         self.clearEditor()
         for k, i in data.items():
             k = self.expandKey(k)
             # most material dict keys are added with addPropertiesToGroup, see tuple with all these properties at module end
             slot = self.widget.Editor.findItems(k, QtCore.Qt.MatchRecursive, 0)
             if len(slot) == 1:
                 slot = slot[0]
                 slot.setText(1, i)
             else:
                 self.addCustomProperty(k, i)
     elif isinstance(data, unicode):
         k = str(data)
         if k:
             if k in self.cards:
                 import importFCMat
                 d = importFCMat.read(self.cards[k])
                 if d:
                     self.updateContents(d)
Пример #16
0
 def chooseMat(self, card):
     "sets self.material from a card"
     if card in self.cards:
         import importFCMat
         self.material = importFCMat.read(self.cards[card])
         self.setFields()
Пример #17
0
 def chooseMat(self, card):
     "sets self.material from a card"
     if card in self.cards:
         import importFCMat
         self.material = importFCMat.read(self.cards[card])
         self.setFields()
Пример #18
0
def get_and_output_all_carddata(cards):
    print('\n\n\nSTART--get_and_output_all_carddata\n--------------------')
    # get all registered material property keys
    registed_cardkeys = []
    template_data = get_material_template()
    # print(template_data)
    for group in template_data:
        gg = list(group.keys())[0]  # group dict has only one key
        for key in group[gg]:
            registed_cardkeys.append(key)
    registed_cardkeys = sorted(registed_cardkeys)
    # print(registed_cardkeys)

    # get all data from all known cards
    all_cards_and_data = {}  # {cardfilename: ['path', materialdict]}
    for card in cards:
        from importFCMat import read
        d = read(cards[card])
        all_cards_and_data[card] = [cards[card], d]
    '''
    for card in all_cards_and_data:
        print(card)
        print(all_cards_and_data[card][0])
        print(all_cards_and_data[card][1])
        print('\n')
    '''

    # find not registered and registered keys in the used data
    used_and_registered_cardkeys = []
    used_and_not_registered_cardkeys = []
    registered_and_not_used_cardkeys = []
    for card in all_cards_and_data:
        for k in all_cards_and_data[card][1]:
            if k in registed_cardkeys:
                used_and_registered_cardkeys.append(k)
            else:
                used_and_not_registered_cardkeys.append(k)
    for k in registed_cardkeys:
        if (k not in used_and_registered_cardkeys) and (
                k not in used_and_not_registered_cardkeys):
            registered_and_not_used_cardkeys.append(k)

    used_and_registered_cardkeys = sorted(
        list(set(used_and_registered_cardkeys)))
    used_and_not_registered_cardkeys = sorted(
        list(set(used_and_not_registered_cardkeys)))
    registered_and_not_used_cardkeys = sorted(
        list(set(registered_and_not_used_cardkeys)))
    FreeCAD.Console.PrintMessage(
        '\nused_and_registered_cardkeys:\n{}\n'.format(
            used_and_registered_cardkeys))
    FreeCAD.Console.PrintMessage(
        '\nused_and_not_registered_cardkeys:\n{}\n'.format(
            used_and_not_registered_cardkeys))
    FreeCAD.Console.PrintMessage(
        '\nregistered_and_not_used_cardkeys:\n{}\n'.format(
            registered_and_not_used_cardkeys))

    # still there might be lots of properties in the template
    # which are not used in other materials
    # but the tmplate is handled here like a material
    print('--------------------\nget_and_output_all_carddata--END\n\n\n')