Package org.woped.core.model.petrinet

Examples of org.woped.core.model.petrinet.AbstractPetriNetElementModel


    {
      root.removeAllChildren();
    Iterator<AbstractPetriNetElementModel> i=elements.getRootElements().iterator();
    while (i.hasNext())
    {
      AbstractPetriNetElementModel currentNode = i.next();
      root.add(new NodeNetInfo(currentNode, true));
    }
    }
View Full Code Here


    // this constructor is called
    Set<AbstractPetriNetElementModel> sources = NetAlgorithms
        .getDirectlyConnectedNodes(model,
            NetAlgorithms.connectionTypeINBOUND);
    Iterator<AbstractPetriNetElementModel> sourceKeyIterator = sources.iterator();
    AbstractPetriNetElementModel sourceModel = sourceKeyIterator.next();
    setSubprocessInput(sourceModel);

    // Check whether the source element already exists
    if (container.getElementById(sourceModel.getId()) == null) {
      CreationMap sourceCreationMap = sourceModel.getCreationMap();
      if (((EditorVC) parentEditor).isCopyFlag() == false) {     
      container.getArcMap().clear();
      container.getIdMap().clear();
      }
      sourceCreationMap.setPosition(10, 160);
      sourceCreationMap.setReadOnly(true);
      sourceCreationMap.setNamePosition(30, 200);
      sourceCreationMap.setEditOnCreation(false);
      sourceCreationMap.setUpperElement(sourceModel);
      createElement(sourceCreationMap, true, true);
    } else {
      container.getElementById(sourceModel.getId()).setNameValue(
          getSubprocessInput().getNameValue());
      container.getElementById(sourceModel.getId()).setReadOnly(true);
    }

    // Get list of output nodes
    Set<AbstractPetriNetElementModel> targets = NetAlgorithms
        .getDirectlyConnectedNodes(model,
            NetAlgorithms.connectionTypeOUTBOUND);
    Iterator<AbstractPetriNetElementModel> targetKeyIterator = targets.iterator();
    AbstractPetriNetElementModel targetModel = targetKeyIterator.next();
    setSubprocessOutput(targetModel);
    // Check whether the target element already exists
    if (container.getElementById(targetModel.getId()) == null) {
      CreationMap targetCreationMap = targetModel.getCreationMap();
      targetCreationMap.setPosition(520, 160);
      targetCreationMap.setReadOnly(true);
      targetCreationMap.setNamePosition(540, 200);
      targetCreationMap.setEditOnCreation(false);
      targetCreationMap.setUpperElement(targetModel);
      createElement(targetCreationMap, true, true);

    } else {
      container.getElementById(targetModel.getId()).setNameValue(
          getSubprocessOutput().getNameValue());
      container.getElementById(targetModel.getId()).setReadOnly(true);
    }

    // We must create a JGraph model
    // representation of the new model element container
    // Disable undo while doing so just as we do for loading a PNML file
View Full Code Here

   *
   * @param transitionId
   * @param triggertype
   */
  public TriggerModel createTrigger(CreationMap map) {
    AbstractPetriNetElementModel transition = getModelProcessor()
    .getElementContainer().getElementById(map.getId());
    if (transition != null && transition instanceof TransitionModel) {
      if (((TransitionModel) transition).hasTrigger()) {
        deleteCell(((TransitionModel) transition).getToolSpecific()
            .getTrigger(), true);
      }

      if (transition.getParent() instanceof GroupModel) {
        GroupModel group = (GroupModel) transition.getParent();
        TriggerModel triggerModel = ((PetriNetModelProcessor) getModelProcessor())
        .newTrigger(map);

        if (map.getTriggerPosition() != null) {
          triggerModel.setPosition(map.getTriggerPosition());
View Full Code Here

   * @param transition
   * @param transResourceId
   * @return
   */
  public TransitionResourceModel createTransitionResource(CreationMap map) {
    AbstractPetriNetElementModel transition = getModelProcessor()
        .getElementContainer().getElementById(map.getId());
    if (transition != null && transition instanceof TransitionModel) {
      if (((TransitionModel) transition).hasResource()) {
        deleteCell(((TransitionModel) transition).getToolSpecific()
            .getTransResource(), true);
      }

      if (transition.getParent() instanceof GroupModel) {
        GroupModel group = (GroupModel) transition.getParent();
        TransitionResourceModel transResourceModell = ((PetriNetModelProcessor) getModelProcessor())
            .newTransResource(map);

        transResourceModell.setPosition(map.getResourcePosition().x,
            map.getResourcePosition().y);
View Full Code Here

      // Create Element, this will assign a new id if none has been
      // defined
      // This id will be unique even across sub-process borders by
      // prepending the
      // id of the sub-process
      AbstractPetriNetElementModel element = getModelProcessor().createElement(
          map);

      // ensure that There is an Position
      if (map.getPosition() != null) {
        Point point = new Point(map.getPosition().x,
            map.getPosition().y);
        // map.setPosition(new IntPair());
        element.setPosition(getGraph().snap(point));
      } else if (getLastMousePosition() != null) {
        Point point = new Point(
            (int) ((getLastMousePosition().getX()
                / getGraph().getScale() - element.getWidth() / 2)),
            (int) ((getLastMousePosition().getY()
                / getGraph().getScale() - element.getHeight() / 2)));
        // map.setPosition(new IntPair((Point) getGraph().snap(point)));
        element.setPosition(getGraph().snap(point));
      } else {
        map.setPosition(30, 30);
      }
      if (element instanceof AbstractPetriNetElementModel) {
        // Name position
        if (map.getNamePosition() == null) {
          if (isRotateSelected()) {
            ((AbstractPetriNetElementModel) element).getNameModel()
                .setPosition(
                    (element.getX() + element.getWidth()),
                    (element.getY()) + 1);
          } else {
            ((AbstractPetriNetElementModel) element).getNameModel()
                .setPosition((element.getX() - 1),
                    (element.getY() + element.getHeight()));
          }
        } else {
          ((AbstractPetriNetElementModel) element).getNameModel()
              .setPosition(map.getNamePosition().x,
                  map.getNamePosition().y);
        }
        if (map.getName() == null) {
          ((AbstractPetriNetElementModel) element).setNameValue(element
              .getId().toString());
        } else {
          ((AbstractPetriNetElementModel) element)
              .setNameValue(map.getName());
        }
        if (map.getReadOnly() != null) {
          ((AbstractPetriNetElementModel) element).setReadOnly(map
              .getReadOnly());
        }
        // Grouping
        GroupModel group = getGraph().groupName(element,
            ((AbstractPetriNetElementModel) element).getNameModel());
        group.setUngroupable(false);
        // System.err.println("In createElement Method - the created elemetn"
        // + element.toString());
        group.add(element);
        group.add(element.getNameModel());
        if (insertIntoCache) {
          getGraph().getGraphLayoutCache().insert(group);
        }

        // edit
View Full Code Here

        allPorts.add(toDelete[i]);
      } else if (toDelete[i] instanceof GroupModel) {
        allPorts.add(toDelete[i]);
      } else if (toDelete[i] instanceof AbstractPetriNetElementModel) {

        AbstractPetriNetElementModel element = (AbstractPetriNetElementModel) toDelete[i];
        // if there are trigger, delete their jgraph model
        if (toDelete[i] instanceof TransitionModel) {
          if (((TransitionModel) toDelete[i]).getToolSpecific()
              .getTrigger() != null) {
            deleteCell(
                ((TransitionModel) getModelProcessor()
                    .getElementContainer().getElementById(
                        element.getId()))
                    .getToolSpecific().getTrigger(),
                withGraph);
          }
        }

        // if there are connected arcs delete their model
        allPorts.add(element.getPort());
        allPorts.add(toDelete[i]);
        getModelProcessor().getElementContainer().removeOnlyElement(
            element.getId());

      }
    }
    if (withGraph) {
      Vector<Object> allDeletedObjects = new Vector<Object>();
View Full Code Here

      if (currentElement instanceof ArcModel) {
        ArcModel tempArc = (ArcModel) currentElement;
        clipboardArcs.add(tempArc);
      }     
      if (currentElement instanceof AbstractPetriNetElementModel) {
        AbstractPetriNetElementModel tempElement = (AbstractPetriNetElementModel) currentElement;
        // copy the element
        m_clipboard.putElement(tempElement);
      }
    }
    // Add all arcs after all other cells, because those cells need to exist in the clipboard
View Full Code Here

    HashMap<String, Object> correctedSourceId = new HashMap<String, Object>();
    HashMap<String, Object> correctedTargetId = new HashMap<String, Object>();
    Point currentPosition;
    Point middleOfSelection = null;

    AbstractPetriNetElementModel tempElement;
    String oldElementId;
    Vector<Object> toSelectElements = new Vector<Object>();
    Iterator<String> eleIter = pasteElements.keySet().iterator();

    boolean originalName = true;
    String originalNameStr = null;

    while (eleIter.hasNext()) {
      sourceMap = pasteElements.get(eleIter.next());
      tempMap = (CreationMap) sourceMap.clone();
      // position for element
      currentPosition = sourceMap.getPosition();

      // set new delta values if a mouse position is given
      if (points.length > 0 && middleOfSelection == null) {
        middleOfSelection = getMiddleOfSelection(pasteElements);

        deltaX = (int) points[0].getX() - middleOfSelection.x
            - tempMap.getSize().getX1() / 2;
        deltaY = (int) points[0].getY() - middleOfSelection.y
            - tempMap.getSize().getX2() / 2;
      }

      // set new position
      tempMap.setPosition(currentPosition.x + deltaX, currentPosition.y
          + deltaY);
      // position for name
      currentPosition = (Point) sourceMap.getNamePosition().clone();
      tempMap.setNamePosition(currentPosition.x + deltaX,
          currentPosition.y + deltaY);

      // position for trigger
      if ((currentPosition = sourceMap.getTriggerPosition()) != null) {
        tempMap.setTriggerPosition(currentPosition.x + deltaX,
            currentPosition.y + deltaY);
      }

      // copy in another frame than the source frame
      if (this != m_clipboard.getM_sourceEditor()) {
        // determine middle of selected elements
        if (middleOfSelection == null) {
          middleOfSelection = getMiddleOfSelection(pasteElements);
        }

        // position for element
        if (points.length > 0) {
          currentPosition = new Point(
              (int) (((int) points[0].getX() / 2)
                  - tempMap.getSize().getX1() / 2
                  + tempMap.getPosition().getX() - middleOfSelection.x),
              (int) (((int) points[0].getY() / 2)
                  - tempMap.getSize().getX2() / 2
                  + tempMap.getPosition().getY() - middleOfSelection.y));
        } else {
          currentPosition = new Point(
              (int) ((getEditorPanel().getWidth() / 2) - tempMap.getSize().getX1()
                  / 2 + tempMap.getPosition().getX() - middleOfSelection.x),
              (int) ((getEditorPanel().getHeight() / 2)
                  - tempMap.getSize().getX2() / 2
                  + tempMap.getPosition().getY() - middleOfSelection.y));

        }
        tempMap.setPosition(currentPosition.x, currentPosition.y);

        // position for name
        if (isRotateSelected()) {
          tempMap.setNamePosition(currentPosition.x
              + tempMap.getSize().getX1(), currentPosition.y - 1);
        } else {
          tempMap.setNamePosition(currentPosition.x - 1,
              currentPosition.y + tempMap.getSize().getX2());
        }

        if (isRotateSelected()) {
          tempMap.setTriggerPosition(currentPosition.x - 20,
              currentPosition.y + 7);
        } else {
          tempMap.setTriggerPosition(currentPosition.x + 7,
              currentPosition.y - 20);

        }

      }

      // keep the sourceMapID
      oldElementId = sourceMap.getId();
      originalNameStr = sourceMap.getName();
      originalName = isOriginalName(originalNameStr, oldElementId);
      tempMap.setEditOnCreation(false);
      tempMap.setReadOnly(false);
      // set ID to null, to get new ID
      tempMap.setId(null);
      // get tempGroupModel with new ID
      GroupModel tempGroupModel = (GroupModel) (create(tempMap));
      // get form the group an AbstractElementModel (extends GraphCell)

      tempElement = tempGroupModel.getMainElement();
      // check if tempElement TransitionModel (PetriNetModelElement)

      if (tempElement instanceof TransitionModel) {
        // GroupModel currentTrans = (GroupModel) (create(currentMap));
        // new element exactly transitionModel
        TransitionModel tempTrans = (TransitionModel) tempElement;
        // copy time
        if ((sourceMap.getTransitionTime() != -1)
            && (sourceMap.getTransitionTimeUnit() != -1)) {
          tempTrans.getToolSpecific().setTime(
              sourceMap.getTransitionTime());
          tempTrans.getToolSpecific().setTimeUnit(
              sourceMap.getTransitionTimeUnit());
        }
        // copy trigger model
        CreationMap map = tempTrans.getCreationMap();
        if (sourceMap.getTriggerType() != -1) {
          if (map != null) {

            map.setTriggerType(sourceMap.getTriggerType());
            createTriggerForPaste(map, tempTrans);
            Point p = tempTrans.getPosition();
            // Why deleteCell?
            // deleteCell(tempTrans.getToolSpecific().getTrigger(),
            // true);
            map.setTriggerPosition(p.x, p.y);
            // copy resource model
            if ((sourceMap.getResourceOrgUnit() != null)
                && sourceMap.getResourceRole() != null) {
              map.setResourceOrgUnit(sourceMap
                  .getResourceOrgUnit());
              map.setResourceRole(sourceMap.getResourceRole());
            }
          }

        } else
          map.setType(1);

      }
      /* change arc source/target */
      Iterator<String> arcIter = pasteArcs.keySet().iterator();
      while (arcIter.hasNext()) {
        currentArcMap = pasteArcs.get(arcIter.next());
        if ((this.getEditorPanel().getContainer().getActionMap()
            .get(currentArcMap.getArcSourceId()) != null)
            || ((currentArcMap.getArcSourceId()
                .equals(oldElementId)) && (!correctedSourceId
                .containsKey(currentArcMap.getArcId())))) {
          currentArcMap.setArcSourceId(tempElement.getId());
          correctedSourceId.put(currentArcMap.getArcId(), null);
        }
        if ((currentArcMap.getArcTargetId().equals(oldElementId))
            && (!correctedTargetId.containsKey(currentArcMap
                .getArcId()))) {
          currentArcMap.setArcTargetId(tempElement.getId());
          correctedTargetId.put(currentArcMap.getArcId(), null);
        }
      }
      /* */
      if (originalName)
        tempElement.setNameValue(tempElement.getId());
      else
        tempElement.setNameValue(originalNameStr);
      toSelectElements.add(tempElement.getParent());
    }

    /* insert arcs */
    Iterator<String> arcIter = pasteArcs.keySet().iterator();
    ArcModel tempArc;
View Full Code Here

   */
  public void scaleNet(double factor) {

    Iterator<AbstractPetriNetElementModel> iter = getModelProcessor()
        .getElementContainer().getRootElements().iterator();
    AbstractPetriNetElementModel aModel;
    while (iter.hasNext()) {
      aModel = (AbstractPetriNetElementModel) iter.next();
      aModel.setPosition((int) (aModel.getX() * factor),
          (int) (aModel.getY() * factor));
      aModel.getNameModel().setPosition(
          (int) (aModel.getNameModel().getX() * factor),
          (int) (aModel.getNameModel().getY() * factor));
      if (aModel instanceof OperatorTransitionModel
          && ((OperatorTransitionModel) aModel).hasTrigger()) {
        TriggerModel trigger = ((OperatorTransitionModel) aModel)
            .getToolSpecific().getTrigger();
        trigger.setPosition((int) (trigger.getX() * factor),
 
View Full Code Here

    // to enable renaming of simpleTransitions in Operators we have to call
    // the method setNameValue() after changing the name with jgraph-method
    // startEditingAtCell()
    if (getGraph().getLastEdited() != null) {
      NameModel nM = getGraph().getLastEdited();
      AbstractPetriNetElementModel aem = getModelProcessor()
          .getElementContainer().getElementById(nM.getOwnerId());
      if (aem != null) {
        aem.setNameValue(nM.getNameValue());
      }
      getGraph().setLastEditedNull();
    }
  }
View Full Code Here

TOP

Related Classes of org.woped.core.model.petrinet.AbstractPetriNetElementModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.