示例#1
0
// P. 150
core::ResultCode BlockHeader::restoreFull(ISchema& schema, DWGBuffer& buffer, const Handle& handle, const Version& version) const
{
//  LOG_WARNING(handle.getValue());
  UnicodeString strName = buffer.readText(version);
  bool flag = buffer.readBit();
  int xref = buffer.readBit16() - 1;
  bool xdep = buffer.readBit();
  bool anonymous = buffer.readBit();
  bool hasattr = buffer.readBit();
  bool isxref = buffer.readBit();
  bool isoverlaidxref = buffer.readBit();

  if (version.isAtLeast(Version::R2000))
    bool loadedbit = buffer.readBit();

  if (version.isAtLeast(Version::R2004))
  {
    size_t owned = buffer.readBit32();
  }

  const double baseX = buffer.readBitDouble();
  const double baseY = buffer.readBitDouble();
  const double baseZ = buffer.readBitDouble();
  UnicodeString strPathName = buffer.readText(version);
//  LOG_DEBUG(strName << " - " << strPathName << " [" << baseX << ", " << baseY << ", " << baseZ << "]");

  if (version.isAtLeast(Version::R2000))
  {
    int tot = 0;
    while (true)
    {
      size_t insertcount = buffer.readRaw8(); // TODO: Read until insertcount == 0???
      if (insertcount == 0)
        break;
      ++tot;
    }
    UnicodeString strDescription = buffer.readText(version);
    const uint32_t previewSize = buffer.readBit32();
    buffer.skipBytes(previewSize);

    if (version.isAtLeast(Version::R2007)) {
      const int16_t insertUnits = buffer.readBit16();
      const bool isExplodable = buffer.readBit();
      const char blockScaling = buffer.readRaw8();
      LOG_WARNING(insertUnits << ".. " << isExplodable << " " << blockScaling);
    }

    Handle handleRefs = buffer.readHandle();
//    LOG_WARNING(tot << " " << strDescription << ": " << previewSize);
//    LOG_WARNING(handleRefs.getCode() << ": " << handleRefs.getValue());
  }

  return core::rcSuccess;
}
示例#2
0
// P. 124
core::ResultCode Face3D::restoreFull(ISchema& schema, DWGBuffer& buffer, const Colour& colour, const Version& version) const
{
  libredwgpp::Vertex3d corners[4];
  uint16_t invisibleEdgeFlag = 0;

  if (version.isAtLeast(Version::R2000))
  {
    bool hasFlag = ~buffer.readBit();
    bool skipZ = buffer.readBit();
    double x = buffer.readRawDouble();
    double y = buffer.readRawDouble();
    double z = 0;
    if (!skipZ)
    {
      z = buffer.readRawDouble();
    }

    corners[0] = libredwgpp::Vertex3d(x, y, z);

    for (int i = 0; i < 3; ++i)
    {
      buffer.readBitDouble(x);
      buffer.readBitDouble(y);
      buffer.readBitDouble(z);
      corners[i + 1] = libredwgpp::Vertex3d(x, y, z);
    }

    if (hasFlag)
    {
      invisibleEdgeFlag = buffer.readBit16();
    }
  } else {
    libredwgpp::Vertex3d corners[4];

    for (int i = 0; i < 4; ++i)
    {
      double x = buffer.readBitDouble();
      double y = buffer.readBitDouble();
      double z = buffer.readBitDouble();
      corners[i] = libredwgpp::Vertex3d(x, y, z);
    }

    invisibleEdgeFlag = buffer.readBit16();
  }

  schema.addFace3d(libredwgpp::Face3d(colour, corners[0], corners[1], corners[2], corners[3]));

  return core::rcSuccess;
}
示例#3
0
////////////////////////////////////////////////////////////////
// P. 109
//int asdf = 0;
core::ResultCode Insert::restoreFull(ISchema& schema, DWGBuffer& buffer, const Colour& colour, const Handle& handle, const Version& version) const
{
  const double translationX = buffer.readBitDouble();
  const double translationY = buffer.readBitDouble();
  const double translationZ = buffer.readBitDouble();
//  LOG_DEBUG("[" << translationX << ", " << translationY << ", " << translationZ << "]");

  double scaleX = 1.;
  double scaleY = 1.;
  double scaleZ = 1.;

  if (version.isBetween(Version::R13, Version::R14))
  {
    scaleX = buffer.readBitDouble();
    scaleY = buffer.readBitDouble();
    scaleZ = buffer.readBitDouble();
  }

  if (version.isAtLeast(Version::R2000))
  {
    int flags = buffer.readBit2();
    if (!(flags & 0x01))
    {
      scaleX = buffer.readRawDouble();
      scaleY = scaleX;
      scaleZ = scaleX;
    }

    if (!(flags & 0x02))
    {
      buffer.readBitDouble(scaleY);
      buffer.readBitDouble(scaleZ);
    }
  }
//    LOG_DEBUG("[" << scaleX << ", " << scaleY << ", " << scaleZ << "]");

  // Rotation + axis
  const double rotation = buffer.readBitDouble();
  const double axisX = buffer.readBitDouble();
  const double axisY = buffer.readBitDouble();
  const double axisZ = buffer.readBitDouble();
//  LOG_ERROR(rotation << "[rad] [" << axisX << ", " << axisY << ", " << axisZ << "]");
  bool hasAttrib = buffer.readBit();
//  LOG_ERROR("Has attribute " << hasAttrib);

  if (version.isAtLeast(Version::R2004))
  {
    int numObj = buffer.readBit32();
    LOG_DEBUG(numObj);
  }

  Handle h = buffer.readHandle();
//  LOG_DEBUG("Handle: " << h.getCode() << " => " << h.getValue());

  try {
//    Handle i = buffer.readHandle();
//    LOG_DEBUG("H2: " << i.getCode() << " => " << i.getValue());
//    Handle j = buffer.readHandle();
//    LOG_DEBUG("H3: " << j.getCode() << " => " << j.getValue());
  } catch (...) {
  }

  schema.insert(h.getValue(), Vertex3d(axisX, axisY, axisZ), rotation,
                                 Vertex3d(scaleX, scaleY, scaleZ),
                                 Vertex3d(translationX, translationY, translationZ));
//LOG_ERROR(++asdf);
//if (++asdf > 138)
//return core::rcFailure;
  return core::rcSuccess;
}
示例#4
0
core::ResultCode Entity::restore(ISchema& schema, DWGBuffer& buffer, const Version& version) const
{
//  LOG_DEBUG("entity");
//LOG_DEBUG(buffer.getPosition() << ", " << buffer.getOffset());
  bool hasGraphic = buffer.readBit();
//  LOG_DEBUG("pic " << hasGraphic);
  if (hasGraphic)
  {
//    LOG_DEBUG("Graphic");
    uint64_t graphicSize = 0;
    if (version.isAtLeast(Version::R2010))
    {
      graphicSize = buffer.readBit64();
    } else {
      graphicSize = buffer.readRaw32();
    }

    LOG_ERROR("Todo: parse or skip graphic data");
    return core::rcFailure;
  }

  if (version.isBetween(Version::R13, Version::R14))
  {
    /*size_t bitSize =*/ buffer.readRaw32();
//    size_t flags = buffer.readBit6();
//    size_t params = buffer.readBit6();

//    LOG_DEBUG("bitsize " << bitSize);
//    LOG_DEBUG(bitSize << "." << flags << "." << params);
  }

  int mode = buffer.readBit2();
  int numReac = buffer.readBit32();

  if (version.isAtLeast(Version::R2004))
  {
    buffer.readBit();
  }

  if (version.isBetween(Version::R13, Version::R14))
  {
    buffer.readBit();
  }

  bool hasLinks = ~buffer.readBit();

  Colour colour = buffer.readColour(version, true);
//  if (version.isAtLeast(Version::R2004))
//  {
//    if (hasLinks)
//    {
//      bool colourMode = buffer.readBit();
//      if (colourMode)
//      {
//        colour.setIndex(buffer.readRaw8());
//      } else {
//        size_t flags = buffer.readRaw16();
//        if (flags & 0x8000)
//        {
//          // TODO: doc says BS of 24 bits for RGB  !?
//          int r = buffer.readRaw8();
//          int g = buffer.readRaw8();
//          int b = buffer.readRaw8();
//          int a = buffer.readRaw8();
//          UnicodeString strName = buffer.readText(version);
//
//          colour.setRGBA(r, g, b, a);
//          colour.setName(strName);
//        }
//
//        if (flags & 0x4000)
//        {
//        }
//
//        if (flags & 0x2000)
//        {
//          int transparency = buffer.readBit32();
//        }
//      }
//    } else {
//      buffer.readBit();
//    }
//  } else {
//    colour = buffer.readColour(version);
//  }
//  ent->linetype_scale = bit_read_BD(dat);

//  Colour colour = data.readColour();
  double lineScale = buffer.readBitDouble();

  if (version.isAtLeast(Version::R2000))
  {
    int lineFlags = buffer.readBit2();
    int plotFlags = buffer.readBit2();
//    LOG_DEBUG(lineFlags << " / " << plotFlags);
  }

  if (version.isAtLeast(Version::R2007))
  {
    int materialFlags = buffer.readBit2();
    int shadowFlags = buffer.readRaw8();
  }

  int invisible = buffer.readBit16();

  if (version.isAtLeast(Version::R2000))
  {
    int lineWeight = buffer.readRaw8();
//    LOG_DEBUG(lineWeight);
  }

//  LOG_DEBUG(mode << " " << numReac << " " << hasLinks << " " << colour.index_ << " " << std::fixed << std::setprecision(6) << lineScale << " " << invisible);
//
//  return core::rcSuccess;
//LOG_DEBUG(buffer.getPosition() << ", " << buffer.getOffset());

  return restoreFull(schema, buffer, colour, version);
}
示例#5
0
// P. 164
core::ResultCode Viewport::restoreFull(ISchema& schema, DWGBuffer& buffer, const Handle& handle, const Version& version) const
{
  UnicodeString strName = buffer.readText(version);
  bool bit1 = buffer.readBit();
  int xref = int(buffer.readBit16()) - 1;
  bool xdep = buffer.readBit();
  double viewHeight = buffer.readBitDouble();
  double aspectRatio = buffer.readBitDouble();
//  LOG_DEBUG(strName << " " << bit1 << " " << xref << " " << xdep << " " << viewHeight << ":" << aspectRatio);
  double centerX = buffer.readRawDouble();
  double centerY = buffer.readRawDouble();
  double targetX = buffer.readBitDouble();
  double targetY = buffer.readBitDouble();
  double targetZ = buffer.readBitDouble();
  double dirX = buffer.readBitDouble();
  double dirY = buffer.readBitDouble();
  double dirZ = buffer.readBitDouble();
  double twist = buffer.readBitDouble();
//  LOG_DEBUG("[" << centerX << ", " << centerY << "] (" << twist << ")");
//  LOG_DEBUG("[" << targetX << ", " << targetY << ", " << targetZ << "]");
//  LOG_DEBUG("[" << dirX << ", " << dirY << ", " << dirZ << "]");
  double lensLen = buffer.readBitDouble();
  double frontClip = buffer.readBitDouble();
  double backClip = buffer.readBitDouble();
  bool vm0 = buffer.readBit();
  bool vm1 = buffer.readBit();
  bool vm2 = buffer.readBit();
  bool vm4 = buffer.readBit();
//  LOG_DEBUG(lensLen << " " << frontClip << " " << backClip << " " << vm0 << " " << vm1 << " " << vm2 << " " << vm4);

  if (version.isAtLeast(Version::R2000))
  {
    int rendermode = buffer.readRaw8();
//    LOG_DEBUG(rendermode);
  }

  if (version.isAtLeast(Version::R2007))
  {
    bool useDefaultLights = buffer.readBit();
    int deflig = buffer.readRaw8();
    double brightness = buffer.readBitDouble();
    double contrast = buffer.readBitDouble();
    Colour ambient = buffer.readColour(version, false);
  }

  double lowerLeftX = buffer.readRawDouble();
  double lowerLeftY = buffer.readRawDouble();
  double upperRightX = buffer.readRawDouble();
  double upperRightY = buffer.readRawDouble();
//  LOG_DEBUG("[" << lowerLeftX << ", " << lowerLeftY << "] [" << upperRightX << ", " << upperRightY << "]");
  bool vm3 = buffer.readBit();
  int zoom = buffer.readBit16();
  bool fastZoom = buffer.readBit();
  bool icon0 = buffer.readBit();
  bool icon1 = buffer.readBit();
  bool gridOn = buffer.readBit();
  double gridSpacingX = buffer.readRawDouble();
  double gridSpacingY = buffer.readRawDouble();
//  LOG_DEBUG("[" << gridSpacingX << ", " << gridSpacingY << "]");
  bool snapOn = buffer.readBit();
  bool snapStyle = buffer.readBit();
  int snapisopair = buffer.readBit16();
  double snaprot = buffer.readBitDouble();
  double snapBaseX = buffer.readRawDouble();
  double snapBaseY = buffer.readRawDouble();
  double snapSpaceX = buffer.readRawDouble();
  double snapSpaceY = buffer.readRawDouble();
//  LOG_DEBUG("[" << snapBaseX << ", " << snapBaseY << "] [" << snapSpaceX << ", " << snapSpaceY << "]");

  if (version.isAtLeast(Version::R2000))
  {
    buffer.readBit();
    bool ucsperview = buffer.readBit();
    double originX = buffer.readBitDouble();
    double originY = buffer.readBitDouble();
    double originZ = buffer.readBitDouble();
    double ucsXX = buffer.readBitDouble();
    double ucsXY = buffer.readBitDouble();
    double ucsXZ = buffer.readBitDouble();
    double ucsYX = buffer.readBitDouble();
    double ucsYY = buffer.readBitDouble();
    double ucsYZ = buffer.readBitDouble();
    double ucselevation = buffer.readBitDouble();
    int ucsorthotype = buffer.readBit16();
//    LOG_DEBUG("Origin [" << originX << ", " << originY << ", " << originZ << "]");
//    LOG_DEBUG("[" << ucsXX << ", " << ucsXY << ", " << ucsXZ << "]");
//    LOG_DEBUG("[" << ucsYX << ", " << ucsYY << ", " << ucsYZ << "]");
  }

  if (version.isAtLeast(Version::R2007))
  {
    int gridflag = buffer.readBit16();
    int gridmajor = buffer.readBit16();
  }

  Handle handlerefs = buffer.readHandle();
//  LOG_DEBUG(handle.getCode() << ": " << handle.getValue());

  if (version.isAtLeast(Version::R2007))
  {
    Handle bghandle = buffer.readHandle();
    Handle vshandle = buffer.readHandle();
    Handle sunhandle = buffer.readHandle();
  }

  if (version.isAtLeast(Version::R2000))
  {
    Handle namedUCShandle = buffer.readHandle();
    Handle baseUCShandle = buffer.readHandle();
//  LOG_DEBUG(namedUCShandle.getCode() << ": " << namedUCShandle.getValue());
//  LOG_DEBUG(baseUCShandle.getCode() << ": " << baseUCShandle.getValue());
  }

//  return core::rcFailure;

  return core::rcSuccess;
}
示例#6
0
文件: Session.cpp 项目: marek629/SIR
/** Restores session from XML file in \a fileName path.
  * \sa save()
  */
void Session::restore(const QString &fileName) {
    QFile file(fileName);

    QFileInfo info = QFileInfo(file);
    convertDialog->sessionDir = info.absoluteDir();
    convertDialog->effectsDir = info.absoluteDir();

    if (!file.open(QIODevice::ReadOnly)) {
        QMessageBox::warning(convertDialog, tr("Session read error"),
                             tr("Session restoring from %1 file failed.\n"
                                "Can't open the file.").arg(fileName) );
        return;
    }
    QDomDocument document;
    if (!document.setContent(&file)) {
        QMessageBox::warning(convertDialog, tr("Session read error"),
                             tr("Session restoring from %1 file failed.\n"
                                "Can't parse the file.").arg(fileName) );
        return;
    }
    QDomElement sir = document.firstChildElement("sir");
    Version version;
    bool fileInvalid(sir.isNull() ||
                     !version.isAtLeast(sir.attribute("version", version.version())) );
    QDomElement session = sir.firstChildElement("session");
    if (!fileInvalid)
        fileInvalid = (session.isNull() || !session.hasChildNodes());
    if (fileInvalid) {
        QMessageBox::warning(convertDialog, tr("Session read error"),
                             tr("Session restoring from %1 file failed.\n"
                                "Invalid file format.").arg(fileName) );
        return;
    }

    QDomElement elem, el, e; // working DOM element variables
    String str;
    QStringList list;
    int x;

    convertDialog->filesTreeWidget->clear();
    elem = session.firstChildElement("files");
    el = elem.firstChildElement("file");
    while (!el.isNull()) {
        convertDialog->filesTreeWidget->loadFile(el.text());
        el = el.nextSiblingElement("file");
    }

    elem = session.firstChildElement("target");
    if (!elem.isNull()) {
        el = elem.firstChildElement("dir");
        if (!el.isNull())
            convertDialog->destFileEdit->setText(el.text());
        el = elem.firstChildElement("prefix");
        if (!el.isNull())
            convertDialog->destPrefixEdit->setText(el.text());
        el = elem.firstChildElement("suffix");
        if (!el.isNull())
            convertDialog->destSuffixEdit->setText(el.text());
        el = elem.firstChildElement("format");
        if (!el.isNull())
            convertDialog->targetFormatComboBox->setCurrentIndex(
                convertDialog->targetFormatComboBox->findText(el.text()) );
    }

    elem = session.firstChildElement("size");
    if (!elem.isNull()) {
        str = elem.attribute("keepaspect", falseString);
        sizeArea->maintainCheckBox->setChecked(str.toBool());
        sizeArea->sizeUnitComboBox->setCurrentIndex(0);
        el = elem.firstChildElement("pixels");
        if (!el.isNull()) {
            sizeArea->widthDoubleSpinBox->setValue(el.attribute("width").toDouble());
            sizeArea->heightDoubleSpinBox->setValue(el.attribute("height").toDouble());
        }
        el = elem.firstChildElement("percent");
        if (!el.isNull()) {
            ConvertSharedData::instance()->sizeWidth = el.attribute("width").toDouble();
            ConvertSharedData::instance()->sizeHeight = el.attribute("height").toDouble();
        }
        el = elem.firstChildElement("filesize");
        if (!el.isNull()) {
            list = el.text().split(' ');
            sizeArea->fileSizeSpinBox->setValue(list[0].toDouble());
            sizeArea->fileSizeComboBox->setCurrentIndex(
                sizeArea->fileSizeComboBox->findText(list[1]) );
        }
        x = sizeArea->sizeUnitComboBox->findText('(' + elem.attribute("unit") + ')',
                Qt::MatchContains);
        sizeArea->sizeUnitComboBox->setCurrentIndex(x);
    }

    elem = session.firstChildElement("options");
    if (!elem.isNull()) {
        el = elem.firstChildElement("quality");
        if (!el.isNull())
            optionsArea->qualitySliderBox->setValue(el.text().toInt());
        el = elem.firstChildElement("progressiveWrite");
        if (el.isElement()) {
            str = el.attribute("enabled", falseString);
            optionsArea->progressiveWriteCheckBox->setChecked(str.toBool());
        }
        el = elem.firstChildElement("optimizedWrite");
        if (el.isElement()) {
            str = el.attribute("enabled", falseString);
            optionsArea->optimizedWriteCheckBox->setChecked(str.toBool());
        }
        el = elem.firstChildElement("background");
        if (!el.isNull()) {
            str = el.attribute("enabled", falseString);
            optionsArea->backgroundColorCheckBox->setChecked(str.toBool());
            optionsArea->backgroundColorFrame->setColor(readColor(el));
        }
        el = elem.firstChildElement("rotation");
        if (!el.isNull()) {
            str = el.attribute("enabled", falseString);
            optionsArea->rotateCheckBox->setChecked(str.toBool());
            optionsArea->rotateDoubleSpinBox->setValue(el.text().toDouble());
        }
        el = elem.firstChildElement("flip");
        if (!el.isNull())
            optionsArea->flipComboBox->setCurrentIndex(el.text().toInt());
    }

    elem = session.firstChildElement("effects");
    collector->read(elem);

    elem = session.firstChildElement("svg");
    if (!elem.isNull()) {
        str = elem.attribute("save");
        svgArea->saveCheckBox->setChecked(str.toBool());
        el = elem.firstChildElement("remove");
        if (!el.isNull()) {
            str = el.attribute("emptygroups", falseString);
            svgArea->removeGroupsCheckBox->setChecked(str.toBool());
            e = el.firstChildElement("text");
            if (!e.isNull()) {
                str = e.attribute("enabled", falseString);
                svgArea->removeTextCheckBox->setChecked(str.toBool());
                svgArea->removeTextLineEdit->setText(e.text());
            }
        }
    }
}