Skip to content

Commit

Permalink
optimization
Browse files Browse the repository at this point in the history
Issue #319
  • Loading branch information
rsoika committed Feb 15, 2024
1 parent b3c8990 commit bf82ca9
Show file tree
Hide file tree
Showing 19 changed files with 454 additions and 455 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ export class LaneDividerView extends ShapeView {
}

/*
* Render a Multi-Line BPN Label
* Render a Multi-Line BPMN Label
*/
@injectable()
export class MultiLineTextNodeView extends ShapeView {
Expand Down
32 changes: 32 additions & 0 deletions open-bpmn.glsp-client/open-bpmn-glsp/src/bpmn-select-listeners.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export class BPMNElementSnapper implements ISnapper {
constructor(public grid: { x: number; y: number } = { x: 1, y: 1 }) { }

snap(position: Point, _element: GModelElement): Point {

// if (isLaneDivider(_element)) {
// return this.findLaneDividerSnapPoint(_element, position);
// }

// move routing-points by 5x5
if ('volatile-routing-point' === _element.type) {
return {
Expand All @@ -64,6 +69,33 @@ export class BPMNElementSnapper implements ISnapper {
y: Math.round(position.y / this.grid.y) * this.grid.y
};
}

/*
* This helper method computes the snap Position of a Lane-Divider.
* The position is based on the Bounds of the containing Pool.
* The final position is always on the x position of the Pool.
*/
/*
private findLaneDividerSnapPoint(element: GModelElement, position: Point): Point {
const x = 0;
let y = position.y;
console.log(' snap lane devider current pos = ' + x + ',' + y)
// test min / max position
if (hasArgs(element)) {
const yMin = Number(element.args.ymin);
const yMax = Number(element.args.ymax);
if (y < yMin) {
y = yMin;
}
if (y > yMax) {
y = yMax;
}
}
// return the new position;
return { x: x, y: y };
}
*/
}

/**
Expand Down
5 changes: 4 additions & 1 deletion open-bpmn.glsp-client/open-bpmn-glsp/src/di.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
GGraph,
GLabel,
GLabelView,
HelperLineType,
IHelperLineOptions,
LogLevel,
RectangularNodeView,
Expand Down Expand Up @@ -89,9 +90,11 @@ const bpmnDiagramModule = new ContainerModule((bind, unbind, isBound, rebind) =>
// bpmn helper lines
bind(TYPES.ISnapper).toConstantValue(new BPMNElementSnapper());
bind<IHelperLineOptions>(TYPES.IHelperLineOptions).toConstantValue({
elementLines: [HelperLineType.Center, HelperLineType.Middle], // only show center and middle lines
viewportLines: [], // do not show alignment lines for viewport
alignmentElementFilter: element =>
isBPMNNode(element) && !isBoundaryEvent(element),
minimumMoveDelta: { x: 15, y: 15 }
minimumMoveDelta: { x: 10, y: 10 }
});

// bind new SelectionListener for BPMNLabels and BoundaryEvents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@
import org.openbpmn.glsp.model.BPMNGModelState;
import org.openbpmn.glsp.model.BPMNSourceModelStorage;
import org.openbpmn.glsp.operations.BPMNApplyPropertiesUpdateOperationHandler;
import org.openbpmn.glsp.operations.BPMNAutoAlignActionHandler;
import org.openbpmn.glsp.operations.BPMNAutoAlignOperationHandler;
import org.openbpmn.glsp.operations.BPMNChangeBoundsOperationHandler;
import org.openbpmn.glsp.operations.BPMNChangeRoutingPointsOperationHandler;
import org.openbpmn.glsp.operations.BPMNClipboardDataActionHandler;
import org.openbpmn.glsp.operations.BPMNComputedBoundsActionHandler;
import org.openbpmn.glsp.operations.BPMNDeleteNodeHandler;
import org.openbpmn.glsp.operations.BPMNPasteOperationHandler;
import org.openbpmn.glsp.operations.BPMNReconnectEdgeOperationHandler;
import org.openbpmn.glsp.operations.BPMNResetRoutingActionHandler;
import org.openbpmn.glsp.operations.BPMNResetRoutingOperationHandler;
import org.openbpmn.glsp.provider.BPMNCommandPaletteActionProvider;
import org.openbpmn.glsp.provider.BPMNToolPaletteItemProvider;
import org.openbpmn.glsp.validators.BPMNGLSPValidator;
Expand Down Expand Up @@ -112,19 +112,11 @@ protected Class<? extends GModelFactory> bindGModelFactory() {
@Override
protected void configureActionHandlers(final MultiBinding<ActionHandler> binding) {
super.configureActionHandlers(binding);

// Clipboard
binding.add(BPMNClipboardDataActionHandler.class);

// Compute Routing Points
binding.add(BPMNComputedBoundsActionHandler.class);

// Clar Routing Points
binding.add(BPMNResetRoutingActionHandler.class);

// Auto Align all elements
binding.add(BPMNAutoAlignActionHandler.class);

}

@Override
Expand Down Expand Up @@ -177,6 +169,10 @@ protected void configureOperationHandlers(final MultiBinding<OperationHandler<?>
// Extension handler
binding.add(BPMNCreateExtensionHandler.class);

// Clar Routing Points
binding.add(BPMNResetRoutingOperationHandler.class);
// Reset Alignment
binding.add(BPMNAutoAlignOperationHandler.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void executeOperation(final CreateNodeOperation operation) {

if (point.isPresent()) {
// compute relative center position...
BPMNPoint targetPosition = BPMNGridSnapper.snap(event, point.get());
BPMNPoint targetPosition = BPMNGridSnapper.center(event, point.get());
// compute default label position
double labelX = targetPosition.getX() + (Event.DEFAULT_WIDTH / 2) - (BPMNLabel.DEFAULT_WIDTH / 2);
double labelY = targetPosition.getY() + Event.DEFAULT_HEIGHT + Event.LABEL_OFFSET;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void executeOperation(final CreateNodeOperation operation) {
Gateway gateway = bpmnProcess.addGateway(gatewayID, getLabel(), operation.getElementTypeId());
Optional<GPoint> point = operation.getLocation();
if (point.isPresent()) {
BPMNPoint targetPosition = BPMNGridSnapper.snap(gateway, point.get());
BPMNPoint targetPosition = BPMNGridSnapper.center(gateway, point.get());
gateway.setPosition(targetPosition);
gateway.setDimension(Gateway.DEFAULT_WIDTH, Gateway.DEFAULT_HEIGHT);
// set label bounds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void executeOperation(final CreateNodeOperation operation) {
if (point.isPresent()) {
// set the bounds
// participant.setPosition(point.get().getX(), point.get().getY());
participant.setPosition(BPMNGridSnapper.snap(point.get().getX(), point.get().getY()));
participant.setPosition(BPMNGridSnapper.center(participant, point.get()));
participant.setDimension(Participant.DEFAULT_WIDTH, Participant.DEFAULT_HEIGHT);
}
} catch (BPMNModelException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected void executeOperation(final CreateNodeOperation operation) {
Activity task = bpmnProcess.addTask(taskID, getLabel(), operation.getElementTypeId());
Optional<GPoint> point = operation.getLocation();
if (point.isPresent()) {
BPMNPoint targetPosition = BPMNGridSnapper.snap(task, point.get());
BPMNPoint targetPosition = BPMNGridSnapper.center(task, point.get());
task.setPosition(targetPosition);
task.setDimension(Activity.DEFAULT_WIDTH, Activity.DEFAULT_HEIGHT);
logger.debug("new BPMNActivity Position = " + targetPosition.getX() + "," + targetPosition.getY());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

import java.util.List;

import org.eclipse.glsp.server.actions.Action;
import org.eclipse.glsp.server.operations.Operation;

/**
* Action defintion to auto align all elements to the grid
*
*/
public class BPMNAutoAlignAction extends Action {
public class BPMNAutoAlignOperation extends Operation {

public static final String KIND = "autoAlign";

private List<String> elementIds;

public BPMNAutoAlignAction() {
public BPMNAutoAlignOperation() {
super(KIND);
}

public BPMNAutoAlignAction(final List<String> elementIds) {
public BPMNAutoAlignOperation(final List<String> elementIds) {
super(KIND);
this.elementIds = elementIds;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/********************************************************************************
* Copyright (c) 2022 Imixs Software Solutions GmbH and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
package org.openbpmn.glsp.operations;

import java.util.Optional;
import java.util.Set;
import java.util.logging.Logger;

import org.eclipse.emf.common.command.Command;
import org.eclipse.glsp.server.operations.GModelOperationHandler;
import org.openbpmn.bpmn.elements.BPMNProcess;
import org.openbpmn.bpmn.elements.Participant;
import org.openbpmn.bpmn.elements.core.BPMNElementNode;
import org.openbpmn.glsp.model.BPMNGModelState;
import org.openbpmn.glsp.utils.BPMNGridSnapper;

import com.google.inject.Inject;

/**
* This ActionHandler reacts on AutoAlign actions send from the client
*
* @author rsoika
*
*/
public class BPMNAutoAlignOperationHandler extends GModelOperationHandler<BPMNAutoAlignOperation> {

private static Logger logger = Logger.getLogger(BPMNAutoAlignOperationHandler.class.getName());

@Inject
protected BPMNGModelState modelState;

@Override
public Optional<Command> createCommand(BPMNAutoAlignOperation operation) {

return commandOf(() -> {

logger.finest("Auto align all elements....");
Set<Participant> participants = modelState.getBpmnModel().getParticipants();
for (Participant participant : participants) {
BPMNGridSnapper.snap(participant);
}

Set<BPMNProcess> processList = modelState.getBpmnModel().getProcesses();
for (BPMNProcess process : processList) {
// snap all elements
Set<BPMNElementNode> allNodes = process.getAllFlowElementNodes();
for (BPMNElementNode _node : allNodes) {
BPMNGridSnapper.snap(_node);
}
}
modelState.reset();
});
}

}
Loading

0 comments on commit bf82ca9

Please sign in to comment.