Use mxICell#insert for port modification (at this time the ordering param should be set)
Keep addPort() only for operations which need an ordering update.
Bug: 5625
Bug: 5626
Bug: 9014
Change-Id: I07c38a8a6089b47d9a8c97cb0152f20770c31846
<add as="verticalLabelPosition" value="bottom"/>
<add as="verticalAlign" value="top"/>
<add as="displayedLabel" value="MUX"/>
+ <add as="spacing" value="2"/>
</add>
<add as="DEMUX" extend="blockWithLabel">
<add as="verticalLabelPosition" value="bottom"/>
<add as="verticalAlign" value="top"/>
<add as="displayedLabel" value="DEMUX"/>
+ <add as="spacing" value="2"/>
</add>
<!-- COMMONLY USED BLOCKS -->
<add as="OUT_f" extend="blockWithLabel">
/**
* Add a port on the block.
+ *
+ * This call should only be used when a port reordering operation must be performed.
+ *
* @param port The port to be added to the block
*/
public void addPort(BasicPort port) {
insert(port);
- BlockPositioning.updateBlockView(this);
port.setOrdering(BasicBlockInfo.getAllTypedPorts(this, false, port.getClass()).size());
+ BlockPositioning.updateBlockView(this);
}
/**
/**
* Add a port on the block.
- *
- * @param port
- * The port to be added to the block
- * @see org.scilab.modules.xcos.block.BasicBlock#addPort(org.scilab.modules.xcos.port.BasicPort)
+ *
+ * @param child the port to add
+ * @param index index where to put the child
*/
@Override
- public void addPort(BasicPort port) {
- super.addPort(port);
- port.setVisible(false);
+ public mxICell insert(mxICell child, int index) {
+ child.setVisible(false);
+ return super.insert(child, index);
}
-
+
/**
* @return input port
*/
import org.scilab.modules.xcos.port.BasicPort;
import org.scilab.modules.xcos.port.Orientation;
+import com.mxgraph.model.mxICell;
+
/**
* The Ground block has only one specificity : it's port position.
*/
/**
* Set the orientation before calling parent method.
- * @param port the port to add.
+ * @param child the port to add.
+ * @param index the index of the add
*/
@Override
- public void addPort(BasicPort port) {
- port.setOrientation(Orientation.NORTH);
- super.addPort(port);
+ public mxICell insert(mxICell child, int index) {
+ if (child instanceof BasicPort) {
+ ((BasicPort) child).setOrientation(Orientation.NORTH);
+ }
+ return super.insert(child, index);
}
}
import org.scilab.modules.xcos.port.BasicPort;
import org.scilab.modules.xcos.port.Orientation;
import org.scilab.modules.xcos.port.command.CommandPort;
+import org.scilab.modules.xcos.port.input.InputPort;
import org.scilab.modules.xcos.port.output.OutputPort;
+import com.mxgraph.model.mxICell;
+
/**
* Implement a round block with inputs spread around the block.
*/
getParametersPCS().addPropertyChangeListener("realParameters", ProdPortLabelingListener.getInstance());
}
}
-
+
/**
- * Calculate current port position on the block and add it.
- * @param port the port to add
- * @see org.scilab.modules.xcos.block.BasicBlock#addPort(org.scilab.modules.xcos.port.BasicPort)
+ * Insert a port into this block.
+ *
+ * @param child the port to add
+ * @param index the index
*/
@Override
- public void addPort(BasicPort port) {
+ public mxICell insert(mxICell child, int index) {
/*
- * Any output port keep its orientation.
+ * Any input are placed around the block.
*/
- if (port instanceof OutputPort || port instanceof CommandPort) {
- super.addPort(port);
- return;
+ if (child instanceof InputPort) {
+ final InputPort port = (InputPort) child;
+ port.setOrientation(getPortOrientation(port.getOrdering()));
+
}
- /*
- * The other ones are placed around the block.
- */
- final int def = port.getOrientation().ordinal() - 1;
- final int side = getChildCount();
-
- final int rotatedSide = (side + def + SIDE_NUMBER) % SIDE_NUMBER;
-
- final Orientation current = Orientation.values()[rotatedSide];
- port.setOrientation(current);
-
- super.addPort(port);
+ return super.insert(child, index);
+ }
+
+ /**
+ * Get the Orientation from the order
+ * @param order the port ordering
+ * @return the selected orientation
+ */
+ private Orientation getPortOrientation(int order) {
+ final Orientation ret;
+
+ switch (order) {
+ case 1:
+ ret = Orientation.SOUTH;
+ break;
+
+ case 2:
+ ret = Orientation.WEST;
+ break;
+
+ case 3:
+ ret = Orientation.NORTH;
+ break;
+
+ default:
+ ret = Orientation.WEST;
+ break;
+ }
+ return ret;
}
}
import org.scilab.modules.xcos.port.output.OutputPort;
import org.scilab.modules.xcos.utils.BlockPositioning;
+import com.mxgraph.model.mxICell;
+
/**
* The VoltageSensor block has only one specificity : it's port position.
*/
/**
* Set the orientation before calling parent method.
- * @param port the port to add.
+ * @param child the port to add.
+ * @param index the port index
*/
@Override
- public void addPort(BasicPort port) {
- if (port instanceof OutputPort) {
- insert(port);
- int order = BasicBlockInfo.getAllTypedPorts(this, false, OutputPort.class).size();
- port.setOrdering(order);
+ public mxICell insert(mxICell child, int index) {
+ if (child instanceof OutputPort) {
+ final OutputPort port = (OutputPort) child;
// Only orientate the first output port
- if (order == 1) {
+ if (port.getOrdering() == 1) {
port.setOrientation(Orientation.SOUTH);
- } else {
- port.setOrientation(Orientation.EAST);
}
-
- BlockPositioning.updateBlockView(this);
- } else {
- super.addPort(port);
}
+
+ return super.insert(child, index);
}
}
import org.scilab.modules.xcos.io.scicos.ScicosFormatException.WrongElementException;
import org.scilab.modules.xcos.io.scicos.ScicosFormatException.WrongStructureException;
import org.scilab.modules.xcos.io.scicos.ScicosFormatException.WrongTypeException;
+import org.scilab.modules.xcos.port.BasicPort;
import org.scilab.modules.xcos.port.command.CommandPort;
import org.scilab.modules.xcos.port.control.ControlPort;
if (dataNbControlPort.getRealPart() != null) {
int nbControlPort = dataNbControlPort.getHeight();
for (int i = 0; i < nbControlPort; i++) {
- into.addPort(new ControlPort());
+ final BasicPort port = new ControlPort();
+
+ // do not use BasicPort#addPort() to avoid the view update
+ port.setOrdering(i + 1);
+ into.insert(port, i);
}
}
if (dataNbCommandPort.getRealPart() != null) {
int nbCommandPort = dataNbCommandPort.getHeight();
for (int i = 0; i < nbCommandPort; i++) {
- into.addPort(new CommandPort());
+ final BasicPort port = new CommandPort();
+
+ // do not use BasicPort#addPort() to avoid the view update
+ port.setOrdering(i + 1);
+ into.insert(port, i);
}
}
}