diff --git a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp index 93cf184..a46ffa4 100644 --- a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp +++ b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp @@ -41,7 +41,8 @@ Painting PaintingUtil::transfromToPainting(QString jsonFilePath) { shared_ptr layerManager = make_shared(jsonObj, elementManager.get()); LayerWrapper* root = layerManager->getRoot(); root->getCache(); - handleLayerWrapper(root, QTransform(), painting, contourMap, QSize(jsonObj.value("width").toVariant().value(), jsonObj.value("height").toVariant().value())); + double maxWidth = getMaxLineWidth(root, QTransform()); + handleLayerWrapper(root, QTransform(), painting, maxWidth, contourMap, QSize(jsonObj.value("width").toVariant().value(), jsonObj.value("height").toVariant().value())); clear(); return painting; //qDebug() << elementManager->toJson(); @@ -70,7 +71,7 @@ Painting PaintingUtil::transfromToPainting(QString jsonFilePath) { } -void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transform, Painting& painting, std::unordered_map& contourMap, const QSize& screenSize) { +void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transform, Painting& painting, double& maxWidth, std::unordered_map& contourMap, const QSize& screenSize) { LeafLayerWrapper* leafLayer = dynamic_cast(nowLayer); qDebug() << nowLayer; @@ -80,7 +81,7 @@ void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transfo GroupElement* wrapperElement = dynamic_cast(leafLayer->wrappedElement); if (wrapperElement != nullptr) { - handleLayerWrapper(wrapperElement->sourceLayer, transform, painting, contourMap, screenSize); + handleLayerWrapper(wrapperElement->sourceLayer, transform, painting, maxWidth, contourMap, screenSize); return; } @@ -90,7 +91,7 @@ void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transfo //qDebug() << leafLayer<<"------" << painterPath; // transform to -1£¬ 1 QTransform trans; - double maxLen = std::max(bound.width(), bound.height()) * 1.00001 * 2; + double maxLen = (std::max(bound.width(), bound.height()) + 2 * maxWidth) * 1.00001 * 2; //qDebug() << maxLen << bound; trans.scale(1 / maxLen, 1 / maxLen); trans.translate(-bound.center().x(), -bound.center().y()); @@ -157,8 +158,60 @@ void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transfo FolderLayerWrapper* folderLayer = dynamic_cast(nowLayer); if (folderLayer != nullptr) { for (auto sonLayer : folderLayer->children) { - handleLayerWrapper(sonLayer.get(), transform, painting, contourMap, screenSize); + handleLayerWrapper(sonLayer.get(), transform, painting, maxWidth, contourMap, screenSize); } } return; +} + +double PaintingUtil::getMaxLineWidth(LayerWrapper* nowLayer, QTransform transform) { + LeafLayerWrapper* leafLayer = dynamic_cast(nowLayer); + transform = nowLayer->property.transform * transform; + + double maxWidth = 0; + if (leafLayer != nullptr) { + + GroupElement* wrapperElement = dynamic_cast(leafLayer->wrappedElement); + if (wrapperElement != nullptr) { + return getMaxLineWidth(wrapperElement->sourceLayer, transform); + } + + PixelPath pixelPath = nowLayer->getCache(); + QPainterPath painterPath = pixelPath.originPath; + QRectF bound = painterPath.boundingRect(); + //qDebug() << maxLen << bound; + // + //++zIndexCount; + auto baseStyles = leafLayer->styles->toBaseStyles(); + qDebug() << baseStyles.size(); + for (auto& baseStyle : std::views::reverse(baseStyles)) { + double lineWidth = 0; + QPainterPath path; + + std::shared_ptr material; + + if (baseStyle.material->type() == Renderer::MaterialStyleType::kStroke) { + qDebug() << "MaterialStyleType::kStroke"; + std::shared_ptr copy = baseStyle.material->clone(); + lineWidth = std::static_pointer_cast(copy)->halfWidth; + maxWidth = std::max(maxWidth, lineWidth); + } + else + { + qDebug() << "MaterialStyleType::kFill"; + material = baseStyle.material; + path = painterPath; + } + } + + return maxWidth; + } + + FolderLayerWrapper* folderLayer = dynamic_cast(nowLayer); + if (folderLayer != nullptr) { + for (auto sonLayer : folderLayer->children) { + maxWidth = std::max(maxWidth, getMaxLineWidth(sonLayer.get(), transform)); + } + } + return maxWidth; } \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.h b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.h index 2e6258b..76517cb 100644 --- a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.h +++ b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.h @@ -12,8 +12,8 @@ private: static void clear(); //static const double pi; static QJsonObject readJsonFile(QString jsonFilePath); - static void handleLayerWrapper(LayerWrapper* nowLayer, QTransform transform, Renderer::Painting& painting, std::unordered_map& contourMap, const QSize& screenSize); - //static double getMaxLineWidth(LayerWrapper* root); + static void handleLayerWrapper(LayerWrapper* nowLayer, QTransform transform, Renderer::Painting& painting, double &maxWidth, std::unordered_map& contourMap, const QSize& screenSize); + static double getMaxLineWidth(LayerWrapper* nowLayer, QTransform transform); public: static Renderer::Painting transfromToPainting(QString jsonFilePath); };