201
192
Arc transportArcToCreate = view.createArc;
203
if (currentObject != transportArcToCreate.getSource()) {
205
transportArcToCreate.setSelectable(true);
207
// This is the first step
208
if (transportArcToCreate.getSource() instanceof Place) {
210
// mikaelhm - Dont allow a transport arc from place to
211
// transition if there is another arc.
212
boolean existsArc = false;
214
// Check if arc has leagal target
215
PlaceTransitionObject target = transportArcToCreate
217
if (!(target instanceof Transition && target != null)) {
218
System.err.println("Error creating transport arc, invalid target");
219
transportArcToCreate.delete();
223
Iterator<Arc> arcsFrom = transportArcToCreate
224
.getSource().getConnectFromIterator();
225
// search for pre-existent arcs from transportArcToCreate's source to
226
// transportArcToCreate's target
227
while (arcsFrom.hasNext()) {
228
Arc someArc = (arcsFrom.next());
229
if (someArc == transportArcToCreate) {
231
} else if (someArc.getSource() == transportArcToCreate.getSource() && someArc.getTarget() == currentObject) {
234
if (someArc instanceof TimedInhibitorArcComponent) {
235
// user has drawn a transport arc where there is
236
// a TAPNInhibitorArc arc already - This does not make sense.
237
cleanupArc(transportArcToCreate, view);
238
System.out.println(ERROR_MSG_TWO_ARCS);
239
JOptionPane.showMessageDialog(
243
JOptionPane.ERROR_MESSAGE);
245
} else if (someArc instanceof TimedTransportArcComponent) {
246
// user has drawn a transport arc where there is
247
// a transport arc already - We do not allow that.
248
cleanupArc(transportArcToCreate, view);
249
System.out.println(ERROR_MSG_TWO_ARCS);
250
JOptionPane.showMessageDialog(CreateGui
251
.getApp(), ERROR_MSG_TWO_ARCS,
252
"Error", JOptionPane.ERROR_MESSAGE);
254
} else if (someArc instanceof TimedOutputArcComponent) {
255
// user has drawn a transport arc where there is
256
// a normal arc already - We do not allow that.
257
cleanupArc(transportArcToCreate, view);
258
System.out.println(ERROR_MSG_TWO_ARCS);
259
JOptionPane.showMessageDialog(CreateGui
260
.getApp(), ERROR_MSG_TWO_ARCS,
261
"Error", JOptionPane.ERROR_MESSAGE);
268
transportArcToCreate.delete();
272
int groupMaxCounter = 0;
274
for (Object pt : transportArcToCreate.getTarget()
276
if (pt instanceof TimedTransportArcComponent) {
277
if (((TimedTransportArcComponent) pt).getGroupNr() > groupMaxCounter) {
278
groupMaxCounter = ((TimedTransportArcComponent) pt).getGroupNr();
283
((TimedTransportArcComponent) transportArcToCreate).setGroupNr(groupMaxCounter + 1);
285
currentObject.addConnectTo(transportArcToCreate);
287
// Evil hack to prevent the arc being added to GuiView
289
contentPane.remove(transportArcToCreate);
291
guiModel.addArc((TimedOutputArcComponent) transportArcToCreate);
292
view.addNewPetriNetObject(transportArcToCreate);
294
freeArc(transportArcToCreate);
296
// Create the next arc
297
TimedTransportArcComponent arc2 = new TimedTransportArcComponent(currentObject, groupMaxCounter + 1, false);
299
//Update the partners for the arcs
300
TimedTransportArcComponent arc1 = ((TimedTransportArcComponent) transportArcToCreate);
302
arc2.setConnectedTo(arc1);
303
arc1.setConnectedTo(arc2);
305
//Draw part 2 of the transport arc
306
createArc(arc2, currentObject);
309
} else if (transportArcToCreate.getSource() instanceof Transition) {
311
TimedTransportArcComponent arc2 = (TimedTransportArcComponent) transportArcToCreate;
312
TimedTransportArcComponent arc1 = arc2.getConnectedTo();
314
dk.aau.cs.model.tapn.TransportArc ta;
316
ta = new dk.aau.cs.model.tapn.TransportArc(
317
((TimedPlaceComponent) arc1.getSource()).underlyingPlace(),
318
((TimedTransitionComponent) arc2.getSource()).underlyingTransition(),
319
((TimedPlaceComponent) arc2.getTarget()).underlyingPlace(),
320
TimeInterval.ZERO_INF);
322
((TimedTransportArcComponent) transportArcToCreate).setUnderlyingArc(ta);
323
arc1.setUnderlyingArc(ta);
324
arc1.updateLabel(true);
325
((TimedTransportArcComponent) transportArcToCreate).updateLabel(true);
326
} catch (RequireException ex) {
327
cleanupArc(arc1, view);
328
cleanupArc(arc2, view);
194
if (currentObject != transportArcToCreate.getSource()) {
196
transportArcToCreate.setSelectable(true);
198
// This is the first step
199
if (transportArcToCreate.getSource() instanceof Place) {
201
// mikaelhm - Dont allow a transport arc from place to
202
// transition if there is another arc.
203
boolean existsArc = false;
205
// Check if arc has leagal target
206
PlaceTransitionObject target = transportArcToCreate.getTarget();
207
if (!(target instanceof Transition)) {
208
transportArcToCreate.delete();
212
Iterator<Arc> arcsFrom = transportArcToCreate.getSource().getConnectFromIterator();
213
// search for pre-existent arcs from transportArcToCreate's source to
214
// transportArcToCreate's target
215
while (arcsFrom.hasNext()) {
216
Arc someArc = (arcsFrom.next());
217
if (someArc == transportArcToCreate) {
219
} else if (someArc.getSource() == transportArcToCreate.getSource() && someArc.getTarget() == currentObject) {
222
// There already is a arc between this place and transition
223
cleanupArc(transportArcToCreate, view);
329
224
JOptionPane.showMessageDialog(
331
"There was an error drawing the arc. Possible problems:\n"
332
+ " - There is already an arc between the source place and transition\n"
333
+ " - There is already an arc between the transtion and the target place\n"
334
+ " - You are attempting to draw an arc between a shared transition and a shared place",
335
"Error", JOptionPane.ERROR_MESSAGE);
339
// Evil hack to prevent the arc being added to GuiView
341
contentPane.remove(arc2);
343
guiModel.addArc(arc2);
344
view.addNewPetriNetObject(arc2);
346
currentObject.addConnectTo(arc2);
348
undoManager.newEdit();
351
new AddTransportArcCommand(
353
arc2.underlyingTransportArc(),
358
freeArc(transportArcToCreate);
360
arc2.setGroupNr(arc1.getGroupNr());
228
JOptionPane.ERROR_MESSAGE);
232
transportArcToCreate.delete();
236
int groupMaxCounter = 0;
238
for (Object pt : transportArcToCreate.getTarget().getPostset()) {
239
if (pt instanceof TimedTransportArcComponent) {
240
if (((TimedTransportArcComponent) pt).getGroupNr() > groupMaxCounter) {
241
groupMaxCounter = ((TimedTransportArcComponent) pt).getGroupNr();
246
((TimedTransportArcComponent) transportArcToCreate).setGroupNr(groupMaxCounter + 1);
248
currentObject.addConnectTo(transportArcToCreate);
250
// Evil hack to prevent the arc being added to GuiView twice
251
//Need to be casted to cointainer, as we only add it to the canvas but not the model
252
((Container) CreateGui.getDrawingSurface()).remove(transportArcToCreate);
254
view.getGuiModel().addArc((TimedOutputArcComponent) transportArcToCreate);
255
view.addNewPetriNetObject(transportArcToCreate);
257
freeArc(transportArcToCreate);
259
// Create the next arc
260
TimedTransportArcComponent arc2 = new TimedTransportArcComponent(currentObject, groupMaxCounter + 1, false);
262
//Update the partners for the arcs
263
TimedTransportArcComponent arc1 = ((TimedTransportArcComponent) transportArcToCreate);
265
arc2.setConnectedTo(arc1);
266
arc1.setConnectedTo(arc2);
268
//Draw part 2 of the transport arc
269
createArc(arc2, currentObject);
272
} else if (transportArcToCreate.getSource() instanceof Transition) {
274
TimedTransportArcComponent arc2 = (TimedTransportArcComponent) transportArcToCreate;
275
TimedTransportArcComponent arc1 = arc2.getConnectedTo();
277
dk.aau.cs.model.tapn.TransportArc ta;
279
ta = new dk.aau.cs.model.tapn.TransportArc(
280
((TimedPlaceComponent) arc1.getSource()).underlyingPlace(),
281
((TimedTransitionComponent) arc2.getSource()).underlyingTransition(),
282
((TimedPlaceComponent) arc2.getTarget()).underlyingPlace(),
283
TimeInterval.ZERO_INF);
284
view.getModel().add(ta);
285
((TimedTransportArcComponent) transportArcToCreate).setUnderlyingArc(ta);
286
arc1.setUnderlyingArc(ta);
287
arc1.updateLabel(true);
288
((TimedTransportArcComponent) transportArcToCreate).updateLabel(true);
289
} catch (RequireException ex) {
290
cleanupArc(arc1, view);
291
cleanupArc(arc2, view);
292
JOptionPane.showMessageDialog(
294
"There was an error drawing the arc. Possible problems:\n"
295
+ " - There is already an arc between the source place and transition\n"
296
+ " - There is already an arc between the transtion and the target place\n"
297
+ " - You are attempting to draw an arc between a shared transition and a shared place",
298
"Error", JOptionPane.ERROR_MESSAGE);
302
// Evil hack to prevent the arc being added to GuiView twice
303
//Need to be casted to cointainer, as we only add it to the canvas but not the model
304
((Container) CreateGui.getDrawingSurface()).remove(arc2);
306
view.getGuiModel().addArc(arc2);
307
view.addNewPetriNetObject(arc2);
309
currentObject.addConnectTo(arc2);
311
undoManager.newEdit();
314
new AddTransportArcCommand(
316
arc2.underlyingTransportArc(),
321
freeArc(transportArcToCreate);
323
arc2.setGroupNr(arc1.getGroupNr());