Drawing Template Sets And Their Implementation In FreeCAD

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
mrlukeparry
Posts: 652
Joined: Fri Jul 22, 2011 8:37 pm
Contact:

Re: Drawing Template Sets And Their Implementation In FreeCA

Postby mrlukeparry » Thu Jan 23, 2014 7:43 pm

j-dowsett wrote:So I've only had a little time to spend on the template selection side of things so far. It's also going to be slow as this involves interacting more with bits of FreeCAD that I've not worked with before. I have a github repo here https://github.com/j-dowsett/FreeCAD.git and the branch templates_menu_working is what I've got so far - this is definitely not for users, right now it's much more of an experimentation branch, but you're welcome to look Luke (or anyone else as long as you don't expect it to do anything!). [really, this is effectively just a local branch, but that i have on github as I'm working on two computers].

In reality all it has so far is a Drawing preferences page, two preferences for ortho_views that (without yet properly being tested...) appear to work. The preferences page also has two preferences for the not-yet-existent template selection dialog - these currently do nothing (not even save the preference). Oh, I have added an 'All templates...' menu item, but haven't connected it up properly yet, I think there might also be a first approximation dialog .ui file in there, but that's definitely not connected to anything, not in any makefiles etc yet.

It really is more still me experimenting with the different things that might come togethor to give something along the lines of this, thinking that I'd get that skeleton function in place before coming back here to finalise whether to have tabs in the dialog for MRU or favourites or whatever. I'll carry on in this experimental / learning vein as time allows, but if you want to work on this too then please do - if anything is going to get into 0.14 then I think it's much more likely to come from you!


Sure thing - I wasn't too sure what you were working on but sounds good. Experimenting is good as you get to delve further into FreeCAD. I don't think my focus is really on the UI details like this, rather than on the underlying tools.

j-dowsett wrote:I'd vaguely had the same thought after finally catching up with a couple of things Luke had said in the same regard. In the short term I'd hoped to simply play with python a little bit and try to get it to create a template of a given size, with a given margin and number of border intervals(? - ie the A, B, C... 1,2,3... bits) and with a given titleblock in a given corner... of course I've yet to manage to put any time into this, and think I'll be looking at the C++ stuff above first.


Well that might be a bit of a winner of an idea.

Stuff like this seems better to be programmed with an interpreted language as it soon becomes messy with c++ when many options are presented. The problem is I'm terrible with python but I can build up the c++ infrastructure to deal with this.

What I'm thinking is the canvas has python methods to draw onto the background behind the views with other template logic for managing the title block size and position but not necessarily calculating it - this is needed e.g. for your ortho-view calculations.

A python class will be given a template file of some format - maybe xml / python for which contains basic template parameters such border position, thickness etc. This python class then draws these using methods on the canvas which I can provide in my Canvas View. We can also provide the option for user defined drawing methods.

Using an abstraction like this means the template drawing data can be interpreted into other formats whether .svg , .dxf, .dwg

Using python functionality would mean someone else could get involved and help reduce the workload for us too. What do people think?
ulrich1a
Posts: 1403
Joined: Sun Jul 07, 2013 12:08 pm

Re: Drawing Template Sets And Their Implementation In FreeCA

Postby ulrich1a » Thu Jan 23, 2014 8:39 pm

mrlukeparry wrote:Using python functionality would mean someone else could get involved and help reduce the workload for us too. What do people think?
I had a quick look into the draft-workbench code. I think there are most pieces available in order to write a python script for an automated generation of an SVG-template. So there is a broader group of potential candidates, who can do this.
From what is visible, there is no code that makes perfect svg projections from complicated parts. There is often missing a small arc or line in the projection. Here I can confirm what quick61 has allready mentioned. So this needs an improvement from someone who has knowledge with occ. The drawing workbench can only do projections from a solid shape. All other items can only projected into the drawing from the draft workbench. But the projections algorithm differ in both workbenches!
Another topic is an improvement of adding dimensions and project them into the drawing. Yorik has allready something working in the Draft-workbench. I posted my ideas about this here: viewtopic.php?f=10&t=5399#p43279
Regarding dimensions (and eventually GD&t) there is a roadmap neccessary, if this will be done in python or C++. A C++-class may have the advantage, that other workbenches can be enabled to generate dimensions with a few mouse-clicks from allready done input. I am thinking for example to make a dimension from a dimensional constraint in the Sketcher.

Ulrich
User avatar
quick61
Posts: 3673
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: Drawing Template Sets And Their Implementation In FreeCA

Postby quick61 » Thu Jan 23, 2014 9:09 pm

I think that sounds like a real good plan so long as current / future templates will still be usable. Not all that concerned about any current template be obsoleted as much as being able to still use such things as a colorful brochures and the like. Maybe make it a "Template Builder Wizard" with the ability to save the templates produced with it for reuse?

A great idea to build the engine on C++ and have the interface in Python. Heck, I might even be able to get a little involved in that. (very little ;) ) With a solid engine underneath the interface could grow and evolve as wanted and/or needed.

Just how would this work? Would one just input the datum for the border, intervals, and the like, then place a title block? Or could it use templates of border segments that then would be copied, scaled, and rotated to make the border? I think if that was possible, the user could add their own custom border types along with the basic ones that would ship with a FreeCAD install.

Mark
This post made with 0.0% Micro$oft products - GOT LINUX?
User avatar
quick61
Posts: 3673
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: Drawing Template Sets And Their Implementation In FreeCA

Postby quick61 » Thu Jan 23, 2014 10:00 pm

I have had something brought to my attention today that I was not aware of until now. This will be of interest to you guys that are working on the template generator as well...

From the message I received:
In order to enable up to scale printing the real word size has to be given in the width and height attributes of the SVG-Tag. The size of the document in user units (px) has to be given in the viewBox attribute.
Example: FreeCAD/FreeCAD_sf_master@41337f6


I am thinking that this should be made the standard, and if so, the Wiki should reflect this. I don't want to go changing or setting any "standards" without the consent of the developers. So, If you all think this is the way the templates standard should be, let me know and I'll update the Wiki.

Currently the Wiki states -

From the Drawing templates page:
Creating templates for the Drawing module is very easy. See also the tutorial Drawing_Template_HowTo. Templates are svg files, created with any application capable of exporting svg files, such as Inkscape. Only two rules must be followed:
One pixel = one millimeter
You must insert, somewhere inside your svg code, where you want the contents of the drawing to appear (for example at the end of the file, just before the last </svg> tag), the following line:

Code: Select all

<!-- DrawingContent -->


And from the Svg Namespace page:
Usage

One pixel = one millimeter.
You must insert, somewhere inside your svg code, where you want the contents of the drawing to appear (for example at the end of the file, just before the last </svg> tag), the following line:

Code: Select all

<!-- DrawingContent -->


Both of these pages should have added to them something like the following -
~~~
In order to enable up to scale printing, the real word size has to be given in the width and height attributes of the SVG-Tag. The size of the document in user units, (px), has to be given in the viewBox attribute.

The following is to be formatted like the example below where:
  • xxx = pixel width
  • yyy = pixel height

Code: Select all

width="xxxmm"
height="yyymm"
viewBox="0 0 xxx yyy"


Or if anyone has a better way to put it...

Mark
This post made with 0.0% Micro$oft products - GOT LINUX?
User avatar
shoogen
Posts: 2822
Joined: Thu Dec 01, 2011 5:24 pm

Re: Drawing Template Sets And Their Implementation In FreeCA

Postby shoogen » Fri Jan 24, 2014 12:15 am

more detailed explanation: viewtopic.php?f=10&t=2226#p16312
i've allready added a paragraph to http://www.freecadweb.org/wiki/index.ph ... #Page_Size
User avatar
quick61
Posts: 3673
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: Drawing Template Sets And Their Implementation In FreeCA

Postby quick61 » Fri Jan 24, 2014 1:34 am

shoogen wrote:more detailed explanation: viewtopic.php?f=10&t=2226#p16312
i've allready added a paragraph to http://www.freecadweb.org/wiki/index.ph ... #Page_Size


Thank's, I'll get together a matching screenshot later on tonight or tomorrow and update the TemplateExample.svg to reflect the change. Probably be a couple of days before I get through all my templates. I need to update them all with the Title block data anyway.

Mark

Edit - Wiki Tutorial done.
This post made with 0.0% Micro$oft products - GOT LINUX?
mario52
Posts: 1863
Joined: Wed May 16, 2012 2:13 pm

Re: Drawing Template Sets And Their Implementation In FreeCA

Postby mario52 » Sat Jan 25, 2014 1:50 pm

hi quick61
You can replace the old by those above (small changes) and it is closed for blocks of titles, they are complete (for the correspondence of the wiki and git)
Templates_18_01_2014.zip
(closed for blocks of titles)
(243.61 KiB) Downloaded 18 times
Windows 10
Maybe you need a special feature, go into Macros_recipes and Code_snippets. My macros on Gist.github
ulrich1a
Posts: 1403
Joined: Sun Jul 07, 2013 12:08 pm

Re: Drawing Template Sets And Their Implementation In FreeCA

Postby ulrich1a » Sun Jan 26, 2014 10:07 pm

mrlukeparry wrote:A python class will be given a template file of some format - maybe xml / python for which contains basic template parameters such border position, thickness etc.
I made a primitive python script, that can create a valid template as an svg-file. It is just a proof of concept. Data for the template definition are given in python lists.
In order to test the script, line 241 has to be edited, and your save path has to be put in. It just has the minimum functionality to generate a template. There is no gui or XML-parser.
There are some templates, that do not work in Windows builds with the dated Qt-version. Generating templates, with such a script has the advantage, that no advanced svg-features are used, like nested items.

During tests with the generated templates, I found that no numbers with decimals can be used in the working space and title block comments. When the numbers have decimals, the automatic scaling for does not work. This may be no problem for A-formats, but limits the definition precision.

Ulrich
User avatar
quick61
Posts: 3673
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: Drawing Template Sets And Their Implementation In FreeCA

Postby quick61 » Sun Jan 26, 2014 10:33 pm

Ulrich, would you want to post that script? I sure wouldn't mind taking a look at it as I am always trying to learn something new about Python. I'v "almost" got the very basics of PyQt figured out and wouldn't mind playing around with putting a gui front end on it and see where it goes.

Mark
This post made with 0.0% Micro$oft products - GOT LINUX?
j-dowsett
Posts: 200
Joined: Wed Sep 07, 2011 9:37 am

Re: Drawing Template Sets And Their Implementation In FreeCA

Postby j-dowsett » Sun Jan 26, 2014 10:36 pm

ulrich1a wrote:[I made a primitive python script, that can create a valid template as an svg-file. It is just a proof of concept. Data for the template definition are given in python lists.
In order to test the script, line 241 has to be edited, and your save path has to be put in. It just has the minimum functionality to generate a template. There is no gui or XML-parser.
There are some templates, that do not work in Windows builds with the dated Qt-version. Generating templates, with such a script has the advantage, that no advanced svg-features are used, like nested items.

During tests with the generated templates, I found that no numbers with decimals can be used in the working space and title block comments. When the numbers have decimals, the automatic scaling for does not work. This may be no problem for A-formats, but limits the definition precision.

Ulrich


That's cool - do you have the code available for testing / playing with?

Yeh, I specified it to work with integers for working space & title block. Given these are mm dimensions, I figured there was little need for fractional values. It's no bother to change this to work with floats ... but you'll have to justify the need first!! :)