forked from workcraft/workcraft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add transformation command to split nodes
Initially apply this command to FSM states and STG transitions. Closes workcraft#1528
- Loading branch information
1 parent
4910e34
commit 81f15e0
Showing
6 changed files
with
415 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...aft/FsmPlugin/src/org/workcraft/plugins/fsm/commands/SplitStateTransformationCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...tgPlugin/src/org/workcraft/plugins/stg/commands/SplitTransitionTransformationCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |
Oops, something went wrong.