00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "freGenericSetupToImageAdaptor.h"
00023 #include "freComponentSetupBrowser.h"
00024 #include "freControllerCentral.h"
00025
00026 namespace FREE
00027 {
00028
00032
00033
00034 void
00035 GenericSetupToImageAdaptor::
00036 SetTemplateSetup(Setup* pSetup)
00037 {
00038 if (m_pTemplateSetup != pSetup)
00039 {
00040 m_pTemplateSetup = pSetup;
00041 RestartAdaptation();
00042 }
00043 };
00044
00045 Setup*
00046 GenericSetupToImageAdaptor::
00047 GetTemplateSetup()
00048 { return m_pTemplateSetup;};
00049
00050 const Adaptation::AdaptationList&
00051 GenericSetupToImageAdaptor::
00052 GetAdaptationList()
00053 {
00054 return *(m_AdaptationList.GetPointer());
00055 };
00056
00057 void
00058 GenericSetupToImageAdaptor::
00059 AddAdaptation (const Adaptation::Adaptation& adaptation)
00060 {
00061 m_AdaptationList->AddElement(adaptation);
00062 }
00063
00064 void
00065 GenericSetupToImageAdaptor::
00066 AddAdaptations (const Adaptation::AdaptationList& adaptations)
00067 {
00068 RestartAdaptation();
00069 m_AdaptationList->AddElements(adaptations);
00070 }
00071
00072 void
00073 GenericSetupToImageAdaptor::
00074 Reset()
00075 {
00076 RestartAdaptation();
00077 m_AdaptationList->Reset();
00078 };
00079
00080 const int
00081 GenericSetupToImageAdaptor::
00082 GetCurrentAdaptationID()
00083 { return m_iCurrentAdaptation; };
00084
00085 void
00086 GenericSetupToImageAdaptor::
00087 RestartAdaptation()
00088 { m_iCurrentAdaptation = -1;};
00089
00090 bool
00091 GenericSetupToImageAdaptor::
00092 EndOfAdaptation()
00093 {
00094 return m_iCurrentAdaptation+1>=m_AdaptationList->Size();
00095 };
00096
00097 Setup::Pointer GenericSetupToImageAdaptor::AdaptSetup(int iActualAdaptationItemID)
00098 {
00099 if (!m_pTemplateSetup) throwExceptionMacro("Template setup has not be defined.");
00100 if ((iActualAdaptationItemID<0) | (iActualAdaptationItemID>=m_AdaptationList->Size())) return NULL;
00101
00102 Setup::Pointer result = Setup::New();
00103 *(result.GetPointer()) = *m_pTemplateSetup;
00104
00105 AdaptSetup(*(m_AdaptationList->GetElement(iActualAdaptationItemID)),*result);
00106
00107 return result;
00108 };
00109
00110 Setup::Pointer
00111 GenericSetupToImageAdaptor::
00112 AdaptNextSetup()
00113 {
00114 m_iCurrentAdaptation++;
00115 Setup::Pointer result = AdaptSetup(m_iCurrentAdaptation);
00116 return result;
00117 };
00118
00119 GenericSetupToImageAdaptor::
00120 GenericSetupToImageAdaptor()
00121 {
00122 RestartAdaptation();
00123 m_pTemplateSetup = NULL;
00124 m_AdaptationList = Adaptation::AdaptationList::New();
00125 };
00126
00127 GenericSetupToImageAdaptor::
00128 ~GenericSetupToImageAdaptor() {};
00129
00130 void
00131 GenericSetupToImageAdaptor::
00132 AdaptSetup(const Adaptation::Adaptation& adaptation, Setup& rSetup)
00133 {
00134 ComponentSetupBrowser search(rSetup.GetRootComponent());
00135
00136
00137 Adaptation::Adaptation::ElementsCountType iIndex;
00138 for (iIndex = 0; iIndex < adaptation.Size(); iIndex++)
00139 {
00140 Adaptation::AdaptationComponent* pAdaptComp = adaptation.GetElement(iIndex);
00141 search.Reset();
00142
00143
00144 search.SearchForComponents(pAdaptComp->GetComponentPath());
00145
00146 switch (pAdaptComp->GetAdaptationMode())
00147 {
00148 case Adaptation::AdaptationComponent::AMOverwrite:
00149 {
00150 if (pAdaptComp->GetComponentPath().IsAbsolute())
00151 {
00152 ComponentSetup* pCompSetup = 0;
00153 if (search.GetFindings().size()>0)
00154 {
00155 pCompSetup = search.GetFindings().front();
00156 }
00157 OverwriteComponent(pAdaptComp,pCompSetup,rSetup);
00158 }
00159 break;
00160 }
00161 case Adaptation::AdaptationComponent::AMReplace:
00162 {
00163 for (ComponentSetupBrowser::FindingsType::iterator it = search.GetFindings().begin(); it != search.GetFindings().end(); it++)
00164 {
00165 ReplaceComponent(pAdaptComp,(*it));
00166 }
00167 break;
00168 }
00169 case Adaptation::AdaptationComponent::AMExtend:
00170 {
00171 for (ComponentSetupBrowser::FindingsType::iterator it = search.GetFindings().begin(); it != search.GetFindings().end(); it++)
00172 {
00173 ExtendComponent(pAdaptComp,(*it));
00174 }
00175 break;
00176 }
00177 case Adaptation::AdaptationComponent::AMAdapt:
00178 {
00179 for (ComponentSetupBrowser::FindingsType::iterator it = search.GetFindings().begin(); it != search.GetFindings().end(); it++)
00180 {
00181 AdaptComponent(pAdaptComp,(*it));
00182 }
00183 break;
00184 }
00185 }
00186 }
00187 };
00188
00189 bool
00190 GenericSetupToImageAdaptor::
00191 ValidateController(const ComponentSetup* pAdaptComp, const ComponentSetup* pComponentSetup)
00192 {
00193 bool bValidController = true;
00194
00195 if ((pAdaptComp->GetControllerID() != csUndefinedController))
00196 {
00197 GenericComponentController* pController = ControllerCentral::GetController(pComponentSetup->GetControllerID());
00198 if (pController) bValidController = pController->IsRelatedTo(pAdaptComp->GetControllerID());
00199 }
00200 return bValidController;
00201 }
00202
00203 void
00204 GenericSetupToImageAdaptor::
00205 AdaptComponent(const ComponentSetup* pAdaptComp, ComponentSetup* pComponentSetup)
00206 {
00207 bool bValidController = ValidateController(pAdaptComp,pComponentSetup);
00208
00209 if (bValidController)
00210 {
00211
00212 for (ParameterCollection::ParameterCountType iParamIndex=0; iParamIndex < pAdaptComp->Parameters().Size(); iParamIndex++)
00213 {
00214 Parameter* pAdapParam = pAdaptComp->Parameters().GetParameter(iParamIndex);
00215
00216 if (pComponentSetup->Parameters().ParameterExists(pAdapParam->GetParameterName()))
00217 {
00218 *(pComponentSetup->Parameters().GetParameter(pAdapParam->GetParameterName())) = *pAdapParam;
00219 }
00220 }
00221
00222
00223 for (ComponentMediaLinks::ElementsCountType iMediaIndex=0; iMediaIndex < pAdaptComp->MediaLinks().Size(); iMediaIndex++)
00224 {
00225 ComponentMediaLink* pAdapLink = pAdaptComp->MediaLinks().GetElement(iMediaIndex);
00226 ComponentMediaLink* pCompLink = pComponentSetup->MediaLinks().GetElement(pAdapLink->GetMediaID());
00227 if (pCompLink)
00228 {
00229 pComponentSetup->MediaLinks().DeleteElement(pComponentSetup->MediaLinks().GetElementIndex(pAdapLink->GetMediaID()));
00230 pComponentSetup->MediaLinks().AddElement(*pAdapLink);
00231 }
00232 }
00233 }
00234
00235
00236 for (int iPos=0; iPos<pAdaptComp->Components().Size(); iPos++)
00237 {
00238 ComponentSetup* pSubAdapComp = pAdaptComp->Components().GetElement(iPos);
00239 ComponentSetup* pSubComp = pComponentSetup->Components().GetElement(pSubAdapComp->GetComponentID());
00240
00241 if (pSubComp)
00242 {
00243 AdaptComponent(pSubAdapComp, pSubComp);
00244 }
00245 }
00246 };
00247
00248 void
00249 GenericSetupToImageAdaptor::
00250 ExtendComponent(const ComponentSetup* pAdaptComp, ComponentSetup* pComponentSetup)
00251 {
00252 bool bValidController = ValidateController(pAdaptComp,pComponentSetup);
00253
00254 if (bValidController)
00255 {
00256
00257 for (ParameterCollection::ParameterCountType iParamIndex=0; iParamIndex < pAdaptComp->Parameters().Size(); iParamIndex++)
00258 {
00259 Parameter* pAdapParam = pAdaptComp->Parameters().GetParameter(iParamIndex);
00260
00261 if (pComponentSetup->Parameters().ParameterExists(pAdapParam->GetParameterName()))
00262 {
00263 *(pComponentSetup->Parameters().GetParameter(pAdapParam->GetParameterName())) = *pAdapParam;
00264 }
00265 else
00266 {
00267 Parameter* pParam = pComponentSetup->Parameters().AddParameter(pAdapParam->GetParameterName());
00268 *pParam = *pAdapParam;
00269 }
00270 }
00271
00272
00273 for (ComponentMediaLinks::ElementsCountType iMediaIndex=0; iMediaIndex < pAdaptComp->MediaLinks().Size(); iMediaIndex++)
00274 {
00275 ComponentMediaLink* pAdapLink = pAdaptComp->MediaLinks().GetElement(iMediaIndex);
00276 ComponentMediaLink* pCompLink = pComponentSetup->MediaLinks().GetElement(pAdapLink->GetMediaID());
00277 if (pCompLink)
00278 {
00279 pComponentSetup->MediaLinks().DeleteElement(pComponentSetup->MediaLinks().GetElementIndex(pAdapLink->GetMediaID()));
00280 }
00281 pComponentSetup->MediaLinks().AddElement(*pAdapLink);
00282 }
00283 }
00284
00285
00286 for (int iPos=0; iPos<pAdaptComp->Components().Size(); iPos++)
00287 {
00288 ComponentSetup* pSubAdapComp = pAdaptComp->Components().GetElement(iPos);
00289 ComponentSetup* pSubComp = pComponentSetup->Components().GetElement(pSubAdapComp->GetComponentID());
00290
00291 if (pSubComp)
00292 {
00293 ExtendComponent(pSubAdapComp, pSubComp);
00294 }
00295 }
00296 };
00297
00298 void
00299 GenericSetupToImageAdaptor::
00300 ReplaceComponent(const ComponentSetup* pAdaptComp, ComponentSetup* pComponentSetup)
00301 {
00302
00303 pComponentSetup->SetControllerID(pAdaptComp->GetControllerID());
00304
00305 pComponentSetup->Parameters() = pAdaptComp->Parameters();
00306 pComponentSetup->MediaLinks() = pAdaptComp->MediaLinks();
00307 pComponentSetup->Components() = pAdaptComp->Components();
00308 };
00309
00310 void
00311 GenericSetupToImageAdaptor::
00312 OverwriteComponent(const ComponentSetup* pAdaptComp, ComponentSetup* pComponentSetup, Setup& rSetup)
00313 {
00314 if (!pComponentSetup)
00315 {
00316 ComponentSetupCollection::ElementsCountType iNewIndex = rSetup.GetRootComponent()->Components().AddElement(pAdaptComp->GetComponentID());
00317 pComponentSetup = rSetup.GetRootComponent()->Components().GetElement(iNewIndex);
00318 }
00319
00320 ReplaceComponent(pAdaptComp,pComponentSetup);
00321 };
00322
00323 }