@@ -123,19 +123,19 @@ def run(self, ifc_files: [IfcFileClass]):
123123 ## end copy form old ifc check (only tempory until new structure is working)
124124
125125 # check uniqueness of GUIDs
126- self .all_guids_unique , self .double_guids = self .run_check_guid_unique (ifc_file )
126+ self .all_guids_unique , self .double_guids = CheckLogicBase .run_check_guid_unique (ifc_file )
127127 list_guids_non_unique = list (self .double_guids .keys ())
128128 self .logger .info ("the GUIDs of all elements are unique: {}" .format (self .all_guids_unique ))
129129 if self .all_guids_unique is False :
130130 self .logger .critical ("non-unique GUIDs: {}" .format (list_guids_non_unique ))
131131 # check emptyness of GUID fields
132- self .all_guids_filled , self .empty_guids = self .run_check_guid_empty (ifc_file )
132+ self .all_guids_filled , self .empty_guids = CheckLogicBase .run_check_guid_empty (ifc_file )
133133 list_guids_empty = list (self .empty_guids .keys ())
134134 self .logger .info ("the GUIDs of all elements are filled (NOT empty): {}" .format (self .all_guids_filled ))
135135 if self .all_guids_filled is False :
136136 self .logger .critical ("empty GUIDs: {}" .format (list_guids_empty ))
137137 # check ifc version
138- self .version_error , self .ifc_version = self .run_check_ifc_version (ifc_file )
138+ self .version_error , self .ifc_version = CheckLogicBase .run_check_ifc_version (ifc_file )
139139 # for doc string
140140 # Logs:
141141 # critical: if loaded IFC is not IFC4
@@ -196,95 +196,7 @@ def validate_sub_inst(self, sub_inst: list) -> list:
196196
197197
198198
199- def run_check_guid_unique (self , ifc_file ) -> (bool , dict ):
200- """check the uniqueness of the guids of the IFC file
201-
202- Input:
203- ifc_file: path of the IFC file, which is checked
204-
205- Returns:
206- all_guids_unique: boolean
207- (true: all guids are unique
208- false: one or more guids are not unique)
209-
210- double_guid: dict
211-
212- """
213- # TODO bring output into the log
214- used_guids : dict [str , ifcos .entity_instance ] = dict () # dict of all elements with guids used in the checked ifc model
215- double_guids : dict [str , ifcos .entity_instance ] = dict () # dict of elements with guids, which are not unique
216- all_guids_unique = True
217-
218- for inst in ifc_file .file :
219- if hasattr (inst , "GlobalId" ):
220- guid = inst .GlobalId
221- name = inst .Name
222- # print(guid)
223- if guid in used_guids :
224- double_guids [guid ] = inst
225- all_guids_unique = False
226- else :
227- used_guids [guid ] = inst
228-
229- return (all_guids_unique , double_guids )
230-
231- def run_check_guid_empty (self , ifc_file ) -> (bool , dict ):
232- """check it there is/are guid/s, which is/are empty in the IFC file
233-
234- Input:
235- ifc_file: path of the IFC file, which is checked
236-
237- Returns:
238- all_guids_filled: boolean
239- (true: all guids has a value (not empty)
240- false: one or more guids has not value (empty))
241-
242- empty_guid: dict
243-
244- """
245-
246- used_guids : dict [str , ifcos .entity_instance ] = dict () # dict of all elements with guids used in the checked ifc model
247- empty_guids : dict [str , ifcos .entity_instance ] = dict () # dict of elements with guids, which are empty
248- all_guids_filled = True
249- guid_empty_no = 0 # count the number of guids without value (empty), this number is used to make unique identifier
250- for inst in ifc_file .file :
251- if hasattr (inst , "GlobalId" ):
252- guid = inst .GlobalId
253- name = inst .Name
254- if guid == '' :
255- all_guids_filled = False
256- guid_empty_no = guid_empty_no + 1
257- name_dict = name + '--' + str (guid_empty_no )
258- empty_guids [name_dict ] = inst
259- else :
260- used_guids [guid ] = inst
261-
262- return (all_guids_filled , empty_guids )
263-
264- @staticmethod
265- def run_check_ifc_version (ifc : ifcos .file ) -> (bool , str ):
266- """
267- Checks the IFC version.
268-
269- Only IFC4 files are valid for bim2sim.
270199
271- Attention: no Error is raised anymore.
272-
273- Args:
274- ifc: ifc file loaded with IfcOpenShell
275- Return:
276- version_error: True if version NOT fit
277- ifc_version: version of the ifc file
278- """
279- schema = ifc .schema
280- if "IFC4" not in schema :
281- version_error = True
282- # raise TypeError(f"Loaded IFC file is of type {schema} but only IFC4"
283- # f"is supported. Please ask the creator of the model"
284- # f" to provide a valid IFC4 file.")
285- else :
286- version_error = False
287- return (version_error , schema )
288200
289201 @staticmethod
290202 def run_ids_check_on_ifc (ifc_file : str , ids_file : str , report_html : bool = False , log_path : str = None ) -> bool :
@@ -529,5 +441,111 @@ def validate_sub_inst(self, bound: entity_instance) -> list:
529441 error )
530442 return error
531443
444+
445+ class CheckLogicBase ():
446+ """Provides logic for ifc files checking regarding simulation.
447+
448+ This is a base class. This base class includes all check logic, which is
449+ useful for all checking use cases.
450+ """
451+
452+ def run_check_guid_unique (ifc_file ) -> (bool , dict ):
453+ """check the uniqueness of the guids of the IFC file
454+
455+ Input:
456+ ifc_file: path of the IFC file, which is checked
457+
458+ Returns:
459+ all_guids_unique: boolean
460+ (true: all guids are unique
461+ false: one or more guids are not unique)
462+
463+ double_guid: dict
464+
465+ """
466+ # TODO bring output into the log
467+ used_guids : dict [str , ifcos .entity_instance ] = dict () # dict of all elements with guids used in the checked ifc model
468+ double_guids : dict [str , ifcos .entity_instance ] = dict () # dict of elements with guids, which are not unique
469+ all_guids_unique = True
470+
471+ for inst in ifc_file .file :
472+ if hasattr (inst , "GlobalId" ):
473+ guid = inst .GlobalId
474+ name = inst .Name
475+ # print(guid)
476+ if guid in used_guids :
477+ double_guids [guid ] = inst
478+ all_guids_unique = False
479+ else :
480+ used_guids [guid ] = inst
481+
482+ return (all_guids_unique , double_guids )
483+
484+ def run_check_guid_empty (ifc_file ) -> (bool , dict ):
485+ """check it there is/are guid/s, which is/are empty in the IFC file
486+
487+ Input:
488+ ifc_file: path of the IFC file, which is checked
489+
490+ Returns:
491+ all_guids_filled: boolean
492+ (true: all guids has a value (not empty)
493+ false: one or more guids has not value (empty))
494+
495+ empty_guid: dict
496+
497+ """
498+
499+ used_guids : dict [str , ifcos .entity_instance ] = dict () # dict of all elements with guids used in the checked ifc model
500+ empty_guids : dict [str , ifcos .entity_instance ] = dict () # dict of elements with guids, which are empty
501+ all_guids_filled = True
502+ guid_empty_no = 0 # count the number of guids without value (empty), this number is used to make unique identifier
503+ for inst in ifc_file .file :
504+ if hasattr (inst , "GlobalId" ):
505+ guid = inst .GlobalId
506+ name = inst .Name
507+ if guid == '' :
508+ all_guids_filled = False
509+ guid_empty_no = guid_empty_no + 1
510+ name_dict = name + '--' + str (guid_empty_no )
511+ empty_guids [name_dict ] = inst
512+ else :
513+ used_guids [guid ] = inst
514+
515+ return (all_guids_filled , empty_guids )
516+
517+
518+ @staticmethod
519+ def run_check_ifc_version (ifc : ifcos .file ) -> (bool , str ):
520+ """
521+ Checks the IFC version.
522+
523+ Only IFC4 files are valid for bim2sim.
524+
525+ Attention: no Error is raised anymore.
526+
527+ Args:
528+ ifc: ifc file loaded with IfcOpenShell
529+ Return:
530+ version_error: True if version NOT fit
531+ ifc_version: version of the ifc file
532+ """
533+ schema = ifc .schema
534+ if "IFC4" not in schema :
535+ version_error = True
536+ # raise TypeError(f"Loaded IFC file is of type {schema} but only IFC4"
537+ # f"is supported. Please ask the creator of the model"
538+ # f" to provide a valid IFC4 file.")
539+ else :
540+ version_error = False
541+ return (version_error , schema )
542+
543+
544+ class CheckLogicBPS (CheckLogicBase ):
545+ """Provides additional logic for ifc files checking regarding BPS."""
546+
547+
548+
549+
532550if __name__ == '__main__' :
533551 pass
0 commit comments