[Uml-devel] branches/KDE/3.5/kdesdk/umbrello/umbrello

Oliver Kellogg okellogg at users.sourceforge.net
Thu Feb 2 14:11:08 UTC 2006


SVN commit 505041 by okellogg:

Start adding attributes of classifiers.

 M  +63 -7     petaltree2uml.cpp  


--- branches/KDE/3.5/kdesdk/umbrello/umbrello/petaltree2uml.cpp #505040:505041
@@ -19,9 +19,38 @@
 #include "import_utils.h"
 #include "package.h"
 #include "classifier.h"
+#include "attribute.h"
+#include "operation.h"
+#include "uml.h"
+#include "umldoc.h"
 
 namespace Import_Rose {
 
+/**
+ * Return the given string without surrounding quotation marks.
+ */
+QString clean(QString quotedStr) {
+    return quotedStr.remove("\"");
+}
+
+/**
+ * Extract the quid attribute from a petal node and return it as a Uml::IDType.
+ */
+Uml::IDType quid(PetalNode *node) {
+    QString quidStr = node->findAttribute("quid").string;
+    if (quidStr.isEmpty())
+        return Uml::id_None;
+    quidStr.remove("\"");
+    return STR2ID(quidStr);
+}
+
+/**
+ * Create an Umbrello object from a PetalNode.
+ *
+ * @return   True for success.
+ *           Given a PetalNode for which the mapping to Umbrello is not yet
+ *           implemented umbrellify() is a no-op but also returns true.
+ */
 bool umbrellify(PetalNode *node, UMLPackage *parentPkg = NULL) {
     if (node == NULL) {
         kdError() << "umbrellify: node is NULL" << endl;
@@ -29,26 +58,50 @@
     }
     QStringList args = node->initialArgs();
     QString objType = args[0];
-    QString name = args[1];
-    name.remove(QRegExp("\""));
-    Uml::Object_Type ot;
+    QString name = clean(args[1]);
+    Uml::IDType id = quid(node);
     if (objType == "Class_Category") {
-        ot = Uml::ot_Package;
         UMLObject *o = Import_Utils::createUMLObject(Uml::ot_Package, name, parentPkg);
-        parentPkg = static_cast<UMLPackage*>(o);
+        o->setID(id);
         PetalNode *logical_models = node->findAttribute("logical_models").node;
         if (logical_models == NULL) {
             kdError() << "umbrellify: cannot find logical_models" << endl;
             return false;
         }
+        UMLPackage *localParent = static_cast<UMLPackage*>(o);
         PetalNode::NameValueList atts = logical_models->attributes();
         for (uint i = 0; i < atts.count(); i++) {
-            umbrellify(atts[i].second.node, parentPkg);
+            umbrellify(atts[i].second.node, localParent);
         }
     } else if (objType == "Class") {
         UMLObject *o = Import_Utils::createUMLObject(Uml::ot_Class, name, parentPkg);
+        o->setID(id);
         UMLClassifier *c = static_cast<UMLClassifier*>(o);
-        // .. to be continued: insert attributes, operations ..
+        // insert attributes
+        PetalNode *class_attributes = node->findAttribute("class_attributes").node;
+        if (class_attributes) {
+            PetalNode::NameValueList attributeList = class_attributes->attributes();
+            for (uint i = 0; i < attributeList.count(); i++) {
+                PetalNode *attNode = attributeList[i].second.node;
+                QStringList initialArgs = attNode->initialArgs();
+                if (initialArgs[0] != "ClassAttribute") {
+                    kdDebug() << "umbrellify(" << name << "): expecting ClassAttribute, "
+                              << "found " << initialArgs[0] << endl;
+                    continue;
+                }
+                UMLAttribute *att = new UMLAttribute(c);
+                att->setName(clean(initialArgs[1]));
+                att->setID(quid(attNode));
+                att->setSecondaryId(clean(attNode->findAttribute("quidu").string));
+                QString vis = attNode->findAttribute("exportControl").string;
+                if (vis != QString::null) {
+                    Uml::Visibility v = Uml::Visibility::fromString(clean(vis.lower()));
+                    att->setVisibility(v);
+                }
+                c->addAttribute(att);
+            }
+        }
+        // .. to be continued: insert operations ..
     } else {
         kdDebug() << "umbrellify: object type " << objType
                   << " is not yet implemented" << endl;
@@ -79,10 +132,13 @@
         kdError() << "petalTree2Uml: cannot find logical_models" << endl;
         return false;
     }
+    Import_Utils::assignUniqueIdOnCreation(false);
     PetalNode::NameValueList atts = logical_models->attributes();
     for (uint i = 0; i < atts.count(); i++) {
         umbrellify(atts[i].second.node);
     }
+    Import_Utils::assignUniqueIdOnCreation(true);
+    UMLApp::app()->getDocument()->resolveTypes();
     return true;
 }
 




More information about the umbrello-devel mailing list