New export: Export Measurements for Body Measurements App/Widget

Issue #576 new
grumpi created an issue

In the longer run, it would be nice to have a way to get the measurements info (including translations) known to Valentina exported into a format that can be used in other apps.

I figured that one way to do this is if I can manage to get VTranslateMeasurements() to compile, I could just write a simple program that

  1. sets a language
  2. exports all the measurements data from VTranslateMeasurements()
  3. repeats for the next language until I have exported data for all languages

I started trying to get VTranslateMeasurements() to compile, but keep running into more dependencies I need to add. I'm at a point where I must start adding things dealing with translations of line, angle and arc names in order to get it to compile.

Code so far at: https://bitbucket.org/dismine/body-measurements-widget/src/53d4e7d78a2f/tools/translation_importer/?at=master

Haven't started trying to export since I couldn't get it to compile yet.

Question: does the approach I'm taking make sense or not? Is there a way I can get VTranslateMeasurements() to compile without a huge load of additional dependencies?

This is not blocking development of measurements app in any way, I can transfer some measurements data by hand and develop the measurements app. Just in the long run it would be cool not to have to maintain duplicate info.

Comments (55)

  1. Roman Telezhynskyi repo owner

    does the approach I'm taking make sense or not?

    Not really. First of all Valentina already provide you with good example. So your task for me is very easy.

    1. If you want VTranslateMeasurements() why try to import source file when you can import the vpatterdb static library or any other if need too? The linker will clear all pieces you don't need.
    2. Class TST_MeasurementRegExp will help you understand how all is working. It tests translation.

    it would be nice to have a way to get the measurements info (including translations) known to Valentina exported into a format that can be used in other apps.

    Tape app supports exporting to CSV format.

  2. grumpi reporter

    I don't know much about C++, haven't used it in years. I also don't know Valentina's codebase well. I've just been looking for the measurements code and trying to get the translations out.

    Because I ran into trouble, I figured that I'm doing this the wrong way, hence why I'm asking instead of wasting time. :p

    With importing the vpatterndb static library you mean I

    1. compile Valentina
    2. copy .o file I need and link that? vpatterndb.o or so?

    Tape app supports exporting to CSV format.

    That's cool, but not really needed for measurements app. .vit files are good. Measurement app needs to work with .vit files anyways, I think, to make using it with Valentina easy. I only meant getting the measurement name/description info (e.g. translations, code letter/number of measurement).

  3. grumpi reporter

    Ok, sorry, I saw vpatterndb has it's own qt project file, that's nice. Don't worry, I'll figure things out from here. And thanks for pointing out that I just need to link the compiled library.

  4. Roman Telezhynskyi repo owner

    All you need is vpatterndb.lib (Windows) or libvpatterndb.a (Unix) file. And saying a linker to use it. You can do it through Qt Creator.

  5. Roman Telezhynskyi repo owner

    Is this utility good only for you? Maybe we should add it as part of the main project?

  6. grumpi reporter

    It should be useful for others who want to do something with measurement translation strings, too, I think. I want to export to JSON.

  7. grumpi reporter

    I'm failing at linking libvpatterndb.a on Ubuntu command line (using qmake and .pro file) but that's my own fault. Trying to add it to .pro file with

    INCLUDE += -L../../../valentina/src/libs/vpatterndb/bin/libvpatterndb.a

    doesn't seem to work. I get

    undefined reference to `VTranslateVars::VTranslateVars(bool)'

    But I'm pretty sure that's just something silly I'm doing wrong since that seems to be a rather normal C++ linking error.

  8. Roman Telezhynskyi repo owner

    Also i forgot to mention that you also will need .QM files. These files contains translation.

  9. Roman Telezhynskyi repo owner

    But I'm pretty sure that's just something silly I'm doing wrong since that seems to be a rather normal C++ linking error.

    I think your syntax is wrong. Did you use Qt Creator?

  10. grumpi reporter

    Not yet, I was working with qmake and editing .pro file because Qt Creator looked so intimidating.

    I managed to get vpatterndb library to link after fixing wrong syntax for linking, but then I had lots of undefined references to qmuparser. Then I linked libqmuparser.so and had undefined references to vmisc library. Then I had undefined references to QPrinter and QPrinterInfo that I resolved by adding QT += printsupport.

    I installed Qt Creator and tried to find the place where to link libraries, but am totally lost in there. I'm much more comfortable on command line.

    my .pro file is https://bitbucket.org/dismine/body-measurements-widget/src/9caf8b7804a3b9569af89d2e5e0a9a3307405b7c/tools/translation_importer/translation_importer.pro?at=master&fileviewer=file-view-default

    It compiles now, but I get

    error while loading shared libraries: libqmuparser.so.2: cannot open shared object file: No such file or directory

    so I'm probably doing something wrong with regard to linking that.

    Edit: link to .pro file updated

  11. Roman Telezhynskyi repo owner

    so I'm probably doing something wrong with regard to linking that.

    You are doing all right for building. But you forgot that when you start the app it can't find the shared library. The library is not in the standard path.

    On linux by default you also can't add just a library to folder with binary. But i know one way.

    1. I recommend you add a symlink to qmuparser library.
    2. Use RPATH option for linker.

    Here is example from Valentina:

    noRunPath{ # For enable run qmake with CONFIG+=noRunPath
        # do nothing
    } else {
        unix:!macx{
            # suppress the default RPATH
            # helps to run the program without Qt Creator
            # see problem with path to libqmuparser and libpropertybrowser
            QMAKE_LFLAGS_RPATH =
            QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN\' -Wl,-rpath,$${OUT_PWD}/../../libs/qmuparser/$${DESTDIR} -Wl,-rpath,$${OUT_PWD}/../../libs/vpropertyexplorer/$${DESTDIR}"
        }
    }
    

    $$ORIGIN is binary folder.

    This way is not recommended for production, but perfect for testing.

  12. grumpi reporter

    Ok, thanks, that makes sense! Considering that this will never be a production app, a hacky solution is fine. I just need to run it whenever measurements known by Valentina are updated. Anyone other than me should be using the exported JSON files directly, instead of running the exporter themselves.

  13. grumpi reporter

    How to build QM files from TS files?

    When I build full Valentina from Valentina.pro, it looks like it's trying to do something to .qm files but there are no .qm files in share/translations/, only .ts files.

  14. Roman Telezhynskyi repo owner

    It should be there after you call qmake. If it is not working. Use script lrelease.sh in folder scripts.

  15. grumpi reporter

    That worked, thanks.

    Looking at the translations I just noticed that the names like "height_neck_back" are translated, too. Does that mean that the correct way to identify a measurement across languages is to use, e.g. "A01", etc?

    Is the correct way to write .vit file (v0.3.3) this:

    <m name="height" value="168.0" full_name="Height: Total" description="Vertical distance from crown of head to floor." />

    or

    <m name="A01" value="168.0" full_name="Height: Total" description="Vertical distance from crown of head to floor." />

    or another different way?

  16. Roman Telezhynskyi repo owner

    Looking at the translations I just noticed that the names like "height_neck_back" are translated, too.

    Yes.

    Does that mean that the correct way to identify a measurement across languages is to use, e.g. "A01", etc?

    No. Valentina has internal names. All files use internal names.

  17. grumpi reporter

    Good. then it seems clear what I need to get out of the system.

    Looks like I'll need to figure out how to make a derived class of VTranslateVars to access all of measurements, guiTexts, descriptions, numbers so I can save them to JSON.

  18. Roman Telezhynskyi repo owner

    Why do you need VTranslateVars you have VTranslateMeasurements? It can do all you need. Class TST_MeasurementRegExp will help you understand how all works.

  19. grumpi reporter

    Simplest way for me to export would be to iterate over measurements and use the getters to get numbers, guiTexts and descriptions.

    Ah, but I still can't access measurements unless I derive a class, right or wrong?

  20. Roman Telezhynskyi repo owner

    Ah, but I still can't access measurements unless I derive a class, right or wrong?

    Who did say this? I don't see any reason why you can't use this class.

  21. grumpi reporter

    But TST_MeasurementsRegExp uses VTranslateVars. That's why I've been trying to use that too since I can then copy code from TST_MeasurementsRegExp.

  22. grumpi reporter

    Compiler says

    error: ‘QMap<QString, qmu::QmuTranslation> VTranslateMeasurements::measurements’ is protected

  23. Roman Telezhynskyi repo owner
    VTranslateVars *trMs;
    const QStringList originalNames = AllGroupNames();
    foreach(const QString &originalName, originalNames)
    {
        const QString translated = trMs->VarToUser(originalName);
    }
    
  24. grumpi reporter

    Ok, good. I have JSON files now.

    It looks like p0-p50 are pattern systems and every pattern system has its own file with measurement names. How do I know what code is for what system? Is there a measurements translation file independent of pattern systems? Like, e.g. original measurements known to Valentina.

  25. Roman Telezhynskyi repo owner

    It looks like p0-p50 are pattern systems and every pattern system has its own file with measurement names.

    Yes.

    How do I know what code is for what system?

    const QStringList listSystems = ListPMSystems();
    QMap<QString, QString> systems;
    for (int i = 0; i < listSystems.size()-1; ++i)
    {
        systems.insert(qApp->TrVars()->PMSystemName(listSystems.at(i)) + " ("+listSystems.at(i)+")", listSystems.at(i));
    }
    

    Is there a measurements translation file independent of pattern systems? Like, e.g. original measurements known to Valentina.

    Sorry, don't understand this question.

  26. grumpi reporter

    I'm trying to export diagrams using MapDiagrams on measurement number. It fails with SegFault because it's trying to access qApp->TrVars() (which my translation exporter program doesn't have).

    What should I do?

  27. Roman Telezhynskyi repo owner

    This is my design mistake. Yes, better to refactor MapDiagrams to take pointer to VTranslateMeasurements from outside. Do you want me make this changes or you want make a pull request yourself?

  28. grumpi reporter

    If you know already how to do it you will be way faster than me. Too clueless about C++, would take me ages. :)

  29. grumpi reporter

    Ah, okay, no, I think I can do that, actually. Refactoring to take a pointer doesn't seem so hard. Just have to find all MapDiagram calls and pass qApp->TrVars().

    Should I?

  30. Log in to comment