Example #1
0
void StateDiagramView::mousePressEvent(QMouseEvent * e)
{
    QPoint diagramPoint(e->x(), e->y());
    QPointF scenePoint = mapToScene(diagramPoint);
    if (!window()->frozen()) {
        UmlCode action = window()->buttonOn();

        switch (action) {
        case UmlState: {
            history_protected = TRUE;
            unselect_all();
            window()->selectOn();
            history_save();

            QGraphicsItem * ci = the_canvas()->collision(scenePoint.toPoint());
            DiagramItem * di;
            bool specified = ((ci != 0) &&
                              ((di = QCanvasItemToDiagramItem(ci)) != 0) &&
                              (di->typeUmlCode() == UmlState) &&
                              ((BrowserState *)((StateCanvas *) di)->get_bn())->may_contains(action));
            BrowserNode * parent;

            if (specified) {
                if ((parent = ((StateCanvas *) di)->pointed_region(scenePoint.toPoint())) == 0)
                    parent = ((StateCanvas *) di)->get_bn();
            }
            else
                parent = (BrowserNode *) window()->browser_diagram()->parent();

            BrowserNode * b = BrowserState::get_state(parent);

            if (b != 0) {
                if (the_canvas()->already_drawn(b)) {
                    msg_information("Douml", TR("already drawn"));
                    history_protected = FALSE;
                    return;
                }

                // may be added in a the state's region rather than the state
                StateCanvas * c = new StateCanvas(b, the_canvas(), scenePoint.x(), scenePoint.y());

                c->show();
                c->upper();
                canvas()->update();
                StateCanvas::force_inside(c, TRUE);
                canvas()->update();
                history_protected = FALSE;
                window()->package_modified();
                return; // canvas already updated
            }
        }
        break;

        case UmlRegion: {
            history_protected = TRUE;
            unselect_all();
            window()->selectOn();
            history_save();

            QGraphicsItem * ci = the_canvas()->collision(scenePoint.toPoint());
            DiagramItem * di;

            if ((ci != 0) &&
                ((di = QCanvasItemToDiagramItem(ci)) != 0) &&
                (di->typeUmlCode() == UmlState) &&
                ((BrowserState *)((StateCanvas *) di)->get_bn())->may_contains(action)) {
                BrowserRegion::add_region(((StateCanvas *) di)->get_bn());
                window()->package_modified();
            }
        }
        break;

        case InitialPS:
        case EntryPointPS:
        case FinalPS:
        case TerminatePS:
        case ExitPointPS:
        case DeepHistoryPS:
        case ShallowHistoryPS:
        case JunctionPS:
        case ChoicePS:
        case ForkPS:
        case JoinPS: {
            history_protected = TRUE;
            unselect_all();
            window()->selectOn();
            history_save();

            QGraphicsItem * ci = the_canvas()->collision(scenePoint.toPoint());
            DiagramItem * di;
            bool specified = ((ci != 0) &&
                              ((di = QCanvasItemToDiagramItem(ci)) != 0) &&
                              (di->typeUmlCode() == UmlState) &&
                              ((BrowserState *)((StateCanvas *) di)->get_bn())->may_contains(action));
            BrowserNode * parent;

            if (specified) {
                if ((parent = ((StateCanvas *) di)->pointed_region(scenePoint.toPoint())) == 0)
                    parent = ((StateCanvas *) di)->get_bn();
            }
            else
                parent = (BrowserNode *) window()->browser_diagram()->parent();

            BrowserNode * b = BrowserPseudoState::get_pseudostate(parent, action);

            if (b != 0) {
                PseudoStateCanvas * c =
                    // may be added in a the state's region rather than the state
                    new PseudoStateCanvas(b, the_canvas(), scenePoint.x(), scenePoint.y());

                c->show();
                c->upper();
                StateCanvas::force_inside(c, FALSE);
                window()->package_modified();
            }
        }
        break;

        case UmlStateAction:
        case UmlSignalIn:
        case UmlSignalOut: {
            history_protected = TRUE;
            unselect_all();
            window()->selectOn();
            history_save();

            QGraphicsItem * ci = the_canvas()->collision(scenePoint.toPoint());
            DiagramItem * di;
            bool specified = ((ci != 0) &&
                              ((di = QCanvasItemToDiagramItem(ci)) != 0) &&
                              (di->typeUmlCode() == UmlState) &&
                              ((BrowserState *)((StateCanvas *) di)->get_bn())->may_contains(UmlStateAction));
            BrowserNode * parent;

            if (specified) {
                if ((parent = ((StateCanvas *) di)->pointed_region(scenePoint.toPoint())) == 0)
                    parent = ((StateCanvas *) di)->get_bn();
            }
            else
                parent = (BrowserNode *) window()->browser_diagram()->parent();

            BrowserNode * b = BrowserStateAction::add_stateaction(parent);

            switch (action) {
            case UmlSignalIn:
                ((StateActionData *) b->get_data())->set_stereotype("receive-signal");
                break;

            case UmlSignalOut:
                ((StateActionData *) b->get_data())->set_stereotype("send-signal");
                break;

            default:	// to avoid warning
                break;
            }

            StateActionCanvas * c =
                // may be added in a the state's region rather than the state
                new StateActionCanvas(b, the_canvas(), scenePoint.x(), scenePoint.y());

            c->show();
            c->upper();
            StateCanvas::force_inside(c, FALSE);
            window()->package_modified();
        }
        break;

        default:
            DiagramView::mousePressEvent(e);
            return;
        }

        canvas()->update();
        history_protected = FALSE;
    }
    else
        DiagramView::mousePressEvent(e);
}
Example #2
0
void StateDiagramView::dropEvent(QDropEvent * e)
{
    BrowserState * mach =
        BrowserState::get_machine(the_canvas()->browser_diagram());
    BrowserNode * bn;
    QPointF p = mapToScene(e->pos());

    if ((bn = UmlDrag::decode(e, UmlState, TRUE)) != 0) {
        if (the_canvas()->already_drawn(bn))
            msg_information("Douml", TR("already drawn"));
        else if (BrowserState::get_machine(bn) != mach)
            msg_information("Douml", TR("illegal"));
        else {
            history_save();

            // mettre des contraintes sur la validite ?
            StateCanvas * c =
                new StateCanvas(bn, the_canvas(), p.x(), p.y());

            history_protected = TRUE;
            c->show();
            c->upper();
            canvas()->update();
            StateCanvas::force_inside(c, TRUE);
            canvas()->update();
            history_protected = FALSE;
            window()->package_modified();
        }
    }
    else if ((bn = UmlDrag::decode(e, UmlPackage)) != 0) {
        history_save();

        PackageCanvas * pk =
            new PackageCanvas(bn, the_canvas(), p.x(), p.y(), 0);

        history_protected = TRUE;
        pk->show();
        pk->upper();
        canvas()->update();
        window()->package_modified();
    }
    else if ((bn = UmlDrag::decode(e, UmlPseudoState, TRUE)) != 0) {
        if (the_canvas()->already_drawn(bn))
            msg_information("Douml", TR("already drawn"));
        else if (BrowserState::get_machine(bn) != mach)
            msg_information("Douml", TR("illegal"));
        else {
            history_save();

            // mettre des contraintes sur la validite ?
            PseudoStateCanvas * c =
                new PseudoStateCanvas(bn, the_canvas(), p.x(), p.y());

            history_protected = TRUE;
            c->show();
            c->upper();
            StateCanvas::force_inside(c, FALSE);
            canvas()->update();
            history_protected = FALSE;
            window()->package_modified();
        }
    }
    else if ((bn = UmlDrag::decode(e, UmlStateAction, TRUE)) != 0) {
        if (the_canvas()->already_drawn(bn))
            msg_information("Douml", TR("already drawn"));
        else if (BrowserState::get_machine(bn) != mach)
            msg_information("Douml", TR("illegal"));
        else {
            history_save();

            // mettre des contraintes sur la validite ?
            StateActionCanvas * c =
                new StateActionCanvas(bn, the_canvas(), p.x(), p.y());

            history_protected = TRUE;
            c->show();
            c->upper();
            StateCanvas::force_inside(c, FALSE);
            canvas()->update();
            history_protected = FALSE;
            window()->package_modified();
        }
    }
    else if ((bn = UmlDrag::decode(e, UmlTransition, TRUE)) != 0) {
        history_save();

        history_protected = TRUE;
        TransitionCanvas::drop(bn, the_canvas());
        canvas()->update();
        history_protected = FALSE;
    }
    else if (((bn = UmlDrag::decode(e, UmlClassDiagram)) != 0) ||
             ((bn = UmlDrag::decode(e, UmlUseCaseDiagram)) != 0) ||
             ((bn = UmlDrag::decode(e, UmlSeqDiagram)) != 0) ||
             ((bn = UmlDrag::decode(e, UmlColDiagram)) != 0) ||
             ((bn = UmlDrag::decode(e, UmlObjectDiagram)) != 0) ||
             ((bn = UmlDrag::decode(e, UmlStateDiagram)) != 0) ||
             ((bn = UmlDrag::decode(e, UmlComponentDiagram)) != 0) ||
             ((bn = UmlDrag::decode(e, UmlDeploymentDiagram)) != 0) ||
             ((bn = UmlDrag::decode(e, UmlStateDiagram, TRUE)) != 0) ||
             ((bn = UmlDrag::decode(e, UmlActivityDiagram, TRUE)) != 0)) {
        history_save();

        IconCanvas * ic = new IconCanvas(bn, the_canvas(), p.x(), p.y(), 0);

        history_protected = TRUE;
        ic->show();
        ic->upper();

        canvas()->update();
        history_protected = FALSE;
        window()->package_modified();
    }
}