Graphic2D Object with mini script and variable

A forum dedicated to the Draft, Arch and BIM workbenches development.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
chakkree
Posts: 327
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: Graphic2D Object with mini script and varriable

Post by chakkree »

johnwang wrote: Tue Jun 30, 2020 4:20 am Needs more wall types: External wall and Internal wall.

External wall : 230 brick wall, brick-veneer wall (110 brick + gap (40 or 50) + timber frame (90 or 70)

Internal wall : timber frame (90 or 70)

Could you fill a rectangle with solid?
1) Do you have sample image or dxf file?
2) I'm think it can be made from Part.makeFace, I will test.
User avatar
johnwang
Veteran
Posts: 1345
Joined: Sun Jan 27, 2019 12:41 am

Re: Graphic2D Object with mini script and varriable

Post by johnwang »

chakkree wrote: Tue Jun 30, 2020 4:45 am
1) Do you have sample image or dxf file?
2) I'm think it can be made from Part.makeFace, I will test.
Just need to fill two rectangles with two different solid color.

Change face color maybe a bit hard.

Code: Select all

from FreeCAD import Base
import Part

V1=Base.Vector(0,0,0)
V2=Base.Vector(300,0,0)
V3=Base.Vector(300,150,0)
V4=Base.Vector(0,150,0)

L1=Part.LineSegment(V1,V2)
L2=Part.LineSegment(V2,V3)
L3=Part.LineSegment(V3,V4)
L4=Part.LineSegment(V4,V1)

S=Part.Shape([L1,L2,L3,L4])
W=Part.Wire(S.Edges)

F=Part.Face(W)
#F.DiffuseColor=[(1.,1.,0.),(0.,1.,1.),(1.,0.,1.),(1.,0.,0.),(0.,1.,0.),(0.,0.,1.)]
Part.show(F)
hfc series CAE workbenches for FreeCAD (hfcNastran95, hfcMystran, hfcFrame3DD, hfcSU2 and more)
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Graphic2D Object with mini script and varriable

Post by carlopav »

chakkree wrote: Tue Jun 30, 2020 2:53 am 1) Hatch pattern have only 2 patterns(ANSI31, ANSI32) and hatch in only rectangular boundary.
I gave a quick look at the code as I was really curious. Looks like you are drawing every hatch line as an Edge. This doesn't look the good approach to me: you will have a lot of unuseful Part Shapes in your document, making the file too heavy too quick.
Draft workbench objects have the possibility to display an SVG hatching. The problem is that it seems to be broken in 0.19. Perhaps trying to fix this can also give some benefit to your objects :) would you join the efforts?

2) The dashed line assign by array [line , blank] or [line1 , blank1 , line2 , blank2] , like stroke-dasharray in SVG.
And the same with dashed lines: why dont use obj.ViewObject.DrawStyle="Dashed"? (this field is something I didnt' really got involved, so perhaps there are limitations when you want to have multiple DrawStyle for just one object).
Probably if you are going to build your own objects and therefor your workbench it worths experimenting a bit also with pivy library (from pivy import coin): it could help you to setup your viewprovider with all the visual style you need. ;)

Edit: the link with the big discussion I linked shows that the field you are experimenting is something that users really need, so I'm happy to see you into it! So go on, and scratch the itch, but also consider if something that you need can be implemented at Draft workbech level, so the whole freecad project can benefit of it.
follow my experiments on BIM modelling for architecture design
User avatar
chakkree
Posts: 327
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: Graphic2D Object with mini script and varriable

Post by chakkree »

carlopav wrote: Tue Jun 30, 2020 7:18 am I gave a quick look at the code as I was really curious. Looks like you are drawing every hatch line as an Edge. This doesn't look the good approach to me: you will have a lot of unuseful Part Shapes in your document, making the file too heavy too quick.
Draft workbench objects have the possibility to display an SVG hatching. The problem is that it seems to be broken in 0.19. Perhaps trying to fix this can also give some benefit to your objects :) would you join the efforts?


..
And the same with dashed lines: why dont use obj.ViewObject.DrawStyle="Dashed"? (this field is something I didnt' really got involved, so perhaps there are limitations when you want to have multiple DrawStyle for just one object).
Probably if you are going to build your own objects and therefor your workbench it worths experimenting a bit also with pivy library (from pivy import coin): it could help you to setup your viewprovider with all the visual style you need. ;)

Edit: the link with the big discussion I linked shows that the field you are experimenting is something that users really need, so I'm happy to see you into it! So go on, and scratch the itch, but also consider if something that you need can be implemented at Draft workbech level, so the whole freecad project can benefit of it.
I cannot compile WB with C++. Draft WB made by C++,that difficult for me. Now,I try to read and understand the discussion.

Part Shape can use "getSVG" function and can make a document(still in experiment)

P.S. and I have some problem about my english. :cry:
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Graphic2D Object with mini script and varriable

Post by carlopav »

chakkree wrote: Tue Jun 30, 2020 7:45 am I cannot compile WB with C++. Draft WB made by C++,that difficult for me. Now,I try to read and understand the discussion.
Draft workbench is pure Python (no c++ at all) ;) check it out! https://github.com/FreeCAD/FreeCAD/tree ... /Mod/Draft

P.S. and I have some problem about my english. :cry:
Let's say there is space to improve! :P
follow my experiments on BIM modelling for architecture design
User avatar
johnwang
Veteran
Posts: 1345
Joined: Sun Jan 27, 2019 12:41 am

Re: Graphic2D Object with mini script and varriable

Post by johnwang »

draft is like autocad
cad2d is like autocad architect.
hfc series CAE workbenches for FreeCAD (hfcNastran95, hfcMystran, hfcFrame3DD, hfcSU2 and more)
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Graphic2D Object with mini script and varriable

Post by yorik »

Amazing stuff @chakkree :o (as always).

I really think we could integate the SFD/BMD diagram tools somewhere in BIM or Arch ;)

Regarding hatches: The (currently not working) way was to have SVG files, then, with Qt, generate a PNG image from the SVG, and use that as a texture. It used to work quite well, with transparency and everything. However, transparency have had some bugs with recent versions of coin (or anything else underneath, I don't remember) and this system doesn't work anymore.

In any case, it was of very poor quality as the PNG-based texture didn't scale very well.

Now in TechDraw WB there is a system that is not based on SVG but on autocad .PAT definitions. And there are methods to create these hatches as OCCT shapes. I tried to make it work from Python here: https://github.com/yorikvanhavre/FreeCA ... 9d05230bbb but it's still crashing... Help welcome ;)

But I think that would be the best solution for Draft hatches: Each Draft object has a Pattern property that, if filled, uses the TD function to generate a shape. Then we add the coin node of that shape to the Draft object's root node. Then we'd have crisp, clean hatching everywhere.
User avatar
johnwang
Veteran
Posts: 1345
Joined: Sun Jan 27, 2019 12:41 am

Re: Graphic2D Object with mini script and varriable

Post by johnwang »

It seems need a lot of effort to find a perfect hatching method.
hfc series CAE workbenches for FreeCAD (hfcNastran95, hfcMystran, hfcFrame3DD, hfcSU2 and more)
User avatar
chakkree
Posts: 327
Joined: Tue Jun 30, 2015 12:58 am
Location: Bangkok Thailand

Re: Graphic2D Object with mini script and varriable

Post by chakkree »

Re-design CAD2D object to pivy.coin.
First test concept:
  • now, cannot change color
  • Command2d, can use only "L;x1,y1;x2,y2"
It's very hard way. :lol:

CAD2D_COIN_01_Proto.png
CAD2D_COIN_01_Proto.png (266.73 KiB) Viewed 1577 times
Attachments
CAD2D_Object_Coin.py
(4.18 KiB) Downloaded 51 times
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Graphic2D Object with mini script and varriable

Post by carlopav »

chakkree wrote: Tue Jun 30, 2020 2:10 pm Re-design CAD2D object to pivy.coin.
WOW, that was quick!
follow my experiments on BIM modelling for architecture design
Post Reply