For example how to make this structure from features?
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+++ ",
" ++++++ ",
" ++++ ",
" ",
" ",
" ",
" "
};
"""