Search in sources :

Example 1 with SectorPointPersistent

use of com.ramussoft.idef0.attribute.SectorPointPersistent in project ramus by Vitaliy-Yakovchuk.

the class PaintSector method loadPoints.

private static void loadPoints(final DataLoader.MemoryData memoryData, final DataPlugin dataPlugin, final PaintSector sector) throws IOException {
    List<SectorPointPersistent> spps = sector.sector.getSectorPointPersistents();
    sector.points = new Point[spps.size()];
    int l = spps.size();
    for (int i = 0; i < l; i++) {
        final Point p = new Point();
        p.load(memoryData, spps.get(i));
        sector.points[i] = p;
    }
}
Also used : SectorPointPersistent(com.ramussoft.idef0.attribute.SectorPointPersistent) FloatPoint(com.dsoft.pb.types.FloatPoint) NCrosspoint(com.ramussoft.pb.data.negine.NCrosspoint) Crosspoint(com.ramussoft.pb.Crosspoint) FloatPoint(com.dsoft.pb.types.FloatPoint)

Example 2 with SectorPointPersistent

use of com.ramussoft.idef0.attribute.SectorPointPersistent in project ramus by Vitaliy-Yakovchuk.

the class UserTemplate method normalize.

private void normalize(List<SectorPointPersistent> list, Engine engine, HashMap<Long, Long> pointIds) {
    for (SectorPointPersistent spp : list) {
        Long id = pointIds.get(spp.getXOrdinateId());
        if (id == null) {
            id = IDEF0Plugin.getNextOrdinateId(engine);
            pointIds.put(spp.getXOrdinateId(), id);
        }
        spp.setXOrdinateId(id);
        id = pointIds.get(spp.getYOrdinateId());
        if (id == null) {
            id = IDEF0Plugin.getNextOrdinateId(engine);
            pointIds.put(spp.getYOrdinateId(), id);
        }
        spp.setYOrdinateId(id);
    }
}
Also used : SectorPointPersistent(com.ramussoft.idef0.attribute.SectorPointPersistent)

Example 3 with SectorPointPersistent

use of com.ramussoft.idef0.attribute.SectorPointPersistent in project ramus by Vitaliy-Yakovchuk.

the class PaintSector method savePoints.

private static void savePoints(final PaintSector sector, Engine engine) {
    List<SectorPointPersistent> list = new ArrayList<SectorPointPersistent>();
    for (final Point element : sector.points) {
        // element.saveToStreamOld(stream, memoryData);
        try {
            list.add(element.save(engine));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    sector.sector.setSectorPointPersistents(list);
}
Also used : ArrayList(java.util.ArrayList) SectorPointPersistent(com.ramussoft.idef0.attribute.SectorPointPersistent) FloatPoint(com.dsoft.pb.types.FloatPoint) IOException(java.io.IOException)

Example 4 with SectorPointPersistent

use of com.ramussoft.idef0.attribute.SectorPointPersistent in project ramus by Vitaliy-Yakovchuk.

the class Point method save.

public SectorPointPersistent save(Engine engine) {
    SectorPointPersistent persistent = new SectorPointPersistent();
    if (xOrdinate.getOrdinateId() < 0l)
        xOrdinate.setOrdinateId(IDEF0Plugin.getNextOrdinateId(engine));
    if (yOrdinate.getOrdinateId() < 0l)
        yOrdinate.setOrdinateId(IDEF0Plugin.getNextOrdinateId(engine));
    persistent.setXOrdinateId(xOrdinate.getOrdinateId());
    persistent.setYOrdinateId(yOrdinate.getOrdinateId());
    persistent.setXPosition(xOrdinate.getPosition());
    persistent.setYPosition(yOrdinate.getPosition());
    persistent.setPointType(type);
    return persistent;
}
Also used : SectorPointPersistent(com.ramussoft.idef0.attribute.SectorPointPersistent)

Example 5 with SectorPointPersistent

use of com.ramussoft.idef0.attribute.SectorPointPersistent 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

SectorPointPersistent (com.ramussoft.idef0.attribute.SectorPointPersistent)5 FloatPoint (com.dsoft.pb.types.FloatPoint)2 Crosspoint (com.ramussoft.pb.Crosspoint)2 NCrosspoint (com.ramussoft.pb.data.negine.NCrosspoint)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 MemoryData (com.dsoft.utils.DataLoader.MemoryData)1 Function (com.ramussoft.pb.Function)1 Row (com.ramussoft.pb.Row)1 Sector (com.ramussoft.pb.Sector)1 Stream (com.ramussoft.pb.Stream)1 NFunction (com.ramussoft.pb.data.negine.NFunction)1 NSector (com.ramussoft.pb.data.negine.NSector)1 PaintSector (com.ramussoft.pb.idef.elements.PaintSector)1 SectorRefactor (com.ramussoft.pb.idef.elements.SectorRefactor)1 MovingArea (com.ramussoft.pb.idef.visual.MovingArea)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1