Search in sources :

Example 26 with Sector

use of com.ramussoft.pb.Sector 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 27 with Sector

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

the class SectorRefactor method getStreamedSectors.

public void getStreamedSectors(final Sector sector, final Crosspoint point, final HashSet v, final boolean streamed) {
    if (point == null)
        return;
    final Sector[] sectors = point.getOppozite(sector);
    for (int i = 0; i < getSectorsCount(); i++) {
        final PaintSector s = getSector(i);
        if (isIn(s, sectors)) {
            if (streamed)
                if (sector.getStream() == null || !equalsStreams(sector.getStream(), s.getStream()))
                    continue;
            if (!v.contains(s) && s.getFunction().equals(sector.getFunction())) {
                v.add(s);
                getStreamedSectors(s, v);
            }
        }
    }
}
Also used : Sector(com.ramussoft.pb.Sector) NSector(com.ramussoft.pb.data.negine.NSector) Crosspoint(com.ramussoft.pb.Crosspoint) FloatPoint(com.dsoft.pb.types.FloatPoint)

Example 28 with Sector

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

the class SectorRefactor method fillFromOwners.

private static void fillFromOwners(Function function, DataPlugin dataPlugin) {
    Function par = (Function) function.getParent();
    if (par == null)
        return;
    Vector<Sector> ends = new Vector<Sector>();
    Vector<Sector> starts = new Vector<Sector>();
    for (Sector sector : par.getSectors()) {
        NSectorBorder start = sector.getStart();
        if (function.equals(start.getFunction()) && start.getCrosspoint() != null) {
            if (start.getCrosspoint().isDLevel()) {
                for (Sector sector2 : start.getCrosspoint().getOppozite(sector)) starts.add(sector2);
            }
        }
        NSectorBorder end = sector.getEnd();
        if (function.equals(end.getFunction()) && end.getCrosspoint() != null) {
            if (end.getCrosspoint().isDLevel()) {
                for (Sector sector2 : end.getCrosspoint().getOppozite(sector)) ends.add(sector2);
            }
        }
    }
    if (ends.size() == 0 && starts.size() == 0)
        return;
    HashSet<Row> owners = new HashSet<Row>();
    boolean[] hasFunctionOwners = new boolean[] { false };
    for (Sector sector : starts) fillStartFromOwners(sector, owners, dataPlugin, hasFunctionOwners);
    for (Sector sector : ends) fillEndFromOwners(sector, owners, dataPlugin, hasFunctionOwners);
    if (!hasFunctionOwners[0] && owners.size() == 0)
        return;
    Stream stream = (Stream) dataPlugin.findRowByGlobalId(function.getLink());
    if (stream == null) {
        if (owners.size() > 0) {
            stream = (Stream) dataPlugin.createRow(dataPlugin.getBaseStream(), true);
            function.setLink(stream.getElement().getId());
            stream.setRows(owners.toArray(new Row[owners.size()]));
        }
    } else {
        stream.setRows(owners.toArray(new Row[owners.size()]));
    }
}
Also used : Function(com.ramussoft.pb.Function) NFunction(com.ramussoft.pb.data.negine.NFunction) NSectorBorder(com.ramussoft.pb.data.negine.NSectorBorder) Sector(com.ramussoft.pb.Sector) NSector(com.ramussoft.pb.data.negine.NSector) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Stream(com.ramussoft.pb.Stream) Row(com.ramussoft.pb.Row) Vector(java.util.Vector) HashSet(java.util.HashSet)

Example 29 with Sector

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

the class SectorRefactor method loadFromFunction.

/**
 * Метод, який завантажує секторну структуру функціонального блоку, якщо
 * інформація вже раніше була завантажена з функціонального блоку, то вона
 * автоматично в нього зберігається.
 *
 * @param function Функціональний блок, з якого завантажаться дані.
 * @param save     Параметр, який вказує, чи зберігати останню завантажену
 *                 функцію.
 */
public void loadFromFunction(final Function function, final boolean save) {
    if (save && this.function != null)
        saveToFunction(this.function);
    sectors.clear();
    texts.clear();
    this.function = function;
    if (function == null)
        return;
    ((NFunction) function).clearSectorsBuffer();
    final byte[] bs = function.getSectorData();
    if (bs == null)
        return;
    final ByteArrayInputStream in = new ByteArrayInputStream(bs);
    try {
        final DataLoader.MemoryData memoryData = new DataLoader.MemoryData();
        // read version
        final int ver = DataLoader.readInteger(in);
        this.loadVersion = ver;
        if (ver < 2 && ver > 0) {
            int n = DataLoader.readInteger(in);
            for (int i = 0; i < n; i++) {
                final PaintSector sector = PaintSector.loadFromStream(in, ver, movingArea, memoryData, getDataPlugin());
                if (sector != null)
                    addSector(sector);
            }
        } else {
            for (Sector sector : function.getSectors()) {
                final PaintSector paintSector = PaintSector.loadFromSector(ver, movingArea, memoryData, getDataPlugin(), sector);
                if (paintSector != null) {
                    if (sector.getCreateState() == Sector.STATE_IN)
                        createInPaintPart(sector);
                    else if (sector.getCreateState() == Sector.STATE_OUT)
                        createOutPaintPart(sector);
                    else
                        addSector(paintSector);
                }
            }
        }
        int n = DataLoader.readInteger(in);
        for (int i = 0; i < n; i++) {
            final MovingText text = movingArea.createText();
            text.setFont(DataLoader.readFont(in, memoryData));
            text.setColor(DataLoader.readColor(in, memoryData));
            text.setBounds(DataLoader.readFRectangle(in));
            text.setText(DataLoader.readString(in));
            texts.add(text);
        }
        in.close();
        HashSet<PaintSector> hashSet = new HashSet<PaintSector>();
        for (int i = 0; i < getSectorsCount(); i++) {
            getSector(i).createTexts(hashSet);
        }
    } catch (final IOException e) {
        e.printStackTrace();
    }
}
Also used : NFunction(com.ramussoft.pb.data.negine.NFunction) Sector(com.ramussoft.pb.Sector) NSector(com.ramussoft.pb.data.negine.NSector) IOException(java.io.IOException) Crosspoint(com.ramussoft.pb.Crosspoint) FloatPoint(com.dsoft.pb.types.FloatPoint) DataLoader(com.dsoft.utils.DataLoader) ByteArrayInputStream(java.io.ByteArrayInputStream) MovingText(com.ramussoft.pb.idef.visual.MovingText) HashSet(java.util.HashSet)

Example 30 with Sector

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

the class SectorRefactor method createInPaintPart.

/**
 * Мотод, який створює відображення всередені.
 *
 * @param sector Сектор для якого буде створено відображення.
 */
private void createInPaintPart(final Sector sector) {
    if (sector.getStart().getCrosspoint() == null) {
        // -->
        final Sector[] opps = sector.getEnd().getCrosspoint().getOppozite(sector);
        if (opps.length == 0) {
            // sector.remove();
            return;
        }
        final Point a = new Point();
        final Point b = new Point();
        switch(sector.getEnd().getBorderType()) {
            case MovingPanel.TOP:
                {
                    final Ordinate o = new Ordinate(Ordinate.TYPE_X);
                    o.setPosition(sector.getCreatePos());
                    a.setXOrdinate(o);
                    b.setXOrdinate(o);
                    a.setYOrdinate(new Ordinate(Ordinate.TYPE_Y));
                    b.setYOrdinate(new Ordinate(Ordinate.TYPE_Y));
                    b.setY(MovingArea.PART_SPACE);
                    a.setY(MovingArea.PART_SPACE + PART_SECTOR_LENGTH);
                }
                break;
            case MovingPanel.BOTTOM:
                {
                    final Ordinate o = new Ordinate(Ordinate.TYPE_X);
                    o.setPosition(sector.getCreatePos());
                    a.setXOrdinate(o);
                    b.setXOrdinate(o);
                    a.setYOrdinate(new Ordinate(Ordinate.TYPE_Y));
                    b.setYOrdinate(new Ordinate(Ordinate.TYPE_Y));
                    b.setY(movingArea.getDoubleHeight() - MovingArea.PART_SPACE);
                    a.setY(movingArea.getDoubleHeight() - MovingArea.PART_SPACE - PART_SECTOR_LENGTH);
                }
                break;
            case MovingPanel.RIGHT:
                {
                    final Ordinate o = new Ordinate(Ordinate.TYPE_Y);
                    o.setPosition(sector.getCreatePos());
                    a.setYOrdinate(o);
                    b.setYOrdinate(o);
                    a.setXOrdinate(new Ordinate(Ordinate.TYPE_X));
                    b.setXOrdinate(new Ordinate(Ordinate.TYPE_X));
                    a.setX(movingArea.getDoubleWidth() - PART_SECTOR_LENGTH - MovingArea.PART_SPACE);
                    b.setX(movingArea.getDoubleWidth() - MovingArea.PART_SPACE);
                }
                break;
            case MovingPanel.LEFT:
                {
                    final Ordinate o = new Ordinate(Ordinate.TYPE_Y);
                    o.setPosition(sector.getCreatePos());
                    a.setYOrdinate(o);
                    b.setYOrdinate(o);
                    a.setXOrdinate(new Ordinate(Ordinate.TYPE_X));
                    b.setXOrdinate(new Ordinate(Ordinate.TYPE_X));
                    a.setX(PART_SECTOR_LENGTH + MovingArea.PART_SPACE);
                    b.setX(MovingArea.PART_SPACE);
                }
                break;
        }
        // sector.setVisualAttributes(opps[0].getVisualAttributes());
        final PaintSector ps = new PaintSector(sector, a, b, movingArea);
        addSector(ps);
    } else {
        final Sector[] opps = sector.getStart().getCrosspoint().getOppozite(sector);
        if (opps.length == 0) {
            // sector.remove();
            return;
        }
        final Point a = new Point();
        final Point b = new Point();
        switch(sector.getStart().getBorderType()) {
            case MovingPanel.TOP:
                {
                    final Ordinate o = new Ordinate(Ordinate.TYPE_X);
                    o.setPosition(sector.getCreatePos());
                    a.setXOrdinate(o);
                    b.setXOrdinate(o);
                    a.setYOrdinate(new Ordinate(Ordinate.TYPE_Y));
                    b.setYOrdinate(new Ordinate(Ordinate.TYPE_Y));
                    a.setY(MovingArea.PART_SPACE);
                    b.setY(MovingArea.PART_SPACE + PART_SECTOR_LENGTH);
                }
                break;
            case MovingPanel.BOTTOM:
                {
                    final Ordinate o = new Ordinate(Ordinate.TYPE_X);
                    o.setPosition(sector.getCreatePos());
                    a.setXOrdinate(o);
                    b.setXOrdinate(o);
                    a.setYOrdinate(new Ordinate(Ordinate.TYPE_Y));
                    b.setYOrdinate(new Ordinate(Ordinate.TYPE_Y));
                    a.setY(movingArea.getDoubleHeight() - MovingArea.PART_SPACE);
                    b.setY(movingArea.getDoubleHeight() - MovingArea.PART_SPACE - PART_SECTOR_LENGTH);
                }
                break;
            case MovingPanel.RIGHT:
                {
                    final Ordinate o = new Ordinate(Ordinate.TYPE_Y);
                    o.setPosition(sector.getCreatePos());
                    a.setYOrdinate(o);
                    b.setYOrdinate(o);
                    a.setXOrdinate(new Ordinate(Ordinate.TYPE_X));
                    b.setXOrdinate(new Ordinate(Ordinate.TYPE_X));
                    a.setX(movingArea.getDoubleWidth() - MovingArea.PART_SPACE);
                    b.setX(movingArea.getDoubleWidth() - MovingArea.PART_SPACE - PART_SECTOR_LENGTH);
                }
                break;
            case MovingPanel.LEFT:
                {
                    final Ordinate o = new Ordinate(Ordinate.TYPE_Y);
                    o.setPosition(sector.getCreatePos());
                    a.setYOrdinate(o);
                    b.setYOrdinate(o);
                    a.setXOrdinate(new Ordinate(Ordinate.TYPE_X));
                    b.setXOrdinate(new Ordinate(Ordinate.TYPE_X));
                    a.setX(MovingArea.PART_SPACE);
                    b.setX(MovingArea.PART_SPACE + PART_SECTOR_LENGTH);
                }
                break;
        }
        if (opps.length == 0) {
            sector.remove();
        } else {
            // sector.setVisualAttributes(opps[0].getVisualAttributes());
            final PaintSector ps = new PaintSector(sector, a, b, movingArea);
            addSector(ps);
        }
    }
}
Also used : Sector(com.ramussoft.pb.Sector) NSector(com.ramussoft.pb.data.negine.NSector) FloatPoint(com.dsoft.pb.types.FloatPoint)

Aggregations

Sector (com.ramussoft.pb.Sector)50 NSector (com.ramussoft.pb.data.negine.NSector)40 Crosspoint (com.ramussoft.pb.Crosspoint)29 Function (com.ramussoft.pb.Function)25 NFunction (com.ramussoft.pb.data.negine.NFunction)19 Vector (java.util.Vector)19 Stream (com.ramussoft.pb.Stream)18 Row (com.ramussoft.pb.Row)15 FloatPoint (com.dsoft.pb.types.FloatPoint)10 PaintSector (com.ramussoft.pb.idef.elements.PaintSector)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 AbstractSector (com.ramussoft.pb.data.AbstractSector)7 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 NStream (com.ramussoft.pb.data.negine.NStream)4 Point (com.ramussoft.pb.idef.elements.Point)4 DataLoader (com.dsoft.utils.DataLoader)3 NCrosspoint (com.ramussoft.pb.data.negine.NCrosspoint)3 DFDFunction (com.ramussoft.pb.dfd.visual.DFDFunction)3