Skip to content

Commit

Permalink
Revert "add-delete bond: undo redo (with issues)"
Browse files Browse the repository at this point in the history
This reverts commit 93959e9.
  • Loading branch information
SashaGraves committed Nov 13, 2023
1 parent 6d49cf3 commit 66337a0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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,
Expand Down Expand Up @@ -172,7 +147,7 @@ export class PolymerBondCleanAttachmentPointsOperation implements Operation {
private firstMonomerAttachmentPoint;
private secondMonomerAttachmentPoint;

constructor(public polymerBond: PolymerBond) {
constructor(private polymerBond: PolymerBond) {
this.polymerBond = polymerBond;
}

Expand Down
132 changes: 17 additions & 115 deletions packages/ketcher-core/src/domain/entities/DrawingEntitiesManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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);

Expand Down

0 comments on commit 66337a0

Please sign in to comment.