Example #1
0
void RelTable::init_row(const SlotRel & sr, int row, QString a, bool visit)
{
    QString b = sr.value->get_name() + QString(":") +
            ((ClassInstanceData *) sr.value->get_data())->get_class()->get_name();

    setItem(row, 0, new TableItem(this, TableItem::Never,
                                  (sr.is_a) ? a : b, TableItem::TableItemType));

    RelationData * d = sr.rel;
    const char * s;

    s = d->get_role_b();
    setItem(row, 1, new TableItem(this, TableItem::Never, (s == 0) ? "" : s, TableItem::TableItemType));

    setItem(row, 2, new TableItem(this, TableItem::Never, stringify(d->get_type()), TableItem::TableItemType));

    s = d->get_role_a();
    setItem(row, 3, new TableItem(this, TableItem::Never, (s == 0) ? "" : s, TableItem::TableItemType));

    setItem(row, 4, new TableItem(this, TableItem::Never,
                                  (sr.is_a) ? b : a, TableItem::TableItemType));

    if (! visit)
        setText(row, 5, "");
}
Example #2
0
bool ClassInstanceData::change_rel(ToolCom * com, const char * args,
                                   bool isadd)
{
    com->get_unsigned(args); // 2

    BrowserRelation * r = (BrowserRelation *) com->get_id(args);
    BrowserClassInstance * other = (BrowserClassInstance *) com->get_id(args);

    if (r->deletedp() || other->deletedp()) {
        com->write_ack(FALSE);
        return FALSE;
    }

    RelationData * rd = (RelationData *) r->get_data();
    Q3ValueList<SlotRel>::Iterator it;

    for (it = relations.begin(); it != relations.end(); ++it) {
        const SlotRel & slot_rel = *it;

        if ((slot_rel.value == other) &&
            (r == ((slot_rel.is_a) ? rd->get_start() : rd->get_end())))
            break;
    }

    if (isadd) {
        if (it == relations.end()) {
            // not yet present
            QList<BrowserRelation *> l;

            cl->get_rels(((ClassInstanceData *)other->get_data())->cl, l);

            if ((! l.contains(r)) ||
                (!other->is_writable() && !root_permission())) {
                // illegal
                com->write_ack(FALSE);
                return FALSE;
            }

            // add it
            if (rd->is_a(r))
                add(other, rd);
            else
                ((ClassInstanceData *)other->get_data())
                ->add((BrowserClassInstance *) browser_node, rd);
        }
    }
    else if (it != relations.end()) {
        // remove it
        if (!other->is_writable() && !root_permission()) {
            // illegal
            com->write_ack(FALSE);
            return FALSE;
        }

        replace(other, rd, 0, (*it).is_a, 0);
    }

    return TRUE;
}
Example #3
0
void RelationData::delete_unconsistent()
{
    while (! Unconsistent.isEmpty()) {
        RelationData * d = Unconsistent.take(0);

        d->start = d->end = 0;

        if (!d->deletedp())
            d->BasicData::delete_it();

        delete d;
    }
}
Example #4
0
void ClassInstanceData::check_rels()
{
    bool modif = FALSE;
    Q3ValueList<SlotRel>::Iterator it_rel = relations.begin();

    while (it_rel != relations.end()) {
        const SlotRel & slot_rel = *it_rel;
        BasicData * d = slot_rel.value->get_data();
        bool remove = slot_rel.value->deletedp();

        if (!remove) {
            RelationData * rd = (RelationData *) slot_rel.rel;
            BrowserClass * other = (slot_rel.is_a)
                                   ? rd->get_end_class() : rd->get_start_class();
            BrowserClass * cl = ((ClassInstanceData *) d)->get_class();

            if (cl == 0) {
                // instance doesn't exist
                // note : its brower_node will be deleted
                remove = TRUE;
            }
            else if (cl != other) {
                QList<BrowserClass *> l;

                cl->get_all_parents(l);
                remove |= (! l.contains(other));
            }
        }

        if (remove) {
            it_rel = relations.remove(it_rel);
            modif = TRUE;
        }
        else
            ++it_rel;
    }

    if (modif)
        modified();
}
Example #5
0
RelationData * RelationData::read_ref(char *& st, bool complete,
                                      const char * k)
{
    if (k == 0)
        read_keyword(st, "relation_ref");
    else if (strcmp(k, "relation_ref"))
        wrong_keyword(k, "relation_ref");

    int id = read_id(st);
    RelationData * result = all[id];

    if (result == 0) {
        result = new RelationData(UmlRelations/*!!*/, id);

        if (complete) {
            // must create a valid temporary relation
            result->SetStart(BrowserRelation::temporary(result));
            result->SetEnd(BrowserRelation::temporary(result));
        }
    }

    return result;
}
Example #6
0
RelationData::RelationData(const BrowserRelation * model,
                           BrowserRelation * r)
    : ClassMemberData((ClassMemberData *) model->get_data()),
      Labeled<RelationData>(all, 0), is_deleted(FALSE), is_unconsistent(FALSE)
{
    RelationData * md = (RelationData *) model->get_data();

    type = md->type;
    name = md->name;
    a = md->a;
    b = md->b;
    set_association(md->association);
    original_id = 0;

    if (md->start == model) {
        start = r;

        if (md->end_removed_from == 0) {
            // bi dir, self to model became self to r
            end = new BrowserRelation((md->get_end_class() == (BrowserClass *) model->parent())
                                      ? (BrowserClass *) r->parent() : md->get_end_class(),
                                      this);
            end_removed_from = 0;
        }
        else {
            // uni dir
            end = 0;
            end_removed_from = (md->end_removed_from == (BrowserClass *) model->parent())
                               ? (BrowserClass *) r->parent() : md->end_removed_from;
            connect(end_removed_from->get_data(), SIGNAL(deleted()),
                    this, SLOT(end_deleted()));
        }
    }
    else {
        // bi dir, self to model became self to r
        end = r;
        start = new BrowserRelation((md->get_start_class() == (BrowserClass *) model->parent())
                                    ? (BrowserClass *) r->parent() : md->get_start_class(),
                                    this);
        end_removed_from = 0;
    }

    if (get_start_class() == md->get_start_class())
        // to not have two times the same role name
        a.role = 0;

    if ((end != 0) && (get_end_class() == md->get_end_class()))
        // to not have two times the same role name
        b.role = 0;
}
Example #7
0
RelationData * RelationData::read(char *& st, char *& k,
                                  BrowserRelation *& unconsistent)
{
    unconsistent = 0;

    RelationData * result;
    int id;

    if (!strcmp(k, "relation_ref")) {
        if ((result = all[id = read_id(st)]) == 0)
            result = new RelationData(UmlRelations/*!!*/, id);

        k = read_keyword(st);
        return result;
    }
    else if (!strcmp(k, "relation")) {
        if ((result = all[id = read_id(st)]) == 0)
            result = new RelationData(relation_type(read_keyword(st)), id);
        else if (result->type != UmlRelations) {
            // shared identifier
            result->set_unconsistent();
            unconsistent = result->start;
            result = new RelationData(relation_type(read_keyword(st)), id);
            result->set_unconsistent();
        }
        else {
            result->type = relation_type(read_keyword(st));
            result->name = default_name(result->type);

            if (result->start != 0) {
                // Created by RelationData::read_ref()
                // invalidate start/end to not delete result
                // when start/end will be deleted
                result->start->invalidate();
                result->end->invalidate();
            }
        }

        k = read_keyword(st);

        if (!strcmp(k, "name")) {
            result->name = read_string(st);
            k = read_keyword(st);
        }

        result->BasicData::read(st, k);	// updates k

        if (in_lib_import()) {
            result->original_id = id;

            if (! strcmp(k, "oid")) {
                // a sub lib is imported as a part of the imported lib
                (void) read_id(st);
                k = read_keyword(st);
            }
        }
        else if (! strcmp(k, "oid")) {
            result->original_id = read_id(st);
            k = read_keyword(st);
        }

        bool assoc = isa_association(result->type);

        if (strcmp(k, "a"))
            wrong_keyword(k, "a");

        read_role(result->a, assoc, st, k, result);		// updates k
        result->start = BrowserRelation::read_ref(st, k);

        read_keyword(st, "b");

        if (!RelationData::uni_directional(result->type)) {
            read_role(result->b, assoc, st, k, result);	// updates k
            result->end = BrowserRelation::read_ref(st, k);
            // 'end' may be read before 'start' : relation's type was unknown
            result->end->set_name(0);
            result->end->set_name(result->name);
        }
        else {
            k = read_keyword(st);

            if (!strcmp(k, "multiplicity")) {
                result->b.multiplicity = read_string(st);
                k = read_keyword(st);
            }
            else
                result->b.multiplicity = 0;

            if (strcmp(k, "parent"))
                wrong_keyword(k, "parent");

            result->end_removed_from = BrowserClass::read_ref(st);
            result->b.uml_visibility =
                ((BrowserNode *) result->end_removed_from->parent())->get_visibility(UmlRelations);
            connect(result->end_removed_from->get_data(), SIGNAL(deleted()),
                    result, SLOT(end_deleted()));
            result->end = 0;

            // manage old declarations
            switch (result->type) {
            case UmlRealize:
            case UmlGeneralisation:
                if (result->a.cpp_decl == "Generated")
                    result->a.cpp_decl = "${type}";

                if (result->a.java_decl == "Generated")
                    result->a.java_decl = "${type}";

                if (result->a.idl_decl == "Generated")
                    result->a.idl_decl = "${type}";

                break;

            case UmlDependency:
                if (!result->a.cpp_decl.isEmpty()) {
                    if (result->stereotype == "friend")
                        result->a.cpp_decl = "${type}";
                    else if ((result->a.cpp_decl == "Generated") ||
                             (result->a.cpp_decl == "${type}"))
                        result->a.cpp_decl = "#include in header";
                    else if ((result->a.cpp_decl == "#include in source") &&
                             (read_file_format() < 56))
                        IncludeToHeaderIfExternal.append(result);
                }

                break;

            default:
                break;
            }
        }

        k = read_keyword(st);

        AType t;

        if (!strcmp(k, "association_type") ||
            !strcmp(k, "association_explicit_type")) {
            t.read(st, "association_type", "association_explicit_type", k);
            result->set_association(t);
            k = read_keyword(st);
        }

        return result;
    }
    else
        return 0;
}
Example #8
0
void UcClassCanvas::draw_all_depend_gene(UcClassCanvas * end) {
  Q3ListViewItem * child;
  Q3CanvasItemList all = canvas()->allItems();
  Q3CanvasItemList::Iterator cit;
  
  for (child = browser_node->firstChild(); child; child = child->nextSibling()) {
    if (dependencyOrGeneralization(((BrowserNode *) child)->get_type()) &&
	!((BrowserNode *) child)->deletedp()) {
      RelationData * def =
	((RelationData *) ((BrowserNode *) child)->get_data());

      if ((def->get_start_class() == browser_node) && 	// rel begins by this
	  ((end == 0) || (def->get_end_class() == end->browser_node)) &&
	  !has_relation(def)) {
	// adds it in case the other class is drawn
	BrowserClass * end_class = 
	  ((BrowserClass *) def->get_end_class());
	DiagramItem * di;
	
	if (end_class == browser_node)
	  di = this;
	else {	
	  di = 0;
	  for (cit = all.begin(); cit != all.end(); ++cit) {
	    DiagramItem * adi = QCanvasItemToDiagramItem(*cit);
	    
	    if ((adi != 0) &&		// an uml canvas item
		(adi->type() == UmlClass) &&
		(((UcClassCanvas *) adi)->browser_node == end_class) &&
		((((UcClassCanvas *) adi) == end) || (*cit)->visible())) {
	      // other class canvas find
	      di = adi;
	      break;
	    }
	  }
	}
	
	if (di != 0)
	  (new RelationCanvas(the_canvas(), this, di,
			      ((BrowserClass *) browser_node), 
			      def->get_type(), 0, -1.0, -1.0, def))
	    ->show();
      }
    }
  }
  
  if ((end == 0) &&
      !DrawingSettings::just_modified() &&
      !on_load_diagram()) {
    for (cit = all.begin(); cit != all.end(); ++cit) {
      DiagramItem * di = QCanvasItemToDiagramItem(*cit);
      
      if ((di != 0) &&	// an uml canvas item
	  (di->type() == UmlClass) &&
	  (((UcClassCanvas *) di) != this) &&
	  !((UcClassCanvas *) di)->browser_node->deletedp() &&
	  ((UcClassCanvas *) di)->visible())
	((UcClassCanvas *) di)->draw_all_depend_gene(this);
    }
  }
}