@@ -623,223 +623,6 @@ def execute(self, context):
623623 return {"FINISHED" }
624624
625625
626- class FilterModelElements (Operator ):
627- """Filter model elements based on selection"""
628-
629- bl_idname = "bim.filter_model_elements"
630- bl_label = "Filter Model Elements"
631- option : StringProperty ("select|isolate|hide" )
632-
633- def execute (self , context ):
634- selection_props = context .scene .IfcSelectorProperties
635- selection = (
636- selection_props .selector_query_syntax
637- if selection_props .manual_override
638- else self .add_groups (selection_props )
639- )
640- selection_props .selector_query_syntax = selection
641- r = core .search (tool .Search , tool .Spatial , query = selection , action = self .option )
642- if isinstance (r , str ):
643- self .report ({"WARNING" }, r )
644- return {"FINISHED" }
645-
646- def add_groups (self , selector : str ) -> str :
647- selection = ""
648- for group_index , group in enumerate (selector .groups ):
649- if group_index != 0 :
650- selection += " | "
651- selection += "(" if len (selector .groups ) > 1 else ""
652- selection = self .add_queries (selection , group )
653-
654- selection += ")" if len (selector .groups ) > 1 else ""
655- return selection
656-
657- def add_queries (self , selection : str , group : str ) -> str :
658- for query_index , query in enumerate (group .queries ):
659- if query_index != 0 :
660- selection += " & " if query .and_or == "and" else " | "
661-
662- if query .selector == "IFC Class" :
663- active_option = query .active_option .split (": " )[1 ]
664- selection += f".{ active_option } "
665- selection = self .add_filters (selection , query )
666-
667- elif query .selector == "GlobalId" :
668- selection += f"#{ query .value } "
669-
670- elif query .selector == "IfcElementType" :
671- index = int (query .active_sub_option .split (":" )[0 ])
672- selection += f"* #{ query .sub_options [index ].global_id } "
673-
674- elif query .selector == "IfcSpatialElement" :
675- index = int (query .active_sub_option .split (":" )[0 ])
676- selection += f"@ #{ query .sub_options [index ].global_id } "
677- return selection
678-
679- def add_filters (self , selection : str , query : str ) -> str :
680- for f_index , f in enumerate (query .filters ):
681- if f_index != 0 :
682- selection += " & " if f .and_or == "and" else " | "
683- selection += f".{ query .active_option } "
684-
685- if f .value in ("True" , "False" ):
686- value = f .value
687- elif f .value .isnumeric () and str (float (f .value ))[0 ] == f .value [0 ]:
688- value = f .value
689- else :
690- value = f'"{ f .value } "'
691-
692- selection += "["
693-
694- if f .selector == "IfcPropertySet" :
695- selection += f'{ f .active_option .split (": " )[1 ]} .{ f .active_sub_option .split (": " )[1 ]} { "!" if f .negation else "" } { f .comparison } { value } '
696- elif f .selector == "Attribute" :
697- # we're using the prop_search functionality in blender which returns the index of the option. Sometimes the user can override this and enter a value that doesn't exist in the list. In this case there is no index and we need to handle it. @vulevukusej
698- pattern = re .compile (r"^[0-9]+:" )
699- match = pattern .search (f .active_option )
700- selection += f'{ f .active_option .split (": " )[1 ] if match else f .active_option } { "!" if f .negation else "" } { f .comparison } { value } '
701- selection += "]"
702- return selection
703-
704-
705- # This needs to be moved into ui code, I know ;) - vulevukusej
706- class IfcSelector (Operator ):
707- """Select elements in model with IFC Selector"""
708-
709- bl_idname = "bim.ifc_selector"
710- bl_label = "Select elements with IFC Selector"
711-
712- def invoke (self , context , event ):
713- return context .window_manager .invoke_props_dialog (self , width = 800 )
714-
715- @classmethod
716- def poll (cls , context ):
717- return IfcStore .get_file ()
718-
719- def execute (self , context ):
720- return {"FINISHED" }
721-
722- def draw (self , context ):
723- from . import ui
724-
725- ui .IfcSelectorUI .draw (context , self .layout )
726-
727-
728- class SaveSelectorQuery (Operator ):
729- bl_idname = "bim.save_selector_query"
730- bl_label = "Save Selector Query"
731- save_name : StringProperty ()
732-
733- def invoke (self , context , event ):
734- return context .window_manager .invoke_props_dialog (self , width = 400 )
735-
736- def draw (self , context ):
737- layout = self .layout
738- layout .prop (self , "save_name" )
739-
740- def execute (self , context ):
741- ifc_selector = context .scene .IfcSelectorProperties
742- new = ifc_selector .query_library .add ()
743- new .name = self .save_name
744- new .query = ifc_selector .selector_query_syntax
745- return {"FINISHED" }
746-
747-
748- class OpenQueryLibrary (Operator ):
749- """Open Query Library"""
750-
751- bl_idname = "bim.open_query_library"
752- bl_label = "Open Query Library"
753-
754- def invoke (self , context , event ):
755- return context .window_manager .invoke_popup (self , width = 400 )
756-
757- def draw (self , context ):
758- layout = self .layout
759- ifc_selector = context .scene .IfcSelectorProperties
760-
761- for index , query in enumerate (ifc_selector .query_library ):
762- row = layout .row (align = True )
763- row .prop (query , "query" , text = query .name )
764- op = row .operator ("bim.load_query" , icon = "SORT_ASC" , text = "" )
765- op .index = index
766-
767- row .context_pointer_set (name = "bim_prop_group" , data = ifc_selector )
768- op = row .operator ("bim.edit_blender_collection" , icon = "REMOVE" , text = "" )
769- op .option = "remove"
770- op .collection = "query_library"
771- op .index = index
772-
773- def execute (self , context ):
774- return {"FINISHED" }
775-
776-
777- class LoadQuery (Operator ):
778- bl_idname = "bim.load_query"
779- bl_label = "Load Query"
780- index : IntProperty ()
781-
782- def invoke (self , context , event ):
783- close_operator_panel (event )
784- return self .execute (context )
785-
786- def execute (self , context ):
787- ifc_selector = context .scene .IfcSelectorProperties
788- ifc_selector .selector_query_syntax = ifc_selector .query_library [self .index ].query
789- return {"FINISHED" }
790-
791-
792- class AddToIfcGroup (Operator ):
793- bl_idname = "bim.add_to_ifc_group"
794- bl_label = "Add to IFC Group"
795- group_name : StringProperty (name = "Group Name" )
796-
797- def invoke (self , context , event ):
798- bpy .ops .bim .load_groups ()
799- return context .window_manager .invoke_props_dialog (self , width = 400 )
800-
801- def draw (self , context ):
802- self .props = context .scene .BIMGroupProperties
803- row = self .layout .row ()
804- row .operator ("bim.add_group" )
805-
806- self .layout .template_list (
807- "BIM_UL_groups" ,
808- "" ,
809- self .props ,
810- "groups" ,
811- self .props ,
812- "active_group_index" ,
813- )
814-
815- if self .props .active_group_id :
816- for attribute in self .props .group_attributes :
817- if attribute .name in ["Name" , "Description" ]:
818- row = self .layout .row (align = True )
819- row .prop (attribute , "string_value" , text = attribute .name )
820-
821- def execute (self , context ):
822- active_group_index = self .props .active_group_index
823- ifc_definition_id = self .props .groups [active_group_index ].ifc_definition_id
824-
825- bpy .ops .bim .enable_editing_group (group = ifc_definition_id )
826-
827- selector_query_syntax = context .scene .IfcSelectorProperties .selector_query_syntax
828-
829- for attribute in self .props .group_attributes :
830- if attribute .name == "Description" :
831- if "*selector*" not in attribute .string_value :
832- attribute .string_value += f" *selector*{ selector_query_syntax } *selector*"
833- else :
834- new_description = attribute .string_value .split ("*selector*" )
835- new_description [1 ] = selector_query_syntax
836- attribute .string_value = "*selector*" .join (new_description )
837-
838- bpy .ops .bim .edit_group ()
839- bpy .ops .bim .disable_group_editing_ui ()
840- return {"FINISHED" }
841-
842-
843626class SelectSimilar (Operator , tool .Ifc .Operator ):
844627 bl_idname = "bim.select_similar"
845628 bl_label = "Select Similar"
0 commit comments