123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565 |
- import { floorplanService } from '../Service/FloorplanService'
- import { elementService } from '../Service/ElementService'
- import { wallService } from '../Service/WallService'
- import { historyUtil } from './HistoryUtil'
- import HistoryEvents from '../enum/HistoryEvents'
- import { coordinate } from '../Coordinate'
- export default class Change {
- constructor() {
- this.lastData = {} // 每次都是当前数据和lastData进行比较,一般在mouseDown的时候存储进来
- this.elements = {} // 当前的变化
- }
- // 保存当前记录
- saveCurrentInfo() {
- //this.lastData.subFloorNum = floorplanService.getSubFloor();
- this.lastData.currentFloor = floorplanService.getCurrentFloor()
- this.lastData.points = JSON.parse(JSON.stringify(floorplanService.getPoints()))
- this.lastData.walls = JSON.parse(JSON.stringify(floorplanService.getWalls()))
- this.lastData.signs = JSON.parse(JSON.stringify(floorplanService.getSigns()))
- this.lastData.tags = JSON.parse(JSON.stringify(floorplanService.getTags()))
- this.lastData.cells = JSON.parse(JSON.stringify(floorplanService.getCells()))
- this.lastData.tables = JSON.parse(JSON.stringify(floorplanService.getTables()))
- this.lastData.rectangles = JSON.parse(JSON.stringify(floorplanService.getRectangles()))
- this.lastData.circles = JSON.parse(JSON.stringify(floorplanService.getCircles()))
- this.lastData.arrows = JSON.parse(JSON.stringify(floorplanService.getArrows()))
- this.lastData.icons = JSON.parse(JSON.stringify(floorplanService.getIcons()))
- this.lastData.title = JSON.parse(JSON.stringify(floorplanService.getTitle()))
- this.lastData.image = JSON.parse(JSON.stringify(floorplanService.getBgImage()))
- this.lastData.compass = JSON.parse(JSON.stringify(floorplanService.getCompass()))
- }
- operate() {
- //
- this.elements = {}
- // let flag = this.compareAngle()
- // if (!flag) {
- this.comparePoints()
- this.compareWalls()
-
- this.compareSigns()
- this.compareTags()
- this.compareCells()
- this.compareTables()
- this.compareRectangles()
- this.compareCircles()
- this.compareArrows()
- this.compareIcons()
- this.compareTitle()
- this.compareImage()
- this.compareCompass()
- // }
- // //旋转了
- // else {
- // this.lastData = {}
- // return true
- // }
- if (
- this.elements.points.length == 0 &&
- this.elements.walls.length == 0 &&
- this.elements.signs.length == 0 &&
- this.elements.tags.length == 0 &&
- this.elements.cells.length == 0 &&
- this.elements.tables.length == 0 &&
- this.elements.rectangles.length == 0 &&
- this.elements.circles.length == 0 &&
- this.elements.arrows.length == 0 &&
- this.elements.icons.length == 0 &&
- this.elements.title == null &&
- this.elements.image == null &&
- this.elements.compass == null
- ) {
- this.saveCurrentInfo()
- return false
- }
- this.lastData = {}
- // 这里不能取this.records.length-1,因为可能撤销后操作,这时候应该是覆盖,而不是往后面添加
- return true
- }
- comparePoints() {
- //const currentFloor = floorplanService.getCurrentFloorNum();
- const points = floorplanService.getPoints()
- this.elements.points = []
- for (const key in points) {
- const point = points[key]
- // 不存在意味着增加
- if (!this.lastData.points[key]) {
- const item = {
- handle: HistoryEvents.AddPoint,
- point: historyUtil.getDataForPoint(point),
- }
- this.elements.points.push(item)
- } else {
- const lastPoint = this.lastData.points[key]
- if (point.x == lastPoint.x && point.y == lastPoint.y && JSON.stringify(point.parent) == JSON.stringify(lastPoint.parent)) {
- delete this.lastData.points[key]
- continue
- } else {
- const item = {
- handle: HistoryEvents.ModifyPoint,
- prePoint: historyUtil.getDataForPoint(lastPoint),
- curPoint: historyUtil.getDataForPoint(point),
- }
- this.elements.points.push(item)
- }
- }
- delete this.lastData.points[key]
- }
- for (const key in this.lastData.points) {
- const item = {
- handle: HistoryEvents.DeletePoint,
- point: historyUtil.getDataForPoint(this.lastData.points[key]),
- }
- this.elements.points.push(item)
- }
- }
- compareWalls() {
- //const currentFloor = floorplanService.getCurrentFloorNum();
- this.elements.walls = []
- const walls = floorplanService.getWalls()
- for (const key in walls) {
- const wall = walls[key]
- const lastWall = this.lastData.walls[key]
- // 不存在意味着增加
- if (!lastWall) {
- const item = {
- handle: HistoryEvents.AddWall,
- wall: historyUtil.getDataForWall(wall),
- }
- this.elements.walls.push(item)
- } else {
- if (!historyUtil.isDifferentForWalls(wall, lastWall)) {
- delete this.lastData.walls[key]
- continue
- } else {
- const item = {
- handle: HistoryEvents.ModifyWall,
- preWall: historyUtil.getDataForWall(lastWall),
- curWall: historyUtil.getDataForWall(wall),
- }
- this.elements.walls.push(item)
- }
- }
- delete this.lastData.walls[key]
- }
- for (const key in this.lastData.walls) {
- const item = {
- handle: HistoryEvents.DeleteWall,
- wall: historyUtil.getDataForWall(this.lastData.walls[key]),
- }
- this.elements.walls.push(item)
- }
- }
- compareTags() {
- this.elements.tags = []
- const tags = floorplanService.getTags()
- for (const key in tags) {
- const tag = tags[key]
- const lastTag = this.lastData.tags[key]
- // 不存在意味着增加
- if (!lastTag) {
- const item = {
- handle: HistoryEvents.AddTag,
- tag: historyUtil.getDataForTag(tag),
- }
- this.elements.tags.push(item)
- } else {
- if (!historyUtil.isDifferentForTags(tag, lastTag)) {
- delete this.lastData.tags[key]
- continue
- } else {
- const item = {
- handle: HistoryEvents.ModifyTag,
- preTag: historyUtil.getDataForTag(lastTag),
- curTag: historyUtil.getDataForTag(tag),
- }
- this.elements.tags.push(item)
- }
- }
- delete this.lastData.tags[key]
- }
- for (const key in this.lastData.tags) {
- const item = {
- handle: HistoryEvents.DeleteTag,
- tag: historyUtil.getDataForTag(this.lastData.tags[key]),
- }
- this.elements.tags.push(item)
- }
- }
- compareCells() {
- this.elements.cells = []
- const cells = floorplanService.getCells()
- for (const key in cells) {
- const cell = cells[key]
- const lastCell = this.lastData.cells[key]
- // 不存在意味着增加
- if (!lastCell) {
- const item = {
- handle: HistoryEvents.AddCell,
- cell: historyUtil.getDataForCell(cell),
- }
- this.elements.cells.push(item)
- } else {
- if (!historyUtil.isDifferentForCells(cell, lastCell)) {
- delete this.lastData.cells[key]
- continue
- } else {
- const item = {
- handle: HistoryEvents.ModifyCell,
- preCell: historyUtil.getDataForCell(lastCell),
- curCell: historyUtil.getDataForCell(cell),
- }
- this.elements.cells.push(item)
- }
- }
- delete this.lastData.cells[key]
- }
- for (const key in this.lastData.cells) {
- const item = {
- handle: HistoryEvents.DeleteCell,
- cell: historyUtil.getDataForCell(this.lastData.cells[key]),
- }
- this.elements.cells.push(item)
- }
- }
- compareTables() {
- this.elements.tables = []
- const tables = floorplanService.getTables()
- for (const key in tables) {
- const table = tables[key]
- const lastTable = this.lastData.tables[key]
- // 不存在意味着增加
- if (!lastTable) {
- const item = {
- handle: HistoryEvents.AddTable,
- table: historyUtil.getDataForTable(table),
- }
- this.elements.tables.push(item)
- } else {
- if (!historyUtil.isDifferentForTables(table, lastTable)) {
- delete this.lastData.tables[key]
- continue
- } else {
- const item = {
- handle: HistoryEvents.ModifyTable,
- preTable: historyUtil.getDataForTable(lastTable),
- curTable: historyUtil.getDataForTable(table),
- }
- this.elements.tables.push(item)
- }
- }
- delete this.lastData.tables[key]
- }
- for (const key in this.lastData.tables) {
- const item = {
- handle: HistoryEvents.DeleteTable,
- table: historyUtil.getDataForTable(this.lastData.tables[key]),
- }
- this.elements.tables.push(item)
- }
- }
- compareRectangles() {
- this.elements.rectangles = []
- const rectangles = floorplanService.getRectangles()
- for (const key in rectangles) {
- const rectangle = rectangles[key]
- const lastRectangle = this.lastData.rectangles[key]
- // 不存在意味着增加
- if (!lastRectangle) {
- const item = {
- handle: HistoryEvents.AddRectangle,
- rectangle: historyUtil.getDataForRectangle(rectangle),
- }
- this.elements.rectangles.push(item)
- } else {
- if (!historyUtil.isDifferentForRectangles(rectangle, lastRectangle)) {
- delete this.lastData.rectangles[key]
- continue
- } else {
- const item = {
- handle: HistoryEvents.ModifyRectangle,
- preRectangle: historyUtil.getDataForRectangle(lastRectangle),
- curRectangle: historyUtil.getDataForRectangle(rectangle),
- }
- this.elements.rectangles.push(item)
- }
- }
- delete this.lastData.rectangles[key]
- }
- for (const key in this.lastData.rectangles) {
- const item = {
- handle: HistoryEvents.DeleteRectangle,
- rectangle: historyUtil.getDataForRectangle(this.lastData.rectangles[key]),
- }
- this.elements.rectangles.push(item)
- }
- }
- compareCircles() {
- this.elements.circles = []
- const circles = floorplanService.getCircles()
- for (const key in circles) {
- const circle = circles[key]
- const lastCircle = this.lastData.circles[key]
- // 不存在意味着增加
- if (!lastCircle) {
- const item = {
- handle: HistoryEvents.AddCircle,
- circle: historyUtil.getDataForCircle(circle),
- }
- this.elements.circles.push(item)
- } else {
- if (!historyUtil.isDifferentForCircles(circle, lastCircle)) {
- delete this.lastData.circles[key]
- continue
- } else {
- const item = {
- handle: HistoryEvents.ModifyCircle,
- preCircle: historyUtil.getDataForCircle(lastCircle),
- curCircle: historyUtil.getDataForCircle(circle),
- }
- this.elements.circles.push(item)
- }
- }
- delete this.lastData.circles[key]
- }
- for (const key in this.lastData.circles) {
- const item = {
- handle: HistoryEvents.DeleteCircle,
- circle: historyUtil.getDataForCircle(this.lastData.circles[key]),
- }
- this.elements.circles.push(item)
- }
- }
- compareArrows() {
- this.elements.arrows = []
- const arrows = floorplanService.getArrows()
- for (const key in arrows) {
- const arrow = arrows[key]
- const lastArrow = this.lastData.arrows[key]
- // 不存在意味着增加
- if (!lastArrow) {
- const item = {
- handle: HistoryEvents.AddArrow,
- arrow: historyUtil.getDataForArrow(arrow),
- }
- this.elements.arrows.push(item)
- } else {
- if (!historyUtil.isDifferentForArrows(arrow, lastArrow)) {
- delete this.lastData.arrows[key]
- continue
- } else {
- const item = {
- handle: HistoryEvents.ModifyArrow,
- preArrow: historyUtil.getDataForArrow(lastArrow),
- curArrow: historyUtil.getDataForArrow(arrow),
- }
- this.elements.arrows.push(item)
- }
- }
- delete this.lastData.arrows[key]
- }
- for (const key in this.lastData.arrows) {
- const item = {
- handle: HistoryEvents.DeleteArrow,
- arrow: historyUtil.getDataForArrow(this.lastData.arrows[key]),
- }
- this.elements.arrows.push(item)
- }
- }
- compareIcons() {
- this.elements.icons = []
- const icons = floorplanService.getIcons()
- for (const key in icons) {
- const icon = icons[key]
- const lastIcon = this.lastData.icons[key]
- // 不存在意味着增加
- if (!lastIcon) {
- const item = {
- handle: HistoryEvents.AddIcon,
- icon: historyUtil.getDataForIcon(icon),
- }
- this.elements.icons.push(item)
- } else {
- if (!historyUtil.isDifferentForIcons(icon, lastIcon)) {
- delete this.lastData.icons[key]
- continue
- } else {
- const item = {
- handle: HistoryEvents.ModifyIcon,
- preIcon: historyUtil.getDataForIcon(lastIcon),
- curIcon: historyUtil.getDataForIcon(icon),
- }
- this.elements.icons.push(item)
- }
- }
- delete this.lastData.icons[key]
- }
- for (const key in this.lastData.icons) {
- const item = {
- handle: HistoryEvents.DeleteIcon,
- icon: historyUtil.getDataForIcon(this.lastData.icons[key]),
- }
- this.elements.icons.push(item)
- }
- }
- compareSigns() {
- //const currentFloor = floorplanService.getCurrentFloorNum();
- this.elements.signs = []
- const signs = floorplanService.getSigns()
- for (const key in signs) {
- const sign = signs[key]
- const lastSign = this.lastData.signs[key]
- // 不存在意味着增加
- if (!lastSign) {
- const item = {
- handle: HistoryEvents.AddSign,
- sign: historyUtil.getDataForSign(sign),
- }
- this.elements.signs.push(item)
- } else {
- if (!historyUtil.isDifferentForSigns(sign, lastSign)) {
- delete this.lastData.signs[key]
- continue
- } else {
- const item = {
- handle: HistoryEvents.ModifySign,
- preSign: historyUtil.getDataForSign(lastSign),
- curSign: historyUtil.getDataForSign(sign),
- }
- this.elements.signs.push(item)
- }
- }
- delete this.lastData.signs[key]
- }
- for (const key in this.lastData.signs) {
- const item = {
- handle: HistoryEvents.DeleteSign,
- sign: historyUtil.getDataForSign(this.lastData.signs[key]),
- }
- this.elements.signs.push(item)
- }
- }
- // compareAngle() {
- // const angle = floorplanService.getAngle()
- // const lastAngle = this.lastData.angle
- // const lastRes = this.lastData.res
- // if (historyUtil.isDifferentForAngle(angle, lastAngle)) {
- // const item = {
- // handle: HistoryEvents.ModifyAngle,
- // preState: {
- // angle: historyUtil.getDataForAngle(lastAngle),
- // res: historyUtil.getDataForRes(lastRes),
- // },
- // curState: {
- // angle: historyUtil.getDataForAngle(angle),
- // res: historyUtil.getDataForRes(coordinate.res),
- // },
- // }
- // this.elements.rotate = item
- // return true
- // } else {
- // return false
- // }
- // }
-
- compareTitle(){
- this.elements.title = null
- const title = floorplanService.getTitle()
- const lastTitle = this.lastData.title
- const flag = historyUtil.isDifferentForTitle(title, lastTitle)
- if(flag){
- const item = {
- handle: HistoryEvents.ModifyTitle,
- preTitle: historyUtil.getDataForTitle(lastTitle),
- curTitle: historyUtil.getDataForTitle(title),
- }
- this.elements.title = item
- }
- }
-
- compareImage(){
- this.elements.image = null
- const image = floorplanService.getBgImage()
- const lastImage = this.lastData.image
- const flag = historyUtil.isDifferentForImage(image, lastImage)
- if(flag){
- const item = {
- handle: HistoryEvents.ModifyImage,
- preImage: historyUtil.getDataForImage(lastImage),
- curImage: historyUtil.getDataForImage(image),
- }
- this.elements.image = item
- }
- }
-
- compareCompass(){
- this.elements.compass = null
- const compass = floorplanService.getCompass()
- const lastCompass = this.lastData.compass
- const flag = historyUtil.isDifferentForCompass(compass, lastCompass)
- if(flag){
- const item = {
- handle: HistoryEvents.ModifyCompass,
- preCompass: historyUtil.getDataForCompass(lastCompass),
- curCompass: historyUtil.getDataForCompass(compass),
- }
- this.elements.compass = item
- }
- }
- }
- const change = new Change()
- export { change }
|