Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backmerge: #5886 - Loading a KET file in macro mode, bond connections are preserved but microstructures are shifted #5919

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading