Library workbench

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
fdomateu
Posts: 26
Joined: Thu May 17, 2018 7:14 am

Library workbench

Postby fdomateu » Sat Oct 20, 2018 3:15 pm

Hello,

Some time ago I started to think how to make a Library workbench. My idea is to make a library that replace the Bolts, Fasteners, etc. Workbenchs. The library defined the dfferent type of objects: screw, nut, washer, bearing, beam, plate, bar, etc. and the users should only create small scrips according the template that will be different if the object shoudl be an screw, nut, washer, etc. You can find more information at the following forum topic:

https://forum.freecadweb.org/viewtopic.php?f=8&t=28798

I have tried to create an standard part object in python but I have not been successful. My idea is to create a new object called Library::StandardPart, the first idea about this object is showed at the picture bellow.

I have only use C or C++ a few times, i used C at the university for programing microcontrollers. Alone I cannot create this workbench on c++, actually I have stilly not learned how to complie FreeCAD, I am only used to create basic thinks on Code:.Block. I would be happy if any developer is interested on participate and help me to improve my knowledge on FreeCAD development.

Any new propose about how to implement the library Workbench and make it compatible with the future Assembly Workbench is also welcome.
Attachments
StandardPart.PNG
StandardPart.PNG (48.6 KiB) Viewed 612 times
ian.rees
Posts: 696
Joined: Sun Jun 15, 2014 3:28 am
Contact:

Re: Library workbench

Postby ian.rees » Fri Oct 26, 2018 8:40 pm

Hi fdomateu, I've split this off from the topic that you originally replied to - it's really not related to that topic, which had been dead for a couple years. Please feel free to change the subject of this thread.

I think you'll find that, it's probably a bit too much, to try and learn C++, the structure of FreeCAD, and also implement your new workbench all at the same time. Probably best to pick one area to learn, and focus on that. From your description, it's a little hard to say, but I would imagine that you could make some good progress to your goal using our Python integration - have you tried playing with that yet?
fdomateu
Posts: 26
Joined: Thu May 17, 2018 7:14 am

Re: Library workbench

Postby fdomateu » Tue Oct 30, 2018 5:32 pm

Hi ian.rees,

I have created some test code in python but I still do not have any correct workbench structure. Everything that I have made has been to learn how FreeCAD is working. I have python knowledge because I used it at the university and I also have knowledge on C for arduino projects, PLC block and microship controllers. My actual lack of knowledge is on C++ clases and for this reason I use Python.

As I have alredy mentioned, I have found problems on the definitiion of properties at part and body, it cannot be done dynamically. For this reason, I am starting the discussion about the need, or not, of a new standard part object with extra fields as norm, manufacturer, etc. If the idea is to allow adding properties at the part in the future, I only need to focus on the rest and wait for this changes.

Actually, at my draft LibraryPy WB I have created an object named standard part with the function encapsulate to create the part and body. Bellow you will found the code from the encapsulate function.

Code: Select all

def Encapsulate(self, obj, objType, text):
        if objType == "PythonFeature":
            pass
        elif objType == "Part":
            WorkDoc = FreeCAD.activeDocument()
            PartObj = WorkDoc.addObject('App::Part',"Part")
            PartObj.addObject(obj)
        elif objType == "Body":
            WorkDoc = FreeCAD.activeDocument()
            BodyObj = WorkDoc.addObject('PartDesign::Body',"Body")
            BodyFeature = BodyObj.newObject('PartDesign::Boolean','Boolean')
            BodyFeature.addObject(obj)
        elif objType == "BodyPart":
            WorkDoc = FreeCAD.activeDocument()
            PartObj = WorkDoc.addObject('App::Part',"Part")
            BodyObj = WorkDoc.addObject('PartDesign::Body',"Body")
            BodyFeature = BodyObj.newObject('PartDesign::Boolean','Boolean')
            BodyFeature.addObject(obj)
            PartObj.addObject(BodyObj)
I also have started on the creation of the interface, my idea is to allow the user between the election of task panel as Arch WB or PopUP windows as Autodesk. Bellow you will found the already designed PopUP window for fastener parts.

Image

The idea is that FreeCAD reads the iso_7092,py file and use all the information to display the library taskpanel or PopUP window:

[*]Icon
[*]dimension sketch
[*]famili info which should be displayed at the famili info tab (norm, old norm, manufacturer, etc,)
[*]Possible diameters/metrics list at the diameter QListWidget
[*]Possible screw or bolt length list at the length QListWidget
[*]Possible material list at the material QListWidget

FreeCAD should read the function geometry when the user click accept and the part should be created. Bellow you will found a first propose about how can looks a standard part file from the library. Actually, WB like Arch are miximg the information storage and the creating functions. The idea is that FreeCAD has at the future the functions to create parts and all the information is storage according an structure that helps the users the creating parts in an easy way. In other words, today some code has to be changed at the Arch WB to add a new beam profile and the library WB will allows that only adding a new file in a directory the new part is already added without changing any code line at FreeCAD.

Code: Select all

class iso_7092(Washer):
    
    "The object from the washer ISO 7092 with all the information necessary for the creation of the washer object"

    def __init__(self):

        Washer.__init__(self)

    def basicInfo(self):

        self.description = {
            "en" : "Plain Washer",
            "es" : "Arandela plana",
        }
        self.norm = "ISO 7092"
        self.oldnorm = "ISO 7092"
        self.manufacturer = ""
    
    def GuiInfo(self):

        #self.icon = ""
        self.icon = FreeCAD.getHomePath() + "Mod/Library/Resources/icons/Washer.svg"
        self.drawing = ""
    
    def geometricalInfo(self):

        self.dimensionConfig = ["d1", "d2", "h"]
        self.possibleDiameters = ["1,6", "2", "2,5", "3", "4", "5", "6", "8", "10", "12", "(14)", "16", "20", "24", "30", "36"]
        self.dimensions = {
             #       d1    d2    h 
            '1,6': (1.7, 3.5, 0.35),
            '2': (2.2, 4.5, 0.35),
            '2,5': (2.7, 5, 0.55),
            '3': (3.2, 6, 0.55),
            '4': (4.3, 8, 0.55),
            '5': (5.3, 9, 1.1),
            '6': (6.4, 11, 1.8),
            '8': (8.4, 15, 1.8),
            '10': (10.5, 18, 1.8),
            '12': (13, 20, 2.2),
            '(14)': (15, 24, 2.7),
            '16': (17, 28, 2.7),
            '20': (21, 34, 3.3),
            '24': (25, 39, 4.3),
            '30': (31, 50, 4.3),
            '36': (37, 60, 5.6)
        }

    
    def materialInfo(self):

        self.PosibleMaterial ={
            '200 HV A2': "",
            '200 HV A4': "",
            '200 HV F1': "",
            '200 HV C1': "",
            '200 HV C4': "",
            'St 200 HV': "",
            'St 300 HV': "",
        }

    def basicGeometry(self, obj, objInfo):

        import Part, FreeCAD, math
        from FreeCAD import Base

        d1 = objInfo().d1()
        d2 = objInfo().d2()
        h = objInfo().h()

        # Definition of the dimensional properties

        obj.addProperty("App::PropertyLength","Dmin","ISO_7092","Diameter minimum from the ISO 7092").Dmin = d1
        obj.addProperty("App::PropertyLength","Dmax","ISO_7092","Diameter maximum from the ISO 7092").Dmax = d2
        obj.addProperty("App::PropertyLength","Thickness","ISO_7092","Thickness from the ISO 7092").Thickness = h

        # Definition points from section

        center = Base.Vector(0,0,0)

        # Definition edges from section

        c1 = Part.makeCircle(obj.Dmax.Value/2, center, Base.Vector(0,0,1))
        c2 = Part.makeCircle(obj.Dmin.Value/2, center, Base.Vector(0,0,1))

        # Generation section face

        wire1 = Part.Wire([c1])
        wire2 = Part.Wire([c2])
        face1 = Part.Face(wire1)
        face2 = Part.Face(wire2)
        section = face1.cut(face2)

        # Extrude the section defined

        washer = section.extrude(FreeCAD.Vector(0,0,obj.Thickness.Value))
        
        #r.reverse()

        obj.Shape = washer
    
    def refineGeometry(self, obj, objInfo):

        pass
ian.rees
Posts: 696
Joined: Sun Jun 15, 2014 3:28 am
Contact:

Re: Library workbench

Postby ian.rees » Wed Oct 31, 2018 7:51 pm

Hi fdomateu,

I think the idea of a "part" in most of your post, is not really what the "part" in Part Design represents. My impression is that the second is a more general thing, which is meant to be created/modified in FreeCAD, but the first thing is more specific - like could be ordered from a manufacturer. Just to make this easier to write/read, I'll call yours an "Item", and the existing one a "Part".

To me, it totally makes sense to have a workbench/macro/tool where Parts can be created from a catalogue of Items as you describe - indeed there are currently ways to do that. We need to generate Parts, simply because they're the things that that this part of FreeCAD manipulates. Would the Part generated in your proposal be mutable? In other words, if I wanted to add a cotter pin to my design, and show that it's bent, would I be able to do that? If it is mutable, what happens to the original manufacturer/part number/etc information when the derived Part is modified? What would Parts that did not originate as Items contain in their manufacturer/part number/etc.?

So, to get back to my original response; I think it's important to take a step back, and think through what it is that you want to accomplish - without worrying about C++ classes or whatever. Is there anything you want to do, which can not be accomplished in the current structure?
fdomateu
Posts: 26
Joined: Thu May 17, 2018 7:14 am

Re: Library workbench

Postby fdomateu » Sun Nov 04, 2018 7:48 pm

Hi ian.rees,

If I have understood correct your question, with my actual python code the standard part is mutable at the case that you introduce the standard part at the model as body. The objType variable from my encapsulate function that I copied some previous posts should be Body to have a mutable standard part.

Bellow you can find an example of a standard part Cube where I have later on made a hole at the middle. The library workbench changes the properties Length, Width or Height of the Cube and the hole is automatically placed at the correct position during the recalculation process.
Attachments
mutable_example.PNG
mutable_example.PNG (27.77 KiB) Viewed 332 times