/**
	Loads a map from an INI-File.
*/
void INIMapEditorLoader::load() {
    checkFeatures();

    loadMap();
    loadHouses();
    loadUnits();
    loadStructures();
    loadReinforcements();
    loadChoam();
    loadTeams();

    pMapEditor->informPlayersChanged();
}
void QgsGeometryPointCoveredByLineCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
{
  Q_UNUSED( messages )

  QMap<QString, QgsFeatureIds> featureIds = ids.isEmpty() ? allLayerFeatureIds( featurePools ) : ids.toMap();
  QgsGeometryCheckerUtils::LayerFeatures layerFeatures( featurePools, featureIds, compatibleGeometryTypes(), feedback, mContext, true );
  for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
  {
    const QgsAbstractGeometry *geom = layerFeature.geometry().constGet();
    for ( int iPart = 0, nParts = geom->partCount(); iPart < nParts; ++iPart )
    {
      const QgsPoint *point = dynamic_cast<const QgsPoint *>( QgsGeometryCheckerUtils::getGeomPart( geom, iPart ) );
      if ( !point )
      {
        // Should not happen
        continue;
      }
      // Check that point lies on a line
      bool touches = false;
      QgsRectangle rect( point->x() - mContext->tolerance, point->y() - mContext->tolerance,
                         point->x() + mContext->tolerance, point->y() + mContext->tolerance );
      QgsGeometryCheckerUtils::LayerFeatures checkFeatures( featurePools, featureIds.keys(), rect, {QgsWkbTypes::LineGeometry}, mContext );
      for ( const QgsGeometryCheckerUtils::LayerFeature &checkFeature : checkFeatures )
      {
        const QgsAbstractGeometry *testGeom = checkFeature.geometry().constGet();
        for ( int jPart = 0, mParts = testGeom->partCount(); jPart < mParts; ++jPart )
        {
          const QgsLineString *testLine = dynamic_cast<const QgsLineString *>( QgsGeometryCheckerUtils::getGeomPart( testGeom, jPart ) );
          if ( !testLine )
          {
            continue;
          }
          if ( QgsGeometryCheckerUtils::pointOnLine( *point, testLine, mContext->tolerance ) )
          {
            touches = true;
            break;
          }
        }
        if ( touches )
        {
          break;
        }
      }
      if ( touches )
      {
        continue;
      }
      errors.append( new QgsGeometryCheckError( this, layerFeature, *point, QgsVertexId( iPart, 0, 0 ) ) );
    }
  }
}
void QgsGeometryLineLayerIntersectionCheck::collectErrors( QList<QgsGeometryCheckError *> &errors, QStringList &/*messages*/, QAtomicInt *progressCounter, const QMap<QString, QgsFeatureIds> &ids ) const
{
  QMap<QString, QgsFeatureIds> featureIds = ids.isEmpty() ? allLayerFeatureIds() : ids;
  featureIds.remove( mCheckLayer ); // Don't check layer against itself
  QgsGeometryCheckerUtils::LayerFeatures layerFeatures( mContext->featurePools, featureIds, mCompatibleGeometryTypes, progressCounter, mContext, true );
  for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
  {
    const QgsAbstractGeometry *geom = layerFeature.geometry().constGet();
    for ( int iPart = 0, nParts = geom->partCount(); iPart < nParts; ++iPart )
    {
      const QgsLineString *line = dynamic_cast<const QgsLineString *>( QgsGeometryCheckerUtils::getGeomPart( geom, iPart ) );
      if ( !line )
      {
        // Should not happen
        continue;
      }

      // Check whether the line intersects with any other features of the specified layer
      QgsGeometryCheckerUtils::LayerFeatures checkFeatures( mContext->featurePools, QStringList() << mCheckLayer, line->boundingBox(), {QgsWkbTypes::LineGeometry, QgsWkbTypes::PolygonGeometry}, mContext );
      for ( const QgsGeometryCheckerUtils::LayerFeature &checkFeature : checkFeatures )
      {
        const QgsAbstractGeometry *testGeom = checkFeature.geometry().constGet();
        for ( int jPart = 0, mParts = testGeom->partCount(); jPart < mParts; ++jPart )
        {
          const QgsAbstractGeometry *part = QgsGeometryCheckerUtils::getGeomPart( testGeom, jPart );
          if ( const QgsLineString *testLine = dynamic_cast<const QgsLineString *>( part ) )
          {
            const QList< QgsPoint > intersections = QgsGeometryCheckerUtils::lineIntersections( line, testLine, mContext->tolerance );
            for ( const QgsPoint &inter : intersections )
            {
              errors.append( new QgsGeometryCheckError( this, layerFeature, inter, QgsVertexId( iPart ), checkFeature.id() ) );
            }
          }
          else if ( const QgsPolygon *polygon = dynamic_cast<const QgsPolygon *>( part ) )
          {
            QList< const QgsLineString * > rings = QgsGeometryCheckerUtils::polygonRings( polygon );
            for ( const QgsLineString *ring : rings )
            {
              const QList< QgsPoint > intersections = QgsGeometryCheckerUtils::lineIntersections( line, ring, mContext->tolerance );
              for ( const QgsPoint &inter : intersections )
              {
                errors.append( new QgsGeometryCheckError( this, layerFeature, inter, QgsVertexId( iPart ), checkFeature.id() ) );
              }
            }
          }
        }
      }
    }
  }
}
Beispiel #4
0
bool deviceTransaction(iguanaDev *idev,       /* required */
                       dataPacket *request,   /* required */
                       dataPacket **response) /* optional */
{
    bool retval = false;
    packetType *type;

    /* For old devices setting pin configs actually becomes 2
       requests, awkward, but the way it has to be to support old
       firmware. */
    if (idev->version <= 3 && 
        (request->code == IG_DEV_SETPINCONFIG ||
         request->code == IG_DEV_GETPINCONFIG))
        return oldPinConfig(idev, request, response);

    type = checkIncomingProtocol(idev, request, response == NULL);
    if (type)
    {
        unsigned char msg[MAX_PACKET_SIZE] = {CTL_START, CTL_START, CTL_TODEV};
        uint64_t then, now;
        int length = MIN_CTL_LENGTH, result, sent = 0;

#ifdef LIBUSB_NO_THREADS
        bool unlocked = false;
#endif

        /* possibly change the code, then translate for the device */
        switch(request->code)
        {
        case IG_DEV_GETID:
            msg[CODE_OFFSET] = IG_DEV_EXECUTE;
            break;
            
        case IG_DEV_SETID:
        {
            unsigned char *block;
            block = generateIDBlock((char*)request->data, idev->version);
            free(request->data);
            request->data = block;
            request->dataLen = 68;

            msg[CODE_OFFSET] = IG_DEV_WRITEBLOCK;
            break;
        }

        /* clear the features if any page is written since this could
           change the returned timings */
        case IG_DEV_WRITEBLOCK:
            idev->features = UNKNOWN_FEATURES;
        default:
            msg[CODE_OFFSET] = request->code;
            break;
        }
        if (! translateDevice(msg + CODE_OFFSET, idev->version, false))
            message(LOG_ERROR, "Failed to translate code for device.\n");

        /* compute the outgoing checksum for IG_DEV_WRITEBLOCK */
        if (msg[CODE_OFFSET] == IG_DEV_WRITEBLOCK &&
            request->dataLen == 68)
        {
            int x;
            uint32_t chksum = 0;
            for(x = 4; x < 68; x++)
                chksum += request->data[x];
            request->data[2] = (chksum & 0xFF00) >> 8;
            request->data[3] = chksum & 0xFF;
        }

        /* SEND and PINBURST do not get their data packed into the
           request packet, unlike everything else. */
        if (request->code != IG_DEV_SEND &&
            request->code != IG_DEV_RESEND &&
            request->code != IG_DEV_PINBURST &&
            request->code != IG_DEV_REPEATER)
        {
            if (request->code != IG_DEV_SETPINCONFIG)
            {
                sent = request->dataLen;
                /* this is only used to get addresses in WRITEBLOCK */
                if (sent > 4)
                    sent = 4;
                memcpy(msg + MIN_CTL_LENGTH, request->data, sent);
                length += sent;
            }
        }
        /* as of version 3 SEND and PINBURST require a length argument */
        else if (idev->version >= 3)
        {
            int dataPos = MIN_CTL_LENGTH;
            if (request->code == IG_DEV_RESEND)
            {
                /* prepare to append the channels and carrier */
                request->data = realloc(request->data, MAX_PACKET_SIZE);
                request->dataLen = MAX_PACKET_SIZE;

                 /* the size will be overwritten in the device firmware */
                request->data[dataPos++] = 0xFF;
            }
            else
                msg[length++] = (unsigned char)request->dataLen;

            /* select which channels to transmit on */
            if (request->code == IG_DEV_SEND ||
                request->code == IG_DEV_RESEND ||
                request->code == IG_DEV_REPEATER)
            {
                if (request->code == IG_DEV_RESEND)
                    request->data[dataPos++] = idev->channels;
                else
                    msg[length++] = idev->channels;

                /* is the carrier frequency finally adjustable? */
                if ((idev->version & 0x00FF) &&
                    (idev->version & 0xFF00))
                {
                    unsigned char *delays;
                    /* the cycle count WAS stable so default to that count: */
                    uint8_t loopCycles = 5 + 5 + 7 + 6 + 6 + 7 + \
                                         (5 + 7) + (5 + 7) + 5;
                    /* we can use the cycle count provided by the
                       firmware with body-4 */
                    if ((idev->version & 0x00FF) >= 0x0004 &&
                        checkFeatures(idev, UNKNOWN_FEATURES))
                        loopCycles = idev->cycles;

                    /* compute the delay length off the carrier */
                    if (request->code == IG_DEV_RESEND)
                        delays = request->data + dataPos;
                    else
                    {
                        delays = msg + length;
                        length += 2;
                    }
                    computeCarrierDelays(idev->carrier, delays, loopCycles);
                }
            }
        }


#ifdef LIBUSB_NO_THREADS_OPTION
        if (idev->libusbNoThreads)
#endif
#ifdef LIBUSB_NO_THREADS
        {
            /* force the reader to give up the lock */
            idev->needToWrite = true;
            EnterCriticalSection(&idev->devLock);
            idev->needToWrite = false;
        }
#endif

        /* flush any extraneous CTL_TODEV responses */
        flushToDevResponsePackets(idev);
        /* time the transfer */
        then = microsSinceX();
        result = interruptSend(idev->usbDev, msg, length,
                               idev->settings->sendTimeout);
        /* error if we were not able to write ALL the data */
        if (result != length)
            printError(LOG_ERROR,
                       "failed to write control packet", idev->usbDev);
        /* if there is more data need to transmit the data stream
           before releasing the devLock */
        else if (request->dataLen > sent &&
                 ! sendData(idev,
                            request->data + sent, request->dataLen - sent,
                            idev->version < 3 && request->code == IG_DEV_SEND))
            message(LOG_ERROR, "Failed to send IR data.\n");
        /* if no ack is necessary then return success now */
        else if (! type->ack)
            retval = true;
        else
        {
            int amount;

#ifdef LIBUSB_NO_THREADS_OPTION
            if (idev->libusbNoThreads)
#endif
#ifdef LIBUSB_NO_THREADS
            {
                /* unlock as soon as possible after all data has been sent */
                LeaveCriticalSection(&idev->devLock);
                unlocked = true;
            }
#endif

            /* using sendTimeout to ensure reader has necessary time
               to recieve the ack */
            amount = notified(idev->responsePipe[READ],
                              idev->settings->sendTimeout);
            if (amount < 0)
                message(LOG_ERROR, "Failed to read control ack: %s\n",
                        translateError(errno));
            else if (amount > 0)
            {
                dataPacket *pos;

                EnterCriticalSection(&idev->listLock);
                pos = idev->response;

                /* un-translate the SETID/WRITEBLOCK codes */
                if (request->code == IG_DEV_SETID &&
                    pos->code == IG_DEV_WRITEBLOCK)
                    pos->code = IG_DEV_SETID;

                errno = EINVAL;
                if (pos->code != IG_DEV_INVALID_ARG)
                {
                    if (pos->code != request->code)
                        message(LOG_ERROR,
                                "Bad ack for send: 0x%x != 0x%x\n",
                                pos->code, request->code);
                    else if (! payloadMatch((unsigned char)type->inData, (unsigned char)pos->dataLen))
                        message(LOG_ERROR, "Response size does not match specification (version 0x%x: %d != %d)\n", idev->version, pos->dataLen,type->inData);
                    else
                    {
                        /* store the retrieved response */
                        if (response != NULL)
                            *response = pos;
                        else
                            freeDataPacket(pos);
                        pos = NULL;

                        /* how long did this all take? */
                        now = microsSinceX();
                        message(LOG_INFO,
                                "Transaction: 0x%x (%lld microseconds)\n",
                                request->code, now - then);
                        retval = true;
                    }
                }

                freeDataPacket(pos);
                idev->response = NULL;
                LeaveCriticalSection(&idev->listLock);
            }
            else
            {
                message(LOG_INFO,
                        "Timeout while waiting for response from device.\n");
                errno = ETIMEDOUT;
            }
        }

#ifdef LIBUSB_NO_THREADS_OPTION
        if (idev->libusbNoThreads)
#endif
#ifdef LIBUSB_NO_THREADS
            /* certain errors may result in unlocking here */
            if (!unlocked)
                LeaveCriticalSection(&idev->devLock);
#endif
    }