vtkInitializationHelper.cxx 3.97 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*=========================================================================

Program:   ParaView
Module:    vtkInitializationHelper.cxx

Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.

This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkInitializationHelper.h"
16
#include "vtkPVConfig.h"
17
#include "vtkPVInitializer.h"
18
#include "vtkClientServerInterpreter.h"
19 20
#include "vtkClientServerInterpreterInitializer.h"
#include "vtkOutputWindow.h"
21
#include "vtkProcessModule.h"
22
#include "vtkPVOptions.h"
23
#include "vtkSmartPointer.h"
24
#include "vtkSMMessage.h"
25
#include "vtkSMProperty.h"
26
#include "vtkSMProxyManager.h"
27

28
#include <string>
29
#include <vtksys/ios/sstream>
30 31

//----------------------------------------------------------------------------
32
void vtkInitializationHelper::Initialize(const char* executable, int type)
33
{
34
  vtkInitializationHelper::Initialize(executable, type, NULL);
35 36 37 38
}

//----------------------------------------------------------------------------
void vtkInitializationHelper::Initialize(const char* executable,
39
  int type, vtkPVOptions* options)
40
{
41 42 43 44 45
  if (!executable)
    {
    vtkGenericWarningMacro("Executable name has to be defined.");
    return;
    }
46 47 48 49

  // Pass the program name to make option parser happier
  char* argv = new char[strlen(executable)+1];
  strcpy(argv, executable);
50 51 52 53 54 55

  vtkSmartPointer<vtkPVOptions> newoptions = options;
  if (!options)
    {
    newoptions = vtkSmartPointer<vtkPVOptions>::New();
    }
56
  vtkInitializationHelper::Initialize(1, &argv, type, newoptions);
57 58 59 60
  delete[] argv;
}

//----------------------------------------------------------------------------
61 62
void vtkInitializationHelper::Initialize(int argc, char**argv,
  int type, vtkPVOptions* options)
63
{
64
  if (vtkProcessModule::GetProcessModule())
65
    {
66
    vtkGenericWarningMacro("Process already initialize. Skipping.");
67 68
    return;
    }
69 70 71 72 73 74 75

  if (!options)
    {
    vtkGenericWarningMacro("vtkPVOptions must be specified.");
    return;
    }

76 77 78 79
  // Verify that the version of the library that we linked against is
  // compatible with the version of the headers we compiled against.
  GOOGLE_PROTOBUF_VERIFY_VERSION;

80
  PARAVIEW_INITIALIZE();
81 82 83 84 85 86

  vtkProcessModule::Initialize(
    static_cast<vtkProcessModule::ProcessTypes>(type), argc, argv);

  vtksys_ios::ostringstream sscerr;
  if (argv && !options->Parse(argc, argv) )
87
    {
88 89 90 91 92 93 94 95 96
    if ( options->GetUnknownArgument() )
      {
      sscerr << "Got unknown argument: " << options->GetUnknownArgument() << endl;
      }
    if ( options->GetErrorMessage() )
      {
      sscerr << "Error: " << options->GetErrorMessage() << endl;
      }
    options->SetHelpSelected(1);
97
    }
98
  if (options->GetHelpSelected())
99
    {
100 101 102
    sscerr << options->GetHelp() << endl;
    vtkOutputWindow::GetInstance()->DisplayText( sscerr.str().c_str() );
    // TODO: indicate to the caller that application must quit.
103
    }
104

105 106
  if (options->GetTellVersion() )
    {
107 108 109
    vtksys_ios::ostringstream str;
    str << "paraview version " << PARAVIEW_VERSION_FULL << "\n";
    vtkOutputWindow::GetInstance()->DisplayText(str.str().c_str());
110 111
    // TODO: indicate to the caller that application must quit.
    }
112

113
  vtkProcessModule::GetProcessModule()->SetOptions(options);
114

115 116 117 118
  // Set multi-server flag to vtkProcessModule
  vtkProcessModule::GetProcessModule()->SetMultipleSessionsSupport(
        options->GetMultiServerMode() != 0);

119 120
  // Make sure the ProxyManager get created...
  vtkSMProxyManager::GetProxyManager();
121 122 123 124 125
}

//----------------------------------------------------------------------------
void vtkInitializationHelper::Finalize()
{
126
  vtkSMProxyManager::Finalize();
127
  vtkProcessModule::Finalize();
128 129 130

  // Optional:  Delete all global objects allocated by libprotobuf.
  google::protobuf::ShutdownProtobufLibrary();
131
}