Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Blocks replacement #191

Closed
Obijuan opened this issue Jan 5, 2018 · 6 comments
Closed

[Feature] Blocks replacement #191

Obijuan opened this issue Jan 5, 2018 · 6 comments
Assignees
Milestone

Comments

@Obijuan
Copy link
Member

Obijuan commented Jan 5, 2018

Currently, if you want to change one block for another (for example an updated block), you have to delete that block and insert the new one. The problem is that you lost all the connections. This is a little bit painful when your design is complex.

In addition, the replacement feature makes the exploration process of newbies much easier. Here are some examples, starting from the simplest one

  • Changing the state of a led:

This is the circuit for turning a led on:

ledon-01

With the replacement feature, you pick a new block, for example a bit 0:

ledon-03

put it over the block you want to change

ledon-04

click the mouse button and the block is replaced

ledon-05

If you replace a block by error, you can use ctr-z (undo) to move back to the previous state

Now imagine you want to make the led blinks. You just replace the bit by a heart. Pick the heart and put it over the block and click the button

ledon-06

ledon-07

I really think that this feature will make a difference in the educational project. I can image an icestudio sheet, with a simple circuit (like the hello world before) and different blocks on the left that change the behaviour on the led. The student just drag the blocks to test what they do with the led

ledon-08

There are many details that should be cover. Let's use this issue to document them

@Obijuan
Copy link
Member Author

Obijuan commented Jan 5, 2018

It would be great if the replacement works also with code blocks:

ledon-09

ledon-11

It brings the question... if the blocks have different names for their outputs, how should the replacement proceed? This is something that we should solve by using it. We will discover the rules as we test it

One rule might be:

  1. If the two block have the same number of outputs, regardless of their names, the replacement operation will be done.

This rule will cover the above case

@Obijuan
Copy link
Member Author

Obijuan commented Jan 5, 2018

One important thing is that the wiring should remain the same after the replacement. I know it should be hard to implement. Let's say we have this circuit

ledon-13

And we want to replace the 1 by the heart. After the replacement has been done, the wiring should stay the same:

ledon-14

@Jesus89 Jesus89 modified the milestones: 0.2.3, 0.3.2 Jan 15, 2018
@Jesus89 Jesus89 self-assigned this Jan 15, 2018
@Jesus89 Jesus89 mentioned this issue Jan 20, 2018
6 tasks
@Jesus89
Copy link
Member

Jesus89 commented Jan 20, 2018

Hi!

I have created a PR for this: #198.

Now you can replace Generic, Code and Input blocks. When the block is replaced, the wires are replaced for each side (left, right and top). First: it tries to match the same name & size connections. Second: if there are ports with the same name, they are replaced by position.

The algorithms has also two steps: create a portsMap between the lowerBlock and the upperBlock, and try to replace the connected wires using this portsMap.

It also preserves the wire's vertices and Undo/Redo works for move&replace and create&replace blocks.

The only thing missing is the match between ports with different name. I need to figure out how to define this behavior to be consistent with the current algorithm.

@Jesus89
Copy link
Member

Jesus89 commented Jan 21, 2018

I have added the following rule. This rule is applied after the first names&size match:

If there is no match replace the connections if the port's size matches ignoring the port's name.

This is an example:

drag replace - 3

@Obijuan
Copy link
Member Author

Obijuan commented Jan 21, 2018

That's awesome! Thanks! :-)

@Obijuan
Copy link
Member Author

Obijuan commented Jan 21, 2018

I think that this issue can be closed. We all can test it and create a new issue when a bug is found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants