Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:44

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     FWViewManagerBase
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:
0010 //         Created:  Sat Jan  5 10:56:17 EST 2008
0011 //
0012 
0013 // system include files
0014 #include "TClass.h"
0015 #include "TROOT.h"
0016 #include <cassert>
0017 #include <iostream>
0018 #include <functional>
0019 
0020 // user include files
0021 #include "Fireworks/Core/interface/FWViewManagerBase.h"
0022 #include "Fireworks/Core/interface/FWModelChangeManager.h"
0023 #include "Fireworks/Core/interface/FWColorManager.h"
0024 
0025 //
0026 // constants, enums and typedefs
0027 //
0028 
0029 //
0030 // static data member definitions
0031 //
0032 
0033 //
0034 // constructors and destructor
0035 //
0036 FWViewManagerBase::FWViewManagerBase() : m_context(nullptr), m_changeManager(nullptr), m_colorManager(nullptr) {}
0037 
0038 // FWViewManagerBase::FWViewManagerBase(const FWViewManagerBase& rhs)
0039 // {
0040 //    // do actual copying here;
0041 // }
0042 
0043 FWViewManagerBase::~FWViewManagerBase() {}
0044 
0045 //
0046 // assignment operators
0047 //
0048 // const FWViewManagerBase& FWViewManagerBase::operator=(const FWViewManagerBase& rhs)
0049 // {
0050 //   //An exception safe implementation is
0051 //   FWViewManagerBase temp(rhs);
0052 //   swap(rhs);
0053 //
0054 //   return *this;
0055 // }
0056 
0057 //
0058 // member functions
0059 //
0060 void* FWViewManagerBase::createInstanceOf(const TClass* iBaseClass, const char* iNameOfClass) {
0061   //create proxy builders
0062   Int_t error;
0063   assert(iBaseClass != nullptr);
0064 
0065   //does the class already exist?
0066   TClass* c = TClass::GetClass(iNameOfClass);
0067   if (nullptr == c) {
0068     //try to load a macro of that name
0069 
0070     //How can I tell if this succeeds or failes? error and value are always 0!
0071     // I could not make the non-compiled mechanism to work without seg-faults
0072     // Int_t value =
0073     gROOT->LoadMacro((std::string(iNameOfClass) + ".C+").c_str(), &error);
0074     c = TClass::GetClass(iNameOfClass);
0075     if (nullptr == c) {
0076       std::cerr << "failed to find " << iNameOfClass << std::endl;
0077       return nullptr;
0078     }
0079   }
0080   void* inst = c->New();
0081   void* baseClassInst = c->DynamicCast(iBaseClass, inst);
0082   if (nullptr == baseClassInst) {
0083     std::cerr << "conversion to " << iBaseClass->ClassName() << " for class " << iNameOfClass << " failed" << std::endl;
0084     return nullptr;
0085   }
0086   return baseClassInst;
0087 }
0088 
0089 void FWViewManagerBase::modelChangesComingSlot() {
0090   //forward call to the virtual function
0091   this->modelChangesComing();
0092 }
0093 void FWViewManagerBase::modelChangesDoneSlot() {
0094   //forward call to the virtual function
0095   this->modelChangesDone();
0096 }
0097 void FWViewManagerBase::colorsChangedSlot() { this->colorsChanged(); }
0098 
0099 void FWViewManagerBase::setChangeManager(FWModelChangeManager* iCM) {
0100   assert(nullptr != iCM);
0101   m_changeManager = iCM;
0102   m_changeManager->changeSignalsAreComing_.connect(std::bind(&FWViewManagerBase::modelChangesComing, this));
0103   m_changeManager->changeSignalsAreDone_.connect(std::bind(&FWViewManagerBase::modelChangesDone, this));
0104 }
0105 
0106 void FWViewManagerBase::setColorManager(FWColorManager* iCM) {
0107   assert(nullptr != iCM);
0108   m_colorManager = iCM;
0109   m_colorManager->colorsHaveChanged_.connect(std::bind(&FWViewManagerBase::colorsChanged, this));
0110   //make sure to pickup any changes that occurred earlier
0111   colorsChanged();
0112 }
0113 
0114 //
0115 // const member functions
0116 //
0117 
0118 FWModelChangeManager& FWViewManagerBase::changeManager() const {
0119   assert(m_changeManager != nullptr);
0120   return *m_changeManager;
0121 }
0122 
0123 FWColorManager& FWViewManagerBase::colorManager() const {
0124   assert(m_colorManager != nullptr);
0125   return *m_colorManager;
0126 }