|
| 1 | +/** |
| 2 | + * This file is part of ILIAS, a powerful learning management system |
| 3 | + * published by ILIAS open source e-Learning e.V. |
| 4 | + * |
| 5 | + * ILIAS is licensed with the GPL-3.0, |
| 6 | + * see https://www.gnu.org/licenses/gpl-3.0.en.html |
| 7 | + * You should have received a copy of said license along with the |
| 8 | + * source code, too. |
| 9 | + * |
| 10 | + * If this is not the case or you just want to try ILIAS, you'll find |
| 11 | + * us at: |
| 12 | + * https://www.ilias.de |
| 13 | + * https://github.com/ILIAS-eLearning |
| 14 | + * |
| 15 | + ******************************************************************** */ |
| 16 | + |
| 17 | +import ShapeFactory from '../shape/shape-factory.js'; |
| 18 | + |
| 19 | +/** |
| 20 | + * Area |
| 21 | + */ |
| 22 | +export default class Area { |
| 23 | + /** |
| 24 | + */ |
| 25 | + constructor( |
| 26 | + shapeType, |
| 27 | + coords, |
| 28 | + hClass, |
| 29 | + hMode, |
| 30 | + id = 0, |
| 31 | + link = null, |
| 32 | + ) { |
| 33 | + this.shapeType = shapeType; |
| 34 | + this.coords = coords; |
| 35 | + this.hClass = hClass; |
| 36 | + this.hMode = hMode; |
| 37 | + this.overlayY = ''; |
| 38 | + this.id = id; |
| 39 | + this.link = link; |
| 40 | + this.shapeFactory = new ShapeFactory(); |
| 41 | + this.shape = {}; |
| 42 | + } |
| 43 | + |
| 44 | + toPropertiesObject(nr) { |
| 45 | + const link = (this.link === null) |
| 46 | + ? null |
| 47 | + : this.link.toPropertiesObject(); |
| 48 | + return { |
| 49 | + Coords: this.coords, |
| 50 | + HighlightClass: this.hClass, |
| 51 | + HighlightMode: this.hMode, |
| 52 | + Id: this.id, |
| 53 | + Link: link, |
| 54 | + Nr: nr, |
| 55 | + Shape: this.shapeType, |
| 56 | + }; |
| 57 | + } |
| 58 | + |
| 59 | + getShape(triggerNr = null) { |
| 60 | + const coords = this.coords.split(','); |
| 61 | + let shape = null; |
| 62 | + if (triggerNr && this.shape[triggerNr]) { |
| 63 | + return this.shape[triggerNr]; |
| 64 | + } |
| 65 | + switch (this.shapeType) { |
| 66 | + case 'Rect': |
| 67 | + shape = this.shapeFactory.rect( |
| 68 | + parseInt(coords[0]), |
| 69 | + parseInt(coords[1]), |
| 70 | + parseInt(coords[2]), |
| 71 | + parseInt(coords[3]), |
| 72 | + { triggerNr, copgEdType: 'shape' }, |
| 73 | + ); |
| 74 | + break; |
| 75 | + case 'Circle': |
| 76 | + shape = this.shapeFactory.circle( |
| 77 | + parseInt(coords[0]), |
| 78 | + parseInt(coords[1]), |
| 79 | + parseInt(coords[0]) + parseInt(coords[2]), |
| 80 | + parseInt(coords[1]), |
| 81 | + { triggerNr, copgEdType: 'shape' }, |
| 82 | + ); |
| 83 | + break; |
| 84 | + case 'Poly': |
| 85 | + const co = []; |
| 86 | + let i; |
| 87 | + coords.forEach((c) => { |
| 88 | + i = parseInt(c); |
| 89 | + if (!isNaN(i)) { |
| 90 | + co.push(parseInt(c)); |
| 91 | + } |
| 92 | + }); |
| 93 | + shape = this.shapeFactory.poly( |
| 94 | + co, |
| 95 | + { |
| 96 | + triggerNr, |
| 97 | + copgEdType: 'shape', |
| 98 | + }, |
| 99 | + ); |
| 100 | + break; |
| 101 | + } |
| 102 | + if (triggerNr) { |
| 103 | + this.shape[triggerNr] = shape; |
| 104 | + } |
| 105 | + return shape; |
| 106 | + } |
| 107 | +} |
0 commit comments