Search in sources :

Example 16 with NFunction

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

the class AbstractCrosspoint method remove1.

public void remove1(final Sector sector) {
    // synchronized (dataPlugin) {
    final boolean b = isDLevel();
    removeData(sector);
    final Sector[] ins = getIns();
    final Sector[] outs = getOuts();
    if (b) {
        if (ins.length == 0 && outs.length == 1) {
            if (outs[0].getEnd().getCrosspoint() == null)
                if (outs[0].getStart().getBorderType() >= 0)
                    outs[0].remove();
                else {
                /*Function function = outs[0].getStart().getFunction();
                        if (function != null
								&& function.getType() == Function.TYPE_DFDS_ROLE) {
							((NFunction) function).remove();
							outs[0].remove();
						}*/
                }
        } else if (ins.length == 1 && outs.length == 0) {
            if (ins[0].getStart().getCrosspoint() == null)
                if (ins[0].getEnd().getBorderType() >= 0)
                    ins[0].remove();
                else {
                    Function function = ins[0].getEnd().getFunction();
                    if (function != null && function.getType() == Function.TYPE_DFDS_ROLE) {
                        ((NFunction) function).remove();
                        ins[0].remove();
                    }
                }
        }
    }
    if (getIns().length == 0 && getOuts().length == 0) {
        dataPlugin.removeCrosspoint(this);
    }
// }
}
Also used : NFunction(com.ramussoft.pb.data.negine.NFunction) Function(com.ramussoft.pb.Function) NFunction(com.ramussoft.pb.data.negine.NFunction) Sector(com.ramussoft.pb.Sector) NSector(com.ramussoft.pb.data.negine.NSector)

Example 17 with NFunction

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

the class DFDSFunction method paint.

@Override
public void paint(Graphics2D g) {
    g.setColor(function.getBackground());
    final Rectangle2D rect = movingArea.getBounds(getBounds());
    g.fill(rect);
    g.setFont(function.getFont());
    Object nameObject = ((NFunction) function).getNameObject();
    if (!(nameObject instanceof DFDSName)) {
        DFDSName dfdsName = new DFDSName();
        if (nameObject == null)
            nameObject = "";
        dfdsName.setShortName(String.valueOf(nameObject));
        dfdsName.setLongName("");
        nameObject = dfdsName;
    }
    DFDSName name = (DFDSName) nameObject;
    if (!transparent && !movingArea.isPrinting() || isNegative()) {
        final Rectangle2D rec = movingArea.getBounds(getBounds());
        g.setColor(fiterColor(movingArea.getBackground()));
        g.fill(rec);
    }
    Font font = getFont();
    g.setFont(font);
    g.setColor(fiterColor(getColor()));
    FRectangle textBounds = getTextBounds();
    FRectangle p = movingArea.paintText(g, // string + ". " +
    name.getShortName(), textBounds, Line.CENTER_ALIGN, 0, true);
    textBounds.setY(textBounds.getY() + p.getHeight() + 2);
    textBounds.setHeight(textBounds.getHeight() - p.getHeight() - 2);
    String term = function.getTerm();
    if (term != null && term.length() > 0) {
        double y = movingArea.getIDoubleOrdinate(p.getBottom()) + 1;
        Stroke stroke = g.getStroke();
        g.setStroke(new BasicStroke(1, 1, 1, 2, new float[] { (float) movingArea.getIDoubleOrdinate(1), (float) movingArea.getIDoubleOrdinate(2) }, (float) movingArea.getIDoubleOrdinate(2)));
        g.draw(new Line2D.Double(rect.getX(), y, rect.getMaxX(), y));
        y++;
        g.setStroke(stroke);
        int size = font.getSize() - movingArea.secondNamePartMinus;
        if (size < 1)
            size = 1;
        g.setFont(new Font(font.getName(), font.getStyle(), size));
        FRectangle fr = movingArea.paintText(g, TERMS, textBounds, Line.LEFT_ALIGN, 0, true);
        FRectangle r = new FRectangle(textBounds);
        r.setX(textBounds.getX() + fr.getWidth() + 2);
        r.setWidth(textBounds.getWidth() - fr.getWidth() - 2);
        p = movingArea.paintText(g, term, r, Line.LEFT_ALIGN, 0, true);
        textBounds.setY(textBounds.getY() + p.getHeight() + 2);
        textBounds.setHeight(textBounds.getHeight() - p.getHeight() - 2);
    }
    if (name.getLongName() != null && name.getLongName().length() > 0) {
        double y = movingArea.getIDoubleOrdinate(p.getBottom()) + 1;
        Stroke stroke = g.getStroke();
        g.setStroke(new BasicStroke(1, 1, 1, 2, new float[] { (float) movingArea.getIDoubleOrdinate(1), (float) movingArea.getIDoubleOrdinate(2) }, (float) movingArea.getIDoubleOrdinate(2)));
        g.draw(new Line2D.Double(rect.getX(), y, rect.getMaxX(), y));
        y++;
        g.setStroke(stroke);
        int size = font.getSize() - movingArea.secondNamePartMinus;
        if (size < 1)
            size = 1;
        g.setFont(new Font(font.getName(), font.getStyle(), size));
        movingArea.paintText(g, name.getLongName(), textBounds, Line.LEFT_ALIGN, 0, true);
    }
    paintBorder(g);
    final Stroke tmp = g.getStroke();
    g.draw(rect);
    if (!function.isHaveRealChilds()) {
        g.draw(new Line2D.Double(rect.getMaxX() - Math.round(movingArea.getIDoubleOrdinate(4)), rect.getY(), rect.getMaxX(), rect.getY() + Math.round(movingArea.getIDoubleOrdinate(4))));
    }
    g.setStroke(new BasicStroke(2));
    g.setFont(function.getFont());
    paintTringle(g);
    g.setStroke(tmp);
    List<DFDSRole> roles = movingArea.getDFDSRoles(this);
    double xc = rect.getCenterX();
    double yc = rect.getCenterY();
    for (DFDSRole role : roles) {
        Rectangle2D r = movingArea.getBounds(role.getBounds());
        if (!rect.intersects(r)) {
            double x = r.getCenterX();
            double y = r.getCenterY();
            double dx = Math.abs(xc - x);
            double dy = Math.abs(yc - y);
            if (dx > dy) {
                if (xc < x)
                    x = r.getX();
                else
                    x = r.getMaxX();
            } else {
                if (yc < y)
                    y = r.getY();
                else
                    y = r.getMaxY();
            }
            ArrowPainter.paintTilda(g, x, y, rect.getX(), rect.getY(), rect.getMaxX(), rect.getMaxY(), 4, movingArea);
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) NFunction(com.ramussoft.pb.data.negine.NFunction) Rectangle2D(java.awt.geom.Rectangle2D) Line2D(java.awt.geom.Line2D) Font(java.awt.Font) FloatPoint(com.dsoft.pb.types.FloatPoint) Crosspoint(com.ramussoft.pb.Crosspoint) FRectangle(com.dsoft.pb.types.FRectangle) DFDSName(com.ramussoft.idef0.attribute.DFDSName)

Example 18 with NFunction

use of com.ramussoft.pb.data.negine.NFunction 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 19 with NFunction

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

the class MovingArea method createLevel.

public void createLevel() {
    if (JOptionPane.showConfirmDialog(this, ResourceLoader.getString("MovingArea.addingLevelWarning"), ResourceLoader.getString("warning"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION)
        return;
    final SectorRefactor r = new SectorRefactor(this);
    r.loadFromFunction(activeFunction, false);
    startUserTransaction();
    Function f = activeFunction;
    final Vector<Row> childs = dataPlugin.getChilds(f, true);
    NFunction n = (NFunction) 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]);
    for (int i = 0; i < childs.size(); i++) {
        final Function c = (Function) childs.get(i);
        c.setParentRow(n);
    }
    for (int i = 0; i < r.getSectorsCount(); i++) r.getSector(i).getSector().setFunction(n);
    ((NFunction) f).clearSectorsBuffer();
    commitUserTransaction();
}
Also used : SectorRefactor(com.ramussoft.pb.idef.elements.SectorRefactor) 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) NFunction(com.ramussoft.pb.data.negine.NFunction) Row(com.ramussoft.pb.Row) 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)

Example 20 with NFunction

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

the class MovingArea method createBlocks.

public void createBlocks(String[] names) {
    double fromX = 20;
    double fromY = 20;
    double x = fromX;
    double y = fromY;
    Attribute attribute = null;
    for (String name : names) {
        Function function = createFunctionalObject(x, y, Function.TYPE_FUNCTION, activeFunction);
        x += 110;
        if (x + 110 + 20 > CLIENT_WIDTH) {
            x = fromX;
            y += 60;
        }
        if (attribute == null)
            attribute = getDataPlugin().getEngine().getAttribute(getDataPlugin().getEngine().getQualifier(((NFunction) function).getQualifierId()).getAttributeForName());
        Object object;
        if (attribute.getAttributeType().getTypeName().equals("DFDSName")) {
            DFDSName dfdsName = new DFDSName();
            dfdsName.setShortName(name);
            dfdsName.setLongName("");
            object = dfdsName;
        } else
            object = name;
        ((NFunction) function).setAttribute(attribute, object);
    }
}
Also used : 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) Attribute(com.ramussoft.common.Attribute) NFunction(com.ramussoft.pb.data.negine.NFunction) DFDSName(com.ramussoft.idef0.attribute.DFDSName) DFDObject(com.ramussoft.pb.dfd.visual.DFDObject)

Aggregations

NFunction (com.ramussoft.pb.data.negine.NFunction)24 Function (com.ramussoft.pb.Function)10 Row (com.ramussoft.pb.Row)9 FloatPoint (com.dsoft.pb.types.FloatPoint)8 FRectangle (com.dsoft.pb.types.FRectangle)7 Attribute (com.ramussoft.common.Attribute)7 Qualifier (com.ramussoft.common.Qualifier)7 Point (com.ramussoft.pb.idef.elements.Point)7 Crosspoint (com.ramussoft.pb.Crosspoint)6 PaintSector (com.ramussoft.pb.idef.elements.PaintSector)6 NSector (com.ramussoft.pb.data.negine.NSector)5 SectorRefactor (com.ramussoft.pb.idef.elements.SectorRefactor)5 Element (com.ramussoft.common.Element)4 Sector (com.ramussoft.pb.Sector)4 DFDFunction (com.ramussoft.pb.dfd.visual.DFDFunction)4 DFDSFunction (com.ramussoft.pb.dfds.visual.DFDSFunction)4 MemoryData (com.dsoft.utils.DataLoader.MemoryData)3 Engine (com.ramussoft.common.Engine)3 DataPlugin (com.ramussoft.pb.DataPlugin)3 PerspectivePoint (com.ramussoft.pb.idef.elements.SectorRefactor.PerspectivePoint)3