Commit a113a1be authored by Oliver Kellogg's avatar Oliver Kellogg
Browse files

(In reply to comment #11)

> handleControlledUnit(): New. To be fleshed out Real Soon Now.
Real Soon Now has turned into 7 years...

umbrello/petaltree2uml.{h,cpp}
- Start fleshing out function handleControlledUnit - tested so far only
  using .cat file, not .sub file.
- Remove duplicated function names in texts at uDebug() / uError()
- At function petalTree2Uml add optional bool argument requireDesign
  defaulting to true. If requireDesign is false then:
  - Do not check for root->name() == "Design"
  - Do not attempt root->findAttribute("root_category"); instead, set
    root_category to root directly.
  - Do not call umldoc->setCurrentRoot(), the current root was already set
    by the loadFromMDL call on the .mdl file (with requireDesign = true.)
  - Do not call importView() for the UseCase, Component, or Deployment view.

umbrello/import_rose.{h,cpp}
- At function loadFromMDL add optional bool argument requireDesign
  defaulting to true. Pass requireDesign into call to petalTree2Uml.

CCBUG:81364
parent f43604bc
......@@ -365,23 +365,29 @@ PetalNode *readAttributes(QStringList initialArgs, QTextStream& stream)
return node;
}
#define SETCODEC(str) stream.setCodec(str); break
/**
* Parse a file into the PetalNode internal tree representation
* and then create Umbrello objects by traversing the tree.
*
* @return True for success, false in case of error.
*/
bool loadFromMDL(QIODevice& file)
bool loadFromMDL(QIODevice& file, bool requireDesign /* = true */)
{
QTextStream stream(&file);
stream.setCodec("ISO 8859-1");
QString line;
PetalNode *root = NULL;
uint nClosures_sav = nClosures;
uint linum_sav = linum;
nClosures = 0;
linum = 0;
while (!(line = stream.readLine()).isNull()) {
linum++;
if (line.contains(QRegExp("^\\s*\\(object Petal"))) {
bool finish = false;
// Nested loop determines character set to use
while (!(line = stream.readLine()).isNull()) {
linum++; // CHECK: do we need petal version info?
if (line.contains(')')) {
......@@ -391,44 +397,55 @@ bool loadFromMDL(QIODevice& file)
QStringList a = line.trimmed().split(QRegExp("\\s+"));
if (a.size() == 2 && a[0] == "charSet") {
const QString& charSet = a[1];
if (charSet == "0") // ASCII
;
else if (charSet == "1") // Default
stream.setCodec("System");
else if (charSet == "2") // Symbol
; // @todo stream.setCodec("what");
else if (charSet == "77") // Mac
stream.setCodec("macintosh");
else if (charSet == "128") // ShiftJIS (Japanese)
stream.setCodec("Shift_JIS");
else if (charSet == "129") // Hangul (Korean)
stream.setCodec("EUC-KR");
else if (charSet == "130") // Johab (Korean)
stream.setCodec("EUC-KR");
else if (charSet == "134") // GB2312 (Chinese)
stream.setCodec("GB18030"); // "Don't use GB2312 here" (Ralf H.)
else if (charSet == "136") // ChineseBig5
stream.setCodec("Big5");
else if (charSet == "161") // Greek
stream.setCodec("windows-1253");
else if (charSet == "162") // Turkish
stream.setCodec("windows-1254");
else if (charSet == "163") // Vietnamese
stream.setCodec("windows-1258");
else if (charSet == "177") // Hebrew
stream.setCodec("windows-1255");
else if (charSet == "178") // Arabic
stream.setCodec("windows-1256");
else if (charSet == "186") // Baltic
stream.setCodec("windows-1257");
else if (charSet == "204") // Russian
stream.setCodec("windows-1251");
else if (charSet == "222") // Thai
stream.setCodec("TIS-620");
else if (charSet == "238") // EastEurope
stream.setCodec("windows-1250");
else if (charSet == "255") // OEM (extended ASCII)
stream.setCodec("windows-1252");
if (!charSet.contains(QRegExp("^\\d+$"))) {
uWarning() << "Unimplemented charSet " << charSet;
if (finish)
break;
continue;
}
const int charSetNum = charSet.toInt();
switch (charSetNum) {
case 0: // ASCII
;
case 1: // Default
SETCODEC("System");
case 2: // Symbol
; // @todo SETCODEC("what");
case 77: // Mac
SETCODEC("macintosh");
case 128: // ShiftJIS (Japanese)
SETCODEC("Shift_JIS");
case 129: // Hangul (Korean)
SETCODEC("EUC-KR");
case 130: // Johab (Korean)
SETCODEC("EUC-KR");
case 134: // GB2312 (Chinese)
SETCODEC("GB18030"); // "Don't use GB2312 here" (Ralf H.)
case 136: // ChineseBig5
SETCODEC("Big5");
case 161: // Greek
SETCODEC("windows-1253");
case 162: // Turkish
SETCODEC("windows-1254");
case 163: // Vietnamese
SETCODEC("windows-1258");
case 177: // Hebrew
SETCODEC("windows-1255");
case 178: // Arabic
SETCODEC("windows-1256");
case 186: // Baltic
SETCODEC("windows-1257");
case 204: // Russian
SETCODEC("windows-1251");
case 222: // Thai
SETCODEC("TIS-620");
case 238: // EastEurope
SETCODEC("windows-1250");
case 255: // OEM (extended ASCII)
SETCODEC("windows-1252");
default:
uWarning() << "Unimplemented charSet number" << charSetNum;
}
}
if (finish)
break;
......@@ -446,10 +463,14 @@ bool loadFromMDL(QIODevice& file)
}
}
file.close();
nClosures = nClosures_sav;
linum = linum_sav;
if (root == NULL)
return false;
return petalTree2Uml(root);
return petalTree2Uml(root, requireDesign);
}
#undef SETCODEC
}
......@@ -21,7 +21,7 @@
*/
namespace Import_Rose {
bool loadFromMDL(QIODevice & file);
bool loadFromMDL(QIODevice & file, bool requireDesign = true);
}
......
......@@ -29,9 +29,11 @@
#include "umldoc.h"
#include "umllistview.h"
#include "umllistviewitem.h"
#include "import_rose.h"
// qt includes
#include <QRegExp>
#include <QFile>
namespace Import_Rose {
......@@ -160,7 +162,7 @@ public:
PetalNode *attributes = node->findAttribute(m_attributeTag).node;
if (attributes == NULL) {
#ifdef VERBOSE_DEBUGGING
uDebug() << "read(" << name << "): no " << m_attributeTag << " found";
uDebug() << name << ": no " << m_attributeTag << " found";
#endif
return;
}
......@@ -169,7 +171,7 @@ public:
PetalNode *attNode = attributeList[i].second.node;
QStringList initialArgs = attNode->initialArgs();
if (attNode->name() != m_elementName) {
uDebug() << "read(" << name << "): expecting " << m_elementName
uDebug() << name << ": expecting " << m_elementName
<< ", " << "found " << initialArgs[0];
continue;
}
......@@ -333,13 +335,50 @@ bool handleControlledUnit(PetalNode *node, const QString& name, Uml::ID::Type id
//bool is_loaded = (node->findAttribute("is_loaded").string != "FALSE");
QString file_name = node->findAttribute("file_name").string;
if (file_name.isEmpty()) {
uError() << "handleControlledUnit(" << name
<< "): attribute file_name not found (?)";
uError() << name << ": attribute file_name not found (?)";
return true;
}
// To Be Continued.
return true;
file_name = file_name.mid(1, file_name.length() - 2); // remove sourrounding ""
/* I wanted to use
file_name.replace(QRegExp("\\\\+") "/");
but this did not work using Qt 4.6.3. Workaround:
*/
file_name.replace("\\\\", "/");
file_name.replace(QRegExp("/+"), "/");
/* End of workaround */
if (file_name.startsWith("$")) {
const int firstSlash = file_name.indexOf(QChar('/'));
QString envVarName;
if (firstSlash < 0) {
envVarName = file_name.mid(1);
} else {
envVarName = file_name.mid(1, firstSlash - 1);
}
QByteArray envVarBA = qgetenv(envVarName.toLatin1());
if (envVarBA.isNull() || envVarBA.isEmpty()) {
uError() << name << "cannot process file_name " << file_name
<< " because environment variable " << envVarName << " not set";
return false;
}
QString envVar(envVarBA);
uDebug() << name << ": envVar " << envVarName << " contains " << envVar;
if (envVar.endsWith("/"))
envVar.chop(1);
file_name = envVar + file_name.mid(firstSlash);
}
QFile file(file_name);
if (!file.exists()) {
uError() << name << ": file_name " << file_name << " not found";
return false;
}
if (!file.open(QIODevice::ReadOnly)) {
uError() << name << ": file_name " << file_name << " cannot be opened";
return false;
}
bool status = loadFromMDL(file, false);
file.close();
return status;
}
/**
......@@ -352,7 +391,7 @@ bool handleControlledUnit(PetalNode *node, const QString& name, Uml::ID::Type id
bool umbrellify(PetalNode *node, UMLPackage *parentPkg = NULL)
{
if (node == NULL) {
uError() << "umbrellify: node is NULL";
uError() << "node is NULL";
return false;
}
QStringList args = node->initialArgs();
......@@ -371,8 +410,8 @@ bool umbrellify(PetalNode *node, UMLPackage *parentPkg = NULL)
umbrellify(atts[i].second.node, localParent);
}
} else if (!handleControlledUnit(node, name, id, parentPkg)) {
uDebug() << "umbrellify: handling of " << objType << " " << name
<< " is not yet implemented";
uWarning() << objType << " handleControlledUnit(" << name
<< ") returned an error";
}
} else if (objType == "Class") {
......@@ -403,7 +442,7 @@ bool umbrellify(PetalNode *node, UMLPackage *parentPkg = NULL)
} else if (objType == "Association") {
PetalNode *roles = node->findAttribute("roles").node;
if (node == NULL) {
uError() << "umbrellify: cannot find roles of Association";
uError() << "cannot find roles of Association";
return false;
}
UMLAssociation *assoc = new UMLAssociation(Uml::AssociationType::UniAssociation);
......@@ -411,11 +450,11 @@ bool umbrellify(PetalNode *node, UMLPackage *parentPkg = NULL)
for (uint i = 0; i <= 1; ++i) {
PetalNode *roleNode = roleList[i].second.node;
if (roleNode == NULL) {
uError() << "umbrellify: roleNode of Association is NULL";
uError() << "roleNode of Association is NULL";
return false;
}
if (roleNode->name() != "Role") {
uDebug() << "umbrellify(" << name << "): expecting Role, found \""
uDebug() << name << ": expecting Role, found \""
<< roleNode->name();
continue;
}
......@@ -464,8 +503,7 @@ bool umbrellify(PetalNode *node, UMLPackage *parentPkg = NULL)
UMLApp::app()->document()->addAssociation(assoc);
} else {
uDebug() << "umbrellify: object type " << objType
<< " is not yet implemented";
uDebug() << "object type " << objType << " is not yet implemented";
}
return true;
}
......@@ -507,7 +545,7 @@ UMLListViewItem::ListViewType folderType(UMLListViewItem *parent)
bool umbrellify(PetalNode *node, const QString& modelsName, UMLListViewItem *parent)
{
if (node == NULL) {
uError() << "umbrellify(" << modelsName << "): node is NULL";
uError() << modelsName << ": node is NULL";
return false;
}
QStringList args = node->initialArgs();
......@@ -527,7 +565,7 @@ bool umbrellify(PetalNode *node, const QString& modelsName, UMLListViewItem *par
item = new UMLListViewItem(parent, name, UMLListViewItem::lvt_Actor, act);
obj = act;
} else {
uDebug() << "umbrellify(" << name << "): handling of Class stereotype "
uDebug() << name << ": handling of Class stereotype "
<< stereotype << " is not yet implemented";
}
} else if (objType == "UseCase") {
......@@ -544,8 +582,7 @@ bool umbrellify(PetalNode *node, const QString& modelsName, UMLListViewItem *par
item = new UMLListViewItem(parent, name, UMLListViewItem::lvt_Node, un);
obj = un;
} else {
uDebug() << "umbrellify: object type " << objType
<< " is not yet implemented";
uDebug() << "object type " << objType << " is not yet implemented";
return true;
}
PetalNode *models = node->findAttribute(modelsName).node;
......@@ -574,13 +611,12 @@ bool importView(PetalNode *root, const QString& rootName,
{
PetalNode *viewRoot = root->findAttribute(rootName).node;
if (viewRoot == NULL) {
uDebug() << "importView: cannot find " << rootName;
uDebug() << "cannot find " << rootName;
return false;
}
PetalNode *models = viewRoot->findAttribute(modelsName).node;
if (models == NULL) {
uError() << "importView: cannot find " << modelsName
<< " of " << rootName;
uError() << "cannot find " << modelsName << " of " << rootName;
return false;
}
PetalNode::NameValueList atts = models->attributes();
......@@ -598,39 +634,50 @@ bool importView(PetalNode *root, const QString& rootName,
* @param root the root of the tree
* @return true for success.
*/
bool petalTree2Uml(PetalNode *root)
bool petalTree2Uml(PetalNode *root, bool requireDesign /* = true */)
{
if (root == NULL) {
uError() << "petalTree2Uml: root is NULL";
return false;
}
if (root->name() != "Design") {
uError() << "petalTree2Uml: expecting root name Design";
uError() << "root is NULL";
return false;
}
//*************************** import Logical View ********************************
PetalNode *root_category = root->findAttribute("root_category").node;
if (root_category == NULL) {
uError() << "petalTree2Uml: cannot find root_category";
return false;
PetalNode *root_category;
if (requireDesign) {
if (root->name() != "Design") {
uError() << "expecting root name Design";
return false;
}
//*********************** import Logical View ********************************
root_category = root->findAttribute("root_category").node;
if (root_category == NULL) {
uError() << "cannot find root_category";
return false;
}
} else {
root_category = root;
}
if (root_category->name() != "Class_Category") {
uError() << "petalTree2Uml: expecting root_category object Class_Category";
uError() << "expecting root_category object Class_Category";
return false;
}
PetalNode *logical_models = root_category->findAttribute("logical_models").node;
if (logical_models == NULL) {
uError() << "petalTree2Uml: cannot find logical_models";
uError() << "cannot find logical_models";
return false;
}
UMLDoc *umldoc = UMLApp::app()->document();
umldoc->setCurrentRoot(Uml::ModelType::Logical);
Import_Utils::assignUniqueIdOnCreation(false);
if (requireDesign) {
umldoc->setCurrentRoot(Uml::ModelType::Logical);
Import_Utils::assignUniqueIdOnCreation(false);
}
PetalNode::NameValueList atts = logical_models->attributes();
for (int i = 0; i < atts.count(); ++i) {
umbrellify(atts[i].second.node);
}
if (!requireDesign) {
return true;
}
// Shorthand for UMLApp::app()->listView()
UMLListView *lv = UMLApp::app()->listView();
......
......@@ -23,7 +23,7 @@ class PetalNode;
*/
namespace Import_Rose {
bool petalTree2Uml(PetalNode *root);
bool petalTree2Uml(PetalNode *root, bool requireDesign = true);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment