freSetupManager.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freSetupManager.cxx,v $
00007   Language:  C++
00008 
00009 
00010 
00011   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00012   Institute for Medical Biometry and Informatics, University of Heidelberg,
00013   Germany). All rights reserved.
00014   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00015   for details.
00016 
00017      This software is distributed WITHOUT ANY WARRANTY; without even 
00018      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00019      PURPOSE.  See the above copyright notices for more information.
00020 
00021 =========================================================================*/
00022 #include "freSetupManager.h"
00023 #include "freSessionBuilder.h"
00024 #include "freControllerCentral.h"
00025 
00026 namespace FREE
00027 {
00028 
00032 SetupManager::ControllerListType
00033 SetupManager::
00034 GetPossibleControllers(const IDPath& componentID, const bool& bCheckOnlyHypothetical)
00035 {
00036   if (m_smpSetup.IsNull()) throwStaticExceptionMacro("Manager has no setup set.");
00037 
00038   ComponentSetup* pComponentSetup = m_smpSetup->GetComponentByIDPath(componentID);
00039   
00040   if (!pComponentSetup) throwStaticExceptionMacro("No component setup found under given ID path. ID path: " << ComponentID(componentID));
00041   
00042   //Get IDPath of the Parent component
00043   IDPath parentIDPath;
00044   if (pComponentSetup->GetParentComponent()) parentIDPath = pComponentSetup->GetParentComponent()->GetIDPath();
00045   
00046   //Get the controller list
00047   typedef ControllerCentral::ControllerListType ListType;
00048   ListType controllers = ControllerCentral::GetControllers();
00049 
00050   ControllerListType ctrlNames;
00051 
00052   //Check every controller, if he is valid.
00053   for (ListType::iterator pos = controllers.begin(); pos!=controllers.end(); pos++)
00054   {
00055     GenericComponentController* pController = (*pos)->GetController();
00056 
00057     IDPathVectorType refusers;
00058     IDPathVectorType refused;
00059     bool bValid = ValidateController(componentID,pController->ControllerID(),refusers,refused);
00060 
00061     //Check if the parent component also refuses 
00062     bool bParentRefusal = false;
00063     for (IDPathVectorType::iterator pathPos = refusers.begin(); pathPos!= refusers.end(); pathPos++)
00064     {
00065       if (*pathPos == parentIDPath)
00066       {
00067         bParentRefusal = true;
00068         break;
00069       };
00070     };
00071 
00072     //Add controller name if valid
00073     if (bValid || (bCheckOnlyHypothetical && !(bParentRefusal))) ctrlNames.push_back(pController->ControllerID());
00074   }
00075   return ctrlNames;
00076 };
00077 
00078 bool
00079 SetupManager::
00080 ValidateController(const IDPath& componentID,
00081                    const std::string& sControllername,
00082                    IDPathVectorType& rRefusingComponents,
00083                    IDPathVectorType& rRefusedComponents)
00084 {
00085   //TODO muss mit den neuen Profilen abgepasst werden und überlegung ob dass nicht auch in eine eigene Klasse soll die sich dann um
00086   //prüfung der ontologie kümmert.
00087 
00088  // if (!pSetup) throwStaticExceptionMacro("Passed setup is NULL.");
00089 
00090  // GenericComponentController* pController = ControllerCentral::GetController(sControllername);
00091  // if (!pController) throwStaticExceptionMacro("Specified controller cannot be found. Controller name: " << sControllername);
00092 
00093  // bool bResult = true;
00094 
00095  // CtrlProfile::ControllerProfile::Pointer smpProfile = pController->GetProfile();
00096 
00097  // //Check component trait against constraint cache of setup
00098  // typedef CtrlProfile::ProfileRequirements::RequirementVectorType RelevantRequirementsType;
00099         //RelevantRequirementsType constraints = pSetup->GetRequirementCache().GetRequirementsByDestination(componentID);
00100 
00101  // for (RelevantRequirementsType::iterator pos = constraints.begin(); pos!=constraints.end(); pos++)
00102  // {
00103  //   if (!(*pos)->ProfileMatchesRequirement(profile))
00104  //   {
00105  //     bResult = false;
00106  //     rRefusingComponents.push_back((*pos)->GetSource());
00107  //   };
00108  // };
00109 
00110  // //Check if any yet chosen component interferes with the constraints of the chosen controller
00111  // for (unsigned int iPos = 0; iPos<profile.Requirements().Size(); iPos++)
00112  // {
00113         //      CtrlProfile::ProfileRequirement* pRequirement = profile.Requirements().GetElement(iPos);
00114  //   IDPath destination = pRequirement->GetDestination();
00115  //   //adapt destination to the actual component path, so its absolute for the given setup
00116  //   destination = destination.TransformIDPath(componentID);
00117 
00118  //   //Get profile of the destination component
00119  //   ComponentSetup* pLtdComponent = pSetup->GetComponentByIDPath(destination);
00120  //   if (pLtdComponent)
00121  //   { //component exists, so check it.
00122  //     if (pLtdComponent->ControllerIsAssigned())
00123  //     { //a controller is defined, so it must be checked
00124  //       GenericComponentController* pLtdController = ControllerCentral::GetController(pLtdComponent->GetControllerID());
00125  //       if (!pLtdController) throwStaticExceptionMacro("Controller of limited component cannot be found, but specified. Controller name: " << pLtdComponent->GetControllerID());
00126  //   
00127  //       if (!pRequirement->ProfileMatchesRequirement(pLtdController->Profile()))
00128  //       {
00129  //         bResult = false;
00130  //         rRefusedComponents.push_back(destination);
00131  //       };
00132  //     };
00133  //   };
00134  // };
00135 
00136  // return bResult;
00137   return false;
00138 };
00139 
00140 bool
00141 SetupManager::
00142 ValidateController(const IDPath& componentID, const std::string& sControllername)
00143 {
00144   IDPathVectorType refusers;
00145   IDPathVectorType refused;
00146   return ValidateController(componentID,sControllername,refusers,refused);
00147 };
00148 
00149 void
00150 SetupManager::
00151 InitializeComponentSetup(Setup* pSetup, ComponentSetup* pComponentSetup)
00152 {
00153   if (pComponentSetup == NULL) throwStaticExceptionMacro("Unable to initialize setup; pComponentSetup is NULL.");
00154 
00155   InitializeComponentSetup(pSetup, pComponentSetup,pComponentSetup->GetControllerID());
00156 };
00157 
00158 void
00159 SetupManager::
00160 InitializeComponentSetup(Setup* pSetup, ComponentSetup* pComponentSetup, const std::string& sControllerName)
00161 {
00162   if (pSetup == NULL) throwStaticExceptionMacro("Unable to initialize setup; pSetup is NULL.");
00163   if (pComponentSetup == NULL) throwStaticExceptionMacro("Unable to initialize setup; pComponentSetup is NULL.");
00164 
00165   ControllerCentral::TriggerBuildEvent(1,"...initializing "+sControllerName+" @ "+ pComponentSetup->GetIDPath().ToStr(), pComponentSetup);
00166 
00167   if (sControllerName == csUndefinedController)
00168   {
00169     ComponentID componentID = pComponentSetup->GetComponentID();
00170     pComponentSetup->Reset();
00171     pComponentSetup->SetComponentID(componentID);
00172   }
00173   else
00174   {
00175     GenericComponentController* pController = ControllerCentral::GetController(sControllerName);
00176       
00177     if (!pController) throwStaticExceptionMacro("Controller not found for initialization. Requested controller name: "<<sControllerName);
00178 
00179                 if (!ValidateController(pComponentSetup->GetIDPath(),sControllerName)) throwStaticExceptionMacro("Error; chosen controller is not valid for the given setup. ControllerID: " << sControllerName);
00180 
00181     //TODO anpassen auf neue intialisierungs schnittstelle
00182     //pController->InitializeSetup(pComponentSetup);
00183 
00184     //update Constraint cache
00185     ActualizeConstraintCache(pSetup,pComponentSetup->GetIDPath(),sControllerName);
00186 
00187                 //Check if any subcomponent have a default controller
00188                 for (ComponentSetupCollection::ElementsCountType index=0; index<pComponentSetup->Components().Size(); index++)
00189                 {
00190                         ComponentSetup* pSubSetup = pComponentSetup->Components().GetElement(index);
00191                         if (pSubSetup->ControllerIsAssigned()) InitializeComponentSetup(pSetup,pSubSetup);
00192                 }
00193   }
00194 };
00195 
00196 void
00197 SetupManager::
00198 InitializeComponentSetup(ComponentSetup* pComponentSetup, const std::string& sControllerName)
00199 {
00200   if (pComponentSetup == NULL) throwStaticExceptionMacro("Unable to initialize setup; pComponentSetup is NULL.");
00201 
00202   ControllerCentral::TriggerBuildEvent(1,"...initializing "+sControllerName+" @ "+ pComponentSetup->GetIDPath().ToStr(), pComponentSetup);
00203 
00204   if (sControllerName == csUndefinedController)
00205   {
00206     ComponentID componentID = pComponentSetup->GetComponentID();
00207     pComponentSetup->Reset();
00208     pComponentSetup->SetComponentID(componentID);
00209   }
00210   else
00211   {
00212     GenericComponentController* pController = ControllerCentral::GetController(sControllerName);
00213       
00214     if (!pController) throwStaticExceptionMacro("Controller not found for initialization. Requested controller name: "<<sControllerName);
00215 
00216     //TODO anpassen auf neue intialisierungs schnittstelle
00217     //pController->InitializeSetup(pComponentSetup);
00218 
00219                 //Check if any subcomponent have a default controller
00220                 for (ComponentSetupCollection::ElementsCountType index=0; index<pComponentSetup->Components().Size(); index++)
00221                 {
00222                         ComponentSetup* pSubSetup = pComponentSetup->Components().GetElement(index);
00223                         if (pSubSetup->ControllerIsAssigned()) InitializeComponentSetup(pSubSetup, pSubSetup->GetControllerID());
00224                 }
00225   }
00226 };
00227 
00228 Setup*
00229 SetupManager::
00230 GetSetup() const
00231 {
00232   return m_smpSetup.GetPointer();
00233 };
00234 
00235 void
00236 SetupManager::
00237 SetSetup(Setup* pSetup)
00238 {
00239   if (m_smpSetup.GetPointer()!=pSetup)
00240   {
00241           m_smpSetup = pSetup;
00242     m_smpRootCache = SessionBuilder::GeneratePassiveComponentCache(pSetup->GetRootComponent());
00243     m_RequirementCache.Reset();
00244   }
00245 };
00246 
00247 const SessionComponentCache*
00248 SetupManager::
00249 GetSessionCache() const
00250 {
00251         return m_smpRootCache.GetPointer();
00252 };
00253   
00254 SessionComponentCache*
00255 SetupManager::
00256 GetSessionCache()
00257 {
00258         return m_smpRootCache.GetPointer();
00259 };
00260 
00261 const SetupManager::ComponentCacheCollectionType&
00262 SetupManager::
00263 GetComponentCaches() const
00264 {
00265   if (this->m_smpRootCache.IsNotNull())
00266   {
00267     return this->m_smpRootCache->SubCaches();
00268   }
00269   throwExceptionMacro("Error; cannot retrieve component caches, root cache is NULL. Ensure that session info has been properly builed.");
00270 };
00271 
00272 SetupManager::ComponentCacheCollectionType&
00273 SetupManager::
00274 GetComponentCaches()
00275 {
00276   if (this->m_smpRootCache.IsNotNull())
00277   {
00278     return this->m_smpRootCache->SubCaches();
00279   }
00280   throwExceptionMacro("Error; cannot retrieve component caches, root cache is NULL. Ensure that session info has been properly builed.");
00281 };
00282 
00283 SetupManager::
00284 SetupManager()
00285 {
00286         m_smpRootCache = 0;
00287   m_smpSetup = 0;
00288 };
00289 
00290 void
00291 SetupManager::
00292 ActualizeConstraintCache(Setup* pSetup, const IDPath& componentID, const std::string& sControllername)
00293 {
00294   //TODO muss mit den neuen Profilen dann geändert werden, gehört in die gleiche Kategorie wie InitializeSetup etc.
00295 
00296  // if (!pSetup) throwStaticExceptionMacro("Passed setup is NULL.");
00297 
00298  // GenericComponentController* pController = ControllerCentral::GetController(sControllername);
00299  // if (!pController) throwStaticExceptionMacro("Specified controller cannot be found. Controller name: " << sControllername);
00300 
00301         //const CtrlProfile::ControllerProfile& profile = pController->Profile();
00302 
00303  // //adapt the constraints of the chosen controller and add it to the cache
00304  // for (unsigned int iPos = 0; iPos<profile.Requirements().Size(); iPos++)
00305  // {
00306  //   CtrlProfile::ProfileRequirement::Pointer smpRequirement = CtrlProfile::ProfileRequirement::New();
00307  //   smpRequirement->operator=(*(profile.Requirements().GetElement(iPos)));
00308 
00309  //   //adapt destination to the actual component path, so its absolute for the given setup
00310  //   smpRequirement->SetDestination(smpRequirement->GetDestination().TransformIDPath(componentID));
00311  //   smpRequirement->SetSource(componentID);
00312 
00313  //   pSetup->GetRequirementCache().AddElement(smpRequirement);
00314  // }
00315 };
00316 
00317 
00318 void
00319 SetupManager::
00320 ActualizeConstraintCache(Setup* pSetup)
00321 {
00322   m_RequirementCache.Reset();
00323   //The is the default constraint to ensure that only registration processors handling the right
00324   //dimension will be allowed
00325         CtrlProfile::ProfileOption* pOption = m_RequirementCache.AddRequirement(cIDPEveryone)->AddProfileOption();
00326         pOption->CheckForIO();
00327 
00328   Setup::SectionVector sections = pSetup->GetSections();
00329   for (unsigned int i = 0; i<sections.size(); i++)
00330   {
00331     ActualizeConstraintCache(pSetup,sections[i]);
00332   }
00333 };
00334 
00335 void
00336 SetupManager::
00337 ActualizeConstraintCache(Setup* pSetup, ComponentSetup* pComponentSetup)
00338 {
00339   if (pComponentSetup->GetControllerID()!=csUndefinedController)
00340   {
00341     ActualizeConstraintCache(pSetup,pComponentSetup->GetIDPath(),pComponentSetup->GetControllerID());
00342   }
00343 
00344   for (unsigned int i = 0; i<pComponentSetup->Components().Size(); i++)
00345   {
00346     ActualizeConstraintCache(pSetup,pComponentSetup->Components().GetElement(i));
00347   }
00348 };
00349 
00350 }//end of namespace FREE

Generated at Sat Oct 13 17:27:27 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000