Skip to content

Commit

Permalink
Revert "fix finishBondCreation"
Browse files Browse the repository at this point in the history
This reverts commit 54b3669.
  • Loading branch information
SashaGraves committed Nov 13, 2023
1 parent 267c9e8 commit 6d49cf3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class PolymerBondDeleteOperation implements Operation {
constructor(
public polymerBond: PolymerBond,
private deletePolymerBondChangeModel: () => void,
private addPolymerBondChangeModel: (polymerBondExists) => PolymerBond,
private finishPolymerBondCreationModelChange: () => PolymerBond,
) {}

Expand All @@ -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);
Expand Down Expand Up @@ -105,7 +107,6 @@ export class PolymerBondFinishCreationOperation implements Operation {
public polymerBond;
constructor(
private finishPolymerBondCreationModelChange: () => PolymerBond,
private deletePolymerBondCreationModelChange: (polymerBond) => void,
) {}

public execute(renderersManager: RenderersManager) {
Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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) {
Expand All @@ -55,7 +53,6 @@ class RnaPresetTool implements Tool {
if (preset?.sugar) {
this.sugar = preset?.sugar;
}
this.history = new EditorHistory(this.editor); // здесь история пишется
}

mousedown() {
Expand Down Expand Up @@ -96,7 +93,6 @@ class RnaPresetTool implements Tool {
: undefined,
});

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
68 changes: 28 additions & 40 deletions packages/ketcher-core/src/domain/entities/DrawingEntitiesManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -395,16 +383,23 @@ 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,
firstMonomer,
secondMonomer,
firstMonomerAttachmentPoint,
secondMonomerAttachmentPoint,
polymerBond.id,
),
this.deletePolymerBondChangeModel.bind(this),
);

command.addOperation(operation);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down

0 comments on commit 6d49cf3

Please sign in to comment.