Verovio
Source code documentation
floatingobject.h
1 // Name: floatingobject.h
3 // Author: Laurent Pugin
4 // Created: 2015
5 // Copyright (c) Authors and others. All rights reserved.
7 
8 #ifndef __VRV_FLOATING_OBJECT_H__
9 #define __VRV_FLOATING_OBJECT_H__
10 
11 #include "devicecontextbase.h"
12 #include "object.h"
13 
14 namespace vrv {
15 
16 class Alignment;
17 class FloatingPositioner;
18 class StaffAlignment;
19 
20 //----------------------------------------------------------------------------
21 // FloatingObject
22 //----------------------------------------------------------------------------
23 
28 class FloatingObject : public Object {
29 public:
36  FloatingObject(ClassId classId);
37  virtual ~FloatingObject();
38  void Reset() override;
39  void ResetDrawing();
41 
42  void UpdateContentBBoxX(int x1, int x2) override;
43  void UpdateContentBBoxY(int y1, int y2) override;
44  void UpdateSelfBBoxX(int x1, int x2) override;
45  void UpdateSelfBBoxY(int y1, int y2) override;
46 
51  int GetDrawingX() const override;
52  int GetDrawingY() const override;
54 
59  void SetCurrentFloatingPositioner(FloatingPositioner *boundingBox);
60  FloatingPositioner *GetCurrentFloatingPositioner() { return m_currentPositioner; }
61  const FloatingPositioner *GetCurrentFloatingPositioner() const { return m_currentPositioner; }
63 
72 
78  int GetDrawingGrpId() const { return m_drawingGrpId; }
79  void SetDrawingGrpId(int drawingGrpId) { m_drawingGrpId = drawingGrpId; }
80  int SetDrawingGrpObject(void *drawingGrpObject);
82 
88  void ResetMaxDrawingYRel() { m_maxDrawingYRel = VRV_UNSET; }
89  void SetMaxDrawingYRel(int maxDrawingYRel, data_STAFFREL place);
90  int GetMaxDrawingYRel() const { return m_maxDrawingYRel; };
92 
97  void ResetDrawingObjectIDs();
99 
103  virtual bool IsExtenderElement() const { return false; }
104 
108  virtual bool IsCloserToStaffThan(const FloatingObject *, data_STAFFREL) const { return false; }
109 
116  virtual std::pair<int, bool> GetVerticalContentBoundaryRel(const Doc *doc, const FloatingPositioner *positioner,
117  const BoundingBox *horizOverlappingBBox, bool contentTop) const;
118 
119  //----------//
120  // Functors //
121  //----------//
122 
127  FunctorCode Accept(Functor &functor) override;
128  FunctorCode Accept(ConstFunctor &functor) const override;
129  FunctorCode AcceptEnd(Functor &functor) override;
130  FunctorCode AcceptEnd(ConstFunctor &functor) const override;
132 
133 private:
134  //
135 public:
136  //
137 private:
138  FloatingPositioner *m_currentPositioner;
139 
140  /* Drawing Id to group floating elements horizontally */
141  int m_drawingGrpId;
142 
143  int m_maxDrawingYRel;
144 
145  //----------------//
146  // Static members //
147  //----------------//
148 
155  static thread_local std::vector<void *> s_drawingObjectIds;
156 };
157 
158 //----------------------------------------------------------------------------
159 // FloatingPositioner
160 //----------------------------------------------------------------------------
161 
166 public:
167  // constructors and destructors
168  FloatingPositioner(FloatingObject *object, StaffAlignment *alignment, char spanningType);
169  virtual ~FloatingPositioner() {}
170  ClassId GetClassId() const override { return FLOATING_POSITIONER; }
171 
172  virtual void ResetPositioner();
173 
178  int GetDrawingX() const override;
179  int GetDrawingY() const override;
181 
182  void ResetCachedDrawingX() const override;
183  void ResetCachedDrawingY() const override;
184 
189  void SetObjectXY(Object *objectX, Object *objectY);
190  Object *GetObjectX() { return m_objectX; }
191  const Object *GetObjectX() const { return m_objectX; }
192  Object *GetObjectY() { return m_objectY; }
193  const Object *GetObjectY() const { return m_objectY; }
195 
201  const FloatingObject *GetObject() const { return m_object; }
203 
209  const StaffAlignment *GetAlignment() const { return m_alignment; }
211 
215  char GetSpanningType() const { return m_spanningType; }
216 
217  data_STAFFREL GetDrawingPlace() const { return m_place; }
218 
224  int GetDrawingYRel() const { return m_drawingYRel; }
225  virtual void SetDrawingYRel(int drawingYRel, bool force = false);
226  int GetDrawingXRel() const { return m_drawingXRel; }
227  virtual void SetDrawingXRel(int drawingXRel);
229 
235  int GetDrawingExtenderWidth() const { return m_drawingExtenderWidth; }
236  void SetDrawingExtenderWidth(int extenderWidth) { m_drawingExtenderWidth = extenderWidth; }
238 
242  bool HasHorizontalOverlapWith(const BoundingBox *bbox, int unit) const;
243 
248  int GetAdmissibleHorizOverlapMargin(const BoundingBox *bbox, int unit) const;
249 
253  void CalcDrawingYRel(const Doc *doc, const StaffAlignment *staffAlignment, const BoundingBox *horizOverlappingBBox);
254 
259 
264  const Doc *doc, const StaffAlignment *staffAlignment, const BoundingBox *horizOverlappingBBox) const;
265 
271  std::pair<int, bool> GetVerticalContentBoundaryRel(
272  const Doc *doc, const BoundingBox *horizOverlappingBBox, bool contentTop) const;
273  int GetVerticalContentBoundary(const Doc *doc, const BoundingBox *horizOverlappingBBox, bool contentTop) const;
275 
279  bool HasVerticalContentOverlap(const Doc *doc, const BoundingBox *horizOverlappingBBox, int margin) const;
280 
281 private:
282  Object *m_objectX;
283  Object *m_objectY;
284 
285 protected:
297 
302 
307 
312 
313  data_STAFFREL m_place;
314 
315 public:
320 };
321 
322 //----------------------------------------------------------------------------
323 // FloatingCurvePositioner
324 //----------------------------------------------------------------------------
325 
330 public:
331  // constructors and destructors
332  FloatingCurvePositioner(FloatingObject *object, StaffAlignment *alignment, char spanningType);
333  virtual ~FloatingCurvePositioner();
334  ClassId GetClassId() const override { return FLOATING_CURVE_POSITIONER; }
335 
336  void ResetPositioner() override;
337 
343 
349  void UpdateCurveParams(const Point points[4], int thickness, curvature_CURVEDIR curveDir);
350  void UpdatePoints(const BezierCurve &bezier);
352 
357  void MoveFrontHorizontal(int distance);
358  void MoveBackHorizontal(int distance);
359  void MoveFrontVertical(int distance);
360  void MoveBackVertical(int distance);
362 
366  int CalcMinMaxY(const Point points[4]) const;
367 
374  const BoundingBox *boundingBox, bool &discard, int margin = 0, bool horizontalOverlap = true) const;
375  int CalcDirectionalAdjustment(const BoundingBox *boundingBox, bool isCurveAbove, bool &discard, int margin = 0,
376  bool horizontalOverlap = true) const;
377  // Refined version that returns the adjustments on the left and right hand side of the bounding box
378  std::pair<int, int> CalcLeftRightAdjustment(
379  const BoundingBox *boundingBox, bool &discard, int margin = 0, bool horizontalOverlap = true) const;
380  std::pair<int, int> CalcDirectionalLeftRightAdjustment(const BoundingBox *boundingBox, bool isCurveAbove,
381  bool &discard, int margin = 0, bool horizontalOverlap = true) const;
383 
388  void GetPoints(Point points[4]) const;
389  int GetThickness() const { return m_thickness; }
390  curvature_CURVEDIR GetDir() const { return m_dir; }
392 
397  bool HasCachedX12() const;
398  std::pair<int, int> GetCachedX12() const { return m_cachedX12; }
399  void SetCachedX12(const std::pair<int, int> &cachedX12) { m_cachedX12 = cachedX12; }
401 
406 
411  void AddSpannedElement(CurveSpannedElement *spannedElement) { m_spannedElements.push_back(spannedElement); }
412 
416  const ArrayOfCurveSpannedElements *GetSpannedElements() { return &m_spannedElements; }
417 
422  void SetCrossStaff(Staff *crossStaff) { m_crossStaff = crossStaff; }
423  Staff *GetCrossStaff() { return m_crossStaff; }
424  const Staff *GetCrossStaff() const { return m_crossStaff; }
425  bool IsCrossStaff() const { return m_crossStaff != NULL; }
427 
432  void SetRequestedStaffSpace(int space) { m_requestedStaffSpace = space; }
433  int GetRequestedStaffSpace() const { return m_requestedStaffSpace; }
435 
439  std::pair<int, int> CalcRequestedStaffSpace(const StaffAlignment *alignment) const;
440 
441 private:
442  //
443 public:
444  //
445 private:
451  Point m_points[4];
452  int m_thickness;
453  curvature_CURVEDIR m_dir;
454  Staff *m_crossStaff;
456 
457  ArrayOfCurveSpannedElements m_spannedElements;
458 
460  mutable int m_cachedMinMaxY;
461 
463  std::pair<int, int> m_cachedX12;
464 
468  int m_requestedStaffSpace;
469 };
470 
471 //----------------------------------------------------------------------------
472 // CurveSpannedElement
473 //----------------------------------------------------------------------------
474 
476 public:
482  {
483  m_boundingBox = NULL;
484  m_discarded = false;
485  m_isBelow = true;
486  }
487  virtual ~CurveSpannedElement() {}
488 
489  Point m_rotatedPoints[4];
490  const BoundingBox *m_boundingBox;
491  bool m_discarded;
492  bool m_isBelow;
493 };
494 
495 } // namespace vrv
496 
497 #endif
Simple class for representing bezier cCurve.
Definition: devicecontextbase.h:258
This class represents a basic object in the layout domain.
Definition: boundingbox.h:32
This abstract class is the base class for all const functors.
Definition: functor.h:126
Definition: floatingobject.h:475
This class is a hold the data and corresponds to the model of a MVC design pattern.
Definition: doc.h:41
This class represents a basic object for a curve (slur, tie) in the layout domain.
Definition: floatingobject.h:329
void UpdateCurveParams(const Point points[4], int thickness, curvature_CURVEDIR curveDir)
Update the curve parameters.
int CalcAdjustment(const BoundingBox *boundingBox, bool &discard, int margin=0, bool horizontalOverlap=true) const
Calculate the adjustment needed for an element for the curve not to overlap with it.
void MoveFrontHorizontal(int distance)
Moves bounding points horizontally or vertically by a specified distance.
std::pair< int, int > CalcRequestedStaffSpace(const StaffAlignment *alignment) const
Calculate the requested staff space above and below.
void AddSpannedElement(CurveSpannedElement *spannedElement)
Add a CurveSpannedElement to the FloatingCurvePositioner.
Definition: floatingobject.h:411
const ArrayOfCurveSpannedElements * GetSpannedElements()
Return a const pointer to the spanned elements.
Definition: floatingobject.h:416
void ResetCurveParams()
Reset the curve parameters in FloatingCurvePositioner::FloatingCurvePositioner and in FloatingCurvePo...
int CalcMinMaxY(const Point points[4]) const
Calculate the min or max Y for a set of points.
void ClearSpannedElements()
Deletes all the CurveSpannedElement objects.
This class represents elements appearing within a measure.
Definition: floatingobject.h:28
virtual bool IsCloserToStaffThan(const FloatingObject *, data_STAFFREL) const
Check whether the current object must be positioned closer to the staff than the other.
Definition: floatingobject.h:108
FloatingPositioner * GetCorrespFloatingPositioner(const FloatingObject *object)
Look for the FloatingPositioner corresponding to the current one but for another object.
void Reset() override
Reset the object, that is 1) removing all children and 2) resetting all attributes.
virtual std::pair< int, bool > GetVerticalContentBoundaryRel(const Doc *doc, const FloatingPositioner *positioner, const BoundingBox *horizOverlappingBBox, bool contentTop) const
Determine the vertical content boundary.
virtual bool IsExtenderElement() const
Check whether current object represents initial element or extender lines.
Definition: floatingobject.h:103
FunctorCode Accept(Functor &functor) override
Interface for class functor visitation.
This class represents a basic object in the layout domain.
Definition: floatingobject.h:165
StaffAlignment * m_alignment
A pointer to the StaffAlignment that owns it.
Definition: floatingobject.h:311
FloatingObject * m_object
A pointer to the FloatingObject it represents.
Definition: floatingobject.h:306
int m_drawingXRel
The X drawing relative position of the object.
Definition: floatingobject.h:291
int GetSpaceBelow(const Doc *doc, const StaffAlignment *staffAlignment, const BoundingBox *horizOverlappingBBox) const
Calculate the vertical space below the element and above the bounding box.
bool HasHorizontalOverlapWith(const BoundingBox *bbox, int unit) const
Check for horizontal overlap with special consideration for extender lines.
StaffAlignment * GetAlignment()
Getter for the StaffAlignment (asserted, cannot be NULL)
Definition: floatingobject.h:208
int m_drawingYRel
The Y drawing relative position of the object.
Definition: floatingobject.h:296
int m_drawingExtenderWidth
The horizontal width of the extender line whenever it is not included in the bounding box.
Definition: floatingobject.h:301
FloatingObject * GetObject()
Getter for the FloatingObject (asserted, cannot be NULL)
Definition: floatingobject.h:200
char m_spanningType
The spanning type of the positioner for spanning control elements.
Definition: floatingobject.h:319
std::pair< int, bool > GetVerticalContentBoundaryRel(const Doc *doc, const BoundingBox *horizOverlappingBBox, bool contentTop) const
Determine the vertical content boundary.
int GetAdmissibleHorizOverlapMargin(const BoundingBox *bbox, int unit) const
Return the horizontal margin for overlap with another element This can be negative,...
void CalcDrawingYRel(const Doc *doc, const StaffAlignment *staffAlignment, const BoundingBox *horizOverlappingBBox)
Update the Y drawing relative position based on collision detection with the overlapping bounding box...
char GetSpanningType() const
Getter for the spanning type.
Definition: floatingobject.h:215
bool HasVerticalContentOverlap(const Doc *doc, const BoundingBox *horizOverlappingBBox, int margin) const
Version of Boundary::VerticalContentOverlap which takes refined boundaries into account.
void AdjustExtenders()
Align extender elements across systems.
This abstract class is the base class for all mutable functors.
Definition: functor.h:101
This class represents a basic object.
Definition: object.h:61
Simple class for representing points.
Definition: devicecontextbase.h:203
This class stores an alignement position staves will point to.
Definition: verticalaligner.h:172
This class represents a staff in a laid-out score (Doc).
Definition: staff.h:107