umbrello API Documentation

model_utils.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  *  copyright (C) 2004-2006                                                *
00009  *  Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                   *
00010  ***************************************************************************/
00011 
00012 // own header
00013 #include "model_utils.h"
00014 
00015 // qt/kde includes
00016 #include <qregexp.h>
00017 #include <qstringlist.h>
00018 #include <klocale.h>
00019 #include <kdebug.h>
00020 #include <kinputdialog.h>
00021 
00022 // app includes
00023 #include "umlobject.h"
00024 #include "umlpackagelist.h"
00025 #include "package.h"
00026 #include "folder.h"
00027 #include "classifier.h"
00028 #include "enum.h"
00029 #include "entity.h"
00030 #include "template.h"
00031 #include "operation.h"
00032 #include "attribute.h"
00033 #include "association.h"
00034 #include "umlrole.h"
00035 #include "umldoc.h"
00036 #include "uml.h"
00037 #include "codegenerator.h"
00038 
00039 namespace Model_Utils {
00040 
00041 bool isCloneable(Uml::Widget_Type type) {
00042     switch (type) {
00043     case Uml::wt_Actor:
00044     case Uml::wt_UseCase:
00045     case Uml::wt_Class:
00046     case Uml::wt_Interface:
00047     case Uml::wt_Enum:
00048     case Uml::wt_Datatype:
00049     case Uml::wt_Package:
00050     case Uml::wt_Component:
00051     case Uml::wt_Node:
00052     case Uml::wt_Artifact:
00053         return true;
00054     default:
00055         return false;
00056     }
00057 }
00058 
00059 UMLObject * findObjectInList(Uml::IDType id, const UMLObjectList& inList) {
00060     for (UMLObjectListIt oit(inList); oit.current(); ++oit) {
00061         UMLObject *obj = oit.current();
00062         if (obj->getID() == id)
00063             return obj;
00064         UMLObject *o;
00065         Uml::Object_Type t = obj->getBaseType();
00066         switch (t) {
00067         case Uml::ot_Folder:
00068         case Uml::ot_Package:
00069         case Uml::ot_Component:
00070             o = static_cast<UMLPackage*>(obj)->findObjectById(id);
00071             if (o)
00072                 return o;
00073             break;
00074         case Uml::ot_Interface:
00075         case Uml::ot_Class:
00076         case Uml::ot_Enum:
00077         case Uml::ot_Entity:
00078             o = static_cast<UMLClassifier*>(obj)->findChildObjectById(id);
00079             if (o == NULL &&
00080                     (t == Uml::ot_Interface || t == Uml::ot_Class))
00081                 o = ((UMLPackage*)obj)->findObjectById(id);
00082             if (o)
00083                 return o;
00084             break;
00085         case Uml::ot_Association:
00086             {
00087                 UMLAssociation *assoc = static_cast<UMLAssociation*>(obj);
00088                 UMLRole *rA = assoc->getUMLRole(Uml::A);
00089                 if (rA->getID() == id)
00090                     return rA;
00091                 UMLRole *rB = assoc->getUMLRole(Uml::B);
00092                 if (rB->getID() == id)
00093                     return rB;
00094             }
00095             break;
00096         default:
00097             break;
00098         }
00099     }
00100     return NULL;
00101 }
00102 
00103 UMLObject* findUMLObject(const UMLObjectList& inList,
00104                          const QString& inName,
00105                          Uml::Object_Type type /* = ot_UMLObject */,
00106                          UMLObject *currentObj /* = NULL */) {
00107     const bool caseSensitive = UMLApp::app()->activeLanguageIsCaseSensitive();
00108     QString name = inName;
00109     QStringList components;
00110 #ifdef TRY_BUGFIX_120682
00111     // If we have a pointer or a reference in cpp we need to remove
00112     // the asterisks and ampersands in order to find the appropriate object
00113     if (UMLApp::app()->getActiveLanguage() == Uml::pl_Cpp) {
00114         if (name.endsWith("*"))
00115             name.remove("*");
00116         else if (name.contains("&"))
00117             name.remove("&");
00118     }
00119 #endif
00120     QString nameWithoutFirstPrefix;
00121     if (name.contains("::"))
00122         components = QStringList::split("::", name);
00123     else if (name.contains("."))
00124         components = QStringList::split(".", name);
00125     if (components.size() > 1) {
00126         name = components.front();
00127         components.pop_front();
00128         nameWithoutFirstPrefix = components.join("::");
00129     }
00130     if (currentObj) {
00131         UMLPackage *pkg = NULL;
00132         if (dynamic_cast<UMLClassifierListItem*>(currentObj)) {
00133             currentObj = static_cast<UMLObject*>(currentObj->parent());
00134         }
00135         pkg = dynamic_cast<UMLPackage*>(currentObj);
00136         if (pkg == NULL)
00137             pkg = currentObj->getUMLPackage();
00138         // Remember packages that we've seen - for avoiding cycles.
00139         UMLPackageList seenPkgs;
00140         for (; pkg; pkg = currentObj->getUMLPackage()) {
00141             if (nameWithoutFirstPrefix.isEmpty()) {
00142                 if (caseSensitive) {
00143                     if (pkg->getName() == name)
00144                         return pkg;
00145                 } else if (pkg->getName().lower() == name.lower()) {
00146                     return pkg;
00147                 }
00148             }
00149             if (seenPkgs.findRef(pkg) != -1) {
00150                 kError() << "findUMLObject(" << name << "): "
00151                     << "breaking out of cycle involving "
00152                     << pkg->getName() << endl;
00153                 break;
00154             }
00155             seenPkgs.append(pkg);
00156             UMLObjectList objectsInCurrentScope = pkg->containedObjects();
00157             for (UMLObjectListIt oit(objectsInCurrentScope); oit.current(); ++oit) {
00158                 UMLObject *obj = oit.current();
00159                 if (caseSensitive) {
00160                     if (obj->getName() != name)
00161                         continue;
00162                 } else if (obj->getName().lower() != name.lower()) {
00163                     continue;
00164                 }
00165                 Uml::Object_Type foundType = obj->getBaseType();
00166                 if (nameWithoutFirstPrefix.isEmpty()) {
00167                     if (type != Uml::ot_UMLObject && type != foundType) {
00168                         kDebug() << "findUMLObject: type mismatch for "
00169                             << name << " (seeking type: "
00170                             << type << ", found type: "
00171                             << foundType << ")" << endl;
00172                         // Class, Interface, and Datatype are all Classifiers
00173                         // and are considered equivalent.
00174                         // The caller must be prepared to handle possible mismatches.
00175                         if ((type == Uml::ot_Class ||
00176                              type == Uml::ot_Interface ||
00177                              type == Uml::ot_Datatype) &&
00178                             (foundType == Uml::ot_Class ||
00179                              foundType == Uml::ot_Interface ||
00180                              foundType == Uml::ot_Datatype)) {
00181                             return obj;
00182                         }
00183                         continue;
00184                     }
00185                     return obj;
00186                 }
00187                 if (foundType != Uml::ot_Package &&
00188                     foundType != Uml::ot_Folder &&
00189                     foundType != Uml::ot_Class &&
00190                     foundType != Uml::ot_Interface &&
00191                     foundType != Uml::ot_Component) {
00192                     kDebug() << "findUMLObject: found \"" << name
00193                         << "\" is not a package (?)" << endl;
00194                     continue;
00195                 }
00196                 UMLPackage *pkg = static_cast<UMLPackage*>(obj);
00197                 return findUMLObject( pkg->containedObjects(),
00198                                       nameWithoutFirstPrefix, type );
00199             }
00200             currentObj = pkg;
00201         }
00202     }
00203     for (UMLObjectListIt oit(inList); oit.current(); ++oit) {
00204         UMLObject *obj = oit.current();
00205         if (caseSensitive) {
00206             if (obj->getName() != name)
00207                 continue;
00208         } else if (obj->getName().lower() != name.lower()) {
00209             continue;
00210         }
00211         Uml::Object_Type foundType = obj->getBaseType();
00212         if (nameWithoutFirstPrefix.isEmpty()) {
00213             if (type != Uml::ot_UMLObject && type != foundType) {
00214                 kDebug() << "findUMLObject: type mismatch for "
00215                     << name << " (seeking type: "
00216                     << type << ", found type: "
00217                     << foundType << ")" << endl;
00218                 continue;
00219             }
00220             return obj;
00221         }
00222         if (foundType != Uml::ot_Package &&
00223             foundType != Uml::ot_Folder &&
00224             foundType != Uml::ot_Class &&
00225             foundType != Uml::ot_Interface &&
00226             foundType != Uml::ot_Component) {
00227             kDebug() << "findUMLObject: found \"" << name
00228                 << "\" is not a package (?)" << endl;
00229             continue;
00230         }
00231         UMLPackage *pkg = static_cast<UMLPackage*>(obj);
00232         return findUMLObject( pkg->containedObjects(),
00233                               nameWithoutFirstPrefix, type );
00234     }
00235     return NULL;
00236 }
00237 
00238 QString uniqObjectName(Uml::Object_Type type, UMLPackage *parentPkg, QString prefix) {
00239     QString currentName = prefix;
00240     if (currentName.isEmpty()) {
00241         if(type == Uml::ot_Class)
00242             currentName = i18n("new_class");
00243         else if(type == Uml::ot_Actor)
00244             currentName = i18n("new_actor");
00245         else if(type == Uml::ot_UseCase)
00246             currentName = i18n("new_usecase");
00247         else if(type == Uml::ot_Package)
00248             currentName = i18n("new_package");
00249         else if(type == Uml::ot_Component)
00250             currentName = i18n("new_component");
00251         else if(type == Uml::ot_Node)
00252             currentName = i18n("new_node");
00253         else if(type == Uml::ot_Artifact)
00254             currentName = i18n("new_artifact");
00255         else if(type == Uml::ot_Interface)
00256             currentName = i18n("new_interface");
00257         else if(type == Uml::ot_Datatype)
00258             currentName = i18n("new_datatype");
00259         else if(type == Uml::ot_Enum)
00260             currentName = i18n("new_enum");
00261         else if(type == Uml::ot_Entity)
00262             currentName = i18n("new_entity");
00263         else if(type == Uml::ot_Folder)
00264             currentName = i18n("new_folder");
00265         else if(type == Uml::ot_Association)
00266             currentName = i18n("new_association");
00267         else {
00268             currentName = i18n("new_object");
00269             kWarning() << "unknown object type in umldoc::uniqObjectName()" << endl;
00270         }
00271     }
00272     UMLDoc *doc = UMLApp::app()->getDocument();
00273     QString name = currentName;
00274     for (int number = 1; !doc->isUnique(name, parentPkg); number++)  {
00275         name = currentName + '_' + QString::number(number);
00276     }
00277     return name;
00278 }
00279 
00280 bool isCommonXMIAttribute( const QString &tag ) {
00281     bool retval = (Uml::tagEq(tag, "name") ||
00282                    Uml::tagEq(tag, "visibility") ||
00283                    Uml::tagEq(tag, "isRoot") ||
00284                    Uml::tagEq(tag, "isLeaf") ||
00285                    Uml::tagEq(tag, "isAbstract") ||
00286                    Uml::tagEq(tag, "isSpecification") ||
00287                    Uml::tagEq(tag, "isActive") ||
00288                    Uml::tagEq(tag, "namespace") ||
00289                    Uml::tagEq(tag, "ownerScope") ||
00290                    Uml::tagEq(tag, "GeneralizableElement.generalization") ||
00291                    Uml::tagEq(tag, "specialization") ||   //NYI
00292                    Uml::tagEq(tag, "clientDependency") || //NYI
00293                    Uml::tagEq(tag, "supplierDependency")  //NYI
00294                   );
00295     return retval;
00296 }
00297 
00298 bool isCommonDataType(QString type) {
00299     CodeGenerator *gen = UMLApp::app()->getGenerator();
00300     if (gen == NULL)
00301         return false;
00302     const bool caseSensitive = UMLApp::app()->activeLanguageIsCaseSensitive();
00303     QStringList dataTypes = gen->defaultDatatypes();
00304     QStringList::Iterator end(dataTypes.end());
00305     for (QStringList::Iterator it = dataTypes.begin(); it != end; ++it) {
00306         if (caseSensitive) {
00307             if (type == *it)
00308                 return true;
00309         } else if (type.lower() == (*it).lower()) {
00310             return true;
00311         }
00312     }
00313     return false;
00314 }
00315 
00316 bool isClassifierListitem(Uml::Object_Type type) {
00317     if (type == Uml::ot_Attribute ||
00318         type == Uml::ot_Operation ||
00319         type == Uml::ot_Template ||
00320         type == Uml::ot_EntityAttribute ||
00321         type == Uml::ot_EnumLiteral) {
00322         return true;
00323     } else {
00324         return false;
00325     }
00326 }
00327 
00328 Uml::Model_Type guessContainer(UMLObject *o) {
00329     Uml::Object_Type ot = o->getBaseType();
00330     if (ot == Uml::ot_Package && o->getStereotype() == "subsystem")
00331         return Uml::mt_Component;
00332     Uml::Model_Type mt = Uml::N_MODELTYPES;
00333     switch (ot) {
00334         case Uml::ot_Package:   // CHECK: packages may appear in other views?
00335         case Uml::ot_Interface:
00336         case Uml::ot_Datatype:
00337         case Uml::ot_Enum:
00338         case Uml::ot_Class:
00339         case Uml::ot_Attribute:
00340         case Uml::ot_Operation:
00341         case Uml::ot_EnumLiteral:
00342         case Uml::ot_Template:
00343             mt = Uml::mt_Logical;
00344             break;
00345         case Uml::ot_Actor:
00346         case Uml::ot_UseCase:
00347             mt = Uml::mt_UseCase;
00348             break;
00349         case Uml::ot_Component:
00350         case Uml::ot_Artifact:  // trouble: artifact can also appear at Deployment
00351             mt = Uml::mt_Component;
00352             break;
00353         case Uml::ot_Node:
00354             mt = Uml::mt_Deployment;
00355             break;
00356         case Uml::ot_Entity:
00357         case Uml::ot_EntityAttribute:
00358             mt = Uml::mt_EntityRelationship;
00359             break;
00360         case Uml::ot_Association:
00361             {
00362                 UMLAssociation *assoc = static_cast<UMLAssociation*>(o);
00363                 UMLDoc *umldoc = UMLApp::app()->getDocument();
00364                 for (int r = Uml::A; r <= Uml::B; r++) {
00365                     UMLObject *roleObj = assoc->getObject((Uml::Role_Type)r);
00366                     if (roleObj == NULL) {
00367                         // Ouch! we have been called while types are not yet resolved
00368                         return Uml::N_MODELTYPES;
00369                     }
00370                     UMLPackage *pkg = roleObj->getUMLPackage();
00371                     if (pkg) {
00372                         while (pkg->getUMLPackage()) {  // wind back to root
00373                             pkg = pkg->getUMLPackage();
00374                         }
00375                         const Uml::Model_Type m = umldoc->rootFolderType(pkg);
00376                         if (m != Uml::N_MODELTYPES)
00377                             return m;
00378                     }
00379                     mt = guessContainer(roleObj);
00380                     if (mt != Uml::mt_Logical)
00381                         break;
00382                 }
00383             }
00384             break;
00385         default:
00386             break;
00387     }
00388     return mt;
00389 }
00390 
00391 int stringToDirection(QString input, Uml::Parameter_Direction & result) {
00392     QRegExp dirx("^(in|out|inout)");
00393     int pos = dirx.search(input);
00394     if (pos == -1)
00395         return 0;
00396     const QString& dirStr = dirx.capturedTexts().first();
00397     uint dirLen = dirStr.length();
00398     if (input.length() > dirLen && !input[dirLen].isSpace())
00399         return 0;       // no match after all.
00400     if (dirStr == "out")
00401         result = Uml::pd_Out;
00402     else if (dirStr == "inout")
00403         result = Uml::pd_InOut;
00404     else
00405         result = Uml::pd_In;
00406     return dirLen;
00407 }
00408 
00409 Parse_Status parseTemplate(QString t, NameAndType& nmTp, UMLClassifier *owningScope) {
00410 
00411     UMLDoc *pDoc = UMLApp::app()->getDocument();
00412 
00413     t = t.stripWhiteSpace();
00414     if (t.isEmpty())
00415         return PS_Empty;
00416 
00417     QStringList nameAndType = QStringList::split( QRegExp("\\s*:\\s*"), t);
00418     if (nameAndType.count() == 2) {
00419         UMLObject *pType = NULL;
00420         if (nameAndType[1] != "class") {
00421             pType = pDoc->findUMLObject(nameAndType[1], Uml::ot_UMLObject, owningScope);
00422             if (pType == NULL)
00423                 return PS_Unknown_ArgType;
00424         }
00425         nmTp = NameAndType(nameAndType[0], pType);
00426     } else {
00427         nmTp = NameAndType(t, NULL);
00428     }
00429     return PS_OK;
00430 }
00431 
00432 Parse_Status parseAttribute(QString a, NameAndType& nmTp, UMLClassifier *owningScope,
00433                             Uml::Visibility *vis /* = 0 */) {
00434     UMLDoc *pDoc = UMLApp::app()->getDocument();
00435 
00436     a = a.simplifyWhiteSpace();
00437     if (a.isEmpty())
00438         return PS_Empty;
00439 
00440     int colonPos = a.find(':');
00441     if (colonPos < 0) {
00442         nmTp = NameAndType(a, NULL);
00443         return PS_OK;
00444     }
00445     QString name = a.left(colonPos).stripWhiteSpace();
00446     if (vis) {
00447         QRegExp mnemonicVis("^([\\+\\#\\-\\~] *)");
00448         int pos = mnemonicVis.search(name);
00449         if (pos == -1) {
00450             *vis = Uml::Visibility::Private;  // default value
00451         } else {
00452             QString caption = mnemonicVis.cap(1);
00453             QString strVis = caption.left(1);
00454             if (strVis == "+")
00455                 *vis = Uml::Visibility::Public;
00456             else if (strVis == "#")
00457                 *vis = Uml::Visibility::Protected;
00458             else if (strVis == "-")
00459                 *vis = Uml::Visibility::Private;
00460             else
00461                 *vis = Uml::Visibility::Implementation;
00462         }
00463         name.remove(mnemonicVis);
00464     }
00465     Uml::Parameter_Direction pd = Uml::pd_In;
00466     if (name.startsWith("in ")) {
00467         pd = Uml::pd_In;
00468         name = name.mid(3);
00469     } else if (name.startsWith("inout ")) {
00470         pd = Uml::pd_InOut;
00471         name = name.mid(6);
00472     } else if (name.startsWith("out ")) {
00473         pd = Uml::pd_Out;
00474         name = name.mid(4);
00475     }
00476     a = a.mid(colonPos + 1).stripWhiteSpace();
00477     if (a.isEmpty()) {
00478         nmTp = NameAndType(name, NULL, pd);
00479         return PS_OK;
00480     }
00481     QStringList typeAndInitialValue = QStringList::split( QRegExp("\\s*=\\s*"), a );
00482     const QString &type = typeAndInitialValue[0];
00483     UMLObject *pType = pDoc->findUMLObject(type, Uml::ot_UMLObject, owningScope);
00484     if (pType == NULL) {
00485         nmTp = NameAndType(name, NULL, pd);
00486         return PS_Unknown_ArgType;
00487     }
00488     QString initialValue;
00489     if (typeAndInitialValue.count() == 2) {
00490         initialValue = typeAndInitialValue[1];
00491     }
00492     nmTp = NameAndType(name, pType, pd, initialValue);
00493     return PS_OK;
00494 }
00495 
00496 Parse_Status parseOperation(QString m, OpDescriptor& desc, UMLClassifier *owningScope) {
00497     UMLDoc *pDoc = UMLApp::app()->getDocument();
00498 
00499     m = m.simplifyWhiteSpace();
00500     if (m.isEmpty())
00501         return PS_Empty;
00502     if (m.contains(QRegExp("operator *()"))) {
00503         // C++ special case: two sets of parentheses
00504         desc.m_name = "operator()";
00505         m.remove(QRegExp("operator *()"));
00506     } else {
00512         QRegExp beginningUpToOpenParenth( "^([^\\(]+)" );
00513         int pos = beginningUpToOpenParenth.search(m);
00514         if (pos == -1)
00515             return PS_Illegal_MethodName;
00516         desc.m_name = beginningUpToOpenParenth.cap(1);
00517     }
00518     desc.m_pReturnType = NULL;
00519     QRegExp pat = QRegExp("\\) *:(.*)$");
00520     int pos = pat.search(m);
00521     if (pos != -1) {  // return type is optional
00522         QString retType = pat.cap(1);
00523         retType = retType.stripWhiteSpace();
00524         if (retType != "void") {
00525             UMLObject *pRetType = owningScope->findTemplate(retType);
00526             if (pRetType == NULL) {
00527                 pRetType = pDoc->findUMLObject(retType, Uml::ot_UMLObject, owningScope);
00528                 if (pRetType == NULL)
00529                     return PS_Unknown_ReturnType;
00530             }
00531             desc.m_pReturnType = pRetType;
00532         }
00533     }
00534     // Remove possible empty parentheses ()
00535     m.remove( QRegExp("\\s*\\(\\s*\\)") );
00536     desc.m_args.clear();
00537     pat = QRegExp( "\\((.*)\\)" );
00538     pos = pat.search(m);
00539     if (pos == -1)  // argument list is optional
00540         return PS_OK;
00541     QString arglist = pat.cap(1);
00542     arglist = arglist.stripWhiteSpace();
00543     if (arglist.isEmpty())
00544         return PS_OK;
00545     QStringList args = QStringList::split( QRegExp("\\s*,\\s*"), arglist);
00546     for (QStringList::Iterator lit = args.begin(); lit != args.end(); ++lit) {
00547         NameAndType nmTp;
00548         Parse_Status ps = parseAttribute(*lit, nmTp, owningScope);
00549         if (ps)
00550             return ps;
00551         desc.m_args.append(nmTp);
00552     }
00553     return PS_OK;
00554 }
00555 
00556 QString psText(Parse_Status value) {
00557     const QString text[] = {
00558                                i18n("OK"), i18n("Empty"), i18n("Malformed argument"),
00559                                i18n("Unknown argument type"), i18n("Illegal method name"),
00560                                i18n("Unknown return type"), i18n("Unspecified error")
00561                            };
00562     return text[(unsigned) value];
00563 }
00564 
00565 QString progLangToString(Uml::Programming_Language pl) {
00566     switch (pl) {
00567         case Uml::pl_ActionScript:
00568             return "ActionScript";
00569         case Uml::pl_Ada:
00570             return "Ada";
00571         case Uml::pl_Cpp:
00572             return "C++";
00573         case Uml::pl_CSharp:
00574             return "C#";
00575         case Uml::pl_D:
00576             return "D";
00577         case Uml::pl_IDL:
00578             return "IDL";
00579         case Uml::pl_Java:
00580             return "Java";
00581         case Uml::pl_JavaScript:
00582             return "JavaScript";
00583         case Uml::pl_Pascal:
00584             return "Pascal";
00585         case Uml::pl_Perl:
00586             return "Perl";
00587         case Uml::pl_PHP:
00588             return "PHP";
00589         case Uml::pl_PHP5:
00590             return "PHP5";
00591         case Uml::pl_Python:
00592             return "Python";
00593         case Uml::pl_Ruby:
00594             return "Ruby";
00595         case Uml::pl_SQL:
00596             return "SQL";
00597         case Uml::pl_Tcl:
00598             return "Tcl";
00599         case Uml::pl_XMLSchema:
00600             return "XMLSchema";
00601         default:
00602             break;
00603     }
00604     return QString::null;
00605 }
00606 
00607 Uml::Programming_Language stringToProgLang(QString str) {
00608     if (str == "ActionScript")
00609         return Uml::pl_ActionScript;
00610     if (str == "Ada")
00611         return Uml::pl_Ada;
00612     if (str == "C++" || str == "Cpp")  // "Cpp" only for bkwd compatibility
00613         return Uml::pl_Cpp;
00614     if (str == "C#")
00615         return Uml::pl_CSharp;
00616     if (str == "IDL")
00617         return Uml::pl_IDL;
00618     if (str == "Java")
00619         return Uml::pl_Java;
00620     if (str == "JavaScript")
00621         return Uml::pl_JavaScript;
00622     if (str == "Pascal")
00623         return Uml::pl_Pascal;
00624     if (str == "Perl")
00625         return Uml::pl_Perl;
00626     if (str == "PHP")
00627         return Uml::pl_PHP;
00628     if (str == "PHP5")
00629         return Uml::pl_PHP5;
00630     if (str == "Python")
00631         return Uml::pl_Python;
00632     if (str == "Ruby")
00633         return Uml::pl_Ruby;
00634     if (str == "SQL")
00635         return Uml::pl_SQL;
00636     if (str == "Tcl")
00637         return Uml::pl_Tcl;
00638     if (str == "XMLSchema")
00639         return Uml::pl_XMLSchema;
00640     return Uml::pl_Reserved;
00641 }
00642 
00643 bool typeIsRootView(Uml::ListView_Type type) {
00644     switch (type) {
00645         case Uml::lvt_View:
00646         case Uml::lvt_Logical_View:
00647         case Uml::lvt_UseCase_View:
00648         case Uml::lvt_Component_View:
00649         case Uml::lvt_Deployment_View:
00650         case Uml::lvt_EntityRelationship_Model:
00651             return true;
00652             break;
00653         default:
00654             break;
00655     }
00656     return false;
00657 }
00658 
00659 bool typeIsCanvasWidget(Uml::ListView_Type type) {
00660     switch (type) {
00661         case Uml::lvt_Actor:
00662         case Uml::lvt_UseCase:
00663         case Uml::lvt_Class:
00664         case Uml::lvt_Package:
00665         case Uml::lvt_Logical_Folder:
00666         case Uml::lvt_UseCase_Folder:
00667         case Uml::lvt_Component_Folder:
00668         case Uml::lvt_Deployment_Folder:
00669         case Uml::lvt_EntityRelationship_Folder:
00670         case Uml::lvt_Subsystem:
00671         case Uml::lvt_Component:
00672         case Uml::lvt_Node:
00673         case Uml::lvt_Artifact:
00674         case Uml::lvt_Interface:
00675         case Uml::lvt_Datatype:
00676         case Uml::lvt_Enum:
00677         case Uml::lvt_Entity:
00678             return true;
00679             break;
00680         default:
00681             break;
00682     }
00683     return false;
00684 }
00685 
00686 bool typeIsFolder(Uml::ListView_Type type) {
00687     if (typeIsRootView(type) ||
00688             type == Uml::lvt_Datatype_Folder ||
00689             type == Uml::lvt_Logical_Folder ||
00690             type == Uml::lvt_UseCase_Folder ||
00691             type == Uml::lvt_Component_Folder ||
00692             type == Uml::lvt_Deployment_Folder ||
00693             type == Uml::lvt_EntityRelationship_Folder) {
00694         return true;
00695     } else {
00696         return false;
00697     }
00698 }
00699 
00700 bool typeIsContainer(Uml::ListView_Type type) {
00701     if (typeIsFolder(type))
00702         return true;
00703     return (type == Uml::lvt_Package ||
00704             type == Uml::lvt_Subsystem ||
00705             type == Uml::lvt_Component);
00706 }
00707 
00708 bool typeIsClassifierList(Uml::ListView_Type type) {
00709     if (type == Uml::lvt_Attribute ||
00710         type == Uml::lvt_Operation ||
00711         type == Uml::lvt_Template ||
00712         type == Uml::lvt_EntityAttribute ||
00713         type == Uml::lvt_EnumLiteral) {
00714         return true;
00715     } else {
00716         return false;
00717     }
00718 }
00719 
00720 bool typeIsDiagram(Uml::ListView_Type type) {
00721     if (type == Uml::lvt_Class_Diagram ||
00722             type == Uml::lvt_Collaboration_Diagram ||
00723             type == Uml::lvt_State_Diagram ||
00724             type == Uml::lvt_Activity_Diagram ||
00725             type == Uml::lvt_Sequence_Diagram ||
00726             type == Uml::lvt_UseCase_Diagram ||
00727             type == Uml::lvt_Component_Diagram ||
00728             type == Uml::lvt_Deployment_Diagram ||
00729             type == Uml::lvt_EntityRelationship_Diagram) {
00730         return true;
00731     } else {
00732         return false;
00733     }
00734 }
00735 
00736 Uml::Model_Type convert_DT_MT(Uml::Diagram_Type dt) {
00737     Uml::Model_Type mt;
00738     switch (dt) {
00739         case Uml::dt_UseCase:
00740             mt = Uml::mt_UseCase;
00741             break;
00742         case Uml::dt_Collaboration:
00743         case Uml::dt_Class:
00744         case Uml::dt_Sequence:
00745         case Uml::dt_State:
00746         case Uml::dt_Activity:
00747             mt = Uml::mt_Logical;
00748             break;
00749         case Uml::dt_Component:
00750             mt = Uml::mt_Component;
00751             break;
00752         case Uml::dt_Deployment:
00753             mt = Uml::mt_Deployment;
00754             break;
00755         case Uml::dt_EntityRelationship:
00756             mt = Uml::mt_EntityRelationship;
00757             break;
00758         default:
00759             kError() << "Model_Utils::convert_DT_MT: illegal input value " << dt << endl;
00760             mt = Uml::N_MODELTYPES;
00761             break;
00762     }
00763     return mt;
00764 }
00765 
00766 Uml::ListView_Type convert_MT_LVT(Uml::Model_Type mt) {
00767     Uml::ListView_Type lvt = Uml::lvt_Unknown;
00768     switch (mt) {
00769         case Uml::mt_Logical:
00770             lvt = Uml::lvt_Logical_View;
00771             break;
00772         case Uml::mt_UseCase:
00773             lvt = Uml::lvt_UseCase_View;
00774             break;
00775         case Uml::mt_Component:
00776             lvt = Uml::lvt_Component_View;
00777             break;
00778         case Uml::mt_Deployment:
00779             lvt = Uml::lvt_Deployment_View;
00780             break;
00781         case Uml::mt_EntityRelationship:
00782             lvt = Uml::lvt_EntityRelationship_Model;
00783             break;
00784         default:
00785             break;
00786     }
00787     return lvt;
00788 }
00789 
00790 Uml::Model_Type convert_LVT_MT(Uml::ListView_Type lvt) {
00791     Uml::Model_Type mt = Uml::N_MODELTYPES;
00792     switch (lvt) {
00793         case Uml::lvt_Logical_View:
00794             mt = Uml::mt_Logical;
00795             break;
00796         case Uml::lvt_UseCase_View:
00797             mt = Uml::mt_UseCase;
00798             break;
00799         case Uml::lvt_Component_View:
00800             mt = Uml::mt_Component;
00801             break;
00802         case Uml::lvt_Deployment_View:
00803             mt = Uml::mt_Deployment;
00804             break;
00805         case Uml::lvt_EntityRelationship_Model:
00806             mt = Uml::mt_EntityRelationship;
00807             break;
00808         default:
00809             break;
00810     }
00811     return mt;
00812 }
00813 
00814 Uml::ListView_Type convert_DT_LVT(Uml::Diagram_Type dt) {
00815     Uml::ListView_Type type =  Uml::lvt_Unknown;
00816     switch(dt) {
00817     case Uml::dt_UseCase:
00818         type = Uml::lvt_UseCase_Diagram;
00819         break;
00820 
00821     case Uml::dt_Class:
00822         type = Uml::lvt_Class_Diagram;
00823         break;
00824 
00825     case Uml::dt_Sequence:
00826         type = Uml::lvt_Sequence_Diagram;
00827         break;
00828 
00829     case Uml::dt_Collaboration:
00830         type = Uml::lvt_Collaboration_Diagram;
00831         break;
00832 
00833     case Uml::dt_State:
00834         type = Uml::lvt_State_Diagram;
00835         break;
00836 
00837     case Uml::dt_Activity:
00838         type = Uml::lvt_Activity_Diagram;
00839         break;
00840 
00841     case Uml::dt_Component:
00842         type = Uml::lvt_Component_Diagram;
00843         break;
00844 
00845     case Uml::dt_Deployment:
00846         type = Uml::lvt_Deployment_Diagram;
00847         break;
00848 
00849     case Uml::dt_EntityRelationship:
00850         type = Uml::lvt_EntityRelationship_Diagram;
00851         break;
00852 
00853     default:
00854         kWarning() << "convert_DT_LVT() called on unknown diagram type" << endl;
00855     }
00856     return type;
00857 }
00858 
00859 Uml::ListView_Type convert_OT_LVT(UMLObject *o) {
00860     Uml::Object_Type ot = o->getBaseType();
00861     Uml::ListView_Type type =  Uml::lvt_Unknown;
00862     switch(ot) {
00863     case Uml::ot_UseCase:
00864         type = Uml::lvt_UseCase;
00865         break;
00866 
00867     case Uml::ot_Actor:
00868         type = Uml::lvt_Actor;
00869         break;
00870 
00871     case Uml::ot_Class:
00872         type = Uml::lvt_Class;
00873         break;
00874 
00875     case Uml::ot_Package:
00876         type = Uml::lvt_Package;
00877         break;
00878 
00879     case Uml::ot_Folder:
00880         {
00881             UMLDoc *umldoc = UMLApp::app()->getDocument();
00882             UMLFolder *f = static_cast<UMLFolder*>(o);
00883             do {
00884                 const Uml::Model_Type mt = umldoc->rootFolderType(f);
00885                 if (mt != Uml::N_MODELTYPES) {
00886                     switch (mt) {
00887                         case Uml::mt_Logical:
00888                             type = Uml::lvt_Logical_Folder;
00889                             break;
00890                         case Uml::mt_UseCase:
00891                             type = Uml::lvt_UseCase_Folder;
00892                             break;
00893                         case Uml::mt_Component:
00894                             type = Uml::lvt_Component_Folder;
00895                             break;
00896                         case Uml::mt_Deployment:
00897                             type = Uml::lvt_Deployment_Folder;
00898                             break;
00899                         case Uml::mt_EntityRelationship:
00900                             type = Uml::lvt_EntityRelationship_Folder;
00901                             break;
00902                         default:
00903                             break;
00904                     }
00905                     return type;
00906                 }
00907             } while ((f = static_cast<UMLFolder*>(f->getUMLPackage())) != NULL);
00908             kError() << "convert_OT_LVT(" << o->getName()
00909                 << "): internal error - object is not properly nested in folder"
00910                 << endl;
00911         }
00912         break;
00913 
00914     case Uml::ot_Component:
00915         type = Uml::lvt_Component;
00916         break;
00917 
00918     case Uml::ot_Node:
00919         type = Uml::lvt_Node;
00920         break;
00921 
00922     case Uml::ot_Artifact:
00923         type = Uml::lvt_Artifact;
00924         break;
00925 
00926     case Uml::ot_Interface:
00927         type = Uml::lvt_Interface;
00928         break;
00929 
00930     case Uml::ot_Datatype:
00931         type = Uml::lvt_Datatype;
00932         break;
00933 
00934     case Uml::ot_Enum:
00935         type = Uml::lvt_Enum;
00936         break;
00937 
00938     case Uml::ot_EnumLiteral:
00939         type = Uml::lvt_EnumLiteral;
00940         break;
00941 
00942     case Uml::ot_Entity:
00943         type = Uml::lvt_Entity;
00944         break;
00945 
00946     case Uml::ot_EntityAttribute:
00947         type = Uml::lvt_EntityAttribute;
00948         break;
00949 
00950     case Uml::ot_Attribute:
00951         type = Uml::lvt_Attribute;
00952         break;
00953 
00954     case Uml::ot_Operation:
00955         type = Uml::lvt_Operation;
00956         break;
00957 
00958     case Uml::ot_Template:
00959         type = Uml::lvt_Template;
00960         break;
00961     default:
00962         break;
00963     }
00964     return type;
00965 }
00966 
00967 Uml::Object_Type convert_LVT_OT(Uml::ListView_Type lvt) {
00968     Uml::Object_Type ot = (Uml::Object_Type)0;
00969     switch (lvt) {
00970     case Uml::lvt_UseCase:
00971         ot = Uml::ot_UseCase;
00972         break;
00973 
00974     case Uml::lvt_Actor:
00975         ot = Uml::ot_Actor;
00976         break;
00977 
00978     case Uml::lvt_Class:
00979         ot = Uml::ot_Class;
00980         break;
00981 
00982     case Uml::lvt_Package:
00983     case Uml::lvt_Subsystem:
00984         ot = Uml::ot_Package;
00985         break;
00986 
00987     case Uml::lvt_Component:
00988         ot = Uml::ot_Component;
00989         break;
00990 
00991     case Uml::lvt_Node:
00992         ot = Uml::ot_Node;
00993         break;
00994 
00995     case Uml::lvt_Artifact:
00996         ot = Uml::ot_Artifact;
00997         break;
00998 
00999     case Uml::lvt_Interface:
01000         ot = Uml::ot_Interface;
01001         break;
01002 
01003     case Uml::lvt_Datatype:
01004         ot = Uml::ot_Datatype;
01005         break;
01006 
01007     case Uml::lvt_Enum:
01008         ot = Uml::ot_Enum;
01009         break;
01010 
01011     case Uml::lvt_Entity:
01012         ot = Uml::ot_Entity;
01013         break;
01014 
01015     case Uml::lvt_EntityAttribute:
01016         ot = Uml::ot_EntityAttribute;
01017         break;
01018 
01019     case Uml::lvt_Attribute:
01020         ot = Uml::ot_Attribute;
01021         break;
01022 
01023     case Uml::lvt_Operation:
01024         ot = Uml::ot_Operation;
01025         break;
01026 
01027     case Uml::lvt_Template:
01028         ot = Uml::ot_Template;
01029         break;
01030 
01031     case Uml::lvt_EnumLiteral:
01032         ot = Uml::ot_EnumLiteral;
01033         break;
01034 
01035     default:
01036         if (typeIsFolder(lvt))
01037             ot = Uml::ot_Folder;
01038         break;
01039     }
01040     return ot;
01041 }
01042 
01043 Uml::Icon_Type convert_LVT_IT(Uml::ListView_Type lvt) {
01044     Uml::Icon_Type icon = Uml::it_Home;
01045     switch (lvt) {
01046         case Uml::lvt_UseCase_View:
01047         case Uml::lvt_UseCase_Folder:
01048             icon = Uml::it_Folder_Grey;
01049             break;
01050         case Uml::lvt_Logical_View:
01051         case Uml::lvt_Logical_Folder:
01052             icon = Uml::it_Folder_Green;
01053             break;
01054         case Uml::lvt_Datatype_Folder:
01055             icon = Uml::it_Folder_Orange;
01056             break;
01057         case Uml::lvt_Component_View:
01058         case Uml::lvt_Component_Folder:
01059             icon = Uml::it_Folder_Red;
01060             break;
01061         case Uml::lvt_Deployment_View:
01062         case Uml::lvt_Deployment_Folder:
01063             icon = Uml::it_Folder_Violet;
01064             break;
01065         case Uml::lvt_EntityRelationship_Model:
01066         case Uml::lvt_EntityRelationship_Folder:
01067             icon = Uml::it_Folder_Cyan;
01068             break;
01069 
01070         case Uml::lvt_Actor:
01071             icon = Uml::it_Actor;
01072             break;
01073         case Uml::lvt_UseCase:
01074             icon = Uml::it_UseCase;
01075             break;
01076         case Uml::lvt_Class:
01077             icon = Uml::it_Class;
01078             break;
01079         case Uml::lvt_Package:
01080             icon = Uml::it_Package;
01081             break;
01082         case Uml::lvt_Subsystem:
01083             icon = Uml::it_Subsystem;
01084             break;
01085         case Uml::lvt_Component:
01086             icon = Uml::it_Component;
01087             break;
01088         case Uml::lvt_Node:
01089             icon = Uml::it_Node;
01090             break;
01091         case Uml::lvt_Artifact:
01092             icon = Uml::it_Artifact;
01093             break;
01094         case Uml::lvt_Interface:
01095             icon = Uml::it_Interface;
01096             break;
01097         case Uml::lvt_Datatype:
01098             icon = Uml::it_Datatype;
01099             break;
01100         case Uml::lvt_Enum:
01101             icon = Uml::it_Enum;
01102             break;
01103         case Uml::lvt_Entity:
01104             icon = Uml::it_Entity;
01105             break;
01106         case Uml::lvt_Template:
01107             icon = Uml::it_Template;
01108             break;
01109         case Uml::lvt_Attribute:
01110             icon = Uml::it_Private_Attribute;
01111             break;
01112         case Uml::lvt_EntityAttribute:
01113             icon = Uml::it_Private_Attribute;
01114             break;
01115         case Uml::lvt_EnumLiteral:
01116             icon = Uml::it_Public_Attribute;
01117             break;
01118         case Uml::lvt_Operation:
01119             icon = Uml::it_Public_Method;
01120             break;
01121 
01122         case Uml::lvt_Class_Diagram:
01123             icon = Uml::it_Diagram_Class;
01124             break;
01125         case Uml::lvt_UseCase_Diagram:
01126             icon = Uml::it_Diagram_Usecase;
01127             break;
01128         case Uml::lvt_Sequence_Diagram:
01129             icon = Uml::it_Diagram_Sequence;
01130             break;
01131         case Uml::lvt_Collaboration_Diagram:
01132             icon = Uml::it_Diagram_Collaboration;
01133             break;
01134         case Uml::lvt_State_Diagram:
01135             icon = Uml::it_Diagram_State;
01136             break;
01137         case Uml::lvt_Activity_Diagram:
01138             icon = Uml::it_Diagram_Activity;
01139             break;
01140         case Uml::lvt_Component_Diagram:
01141             icon = Uml::it_Diagram_Component;
01142             break;
01143         case Uml::lvt_Deployment_Diagram:
01144             icon = Uml::it_Diagram_Deployment;
01145             break;
01146         case Uml::lvt_EntityRelationship_Diagram:
01147             icon = Uml::it_Diagram_EntityRelationship;
01148             break;
01149 
01150         default:
01151             break;
01152     }
01153     return icon;
01154 }
01155 
01156 Uml::Diagram_Type convert_LVT_DT(Uml::ListView_Type lvt) {
01157     Uml::Diagram_Type dt = Uml::dt_Undefined;
01158     switch (lvt) {
01159         case Uml::lvt_Class_Diagram:
01160             dt = Uml::dt_Class;
01161             break;
01162         case Uml::lvt_UseCase_Diagram:
01163             dt = Uml::dt_UseCase;
01164             break;
01165         case Uml::lvt_Sequence_Diagram:
01166             dt = Uml::dt_Sequence;
01167             break;
01168         case Uml::lvt_Collaboration_Diagram:
01169             dt = Uml::dt_Collaboration;
01170             break;
01171         case Uml::lvt_State_Diagram:
01172             dt = Uml::dt_State;
01173             break;
01174         case Uml::lvt_Activity_Diagram:
01175             dt = Uml::dt_Activity;
01176             break;
01177         case Uml::lvt_Component_Diagram:
01178             dt = Uml::dt_Component;
01179             break;
01180         case Uml::lvt_Deployment_Diagram:
01181             dt = Uml::dt_Deployment;
01182             break;
01183         case Uml::lvt_EntityRelationship_Diagram:
01184             dt = Uml::dt_EntityRelationship;
01185             break;
01186         default:
01187             break;
01188     }
01189     return dt;
01190 }
01191 
01192 Uml::Model_Type convert_OT_MT(Uml::Object_Type ot) {
01193     Uml::Model_Type mt = Uml::N_MODELTYPES;
01194     switch (ot) {
01195         case Uml::ot_Actor:
01196         case Uml::ot_UseCase:
01197             mt = Uml::mt_UseCase;
01198             break;
01199         case Uml::ot_Component:
01200         case Uml::ot_Artifact:
01201             mt = Uml::mt_Component;
01202             break;
01203         case Uml::ot_Node:
01204             mt = Uml::mt_Deployment;
01205             break;
01206         case Uml::ot_Entity:
01207         case Uml::ot_EntityAttribute:
01208             mt = Uml::mt_EntityRelationship;
01209             break;
01210         default:
01211             mt = Uml::mt_Logical;
01212             break;
01213     }
01214     return mt;
01215 }
01216 
01217 }  // namespace Model_Utils
01218 
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:07:58 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003