Commit 9f2c0115 authored by Oliver Kellogg's avatar Oliver Kellogg
Browse files

umbrello/import_rose.cpp

- Implementation-level global variable `dirPrefix' of type QString buffers
  the directory prefix of the main .mdl file passed into user level call to
  loadFromMDL(). It is used for finding .cat/.sub controlled units if no
  path is given at their definition.

umbrello/import_rose.{h,cpp}
- At function loadFromMDL() change type of parameter `file' from QIODevice
  to QFile. Reason: Body of loadFromMDL() requires access to fileName().
- New function mdlPath() returns dirPrefix.

umbrello/petaltree2uml.cpp
- At function fetchLocation() add arguments `width' and `height'.
  Reason: Encapsulate scaling by `Rose2Qt' in function body.
- In function handleControlledUnit(), before attempting instantiation of
  QFile(file_name), if file_name is not an absolute path then prefix
  Import_Rose::mdlPath() to it.
- In function petalTree2Uml(),
  - Store original parentPkg in parentPkg_sav;
  - Before for-loop calling umbrellify(), if parentPkg is NULL then set
    parentPkg to umldoc->rootFolder(Uml::ModelType::Logical);
  - At shortcut "return true" after for-loop, test parentPkg_sav in lieu of
    parentPkg.
parent 69f447eb
......@@ -28,6 +28,12 @@
namespace Import_Rose {
/**
* Directory prefix of .mdl file is buffered for possibly finding .cat/.sub
* controlled units (if no path is given at their definition.)
*/
QString dirPrefix;
uint nClosures; // Multiple closing parentheses may appear on a single
// line. The parsing is done line-by-line and using
// recursive descent. This means that we can only handle
......@@ -45,6 +51,11 @@ void methodName(const QString& m)
g_methodName = m;
}
QString mdlPath()
{
return dirPrefix;
}
/**
* Auxiliary function for diagnostics: Return current location.
*/
......@@ -373,8 +384,15 @@ PetalNode *readAttributes(QStringList initialArgs, QTextStream& stream)
*
* @return True for success, false in case of error.
*/
bool loadFromMDL(QIODevice& file, UMLPackage *parentPkg /* = 0 */)
bool loadFromMDL(QFile& file, UMLPackage *parentPkg /* = 0 */)
{
if (parentPkg == NULL) {
QString fName = file.fileName();
int lastSlash = fName.lastIndexOf('/');
if (lastSlash > 0) {
dirPrefix = fName.left(lastSlash + 1);
}
}
QTextStream stream(&file);
stream.setCodec("ISO 8859-1");
QString line;
......
......@@ -11,7 +11,7 @@
#ifndef IMPORT_ROSE__H
#define IMPORT_ROSE__H
#include <qiodevice.h>
#include <QFile>
class UMLPackage;
......@@ -23,7 +23,9 @@ class UMLPackage;
*/
namespace Import_Rose {
bool loadFromMDL(QIODevice & file, UMLPackage *parentPkg = 0);
bool loadFromMDL(QFile & file, UMLPackage *parentPkg = 0);
QString mdlPath();
}
......
......@@ -17,6 +17,7 @@
#include "import_utils.h"
#include "import_rose.h"
#include "package.h"
#include "folder.h"
#include "classifier.h"
#include "attribute.h"
#include "operation.h"
......@@ -91,7 +92,7 @@ QString quidu(const PetalNode *node)
/**
* Extract the location attribute from a petal node.
*/
QPointF fetchLocation(const PetalNode *node)
QPointF fetchLocation(const PetalNode *node, qreal width, qreal height)
{
QString location = node->findAttribute("location").string;
QStringList a = location.split(' ');
......@@ -100,13 +101,19 @@ QPointF fetchLocation(const PetalNode *node)
}
bool ok;
qreal x = a[0].toDouble(&ok);
if (!ok)
QPointF();
if (!ok) {
return QPointF();
}
qreal y = a[1].toDouble(&ok);
if (!ok) {
return QPointF();
}
return QPointF(x * Rose2Qt, y * Rose2Qt);
x *= Rose2Qt; // adjust scale to Qt
y *= Rose2Qt; // adjust scale to Qt
// Rose diagram locations denote the object _center_ thus:
// - for X we must subtract width/2
// - for Y we must subtract height/2
return QPointF(x - width / 2.0, y - height / 2.0);
}
/**
......@@ -421,7 +428,15 @@ bool handleControlledUnit(PetalNode *node, const QString& name, Uml::ID::Type id
uDebug() << name << ": envVar " << envVarName << " contains " << envVar;
if (envVar.endsWith("/"))
envVar.chop(1);
file_name = envVar + file_name.mid(firstSlash);
if (firstSlash < 0)
file_name = envVar;
else
file_name = envVar + file_name.mid(firstSlash);
}
if (!file_name.startsWith("/")) {
// Must have an absolute path by now.
// If we don't then use the directory of the .mdl file.
file_name = Import_Rose::mdlPath() + file_name;
}
QFile file(file_name);
if (!file.exists()) {
......@@ -604,13 +619,9 @@ bool umbrellify(PetalNode *node, UMLPackage *parentPkg = NULL)
continue;
}
QPointF pos = fetchLocation(attr);
QPointF pos = fetchLocation(attr, width, height);
if (!pos.isNull()) {
// Rose diagram locations denote the object _center_ thus:
// - for X we must subtract width/2
// - for Y we must subtract height/2
w->setX(pos.x() - width / 2.0);
w->setY(pos.y() - height / 2.0);
w->setPos(pos);
}
#if 0
......@@ -743,7 +754,7 @@ bool importLogicalPresentations(PetalNode *root, const QString &category)
}
PetalNode *logical_presentations = root_category->findAttribute("logical_presentations").node;
if (logical_presentations == NULL) {
uError() << "petalTree2Uml: cannot find logical_presentations";
uError() << "importLogicalPresentations: cannot find logical_presentations";
return false;
}
PetalNode::NameValueList atts = logical_presentations->attributes();
......@@ -838,6 +849,7 @@ bool petalTree2Uml(PetalNode *root, UMLPackage *parentPkg /* = 0 */)
uError() << "expecting root_category object Class_Category";
return false;
}
UMLPackage *parentPkg_sav = parentPkg;
if (parentPkg) {
QStringList args = root->initialArgs();
QString name = clean(args[1]);
......@@ -854,6 +866,7 @@ bool petalTree2Uml(PetalNode *root, UMLPackage *parentPkg /* = 0 */)
UMLDoc *umldoc = UMLApp::app()->document();
if (parentPkg == NULL) {
umldoc->setCurrentRoot(Uml::ModelType::Logical);
parentPkg = umldoc->rootFolder(Uml::ModelType::Logical);
Import_Utils::assignUniqueIdOnCreation(false);
}
PetalNode::NameValueList atts = logical_models->attributes();
......@@ -861,7 +874,7 @@ bool petalTree2Uml(PetalNode *root, UMLPackage *parentPkg /* = 0 */)
umbrellify(atts[i].second.node, parentPkg);
}
if (parentPkg) {
if (parentPkg_sav) {
return true;
}
......
Supports Markdown
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