LidarView源码分析(二)程序入口

LidarView的程序入口(main函数)代码文件是LidarView_main.cxx。该文件是在构建输出文件夹下的Application文件夹中,即该文件是使用CMake生成的文件。其关键代码如下:

  QApplication qtapp(argc, argv);
  // QApplication docs suggest resetting to "C" after the QApplication is
  // initialized.
  setlocale(LC_NUMERIC, "C");

  // However, this is needed to address BUG #17225, #17226.
  QLocale::setDefault(QLocale::c());

  using InitializerT = pqLidarViewInitializer;

  InitializerT pvInitializer;
  InitializerT::Status status = pvInitializer.Initialize(argc, argv);
  switch (status)
  {
    case InitializerT::ExitSuccess:
      return EXIT_SUCCESS;
    case InitializerT::ExitFailure:
      return EXIT_FAILURE;
    case InitializerT::RunApplication:
      return QApplication::exec();
  }

可以看出,其中主要使用了pqLidarViewInitializer类进行初始化,然后使用QApplication::exec()进行应用程序的运行。

pqLidarViewInitializer类源码仍然位于构建文件夹下的Application文件夹中。其类的定义如下:

// ***************** DO NOT EDIT ***********************************
// This is a generated file.
// It will be replaced next time you rebuild.
/*=========================================================================

   Program: LidarView
   Module:  pqLidarViewInitializer.h

   Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
   All rights reserved.

   ParaView is a free software; you can redistribute it and/or modify it
   under the terms of the ParaView license version 1.2.

   See License_v1.2.txt for the full ParaView license.
   A copy of this license can be obtained by contacting
   Kitware Inc.
   28 Corporate Drive
   Clifton Park, NY 12065
   USA

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

=========================================================================*/

#ifndef pqLidarViewInitializer_h
#define pqLidarViewInitializer_h

class QMainWindow;
class pqPVApplicationCore;
class QSplashScreen;

class pqLidarViewInitializer
{
public:
  enum Status
  {
    ExitSuccess,
    ExitFailure,
    RunApplication
  };

  pqLidarViewInitializer();
  ~pqLidarViewInitializer();

  /// Initialize ParaView. It returns false if the initialization failed.
  Status Initialize(int argc, char* argv[]);
private:
  pqPVApplicationCore* PVApp;
  QMainWindow* MainWindow;
  QSplashScreen* Splash;
};

#endif

pqLidarViewInitializer类的最重要函数是

Status Initialize(int argc, char* argv[]);

该函数负责了程序的初始化工作。其初始化步骤如下:

step1:创建pqPVApplicationCore对象。pqPVApplicationCore是基于ParaView的应用程序使用的应用程序代码,这些应用程序使用的ParaView功能比pqApplicationCore提供的更多,如选择管理器、动画管理器等。

step2:本地化,设置本地字体语言等。

step3:显示启动图片。即主程序打开前会先显示一个图片,上面显示了该程序的一些信息。使用的是QSplashScreen类。

step4:创建主界面vvMainWindow。

step5:加载插件。

step6:显示主界面,并结束显示启动图片。

step7:返回初始化状态。

其代码如下:

pqLidarViewInitializer::Status pqLidarViewInitializer::Initialize(int argc, char* argv[])
{
  // step 1 创建pqPVApplicationCore
  try
  {
    vtkVLogScopeF(PARAVIEW_LOG_APPLICATION_VERBOSITY(), "initialize pqPVApplicationCore");
    this->PVApp = new pqPVApplicationCore (argc, argv);
  }
  catch (const pqApplicationCoreExitCode& exitCode)
  {
    return exitCode.code() == EXIT_SUCCESS ? ExitSuccess : ExitFailure;
  }

  // step2 本地化,设置本地字体语言等。
  // Get locale from user settings or envvar
  QString locale = this->PVApp->getInterfaceLanguage();
  // Set the default language
  QProcessEnvironment options = QProcessEnvironment::systemEnvironment();
  if (!this->PVApp->settings()->contains("GeneralSettings.InterfaceLanguage"))
  {
    this->PVApp->settings()->setValue("GeneralSettings.InterfaceLanguage", locale);
  }
  // en_US is default ParaView language, so no need to load en_US translators
  if (locale != "en_US")
  {
    // Load ParaView translations
    QTranslator* UITranslator = this->PVApp->getQtTranslations("paraview", locale);
    QCoreApplication::installTranslator(UITranslator);
    // Load Qt translations
    QTranslator* qtTranslator = this->PVApp->getQtTranslations("qt", locale);
    QCoreApplication::installTranslator(qtTranslator);
    QTranslator* qtbaseTranslator = this->PVApp->getQtTranslations("qtbase", locale);
    QCoreApplication::installTranslator(qtbaseTranslator);
  }
  // Attach custom event filter
  QApplication::instance()->installEventFilter(this->PVApp);

#if !_paraview_client_built_shared
  Q_INIT_RESOURCE(LidarView_splash);
  Q_INIT_RESOURCE(LidarView_configuration);

#endif
  // step3:显示启动图片。
#if _paraview_client_SPLASH_IMAGE
  pqSettings *settings = this->PVApp->settings();
  auto coreConfig = vtkRemotingCoreConfiguration::GetInstance();
  if (!coreConfig->GetDisableRegistry() &&
    settings->value("GeneralSettings.ShowSplashScreen", true).toBool())
  {
    // Create and show the splash screen as the main window is being created.
    QPixmap pixmap(":/LidarView/LidarView_splash");
    this->Splash = new QSplashScreen(pixmap, Qt::WindowStaysOnTopHint);
    this->Splash->setMask(pixmap.createMaskFromColor(QColor(Qt::transparent)));
    this->Splash->show();
  }
#endif
  // step4 创建主界面
  // Create main window.
  vtkVLogStartScopeF(PARAVIEW_LOG_APPLICATION_VERBOSITY(), "create-window",
      "creating main window `vvMainWindow`");
  this->MainWindow = new vvMainWindow();
  vtkLogEndScope("create-window");

  // load distributed plugins configuration.
  vtkVLogStartScopeF(PARAVIEW_LOG_PLUGIN_VERBOSITY(), "app-plugins", "load `LidarView` plugin conf");
  vtkPVPluginTracker::GetInstance()->LoadPluginConfigurationXMLs("LidarView");
  vtkLogEndScope("app-plugins");

  vtkNew<vtkPVPluginLoader> loader;

  // step5:加载插件
  // Load required application plugins.
  vtkVLogStartScopeF(PARAVIEW_LOG_PLUGIN_VERBOSITY(), "req-plugins", "load required plugins: `PythonQtPlugin;LidarCorePlugin`");
  QString plugin_string = "PythonQtPlugin;LidarCorePlugin";
  QStringList plugin_list = plugin_string.split(';',PV_QT_SKIP_EMPTY_PARTS);
  Q_FOREACH (const QString plugin_name, plugin_list)
  {
    if (!loader->LoadPluginByName(plugin_name.toUtf8().data()))
    {
      std::cerr << "warning: failed to load required plugin "
        << plugin_name.toUtf8().data() << std::endl;
    }
  }
  vtkLogEndScope("req-plugins");

  // Load optional plugins.
  vtkVLogStartScopeF(PARAVIEW_LOG_PLUGIN_VERBOSITY(), "opt-plugins", "load optional plugins: ``");
  plugin_string = "";
  plugin_list = plugin_string.split(';', PV_QT_SKIP_EMPTY_PARTS);
  Q_FOREACH (const QString plugin_name, plugin_list)
  {
    if (!loader->LoadPluginByName(plugin_name.toUtf8().data()))
    {
      std::cerr << "info: failed to load optional plugin "
        << plugin_name.toUtf8().data() << std::endl;
    }
  }
  vtkLogEndScope("opt-plugins");

  // now load plugins based on user-preferences.
  vtkVLogStartScopeF(PARAVIEW_LOG_PLUGIN_VERBOSITY(), "ini-plugins", "load plugins from settings");
  this->PVApp->getPluginManager()->loadPluginsFromSettings();
  vtkLogEndScope("ini-plugins");

#if _paraview_client_APPLICATION_XMLS
  // Load configuration xmls after all components have been instantiated.
  // This configuration part is something that needs to be cleaned up, I haven't
  // given this too much thought.
  QDir dir2(":/LidarView/Configuration");
  QStringList files = dir2.entryList(QDir::Files);
  Q_FOREACH (QString file, files)
  {
    this->PVApp->loadConfiguration(QString(":/LidarView/Configuration/") + file);
  }
#else
  // NO XMLS provided, Reader and Writers still needs to be updated
  this->PVApp->updateAvailableReadersAndWriters();
#endif

#if _paraview_client_TITLE
  this->MainWindow->setWindowTitle("LidarView 4.3.0-49-g1ae1efa0 Windows-AMD64");
#endif

  // the user can specify a different window title by setting the PARAVIEW_WINDOW_TITLE
  // environment variable. This helps when using multiple PV GUIs simultaneously
  // and context switching quickly between them.
  if (const char* newWindowTitle = vtksys::SystemTools::GetEnv("PARAVIEW_WINDOW_TITLE"))
  {
    this->MainWindow->setWindowTitle(newWindowTitle);
  }

  // Fire the signal that the initialization is complete.
  this->PVApp->_paraview_client_environment_complete();

  // step6:显示主界面,并结束显示启动图片
  // We used to call processEvents() here. We removed it, since that results in
  // timers (esp. pqCommandLineOptionsBehavior::playTests(), or
  // pqServer::processServerNotification()) timers could timeout here and that
  // causes test failures. Any case, the UI will update when the main event loop
  // resumes hence these processEvents are fairly useless.
  this->MainWindow->show();
  if (this->Splash)
  {
    this->Splash->finish(this->MainWindow);
  }
  // step7:返回初始化状态
  return RunApplication;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值