OpenModelica icon indicating copy to clipboard operation
OpenModelica copied to clipboard

Copy & Paste of diagram elements into the same diagram

Open abuntrock opened this issue 1 year ago • 9 comments

Description

When copying a class instance from a diagram and paste it into the same diagram again the two instances are directly on top of each other and are both selected.

Steps to Reproduce

  1. Create a new class.
  2. Drag any other class onto it. E.g.: Modelica.Blocks.Continuous.Integrator image
  3. Copy and paste the integrator instance with Ctrl+C and Ctrl+V. image
  4. The two class instances are now directly on top of each other. When starting to move the copied class around the "old" class moves with it since both instances seem to be selected after the copying process.

Expected Behavior

Only the newly copied class is selected after the copying process (otherwise one always has to deselect both instances by clicking somewhere else and then clicking on the new component again). The copied class is not directly instantiated on top of the old class but shifted for example 10 points in each direction. This allows the select to desired class (old or new) in the diagram window after the copying process. The expected behavior is similar to the one in Dymola. There the result of the copying looks as follows: image

Version and OS

  • OpenModelica Version: 1.23.0
  • OS: Windows 11, 64 bit
  • MSL 4.0.0

Thanks for looking into this Aaron Buntrock - Bosch Rexroth

abuntrock avatar Jul 03 '24 07:07 abuntrock

It is possible that after Ctrl+V the icons are attached to the mouse waiting for a click on their final position?

BasilioPV avatar Jul 03 '24 08:07 BasilioPV

If I click somewhere after Ctrl+v, the instances are just deselected.

abuntrock avatar Jul 03 '24 08:07 abuntrock

Only the newly copied class is selected after the copying process (otherwise one always has to deselect both instances by clicking somewhere else and then clicking on the new component again). The copied class is not directly instantiated on top of the old class but shifted for example 10 points in each direction. This allows the select to desired class (old or new) in the diagram window after the copying process.

AFAICT, this expected behaviour is already available if you press "duplicate" in the context menu (or Ctrl-D)? So I'm not sure this feature request is already effectively implemented?

Occasionally I find it useful to do ctrl-c/ctrl-v when copying instances and they end up on top of each other, e.g. when wanting to maintain alignment -- please don't move the resulting object arbitrarily when pasting!

bilderbuchi avatar Jul 03 '24 09:07 bilderbuchi

@bilderbuchi Thanks for letting me know. For a single element the "duplicate" feature behaves just like I the expected behavior I described.

However, the duplicate feature can only be applied to one instance and not to multiple ones in contrast to ctrl-c/ctrl-v. In this case it is especially annoying from my opinion that not only the newly copied instances are selected. You have to move all copied instances to the new location one by another instead of moving the whole copied "system" at once. So maybe a compromise could be that they are copied one top of each other but only the new instances are selected?

abuntrock avatar Jul 03 '24 10:07 abuntrock

However, the duplicate feature can only be applied to one instance and not to multiple ones in contrast to ctrl-c/ctrl-v.

I don't know what you mean? I just tried this and it works (OM 1.23) -- select multiple object (with Shift pressed), press Ctrl-D, you get a dialog prompting for the new names for all components sequentially, and afterwards you get the offset new entities, only new ones selected. What am I missing?

Note: Why you have to use Shift and not Ctrl to select multiple objects, in contrast to my experience with virtually any other tool, I don't know 🤷 , but that's another issue I'd say.

bilderbuchi avatar Jul 03 '24 10:07 bilderbuchi

So maybe a compromise could be that they are copied one top of each other but only the new instances are selected?

This is what I would expect.

casella avatar Jul 03 '24 10:07 casella

@bilderbuchi It seems that I was not familiar enough with the duplicate feature. However, its not possible to duplicate connection lines with this approach. I will add another issue for this and would leave this ticket for the selection topic (only the new instances).

abuntrock avatar Jul 03 '24 10:07 abuntrock

For some reason we have 2 different implementations and both have their limitation. I personally prefer that we remove duplicate functionality and only have copy/paste. The copy/paste then needs to be updated to use the mouse position i.e., add the current mouse position as the offset when pasting items. For example, copy something in Dymola and then just move mouse to a new position and paste.

adeas31 avatar Sep 06 '24 12:09 adeas31

For some reason we have 2 different implementations and both have their limitation. I personally prefer that we remove duplicate functionality and only have copy/paste. The copy/paste then needs to be updated to use the mouse position i.e., add the current mouse position as the offset when pasting items. For example, copy something in Dymola and then just move mouse to a new position and paste.

If you go this route, please make sure that there is a viable approach to create aligned components. Paste-in-place is quite useful for creating a regular/aligned array of components. For example, if you don't move the mouse between copy and paste events, then paste at the original position.

bilderbuchi avatar Sep 09 '24 05:09 bilderbuchi

We finally made a lot of progress in this direction. #13563, #13596, #13600, #13601, #13614 and #13623.

  • It is now possible to paste items at the mouse position.
  • Paste-in-place is possible if you don't move the mouse between copy and paste.
  • Only the pasted items are selected.
  • The duplicate use the implementation. The only difference is that in case of duplicate the items are moved to the right by grid size of coordinate system.

adeas31 avatar Feb 14 '25 13:02 adeas31

Good that we have this feature in 1.25.0

casella avatar Feb 14 '25 18:02 casella

Works perfect with today's nightly. Thanks a lot.

abuntrock avatar Feb 17 '25 08:02 abuntrock