From 8b11d82d32469256ce633ef3194221f4025c055b Mon Sep 17 00:00:00 2001 From: Igor Korsukov Date: Mon, 16 Oct 2023 16:11:16 +0300 Subject: [PATCH] [engraving] changed implementation Beam shape --- src/engraving/dom/barline.cpp | 11 ------ src/engraving/dom/barline.h | 1 - src/engraving/dom/beam.cpp | 7 +--- src/engraving/dom/engravingitem.h | 28 ++++++++++---- src/engraving/infrastructure/shape.h | 8 ++-- src/engraving/rendering/dev/beamlayout.cpp | 43 +++++++++++++--------- 6 files changed, 51 insertions(+), 47 deletions(-) diff --git a/src/engraving/dom/barline.cpp b/src/engraving/dom/barline.cpp index 84e3665b04..aafa59becf 100644 --- a/src/engraving/dom/barline.cpp +++ b/src/engraving/dom/barline.cpp @@ -844,17 +844,6 @@ void BarLine::endEditDrag(EditData& ed) bed->yoff2 = 0.0; } -//--------------------------------------------------------- -// shape -//--------------------------------------------------------- - -Shape BarLine::doCreateShape() const -{ - Shape shape; - shape.add(ldata()->bbox(), this); - return shape; -} - //--------------------------------------------------------- // scanElements //--------------------------------------------------------- diff --git a/src/engraving/dom/barline.h b/src/engraving/dom/barline.h index b1b985aff3..b7058ca5ac 100644 --- a/src/engraving/dom/barline.h +++ b/src/engraving/dom/barline.h @@ -108,7 +108,6 @@ public: bool edit(EditData& ed) override; void editDrag(EditData&) override; void endEditDrag(EditData&) override; - Shape doCreateShape() const override; const ElementList* el() const { return &m_el; } diff --git a/src/engraving/dom/beam.cpp b/src/engraving/dom/beam.cpp index 56677d7ee7..d24d24f757 100644 --- a/src/engraving/dom/beam.cpp +++ b/src/engraving/dom/beam.cpp @@ -848,11 +848,8 @@ bool Beam::hasAllRests() Shape Beam::doCreateShape() const { - Shape shape; - for (BeamSegment* beamSegment : m_beamSegments) { - shape.add(beamSegment->shape()); - } - return shape; + UNREACHABLE; + return Shape(); } //------------------------------------------------------- diff --git a/src/engraving/dom/engravingitem.h b/src/engraving/dom/engravingitem.h index bc80db180a..9109a7a2d3 100644 --- a/src/engraving/dom/engravingitem.h +++ b/src/engraving/dom/engravingitem.h @@ -536,13 +536,25 @@ public: return m_shape.value(mode).bbox(); } -// Shape shape() const -// { -// Shape old = m_item->_internal_shape(); -// const Shape& sh = m_shape.value(LD_ACCESS::CHECK); -// DO_ASSERT(old.equal(sh)); -// return old; -// } + bool isSetShape() const { return m_shape.has_value(); } + void clearShape() { m_shape.reset(); } + Shape shape() const + { + const Shape& sh = m_shape.value(LD_ACCESS::CHECK); + + //! NOTE Temporary for debuging + { + switch (m_item->type()) { + case ElementType::BEAM: return sh; + default: + break; + } + } + Shape old = m_item->_internal_shape(); + return old; + } + + void setShape(const Shape& sh) { m_shape.set_value(sh); } void setBbox(const mu::RectF& r) { @@ -606,7 +618,7 @@ public: LayoutData* mutldata(); virtual double mag() const; - Shape shape() const { return doCreateShape(); } + Shape shape() const { return ldata()->shape(); } virtual double baseLine() const { return -height(); } mu::RectF abbox(LD_ACCESS mode = LD_ACCESS::CHECK) const { return ldata()->bbox(mode).translated(pagePos()); } diff --git a/src/engraving/infrastructure/shape.h b/src/engraving/infrastructure/shape.h index 13c939a38c..379c8a72c5 100644 --- a/src/engraving/infrastructure/shape.h +++ b/src/engraving/infrastructure/shape.h @@ -82,11 +82,11 @@ public: bool equal(const Shape& sh) const { - if (m_type != sh.m_type) { - return false; - } +// if (m_type != sh.m_type) { +// return false; +// } - switch (m_type) { + switch (sh.type()) { case Type::Fixed: return this->bbox() == sh.bbox(); case Type::Composite: return this->m_elements == sh.m_elements; } diff --git a/src/engraving/rendering/dev/beamlayout.cpp b/src/engraving/rendering/dev/beamlayout.cpp index 784698bf66..2ea7c62aff 100644 --- a/src/engraving/rendering/dev/beamlayout.cpp +++ b/src/engraving/rendering/dev/beamlayout.cpp @@ -52,6 +52,7 @@ using namespace mu::engraving::rendering::dev; void BeamLayout::layout(Beam* item, LayoutContext& ctx) { + Beam::LayoutData* ldata = item->mutldata(); // all of the beam layout code depends on _elements being in order by tick // this may not be the case if two cr's were recently swapped. std::sort(item->elements().begin(), item->elements().end(), @@ -83,7 +84,9 @@ void BeamLayout::layout(Beam* item, LayoutContext& ctx) } crl.push_back(cr); } - item->setbbox(RectF()); + + Shape beamShape(Shape::Type::Composite); + if (!crl.empty()) { SpannerSegmentType st; if (n == 0) { @@ -96,30 +99,34 @@ void BeamLayout::layout(Beam* item, LayoutContext& ctx) } layout2(item, ctx, crl, st, static_cast(n)); - double lw2 = item->beamWidth() / 2.0; +// double lw2 = item->beamWidth() / 2.0; for (const BeamSegment* bs : item->beamSegments()) { - PolygonF a(4); - a[0] = PointF(bs->line.x1(), bs->line.y1()); - a[1] = PointF(bs->line.x2(), bs->line.y2()); - a[2] = PointF(bs->line.x2(), bs->line.y2()); - a[3] = PointF(bs->line.x1(), bs->line.y1()); + beamShape.add(bs->shape()); - RectF pr = a.boundingRect(); - //! TODO In some cases (/vtest/scores/beams-19.mscz) the points of the line may be nan. - //! This is a correction of the effect, we need to find the cause. - { - pr.setX((std::isinf(pr.x()) || std::isnan(pr.x())) ? 0.0 : pr.x()); - pr.setY((std::isinf(pr.y()) || std::isnan(pr.y())) ? 0.0 : pr.y()); - pr.setWidth((std::isinf(pr.width()) || std::isnan(pr.width())) ? 0.0 : pr.width()); - pr.setHeight((std::isinf(pr.height()) || std::isnan(pr.height())) ? 0.0 : pr.height()); - } +// PolygonF a(4); +// a[0] = PointF(bs->line.x1(), bs->line.y1()); +// a[1] = PointF(bs->line.x2(), bs->line.y2()); +// a[2] = PointF(bs->line.x2(), bs->line.y2()); +// a[3] = PointF(bs->line.x1(), bs->line.y1()); - RectF r(pr.adjusted(0.0, -lw2, 0.0, lw2)); - item->addbbox(r); +// RectF pr = a.boundingRect(); +// //! TODO In some cases (/vtest/scores/beams-19.mscz) the points of the line may be nan. +// //! This is a correction of the effect, we need to find the cause. +// { +// pr.setX((std::isinf(pr.x()) || std::isnan(pr.x())) ? 0.0 : pr.x()); +// pr.setY((std::isinf(pr.y()) || std::isnan(pr.y())) ? 0.0 : pr.y()); +// pr.setWidth((std::isinf(pr.width()) || std::isnan(pr.width())) ? 0.0 : pr.width()); +// pr.setHeight((std::isinf(pr.height()) || std::isnan(pr.height())) ? 0.0 : pr.height()); +// } + +// RectF r(pr.adjusted(0.0, -lw2, 0.0, lw2)); +// item->addbbox(r); } } + ldata->setShape(beamShape); + // The beam may have changed shape. one-note trems within this beam need to be layed out here for (ChordRest* cr : item->elements()) { if (cr->isChord() && toChord(cr)->tremolo() && !toChord(cr)->tremolo()->twoNotes()) {