00001 #include "stdafx.h"
00002
00003 #include "BON.h"
00004 #include "BONImpl.h"
00005
00006 #include "ConnectionRep.h"
00007 #include "logger.h"
00008 #include "ModelRep.h"
00009
00010 #include "globals.h"
00011 extern Globals global_vars;
00012
00013 const std::string ConnectionRep::Color_str = "Color";
00014 const std::string ConnectionRep::ConnLineEnd_str = "ConnLineEnd";
00015 const std::string ConnectionRep::ConnLineStart_str = "ConnLineStart";
00016 const std::string ConnectionRep::ConnLineType_str = "ConnLineType";
00017 const std::string ConnectionRep::LabelFormatStr_str = "LabelFormatStr";
00018 const std::string ConnectionRep::SrcAttrLabel1_str = "SrcAttrLabel1";
00019 const std::string ConnectionRep::SrcAttrLabel2_str = "SrcAttrLabel2";
00020 const std::string ConnectionRep::DstAttrLabel1_str = "DstAttrLabel1";
00021 const std::string ConnectionRep::DstAttrLabel2_str = "DstAttrLabel2";
00022
00023 ConnectionRep::ConnectionRep( BON::FCO& ptr, BON::FCO& resp_ptr)
00024 : FCO( ptr, resp_ptr)
00025 {
00026 m_jointList.clear();
00027 }
00028
00029
00030 ConnectionRep::~ConnectionRep()
00031 {
00032 m_jointList.clear();
00033 }
00034
00035
00036 void ConnectionRep::initAttributes()
00037 {
00038
00039
00040
00041
00042 m_isInRootFolder = m_isInRootFolder || m_ptr->getAttribute( InRootFolder_str)->getBooleanValue();
00043
00044
00045
00046 bool isabs = true;
00047 bool isabs_set = false;
00048 if( m_ptr->getAttribute( IsAbstract_str)->getStatus() >= BON::AS_Here)
00049 {
00050 isabs = isabs && m_ptr->getAttribute( IsAbstract_str)->getBooleanValue();
00051 isabs_set = true;
00052 }
00053
00054
00055
00056 bool isgenpref_set = false;
00057 if( m_ptr->getAttribute( GeneralPreferences_str)->getStatus() >= BON::AS_Here)
00058 {
00059 m_sAttrGenPref = m_ptr->getAttribute( GeneralPreferences_str)->getStringValue();
00060 isgenpref_set = true;
00061 }
00062
00063
00064 bool isdispname_set = false;
00065 if( m_ptr->getAttribute( DisplayedName_str)->getStatus() >= BON::AS_Here)
00066 {
00067 m_sAttrDispName = m_ptr->getAttribute( DisplayedName_str)->getStringValue();
00068 isdispname_set = true;
00069 }
00070
00071
00072 bool iscolor_set = false;
00073
00074 {
00075 m_sAttrColor = m_ptr->getAttribute( Color_str)->getStringValue();
00076 iscolor_set = true;
00077 }
00078 bool isconnlineend_set = false;
00079
00080 {
00081 m_sAttrConnLineEnd = m_ptr->getAttribute( ConnLineEnd_str)->getStringValue();
00082 isconnlineend_set = true;
00083 }
00084 bool isconnlinestart_set = false;
00085
00086 {
00087 m_sAttrConnLineStart = m_ptr->getAttribute( ConnLineStart_str)->getStringValue();
00088 isconnlinestart_set = true;
00089 }
00090
00091 bool isconnlinetype_set = false;
00092
00093 {
00094 m_sAttrConnLineType = m_ptr->getAttribute( ConnLineType_str)->getStringValue();
00095 isconnlinetype_set = true;
00096 }
00097
00098 bool islabelformat_set = false;
00099 if( m_ptr->getAttribute( LabelFormatStr_str)->getStatus() >= BON::AS_Here)
00100 {
00101 m_sAttrLabelFormatStr = m_ptr->getAttribute( LabelFormatStr_str)->getStringValue();
00102 islabelformat_set = true;
00103 }
00104
00105 bool issrclabel1_set = false;
00106 if( m_ptr->getAttribute( SrcAttrLabel1_str)->getStatus() >= BON::AS_Here)
00107 {
00108 m_sAttrSrcAttrLabel1 = m_ptr->getAttribute( SrcAttrLabel1_str)->getStringValue();
00109 issrclabel1_set = true;
00110 }
00111 bool issrclabel2_set = false;
00112 if( m_ptr->getAttribute( SrcAttrLabel2_str)->getStatus() >= BON::AS_Here)
00113 {
00114 m_sAttrSrcAttrLabel2 = m_ptr->getAttribute( SrcAttrLabel2_str)->getStringValue();
00115 issrclabel2_set = true;
00116 }
00117 bool isdstlabel1_set = false;
00118 if( m_ptr->getAttribute( DstAttrLabel1_str)->getStatus() >= BON::AS_Here)
00119 {
00120 m_sAttrDstAttrLabel1 = m_ptr->getAttribute( DstAttrLabel1_str)->getStringValue();
00121 isdstlabel1_set = true;
00122 }
00123 bool isdstlabel2_set = false;
00124 if( m_ptr->getAttribute( DstAttrLabel2_str)->getStatus() >= BON::AS_Here)
00125 {
00126 m_sAttrDstAttrLabel2 = m_ptr->getAttribute( DstAttrLabel2_str)->getStringValue();
00127 isdstlabel2_set = true;
00128 }
00129
00130 std::set< BON::FCO >::const_iterator it = m_equivs.begin();
00131 for ( ; it != m_equivs.end(); ++it)
00132 {
00133 if ( *it == m_ptr) continue;
00134
00135
00136
00137 m_isInRootFolder = m_isInRootFolder || (*it)->getAttribute( InRootFolder_str)->getBooleanValue();
00138
00139
00140
00141 if( (*it)->getAttribute( IsAbstract_str)->getStatus() >= BON::AS_Here)
00142 {
00143 isabs = isabs && (*it)->getAttribute( IsAbstract_str)->getBooleanValue();
00144 isabs_set = true;
00145 }
00146
00147 #if(1)
00148
00149 if( !isgenpref_set && (*it)->getAttribute( GeneralPreferences_str)->getStatus() >= BON::AS_Here)
00150 {
00151 m_sAttrGenPref = (*it)->getAttribute( GeneralPreferences_str)->getStringValue();
00152 isgenpref_set = true;
00153 }
00154
00155
00156
00157 if( !isdispname_set && (*it)->getAttribute( DisplayedName_str)->getStatus() >= BON::AS_Here)
00158 {
00159 m_sAttrDispName = (*it)->getAttribute( DisplayedName_str)->getStringValue();
00160 isdispname_set = true;
00161 }
00162
00163
00164
00165 if ((*it)->getObjectMeta().name().find("Proxy") != std::string::npos) continue;
00166
00167 if( !iscolor_set && (*it)->getAttribute( Color_str)->getStatus() >= BON::AS_Here)
00168 {
00169 m_sAttrColor = (*it)->getAttribute( Color_str)->getStringValue();
00170 iscolor_set = true;
00171 }
00172
00173 if( !isconnlineend_set && (*it)->getAttribute( ConnLineEnd_str)->getStatus() >= BON::AS_Here)
00174 {
00175 m_sAttrConnLineEnd = (*it)->getAttribute( ConnLineEnd_str)->getStringValue();
00176 isconnlineend_set = true;
00177 }
00178
00179 if( !isconnlinestart_set && (*it)->getAttribute( ConnLineStart_str)->getStatus() >= BON::AS_Here)
00180 {
00181 m_sAttrConnLineStart = (*it)->getAttribute( ConnLineStart_str)->getStringValue();
00182 isconnlinestart_set = true;
00183 }
00184 if( !isconnlinetype_set && (*it)->getAttribute( ConnLineType_str)->getStatus() >= BON::AS_Here)
00185 {
00186 m_sAttrConnLineType = (*it)->getAttribute( ConnLineType_str)->getStringValue();
00187 isconnlinetype_set = true;
00188 }
00189
00190 if( !islabelformat_set && (*it)->getAttribute( LabelFormatStr_str)->getStatus() >= BON::AS_Here)
00191 {
00192 m_sAttrLabelFormatStr = (*it)->getAttribute( LabelFormatStr_str)->getStringValue();
00193 islabelformat_set = true;
00194 }
00195
00196 if( !issrclabel1_set && (*it)->getAttribute( SrcAttrLabel1_str)->getStatus() >= BON::AS_Here)
00197 {
00198 m_sAttrSrcAttrLabel1 = (*it)->getAttribute( SrcAttrLabel1_str)->getStringValue();
00199 issrclabel1_set = true;
00200 }
00201 if( !issrclabel2_set && (*it)->getAttribute( SrcAttrLabel2_str)->getStatus() >= BON::AS_Here)
00202 {
00203 m_sAttrSrcAttrLabel2 = (*it)->getAttribute( SrcAttrLabel2_str)->getStringValue();
00204 issrclabel2_set = true;
00205 }
00206 if( !isdstlabel1_set && (*it)->getAttribute( DstAttrLabel1_str)->getStatus() >= BON::AS_Here)
00207 {
00208 m_sAttrDstAttrLabel1 = (*it)->getAttribute( DstAttrLabel1_str)->getStringValue();
00209 isdstlabel1_set = true;
00210 }
00211 if( !isdstlabel2_set && (*it)->getAttribute( DstAttrLabel2_str)->getStatus() >= BON::AS_Here)
00212 {
00213 m_sAttrDstAttrLabel2 = (*it)->getAttribute( DstAttrLabel2_str)->getStringValue();
00214 isdstlabel2_set = true;
00215 }
00216 #endif
00217 }
00218
00219 if( isabs_set) m_isAbstract = isabs;
00220 }
00221
00222
00223 void ConnectionRep::addJoint( ConnJoint & joint)
00224 {
00225 m_jointList.push_back( joint);
00226 }
00227
00228
00229 void ConnectionRep::appendJointElements( const ConnJoint & joint_of_ancestor)
00230 {
00231 ConnJoint a_joint( joint_of_ancestor);
00232 a_joint.setConnectionPtr( this);
00233
00234 if (m_jointList.empty())
00235 m_jointList.push_back( a_joint);
00236 else
00237 {
00238 m_jointList.push_back( a_joint);
00239
00240 bool desc = false;
00241
00242 std::list<ConnJoint>::iterator it = m_jointList.begin();
00243 for( ; !desc && it != m_jointList.end(); ++it)
00244 desc = desc || it->descendantsOf( a_joint);
00245
00246 if ( !desc)
00247 global_vars.err << MSG_ERROR << "Design error at connection \"" << m_ptr << "\". Derived connection is valid only if defined between fcos derived from the fcos connected by the base connection.\n";
00248 }
00249 }
00250
00251
00252 void ConnectionRep::inherit()
00253 {
00254 ModelRepPtrList models = this->modelsIAmPartOfFinal();
00255
00256
00257 ModelRepPtrList_Iterator mod_it = models.begin();
00258
00259 for( ; mod_it != models.end(); ++mod_it )
00260 {
00261 ModelRep* mod_ptr = *mod_it;
00262
00263
00264 std::list<ConnJoint>::iterator joint_it = m_jointList.begin();
00265 for( ; joint_it != m_jointList.end(); ++joint_it )
00266 {
00267 joint_it->intInherit( mod_ptr);
00268 }
00269 }
00270
00271
00272 std::vector<FCO*> conn_descendants;
00273 this->getImpDescendants( conn_descendants);
00274
00275
00276 std::vector<FCO*>::iterator conn_it = conn_descendants.begin();
00277 for( ; conn_it != conn_descendants.end(); ++conn_it)
00278 {
00279 std::list<ConnJoint>::iterator joint_it = m_jointList.begin();
00280 for( ; joint_it != m_jointList.end(); ++joint_it )
00281 {
00282 ConnectionRep * conn_rep = 0;
00283 if ( (*conn_it)->getMyKind() == Any::CONN)
00284 conn_rep = dynamic_cast<ConnectionRep *>( *conn_it);
00285 if (conn_rep)
00286 conn_rep->appendJointElements( *joint_it);
00287 }
00288 }
00289 }
00290
00291
00292 std::string ConnectionRep::dumpConnDetails()
00293 {
00294 std::string mmm;
00295
00296 {
00297 mmm = indStr() + "<regnode name = \"color\" value =\"" + (m_sAttrColor.empty()?"0x000000":m_sAttrColor) + "\"></regnode>\n";
00298
00299 if( !m_sAttrConnLineEnd.empty())
00300 mmm += indStr() + "<regnode name = \"dstStyle\" value =\"" + m_sAttrConnLineEnd + "\"></regnode>\n";
00301
00302 if( !m_sAttrConnLineStart.empty())
00303 mmm += indStr() + "<regnode name = \"srcStyle\" value =\"" + m_sAttrConnLineStart + "\"></regnode>\n";
00304
00305 if( !m_sAttrConnLineType.empty())
00306 mmm += indStr() + "<regnode name = \"lineType\" value =\"" + m_sAttrConnLineType + "\"></regnode>\n";
00307
00308
00309 if( !m_sAttrLabelFormatStr.empty())
00310 mmm += indStr() + "<regnode name = \"labelFormatStr\" value =\"" + m_sAttrLabelFormatStr + "\"></regnode>\n";
00311
00312 std::string * which[] =
00313 {
00314 &m_sAttrSrcAttrLabel1,
00315 &m_sAttrSrcAttrLabel2,
00316 &m_sAttrDstAttrLabel1,
00317 &m_sAttrDstAttrLabel2
00318 };
00319
00320 std::string reg_label[] =
00321 {
00322 "srcLabel1",
00323 "srcLabel2",
00324 "dstLabel1",
00325 "dstLabel2"
00326 };
00327
00328 for( int i = 0; i < 4 ; ++ i)
00329 {
00330 std::string &label = *which[i];
00331 if( !label.empty()) {
00332
00333
00334
00335 if ( label.length() > 1 && label[0] == '%' && label[ label.length() - 1] == '%')
00336 {
00337 bool attr = findFinalAttributeBasedOnName( label.substr( 1, label.length() - 2));
00338 if( attr )
00339 mmm += indStr() + "<regnode name= \"" + reg_label[i] + "\" value=\"" + label + "\"/>\n";
00340 else
00341 global_vars.err << MSG_ERROR << "Attribute \"" << label.substr( 1, label.length() - 2) << "\" not found for connection \"" << m_ptr << "\". Wrong label specification.\n";
00342 }
00343 else
00344 {
00345 bool attr = findFinalAttributeBasedOnName( label);
00346 if( attr )
00347 mmm += indStr() + "<regnode name= \"" + reg_label[i] + "\" value=\"%" + label + "%\"/>\n";
00348 else
00349 mmm += indStr() + "<regnode name= \"" + reg_label[i] + "\" value=\"" + label + "\"/>\n";
00350
00351 }
00352 }
00353 }
00354 }
00355 return mmm;
00356 }
00357
00358
00359 std::string ConnectionRep::doDump()
00360 {
00361 std::string m_ref = askMetaRef();
00362
00363 std::string mmm = indStr() + "<connection name = \"" + getName() + "\" metaref = \"" + m_ref + "\"";
00364
00365 mmm += dumpAttributeList();
00366
00367 mmm +=" >\n";
00368 ++ind;
00369 mmm += dumpDispName();
00370 ++ind;
00371 mmm += dumpGeneralPref();
00372 mmm += dumpConnDetails();
00373
00374 --ind;
00375 mmm += dumpConstraints();
00376 mmm += dumpAttributes();
00377
00378 ModelRepPtrList models = this->modelsIAmPartOfFinal();
00379
00380 std::list<ConnJoint>::iterator joint_it = m_jointList.begin();
00381 for( ; joint_it != m_jointList.end(); ++joint_it )
00382 {
00383 std::string nnn = joint_it->dumpElements( models);
00384 mmm += nnn;
00385 }
00386 --ind;
00387 mmm += indStr() + "</connection>\n";
00388
00389 return mmm;
00390 }
00391
00392
00393 bool ConnectionRep::checkConnectionTargets()
00394 {
00395 bool res = true;
00396 std::list<ConnJoint>::iterator joint_it = m_jointList.begin();
00397 for( ; joint_it != m_jointList.end(); ++joint_it )
00398 {
00399 res = res && joint_it->checkElements( getName());
00400 }
00401 return res;
00402 }
00403
00404
00405 void ConnectionRep::createConstraints(Sheet * s)
00406 {
00407 std::list<ConnJoint>::iterator joint_it = m_jointList.begin();
00408 for( ; joint_it != m_jointList.end(); ++joint_it )
00409 joint_it->createConstraints(s, getName());
00410 }
00411