Search in sources :

Example 1 with AbstractSector

use of com.ramussoft.pb.data.AbstractSector in project ramus by Vitaliy-Yakovchuk.

the class PaintSector method removeAther.

/**
 * Перевіряє і видаляє під’єднані до сектора сектори.
 */
private void removeAther(final Crosspoint point) {
    // System.out.println("Remove other "+point);
    if (point != null) {
        Row[] del;
        if (getStream() == null)
            del = new Row[] {};
        else
            del = getStream().getAdded();
        if (!point.isDLevel()) {
            final boolean start = !point.isIn(sector);
            ((AbstractSector) sector).removeFromParent(del, start);
        }
        if (point.isRemoveable()) {
            PaintSector s = null;
            for (int i = 0; i < movingArea.getRefactor().getSectorsCount(); i++) {
                s = movingArea.getRefactor().getSector(i);
                if (point.isIn(s.getSector()))
                    break;
            }
            if (s == null)
                return;
            try {
                s.joinSector(movingArea.getRefactor().getOppozite(s, point)[0]);
            } catch (Exception exception) {
                exception.printStackTrace();
            }
            s.createTexts();
        }
    }
}
Also used : AbstractSector(com.ramussoft.pb.data.AbstractSector) Row(com.ramussoft.pb.Row) NCrosspoint(com.ramussoft.pb.data.negine.NCrosspoint) Crosspoint(com.ramussoft.pb.Crosspoint) FloatPoint(com.dsoft.pb.types.FloatPoint) IOException(java.io.IOException)

Example 2 with AbstractSector

use of com.ramussoft.pb.data.AbstractSector in project ramus by Vitaliy-Yakovchuk.

the class MovingArea method removeLevel.

/**
 * Метод, який видяляє рівень з функціонального блоку
 */
public void removeLevel() {
    final Function f = ((MovingFunction) getActiveObject()).getFunction();
    if (f.getChildCount() != 1) {
        JOptionPane.showMessageDialog(this, ResourceLoader.getString("MovingArea.functionHaveNotOneChild"));
        return;
    }
    Vector<Row> childs = dataPlugin.getChilds(f, true);
    if (childs.size() != 1)
        return;
    final Function c = (Function) childs.get(0);
    if (f.isLocked() || c.isLocked()) {
        JOptionPane.showMessageDialog(this, ResourceLoader.getString("MovingArea.functionIsLocked"));
        return;
    }
    if (!checkRemoveLevelFunction(c)) {
        JOptionPane.showMessageDialog(this, ResourceLoader.getString("MovingArea.removingLevelSectorError"));
        return;
    }
    if (JOptionPane.showConfirmDialog(this, ResourceLoader.getString("MovingArea.removingLevelWarning"), ResourceLoader.getString("warning"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION)
        return;
    f.lock();
    c.lock();
    startUserTransaction();
    Vector<Sector> sectors = new Vector<Sector>(f.getSectors());
    for (int i = 0; i < sectors.size(); i++) {
        final Sector sector = sectors.get(i);
        Crosspoint opp;
        Crosspoint crosspoint;
        if (c.equals(sector.getStart().getFunction())) {
            opp = sector.getStart().getCrosspoint();
            crosspoint = sector.getEnd().getCrosspoint();
        } else {
            opp = sector.getEnd().getCrosspoint();
            crosspoint = sector.getStart().getCrosspoint();
        }
        Sector o = null;
        final Sector[] os = opp.getOppozite(sector);
        for (final Sector s : os) o = s;
        class X {

            int createState;

            double createPos;

            Stream stream;

            byte[] visual;

            int sBorderType;

            int eBorderType;
        }
        X x = null;
        if (o != null && (o.getStart().getCrosspoint() == null || o.getEnd().getCrosspoint() == null)) {
            x = new X();
            x.createState = o.getCreateState();
            x.createPos = o.getCreatePos();
            x.stream = o.getStream();
            x.visual = o.getVisualAttributes();
            x.sBorderType = o.getStart().getBorderType();
            x.eBorderType = o.getEnd().getBorderType();
        }
        sector.remove();
        if (x != null) {
            o = dataPlugin.createSector();
            o.setCreateState(x.createState, x.createPos);
            ((AbstractSector) o).setThisStream(x.stream);
            o.setVisualAttributes(x.visual);
            o.setFunction(c);
            o.getStart().setBorderTypeA(x.sBorderType);
            o.getEnd().setBorderTypeA(x.eBorderType);
            o.getStart().commit();
            o.getEnd().commit();
        }
        if (o != null) {
            if (c.equals(sector.getStart().getFunction())) {
                o.getEnd().setCrosspointA(crosspoint);
                o.getEnd().commit();
            } else {
                o.getStart().setCrosspointA(crosspoint);
                o.getEnd().commit();
            }
        }
    }
    sectors = new Vector<Sector>(c.getSectors());
    for (int i = 0; i < sectors.size(); i++) {
        final Sector sector = sectors.get(i);
        sector.setFunction(f);
    }
    f.setSectorData(c.getSectorData());
    c.setSectorData(new byte[0]);
    childs = dataPlugin.getChilds(c, true);
    for (int i = 0; i < childs.size(); i++) {
        final Function c1 = (Function) childs.get(i);
        c1.setParentRow(f);
    }
    c.unlock();
    if (!dataPlugin.removeRow(c)) {
        JOptionPane.showMessageDialog(this, ResourceLoader.getString("MovingArea.cantRemoveFunctionByRemovingLevel"));
    }
    f.unlock();
    if (panel != null)
        panel.getFrame().propertyChange(MChangeListener.RELOAD_FUNCTION_IN_TREE, dataPlugin.getBaseFunction());
    commitUserTransaction();
}
Also used : 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) 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) 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) AbstractSector(com.ramussoft.pb.data.AbstractSector) Stream(com.ramussoft.pb.Stream) Row(com.ramussoft.pb.Row) Vector(java.util.Vector)

Example 3 with AbstractSector

use of com.ramussoft.pb.data.AbstractSector 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)

Aggregations

FloatPoint (com.dsoft.pb.types.FloatPoint)3 Crosspoint (com.ramussoft.pb.Crosspoint)3 Row (com.ramussoft.pb.Row)3 AbstractSector (com.ramussoft.pb.data.AbstractSector)3 Function (com.ramussoft.pb.Function)2 Sector (com.ramussoft.pb.Sector)2 NFunction (com.ramussoft.pb.data.negine.NFunction)2 NSector (com.ramussoft.pb.data.negine.NSector)2 DFDFunction (com.ramussoft.pb.dfd.visual.DFDFunction)2 DFDSFunction (com.ramussoft.pb.dfds.visual.DFDSFunction)2 PaintSector (com.ramussoft.pb.idef.elements.PaintSector)2 Point (com.ramussoft.pb.idef.elements.Point)2 PerspectivePoint (com.ramussoft.pb.idef.elements.SectorRefactor.PerspectivePoint)2 Vector (java.util.Vector)2 Stream (com.ramussoft.pb.Stream)1 NCrosspoint (com.ramussoft.pb.data.negine.NCrosspoint)1 Ordinate (com.ramussoft.pb.idef.elements.Ordinate)1 SectorRefactor (com.ramussoft.pb.idef.elements.SectorRefactor)1 IOException (java.io.IOException)1