void RS_ActionModifyDeleteFree::trigger() {
    if (e1 && e2) {
        RS_EntityContainer* parent = e2->getParent();
        if (parent) {
            if (parent->rtti()==RS2::EntityPolyline) {
                if(parent->getId() == polyline->getId()) {

                    // deletes whole polyline on screen:
                    graphicView->deleteEntity((RS_Entity*)polyline);

                    // splits up the polyline in the container:
                    RS_Polyline* pl1;
                    RS_Polyline* pl2;
                    RS_Modification m(*container);
                    m.splitPolyline(*polyline,
                                    *e1, pPoints->v1,
                                    *e2, pPoints->v2,
                                    &pl1, &pl2);

                    if (document) {
                        document->startUndoCycle();
                        document->addUndoable(polyline);
                        document->addUndoable(pl1);
                        document->addUndoable(pl2);
                        document->endUndoCycle();
                    }

                    // draws the new polylines on the screen:
                    graphicView->redraw(RS2::RedrawDrawing);

                    init();

                    RS_DIALOGFACTORY->updateSelectionWidget(
                        container->countSelected(),container->totalSelectedLength());
                } else {
                    RS_DIALOGFACTORY->commandMessage(tr("Entities not in the same polyline."));
                }
            } else {
                RS_DIALOGFACTORY->commandMessage(tr("Parent of second entity is not a polyline"));
            }
        } else {
            RS_DIALOGFACTORY->commandMessage(tr("Parent of second entity is nullptr"));
        }
    } else {
        RS_DIALOGFACTORY->commandMessage(tr("One of the chosen entities is nullptr"));
    }
}
void RS_ActionModifyDeleteFree::mouseReleaseEvent(QMouseEvent* e) {
    if (e->button()==Qt::RightButton) {
        init(getStatus()-1);
    } else {

        switch (getStatus()) {
        case 0: {
            pPoints->v1 = snapPoint(e);
            e1 = getKeyEntity();
            if (e1) {
                RS_EntityContainer* parent = e1->getParent();
                if (parent) {
                    if (parent->rtti()==RS2::EntityPolyline) {
                        polyline = (RS_Polyline*)parent;
                        setStatus(1);
                    } else {
                        RS_DIALOGFACTORY->commandMessage(
                            tr("Parent of first entity is not a polyline"));
                    }
                } else {
                    RS_DIALOGFACTORY->commandMessage(
                        tr("Parent of first entity is nullptr"));
                }
            } else {
                RS_DIALOGFACTORY->commandMessage(
                    tr("First entity is nullptr"));
            }
        }
        break;

        case 1: {
            pPoints->v2 = snapPoint(e);
            e2 = getKeyEntity();

            if (e2) {
                trigger();
            } else {
                RS_DIALOGFACTORY->commandMessage(tr("Second entity is nullptr"));
            }
        }
        break;
        }
    }
}