-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2078 – Center molecules after layout
- Loading branch information
Showing
6 changed files
with
125 additions
and
36 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
ketcher-autotests/tests/Indigo-Tools/Layout/layout.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Page, test } from '@playwright/test'; | ||
import { | ||
selectTopPanelButton, | ||
TopPanelButton, | ||
takeEditorScreenshot, | ||
openFile, | ||
pressButton, | ||
waitForLoad, | ||
getCoordinatesOfTheMiddleOfTheScreen, | ||
} from '@utils'; | ||
|
||
async function openFileWithShift(filename: string, page: Page) { | ||
await selectTopPanelButton(TopPanelButton.Open, page); | ||
await openFile(filename, page); | ||
await waitForLoad(page, async () => { | ||
await pressButton(page, 'Add to Canvas'); | ||
}); | ||
const { x, y } = await getCoordinatesOfTheMiddleOfTheScreen(page); | ||
const shift = 150; | ||
await page.mouse.click(x + shift, y + shift); | ||
} | ||
|
||
test.describe('Indigo Tools - Layout', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto(''); | ||
}); | ||
|
||
test('Center molecule after layout', async ({ page }) => { | ||
// Related Github issue: https://github.com/epam/ketcher/issues/2078 | ||
const anyStructure = 'benzene-rings.mol'; | ||
await openFileWithShift(anyStructure, page); | ||
await selectTopPanelButton(TopPanelButton.Layout, page); | ||
await takeEditorScreenshot(page); | ||
}); | ||
}); |
Binary file added
BIN
+9.95 KB
...apshots/Indigo-Tools---Layout-Center-molecule-after-layout-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
null | ||
Ketcher 7172314 12D 1 1.00000 0.00000 0 | ||
|
||
18 20 0 0 0 0 0 0 0 0999 V2000 | ||
20.5750 -8.6000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
19.7090 -10.1000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
19.7090 -9.1000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
20.5750 -10.6000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
21.4410 -9.1000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
21.4410 -10.1000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
19.8679 -7.8929 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
18.1961 -7.4466 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
18.9014 -8.1523 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
18.4545 -6.4796 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
20.1273 -6.9220 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
19.4156 -6.2194 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
20.1227 -5.5123 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
18.8981 -4.2900 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
19.1560 -5.2537 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
19.6054 -3.5817 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
20.8329 -4.8013 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
20.5678 -3.8369 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
3 1 2 0 0 0 | ||
4 2 2 0 0 0 | ||
1 5 1 0 0 0 | ||
2 3 1 0 0 0 | ||
5 6 2 0 0 0 | ||
6 4 1 0 0 0 | ||
1 7 1 0 0 0 | ||
9 7 2 0 0 0 | ||
10 8 2 0 0 0 | ||
7 11 1 0 0 0 | ||
8 9 1 0 0 0 | ||
11 12 2 0 0 0 | ||
12 10 1 0 0 0 | ||
12 13 1 0 0 0 | ||
15 13 2 0 0 0 | ||
16 14 2 0 0 0 | ||
13 17 1 0 0 0 | ||
14 15 1 0 0 0 | ||
17 18 2 0 0 0 | ||
18 16 1 0 0 0 | ||
M END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ | |
|
||
export * from './customOnChangeHandler'; | ||
export * from './elementOffset'; | ||
export * from './structLayout'; |
23 changes: 23 additions & 0 deletions
23
packages/ketcher-react/src/script/editor/utils/structLayout.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Editor, ReStruct, Vec2 } from 'ketcher-core'; | ||
|
||
export function getSelectionMap(structure: ReStruct) { | ||
return Object.keys(ReStruct.maps).reduce((result, map) => { | ||
result[map] = Array.from(structure[map].keys()); | ||
return result; | ||
}, {}); | ||
} | ||
|
||
export function getStructCenter(ReStruct, selection?) { | ||
const bb = ReStruct.getVBoxObj(selection || {}); | ||
return Vec2.lc2(bb.p0, 0.5, bb.p1, 0.5); | ||
} | ||
|
||
export function recoordinate(editor: Editor, rp?: Vec2) { | ||
// rp is a point in scaled coordinates, which will be positioned | ||
console.assert(rp, 'Reference point not specified'); | ||
if (rp) { | ||
editor.render.setScrollOffset(rp.x, rp.y); | ||
} else { | ||
editor.render.setScrollOffset(0, 0); | ||
} | ||
} |