| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | """Diffing tool for NativeIFC project objects""" |
| |
|
| | import difflib |
| |
|
| | import ifcopenshell |
| |
|
| | import FreeCAD |
| | import FreeCADGui |
| | import Arch_rc |
| |
|
| | from . import ifc_tools |
| |
|
| | translate = FreeCAD.Qt.translate |
| |
|
| |
|
| | def get_diff(proj): |
| | """Obtains a diff between the current version and the saved version of a project""" |
| |
|
| | if not getattr(proj, "IfcFilePath", None): |
| | old = [] |
| | return 1 |
| | else: |
| | |
| | |
| | f = ifcopenshell.open(proj.IfcFilePath) |
| | old = f.wrapped_data.to_string().split("\n") |
| | if not old: |
| | return "" |
| | ifcfile = ifc_tools.get_ifcfile(proj) |
| | if not ifcfile: |
| | return "" |
| | new = ifcfile.wrapped_data.to_string().split("\n") |
| | |
| | res = [l for l in difflib.unified_diff(old, new, lineterm="")] |
| | res = [l for l in res if l.startswith("+") or l.startswith("-")] |
| | res = [l for l in res if not l.startswith("+++") and not l.startswith("---")] |
| | return "\n".join(res) |
| |
|
| |
|
| | def htmlize(diff): |
| | """Returns an HTML version of a diff list""" |
| |
|
| | html = "<html><body>\n" |
| | if diff == 1: |
| | html += ( |
| | translate( |
| | "BIM", |
| | "The IFC file is not saved. Save once" |
| | " to have an existing IFC file to compare with." |
| | " Then, run this command again.", |
| | ) |
| | + "<br/>\n" |
| | ) |
| | elif diff: |
| | diff = diff.split("\n") |
| | for l in diff: |
| | if l.startswith("+"): |
| | html += "<span style='color:green;'>" + l[:100] + "</span><br/>\n" |
| | elif l.startswith("-"): |
| | html += "<span style='color:red;'>" + l[:100] + "</span><br/>\n" |
| | else: |
| | html += l + "<br/>\n" |
| | else: |
| | html += translate("BIM", "No changes to display.") + "<br/>\n" |
| | html += "</body></html>" |
| | return html |
| |
|
| |
|
| | def show_diff(diff): |
| | """Shows a dialog showing the diff contents""" |
| |
|
| | dlg = FreeCADGui.PySideUic.loadUi(":/ui/dialogDiff.ui") |
| | dlg.textEdit.setStyleSheet("background-color: white; color: black;") |
| | dlg.textEdit.setHtml(htmlize(diff)) |
| | result = dlg.exec_() |
| |
|