BrowserNode * BrowserClassInstance::duplicate(BrowserNode * p, const QString & name) { BrowserClassInstance * result = new BrowserClassInstance(this, p); result->set_name((name.isEmpty()) ? get_name() : name); result->update_stereotype(); return result; }
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; }
bool ClassInstanceData::tool_cmd(ToolCom * com, const char * args, BrowserNode * bn, const QString & comment) { if (((unsigned char) args[-1]) >= firstSetCmd) { if (!bn->is_writable() && !root_permission()) com->write_ack(FALSE); else { switch ((unsigned char) args[-1]) { case setTypeCmd: set_class((BrowserClass *) com->get_id(args)); break; case setAttributeCmd: { BrowserAttribute * at = (BrowserAttribute *) com->get_id(args); bool find = FALSE; Q3ValueList<SlotAttr>::Iterator it_attr; for (it_attr = attributes.begin(); it_attr != attributes.end(); ++it_attr) { SlotAttr & slot_attr = *it_attr; if (slot_attr.att == at) { find = TRUE; if (*args == 0) // remove it attributes.remove(it_attr); else // replace it slot_attr.value = args; break; } } if (! find) { // add it Q3PtrList<BrowserClass> l; cl->get_all_parents(l); l.append(cl); if (at->deletedp() || (l.findRef((BrowserClass *) at->parent()) == -1)) { // illegal com->write_ack(FALSE); return TRUE; } attributes.append(SlotAttr(at, args)); } } break; case addRelationCmd: if (! change_rel(com, args, TRUE)) return TRUE; break; case removeRelationCmd: if (! change_rel(com, args, FALSE)) return TRUE; break; default: return BasicData::tool_cmd(com, args, bn, comment); } // ok case bn->modified(); modified(); com->write_ack(TRUE); } } else { switch ((unsigned char) args[-1]) { case attributesCmd: if (args[0] == 0) { com->write_unsigned(attributes.count()); Q3ValueList<SlotAttr>::Iterator it; for (it = attributes.begin(); it != attributes.end(); ++it) { const SlotAttr & slot = *it; slot.att->write_id(com); com->write_string(slot.value); } } else { // get all available attributes BrowserNodeList l; BrowserNode * bn; cl->get_attrs(l); com->write_unsigned(l.count()); for (bn = l.first(); bn != 0; bn = l.next()) bn->write_id(com); } break; case relationsCmd: { BrowserClassInstance * other = (BrowserClassInstance *) com->get_id(args); if (other == 0) { com->write_unsigned(relations.count()); Q3ValueList<SlotRel>::Iterator it; for (it = relations.begin(); it != relations.end(); ++it) { const SlotRel & slot = *it; ((slot.is_a) ? slot.rel->get_start() : slot.rel->get_end()) ->write_id(com); slot.value->write_id(com); } } else { // get all available relations Q3PtrList<BrowserRelation> l; BrowserRelation * r; cl->get_rels(((ClassInstanceData *)other->get_data())->cl, l); com->write_unsigned(l.count()); for (r = l.first(); r != 0; r = l.next()) r->write_id(com); } } break; default: return BasicData::tool_cmd(com, args, bn, comment); } } return TRUE; }
OdClassInstCanvas * OdClassInstCanvas::read(char * & st, UmlCanvas * canvas, char * k) { if (!strcmp(k, "classinstance_ref")) return ((OdClassInstCanvas *) dict_get(read_id(st), "classinstance", canvas)); else if (!strcmp(k, "classinstance")) { // old release int id = read_id(st); BrowserClass * cl = BrowserClass::read_ref(st); k = read_keyword(st); UmlColor co = UmlDefaultColor; read_color(st, "color", co, k); // updates k Uml3States ho; if (!strcmp(k, "write_horizontally") || !strcmp(k, "write_horizontaly")) { ho = state(read_keyword(st)); k = read_keyword(st); } else ho = UmlDefaultState; if (strcmp(k, "xyz")) wrong_keyword(k, "xyz"); int x = (int) read_double(st); int y = (int) read_double(st); double z = read_double(st); read_keyword(st, "name"); BrowserNode * parent = canvas->browser_diagram()->container(UmlClass); BrowserClassInstance * icl = // create a new one, don't look at already exising instances // contrarilly to the collaboration and sequence diagram // because of attributes & relations new BrowserClassInstance(read_string(st), cl, parent); OdClassInstCanvas * result = new OdClassInstCanvas(icl, canvas, x, y, id); result->setZ(z); result->itscolor = co; result->write_horizontally = ho; result->show_context_mode = noContext; k = read_keyword(st); if (!strcmp(k, "values")) ((ClassInstanceData *) icl->get_data())->read_attributes(st, k); // updates k else if (strcmp(k, "end") && strcmp(k, "xyz")) wrong_keyword(k, "end or xyz"); if (*k == 'x') read_xyz(st, result); result->compute_size(); result->set_center100(); result->show(); // to save new instance and diagram def result->package_modified(); canvas->browser_diagram()->modified(); return result; } else if (!strcmp(k, "classinstancecanvas")) { int id = read_id(st); BrowserClassInstance * icl = BrowserClassInstance::read_ref(st); read_keyword(st, "xyz"); int x = (int) read_double(st); OdClassInstCanvas * result = new OdClassInstCanvas(icl, canvas, x, (int) read_double(st), id); result->setZ(read_double(st)); result->ClassInstCanvas::read(st, k); if (read_file_format() < 74) result->show_context_mode = noContext; result->read_stereotype_property(st, k); // updates k if (strcmp(k, "end")) wrong_keyword(k, "end"); if (result->get_type() != 0) { // not a deleted instance result->compute_size(); result->set_center100(); result->show(); result->check_stereotypeproperties(); } return result; } else return 0; }