[SOLVED] How to connect fetures (as sub feature) to parent feature?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

[SOLVED] How to connect fetures (as sub feature) to parent feature?

Post by Evgeniy »

How to connect fetures (as sub feature) to parent feature?

For example how to make this structure from features?

Molecula.png
Molecula.png (7.73 KiB) Viewed 383 times

How to make feature is connectable?

And is it possible to attach sub-sub-fetures to sub-feature?

Is there limits in the levels of nesting?

This code can be used as a basis:

Code: Select all

# -*- coding: utf-8 -*-
import FreeCAD
import FreeCAD as App
import FreeCADGui

obj = App.ActiveDocument.addObject('App::FeaturePython', 'Molecula')
MoleculaFeature(obj)
MoleculaViewProvider(obj.ViewObject)

obj = App.ActiveDocument.addObject('App::FeaturePython', 'Atom')
H_AtomFeature(obj)
H_AtomViewProvider(obj.ViewObject)

obj = App.ActiveDocument.addObject('App::FeaturePython', 'Atom')
O_AtomFeature(obj)
O_AtomViewProvider(obj.ViewObject)

obj = App.ActiveDocument.addObject('App::FeaturePython', 'Atom')
O_AtomFeature(obj)
O_AtomViewProvider(obj.ViewObject)

App.ActiveDocument.recompute()

class MoleculaFeature():

    def __init__(self, obj):
        self.Type = 'MoleculaFeature'
        obj.addProperty('App::PropertyString', 'Description', 'Base', 'Feature description').Description = ""
        obj.Proxy = self
        self.obj = obj

    def onChanged(self, obj, prop):
        val = obj.getPropertyByName(prop)

    def execute(self, obj):
        App.Console.PrintMessage("MoleculaFeature execute \n")

class MoleculaViewProvider:

    def __init__(self, obj):
        obj.Proxy = self

    def getDetailPath(self, subname, path, append):
        FreeCAD.Console.PrintMessage("MoleculaViewProvider getDetailPath: " + str(subname) + " " + str(path) + " " + str(append) + "\n")
   
    def getElementPicked(self, pp):
        FreeCAD.Console.PrintMessage("MoleculaViewProvider getElementPicked: " + str(pp) + "\n")

    def attach(self, obj):
        from pivy import coin    # Without that icon is be gray
        self.standard = coin.SoGroup()
        obj.addDisplayMode(self.standard,"Standard");

    def updateData(self, obj, prop):
        return

    def getDisplayModes(self, obj):
        return ["Standard"]

    def getDefaultDisplayMode(self):
        return "Standard"

    def setDisplayMode(self,mode):
        return mode

    def onChanged(self, obj, prop):
        return

    def getIcon(self):
        return """
               /* XPM */
               static char *Some_icon_xpm[] = {
               /* columns rows colors chars-per-pixel */
               "16 16 3 1 ",
               "  c None",
               ". c #00AAFF",
               "+ c #FF0000",
               /* pixels */
               "                ",
               "                ",
               "                ",
               "      ++++      ",
               "     ++++++     ",
               "    ++++++++    ",
               "   ++++++++++   ",
               "   ++++++++++   ",
               "   ++++++++++   ",
               "   ++++++++++   ",
               "  ...++++++...  ",
               " .....++++..... ",
               " .....    ..... ",
               " .....    ..... ",
               "  ...      ...  ",
               "                "
               };
               """

class H_AtomFeature():

    def __init__(self, obj):
        self.Type = 'AtomFeature'
        obj.addProperty('App::PropertyString', 'Description', 'Base', 'Feature description').Description = ""
        obj.Proxy = self
        self.obj = obj

    def onChanged(self, obj, prop):
        val = obj.getPropertyByName(prop)

    def execute(self, obj):
        App.Console.PrintMessage("H_AtomFeature execute \n")

class O_AtomFeature(H_AtomFeature):

    def execute(self, obj):
        App.Console.PrintMessage("O_AtomFeature execute \n")    

class H_AtomViewProvider():

    def __init__(self, obj):
        obj.Proxy = self

    def getDetailPath(self, subname, path, append):
        FreeCAD.Console.PrintMessage("AtomViewProvider getDetailPath: " + str(subname) + " " + str(path) + " " + str(append) + "\n")
   
    def getElementPicked(self, pp):
        FreeCAD.Console.PrintMessage("AtomViewProvider getElementPicked: " + str(pp) + "\n")

    def attach(self, obj):
        from pivy import coin    # Without that icon is be gray
        self.standard = coin.SoGroup()
        obj.addDisplayMode(self.standard,"Standard");

    def updateData(self, obj, prop):
        return

    def getDisplayModes(self, obj):
        return ["Standard"]

    def getDefaultDisplayMode(self):
        return "Standard"

    def setDisplayMode(self,mode):
        return mode

    def onChanged(self, obj, prop):
        return

    def getIcon(self):
        return """
               /* XPM */
               static char *Some_icon_xpm[] = {
               /* columns rows colors chars-per-pixel */
               "16 16 3 1 ",
               "  c None",
               "o c #FFFFFF",
               "+ c #00AAFF",
               /* pixels */
               "                ",
               "                ",
               "                ",
               "      ++++      ",
               "     ++++++     ",
               "    ++++++++    ",
               "   +++o++o+++   ",
               "   +++o++o+++   ",
               "   +++oooo+++   ",
               "   +++o++o+++   ",
               "   +++o++o+++   ",
               "    ++++++++    ",
               "     ++++++     ",
               "      ++++      ",
               "                ",
               "                ",
               "                "
               };
               """

class O_AtomViewProvider(H_AtomViewProvider):

    def getIcon(self):
        return """
               /* XPM */
               static char *Some_icon_xpm[] = {
               /* columns rows colors chars-per-pixel */
               "16 16 3 1 ",
               "  c None",
               "o c #FFFFFF",
               "+ c #FF0000",
               /* pixels */
               "                ",
               "                ",
               "                ",
               "                ",
               "      ++++      ",
               "     ++++++     ",
               "    +++oo+++    ",
               "    ++o++o++    ",
               "    ++o++o++    ",
               "    ++o++o++    ",
               "    +++oo+++    ",
               "     ++++++     ",
               "      ++++      ",
               "                ",
               "                ",
               "                ",
               "                "
               };
               """


Last edited by Evgeniy on Sat Dec 24, 2022 11:17 pm, edited 1 time in total.
wmayer
Founder
Posts: 20303
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How to connect fetures (as sub feature) to parent feature?

Post by wmayer »

What you basically have to do is implementing the method claimChildren() in your MoleculaViewProvider class. This method must return a list of the objects that should be underneath the tree item. In the modified code I added a PropertyLinkList to MoleculaFeature and assigned a list of the objects from outside. The view provider then updates itself when updateData() is called.

Code: Select all

# -*- coding: utf-8 -*-
import FreeCAD
import FreeCAD as App
import FreeCADGui

atoms = []
obj = App.ActiveDocument.addObject('App::FeaturePython', 'Atom')
atoms.append(obj)
H_AtomFeature(obj)
H_AtomViewProvider(obj.ViewObject)

obj = App.ActiveDocument.addObject('App::FeaturePython', 'Atom')
atoms.append(obj)
O_AtomFeature(obj)
O_AtomViewProvider(obj.ViewObject)

obj = App.ActiveDocument.addObject('App::FeaturePython', 'Atom')
atoms.append(obj)
O_AtomFeature(obj)
O_AtomViewProvider(obj.ViewObject)

obj = App.ActiveDocument.addObject('App::FeaturePython', 'Molecula')
MoleculaFeature(obj)
MoleculaViewProvider(obj.ViewObject)
obj.Atoms = atoms

App.ActiveDocument.recompute()

class MoleculaFeature():
    
    def __init__(self, obj):
        self.Type = 'MoleculaFeature'
        obj.addProperty('App::PropertyString', 'Description', 'Base', 'Feature description').Description = ""
        obj.addProperty('App::PropertyLinkList', 'Atoms', 'Base', 'Feature description')
        obj.Proxy = self
        self.obj = obj
    
    def onChanged(self, obj, prop):
        val = obj.getPropertyByName(prop)
    
    def execute(self, obj):
        App.Console.PrintMessage("MoleculaFeature execute \n")

class MoleculaViewProvider:
    
    def __init__(self, obj):
        obj.Proxy = self
        self.atoms = []
    
    def getDetailPath(self, subname, path, append):
        FreeCAD.Console.PrintMessage("MoleculaViewProvider getDetailPath: " + str(subname) + " " + str(path) + " " + str(append) + "\n")
    
    def getElementPicked(self, pp):
        FreeCAD.Console.PrintMessage("MoleculaViewProvider getElementPicked: " + str(pp) + "\n")
    
    def attach(self, obj):
        from pivy import coin    # Without that icon is be gray
        self.standard = coin.SoGroup()
        obj.addDisplayMode(self.standard,"Standard");
    
    def updateData(self, obj, prop):
        self.atoms = obj.Atoms
        return
    
    def getDisplayModes(self, obj):
        return ["Standard"]
    
    def getDefaultDisplayMode(self):
        return "Standard"
    
    def setDisplayMode(self,mode):
        return mode
    
    def onChanged(self, obj, prop):
        return
    
    def claimChildren(self):
        return self.atoms
    
    def getIcon(self):
        return """
               /* XPM */
               static char *Some_icon_xpm[] = {
               /* columns rows colors chars-per-pixel */
               "16 16 3 1 ",
               "  c None",
               ". c #00AAFF",
               "+ c #FF0000",
               /* pixels */
               "                ",
               "                ",
               "                ",
               "      ++++      ",
               "     ++++++     ",
               "    ++++++++    ",
               "   ++++++++++   ",
               "   ++++++++++   ",
               "   ++++++++++   ",
               "   ++++++++++   ",
               "  ...++++++...  ",
               " .....++++..... ",
               " .....    ..... ",
               " .....    ..... ",
               "  ...      ...  ",
               "                "
               };
               """

class H_AtomFeature():
    
    def __init__(self, obj):
        self.Type = 'AtomFeature'
        obj.addProperty('App::PropertyString', 'Description', 'Base', 'Feature description').Description = ""
        obj.Proxy = self
        self.obj = obj
    
    def onChanged(self, obj, prop):
        val = obj.getPropertyByName(prop)
    
    def execute(self, obj):
        App.Console.PrintMessage("H_AtomFeature execute \n")
    
class O_AtomFeature(H_AtomFeature):
    
    def execute(self, obj):
        App.Console.PrintMessage("O_AtomFeature execute \n")    
    
class H_AtomViewProvider():
    
    def __init__(self, obj):
        obj.Proxy = self
    
    def getDetailPath(self, subname, path, append):
        FreeCAD.Console.PrintMessage("AtomViewProvider getDetailPath: " + str(subname) + " " + str(path) + " " + str(append) + "\n")
    
    def getElementPicked(self, pp):
        FreeCAD.Console.PrintMessage("AtomViewProvider getElementPicked: " + str(pp) + "\n")
    
    def attach(self, obj):
        from pivy import coin    # Without that icon is be gray
        self.standard = coin.SoGroup()
        obj.addDisplayMode(self.standard,"Standard");
    
    def updateData(self, obj, prop):
        return
    
    def getDisplayModes(self, obj):
        return ["Standard"]
    
    def getDefaultDisplayMode(self):
        return "Standard"
    
    def setDisplayMode(self,mode):
        return mode
    
    def onChanged(self, obj, prop):
        return
    
    def getIcon(self):
        return """
               /* XPM */
               static char *Some_icon_xpm[] = {
               /* columns rows colors chars-per-pixel */
               "16 16 3 1 ",
               "  c None",
               "o c #FFFFFF",
               "+ c #00AAFF",
               /* pixels */
               "                ",
               "                ",
               "                ",
               "      ++++      ",
               "     ++++++     ",
               "    ++++++++    ",
               "   +++o++o+++   ",
               "   +++o++o+++   ",
               "   +++oooo+++   ",
               "   +++o++o+++   ",
               "   +++o++o+++   ",
               "    ++++++++    ",
               "     ++++++     ",
               "      ++++      ",
               "                ",
               "                ",
               "                "
               };
               """

class O_AtomViewProvider(H_AtomViewProvider):
    
    def getIcon(self):
        return """
               /* XPM */
               static char *Some_icon_xpm[] = {
               /* columns rows colors chars-per-pixel */
               "16 16 3 1 ",
               "  c None",
               "o c #FFFFFF",
               "+ c #FF0000",
               /* pixels */
               "                ",
               "                ",
               "                ",
               "                ",
               "      ++++      ",
               "     ++++++     ",
               "    +++oo+++    ",
               "    ++o++o++    ",
               "    ++o++o++    ",
               "    ++o++o++    ",
               "    +++oo+++    ",
               "     ++++++     ",
               "      ++++      ",
               "                ",
               "                ",
               "                ",
               "                "
               };
               """
And is it possible to attach sub-sub-fetures to sub-feature?

Is there limits in the levels of nesting?
Sure, no problem. The idea is the same. Just implement the claimChildren() of the view provider

Code: Select all

# -*- coding: utf-8 -*-
import FreeCAD
import FreeCAD as App
import FreeCADGui

obj1 = App.ActiveDocument.addObject('App::FeaturePython', 'Atom')
H_AtomFeature(obj1)
H_AtomViewProvider(obj1.ViewObject)

obj2 = App.ActiveDocument.addObject('App::FeaturePython', 'Atom')
O_AtomFeature(obj2)
O_AtomViewProvider(obj2.ViewObject)
obj2.Atom = obj1

obj3 = App.ActiveDocument.addObject('App::FeaturePython', 'Atom')
O_AtomFeature(obj3)
O_AtomViewProvider(obj3.ViewObject)
obj3.Atom = obj2

obj4 = App.ActiveDocument.addObject('App::FeaturePython', 'Molecula')
MoleculaFeature(obj4)
MoleculaViewProvider(obj4.ViewObject)
obj4.Atoms = obj3

App.ActiveDocument.recompute()

class MoleculaFeature():
    
    def __init__(self, obj):
        self.Type = 'MoleculaFeature'
        obj.addProperty('App::PropertyString', 'Description', 'Base', 'Feature description').Description = ""
        obj.addProperty('App::PropertyLinkList', 'Atoms', 'Base', 'Feature description')
        obj.Proxy = self
        self.obj = obj
    
    def onChanged(self, obj, prop):
        val = obj.getPropertyByName(prop)
    
    def execute(self, obj):
        App.Console.PrintMessage("MoleculaFeature execute \n")

class MoleculaViewProvider:
    
    def __init__(self, obj):
        obj.Proxy = self
        self.atoms = []
    
    def getDetailPath(self, subname, path, append):
        FreeCAD.Console.PrintMessage("MoleculaViewProvider getDetailPath: " + str(subname) + " " + str(path) + " " + str(append) + "\n")
    
    def getElementPicked(self, pp):
        FreeCAD.Console.PrintMessage("MoleculaViewProvider getElementPicked: " + str(pp) + "\n")
    
    def attach(self, obj):
        from pivy import coin    # Without that icon is be gray
        self.standard = coin.SoGroup()
        obj.addDisplayMode(self.standard,"Standard");
    
    def updateData(self, obj, prop):
        self.atoms = obj.Atoms
        return
    
    def getDisplayModes(self, obj):
        return ["Standard"]
    
    def getDefaultDisplayMode(self):
        return "Standard"
    
    def setDisplayMode(self,mode):
        return mode
    
    def onChanged(self, obj, prop):
        return
    
    def claimChildren(self):
        return self.atoms
    
    def getIcon(self):
        return """
               /* XPM */
               static char *Some_icon_xpm[] = {
               /* columns rows colors chars-per-pixel */
               "16 16 3 1 ",
               "  c None",
               ". c #00AAFF",
               "+ c #FF0000",
               /* pixels */
               "                ",
               "                ",
               "                ",
               "      ++++      ",
               "     ++++++     ",
               "    ++++++++    ",
               "   ++++++++++   ",
               "   ++++++++++   ",
               "   ++++++++++   ",
               "   ++++++++++   ",
               "  ...++++++...  ",
               " .....++++..... ",
               " .....    ..... ",
               " .....    ..... ",
               "  ...      ...  ",
               "                "
               };
               """

class H_AtomFeature():
    
    def __init__(self, obj):
        self.Type = 'AtomFeature'
        obj.addProperty('App::PropertyString', 'Description', 'Base', 'Feature description').Description = ""
        obj.addProperty('App::PropertyLink', 'Atom', 'Base', 'Feature description')
        obj.Proxy = self
        self.obj = obj
    
    def onChanged(self, obj, prop):
        val = obj.getPropertyByName(prop)
    
    def execute(self, obj):
        App.Console.PrintMessage("H_AtomFeature execute \n")

class O_AtomFeature(H_AtomFeature):
    
    def execute(self, obj):
        App.Console.PrintMessage("O_AtomFeature execute \n")    

class H_AtomViewProvider():
    
    def __init__(self, obj):
        obj.Proxy = self
        self.atom = []
    
    def getDetailPath(self, subname, path, append):
        FreeCAD.Console.PrintMessage("AtomViewProvider getDetailPath: " + str(subname) + " " + str(path) + " " + str(append) + "\n")
    
    def getElementPicked(self, pp):
        FreeCAD.Console.PrintMessage("AtomViewProvider getElementPicked: " + str(pp) + "\n")
    
    def attach(self, obj):
        from pivy import coin    # Without that icon is be gray
        self.standard = coin.SoGroup()
        obj.addDisplayMode(self.standard,"Standard");
    
    def updateData(self, obj, prop):
        self.atom = [obj.Atom]
        return
    
    def getDisplayModes(self, obj):
        return ["Standard"]
    
    def getDefaultDisplayMode(self):
        return "Standard"
    
    def setDisplayMode(self,mode):
        return mode
    
    def onChanged(self, obj, prop):
        return
    
    def claimChildren(self):
        return self.atom
    
    def getIcon(self):
        return """
               /* XPM */
               static char *Some_icon_xpm[] = {
               /* columns rows colors chars-per-pixel */
               "16 16 3 1 ",
               "  c None",
               "o c #FFFFFF",
               "+ c #00AAFF",
               /* pixels */
               "                ",
               "                ",
               "                ",
               "      ++++      ",
               "     ++++++     ",
               "    ++++++++    ",
               "   +++o++o+++   ",
               "   +++o++o+++   ",
               "   +++oooo+++   ",
               "   +++o++o+++   ",
               "   +++o++o+++   ",
               "    ++++++++    ",
               "     ++++++     ",
               "      ++++      ",
               "                ",
               "                ",
               "                "
               };
               """

class O_AtomViewProvider(H_AtomViewProvider):
    
    def getIcon(self):
        return """
               /* XPM */
               static char *Some_icon_xpm[] = {
               /* columns rows colors chars-per-pixel */
               "16 16 3 1 ",
               "  c None",
               "o c #FFFFFF",
               "+ c #FF0000",
               /* pixels */
               "                ",
               "                ",
               "                ",
               "                ",
               "      ++++      ",
               "     ++++++     ",
               "    +++oo+++    ",
               "    ++o++o++    ",
               "    ++o++o++    ",
               "    ++o++o++    ",
               "    +++oo+++    ",
               "     ++++++     ",
               "      ++++      ",
               "                ",
               "                ",
               "                ",
               "                "
               };
               """
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: How to connect fetures (as sub feature) to parent feature?

Post by Evgeniy »

wmayer wrote: Fri Dec 09, 2022 12:33 pm What you basically have to do is implementing the method claimChildren() in your MoleculaViewProvider class.
Big thanks! It's really not difficult and convenient.

Only now I realized that I had mixed up the atoms. There should be one O atom and two H atoms. Now the example is chemical correct.

Code: Select all

# -*- coding: utf-8 -*-
import FreeCAD
import FreeCAD as App
import FreeCADGui

# Array for atoms
atoms = []

# Add O atom
obj = App.ActiveDocument.addObject('App::FeaturePython', 'Atom')
atoms.append(obj)
O_AtomFeature(obj)
O_AtomViewProvider(obj.ViewObject)

# Add H atom
obj = App.ActiveDocument.addObject('App::FeaturePython', 'Atom')
atoms.append(obj)
H_AtomFeature(obj)
H_AtomViewProvider(obj.ViewObject)

# Add H atom
obj = App.ActiveDocument.addObject('App::FeaturePython', 'Atom')
atoms.append(obj)
H_AtomFeature(obj)
H_AtomViewProvider(obj.ViewObject)

# Create molecula and connect atoms to it
obj = App.ActiveDocument.addObject('App::FeaturePython', 'Molecula')
MoleculaFeature(obj)
MoleculaViewProvider(obj.ViewObject)
obj.Atoms = atoms

App.ActiveDocument.recompute()

class MoleculaFeature():
    
    def __init__(self, obj):
        self.Type = 'MoleculaFeature'
        obj.addProperty('App::PropertyString', 'Description', 'Base', 'Feature description').Description = ""
        obj.addProperty('App::PropertyLinkList', 'Atoms', 'Base', 'Feature description')
        obj.Proxy = self
        self.obj = obj
    
    def onChanged(self, obj, prop):
        val = obj.getPropertyByName(prop)
    
    def execute(self, obj):
        App.Console.PrintMessage("MoleculaFeature execute \n")

class MoleculaViewProvider:
    
    def __init__(self, obj):
        obj.Proxy = self
        self.atoms = []
    
    def getDetailPath(self, subname, path, append):
        FreeCAD.Console.PrintMessage("MoleculaViewProvider getDetailPath: " + str(subname) + " " + str(path) + " " + str(append) + "\n")
    
    def getElementPicked(self, pp):
        FreeCAD.Console.PrintMessage("MoleculaViewProvider getElementPicked: " + str(pp) + "\n")
    
    def attach(self, obj):
        from pivy import coin    # Without that icon is be gray
        self.standard = coin.SoGroup()
        obj.addDisplayMode(self.standard,"Standard");
    
    def updateData(self, obj, prop):
        self.atoms = obj.Atoms
        return
    
    def getDisplayModes(self, obj):
        return ["Standard"]
    
    def getDefaultDisplayMode(self):
        return "Standard"
    
    def setDisplayMode(self,mode):
        return mode
    
    def onChanged(self, obj, prop):
        return
    
    def claimChildren(self):
        return self.atoms
    
    def getIcon(self):
        return """
               /* XPM */
               static char *Some_icon_xpm[] = {
               /* columns rows colors chars-per-pixel */
               "16 16 3 1 ",
               "  c None",
               ". c #00AAFF",
               "+ c #FF0000",
               /* pixels */
               "                ",
               "                ",
               "                ",
               "      ++++      ",
               "     ++++++     ",
               "    ++++++++    ",
               "   ++++++++++   ",
               "   ++++++++++   ",
               "   ++++++++++   ",
               "   ++++++++++   ",
               "  ...++++++...  ",
               " .....++++..... ",
               " .....++++..... ",
               " .....    ..... ",
               "  ...      ...  ",
               "                "
               };
               """

class O_AtomFeature():
    
    def __init__(self, obj):
        self.Type = 'AtomFeature'
        obj.addProperty('App::PropertyString', 'Description', 'Base', 'Feature description').Description = ""
        obj.Proxy = self
        self.obj = obj
    
    def onChanged(self, obj, prop):
        val = obj.getPropertyByName(prop)
    
    def execute(self, obj):
        App.Console.PrintMessage("O_AtomFeature execute \n")

class H_AtomFeature(O_AtomFeature):
    
    def execute(self, obj):
        App.Console.PrintMessage("H_AtomFeature execute \n")    

class O_AtomViewProvider():
    
    def __init__(self, obj):
        obj.Proxy = self
    
    def getDetailPath(self, subname, path, append):
        FreeCAD.Console.PrintMessage("AtomViewProvider getDetailPath: " + str(subname) + " " + str(path) + " " + str(append) + "\n")
    
    def getElementPicked(self, pp):
        FreeCAD.Console.PrintMessage("AtomViewProvider getElementPicked: " + str(pp) + "\n")
    
    def attach(self, obj):
        from pivy import coin    # Without that icon is be gray
        self.standard = coin.SoGroup()
        obj.addDisplayMode(self.standard,"Standard");
    
    def updateData(self, obj, prop):
        return
    
    def getDisplayModes(self, obj):
        return ["Standard"]
    
    def getDefaultDisplayMode(self):
        return "Standard"
    
    def setDisplayMode(self,mode):
        return mode
    
    def onChanged(self, obj, prop):
        return
    
    def getIcon(self):
        return """
               /* XPM */
               static char *Some_icon_xpm[] = {
               /* columns rows colors chars-per-pixel */
               "16 16 3 1 ",
               "  c None",
               "o c #FFFFFF",
               "+ c #FF0000",
               /* pixels */
               "                ",
               "                ",
               "                ",
               "      ++++      ",
               "     ++++++     ",
               "    ++++++++    ",
               "   ++++oo++++   ",
               "   +++o++o+++   ",
               "   +++o++o+++   ",
               "   +++o++o+++   ",
               "   ++++oo++++   ",
               "    ++++++++    ",
               "     ++++++     ",
               "      ++++      ",
               "                ",
               "                ",
               "                "
               };
               """

class H_AtomViewProvider(O_AtomViewProvider):
    
    def getIcon(self):
        return """
               /* XPM */
               static char *Some_icon_xpm[] = {
               /* columns rows colors chars-per-pixel */
               "16 16 3 1 ",
               "  c None",
               "o c #FFFFFF",
               "+ c #00AAFF",
               /* pixels */
               "                ",
               "                ",
               "                ",
               "                ",
               "      ++++      ",
               "     +o++o+     ",
               "     +o++o+     ",
               "     +oooo+     ",
               "     +o++o+     ",
               "     +o++o+     ",
               "      ++++      ",
               "                ",
               "                ",
               "                ",
               "                ",
               "                "
               };
               """

# End
It would be nice if those who write articles in the freecad wiki would add this code to some article on the topic of scripting objects.
Post Reply