Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restricting Connections #56

Closed
InannaInai opened this issue Sep 26, 2019 · 1 comment
Closed

Restricting Connections #56

InannaInai opened this issue Sep 26, 2019 · 1 comment

Comments

@InannaInai
Copy link

Dear freegroup,

is it possible to restrict connections?

For example, a connection should be able between two rects and two diamonds, but not between a rect and a diamond.

Maybe I've missed the example?

Best regards

@InannaInai
Copy link
Author

I'll answer my own question as I've found the solution:

You have to create your own:
var DragConnectionCreatePolicy = draw2d.policy.connection.DragConnectionCreatePolicy.extend({})

and then edit the
onMouseUp: function(canvas, x, y, shiftKey, ctrlKey)

There you can add an if-statement and change the code:

if(this.currentDropTarget instanceof draw2d.Port){
                    var request = new draw2d.command.CommandType(draw2d.command.CommandType.CONNECT);
                    request.source = this.currentDropTarget;
                    request.target = this.mouseDraggingElement;
                    var command = this.mouseDraggingElement.createCommand(request);

                    if(command!==null){
                        command.setConnection(this.createConnection());
                        canvas.getCommandStack().execute(command);
                        this.currentDropTarget.onCatch(this.mouseDraggingElement, x, y, shiftKey, ctrlKey);
                    }
                }

to -->

if((this.mouseDownElement.parent instanceof customButton1&& this.currentDropTarget.parent instanceof customButton1)
                	|| 	(this.mouseDownElement.parent instanceof customButton2&& this.currentDropTarget.parent instanceof customButton1)
                	|| 	(this.mouseDownElement.parent instanceof customButton1&& this.currentDropTarget.parent instanceof customButton2)
                	|| 	(this.mouseDownElement.parent instanceof customButton3&& this.currentDropTarget.parent instanceof customButton2)
                	|| 	(this.mouseDownElement.parent instanceof customButton3&& this.currentDropTarget.parent instanceof customButton1)){
                if(this.currentDropTarget instanceof draw2d.Port){
                    var request = new draw2d.command.CommandType(draw2d.command.CommandType.CONNECT);
                    request.source = this.currentDropTarget;
                    request.target = this.mouseDraggingElement;
                    var command = this.mouseDraggingElement.createCommand(request);

                    if(command!==null){
                        command.setConnection(this.createConnection());
                        canvas.getCommandStack().execute(command);
                        this.currentDropTarget.onCatch(this.mouseDraggingElement, x, y, shiftKey, ctrlKey);
                    }
                }
                }

The customButton1 in this case are the custom created figures (rectsm diamonds,...).

Hopefully that helps someone else

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant