Ejemplo n.º 1
0
static int check_adds(trie_dict *t, string word, int edits, rb_tree *suggs){
  int i, j;
  char c, ch;
  string tmp;
  tmp.len = word.len+1;
  tmp.str = alloca(tmp.len);
  for(i=0;i<=word.len;i++){
/*
  I might be off on the indexing here
*/
    trie_dict_node *node = trie_dict_lookup_node(t, word.mem, i);
    if(!node){
      continue;
    }
    memcpy(tmp.str, word.str, i);
    memcpy(tmp.str + i + 1, word.str + i, word.len - i);
    for(j=0;j<52;j++){
      tmp.str[i] = eng_alphabet[j];
      if(trie_dict_lookup(node->children[j], word.mem + i,
                          word.len - i)){
        add_suggestion(suggs, tmp);
      }
      check_edits(t, tmp, edits-1, suggs);
    }
  }
  return 0;
}
Ejemplo n.º 2
0
void BasicDialog::accept() {
  if (!check_edits(edits) || !kvtable->check_unique())
    return;
    
  BrowserNode * bn = data->get_browser_node();

  if (edname != 0) {
    QString s = edname->text().stripWhiteSpace();

    if ((s != bn->get_name()) &&
	((BrowserNode *) bn->parent())->wrong_child_name(s, bn->get_type(),
							 bn->allow_spaces(),
							 bn->allow_empty())) {
      msg_critical(TR("Error"), edname->text() + TR("\n\nillegal name or already used"));
      return;
    }
    else
      bn->set_name(s);
  }

  bool newst = data->set_stereotype(fromUnicode(edstereotype->currentText().stripWhiteSpace()));
  
  bn->set_comment(comment->text());
  UmlWindow::update_comment_if_needed(bn);
    
  kvtable->update(bn);
  
  ProfiledStereotypes::modified(bn, newst);
  
  bn->package_modified();
  data->modified();
    
  Q3TabDialog::accept();
}
Ejemplo n.º 3
0
static int check_subs(trie_dict *t, string word, int edits, rb_tree *suggs){
  int i, j;
  char c, ch;
  string tmp;
  tmp.len = word.len;
  tmp.str = alloca(tmp.len);
  memcpy(tmp.mem, word.mem, word.len);
  for(i=0;i<word.len;i++){
    trie_dict_node *node = trie_dict_lookup_node(t, word.mem, i);
    if(!node){
      continue;
    }
    ch = word.str[i];
    for(j=0;j<52;j++){
      if(ch == eng_alphabet[j]){continue;}
      tmp.str[i] = eng_alphabet[j];
      if(trie_dict_lookup(node->children[j], word.mem + (i+1),
                          word.len - (i+1))){
        add_suggestion(suggs, tmp);
      }
      check_edits(t, tmp, edits-1, suggs);
    }
    tmp.str[i] = ch;
  }
  return 0;
}
Ejemplo n.º 4
0
void PseudoStateDialog::accept()
{
    if (!check_edits(edits) || !kvtable->check_unique())
        return;

    QString s = edname->text().stripWhiteSpace();
    BrowserPseudoState * bn = (BrowserPseudoState *) pst->browser_node;

    if ((s != bn->get_name()) &&
        ((BrowserNode *) bn->parent())->wrong_child_name(s, UmlPseudoState,
                bn->allow_spaces(),
                bn->allow_empty())) {
        msg_critical(TR("Error"), edname->text() + TR("\n\nillegal name or already used"));
        return;
    }
    else
        bn->set_name(s);

    bool newst = pst->set_stereotype(fromUnicode(edstereotype->currentText().stripWhiteSpace()));

    bn->set_comment(comment->text());
    UmlWindow::update_comment_if_needed(bn);

    kvtable->updateNodeFromThis(bn);

    if (edreference != 0) {
        int index = reflist.findIndex(edreference->currentText());
        BrowserPseudoState * ps;

        if (index != -1) {
            ps = (BrowserPseudoState *) pseudostates.at(index);

            if (! bn->can_reference(ps))
                ps = 0;
        }
        else
            ps = 0;

        pst->set_reference(ps);
    }

    ProfiledStereotypes::modified(bn, newst);

    bn->modified();
    bn->package_modified();
    pst->modified();

    Q3TabDialog::accept();
}
Ejemplo n.º 5
0
void ActivityDialog::accept()
{
    if (!check_edits(edits) || !kvtable->check_unique())
        return;

    BrowserNode * bn = activity->browser_node;
    QString s;

    s = edname->text().trimmed();

    if ((s != bn->get_name()) &&
            ((BrowserNode *) bn->parent())->wrong_child_name(s, UmlActivity,
                                                             bn->allow_spaces(),
                                                             bn->allow_empty()))
        msg_critical(tr("Error"), s + tr("\n\nillegal name or already used"));
    else {
        bn->set_name(s);

        bool newst = activity->set_stereotype(fromUnicode(edstereotype->currentText().trimmed()));
        int index = list.indexOf(edspecification->currentText().trimmed());

        activity->set_specification((index != -1)
                                    ? (BrowserOperation *) opers.at(index)
                                    : 0);

        activity->read_only = readonly_cb->isChecked();
        activity->single_execution = singlexec_cb->isChecked();
        activity->is_active = active_cb->isChecked();

        uml.accept(activity->uml_condition);
        cpp.accept(activity->cpp_condition);
        java.accept(activity->java_condition);

        bn->set_comment(comment->text());
        UmlWindow::update_comment_if_needed(bn);

        activity->constraint = constraint->trimmedText();

        kvtable->updateNodeFromThis(bn);

        ProfiledStereotypes::modified(bn, newst);

        bn->modified();
        bn->package_modified();
        activity->modified();

        TabDialog::accept();
    }
}
Ejemplo n.º 6
0
/*
  Potential optimization, have a static variable for a freelist of rbtree nodes
*/
int trie_check_word(trie_dict *t, string word, FILE *out, int n_edits){
  char *tmp = string_to_cstra(word);
  //  DEBUG_PRINTF("Checking %s\n", tmp);
  if(trie_dict_lookup(t, word.mem, word.len)){
    fprintf(out, "correct: %s\n", tmp);
  } else {
    rb_tree *suggs = make_empty_rbtree((int(*)(void*,void*))string_ptr_cmp);
    fprintf(out, "incorrect: %s\n", tmp);
    check_edits(t, word, n_edits, suggs);
    fprintf(out, "suggestions:\n");
    rb_traverse(suggs, out, output_suggest_visit);
    fprintf(out, "\t----\n");
    destroy_rbtree_custom(suggs, free);
  }
  return 0;
}
Ejemplo n.º 7
0
void ActivityObjectDialog::accept()
{
    if (!check_edits(edits))
        return;

    BrowserNode * bn = data->browser_node;
    QString s = edname->text().stripWhiteSpace();

    bn->set_name(s);

    bool newst = data->set_stereotype(fromUnicode(edstereotype->currentText().stripWhiteSpace()));
    AType t;

    s = edtype->currentText().stripWhiteSpace();

    if (!s.isEmpty()) {
        int index = list.findIndex(s);

        if (index >= 0)
            t.type = (BrowserClass *) nodes.at(index);
        else
            t.explicit_type = s;
    }

    data->set_type(t);
    data->multiplicity =
        edmultiplicity->currentText().stripWhiteSpace();
    data->ordering = ordering(edordering->currentText());
    data->is_control = is_control_cb->isChecked();
    data->in_state = edin_state->text().stripWhiteSpace();
    data->uml_selection = eduml_selection->text().stripWhiteSpace();
    data->cpp_selection = edcpp_selection->text().stripWhiteSpace();
    data->java_selection = edjava_selection->text().stripWhiteSpace();

    bn->set_comment(comment->text());
    UmlWindow::update_comment_if_needed(bn);

    kvtable->updateNodeFromThis(bn);

    ProfiledStereotypes::modified(bn, newst);

    bn->modified();
    bn->package_modified();
    data->modified();

    Q3TabDialog::accept();
}
Ejemplo n.º 8
0
void TransitionDialog::accept()
{
    if (!check_edits(edits) || !kvtable->check_unique())
        return;

    BrowserNode * bn = rel->browser_node;
    QString s;

    s = edname->text().trimmed();

    if (s.isEmpty())
        s = "<transition>";

    if ((s != bn->get_name()) &&
        ((BrowserNode *) bn->parent())->wrong_child_name(s, UmlTransition,
                bn->allow_spaces(),
                bn->allow_empty()))
        msg_critical(tr("Error"), s + tr("\n\nillegal name or already used"));
    else {
        bn->set_name(s);

        bool newst = rel->set_stereotype(fromUnicode(edstereotype->currentText().trimmed()));

        if (internal_cb != 0)
            rel->set_internal(internal_cb->isChecked());

        uml.accept(rel->uml);
        cpp.accept(rel->cpp);
        java.accept(rel->java);

        bn->set_comment(comment->text());
        UmlWindow::update_comment_if_needed(bn);

        kvtable->updateNodeFromThis(bn);

        ProfiledStereotypes::modified(bn, newst);

        bn->modified();
        bn->package_modified();
        rel->modified();

        TabDialog::accept();
    }
}
Ejemplo n.º 9
0
void ParameterSetDialog::accept()
{
    if (!check_edits(edits) || !kvtable->check_unique())
        return;

    QString s = edname->text().stripWhiteSpace();
    BrowserParameterSet * bn =
        (BrowserParameterSet *) data->get_browser_node();

    if ((s != bn->get_name()) &&
        ((BrowserNode *) bn->parent())->wrong_child_name(s, bn->get_type(),
                bn->allow_spaces(),
                bn->allow_empty()))
        msg_critical(TR("Error"), edname->text() + TR("\n\nillegal name or already used"));
    else {
        bn->set_name(s);
        bn->set_comment(comment->text());
        UmlWindow::update_comment_if_needed(bn);

        QString stereotype =
            fromUnicode(edstereotype->currentText().stripWhiteSpace());
        bool newst = data->set_stereotype(stereotype);
        Q3ValueList<BrowserPin *> l;
        unsigned n = lb_member->count();

        for (unsigned i = 0; i != n; i += 1)
            l.append((BrowserPin *)
                     (((ListBoxBrowserNode *) lb_member->item(i))
                      ->browser_node));

        data->set_pins(l);

        kvtable->updateNodeFromThis(bn);

        ProfiledStereotypes::modified(bn, newst);

        bn->modified();
        bn->package_modified();
        data->modified();

        Q3TabDialog::accept();
    }
}
Ejemplo n.º 10
0
static int check_dels(trie_dict *t, string word, int edits, rb_tree *suggs){
  int i, j;
  char c, ch;
  string tmp;
  tmp.len = word.len-1;
  tmp.str = alloca(tmp.len);
//it may be possible to optimize this using the trie, But it doesn't seem
//like it'd be worth it
  for(i=0;i<word.len;i++){
    memcpy(tmp.str, word.str, i);
    memcpy(tmp.str + i, word.str + i + 1, word.len - (i+1));
    if(trie_dict_lookup(t, tmp.mem, tmp.len)){
      //      DEBUG_PRINTF("adding suggestion (del) %.*s\n", (int)tmp.len, tmp.str);
      add_suggestion(suggs, tmp);
    }
    check_edits(t, tmp, edits-1, suggs);
  }
  return 0;
}
Ejemplo n.º 11
0
void SimpleRelationDialog::accept() {
  if (!check_edits(edits) || !kvtable->check_unique())
    return;
    
  BrowserNode * bn = rel->get_browser_node();
  bool newst = rel->set_stereotype(fromUnicode(edstereotype->currentText().stripWhiteSpace()));
  
  bn->set_comment(comment->text());
  UmlWindow::update_comment_if_needed(bn);
  
  kvtable->update(bn);
  
  ProfiledStereotypes::modified(bn, newst);
  
  bn->package_modified();
  rel->modified();
  
  QTabDialog::accept();
}
Ejemplo n.º 12
0
void ExpansionRegionDialog::accept()
{
    if (!check_edits(edits) || !kvtable->check_unique())
        return;

    BrowserNode * bn = data->get_browser_node();

    if (edname != 0) {
        QString s = edname->text().trimmed();

        if ((s != bn->get_name()) &&
                ((BrowserNode *) bn->parent())->wrong_child_name(s, bn->get_type(),
                        bn->allow_spaces(),
                        bn->allow_empty())) {
            msg_critical(TR("Error"), edname->text() + TR("\n\nillegal name or already used"));
            return;
        }
        else
            bn->set_name(s);
    }

    data->must_isolate = must_isolate_cb->isChecked();
    data->mode = expansion_mode_kind(edmode->currentText().toLatin1().constData());

    bool newst = data->set_stereotype(fromUnicode(edstereotype->currentText().trimmed()));

    bn->set_comment(comment->text());
    UmlWindow::update_comment_if_needed(bn);

    kvtable->updateNodeFromThis(bn);

    ProfiledStereotypes::modified(bn, newst);

    bn->package_modified();
    data->modified();

    TabDialog::accept();
}
Ejemplo n.º 13
0
void FlowDialog::accept()
{
    if (!check_edits(edits) || !kvtable->check_unique())
        return;

    BrowserNode * bn = flow->browser_node;
    QString s;

    s = edname->text().stripWhiteSpace();

    if ((s != bn->get_name()) &&
        ((BrowserNode *) bn->parent())->wrong_child_name(s, UmlFlow,
                bn->allow_spaces(),
                bn->allow_empty()))
        msg_critical(TR("Error"), s + TR("\n\nillegal name or already used"));
    else {
        bn->set_name(s);

        bool newst = flow->set_stereotype(fromUnicode(edstereotype->currentText().stripWhiteSpace()));

        uml.accept(flow->uml);
        cpp.accept(flow->cpp);
        java.accept(flow->java);

        bn->set_comment(comment->text());
        UmlWindow::update_comment_if_needed(bn);

        kvtable->updateNodeFromThis(bn);

        ProfiledStereotypes::modified(bn, newst);

        bn->modified();
        bn->package_modified();
        flow->modified();

        Q3TabDialog::accept();
    }
}
Ejemplo n.º 14
0
void ParameterDialog::accept()
{
    if (!check_edits(edits) || !kvtable->check_unique())
        return;

    BrowserNode * bn = param->browser_node;
    QString s;

    s = edname->text().trimmed();

    if ((s != param->name()) &&
            ((BrowserNode *) bn->parent())->wrong_child_name(s, UmlParameter,
                                                             bn->allow_spaces(),
                                                             bn->allow_empty()))
        msg_critical(tr("Error"), s + tr("\n\nillegal name or already used"));
    else {
        // check consistency
        UmlParamDirection dir = direction(eddir->currentText());
        bool exception = exception_rb->isChecked();
        UmlParamEffect effect = ::effect(edeffect->currentText());
        QString err;

        if ((dir == UmlIn) && exception)
            err = tr("An input parameter cannot be an exception.\n");

        switch (effect) {
        case UmlDelete:
            if ((dir != UmlIn) && (dir != UmlInOut))
                err += tr("Only in and inout parameter may have a delete effect.");

            break;

        case UmlCreate:
            if ((dir != UmlOut) && (dir != UmlInOut) && (dir != UmlReturn))
                err += tr("Only out, inout and return parameter may have a create effect.");

            break;

        default:
            break;
        }

        if (!err.isEmpty())
            msg_critical(tr("Error"), err);
        else {
            bn->set_name(s);

            bool newst = param->set_stereotype(fromUnicode(edstereotype->currentText().trimmed()));
            AType t;

            s = edtype->currentText().trimmed();

            if (!s.isEmpty()) {
                int index = list.indexOf(s);

                if (index >= 0)
                    t.type = (BrowserClass *) nodes.at(index);
                else
                    t.explicit_type = s;
            }

            param->set_type(t);
            param->dir = dir;
            param->multiplicity =
                    edmultiplicity->currentText().trimmed();
            param->ordering = ordering(edordering->currentText().toLatin1());
            param->effect = effect;
            param->is_control = is_control_cb->isChecked();
            param->unique = unique_cb->isChecked();
            param->exception = exception;
            param->stream = stream_rb->isChecked();
            param->in_state = edin_state->text().trimmed();
            param->default_value = edinit->text();
            param->uml_selection = eduml_selection->text().trimmed();
            param->cpp_selection = edcpp_selection->text().trimmed();
            param->java_selection = edjava_selection->text().trimmed();

            bn->set_comment(comment->text());
            UmlWindow::update_comment_if_needed(bn);

            kvtable->updateNodeFromThis(bn);

            ProfiledStereotypes::modified(bn, newst);

            bn->modified();
            bn->package_modified();
            param->modified();

            TabDialog::accept();
        }
    }
}