#include "UmlRelation.h"
#include "FileOut.h"
#include "UmlClass.h"
bool UmlRelation::write_if_needed(FileOut & out) {
// class already generated
switch (relationKind()) {
case aGeneralisation:
case aRealization:
write_generalization(out);
break;
case aDependency:
write_dependency(out);
break;
default:
// don't generate them for actors
{
UmlItem * p = parent();
do {
p = p->parent();
} while (p->kind() == aClass);
if (p->kind() == aClassView)
write_relation(out);
}
break;
}
return TRUE;
}
void UmlRelation::write_generalization(FileOut & out) {
out.indent();
out << "\n";
out.indent();
out << "\t";
parent()->ref(out);
out << "\n";
out.indent();
out << "\t";
roleType()->ref(out);
out << "\n";
out.indent(+1);
write_stereotype(out);
write_description_properties(out);
out.indent(-1);
out.indent();
out << "\n";
}
void UmlRelation::write_dependency(FileOut & out) {
out.indent();
out << "\n";
out.indent(+1);
write_stereotype(out);
write_description_properties(out);
out.indent(-1);
out.indent();
out << "\n";
}
void UmlRelation::write_relation(FileOut & out) {
if (side(TRUE) != this)
return;
out.indent();
out << ")"))
out << " name=\"" << name() << '"';
out.id(this);
out << ">\n";
out.indent();
out << "\t\n";
write_relation(out, anAssociation);
UmlRelation * other = side(FALSE);
if (other != 0)
other->write_relation(out, relationKind());
else {
out.indent();
out << "\t\t\n";
out.indent();
out << "\t\t\t\n";
out.indent();
out << "\t\t\t\t";
parent()->ref(out);
out << '\n';
out.indent();
out << "\t\t\t\n";
out.indent();
out << "\t\t\n";
}
out.indent();
out << "\t\n";
out.indent();
out << "\n";
}
void UmlRelation::write_relation(FileOut & out, aRelationKind k) {
out.indent();
out << "\t\t\n";
if (!multiplicity().isEmpty()) {
QCString min;
QCString max;
int index = multiplicity().find("..");
if (index != -1) {
min = multiplicity().left(index).stripWhiteSpace();
max = multiplicity().mid(index+2).stripWhiteSpace();
}
else
min = max = multiplicity().stripWhiteSpace();
if (min == "*")
min = "0";
if (max == "*")
max = "-1";
out.indent();
out << "\t\t\t\n";
out.indent();
out << "\t\t\t\t\n";
out.indent();
out << "\t\t\t\t\t\n";
out.indent();
out << "\t\t\t\t\t\t\n";
out.indent();
out << "\t\t\t\t\t\n";
out.indent();
out << "\t\t\t\t\n";
out.indent();
out << "\t\t\t\n";
}
out.indent();
out << "\t\t\t\n";
out.indent();
out << "\t\t\t\t";
roleType()->ref(out);
out << '\n';
out.indent();
out << "\t\t\t\n";
out.indent(+3);
write_stereotype(out);
write_annotation(out);
write_description_properties(out);
out.indent(-3);
out.indent();
out << "\t\t\n";
}