Skip to content

Commit

Permalink
Preview: Update Image object in KET file to support CDX/CDXML format (#…
Browse files Browse the repository at this point in the history
…5188)

* #5172 - updated ket image format

* #5172 - fixed failing types

* #5172 - fixed regex

* #5172 - fixed package-lock file

* #5172 - updated file mime regexp
  • Loading branch information
daniil-sloboda authored and Guch1g0v committed Oct 17, 2024
1 parent f22fc39 commit fb230c2
Show file tree
Hide file tree
Showing 41 changed files with 327 additions and 329 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/ketcher-core/src/application/editor/actions/erase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
AtomDelete,
BondDelete,
CalcImplicitH,
RasterImageDelete,
ImageDelete,
RGroupAttachmentPointRemove,
RxnArrowDelete,
RxnPlusDelete,
Expand All @@ -40,7 +40,7 @@ import { fromFragmentSplit } from './fragment';
import { fromRGroupAttachmentPointDeletion } from './rgroupAttachmentPoint';
import { ReStruct } from 'application/render';
import { isNumber } from 'lodash';
import { RASTER_IMAGE_KEY } from 'domain/constants';
import { IMAGE_KEY } from 'domain/constants';

export function fromOneAtomDeletion(restruct, atomId: number) {
return fromFragmentDeletion(restruct, { atoms: [atomId] });
Expand Down Expand Up @@ -218,8 +218,8 @@ export function fromFragmentDeletion(restruct, rawSelection) {
action.addOp(new TextDelete(id));
});

selection[RASTER_IMAGE_KEY].forEach((id) => {
action.addOp(new RasterImageDelete(id));
selection[IMAGE_KEY].forEach((id) => {
action.addOp(new ImageDelete(id));
});

const actionToDeleteRGroupAttachmentPoints = new Action();
Expand Down
10 changes: 5 additions & 5 deletions packages/ketcher-core/src/application/editor/actions/fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ import {
SGroupDataMove,
SimpleObjectMove,
TextMove,
RasterImageMove,
ImageMove,
} from '../operations';
import { Pile, RGroup, Vec2 } from 'domain/entities';
import { fromRGroupFragment, fromUpdateIfThen } from './rgroup';

import { Action } from './action';
import { fromAtomsFragmentAttr } from './atom';
import { getRelSGroupsBySelection } from './utils';
import { RASTER_IMAGE_KEY } from 'domain/constants';
import { IMAGE_KEY } from 'domain/constants';

export function fromMultipleMove(restruct, lists, d: Vec2) {
d = new Vec2(d);
Expand Down Expand Up @@ -129,9 +129,9 @@ export function fromMultipleMove(restruct, lists, d: Vec2) {
});
}

if (lists[RASTER_IMAGE_KEY]) {
lists[RASTER_IMAGE_KEY].forEach((rasterImage) => {
action.addOp(new RasterImageMove(rasterImage, d));
if (lists[IMAGE_KEY]) {
lists[IMAGE_KEY].forEach((image) => {
action.addOp(new ImageMove(image, d));
});
}

Expand Down
48 changes: 48 additions & 0 deletions packages/ketcher-core/src/application/editor/actions/image.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { ReStruct } from 'application/render';
import { ImageReferencePositionInfo, Vec2 } from 'domain/entities';
import {
Action,
ImageDelete,
ImageMove,
ImageResize,
ImageUpsert,
} from 'application/editor';
import { Image } from 'domain/entities/image';

export function fromImageCreation(
reStruct: ReStruct,
bitmap: string,
center: Vec2,
halfSize: Vec2,
) {
const action = new Action();
const image = new Image(bitmap, center, halfSize);
action.addOp(new ImageUpsert(image));
return action.perform(reStruct);
}

export function fromImageDeletion(reStruct: ReStruct, id: number) {
const action = new Action();
action.addOp(new ImageDelete(id));
return action.perform(reStruct);
}

export function fromImageMove(reStruct: ReStruct, id: number, offset: Vec2) {
const action = new Action();
action.addOp(new ImageMove(id, offset));
return action.perform(reStruct);
}

export function fromImageResize(
reStruct: ReStruct,
id: number,
position: Vec2,
referencePositionInfo: ImageReferencePositionInfo,
) {
const action = new Action();
const positionWithOffset = position.add(referencePositionInfo.offset);
action.addOp(
new ImageResize(id, positionWithOffset, referencePositionInfo.name),
);
return action.perform(reStruct);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export * from './closelyFusing';
export * from './erase';
export * from './fragment';
export * from './paste';
export * from './rasterImage';
export * from './image';
export * from './reaction';
export * from './rgroup';
export * from './rgroupAttachmentPoint';
Expand Down
12 changes: 6 additions & 6 deletions packages/ketcher-core/src/application/editor/actions/paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
FragmentSetProperties,
BondAttr,
AtomAttr,
RasterImageUpsert,
ImageUpsert,
} from '../operations';
import { fromRGroupAttrs, fromUpdateIfThen } from './rgroup';

Expand All @@ -37,7 +37,7 @@ import { SGroup, Struct, Vec2 } from 'domain/entities';
import { fromSgroupAddition } from './sgroup';
import { fromRGroupAttachmentPointAddition } from './rgroupAttachmentPoint';
import { MonomerMicromolecule } from 'domain/entities/monomerMicromolecule';
import { RasterImage } from 'domain/entities/rasterImage';
import { Image } from 'domain/entities/image';

export function fromPaste(
restruct,
Expand Down Expand Up @@ -190,11 +190,11 @@ export function fromPaste(
);
});

pstruct.rasterImages.forEach((rasterImage: RasterImage) => {
const clonedImage = rasterImage.clone();
pstruct.images.forEach((image: Image) => {
const clonedImage = image.clone();
clonedImage.addPositionOffset(offset);

action.addOp(new RasterImageUpsert(clonedImage).perform(restruct));
action.addOp(new ImageUpsert(clonedImage).perform(restruct));
});

pstruct.rgroups.forEach((rg, rgid) => {
Expand Down Expand Up @@ -247,7 +247,7 @@ function getStructCenter(struct: Struct): Vec2 {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
if (struct.texts.size > 0) return struct.texts.get(0)!.position;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
if (struct.rasterImages.size > 0) return struct.rasterImages.get(0)!.center();
if (struct.images.size > 0) return struct.images.get(0)!.center();

return new Vec2(0, 0);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ export const OperationType = Object.freeze({
DRAWING_ENTITY_SELECT: 'Select drawing entity',
DRAWING_ENTITY_HOVER: 'Hover drawing entity',
SHOW_POLYMER_BOND_INFORMATION: 'Show polymer bond information',
RASTER_IMAGE_UPSERT: 'Upsert raster image',
RASTER_IMAGE_DELETE: 'Delete raster image',
RASTER_IMAGE_MOVE: 'Move raster image',
RASTER_IMAGE_RESIZE: 'Resize raster image',
IMAGE_UPSERT: 'Upsert image',
IMAGE_DELETE: 'Delete image',
IMAGE_MOVE: 'Move image',
IMAGE_RESIZE: 'Resize image',
});

export enum OperationPriority {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { OperationType } from 'application/editor';
import { ReStruct } from 'application/render';
import { Scale } from 'domain/helpers';

export class RasterImageMove extends BaseOperation {
export class ImageMove extends BaseOperation {
constructor(private id: number, private offset: Vec2) {
super(OperationType.RASTER_IMAGE_MOVE);
super(OperationType.IMAGE_MOVE);
}

execute(reStruct: ReStruct) {
const renderItem = reStruct.rasterImages.get(this.id);
const item = reStruct.molecule.rasterImages.get(this.id);
const renderItem = reStruct.images.get(this.id);
const item = reStruct.molecule.images.get(this.id);

if (!item || !renderItem) {
return;
Expand All @@ -26,6 +26,6 @@ export class RasterImageMove extends BaseOperation {
}

invert(): BaseOperation {
return new RasterImageMove(this.id, this.offset.negated());
return new ImageMove(this.id, this.offset.negated());
}
}
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
import { BaseOperation } from 'application/editor/operations/base';
import { RasterImageReferenceName, Vec2 } from 'domain/entities';
import { ImageReferenceName, Vec2 } from 'domain/entities';
import { ReStruct } from 'application/render';
import { OperationType } from 'application/editor';

const moveLeftPositions: Array<RasterImageReferenceName> = [
const moveLeftPositions: Array<ImageReferenceName> = [
'topLeftPosition',
'leftMiddlePosition',
'bottomLeftPosition',
];

const moveRightPositions: Array<RasterImageReferenceName> = [
const moveRightPositions: Array<ImageReferenceName> = [
'topRightPosition',
'rightMiddlePosition',
'bottomRightPosition',
];

const moveTopPositions: Array<RasterImageReferenceName> = [
const moveTopPositions: Array<ImageReferenceName> = [
'topLeftPosition',
'topMiddlePosition',
'topRightPosition',
];

const moveBottomPositions: Array<RasterImageReferenceName> = [
const moveBottomPositions: Array<ImageReferenceName> = [
'bottomLeftPosition',
'bottomMiddlePosition',
'bottomRightPosition',
];

export class RasterImageResize extends BaseOperation {
export class ImageResize extends BaseOperation {
private previousPosition: Vec2 | null = null;
constructor(
private id: number,
private position: Vec2,
private referencePositionName: RasterImageReferenceName,
private referencePositionName: ImageReferenceName,
) {
super(OperationType.RASTER_IMAGE_RESIZE);
super(OperationType.IMAGE_RESIZE);
}

execute(reStruct: ReStruct) {
const item = reStruct.molecule.rasterImages.get(this.id);
const renderItem = reStruct.rasterImages.get(this.id);
const item = reStruct.molecule.images.get(this.id);
const renderItem = reStruct.images.get(this.id);

if (!item || !renderItem) {
return;
Expand Down Expand Up @@ -69,7 +69,7 @@ export class RasterImageResize extends BaseOperation {
}

invert(): BaseOperation {
return new RasterImageResize(
return new ImageResize(
this.id,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.previousPosition!,
Expand Down
Loading

0 comments on commit fb230c2

Please sign in to comment.