Line Code
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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
// -*- C++ -*-
//
// Package:     Core
// Class  :     FWViewManagerBase
//
// Implementation:
//     <Notes on implementation>
//
// Original Author:
//         Created:  Sat Jan  5 10:56:17 EST 2008
//

// system include files
#include "TClass.h"
#include "TROOT.h"
#include <cassert>
#include <iostream>
#include <functional>

// user include files
#include "Fireworks/Core/interface/FWViewManagerBase.h"
#include "Fireworks/Core/interface/FWModelChangeManager.h"
#include "Fireworks/Core/interface/FWColorManager.h"

//
// constants, enums and typedefs
//

//
// static data member definitions
//

//
// constructors and destructor
//
FWViewManagerBase::FWViewManagerBase() : m_context(nullptr), m_changeManager(nullptr), m_colorManager(nullptr) {}

// FWViewManagerBase::FWViewManagerBase(const FWViewManagerBase& rhs)
// {
//    // do actual copying here;
// }

FWViewManagerBase::~FWViewManagerBase() {}

//
// assignment operators
//
// const FWViewManagerBase& FWViewManagerBase::operator=(const FWViewManagerBase& rhs)
// {
//   //An exception safe implementation is
//   FWViewManagerBase temp(rhs);
//   swap(rhs);
//
//   return *this;
// }

//
// member functions
//
void* FWViewManagerBase::createInstanceOf(const TClass* iBaseClass, const char* iNameOfClass) {
  //create proxy builders
  Int_t error;
  assert(iBaseClass != nullptr);

  //does the class already exist?
  TClass* c = TClass::GetClass(iNameOfClass);
  if (nullptr == c) {
    //try to load a macro of that name

    //How can I tell if this succeeds or failes? error and value are always 0!
    // I could not make the non-compiled mechanism to work without seg-faults
    // Int_t value =
    gROOT->LoadMacro((std::string(iNameOfClass) + ".C+").c_str(), &error);
    c = TClass::GetClass(iNameOfClass);
    if (nullptr == c) {
      std::cerr << "failed to find " << iNameOfClass << std::endl;
      return nullptr;
    }
  }
  void* inst = c->New();
  void* baseClassInst = c->DynamicCast(iBaseClass, inst);
  if (nullptr == baseClassInst) {
    std::cerr << "conversion to " << iBaseClass->ClassName() << " for class " << iNameOfClass << " failed" << std::endl;
    return nullptr;
  }
  return baseClassInst;
}

void FWViewManagerBase::modelChangesComingSlot() {
  //forward call to the virtual function
  this->modelChangesComing();
}
void FWViewManagerBase::modelChangesDoneSlot() {
  //forward call to the virtual function
  this->modelChangesDone();
}
void FWViewManagerBase::colorsChangedSlot() { this->colorsChanged(); }

void FWViewManagerBase::setChangeManager(FWModelChangeManager* iCM) {
  assert(nullptr != iCM);
  m_changeManager = iCM;
  m_changeManager->changeSignalsAreComing_.connect(std::bind(&FWViewManagerBase::modelChangesComing, this));
  m_changeManager->changeSignalsAreDone_.connect(std::bind(&FWViewManagerBase::modelChangesDone, this));
}

void FWViewManagerBase::setColorManager(FWColorManager* iCM) {
  assert(nullptr != iCM);
  m_colorManager = iCM;
  m_colorManager->colorsHaveChanged_.connect(std::bind(&FWViewManagerBase::colorsChanged, this));
  //make sure to pickup any changes that occurred earlier
  colorsChanged();
}

//
// const member functions
//

FWModelChangeManager& FWViewManagerBase::changeManager() const {
  assert(m_changeManager != nullptr);
  return *m_changeManager;
}

FWColorManager& FWViewManagerBase::colorManager() const {
  assert(m_colorManager != nullptr);
  return *m_colorManager;
}