Skip to content

Commit

Permalink
Merge pull request #157 from kbwbe/devel
Browse files Browse the repository at this point in the history
Per face transparency supported now (experimental)
  • Loading branch information
kbwbe authored Jan 20, 2019
2 parents 96bc288 + 3941d44 commit 446989b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 25 deletions.
2 changes: 1 addition & 1 deletion GuiA2p/Resources/ui/a2p_prefs.ui
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
<item>
<widget class="Gui::PrefCheckBox" name="checkBox_7">
<property name="text">
<string>inherit per face transparency from sub-assemblies</string>
<string>inherit per face transparency from parts and sub-assemblies (experimental)</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>usePerFaceTransparency</cstring>
Expand Down
22 changes: 16 additions & 6 deletions a2p_MuxAssembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ def muxAssemblyWithTopoNames(doc, withColor=False):

if withColor:
if colorFlag:
faceColors.append(shapeCol)
if not a2plib.getPerFaceTransparency():
faceColors.append(shapeCol)
else:
faceColors.append(makeDiffuseElement(shapeCol,transparency))
else:
faceColors.append(diffuseCol[i])

Expand Down Expand Up @@ -165,6 +168,7 @@ def muxObjectsWithKeys(objsIn, withColor=False):
shapeCol = obj.ViewObject.ShapeColor
diffuseCol = obj.ViewObject.DiffuseColor
tempShape = makePlacedShape(obj)
transparency = obj.ViewObject.Transparency

# now start the loop with use of the stored values..(much faster)
for i, face in enumerate(tempShape.Faces):
Expand All @@ -173,17 +177,23 @@ def muxObjectsWithKeys(objsIn, withColor=False):

if withColor:
if colorFlag:
faceColors.append(shapeCol)
if not a2plib.getPerFaceTransparency():
faceColors.append(shapeCol)
else:
faceColors.append(makeDiffuseElement(shapeCol,transparency))
else:
faceColors.append(diffuseCol[i])

shell = Part.makeShell(faces)
Msg("A2P MUX: result: {}\n".format(shell))
DebugMsg(A2P_DEBUG_3,"a2p MUX: faceColors:\n{}\n".format(faceColors)) # has result all faces' color values?
try:
solid = Part.Solid(shell)
except:
# keeping a shell if solid is failing
solid = shell
if withColor:
return muxInfo, shell, faceColors
return muxInfo, solid, faceColors, transparency
else:
return muxInfo, shell
return muxInfo, solid

#NOTE: muxObjects is never called in A2plus
def muxObjects(doc, mode=0):
Expand Down
5 changes: 3 additions & 2 deletions a2p_convertPart.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ def convertToImportedPart(doc, obj):
for p in obj.ViewObject.PropertiesList:
if hasattr(obj.ViewObject, p) and p not in ['DiffuseColor','Proxy','MappedColors']:
setattr(newObj.ViewObject, p, getattr( obj.ViewObject, p))
newObj.ViewObject.DiffuseColor = copy.copy( obj.ViewObject.DiffuseColor )
newObj.ViewObject.Transparency = obj.ViewObject.Transparency
# newObj.ViewObject.Transparency = obj.ViewObject.Transparency # should have been done within the above loop
newObj.ViewObject.DiffuseColor = copy.copy( obj.ViewObject.DiffuseColor ) # diffuse needs to happen last

newObj.Placement.Base = obj.Placement.Base
newObj.Placement.Rotation = obj.Placement.Rotation

Expand Down
25 changes: 15 additions & 10 deletions a2p_importpart.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,17 +369,22 @@ def updateImportedParts(doc):
# save Placement because following newObject.Shape.copy() isn't resetting it to zeroes...
savedPlacement = obj.Placement
obj.Shape = newObject.Shape.copy()
obj.ViewObject.DiffuseColor = copy.copy(newObject.ViewObject.DiffuseColor)
obj.ViewObject.Transparency = newObject.ViewObject.Transparency
obj.Placement = savedPlacement # restore the old placement
if hasattr (obj, 'ViewObject'):
if hasattr (obj.ViewObject, 'Transparency'):
if obj.ViewObject.Transparency > 0:
transparency = obj.ViewObject.Transparency
obj.ViewObject.Transparency = 0
obj.ViewObject.Transparency = transparency
FreeCADGui.Selection.addSelection(obj)
FreeCADGui.Selection.removeSelection(obj)

if not a2plib.getPerFaceTransparency():
obj.ViewObject.DiffuseColor = copy.copy(newObject.ViewObject.DiffuseColor)
obj.ViewObject.Transparency = newObject.ViewObject.Transparency

if obj.ViewObject.Transparency > 0:
transparency = obj.ViewObject.Transparency
obj.ViewObject.Transparency = 0
obj.ViewObject.Transparency = transparency
FreeCADGui.Selection.addSelection(obj)
FreeCADGui.Selection.removeSelection(obj)

if a2plib.getPerFaceTransparency():
obj.ViewObject.DiffuseColor = copy.copy(newObject.ViewObject.DiffuseColor) # diffuse must be set last


mw = FreeCADGui.getMainWindow()
mdi = mw.findChild(QtGui.QMdiArea)
Expand Down
5 changes: 4 additions & 1 deletion a2p_topomapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,10 @@ def createTopoNames(self,withColor=False):

if withColor:
if colorFlag:
faceColors.append(shapeCol)
if not a2plib.getPerFaceTransparency():
faceColors.append(shapeCol)
else:
faceColors.append(a2plib.makeDiffuseElement(shapeCol,transparency))
else:
faceColors.append(diffuseCol[i])

Expand Down
19 changes: 14 additions & 5 deletions a2plib.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,11 @@ def setTransparency():
for obj in doc.Objects:
if hasattr(obj,'ViewObject'):
if hasattr(obj.ViewObject,'Transparency'):
# if hasattr(obj.ViewObject,'DiffuseColor'):
SAVED_TRANSPARENCY.append(
(obj.Name, obj.ViewObject.Transparency, obj.ViewObject.DiffuseColor)
if not a2plib.getPerFaceTransparency():
SAVED_TRANSPARENCY.append(obj.Name, obj.ViewObject.Transparency, obj.ViewObject.ShapeColor)
else:
SAVED_TRANSPARENCY.append(
(obj.Name, obj.ViewObject.Transparency, obj.ViewObject.DiffuseColor)
)
obj.ViewObject.Transparency = 80
#------------------------------------------------------------------------------
Expand All @@ -187,7 +189,11 @@ def restoreTransparency():
obj = doc.getObject(setting[0])
if obj is not None:
obj.ViewObject.Transparency = setting[1]
obj.ViewObject.DiffuseColor = setting[2]
if not a2plib.getPerFaceTransparency():
obj.ViewObject.ShapeColor = setting[2]
else:
obj.ViewObject.DiffuseColor = setting[2]

SAVED_TRANSPARENCY = []
#------------------------------------------------------------------------------
def isTransparencyEnabled():
Expand Down Expand Up @@ -643,4 +649,7 @@ def isA2pObject(obj):
result = True
return result
#------------------------------------------------------------------------------

def makeDiffuseElement(color,trans):
elem = (color[0],color[1],color[2],trans/100.0)
return elem
#------------------------------------------------------------------------------

0 comments on commit 446989b

Please sign in to comment.