Search in sources :

Example 26 with Crosspoint

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

the class UserTemplate method getCrosspoint.

private Crosspoint getCrosspoint(final DataPlugin dataPlugin, final Hashtable<Long, Long> trans, final InputStream stream) throws IOException {
    long id;
    Crosspoint c;
    id = DataLoader.readLong(stream);
    final Long cId = trans.get(id);
    if (cId == null) {
        c = dataPlugin.createCrosspoint();
        trans.put(id, c.getGlobalId());
    } else
        c = dataPlugin.findCrosspointByGlobalId(cId);
    return c;
}
Also used : NCrosspoint(com.ramussoft.pb.data.negine.NCrosspoint) Crosspoint(com.ramussoft.pb.Crosspoint)

Example 27 with Crosspoint

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

the class AbstractSector method getStreamedSectors.

/**
 * Метод повертає набір під’єднаних секторв, які мають зв’язок з потоком.
 *
 * @param point
 * @param v
 */
protected void getStreamedSectors(final Crosspoint point, final Vector<Sector> v) {
    if (point == null)
        return;
    final int oLen = v.size();
    point.getSectors(v);
    final int len = v.size();
    final Vector<Sector> r = new Vector<Sector>();
    for (int i = oLen; i < len; i++) if (!v.get(i).getFunction().equals(getFunction()) || v.get(i).getStream() == null || !v.get(i).getStream().equals(getStream()))
        r.add(v.get(i));
    for (int i = 0; i < r.size(); i++) v.remove(r.get(i));
}
Also used : Sector(com.ramussoft.pb.Sector) NSector(com.ramussoft.pb.data.negine.NSector) Vector(java.util.Vector) Crosspoint(com.ramussoft.pb.Crosspoint)

Example 28 with Crosspoint

use of com.ramussoft.pb.Crosspoint 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 29 with Crosspoint

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

the class UserTemplate method createChilds.

public void createChilds(final Function function, final DataPlugin dataPlugin) {
    Hashtable<Long, Long> trans = new Hashtable<Long, Long>();
    final MovingArea ma = new MovingArea(dataPlugin);
    ma.setDataPlugin(dataPlugin);
    ma.setActiveFunction(function);
    final SectorRefactor refactor = ma.getRefactor();
    try {
        final ByteArrayInputStream streamr = new ByteArrayInputStream(data);
        final ObjectInputStream stream = new ObjectInputStream(streamr);
        final MemoryData data = new MemoryData();
        int l = DataLoader.readInteger(stream);
        for (int i = 0; i < l; i++) {
            final Function c = (Function) dataPlugin.createRow(function, true);
            c.setName(functionNames.get(i));
            if (i < functionTypes.size())
                c.setType(functionTypes.get(i));
            if (i < functionLinks.size()) {
                Row r = dataPlugin.findRowByGlobalId(functionLinks.get(i));
                if (r != null) {
                    if (r instanceof Stream) {
                        Stream st = (Stream) r;
                        Stream s = (Stream) dataPlugin.createRow(dataPlugin.getBaseStream(), true);
                        s.setAttachedStatus(st.getAttachedStatus());
                        s.setEmptyName(st.isEmptyName());
                        s.setRows(st.getAdded());
                        c.setLink(s.getElement().getId());
                    }
                }
            }
            final long id = DataLoader.readLong(stream);
            trans.put(id, c.getElement().getId());
            c.setBounds(DataLoader.readFRectangle(stream));
            c.setFont(DataLoader.readFont(stream, data));
            c.setBackground(DataLoader.readColor(stream, data));
            c.setForeground(DataLoader.readColor(stream, data));
        }
        // Read version of
        final int ver = DataLoader.readInteger(stream);
        // Paint
        // Sector format
        l = DataLoader.readInteger(stream);
        HashMap<Sector, List<SectorPointPersistent>> pointsCache = new HashMap<Sector, List<SectorPointPersistent>>();
        HashMap<Long, Long> pointIds = new HashMap<Long, Long>();
        for (int i = 0; i < l; i++) {
            final Sector s = dataPlugin.createSector();
            s.setFunction(function);
            final long id = DataLoader.readLong(stream);
            trans.put(id, ((NSector) s).getElementId());
            final byte[] va = DataLoader.readBytes(stream);
            s.setVisualAttributes(va);
            List<SectorPointPersistent> points = (List) stream.readObject();
            pointsCache.put(s, points);
            normalize(points, dataPlugin.getEngine(), pointIds);
            s.setSectorPointPersistents(points);
            s.setSectorProperties((SectorPropertiesPersistent) stream.readObject());
            // final byte bs[] = DataLoader.readBytes(stream);
            // final ByteArrayInputStream ba = new ByteArrayInputStream(bs);
            final PaintSector ps = PaintSector.loadFromSector(ver, ma, data, dataPlugin, s);
            refactor.addSector(ps);
            Crosspoint c;
            if (DataLoader.readBoolean(stream)) {
                c = getCrosspoint(dataPlugin, trans, stream);
                s.getStart().setCrosspointA(c);
            }
            loadBorder(s.getStart(), stream, trans, dataPlugin, refactor, ps, true);
            s.getStart().commit();
            if (DataLoader.readBoolean(stream)) {
                c = getCrosspoint(dataPlugin, trans, stream);
                s.getEnd().setCrosspointA(c);
            }
            loadBorder(s.getEnd(), stream, trans, dataPlugin, refactor, ps, false);
            s.getEnd().commit();
            if (DataLoader.readBoolean(stream)) {
                int count = DataLoader.readInteger(stream);
                List<Row> rows = new ArrayList<Row>();
                for (int j = 0; j < count; j++) {
                    Row row = loadRow(stream, dataPlugin);
                    if (row != null)
                        rows.add(row);
                }
                if (rows.size() > 0) {
                    Stream stream2 = (Stream) dataPlugin.createRow(dataPlugin.getBaseStream(), true);
                    stream2.setRows(rows.toArray(new Row[rows.size()]));
                    ((NSector) s).setThisStream(stream2);
                }
            }
        }
        setPoints(pointsCache);
        refactor.saveToFunction();
    } catch (final Exception e) {
        e.printStackTrace();
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Function(com.ramussoft.pb.Function) NFunction(com.ramussoft.pb.data.negine.NFunction) NSector(com.ramussoft.pb.data.negine.NSector) PaintSector(com.ramussoft.pb.idef.elements.PaintSector) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectInputStream(java.io.ObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectOutputStream(java.io.ObjectOutputStream) OutputStream(java.io.OutputStream) Stream(com.ramussoft.pb.Stream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) List(java.util.List) MovingArea(com.ramussoft.pb.idef.visual.MovingArea) SectorRefactor(com.ramussoft.pb.idef.elements.SectorRefactor) Hashtable(java.util.Hashtable) Sector(com.ramussoft.pb.Sector) NSector(com.ramussoft.pb.data.negine.NSector) PaintSector(com.ramussoft.pb.idef.elements.PaintSector) NCrosspoint(com.ramussoft.pb.data.negine.NCrosspoint) Crosspoint(com.ramussoft.pb.Crosspoint) NCrosspoint(com.ramussoft.pb.data.negine.NCrosspoint) Crosspoint(com.ramussoft.pb.Crosspoint) IOException(java.io.IOException) ByteArrayInputStream(java.io.ByteArrayInputStream) MemoryData(com.dsoft.utils.DataLoader.MemoryData) SectorPointPersistent(com.ramussoft.idef0.attribute.SectorPointPersistent) Row(com.ramussoft.pb.Row) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

Crosspoint (com.ramussoft.pb.Crosspoint)29 NSector (com.ramussoft.pb.data.negine.NSector)18 Sector (com.ramussoft.pb.Sector)16 FloatPoint (com.dsoft.pb.types.FloatPoint)15 Function (com.ramussoft.pb.Function)12 NFunction (com.ramussoft.pb.data.negine.NFunction)11 NCrosspoint (com.ramussoft.pb.data.negine.NCrosspoint)9 Row (com.ramussoft.pb.Row)6 Vector (java.util.Vector)6 AbstractSector (com.ramussoft.pb.data.AbstractSector)5 PaintSector (com.ramussoft.pb.idef.elements.PaintSector)5 Stream (com.ramussoft.pb.Stream)4 Point (com.ramussoft.pb.idef.elements.Point)4 DFDFunction (com.ramussoft.pb.dfd.visual.DFDFunction)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ArrayList (java.util.ArrayList)3 DFDSFunction (com.ramussoft.pb.dfds.visual.DFDSFunction)2 Ordinate (com.ramussoft.pb.idef.elements.Ordinate)2 SectorRefactor (com.ramussoft.pb.idef.elements.SectorRefactor)2