diff --git a/packages/ketcher-core/src/application/editor/operations/polymerBond/index.ts b/packages/ketcher-core/src/application/editor/operations/polymerBond/index.ts index 059711b74b..2b97f1f0a5 100644 --- a/packages/ketcher-core/src/application/editor/operations/polymerBond/index.ts +++ b/packages/ketcher-core/src/application/editor/operations/polymerBond/index.ts @@ -47,6 +47,7 @@ export class PolymerBondDeleteOperation implements Operation { constructor( public polymerBond: PolymerBond, private deletePolymerBondChangeModel: () => void, + private addPolymerBondChangeModel: (polymerBondExists) => PolymerBond, private finishPolymerBondCreationModelChange: () => PolymerBond, ) {} @@ -59,6 +60,7 @@ export class PolymerBondDeleteOperation implements Operation { public invert(renderersManager: RenderersManager) { console.log('invert PolymerBondDeleteOperation'); this.polymerBond = this.finishPolymerBondCreationModelChange(); + this.addPolymerBondChangeModel(this.polymerBond); renderersManager.addPolymerBond(this.polymerBond); console.log('this.polymerBond: ', this.polymerBond); @@ -105,7 +107,6 @@ export class PolymerBondFinishCreationOperation implements Operation { public polymerBond; constructor( private finishPolymerBondCreationModelChange: () => PolymerBond, - private deletePolymerBondCreationModelChange: (polymerBond) => void, ) {} public execute(renderersManager: RenderersManager) { @@ -116,7 +117,6 @@ export class PolymerBondFinishCreationOperation implements Operation { public invert(renderersManager: RenderersManager) { console.log('invert PolymerBondFinishCreationOperation'); - this.deletePolymerBondCreationModelChange(this.polymerBond); renderersManager.deletePolymerBond(this.polymerBond); } } diff --git a/packages/ketcher-core/src/application/editor/tools/RnaPreset.ts b/packages/ketcher-core/src/application/editor/tools/RnaPreset.ts index 199d95a619..9dfd064f74 100644 --- a/packages/ketcher-core/src/application/editor/tools/RnaPreset.ts +++ b/packages/ketcher-core/src/application/editor/tools/RnaPreset.ts @@ -17,7 +17,7 @@ import { Tool, IRnaPreset } from 'application/editor/tools/Tool'; import { Sugar } from 'domain/entities/Sugar'; import { Vec2 } from 'domain/entities'; -import { CoreEditor, EditorHistory } from 'application/editor'; +import { CoreEditor } from 'application/editor'; import { BaseMonomerRenderer } from 'application/render/renderers'; import { MonomerItemType } from 'domain/types'; import { monomerFactory } from '../operations/monomer/monomerFactory'; @@ -42,8 +42,6 @@ class RnaPresetTool implements Tool { readonly RNA_BASE_PREVIEW_OFFSET_X = 2; readonly RNA_BASE_PREVIEW_OFFSET_Y = 20; readonly PHOSPHATE_PREVIEW_OFFSET_X = 18; - history: EditorHistory; - constructor(private editor: CoreEditor, preset: IRnaPreset) { this.editor = editor; if (preset?.base) { @@ -55,7 +53,6 @@ class RnaPresetTool implements Tool { if (preset?.sugar) { this.sugar = preset?.sugar; } - this.history = new EditorHistory(this.editor); // здесь история пишется } mousedown() { @@ -96,7 +93,6 @@ class RnaPresetTool implements Tool { : undefined, }); - this.history.update(modelChanges); this.editor.renderersContainer.update(modelChanges); } diff --git a/packages/ketcher-core/src/application/render/renderers/RenderersManager.ts b/packages/ketcher-core/src/application/render/renderers/RenderersManager.ts index bb8329a77b..71a564509c 100644 --- a/packages/ketcher-core/src/application/render/renderers/RenderersManager.ts +++ b/packages/ketcher-core/src/application/render/renderers/RenderersManager.ts @@ -94,10 +94,6 @@ export class RenderersManager { polymerBond.secondMonomer.renderer?.redrawAttachmentPoints(); polymerBond.secondMonomer.renderer?.drawSelection(); polymerBond.secondMonomer.renderer?.redrawHover(); - this.polymerBonds.get(polymerBond.id)?.remove(); - const polymerBondRenderer = new PolymerBondRenderer(polymerBond); - this.polymerBonds.set(polymerBond.id, polymerBondRenderer); - polymerBond.renderer?.show(); } public cancelPolymerBondCreation(polymerBond) { diff --git a/packages/ketcher-core/src/domain/entities/DrawingEntitiesManager.ts b/packages/ketcher-core/src/domain/entities/DrawingEntitiesManager.ts index bfa769e5dc..745714c552 100644 --- a/packages/ketcher-core/src/domain/entities/DrawingEntitiesManager.ts +++ b/packages/ketcher-core/src/domain/entities/DrawingEntitiesManager.ts @@ -25,6 +25,7 @@ import { PolymerBondMoveOperation, PolymerBondShowInfoOperation, PolymerBondCleanAttachmentPointsOperation, + PolymerBondAddAttachmentPointsOperation, } from 'application/editor/operations/polymerBond'; import { monomerFactory } from 'application/editor/operations/monomer/monomerFactory'; import { provideEditorSettings } from 'application/editor/editorSettings'; @@ -285,21 +286,6 @@ export class DrawingEntitiesManager { public deletePolymerBondChangeModel(polymerBond: PolymerBond) { this.polymerBonds.delete(polymerBond.id); - - const firstMonomerAttachmentPoint = - polymerBond.firstMonomer.getAttachmentPointByBond(polymerBond); - const secondMonomerAttachmentPoint = - polymerBond.secondMonomer?.getAttachmentPointByBond(polymerBond); - polymerBond.firstMonomer.removePotentialBonds(); - polymerBond.secondMonomer?.removePotentialBonds(); - polymerBond.firstMonomer.turnOffSelection(); - polymerBond.secondMonomer?.turnOffSelection(); - if (firstMonomerAttachmentPoint) { - polymerBond.firstMonomer.unsetBond(firstMonomerAttachmentPoint); - } - if (secondMonomerAttachmentPoint) { - polymerBond.secondMonomer?.unsetBond(secondMonomerAttachmentPoint); - } } public deletePolymerBond(polymerBond: PolymerBond) { @@ -312,6 +298,12 @@ export class DrawingEntitiesManager { const operation = new PolymerBondDeleteOperation( polymerBond, this.deletePolymerBondChangeModel.bind(this, polymerBond), + this.addPolymerBondChangeModel.bind( + this, + polymerBond.firstMonomer, + polymerBond.startPosition, + polymerBond.endPosition, + ), this.finishPolymerBondCreationModelChange.bind( this, polymerBond.firstMonomer, @@ -358,16 +350,12 @@ export class DrawingEntitiesManager { secondMonomer: BaseMonomer, firstMonomerAttachmentPoint: string, secondMonomerAttachmentPoint: string, - bondId?: number, ) { const polymerBond = new PolymerBond(firstMonomer); - if (bondId) { - polymerBond.id = bondId; - } - this.polymerBonds.set(polymerBond.id, polymerBond); polymerBond.setSecondMonomer(secondMonomer); polymerBond.firstMonomer.setBond(firstMonomerAttachmentPoint, polymerBond); assert(polymerBond.secondMonomer); + assert(secondMonomer.renderer); polymerBond.secondMonomer.setBond( secondMonomerAttachmentPoint, polymerBond, @@ -395,6 +383,15 @@ export class DrawingEntitiesManager { const firstMonomer = polymerBond.firstMonomer; this.polymerBonds.delete(polymerBond.id); + // const operationAddAttachmentPoints = + // new PolymerBondAddAttachmentPointsOperation( + // polymerBond, + // secondMonomer, + // firstMonomerAttachmentPoint, + // secondMonomerAttachmentPoint, + // ); + + // command.addOperation(operationAddAttachmentPoints); const operation = new PolymerBondFinishCreationOperation( this.finishPolymerBondCreationModelChange.bind( this, @@ -402,9 +399,7 @@ export class DrawingEntitiesManager { secondMonomer, firstMonomerAttachmentPoint, secondMonomerAttachmentPoint, - polymerBond.id, ), - this.deletePolymerBondChangeModel.bind(this), ); command.addOperation(operation); @@ -561,13 +556,16 @@ export class DrawingEntitiesManager { monomersToAdd.forEach(([monomerItem, monomerPosition]) => { const [Monomer] = monomerFactory(monomerItem); const monomer = new Monomer(monomerItem, monomerPosition); + this.monomers.set(monomer.id, monomer); let monomerAddOperation; if (previousMonomer) { - monomerAddOperation = new MonomerAddOperation( - this.addMonomerChangeModel.bind(this, monomerItem, monomerPosition), - this.deleteMonomerChangeModel.bind(this), - ); + const polymerBond = new PolymerBond(previousMonomer); + this.polymerBonds.set(polymerBond.id, polymerBond); + monomerAddOperation = new MonomerAddOperation(monomer, () => { + polymerBond.moveToLinkedMonomers(); + }); command.addOperation(monomerAddOperation); + polymerBond.setSecondMonomer(monomer); // requirements are: Base(R1)-(R3)Sugar(R2)-(R1)Phosphate const attPointStart = previousMonomer.getValidSourcePoint(monomer); @@ -576,22 +574,12 @@ export class DrawingEntitiesManager { assert(attPointStart); assert(attPointEnd); - const operation = new PolymerBondFinishCreationOperation( - this.finishPolymerBondCreationModelChange.bind( - this, - previousMonomer, - monomer, - attPointStart, - attPointEnd, - ), - this.deletePolymerBondChangeModel.bind(this), - ); + previousMonomer.setBond(attPointStart, polymerBond); + monomer.setBond(attPointEnd, polymerBond); + const operation = new PolymerBondAddOperation(polymerBond); command.addOperation(operation); } else { - monomerAddOperation = new MonomerAddOperation( - this.addMonomerChangeModel.bind(this, monomerItem, monomerPosition), - this.deleteMonomerChangeModel.bind(this), - ); + monomerAddOperation = new MonomerAddOperation(monomer); command.addOperation(monomerAddOperation); }