00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "freConstrainedSetupTransformController.h"
00024 #include "freExceptions.h"
00025
00026 namespace FREE
00027 {
00028
00032
00033
00034
00035 DefineParameterMacro(ConstrainedSetupTransformController,Constraints,"Constraints","The constraints of the setup transform. First element is the ID of the constrained parameter, second value indicates the type of relation (0: equal; 1: lesser or equal; 2: greater or equal). The third value is the constraint term. Parameter IDs, if used in the term have an underscore as prefix.\nExample: 1 | 2 | (_2 * 4) + _3\nBy this constrained parameter 1 should be greater or equal four times parameter 2 + parameter 3.");
00036
00037 ConstrainedSetupTransformController::
00038 ConstrainedSetupTransformController()
00039 {
00040
00041 this->UpdateControllerID(ControllerID::ConstrainedSetupTransformController);
00042 this->m_Description = "Transform a free setup, by changing specified parameters regarding given constraint terms.";
00043 };
00044
00045 void
00046 ConstrainedSetupTransformController::
00047 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00048 const SessionComponentCache* pComponentCache,
00049 bool bRegardOldSetup) const
00050 {
00051 Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00052
00053
00054 if (bRegardOldSetup)
00055 {
00056 profile.Parameters().AddParameter(cParam_Constraints,CtrlProfile::Parameter::PVTString,cParamDsc_Constraints,3,"",-1);
00057 }
00058 else
00059 {
00060 Parameter* pParam = pComponentCache->Setup()->Parameters().GetParameter(cParam_ParameterIDs);
00061 if (!pParam) throwCtrlExceptionMacro("","Error. Cannot retrieve parameter \"ParameterIDs\". Please ensure that component is properly initialized.");
00062
00063 profile.Parameters().AddParameter(cParam_Constraints,CtrlProfile::Parameter::PVTString,cParamDsc_Constraints,3,"",pParam->LayerCount());
00064 }
00065 };
00066
00067 void
00068 ConstrainedSetupTransformController::
00069 ActualizeMainComponent(ComponentType* pMainComponent,
00070 SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo,
00071 const unsigned int& iActLevel) const
00072 {
00073 bool bAutoInitValues;
00074
00075 try
00076 {
00077 SessionAccessor::GetParameterValue(pComponentCache,cParam_AutoInitialValues,bAutoInitValues);
00078 }
00079 catchAllNPassMacro("Error while retrieving parameter values.");
00080
00081 pMainComponent->SetAutoInitialValues(bAutoInitValues);
00082 pMainComponent->ResetParameterIDs();
00083 pMainComponent->ResetParameterConstraints();
00084
00085
00086 Parameter::Pointer smpParameter = SessionAccessor::GetParameter(pComponentCache,cParam_ParameterIDs);
00087 if (smpParameter.IsNull()) throwExceptionMacro("Missing parameter: " << cParam_ParameterIDs);
00088
00089 Parameter::Pointer smpConstraints = SessionAccessor::GetParameter(pComponentCache,cParam_Constraints);
00090 if (smpConstraints.IsNull()) throwExceptionMacro("Missing parameter: " << cParam_Constraints);
00091
00092 for (unsigned int index = 0; index < smpParameter->ParameterSize(); index++)
00093 {
00094 std::string id;
00095 smpParameter->GetParameterValue(id,index);
00096 pMainComponent->AddParameterID(IDPath(id));
00097 }
00098
00099 for (unsigned int index = 0; index < smpConstraints->LayerCount(); index++)
00100 {
00101 int iParamID;
00102 std::string sRelationType;
00103 std::string sTerm;
00104
00105 if (!smpConstraints->GetParameterValue(iParamID,0,index)) throwExceptionMacro("Faulty parameter; cannot retrieve parameter id. constraint nr: " << index);
00106 if (!smpConstraints->GetParameterValue(sRelationType,1,index)) throwExceptionMacro("Faulty parameter; cannot retrieve relation type. constraint nr: " << index);
00107 if (!smpConstraints->GetParameterValue(sTerm,2,index)) throwExceptionMacro("Faulty parameter; cannot retrieve constraint term. constraint nr: " << index);
00108
00109 SetupParameterConstraint::Pointer smpNewCnstr = SetupParameterConstraint::New(iParamID,Convert::ToRelationType(sRelationType),sTerm);
00110 pMainComponent->AddParameterConstraint(*(smpNewCnstr.GetPointer()));
00111 }
00112
00113
00114
00115 if (!bAutoInitValues)
00116 {
00117 smpParameter = SessionAccessor::GetParameter(pComponentCache,cParam_InitialTransformValues);
00118 if (smpParameter.IsNull()) throwExceptionMacro("Missing parameter: " << cParam_InitialTransformValues);
00119 ComponentType::ParametersType values = Convert::ParameterLayerToArray<ComponentType::ParametersType>(*(smpParameter->GetParameterLayer(0)));
00120
00121 pMainComponent->SetParameters( values );
00122 }
00123 };
00124
00125 }