Keep Copying the node

Hi,

how can I set a mode so that while I am dragging and dropping from palette I don’t have to pick the same node again and keep dropping the same node again and again?

I do not see how that would work – repeated drag-and-drops from one diagram to another could only copy whatever the user dragged. But you could use this tool: https://gojs.net/latest/api/symbols/ClickCreatingTool.html. Several samples demonstrate the use of that tool, including https://gojs.net/latest/samples/basic.html and https://gojs.net/latest/samples/systemDynamics.html.

Note particularly how it is used in that System Dynamics sample. The user can select one of three choices (Stock, Cloud, Variable) and from then on, a background click in the diagram creates an instance of that kind of node.

In your case where you are using a Palette with many and possibly varying nodes in it, you could have the selection of a node in the palette control what the main diagram’s ClickCreatingTool will do. Just implement a “ChangedSelection” DiagramEvent listener on the palette to set the ClickCreatingTool.archetypeNodeData on the main diagram. That includes setting it to null when there is nothing selected in the palette, which disables the ClickCreatingTool.

You might want to set https://gojs.net/latest/api/symbols/Diagram.html#maxSelectionCount to 1 on the palette.

Yes some thing like the system dynamics but should also have the node on the cursor while creating the nodes in diagram.

Have the https://gojs.net/latest/intro/events.html#ChangedSelection listener also set https://gojs.net/latest/api/symbols/Diagram.html#defaultCursor and https://gojs.net/latest/api/symbols/Diagram.html#currentCursor to an appropriate custom CSS cursor.

Can’t I use the same method by which you are assigning the cursor to be a node in the diagram while drag and drop.

GoJS can only do what HTML/CSS/DOM allows us to do: https://developer.mozilla.org/en-US/docs/Web/CSS/cursor

Yes so instead of assigning an image or url to the cursor can’t I use the method which you are using to create that cursor because I need the same cursor just without the drag drop.
At time of drag and drop the currentCursor for diagram is ‘copy’ but I tried assigning the same while starting or while assigning “SD.itemType”(in respect to system dynamics example) but it was not working.
Do I need to set some other property also?

I haven’t tried it, but I believe setting those two Diagram properties should be sufficient. Yes, if you want the cursor to look like some particular node, you will have to generate an image of it so that the CSS cursor can refer to it. If the image needs to depend on what the user has chosen, you have to do that work on demand.

I want it (click creation tool) to work on a group but that’s not working.
And how can we achieve the same cursor which is used while drag & drop where node is displayed with the cursor without generating the images as those are already generated in gojs and setting currentCursor= ‘copy’ is not working the same way.

A post was split to a new topic: ClickCreatingTool not working on a Group

A normal drag-and-drop does not change the cursor to be an image of the Nodes and Links that are being copied while being dragged. Instead the tool is moving a copy of the dragged Parts. Meanwhile the cursor does change, but only to a standard cursor: “copy”.

I thought you were asking to change the cursor while the mouse is over the background where the ClickCreatingTool could run if the user clicks. So what is it that you want?

Yes I need that exactly to have the same cursor at the time of click creating tool, that we use for drag and drop.
But I was also trying a single cursor only like when I am enabling this click creating tool I am setting
diagram.currentCursor = ‘crosshair’ but it’s not working from somewhere else in diagram it is getting overriden to ‘auto’.

Did you also set the Diagram.defaultCursor, as I first said above?

I think I missed that, let me try.

Hi @walter,
I was able to set the cursor but on undo of the all nodes I created the cursor is also getting set to auto at last undo point. Is there a way that we can ignore the cursor from transactions?

When did you set the Diagram.defaultCursor? If you did it in the Diagram initialization, before setting the Diagram.model, I think you’ll be OK, although I haven’t tested to be sure.

I am setting the defaultCursor when I am setting the mode to node copy, because all the other time and on diagram start I don’t want that cursor.

Oh, I see – in other words whenever the user changes the “mode”. OK – temporarily set Diagram.skipsUndoManager to true before setting Diagram.defaultCursor, and then set it back to false.