00001 #include "stdafx.h"
00002
00003 #include "MgaUtil.h"
00004
00005 #include "Dumper.h"
00006 #include "AspectSpecDlg.h"
00007 #include "GlobalAspOrder.h"
00008 #include "Options.h"
00009 #include "Broker.h"
00010 #include "Token.h"
00011 #include "algorithm"
00012 #include <afxdlgs.h>
00013 #include <comdef.h>
00014
00015 #include "globals.h"
00016 extern Globals global_vars;
00017
00018 int ind = 0;
00019 CAspectSpecDlg *theAspectDlg = 0;
00020
00021
00022 #define DUMPER_NOT_SPECIFIED_STR "Not specified"
00023
00024
00025 Sheet * Dumper::getInstance()
00026 {
00027 if (!Sheet::m_theOnlyInstance)
00028 {
00029 Sheet::m_theOnlyInstance = new Dumper();
00030 return Sheet::m_theOnlyInstance;
00031 }
00032 return Sheet::m_theOnlyInstance;
00033 }
00034
00035
00036 Dumper::Dumper(): Sheet()
00037 {
00038 }
00039
00040
00041 Dumper::~Dumper()
00042 {
00043 Broker::reset();
00044 }
00045
00046
00047 bool Dumper::findInFolders( FCO * fco)
00048 {
00049 std::vector<FolderRep*>::iterator it( m_folderList.begin());
00050 while( it != m_folderList.end() && !(*it)->isFCOContained( fco))
00051 ++it;
00052 return it != m_folderList.end();
00053 }
00054
00055
00056 void Dumper::inheritMoReSeCoFolAsp()
00057 {
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 ModelRep_Iterator mod_iter( m_modelList.begin());
00159 for( ; mod_iter != m_modelList.end(); ++mod_iter)
00160 (*mod_iter)->inherit();
00161
00162
00163
00164 ReferenceRep_Iterator ref_iter( m_refList.begin());
00165 for( ; ref_iter != m_refList.end(); ++ref_iter)
00166 (*ref_iter)->inherit();
00167
00168 ref_iter = m_refList.begin();
00169 for( ; ref_iter != m_refList.end(); ++ref_iter)
00170 if (!(*ref_iter)->finalize())
00171 {
00172
00173 }
00174
00175
00176 ConnectionRep_Iterator conn_iter( m_connList.begin());
00177 for( ; conn_iter != m_connList.end(); ++conn_iter)
00178 (*conn_iter)->inherit();
00179
00180
00181 SetRep_Iterator set_iter( m_setList.begin());
00182 for( ; set_iter != m_setList.end(); ++set_iter)
00183 (*set_iter)->inherit();
00184
00185
00186 std::vector<FolderRep*>::iterator folder_iter( m_folderList.begin());
00187 for( ; folder_iter != m_folderList.end(); ++folder_iter)
00188 (*folder_iter)->extendMembership();
00189
00190
00191 std::vector<AspectRep*>::iterator asp_iter( m_aspectList.begin());
00192 for( ; asp_iter != m_aspectList.end(); ++asp_iter)
00193 (*asp_iter)->extendAspectWithDescendants();
00194 }
00195
00196
00197 void Dumper::inheritConstraintsAndAttributes(FCO * ptr, FCO * c_ptr)
00198 {
00199
00200 c_ptr->addFinalConstraintList( ptr->getInitialConstraintRepPtrList());
00201
00202
00203 c_ptr->addFinalAttributeList( ptr->getInitialAttributeRepPtrList());
00204 }
00205
00206
00207 void Dumper::inheritAspConsAttr()
00208 {
00209 {FcoRep_Iterator it0( m_fcoRepList.begin());
00210 for( ; it0 != m_fcoRepList.end(); ++it0 )
00211 {
00212 std::vector<FCO*> children;
00213 (*it0)->getImpDescendants( children);
00214 children.push_back( *it0);
00215
00216 std::vector<FCO*>::iterator child_it = children.begin();
00217 for( ; child_it != children.end(); ++child_it )
00218 inheritConstraintsAndAttributes( *it0, *child_it);
00219 }}
00220
00221 {AtomRep_Iterator it1 = m_atomList.begin();
00222 for( ; it1 != m_atomList.end(); ++it1 )
00223 {
00224 std::vector<FCO*> children;
00225 (*it1)->getImpDescendants( children);
00226 children.push_back( *it1);
00227
00228 std::vector<FCO*>::iterator child_it = children.begin();
00229 for( ; child_it != children.end(); ++child_it )
00230 inheritConstraintsAndAttributes( *it1, *child_it);
00231 }}
00232
00233 {ModelRep_Iterator it2 = m_modelList.begin();
00234 for( ; it2 != m_modelList.end(); ++it2 )
00235 {
00236 std::vector<FCO*> children;
00237 (*it2)->getImpDescendants( children);
00238 children.push_back( *it2);
00239
00240 std::vector<FCO*>::iterator child_it = children.begin();
00241 for( ; child_it != children.end(); ++child_it )
00242 {
00243 ModelRep * child_mod_ptr = dynamic_cast<ModelRep *>( *child_it);
00244 if ( !child_mod_ptr) global_vars.err << MSG_ERROR << "Internal error: after dynamic cast - inheritAspConsAttr.\n";
00245
00246
00247 const ModelRep::AspectRepPtrList &asp_list = (*it2)->getAspectRepPtrList();
00248 child_mod_ptr->addFinalAspectList( asp_list);
00249
00250 inheritConstraintsAndAttributes( *it2, *child_it);
00251 }
00252 }}
00253
00254 {ConnectionRep_Iterator it3 = m_connList.begin();
00255 for( ; it3 != m_connList.end(); ++it3 )
00256 {
00257 std::vector<FCO*> children;
00258 (*it3)->getImpDescendants( children);
00259 children.push_back( *it3);
00260
00261 std::vector<FCO*>::iterator child_it = children.begin();
00262 for( ; child_it != children.end(); ++child_it )
00263 inheritConstraintsAndAttributes( *it3, *child_it);
00264 }}
00265
00266 {SetRep_Iterator it4 = m_setList.begin();
00267 for( ; it4 != m_setList.end(); ++it4 )
00268 {
00269 std::vector<FCO*> children;
00270 (*it4)->getImpDescendants( children);
00271 children.push_back( *it4);
00272
00273 std::vector<FCO*>::iterator child_it = children.begin();
00274 for( ; child_it != children.end(); ++child_it )
00275 {
00276 inheritConstraintsAndAttributes( *it4, *child_it);
00277 }
00278 }}
00279
00280 {ReferenceRep_Iterator it5 = m_refList.begin();
00281 for( ; it5 != m_refList.end(); ++it5 )
00282 {
00283 std::vector<FCO*> children;
00284 (*it5)->getImpDescendants( children);
00285 children.push_back( *it5);
00286
00287 std::vector<FCO*>::iterator child_it = children.begin();
00288 for( ; child_it != children.end(); ++child_it )
00289 inheritConstraintsAndAttributes( *it5, *child_it);
00290 }}
00291
00292 {
00293 FolderRep_Iterator folder_iter( m_folderList.begin());
00294 for( ; folder_iter != m_folderList.end(); ++folder_iter)
00295 (*folder_iter)->addFinalConstraintList( (*folder_iter)->getInitialConstraintRepPtrList());
00296 }
00297 }
00298
00299
00300 void Dumper::doAspectPartsMap()
00301 {
00302
00303 ModelRep_Iterator jt( m_modelList.begin());
00304 for( ; jt != m_modelList.end(); ++jt)
00305 {
00306 ModelRep * mod_ptr = *jt;
00307 if (!mod_ptr->isAbstract())
00308 {
00309 mod_ptr->sortMyAspects();
00310 mod_ptr->createPartsInModelAspects();
00311 }
00312 }
00313
00314
00315 std::vector<AspectRep*>::iterator it( m_aspectList.begin());
00316 for( ; it != m_aspectList.end(); ++it)
00317 {
00318 AspectRep * asp_ptr = *it;
00319 asp_ptr->sortPartMap();
00320 }
00321 }
00322
00323
00324
00325 bool Dumper::am()
00326 {
00327 bool aspect_selection_impossible( false);
00328 bool is_first_time_used_the_new_interpreter ( false);
00329
00330
00331 std::vector<PartRep> all_parts;
00332 unsigned int i = 0;
00333 std::vector< std::string> default_kindaspect_values_for_parts;
00334
00335 std::map< unsigned int, unsigned int> asp_map;
00336
00337 theAspectDlg = new CAspectSpecDlg("Configure Aspect Mapping");
00338 if (!theAspectDlg)
00339 {
00340 global_vars.err << MSG_ERROR << "ERROR: Aspect Dialogue cannot be created.\n";
00341 return true;
00342 }
00343
00344
00345 std::vector<AspectRep*>::iterator it( m_aspectList.begin());
00346 for( ; it != m_aspectList.end(); ++it)
00347 {
00348 AspectRep * asp_ptr = *it;
00349 const std::string asp_name = asp_ptr->getName();
00350
00351 if(asp_ptr->getReadOnly())
00352 {
00353 ModelRep_Iterator jt( m_modelList.begin());
00354 for( ; jt != m_modelList.end(); ++jt)
00355 {
00356 ModelRep * parent_mod_ptr = *jt;
00357 std::string parent_name = parent_mod_ptr->getName();
00358
00359
00360 const AspectRep::PartRepSeries & part_series = asp_ptr->getPartSeries( parent_mod_ptr);
00361 AspectRep::PartRepSeries_ConstIterator kt = part_series.begin();
00362 for ( ; kt != part_series.end(); ++kt)
00363 {
00364 PartRep part = *kt;
00365 std::string r_name = part.getRoleRepPtr()->getSmartRoleName();
00366 std::string primary_reg_path = "/PrimaryAspects/" + parent_name + ":" + r_name + "/" + asp_name;
00367 try {
00368 part.getFCOPtr()->getMyRegistry()->setValueByPath( primary_reg_path, "no");
00369 }
00370 catch(...) {
00371 global_vars.err << MSG_ERROR << "Internal error: Exception during registry related write operation.\n";
00372 }
00373 }
00374 }
00375 continue;
00376 }
00377
00378
00379 ModelRep_Iterator jt( m_modelList.begin());
00380 for( ; jt != m_modelList.end(); ++jt)
00381 {
00382 ModelRep * parent_mod_ptr = *jt;
00383 std::string parent_name = parent_mod_ptr->getName();
00384
00385
00386 const AspectRep::PartRepSeries & part_series = asp_ptr->getPartSeries( parent_mod_ptr);
00387 AspectRep::PartRepSeries_ConstIterator kt = part_series.begin();
00388 for ( ; kt != part_series.end(); ++kt)
00389 {
00390 PartRep part = *kt;
00391 std::string r_name = part.getRoleRepPtr()->getSmartRoleName();
00392 std::string primary_reg_path = "/PrimaryAspects/" + parent_name + ":" + r_name + "/" + asp_name;
00393 std::string kindasp_reg_path = "/KindAspects/" + parent_name + ":" + r_name + "/" + asp_name;
00394
00395 bool skip = false;
00396 bool is_model = ( part.getFCOPtr()->getMyKind() == Any::MODEL);
00397
00398 bool is_ref_to_model = false;
00399 if ( part.getFCOPtr()->getMyKind() == Any::REF)
00400 {
00401 const ReferenceRep * ref_ptr = dynamic_cast<const ReferenceRep *>( part.getFCOPtr());
00402 std::string nn = ref_ptr->getName();
00403 if (ref_ptr->pointsToModels()) is_ref_to_model = true;
00404 }
00405
00406 bool primary_aspect_needed ( parent_mod_ptr->howManyAspects() > 1);
00407 bool kind_aspect_needed ( is_model || is_ref_to_model);
00408
00409 if ( primary_aspect_needed)
00410 {
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421 int no_of_membership_in_aspects = parent_mod_ptr->searchMyAspectsForPart( part);
00422 if ( no_of_membership_in_aspects <= 1)
00423 primary_aspect_needed = false;
00424 }
00425
00426 if ( !primary_aspect_needed)
00427 {
00428
00429 std::string regVal;
00430 regVal = "yes";
00431 try {
00432
00433 part.getFCOPtr()->getMyRegistry()->setValueByPath( primary_reg_path, regVal);
00434 }
00435 catch(...) {
00436 global_vars.err << MSG_ERROR << "Internal error: Exception during registry related write operation.\n";
00437 }
00438 }
00439
00440 if ( !is_model && !is_ref_to_model)
00441 {
00442
00443
00444 skip = !primary_aspect_needed;
00445 }
00446 else if ( is_model)
00447 {
00448 const ModelRep * sub_model = dynamic_cast<const ModelRep*>( part.getFCOPtr());
00449 int sub_model_no_of_aspects = sub_model->howManyAspects();
00450 if ( sub_model_no_of_aspects <= 1)
00451 {
00452 std::string regVal;
00453 regVal = " ";
00454 try {
00455
00456 part.getFCOPtr()->getMyRegistry()->setValueByPath( kindasp_reg_path, regVal);
00457 }
00458 catch(...) {
00459 global_vars.err << MSG_ERROR << "Internal error: Exception during registry related write operation.\n";
00460 }
00461
00462 kind_aspect_needed = false;
00463 }
00464 skip = !primary_aspect_needed && !kind_aspect_needed;
00465 }
00466 else if ( 0 && is_ref_to_model)
00467 {
00468 const ReferenceRep * reference = dynamic_cast<const ReferenceRep*>( part.getFCOPtr());
00469 std::vector< AspectRep *> asp_intersect = reference->getAspectsIntersection();
00470 if ( asp_intersect.size() == 1)
00471 {
00472 AspectRep * sel = *asp_intersect.begin();
00473
00474 std::string regVal;
00475 regVal = sel->getName();
00476 try {
00477
00478 part.getFCOPtr()->getMyRegistry()->setValueByPath( kindasp_reg_path, regVal);
00479 }
00480 catch(...) {
00481 global_vars.err << MSG_ERROR << "Internal error: Exception during registry related write operation.\n";
00482 }
00483
00484 kind_aspect_needed = false;
00485 }
00486 skip = !primary_aspect_needed && !kind_aspect_needed;
00487 }
00488
00489 if (!skip)
00490 {
00491
00492
00493
00494
00495
00496
00497
00498
00499 if ( primary_aspect_needed)
00500 {
00501 std::string regVal;
00502
00503 std::string old_regVal1 = part.getFCOPtr()->getPtr()->getRegistry()->getValueByPath( primary_reg_path);
00504 std::string old_regVal2 = part.getFCOPtr()->getMyRegistryOld()->getValueByPath( primary_reg_path);
00505 regVal = part.getFCOPtr()->getMyRegistry()->getValueByPath( primary_reg_path);
00506 if (regVal.empty() && ( !old_regVal1.empty() || !old_regVal2.empty()))
00507 {
00508 regVal = old_regVal2.empty()? old_regVal1:old_regVal2;
00509 std::string n_msg = "PrimaryAspect registry information taken from the old place. Registry of: " + part.getFCOPtr()->getName() + " Registry path: " + primary_reg_path + ".\n";
00510 global_vars.err << MSG_ERROR << n_msg;
00511 is_first_time_used_the_new_interpreter = true;
00512 }
00513
00514 if ( !regVal.empty() && regVal == "no")
00515 {
00516 part.setPrimary( false);
00517 }
00518 }
00519
00520 std::string default_kind_aspect_name = "N/A", kind_aspect_name = "N/A";
00521
00522
00523 if ( kind_aspect_needed && (is_model || is_ref_to_model))
00524 {
00525 default_kind_aspect_name = DUMPER_NOT_SPECIFIED_STR; kind_aspect_name = "N/A";
00526
00527 if (is_ref_to_model)
00528 {
00529 const ReferenceRep * reference = dynamic_cast<const ReferenceRep*>( part.getFCOPtr());
00530
00531
00532 std::vector< AspectRep *> asp_intersect = reference->getAspectsIntersection();
00533 std::vector< AspectRep *>::iterator asp_intersect_it = asp_intersect.begin();
00534 while( asp_intersect_it != asp_intersect.end() && (*asp_intersect_it)->getName() != asp_name)
00535 ++asp_intersect_it;
00536 if ( asp_intersect_it != asp_intersect.end())
00537 default_kind_aspect_name = asp_name;
00538 else
00539 {
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550 if( asp_intersect.empty())
00551 {
00552
00553
00554
00555 }
00556 }
00557 }
00558 else
00559 {
00560 const ModelRep * sub_model = dynamic_cast<const ModelRep*>( part.getFCOPtr());
00561
00562
00563 std::vector< AspectRep*> sub_model_aspects = sub_model->getFinalAspectRepPtrList();
00564 std::vector< AspectRep*>::iterator sub_model_aspect_it = sub_model_aspects.begin();
00565 while( sub_model_aspect_it != sub_model_aspects.end() && (*sub_model_aspect_it)->getName() != asp_name)
00566 ++sub_model_aspect_it;
00567 if ( sub_model_aspect_it != sub_model_aspects.end())
00568 default_kind_aspect_name = asp_name;
00569 else
00570 {
00571 AspectRep * def_asp = sub_model->getFirstAspect();
00572 if (def_asp)
00573 default_kind_aspect_name = def_asp->getName();
00574 else
00575 {
00576 global_vars.err << MSG_WARNING << "Warning: Model \"" << sub_model->getPtr() << "\" has no valid aspect.\n";
00577 aspect_selection_impossible = true;
00578 }
00579 }
00580 }
00581
00582
00583 std::string regVal = "";
00584
00585 std::string old_regVal1 = part.getFCOPtr()->getPtr()->getRegistry()->getValueByPath( kindasp_reg_path);
00586 std::string old_regVal2 = part.getFCOPtr()->getMyRegistryOld()->getValueByPath( kindasp_reg_path);
00587 regVal = part.getFCOPtr()->getMyRegistry()->getValueByPath( kindasp_reg_path);
00588 if ( regVal.empty() && ( !old_regVal1.empty() || !old_regVal2.empty()))
00589 {
00590 regVal = old_regVal2.empty()?old_regVal1:old_regVal2;
00591 std::string n_msg = "KindAspect registry information taken from the old place. Registry of: " + part.getFCOPtr()->getName() + " Registry path: " + kindasp_reg_path + ".\n";
00592 global_vars.err << MSG_ERROR << n_msg;
00593 is_first_time_used_the_new_interpreter = true;
00594 }
00595
00596 bool correct_info_in_reg = false;
00597 if ( !regVal.empty() && regVal != " " && regVal != "__GME_default_mechanism")
00598 {
00599
00600 std::vector<AspectRep*> same_aspects_on_sheet = findAspectBasedOnName( regVal);
00601 if ( !same_aspects_on_sheet.empty())
00602 {
00603 if ( is_ref_to_model)
00604 {
00605 const ReferenceRep * reference = dynamic_cast<const ReferenceRep*>( part.getFCOPtr());
00606
00607
00608 std::vector< AspectRep *> asp_intersect = reference->getAspectsIntersection();
00609 std::vector< AspectRep *>::iterator asp_intersect_it = asp_intersect.begin();
00610 AspectRep * ar = 0;
00611 while( !ar && asp_intersect_it != asp_intersect.end())
00612 {
00613 if ( regVal.compare( (*asp_intersect_it)->getName()) == 0)
00614 ar = *asp_intersect_it;
00615 else
00616 ++asp_intersect_it;
00617 }
00618 if (ar)
00619 {
00620 kind_aspect_name = regVal;
00621 part.setKindAspectPtr( ar);
00622 correct_info_in_reg = true;
00623 }
00624 else
00625 global_vars.err << MSG_WARNING << "Warning: Reference \"" << reference->getPtr() << "\" registry value: \"" << regVal << "\". Aspect registry value not found among intersection of aspects the reference may have.\n";
00626 }
00627 else
00628 {
00629 const ModelRep * sub_model = dynamic_cast<const ModelRep*>( part.getFCOPtr());
00630
00631 AspectRep * ar = sub_model->getMyFirstAspectFromSet( same_aspects_on_sheet);
00632 if ( ar)
00633 {
00634 kind_aspect_name = regVal;
00635 part.setKindAspectPtr( ar);
00636 correct_info_in_reg = true;
00637
00638 }
00639 else
00640 global_vars.err << MSG_WARNING << "Warning: Model \"" << sub_model->getPtr() << "\" has no valid aspect stored in registry.\n";
00641 }
00642 }
00643 }
00644 if (!correct_info_in_reg)
00645 {
00646 kind_aspect_name = default_kind_aspect_name;
00647 }
00648 }
00649 all_parts.push_back( part);
00650 default_kindaspect_values_for_parts.push_back( default_kind_aspect_name);
00651 asp_map[
00652 (theAspectDlg->AddEntry( CString(asp_name.c_str()), CString(parent_name.c_str()) + ":" + r_name.c_str(), CString( kind_aspect_name.c_str()), primary_aspect_needed?(part.isPrimary()?"yes":"no"):"N/A", part.getFCOPtr() ))
00653 ] = i++;
00654
00655 }
00656 }
00657 }
00658 }
00659 if ( 0 &&aspect_selection_impossible)
00660 {
00661 TO("Aspect selection not possible!");
00662 delete theAspectDlg;
00663 return false;
00664 }
00665
00666 if ( is_first_time_used_the_new_interpreter)
00667 {
00668 const std::string m_note =
00669 "Probably this metamodel is interpreted with MetaGME2004 Interpreter for the first time because no data "
00670 "has been found in the new registry. Some registry entries have been copied from the old registry. "
00671 "Next time you interpret this metamodel you should not see this message.";
00672 TO( m_note);
00673 global_vars.err << MSG_INFO << m_note << "\n";
00674 }
00675
00676 int dlg_res = IDOK;
00677 if( global_vars.silent_mode)
00678 { }
00679 else
00680 dlg_res = theAspectDlg->DoModal();
00681
00682 if ( i != 0 && dlg_res == IDOK)
00683 {
00684 CWaitCursor wait;
00685
00686 std::map<unsigned int, unsigned int>::iterator it = asp_map.begin();
00687
00688 while ( it != asp_map.end())
00689 {
00690
00691
00692 unsigned short row_id = it->first;
00693 unsigned int index = it->second;
00694
00695 PartRep &act_part = all_parts[ index];
00696 ++it;
00697
00698
00699 const AspectRep * act_aspect_rep = act_part.getContainerAspectPtr();
00700 if ( !act_aspect_rep) global_vars.err << MSG_ERROR << "Internal error: ZERO pointer after aspect mapping in act_part.getContainerAspectPtr.\n";
00701 ASSERT( act_aspect_rep);
00702 std::string act_asp_name = act_aspect_rep->getName();
00703
00704 const ModelRep * act_mod_ptr = act_part.getParentPtr();
00705 if( !act_mod_ptr) global_vars.err << MSG_ERROR << "Internal error: ZERO pointer after aspect mapping in act_part.getParentPtr.\n";
00706 ASSERT( act_mod_ptr);
00707 std::string act_mod_name = act_mod_ptr->getName();
00708
00709 std::string act_role_name = act_part.getRoleRepPtr()->getSmartRoleName();
00710
00711 std::string regPath, regVal;
00712 CString dummy="";
00713 CString selected_kind_aspect_name;
00714 CString selected_primary_value;
00715 const void * useless_ptr;
00716
00717 theAspectDlg->GetEntry(row_id, dummy, selected_kind_aspect_name, selected_primary_value, useless_ptr);
00718
00719
00720 if ( !selected_primary_value.IsEmpty() && (selected_primary_value.Compare("no") == 0 || selected_primary_value.Compare("yes") == 0))
00721 {
00722
00723 regPath = "/PrimaryAspects/" + act_mod_name + ":" + act_role_name + "/" + act_asp_name;
00724 regVal = (selected_primary_value.Compare("no") == 0)?"no":"yes";
00725 act_part.setPrimary( regVal.compare("no") == 0?false:true);
00726
00727
00728 try {
00729
00730 act_part.getFCOPtr()->getMyRegistry()->setValueByPath( regPath, regVal);
00731 } catch( ...) {
00732 global_vars.err << MSG_ERROR << "Internal error: Exception during registry related write operation.\n";
00733 }
00734 }
00735
00736
00737 if ( ( act_part.getFCOPtr()->getMyKind() == Any::MODEL || act_part.getFCOPtr()->getMyKind() == Any::REF) && !selected_kind_aspect_name.IsEmpty() && selected_kind_aspect_name != "N/A")
00738 {
00739
00740 std::vector<AspectRep*> aspects_on_sheet = findAspectBasedOnName(std::string((LPCTSTR)selected_kind_aspect_name));
00741 if ( !aspects_on_sheet.empty())
00742 {
00743
00744 act_part.setKindAspectPtr( *aspects_on_sheet.begin());
00745
00746 regPath = "/KindAspects/" + act_mod_name + ":" + act_role_name + "/" + act_asp_name;
00747 regVal = selected_kind_aspect_name;
00748
00749
00750 if ( act_part.getFCOPtr()->getMyKind() == Any::MODEL && default_kindaspect_values_for_parts[ index].compare( selected_kind_aspect_name) == 0)
00751 {
00752
00753
00754 regVal = " ";
00755 }
00756
00757
00758 try {
00759
00760 act_part.getFCOPtr()->getMyRegistry()->setValueByPath( regPath, regVal);
00761 } catch(...) {
00762 global_vars.err << MSG_ERROR << "Internal error: Exception during registry related write operation.\n";
00763 }
00764 }
00765 else
00766 {
00767 act_part.setKindAspectPtr( 0);
00768 if( selected_kind_aspect_name == DUMPER_NOT_SPECIFIED_STR)
00769 {
00770 }
00771 else
00772 global_vars.err << MSG_WARNING << "Warning: User selected aspect not found on sheet! Aspect \"" << act_asp_name << "\" Model \"" << act_mod_name << "\" Role \"" << act_role_name << "\" Selected aspect name: \"" << (LPCTSTR) selected_kind_aspect_name << "\".\n";
00773
00774
00775 regPath = "/KindAspects/" + act_mod_name + ":" + act_role_name + "/" + act_asp_name;
00776 regVal = "";
00777
00778
00779 try {
00780 act_part.getFCOPtr()->getMyRegistry()->setValueByPath( regPath, regVal);
00781 } catch(...) {
00782 global_vars.err << MSG_ERROR << "Internal error: Exception during registry related write operation.\n";
00783 }
00784 }
00785 }
00786 if ( ( act_part.getFCOPtr()->getMyKind() == Any::MODEL || act_part.getFCOPtr()->getMyKind() == Any::REF) && selected_kind_aspect_name == "N/A")
00787 {
00788
00789
00790 }
00791 }
00792 }
00793 else if( i == 0)
00794 global_vars.err << MSG_INFO << "Note: Aspect mapping avoided. No user choice needed to be made.\n";
00795 else
00796 global_vars.err << MSG_INFO << "Note: Aspect mapping cancelled. Some data may not have been written back to registry.\n";
00797 delete theAspectDlg;
00798 return true;
00799 }
00800
00801
00802 std::vector<AspectRep *> Dumper::findAspectBasedOnName(const std::string & name_to_find) const
00803 {
00804 std::vector<AspectRep *> result;
00805
00806 std::vector<AspectRep *>::const_iterator asp_iter( m_aspectList.begin());
00807 for( ; asp_iter != m_aspectList.end(); ++asp_iter )
00808 {
00809 if ( (*asp_iter)->getName() == name_to_find )
00810 {
00811 if ( std::find( result.begin(), result.end(), *asp_iter) == result.end())
00812 result.push_back( *asp_iter);
00813 }
00814 }
00815 return result;
00816 }
00817
00818
00819 void Dumper::createConstraints()
00820 {
00821
00822
00823 ConnectionRep_Iterator conn_iter( m_connList.begin());
00824
00825 for( ; conn_iter != m_connList.end(); ++conn_iter)
00826 (*conn_iter)->createConstraints( this);
00827
00828
00829 std::vector<ModelRep*>::const_iterator it_m = m_modelList.begin();
00830 for( ; it_m != m_modelList.end(); ++it_m)
00831 {
00832 (*it_m)->createConstraints( this);
00833 }
00834
00835
00836
00837
00838 {
00839 }
00840
00841
00842
00843
00844 {
00845 }
00846
00847
00848
00849
00850 {
00851 }
00852
00853
00854 std::vector<FolderRep*>::iterator it_fd = m_folderList.begin();
00855 for( ; it_fd != m_folderList.end(); ++it_fd)
00856 {
00857 (*it_fd)->createConstraints( this);
00858 }
00859 }
00860
00861
00862 void Dumper::doDump()
00863 {
00864
00865 std::string mmm= "<?xml version=\"1.0\"?>\n<!DOCTYPE paradigm SYSTEM \"edf.dtd\">"
00866 "\n\n<paradigm "
00867 "name=\"" + xmlFilter(m_projName) + "\" " +
00868 (m_projVersion.empty() ? "" : "version=\"" + xmlFilter(m_projVersion) + "\" ") +
00869 "guid=\"" + m_projGUID + "\" " +
00870 "cdate=\"" + xmlFilter(m_projCreated) + "\" " +
00871 "mdate=\"" + xmlFilter(m_projModified) + "\" " +
00872 ">\n\n" +
00873 "\t<comment>" + xmlFilter(m_projComment) + "</comment>\n\n" +
00874 "\t<author>" + xmlFilter(m_projAuthor) + "</author>\n\n";
00875
00876 DMP( mmm); mmm = "";
00877
00878 mmm = m_rootFolder.headDump();
00879
00880 DMP( mmm); mmm = "";
00881
00882 ++ind;
00883
00884 std::map< std::string, bool, StringLex> already_dumped;
00885
00886
00887 {
00888 AnyLexicographicSort lex;
00889 std::string last_name = "";
00890 std::sort( m_constraintList.begin(), m_constraintList.end(), lex );
00891 ConstraintRep_Iterator it_cons1 = m_constraintList.begin();
00892 for( ; it_cons1 != m_constraintList.end(); ++it_cons1)
00893 if (!(*it_cons1)->isAttached())
00894 {
00895 mmm += (*it_cons1)->doDump();
00896 if ( last_name != "" && last_name == (*it_cons1)->getName())
00897 global_vars.err << MSG_ERROR << "Error: Duplicate global constraint name found \"" << (*it_cons1)->getPtr() << "\".\n";
00898 last_name = (*it_cons1)->getName();
00899 }
00900 }
00901
00902 DMP( mmm); mmm = "";
00903
00904
00905
00906 {
00907 AnyLexicographicSort lex;
00908 std::string last_name = "";
00909 std::sort( m_constraintFuncList.begin(), m_constraintFuncList.end(), lex );
00910
00911 ConstraintFuncRep_Iterator it_cons2 = m_constraintFuncList.begin();
00912 for( ; it_cons2 != m_constraintFuncList.end(); ++it_cons2)
00913 {
00914 mmm += (*it_cons2)->doDump();
00915 if ( last_name != "" && last_name == (*it_cons2)->getName())
00916 global_vars.err << MSG_ERROR << "Error: Duplicate constraint function name found \"" << (*it_cons2)->getPtr() << "\".\n";
00917 last_name = (*it_cons2)->getName();
00918 }
00919 }
00920
00921 DMP( mmm); mmm = "";
00922
00923
00924
00925 {
00926 AnyLexicographicSort lex;
00927 std::string last_name = "";
00928 std::sort( m_attributeList.begin(), m_attributeList.end(), lex );
00929
00930 AttributeRep_Iterator it = m_attributeList.begin();
00931 for( ; it != m_attributeList.end(); ++it)
00932
00933 if((*it)->isGlobal())
00934 {
00935
00936 mmm += (*it)->doDumpAttr("");
00937 if ( last_name != "" && last_name == (*it)->getName())
00938 global_vars.err << MSG_ERROR << "Error: Duplicate global attribute name found \"" << (*it)->getPtr() << "\".\n";
00939 last_name = (*it)->getName();
00940 }
00941 }
00942
00943 DMP( mmm); mmm = "";
00944
00945
00946 {AnyLexicographicSort lex;
00947 std::string last_name = "", this_name = "";
00948 std::sort( m_atomList.begin(), m_atomList.end(), lex );
00949 std::vector<AtomRep*>::const_iterator it_b = m_atomList.begin();
00950 if ( it_b != m_atomList.end())
00951 {
00952 for( ; it_b != m_atomList.end(); ++it_b)
00953 {
00954 if ( !(*it_b)->isAbstract())
00955 {
00956 mmm += (*it_b)->doDump();
00957
00958 this_name = (*it_b)->getName();
00959 if (last_name != "" && last_name == this_name)
00960 global_vars.err << MSG_ERROR << "Error: Duplicate atom name found \"" << this_name << "\".\n";
00961 else if (already_dumped[ this_name])
00962 global_vars.err << MSG_ERROR << "Error: Duplicate fco name found \"" << this_name << "\".\n";
00963
00964 already_dumped[ this_name] = true;
00965 last_name = this_name;
00966 }
00967 }
00968 DMP( mmm);
00969 mmm = "";
00970 }}
00971
00972
00973 {AnyLexicographicSort lex;
00974 std::string last_name = "", this_name = "";
00975 std::sort( m_setList.begin(), m_setList.end(), lex );
00976 std::vector<SetRep*>::const_iterator it_c = m_setList.begin();
00977 if ( it_c != m_setList.end())
00978 {
00979 for( ; it_c != m_setList.end(); ++it_c)
00980 {
00981 if ( !(*it_c)->isAbstract())
00982 {
00983 mmm += (*it_c)->doDump();
00984
00985 this_name = (*it_c)->getName();
00986 if ( last_name != "" && last_name == this_name)
00987 global_vars.err << MSG_ERROR << "Error: Duplicate set name found \"" << this_name << "\".\n";
00988 else if (already_dumped[ this_name])
00989 global_vars.err << MSG_ERROR << "Error: Duplicate fco name found \"" << this_name << "\".\n";
00990
00991 already_dumped[ this_name] = true;
00992 last_name = this_name;
00993 }
00994 }
00995 DMP( mmm);
00996 mmm = "";
00997 }}
00998
00999
01000 {AnyLexicographicSort lex;
01001 std::string last_name = "", this_name = "";
01002 std::sort( m_connList.begin(), m_connList.end(), lex );
01003 std::vector<ConnectionRep*>::const_iterator it_cn = m_connList.begin();
01004 if ( it_cn != m_connList.end())
01005 {
01006 for( ; it_cn != m_connList.end(); ++it_cn)
01007 {
01008 if ( !(*it_cn)->isAbstract())
01009 {
01010 mmm += (*it_cn)->doDump();
01011
01012 this_name = (*it_cn)->getName();
01013 if ( last_name != "" && last_name == this_name)
01014 global_vars.err << MSG_ERROR << "Error: Duplicate connection name found \"" << this_name << "\".\n";
01015 else if (already_dumped[ this_name])
01016 global_vars.err << MSG_ERROR << "Error: Duplicate fco name found \"" << this_name << "\".\n";
01017
01018 already_dumped[ this_name] = true;
01019 last_name = this_name;
01020 }
01021 }
01022 DMP( mmm);
01023 mmm = "";
01024 }}
01025
01026
01027 {AnyLexicographicSort lex;
01028 std::string last_name = "", this_name = "";
01029 std::sort( m_refList.begin(), m_refList.end(), lex );
01030 std::vector<ReferenceRep*>::const_iterator it_ref = m_refList.begin();
01031 if ( it_ref != m_refList.end())
01032 {
01033 for( ; it_ref != m_refList.end(); ++it_ref)
01034 {
01035 if ( !(*it_ref)->isAbstract())
01036 {
01037 mmm += (*it_ref)->doDump();
01038
01039 this_name = (*it_ref)->getName();
01040 if ( last_name != "" && last_name == this_name)
01041 global_vars.err << MSG_ERROR << "Error: Duplicate reference name found \"" << this_name << "\".\n";
01042 else if (already_dumped[ this_name])
01043 global_vars.err << MSG_ERROR << "Error: Duplicate fco name found \"" << this_name << "\".\n";
01044
01045 already_dumped[ this_name] = true;
01046 last_name = this_name;
01047 }
01048 }
01049 DMP( mmm);
01050 mmm = "";
01051 }}
01052
01053
01054 {AnyLexicographicSort lex;
01055 std::string last_name = "", this_name = "";
01056 std::sort( m_modelList.begin(), m_modelList.end(), lex );
01057 std::vector<ModelRep*>::const_iterator it_m = m_modelList.begin();
01058 if ( it_m != m_modelList.end())
01059 {
01060 for( ; it_m != m_modelList.end(); ++it_m)
01061 {
01062 if ( !(*it_m)->isAbstract())
01063 {
01064 mmm += (*it_m)->doDump();
01065
01066 this_name = (*it_m)->getName();
01067 if ( last_name != "" && last_name == this_name)
01068 global_vars.err << MSG_ERROR << "Error: Duplicate model name found \"" << this_name << "\".\n";
01069 else if (already_dumped[ this_name])
01070 global_vars.err << MSG_ERROR << "Error: Duplicate fco name found \"" << this_name << "\".\n";
01071
01072 already_dumped[ this_name] = true;
01073 last_name = this_name;
01074 }
01075 }
01076 DMP( mmm);
01077 mmm = "";
01078 }}
01079
01080
01081 {AnyLexicographicSort lex;
01082 std::string last_name = "", this_name = "";
01083 std::sort( m_folderList.begin(), m_folderList.end(), lex );
01084 std::vector<FolderRep*>::iterator it_fd = m_folderList.begin();
01085 if ( it_fd != m_folderList.end())
01086 {
01087 for( ; it_fd != m_folderList.end(); ++it_fd)
01088 {
01089 mmm += (*it_fd)->doDump();
01090
01091 this_name = (*it_fd)->getName();
01092 if ( last_name != "" && last_name == this_name)
01093 global_vars.err << MSG_ERROR << "Error: Duplicate folder name found \"" << this_name << "\".\n";
01094 else if (already_dumped[ this_name])
01095 global_vars.err << MSG_ERROR << "Error: Duplicate name found \"" << this_name << "\".\n";
01096
01097 already_dumped[ this_name] = true;
01098 last_name = this_name;
01099 }
01100 DMP( mmm);
01101 mmm = "";
01102 }}
01103
01104 mmm += m_rootFolder.tailDump();
01105
01106 DMP( mmm);
01107 mmm = "";
01108
01109 --ind;
01110 DMP("</paradigm>\n");
01111
01112
01113
01114 {std::vector<AspectRep*>::iterator it( m_aspectList.begin());
01115 for( ; it != m_aspectList.end(); ++it)
01116 {
01117 const std::string asp_name = (*it)->getName();
01118 if (already_dumped[ asp_name])
01119 {
01120 global_vars.err << MSG_WARNING << "Error: Duplicate name found \"" << asp_name << "\" (aspect and kind names should be unique).\n";
01121 }
01122 }}
01123
01124 }
01125
01126
01127 bool Dumper::checkAll()
01128 {
01129 const MON::Object& meta = this->m_BON_Project_Root_Folder->getObjectMeta();
01130 if (meta.project().displayedName() != "MetaGME")
01131 global_vars.err << MSG_WARNING << "Warning: file's paradigm '" << meta.project().displayedName() << "' is not MetaGME\n";
01132 bool res0 = checkRootFolder();
01133 bool res1 = checkAllFCOs();
01134 bool res2 = checkOrphanAttributes();
01135 bool res3 = checkEmptyFolders();
01136 res0 = res0 && res1 && res2 && res3;
01137 return res0;
01138 }
01139
01140
01141 bool Dumper::checkRootFolder() const
01142 {
01143 if (m_rootFolder.isEmpty())
01144 {
01145 global_vars.err << MSG_ERROR << "CHECK: RootFolder is empty.\n";
01146 return false;
01147 }
01148 return true;
01149 }
01150
01151
01152 bool Dumper::checkEmptyFolders() const
01153 {
01154 bool res = true;
01155 FolderRep_ConstIterator it6 = m_folderList.begin();
01156 for( ; it6 != m_folderList.end(); ++it6 )
01157 {
01158 if ((*it6)->isEmpty())
01159 {
01160 global_vars.err << MSG_ERROR << "CHECK: Folder \"" << (*it6)->getPtr() << "\" is empty.\n";
01161 res = false;
01162 }
01163 }
01164 return res;
01165 }
01166
01167
01168 bool Dumper::checkOrphanAttributes()
01169 {
01170 bool res = true;
01171 AttributeRep_Iterator it = m_attributeList.begin();
01172 for( ; it != m_attributeList.end(); ++it)
01173 {
01174 if ((*it)->hasAnyOwner() < 1 && !(*it)->isGlobal())
01175 {
01176 res = false;
01177 global_vars.err << MSG_ERROR << "CHECK: \"" << (*it)->getPtr() << "\" local scope attribute not owned by any FCO.\n";
01178 }
01179 }
01180 return res;
01181 }
01182
01183
01184 bool Dumper::checkAllFCOs()
01185 {
01186 bool res = true;
01187 {FcoRep_Iterator it0( m_fcoRepList.begin());
01188 for( ; it0 != m_fcoRepList.end(); ++it0 )
01189 {
01190
01191
01192 if (!(*it0)->isAbstract())
01193 {
01194 global_vars.err << MSG_ERROR << "CHECK: FCO \"" << (*it0)->getPtr() << "\" should be abstract.\n";
01195 res = false;
01196 }
01197 if (!(*it0)->isAbstract() && !(*it0)->checkIsPartOfFinal())
01198 {
01199
01200
01201 }
01202 }}
01203
01204 {AtomRep_Iterator it1 = m_atomList.begin();
01205 for( ; it1 != m_atomList.end(); ++it1 )
01206 {
01207 if (!(*it1)->checkInheritance())
01208 res = false;
01209 if (!(*it1)->isAbstract() && !(*it1)->checkIsPartOfFinal())
01210 {
01211
01212
01213 }
01214 }}
01215
01216 {ModelRep_Iterator it2 = m_modelList.begin();
01217 for( ; it2 != m_modelList.end(); ++it2 )
01218 {
01219 if (!(*it2)->checkInheritance())
01220 res = false;
01221
01222 if (!(*it2)->isAbstract())
01223 if( !(*it2)->checkMyAspects( this))
01224 res = false;
01225
01226 if (!(*it2)->isAbstract() && !(*it2)->checkIsPartOfFinal() && !m_rootFolder.isInRoot( *it2) && !findInFolders(*it2))
01227 {
01228
01229
01230
01231 }
01232 }}
01233
01234 {ConnectionRep_Iterator it3 = m_connList.begin();
01235 for( ; it3 != m_connList.end(); ++it3 )
01236 {
01237 if (!(*it3)->checkInheritance())
01238 res = false;
01239 if (!(*it3)->checkConnectionTargets())
01240 res = false;
01241 if (!(*it3)->isAbstract() && !(*it3)->checkIsPartOfFinal())
01242 {
01243
01244
01245 }
01246 }}
01247
01248 {SetRep_Iterator it4 = m_setList.begin();
01249 for( ; it4 != m_setList.end(); ++it4 )
01250 {
01251 if (!(*it4)->checkInheritance())
01252 res = false;
01253 if( !(*it4)->checkSetElements())
01254 res = false;
01255 if (!(*it4)->isAbstract() && !(*it4)->checkIsPartOfFinal())
01256 {
01257
01258
01259 }
01260 }}
01261
01262 {ReferenceRep_Iterator it5 = m_refList.begin();
01263 for( ; it5 != m_refList.end(); ++it5 )
01264 {
01265 if (!(*it5)->checkInheritance())
01266 res = false;
01267 if (!(*it5)->checkNotEmpty())
01268 {
01269 global_vars.err << MSG_WARNING << "CHECK: Reference \"" << (*it5)->getPtr() << "\" is not referring to any fco.\n";
01270 res = false;
01271 }
01272 else
01273 {
01274
01275
01276
01277
01278
01279
01280 if (!(*it5)->isAbstract() && !(*it5)->checkIsPartOfFinal())
01281 {
01282
01283
01284 }
01285 }
01286 }}
01287
01288 return res;
01289 }
01290
01291
01292 void Dumper::findMaxOfMetaRefs()
01293 {
01294 {FcoRep_Iterator it0( m_fcoRepList.begin());
01295 for( ; it0 != m_fcoRepList.end(); ++it0 )
01296 Broker::initFromObj( (*it0)->getPtr(), (*it0)->getParentFolder(), (*it0)->getMyKindStr());}
01297
01298 {AtomRep_Iterator it1 = m_atomList.begin();
01299 for( ; it1 != m_atomList.end(); ++it1 )
01300 Broker::initFromObj( (*it1)->getPtr(), (*it1)->getParentFolder(), (*it1)->getMyKindStr());}
01301
01302 {ModelRep_Iterator it2 = m_modelList.begin();
01303 for( ; it2 != m_modelList.end(); ++it2 )
01304 Broker::initFromObj( (*it2)->getPtr(), (*it2)->getParentFolder(), (*it2)->getMyKindStr());}
01305
01306 {ConnectionRep_Iterator it3 = m_connList.begin();
01307 for( ; it3 != m_connList.end(); ++it3 )
01308 Broker::initFromObj( (*it3)->getPtr(), (*it3)->getParentFolder(), (*it3)->getMyKindStr());}
01309
01310 {SetRep_Iterator it4 = m_setList.begin();
01311 for( ; it4 != m_setList.end(); ++it4 )
01312 Broker::initFromObj( (*it4)->getPtr(), (*it4)->getParentFolder(), (*it4)->getMyKindStr());}
01313
01314 {ReferenceRep_Iterator it5 = m_refList.begin();
01315 for( ; it5 != m_refList.end(); ++it5 )
01316 Broker::initFromObj( (*it5)->getPtr(), (*it5)->getParentFolder(), (*it5)->getMyKindStr());}
01317
01318 {FolderRep_Iterator it6 = m_folderList.begin();
01319 for( ; it6 != m_folderList.end(); ++it6 )
01320 Broker::initFromObj( (*it6)->getPtr(), (*it6)->getParentFolder(), (*it6)->getMyKindStr());}
01321
01322 {AspectRep_Iterator it7 = m_aspectList.begin();
01323 for( ; it7 != m_aspectList.end(); ++it7)
01324 Broker::initFromAspectObj( (*it7)->getPtr(), (*it7)->getName(), Sheet::m_BON_Project_Root_Folder);}
01325
01326 {AttributeRep_Iterator it8 = m_attributeList.begin();
01327 for (; it8 != m_attributeList.end(); ++it8)
01328 Broker::initFromObj( (*it8)->getPtr(), (*it8)->getParentFolder(), (*it8)->getMyKindStr());}
01329
01330 Broker::checkDuplicates();
01331 Broker::init();
01332 }
01333
01334
01335 bool Dumper::sortPtrs()
01336 {
01337
01338 AnyLexicographicSort lex;
01339
01340 std::sort( m_folderList.begin(), m_folderList.end(), lex );
01341 std::sort( m_fcoRepList.begin(), m_fcoRepList.end(), lex );
01342 std::sort( m_atomList.begin(), m_atomList.end(), lex );
01343 std::sort( m_refList.begin(), m_refList.end(), lex );
01344 std::sort( m_connList.begin(), m_connList.end(), lex );
01345 std::sort( m_setList.begin(), m_setList.end(), lex );
01346 std::sort( m_modelList.begin(), m_modelList.end(), lex );
01347
01348
01349 std::sort( m_constraintList.begin(), m_constraintList.end(), lex );
01350 std::sort( m_constraintFuncList.begin(), m_constraintFuncList.end(), lex );
01351 std::sort( m_attributeList.begin(), m_attributeList.end(), lex );
01352
01353 return true;
01354 }
01355
01356
01357 bool Dumper::checkUniqueAspectNames()
01358 {
01359 std::map< std::string, AspectRep *> names;
01360 for( unsigned int i = 0; i < m_aspectList.size(); ++i)
01361 {
01362 if( names.find( m_aspectList[i]->getName()) == names.end())
01363 names[ m_aspectList[i]->getName()] = m_aspectList[i];
01364 else
01365 global_vars.err << MSG_WARNING << "Warning: Duplicate aspect name \""
01366 << m_aspectList[i]->getName() << "\" found. See objects: "
01367 << m_aspectList[i]->getPtr() << " and "
01368 << names.find( m_aspectList[i]->getName())->second->getPtr() << " ! Use SameAspect relation to connect them.\n";
01369 }
01370 return true;
01371 }
01372
01373
01374
01375
01376
01377
01378 bool Dumper::aspectOrderSel()
01379 {
01380 unsigned int sz = m_aspectList.size();
01381 if ( sz == 0) return false;
01382 else if ( sz == 1) return true;
01383
01384 GlobalAspOrder g;
01385 const std::string aspect_order_registry_token = "/AspectOrder";
01386 std::vector< AspectRep * > dlg_aspects_init_order;
01387
01388 std::sort( m_aspectList.begin(), m_aspectList.end(), AspectCompare());
01389
01390 BON::RegistryNode rn = Sheet::m_BON_Project_Root_Folder->getRegistry()->getChild( AspectRep::m_aspectRegistryRoot + aspect_order_registry_token);
01391 if ( rn && rn->getValue() == "valid")
01392 {
01393
01394
01395
01396 std::set< AspNamePriorityComp::Type, AspNamePriorityComp> asp_order;
01397 std::set<BON::RegistryNode> ch = rn->getChildren();
01398 std::set<BON::RegistryNode>::iterator i = ch.begin();
01399 for( ; i != ch.end(); ++i)
01400 {
01401 asp_order.insert( AspNamePriorityComp::Type( (*i)->getName(), (*i)->getIntegerValue()));
01402 }
01403
01404 std::set< AspNamePriorityComp::Type, AspNamePriorityComp>::iterator it = asp_order.begin();
01405 for( ; it != asp_order.end(); ++it)
01406 {
01407 std::vector<AspectRep *> asp_with_this_name = findAspectBasedOnName( it->first);
01408 for( unsigned int l = 0; l < asp_with_this_name.size(); ++l)
01409 dlg_aspects_init_order.push_back( asp_with_this_name[ l]);
01410 }
01411
01412 int needed = m_aspectList.size() - dlg_aspects_init_order.size();
01413
01414 ASSERT( needed >= 0);
01415
01416 if ( needed > 0)
01417 {
01418 std::vector<AspectRep*>::iterator aspvec_it = m_aspectList.begin();
01419 for( ; aspvec_it != m_aspectList.end() && needed > 0; ++aspvec_it)
01420 {
01421 std::string asp_name = (*aspvec_it)->getName();
01422
01423 std::vector<AspectRep*>::iterator asp_init_it = dlg_aspects_init_order.begin();
01424 while( asp_init_it != dlg_aspects_init_order.end() && (*asp_init_it)->getName() != asp_name )
01425 ++asp_init_it;
01426 if ( asp_init_it == dlg_aspects_init_order.end())
01427 {
01428 dlg_aspects_init_order.push_back( *aspvec_it);
01429 --needed;
01430 }
01431 }
01432 }
01433 ASSERT( dlg_aspects_init_order.size() == m_aspectList.size());
01434 }
01435 else
01436 dlg_aspects_init_order = m_aspectList;
01437
01438 ASSERT( dlg_aspects_init_order.size() == m_aspectList.size());
01439 g.addAspects( dlg_aspects_init_order );
01440
01441 int dlg_res;
01442 if( global_vars.silent_mode)
01443 {
01444 g.m_resultAspects = dlg_aspects_init_order;
01445 dlg_res = IDOK;
01446 }
01447 else
01448 dlg_res = g.DoModal();
01449
01450 if ( dlg_res == IDOK)
01451 {
01452 const std::string path( "/" + AspectRep::m_aspectRegistryRoot + aspect_order_registry_token);
01453 Sheet::m_BON_Project_Root_Folder->getRegistry()->setValueByPath( path, "valid");
01454
01455 ASSERT( g.m_resultAspects.size() == m_aspectList.size());
01456 unsigned int i = 0;
01457 for( ; i < g.m_resultAspects.size(); ++i)
01458 {
01459 AspectRep * curr_asp = g.m_resultAspects[i];
01460 curr_asp->setPriority( i+1);
01461
01462 std::string subtoken = "/" + curr_asp->getName();
01463 char idx_str[32];
01464 sprintf( idx_str, "%d", i+1);
01465 Sheet::m_BON_Project_Root_Folder->getRegistry()->setValueByPath( path + subtoken, idx_str);
01466 }
01467
01468
01469 for( i = 0; i < m_aspectList.size(); ++i)
01470 {
01471 if ( m_aspectList[i]->getPriority() == 0)
01472 {
01473 ASSERT(0);
01474 global_vars.err << MSG_INFO << "Internal error: aspect \"" << m_aspectList[i]->getName() << "\" has 0 priority value set after the dialog. Reset to 0x7fffffff.\n";
01475 m_aspectList[i]->setPriority( 0x7fffffff);
01476 }
01477 }
01478
01479 }
01480
01481 std::sort( m_aspectList.begin(), m_aspectList.end(), AspectCompare());
01482
01483 return true;
01484 }
01485
01486
01487 bool Dumper::build()
01488 {
01489 bool success = true;
01490 CWaitCursor wait;
01491 findMaxOfMetaRefs();
01492
01493 checkUniqueAspectNames();
01494 aspectOrderSel();
01495 wait.Restore();
01496
01497 sortPtrs();
01498
01499 createConstraints();
01500 inheritMoReSeCoFolAsp();
01501 inheritAspConsAttr();
01502
01503 if ( !checkAll())
01504 {
01505 TO("Please correct the errors!");
01506
01507 }
01508
01509 doAspectPartsMap();
01510
01511 bool am_res = am();
01512 if (!am_res)
01513 success = false;
01514
01515 wait.Restore();
01516 doDump();
01517
01518 return success;
01519 }
01520
01521 bool Dumper::doParseCardinality(const std::string& cardinality, const std::string &target, const std::string &contextDesc, std::string &expr)
01522 {
01523
01524
01525
01526
01527
01528 Tokenizer tok;
01529
01530
01531 expr = "";
01532
01533
01534 std::string card( cardinality);
01535
01536 tok.removeWSP( card);
01537
01538
01539
01540 bool berr = false;
01541
01542 std::vector< std::string > ORs;
01543
01544 tok.split( card, ",", ORs);
01545
01546 for (int i = 0; i < ORs.size(); i++) {
01547
01548 std::vector< std::string > bounds;
01549
01550 tok.split( ORs[i], "..", bounds);
01551
01552
01553 std::string orexpr;
01554
01555
01556 if (bounds.size() == 1) {
01557 int multip;
01558
01559 if(sscanf( bounds[0].c_str(),"%d",&multip) != 1) {
01560 berr = true;
01561 break;
01562 }
01563 else {
01564 if (multip < 0) {
01565 global_vars.err << MSG_ERROR << "Error: Multiplicity is negative: " << contextDesc << ".\n";
01566 }
01567
01568 orexpr = "(" + target + " = ";
01569 char tmp[32];
01570 sprintf( tmp, "%d", multip);
01571 orexpr += tmp;
01572 orexpr += ")";
01573 }
01574 }
01575
01576 else if (bounds.size() == 2) {
01577 int multipmin, multipmax;
01578
01579 std::string andexpr1, andexpr2;
01580
01581
01582 if(sscanf( bounds[0].c_str(),"%d",&multipmin) != 1) {
01583 berr = true;
01584 break;
01585 }
01586 else {
01587 if (multipmin < 0) {
01588 global_vars.err << MSG_ERROR << "Error: Minimum multiplicity is negative: " << contextDesc << ".\n";
01589 }
01590 if (multipmin > 0) {
01591
01592 andexpr1 = "(" + target + " >= ";
01593 char tmp[32];
01594 sprintf( tmp, "%d", multipmin);
01595 andexpr1 += tmp;
01596 andexpr1 += ")";
01597 }
01598 }
01599
01600
01601 if(sscanf( bounds[1].c_str(),"%d",&multipmax) != 1) {
01602 if (bounds[1] != "*") {
01603 berr = true;
01604 break;
01605 }
01606 }
01607 else {
01608
01609 andexpr2 = "(" + target + " <= ";
01610 char tmp[32];
01611 sprintf( tmp, "%d", multipmax);
01612 andexpr2 += tmp;
01613 andexpr2 += ")";
01614 if (multipmax < 0) {
01615 global_vars.err << MSG_ERROR << "Error: Maximum multiplicity is negative: " << contextDesc << ".\n";
01616 }
01617 if (multipmax < multipmin) {
01618 global_vars.err << MSG_ERROR << "Error: Minimum multiplicity > Maximum multiplicity : " << contextDesc << ".\n";
01619 }
01620 }
01621
01622
01623 if ((!andexpr1.empty()) && (!andexpr2.empty())) {
01624
01625 orexpr = "( " + andexpr1 + " and " + andexpr2 + " )";
01626 }
01627
01628 else if (!andexpr1.empty()) {
01629 orexpr = andexpr1;
01630 }
01631
01632 else if (!andexpr2.empty()) {
01633 orexpr = andexpr2;
01634 }
01635 }
01636
01637
01638 if (!orexpr.empty()) {
01639
01640 if (!expr.empty()) {
01641 expr += " or ";
01642 }
01643 expr += orexpr;
01644 }
01645 }
01646
01647 if (berr) {
01648 expr = "";
01649 }
01650
01651
01652 return berr;
01653 }
01654
01655 std::string Dumper::makeValidFileName( const std::string& pInFile)
01656 {
01657 std::string res;
01658 std::string badchars(_T("\\/:*?\"<>|"));
01659 for( unsigned int i = 0; i < pInFile.length(); ++i)
01660 {
01661 if( badchars.find( pInFile[i] ) == std::string::npos)
01662 res += pInFile[i];
01663 else
01664 res += '_';
01665 }
01666 return res;
01667 }
01668
01669 int Dumper::selectOutputFiles( const BON::Project& proj, const std::string& p_proj_name, const std::string& proj_path)
01670 {
01671 std::string proj_name = makeValidFileName( p_proj_name);
01672 try {
01673 global_vars.xmp_file_name = proj_name + ".xmp";
01674 global_vars.err_file_name = global_vars.xmp_file_name + ".log";
01675 CString def_name = global_vars.xmp_file_name.c_str();
01676
01677 if( global_vars.silent_mode)
01678 {
01679 global_vars.xmp_file_name = proj_path + proj_name + ".xmp";
01680 try {
01681 CFile f( global_vars.xmp_file_name.c_str(), CFile::modeCreate);
01682 global_vars.xmp_file_name = f.GetFilePath();
01683 f.Close();
01684 CFile::Remove( global_vars.xmp_file_name.c_str());
01685 }
01686 catch(...) {
01687 global_vars.xmp_file_name = proj_path + proj_name + ".xmp";
01688 }
01689 global_vars.err_file_name = global_vars.xmp_file_name + ".log";
01690 }
01691 else
01692 {
01693 CWaitCursor w;
01694 CFileDialog dlg(FALSE, "xmp", def_name,
01695 OFN_EXPLORER | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
01696 "XML Paradigm Files (*.xmp)|*.xmp|");
01697 dlg.GetOFN().lpstrInitialDir = proj_path.c_str();
01698
01699 int dlg_res = IDOK;
01700 dlg_res = dlg.DoModal();
01701 if( dlg_res == IDOK)
01702 {
01703 CString filename = dlg.GetPathName();
01704 global_vars.xmp_file_name = (LPCTSTR) filename;
01705 global_vars.err_file_name = global_vars.xmp_file_name + ".log";
01706 }
01707 else
01708 {
01709
01710 return 4;
01711 }
01712 }
01713 } catch (...) {
01714 global_vars.err << MSG_ERROR << "Exception caught! Using default filenames.\n";
01715 }
01716 return 1;
01717 }
01718
01719
01720 int Dumper::selectOptions( const BON::Project& proj)
01721 {
01722 int v1( 0), v2( 0), v3( 0), vp( 1);
01723
01724 try {
01725
01726
01727 if( !Options::fetchOpts( proj, &v1, &v2, &v3, &vp)) return 1;
01728
01729 global_vars.genConstr.reg_cont_mask = v1;
01730 global_vars.genConstr.fol_cont_mask = v2;
01731 global_vars.genConstr.connect_mask = v3;
01732 global_vars.genConstr.priority = vp;
01733
01734 } catch(...) {
01735 global_vars.err << MSG_ERROR << "[MetaInterpreter] Option load did not succeed.";
01736 }
01737
01738 if( global_vars.silent_mode)
01739 {
01740 return 1;
01741 }
01742 else
01743 {
01744 Options dlg;
01745 dlg.setDefs( v1, v2, v3, vp);
01746 int v = dlg.DoModal();
01747 if( v == IDOK)
01748 {
01749 bool dont_ask = false;
01750 dlg.getResults( &v1, &v2, &v3, &vp, &dont_ask);
01751
01752 global_vars.genConstr.reg_cont_mask = v1;
01753 global_vars.genConstr.fol_cont_mask = v2;
01754 global_vars.genConstr.connect_mask = v3;
01755 global_vars.genConstr.priority = vp;
01756
01757
01758 try {
01759 Options::saveOpts( proj, v1, v2, v3, vp, dont_ask);
01760 } catch(...) {
01761 global_vars.err << MSG_ERROR << "[MetaInterpreter] Option saving did not succeed.";
01762 }
01763 }
01764
01765 return (v == IDOK)?1:2;
01766 }
01767 }
01768
01769
01770
01771 void Dumper::registerIt( const std::string& f_name)
01772 {
01773 int res = IDYES;
01774
01775 if( global_vars.silent_mode)
01776 TO( "Successfully generated " + CString(f_name.c_str()));
01777 else
01778 res = AfxMessageBox( "Successfully generated " + CString(f_name.c_str()) + "\n\nWould you like to register your new paradigm ?", MB_YESNO | MB_ICONINFORMATION);
01779
01780 if ( res == IDYES)
01781 {
01782 CWaitCursor wait;
01783 CComPtr<IMgaRegistrar> registrar;
01784 HRESULT hr = registrar.CoCreateInstance(L"MGA.MgaRegistrar");
01785 if (SUCCEEDED(hr)) {
01786 CComBSTR path = CString("XML=") + f_name.c_str();
01787 hr = registrar->RegisterParadigmFromData(path, NULL, REGACCESS_USER);
01788 }
01789 if (FAILED(hr)) {
01790 _bstr_t error;
01791 CComQIPtr<ISupportErrorInfo> supperr = registrar;
01792 if (supperr) {
01793 CComPtr<IErrorInfo> errorInfo;
01794 if (SUCCEEDED(GetErrorInfo(0, &errorInfo))) {
01795 errorInfo->GetDescription(error.GetAddress());
01796 error = L"Error occurred while registering new paradigm: " + error;
01797 }
01798 }
01799 if (error == _bstr_t()) {
01800 error = L"Error occurred while registering new paradigm.";
01801 }
01802 if( global_vars.silent_mode)
01803 TO(error);
01804 else
01805 AfxMessageBox(error, MB_ICONSTOP | MB_OK);
01806 }
01807 }
01808 }
01809
01810
01811 std::string Dumper::xmlFilter( const std::string& in)
01812 {
01813 std::map<char, std::string> m;
01814 m['&'] = "&";
01815 m['>'] = ">";
01816 m['<'] = "<";
01817 m['"'] = """;
01818 m['\''] = "'";
01819
01820 std::string ret;
01821 for( std::string::const_iterator i = in.begin(); i != in.end(); ++i)
01822 if ( m.find( *i) != m.end())
01823 ret += m[*i];
01824 else
01825 ret += *i;
01826
01827 return ret;
01828 }