Skip to content

Commit

Permalink
#5659 - Moving of selected microstructures on macro canvas works wrong (
Browse files Browse the repository at this point in the history
#5769) (#5820)

- removed hidden chems created for molecules in model from selection
- fixed performance by collecting moving
  • Loading branch information
rrodionov91 authored Oct 21, 2024
1 parent a1679c7 commit ba82bf0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class EditorHistory {

const lastCommand = this.historyStack[this.historyPointer];
lastCommand.execute(this.editor.renderersContainer);
lastCommand.executeAfterAllOperations(this.editor.renderersContainer);
this.historyPointer++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ export class DrawingEntityMoveOperation implements Operation {
private drawingEntity: DrawingEntity,
) {}

public execute(renderersManager: RenderersManager) {
public execute() {
this.wasInverted
? this.redoDrawingEntityChangeModel()
: this.moveDrawingEntityChangeModel();
}

public invert(renderersManager: RenderersManager) {
this.invertMoveDrawingEntityChangeModel();

if (
this.drawingEntity instanceof PolymerBond ||
this.drawingEntity instanceof MonomerToAtomBond
Expand All @@ -43,11 +48,11 @@ export class DrawingEntityMoveOperation implements Operation {
} else {
renderersManager.moveDrawingEntity(this.drawingEntity);
}
}

public invert(renderersManager: RenderersManager) {
this.invertMoveDrawingEntityChangeModel();
this.wasInverted = true;
}

public executeAfterAllOperations(renderersManager: RenderersManager) {
// Redraw Polymer bonds instead of moving needed here because
// they have two drawing modes: straight and curved.
// During switching snake/flex layout modes and undo/redo
Expand All @@ -60,10 +65,9 @@ export class DrawingEntityMoveOperation implements Operation {
} else {
renderersManager.moveDrawingEntity(this.drawingEntity);
}

this.wasInverted = true;
}
}

export class DrawingEntityRedrawOperation implements Operation {
constructor(
private drawingEntityRedrawModelChange: () => DrawingEntity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,13 @@ export class RenderersManager {
}

public update(modelChanges?: Command) {
const editor = CoreEditor.provideEditorInstance();
const viewModel = editor.viewModel;

modelChanges?.execute(this);
viewModel.initialize([...editor.drawingEntitiesManager.bonds.values()]);
modelChanges?.executeAfterAllOperations(this);

this.runPostRenderMethods();
notifyRenderComplete();
}
Expand Down
8 changes: 8 additions & 0 deletions packages/ketcher-core/src/domain/entities/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ export class Command {
renderersManagers.runPostRenderMethods();
}

public executeAfterAllOperations(renderersManagers: RenderersManager) {
this.operations.forEach((operation) => {
if (operation.executeAfterAllOperations) {
operation.executeAfterAllOperations(renderersManagers);
}
});
}

public clear() {
this.operations = [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,7 @@ export class DrawingEntitiesManager {
if (drawingEntity instanceof PolymerBond) {
drawingEntity.moveToLinkedMonomers();
} else if (drawingEntity instanceof Bond) {
const editor = CoreEditor.provideEditorInstance();
const viewModel = editor.viewModel;

drawingEntity.moveToLinkedAtoms();
viewModel.initialize([...this.bonds.values()]);
} else if (drawingEntity instanceof MonomerToAtomBond) {
drawingEntity.moveToLinkedMonomerAndAtom();
} else {
Expand Down Expand Up @@ -389,6 +385,14 @@ export class DrawingEntitiesManager {

[...this.atoms.values(), ...this.monomers.values()].forEach(
(drawingEntity) => {
if (
drawingEntity instanceof BaseMonomer &&
drawingEntity.monomerItem.props.isMicromoleculeFragment &&
!isMonomerSgroupWithAttachmentPoints(drawingEntity)
) {
return;
}

if (drawingEntity.selected) {
command.merge(
this.createDrawingEntityMovingCommand(
Expand Down
1 change: 1 addition & 0 deletions packages/ketcher-core/src/domain/entities/Operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export interface Operation {
polymerBond?: PolymerBond;
execute(renderersManager: RenderersManager): void;
invert(renderersManager: RenderersManager): void;
executeAfterAllOperations?(renderersManager: RenderersManager): void;
}

0 comments on commit ba82bf0

Please sign in to comment.