Skip to content

Commit

Permalink
#85 move circle to ellipse
Browse files Browse the repository at this point in the history
  • Loading branch information
ensemenova committed Feb 8, 2021
1 parent 708a370 commit bdf87dc
Show file tree
Hide file tree
Showing 20 changed files with 757 additions and 293 deletions.
3 changes: 0 additions & 3 deletions packages/ketcher-react/src/icons/files/shape-circle.svg

This file was deleted.

3 changes: 3 additions & 0 deletions packages/ketcher-react/src/icons/files/shape-ellipse.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions packages/ketcher-react/src/icons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import TransformRotateIcon from './files/transform-rotate.svg'
import UndoIcon from './files/undo.svg'
import ZoomInIcon from './files/zoom-in.svg'
import ZoomOutIcon from './files/zoom-out.svg'
import ShapeCircleIcon from './files/shape-circle.svg'
import ShapeEllipseIcon from './files/shape-ellipse.svg'
import ShapeRectangleIcon from './files/shape-rectangle.svg'
import ShapePolylineIcon from './files/shape-polyline.svg'
import ShapeLineIcon from './files/shape-line.svg'
Expand Down Expand Up @@ -157,7 +157,7 @@ const icons = {
undo: UndoIcon,
'zoom-in': ZoomInIcon,
'zoom-out': ZoomOutIcon,
'shape-circle': ShapeCircleIcon,
'shape-ellipse': ShapeEllipseIcon,
'shape-rectangle': ShapeRectangleIcon,
'shape-polyline': ShapePolylineIcon,
'shape-line': ShapeLineIcon
Expand Down
29 changes: 3 additions & 26 deletions packages/ketcher-react/src/script/chem/struct/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Fragment from './fragment'
import SGroup from './sgroup'
import RGroup from './rgroup'
import SGroupForest from './sgforest'
import { SimpleObject, SimpleObjectMode } from './simpleObject'

function Struct() {
this.atoms = new Pool()
Expand Down Expand Up @@ -1042,31 +1043,6 @@ RxnPlus.prototype.clone = function () {
return new RxnPlus(this)
}

function SimpleObject(params) {
params = params || {}
this.pos = []

if (params.pos)
for (let i = 0; i < params.pos.length; i++)
this.pos[i] = params.pos[i] ? new Vec2(params.pos[i]) : new Vec2()

this.mode = params.mode
}

SimpleObject.prototype.clone = function () {
return new SimpleObject(this)
}

SimpleObject.prototype.center = function () {
switch (this.mode) {
case 'rectangle': {
return Vec2.centre(this.pos[0], this.pos[1])
}
default:
return this.pos[0]
}
}

function RxnArrow(params) {
params = params || {}
this.pp = params.pp ? new Vec2(params.pp) : new Vec2()
Expand Down Expand Up @@ -1095,5 +1071,6 @@ export {
RGroup,
RxnPlus,
RxnArrow,
SimpleObject
SimpleObject,
SimpleObjectMode
}
53 changes: 53 additions & 0 deletions packages/ketcher-react/src/script/chem/struct/simpleObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/****************************************************************************
* Copyright 2021 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
import Vec2 from '../../util/vec2'

class SimpleObject {
pos: Array<Vec2>
mode: SimpleObjectMode

constructor(params: { mode: SimpleObjectMode; pos?: Array<Vec2> }) {
params = params || {}
this.pos = []

if (params.pos)
for (let i = 0; i < params.pos.length; i++)
this.pos[i] = params.pos[i] ? new Vec2(params.pos[i]) : new Vec2()

this.mode = params.mode
}

clone(): SimpleObject {
return new SimpleObject(this)
}

center(): Vec2 {
switch (this.mode) {
case SimpleObjectMode.rectangle: {
return Vec2.centre(this.pos[0], this.pos[1])
}
default:
return this.pos[0]
}
}
}

enum SimpleObjectMode {
ellipse = 'ellipse',
rectangle = 'rectangle',
line = 'line'
}
export { SimpleObject, SimpleObjectMode }
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,23 @@ export function fromSimpleObjectDeletion(restruct, id) {
return action.perform(restruct)
}

export function fromSimpleObjectAddition(restruct, pos, mode) {
export function fromSimpleObjectAddition(restruct, pos, mode, toCircle) {
var action = new Action()
action.addOp(new op.SimpleObjectAdd(pos, mode))
action.addOp(new op.SimpleObjectAdd(pos, mode, toCircle))
return action.perform(restruct)
}

export function fromSimpleObjectResizing(restruct, id, d, current, anchor) {
export function fromSimpleObjectResizing(
restruct,
id,
d,
current,
anchor,
toCircle
) {
var action = new Action()
action.addOp(new op.SimpleObjectResize(id, d, current, anchor))
action.addOp(
new op.SimpleObjectResize(id, d, current, anchor, false, toCircle)
)
return action.perform(restruct)
}
45 changes: 44 additions & 1 deletion packages/ketcher-react/src/script/editor/operations/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Base {
this.type = type
}

execute() {
execute(restruct) {
throw new Error('Operation.execute() is not implemented')
}

Expand All @@ -27,6 +27,49 @@ class Base {
}
}

export const OperationType = {
ATOM_ADD: 'Add atom',
ATOM_DELETE: 'Delete atom',
ATOM_ATTR: 'Set atom attribute',
ATOM_MOVE: 'Move atom',
BOND_ADD: 'Add bond',
BOND_DELETE: 'Delete bond',
BOND_ATTR: 'Set bond attribute',
BOND_MOVE: 'Move bond',
LOOP_MOVE: 'Move loop',
S_GROUP_ATOM_ADD: 'Add atom to s-group',
S_GROUP_ATOM_REMOVE: 'Remove atom from s-group',
S_GROUP_ATTR: 'Set s-group attribute',
S_GROUP_CREATE: 'Create s-group',
S_GROUP_DELETE: 'Delete s-group',
S_GROUP_ADD_TO_HIERACHY: 'Add s-group to hierarchy',
S_GROUP_REMOVE_FROM_HIERACHY: 'Delete s-group from hierarchy',
R_GROUP_ATTR: 'Set r-group attribute',
R_GROUP_FRAGMENT: 'R-group fragment',
UPDATE_IF_THEN: 'Update',
RESTORE_IF_THEN: 'Restore',
RXN_ARROW_ADD: 'Add rxn arrow',
RXN_ARROW_DELETE: 'Delete rxn arrow',
RXN_ARROW_MOVE: 'Move rxn arrow',
RXN_PLUS_ADD: 'Add rxn plus',
RXN_PLUS_DELETE: 'Delete rxn plus',
RXN_PLUS_MOVE: 'Move rxn plus',
S_GROUP_DATA_MOVE: 'Move s-group data',
CANVAS_LOAD: 'Load canvas',
ALIGN_DESCRIPTORS: 'Align descriptors',
SIMPLE_OBJECT_ADD: 'Add simple object',
SIMPLE_OBJECT_DELETE: 'Delete simple object',
SIMPLE_OBJECT_MOVE: 'Move simple object',
SIMPLE_OBJECT_RESIZE: 'Resize simple object',
RESTORE_DESCRIPTORS_POSITION: 'Restore descriptors position',
FRAGMENT_ADD: 'Add fragment',
FRAGMENT_DELETE: 'Delete fragment',
FRAGMENT_STEREO_FLAG: 'Add fragment stereo flag',
FRAGMENT_ADD_STEREO_ATOM: 'Add stereo atom to fragment',
FRAGMENT_DELETE_STEREO_ATOM: 'Delete stereo atom from fragment',
ENHANCED_FLAG_MOVE: 'Move enhanced flag'
}

export function invalidateAtom(restruct, aid, level) {
const atom = restruct.atoms.get(aid)

Expand Down
Loading

0 comments on commit bdf87dc

Please sign in to comment.