From 717c28b7c9fdec86eecc5c71a614b04dbb3993ce Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 10 Jul 2023 17:16:20 +1000 Subject: [PATCH] Override Ctrl-N new file menu to make it easier to start new projects and new IFC icon. --- src/blenderbim/blenderbim/bim/__init__.py | 23 ++++ .../blenderbim/bim/data/icons/IFC.png | Bin 0 -> 2404 bytes .../bim/module/geometry/__init__.py | 13 +++ .../blenderbim/bim/module/project/__init__.py | 18 ++++ .../blenderbim/bim/module/project/ui.py | 35 ++++-- src/blenderbim/blenderbim/bim/prop.py | 33 +++--- src/blenderbim/scripts/icons.svg | 100 ++++++++++++++++++ 7 files changed, 199 insertions(+), 23 deletions(-) create mode 100644 src/blenderbim/blenderbim/bim/data/icons/IFC.png create mode 100644 src/blenderbim/scripts/icons.svg diff --git a/src/blenderbim/blenderbim/bim/__init__.py b/src/blenderbim/blenderbim/bim/__init__.py index 529fc28676..cff7dd9022 100644 --- a/src/blenderbim/blenderbim/bim/__init__.py +++ b/src/blenderbim/blenderbim/bim/__init__.py @@ -16,11 +16,15 @@ # You should have received a copy of the GNU General Public License # along with BlenderBIM Add-on. If not, see . +import os import bpy +import bpy.utils.previews import blenderbim import importlib from . import handler, ui, prop, operator, helper +cwd = os.path.dirname(os.path.realpath(__file__)) + modules = { "project": None, "search": None, @@ -143,6 +147,9 @@ for mod in modules.values(): classes.extend(mod.classes) +icons = None + + def on_register(scene): handler.setDefaultProperties(scene) if not bpy.app.background: @@ -177,8 +184,24 @@ def register(): for mod in modules.values(): mod.register() + global icons + + icons_dir = os.path.join(cwd, "data", "icons") + icon_preview = bpy.utils.previews.new() + for filename in os.listdir(icons_dir): + if filename.endswith(".png"): + icon_name = os.path.splitext(filename)[0] + icon_path = os.path.join(icons_dir, filename) + icon_preview.load(icon_name, icon_path, "IMAGE") + + icons = icon_preview + def unregister(): + global icons + + bpy.utils.previews.remove(icons) + for cls in reversed(classes): if getattr(cls, "is_registered", None) is None: bpy.utils.unregister_class(cls) diff --git a/src/blenderbim/blenderbim/bim/data/icons/IFC.png b/src/blenderbim/blenderbim/bim/data/icons/IFC.png new file mode 100644 index 0000000000000000000000000000000000000000..fa6a5a8ef87f8da81b27e2bb338aa73fd83694e4 GIT binary patch literal 2404 zcmV-q37htbP)j{00009a7bBm000*< z000*<0rj`@#sB~S8FWQhbW?9;ba!ELWdL_~cP?peYja~^aAhuUa%Y?FJQ@H12=Pfo zK~!jg#hYu4T~!r;*X_*M*R(c_RH{%wC_;hO3K6VStQsB(ROfF{SJAtj)3mP6FxAF1hbC}k zg{`siXMm=#h=VKY=+J z{$yaYfxkUdOn@V4JyCxFrh76h1;!%uMu7`bbxKwIY}8oA;6>o5(!A-wR%6}(Fb#L5 z_GJHm99_V&ESD3%0?E&6isBal2MqYL zxJKf0k2yVE)Jqn={wX}rat_XhBZc9p*pH6k(CggdgjdClgWfLGm?kNIlR=D(VRwRXUBGXF zjkp~>4Hz=$uS}qwk8X4$Vz2`^ygb+c&;ag8Q2ZC9@65H{ytUrEMX2KvgBucg2zmma zH0W(ZW04l+yU-}ff}3jy)D8T*H2-Jb_vfL{QV0&APi!i`slZc){9Ax2l$2j*Olktx z)euC0c>!8K_HZsD?zH@|CeInb^M)?{WHv~E3k~E$z*RMc$d7gizUSe^oR(4QJ%2*l zv$~2*`9DRFMycs9dt-KlZWFk|!(AT1{csz+j{~Nr{#AY@?RR^y;0C7AOwEUVU5Y? zTUy?!t0VM57kN>J+W_v#{{J>=G<{k}17`uJpbm~DPb{onC#dm>!6vGst9&fZaNhBR zeuSc5eS^Vc2$$aK0@eeUlz2Q>n)5pF1F9EcI`C(M=Qjnlrm-|Jz++TLSt|(p|8JKR zxYgiMmEIEI8sb;y!IEr!3Hs~-dh-dhu+zn>JO&Nmrv^U2hSHq74E%pkyf!Nmcx=SQ z4j;h|pGVM>RB&&PL33+Wum`K(f zW6_n1!7xSl^m5{FGUyKXmUzu3T%auTxFUf^N>Vkb{7JxT27@;#R$Z54=lvc*@3x>v ze*gmN`6~)Z(h6ElfOLJBm`0rMS1x@E#9TCp}AEKy8 z*+unX42{Oh*D9rG;d^hFpwVF!9HKhC-GfG)GJzC zUBTyY+{<8%X~5GF`dbAp4u)W9BBRiFv_$WA?>nn#F-E5vfDn(H2XWzS z-O&?J?nV#CDq0M5sQePbPSO7SXvVyz-L!UGq>Nb+n#(;rtJ9)#+U*wNUi%QmUL!Wq7HAe2(}IjG%@u$1fKx2C3JnakC*mXf?VET7CPJD(92b zD<1yHpcg7yfcg8r(P33(g!H6pOOI}d z;E}|uoMa4Bgv)ovGOB*m)kC}$&9_xnOG*>%5NVkoBYYgLAut5LOjKUbg}UFM_Zk|G zrqG*$-QwB=z7wKhF*pVIufd>Bt4d1H@e(e242>Ds&C2fp--yvk5%>(WqcH}tmhT=k z%*>M$ldyx17YOIzW)iO~gO=UR9^BL&TTHwKwF!KyVxE5|{ha+2?47IfD^jw_ZvkIS z(JNJX0ltLY@_m_yKNSrgYsy!EX8XA>~e<2^>hIH-Khp z+LpglUC%?rrHKH(cFIBmek78 zfN}d3^;bmX8WA~NM0!MIhls2fk<}tH(gwX=5m_c83q@p#i0l-R2Swy>;~}hw$o~N} WMM3W&jz_@&0000. import os +import blenderbim.bim from blenderbim.bim.helper import prop_with_search from bpy.types import Panel, Menu, UIList from blenderbim.bim.ifc import IfcStore @@ -28,12 +29,32 @@ class BIM_MT_project(Menu): bl_label = "New IFC Project" def draw(self, context): - layout = self.layout - layout.operator("bim.new_project", text="New Metric (m) Project").preset = "metric_m" - layout.operator("bim.new_project", text="New Metric (mm) Project").preset = "metric_mm" - layout.operator("bim.new_project", text="New Imperial (ft) Project").preset = "imperial_ft" - layout.operator("bim.new_project", text="New Demo Project").preset = "demo" - layout.operator("bim.new_project", text="New Project Wizard").preset = "wizard" + self.layout.operator("bim.new_project", text="New Metric (m) Project").preset = "metric_m" + self.layout.operator("bim.new_project", text="New Metric (mm) Project").preset = "metric_mm" + self.layout.operator("bim.new_project", text="New Imperial (ft) Project").preset = "imperial_ft" + self.layout.operator("bim.new_project", text="New Demo Project").preset = "demo" + self.layout.operator("bim.new_project", text="New Project Wizard").preset = "wizard" + + +class BIM_MT_new_project(Menu): + bl_idname = "BIM_MT_new_project" + bl_label = "New Project" + + def draw(self, context): + self.layout.label(text="New IFC Project", icon_value=blenderbim.bim.icons["IFC"].icon_id) + self.layout.operator("bim.new_project", text="Metric (m) Project").preset = "metric_m" + self.layout.operator("bim.new_project", text="Metric (mm) Project").preset = "metric_mm" + self.layout.operator("bim.new_project", text="Imperial (ft) Project").preset = "imperial_ft" + self.layout.operator("bim.new_project", text="Demo Project").preset = "demo" + self.layout.operator("bim.new_project", text="Project Wizard").preset = "wizard" + self.layout.separator() + self.layout.label(text="New Blender Project", icon="BLENDER") + # In theory we can dynamically grab the list from list(bpy.utils.app_template_paths()) + self.layout.operator("wm.read_homefile", text="General Project").app_template = "" + self.layout.operator("wm.read_homefile", text="2D Animation Project").app_template = "2D_Animation" + self.layout.operator("wm.read_homefile", text="Sculpting Project").app_template = "Sculpting" + self.layout.operator("wm.read_homefile", text="VFX Project").app_template = "VFX" + self.layout.operator("wm.read_homefile", text="Video Editing Project").app_template = "Video_Editing" def file_menu(self, context): @@ -205,7 +226,7 @@ class BIM_PT_project(Panel): row = self.layout.row(align=True) row.operator("bim.create_project") - row.operator("bim.load_project").should_start_fresh_session = False + row.operator("bim.load_project").should_start_fresh_session = True class BIM_PT_project_library(Panel): diff --git a/src/blenderbim/blenderbim/bim/prop.py b/src/blenderbim/blenderbim/bim/prop.py index d192394b69..690b4ae39d 100644 --- a/src/blenderbim/blenderbim/bim/prop.py +++ b/src/blenderbim/blenderbim/bim/prop.py @@ -30,8 +30,9 @@ from ifcopenshell.util.doc import ( get_property_doc, get_predefined_type_doc, ) -import blenderbim.bim.handler +import blenderbim.bim import blenderbim.bim.schema +import blenderbim.bim.handler from blenderbim.bim.ifc import IfcStore import blenderbim.tool as tool from collections import defaultdict @@ -335,22 +336,22 @@ class ModuleVisibility(PropertyGroup): is_visible: BoolProperty(name="Value", default=True, update=update_is_visible) +def get_tab(self, context): + return [ + ("PROJECT", "Project Overview", "", blenderbim.bim.icons["IFC"].icon_id, 0), + ("OBJECT", "Object Information", "", "FILE_3D", 1), + ("MATERIALS", "Materials and Styles", "", "MATERIAL", 2), + ("DRAWINGS", "Drawings and Documents", "", "DOCUMENTS", 3), + ("SERVICES", "Services and Systems", "", "NETWORK_DRIVE", 4), + ("STRUCTURE", "Structural Analysis", "", "EDITMODE_HLT", 5), + ("SCHEDULING", "Construction Scheduling", "", "NLA", 6), + ("FM", "Facility Management", "", "PACKAGE", 7), + ("OTHER", "Other Properties", "", "COLLAPSEMENU", 8), + ] + + class BIMAreaProperties(PropertyGroup): - tab: EnumProperty( - default="PROJECT", - items=[ - ("PROJECT", "Project Overview", "", "VIEW3D", 1), - ("OBJECT", "Object Information", "", "FILE_3D", 2), - ("MATERIALS", "Materials and Styles", "", "MATERIAL", 3), - ("DRAWINGS", "Drawings and Documents", "", "DOCUMENTS", 4), - ("SERVICES", "Services and Systems", "", "NETWORK_DRIVE", 5), - ("STRUCTURE", "Structural Analysis", "", "EDITMODE_HLT", 6), - ("SCHEDULING", "Construction Scheduling", "", "NLA", 7), - ("FM", "Facility Management", "", "PACKAGE", 8), - ("OTHER", "Other Properties", "", "COLLAPSEMENU", 9), - ], - name="Tab", - ) + tab: EnumProperty(default=0, items=get_tab, name="Tab") class BIMProperties(PropertyGroup): diff --git a/src/blenderbim/scripts/icons.svg b/src/blenderbim/scripts/icons.svg new file mode 100644 index 0000000000..ad622f3f07 --- /dev/null +++ b/src/blenderbim/scripts/icons.svg @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + +