Example #1
0
/**
 * Auxiliary method for recursively traversing the #include dependencies
 * in order to feed innermost includes to the model before dependent
 * includes.  It is important that includefiles are fed to the model
 * in proper order so that references between UML objects are created
 * properly.
 * @param fileName   the file to import
 */
void CppImport::feedTheModel(const QString& fileName)
{
    if (ms_seenFiles.indexOf(fileName) != -1)
        return;
    ms_seenFiles.append(fileName);
    QMap<QString, Dependence> deps = ms_driver->dependences(fileName);
    if (! deps.empty()) {
        QMap<QString, Dependence>::Iterator it;
        for (it = deps.begin(); it != deps.end(); ++it) {
            if (it.value().second == Dep_Global)  // don't want these
                continue;
            QString includeFile = it.key();
            if (includeFile.isEmpty()) {
                uError() << fileName << ": " << it.value().first << " not found";
                continue;
            }
            uDebug() << fileName << ": " << includeFile << " => " << it.value().first;
            if (ms_seenFiles.indexOf(includeFile) == -1)
                feedTheModel(includeFile);
        }
    }
    TranslationUnitAST *ast = ms_driver->translationUnit( fileName );
    if (ast == NULL) {
        uError() << fileName << " not found";
        return;
    }
    CppTree2Uml modelFeeder( fileName );
    modelFeeder.parseTranslationUnit( ast );
}
QString collectVerbatimText(QTextStream& stream)
{
    QString result;
    QString line;
    methodName(QLatin1String("collectVerbatimText"));
    while (!(line = stream.readLine()).isNull()) {
        linum++;
        line = line.trimmed();
        if (line.isEmpty() || line.startsWith(QLatin1Char(')')))
            break;
        if (line[0] != QLatin1Char('|')) {
            uError() << loc() << "expecting '|' at start of verbatim text";
            return QString();
        } else {
            result += line.mid(1) + QLatin1Char('\n');
        }
    }
    if (line.isNull()) {
        uError() << loc() << "premature EOF";
        return QString();
    }
    if (! line.isEmpty()) {
        for (int i = 0; i < line.length(); ++i) {
            const QChar& clParenth = line[i];
            if (clParenth != QLatin1Char(')')) {
                uError() << loc() << "expected ')', found: " << clParenth;
                return QString();
            }
            nClosures++;
        }
    }
    return result;
}
Example #3
0
/**
 * This is really an auxiliary method for loadFromMDL() but is kept in a
 * separate file to reflect that it is not coupled with the parser
 * (other than by the PetalNode.)
 *
 * @param root   the root of the tree
 * @return  true for success.
 */
bool petalTree2Uml(PetalNode *root)
{
    if (root == NULL) {
        uError() << "petalTree2Uml: root is NULL";
        return false;
    }
    if (root->name() != "Design") {
        uError() << "petalTree2Uml: expecting root name Design";
        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;
    }
    if (root_category->name() != "Class_Category") {
        uError() << "petalTree2Uml: 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";
        return false;
    }
    UMLDoc *umldoc = UMLApp::app()->document();
    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);
    }

    // Shorthand for UMLApp::app()->listView()
    UMLListView *lv = UMLApp::app()->listView();

    //*************************** import Use Case View ********************************
    umldoc->setCurrentRoot(Uml::ModelType::UseCase);
    importView(root, "root_usecase_package", "logical_models", lv->theUseCaseView());

    //*************************** import Component View *******************************
    umldoc->setCurrentRoot(Uml::ModelType::Component);
    importView(root, "root_subsystem", "physical_models", lv->theComponentView());

    //*************************** import Deployment View ******************************
    umldoc->setCurrentRoot(Uml::ModelType::Deployment);
    importView(root, "process_structure", "ProcsNDevs", lv->theDeploymentView());

    //***************************       wrap up        ********************************
    umldoc->setCurrentRoot(Uml::ModelType::Logical);
    Import_Utils::assignUniqueIdOnCreation(true);
    umldoc->resolveTypes();
    return true;
}
// we basically want to update the body of this method
void CPPSourceCodeAccessorMethod::updateContent()
{
    CodeClassField * parentField = getParentClassField();
    CPPCodeClassField * cppfield = dynamic_cast<CPPCodeClassField*>(parentField);

    // Check for dynamic casting failure!
    if(cppfield == NULL)
    {
        uError() << "cppfield: invalid dynamic cast";
        return;
    }

    CodeGenPolicyExt *pe = UMLApp::app()->policyExt();
    CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe);

    // Check for dynamic casting failure!
    if(policy == NULL)
    {
        uError() << "policy: invalid dynamic cast";
        return;
    }

    bool isInlineMethod = policy->getAccessorsAreInline();

    QString variableName = cppfield->getFieldName();
    QString itemClassName = cppfield->getTypeName();
    QString text;

    if(isInlineMethod) {
        switch(getType()) {
        case CodeAccessorMethod::ADD:
            text = policy->getVectorMethodAppend(variableName, itemClassName);
            break;
        case CodeAccessorMethod::REMOVE:
            text = policy->getVectorMethodRemove(variableName, itemClassName);
            break;
        case CodeAccessorMethod::SET:
            text = variableName + QLatin1String(" = value;");
            break;
        case CodeAccessorMethod::LIST:
        case CodeAccessorMethod::GET:
        default:
            text = QLatin1String("return ") + variableName + QLatin1Char(';');
            break;
        }
    }

    setText(text);
}
Example #5
0
bool Import_Argo::loadFromArgoFile(const KZip &zipFile, const QString &fileName)
{
    const KArchiveFile *file = static_cast<const KArchiveFile*>(zipFile.directory()->entry(fileName));
    if (!file)
        return false;

    QXmlStreamReader xml;
    xml.addData(file->data());

    while (!xml.atEnd()) {
        xml.readNext();
        if (xml.name() == QLatin1String("member")) {
            QXmlStreamAttributes attributes = xml.attributes();
            QString type = attributes.value(QLatin1String("type")).toString();
            QString name = attributes.value(QLatin1String("name")).toString();
            if (type == QLatin1String("xmi"))
                loadFromXMIFile(zipFile, name);
            else if (type == QLatin1String("pgml"))
                loadFromPGMLFile(zipFile, name);
            else if (type == QLatin1String("todo"))
                loadFromTodoFile(zipFile, name);
            else
                uError() << "unknown file type" << type << "in file" << zipFile.fileName() << ":" << fileName;
        }
    }
    if (xml.hasError()) {
         reportError(xml, zipFile, fileName);
         return false;
    }
    return true;
}
Example #6
0
/**
 * Reimplemented from UMLWidget::slotMenuSelection to handle
 * rename action.
 */
void SignalWidget::slotMenuSelection(QAction* action)
{
    bool ok = false;
    QString text;

    ListPopupMenu *menu = ListPopupMenu::menuFromAction(action);
    if (!menu) {
        uError() << "Action's data field does not contain ListPopupMenu pointer";
        return;
    }
    ListPopupMenu::MenuType sel = menu->getMenuType(action);

    switch( sel ) {
    case ListPopupMenu::mt_Rename:
        text = KInputDialog::getText( i18n("Enter signal name"),
                                      i18n("Enter the signal name :"),
                                      name(), &ok );
        if (ok && !text.isEmpty()) {
            setName(text);
        }
        break;

    default:
        UMLWidget::slotMenuSelection(action);
    }
}
bool CPPSourceCodeDocument::addCodeOperation (CodeOperation * op )
{
    bool retval = false;
    if (op->getParentOperation()->isLifeOperation()) {
        if (m_constructorBlock)
            retval = m_constructorBlock->addTextBlock(op);
        else
            uError() << "m_constructorBlock is NULL";
    } else {
        if (m_methodsBlock)
            retval = m_methodsBlock->addTextBlock(op);
        else
            uError() << "m_methodsBlock is NULL";
    }
    return retval;
}
Example #8
0
/**
 * Reimplemented from UMLWidget::slotMenuSelection to handle
 * some menu actions.
 */
void NoteWidget::slotMenuSelection(QAction* action)
{
    ListPopupMenu *menu = ListPopupMenu::menuFromAction(action);
    if (!menu) {
        uError() << "Action's data field does not contain ListPopupMenu pointer";
        return;
    }
    ListPopupMenu::MenuType sel = menu->getMenuType(action);
    switch(sel) {
    case ListPopupMenu::mt_Rename:
        {
            umlScene()->updateDocumentation(false);
            NoteDialog * dlg = new NoteDialog(umlScene()->activeView(), this);
            if (dlg->exec()) {
                umlScene()->showDocumentation(this, true);
                umlDoc()->setModified(true);
                update();
            }
            delete dlg;
        }
        break;

    case ListPopupMenu::mt_Clear:
        umlScene()->updateDocumentation(true);
        setDocumentation(QString());
        umlScene()->showDocumentation(this, true);
        umlDoc()->setModified(true);
        update();
        break;

    default:
        UMLWidget::slotMenuSelection(action);
        break;
    }
}
/**
 * This method simply ensures presence of two points and
 * adds the needed points for self associations.
 */
void AssociationLine::calculateInitialEndPoints()
{
    if (m_associationWidget->isSelf() && count() < 4) {
        for (int i = count(); i < 4; ++i) {
            insertPoint(i, QPointF());
        }
        UMLWidget *wid = m_associationWidget->widgetForRole(Uml::RoleType::B);
        if (!wid) {
            uError() << "AssociationWidget is partially constructed."
                "UMLWidget for role B is null.";
            return;
        }
        const QRectF rect = m_associationWidget->mapFromScene(
                mapToScene(wid->rect()).boundingRect()).boundingRect();

        qreal l = rect.left() + .25 * rect.width();
        qreal r = rect.left() + .75 * rect.width();
        bool drawAbove = rect.top() >= SelfAssociationMinimumHeight;
        qreal y = drawAbove ? rect.top() : rect.bottom();
        qreal yOffset = SelfAssociationMinimumHeight;
        if (drawAbove) {
            yOffset *= -1.0;
        }

        setPoint(0, QPointF(l, y));
        setPoint(1, QPointF(l, y + yOffset));
        setPoint(2, QPointF(r, y + yOffset));
        setPoint(3, QPointF(r, y));
    } else if (!m_associationWidget->isSelf() && count() < 2) {
        setEndPoints(QPointF(), QPointF());
    }
}
Example #10
0
/**
 * Call when you wish move changes in the doc window back into the
 * members documentation.
 *
 * If clear is true the doc window will display the documentation
 * for the current project instead of the widget documentation.
 *
 * This is usually called before displaying a properties dialog.
 *
 * @param clear     If true, show the documentation of current project
 * @param startup   If true, no setModified(true) calls will be done and nothing is pushed to the undo stack
 */
void DocWindow::updateDocumentation(bool clear, bool startup)
{
    // the file is marked modified, if the documentation differs
    // we don't do this on startup/load of a xmi file, because every time
    // modified is set, we get another undo/redo backup point
    if (isModified()) {
        if (m_Showing == st_UMLObject && m_pUMLObject) {
            m_pUMLObject->setDoc(m_docTE->toPlainText());
        } else if(m_Showing == st_UMLScene &&  m_pUMLScene) {
            m_pUMLScene->setDocumentation(m_docTE->toPlainText());
        } else if (m_Showing == st_UMLWidget &&  m_pUMLWidget) {
            m_pUMLWidget->setDocumentation(m_docTE->toPlainText());
        } else if (m_Showing == st_Association &&  m_pAssocWidget) {
            m_pAssocWidget->setDocumentation(m_docTE->toPlainText());
        } else if (m_Showing == st_Project) {
            m_pUMLDoc->setDocumentation(m_docTE->toPlainText());
        } else {
            uError() << "could not update documentation because of unknown type and object combination";
        }

        // now do the setModified call
        if (startup == false) {
            m_pUMLDoc->setModified(true);
        }
    }

    // we should show the documentation of the whole project
    if (clear) {
        reset();
    }
}
Example #11
0
/**
 * Remove a message widget from the list.
 *
 * @param message   Pointer to the MessageWidget to remove.
 */
void ObjectWidget::messageRemoved(MessageWidget* message)
{
    if (m_messages.removeAll(message) == false) {
        uError() << message->name() << ": missing entry !";
        return ;
    }
}
Example #12
0
/**
 * Call this method to generate sql code for a UMLClassifier.
 * @param c the class to generate code for
 */
void SQLWriter::writeClass(UMLClassifier *c)
{
    UMLEntity* e = c->asUMLEntity();

    if (!e) {
        uError() << "Invalid cast from" << c->baseTypeStr() << "'" << c->name() << "' to UMLEntity*";
        return;
    }

    m_pEntity = e;

    QString entityname = cleanName(m_pEntity->name());

    //find an appropriate name for our file
    QString fileName = findFileName(m_pEntity, QLatin1String(".sql"));
    if (fileName.isEmpty()) {
        emit codeGenerated(m_pEntity, false);
        return;
    }

    QFile file;
    if (!openFile(file, fileName)) {
        emit codeGenerated(m_pEntity, false);
        return;
    }

    //Start generating the code!!

    QTextStream sql(&file);
    //try to find a heading file (license, coments, etc)
    QString str;
    str = getHeadingFile(QLatin1String(".sql"));
    if (!str.isEmpty()) {
        str.replace(QRegExp(QLatin1String("%filename%")), fileName);
        str.replace(QRegExp(QLatin1String("%filepath%")), file.fileName());
        sql << str << m_endl;
    }

    //Write class Documentation if there is somthing or if force option
    if (forceDoc() || !m_pEntity->doc().isEmpty()) {
        sql << m_endl << "--" << m_endl;
        sql << "-- TABLE: " << entityname << m_endl;
        sql << formatDoc(m_pEntity->doc(),QLatin1String("-- "));
        sql << "--  " << m_endl << m_endl;
    }

    // write all entity attributes
    UMLEntityAttributeList entAttList = m_pEntity->getEntityAttributes();

    sql << "CREATE TABLE " <<  entityname << " (";

    printEntityAttributes(sql, entAttList);

    sql << m_endl << ");" << m_endl;

    // auto increments
    UMLEntityAttributeList autoIncrementList;
    foreach(UMLEntityAttribute* entAtt, entAttList) {
        autoIncrementList.append(entAtt);
    }
/**
 * Slot for the generate button. Starts the code generation.
 */
void CodeGenStatusPage::generateCode()
{
    ui_pushButtonGenerate->setEnabled(false);
    setCommitPage(true);  //:TODO: disable back and cancel button ?

    CodeGenerator* codeGenerator = UMLApp::app()->generator();
    UMLDoc* doc = UMLApp::app()->document();

    if (codeGenerator) {
        connect(codeGenerator, SIGNAL(codeGenerated(UMLClassifier*,bool)),
                this, SLOT(classGenerated(UMLClassifier*,bool)));
        connect(codeGenerator, SIGNAL(showGeneratedFile(QString)),
                this, SLOT(showFileGenerated(QString)));

        UMLClassifierList cList;

        for (int row = 0; row < ui_tableWidgetStatus->rowCount(); ++row) {
            QTableWidgetItem* item = ui_tableWidgetStatus->item(row, 0);
            UMLClassifier *concept = doc->findUMLClassifier(item->text());
            if (concept == NULL) {
                uError() << "Could not find classifier " << item->text()
                         << " - not included in generated code.";
                continue;
            }
            cList.append(concept);
        }
        codeGenerator->writeCodeToFile(cList);

        m_generationDone = true;
        setFinalPage(true);
        emit completeChanged();
    }
}
/**
 * Extract the stripped down value from a (value ...) element.
 * Example: for the input
 *            (value Text "This is some text")
 *          the following is extracted:
 *            "This is some text"
 * Extracted elements and syntactic sugar of the value element are
 * removed from the input list.
 * The stream is passed into this method because it may be necessary
 * to read new lines - in the case of verbatim text.
 * The format of verbatim text in petal files is as follows:
 *
 *         (value Text
 * |This is the first line of verbatim text.
 * |This is another line of verbatim text.
 *        )
 * (The '|' character is supposed to be in the first column of the line)
 * In this case the two lines are extracted without the leading '|'.
 * The line ending '\n' of each line is preserved.
 */
QString extractValue(QStringList& l, QTextStream& stream)
{
    methodName(QLatin1String("extractValue"));
    if (l.count() == 0)
        return QString();
    if (l.first() == QLatin1String("("))
        l.pop_front();
    if (l.first() != QLatin1String("value"))
        return QString();
    l.pop_front();  // remove "value"
    l.pop_front();  // remove the value type: could be e.g. "Text" or "cardinality"
    QString result;
    if (l.count() == 0) {  // expect verbatim text to follow on subsequent lines
        QString text = collectVerbatimText(stream);
        nClosures--;  // expect own closure
        return text;
    } else {
        result = shift(l);
        if (l.first() != QLatin1String(")")) {
            uError() << loc() << "expecting closing parenthesis";
            return result;
        }
        l.pop_front();
    }
    while (l.count() && l.first() == QLatin1String(")")) {
        nClosures++;
        l.pop_front();
    }
    return result;
}
Example #15
0
/**
 * Copy operation.
 * @param fromView   flag if it is from view
 * @return           the mime data
 */
QMimeData* UMLClipboard::copy(bool fromView/*=false*/)
{
    // Clear previous copied data
    m_AssociationList.clear();
    m_ObjectList.clear();
    m_ViewList.clear();

    UMLDragData *data = 0;
    QPixmap* png = 0;

    UMLListView * listView = UMLApp::app()->listView();

    if (fromView) {
        m_type = clip4;
        UMLView *view = UMLApp::app()->currentView();
        if (view == 0) {
            uError() << "UMLApp::app()->currentView() is NULL";
            return 0;
        }
        UMLScene *scene = view->umlScene();
        if (scene == 0) {
            uError() << "currentView umlScene() is NULL";
            return 0;
        }
        m_WidgetList = scene->selectedWidgetsExt();
        //if there is no selected widget then there is no copy action
        if (!m_WidgetList.count()) {
            return 0;
        }
        m_AssociationList = scene->selectedAssocs();
        scene->copyAsImage(png);

        // Clip4 needs related widgets.
        addRelatedWidgets();

        // Clip4 needs UMLObjects because it's possible the UMLObject
        // is no longer there when pasting this mime data. This happens for
        // example when using cut-paste or pasting to another Umbrello
        // instance.
        fillObjectListForWidgets(m_WidgetList);

        foreach (WidgetBase* widget, m_AssociationList) {
            if (widget->umlObject() != 0) {
                m_ObjectList.append(widget->umlObject());
            }
        }
    } else {
Example #16
0
void CppTree2Uml::parseTemplateDeclaration(TemplateDeclarationAST* ast)
{
    TemplateParameterListAST* parmListAST = ast->templateParameterList();
    if (parmListAST == NULL)
        return;
    QList<TemplateParameterAST*> parmList = parmListAST->templateParameterList();
    for (int i = 0; i < parmList.size(); ++i) {
        // The template is either a typeParameter or a typeValueParameter.
        TemplateParameterAST* tmplParmNode = parmList.at(i);
        TypeParameterAST* typeParmNode = tmplParmNode->typeParameter();
        if (typeParmNode) {
            NameAST* nameNode = typeParmNode->name();
            if (nameNode) {
                QString typeName = nameNode->unqualifiedName()->text();
                Model_Utils::NameAndType nt(typeName, NULL);
                m_templateParams.append(nt);
            } else {
                uError() << "nameNode is NULL";
            }
        }

        ParameterDeclarationAST* valueNode = tmplParmNode->typeValueParameter();
        if (valueNode) {
            TypeSpecifierAST* typeSpec = valueNode->typeSpec();
            if (typeSpec == NULL) {
                uError() << "typeSpec is NULL";
                continue;
            }
            QString typeName = typeSpec->name()->text();
            UMLObject *t = Import_Utils::createUMLObject(UMLObject::ot_UMLObject, typeName,
                                                          m_currentNamespace[m_nsCnt]);
            DeclaratorAST* declNode = valueNode->declarator();
            NameAST* nameNode = declNode->declaratorId();
            if (nameNode == NULL) {
                uError() << "CppTree2Uml::parseTemplateDeclaration(value):"
                         << " nameNode is NULL";
                continue;
            }
            QString paramName = nameNode->unqualifiedName()->text();
            Model_Utils::NameAndType nt(paramName, t);
            m_templateParams.append(nt);
        }
    }

    if (ast->declaration())
        TreeParser::parseDeclaration(ast->declaration());
}
Example #17
0
/**
 * Add a message widget to the list.
 *
 * @param message   Pointer to the MessageWidget to add.
 */
void ObjectWidget::messageAdded(MessageWidget* message)
{
    if (m_messages.count(message)) {
        uError() << message->name() << ": duplicate entry !";
        return ;
    }
    m_messages.append(message);
}
Example #18
0
/**
 * Sets up a stereotype.
 *
 * @param name   The name of this UMLStereotype.
 * @param id     The unique id given to this UMLStereotype.
 */
UMLStereotype::UMLStereotype(const QString &name, Uml::ID::Type id /* = Uml::id_None */)
  : UMLObject(name, id)
{
    m_BaseType = UMLObject::ot_Stereotype;
    UMLStereotype * existing = UMLApp::app()->document()->findStereotype(name);
    if (existing) {
        uError() << "UMLStereotype constructor: " << name << " already exists";
    }
    m_refCount = 0;
}
Example #19
0
/**
 * Deletes the child listview item representing the given UMLClassifierListItem.
 */
void UMLListViewItem::deleteChildItem(UMLClassifierListItem *child)
{
    UMLListViewItem *childItem = findChildObject(child);
    if (childItem == 0) {
        uError() << child->name() << ": child listview item not found";
        return;
    }
    m_comap.remove(child);
    delete childItem;
}
Example #20
0
/**
 * Reimplement operation from NativeImportBase.
 * In addition to handling multiline comments, this method transforms
 * changes in leading indentation into braces (opening brace for increase
 * in indentation, closing brace for decrease in indentation) in m_source.
 * Removal of Python's indentation sensitivity simplifies subsequent
 * processing using Umbrello's native import framework.
 * @param line   the line to preprocess
 * @return success status of operation
 */
bool PythonImport::preprocess(QString& line)
{
    if (NativeImportBase::preprocess(line))
        return true;
    // Handle single line comment
    int pos = line.indexOf(m_singleLineCommentIntro);
    if (pos != -1) {
        QString cmnt = line.mid(pos);
        m_source.append(cmnt);
        m_srcIndex++;
        if (pos == 0)
            return true;
        line = line.left(pos);
        line.remove(QRegExp(QLatin1String("\\s+$")));
    }
    // Transform changes in indentation into braces a la C++/Java/Perl/...
    pos = line.indexOf(QRegExp(QLatin1String("\\S")));
    if (pos == -1)
        return true;
    bool isContinuation = false;
    int leadingWhite = line.left(pos).count(QRegExp(QLatin1String("\\s")));
    if (leadingWhite > m_srcIndent[m_srcIndentIndex]) {
        if (m_srcIndex == 0) {
            uError() << "internal error";
            return true;
        }
        if (m_braceWasOpened) {
            m_srcIndent[++m_srcIndentIndex] = leadingWhite;
            m_braceWasOpened = false;
        } else {
            isContinuation = true;
        }
    } else {
        while (m_srcIndentIndex > 0 && leadingWhite < m_srcIndent[m_srcIndentIndex]) {
            m_srcIndentIndex--;
            m_source.append(QLatin1String("}"));
            m_srcIndex++;
        }
    }

    if (m_braceWasOpened && m_srcIndentIndex == 0) {
        m_source.append(QLatin1String("}"));
        m_srcIndex++;
    }

    if (line.endsWith(QLatin1Char(':'))) {
        line.replace(QRegExp(QLatin1String(":$")), QLatin1String("{"));
        m_braceWasOpened = true;
    } else {
        m_braceWasOpened = false;
    }
    if (!isContinuation && !m_braceWasOpened)
        line += QLatin1Char(';');
    return false;  // The input was not completely consumed by preprocessing.
}
Example #21
0
/**
 * Creates the <UML:AssociationEnd> XMI element.
 */
void UMLRole::saveToXMI(QDomDocument & qDoc, QDomElement & qElement)
{
    QDomElement roleElement = UMLObject::save(QLatin1String("UML:AssociationEnd"), qDoc);
    if (m_pSecondary)
        roleElement.setAttribute(QLatin1String("type"), Uml::ID::toString(m_pSecondary->id()));
    else
        uError() << "id " << Uml::ID::toString(m_nId) << ": m_pSecondary is NULL";
    if (!m_Multi.isEmpty())
        roleElement.setAttribute(QLatin1String("multiplicity"), m_Multi);
    if (m_role == Uml::RoleType::A) {  // role aggregation based on parent type
        // role A
        switch (m_pAssoc->getAssocType()) {
        case Uml::AssociationType::Composition:
            roleElement.setAttribute(QLatin1String("aggregation"), QLatin1String("composite"));
            break;
        case Uml::AssociationType::Aggregation:
            roleElement.setAttribute(QLatin1String("aggregation"), QLatin1String("aggregate"));
            break;
        default:
            roleElement.setAttribute(QLatin1String("aggregation"), QLatin1String("none"));
            break;
        }
        if (m_pAssoc->getAssocType() == Uml::AssociationType::UniAssociation) {
            // Normally the isNavigable attribute is "true".
            // We set it to false on role A to indicate that
            // role B gets an explicit arrowhead.
            roleElement.setAttribute(QLatin1String("isNavigable"), QLatin1String("false"));
        } else {
            roleElement.setAttribute(QLatin1String("isNavigable"), QLatin1String("true"));
        }
    } else {
        roleElement.setAttribute(QLatin1String("aggregation"), QLatin1String("none"));
        roleElement.setAttribute(QLatin1String("isNavigable"), QLatin1String("true"));
        //FIXME obviously this isn't standard XMI
        if (m_pAssoc->getAssocType() == Uml::AssociationType::Relationship) {
            roleElement.setAttribute(QLatin1String("relationship"), QLatin1String("true"));
        }
    }

    roleElement.setAttribute(QLatin1String("visibility"), Uml::Visibility::toString(visibility(), false));

    switch (m_Changeability) {
        case Uml::Changeability::Frozen:
            roleElement.setAttribute(QLatin1String("changeability"), QLatin1String("frozen"));
            break;
        case Uml::Changeability::AddOnly:
            roleElement.setAttribute(QLatin1String("changeability"), QLatin1String("addOnly"));
            break;
        case Uml::Changeability::Changeable:
            roleElement.setAttribute(QLatin1String("changeability"), QLatin1String("changeable"));
            break;
    }
    qElement.appendChild(roleElement);
}
Example #22
0
/**
 * Set the ID of the diagram hyperlinked to this note.
 * To switch off the hyperlink, set this to Uml::id_None.
 *
 * @param sceneID ID of an UMLScene.
 * @todo Fix the display of diagram link.
 */
void NoteWidget::setDiagramLink(Uml::IDType sceneID)
{
    UMLView *view = umlDoc()->findView(sceneID);
    if (view == 0) {
        uError() << "no view found for viewID " << ID2STR(sceneID);
        return;
    }

    QString linkText("Diagram: " + view->umlScene()->name());
    m_diagramLink = sceneID;
}
Example #23
0
/**
 * Shows an operation dialog box.
 *
 * @param enableAutoIncrement Enable auto increment checkbox
 */
void FloatingTextWidget::showOperationDialog(bool enableAutoIncrement)
{
    if (!m_linkWidget) {
        uError() << "m_linkWidget is NULL";
        return;
    }
    QString seqNum = m_linkWidget->sequenceNumber();
    UMLClassifier* c = m_linkWidget->lwClassifier();
    QString opText = m_linkWidget->lwOperationText();
    if (!c) {
        uError() << "m_linkWidget->lwClassifier() returns a NULL classifier";
        return;
    }

    QPointer<SelectOperationDialog> selectDialog = new SelectOperationDialog(m_scene->activeView(), c, enableAutoIncrement);
    if (enableAutoIncrement && m_scene->autoIncrementSequence()) {
        seqNum = m_scene->autoIncrementSequenceValue();
        selectDialog->setAutoIncrementSequence(true);
    }
    selectDialog->setSeqNumber(seqNum);
    if (m_linkWidget->operation() == 0) {
        selectDialog->setCustomOp(opText);
    } else {
        selectDialog->setClassOp(opText);
    }
    if (selectDialog->exec()) {
        seqNum = selectDialog->getSeqNumber();
        opText = selectDialog->getOpText();
        if (selectDialog->isClassOp()) {
            Model_Utils::OpDescriptor od;
            Model_Utils::Parse_Status st = Model_Utils::parseOperation(opText, od, c);
            if (st == Model_Utils::PS_OK) {
                UMLClassifierList selfAndAncestors = c->findSuperClassConcepts();
                selfAndAncestors.prepend(c);
                UMLOperation *op = 0;
                foreach (UMLClassifier *cl, selfAndAncestors) {
                    op = cl->findOperation(od.m_name, od.m_args);
                    if (op) {
                        break;
                    }
                }
Example #24
0
/**
 * Extract and load code for operations from xmi section.
 * Probably we have code which was entered in classpropdlg for an operation.
 */
void CodeGenerator::loadCodeForOperation(const QString& idStr, const QDomElement& codeDocElement)
{
    Uml::IDType id = STR2ID(idStr);
    UMLObject *obj = m_document->findObjectById(id);
    if (obj) {
        uDebug() << "found UMLObject for id:" << idStr;
        QString value = codeDocElement.attribute("value", "");

        Uml::Object_Type t = obj->baseType();
        if (t == Uml::ot_Operation) {
            UMLOperation *op = static_cast<UMLOperation*>(obj);
            op->setSourceCode(value);
        }
        else {
            uError() << "sourcecode id " << idStr << " has unexpected type " << t;
        }
    }
    else {
        uError() << "unknown sourcecode id " << idStr;
    }
}
Example #25
0
/**
 * Set the ID of the diagram hyperlinked to this note.
 * To switch off the hyperlink, set this to Uml::id_None.
 *
 * @param viewID    ID of an UMLScene.
 */
void NoteWidget::setDiagramLink(Uml::ID::Type viewID)
{
    UMLDoc *umldoc = UMLApp::app()->document();
    UMLView *view = umldoc->findView(viewID);
    if (view == NULL) {
        uError() << "no view found for viewID " << Uml::ID::toString(viewID);
        return;
    }
    QString linkText(QLatin1String("Diagram: ") + view->umlScene()->name());
    setDocumentation(linkText);
    m_diagramLink = viewID;
    update();
}
Example #26
0
/**
 * Returns true if the UMLListViewItem of the given ID is a parent of
 * this UMLListViewItem.
 */
bool UMLListViewItem::isOwnParent(Uml::ID::Type listViewItemID)
{
    UMLListView* listView = static_cast<UMLListView*>(treeWidget());
    QTreeWidgetItem *lvi = static_cast<QTreeWidgetItem*>(listView->findItem(listViewItemID));
    if (lvi == 0) {
        uError() << "ListView->findItem(" << Uml::ID::toString(listViewItemID) << ") returns NULL";
        return true;
    }
    for (QTreeWidgetItem *self = static_cast<QTreeWidgetItem*>(this); self; self = self->parent()) {
        if (lvi == self)
            return true;
    }
    return false;
}
Example #27
0
File: xkbvleds.c Project: aosm/X11
static Display *
GetDisplay(char *program, char *dpyName)
{
int		mjr,mnr,error;
Display	*	dpy;

    mjr= XkbMajorVersion;
    mnr= XkbMinorVersion;
    dpy= XkbOpenDisplay(dpyName,&evBase,&errBase,&mjr,&mnr,&error);
    if (dpy==NULL) {
	switch (error) {
	    case XkbOD_BadLibraryVersion:
		uInformation("%s was compiled with XKB version %d.%02d\n",
				program,XkbMajorVersion,XkbMinorVersion);
		uError("X library supports incompatible version %d.%02d\n",
				mjr,mnr);
		break;
	    case XkbOD_ConnectionRefused:
		uError("Cannot open display \"%s\"\n",dpyName);
		break;
	    case XkbOD_NonXkbServer:
		uError("XKB extension not present on %s\n",dpyName);
		break;
	    case XkbOD_BadServerVersion:
		uInformation("%s was compiled with XKB version %d.%02d\n",
				program,XkbMajorVersion,XkbMinorVersion);
		uError("Server %s uses incompatible version %d.%02d\n",
				dpyName,mjr,mnr);
		break;
	    default:
		uInternalError("Unknown error %d from XkbOpenDisplay\n",error);
	}
    }
    else if (synch)
	XSynchronize(dpy,True);
    return dpy;
}
Example #28
0
/**
 * Loads from the "messagewidget" XMI element.
 */
bool MessageWidget::loadFromXMI(QDomElement& qElement)
{
    if (!UMLWidget::loadFromXMI(qElement)) {
        return false;
    }
    if (!LinkWidget::loadFromXMI(qElement)) {
        return false;
    }
    QString textid = qElement.attribute(QLatin1String("textid"), QLatin1String("-1"));
    QString widgetaid = qElement.attribute(QLatin1String("widgetaid"), QLatin1String("-1"));
    QString widgetbid = qElement.attribute(QLatin1String("widgetbid"), QLatin1String("-1"));
    m_CustomOp = qElement.attribute(QLatin1String("operation"));
    QString sequenceMessageType = qElement.attribute(QLatin1String("sequencemessagetype"), QLatin1String("1001"));
    m_sequenceMessageType = Uml::SequenceMessage::fromInt(sequenceMessageType.toInt());
    if (m_sequenceMessageType == Uml::SequenceMessage::Lost || m_sequenceMessageType == Uml::SequenceMessage::Found) {
        m_xclicked = qElement.attribute(QLatin1String("xclicked"), QLatin1String("-1")).toFloat();
        m_yclicked = qElement.attribute(QLatin1String("yclicked"), QLatin1String("-1")).toFloat();
    }

    m_widgetAId = Uml::ID::fromString(widgetaid);
    m_widgetBId = Uml::ID::fromString(widgetbid);
    m_textId = Uml::ID::fromString(textid);

    Uml::TextRole::Enum tr = Uml::TextRole::Seq_Message;
    if (m_widgetAId == m_widgetBId)
        tr = Uml::TextRole::Seq_Message_Self;

    //now load child elements
    QDomNode node = qElement.firstChild();
    QDomElement element = node.toElement();
    if (!element.isNull()) {
        QString tag = element.tagName();
        if (tag == QLatin1String("floatingtext") || tag == QLatin1String("UML::FloatingTextWidget")) {
            m_pFText = new FloatingTextWidget(m_scene, tr, operationText(m_scene), m_textId);
            m_scene->addFloatingTextWidget(m_pFText);
            if(! m_pFText->loadFromXMI(element)) {
                // Most likely cause: The FloatingTextWidget is empty.
                delete m_pFText;
                m_pFText = NULL;
            }
            else
                m_pFText->setSequenceNumber(m_SequenceNumber);
        } else {
            uError() << "unknown tag " << tag;
        }
    }
    return true;
}
Example #29
0
/**
 * Handle a controlled unit.
 *
 * @param node       Pointer to the PetalNode which may contain a controlled unit
 * @param name       Name of the current node
 * @param id         QUID of the current node
 * @param parentPkg  Pointer to the current parent UMLPackage.
 * @return      True if the node actually contained a controlled unit.
 */
bool handleControlledUnit(PetalNode *node, const QString& name, Uml::IDType id, UMLPackage * parentPkg)
{
    Q_UNUSED(id); Q_UNUSED(parentPkg);
    if (node->findAttribute("is_unit").string != "TRUE")
        return false;
    //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 (?)";
        return true;
    }
    // To Be Continued.

    return true;
}
Example #30
0
/**
 * Sets the UMLObject playing the role in the association.
 *
 * @param obj   Pointer to the UMLObject of role.
 */
void UMLRole::setObject(UMLObject *obj)
{
    // because we will get the id of this role from the parent
    // object, we CANT allow UMLRoles to take other UMLRoles as
    // parent objects. In fact, there is probably good reason
    // to only take UMLClassifiers here, but I'll leave it more open
    // for the time being. -b.t.
    if (obj && obj->asUMLRole()) {
        uError() << "UMLRole(" << Uml::ID::toString(m_nId) << ") cannot setObject() to another UMLRole("
            << Uml::ID::toString(obj->id()) << ")";
        return;
    }

    m_pSecondary = obj;
    UMLObject::emitModified();
}