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

Add copy, paste, cut functionality #16383

Merged
merged 6 commits into from
Aug 9, 2023
Merged

Add copy, paste, cut functionality #16383

merged 6 commits into from
Aug 9, 2023

Conversation

casperlamboo
Copy link
Contributor

@casperlamboo casperlamboo commented Aug 4, 2023

This PR adds copy, past and cut of buildplate models to cura.

Screen.Recording.2023-08-04.at.13.25.29.mov

Copy/paste works even after a model has been deleted for the build plate (no reference is needed to the orginal model). This works by writing the serialized model data to the clipboard. As a consequence a users clipboard might look similar to this after using cura

<?xml version="1.0"?>
<model unit="millimeter" xmlns="http://schemas.microsoft.com/3dmanufacturing/core/2015/02" xmlns:cura="http://software.ultimaker.com/xml/cura/3mf/2015/10" xml:lang="en-US">
	<resources>
		<object id="1" name="cube.stl" type="model">
			<metadatagroup>
				<metadata name="cura:extruder_nr">0</metadata>
			</metadatagroup>
			<mesh>
				<vertices>
					<vertex x="-5" y="5" z="-5" />
					<vertex x="5" y="5" z="5" />
					<vertex x="5" y="5" z="-5" />
					<vertex x="5" y="5" z="5" />
					<vertex x="-5" y="5" z="-5" />
					<vertex x="-5" y="5" z="5" />
					<vertex x="-5" y="-5" z="5" />
					<vertex x="5" y="-5" z="-5" />
					<vertex x="5" y="-5" z="5" />
					<vertex x="5" y="-5" z="-5" />
					<vertex x="-5" y="-5" z="5" />
					<vertex x="-5" y="-5" z="-5" />
					<vertex x="-5" y="-5" z="5" />
					<vertex x="5" y="5" z="5" />
					<vertex x="-5" y="5" z="5" />
					<vertex x="5" y="5" z="5" />
					<vertex x="-5" y="-5" z="5" />
					<vertex x="5" y="-5" z="5" />
					<vertex x="5" y="5" z="5" />
					<vertex x="5" y="-5" z="-5" />
					<vertex x="5" y="5" z="-5" />
					<vertex x="5" y="-5" z="-5" />
					<vertex x="5" y="5" z="5" />
					<vertex x="5" y="-5" z="5" />
					<vertex x="5" y="-5" z="-5" />
					<vertex x="-5" y="5" z="-5" />
					<vertex x="5" y="5" z="-5" />
					<vertex x="-5" y="5" z="-5" />
					<vertex x="5" y="-5" z="-5" />
					<vertex x="-5" y="-5" z="-5" />
					<vertex x="-5" y="-5" z="5" />
					<vertex x="-5" y="5" z="-5" />
					<vertex x="-5" y="-5" z="-5" />
					<vertex x="-5" y="5" z="-5" />
					<vertex x="-5" y="-5" z="5" />
					<vertex x="-5" y="5" z="5" />
				</vertices>
				<triangles>
					<triangle v1="0" v2="1" v3="2" />
					<triangle v1="3" v2="4" v3="5" />
					<triangle v1="6" v2="7" v3="8" />
					<triangle v1="9" v2="10" v3="11" />
					<triangle v1="12" v2="13" v3="14" />
					<triangle v1="15" v2="16" v3="17" />
					<triangle v1="18" v2="19" v3="20" />
					<triangle v1="21" v2="22" v3="23" />
					<triangle v1="24" v2="25" v3="26" />
					<triangle v1="27" v2="28" v3="29" />
					<triangle v1="30" v2="31" v3="32" />
					<triangle v1="33" v2="34" v3="35" />
				</triangles>
			</mesh>
		</object>
	</resources>
	<build>
		<item objectid="1" transform="1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 16.52989959716797 5.0 -0.002300000051036477" />
	</build>
</model>

After a model has been pasted the newly added objects are automatically selected.

The "cut" functionality is also added which simply works by sequencing the copy and delete selected actions.
https://github.com/Ultimaker/Cura/blob/f07faac4223d3d15d36b486e1fce18a84ea55fb0/cura/CuraActions.py#L191C6-L193

Copy paste cut can be executed by either pressing ctrl+c, ctrl+v, ctrl+x keys or by the right click context menu

Screenshot 2023-08-04 at 13 32 28

CURA-7912

cura/CuraActions.py Outdated Show resolved Hide resolved
cura/CuraActions.py Outdated Show resolved Hide resolved
# Parse the scene from the clipboard
scene_string = QApplication.clipboard().text()

mesh_reader = application.getMeshFileHandler().getReaderForFile(".3mf")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Derp. I didn't notice this the previous time. But you can actually disable 3mf reader

If the user did this, there won't be mesh_reader returned here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could make the 3mf reader a required plugin, or you could disable copy/paste if the plugin is not available.

Copy link
Contributor Author

@casperlamboo casperlamboo Aug 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c393d91, this change also required a change in uranium: Ultimaker/Uranium@83f88ac

@fieldOfView
Copy link
Collaborator

In response to the screen recording above: people are going to complain that the resulting objects get auto-arranged, disregarding the original relative positions. One of the main usecases for copy/paste - I imagine - would be to create grids.

@jellespijker jellespijker merged commit 16ce595 into main Aug 9, 2023
9 checks passed
@jellespijker jellespijker deleted the CURA-7913 branch August 9, 2023 12:37
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

Successfully merging this pull request may close these issues.

4 participants