superBlock.invalidateRpar();
superBlock.updateExportedPort();
+ /*
+ * Clear the transaction log in the child.
+ * From the user point of view, the operation cannot be undo'ed.
+ */
+ childGraph.getUndoManager().clear();
+
Xcos.getInstance().addDiagram(parentGraph.getSavedFile(), childGraph);
} finally {
parentGraph.getModel().endUpdate();
cellsToCopy.add(b.getChildLink());
}
+ // create the local array to use the JGraphX API
+ final Object[] cells = cellsToCopy.toArray();
+
+ /*
+ * Translate the cells to the origin
+ *
+ * NOTE: this should be done on the parent diagram because
+ * getBoundsForCells only works for already added cells (not on the transaction)
+ */
+ mxRectangle rect = parentGraph.getBoundsForCells(cells, true, true, false);
+ parentGraph.moveCells(cells, -rect.getX(), -rect.getY());
+
/*
* Really copy the cells
*/
- final Object[] cells = cellsToCopy.toArray();
parentGraph.removeCells(cells, false);
childGraph.addCells(cells);
import org.scilab.modules.xcos.utils.XcosEvent;
import org.scilab.modules.xcos.utils.XcosMessages;
-import com.mxgraph.model.mxCell;
import com.mxgraph.model.mxICell;
import com.mxgraph.util.mxEvent;
import com.mxgraph.util.mxEventObject;
-import com.mxgraph.util.mxUtils;
public final class SuperBlockDiagram extends XcosDiagram implements Serializable, Cloneable {
/**
* Validate I/O ports.
*
+ * /!\ No model modification should be made in this method, this is only a validation method.
+ *
* @param cell
* Cell that represents the cell to validate.
* @param context
err = str.toString();
}
- // Update the port labels on the superblock
- if (err == null) {
- mxCell identifier = this.getOrCreateCellIdentifier(block);
- final Object current = this.getModel().getValue(identifier);
- String text = "";
- if (current == null) {
- text = "";
- } else {
- text = mxUtils.getBodyMarkup(current.toString(), false);
- }
- this.fireEvent(new mxEventObject(mxEvent.LABEL_CHANGED, "cell", identifier, "value", text, "parent", block));
- }
-
return err;
}
if (block != null) {
block.updateExportedPort();
}
+
+ // validate display errors
+ graph.getAsComponent().clearCellOverlays();
+ graph.getAsComponent().validateGraph();
}
}
import com.mxgraph.model.mxGraphModel.mxChildChange;
import com.mxgraph.model.mxGraphModel.mxStyleChange;
import com.mxgraph.model.mxICell;
+import com.mxgraph.model.mxIGraphModel;
import com.mxgraph.model.mxIGraphModel.mxAtomicGraphModelChange;
import com.mxgraph.util.mxEvent;
import com.mxgraph.util.mxEventObject;
import com.mxgraph.util.mxRectangle;
import com.mxgraph.util.mxUndoableEdit;
import com.mxgraph.util.mxUndoableEdit.mxUndoableChange;
+import com.mxgraph.util.mxUtils;
import com.mxgraph.view.mxGraphSelectionModel;
import com.mxgraph.view.mxMultiplicity;
import com.mxgraph.view.mxStylesheet;
@Override
public boolean filter(Object cell) {
if (cell instanceof BasicBlock) {
+ final BasicBlock blk = (BasicBlock) cell;
+
// Update parent on cell addition
- ((BasicBlock) cell).setParentDiagram(diagram);
+ blk.setParentDiagram(diagram);
// update port numbering
- diagram.updateIOBlocks((BasicBlock) cell);
+ diagram.updateIOBlocks(blk);
+
+ // Fire an identifier update to let the I/O ports update their labels
+ mxCell identifier = diagram.getCellIdentifier(blk);
+ if (identifier != null) {
+ final Object current = diagram.getModel().getValue(identifier);
+ if (current != null) {
+ final String text = mxUtils.getBodyMarkup(current.toString(), false);
+ diagram.fireEvent(new mxEventObject(mxEvent.LABEL_CHANGED, "cell", identifier, "value", text, "parent", blk));
+ }
+ }
+
+ diagram.getView().invalidate();
}
return false;
}
for (final Object object : changedCells) {
if (object instanceof BasicBlock) {
final BasicBlock current = (BasicBlock) object;
+ final XcosDiagram graph = current.getParentDiagram();
// When we change the style property we have to update
// some BasiBlock fields
// update the superblock container ports if the block is
// inside a superblock diagram
- if (current.getParentDiagram() instanceof SuperBlockDiagram) {
+ if (graph instanceof SuperBlockDiagram) {
SuperBlockDiagram superdiagram = (SuperBlockDiagram) current.getParentDiagram();
SuperBlock superblock = superdiagram.getContainer();
superblock.updateExportedPort();
// force a refresh of the block ports and links
// connected to these ports
- final int childCount = current.getParentDiagram().getModel().getChildCount(current);
+ final int childCount = model.getChildCount(current);
for (int i = 0; i < childCount; i++) {
- final Object port = current.getParentDiagram().getModel().getChildAt(current, i);
- current.getParentDiagram().getView().clear(port, true, true);
- final int edgeCount = current.getParentDiagram().getModel().getEdgeCount(port);
+ final Object port = model.getChildAt(current, i);
+ graph.getView().clear(port, true, true);
+ final int edgeCount = model.getEdgeCount(port);
for (int j = 0; j < edgeCount; j++) {
- final Object edge = current.getParentDiagram().getModel().getEdgeAt(port, j);
- current.getParentDiagram().getView().clear(edge, true, true);
+ final Object edge = model.getEdgeAt(port, j);
+ graph.getView().clear(edge, true, true);
}
}
// force a refresh of the block
- current.getParentDiagram().getView().clear(current, true, true);
+ graph.getView().clear(current, true, true);
- current.getParentDiagram().getView().validate();
- current.getParentDiagram().repaint();
+ graph.getView().validate();
+ graph.repaint();
}
}
} finally {
diagram.getView().clear(updatedBlock, true, true);
+ // validate display errors
+ diagram.getAsComponent().clearCellOverlays();
diagram.getAsComponent().validateGraph();
+
diagram.getView().validate();
} finally {
diagram.getModel().endUpdate();