From 66337a032d668d8b2cd21ec62219ec0e55eb9e98 Mon Sep 17 00:00:00 2001 From: Sasha Graves Date: Mon, 13 Nov 2023 11:03:18 +0100 Subject: [PATCH] Revert "add-delete bond: undo redo (with issues)" This reverts commit 93959e93a4dd19c23746f4d82de39554816eda8e. --- .../editor/operations/polymerBond/index.ts | 47 ++----- .../domain/entities/DrawingEntitiesManager.ts | 132 +++--------------- 2 files changed, 28 insertions(+), 151 deletions(-) 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..1d8d5afd88 100644 --- a/packages/ketcher-core/src/application/editor/operations/polymerBond/index.ts +++ b/packages/ketcher-core/src/application/editor/operations/polymerBond/index.ts @@ -14,103 +14,78 @@ * limitations under the License. ***************************************************************************/ /* eslint-disable @typescript-eslint/no-use-before-define */ -// eslint-disable no-unused-vars -/* eslint-disable @typescript-eslint/no-unused-vars */ import { PolymerBond } from 'domain/entities/PolymerBond'; import { RenderersManager } from 'application/render/renderers/RenderersManager'; import { Operation } from 'domain/entities/Operation'; import assert from 'assert'; -import { Command } from 'domain/entities/Command'; export class PolymerBondAddOperation implements Operation { - public polymerBond; - constructor( - private addPolymerBondChangeModel: () => PolymerBond, - private deletePolymerBondChangeModel: (polymerBond) => void, - ) { - this.polymerBond = this.addPolymerBondChangeModel(); - } + constructor(private polymerBond: PolymerBond) {} public execute(renderersManager: RenderersManager) { renderersManager.addPolymerBond(this.polymerBond); } public invert(renderersManager: RenderersManager) { - this.deletePolymerBondChangeModel(this.polymerBond); - renderersManager.deletePolymerBond(this.polymerBond); console.log('invert PolymerBondAddOperation'); } } export class PolymerBondDeleteOperation implements Operation { - constructor( - public polymerBond: PolymerBond, - private deletePolymerBondChangeModel: () => void, - private addPolymerBondChangeModel: (polymerBondExists) => PolymerBond, - private finishPolymerBondCreationModelChange: () => PolymerBond, - ) {} + constructor(private polymerBond: PolymerBond) {} public execute(renderersManager: RenderersManager) { - this.deletePolymerBondChangeModel(); renderersManager.deletePolymerBond(this.polymerBond); console.log('execute PolymerBondDeleteOperation'); } 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); } } export class PolymerBondMoveOperation implements Operation { - constructor(public polymerBond: PolymerBond) {} + constructor(private polymerBond: PolymerBond) {} public execute(renderersManager: RenderersManager) { renderersManager.movePolymerBond(this.polymerBond); } - public invert(_renderersManager: RenderersManager) { + public invert(renderersManager: RenderersManager) { console.log('invert PolymerBondMoveOperation'); } } export class PolymerBondShowInfoOperation implements Operation { - constructor(public polymerBond: PolymerBond) {} + constructor(private polymerBond: PolymerBond) {} public execute(renderersManager: RenderersManager) { renderersManager.showPolymerBondInformation(this.polymerBond); } - public invert(_renderersManager: RenderersManager) { + public invert(renderersManager: RenderersManager) { console.log('invert PolymerBondShowInfoOperation'); } } export class PolymerBondCancelCreationOperation implements Operation { - constructor(public polymerBond: PolymerBond) {} + constructor(private polymerBond: PolymerBond) {} public execute(renderersManager: RenderersManager) { renderersManager.cancelPolymerBondCreation(this.polymerBond); } - public invert(_renderersManager: RenderersManager) { + public invert(renderersManager: RenderersManager) { console.log('invert PolymerBondCancelCreationOperation'); } } export class PolymerBondFinishCreationOperation implements Operation { - public polymerBond; - constructor( - private finishPolymerBondCreationModelChange: () => PolymerBond, - ) {} + constructor(private polymerBond: PolymerBond) {} public execute(renderersManager: RenderersManager) { - this.polymerBond = this.finishPolymerBondCreationModelChange(); renderersManager.finishPolymerBondCreation(this.polymerBond); console.log('execute PolymerBondFinishCreationOperation'); } @@ -123,7 +98,7 @@ export class PolymerBondFinishCreationOperation implements Operation { export class PolymerBondAddAttachmentPointsOperation implements Operation { constructor( - public polymerBond: PolymerBond, + private polymerBond: PolymerBond, private secondMonomer, private firstMonomerAttachmentPoint, private secondMonomerAttachmentPoint, @@ -172,7 +147,7 @@ export class PolymerBondCleanAttachmentPointsOperation implements Operation { private firstMonomerAttachmentPoint; private secondMonomerAttachmentPoint; - constructor(public polymerBond: PolymerBond) { + constructor(private polymerBond: PolymerBond) { this.polymerBond = polymerBond; } diff --git a/packages/ketcher-core/src/domain/entities/DrawingEntitiesManager.ts b/packages/ketcher-core/src/domain/entities/DrawingEntitiesManager.ts index 745714c552..1719a5c95e 100644 --- a/packages/ketcher-core/src/domain/entities/DrawingEntitiesManager.ts +++ b/packages/ketcher-core/src/domain/entities/DrawingEntitiesManager.ts @@ -87,20 +87,14 @@ export class DrawingEntitiesManager { return mergedCommand; } - public addMonomerChangeModel(monomerItem: MonomerItemType, position: Vec2) { + public addMonomer(monomerItem: MonomerItemType, position: Vec2) { const [Monomer] = monomerFactory(monomerItem); const monomer = new Monomer(monomerItem, position); monomer.moveAbsolute(position); this.monomers.set(monomer.id, monomer); - return monomer; - } - public addMonomer(monomerItem: MonomerItemType, position: Vec2) { const command = new Command(); - const operation = new MonomerAddOperation( - this.addMonomerChangeModel.bind(this, monomerItem, position), - this.deleteMonomerChangeModel.bind(this), - ); + const operation = new MonomerAddOperation(monomer); command.addOperation(operation); @@ -190,21 +184,10 @@ export class DrawingEntitiesManager { return command; } - private deleteMonomerChangeModel(monomer: BaseMonomer) { - this.monomers.delete(monomer.id); - } - public deleteMonomer(monomer: BaseMonomer) { + this.monomers.delete(monomer.id); const command = new Command(); - const operation = new MonomerDeleteOperation( - monomer, - this.addMonomerChangeModel.bind( - this, - monomer.monomerItem, - monomer.position, - ), - this.deleteMonomerChangeModel.bind(this), - ); + const operation = new MonomerDeleteOperation(monomer); command.addOperation(operation); if (monomer.hasBonds) { @@ -248,74 +231,31 @@ export class DrawingEntitiesManager { return command; } - public addPolymerBondChangeModel( - firstMonomer, - startPosition, - endPosition, - polymerBondExists?: PolymerBond, - ) { - let polymerBond = new PolymerBond(firstMonomer); - if (polymerBondExists) { - polymerBond = polymerBondExists; - } + public addPolymerBond(firstMonomer, startPosition, endPosition) { + const polymerBond = new PolymerBond(firstMonomer); this.polymerBonds.set(polymerBond.id, polymerBond); const attachmentPoint = firstMonomer.getValidSourcePoint(); firstMonomer.setPotentialBond(attachmentPoint, polymerBond); polymerBond.moveBondStartAbsolute(startPosition.x, startPosition.y); polymerBond.moveBondEndAbsolute(endPosition.x, endPosition.y); - return polymerBond; - } - public addPolymerBond(firstMonomer, startPosition, endPosition) { const command = new Command(); - - const operation = new PolymerBondAddOperation( - this.addPolymerBondChangeModel.bind( - this, - firstMonomer, - startPosition, - endPosition, - ), - this.deletePolymerBondChangeModel.bind(this), - ); + const operation = new PolymerBondAddOperation(polymerBond); command.addOperation(operation); - return { command, polymerBond: operation.polymerBond }; - } - - public deletePolymerBondChangeModel(polymerBond: PolymerBond) { - this.polymerBonds.delete(polymerBond.id); + return { command, polymerBond }; } public deletePolymerBond(polymerBond: PolymerBond) { + this.polymerBonds.delete(polymerBond.id); const command = new Command(); const operationCleanAttachmentPoints = new PolymerBondCleanAttachmentPointsOperation(polymerBond); command.addOperation(operationCleanAttachmentPoints); - 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, - polymerBond.secondMonomer as BaseMonomer, - polymerBond.firstMonomer.getAttachmentPointByBond( - polymerBond, - ) as string, - polymerBond.secondMonomer?.getAttachmentPointByBond( - polymerBond, - ) as string, - ), - ); + const operation = new PolymerBondDeleteOperation(polymerBond); command.addOperation(operation); return command; @@ -345,34 +285,6 @@ export class DrawingEntitiesManager { return command; } - public finishPolymerBondCreationModelChange( - firstMonomer: BaseMonomer, - secondMonomer: BaseMonomer, - firstMonomerAttachmentPoint: string, - secondMonomerAttachmentPoint: string, - ) { - const polymerBond = new PolymerBond(firstMonomer); - polymerBond.setSecondMonomer(secondMonomer); - polymerBond.firstMonomer.setBond(firstMonomerAttachmentPoint, polymerBond); - assert(polymerBond.secondMonomer); - assert(secondMonomer.renderer); - polymerBond.secondMonomer.setBond( - secondMonomerAttachmentPoint, - polymerBond, - ); - polymerBond.firstMonomer.removePotentialBonds(); - polymerBond.secondMonomer.removePotentialBonds(); - polymerBond.moveToLinkedMonomers(); - polymerBond.firstMonomer.turnOffSelection(); - polymerBond.firstMonomer.turnOffHover(); - polymerBond.firstMonomer.turnOffAttachmentPointsVisibility(); - polymerBond.secondMonomer.turnOffSelection(); - polymerBond.secondMonomer.turnOffHover(); - polymerBond.secondMonomer.turnOffAttachmentPointsVisibility(); - polymerBond.turnOffHover(); - return polymerBond; - } - public finishPolymerBondCreation( polymerBond: PolymerBond, secondMonomer: BaseMonomer, @@ -381,26 +293,16 @@ export class DrawingEntitiesManager { ) { const command = new Command(); - 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, - firstMonomer, + const operationAddAttachmentPoints = + new PolymerBondAddAttachmentPointsOperation( + polymerBond, secondMonomer, firstMonomerAttachmentPoint, secondMonomerAttachmentPoint, - ), - ); + ); + + command.addOperation(operationAddAttachmentPoints); + const operation = new PolymerBondFinishCreationOperation(polymerBond); command.addOperation(operation);