Skip to content

Commit

Permalink
Backmerge: #5886 - Loading a KET file in macro mode, bond connections…
Browse files Browse the repository at this point in the history
… are preserved but microstructures are shifted (#5919)

- added repositioning for all entities during paste/open structures
- updated screenshots
  • Loading branch information
rrodionov91 authored Nov 6, 2024
1 parent 5fe4ef3 commit 5a281ac
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 26 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 11 additions & 16 deletions packages/ketcher-core/src/application/editor/modes/BaseMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export abstract class BaseMode {
return;
}

this.updateMonomersPosition(drawingEntitiesManager);
this.updateEntitiesPosition(drawingEntitiesManager);
const { command: modelChanges, mergedDrawingEntities } =
drawingEntitiesManager.mergeInto(editor.drawingEntitiesManager);

Expand Down Expand Up @@ -303,24 +303,19 @@ export abstract class BaseMode {
}
}

private updateMonomersPosition(
private updateEntitiesPosition(
drawingEntitiesManager: DrawingEntitiesManager,
) {
let offset: Vec2;
let index = 0;
const newNodePosition = this.getNewNodePosition();
drawingEntitiesManager.monomers.forEach((monomer) => {
let position;
if (index === 0) {
offset = Vec2.diff(newNodePosition, new Vec2(monomer.position));
position = newNodePosition;
} else {
position = offset
? new Vec2(monomer.position).add(offset)
: new Vec2(monomer.position);
}
drawingEntitiesManager.moveMonomer(monomer, position);
index++;
const firstEntityPosition =
drawingEntitiesManager.allEntities[0]?.[1].position;
const offset = Vec2.diff(newNodePosition, new Vec2(firstEntityPosition));

drawingEntitiesManager.allEntities.forEach(([, drawindEntity]) => {
drawingEntitiesManager.moveDrawingEntityModelChange(
drawindEntity,
offset,
);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class FlexMode extends BaseMode {

getNewNodePosition() {
const editor = CoreEditor.provideEditorInstance();

return Coordinates.canvasToModel(editor.lastCursorPositionOfCanvas);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ export class DrawingEntitiesManager {

public get allBondsToMonomers() {
return [
...(this.polymerBonds as Map<number, DrawingEntity>),
...(this.monomerToAtomBonds as Map<number, DrawingEntity>),
...(this.polymerBonds as Map<number, PolymerBond>),
...(this.monomerToAtomBonds as Map<number, MonomerToAtomBond>),
];
}

Expand Down Expand Up @@ -1808,14 +1808,9 @@ export class DrawingEntitiesManager {
);
const structCenter = this.getMacroStructureCenter();
const offset = Vec2.diff(centerPointOfModel, structCenter);
this.monomers.forEach((monomer: BaseMonomer) => {
this.moveMonomer(monomer, new Vec2(monomer.position).add(offset));
});
this.polymerBonds.forEach((bond: PolymerBond) => {
const { x: startX, y: startY } = new Vec2(bond.position).add(offset);
bond.moveBondStartAbsolute(startX, startY);
const { x: endX, y: endY } = new Vec2(bond.endPosition).add(offset);
bond.moveBondEndAbsolute(endX, endY);

this.allEntities.forEach(([, entity]) => {
this.moveDrawingEntityModelChange(entity, offset);
});
}

Expand Down

0 comments on commit 5a281ac

Please sign in to comment.