Skip to content

Commit

Permalink
Do basic project setup
Browse files Browse the repository at this point in the history
 - Adds initgui and workbench settings
 - Adds FeaturePython for TextureConfig
  • Loading branch information
furti committed Sep 30, 2018
1 parent 637049d commit e777bba
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -1,3 +1,7 @@
textures/**
testfiles/**
.vscode/**

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
1 change: 1 addition & 0 deletions Init.py
@@ -0,0 +1 @@
# Empty for now. Nothing special to initialize
25 changes: 25 additions & 0 deletions InitGui.py
@@ -0,0 +1,25 @@
import FreeCAD, FreeCADGui

class ArchTextureWorkbench (FreeCADGui.Workbench):
"Texture Architectural objects in FreeCAD"

MenuText = "Arch Texture"
ToolTip = "Texture architectural objects"

def __init__(self):
from utils.resource_utils import iconPath
# self.__class__.Icon = iconPath("Workbench.svg")


def Initialize(self):
# Initialize the module
import toolbars

for name,commands in toolbars.toolbarManager.Toolbars.items():
self.appendToolbar(name,[command.commandName for command in commands])

# def Activated(self):

# def Deactivated(self):

FreeCADGui.addWorkbench(ArchTextureWorkbench())
Empty file.
Empty file added Resources/Icons/.gitkeep
Empty file.
Empty file added Resources/UI/.gitkeep
Empty file.
29 changes: 29 additions & 0 deletions test.py
@@ -0,0 +1,29 @@
import FreeCAD
import math
from os import path
from pivy import coin

filePath = path.join(path.dirname(path.realpath(__file__)), 'textures')
bricks = path.join(filePath, 'Bricks_Red.jpg')

tex = coin.SoTexture2()
tex.filename = bricks

transform = coin.SoTexture2Transform()
transform.rotation = math.radians(90)
#transform.scaleFactor = [0.8889, 0.8889]

print(bricks)

def textureObjects():
for o in FreeCAD.ActiveDocument.Objects:
if hasattr(o,'Shape'):
if hasattr(o, 'IfcRole'):
print 'got object %s' %(o)
rootnode = o.ViewObject.RootNode
rootnode.insertChild(transform, 1)
rootnode.insertChild(tex, 1)


if __name__ == "__main__":
textureObjects()
51 changes: 51 additions & 0 deletions texture_config.py
@@ -0,0 +1,51 @@
import FreeCAD, FreeCADGui
from pivy import coin

class TextureConfig():
def __init__(self, obj):
obj.Proxy = self
# maybe add some properties later on
# obj.addProperty("App::PropertyString","SomeProp","TextureConfig","Description").SomeProp=value

def execute(self, fp):
pass

def __getstate__(self):
'''Store the texture config inside the FreeCAD File'''
return ()

def __setstate__(self, state):
'''Load the texture config from the FreeCAD File'''
pass

class ViewProviderTextureConfig():
def __init__(self, vobj):
vobj.Proxy = self

def attach(self, vobj):
self.ViewObject = vobj
self.Object = vobj.Object
self.TextureConfig = self.Object.Proxy

self.coinNode = coin.SoGroup()
vobj.addDisplayMode(self.coinNode, "Standard");

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

def getDefaultDisplayMode(self):
return "Standard"

def updateData(self, fp, prop):
pass

def onChanged(self, vp, prop):
pass

def createTextureConfig():
textureConfigObject = FreeCAD.ActiveDocument.addObject("App::FeaturePython", "TextureConfig")
textureConfig = TextureConfig(textureConfigObject)
ViewProviderTextureConfig(textureConfigObject.ViewObject)

if __name__ == "__main__":
createTextureConfig()
13 changes: 13 additions & 0 deletions toolbars.py
@@ -0,0 +1,13 @@
from collections import OrderedDict
import FreeCAD, FreeCADGui

class ToolbarManager:
Toolbars = OrderedDict()

def registerCommand(self, command):
FreeCADGui.addCommand(command.commandName, command)
self.Toolbars.setdefault(command.toolbarName, []).append(command)

toolbarManager = ToolbarManager()

# import commands here
16 changes: 16 additions & 0 deletions utils/resource_utils.py
@@ -0,0 +1,16 @@
import FreeCAD
from os import path

resources_path = path.join(path.dirname(path.realpath(__file__)), '../Resources')
icons_path = path.join(resources_path, 'Icons')
ui_path = path.join(resources_path, 'UI')

def iconPath(name):
f = path.join(icons_path, name)

return f

def uiPath(name):
f = path.join(ui_path, name)

return f

0 comments on commit e777bba

Please sign in to comment.