2021-10-05 01:56:40 +02:00
|
|
|
/*
|
|
|
|
* Copyright [2015] [wisemapping]
|
|
|
|
*
|
|
|
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
|
|
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
|
|
|
* "powered by wisemapping" text requirement on every single page;
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the license at
|
|
|
|
*
|
|
|
|
* http://www.wisemapping.org/license
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
const Element = require('./Element').default;
|
|
|
|
const Toolkit = require('./Toolkit').default;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A group object can be used to collect shapes.
|
|
|
|
*/
|
|
|
|
const Group = new Class({
|
|
|
|
Extends: Element,
|
|
|
|
initialize(attributes) {
|
|
|
|
const peer = Toolkit.createGroup();
|
|
|
|
const defaultAttributes = {
|
|
|
|
width: 50, height: 50, x: 50, y: 50, coordOrigin: '0 0', coordSize: '50 50',
|
|
|
|
};
|
|
|
|
for (const key in attributes) {
|
2021-10-06 04:08:42 +02:00
|
|
|
if (Object.prototype.hasOwnProperty.call(attributes, key)) {
|
|
|
|
defaultAttributes[key] = attributes[key];
|
|
|
|
}
|
2021-10-05 01:56:40 +02:00
|
|
|
}
|
|
|
|
this.parent(peer, defaultAttributes);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove an element as a child to the object.
|
|
|
|
*/
|
|
|
|
removeChild(element) {
|
|
|
|
if (!$defined(element)) {
|
2021-10-05 02:17:02 +02:00
|
|
|
throw new Error('Child element can not be null');
|
2021-10-05 01:56:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (element == this) {
|
2021-10-05 02:17:02 +02:00
|
|
|
throw new Error("It's not possible to add the group as a child of itself");
|
2021-10-05 01:56:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const elementType = element.getType();
|
|
|
|
if (elementType == null) {
|
2021-10-05 02:17:02 +02:00
|
|
|
throw new Error(`It seems not to be an element ->${element}`);
|
2021-10-05 01:56:40 +02:00
|
|
|
}
|
|
|
|
|
2021-10-05 02:17:02 +02:00
|
|
|
this.peer.removeChild(element.peer);
|
2021-10-05 01:56:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Appends an element as a child to the object.
|
|
|
|
*/
|
|
|
|
append(element) {
|
|
|
|
if (!$defined(element)) {
|
2021-10-05 02:17:02 +02:00
|
|
|
throw Error('Child element can not be null');
|
2021-10-05 01:56:40 +02:00
|
|
|
}
|
|
|
|
|
2021-10-06 04:08:42 +02:00
|
|
|
if (element === this) {
|
2021-10-05 02:17:02 +02:00
|
|
|
throw new Error("It's not posible to add the group as a child of itself");
|
2021-10-05 01:56:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const elementType = element.getType();
|
|
|
|
if (elementType == null) {
|
2021-10-05 02:17:02 +02:00
|
|
|
throw new Error(`It seems not to be an element ->${element}`);
|
2021-10-05 01:56:40 +02:00
|
|
|
}
|
|
|
|
|
2021-10-06 04:08:42 +02:00
|
|
|
if (elementType === 'Workspace') {
|
2021-10-05 02:17:02 +02:00
|
|
|
throw new Error('A group can not have a workspace as a child');
|
2021-10-05 01:56:40 +02:00
|
|
|
}
|
|
|
|
|
2021-10-05 02:17:02 +02:00
|
|
|
this.peer.append(element.peer);
|
2021-10-05 01:56:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
getType() {
|
|
|
|
return 'Group';
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The group element is a containing blocks for this content - they define a CSS2 "block level box".
|
|
|
|
* Inside the containing block a local coordinate system is defined for any sub-elements using the coordsize and coordorigin attributes.
|
|
|
|
* All CSS2 positioning information is expressed in terms of this local coordinate space.
|
|
|
|
* Consequently CSS2 position attributes (left, top, width, height and so on) have no unit specifier -
|
|
|
|
* they are simple numbers, not CSS length quantities.
|
|
|
|
*/
|
|
|
|
setCoordSize(width, height) {
|
2021-10-05 02:17:02 +02:00
|
|
|
this.peer.setCoordSize(width, height);
|
2021-10-05 01:56:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
setCoordOrigin(x, y) {
|
2021-10-05 02:17:02 +02:00
|
|
|
this.peer.setCoordOrigin(x, y);
|
2021-10-05 01:56:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
getCoordOrigin() {
|
2021-10-05 02:17:02 +02:00
|
|
|
return this.peer.getCoordOrigin();
|
2021-10-05 01:56:40 +02:00
|
|
|
},
|
|
|
|
getSize() {
|
2021-10-05 02:17:02 +02:00
|
|
|
return this.peer.getSize();
|
2021-10-05 01:56:40 +02:00
|
|
|
},
|
|
|
|
|
2021-10-05 02:17:02 +02:00
|
|
|
setFill() {
|
|
|
|
throw new Error('Unsupported operation. Fill can not be set to a group');
|
2021-10-05 01:56:40 +02:00
|
|
|
},
|
|
|
|
|
2021-10-05 02:17:02 +02:00
|
|
|
setStroke() {
|
|
|
|
throw new Error('Unsupported operation. Stroke can not be set to a group');
|
2021-10-05 01:56:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
getCoordSize() {
|
2021-10-05 02:17:02 +02:00
|
|
|
return this.peer.getCoordSize();
|
2021-10-05 01:56:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
appendDomChild(DomElement) {
|
|
|
|
if (!$defined(DomElement)) {
|
2021-10-05 02:17:02 +02:00
|
|
|
throw new Error('Child element can not be null');
|
2021-10-05 01:56:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (DomElement == this) {
|
2021-10-05 02:17:02 +02:00
|
|
|
throw new Error('Its not possible to add the group as a child of itself');
|
2021-10-05 01:56:40 +02:00
|
|
|
}
|
|
|
|
|
2021-10-05 02:17:02 +02:00
|
|
|
this.peer._native.append(DomElement);
|
2021-10-05 01:56:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
setOpacity(value) {
|
2021-10-05 02:17:02 +02:00
|
|
|
this.peer.setOpacity(value);
|
2021-10-05 01:56:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
export default Group;
|