From be6dd8f442a3bb9cde57f7149c07b35c74cdd1ae Mon Sep 17 00:00:00 2001 From: bjoernh2000 Date: Sat, 30 Jan 2021 19:30:51 +0100 Subject: [PATCH 1/6] filled out initial selection class --- src/app/core/device.js | 2 + src/app/view/mouseAndKeyboardHandler.js | 22 +++++++---- src/app/view/paperView.js | 9 +++-- src/app/view/selection.js | 51 +++++++++++++++++++++++-- src/app/view/tools/copyTool.js | 13 ++++++- src/app/view/viewManager.js | 49 +++++++++++++++++------- 6 files changed, 116 insertions(+), 30 deletions(-) diff --git a/src/app/core/device.js b/src/app/core/device.js index 94c24b2f..3bb01580 100644 --- a/src/app/core/device.js +++ b/src/app/core/device.js @@ -917,6 +917,7 @@ export default class Device { return component; } } + return null; // if no component found return null } /** @@ -932,6 +933,7 @@ export default class Device { return connection; } } + return null; // if no connection found return null } /** diff --git a/src/app/view/mouseAndKeyboardHandler.js b/src/app/view/mouseAndKeyboardHandler.js index 4de97626..d4bbba06 100644 --- a/src/app/view/mouseAndKeyboardHandler.js +++ b/src/app/view/mouseAndKeyboardHandler.js @@ -106,13 +106,13 @@ export default class MouseAndKeyboardHandler { } // Copy if ((event.ctrlKey || event.metaKey) && key == 67) { - //console.log("Ctl c detected"); + // console.log("Ctl c detected"); reference.initiateCopy(); } // Cut if ((event.ctrlKey || event.metaKey) && key == 88) { //console.log("Ctl x detected"); - let selectedFeatures = reference.view.getSelectedFeatures(); + let selection = reference.view.getSelectedFeatures(); if (selectedFeatures.length > 0) { reference.pasteboard[0] = selectedFeatures[0]; } @@ -121,12 +121,18 @@ export default class MouseAndKeyboardHandler { } // Paste if ((event.ctrlKey || event.metaKey) && key == 86) { - //console.log("Ctl v detected"); - let pasteboardFeatures = reference.pasteboard; - if (pasteboardFeatures.length > 0) { - reference.updateDefaultsFromFeature(pasteboardFeatures[0]); - reference.activateTool(pasteboardFeatures[0].getType()); - } + console.log("Ctl v detected"); + let selection = reference.selection; + + // if (pasteboardFeatures.length == 1) { // 1 feature + // reference.updateDefaultsFromFeature(pasteboardFeatures[0]); + // reference.activateTool(pasteboardFeatures[0].getType()); + + // } else if (pasteboardFeatures.length > 1) { // multiple features + // console.log("multiple features detected") + // reference.updateDefaultsFromFeatures(pasteboardFeatures); + // reference.activateTools(pasteboardFeatures); + // } } //Undo diff --git a/src/app/view/paperView.js b/src/app/view/paperView.js index 9dee3f29..b67c420a 100644 --- a/src/app/view/paperView.js +++ b/src/app/view/paperView.js @@ -19,6 +19,7 @@ import * as DXFSolidObjectRenderer from "./render2D/dxfSolidObjectRenderer2D"; import Layer from "../core/layer"; import Device from "../core/device"; import Feature from "../core/feature"; +import Selection from "./selection"; /** * Paper View class */ @@ -74,16 +75,18 @@ export default class PaperView { /** * Returns a list of selected items on the canvas - * @return {Array} + * @return {Selection} * @memberof PaperView */ getSelectedFeatures() { let output = []; let items = paper.project.selectedItems; for (let i = 0; i < items.length; i++) { - output.push(this.__viewManagerDelegate.currentDevice.getFeatureByID(items[i].featureID)); + output.push(items[i].featureID); } - return output; + console.log(output); + let selection = new Selection(output); + return selection; } /** * Deselects the items from the canvas diff --git a/src/app/view/selection.js b/src/app/view/selection.js index 2cd4afc9..f6afcb56 100644 --- a/src/app/view/selection.js +++ b/src/app/view/selection.js @@ -1,4 +1,6 @@ import paper from "paper"; +import * as Registry from "../core/registry"; + /** * Selection class */ @@ -11,13 +13,38 @@ export default class Selection { this.__components = []; this.__connections = []; this.__otherFeatures = []; - //Sort out wether each of the items selected belongs to one of the following - for (let i in items) { - console.log(items[i]); + //Sort out where each of the items selected belongs to one of the following + for (let i in items) { // query if its a component, connection or other feature + let feature = Registry.currentDevice.getComponentByID(items[i]); + if (feature == null) { + feature = Registry.currentDevice.getConnectionByID(items[i]); + if (feature == null) { + console.log("Other Feature Selected"); + feature = Registry.currentDevice.getFeatureByID(items[i]); + console.log(feature); + console.log(items[i]); + console.log(Registry.currentDevice.getFeatureIDs); + this.__otherFeatures.push(items[i]); + } else { + console.log("Connection Feature Selected"); + this.__connections.push(items[i]); + } + } else { + console.log("Component Feature Selected"); + this.__components.push(items[i]); + } } this.__bounds = this.__calculateSelectionBounds(); } + getFeatureIDs() { + let ret = []; + ret.concat(this.__components); + ret.concat(this.__connections); + ret.concat(this.__otherFeatures); + return ret; + } + /** * Generates a replica * @param {number} x X coordinate for here the selection should be replicated @@ -35,17 +62,33 @@ export default class Selection { console.log("reference point:", referencepoint); + for (let i in this.__components) { - let render = Registry.currentDevice.getFeatureByID(this.__components[i]); + let render = Registry.currentDevice.getComponentByID(this.__components[i]); + let newx = referencepoint.x + render.bounds.x; + newx -= x; + let newy = referencepoint.y - render.bounds.y; + newy += y; + let newComponent = render.replicate(newx,newy); + Registry.currentDevice.addComponent(newComponent); + console.log("registry added replicated device"); } for (let i in this.__connections) { let render = Registry.currentDevice.getFeatureByID(this.__connections[i]); + let replica = render.replicate(x,y); } for (let i in this.__otherFeatures) { let render = Registry.currentDevice.getFeatureByID(this.__otherFeatures[i]); + let newx = referencepoint.x + render.bounds.x; + newx -= x; + let newy = referencepoint.y - render.bounds.y; + newy += y; + let newFeature = render.replicate(newx,newy); + let replica = render.replicate(newx,newy); } + } /** * Selects all the components, connections and features diff --git a/src/app/view/tools/copyTool.js b/src/app/view/tools/copyTool.js index a1ac00e6..c0f1ea24 100644 --- a/src/app/view/tools/copyTool.js +++ b/src/app/view/tools/copyTool.js @@ -3,7 +3,18 @@ // var Feature = require("../../core/feature"); // import SimpleQueue from "../../utils/simpleQueue"; // var PageSetup = require("../pageSetup"); +import Selection from "../selection"; +import positionTool from "./positionTool"; export default class CopyTool extends positionTool { - // constructor(typeString, setString, ) + constructor(typeString, setString, selection) { + super(typeString, setString); + this.__selection = selection; // Selection, what we are copying + } + + createNewFeature(point) { + let [x,y] = positionTool.getTarget(point); + this.__selection.replicate(x,y); + Registry.viewManager.saveDeviceState(); + } } diff --git a/src/app/view/viewManager.js b/src/app/view/viewManager.js index 77d9fc22..862c4989 100644 --- a/src/app/view/viewManager.js +++ b/src/app/view/viewManager.js @@ -34,11 +34,13 @@ import CustomComponentManager from "./customComponentManager"; import EditDeviceDialog from "./ui/editDeviceDialog"; import ManufacturingPanel from "./ui/manufacturingPanel"; import CustomComponentPositionTool from "./tools/customComponentPositionTool"; +import CopyTool from "./tools/copyTool"; import CustomComponent from "../core/customComponent"; import { setButtonColor } from "../utils/htmlUtils"; import ExportPanel from "./ui/exportPanel"; import HelpDialog from "./ui/helpDialog"; import PaperView from "./paperView"; +import Selection from "./selection"; import AdaptiveGrid from "./grid/adaptiveGrid"; import TaguchiDesigner from "./ui/taguchiDesigner"; import RightClickMenu from "./ui/rightClickMenu"; @@ -81,6 +83,7 @@ export default class ViewManager { this._introDialog = new IntroDialog(); this._dampFabricateDialog = new DAMPFabricationDialog(); let reference = this; + this.selection = null; this.updateQueue = new SimpleQueue(function() { reference.view.refresh(); }, 20); @@ -147,10 +150,16 @@ export default class ViewManager { * @memberof ViewManager */ initiateCopy() { - let selectedFeatures = this.view.getSelectedFeatures(); - if (selectedFeatures.length > 0) { - this.pasteboard[0] = selectedFeatures[0]; - } + this.selection = this.view.getSelectedFeatures(); + + + // if (selectedFeatures.length > 0) { + // for (let i = 0; i < selectedFeatures.length; i++) { + // this.pasteboard[i] = selectedFeatures[i]; + // } + // console.log("initiateCopy"); + // console.log(this.pasteboard); + // } } /** * Initiating the zoom toolbar @@ -862,8 +871,13 @@ export default class ViewManager { * @returns {void} * @memberof ViewManager */ - adjustParams(typeString, setString, valueString, value) { - let selectedFeatures = this.view.getSelectedFeatures(); + adjustParams(typeString, setString, valueString, value) { + let selection_ = this.view.getSelectedFeatures(); + let featureIDs = selection_.getFeatureIDs(); + let selectedFeatures = []; + for (let featureID in featureIDs) { + selectedFeatures.push(this.__currentDevice.getFeatureByID(featureID)); + } if (selectedFeatures.length > 0) { let correctType = this.getFeaturesOfType(typeString, setString, selectedFeatures); if (correctType.length > 0) { @@ -905,7 +919,7 @@ export default class ViewManager { */ updateDefaultsFromFeature(feature) { let heritable = feature.getHeritableParams(); - for (let key in heritable) { + for (let key in heritable) { this.updateDefault(feature.getType(), feature.getSet(), key, feature.getValue(key)); } } @@ -973,16 +987,23 @@ export default class ViewManager { * @memberof ViewManager */ activateTool(toolString, rightClickToolString = "SelectTool") { - if (this.tools[toolString] == null) { - throw new Error("Could not find tool with the matching string"); - } + if (toolString === "CopyTool") { + //Cleanup job when activating new tool + this.view.clearSelectedItems(); - //Cleanup job when activating new tool - this.view.clearSelectedItems(); + this.mouseAndKeyboardHandler.leftMouseTool = this.tools[new CopyTool(toolString, "Copy", selection)]; + } else { + if (this.tools[toolString] == null) { + throw new Error("Could not find tool with the matching string"); + } + //Cleanup job when activating new tool + this.view.clearSelectedItems(); + + this.mouseAndKeyboardHandler.leftMouseTool = this.tools[toolString]; + } - this.mouseAndKeyboardHandler.leftMouseTool = this.tools[toolString]; this.mouseAndKeyboardHandler.rightMouseTool = this.tools[rightClickToolString]; - this.mouseAndKeyboardHandler.updateViewMouseEvents(); + this.mouseAndKeyboardHandler.updateViewMouseEvents(); } /** From 580924047699a1e8876be395c6cce687e7400c2d Mon Sep 17 00:00:00 2001 From: bjoernh2000 Date: Tue, 2 Feb 2021 03:43:44 +0100 Subject: [PATCH 2/6] added selection for pasting --- src/app/core/feature.js | 28 +++++++++++++++++++++++++ src/app/view/mouseAndKeyboardHandler.js | 5 +++++ src/app/view/selection.js | 8 +++---- src/app/view/tools/copyTool.js | 7 ++++--- src/app/view/viewManager.js | 2 +- 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/app/core/feature.js b/src/app/core/feature.js index efa0d39d..94e46eb4 100644 --- a/src/app/core/feature.js +++ b/src/app/core/feature.js @@ -2,6 +2,8 @@ import CustomComponent from "./customComponent"; import Params from "./params"; import Device from "./device"; +import paper from "paper"; + import * as Parameters from "./parameters"; const StringValue = Parameters.StringValue; import * as FeatureSets from "../featureSets"; @@ -31,6 +33,13 @@ export default class Feature { this.__fabtype = fabtype; this.__dxfObjects = []; this.__referenceID = null; + this.__bounds = null; + + if (this.__params != null) { + console.log(this.__params); + let [x,y] = this.__params.getValue("position"); + this.__bounds = new paper.Rectangle(new paper.Point(x, y), new paper.Point(x, y)); + } } /** @@ -43,6 +52,25 @@ export default class Feature { return this.__referenceObject; } + get bounds() { + return this.__bounds; + } + + /** + * Sets the bounds i.e. the x,y position and the width and length of the feature + * @param {Object} bounds PaperJS Rectangle object associated with a Path.bounds property + * @memberof Feature + * @returns {void} + */ + setBounds(bounds) { + this.__bounds = bounds; + let topleftpt = bounds.topLeft; + this.__params.position = [topleftpt.x, topleftpt.y]; + this.__params.xspan = bounds.width; + this.__params.yspan = bounds.height; + } + + /** * Sets the reference object id * @param {} value diff --git a/src/app/view/mouseAndKeyboardHandler.js b/src/app/view/mouseAndKeyboardHandler.js index d4bbba06..aac6ef1b 100644 --- a/src/app/view/mouseAndKeyboardHandler.js +++ b/src/app/view/mouseAndKeyboardHandler.js @@ -123,6 +123,11 @@ export default class MouseAndKeyboardHandler { if ((event.ctrlKey || event.metaKey) && key == 86) { console.log("Ctl v detected"); let selection = reference.selection; + let pastedFeatures = selection.getSelectedFeatures(); + console.log(pastedFeatures); + if (pastedFeatures.length > 0) { + reference.activateTool("CopyTool"); + } // if (pasteboardFeatures.length == 1) { // 1 feature // reference.updateDefaultsFromFeature(pasteboardFeatures[0]); diff --git a/src/app/view/selection.js b/src/app/view/selection.js index f6afcb56..2dfb7ec2 100644 --- a/src/app/view/selection.js +++ b/src/app/view/selection.js @@ -23,7 +23,6 @@ export default class Selection { feature = Registry.currentDevice.getFeatureByID(items[i]); console.log(feature); console.log(items[i]); - console.log(Registry.currentDevice.getFeatureIDs); this.__otherFeatures.push(items[i]); } else { console.log("Connection Feature Selected"); @@ -37,11 +36,10 @@ export default class Selection { this.__bounds = this.__calculateSelectionBounds(); } - getFeatureIDs() { + getSelectedFeatures() { let ret = []; - ret.concat(this.__components); - ret.concat(this.__connections); - ret.concat(this.__otherFeatures); + ret = this.__components.concat(this.__connections); + ret = ret.concat(this.__otherFeatures); return ret; } diff --git a/src/app/view/tools/copyTool.js b/src/app/view/tools/copyTool.js index c0f1ea24..13139e60 100644 --- a/src/app/view/tools/copyTool.js +++ b/src/app/view/tools/copyTool.js @@ -4,16 +4,17 @@ // import SimpleQueue from "../../utils/simpleQueue"; // var PageSetup = require("../pageSetup"); import Selection from "../selection"; -import positionTool from "./positionTool"; +import PositionTool from "./positionTool"; -export default class CopyTool extends positionTool { +export default class CopyTool extends PositionTool { constructor(typeString, setString, selection) { super(typeString, setString); this.__selection = selection; // Selection, what we are copying } createNewFeature(point) { - let [x,y] = positionTool.getTarget(point); + console.log("mouseDown Copy"); + let [x,y] = PositionTool.getTarget(point); this.__selection.replicate(x,y); Registry.viewManager.saveDeviceState(); } diff --git a/src/app/view/viewManager.js b/src/app/view/viewManager.js index 862c4989..ecd29bd1 100644 --- a/src/app/view/viewManager.js +++ b/src/app/view/viewManager.js @@ -991,7 +991,7 @@ export default class ViewManager { //Cleanup job when activating new tool this.view.clearSelectedItems(); - this.mouseAndKeyboardHandler.leftMouseTool = this.tools[new CopyTool(toolString, "Copy", selection)]; + this.mouseAndKeyboardHandler.leftMouseTool = new CopyTool(toolString, "Copy", this.selection); } else { if (this.tools[toolString] == null) { throw new Error("Could not find tool with the matching string"); From 73c542e74603bada7967f9c20933df2cfd1261e5 Mon Sep 17 00:00:00 2001 From: bjoernh2000 Date: Tue, 2 Feb 2021 19:17:18 +0100 Subject: [PATCH 3/6] initial working version --- src/app/core/feature.js | 3 +-- src/app/view/mouseAndKeyboardHandler.js | 3 +-- src/app/view/paperView.js | 1 - src/app/view/selection.js | 18 ++++++++++-------- src/app/view/tools/copyTool.js | 7 ++++++- src/app/view/viewManager.js | 6 +++--- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/app/core/feature.js b/src/app/core/feature.js index 94e46eb4..5e3c021e 100644 --- a/src/app/core/feature.js +++ b/src/app/core/feature.js @@ -36,9 +36,8 @@ export default class Feature { this.__bounds = null; if (this.__params != null) { - console.log(this.__params); let [x,y] = this.__params.getValue("position"); - this.__bounds = new paper.Rectangle(new paper.Point(x, y), new paper.Point(x, y)); + this.__bounds = new paper.Point(x, y); } } diff --git a/src/app/view/mouseAndKeyboardHandler.js b/src/app/view/mouseAndKeyboardHandler.js index aac6ef1b..273183e7 100644 --- a/src/app/view/mouseAndKeyboardHandler.js +++ b/src/app/view/mouseAndKeyboardHandler.js @@ -123,8 +123,7 @@ export default class MouseAndKeyboardHandler { if ((event.ctrlKey || event.metaKey) && key == 86) { console.log("Ctl v detected"); let selection = reference.selection; - let pastedFeatures = selection.getSelectedFeatures(); - console.log(pastedFeatures); + let pastedFeatures = selection.getFeatureIDs(); if (pastedFeatures.length > 0) { reference.activateTool("CopyTool"); } diff --git a/src/app/view/paperView.js b/src/app/view/paperView.js index b67c420a..c77c6f49 100644 --- a/src/app/view/paperView.js +++ b/src/app/view/paperView.js @@ -84,7 +84,6 @@ export default class PaperView { for (let i = 0; i < items.length; i++) { output.push(items[i].featureID); } - console.log(output); let selection = new Selection(output); return selection; } diff --git a/src/app/view/selection.js b/src/app/view/selection.js index 2dfb7ec2..e361a00f 100644 --- a/src/app/view/selection.js +++ b/src/app/view/selection.js @@ -34,9 +34,10 @@ export default class Selection { } } this.__bounds = this.__calculateSelectionBounds(); + console.log("bounds: ", this.__bounds); } - getSelectedFeatures() { + getFeatureIDs() { let ret = []; ret = this.__components.concat(this.__connections); ret = ret.concat(this.__otherFeatures); @@ -56,7 +57,7 @@ export default class Selection { 2. Go through each of the items 3. Clone components/connections/other features */ - let referencepoint = this.__bounds.topleft; + let referencepoint = this.__bounds; console.log("reference point:", referencepoint); @@ -85,6 +86,7 @@ export default class Selection { newy += y; let newFeature = render.replicate(newx,newy); let replica = render.replicate(newx,newy); + Registry.currentLayer.addFeature(replica); } } @@ -178,15 +180,15 @@ export default class Selection { if (bounds.y < ymin) { ymin = bounds.y; } - if (bounds.x + bounds.width > xmax) { - xmax = bounds.x + bounds.width; + if (bounds.x > xmax) { + xmax = bounds.x; } - if (bounds.y + bounds.height > ymax) { - ymax = bounds.y + bounds.height; + if (bounds.y > ymax) { + ymax = bounds.y; } } - - let ret = new paper.Rectangle(new paper.Point(xmin, ymin), new paper.Point(xmax, ymax)); + console.log(xmin,xmax,ymin,ymax); + let ret = new paper.Point((xmin+xmax)/2, (ymin+ymax)/2); return ret; } } diff --git a/src/app/view/tools/copyTool.js b/src/app/view/tools/copyTool.js index 13139e60..fc3afa34 100644 --- a/src/app/view/tools/copyTool.js +++ b/src/app/view/tools/copyTool.js @@ -8,7 +8,7 @@ import PositionTool from "./positionTool"; export default class CopyTool extends PositionTool { constructor(typeString, setString, selection) { - super(typeString, setString); + super(typeString, setString); // typeString == CopyString, setString == Copy this.__selection = selection; // Selection, what we are copying } @@ -18,4 +18,9 @@ export default class CopyTool extends PositionTool { this.__selection.replicate(x,y); Registry.viewManager.saveDeviceState(); } + + showTarget() { // TODO render Target + let target = PositionTool.getTarget(this.lastPoint); + Registry.viewManager.updateTarget(this.typeString, this.setString, target); + } } diff --git a/src/app/view/viewManager.js b/src/app/view/viewManager.js index ecd29bd1..8f10dd70 100644 --- a/src/app/view/viewManager.js +++ b/src/app/view/viewManager.js @@ -875,8 +875,8 @@ export default class ViewManager { let selection_ = this.view.getSelectedFeatures(); let featureIDs = selection_.getFeatureIDs(); let selectedFeatures = []; - for (let featureID in featureIDs) { - selectedFeatures.push(this.__currentDevice.getFeatureByID(featureID)); + for (let i in featureIDs) { + selectedFeatures.push(this.__currentDevice.getFeatureByID(featureIDs[i])); } if (selectedFeatures.length > 0) { let correctType = this.getFeaturesOfType(typeString, setString, selectedFeatures); @@ -1107,7 +1107,7 @@ export default class ViewManager { * @returns {void} */ saveDeviceState() { - console.log("Saving to statck"); + console.log("Saving to stack"); let save = JSON.stringify(Registry.currentDevice.toInterchangeV1()); From 2050cbe82353a897c0027cbfe95f580f15e92972 Mon Sep 17 00:00:00 2001 From: bjoernh2000 Date: Wed, 3 Feb 2021 03:14:48 +0100 Subject: [PATCH 4/6] fixed positioning --- src/app/core/feature.js | 2 +- src/app/view/selection.js | 18 +++++++++--------- src/app/view/tools/copyTool.js | 1 + 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/app/core/feature.js b/src/app/core/feature.js index 5e3c021e..81ecf0c0 100644 --- a/src/app/core/feature.js +++ b/src/app/core/feature.js @@ -35,7 +35,7 @@ export default class Feature { this.__referenceID = null; this.__bounds = null; - if (this.__params != null) { + if (this.__params != null & this.__type !== "Connection") { let [x,y] = this.__params.getValue("position"); this.__bounds = new paper.Point(x, y); } diff --git a/src/app/view/selection.js b/src/app/view/selection.js index e361a00f..8ec74472 100644 --- a/src/app/view/selection.js +++ b/src/app/view/selection.js @@ -80,11 +80,12 @@ export default class Selection { for (let i in this.__otherFeatures) { let render = Registry.currentDevice.getFeatureByID(this.__otherFeatures[i]); - let newx = referencepoint.x + render.bounds.x; - newx -= x; + let newx = referencepoint.x - render.bounds.x; + newx = x + newx; + console.log("newx: ", newx); let newy = referencepoint.y - render.bounds.y; - newy += y; - let newFeature = render.replicate(newx,newy); + newy = y + newy; + console.log("newy: ", newy); let replica = render.replicate(newx,newy); Registry.currentLayer.addFeature(replica); } @@ -131,10 +132,10 @@ export default class Selection { * @memberof Selection */ __calculateSelectionBounds() { - let xmin = 0; - let ymin = 0; - let xmax = 0; - let ymax = 0; + let xmin = Number.MAX_SAFE_INTEGER; + let ymin = Number.MAX_SAFE_INTEGER; + let xmax = Number.MIN_SAFE_INTEGER; + let ymax = Number.MIN_SAFE_INTEGER; let bounds; for (let i in this.__components) { @@ -187,7 +188,6 @@ export default class Selection { ymax = bounds.y; } } - console.log(xmin,xmax,ymin,ymax); let ret = new paper.Point((xmin+xmax)/2, (ymin+ymax)/2); return ret; } diff --git a/src/app/view/tools/copyTool.js b/src/app/view/tools/copyTool.js index fc3afa34..8b2b158c 100644 --- a/src/app/view/tools/copyTool.js +++ b/src/app/view/tools/copyTool.js @@ -15,6 +15,7 @@ export default class CopyTool extends PositionTool { createNewFeature(point) { console.log("mouseDown Copy"); let [x,y] = PositionTool.getTarget(point); + console.log("mouse at: ", x,y); this.__selection.replicate(x,y); Registry.viewManager.saveDeviceState(); } From 6e9286df634ca2aaa5b18e1cc43d422b72ecabc7 Mon Sep 17 00:00:00 2001 From: bjoernh2000 Date: Sat, 6 Feb 2021 18:40:32 +0100 Subject: [PATCH 5/6] added rendering --- src/app/view/mouseAndKeyboardHandler.js | 2 ++ src/app/view/paperView.js | 32 ++++++++++++++++--- src/app/view/selection.js | 41 ++++++++++++++----------- src/app/view/tools/copyTool.js | 2 +- src/app/view/viewManager.js | 11 +------ 5 files changed, 55 insertions(+), 33 deletions(-) diff --git a/src/app/view/mouseAndKeyboardHandler.js b/src/app/view/mouseAndKeyboardHandler.js index 273183e7..e17eb6f8 100644 --- a/src/app/view/mouseAndKeyboardHandler.js +++ b/src/app/view/mouseAndKeyboardHandler.js @@ -126,6 +126,8 @@ export default class MouseAndKeyboardHandler { let pastedFeatures = selection.getFeatureIDs(); if (pastedFeatures.length > 0) { reference.activateTool("CopyTool"); + } else { + console.error("No features to paste"); } // if (pasteboardFeatures.length == 1) { // 1 feature diff --git a/src/app/view/paperView.js b/src/app/view/paperView.js index c77c6f49..1022ff7d 100644 --- a/src/app/view/paperView.js +++ b/src/app/view/paperView.js @@ -607,10 +607,34 @@ export default class PaperView { */ addTarget(featureType, set, position) { this.removeTarget(); - this.lastTargetType = featureType; - this.lastTargetPosition = position; - this.lastTargetSet = set; - this.updateTarget(); + if (featureType === "CopyTool") { // render the preview of the copied selection + let selection = this.__viewManagerDelegate.selection; + let referencepoint = selection.getReferencePoint(); // calculate position of where to render target + let featureIDs = selection.getFeatureIDs(); + let [x,y] = position; + for (let i=0;i xmax) { - xmax = bounds.x + bounds.width; + if (bounds.x > xmax) { + xmax = bounds.x; } - if (bounds.y + bounds.height > ymax) { - ymax = bounds.y + bounds.height; + if (bounds.y > ymax) { + ymax = bounds.y; } } @@ -164,11 +169,11 @@ export default class Selection { if (bounds.y < ymin) { ymin = bounds.y; } - if (bounds.x + bounds.width > xmax) { - xmax = bounds.x + bounds.width; + if (bounds.x > xmax) { + xmax = bounds.x; } - if (bounds.y + bounds.height > ymax) { - ymax = bounds.y + bounds.height; + if (bounds.y > ymax) { + ymax = bounds.y; } } diff --git a/src/app/view/tools/copyTool.js b/src/app/view/tools/copyTool.js index 8b2b158c..ddc824a5 100644 --- a/src/app/view/tools/copyTool.js +++ b/src/app/view/tools/copyTool.js @@ -8,7 +8,7 @@ import PositionTool from "./positionTool"; export default class CopyTool extends PositionTool { constructor(typeString, setString, selection) { - super(typeString, setString); // typeString == CopyString, setString == Copy + super(typeString, setString); // typeString == "CopyTool", setString == "Basic" this.__selection = selection; // Selection, what we are copying } diff --git a/src/app/view/viewManager.js b/src/app/view/viewManager.js index 8f10dd70..a401ceeb 100644 --- a/src/app/view/viewManager.js +++ b/src/app/view/viewManager.js @@ -151,15 +151,6 @@ export default class ViewManager { */ initiateCopy() { this.selection = this.view.getSelectedFeatures(); - - - // if (selectedFeatures.length > 0) { - // for (let i = 0; i < selectedFeatures.length; i++) { - // this.pasteboard[i] = selectedFeatures[i]; - // } - // console.log("initiateCopy"); - // console.log(this.pasteboard); - // } } /** * Initiating the zoom toolbar @@ -991,7 +982,7 @@ export default class ViewManager { //Cleanup job when activating new tool this.view.clearSelectedItems(); - this.mouseAndKeyboardHandler.leftMouseTool = new CopyTool(toolString, "Copy", this.selection); + this.mouseAndKeyboardHandler.leftMouseTool = new CopyTool(toolString, "Basic", this.selection); } else { if (this.tools[toolString] == null) { throw new Error("Could not find tool with the matching string"); From ef489c2beaad2ccf63a06f955575499553f476ce Mon Sep 17 00:00:00 2001 From: bjoernh2000 Date: Mon, 8 Feb 2021 20:54:01 +0100 Subject: [PATCH 6/6] fixed some issues with clipboard --- src/app/view/selection.js | 74 +++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 18 deletions(-) diff --git a/src/app/view/selection.js b/src/app/view/selection.js index 4158919a..dbd40754 100644 --- a/src/app/view/selection.js +++ b/src/app/view/selection.js @@ -1,5 +1,8 @@ import paper from "paper"; import * as Registry from "../core/registry"; +import Feature from "../core/feature"; +import Params from "../core/params"; +import Component from "../core/component"; /** * Selection class @@ -15,17 +18,24 @@ export default class Selection { this.__otherFeatures = []; //Sort out where each of the items selected belongs to one of the following for (let i in items) { // query if its a component, connection or other feature - let feature = Registry.currentDevice.getComponentByID(items[i]); + let feature = Registry.currentDevice.getComponentByID(items[i]); if (feature == null) { feature = Registry.currentDevice.getConnectionByID(items[i]); if (feature == null) { - console.log("Other Feature Selected"); feature = Registry.currentDevice.getFeatureByID(items[i]); - if (feature) console.log(feature); console.log(items[i]); - this.__otherFeatures.push(items[i]); + if (feature.__type === "Connection") { + console.log("Connection Feature Selected"); + this.__connections.push(items[i]); + } else if (feature.__type === "EDGE") { + // ignore the edge + } else { + console.log("Other Feature Selected"); + this.__otherFeatures.push(items[i]); + } } else { + console.log("Connection:",feature); console.log("Connection Feature Selected"); this.__connections.push(items[i]); } @@ -81,6 +91,7 @@ export default class Selection { for (let i in this.__connections) { // let render = Registry.currentDevice.getFeatureByID(this.__connections[i]); // let replica = render.replicate(x,y); + console.log("implement connections"); } for (let i in this.__otherFeatures) { @@ -93,6 +104,33 @@ export default class Selection { console.log("newy: ", newy); let replica = render.replicate(newx,newy); Registry.currentLayer.addFeature(replica); + + // if component do this + let featureIDs = []; + featureIDs.push(this.__otherFeatures[i]); + let typeString = replica.__type; + let paramdata = replica.getParams(); + + let definition = Registry.featureSet.getDefinition(typeString); + let cleanparamdata = {}; + for (let key in paramdata) { + cleanparamdata[key] = paramdata[key].getValue(); + } + let params = new Params(cleanparamdata, definition.unique, definition.heritable); + let componentid = Feature.generateID(); + let name = Registry.currentDevice.generateNewName(typeString); + let newComponent = new Component(typeString, params, name, definition.mint, componentid); + let feature; + + for (let i in featureIDs) { + newComponent.addFeatureID(featureIDs[i]); + + //Update the component reference + feature = Registry.currentDevice.getFeatureByID(featureIDs[i]); + feature.referenceID = componentid; + } + + Registry.currentDevice.addComponent(newComponent); } } @@ -161,20 +199,20 @@ export default class Selection { } for (let i in this.__connections) { - let render = Registry.currentDevice.getFeatureByID(this.__connections[i]); - bounds = render.bounds; - if (bounds.x < xmin) { - xmin = bounds.x; - } - if (bounds.y < ymin) { - ymin = bounds.y; - } - if (bounds.x > xmax) { - xmax = bounds.x; - } - if (bounds.y > ymax) { - ymax = bounds.y; - } + // let render = Registry.currentDevice.getFeatureByID(this.__connections[i]); + // bounds = render.bounds; + // if (bounds.x < xmin) { + // xmin = bounds.x; + // } + // if (bounds.y < ymin) { + // ymin = bounds.y; + // } + // if (bounds.x > xmax) { + // xmax = bounds.x; + // } + // if (bounds.y > ymax) { + // ymax = bounds.y; + // } } for (let i in this.__otherFeatures) {