-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into #1990-functional-group-does-not-connect-wi…
…th-another-functional-group-on-clickdrag
- Loading branch information
Showing
10 changed files
with
331 additions
and
309 deletions.
There are no files selected for viewing
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
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
54 changes: 54 additions & 0 deletions
54
packages/ketcher-react/src/script/editor/tool/helper/dropAndMerge.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,54 @@ | ||
import { Action, fromItemsFuse, ReStruct, setExpandSGroup } from 'ketcher-core' | ||
import Editor from '../../Editor' | ||
import { getGroupIdsFromItemMaps } from './getGroupIdsFromItems' | ||
|
||
type MergeItems = { | ||
atoms: Map<number, number> | ||
bonds: Map<number, number> | ||
} | ||
|
||
export function dropAndMerge( | ||
editor: Editor, | ||
mergeItems: MergeItems, | ||
action?: Action | ||
): void { | ||
const restruct = editor.render.ctab | ||
const isMerging = !!mergeItems | ||
let dropItemAction = new Action() | ||
|
||
if (isMerging) { | ||
const expandGroupsAction = getExpandGroupsInMergeAction( | ||
editor.render.ctab, | ||
mergeItems | ||
) | ||
dropItemAction = dropItemAction.mergeWith(expandGroupsAction) | ||
} | ||
|
||
dropItemAction = fromItemsFuse(restruct, mergeItems).mergeWith(dropItemAction) | ||
|
||
if (action) { | ||
dropItemAction = dropItemAction.mergeWith(action) | ||
} | ||
|
||
editor.hover(null) | ||
if (isMerging) editor.selection(null) | ||
|
||
if (dropItemAction?.operations.length > 0) { | ||
editor.update(dropItemAction) | ||
} | ||
} | ||
|
||
function getExpandGroupsInMergeAction( | ||
restruct: ReStruct, | ||
mergeItems: MergeItems | ||
): Action { | ||
const action = new Action() | ||
const groupsInMerge = getGroupIdsFromItemMaps(restruct.molecule, mergeItems) | ||
if (groupsInMerge.length) { | ||
groupsInMerge.forEach((groupId) => { | ||
action.mergeWith(setExpandSGroup(restruct, groupId, { expanded: true })) | ||
}) | ||
} | ||
|
||
return action | ||
} |
43 changes: 43 additions & 0 deletions
43
packages/ketcher-react/src/script/editor/tool/helper/getGroupIdsFromItems.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,43 @@ | ||
import { mergeMapOfItemsToSet, Struct } from 'ketcher-core' | ||
|
||
type Items = { | ||
atoms?: number[] | ||
bonds?: number[] | ||
} | ||
|
||
function getGroupIdsFromItemArrays(struct: Struct, items?: Items): number[] { | ||
if (!struct.sgroups.size) return [] | ||
|
||
const groupsIds = new Set<number>() | ||
|
||
items?.atoms?.forEach((atomId) => { | ||
const groupId = struct.getGroupIdFromAtomId(atomId) | ||
if (groupId !== null) groupsIds.add(groupId) | ||
}) | ||
|
||
items?.bonds?.forEach((bondId) => { | ||
const groupId = struct.getGroupIdFromBondId(bondId) | ||
if (groupId !== null) groupsIds.add(groupId) | ||
}) | ||
|
||
return Array.from(groupsIds) | ||
} | ||
|
||
type MergeItems = { | ||
atoms: Map<number, number> | ||
bonds: Map<number, number> | ||
} | ||
|
||
function getGroupIdsFromItemMaps( | ||
struct: Struct, | ||
mergeMaps: MergeItems | null | ||
): number[] { | ||
const atoms = | ||
mergeMaps?.atoms && Array.from(mergeMapOfItemsToSet(mergeMaps.atoms)) | ||
const bonds = | ||
mergeMaps?.bonds && Array.from(mergeMapOfItemsToSet(mergeMaps.bonds)) | ||
|
||
return getGroupIdsFromItemArrays(struct, { atoms, bonds }) | ||
} | ||
|
||
export { getGroupIdsFromItemArrays, getGroupIdsFromItemMaps } |
18 changes: 18 additions & 0 deletions
18
packages/ketcher-react/src/script/editor/tool/helper/getMergeItems.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,18 @@ | ||
import { getItemsToFuse } from 'ketcher-core' | ||
import Editor from '../../Editor' | ||
import utils from '../../shared/utils' | ||
|
||
export function getMergeItems( | ||
editor: Editor, | ||
items: Record<string, number[]> | ||
): Record<string, Map<unknown, unknown>> | null { | ||
const nonGroupItemsAndAttachPoints = { | ||
...items, | ||
...utils.getNonGroupItemsAndAttachmentPoints( | ||
items, | ||
editor.render.ctab.molecule | ||
) | ||
} | ||
|
||
return getItemsToFuse(editor, nonGroupItemsAndAttachPoints) | ||
} |
Oops, something went wrong.