SolveSpace Logo SOLVESPACE -- parametric 2d/3d CAD
Examples
Tutorials
Features
Download
Reference
Technology
Library
Forum
Contact
USER FORUM

(you are viewing a thread; or go back to list of threads)

Copy paste between files and with constraints (by Rune)
Hi, It would really be great if it was possible to copy paste between two open instances of the program. Wouldn't it be simple to implement - using the clipboard?.
And while were at it, why not include the constraints? Clearly those involving elements not in the copy have to be discarded but the internal and the simple ones like horiz,vert, radius, length etc. should be maintained in the copy-paste process (eventually controlled by an option).
Fri Nov 7 2014, 04:12:14
(no subject) (by Jonathan Westhues)
Such a feature would be nice to have. If you're interested to implement this, note that the clipboard facility provided by the OS doesn't have a standard "entities and constraints for a CAD program" format; so you probably don't gain much by using that for your IPC vs. just some shared memory or whatever.
Sun Nov 9 2014, 20:24:54
(no subject) (by Rune)
I think that selecting a part of a design - copying - pasting is fundamental during the conceptual phase of the design.
Maybe the most flexible solution would be to to convert elements and constraints to some string that could be exported to file/clipboard and then imported. I guess I'd have to study the datastructure - could you give indications of where to start? I'll look into it when I got the opportunity/time
Cheers
Mon Nov 10 2014, 04:12:54
(no subject) (by Mihal)
I miss that feature too. Having relative complex model,
it is really annoying to constraint 20x the same shaped hole
(you draw and constraint the first one, then you copy paste it,
then in order to place it to the exact position you have to constraint the pasted copy manually).
Fri Nov 14 2014, 02:12:03
(no subject) (by Jonathan Westhues)
Can you draw the 2d section for the hole in another file, and then import and extrude it where desired? That would avoid the need to cut and paste, and keep the model parametric.
Fri Nov 14 2014, 03:27:28
(no subject) (by Rune)
In such a case it requires more work importing and placing and extruding than just copying the shaped hole and re-constraining. It would actually be very efficient if you could make a copy of a group directly. I know that the step translate-rotate is sort of that but its very restrictive. It would be nice to make multiple copies with some per-inserted constraints between them (some equal constrains of point-point distance, H,V,angle,radius constraints). The user could then delete what is not necessary.
A good copy paste function would be an implementation of this and would also solve my issue about "reordering groups" "shells" "import order" etc.

BTW. I just found the DOC.txt in \solvespace-solvespace\exposed
which explains a lot of things about the inner workings of the program.
Jonathan, I think it would be good if you could mention and link to this document under the sourcecode section on the page http://solvespace.com/download.pl.


P.S. I start getting nice results using the program. It really solves some problems in my research project.
Thank you Jonathan
Fri Nov 14 2014, 04:24:07
(no subject) (by Mihal)
> Can you draw the 2d section ....
I will try that, thanks for the hint.
Fri Nov 14 2014, 04:39:47
(no subject) (by Mihal)
I tried it. Parameterics is kept but the
result is way too much complicated.
Every import makes its own group,
I can't constraint the imports easily
(I have to switch between groups, etc, etc).

So, as of me, I vote for copy-paste
optionally with constraints :).

~Mihal
Fri Nov 14 2014, 05:13:50
Workaround (by Rune)
Hi Mihal, I have a similar problem. My current workaround is to have a 'component' file C that I include in the assembly A.
Both file C and A have included a 'Dimension' file D as the first thing. File D contains lines representing my dimensions, which I constrain against both in file A and C. This way I only have to modify dimensions in one file. Unfortunately has I have asked (http://solvespace.com/forum.pl?action=viewthread&parent=322) it seems like you have to open the included files and resave to let changes propagate.

For simple 2d geometries I make a copy, make a lot of equal constraints to the original until the copy can be dragged to its new place without deformations.

Hope it was helpful
Fri Nov 14 2014, 07:22:25
(no subject) (by Mihal)
> Workaround (by Rune)
Thanks Rune.
Tue Nov 18 2014, 07:39:44
(no subject) (by Mihal)
> For simple 2d geometries I make a copy, make a lot of equal
> constraints to the original until the copy can be dragged
> to its new place without deformations.

Do it 20 or so times... For simple plate with 20 or so relatively complex holes it can be time consuming...
Thu Nov 20 2014, 04:26:22
(no subject) (by Mihal)
So after some research I was able to modify the clipboard code
to copy-paste horizontal constraint:

GraphicsWindow::CopySelection(void)
...
for(c = SK.constraint.First(); c; c = SK.constraint.NextAfter(c)) {
if(c->type == Constraint::POINTS_COINCIDENT) {
if(!SS.clipboard.ContainsEntity(c->ptA)) continue; //m no entities for given points -> empty points -> don't constrain
if(!SS.clipboard.ContainsEntity(c->ptB)) continue;
}
else if(c->type == Constraint::HORIZONTAL) {
}
else if(c->type == Constraint::VERTICAL) {
continue; //prepared for vertical..
}
else {
continue;
}
SS.clipboard.c.Add(c);
}

and void GraphicsWindow::PasteClipboard(Vector trans, double theta, double scale) {

...

if(c->type == Constraint::POINTS_COINCIDENT) {
Constraint::ConstrainCoincident(SS.clipboard.NewEntityFor(c->ptA),
SS.clipboard.NewEntityFor(c->ptB));
}
if(c->type == Constraint::HORIZONTAL) { //horizontally constrainted is either a line segment or 2 points
Entity *ea = SK.GetEntityNoOops(c->entityA);
if(ea && ea->type == Entity::LINE_SEGMENT) {
Constraint::Constrain(Constraint::HORIZONTAL,
Entity::NO_ENTITY,
Entity::NO_ENTITY,
SS.clipboard.NewEntityFor(c->entityA));
}
else {
Constraint::Constrain(Constraint::HORIZONTAL, SS.clipboard.NewEntityFor(c->ptA),
SS.clipboard.NewEntityFor(c->ptB),
Entity::NO_ENTITY);
}

}


The copy-paste operation works. The copy-paste-paste
also works. But copy-paste-copy-paste crashes the
solvespace. At this point I'm unable to continue...
Thu Nov 20 2014, 07:56:25
Update (by Mihal)
I managed to compile the solvespace under
VS2013 IDE so I finally got a debugger :)
Now I can see the clipboard logic.
When copying POINTS_COINCIDENT then only
the points that are included in clipboard are copied.

My horizontal code doesn't do that check
so all SK constraints are copied into clipboard
and program crashes when it tries to paste them...
Thu Nov 20 2014, 12:00:31
Update (by Mihal)
Done. Version 1.21eMVe

Copy line segment with horizontal contstraint
Copy line segment with vertical contstraint
Copy 2 points with horizontal contstraint
Copy 2 points with vertical contstraint
Copy 2 points (line segment) with distance contstraint
Copy circle and arc with diameter constraint
Copy circle with equal radius constraint

Toggle on/off = Edit -> Copy Constraints

Now I can make my 20 holes :))).

~m
Thu Nov 20 2014, 15:35:33, download attachment solvespaceWin.rar
Cant make it work (by Rune)
Hi Mihal, exellent idea I was so excited to test it, but it does not seem to work. I unpacked your file but copy - paste of a simple rectangle does not seem to keep the H&V constraints.

BTW. Im not much of a programmer but Id like to have a go at it. Could you please share how you imported it in VS2013 IDE. (I've installed VS2010, but knows too little about the IDE to make the project).
Please
Fri Nov 21 2014, 04:09:58
(no subject) (by Mihal)
> paste of a simple rectangle does not seem to keep the H&V
> constraints

Hi Rune,
Did you check the Copy Constraints menu item?
I will place the sources somewhere but the project
needs to be reshaped as it didn't follow the original
directory structure.
BTW you can get the full VS2013 community version
for free directly from MS.
Fri Nov 21 2014, 05:56:20
(no subject) (by Rune)
Oh, I didnt see that . Brilliant, got it, works but not with angle, arc endpoint on line constraints.

Since you're a programmer, could you implement a swap of two groups in the group order?

Another point: It's not possible to delete the active group, it tells you to "activate a different group before proceeding" thats contrary to logic. Could you invert that? I believe that the logic should be to activate a group before deleting it (as is the normal logic of things)
Fri Nov 21 2014, 06:37:34
(no subject) (by Mihal)
> works but not with angle, arc endpoint on line constraints

What constraints can be copied is described in the above post,
except of copying of equal radius constraint.

Will get to it later....

As of groups rearrangement, etc - I think that something
like that can be done only by Jonathan.

~m
Fri Nov 21 2014, 09:56:14
(no subject) (by Jonathan Westhues)
Mihal - Thanks, and if you send a merge request on gitorious then I can take a look, and see what it would take to integrate that into master.

Reordering groups is indeed tricky. At the very least, you'd need to renumber the groups, and then rewrite the hGroup for all entities and constraints in those groups. That alone would work in some cases; but after deleting everything with a now-missing dependency, there may not be very much left in the sketch. So some heuristics to fix that up would be desirable too, and that gets complicated.
Fri Nov 21 2014, 13:10:31
Version 2.1eMVe2 (by Mihal)
Here it goes with copy equal constraints bug fixed.
https://www.youtube.com/watch?v=3uvg_3tJ3qk
VC sources should be on github (or somewhere) soon.
~m
Sun Nov 23 2014, 06:21:35, download attachment solvespace-2.1eMVe2.rar
Tadaaa (by Mihal)
Solvespace for visualstudio 2013 IDE:
https://github.com/eMVe/solvespace/
Sun Nov 23 2014, 07:48:25
(no subject) (by Rune)
Great work Mihal. Copy equal constaints does not seem to work.
Mon Nov 24 2014, 03:41:51
(no subject) (by Rune)
..for length
Mon Nov 24 2014, 03:53:25
(no subject) (by Mihal)
> Copy equal constaints does not seem to work.
It works for length of line segment
and for distance between two points.
It will not work for distance between point and line.
Mon Nov 24 2014, 05:06:48
(no subject) (by Rune)
Mihal, my Version 2.1eMVe2 does not copy equal line segment constraints. See attached file.
I have a rect with height 20. Another rect is constraint to the same height. I make a copy of that second rect and the
height constraint is gone (along with horiz constraint).

Am I missing something?

Circles diameter equal constraint is working fine though.

P.S.
After 4 hours vs2013 is still downloading. In VS2010 it gave a compile error (something missing)
Mon Nov 24 2014, 05:48:26, download attachment test.slvs
(no subject) (by Rune)
Looking at the source I find a need for testing EQUAL_LENGTH_LINES
in the pasteclipboard and copyselection functions.
Could you add that please, my naive attempt did not seem to work?
Mon Nov 24 2014, 08:13:15
(no subject) (by Mihal)
> Am I missing something?
I don't know.
When I select the whole rectangle, then after Ctrl-C Ctrl-V
I get the new one with 20.00 vertical diameter constraint
present...
Version eMVe2.
Mon Nov 24 2014, 08:17:28
(no subject) (by Rune)
Mihal, if you select the first one you maintain the fixed length constraint. If you copy the second you loose the equal_length constraint which would be the interresting one to copy. It analogue to your copy of holes example. If you want to make n copies of a square and want to change all the sidelenghts at once you would prefer to have them constraint against one reference. If you make n copies of the first one you would have to go and change the value of each one manually.
Hope it clarifies the issue. So I believe its the EQUAL_LENGTH_LINES case that misses.And I believe it would be 'piece of cake' for you to insert.
Please ;)
Mon Nov 24 2014, 10:27:49
(no subject) (by Mihal)
EQUAL_LENGTH_LINES constraint is not copied,
it is not as trivial as it might look at the first sight...
Mon Nov 24 2014, 11:26:43
(no subject) (by Rune)
Is it much different than EQUAL_RADIUS ?
Ps. what do you mean by your comment: "only one circle with this particular constraint can be copied!"?
Mon Nov 24 2014, 11:51:30
(no subject) (by Mihal)
Copying b) (see below) constraints is tricky as it can make solver very easily busy and thus solvespace unresponsive.
Equal diameter constraint seems to be less restrictive
than equal length lines constraint.

If we do copy of a constraint, this particular constraint
can constrain
a) two objects within the copy (let's say
it is inner constraint) or
b) it can constrain some object within the copy
to some outside object.

Constraining diameter was meant for case, when there is
one reference hole within the design and its copies
are constrained to this reference "master" hole.
It is category b).
Then I figured out, that if I have such a configuration
(let's say 5 holes, one master, one secondary constrained
to master and 3 copies of secondary, constrained to
secondary) and if I make 6th hole, which is copy of master
hole, the current code copies all existing constraints
and attaches them to that 6th hole, which isn't much
optimal, but solvespace doesn't care.
But if I do that with equal length lines, solvespace
complains. On the other words to use such feature
you have exactly to know what are you doing otherwise
you may very easily fall into troubles...

I will sync the eMVe6 version to github but you have to
turn that feature on and compile the solvespace by yourself
(line 181 in clipboard.cpp).

-m
Mon Nov 24 2014, 13:08:49
(no subject) (by Rune)
Hi Mihal, great work, it sort of works. As you say the solver gets very slow which I take as a sign that its not the way to go. It only copies one constaint not a hole figure, see attachment. If you copy the lower line its ok. If you copy the whole polygon it does not keep the constraint between the 10 and the 10 ref line.
It is a bit strange that even if I uncheck the 'copy constraints' it keeps becoming slower.

By the way, it would be useful to have a timeout on the solver that could be set by user to say 1,2 or 4 seconds. Its really annoying that it keeps blocking (yes I know you can relax constraints but then its too cumbersome and sometimes sends your sketch far off the screen)
Tue Nov 25 2014, 08:10:48, download attachment test.slvs
(no subject) (by Mihal)
Hi Rune,
I think that it can't be made anything wrong
by copying the "inner" constraints.
However with "outer" constraints it's a totally
different story.
I think that the problem can be partially solved by distinguishing between types of copy operation
and implementing additional logic:
If user copies only the inner constraints then
the code creates inner constraints.
If user copies only the outer constraints then
the code creates outer constrains (and ideally
somehow optimizes their count).
If user messes into copy selection inner and outer
constraints together the constraints are not
created at all.

Please note that inner and outer constraints
are of "same something" type.
If there is value (valA) involved,
then the reference is not property
of other object but the value itself.
These (valA) constraints are easy - they can
be created each time.

The current code doesn't work with
inner "equal diameter" constraint.
Frankly I created it to simplify my life :),
doing 50x just Ctrl+C and bunch of Ctrl+V is faster,
than Ctrl+C , Ctrl+V and clicking and constraining...
Manually constraining the 50 holes would maybe
take much less time than all the programming work,
but who would do it manually when it can be coded :)))?

The not so good news is that I currently don't have much
time to continue... Anyway, anybody can pick the
code and improve it - it's beauty of open source...

-m
Tue Nov 25 2014, 12:50:31
(no subject) (by Mihal)
eMVe8 is out, see solvespace-emve.txt.
This is probably the last one from me.
-m
P.S. Thanks Jonathan for open sourcing
this great program.
Tue Nov 25 2014, 16:20:09
Thanks (by Rune)
I want to join in on the thanks to Jonathan for the great work and also thanks to you Mihal for improving the copy paste capacities and for the comments and insights into the code. I hope this discussion may be useful for further improvements.
Among the programs that I have tried (Sketchup, Wings, Freecad, Design spark mechanical and Rinoceros) it definitely has been the fastest to learn and most useful for 3D printing and simulation of dynamics.

I hope Jonathan and others will continue the development especially on copy-paste, reordering of groups.
Wed Nov 26 2014, 05:52:46
UI Addition (by Rune)
Hi everyone. Thanks to Mihal I started fiddeling with the source code. As my first attempt is to change the annoying delete only non selected group and a keyboard shortcut for changing active group.
ToDO:Remember hidden states and set it back when leaving a group
As I'm not a C++ programmer its a dirty fix, but here it is, build on the last commitment from Mihal.
Tue Dec 2 2014, 12:47:25, download attachment solvespace.zip
Merged (by whitequark)
I made the patch simpler and more robust; now it copies any constraints that are associated with the entities in the clipboard. See commit https://github.com/whitequark/...2c451bb205b36e0a5474ae7e9f8288.
Wed Dec 30 2015, 07:38:23
Post a reply to this comment:
Your Name:
Your Email:
Subject:
(no HTML tags; use plain text, and hit Enter for a line break)
Attached file (if you want, 5 MB max):
© 2008-2022 SolveSpace contributors. Most recent update June 2 2022.