Replies: 3 comments 1 reply
-
I think I found a simple solution. In the override mouseMove(target: SModelElement, event: MouseEvent): Action[] {
// fetch the SVG element from the diagram panel...
const targetElement = event.target instanceof SVGElement ? event.target : undefined;
const svgParentElement = targetElement?.closest('svg');
if (svgParentElement) {
// draw a line...
const newLine = document.createElementNS('http://www.w3.org/2000/svg','line');
newLine.setAttribute('id','line2');
newLine.setAttribute('x1','0');
newLine.setAttribute('y1','0');
newLine.setAttribute('x2','200');
newLine.setAttribute('y2','200');
newLine.setAttribute("stroke", "green");
svgParentElement.appendChild(newLine);
}
return [];
} |
Beta Was this translation helpful? Give feedback.
-
Hi, You are making already great progress and are diving into the pretty advanced stuff in GLSP! Great! However, I'm not sure I'd recommend to create elements directly in the DOM from your mouse tool to draw something on the diagram as you suggest in your answer. A good example could be the Marquee feature: As you can see, this way, we benefit from the whole Sprotty approach, because
As mentioned in my answer to your other question, this sounds like a very interesting generic feature for GLSP, in case you'd be interested to contribute that. Thanks! |
Beta Was this translation helpful? Give feedback.
-
@planger I followed all your advice and finally completed the feature. You can check the implementation here: To integrate the module, the following bindings are needed: // bpmn helper lines
bind(TYPES.MouseListener).to(HelperLineListener);
configureCommand({ bind, isBound }, DrawHelperLinesCommand);
configureCommand({ bind, isBound }, RemoveHelperLinesCommand);
configureView({ bind, isBound }, 'helpline', HelperLineView); I will contribute this to your project if you like to reuse it or to customize it. For my BPMN elements I need to customize this solution now anyway. This is because the BPMN elements (Symbol and text underneath) is still a challenge to compute the correct center-point for the alignment. For the routing I solved this with a Port (same dimensions as the symbol) , but the uncommon layout requires again some tweeks for the helper lines. A |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to implement a HelperLine UIExtension that displays helper lines when the user is moving a node element in the diagram. The goal is to give visual feedback for aliment several elements in line.
My first question was how to get a event listener reacting on a mouse-move event. I think I solved this by registering a
MouseListener
and injecting aSelectionService
. So I am now able to calculate helper lines based on the surrounding elements. (I'm a bit proud that I was able to solve this).But now I need some help how to draw some lines into the diagram out from my MouseMove event. I have the selected Element (
SModelElement
) and the root element (SRootElement
)I think the Helper Line Feature can be in some way similar to the marquee tool. So I tried to implement a HelpLIneNode and a HelpLineView......
In the render method I can render some SVG lines or rectangle showing the alignment hints. That's my idea so far.....
But is this the right approach? What I did not figure out is how to add or remove an instance of my HelpLineNode to the Diagram Root as a reaction to the current mouseMove event.
Is this possible or is it an idiotic idea? I had already thought about of simply painting lines into the diagram within my UIExtension, but that feels kind of wrong.
Beta Was this translation helpful? Give feedback.
All reactions