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

#5761 - updated minimal ket validation distance #5779

Merged
merged 1 commit into from
Oct 22, 2024
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
40 changes: 40 additions & 0 deletions DEVNOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,43 @@ docker-compose up -d
```

Service with Ketcher will be run under localhost:8080/ketcher.html

## Custom Buttons

Custom buttons enable developers who embed Ketcher into their applications to extend its functionality by implementing custom workflows using existing Ketcher APIs. To add custom buttons to the Ketcher top toolbar, follow these steps:

1. **Provide an Array of Custom Buttons to the Editor Component**

Pass an array of custom buttons to the `<Editor>` component using the `customButtons` prop:

```jsx
<Editor customButtons={array_of_custom_buttons_here} />
```

Each custom button should follow this schema:

```ts
{
id: string, // unique identifier of the button
title: string, // optional button tooltip
imageLink: string // absolute link to the image icon
}
```

Once added, all the buttons will appear on the top toolbar.

2. **Subscribe to the `'CUSTOM_BUTTON_PRESSED'` Event on the Ketcher Bus**

Subscribe to the event using the following code:

```js
ketcher.eventBus.on('CUSTOM_BUTTON_PRESSED', (id: string) => {
// Your custom logic here
});
```

This function receives a single parameter, `id`, which is the identifier of the pressed button. The function is invoked each time a user presses one of the custom buttons. It is up to the developer to use Ketcher APIs to implement the custom workflow logic.

### Limitations

Currently, custom buttons have a slightly different visual appearance compared to native buttons. Since images are used via links, it is not possible to change the color of the icons based on user actions like hovering.
Original file line number Diff line number Diff line change
Expand Up @@ -307,32 +307,36 @@ test.describe('Multi-Tailed Arrow Tool', () => {
detailedDescription: `Multi-Tailed Arrow with different x-coordinates of spine can't be added from KET file to Canvas and error message
is displayed - "Cannot deserialize input JSON."`,
},
{
// TODO
/* {
description:
'Multi-Tailed Arrow with head less than 0.5 cannot be added from KET file to Canvas',
'Multi-Tailed Arrow with head less than 0.5 cannot be added from KET file to Canvas - no longer applicable since 0.01 is the new limit',
file: 'KET/multi-tailed-arrow-invalid-head-0.49.ket',
detailedDescription: `Multi-Tailed Arrow with head less than 0.5 can't be added from KET file to Canvas and error message is displayed - "Cannot deserialize input JSON."`,
},
{
}, */
// TODO
/* {
description:
'Multi-Tailed Arrow with head positioned less than 0.15 to top tail cannot be added from KET file',
'Multi-Tailed Arrow with head positioned less than 0.15 to top tail cannot be added from KET file - no longer applicable since 0.01 is the new limit',
file: 'KET/multi-tailed-arrow-invalid-head-position-0.14.ket',
detailedDescription: `Multi-Tailed Arrow with head is positioned less than 0.15 to top tail can't be added from KET file to Canvas and error message
is displayed - "Cannot deserialize input JSON."`,
},
{
}, */
// TODO
/* {
description:
'Multi-Tailed Arrow with tail less than 0.4 cannot be added from KET file to Canvas',
'Multi-Tailed Arrow with tail less than 0.4 cannot be added from KET file to Canvas - no longer applicable since 0.01 is the new limit',
file: 'KET/multi-tailed-arrow-invalid-tails-0.39.ket',
detailedDescription: `Multi-Tailed Arrow with tail less than 0.4 can't be added from KET file to Canvas and error message is displayed - "Cannot deserialize input JSON."`,
},
{
}, */
// TODO
/* {
description:
'Multi-Tailed Arrow with tail distance less than 0.35 cannot be added from KET file to Canvas',
'Multi-Tailed Arrow with tail distance less than 0.35 cannot be added from KET file to Canvas - no longer applicable since 0.01 is the new limit',
file: 'KET/multi-tailed-arrow-invalid-tails-distance.ket',
detailedDescription: `Multi-Tailed Arrow with tail distance less than 0.35 can't be added from KET file to Canvas and error message
is displayed - "Cannot deserialize input JSON."`,
},
}, */
{
description:
'Multi-Tailed Arrow with different lengths of tails cannot be added from KET file to Canvas',
Expand Down
15 changes: 9 additions & 6 deletions packages/ketcher-core/src/domain/entities/multitailArrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ interface TailDistance {
}

export class MultitailArrow extends BaseMicromoleculeEntity {
static KET_MIN_DISTANCE =
FixedPrecisionCoordinates.fromFloatingPrecision(0.01);

static MIN_TAIL_DISTANCE =
FixedPrecisionCoordinates.fromFloatingPrecision(0.35);

Expand Down Expand Up @@ -145,14 +148,14 @@ export class MultitailArrow extends BaseMicromoleculeEntity {

if (
spineStartX.value !== spineEndX.value ||
spineStartY.value < spineEndY.sub(MultitailArrow.MIN_HEIGHT).value
spineStartY.value < spineEndY.sub(MultitailArrow.KET_MIN_DISTANCE).value
) {
return MultitailValidationErrors.INCORRECT_SPINE;
}
if (
headX.value < spineStartX.add(MultitailArrow.MIN_HEAD_LENGTH).value ||
headY.sub(MultitailArrow.MIN_TOP_BOTTOM_OFFSET).value < spineEndY.value ||
headY.add(MultitailArrow.MIN_TOP_BOTTOM_OFFSET).value > spineStartY.value
headX.value < spineStartX.add(MultitailArrow.KET_MIN_DISTANCE).value ||
headY.sub(MultitailArrow.KET_MIN_DISTANCE).value < spineEndY.value ||
headY.add(MultitailArrow.KET_MIN_DISTANCE).value > spineStartY.value
) {
return MultitailValidationErrors.INCORRECT_HEAD;
}
Expand All @@ -165,7 +168,7 @@ export class MultitailArrow extends BaseMicromoleculeEntity {

const firstTailX = tailsFixedPrecision[0].x;
if (
firstTailX.value > spineStartX.sub(MultitailArrow.MIN_TAIL_LENGTH).value
firstTailX.value > spineStartX.sub(MultitailArrow.KET_MIN_DISTANCE).value
) {
return MultitailValidationErrors.INCORRECT_TAILS;
}
Expand All @@ -174,7 +177,7 @@ export class MultitailArrow extends BaseMicromoleculeEntity {
if (
index > 0 &&
allTails[index - 1].y.value <
tail.y.add(MultitailArrow.MIN_TAIL_DISTANCE).value
tail.y.add(MultitailArrow.KET_MIN_DISTANCE).value
) {
return false;
}
Expand Down
Loading