diff --git a/GuiA2p/Resources/ui/a2p_prefs.ui b/GuiA2p/Resources/ui/a2p_prefs.ui index 5e520132..bf5870b0 100644 --- a/GuiA2p/Resources/ui/a2p_prefs.ui +++ b/GuiA2p/Resources/ui/a2p_prefs.ui @@ -131,7 +131,7 @@ - inherit per face transparency from sub-assemblies + inherit per face transparency from parts and sub-assemblies (experimental) usePerFaceTransparency diff --git a/a2p_MuxAssembly.py b/a2p_MuxAssembly.py index 00e4a417..f3cbf0e9 100644 --- a/a2p_MuxAssembly.py +++ b/a2p_MuxAssembly.py @@ -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]) @@ -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): @@ -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): diff --git a/a2p_convertPart.py b/a2p_convertPart.py index 575d599c..9d1a7825 100644 --- a/a2p_convertPart.py +++ b/a2p_convertPart.py @@ -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 diff --git a/a2p_importpart.py b/a2p_importpart.py index 869fe55e..ce0b64f0 100644 --- a/a2p_importpart.py +++ b/a2p_importpart.py @@ -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) diff --git a/a2p_topomapper.py b/a2p_topomapper.py index febac157..62d01784 100644 --- a/a2p_topomapper.py +++ b/a2p_topomapper.py @@ -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]) diff --git a/a2plib.py b/a2plib.py index 5c2a35d0..4297253d 100644 --- a/a2plib.py +++ b/a2plib.py @@ -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 #------------------------------------------------------------------------------ @@ -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(): @@ -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 +#------------------------------------------------------------------------------