lenmus / lomse

A C++ library for rendering, editing and playing back music scores.
MIT License
117 stars 28 forks source link

Determine coordinates from system number #379

Closed cecilios closed 1 year ago

cecilios commented 1 year ago

In discussion #377 it was mentioned the need to:

To determine the coordinates for a system it is enough to access the graphical model and get the sytem box for the desired system. A simple way of doing this would be:

GraphicModel* pGM = pInteractor->get_graphic_model();
GmoBoxSystem* pBoxSystem = pGM->get_system_box(iSystem);    //iSystem=0..n-1
UPoint pos = pBoxSystem->get_origin();   //top-left corner, in LUnits

The system origin is relative to page origin but for FreeFlowView, as it is only one page, the point will be absolute logical units as page origin is always at (0, 0).

And to determine the height of a system use any of these methods:

// Returns the height of the bounding box, in logical units. */
LUnits height = pBoxSystem->get_height();

// Returns the width and heigh of the bounding box rectangle (in logical units).
USize size = pBoxSystem->get_size();

// Returns the bounding box rectangle, in logical units. Origin (top left corner)
// is relative to top left corner of GmoDocPage containing this object.
URect rect = pBoxSystem->get_bounds();

Let me know if this solves your needs

npiegdon commented 1 year ago

Those look perfect. Thanks for coming up with this and for the additional documentation on the graphical model!

Again, I think my only question is how do I determine how high iSystem can go? Could we just keep incrementing it until a null GmoBoxSystem comes back?

cecilios commented 1 year ago

Hoops! I have detected an error in method GraphicModel::get_system_box(int iSystem): although its signature was in lomse_graphical_model.h and, thus, I documented it, this method was never implemented!

PR #381 implements this method as well as a new method for getting the number of systems in the score.

Please note that an additional parameter socoreId was added, as a document can contain many scores and then it is necessary to specify to which score is the request referring to. So, in the examples, replace

GmoBoxSystem* pBoxSystem = pGM->get_system_box(iSystem);    //iSystem=0..n-1

by

GmoBoxSystem* pBoxSystem = pGM->get_system_box(iSystem, scoreId);    //iSystem=0..n-1

how do I determine how high iSystem can go? Could we just keep incrementing it until a null GmoBoxSystem comes back?

Apart from new method GraphicModel::get_num_systems(ImoId scoreId) it is also possible just keep incrementing iSystem until you get a nullptr.

cecilios commented 1 year ago

I am closing this issue as there is no further feedback, so it appears to be resolved. If you believe things are still unresolved please let me know and I can reopen if needed.