Search in sources :

Example 16 with Point

use of com.ramussoft.pb.idef.elements.Point in project ramus by Vitaliy-Yakovchuk.

the class MovingArea method addLevel.

/**
 * Метод, який додає рівень до активного функціонального блоку на моделі,
 * контекст функціонального блоку заміняється на новий функціональний блок з
 * контекстом, який мав активний функціональний блок.
 */
public synchronized void addLevel() {
    final Function f = ((MovingFunction) getActiveObject()).getFunction();
    if (f.isLocked()) {
        JOptionPane.showMessageDialog(this, ResourceLoader.getString("MovingArea.functionIsLocked"));
        return;
    }
    if (JOptionPane.showConfirmDialog(this, ResourceLoader.getString("MovingArea.addingLevelWarning"), ResourceLoader.getString("warning"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION)
        return;
    f.lock();
    final Vector<Row> childs = dataPlugin.getChilds(f, true);
    final Function n = (Function) dataPlugin.createRow(f, true);
    n.setSectorData(f.getSectorData());
    n.setBounds(f.getBounds());
    n.setBackground(f.getBackground());
    n.setForeground(f.getForeground());
    n.setName(f.getName());
    n.setDecompositionType(f.getDecompositionType());
    n.setType(f.getType());
    f.setName(f.getName() + " (" + ResourceLoader.getString("MovingArea.context") + ")");
    n.setFont(f.getFont());
    f.setSectorData(new byte[0]);
    final SectorRefactor r = new SectorRefactor(this);
    // .getBounds().getHeight()));
    for (int i = 0; i < childs.size(); i++) {
        final Function c = (Function) childs.get(i);
        c.setParentRow(n);
    }
    Vector srs = new Vector(f.getSectors());
    for (int i = 0; i < srs.size(); i++) {
        final Sector sector = (Sector) srs.get(i);
        sector.setFunction(n);
    // System.out.println(sector.getFunction());
    }
    final Function p = (Function) f.getParent();
    srs = p.getSectors();
    final int[] cnts = new int[4];
    final double[] poses = new double[4];
    final double[] hs = new double[4];
    for (int i = 0; i < cnts.length; i++) cnts[i] = 0;
    for (int i = 0; i < srs.size(); i++) {
        final Sector sector = (Sector) srs.get(i);
        if (f.equals(sector.getStart().getFunction())) {
            cnts[MovingPanel.RIGHT]++;
        }
        if (f.equals(sector.getEnd().getFunction())) {
            cnts[sector.getEnd().getFunctionType()]++;
        }
    }
    for (int i = 0; i < cnts.length; i++) {
        if (cnts[i] > 0) {
            if (i == MovingPanel.LEFT || i == MovingPanel.RIGHT)
                hs[i] = n.getBounds().getHeight() / cnts[i];
            else
                hs[i] = n.getBounds().getWidth() / cnts[i];
        }
        poses[i] = hs[i] / 2.0d;
    }
    for (int i = 0; i < srs.size(); i++) {
        final Sector sector = (Sector) srs.get(i);
        if (f.equals(sector.getStart().getFunction())) {
            final Crosspoint c = sector.getStart().getCrosspoint();
            final Sector[] ss = c.getOppozite(sector);
            Sector so = null;
            for (final Sector element : ss) {
                so = element;
            }
            final Sector s = dataPlugin.createSector();
            ((AbstractSector) s).setThisStream(SectorRefactor.cloneStream(sector.getStream(), dataPlugin, s));
            s.setVisualAttributes(sector.getVisualAttributes());
            s.setFunction(f);
            final Ordinate x1 = new Ordinate(Ordinate.TYPE_X);
            final Ordinate x2 = new Ordinate(Ordinate.TYPE_X);
            x1.setPosition(n.getBounds().getX() + n.getBounds().getWidth());
            x2.setPosition(getDoubleWidth() - PART_SPACE);
            final Ordinate y = new Ordinate(Ordinate.TYPE_Y);
            y.setPosition(n.getBounds().getY() + poses[MovingPanel.RIGHT]);
            poses[MovingPanel.RIGHT] += hs[MovingPanel.RIGHT];
            final Point p1 = new Point(x1, y);
            final Point p2 = new Point(x2, y);
            final PaintSector ps = new PaintSector(s, p1, p2, this);
            r.addSector(ps);
            final Crosspoint cp = dataPlugin.createCrosspoint();
            if (so != null) {
                so.getEnd().setCrosspointA(cp);
                so.getEnd().commit();
            }
            s.getEnd().setCrosspointA(c);
            s.getStart().setCrosspointA(cp);
            s.getStart().setFunctionA(n);
            s.getStart().setFunctionTypeA(MovingPanel.RIGHT);
            s.getEnd().setBorderTypeA(MovingPanel.RIGHT);
            s.getStart().commit();
            s.getEnd().commit();
        }
        if (f.equals(sector.getEnd().getFunction())) {
            final int et = sector.getEnd().getFunctionType();
            final Crosspoint c = sector.getEnd().getCrosspoint();
            final Sector[] ss = c.getOppozite(sector);
            Sector so = null;
            for (final Sector element : ss) {
                so = element;
                so.setFunction(n);
            }
            final Sector s = dataPlugin.createSector();
            ((AbstractSector) s).setThisStream(SectorRefactor.cloneStream(sector.getStream(), dataPlugin, s));
            s.setVisualAttributes(sector.getVisualAttributes());
            s.setFunction(f);
            if (et == MovingPanel.LEFT) {
                final Ordinate x1 = new Ordinate(Ordinate.TYPE_X);
                final Ordinate x2 = new Ordinate(Ordinate.TYPE_X);
                x2.setPosition(n.getBounds().getX());
                x1.setPosition(PART_SPACE);
                final Ordinate y = new Ordinate(Ordinate.TYPE_Y);
                y.setPosition(n.getBounds().getY() + poses[et]);
                final Point p1 = new Point(x1, y);
                final Point p2 = new Point(x2, y);
                final PaintSector ps = new PaintSector(s, p1, p2, this);
                r.addSector(ps);
            } else if (et == MovingPanel.TOP) {
                final Ordinate y1 = new Ordinate(Ordinate.TYPE_Y);
                final Ordinate y2 = new Ordinate(Ordinate.TYPE_Y);
                y2.setPosition(n.getBounds().getY());
                y1.setPosition(PART_SPACE);
                final Ordinate x = new Ordinate(Ordinate.TYPE_X);
                x.setPosition(n.getBounds().getX() + poses[et]);
                final Point p1 = new Point(x, y1);
                final Point p2 = new Point(x, y2);
                final PaintSector ps = new PaintSector(s, p1, p2, this);
                r.addSector(ps);
            } else if (et == MovingPanel.BOTTOM) {
                final Ordinate y1 = new Ordinate(Ordinate.TYPE_Y);
                final Ordinate y2 = new Ordinate(Ordinate.TYPE_Y);
                y2.setPosition(n.getBounds().getY() + n.getBounds().getHeight());
                y1.setPosition(PART_SPACE + getDoubleHeight());
                final Ordinate x = new Ordinate(Ordinate.TYPE_X);
                x.setPosition(n.getBounds().getX() + poses[et]);
                final Point p1 = new Point(x, y1);
                final Point p2 = new Point(x, y2);
                final PaintSector ps = new PaintSector(s, p1, p2, this);
                r.addSector(ps);
            }
            poses[et] += hs[et];
            final Crosspoint cp = dataPlugin.createCrosspoint();
            if (so != null) {
                so.getStart().setCrosspointA(cp);
                so.setFunction(n);
                so.getStart().commit();
            }
            s.getStart().setCrosspointA(c);
            s.getEnd().setCrosspointA(cp);
            s.getEnd().setFunctionA(n);
            s.getEnd().setFunctionTypeA(et);
            s.getStart().setBorderTypeA(et);
            s.getStart().commit();
            s.getEnd().commit();
        }
    }
    r.saveToFunction(f);
    if (panel != null)
        panel.getFrame().propertyChange(MChangeListener.RELOAD_FUNCTION_IN_TREE, dataPlugin.getBaseFunction());
    ((NFunction) f).clearSectorsBuffer();
    f.unlock();
}
Also used : SectorRefactor(com.ramussoft.pb.idef.elements.SectorRefactor) NFunction(com.ramussoft.pb.data.negine.NFunction) PaintSector(com.ramussoft.pb.idef.elements.PaintSector) Sector(com.ramussoft.pb.Sector) NSector(com.ramussoft.pb.data.negine.NSector) AbstractSector(com.ramussoft.pb.data.AbstractSector) PerspectivePoint(com.ramussoft.pb.idef.elements.SectorRefactor.PerspectivePoint) FloatPoint(com.dsoft.pb.types.FloatPoint) Point(com.ramussoft.pb.idef.elements.Point) Crosspoint(com.ramussoft.pb.Crosspoint) PerspectivePoint(com.ramussoft.pb.idef.elements.SectorRefactor.PerspectivePoint) FloatPoint(com.dsoft.pb.types.FloatPoint) Crosspoint(com.ramussoft.pb.Crosspoint) Point(com.ramussoft.pb.idef.elements.Point) Ordinate(com.ramussoft.pb.idef.elements.Ordinate) DFDSFunction(com.ramussoft.pb.dfds.visual.DFDSFunction) Function(com.ramussoft.pb.Function) DFDFunction(com.ramussoft.pb.dfd.visual.DFDFunction) NFunction(com.ramussoft.pb.data.negine.NFunction) PaintSector(com.ramussoft.pb.idef.elements.PaintSector) AbstractSector(com.ramussoft.pb.data.AbstractSector) Row(com.ramussoft.pb.Row) Vector(java.util.Vector)

Example 17 with Point

use of com.ramussoft.pb.idef.elements.Point in project ramus by Vitaliy-Yakovchuk.

the class IDEF0Object method mouseClicked.

/**
 * @see com.ramussoft.pb.idef.visual.MovingPanel#mouseClicked(com.dsoft.pb.types.FloatPoint)
 */
@Override
public void mouseClicked(final FloatPoint point) {
    super.mouseClicked(point);
    if (movingArea.getChangingState() == MovingArea.ARROW_CHANGING_STATE) {
        if (movingArea.getPointChangingType() == SectorRefactor.TYPE_START) {
            if (getTriangle(point) == RIGHT) {
                final Ordinate x = new Ordinate(Ordinate.TYPE_X);
                final Ordinate y = new Ordinate(Ordinate.TYPE_Y);
                final Point p = new Point(x, y);
                x.setPosition(getBounds().getRight());
                y.setPosition(getBounds().getY() + point.getY());
                final SectorRefactor.PerspectivePoint pp = new SectorRefactor.PerspectivePoint();
                pp.point = p;
                pp.x = p.getX();
                pp.y = p.getY();
                pp.setFunction(getFunction(), RIGHT);
                pp.type = SectorRefactor.TYPE_START;
                movingArea.getRefactor().setPoint(pp);
                movingArea.doSector();
            }
        } else {
            final int type = getTriangle(point);
            if (type == -1 || type == RIGHT)
                return;
            final Ordinate x = new Ordinate(Ordinate.TYPE_X);
            final Ordinate y = new Ordinate(Ordinate.TYPE_Y);
            final Point p = new Point(x, y);
            final SectorRefactor.PerspectivePoint pp = new SectorRefactor.PerspectivePoint();
            pp.point = p;
            switch(type) {
                case LEFT:
                    {
                        pp.setFunction(getFunction(), LEFT);
                        x.setPosition(getBounds().getLeft());
                        y.setPosition(getBounds().getY() + point.getY());
                    }
                    break;
                case TOP:
                    {
                        pp.setFunction(getFunction(), TOP);
                        x.setPosition(getBounds().getX() + point.getX());
                        y.setPosition(getBounds().getTop());
                    }
                    break;
                case BOTTOM:
                    {
                        pp.setFunction(getFunction(), BOTTOM);
                        x.setPosition(getBounds().getX() + point.getX());
                        y.setPosition(getBounds().getBottom());
                    }
                    break;
            }
            pp.x = x.getPosition();
            pp.y = y.getPosition();
            pp.type = SectorRefactor.TYPE_END;
            movingArea.getRefactor().setPoint(pp);
            movingArea.doSector();
        }
    }
}
Also used : SectorRefactor(com.ramussoft.pb.idef.elements.SectorRefactor) Point(com.ramussoft.pb.idef.elements.Point) FloatPoint(com.dsoft.pb.types.FloatPoint) Ordinate(com.ramussoft.pb.idef.elements.Ordinate) Point(com.ramussoft.pb.idef.elements.Point) FloatPoint(com.dsoft.pb.types.FloatPoint)

Example 18 with Point

use of com.ramussoft.pb.idef.elements.Point in project ramus by Vitaliy-Yakovchuk.

the class IDEF0Object method centerPoints.

/**
 * Центрує набір точок на стороні.
 *
 * @param points Вестор з посиланнями на точки.
 * @param type   Ordinate.TYPE_X - точки знаходяться на верхній або нижній
 *               стороні. Ordinate.TYPE_Y - точки знаходяться на лівій або
 *               правій стороні.
 */
protected void centerPoints(final Vector<Point> points, final int type, int borderType) {
    final double[] ds = new double[points.size()];
    int i;
    FRectangle bounds = getBounds();
    if (type == Ordinate.TYPE_X) {
        for (i = 0; i < ds.length; i++) ds[i] = points.get(i).getX();
        centerArray(ds, bounds.getLeft(), bounds.getRight());
        for (i = 0; i < ds.length; i++) {
            final Point p = points.get(i);
            if (p.isMoveable(ds[i], Ordinate.TYPE_X)) {
                p.setX(ds[i]);
                p.setY(getY(ds[i], TOP == borderType, bounds));
            }
        }
    } else {
        for (i = 0; i < ds.length; i++) ds[i] = points.get(i).getY();
        centerArray(ds, bounds.getTop(), bounds.getBottom());
        for (i = 0; i < ds.length; i++) {
            final Point p = points.get(i);
            if (p.isMoveable(ds[i], Ordinate.TYPE_Y)) {
                p.setY(ds[i]);
                p.setX(getX(ds[i], LEFT == borderType, bounds));
            }
        }
    }
}
Also used : FRectangle(com.dsoft.pb.types.FRectangle) Point(com.ramussoft.pb.idef.elements.Point) FloatPoint(com.dsoft.pb.types.FloatPoint) Point(com.ramussoft.pb.idef.elements.Point) FloatPoint(com.dsoft.pb.types.FloatPoint)

Example 19 with Point

use of com.ramussoft.pb.idef.elements.Point in project ramus by Vitaliy-Yakovchuk.

the class IDEF0Object method getTriangle.

protected int getTriangle(final FloatPoint point) {
    int res = -1;
    FloatPoint l = getLocation();
    for (int type = MovingPanel.RIGHT; type <= MovingPanel.TOP; type++) {
        GeneralPath gp = getTrianglePath(type);
        double y = point.getY() + l.getY();
        double x = point.getX() + l.getX();
        if (gp.contains(new Point2D.Double(x, y))) {
            res = type;
            break;
        }
    }
    if (isShowRight() ^ res == Point.RIGHT)
        res = -1;
    return res;
}
Also used : FloatPoint(com.dsoft.pb.types.FloatPoint) GeneralPath(java.awt.geom.GeneralPath) Point2D(java.awt.geom.Point2D) Point(com.ramussoft.pb.idef.elements.Point) FloatPoint(com.dsoft.pb.types.FloatPoint)

Example 20 with Point

use of com.ramussoft.pb.idef.elements.Point in project ramus by Vitaliy-Yakovchuk.

the class IDEF0Object method centerAddedSetors.

/**
 * Метод вирівнює розташування всіх під’єднаних до функціонального блока
 * секторів.
 */
@SuppressWarnings("unchecked")
public void centerAddedSetors() {
    final Vector<Point>[] vectors = new Vector[4];
    vectors[LEFT] = new Vector<Point>();
    vectors[RIGHT] = new Vector<Point>();
    vectors[TOP] = new Vector<Point>();
    vectors[BOTTOM] = new Vector<Point>();
    final SectorRefactor refactor = movingArea.getRefactor();
    for (int i = 0; i < refactor.getSectorsCount(); i++) {
        final PaintSector sector = refactor.getSector(i);
        if (function.equals(sector.getSector().getStart().getFunction()))
            vectors[sector.getSector().getStart().getFunctionType()].add(sector.getStartPoint());
        if (function.equals(sector.getSector().getEnd().getFunction()))
            vectors[sector.getSector().getEnd().getFunctionType()].add(sector.getEndPoint());
    }
    for (int i = 0; i < 4; i++) centerPoints(vectors[i], i == LEFT || i == RIGHT ? Ordinate.TYPE_Y : Ordinate.TYPE_X, i);
    for (int i = 0; i < refactor.getSectorsCount(); i++) {
        final PaintSector sector = refactor.getSector(i);
        if (function.equals(sector.getSector().getStart().getFunction()))
            sector.tryRemovePin(getMovingArea());
        else if (function.equals(sector.getSector().getEnd().getFunction()))
            sector.tryRemovePin(getMovingArea());
    }
}
Also used : SectorRefactor(com.ramussoft.pb.idef.elements.SectorRefactor) PaintSector(com.ramussoft.pb.idef.elements.PaintSector) Point(com.ramussoft.pb.idef.elements.Point) FloatPoint(com.dsoft.pb.types.FloatPoint) Vector(java.util.Vector) Point(com.ramussoft.pb.idef.elements.Point) FloatPoint(com.dsoft.pb.types.FloatPoint)

Aggregations

Point (com.ramussoft.pb.idef.elements.Point)21 FloatPoint (com.dsoft.pb.types.FloatPoint)19 SectorRefactor (com.ramussoft.pb.idef.elements.SectorRefactor)12 Ordinate (com.ramussoft.pb.idef.elements.Ordinate)11 PaintSector (com.ramussoft.pb.idef.elements.PaintSector)6 Crosspoint (com.ramussoft.pb.Crosspoint)5 GeneralPath (java.awt.geom.GeneralPath)4 Point2D (java.awt.geom.Point2D)4 Function (com.ramussoft.pb.Function)3 FRectangle (com.dsoft.pb.types.FRectangle)2 Row (com.ramussoft.pb.Row)2 Sector (com.ramussoft.pb.Sector)2 PerspectivePoint (com.ramussoft.pb.idef.elements.SectorRefactor.PerspectivePoint)2 MovingLabel (com.ramussoft.pb.idef.visual.MovingLabel)2 ArrayList (java.util.ArrayList)2 Vector (java.util.Vector)2 MemoryData (com.dsoft.utils.DataLoader.MemoryData)1 AbstractSector (com.ramussoft.pb.data.AbstractSector)1 NFunction (com.ramussoft.pb.data.negine.NFunction)1 NSector (com.ramussoft.pb.data.negine.NSector)1