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

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

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 @@ -239,7 +239,7 @@ export abstract class BaseMode {
return;
}

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

Expand Down Expand Up @@ -277,24 +277,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 @@ -24,6 +24,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 @@ -162,8 +162,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 @@ -1762,14 +1762,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