同步main
parent
fbfc5f2759
commit
99d31f4db4
|
@ -149,7 +149,7 @@ QJsonArray LayerStyleContainer::toJson() const
|
|||
QStringList LayerStyleContainer::unusedStyleNames() const
|
||||
{
|
||||
QStringList result;
|
||||
for(const auto& name : unusedStyles | std::views::keys)
|
||||
for (const auto& name : unusedStyles | std::views::keys)
|
||||
{
|
||||
result << name;
|
||||
}
|
||||
|
@ -293,208 +293,6 @@ QJsonObject StrokeElementLayerStyle::toJson() const
|
|||
return json;
|
||||
}
|
||||
|
||||
std::unique_ptr<LayerStyle> StrokeElementLayerStyle::clone() const
|
||||
{
|
||||
LayerStyleContainer container(isClosedElement);
|
||||
for (const auto& style : jsonArray)
|
||||
{
|
||||
container.useStyle(LayerStyle::fromJson(style.toObject()));
|
||||
}
|
||||
return container;
|
||||
}
|
||||
|
||||
LayerStyleContainer::LayerStyleContainer(bool isClosedElement) : hash(0)
|
||||
{
|
||||
for (const auto& style : commonStyles)
|
||||
{
|
||||
unusedStyles.insert(style);
|
||||
}
|
||||
if (isClosedElement)
|
||||
{
|
||||
for (const auto& style : closedOnlyStyles)
|
||||
{
|
||||
unusedStyles.insert(style);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (const auto& style : unclosedOnlyStyles)
|
||||
{
|
||||
unusedStyles.insert(style);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Renderer::BaseStyle> LayerStyleContainer::toBaseStyles() const
|
||||
{
|
||||
std::vector<Renderer::BaseStyle> result;
|
||||
for (const auto& style : styles | std::views::values)
|
||||
{
|
||||
auto baseStyles = style->toBaseStyles();
|
||||
result.insert(result.end(),
|
||||
std::make_move_iterator(baseStyles.begin()),
|
||||
std::make_move_iterator(baseStyles.end()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QJsonArray LayerStyleContainer::toJson() const
|
||||
{
|
||||
QJsonArray json;
|
||||
for (const auto& style : styles | std::views::values)
|
||||
{
|
||||
json.append(style->toJson());
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
QStringList LayerStyleContainer::unusedStyleNames() const
|
||||
{
|
||||
QStringList result;
|
||||
for(const auto& name : unusedStyles | std::views::keys)
|
||||
{
|
||||
result << name;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::unique_ptr<LayerStyle> LayerStyleContainer::makeUnusedStyle(const QString& styleName) const
|
||||
{
|
||||
return unusedStyles.at(styleName)();
|
||||
}
|
||||
|
||||
bool LayerStyleContainer::empty() const
|
||||
{
|
||||
return styles.empty();
|
||||
}
|
||||
|
||||
bool LayerStyleContainer::full() const
|
||||
{
|
||||
return unusedStyles.empty();
|
||||
}
|
||||
|
||||
std::map<QString, std::shared_ptr<LayerStyle>>::iterator LayerStyleContainer::begin()
|
||||
{
|
||||
return styles.begin();
|
||||
}
|
||||
|
||||
std::map<QString, std::shared_ptr<LayerStyle>>::iterator LayerStyleContainer::end()
|
||||
{
|
||||
return styles.end();
|
||||
}
|
||||
|
||||
bool LayerStyleContainer::useStyle(const std::shared_ptr<LayerStyle>& style)
|
||||
{
|
||||
auto styleNode = unusedStyles.extract(style->getDisplayName());
|
||||
if (styleNode.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
styles[styleNode.key()] = style;
|
||||
usedStyles.insert(std::move(styleNode));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LayerStyleContainer::dropStyle(const QString& styleName)
|
||||
{
|
||||
auto styleNode = usedStyles.extract(styleName);
|
||||
if (styleNode.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
styles.erase(styleName);
|
||||
unusedStyles.insert(std::move(styleNode));
|
||||
return true;
|
||||
}
|
||||
|
||||
float LayerStyleContainer::boundingBoxAffectValue() const {
|
||||
float maxLineWidth = 0;
|
||||
const auto strokeStyle = styles.find(StrokeElementLayerStyle::displayName());
|
||||
if (strokeStyle != styles.end())
|
||||
{
|
||||
if (const auto strokeElementLayerStyle =
|
||||
std::dynamic_pointer_cast<StrokeElementLayerStyle>(strokeStyle->second);
|
||||
strokeElementLayerStyle != nullptr)
|
||||
{
|
||||
const auto& leftStyleStroke = strokeElementLayerStyle->strokePair.first;
|
||||
const auto& rightStyleStroke = strokeElementLayerStyle->strokePair.second;
|
||||
if (leftStyleStroke != nullptr)
|
||||
{
|
||||
maxLineWidth = std::max(maxLineWidth, leftStyleStroke->halfWidth);
|
||||
}
|
||||
if (rightStyleStroke != nullptr)
|
||||
{
|
||||
maxLineWidth = std::max(maxLineWidth, rightStyleStroke->halfWidth);
|
||||
}
|
||||
}
|
||||
}
|
||||
return maxLineWidth;
|
||||
}
|
||||
|
||||
size_t LayerStyleContainer::getHash() const
|
||||
{
|
||||
return hash;
|
||||
}
|
||||
|
||||
std::unique_ptr<StrokeElementLayerStyle> StrokeElementLayerStyle::fromJson(const QJsonObject& json)
|
||||
{
|
||||
auto ptr = std::make_unique<StrokeElementLayerStyle>(
|
||||
std::static_pointer_cast<MaterialStyleStroke>(
|
||||
std::shared_ptr(std::move(MaterialStyle::decoded(EncodeUtil::fromBase64<GLfloat>(json["left"].toString()))))
|
||||
),
|
||||
std::static_pointer_cast<MaterialStyleStroke>(
|
||||
std::shared_ptr(std::move(MaterialStyle::decoded(EncodeUtil::fromBase64<GLfloat>(json["right"].toString()))))
|
||||
)
|
||||
);
|
||||
ptr->enableEachSideIndependent = json["enableEachSideIndependent"].toBool();
|
||||
return ptr;
|
||||
}
|
||||
|
||||
StrokeElementLayerStyle::StrokeElementLayerStyle()
|
||||
{
|
||||
const auto materialMap = std::map<float, Renderer::Material>();
|
||||
this->strokePair.first = std::make_shared<MaterialStyleStroke>(
|
||||
7,
|
||||
Renderer::StrokeType::kLeftSide, Renderer::StrokeEndType::kFlat,
|
||||
std::make_shared<Renderer::StrokeRadialGradient>(materialMap, false)
|
||||
);
|
||||
|
||||
this->strokePair.second = std::make_shared<MaterialStyleStroke>(
|
||||
7,
|
||||
Renderer::StrokeType::kRightSide, Renderer::StrokeEndType::kFlat,
|
||||
std::make_shared<Renderer::StrokeRadialGradient>(materialMap, false)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
StrokeElementLayerStyle::StrokeElementLayerStyle(const PMaterialStyleStroke& left, const PMaterialStyleStroke& right)
|
||||
{
|
||||
this->strokePair.first = left;
|
||||
this->strokePair.second = right ? right : std::static_pointer_cast<MaterialStyleStroke>(
|
||||
std::shared_ptr(std::move(left->clone()))
|
||||
);
|
||||
}
|
||||
|
||||
StrokeElementLayerStyle::StrokeElementLayerStyle(const StrokeElementLayerStyle& other)
|
||||
{
|
||||
strokePair.first = std::static_pointer_cast<MaterialStyleStroke>(
|
||||
std::shared_ptr(std::move(other.strokePair.first->clone()))
|
||||
);
|
||||
strokePair.second = std::static_pointer_cast<MaterialStyleStroke>(
|
||||
std::shared_ptr(std::move(other.strokePair.second->clone()))
|
||||
);
|
||||
enableEachSideIndependent = other.enableEachSideIndependent;
|
||||
}
|
||||
|
||||
QJsonObject StrokeElementLayerStyle::toJson() const
|
||||
{
|
||||
auto json = LayerStyle::toJson();
|
||||
json["enableEachSideIndependent"] = enableEachSideIndependent;
|
||||
json["left"] = EncodeUtil::toBase64<GLfloat>(strokePair.first->encoded());
|
||||
json["right"] = EncodeUtil::toBase64<GLfloat>(strokePair.second->encoded());
|
||||
return json;
|
||||
}
|
||||
|
||||
std::unique_ptr<LayerStyle> StrokeElementLayerStyle::clone() const
|
||||
{
|
||||
return std::make_unique<StrokeElementLayerStyle>(StrokeElementLayerStyle(*this));
|
||||
|
|
|
@ -253,7 +253,7 @@ GLuint Renderer::Model::loadPainting(std::string path)
|
|||
vector<std::pair<std::shared_ptr<Contour>, float>> contours;
|
||||
Painting painting;
|
||||
//if (auto file = QFileInfo(QString(path.c_str())); file.isFile())
|
||||
if(auto file = QFileInfo(QString("../test.json")); file.isFile())
|
||||
if (auto file = QFileInfo(QString("../test.json")); file.isFile())
|
||||
painting = PaintingUtil::transfromToPainting("../test.json");
|
||||
else
|
||||
{
|
||||
|
@ -376,6 +376,7 @@ GLuint Renderer::Model::loadPainting(std::string path)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
painting.generateBuffers(glFunc);
|
||||
|
||||
auto index = vtManager->createVirtualTexture(painting);
|
||||
|
|
Loading…
Reference in New Issue