21 | %language ElabReflection
22 | %hide Language.Reflection.TTImp.Mode
24 | ||| Record pairing graph with one of its node's index
33 | export
37 | --------------------------------------------------------------------------------
38 | -- Drawing Mode
39 | --------------------------------------------------------------------------------
66 | --------------------------------------------------------------------------------
67 | -- Hovering Rules
68 | --------------------------------------------------------------------------------
95 | --------------------------------------------------------------------------------
96 | -- Drawing State
97 | --------------------------------------------------------------------------------
101 | [noHints]
115 | ||| Current SVG scene rendered to a string
116 | ||| We keep track of this and the previous one to easily
117 | ||| decide when to redraw the scene.
120 | ||| Previous SVG scene rendered to a string
139 | ||| True, if the current mol graph is the empty graph.
144 | --------------------------------------------------------------------------------
145 | -- State initialization
146 | --------------------------------------------------------------------------------
148 | ||| Mode used to scale a molecule.
149 | |||
150 | ||| This is used when centering a molecule, for instance, when we begin
151 | ||| drawing, or when we just display a molecule and want to zoom in for it
152 | ||| to fill the whole scene.
155 | ||| Scale mode used when initializing a scene for drawing
158 | ||| Scale mode used when centering the molecule (by pressing the "reset" button)
161 | ||| Scale mode used when displaying a molecule so that it fills the whole
162 | ||| scene
180 | export
184 | ||| Scales the molecule at the current mouse position.
185 | export
189 | ||| Scales the molecule at the center of the scene
190 | export
197 | where
206 | where
223 | export
227 | export
231 | --------------------------------------------------------------------------------
232 | -- Current Molecule
233 | --------------------------------------------------------------------------------
235 | -- Computes the molecule to be drawn based on the current
236 | -- state and mode. This is used both for displaying the current
237 | -- molecule in its editing state as well as for replacing the current
238 | -- molecule with its updated version when an editing step ends
239 | -- Using this for drawing allows us to not store additional information
240 | -- in the drawing mode.
265 | --------------------------------------------------------------------------------
266 | -- Editing Molecule
267 | --------------------------------------------------------------------------------
269 | -- overwrites the current molecule, adding it to the `undo` stack
279 | -- adjusts the atoms fulfilling the given predicate with the given function
280 | -- this will delete any abbreviation associated with these atoms.
290 | where
294 | -- adjusts the currently hovered atom with the given function
295 | -- this will delete any abbreviation associated with the hovered atom.
299 | %inline
303 | -- delete the currently selected atoms
304 | %inline
308 | --------------------------------------------------------------------------------
309 | -- Current Selection
310 | --------------------------------------------------------------------------------
312 | -- draws a rectangle around the currently selected atoms (if any),
313 | -- depending on whether the mouse is currently within the dragging zone
320 | -- tests if any atoms are selected and if that's the case, whether
321 | -- the mouse is currently in the dragging zone.
330 | -----------------------------------------------------------------------------
331 | -- Update State
332 | -----------------------------------------------------------------------------
346 | ST
360 | }
381 | -- Elaborates the current mode and elevates the fitting argument to a return
382 | -- value
383 | export
405 | -- When we move the mouse, we must adjust the current mouse position
406 | -- in the application state. If the middle mouse button is pressed,
407 | -- we also translate the drawing area, otherwise we adjust the hovering
408 | -- state of atoms.
422 | -- Pressing the left button typically begins an editing step
423 | -- If this step depends on the start and end position of the mouse,
424 | -- we enter a new mode and finish editing on the `leftUp` event.
425 | -- Otherwise (for instance, when setting the label of an atom at
426 | -- the mouse position),
427 | -- the modification happens immediately.
434 | applyWhenSel
435 | s
461 | -- adding template at hovered atom
466 | -- exactly one overlap -> rotating around it possible
478 | -- When the left mouse button is lifted, this ends an ongoing editing
479 | -- or selection process. We typically overwrite the current molecule with
480 | -- the freshly edited one, adjust the drawing roles of atoms and bonds, and
481 | -- determine the currently hovered atom anew.
497 | %inline
519 | -- Adds a bond to the molecule when hovering over a node
520 | -- (excluding nodes that are abbreviations),
521 | -- or changes the bond type (e.g., from Single to Triple) when
522 | -- hovering over an edge with NoBondStereo.
544 | -- Adds a group to the molecule if hovering over a valid atom or bond,
545 | -- ensuring it's not an abbreviation.
563 | -- Adds an abbreviation to the molecule if hovering over a valid atom,
564 | -- ensuring it's not an abbreviation.
577 | in
581 | -- Enables node-edge-node navigation by setting 'Hover' to the neighbor whose
582 | -- bond angle best matches the input angle, if the angle difference is within
583 | -- the direction margin.
584 | %inline
669 | ||| Convert an `AffineTransformation` to a transformation to be
670 | ||| used in an SVG element.
671 | export
690 | -- Embeds a graph, in the MOL file format, in an SVG node `metadata`.
691 | -- Therefore, the SVG can be read in again later, and the graph can be
692 | -- parsed from the string of the MOL file inside the metadata tag.
705 | svg
710 | export
716 | --------------------------------------------------------------------------------
717 | -- Initialization
718 | --------------------------------------------------------------------------------
722 | ||| Initializes the drawing state for the given mol graph.
723 | |||
724 | ||| The `SceneDims` are used for centering the molecule, as well
725 | ||| as for scaling it to fill the scene. The `metadata` flag is
726 | ||| used to decide if the graph is atached to the SVG in form of
727 | ||| a MOL file string.
728 | export
730 | SceneDims
748 | ||| Generates a string holding the SVG-encoded molecular structur
749 | ||| together with the dimensions of the SVG-scnene.
750 | |||
751 | ||| The `metadata` flag indicates, whether a `<metadata>` tag
752 | ||| containing the molecular structure in `.mol` format should be
753 | ||| included in the SVG content.
754 | export
766 | ||| Generates an SVG string out of the current DrawState. The
767 | ||| graph is included as MOL file string inside the metadata tag.
768 | ||| The border margin depends on the `CoreDims`s `selectBufferSize`
769 | ||| field value.
770 | export