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]
116 | ||| Current SVG scene rendered to a string
117 | ||| We keep track of this and the previous one to easily
118 | ||| decide when to redraw the scene.
121 | ||| Previous SVG scene rendered to a string
140 | ||| True, if the current mol graph is the empty graph.
145 | --------------------------------------------------------------------------------
146 | -- State initialization
147 | --------------------------------------------------------------------------------
149 | ||| Mode used to scale a molecule.
150 | |||
151 | ||| This is used when centering a molecule, for instance, when we begin
152 | ||| drawing, or when we just display a molecule and want to zoom in for it
153 | ||| to fill the whole scene.
156 | ||| Scale mode used when initializing a scene for drawing
159 | ||| Scale mode used when centering the molecule (by pressing the "reset" button)
162 | ||| Scale mode used when displaying a molecule so that it fills the whole
163 | ||| scene
181 | export
185 | ||| Scales the molecule at the current mouse position.
186 | export
190 | ||| Scales the molecule at the center of the scene
191 | export
198 | where
207 | where
224 | export
228 | export
232 | --------------------------------------------------------------------------------
233 | -- Current Molecule
234 | --------------------------------------------------------------------------------
236 | -- Computes the molecule to be drawn based on the current
237 | -- state and mode. This is used both for displaying the current
238 | -- molecule in its editing state as well as for replacing the current
239 | -- molecule with its updated version when an editing step ends
240 | -- Using this for drawing allows us to not store additional information
241 | -- in the drawing mode.
266 | --------------------------------------------------------------------------------
267 | -- Editing Molecule
268 | --------------------------------------------------------------------------------
270 | -- overwrites the current molecule, adding it to the `undo` stack
280 | -- adjusts the atoms fulfilling the given predicate with the given function
281 | -- this will delete any abbreviation associated with these atoms.
291 | where
295 | -- adjusts the currently hovered atom with the given function
296 | -- this will delete any abbreviation associated with the hovered atom.
300 | %inline
304 | -- delete the currently selected atoms
305 | %inline
309 | --------------------------------------------------------------------------------
310 | -- Current Selection
311 | --------------------------------------------------------------------------------
313 | -- draws a rectangle around the currently selected atoms (if any),
314 | -- depending on whether the mouse is currently within the dragging zone
321 | -- tests if any atoms are selected and if that's the case, whether
322 | -- the mouse is currently in the dragging zone.
331 | -----------------------------------------------------------------------------
332 | -- Update State
333 | -----------------------------------------------------------------------------
347 | ST
362 | }
383 | -- Elaborates the current mode and elevates the fitting argument to a return
384 | -- value
385 | export
407 | -- When we move the mouse, we must adjust the current mouse position
408 | -- in the application state. If the middle mouse button is pressed,
409 | -- we also translate the drawing area, otherwise we adjust the hovering
410 | -- state of atoms.
424 | -- Pressing the left button typically begins an editing step
425 | -- If this step depends on the start and end position of the mouse,
426 | -- we enter a new mode and finish editing on the `leftUp` event.
427 | -- Otherwise (for instance, when setting the label of an atom at
428 | -- the mouse position),
429 | -- the modification happens immediately.
436 | applyWhenSel
437 | s
463 | -- adding template at hovered atom
468 | -- exactly one overlap -> rotating around it possible
480 | -- When the left mouse button is lifted, this ends an ongoing editing
481 | -- or selection process. We typically overwrite the current molecule with
482 | -- the freshly edited one, adjust the drawing roles of atoms and bonds, and
483 | -- determine the currently hovered atom anew.
499 | %inline
521 | -- Adds a bond to the molecule when hovering over a node
522 | -- (excluding nodes that are abbreviations),
523 | -- or changes the bond type (e.g., from Single to Triple) when
524 | -- hovering over an edge with NoBondStereo.
546 | -- Adds a group to the molecule if hovering over a valid atom or bond,
547 | -- ensuring it's not an abbreviation.
565 | -- Adds an abbreviation to the molecule if hovering over a valid atom,
566 | -- ensuring it's not an abbreviation.
579 | in
583 | -- Enables node-edge-node navigation by setting 'Hover' to the neighbor whose
584 | -- bond angle best matches the input angle, if the angle difference is within
585 | -- the direction margin.
586 | %inline
638 | -- prevent unwanted resizes from events that might slightly affect the
639 | -- canvas dims
682 | ||| Convert an `AffineTransformation` to a transformation to be
683 | ||| used in an SVG element.
684 | export
703 | -- Embeds a graph, in the MOL file format, in an SVG node `metadata`.
704 | -- Therefore, the SVG can be read in again later, and the graph can be
705 | -- parsed from the string of the MOL file inside the metadata tag.
718 | svg
725 | export
731 | --------------------------------------------------------------------------------
732 | -- Initialization
733 | --------------------------------------------------------------------------------
737 | ||| Initializes the drawing state for the given mol graph.
738 | |||
739 | ||| The `SceneDims` are used for centering the molecule, as well
740 | ||| as for scaling it to fill the scene. The `metadata` flag is
741 | ||| used to decide if the graph is atached to the SVG in form of
742 | ||| a MOL file string.
743 | export
745 | SceneDims
763 | ||| Generates a string holding the SVG-encoded molecular structur
764 | ||| together with the dimensions of the SVG-scnene.
765 | |||
766 | ||| The `metadata` flag indicates, whether a `<metadata>` tag
767 | ||| containing the molecular structure in `.mol` format should be
768 | ||| included in the SVG content.
769 | export
781 | ||| Generates an SVG string out of the current DrawState. The
782 | ||| graph is included as MOL file string inside the metadata tag.
783 | ||| The border margin depends on the `CoreDims`s `selectBufferSize`
784 | ||| field value.
785 | export