Skip to content

Commit

Permalink
Merge branch 'implement-faces-property' into implement-facelist-property
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/path/face.cpp
#	src/path/face.h
#	src/properties/CMakeLists.txt
#	src/properties/splineproperty.cpp
#	src/propertytypeenum.h
#	src/renderers/offscreenrenderer.cpp
#	src/variant.h
  • Loading branch information
Pascal Bies committed Apr 1, 2022
2 parents 319bd04 + d2ef593 commit c53cce5
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 55 deletions.
26 changes: 0 additions & 26 deletions src/mainwindow/pathactions.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
#include "mainwindow/pathactions.h"
} else {
worker.sub(EMPTY_POINTER)->set_value(false);
worker.sub(PATH_ID_POINTER)->set_value(path_points.front()->path_vector()->path_object()->id());
worker.set_value(path_points, [](const auto* path_point, auto& worker) {
worker.set_value(path_point->index());
});
}
}
#include "commands/addcommand.h"
#include "commands/joinpointscommand.h"
#include "commands/modifypointscommand.h"
Expand Down Expand Up @@ -181,24 +173,6 @@ void remove_selected_faces(Application& app)
Q_UNUSED(app)
}

void convert_objects(Application& app)
{
const auto convertibles = util::remove_if(app.scene->item_selection<Object>(), [](const Object* o) {
return !(o->flags() & Flag::Convertible);
});
if (!convertibles.empty()) {
Scene& scene = *app.scene;
auto macro = scene.history().start_macro(QObject::tr("convert"));
scene.submit<ObjectSelectionCommand>(*app.scene, convertibles);
const auto converted_objects = convert_objects_recursively(app, convertibles);
scene.submit<ObjectSelectionCommand>(*app.scene, converted_objects);
const auto is_path = [](auto&& object) { return object->type() == PathObject::TYPE; };
if (std::all_of(converted_objects.begin(), converted_objects.end(), is_path)) {
scene.set_mode(SceneMode::Vertex);
}
}
}

void remove_selected_items(Application& app)
{
switch (app.scene_mode()) {
Expand Down
12 changes: 11 additions & 1 deletion src/path/face.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "path/edge.h"
#include <QString>
#include <list>
#include <deque>
Expand All @@ -10,9 +11,14 @@ class QPainterPath;
namespace omm
{

namespace serialization
{
class SerializerWorker;
class DeserializerWorker;
} // namespace serialization

class Point;
class PathPoint;
class Edge;

class Face
{
Expand Down Expand Up @@ -59,6 +65,10 @@ class Face
[[nodiscard]] bool operator!=(const Face& other) const;
[[nodiscard]] bool operator<(const Face& other) const;

class ReferencePolisher;
void serialize(serialization::SerializerWorker& worker) const;
void deserialize(serialization::DeserializerWorker& worker);

private:
std::deque<Edge> m_edges;
};
Expand Down
6 changes: 0 additions & 6 deletions src/properties/facelistproperty.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
#include "properties/facelistproperty.h"
#include <QCoreApplication>

namespace omm
{

const Property::PropertyDetail FaceListProperty::detail{nullptr};

FaceListProperty::FaceListProperty(const FaceList& default_value)
: TypedProperty(default_value)
{
}

void FaceListProperty::deserialize(serialization::DeserializerWorker &worker)
{
TypedProperty::deserialize(worker);
Expand Down
3 changes: 1 addition & 2 deletions src/properties/facelistproperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ namespace omm
class FaceListProperty : public TypedProperty<FaceList>
{
public:
explicit FaceListProperty(const FaceList& default_value = FaceList{});
using TypedProperty::TypedProperty;
void deserialize(serialization::DeserializerWorker& worker) override;
void serialize(serialization::SerializerWorker& worker) const override;
static constexpr auto MODE_PROPERTY_KEY = "mode";

static const PropertyDetail detail;
};
Expand Down
21 changes: 21 additions & 0 deletions src/properties/facesproperty.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//#include "properties/facesproperty.h"


//namespace omm
//{

//const Property::PropertyDetail FacesProperty::detail{nullptr};

//void FacesProperty::deserialize(serialization::DeserializerWorker& worker)
//{
// TypedProperty::deserialize(worker);
// set(worker.sub(TypedPropertyDetail::VALUE_POINTER)->get<Faces>());
//}

//void FacesProperty::serialize(serialization::SerializerWorker& worker) const
//{
// TypedProperty::serialize(worker);
// worker.sub(TypedPropertyDetail::VALUE_POINTER)->set_value(value());
//}

//} // namespace omm
19 changes: 19 additions & 0 deletions src/properties/facesproperty.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//#pragma once

//#include "path/face.h"
//#include "properties/typedproperty.h"


//namespace omm
//{

//class FacesProperty : public TypedProperty<Faces>
//{
//public:
// using TypedProperty::TypedProperty;
// void deserialize(serialization::DeserializerWorker& worker) override;
// void serialize(serialization::SerializerWorker& worker) const override;
// static const PropertyDetail detail;
//};

//} // namespace omm
6 changes: 1 addition & 5 deletions src/properties/splineproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

namespace omm
{
const Property::PropertyDetail SplineProperty::detail{nullptr};

SplineProperty::SplineProperty(const omm::SplineType& default_value)
: TypedProperty(default_value)
{
}
const Property::PropertyDetail SplineProperty::detail{nullptr};

void SplineProperty::deserialize(serialization::DeserializerWorker& worker)
{
Expand Down
4 changes: 2 additions & 2 deletions src/properties/splineproperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

#include "properties/typedproperty.h"
#include "splinetype.h"
#include <Qt>

namespace omm
{

class SplineProperty : public TypedProperty<SplineType>
{
public:
explicit SplineProperty(const SplineType& default_value = SplineType());
using TypedProperty::TypedProperty;
void deserialize(serialization::DeserializerWorker& worker) override;
void serialize(serialization::SerializerWorker& worker) const override;
static constexpr auto MODE_PROPERTY_KEY = "mode";
Expand Down
10 changes: 5 additions & 5 deletions src/propertytypeenum.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FaceList;

enum class Type{
Invalid, Float, Integer, Option, FloatVector,
IntegerVector, String, Color, Reference, Bool, Spline, Trigger, FaceList
IntegerVector, String, Color, Reference, Bool, Spline, Trigger, Faces,
};

constexpr bool is_integral(const Type type)
Expand Down Expand Up @@ -47,7 +47,7 @@ constexpr bool is_color(const Type type)
constexpr auto variant_types = std::array{
Type::Bool, Type::Float, Type::Color, Type::Integer, Type::IntegerVector,
Type::FloatVector, Type::Reference, Type::String, Type::Option, Type::Trigger,
Type::FloatVector, Type::IntegerVector, Type::Spline, Type::FaceList, Type::Invalid
Type::FloatVector, Type::IntegerVector, Type::Spline, Type::Faces, Type::Invalid
};

constexpr std::string_view variant_type_name(const Type type) noexcept
Expand Down Expand Up @@ -75,8 +75,8 @@ constexpr std::string_view variant_type_name(const Type type) noexcept
return QT_TRANSLATE_NOOP("DataType", "IntegerVector");
case Type::Spline:
return QT_TRANSLATE_NOOP("DataType", "Spline");
case Type:: FaceList:
return QT_TRANSLATE_NOOP("DataType", "FaceList");
case Type::Faces:
return QT_TRANSLATE_NOOP("DataType", "Faces");
case Type:: Invalid:
return QT_TRANSLATE_NOOP("DataType", "Invalid");
}
Expand Down Expand Up @@ -111,7 +111,7 @@ template<typename T> constexpr Type get_variant_type() noexcept
} else if constexpr (std::is_same_v<T, SplineType>) {
return Type::Spline;
} else if constexpr (std::is_same_v<T, FaceList>) {
return Type::FaceList;
return Type::Faces;
} else {
return Type::Invalid;
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/offscreenrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void set_uniform(omm::OffscreenRenderer& self, const QString& name, const T& val
const auto mat = value.to_qmatrix3x3();
program->setUniformValue(location, mat);
} else if constexpr (std::is_same_v<T, FaceList>) {
// FaceList is not available in GLSL
// faces is not available in GLSL
} else {
// statically fail here. If you're data type is not supported, add it explicitely.
static_assert(std::is_same_v<T, int> && !std::is_same_v<T, int>);
Expand Down
11 changes: 6 additions & 5 deletions src/scene/disjointpathpointsetforest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
#include "objects/pathobject.h"
#include "scene/scene.h"

static constexpr auto FOREST_POINTER = "forest";
static constexpr auto PATH_ID_POINTER = "path-id";
static constexpr auto INDEX_POINTER = "index";

namespace
{

static constexpr auto FOREST_POINTER = "forest";
static constexpr auto PATH_ID_POINTER = "path-id";
static constexpr auto INDEX_POINTER = "index";

struct PathPointId
{
constexpr explicit PathPointId(const std::size_t path_id, const std::size_t point_index)
Expand Down Expand Up @@ -51,8 +52,8 @@ class DisjointPathPointSetForest::ReferencePolisher : public omm::serialization:
for (const auto& set : m_joined_point_indices) {
auto& forest_set = m_ref.m_forest.emplace_back();
for (const auto& [path_id, point_index] : set) {
auto* path_object = dynamic_cast<PathObject*>(map.at(path_id));
auto& path_point = path_object->geometry().point_at_index(point_index);
const auto& path_object = dynamic_cast<PathObject&>(*map.at(path_id));
auto& path_point = path_object.geometry().point_at_index(point_index);
forest_set.insert(&path_point);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/serializers/deserializerworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ variant_type DeserializerWorker::get(const QString& type)
return get<Vec2f>();
} else if (type == "IntegerVector") {
return get<Vec2i>();
} else if (type == "FacesList") {
return get<FaceList>();
} else if (type == "SplineType") {
return get<SplineType>();
} else if (type == "Reference") {
Expand Down
6 changes: 4 additions & 2 deletions src/variant.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#pragma once

#include "color/color.h"
#include "path/face.h"
#include "geometry/vec2.h"
#include "logging.h"
#include "splinetype.h"
#include "facelist.h"
#include <QString>
#include <variant>
#include <deque>

namespace omm
{
Expand All @@ -23,8 +25,8 @@ class TriggerPropertyDummyValueType
{
return false;
}
}
;
};

using variant_type = std::variant<bool,
double,
Color,
Expand Down

0 comments on commit c53cce5

Please sign in to comment.