import FreeCAD as App
import FreeCADGui as Gui
import Part

def create(obj_name):
    """
    Object creation method
    """
    obj = App.ActiveDocument.addObject('Part::FeaturePython', obj_name)
    box(obj)
    ViewProviderBox(obj.ViewObject)
    App.ActiveDocument.recompute()
    return obj

class box():

    def __init__(self, obj):
        """
        Default constructor
        """
        self.Type = 'box'
        obj.Proxy = self
        obj.addProperty("App::PropertyLinkListGlobal", "OperatesOn", "Relations", "")

    def execute(self, obj):
        """
        Called on document recompute
        """
        obj.Shape = Part.makeBox(1, 1, 1)


class ViewProviderBox:

    def __init__(self, obj):
        """
        Set this object to the proxy object of the actual view provider
        """
        obj.Proxy = self

    def attach(self, obj):
        """
        Setup the scene sub-graph of the view provider, this method is mandatory
        """
        return

    def updateData(self, fp, prop):
        """
        If a property of the handled feature has changed we have the chance to handle this here
        """
        return

    def getDisplayModes(self,obj):
        """
        Return a list of display modes.
        """
        return []

    def getDefaultDisplayMode(self):
        """
        Return the name of the default display mode. It must be defined in getDisplayModes.
        """
        return "Shaded"

    def setDisplayMode(self,mode):
        """
        Map the display mode defined in attach with those defined in getDisplayModes.
        Since they have the same names nothing needs to be done.
        This method is optional.
        """
        return mode

    def onChanged(self, vp, prop):
        """
        Print the name of the property that has changed
        """
        App.Console.PrintMessage("Change property: " + str(prop) + "\n")

    def getIcon(self):
        """
        Return the icon in XMP format which will appear in the tree view. This method is optional and if not defined a default icon is shown.
        """
        return 


    def __getstate__(self):
        """
        Called during document saving.
        """
        return None

    def __setstate__(self,state):
        """
        Called during document restore.
        """
        return None


App.newDocument("Unnamed")
App.ActiveDocument.addObject("Part::Box","Box")
App.ActiveDocument.ActiveObject.Label = "Cube"
App.ActiveDocument.getObject('Box').Placement = App.Placement(App.Vector(20,0,0),App.Rotation(App.Vector(0,0,1),0))
App.ActiveDocument.recompute()
Gui.ActiveDocument.ActiveView.fitAll()
create('test')
