Welcome to mirror list, hosted at ThFree Co, Russian Federation.

build_style.cpp « build_style « qt - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 09d393da67cd5e917a3a2fe08f4588be433b3fef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "build_style.h"
#include "build_common.h"

#include "build_skins.h"
#include "build_drules.h"

#include "platform/platform.hpp"

#include "base/logging.hpp"

#include <exception>
#include <future>

#include <QFile>
#include <QDir>
#include <QCoreApplication>

namespace
{
QString GetRecalculateGeometryScriptPath()
{
  return GetExternalPath("recalculate_geom_index.py", "", "../tools/python");
}

QString GetGeometryToolPath()
{
  return GetExternalPath("generator_tool", "generator_tool.app/Contents/MacOS", "");
}

QString GetGeometryToolResourceDir()
{
  return GetExternalPath("", "generator_tool.app/Contents/Resources", "");
}
}  // namespace

namespace build_style
{
void BuildAndApply(QString const & mapcssFile)
{
  // Ensure mapcss exists
  if (!QFile(mapcssFile).exists())
    throw std::runtime_error("mapcss files does not exist");

  QDir const projectDir = QFileInfo(mapcssFile).absoluteDir();
  QString const styleDir = projectDir.absolutePath() + QDir::separator();
  QString const outputDir = styleDir + "out" + QDir::separator();

  // Ensure output directory is clear
  if (QDir(outputDir).exists() && !QDir(outputDir).removeRecursively())
    throw std::runtime_error("Unable to remove the output directory");
  if (!QDir().mkdir(outputDir))
    throw std::runtime_error("Unable to make the output directory");

  bool const hasSymbols = QDir(styleDir + "symbols/").exists();
  if (hasSymbols)
  {
    auto future = std::async(BuildSkins, styleDir, outputDir);
    BuildDrawingRules(mapcssFile, outputDir);
    future.get(); // may rethrow exception from the BuildSkin

    ApplyDrawingRules(outputDir);
    ApplySkins(outputDir);
  }
  else
  {
    BuildDrawingRules(mapcssFile, outputDir);
    ApplyDrawingRules(outputDir);
  }
}

void RunRecalculationGeometryScript(QString const & mapcssFile)
{
  QString const resourceDir = GetPlatform().ResourcesDir().c_str();
  QString const writableDir = GetPlatform().WritableDir().c_str();

  QString const generatorToolPath = GetGeometryToolPath();
  QString const appPath = QCoreApplication::applicationFilePath();

  QString const geometryToolResourceDir = GetGeometryToolResourceDir();

  CopyFromResources("drules_proto_design.bin", geometryToolResourceDir);
  CopyFromResources("classificator.txt", geometryToolResourceDir);
  CopyFromResources("types.txt", geometryToolResourceDir);

  QStringList params;
  params << "python" <<
            '"' + GetRecalculateGeometryScriptPath() + '"' <<
            '"' + resourceDir + '"' <<
            '"' + writableDir + '"' <<
            '"' + generatorToolPath + '"' <<
            '"' + appPath + '"' <<
            '"' + mapcssFile + '"';
  QString const cmd = params.join(' ');

  auto const res = ExecProcess(cmd);

  // If script returns non zero then it is error
  if (res.first != 0)
  {
    QString msg = QString("System error ") + to_string(res.first).c_str();
    if (!res.second.isEmpty())
      msg = msg + "\n" + res.second;
    throw std::runtime_error(to_string(msg));
  }
}

bool NeedRecalculate = false;
}  // namespace build_style