From 20fe2aabee8d880156bf8c0cd6e1445edf582a63 Mon Sep 17 00:00:00 2001 From: Furgo <148809153+furgo16@users.noreply.github.com> Date: Sun, 5 May 2024 09:53:37 +0200 Subject: [PATCH] Arch: adapt materials to new Materials path scheme --- src/Mod/Arch/ArchMaterial.py | 33 ++++++++++++++++++++++++--------- src/Mod/Material/importFCMat.py | 4 ++-- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/Mod/Arch/ArchMaterial.py b/src/Mod/Arch/ArchMaterial.py index f5d39abcb1..2c18322e85 100644 --- a/src/Mod/Arch/ArchMaterial.py +++ b/src/Mod/Arch/ArchMaterial.py @@ -652,7 +652,7 @@ class _ArchMaterialTaskPanel: "sets self.material from a card" if card in self.cards: import importFCMat - self.material = importFCMat.read(self.cards[card]) + self.material = importFCMat.read(self.cards[card][0], self.cards[card][1]) self.setFields() def fromExisting(self,index): @@ -690,16 +690,31 @@ class _ArchMaterialTaskPanel: "fills the combo with the existing FCMat cards" # look for cards in both resources dir and a Materials sub-folder in the user folder. # User cards with same name will override system cards - paths = [FreeCAD.getResourceDir() + os.sep + "Mod" + os.sep + "Material" + os.sep + "StandardMaterial"] - ap = FreeCAD.ConfigGet("UserAppData") + os.sep + "Materials" - if os.path.exists(ap): - paths.append(ap) + resources_mat_path = os.path.join(FreeCAD.getResourceDir(), "Mod", "Material", "Resources", "Materials") + resources_mat_path_std = os.path.join(resources_mat_path, "Standard") + user_mat_path = os.path.join(FreeCAD.ConfigGet("UserAppData"), "Material") + + paths = [resources_mat_path_std] + if os.path.exists(user_mat_path): + paths.append(user_mat_path) self.cards = {} + library = None for p in paths: - for f in os.listdir(p): - b,e = os.path.splitext(f) - if e.upper() == ".FCMAT": - self.cards[b] = p + os.sep + f + for root, _, f_names in os.walk(p): + for f in f_names: + b,e = os.path.splitext(f) + if e.upper() == ".FCMAT": + if p == resources_mat_path_std: + root_removed = root.replace(resources_mat_path, '') + library = "System" + else: + root_removed = root.replace(p, '') + library = "User" + mat_path = os.path.join(root_removed, f) + # Material paths follow the OS' filesystem hierarchy but + # are stored internally separated by '/', regardless of the platform + # E.g. '/Standard/Metal/Steel/CalculiX-Steel.FCMat' + self.cards[b] = (mat_path.replace(os.sep, '/'), library) if self.cards: for k in sorted(self.cards): self.form.comboBox_MaterialsInDir.addItem(k) diff --git a/src/Mod/Material/importFCMat.py b/src/Mod/Material/importFCMat.py index 524ce60a15..cdd5ed0ea9 100644 --- a/src/Mod/Material/importFCMat.py +++ b/src/Mod/Material/importFCMat.py @@ -97,9 +97,9 @@ def decode(name): # as we had and we might will have problems again and again # https://github.com/berndhahnebach/FreeCAD_bhb/commits/materialdev -def read(filename): +def read(filename, library): materialManager = Materials.MaterialManager() - material = materialManager.getMaterialByPath(filename) + material = materialManager.getMaterialByPath(filename, library) return material.Properties # Metainformation