From 5eb60ceacca3888f448578f428981e40b1cdc8e3 Mon Sep 17 00:00:00 2001 From: even1024 Date: Mon, 12 Aug 2024 11:33:29 +0200 Subject: [PATCH] Backmerge: #2213 - Layout for 1-step reactions is broken (#2214) --- .../integration/ref/formats/cdx_to_ket.py.out | 110 +++---- .../ref/formats/rxn_no_layout.py.out | 6 +- .../integration/ref/layout/ket_layout.py.out | 2 + .../integration/tests/formats/ket_cdxml.py | 2 +- .../tests/formats/ref/961-text_size.ket | 2 +- .../integration/tests/formats/ref/agents.ket | 12 +- .../integration/tests/formats/ref/generic.ket | 2 +- .../integration/tests/formats/ref/multi.ket | 20 +- .../tests/formats/ref/multi_overlap.ket | 16 +- .../tests/layout/reactions/balance.ket | 294 +++++++++++++++++ .../tests/layout/ref/932-agents.ket | 298 +++++++++--------- .../integration/tests/layout/ref/balance.ket | 290 +++++++++++++++++ .../integration/tests/layout/smiles_layout.py | 6 +- .../tests/reaction/reactions/issue_1205.ket | 2 +- .../tests/reaction/save_ket_layout_1205.py | 6 +- core/indigo-core/layout/reaction_layout.h | 5 + .../layout/src/reaction_layout.cpp | 153 ++++++++- core/indigo-core/molecule/ket_commons.h | 27 ++ .../molecule/src/molecule_cdxml_saver.cpp | 6 +- .../molecule/src/molecule_json_saver.cpp | 14 +- .../reaction/reaction_json_saver.h | 3 - .../reaction/src/reaction_cdxml_saver.cpp | 4 +- .../reaction/src/reaction_json_loader.cpp | 28 +- .../reaction/src/reaction_json_saver.cpp | 217 ++----------- core/render2d/src/render_item_aux.cpp | 17 +- 25 files changed, 1067 insertions(+), 475 deletions(-) create mode 100644 api/tests/integration/ref/layout/ket_layout.py.out create mode 100644 api/tests/integration/tests/layout/reactions/balance.ket create mode 100644 api/tests/integration/tests/layout/ref/balance.ket diff --git a/api/tests/integration/ref/formats/cdx_to_ket.py.out b/api/tests/integration/ref/formats/cdx_to_ket.py.out index 491a8b896f..36f313395f 100644 --- a/api/tests/integration/ref/formats/cdx_to_ket.py.out +++ b/api/tests/integration/ref/formats/cdx_to_ket.py.out @@ -2893,7 +2893,7 @@ CDXML loader: Not a molecule. Found 1 arrows. "z": 0.0 }, { - "x": 12.442000389099121, + "x": 12.44200038909912, "y": -1.1613332033157349, "z": 0.0 } @@ -2915,7 +2915,7 @@ CDXML loader: Not a molecule. Found 1 arrows. "type": "plus", "location": [ 16.42766571044922, - -0.9143331050872803, + -0.9143331050872804, 0.0 ] }, @@ -3033,14 +3033,14 @@ CDXML loader: Not a molecule. Found 1 arrows. "label": "C", "location": [ 6.1419997215271, - -0.18999938666820527, + -0.1899993866682053, 0.0 ] }, { "label": "C", "location": [ - 5.3329997062683109, + 5.332999706268311, -0.7776662111282349, 0.0 ] @@ -3114,15 +3114,15 @@ CDXML loader: Not a molecule. Found 1 arrows. { "label": "C", "location": [ - 13.934000015258789, - -0.24399922788143159, + 13.934000015258788, + -0.2439992278814316, 0.0 ] }, { "label": "C", "location": [ - 13.125333786010743, + 13.125333786010744, -0.8319997191429138, 0.0 ] @@ -3130,7 +3130,7 @@ CDXML loader: Not a molecule. Found 1 arrows. { "label": "C", "location": [ - 13.434000015258789, + 13.434000015258788, -1.7829996347427369, 0.0 ] @@ -3138,7 +3138,7 @@ CDXML loader: Not a molecule. Found 1 arrows. { "label": "C", "location": [ - 14.434000015258789, + 14.434000015258788, -1.7829996347427369, 0.0 ] @@ -3146,7 +3146,7 @@ CDXML loader: Not a molecule. Found 1 arrows. { "label": "C", "location": [ - 14.743000030517579, + 14.74300003051758, -0.8319997191429138, 0.0 ] @@ -3204,7 +3204,7 @@ CDXML loader: Not a molecule. Found 1 arrows. { "label": "C", "location": [ - 17.968332290649415, + 17.968332290649419, -0.7373331785202026, 0.0 ] @@ -3509,7 +3509,7 @@ CDXML loader: Not a molecule. Found 14 arrows. "content": "{\"blocks\":[{\"text\":\"test\",\"inlineStyleRanges\":[{\"offset\":0,\"length\":4,\"style\":\"CUSTOM_FONT_SIZE_15px\"}],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}}", "position": { "x": 17.70600128173828, - "y": -1.8826665878295899, + "y": -1.88266658782959, "z": 0.0 } } @@ -3519,7 +3519,7 @@ CDXML loader: Not a molecule. Found 14 arrows. "data": { "content": "{\"blocks\":[{\"text\":\"6\",\"inlineStyleRanges\":[{\"offset\":0,\"length\":1,\"style\":\"BOLD\"},{\"offset\":0,\"length\":1,\"style\":\"CUSTOM_FONT_SIZE_15px\"}],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}}", "position": { - "x": 20.129331588745118, + "x": 20.12933158874512, "y": -1.3268331289291382, "z": 0.0 } @@ -3585,8 +3585,8 @@ CDXML loader: Not a molecule. Found 14 arrows. "data": { "content": "{\"blocks\":[{\"text\":\"test2\",\"inlineStyleRanges\":[{\"offset\":0,\"length\":5,\"style\":\"CUSTOM_FONT_SIZE_15px\"}],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}}", "position": { - "x": 3.1116669178009035, - "y": -1.8923335075378419, + "x": 3.1116669178009039, + "y": -1.892333507537842, "z": 0.0 } } @@ -3640,7 +3640,7 @@ CDXML loader: Not a molecule. Found 14 arrows. "data": { "content": "{\"blocks\":[{\"text\":\"test3\",\"inlineStyleRanges\":[{\"offset\":0,\"length\":5,\"style\":\"CUSTOM_FONT_SIZE_15px\"}],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}}", "position": { - "x": 10.712333679199219, + "x": 10.71233367919922, "y": -1.4706664085388184, "z": 0.0 } @@ -3652,7 +3652,7 @@ CDXML loader: Not a molecule. Found 14 arrows. "content": "{\"blocks\":[{\"text\":\"test20\",\"inlineStyleRanges\":[{\"offset\":0,\"length\":6,\"style\":\"BOLD\"},{\"offset\":0,\"length\":6,\"style\":\"CUSTOM_FONT_SIZE_15px\"}],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}}", "position": { "x": 27.751501083374025, - "y": -3.7408337593078615, + "y": -3.7408337593078619, "z": 0.0 } } @@ -3707,7 +3707,7 @@ CDXML loader: Not a molecule. Found 14 arrows. "content": "{\"blocks\":[{\"text\":\"500 mg (int-2)\",\"inlineStyleRanges\":[{\"offset\":0,\"length\":14,\"style\":\"CUSTOM_FONT_SIZE_15px\"}],\"entityRanges\":[],\"data\":{}},{\"text\":\"\",\"inlineStyleRanges\":[],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}}", "position": { "x": 1.4541666507720948, - "y": -5.9666666984558109, + "y": -5.966666698455811, "z": 0.0 } } @@ -3718,7 +3718,7 @@ CDXML loader: Not a molecule. Found 14 arrows. "content": "{\"blocks\":[{\"text\":\"test7\",\"inlineStyleRanges\":[{\"offset\":0,\"length\":5,\"style\":\"CUSTOM_FONT_SIZE_15px\"}],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}}", "position": { "x": 7.121333122253418, - "y": -5.9666666984558109, + "y": -5.966666698455811, "z": 0.0 } } @@ -3740,7 +3740,7 @@ CDXML loader: Not a molecule. Found 14 arrows. "content": "{\"blocks\":[{\"text\":\"TEST, iTest, 80 oC, 12 h\",\"inlineStyleRanges\":[{\"offset\":0,\"length\":6,\"style\":\"CUSTOM_FONT_SIZE_15px\"},{\"offset\":6,\"length\":1,\"style\":\"ITALIC\"},{\"offset\":6,\"length\":1,\"style\":\"SUPERSCRIPT\"},{\"offset\":6,\"length\":1,\"style\":\"CUSTOM_FONT_SIZE_15px\"},{\"offset\":7,\"length\":9,\"style\":\"CUSTOM_FONT_SIZE_15px\"},{\"offset\":16,\"length\":1,\"style\":\"SUPERSCRIPT\"},{\"offset\":16,\"length\":1,\"style\":\"CUSTOM_FONT_SIZE_15px\"},{\"offset\":17,\"length\":7,\"style\":\"CUSTOM_FONT_SIZE_15px\"}],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}}", "position": { "x": 4.072500228881836, - "y": -5.5998334884643559, + "y": -5.599833488464356, "z": 0.0 } } @@ -3783,7 +3783,7 @@ CDXML loader: Not a molecule. Found 14 arrows. "data": { "content": "{\"blocks\":[{\"text\":\"200 mg\",\"inlineStyleRanges\":[{\"offset\":0,\"length\":6,\"style\":\"CUSTOM_FONT_SIZE_15px\"}],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}}", "position": { - "x": 15.214333534240723, + "x": 15.214333534240725, "y": -8.036666870117188, "z": 0.0 } @@ -3883,7 +3883,7 @@ CDXML loader: Not a molecule. Found 14 arrows. "content": "{\"blocks\":[{\"text\":\"test15\",\"inlineStyleRanges\":[{\"offset\":0,\"length\":6,\"style\":\"CUSTOM_FONT_SIZE_15px\"}],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}}", "position": { "x": 25.946334838867189, - "y": -9.451665878295899, + "y": -9.4516658782959, "z": 0.0 } } @@ -3941,7 +3941,7 @@ CDXML loader: Not a molecule. Found 14 arrows. "mode": "open-angle", "pos": [ { - "x": 24.649999618530275, + "x": 24.649999618530278, "y": -2.245000123977661, "z": 0.0 }, @@ -3977,7 +3977,7 @@ CDXML loader: Not a molecule. Found 14 arrows. "mode": "open-angle", "pos": [ { - "x": 10.425999641418457, + "x": 10.425999641418456, "y": -4.869000434875488, "z": 0.0 }, @@ -3995,7 +3995,7 @@ CDXML loader: Not a molecule. Found 14 arrows. "mode": "open-angle", "pos": [ { - "x": 10.425999641418457, + "x": 10.425999641418456, "y": -5.949333667755127, "z": 0.0 }, @@ -4144,7 +4144,7 @@ CDXML loader: Not a molecule. Found 14 arrows. "z": 0.0 }, { - "x": 28.051000595092775, + "x": 28.051000595092778, "y": -9.73566722869873, "z": 0.0 } @@ -4159,7 +4159,7 @@ CDXML loader: Not a molecule. Found 14 arrows. { "label": "Si", "location": [ - 2.3273332118988039, + 2.327333211898804, 0.3419998288154602, 0.0 ] @@ -4168,7 +4168,7 @@ CDXML loader: Not a molecule. Found 14 arrows. "label": "C", "location": [ 2.4753334522247316, - -0.11299998313188553, + -0.11299998313188552, 0.0 ] }, @@ -4176,7 +4176,7 @@ CDXML loader: Not a molecule. Found 14 arrows. "label": "C", "location": [ 2.1553335189819338, - -0.46866658329963686, + -0.4686665832996369, 0.0 ] }, @@ -4184,7 +4184,7 @@ CDXML loader: Not a molecule. Found 14 arrows. "label": "O", "location": [ 2.303333282470703, - -0.9233332276344299, + -0.92333322763443, 0.0 ] }, @@ -4216,14 +4216,14 @@ CDXML loader: Not a molecule. Found 14 arrows. "label": "C", "location": [ 1.9833333492279053, - -1.2789998054504395, + -1.2789998054504397, 0.0 ] }, { "label": "C", "location": [ - 1.8350001573562623, + 1.8350001573562625, -2.50433349609375, 0.0 ] @@ -4239,8 +4239,8 @@ CDXML loader: Not a molecule. Found 14 arrows. { "label": "N", "location": [ - 1.8350001573562623, - -1.7356668710708619, + 1.8350001573562625, + -1.735666871070862, 0.0 ] } @@ -4345,7 +4345,7 @@ CDXML loader: Not a molecule. Found 14 arrows. { "label": "C", "location": [ - 28.618000030517579, + 28.61800003051758, -2.4803335666656496, 0.0 ] @@ -4353,7 +4353,7 @@ CDXML loader: Not a molecule. Found 14 arrows. { "label": "C", "location": [ - 28.618000030517579, + 28.61800003051758, -2.9603333473205568, 0.0 ] @@ -4437,7 +4437,7 @@ CDXML loader: Not a molecule. Found 14 arrows. "label": "C", "location": [ 24.004667282104493, - -1.2470000982284547, + -1.2470000982284549, 0.0 ] }, @@ -4469,14 +4469,14 @@ CDXML loader: Not a molecule. Found 14 arrows. "label": "O", "location": [ 24.338998794555665, - -0.30266672372817995, + -0.30266672372818, 0.0 ] }, { "label": "C", "location": [ - 25.250667572021486, + 25.250667572021489, 1.1613332033157349, 0.0 ] @@ -4501,7 +4501,7 @@ CDXML loader: Not a molecule. Found 14 arrows. "label": "C", "location": [ 23.871334075927736, - -0.40199992060661318, + -0.4019999206066132, 0.0 ] } @@ -4614,7 +4614,7 @@ CDXML loader: Not a molecule. Found 14 arrows. { "label": "N", "location": [ - 9.334667205810547, + 9.334667205810549, -0.6086664795875549, 0.0 ] @@ -4622,7 +4622,7 @@ CDXML loader: Not a molecule. Found 14 arrows. { "label": "C", "location": [ - 9.616666793823243, + 9.616666793823244, -0.9970000982284546, 0.0 ] @@ -4630,7 +4630,7 @@ CDXML loader: Not a molecule. Found 14 arrows. { "label": "C", "location": [ - 9.334667205810547, + 9.334667205810549, -1.3853332996368409, 0.0 ] @@ -4639,7 +4639,7 @@ CDXML loader: Not a molecule. Found 14 arrows. "label": "C", "location": [ 8.878000259399414, - -1.2369999885559083, + -1.2369999885559085, 0.0 ] }, @@ -4647,14 +4647,14 @@ CDXML loader: Not a molecule. Found 14 arrows. "label": "Si", "location": [ 10.714666366577149, - 0.9563333988189697, + 0.9563333988189696, 0.0 ] }, { "label": "C", "location": [ - 10.567000389099121, + 10.56700038909912, 0.501666784286499, 0.0 ] @@ -4670,7 +4670,7 @@ CDXML loader: Not a molecule. Found 14 arrows. { "label": "O", "location": [ - 9.951000213623047, + 9.951000213623049, -0.05266672745347023, 0.0 ] @@ -4678,7 +4678,7 @@ CDXML loader: Not a molecule. Found 14 arrows. { "label": "C", "location": [ - 10.862667083740235, + 10.862667083740237, 1.4113332033157349, 0.0 ] @@ -4702,7 +4702,7 @@ CDXML loader: Not a molecule. Found 14 arrows. { "label": "C", "location": [ - 9.482999801635743, + 9.482999801635744, -0.15199992060661317, 0.0 ] @@ -4853,7 +4853,7 @@ CDXML loader: Not a molecule. Found 14 arrows. { "label": "Si", "location": [ - 17.893333435058595, + 17.893333435058599, 0.6843332648277283, 0.0 ] @@ -4869,7 +4869,7 @@ CDXML loader: Not a molecule. Found 14 arrows. { "label": "C", "location": [ - 17.277667999267579, + 17.27766799926758, 0.1299998015165329, 0.0 ] @@ -4878,7 +4878,7 @@ CDXML loader: Not a molecule. Found 14 arrows. "label": "O", "location": [ 17.129667282104493, - -0.32499998807907107, + -0.3249999880790711, 0.0 ] }, @@ -5046,8 +5046,8 @@ CDXML loader: Not a molecule. Found 14 arrows. { "label": "Cl", "location": [ - 19.573667526245118, - -1.1426665782928467, + 19.57366752624512, + -1.142666578292847, 0.0 ], "charge": -1 @@ -5158,7 +5158,7 @@ CDXML loader: Not a molecule. Found 14 arrows. { "label": "C", "location": [ - 11.731667518615723, + 11.731667518615725, -0.02666676789522171, 0.0 ] diff --git a/api/tests/integration/ref/formats/rxn_no_layout.py.out b/api/tests/integration/ref/formats/rxn_no_layout.py.out index 17697cf853..cd598ab3ad 100644 --- a/api/tests/integration/ref/formats/rxn_no_layout.py.out +++ b/api/tests/integration/ref/formats/rxn_no_layout.py.out @@ -29,7 +29,7 @@ { "type": "plus", "location": [ - 9.501733779907227, + 9.501733779907229, 0.0, 0.0 ] @@ -37,7 +37,7 @@ { "type": "plus", "location": [ - 19.503467559814454, + 19.503467559814458, 0.0, 0.0 ] @@ -69,7 +69,7 @@ { "type": "plus", "location": [ - 48.909507751464847, + 48.90950775146485, 0.0, 0.0 ] diff --git a/api/tests/integration/ref/layout/ket_layout.py.out b/api/tests/integration/ref/layout/ket_layout.py.out new file mode 100644 index 0000000000..2eece71f6a --- /dev/null +++ b/api/tests/integration/ref/layout/ket_layout.py.out @@ -0,0 +1,2 @@ +*** KET LAYOUT *** +balance.ket:SUCCEED diff --git a/api/tests/integration/tests/formats/ket_cdxml.py b/api/tests/integration/tests/formats/ket_cdxml.py index 8a504cdd09..aae62f6081 100644 --- a/api/tests/integration/tests/formats/ket_cdxml.py +++ b/api/tests/integration/tests/formats/ket_cdxml.py @@ -59,7 +59,7 @@ def find_diff(a, b): ket_result = ket.json() - # with open(os.path.join(ref_path, filename), "w") as file: + # with open(os.path.join(ref_path, filename + ".ket"), "w") as file: # file.write(ket_result) with open(os.path.join(ref_path, filename) + ".ket", "r") as file: diff --git a/api/tests/integration/tests/formats/ref/961-text_size.ket b/api/tests/integration/tests/formats/ref/961-text_size.ket index 5485ddce68..d098373bf4 100644 --- a/api/tests/integration/tests/formats/ref/961-text_size.ket +++ b/api/tests/integration/tests/formats/ref/961-text_size.ket @@ -135,7 +135,7 @@ { "label": "C", "location": [ - 12.442792892456055, + 12.442792892456057, -5.227451801300049, 0.0 ] diff --git a/api/tests/integration/tests/formats/ref/agents.ket b/api/tests/integration/tests/formats/ref/agents.ket index fbcc7fbd84..d401ef5687 100644 --- a/api/tests/integration/tests/formats/ref/agents.ket +++ b/api/tests/integration/tests/formats/ref/agents.ket @@ -205,7 +205,7 @@ { "label": "C", "location": [ - 16.395389556884767, + 16.39538955688477, -7.258016109466553, 0.0 ] @@ -229,7 +229,7 @@ { "label": "C", "location": [ - 16.395389556884767, + 16.39538955688477, -5.258028984069824, 0.0 ] @@ -237,7 +237,7 @@ { "label": "C", "location": [ - 16.395389556884767, + 16.39538955688477, -4.258035659790039, 0.0 ] @@ -246,7 +246,7 @@ "label": "C", "location": [ 15.529335975646973, - -3.7580387592315676, + -3.758038759231568, 0.0 ] }, @@ -254,7 +254,7 @@ "label": "C", "location": [ 14.663400650024414, - -3.2580418586730959, + -3.258041858673096, 0.0 ] }, @@ -361,7 +361,7 @@ { "label": "Cl", "location": [ - 10.475000381469727, + 10.475000381469729, -4.5, 0.0 ] diff --git a/api/tests/integration/tests/formats/ref/generic.ket b/api/tests/integration/tests/formats/ref/generic.ket index 1de13ad650..f463328faf 100644 --- a/api/tests/integration/tests/formats/ref/generic.ket +++ b/api/tests/integration/tests/formats/ref/generic.ket @@ -57,7 +57,7 @@ { "label": "C", "location": [ - 3.3677926063537599, + 3.36779260635376, -4.227451324462891, 0.0 ] diff --git a/api/tests/integration/tests/formats/ref/multi.ket b/api/tests/integration/tests/formats/ref/multi.ket index 5447b919f2..158a74c7c2 100644 --- a/api/tests/integration/tests/formats/ref/multi.ket +++ b/api/tests/integration/tests/formats/ref/multi.ket @@ -31,7 +31,7 @@ }, { "x": 10.425000190734864, - "y": -3.7249999046325685, + "y": -3.724999904632569, "z": 0.0 } ] @@ -59,7 +59,7 @@ "type": "plus", "location": [ 4.400000095367432, - -3.6500000953674318, + -3.650000095367432, 0.0 ] }, @@ -95,7 +95,7 @@ { "label": "C", "location": [ - 3.5285041332244875, + 3.5285041332244879, -3.127451181411743, 0.0 ] @@ -267,7 +267,7 @@ { "label": "C", "location": [ - 23.426637649536134, + 23.426637649536138, -2.549967050552368, 0.0 ] @@ -348,7 +348,7 @@ { "label": "C", "location": [ - 10.854475975036621, + 10.85447597503662, -3.118603229522705, 0.0 ] @@ -357,7 +357,7 @@ "label": "C", "location": [ 11.638409614562989, - -2.5010316371917726, + -2.501031637191773, 0.0 ] }, @@ -373,7 +373,7 @@ "label": "C", "location": [ 13.045523643493653, - -3.6193912029266359, + -3.619391202926636, 0.0 ] }, @@ -388,7 +388,7 @@ { "label": "C", "location": [ - 12.612141609191895, + 12.612141609191897, -4.526418209075928, 0.0 ] @@ -461,7 +461,7 @@ "label": "C", "location": [ 15.508987426757813, - -2.8249926567077638, + -2.824992656707764, 0.0 ] }, @@ -493,7 +493,7 @@ "label": "C", "location": [ 17.241010665893556, - -2.8249926567077638, + -2.824992656707764, 0.0 ] }, diff --git a/api/tests/integration/tests/formats/ref/multi_overlap.ket b/api/tests/integration/tests/formats/ref/multi_overlap.ket index f997f23dc0..6f08ebda63 100644 --- a/api/tests/integration/tests/formats/ref/multi_overlap.ket +++ b/api/tests/integration/tests/formats/ref/multi_overlap.ket @@ -103,7 +103,7 @@ { "label": "C", "location": [ - 11.369860649108887, + 11.369860649108889, -9.212441444396973, 0.0 ] @@ -111,7 +111,7 @@ { "label": "C", "location": [ - 11.369860649108887, + 11.369860649108889, -8.212483406066895, 0.0 ] @@ -120,7 +120,7 @@ "label": "C", "location": [ 10.503897666931153, - -7.7125043869018559, + -7.712504386901856, 0.0 ] }, @@ -191,7 +191,7 @@ { "label": "C", "location": [ - 26.057207107543947, + 26.05720710754395, -8.89754867553711, 0.0 ] @@ -274,7 +274,7 @@ { "label": "C", "location": [ - 17.044635772705079, + 17.04463577270508, -9.00248908996582, 0.0 ] @@ -325,7 +325,7 @@ { "label": "C", "location": [ - 19.534748077392579, + 19.53474807739258, -8.932470321655274, 0.0 ] @@ -341,7 +341,7 @@ { "label": "C", "location": [ - 20.035423278808595, + 20.035423278808599, -8.067529678344727, 0.0 ] @@ -410,7 +410,7 @@ "label": "C", "location": [ 6.014000415802002, - -9.242452621459961, + -9.24245262145996, 0.0 ] }, diff --git a/api/tests/integration/tests/layout/reactions/balance.ket b/api/tests/integration/tests/layout/reactions/balance.ket new file mode 100644 index 0000000000..f4c4c1e1f0 --- /dev/null +++ b/api/tests/integration/tests/layout/reactions/balance.ket @@ -0,0 +1,294 @@ +{ + "root": { + "nodes": [ + { + "$ref": "mol0" + }, + { + "$ref": "mol1" + }, + { + "$ref": "mol2" + }, + { + "$ref": "mol3" + }, + { + "type": "arrow", + "data": { + "mode": "equilibrium-filled-half-bow", + "pos": [ + { + "x": 8.425, + "y": -5.625, + "z": 0 + }, + { + "x": 10.651263686089319, + "y": -5.625, + "z": 0 + } + ] + } + }, + { + "type": "plus", + "location": [ + 5.375, + -5.65, + 0 + ], + "prop": {} + }, + { + "type": "plus", + "location": [ + 13.675, + -5.575, + 0 + ], + "prop": {} + } + ], + "connections": [], + "templates": [] + }, + "mol0": { + "type": "molecule", + "atoms": [ + { + "label": "C", + "location": [ + 3.52437421436393, + -6.057470415521405, + 0 + ] + }, + { + "label": "C", + "location": [ + 4.525625785636071, + -6.057470415521405, + 0 + ] + }, + { + "label": "C", + "location": [ + 4.025050188048686, + -5.192529584478595, + 0 + ] + } + ], + "bonds": [ + { + "type": 1, + "atoms": [ + 0, + 1 + ] + }, + { + "type": 1, + "atoms": [ + 1, + 2 + ] + }, + { + "type": 1, + "atoms": [ + 2, + 0 + ] + } + ] + }, + "mol1": { + "type": "molecule", + "atoms": [ + { + "label": "C", + "location": [ + 7.407207454738979, + -6.147548743464719, + 0 + ] + }, + { + "label": "C", + "location": [ + 7.40350411466491, + -5.152451256535281, + 0 + ] + }, + { + "label": "C", + "location": [ + 6.395294802067824, + -6.134637098341615, + 0 + ] + }, + { + "label": "C", + "location": [ + 6.392792545261022, + -5.152451256535281, + 0 + ] + } + ], + "bonds": [ + { + "type": 1, + "atoms": [ + 0, + 1 + ] + }, + { + "type": 1, + "atoms": [ + 1, + 3 + ] + }, + { + "type": 1, + "atoms": [ + 3, + 2 + ] + }, + { + "type": 1, + "atoms": [ + 2, + 0 + ] + } + ] + }, + "mol2": { + "type": "molecule", + "atoms": [ + { + "label": "C", + "location": [ + 12.507207454738978, + -6.122548743464718, + 0 + ] + }, + { + "label": "C", + "location": [ + 12.50350411466491, + -5.127451256535281, + 0 + ] + }, + { + "label": "C", + "location": [ + 11.495294802067825, + -6.109637098341615, + 0 + ] + }, + { + "label": "C", + "location": [ + 11.492792545261022, + -5.127451256535281, + 0 + ] + } + ], + "bonds": [ + { + "type": 1, + "atoms": [ + 0, + 1 + ] + }, + { + "type": 1, + "atoms": [ + 1, + 3 + ] + }, + { + "type": 1, + "atoms": [ + 3, + 2 + ] + }, + { + "type": 1, + "atoms": [ + 2, + 0 + ] + } + ] + }, + "mol3": { + "type": "molecule", + "atoms": [ + { + "label": "C", + "location": [ + 14.67437421436393, + -6.007470415521405, + 0 + ] + }, + { + "label": "C", + "location": [ + 15.67562578563607, + -6.007470415521405, + 0 + ] + }, + { + "label": "C", + "location": [ + 15.175050188048687, + -5.142529584478595, + 0 + ] + } + ], + "bonds": [ + { + "type": 1, + "atoms": [ + 0, + 1 + ] + }, + { + "type": 1, + "atoms": [ + 1, + 2 + ] + }, + { + "type": 1, + "atoms": [ + 2, + 0 + ] + } + ] + } +} \ No newline at end of file diff --git a/api/tests/integration/tests/layout/ref/932-agents.ket b/api/tests/integration/tests/layout/ref/932-agents.ket index a579fbfeb9..48ddc90a81 100644 --- a/api/tests/integration/tests/layout/ref/932-agents.ket +++ b/api/tests/integration/tests/layout/ref/932-agents.ket @@ -83,7 +83,7 @@ "z": 0.0 }, { - "x": 52.042545318603519, + "x": 52.04254531860352, "y": 0.0, "z": 0.0 } @@ -226,83 +226,102 @@ ] }, "mol3": { - "type": "molecule", - "atoms": [ - { - "label": "S", - "location": [ - 54.04254531860352, - 0.0, - 0.0 - ] - } - ], - "bonds": [] - }, - "mol4": { "type": "molecule", "atoms": [ { "label": "C", "location": [ - 60.3739128112793, - 1.931370735168457, + 15.90000057220459, + 1.892820119857788, 0.0 ] }, { "label": "C", "location": [ - 58.7739143371582, - 1.931370735168457, + 17.285640716552736, + 1.0928202867507937, 0.0 ] }, { "label": "C", "location": [ - 57.64254379272461, - 0.7999999523162842, + 18.671281814575197, + 1.892820119857788, 0.0 ] + } + ], + "bonds": [ + { + "type": 1, + "atoms": [ + 0, + 1 + ] }, + { + "type": 1, + "atoms": [ + 1, + 2 + ] + } + ] + }, + "mol4": { + "type": "molecule", + "atoms": [ { "label": "C", "location": [ - 57.64254379272461, - -0.7999998331069946, + 22.871280670166017, + 1.4928202629089356, 0.0 ] - }, + } + ], + "bonds": [] + }, + "mol5": { + "type": "molecule", + "atoms": [ { - "label": "C", + "label": "P", "location": [ - 58.7739143371582, - -1.931370735168457, + 27.071279525756837, + 1.4928202629089356, 0.0 ] - }, + } + ], + "bonds": [] + }, + "mol6": { + "type": "molecule", + "atoms": [ { "label": "C", "location": [ - 60.3739128112793, - -1.931370735168457, + 31.271278381347658, + 1.892820119857788, 0.0 ] }, { "label": "C", "location": [ - 61.50528717041016, - -0.7999998331069946, + 32.65691757202149, + 1.0928202867507937, 0.0 ] }, { "label": "C", "location": [ - 61.50528335571289, - 0.7999999523162842, + 34.04256057739258, + 1.892820119857788, 0.0 ] } @@ -321,89 +340,33 @@ 1, 2 ] - }, - { - "type": 1, - "atoms": [ - 2, - 3 - ] - }, - { - "type": 1, - "atoms": [ - 3, - 4 - ] - }, - { - "type": 1, - "atoms": [ - 4, - 5 - ] - }, - { - "type": 1, - "atoms": [ - 5, - 6 - ] - }, - { - "type": 1, - "atoms": [ - 6, - 7 - ] - }, - { - "type": 1, - "atoms": [ - 7, - 0 - ] } ] }, - "mol5": { - "type": "molecule", - "atoms": [ - { - "label": "O", - "location": [ - 65.10528564453125, - 0.0, - 0.0 - ] - } - ], - "bonds": [] - }, - "mol6": { + "mol7": { "type": "molecule", "atoms": [ { "label": "C", "location": [ - 15.90000057220459, - 1.892820119857788, + 38.242557525634769, + 2.185640573501587, 0.0 ] }, { "label": "C", "location": [ - 17.285640716552736, - 1.0928202867507937, + 39.84255599975586, + 2.185640573501587, 0.0 ] }, { "label": "C", "location": [ - 18.671281814575197, - 1.892820119857788, + 39.04255676269531, + 0.7999999523162842, 0.0 ] } @@ -422,16 +385,23 @@ 1, 2 ] + }, + { + "type": 1, + "atoms": [ + 2, + 0 + ] } ] }, - "mol7": { + "mol8": { "type": "molecule", "atoms": [ { - "label": "C", + "label": "F", "location": [ - 22.871280670166017, + 44.04255294799805, 1.4928202629089356, 0.0 ] @@ -439,13 +409,13 @@ ], "bonds": [] }, - "mol8": { + "mol9": { "type": "molecule", "atoms": [ { - "label": "P", + "label": "I", "location": [ - 27.071279525756837, + 48.24254989624024, 1.4928202629089356, 0.0 ] @@ -453,74 +423,83 @@ ], "bonds": [] }, - "mol9": { + "mol10": { + "type": "molecule", + "atoms": [ + { + "label": "S", + "location": [ + 54.04254531860352, + 0.0, + 0.0 + ] + } + ], + "bonds": [] + }, + "mol11": { "type": "molecule", "atoms": [ { "label": "C", "location": [ - 31.271278381347658, - 1.892820119857788, + 60.3739128112793, + 1.931370735168457, 0.0 ] }, { "label": "C", "location": [ - 32.65691757202149, - 1.0928202867507937, + 58.7739143371582, + 1.931370735168457, 0.0 ] }, { "label": "C", "location": [ - 34.04256057739258, - 1.892820119857788, + 57.64254379272461, + 0.7999999523162842, 0.0 ] - } - ], - "bonds": [ + }, { - "type": 1, - "atoms": [ - 0, - 1 + "label": "C", + "location": [ + 57.64254379272461, + -0.7999998331069946, + 0.0 ] }, { - "type": 1, - "atoms": [ - 1, - 2 + "label": "C", + "location": [ + 58.7739143371582, + -1.931370735168457, + 0.0 ] - } - ] - }, - "mol10": { - "type": "molecule", - "atoms": [ + }, { "label": "C", "location": [ - 38.242557525634769, - 2.185640573501587, + 60.3739128112793, + -1.931370735168457, 0.0 ] }, { "label": "C", "location": [ - 39.84255599975586, - 2.185640573501587, + 61.50528717041016, + -0.7999998331069946, 0.0 ] }, { "label": "C", "location": [ - 39.04255676269531, + 61.50528335571289, 0.7999999523162842, 0.0 ] @@ -545,33 +524,54 @@ "type": 1, "atoms": [ 2, - 0 + 3 ] - } - ] - }, - "mol11": { - "type": "molecule", - "atoms": [ + }, { - "label": "F", - "location": [ - 44.04255294799805, - 1.4928202629089356, - 0.0 + "type": 1, + "atoms": [ + 3, + 4 + ] + }, + { + "type": 1, + "atoms": [ + 4, + 5 + ] + }, + { + "type": 1, + "atoms": [ + 5, + 6 + ] + }, + { + "type": 1, + "atoms": [ + 6, + 7 + ] + }, + { + "type": 1, + "atoms": [ + 7, + 0 ] } - ], - "bonds": [] + ] }, "mol12": { "type": "molecule", "atoms": [ { - "label": "I", + "label": "O", "location": [ - 48.24254989624024, - 1.4928202629089356, + 65.10528564453125, + 0.0, 0.0 ] } diff --git a/api/tests/integration/tests/layout/ref/balance.ket b/api/tests/integration/tests/layout/ref/balance.ket new file mode 100644 index 0000000000..5e8dbe1d8a --- /dev/null +++ b/api/tests/integration/tests/layout/ref/balance.ket @@ -0,0 +1,290 @@ +{ + "root": { + "nodes": [ + { + "$ref": "mol0" + }, + { + "$ref": "mol1" + }, + { + "$ref": "mol2" + }, + { + "$ref": "mol3" + }, + { + "type": "plus", + "location": [ + 4.699999809265137, + 0.0, + 0.0 + ] + }, + { + "type": "plus", + "location": [ + 17.700000762939454, + 0.0, + 0.0 + ] + }, + { + "type": "arrow", + "data": { + "mode": "equilibrium-filled-half-bow", + "pos": [ + { + "x": 9.100000381469729, + "y": 0.0, + "z": 0.0 + }, + { + "x": 13.30000114440918, + "y": 0.0, + "z": 0.0 + } + ] + } + } + ] + }, + "mol0": { + "type": "molecule", + "atoms": [ + { + "label": "C", + "location": [ + 1.2999999523162842, + 0.6928203105926514, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 2.899999856948853, + 0.6928203105926514, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 2.0999999046325685, + -0.6928203105926514, + 0.0 + ] + } + ], + "bonds": [ + { + "type": 1, + "atoms": [ + 0, + 1 + ] + }, + { + "type": 1, + "atoms": [ + 1, + 2 + ] + }, + { + "type": 1, + "atoms": [ + 2, + 0 + ] + } + ] + }, + "mol1": { + "type": "molecule", + "atoms": [ + { + "label": "C", + "location": [ + 6.5, + 0.7999999523162842, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 8.100000381469727, + 0.7999999523162842, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 6.5, + -0.7999999523162842, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 8.100000381469727, + -0.7999999523162842, + 0.0 + ] + } + ], + "bonds": [ + { + "type": 1, + "atoms": [ + 0, + 1 + ] + }, + { + "type": 1, + "atoms": [ + 1, + 3 + ] + }, + { + "type": 1, + "atoms": [ + 3, + 2 + ] + }, + { + "type": 1, + "atoms": [ + 2, + 0 + ] + } + ] + }, + "mol2": { + "type": "molecule", + "atoms": [ + { + "label": "C", + "location": [ + 14.30000114440918, + 0.7999999523162842, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 15.900001525878908, + 0.7999999523162842, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 14.30000114440918, + -0.7999999523162842, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 15.900001525878908, + -0.7999999523162842, + 0.0 + ] + } + ], + "bonds": [ + { + "type": 1, + "atoms": [ + 0, + 1 + ] + }, + { + "type": 1, + "atoms": [ + 1, + 3 + ] + }, + { + "type": 1, + "atoms": [ + 3, + 2 + ] + }, + { + "type": 1, + "atoms": [ + 2, + 0 + ] + } + ] + }, + "mol3": { + "type": "molecule", + "atoms": [ + { + "label": "C", + "location": [ + 19.5, + 0.6928203105926514, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 21.100000381469728, + 0.6928203105926514, + 0.0 + ] + }, + { + "label": "C", + "location": [ + 20.299999237060548, + -0.6928203105926514, + 0.0 + ] + } + ], + "bonds": [ + { + "type": 1, + "atoms": [ + 0, + 1 + ] + }, + { + "type": 1, + "atoms": [ + 1, + 2 + ] + }, + { + "type": 1, + "atoms": [ + 2, + 0 + ] + } + ] + } +} \ No newline at end of file diff --git a/api/tests/integration/tests/layout/smiles_layout.py b/api/tests/integration/tests/layout/smiles_layout.py index da24a83b57..8473a0348d 100644 --- a/api/tests/integration/tests/layout/smiles_layout.py +++ b/api/tests/integration/tests/layout/smiles_layout.py @@ -28,9 +28,13 @@ def find_diff(a, b): for filename in files: rea = indigo.loadReactionFromFile(os.path.join(root, filename + ".smi")) rea.layout() + ket = rea.json() + + # with open(os.path.join(ref_path, filename) + ".ket", "w") as file: + # file.write(ket) + with open(os.path.join(ref_path, filename) + ".ket", "r") as file: ket_ref = file.read() - ket = rea.json() diff = find_diff(ket_ref, ket) if not diff: print(filename + ".ket:SUCCEED") diff --git a/api/tests/integration/tests/reaction/reactions/issue_1205.ket b/api/tests/integration/tests/reaction/reactions/issue_1205.ket index ad99a57f5e..d5d8a1777c 100644 --- a/api/tests/integration/tests/reaction/reactions/issue_1205.ket +++ b/api/tests/integration/tests/reaction/reactions/issue_1205.ket @@ -1 +1 @@ -{"root":{"nodes":[{"$ref":"mol0"},{"$ref":"mol1"},{"$ref":"mol2"},{"$ref":"mol3"},{"type":"arrow","data":{"mode":"open-angle","pos":[{"x":10.515000343322754,"y":-8.324899673461914,"z":0.0},{"x":15.034599304199219,"y":-8.274900436401368,"z":0.0}]}}]},"mol0":{"type":"molecule","atoms":[{"label":"C","location":[7.7846999168396,-7.824999809265137,0.0]},{"label":"C","location":[9.515000343322754,-7.82450008392334,0.0]},{"label":"C","location":[8.65149974822998,-7.324900150299072,0.0]},{"label":"C","location":[9.515000343322754,-8.825400352478028,0.0]},{"label":"C","location":[7.7846999168396,-8.829899787902832,0.0]},{"label":"C","location":[8.65369987487793,-9.324899673461914,0.0]}],"bonds":[{"type":2,"atoms":[2,0]},{"type":2,"atoms":[3,1]},{"type":1,"atoms":[0,4]},{"type":1,"atoms":[1,2]},{"type":2,"atoms":[4,5]},{"type":1,"atoms":[5,3]}]},"mol1":{"type":"molecule","atoms":[{"label":"C","location":[16.03459930419922,-7.775000095367432,0.0]},{"label":"C","location":[17.76499938964844,-7.774499893188477,0.0]},{"label":"C","location":[16.90139961242676,-7.274899959564209,0.0]},{"label":"C","location":[17.76499938964844,-8.775400161743164,0.0]},{"label":"C","location":[16.03459930419922,-8.779899597167969,0.0]},{"label":"C","location":[16.903600692749025,-9.274900436401368,0.0]}],"bonds":[{"type":2,"atoms":[2,0]},{"type":2,"atoms":[3,1]},{"type":1,"atoms":[0,4]},{"type":1,"atoms":[1,2]},{"type":2,"atoms":[4,5]},{"type":1,"atoms":[5,3]}]},"mol2":{"type":"molecule","atoms":[{"label":"Cl","location":[12.974800109863282,-8.824899673461914,0.0]}],"bonds":[]},"mol3":{"type":"molecule","atoms":[{"label":"N","location":[12.549799919128418,-7.724899768829346,0.0]}],"bonds":[]}} +{"root":{"nodes":[{"$ref":"mol0"},{"$ref":"mol1"},{"$ref":"mol2"},{"$ref":"mol3"},{"type":"arrow","data":{"mode":"open-angle","pos":[{"x":10.515000343322754,"y":-8.324899673461914,"z":0.0},{"x":15.03459930419922,"y":-8.274900436401368,"z":0.0}]}}]},"mol0":{"type":"molecule","atoms":[{"label":"C","location":[7.7846999168396,-7.824999809265137,0.0]},{"label":"C","location":[9.515000343322754,-7.82450008392334,0.0]},{"label":"C","location":[8.65149974822998,-7.324900150299072,0.0]},{"label":"C","location":[9.515000343322754,-8.825400352478028,0.0]},{"label":"C","location":[7.7846999168396,-8.829899787902832,0.0]},{"label":"C","location":[8.65369987487793,-9.324899673461914,0.0]}],"bonds":[{"type":2,"atoms":[2,0]},{"type":2,"atoms":[3,1]},{"type":1,"atoms":[0,4]},{"type":1,"atoms":[1,2]},{"type":2,"atoms":[4,5]},{"type":1,"atoms":[5,3]}]},"mol1":{"type":"molecule","atoms":[{"label":"C","location":[16.03459930419922,-7.775000095367432,0.0]},{"label":"C","location":[17.76499938964844,-7.774499893188477,0.0]},{"label":"C","location":[16.90139961242676,-7.274899959564209,0.0]},{"label":"C","location":[17.76499938964844,-8.775400161743164,0.0]},{"label":"C","location":[16.03459930419922,-8.779899597167969,0.0]},{"label":"C","location":[16.903600692749025,-9.274900436401368,0.0]}],"bonds":[{"type":2,"atoms":[2,0]},{"type":2,"atoms":[3,1]},{"type":1,"atoms":[0,4]},{"type":1,"atoms":[1,2]},{"type":2,"atoms":[4,5]},{"type":1,"atoms":[5,3]}]},"mol2":{"type":"molecule","atoms":[{"label":"Cl","location":[12.974800109863282,-8.824899673461914,0.0]}],"bonds":[]},"mol3":{"type":"molecule","atoms":[{"label":"N","location":[12.549799919128418,-7.724899768829346,0.0]}],"bonds":[]}} \ No newline at end of file diff --git a/api/tests/integration/tests/reaction/save_ket_layout_1205.py b/api/tests/integration/tests/reaction/save_ket_layout_1205.py index a6faeb815b..1988a7ea3c 100644 --- a/api/tests/integration/tests/reaction/save_ket_layout_1205.py +++ b/api/tests/integration/tests/reaction/save_ket_layout_1205.py @@ -18,9 +18,13 @@ def find_diff(a, b): r1 = indigo.loadReactionFromFile( joinPathPy("reactions/issue_1205.rxn", __file__) ) +ket_out = r1.json() + +# with open(joinPathPy("reactions/issue_1205.ket", __file__), "w") as file: +# file.write(ket_out) + with open(joinPathPy("reactions/issue_1205.ket", __file__), "r") as file: ket_ref = file.read() -ket_out = r1.json() diff = find_diff(ket_ref, ket_out) if diff: print("Difference found:\n", diff) diff --git a/core/indigo-core/layout/reaction_layout.h b/core/indigo-core/layout/reaction_layout.h index b6488c7a58..223e319693 100644 --- a/core/indigo-core/layout/reaction_layout.h +++ b/core/indigo-core/layout/reaction_layout.h @@ -38,6 +38,10 @@ namespace indigo void make(); + // layout if reaction components are not in the places + void fixLayout(); + void processSideBoxes(std::vector& pluses, Rect2f& type_box, int side); + float bond_length; float atom_label_width; float plus_interval_factor; @@ -49,6 +53,7 @@ namespace indigo layout_orientation_value layout_orientation; private: + void _updateMetadata(); void _pushMol(Metalayout::LayoutLine& line, int id, bool is_agent = false); void _pushSpace(Metalayout::LayoutLine& line, float size); BaseMolecule& _getMol(int id); diff --git a/core/indigo-core/layout/src/reaction_layout.cpp b/core/indigo-core/layout/src/reaction_layout.cpp index 34eb55eda6..f365fdefd4 100644 --- a/core/indigo-core/layout/src/reaction_layout.cpp +++ b/core/indigo-core/layout/src/reaction_layout.cpp @@ -18,21 +18,169 @@ #include "layout/reaction_layout.h" #include "layout/molecule_layout.h" +#include "molecule/ket_commons.h" #include "molecule/molecule.h" #include "reaction/reaction.h" +#include #include using namespace indigo; ReactionLayout::ReactionLayout(BaseReaction& r, bool smart_layout) : bond_length(MoleculeLayout::DEFAULT_BOND_LENGTH), plus_interval_factor(1), arrow_interval_factor(2), preserve_molecule_layout(false), _r(r), - _smart_layout(smart_layout), horizontal_interval_factor(DEFAULT_HOR_INTERVAL_FACTOR), atom_label_width(1.3f) + _smart_layout(smart_layout), horizontal_interval_factor(DEFAULT_HOR_INTERVAL_FACTOR), atom_label_width(1.3f), layout_orientation(UNCPECIFIED), + max_iterations(0) { - max_iterations = 0; +} + +void ReactionLayout::fixLayout() +{ + int arrows_count = _r.meta().getMetaCount(KETReactionArrow::CID); + int simple_count = _r.meta().getMetaCount(KETSimpleObject::CID) + _r.meta().getMetaCount(KETTextObject::CID); + if (arrows_count > 1 || simple_count) + return; + + Vec2f rmax{Vec2f::min_coord(), Vec2f::min_coord()}, pmin{Vec2f::max_coord(), Vec2f::max_coord()}; + Rect2f bb; + // Calculate rightTop of reactant bounding box + for (int i = _r.reactantBegin(); i != _r.reactantEnd(); i = _r.reactantNext(i)) + { + _r.getBaseMolecule(i).getBoundingBox(bb); + rmax.max(bb.rightTop()); + } + + // Calculate leftBottom of product bounding box + for (int i = _r.productBegin(); i != _r.productEnd(); i = _r.productNext(i)) + { + _r.getBaseMolecule(i).getBoundingBox(bb); + pmin.min(bb.leftBottom()); + } + + // if left side of product bb at left of right side of reactant bb - fix layout + if (rmax.x > pmin.x) + { + ReactionLayout rl(_r, true); + rl.preserve_molecule_layout = true; + rl.make(); + } + else if (_r.meta().getMetaCount(KETReactionArrow::CID) == 0) + _updateMetadata(); +} + +void ReactionLayout::_updateMetadata() +{ + float arrow_height = 0; + int arrow_type = KETReactionArrow::EOpenAngle; + if (_r.meta().getMetaCount(KETReactionArrow::CID) > 0) + { + auto& ra = static_cast(_r.meta().getMetaObject(KETReactionArrow::CID, 0)); + // remember arrow type & height + arrow_type = ra.getArrowType(); + arrow_height = ra.getHeight(); + // reset pluses and arrows + _r.meta().resetReactionData(); + } + + std::vector pluses; + Rect2f react_box, product_box, catalyst_box; + bool last_single_reactant = false; + bool first_single_product = false; + if (_r.reactantsCount() > 0) + { + processSideBoxes(pluses, react_box, BaseReaction::REACTANT); + for (int i = _r.reactantBegin(); i != _r.reactantEnd(); i = _r.reactantNext(i)) + last_single_reactant = _r.getBaseMolecule(i).vertexCount() == 1; + } + + if (_r.productsCount() > 0) + { + processSideBoxes(pluses, product_box, BaseReaction::PRODUCT); + first_single_product = _r.getBaseMolecule(_r.productBegin()).vertexCount() == 1; + } + + if (_r.catalystCount() > 0) + processSideBoxes(pluses, catalyst_box, BaseReaction::CATALYST); + + for (const auto& plus_offset : pluses) + _r.meta().addMetaObject(new KETReactionPlus(plus_offset)); + + Vec2f arrow_head(0, 0); + Vec2f arrow_tail(0, 0); + + constexpr float shift = 1.0f; + if (_r.productsCount() == 0) + { + arrow_tail.x = react_box.right() + shift; + arrow_tail.y = react_box.middleY(); + arrow_head.x = arrow_tail.x + shift; + arrow_head.y = arrow_tail.y; + } + else if (_r.reactantsCount() == 0) + { + arrow_head.x = product_box.left() - shift; + arrow_head.y = product_box.middleY(); + arrow_tail.x = arrow_head.x - shift; + arrow_tail.y = arrow_head.y; + } + else + { + const float ptab = first_single_product ? 2.0f : 1.0f; + const float rtab = last_single_reactant ? 2.0f : 1.0f; + + arrow_head.y = product_box.middleY(); + arrow_tail.y = react_box.middleY(); + + if (product_box.left() > react_box.right()) + { + arrow_head.x = product_box.left() - ptab; + arrow_tail.x = react_box.right() + rtab; + } + else + { + arrow_head.x = react_box.right() + rtab; + arrow_tail.x = product_box.left() - ptab; + } + } + _r.meta().addMetaObject(new KETReactionArrow(arrow_type, arrow_tail, arrow_head, arrow_height)); +} + +void ReactionLayout::processSideBoxes(std::vector& pluses, Rect2f& type_box, int side) +{ + int begin = _r.sideBegin(side); + std::vector boxes; + + for (int i = begin; i != _r.sideEnd(); i = _r.sideNext(side, i)) + { + BaseMolecule& mol = _r.getBaseMolecule(i); + + Rect2f box; + mol.getBoundingBox(box); + if (i == begin) + type_box.copy(box); + else + type_box.extend(box); + + if (side != BaseReaction::CATALYST) + boxes.emplace_back(box); + } + + // For REACTANT and PRODUCT insert pluses between boxes + if (side != BaseReaction::CATALYST && boxes.size() > 1) + { + std::ignore = std::accumulate(std::next(boxes.begin()), boxes.end(), boxes[0], [&pluses](Rect2f left, Rect2f right) { + pluses.emplace_back(right.between_left_box(left), left.middleY()); + return right; + }); + } } void ReactionLayout::make() { + int arrows_count = _r.meta().getMetaCount(KETReactionArrow::CID); + int simple_count = _r.meta().getNonChemicalMetaCount(); + if (arrows_count > 1 || simple_count) + return; // not implemented yet + const auto kHalfBondLength = bond_length / 2; const auto kDoubleBondLength = bond_length * 2; // update layout of molecules, if needed @@ -92,6 +240,7 @@ void ReactionLayout::make() _ml.scaleSz(); _ml.calcContentSize(); _ml.process(); + _updateMetadata(); } void ReactionLayout::_pushMol(Metalayout::LayoutLine& line, int id, bool is_agent) diff --git a/core/indigo-core/molecule/ket_commons.h b/core/indigo-core/molecule/ket_commons.h index 48e951caeb..19982682bb 100644 --- a/core/indigo-core/molecule/ket_commons.h +++ b/core/indigo-core/molecule/ket_commons.h @@ -244,6 +244,27 @@ namespace indigo return new KETReactionArrow(_arrow_type, _begin, _end, _height); } + int getArrowType() const + { + return _arrow_type; + } + + float getHeight() const + { + return _height; + } + + const auto& getHead() const + { + return _end; + } + + const auto& getTail() const + { + return _begin; + } + + private: int _arrow_type; float _height; Vec2f _begin; @@ -267,6 +288,12 @@ namespace indigo EKETRectangle, EKETLine }; + const auto& getPos() const + { + return _pos; + } + + private: Vec2f _pos; }; diff --git a/core/indigo-core/molecule/src/molecule_cdxml_saver.cpp b/core/indigo-core/molecule/src/molecule_cdxml_saver.cpp index 53edacb563..46a69de96a 100644 --- a/core/indigo-core/molecule/src/molecule_cdxml_saver.cpp +++ b/core/indigo-core/molecule/src/molecule_cdxml_saver.cpp @@ -1424,15 +1424,15 @@ void MoleculeCdxmlSaver::addMetaObject(const MetaObject& obj, int id) { case KETReactionArrow::CID: { KETReactionArrow& ar = (KETReactionArrow&)(obj); - addArrow(id, ar._arrow_type, ar._begin, ar._end); + addArrow(id, ar.getArrowType(), ar.getTail(), ar.getHead()); } break; case KETReactionPlus::CID: { KETReactionPlus& rp = (KETReactionPlus&)(obj); attrs.insert("GraphicType", "Symbol"); attrs.insert("SymbolType", "Plus"); - Vec2f v1(rp._pos.x, rp._pos.y - PLUS_HALF_HEIGHT / _bond_length); - Vec2f v2(rp._pos.x, rp._pos.y + PLUS_HALF_HEIGHT / _bond_length); + Vec2f v1(rp.getPos().x, rp.getPos().y - PLUS_HALF_HEIGHT / _bond_length); + Vec2f v2(rp.getPos().x, rp.getPos().y + PLUS_HALF_HEIGHT / _bond_length); addElement("graphic", id, v1, v2, attrs); } break; diff --git a/core/indigo-core/molecule/src/molecule_json_saver.cpp b/core/indigo-core/molecule/src/molecule_json_saver.cpp index b041f9dc8b..00c5f44a0c 100644 --- a/core/indigo-core/molecule/src/molecule_json_saver.cpp +++ b/core/indigo-core/molecule/src/molecule_json_saver.cpp @@ -1756,7 +1756,7 @@ void MoleculeJsonSaver::saveMetaData(JsonWriter& writer, MetaDataStorage& meta) // arrow mode writer.Key("mode"); std::string arrow_mode = "open-angle"; - auto at_it = _arrow_type2string.find(ar._arrow_type); + auto at_it = _arrow_type2string.find(ar.getArrowType()); if (at_it != _arrow_type2string.end()) arrow_mode = at_it->second.c_str(); writer.String(arrow_mode.c_str()); @@ -1766,18 +1766,18 @@ void MoleculeJsonSaver::saveMetaData(JsonWriter& writer, MetaDataStorage& meta) writer.StartArray(); writer.StartObject(); writer.Key("x"); - writer.Double(ar._begin.x); + writer.Double(ar.getTail().x); writer.Key("y"); - writer.Double(ar._begin.y); + writer.Double(ar.getTail().y); writer.Key("z"); writer.Double(0); writer.EndObject(); writer.StartObject(); writer.Key("x"); - writer.Double(ar._end.x); + writer.Double(ar.getHead().x); writer.Key("y"); - writer.Double(ar._end.y); + writer.Double(ar.getHead().y); writer.Key("z"); writer.Double(0); writer.EndObject(); @@ -1794,8 +1794,8 @@ void MoleculeJsonSaver::saveMetaData(JsonWriter& writer, MetaDataStorage& meta) writer.String("plus"); writer.Key("location"); writer.StartArray(); - writer.Double(rp._pos.x); - writer.Double(rp._pos.y); + writer.Double(rp.getPos().x); + writer.Double(rp.getPos().y); writer.Double(0); writer.EndArray(); writer.EndObject(); diff --git a/core/indigo-core/reaction/reaction_json_saver.h b/core/indigo-core/reaction/reaction_json_saver.h index 913afaaaba..7779bc9a46 100644 --- a/core/indigo-core/reaction/reaction_json_saver.h +++ b/core/indigo-core/reaction/reaction_json_saver.h @@ -41,8 +41,6 @@ namespace indigo ~ReactionJsonSaver(); void saveReaction(BaseReaction& rxn); - void saveReaction(BaseReaction& rxn, BaseMolecule& merged, MoleculeJsonSaver& json_saver); - void saveReactionWithMetaData(BaseReaction& rxn, BaseMolecule& merged, MoleculeJsonSaver& json_saver); bool add_stereo_desc; bool pretty_json; DECL_ERROR; @@ -53,7 +51,6 @@ namespace indigo private: ReactionJsonSaver(const ReactionJsonSaver&); // no implicit copy static void _getBounds(BaseMolecule& mol, Vec2f& min_vec, Vec2f& max_vec, float scale); - void _fixLayout(BaseReaction& rxn); std::unordered_map _arrow_type2string = { {ReactionComponent::ARROW_BASIC, "open-angle"}, diff --git a/core/indigo-core/reaction/src/reaction_cdxml_saver.cpp b/core/indigo-core/reaction/src/reaction_cdxml_saver.cpp index 9b2561610d..6fd3fcf3f8 100644 --- a/core/indigo-core/reaction/src/reaction_cdxml_saver.cpp +++ b/core/indigo-core/reaction/src/reaction_cdxml_saver.cpp @@ -121,9 +121,9 @@ void ReactionCdxmlSaver::saveReaction(BaseReaction& rxn) if (obj._class_id == KETReactionArrow::CID) { KETReactionArrow& arrow = (KETReactionArrow&)(obj); - if (arrow._arrow_type == KETReactionArrow::ERetrosynthetic) + if (arrow.getArrowType() == KETReactionArrow::ERetrosynthetic) { - molsaver.addRetrosynteticArrow(++_id, meta_ids[i], arrow._begin, arrow._end); + molsaver.addRetrosynteticArrow(++_id, meta_ids[i], arrow.getTail(), arrow.getHead()); retro_arrows_graph_id[meta_ids[i]] = _id; continue; } diff --git a/core/indigo-core/reaction/src/reaction_json_loader.cpp b/core/indigo-core/reaction/src/reaction_json_loader.cpp index fee3e97b87..42f3c66a2e 100644 --- a/core/indigo-core/reaction/src/reaction_json_loader.cpp +++ b/core/indigo-core/reaction/src/reaction_json_loader.cpp @@ -246,7 +246,7 @@ void ReactionJsonLoader::parseMultipleArrowReaction(BaseReaction& rxn) for (int i = 0; i < rxn.meta().getMetaCount(KETReactionPlus::CID); ++i) { auto& plus = (const KETReactionPlus&)rxn.meta().getMetaObject(KETReactionPlus::CID, i); - const Vec2f& plus_pos = plus._pos; + const auto& plus_pos = plus.getPos(); Rect2f bbox(plus_pos - PLUS_BBOX_SHIFT, plus_pos + PLUS_BBOX_SHIFT); _reaction_components.emplace_back(ReactionComponent::PLUS, bbox, i, std::unique_ptr(nullptr)); _reaction_components.back().coordinates.push_back(plus_pos); @@ -260,10 +260,10 @@ void ReactionJsonLoader::parseMultipleArrowReaction(BaseReaction& rxn) for (int i = 0; i < rxn.meta().getMetaCount(KETReactionArrow::CID); ++i) { auto& arrow = (const KETReactionArrow&)rxn.meta().getMetaObject(KETReactionArrow::CID, i); - int arrow_type = arrow._arrow_type; - bool reverseReactionOrder = arrow._arrow_type == KETReactionArrow::ERetrosynthetic; - const Vec2f& arr_begin = !reverseReactionOrder ? arrow._begin : arrow._end; - const Vec2f& arr_end = !reverseReactionOrder ? arrow._end : arrow._begin; + int arrow_type = arrow.getArrowType(); + bool reverseReactionOrder = arrow_type == KETReactionArrow::ERetrosynthetic; + const Vec2f& arr_begin = !reverseReactionOrder ? arrow.getTail() : arrow.getHead(); + const Vec2f& arr_end = !reverseReactionOrder ? arrow.getTail() : arrow.getHead(); Rect2f bbox(arr_begin - ARROW_BBOX_SHIFT, arr_end + ARROW_BBOX_SHIFT); _reaction_components.emplace_back(arrow_type, bbox, i, std::unique_ptr(nullptr)); _reaction_components.back().coordinates.push_back(arr_begin); @@ -283,8 +283,8 @@ void ReactionJsonLoader::parseMultipleArrowReaction(BaseReaction& rxn) for (int i = 0; i < rxn.meta().getMetaCount(KETReactionPlus::CID); ++i) { - auto& plus = (const KETReactionPlus&)rxn.meta().getMetaObject(KETReactionPlus::CID, i); - const Vec2f& plus_pos = plus._pos; + auto& plus = static_cast(rxn.meta().getMetaObject(KETReactionPlus::CID, i)); + auto& plus_pos = plus.getPos(); std::pair plus_connection; // (component1_index, component2_index) if (findPlusNeighbours(plus_pos, mol_tops, mol_bottoms, mol_lefts, mol_rights, plus_connection)) @@ -388,10 +388,10 @@ void ReactionJsonLoader::parseMultipleArrowReaction(BaseReaction& rxn) for (int i = 0; i < rxn.meta().getMetaCount(KETReactionArrow::CID); ++i) { auto& arrow = (const KETReactionArrow&)rxn.meta().getMetaObject(KETReactionArrow::CID, i); - int arrow_type = arrow._arrow_type; - bool reverseReactionOrder = arrow._arrow_type == KETReactionArrow::ERetrosynthetic; - const Vec2f& arr_begin = !reverseReactionOrder ? arrow._begin : arrow._end; - const Vec2f& arr_end = !reverseReactionOrder ? arrow._end : arrow._begin; + int arrow_type = arrow.getArrowType(); + bool reverseReactionOrder = arrow_type == KETReactionArrow::ERetrosynthetic; + const Vec2f& arr_begin = !reverseReactionOrder ? arrow.getTail() : arrow.getHead(); + const Vec2f& arr_end = !reverseReactionOrder ? arrow.getHead() : arrow.getTail(); double min_dist_prod = -1, min_dist_reac = -1; int idx_cs_min_prod = -1, idx_cs_min_reac = -1; for (int index_cs = 0; index_cs < static_cast(_component_summ_blocks.size()); ++index_cs) @@ -490,7 +490,7 @@ void ReactionJsonLoader::parseOneArrowReaction(BaseReaction& rxn) } auto& arrow = (const KETReactionArrow&)rxn.meta().getMetaObject(KETReactionArrow::CID, 0); - bool reverseReactionOrder = arrow._arrow_type == KETReactionArrow::ERetrosynthetic; + bool reverseReactionOrder = arrow.getArrowType() == KETReactionArrow::ERetrosynthetic; if (reverseReactionOrder) rxn.setIsRetrosyntetic(); @@ -513,7 +513,7 @@ void ReactionJsonLoader::parseOneArrowReaction(BaseReaction& rxn) { Vec3f& pt3d = cmol.getAtomXyz(idx); Vec2f pt(pt3d.x, pt3d.y); - int side = !reverseReactionOrder ? getPointSide(pt, arrow._begin, arrow._end) : getPointSide(pt, arrow._end, arrow._begin); + int side = !reverseReactionOrder ? getPointSide(pt, arrow.getTail(), arrow.getHead()) : getPointSide(pt, arrow.getHead(), arrow.getTail()); switch (side) { case KETReagentUpArea: @@ -534,7 +534,7 @@ void ReactionJsonLoader::parseOneArrowReaction(BaseReaction& rxn) case ReactionFragmentType::TEXT: { const auto& bbox = std::get(comp); Vec2f pt(bbox.center()); - int side = !reverseReactionOrder ? getPointSide(pt, arrow._begin, arrow._end) : getPointSide(pt, arrow._end, arrow._begin); + int side = !reverseReactionOrder ? getPointSide(pt, arrow.getTail(), arrow.getHead()) : getPointSide(pt, arrow.getHead(), arrow.getTail()); if (side == KETReagentUpArea || side == KETReagentDownArea) { rxn.addSpecialCondition(text_meta_idx, bbox); diff --git a/core/indigo-core/reaction/src/reaction_json_saver.cpp b/core/indigo-core/reaction/src/reaction_json_saver.cpp index 9a1a73683e..788e096bf3 100644 --- a/core/indigo-core/reaction/src/reaction_json_saver.cpp +++ b/core/indigo-core/reaction/src/reaction_json_saver.cpp @@ -17,7 +17,6 @@ ***************************************************************************/ #include -#include #include #include @@ -35,33 +34,6 @@ using namespace rapidjson; IMPL_ERROR(ReactionJsonSaver, "reaction KET saver"); -void ReactionJsonSaver::_fixLayout(BaseReaction& rxn) -{ - Vec2f rmax{Vec2f::min_coord(), Vec2f::min_coord()}, pmin{Vec2f::max_coord(), Vec2f::max_coord()}; - Rect2f bb; - // Calculate rightTop of reactant bounding box - for (int i = rxn.reactantBegin(); i != rxn.reactantEnd(); i = rxn.reactantNext(i)) - { - rxn.getBaseMolecule(i).getBoundingBox(bb); - rmax.max(bb.rightTop()); - } - - // Calculate leftBottom of product bounding box - for (int i = rxn.productBegin(); i != rxn.productEnd(); i = rxn.productNext(i)) - { - rxn.getBaseMolecule(i).getBoundingBox(bb); - pmin.min(bb.leftBottom()); - } - - // if left side of product bb at left of right side of reactant bb - fix layout - if (rmax.x > pmin.x) - { - ReactionLayout rl(rxn, true); - rl.preserve_molecule_layout = true; - rl.make(); - } -} - void ReactionJsonSaver::_getBounds(BaseMolecule& mol, Vec2f& min_vec, Vec2f& max_vec, float scale) { Rect2f bbox; @@ -80,195 +52,44 @@ ReactionJsonSaver::~ReactionJsonSaver() { } -void ReactionJsonSaver::saveReactionWithMetaData(BaseReaction& rxn, BaseMolecule& merged, MoleculeJsonSaver& json_saver) -{ - for (int i = rxn.begin(); i != rxn.end(); i = rxn.next(i)) - merged.mergeWithMolecule(rxn.getBaseMolecule(i), 0, 0); - - merged.meta().clone(rxn.meta()); - StringBuffer s; - JsonWriter writer(pretty_json); - writer.Reset(s); - json_saver.saveMolecule(merged, writer); - _output.printf("%s", s.GetString()); -} - -static void _processSideBoxes(std::unique_ptr& reaction, BaseMolecule& merged, std::vector& pluses, Rect2f& type_box, int side) +void ReactionJsonSaver::saveReaction(BaseReaction& rxn) { - int begin = reaction->sideBegin(side); - std::vector boxes; - - for (int i = begin; i != reaction->sideEnd(); i = reaction->sideNext(side, i)) + MoleculeJsonSaver json_saver(_output); + json_saver.add_stereo_desc = add_stereo_desc; + std::unique_ptr merged; + if (rxn.isQueryReaction()) { - BaseMolecule& mol = reaction->getBaseMolecule(i); - merged.mergeWithMolecule(mol, 0, 0); - - Rect2f box; - mol.getBoundingBox(box); - if (i == begin) - type_box.copy(box); - else - type_box.extend(box); - - if (side != BaseReaction::CATALYST) - boxes.emplace_back(box); + merged = std::make_unique(); } - - // For REACTANT and PRODUCT insert pluses between boxes - if (side != BaseReaction::CATALYST && boxes.size() > 1) + else { - std::ignore = std::accumulate(std::next(boxes.begin()), boxes.end(), boxes[0], [&pluses](Rect2f left, Rect2f right) { - pluses.emplace_back(right.between_left_box(left), left.middleY()); - return right; - }); + merged = std::make_unique(); } -} -void ReactionJsonSaver::saveReaction(BaseReaction& rxn, BaseMolecule& merged, MoleculeJsonSaver& json_saver) -{ - std::vector pluses; - Rect2f react_box, product_box, catalyst_box; - bool last_single_reactant = false; - bool first_single_product = false; std::unique_ptr reaction(rxn.neu()); reaction->clone(rxn); - _fixLayout(*reaction); - if (reaction->reactantsCount() > 0) - { - _processSideBoxes(reaction, merged, pluses, react_box, BaseReaction::REACTANT); - for (int i = reaction->reactantBegin(); i != reaction->reactantEnd(); i = reaction->reactantNext(i)) - { - last_single_reactant = reaction->getBaseMolecule(i).vertexCount() == 1; - } - } + ReactionLayout rl(*reaction); + rl.fixLayout(); - if (reaction->productsCount() > 0) - { - _processSideBoxes(reaction, merged, pluses, product_box, BaseReaction::PRODUCT); - first_single_product = reaction->getBaseMolecule(reaction->productBegin()).vertexCount() == 1; - } + // merge + for (int i = reaction->begin(); i != reaction->end(); i = reaction->next(i)) + merged->mergeWithMolecule(reaction->getBaseMolecule(i), 0, 0); - if (reaction->catalystCount() > 0) - { - _processSideBoxes(reaction, merged, pluses, catalyst_box, BaseReaction::CATALYST); - } + merged->meta().clone(reaction->meta()); // dump molecules StringBuffer s; JsonWriter writer(pretty_json); writer.Reset(s); - json_saver.saveMolecule(merged, writer); + json_saver.saveMolecule(*merged, writer); Document ket; ket.Parse(s.GetString()); if (!(ket.HasMember("root") && ket["root"].HasMember("nodes"))) throw Error("reaction_json_saver: MoleculeJsonSaver::saveMolecule failed"); - auto& nodes = ket["root"]["nodes"]; - - for (const auto& plus_offset : pluses) - { - Value plus(kObjectType); - plus.AddMember("type", "plus", ket.GetAllocator()); - Value location(kArrayType); - location.PushBack(Value().SetDouble(plus_offset.x), ket.GetAllocator()); - location.PushBack(Value().SetDouble(plus_offset.y), ket.GetAllocator()); - location.PushBack(Value().SetDouble(0.0), ket.GetAllocator()); - plus.AddMember("location", location, ket.GetAllocator()); - nodes.PushBack(plus, ket.GetAllocator()); - } - - // calculate arrow - Vec2f arrow_head(0, 0); - Vec2f arrow_tail(0, 0); - if (reaction->reactantsCount() || reaction->productsCount()) - { - constexpr float shift = 1.0f; - if (reaction->productsCount() == 0) - { - arrow_tail.x = react_box.right() + shift; - arrow_tail.y = react_box.middleY(); - arrow_head.x = arrow_tail.x + shift; - arrow_head.y = arrow_tail.y; - } - else if (reaction->reactantsCount() == 0) - { - arrow_head.x = product_box.left() - shift; - arrow_head.y = product_box.middleY(); - arrow_tail.x = arrow_head.x - shift; - arrow_tail.y = arrow_head.y; - } - else - { - const float ptab = first_single_product ? 2.0f : 1.0f; - const float rtab = last_single_reactant ? 2.0f : 1.0f; - - arrow_head.y = product_box.middleY(); - arrow_tail.y = react_box.middleY(); - - if (product_box.left() > react_box.right()) - { - arrow_head.x = product_box.left() - ptab; - arrow_tail.x = react_box.right() + rtab; - } - else - { - arrow_head.x = react_box.right() + rtab; - arrow_tail.x = product_box.left() - ptab; - } - } - - Value arrow(kObjectType); - arrow.AddMember("type", "arrow", ket.GetAllocator()); - Value data(kObjectType); - Value pos_array(kArrayType); - Value pos1(kObjectType); - Value pos2(kObjectType); - pos1.AddMember("x", Value().SetDouble(arrow_head.x), ket.GetAllocator()); - pos1.AddMember("y", Value().SetDouble(arrow_head.y), ket.GetAllocator()); - pos1.AddMember("z", Value().SetDouble(0.0), ket.GetAllocator()); - pos2.AddMember("x", Value().SetDouble(arrow_tail.x), ket.GetAllocator()); - pos2.AddMember("y", Value().SetDouble(arrow_tail.y), ket.GetAllocator()); - pos2.AddMember("z", Value().SetDouble(0.0), ket.GetAllocator()); - pos_array.PushBack(pos2, ket.GetAllocator()); - pos_array.PushBack(pos1, ket.GetAllocator()); - data.AddMember("mode", "open-angle", ket.GetAllocator()); - data.AddMember("pos", pos_array, ket.GetAllocator()); - arrow.AddMember("data", data, ket.GetAllocator()); - nodes.PushBack(arrow, ket.GetAllocator()); - s.Clear(); - writer.Reset(s); - ket.Accept(writer); - - _output.printf("%s", s.GetString()); - } - else - throw Error("Empty reaction"); -} - -void ReactionJsonSaver::saveReaction(BaseReaction& rxn) -{ - MoleculeJsonSaver json_saver(_output); - json_saver.add_stereo_desc = add_stereo_desc; - std::unique_ptr merged; - if (rxn.isQueryReaction()) - { - merged = std::make_unique(); - } - else - { - merged = std::make_unique(); - } - - int arrows_count = rxn.meta().getMetaCount(KETReactionArrow::CID); - int simple_count = rxn.meta().getMetaCount(KETSimpleObject::CID) + rxn.meta().getMetaCount(KETTextObject::CID); - if (arrows_count || simple_count) - { - // if metadata presents - saveReactionWithMetaData(rxn, *merged, json_saver); - } - else - { - saveReaction(rxn, *merged, json_saver); - } + s.Clear(); + writer.Reset(s); + ket.Accept(writer); + _output.printf("%s", s.GetString()); } diff --git a/core/render2d/src/render_item_aux.cpp b/core/render2d/src/render_item_aux.cpp index 4a01c512bd..0d026a3ee1 100644 --- a/core/render2d/src/render_item_aux.cpp +++ b/core/render2d/src/render_item_aux.cpp @@ -174,11 +174,11 @@ void RenderItemAuxiliary::_drawPlus() void RenderItemAuxiliary::_drawArrow(const KETReactionArrow& ar) { _rc.setSingleSource(CWC_BASE); - auto beg = ar._begin; - auto end = ar._end; + Vec2f beg = ar.getTail(); + Vec2f end = ar.getHead(); scale(beg); scale(end); - switch (ar._arrow_type) + switch (ar.getArrowType()) { case KETReactionArrow::EOpenAngle: _rc.drawCustomArrow(beg, end, _settings.metaLineWidth, _settings.arrowHeadWidth, _settings.arrowHeadSize, false, false); @@ -233,19 +233,19 @@ void RenderItemAuxiliary::_drawArrow(const KETReactionArrow& ar) break; case KETReactionArrow::EEllipticalArcFilledBow: - _rc.drawEllipticalArrow(beg, end, _settings.metaLineWidth, _settings.arrowHeadWidth, _settings.arrowHeadSize, ar._height, ar._arrow_type); + _rc.drawEllipticalArrow(beg, end, _settings.metaLineWidth, _settings.arrowHeadWidth, _settings.arrowHeadSize, ar.getHeight(), ar.getArrowType()); break; case KETReactionArrow::EEllipticalArcFilledTriangle: - _rc.drawEllipticalArrow(beg, end, _settings.metaLineWidth, _settings.arrowHeadWidth, _settings.arrowHeadSize, ar._height, ar._arrow_type); + _rc.drawEllipticalArrow(beg, end, _settings.metaLineWidth, _settings.arrowHeadWidth, _settings.arrowHeadSize, ar.getHeight(), ar.getArrowType()); break; case KETReactionArrow::EEllipticalArcOpenAngle: - _rc.drawEllipticalArrow(beg, end, _settings.metaLineWidth, _settings.arrowHeadWidth, _settings.arrowHeadSize, ar._height, ar._arrow_type); + _rc.drawEllipticalArrow(beg, end, _settings.metaLineWidth, _settings.arrowHeadWidth, _settings.arrowHeadSize, ar.getHeight(), ar.getArrowType()); break; case KETReactionArrow::EEllipticalArcOpenHalfAngle: - _rc.drawEllipticalArrow(beg, end, _settings.metaLineWidth, _settings.arrowHeadWidth, _settings.arrowHeadSize, ar._height, ar._arrow_type); + _rc.drawEllipticalArrow(beg, end, _settings.metaLineWidth, _settings.arrowHeadWidth, _settings.arrowHeadSize, ar.getHeight(), ar.getArrowType()); break; case KETReactionArrow::ERetrosynthetic: @@ -366,7 +366,7 @@ void RenderItemAuxiliary::_drawMeta(bool idle) case KETReactionPlus::CID: { const KETReactionPlus& rp = static_cast(mobj); _rc.setSingleSource(CWC_BASE); - auto plus_pos = rp._pos; + Vec2f plus_pos = rp.getPos(); scale(plus_pos); _rc.drawPlus(plus_pos, _settings.metaLineWidth, _settings.plusSize); } @@ -378,7 +378,6 @@ void RenderItemAuxiliary::_drawMeta(bool idle) break; case KETImage::CID: { const KETImage& img = static_cast(mobj); - _drawImage(img); } break;