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 2b97f1f0a5..059711b74b 100644 --- a/packages/ketcher-core/src/application/editor/operations/polymerBond/index.ts +++ b/packages/ketcher-core/src/application/editor/operations/polymerBond/index.ts @@ -47,7 +47,6 @@ export class PolymerBondDeleteOperation implements Operation { constructor( public polymerBond: PolymerBond, private deletePolymerBondChangeModel: () => void, - private addPolymerBondChangeModel: (polymerBondExists) => PolymerBond, private finishPolymerBondCreationModelChange: () => PolymerBond, ) {} @@ -60,7 +59,6 @@ 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); @@ -107,6 +105,7 @@ export class PolymerBondFinishCreationOperation implements Operation { public polymerBond; constructor( private finishPolymerBondCreationModelChange: () => PolymerBond, + private deletePolymerBondCreationModelChange: (polymerBond) => void, ) {} public execute(renderersManager: RenderersManager) { @@ -117,6 +116,7 @@ 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 b60b7565d1..f5d32ea485 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 } from 'application/editor'; +import { CoreEditor, EditorHistory } from 'application/editor'; import { BaseMonomerRenderer } from 'application/render/renderers'; import { MonomerItemType } from 'domain/types'; import { monomerFactory } from '../operations/monomer/monomerFactory'; @@ -42,6 +42,8 @@ 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) { @@ -53,6 +55,7 @@ class RnaPresetTool implements Tool { if (preset?.sugar) { this.sugar = preset?.sugar; } + this.history = new EditorHistory(this.editor); // здесь история пишется } mousedown() { @@ -93,6 +96,7 @@ 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 71a564509c..bb8329a77b 100644 --- a/packages/ketcher-core/src/application/render/renderers/RenderersManager.ts +++ b/packages/ketcher-core/src/application/render/renderers/RenderersManager.ts @@ -94,6 +94,10 @@ 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 3204b460c5..028de483b1 100644 --- a/packages/ketcher-core/src/domain/entities/DrawingEntitiesManager.ts +++ b/packages/ketcher-core/src/domain/entities/DrawingEntitiesManager.ts @@ -27,7 +27,6 @@ import { PolymerBondMoveOperation, PolymerBondShowInfoOperation, PolymerBondCleanAttachmentPointsOperation, - PolymerBondAddAttachmentPointsOperation, } from 'application/editor/operations/polymerBond'; import { monomerFactory } from 'application/editor/operations/monomer/monomerFactory'; import { provideEditorSettings } from 'application/editor/editorSettings'; @@ -290,6 +289,21 @@ 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) { @@ -302,12 +316,6 @@ 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, @@ -354,12 +362,16 @@ 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, @@ -387,15 +399,6 @@ 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, @@ -403,7 +406,9 @@ export class DrawingEntitiesManager { secondMonomer, firstMonomerAttachmentPoint, secondMonomerAttachmentPoint, + polymerBond.id, ), + this.deletePolymerBondChangeModel.bind(this), ); command.addOperation(operation); @@ -579,16 +584,13 @@ 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) { - const polymerBond = new PolymerBond(previousMonomer); - this.polymerBonds.set(polymerBond.id, polymerBond); - monomerAddOperation = new MonomerAddOperation(monomer, () => { - polymerBond.moveToLinkedMonomers(); - }); + monomerAddOperation = new MonomerAddOperation( + this.addMonomerChangeModel.bind(this, monomerItem, monomerPosition), + this.deleteMonomerChangeModel.bind(this), + ); command.addOperation(monomerAddOperation); - polymerBond.setSecondMonomer(monomer); // requirements are: Base(R1)-(R3)Sugar(R1)-(R2)Phosphate const attPointStart = previousMonomer.R1AttachmentPoint; @@ -603,12 +605,22 @@ export class DrawingEntitiesManager { assert(attPointStart); assert(attPointEnd); - previousMonomer.setBond(attPointStart, polymerBond); - monomer.setBond(attPointEnd, polymerBond); - const operation = new PolymerBondAddOperation(polymerBond); + const operation = new PolymerBondFinishCreationOperation( + this.finishPolymerBondCreationModelChange.bind( + this, + previousMonomer, + monomer, + attPointStart, + attPointEnd, + ), + this.deletePolymerBondChangeModel.bind(this), + ); command.addOperation(operation); } else { - monomerAddOperation = new MonomerAddOperation(monomer); + monomerAddOperation = new MonomerAddOperation( + this.addMonomerChangeModel.bind(this, monomerItem, monomerPosition), + this.deleteMonomerChangeModel.bind(this), + ); command.addOperation(monomerAddOperation); }