Skip to content

Commit

Permalink
#6109 - Antisense of layout doesn't work on flex mode after load (#6114
Browse files Browse the repository at this point in the history
…) (#6138)

* #6109 - Antisense of layout doesn't work on flex mode after load
- applied snake layout in flex mode if open/paste file with antisense chain
- fixed open file implementation

* #6083 - Creation of antisense chain causes monomer re-arrangement on the flex canvas
- applied zoom to left top corner of the structures after antisense chains creation
- updated ketcher version to 2.28.0-rc.2
  • Loading branch information
rrodionov91 authored Dec 12, 2024
1 parent 6c4a38b commit 42a2a6c
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/ketcher-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ketcher-core",
"version": "2.28.0-rc.1",
"version": "2.28.0-rc.2",
"description": "Web-based molecule sketcher",
"license": "Apache-2.0",
"homepage": "http://lifescience.opensource.epam.com/ketcher",
Expand Down
21 changes: 20 additions & 1 deletion packages/ketcher-core/src/application/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ import assert from 'assert';
import { SequenceType, Struct, Vec2 } from 'domain/entities';
import { BaseMonomer } from 'domain/entities/BaseMonomer';
import { Command } from 'domain/entities/Command';
import { DrawingEntitiesManager } from 'domain/entities/DrawingEntitiesManager';
import {
DrawingEntitiesManager,
MONOMER_START_X_POSITION,
MONOMER_START_Y_POSITION,
SNAKE_LAYOUT_CELL_WIDTH,
} from 'domain/entities/DrawingEntitiesManager';
import { PolymerBond } from 'domain/entities/PolymerBond';
import { AttachmentPointName, MonomerItemType } from 'domain/types';
import { DOMSubscription } from 'subscription';
Expand Down Expand Up @@ -416,6 +421,7 @@ export class CoreEditor {

this.renderersContainer.update(modelChanges);
history.update(modelChanges);
this.scrollToTopLeftCorner();
}

private onSelectMonomer(monomer: MonomerItemType) {
Expand Down Expand Up @@ -786,4 +792,17 @@ export class CoreEditor {

ZoomTool.instance.zoomStructureToFitHalfOfCanvas(structureBbox);
}

public scrollToTopLeftCorner() {
const drawnEntitiesBoundingBox =
RenderersManager.getRenderedStructuresBbox();

ZoomTool.instance.scrollTo(
new Vec2(drawnEntitiesBoundingBox.left, drawnEntitiesBoundingBox.top),
false,
MONOMER_START_X_POSITION - SNAKE_LAYOUT_CELL_WIDTH / 4,
MONOMER_START_Y_POSITION - SNAKE_LAYOUT_CELL_WIDTH / 4,
false,
);
}
}
20 changes: 19 additions & 1 deletion packages/ketcher-core/src/application/editor/modes/FlexMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,25 @@ export class FlexMode extends BaseMode {
}

applyAdditionalPasteOperations() {
return new Command();
const command = new Command();
const editor = CoreEditor.provideEditorInstance();

editor.drawingEntitiesManager.recalculateAntisenseChains();

if (!editor.drawingEntitiesManager.hasAntisenseChains) {
return command;
}

command.merge(
editor.drawingEntitiesManager.applySnakeLayout(
editor.canvas.width.baseVal.value,
true,
true,
true,
),
);

return command;
}

isPasteAllowedByMode(): boolean {
Expand Down
19 changes: 1 addition & 18 deletions packages/ketcher-core/src/application/editor/modes/SnakeMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import { Command } from 'domain/entities/Command';
import { ReinitializeModeOperation } from 'application/editor/operations/modes';
import { Vec2 } from 'domain/entities';
import { RenderersManager } from 'application/render/renderers/RenderersManager';
import {
MONOMER_START_X_POSITION,
MONOMER_START_Y_POSITION,
SNAKE_LAYOUT_CELL_WIDTH,
} from 'domain/entities/DrawingEntitiesManager';

export class SnakeMode extends BaseMode {
constructor(previousMode?: LayoutMode) {
Expand All @@ -33,22 +28,10 @@ export class SnakeMode extends BaseMode {
);

editor.drawingEntitiesManager.applyFlexLayoutMode();

command.merge(modelChanges);
editor.renderersContainer.update(modelChanges);
command.setUndoOperationReverse();

const drawnEntitiesBoundingBox =
RenderersManager.getRenderedStructuresBbox();
const zoom = ZoomTool.instance;

zoom.scrollTo(
new Vec2(drawnEntitiesBoundingBox.left, drawnEntitiesBoundingBox.top),
false,
MONOMER_START_X_POSITION - SNAKE_LAYOUT_CELL_WIDTH / 4,
MONOMER_START_Y_POSITION - SNAKE_LAYOUT_CELL_WIDTH / 4,
false,
);
editor.scrollToTopLeftCorner();

return command;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2824,6 +2824,12 @@ export class DrawingEntitiesManager {
return command;
}

public get hasAntisenseChains() {
return [...this.monomers.values()].some(
(monomer) => monomer.monomerItem.isAntisense,
);
}

private getAntisenseBaseLabel(rnaBase: RNABase | AmbiguousMonomer) {
return this.antisenseChainBasesMap[
rnaBase instanceof AmbiguousMonomer
Expand Down
2 changes: 1 addition & 1 deletion packages/ketcher-macromolecules/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ketcher-macromolecules",
"version": "2.28.0-rc.1",
"version": "2.28.0-rc.2",
"description": "Web-based molecule sketcher",
"license": "Apache-2.0",
"homepage": "http://lifescience.opensource.epam.com/ketcher",
Expand Down
17 changes: 17 additions & 0 deletions packages/ketcher-macromolecules/src/components/modal/Open/Open.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
macromoleculesFilesInputFormats,
ModeTypes,
SnakeMode,
FlexMode,
} from 'ketcher-core';
import { IndigoProvider } from 'ketcher-react';
import { RequiredModalProps } from '../modalContainer';
Expand Down Expand Up @@ -175,6 +176,22 @@ const addToCanvas = ({
const editorHistory = new EditorHistory(editor);
const isSequenceMode = editor.mode instanceof SequenceMode;
const isSnakeMode = editor.mode instanceof SnakeMode;
const isFlexMode = editor.mode instanceof FlexMode;

if (isFlexMode) {
editor.drawingEntitiesManager.recalculateAntisenseChains();

if (editor.drawingEntitiesManager.hasAntisenseChains) {
modelChanges.merge(
editor.drawingEntitiesManager.applySnakeLayout(
editor.canvas.width.baseVal.value,
true,
true,
true,
),
);
}
}

editor.renderersContainer.update(modelChanges);
editorHistory.update(modelChanges);
Expand Down
2 changes: 1 addition & 1 deletion packages/ketcher-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ketcher-react",
"version": "2.28.0-rc.1",
"version": "2.28.0-rc.2",
"description": "Web-based molecule sketcher",
"license": "Apache-2.0",
"homepage": "http://lifescience.opensource.epam.com/ketcher",
Expand Down
2 changes: 1 addition & 1 deletion packages/ketcher-standalone/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ketcher-standalone",
"version": "2.28.0-rc.1",
"version": "2.28.0-rc.2",
"description": "Web-based molecule sketcher",
"license": "Apache-2.0",
"homepage": "http://lifescience.opensource.epam.com/ketcher",
Expand Down

0 comments on commit 42a2a6c

Please sign in to comment.