Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ nbproject/private/
out/
.idea/workspace.xml
.idea/tasks.xml
/bin/
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
PNEditor (Petri Net editor)
========
Status of the different branches :

- Invariant : adds a token limit on places
- MacroRecorder : abandonned branche (a version of macro that had modifications from invariant)
- MacroRecorderClean : adds a macro manager
- MacroLimit : integrates the token limit and the macro manager
- macroAndTokenLimit : integrates the token limit, the macro manager and the fire N modification
from https://github.com/e17goudi/pneditor. due to some modifications on the marking class there,
this version compile but has some bugs (try to find them !)



You can download PNEditor from [www.pneditor.org](http://www.pneditor.org/)

Expand Down
20 changes: 18 additions & 2 deletions src/org/pneditor/editor/Root.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public JPopupMenu getCanvasPopup() {

//per application
private JToggleButton select, place, transition, arc, token;
private Action setLabel, setTokens, setArcMultiplicity, setArcInhibitory, setArcReset, delete;
private Action setLabel, setTokens, setArcMultiplicity, setArcInhibitory, setArcReset, delete, setTokenLimit;
private Action setPlaceStatic;
private Action addSelectedTransitionsToSelectedRoles;
private Action removeSelectedTransitionsFromSelectedRoles;
Expand Down Expand Up @@ -335,6 +335,15 @@ private void enableOnlyPossibleActions() {
boolean roleSelected = !roleEditor.getSelectedElements().isEmpty();
boolean isParent = !document.petriNet.isCurrentSubnetRoot();
boolean isPtoT = false;
boolean isStaticPlaceNode = false;
boolean isLimitedPlaceNode = false;

if (isPlaceNode) {
isStaticPlaceNode = ((PlaceNode) clickedElement).isStatic();
isLimitedPlaceNode = ((PlaceNode) clickedElement).getTokenLimit()!=0;
}



if (isArc) {
Arc test;
Expand All @@ -352,6 +361,7 @@ private void enableOnlyPossibleActions() {
setArcReset.setEnabled(isPtoT);
setTokens.setEnabled(isPlaceNode);
setLabel.setEnabled(isPlaceNode || isTransitionNode);
setTokenLimit.setEnabled(!isStaticPlaceNode);
addSelectedTransitionsToSelectedRoles.setEnabled((isTransitionNode || areTransitionNodes) && roleSelected);
removeSelectedTransitionsFromSelectedRoles.setEnabled((isTransitionNode || areTransitionNodes) && roleSelected);
convertTransitionToSubnet.setEnabled(isTransition || areTransitions || isSubnet || areSubnets);
Expand All @@ -361,7 +371,7 @@ private void enableOnlyPossibleActions() {
closeSubnet.setEnabled(isParent);
undo.setEnabled(getUndoManager().isUndoable());
redo.setEnabled(getUndoManager().isRedoable());
setPlaceStatic.setEnabled(isPlaceNode);
setPlaceStatic.setEnabled(!isLimitedPlaceNode);
}

@Override
Expand Down Expand Up @@ -450,6 +460,7 @@ private void setupMainFrame() {
Action quit = new QuitAction(this);
setLabel = new SetLabelAction(this);
setTokens = new SetTokensAction(this);
setTokenLimit = new SetTokenLimitAction(this);
setPlaceStatic = new SetPlaceStaticAction(this);
setArcMultiplicity = new SetArcMultiplicityAction(this);
setArcInhibitory = new SetArcInhibitoryAction(this);
Expand Down Expand Up @@ -582,6 +593,7 @@ private void setupMainFrame() {
elementMenu.add(setLabel);
elementMenu.addSeparator();
elementMenu.add(setTokens);
elementMenu.add(setTokenLimit);
elementMenu.add(setPlaceStatic);
elementMenu.addSeparator();
elementMenu.add(setArcMultiplicity);
Expand All @@ -606,15 +618,18 @@ private void setupMainFrame() {

placePopup = new JPopupMenu();
placePopup.add(setLabel);
placePopup.add(setTokenLimit);
placePopup.add(setTokens);
placePopup.add(setPlaceStatic);
placePopup.addSeparator();
placePopup.add(cutAction);
placePopup.add(copyAction);
placePopup.add(delete);


transitionPopup = new JPopupMenu();
transitionPopup.add(setLabel);

transitionPopup.add(convertTransitionToSubnet);
transitionPopup.add(addSelectedTransitionsToSelectedRoles);
transitionPopup.add(removeSelectedTransitionsFromSelectedRoles);
Expand All @@ -632,6 +647,7 @@ private void setupMainFrame() {
subnetPopup = new JPopupMenu();
subnetPopup.add(openSubnet).setFont(boldFont);
subnetPopup.add(setLabel);
//subnetPopup.add(setTokenLimit);
subnetPopup.add(replaceSubnet);
subnetPopup.add(saveSubnetAs);
subnetPopup.add(convertTransitionToSubnet);
Expand Down
5 changes: 4 additions & 1 deletion src/org/pneditor/editor/actions/SetPlaceStaticAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public SetPlaceStaticAction(Root root) {
public void actionPerformed(ActionEvent e) {
if (root.getClickedElement() instanceof PlaceNode) {
PlaceNode placeNode = (PlaceNode) root.getClickedElement();
root.getUndoManager().executeCommand(new SetUnsetPlaceStaticCommand(placeNode));
if (placeNode.getTokenLimit()==0)
{
root.getUndoManager().executeCommand(new SetUnsetPlaceStaticCommand(placeNode));
}
}
}

Expand Down
83 changes: 83 additions & 0 deletions src/org/pneditor/editor/actions/SetTokenLimitAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (C) 2008-2010 Martin Riesz <riesz.martin at gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.pneditor.editor.actions;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import org.pneditor.editor.Root;
import org.pneditor.editor.commands.SetTokenLimitCommand;
import org.pneditor.petrinet.Marking;
import org.pneditor.petrinet.Place;
import org.pneditor.petrinet.PlaceNode;
import org.pneditor.util.GraphicsTools;

/**
*
* @author Ladislas Ducerf <ladislas.ducerf at gmail.com>
*/

/*
*
* S'inspirer de setTokenAction ?
* Notamment pour cas de mauvais input
*/
public class SetTokenLimitAction extends AbstractAction {

private Root root;

public SetTokenLimitAction(Root root) {
this.root = root;
String name = "Set token limit";
putValue(NAME, name);
putValue(SMALL_ICON, GraphicsTools.getIcon("pneditor/tokenLimit.gif"));
putValue(SHORT_DESCRIPTION, name);
setEnabled(false);
}


public void actionPerformed(ActionEvent e) {
Marking initialMarking = root.getDocument().petriNet.getInitialMarking();
if (root.getClickedElement() != null) {
if (root.getClickedElement() instanceof PlaceNode) {
PlaceNode placeNode = (PlaceNode) root.getClickedElement();
int tokenLimit = placeNode.getTokenLimit();
String response = JOptionPane.showInputDialog(root.getParentFrame(), "Token limit (0 = no limit) :", tokenLimit);
if (response != null) {
try {
tokenLimit = Integer.parseInt(response);
} catch (NumberFormatException exception) {
JOptionPane.showMessageDialog(root.getParentFrame(), exception.getMessage() + " is not a number");
}

if (tokenLimit < 0) {
tokenLimit = placeNode.getTokenLimit(); // restore old value
JOptionPane.showMessageDialog(root.getParentFrame(), "Token limit must be non-negative");
}
}

if (placeNode.getTokenLimit() != tokenLimit) {
//placeNode.setTokenLimit(tokenLimit);
root.getUndoManager().executeCommand(new SetTokenLimitCommand(placeNode, tokenLimit, initialMarking));
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public void actionPerformed(ActionEvent e) {
}

if (isUnboundedness) {
JOptionPane.showMessageDialog(root.getParentFrame(), "PetriNet is NOT bounded ", "Algorithm output", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(root.getParentFrame(), "PetriNet is NOT bounded \n(This ignore token limits)", "Algorithm output", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(root.getParentFrame(), "PetriNet is bounded", "Algorithm output", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(root.getParentFrame(), "PetriNet is bounded \n(This ignore token limits)", "Algorithm output", JOptionPane.INFORMATION_MESSAGE);
}
}

Expand Down Expand Up @@ -112,7 +112,7 @@ private boolean isOmega(Marking newMarking, Marking oldMarking) {

Place oldMarkingPlace = null;
for (Place place : oldMarkingPlaces) {
if (place.equals(newMarkingPlace)) {
if (place.equals(newMarkingPlace)) {
oldMarkingPlace = place;
break;
}
Expand All @@ -123,10 +123,9 @@ private boolean isOmega(Marking newMarking, Marking oldMarking) {
if (!(newTokens >= oldTokens)) {
return false;
} else if (newTokens > oldTokens) {
isOneSharplyHigher = true;
isOneSharplyHigher = true;
}

}
}

if (isOneSharplyHigher) {
return true;
Expand Down
5 changes: 4 additions & 1 deletion src/org/pneditor/editor/commands/AddTokenCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ public AddTokenCommand(PlaceNode placeNode, Marking marking) {
this.marking = marking;
}

private int oldValue;

public void execute() {
oldValue = marking.getTokens(placeNode);
marking.setTokens(placeNode, marking.getTokens(placeNode) + 1);
}

public void undo() {
new RemoveTokenCommand(placeNode, marking).execute();
marking.setTokens(placeNode, oldValue);
}

public void redo() {
Expand Down
64 changes: 64 additions & 0 deletions src/org/pneditor/editor/commands/SetTokenLimitCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2008-2010 Martin Riesz <riesz.martin at gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.pneditor.editor.commands;

import org.pneditor.petrinet.Marking;
import org.pneditor.petrinet.PlaceNode;
import org.pneditor.util.Command;

/**
*
* @author Ladislas Ducerf <ladislas.ducerf at gmail.com>
*/
public class SetTokenLimitCommand implements Command {

private PlaceNode placeNode;
private int newLimitValue;
private Marking marking;


public SetTokenLimitCommand(PlaceNode placeNode, int limit, Marking marking) {
this.placeNode = placeNode;
this.newLimitValue = limit;
this.marking = marking;
}

private int oldLimitValue;
private int oldTokenValue;


public void execute() {
this.oldTokenValue = marking.getTokens(placeNode);
this.oldLimitValue = placeNode.getTokenLimit();

placeNode.setTokenLimit(newLimitValue);
}

public void undo() {
this.placeNode.setTokenLimit(oldLimitValue);
this.marking.setTokens(this.placeNode, this.oldTokenValue);
}

public void redo() {
execute();
}

@Override
public String toString() {
return "Set/unset place node token limit";
}
}
Loading