Ejemplo n.º 1
0
  private void writeDebug() throws JsonGenerationException, IOException {
    if (debugInfo != null) {
      writer.writeFieldName("debug");
      writer.writeStartObject();

      writer.writeStringField("script-version", debugInfo.getScriptVersion());

      List<LoadDescription> descriptions = debugInfo.getDescriptions();
      List<QueryData> queries = debugInfo.getQueries();
      for (int index = 0; index < descriptions.size(); index++) {
        writer.writeFieldName("query_" + index);
        writer.writeStartObject();

        LoadDescription description = descriptions.get(index);
        OrcsSession session = description.getSession();
        if (session != null) {
          writer.writeStringField("session", session.getGuid());
        }
        Options options = description.getOptions();
        for (String key : new TreeSet<String>(options.getKeys())) {
          writer.writeStringField(key, options.get(key).replaceAll("\\s+", " "));
        }
        writeQuery(queries.get(index));
        writer.writeEndObject();
      }
      writer.writeEndObject();
    }
  }
Ejemplo n.º 2
0
 @Override
 public void onQueryStart(QueryData data) {
   super.onQueryStart(data);
   if (isDebugModeEnabled) {
     debugInfo.addQuery(data);
   }
 }
Ejemplo n.º 3
0
 @Override
 public void onExecutionStart(String version) {
   super.onExecutionStart(version);
   if (isDebugModeEnabled) {
     debugInfo.setScriptVersion(version);
   }
 }
Ejemplo n.º 4
0
 @Override
 public void onLoadDescription(LoadDescription data) throws OseeCoreException {
   super.onLoadDescription(data);
   first = Iterables.getFirst(data.getObjectDescription().getDynamicData(), null);
   wasStarted = false;
   if (debugInfo != null) {
     debugInfo.addDescription(data);
   }
 }
  @Override
  public void fire(ActivityInstance context) {
    // perform all as semantics actions
    Object contextValue = null;
    MofClassSemantics semantics = null;
    switch (self.getActionKind()) {
      case EXPRESSION:
        DebugInfo.printInfo("eval " + self.getActionBody());
        propagateOutput(
            evaluateExpression(self, self.getActionBody(), self.getInput(), context),
            true,
            context);
        break;
      case CALL:
        DebugInfo.printInfo("call " + self.getActionBody());
        String operationName = getActionBody();
        ;
        contextValue = context.getOclContext();
        ReflectiveSequence<Argument> arguments = new ListImpl<Argument>();
        for (InputPin pin : self.getInput()) {
          if (pin instanceof ContextPin) {
            contextValue = ((PinInstance) context.getPlaces(pin)).getValue();
          } else {
            arguments.add(
                new ArgumentImpl(null, ((PinInstance) context.getPlaces(pin)).getValue()));
          }
        }
        if (contextValue == null) {
          throw new SemanticException("Context must not be null for call " + self.getActionBody());
        }
        semantics =
            MofClassSemantics.createClassClassifierForUmlClass(
                (UmlClass) getTypeForObject(contextValue));

        for (InputPin inputPin : self.getInput()) {
          if (!(inputPin instanceof ContextPin)) {
            operationName +=
                "_" + getTypeOfValue(((PinInstance) context.getPlaces(inputPin)).getValue());
          }
        }
        Operation operation = semantics.getFinalOperation(operationName);
        if (operation == null) {
          throw new SemanticException(
              "The arguments of action "
                  + toString()
                  + "(call "
                  + operationName
                  + ") does not match to an operation in the given context.");
        }
        Object result =
            ((cmof.reflection.Object) contextValue).invokeOperation(operation, arguments);
        propagateOutput(result, false, context);
        DebugInfo.printInfo("end call " + self.getActionBody());
        break;
      case PRINT:
        System.out.println(self.getActionBody());
        break;
      case WRITE_STRUCTURAL_FEATURE:
        DebugInfo.printInfo("set " + self.getActionBody());
        contextValue = context.getOclContext();
        Object featureValue = null;
        Object qualifierValue = null;
        for (InputPin pin : self.getInput()) {
          if (pin instanceof ContextPin) {
            contextValue = ((PinInstance) context.getPlaces(pin)).getValue();
          } else {
            if (featureValue != null) {
              if (qualifierValue != null) {
                throw new SemanticException(
                    "To much input pins for a write structural feature action.");
              }
              qualifierValue = featureValue;
            }
            featureValue = ((PinInstance) context.getPlaces(pin)).getValue();
            if (featureValue instanceof MofClassSemantics) {
              System.out.println("Fehler!!!");
            }
          }
        }
        Property feature = resolveFeature(contextValue);
        if (qualifierValue != null) {
          if (feature.getQualifier() == null) {
            throw new SemanticException(
                "To much input pins for a write structural feature action without qualifier.");
          }
          ((cmof.reflection.Object) contextValue).set(feature, qualifierValue, featureValue);
        } else {
          if (feature.getQualifier() != null) {
            throw new SemanticException(
                "Not enough input pins for a write structural feature action with qualifier.");
          }
          ((cmof.reflection.Object) contextValue).set(feature, featureValue);
        }
        break;
      case WRITE_STRUCTURAL_FEATURE_VALUE:
        DebugInfo.printInfo("add " + self.getActionBody());
        contextValue = context.getOclContext();
        featureValue = null;
        for (InputPin pin : self.getInput()) {
          if (pin instanceof ContextPin) {
            contextValue = ((PinInstance) context.getPlaces(pin)).getValue();
          } else {
            if (featureValue != null) {
              throw new SemanticException(
                  "To much input pins for a write structural feature action.");
            }
            featureValue = ((PinInstance) context.getPlaces(pin)).getValue();
          }
        }
        feature = resolveFeature(contextValue);
        ((ReflectiveSequence) ((cmof.reflection.Object) contextValue).get(feature))
            .add(featureValue);
        break;
      case REMOVE_STRUCTURAL_FEATURE_VALUE:
        DebugInfo.printInfo("remove " + self.getActionBody());
        contextValue = context.getOclContext();
        featureValue = null;
        for (InputPin pin : self.getInput()) {
          if (pin instanceof ContextPin) {
            contextValue = ((PinInstance) context.getPlaces(pin)).getValue();
          } else {
            if (featureValue != null) {
              throw new SemanticException(
                  "To much input pins for a write structural feature action.");
            }
            featureValue = ((PinInstance) context.getPlaces(pin)).getValue();
          }
        }
        feature = resolveFeature(contextValue);
        ((ReflectiveSequence) ((cmof.reflection.Object) contextValue).get(feature))
            .remove(featureValue);
        break;
      case CREATE_OBJECT:
        DebugInfo.printInfo("create " + self.getActionBody());
        boolean hasContextClass = false;
        contextValue = context.getOclContext();
        for (InputPin pin : self.getInput()) {
          if (pin instanceof ContextPin) {
            contextValue = ((PinInstance) context.getPlaces(pin)).getValue();
            hasContextClass = true;
          } else {
            throw new SemanticException(
                "Only a single context pin is allowed for a create action.");
          }
        }
        if (hasContextClass) {
          UmlClass syntaxClass = (UmlClass) getTypeForObject(contextValue);
          String className = self.getActionBody();
          UmlClass runtimeClass = null;
          for (Type classAsType : syntaxClass.getPackage().getOwnedType()) {
            if (classAsType instanceof UmlClass && className.equals(classAsType.getName())) {
              runtimeClass = (UmlClass) classAsType;
            }
          }
          if (runtimeClass == null) {
            throw new SemanticException(
                "Class with name "
                    + className
                    + " does not exist in package "
                    + syntaxClass.getPackage().getQualifiedName()
                    + ".");
          }
          semantics = MofClassSemantics.createClassClassifierForUmlClass(syntaxClass);
          Operation op =
              semantics.getFinalOperation(M1SemanticModel.getCreateOperationName(runtimeClass));
          result =
              ((cmof.reflection.Object) contextValue).invokeOperation(op, new ListImpl<Argument>());
          propagateOutput(result, false, context);
        } else {
          throw new SemanticException("not implemented yet.");
        }
        break;
      case PRINT_EXPRESSION:
        System.out.println(
            evaluateExpression(self, self.getActionBody(), self.getInput(), context));
        break;
      default:
        System.out.println("WARNING: unknown action kind");
    }

    // call the actual petri net semantics perfom method
    ((Transition) getSuper(Transition.class)).fire(context);
  }
  /** Build a navigation path using the provided points and the A* method */
  private boolean buildNavigationPath(
      Path navPath,
      Cell startCell,
      Vector3f startPos,
      Cell endCell,
      Vector3f endPos,
      float entityRadius,
      DebugInfo debugInfo) {

    // Increment our path finding session ID
    // This Identifies each pathfinding session
    // so we do not need to clear out old data
    // in the cells from previous sessions.
    sessionID++;

    // load our data into the Heap object
    // to prepare it for use.
    heap.initialize(sessionID, startPos);

    // We are doing a reverse search, from EndCell to StartCell.
    // Push our EndCell onto the Heap at the first cell to be processed
    endCell.queryForPath(heap, null, 0.0f);

    // process the heap until empty, or a path is found
    boolean foundPath = false;
    while (heap.isNotEmpty() && !foundPath) {

      // pop the top cell (the open cell with the lowest cost) off the
      // Heap
      Node currentNode = heap.getTop();

      // if this cell is our StartCell, we are done
      if (currentNode.cell.equals(startCell)) {
        foundPath = true;
      } else {
        // Process the Cell, Adding it's neighbors to the Heap as needed
        currentNode.cell.processCell(heap);
      }
    }

    Vector2f intersectionPoint = new Vector2f();

    // if we found a path, build a waypoint list
    // out of the cells on the path
    if (!foundPath) {
      return false;
    }

    // Setup the Path object, clearing out any old data
    navPath.initialize(navMesh, startPos, startCell, endPos, endCell);

    Vector3f lastWayPoint = startPos;

    // Step through each cell linked by our A* algorithm
    // from StartCell to EndCell
    Cell currentCell = startCell;
    while (currentCell != null && currentCell != endCell) {

      if (debugInfo != null) {
        debugInfo.addPlannedCell(currentCell);
      }

      // add the link point of the cell as a way point (the exit
      // wall's center)
      int linkWall = currentCell.getArrivalWall();
      Vector3f newWayPoint = currentCell.getWallMidpoint(linkWall).clone();

      Line2D wall = currentCell.getWall(linkWall);
      float length = wall.length();
      float distBlend = entityRadius / length;

      Line2D lineToGoal =
          new Line2D(
              new Vector2f(lastWayPoint.x, lastWayPoint.z), new Vector2f(endPos.x, endPos.z));
      LineIntersect result = lineToGoal.intersect(wall, intersectionPoint);
      switch (result) {
        case SegmentsIntersect:
          float d1 = wall.getPointA().distance(intersectionPoint);
          float d2 = wall.getPointB().distance(intersectionPoint);
          if (d1 > entityRadius && d2 > entityRadius) {
            // we can fit through the wall if we go
            // directly to the goal.
            newWayPoint = new Vector3f(intersectionPoint.x, 0, intersectionPoint.y);
          } else {
            // cannot fit directly.
            // try to find point where we can
            if (d1 < d2) {
              intersectionPoint.interpolate(wall.getPointA(), wall.getPointB(), distBlend);
              newWayPoint = new Vector3f(intersectionPoint.x, 0, intersectionPoint.y);
            } else {
              intersectionPoint.interpolate(wall.getPointB(), wall.getPointA(), distBlend);
              newWayPoint = new Vector3f(intersectionPoint.x, 0, intersectionPoint.y);
            }
          }
          currentCell.computeHeightOnCell(newWayPoint);
          break;
        case LinesIntersect:
        case ABisectsB:
        case BBisectsA:
          Vector2f lastPt2d = new Vector2f(lastWayPoint.x, lastWayPoint.z);
          Vector2f endPos2d = new Vector2f(endPos.x, endPos.z);

          Vector2f normalEnd = endPos2d.subtract(lastPt2d).normalizeLocal();
          Vector2f normalA = wall.getPointA().subtract(lastPt2d).normalizeLocal();
          Vector2f normalB = wall.getPointB().subtract(lastPt2d).normalizeLocal();
          if (normalA.dot(normalEnd) < normalB.dot(normalEnd)) {
            // choose point b
            intersectionPoint.interpolate(wall.getPointB(), wall.getPointA(), distBlend);
            newWayPoint = new Vector3f(intersectionPoint.x, 0, intersectionPoint.y);
          } else {
            // choose point a
            intersectionPoint.interpolate(wall.getPointA(), wall.getPointB(), distBlend);
            newWayPoint = new Vector3f(intersectionPoint.x, 0, intersectionPoint.y);
          }
          currentCell.computeHeightOnCell(newWayPoint);

          break;
        case CoLinear:
        case Parallel:
          System.out.println("## colinear or parallel");
          break;
      }

      if (debugInfo != null) {
        debugInfo.addPreOptWaypoints(newWayPoint.clone());
      }
      //                newWayPoint = snapPointToCell(currentCell, newWayPoint);
      lastWayPoint = newWayPoint.clone();

      navPath.addWaypoint(newWayPoint, currentCell);

      // get the next cell
      currentCell = currentCell.getLink(linkWall);
    }

    // cap the end of the path.
    navPath.finishPath();

    // remove optimization so it can be done as the actor moves
    // further: optimize the path
    List<Waypoint> newPath = new ArrayList<Waypoint>();
    Waypoint curWayPoint = navPath.getFirst();
    newPath.add(curWayPoint);
    while (curWayPoint != navPath.getLast()) {
      curWayPoint = navPath.getFurthestVisibleWayPoint(curWayPoint);
      newPath.add(curWayPoint);
    }

    navPath.initialize(navMesh, startPos, startCell, endPos, endCell);
    for (Waypoint newWayPoint : newPath) {
      navPath.addWaypoint(newWayPoint.getPosition(), newWayPoint.getCell());
    }
    navPath.finishPath();

    return true;
  }