Skip to content

Commit

Permalink
Add transformation command to split nodes
Browse files Browse the repository at this point in the history
Initially apply this command to FSM states and STG transitions.

Closes workcraft#1528
  • Loading branch information
danilovesky committed Dec 17, 2024
1 parent 4910e34 commit 81f15e0
Show file tree
Hide file tree
Showing 6 changed files with 415 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ private void initPluginManager() {

ScriptableCommandUtils.registerCommand(MergeStateTransformationCommand.class, "transformFsmMergeState",
"transform the FSM/FST 'work' by merging selected states");
ScriptableCommandUtils.registerCommand(SplitStateTransformationCommand.class, "transformFsmSplitState",
"transform the FSM/FST 'work' by splitting selected states");
ScriptableCommandUtils.registerCommand(ContractStateTransformationCommand.class, "transformFsmContractState",
"transform the FSM/FST 'work' by contracting selected states");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.workcraft.plugins.fsm.commands;

import org.workcraft.commands.AbstractSplitTransformationCommand;
import org.workcraft.dom.visual.VisualComponent;
import org.workcraft.dom.visual.VisualModel;
import org.workcraft.dom.visual.VisualNode;
import org.workcraft.plugins.fsm.VisualFsm;
import org.workcraft.plugins.fsm.VisualState;
import org.workcraft.utils.WorkspaceUtils;
import org.workcraft.workspace.ModelEntry;
import org.workcraft.workspace.WorkspaceEntry;

public final class SplitStateTransformationCommand extends AbstractSplitTransformationCommand {

public SplitStateTransformationCommand() {
registerSplittableClass(VisualState.class);
}

@Override
public String getDisplayName() {
return "Split selected states";
}

@Override
public String getPopupName(ModelEntry me, VisualNode node) {
return "Split state";
}

@Override
public boolean isApplicableTo(WorkspaceEntry we) {
return WorkspaceUtils.isApplicable(we, VisualFsm.class);
}

@Override
public VisualComponent createDuplicate(VisualModel model, VisualComponent component) {
VisualComponent result = super.createDuplicate(model, component);
if ((component instanceof VisualState state) && (result instanceof VisualState newState)) {
newState.getReferencedComponent().setInitial(state.getReferencedComponent().isInitial());
}
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ private void initPluginManager() {
"transform the STG 'work' by contracting a selected transition");
ScriptableCommandUtils.registerCommand(MergeTransitionTransformationCommand.class, "transformStgMergeTransition",
"transform the STG 'work' by merging selected transitions");
ScriptableCommandUtils.registerCommand(SplitTransitionTransformationCommand.class, "transformStgSplitTransition",
"transform the STG 'work' by splitting selected transitions");
ScriptableCommandUtils.registerCommand(InsertDummyTransformationCommand.class, "transformStgInsertDummy",
"transform the STG 'work' by inserting dummies into selected arcs");
ScriptableCommandUtils.registerCommand(InsertInputTransformationCommand.class, "transformStgInsertInputTransition",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.workcraft.plugins.stg.commands;

import org.workcraft.commands.AbstractSplitTransformationCommand;
import org.workcraft.dom.visual.VisualComponent;
import org.workcraft.dom.visual.VisualModel;
import org.workcraft.dom.visual.VisualNode;
import org.workcraft.dom.visual.connections.VisualConnection;
import org.workcraft.plugins.petri.VisualReadArc;
import org.workcraft.plugins.petri.utils.ConversionUtils;
import org.workcraft.plugins.stg.VisualDummyTransition;
import org.workcraft.plugins.stg.VisualNamedTransition;
import org.workcraft.plugins.stg.VisualSignalTransition;
import org.workcraft.plugins.stg.VisualStg;
import org.workcraft.utils.Hierarchy;
import org.workcraft.utils.WorkspaceUtils;
import org.workcraft.workspace.ModelEntry;
import org.workcraft.workspace.WorkspaceEntry;

public final class SplitTransitionTransformationCommand extends AbstractSplitTransformationCommand {

public SplitTransitionTransformationCommand() {
registerSplittableClass(VisualNamedTransition.class);
}

@Override
public String getDisplayName() {
return "Split selected transition";
}

@Override
public String getPopupName(ModelEntry me, VisualNode node) {
return "Split transition";
}

@Override
public boolean isApplicableTo(WorkspaceEntry we) {
return WorkspaceUtils.isApplicable(we, VisualStg.class);
}

@Override
public void beforeNodeTransformation(VisualModel model, VisualNode node) {
if (model instanceof VisualStg stg) {
for (VisualConnection connection : stg.getConnections(node)) {
if (connection instanceof VisualReadArc readArc) {
ConversionUtils.convertReadArcTotDualArc(model, readArc);
}
}
}
}

@Override
public VisualComponent createDuplicate(VisualModel model, VisualComponent component) {
if (model instanceof VisualStg stg) {
if (component instanceof VisualDummyTransition dummyTransition) {
VisualDummyTransition result = stg.createVisualDummyTransition(stg.getMathName(dummyTransition),
Hierarchy.getNearestContainer(component));

result.copyPosition(component);
return result;
}
if (component instanceof VisualSignalTransition signalTransition) {
VisualSignalTransition result = stg.createVisualSignalTransition(stg.getSignalReference(signalTransition),
signalTransition.getSignalType(), signalTransition.getDirection(),
Hierarchy.getNearestContainer(component));

result.copyPosition(component);
return result;
}
}
return super.createDuplicate(model, component);
}

@Override
public void removeOriginalComponentAndInheritName(VisualModel model, VisualComponent component,
VisualComponent firstComponent, VisualComponent secondComponent) {

model.remove(component);
// Split transitions do not need renaming as are instances of the original one
}

}
Loading

0 comments on commit 81f15e0

Please sign in to comment.