Skip to content

Commit

Permalink
refactor commit of pending changes
Browse files Browse the repository at this point in the history
New DXFEntity.commit_pending_changes() method to commit
pending changes before DXF export, like temporary transformations
of ACIS entities.
  • Loading branch information
mozman committed Apr 9, 2024
1 parent 27ebde9 commit 44dd86c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
1 change: 0 additions & 1 deletion notes/pages/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ id:: 65e30c28-021e-4c24-ab6e-a9e9fa7c6a51
- NEW: support for transformation of [[ACIS]] based entities
- the transformation is stored as temporary transformation and will be applied automatically before export
- the applied transformation is a transformed anonymous block that contains that [[ACIS]] entity
- NEW: method `ezdxf.document.Drawing.apply_temporary_transformations()`, called automatically before DXF export
- NEW: function `ezdxf.transform.apply_temporary_transformations()`
- CHANGE: class `RenderContext` accepts ctb files as instances of `acadctb.ColorDependentPlotStyles`
- CHANGE: replaced the `Designer` class of the `drawing` add-on by a render pipeline with separated render stages
Expand Down
18 changes: 7 additions & 11 deletions src/ezdxf/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,9 @@ def write(self, stream: Union[TextIO, BinaryIO], fmt: str = "asc") -> None:
fmt: "asc" for ASCII DXF (default) or "bin" for binary DXF
"""
# These changes may alter the document content (create new entities, blocks ...)
# and have to be done before the export and the update of internal structures
# can be done.
self.commit_pending_changes()

dxfversion = self.dxfversion
Expand Down Expand Up @@ -643,6 +646,10 @@ def export_sections(self, tagwriter: AbstractTagWriter) -> None:

tagwriter.write_tag2(0, "EOF")

def commit_pending_changes(self) -> None:
for entity in self.entitydb.values():
entity.commit_pending_changes()

def update_all(self) -> None:
if self.dxfversion > DXF12:
self.classes.add_required_classes(self.dxfversion)
Expand Down Expand Up @@ -1176,17 +1183,6 @@ def set_modelspace_vport(self, height, center=(0, 0), *, dxfattribs=None) -> VPo
self.header.reset_wcs()
return vport

def commit_pending_changes(self) -> None:
"""Commit all pending changes."""
self.apply_temporary_transformations()

def apply_temporary_transformations(self) -> None:
"""Apply temporary transformations to all entities in this drawing."""
for entity in self.entitydb.values():
if isinstance(entity, SupportsTemporaryTransformation):
tt = entity.temporary_transformation()
tt.apply_transformation(entity)


class MetaData(abc.ABC):
"""Manage ezdxf meta-data by dict-like interface. Values are limited to
Expand Down
3 changes: 3 additions & 0 deletions src/ezdxf/entities/acis.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ def convert_acis_data(self) -> None:
if msg:
logger.info(msg)

def commit_pending_changes(self) -> None:
self._temporary_transformation.apply_transformation(self)

def preprocess_export(self, tagwriter: AbstractTagWriter) -> bool:
msg = ""
if tagwriter.dxfversion < const.DXF2013:
Expand Down
7 changes: 7 additions & 0 deletions src/ezdxf/entities/dxfentity.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,13 @@ def _silent_kill(self): # final - do not override this method!
del self.doc
del self.dxf # check mark for is_alive

def commit_pending_changes(self) -> None:
"""Commit all unapplied changes like temporary transformations of ACIS entities.
(internal API)
"""
pass

def preprocess_export(self, tagwriter: AbstractTagWriter) -> bool:
"""Pre requirement check and pre-processing for export.
Expand Down

0 comments on commit 44dd86c

Please sign in to comment.