Skip to content

Commit

Permalink
Merge pull request #117 from kbwbe/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
kbwbe authored Nov 11, 2018
2 parents 4cd459d + ac8d9fa commit 46d4039
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 172 deletions.
4 changes: 3 additions & 1 deletion a2p_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
BOM_SHEET_NAME,
BOM_SHEET_LABEL,
PARTINFORMATION_SHEET_NAME,
BOM_MAX_COLS,
BOM_MAX_LENGTH
)

Expand All @@ -59,6 +60,7 @@ def createPartList(
)
workingDir,basicFileName = os.path.split(fileNameInProject)
docReader1 = FCdocumentReader()

docReader1.openDocument(fileNameInProject)
for ob in docReader1.getA2pObjects():
#print(u'{}, Subassembly? = {}'.format(ob,ob.isSubassembly()))
Expand Down Expand Up @@ -122,7 +124,7 @@ def clearPartList(self):
alphabet_list = list(string.ascii_uppercase)
doc = FreeCAD.activeDocument()
ss = doc.getObject(BOM_SHEET_NAME)
for i in range(0,12): #12 Rows enought for a partlist
for i in range(0,BOM_MAX_COLS):
for k in range(0,BOM_MAX_LENGTH):
cellAdress = alphabet_list[i]+str(k+1)
ss.set(cellAdress,'')
Expand Down
15 changes: 4 additions & 11 deletions a2p_convertPart.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from PySide import QtGui, QtCore
import os, copy, time
import a2plib
from a2p_importpart import filterImpParts
from a2p_MuxAssembly import createTopoInfo
from a2p_viewProviderProxies import *
from a2p_versionmanagement import SubAssemblyWalk, A2P_VERSION
Expand All @@ -41,17 +40,11 @@ def execute(self, shape):
pass

def convertToImportedPart(doc, obj):
'''convertToImportedPart(document, documentObject) - changes a regular FreeCAD object into an A2plus
'''
convertToImportedPart(document, documentObject) - changes a regular FreeCAD object into an A2plus
importedPart, adds the importedPart to the document and removes the FreeCAD object from the
document. Returns None'''

# objExpand = filterImpParts(obj)
# if not objExpand:
# msg = obj.Name + " was not converted."
# FreeCADGui.Console.Message(msg)
# for oe in objExpand:

#partName = obj.Name
document. Returns None
'''
partName = a2plib.findUnusedObjectName( obj.Label, document=doc )
partLabel = a2plib.findUnusedObjectLabel( obj.Label, document=doc )
filename = "converted" #or none? if obj is already in this doc, we don't know it's original filename
Expand Down
5 changes: 5 additions & 0 deletions a2p_fcdocumentreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ def getA2pObjects(self):
for ob in self.objects:
if ob.propertyDict.get('a2p_Version',None) != None:
out.append(ob)
continue
elif ob.propertyDict.get('assembly2Version',None) != None: # for very old a2p projects...
out.append(ob)
continue

return out

def getSpreadsheetObjects(self):
Expand Down
204 changes: 89 additions & 115 deletions a2p_importpart.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,78 +94,6 @@ def len(self):

objectCache = ObjectCache()

def globalVisibility(doc, imp):
if not imp.InList:
return imp.ViewObject.Visibility
else:
for parent in imp.InList:
if not parent.ViewObject.Visibility:
return parent.ViewObject.Visibility
else:
return globalVisibility(doc, parent)

def getImpPartsFromDoc(doc, visibleOnly = True):
objsIn = doc.Objects
impPartsOut = list()
for obj in objsIn:
impPartList = filterImpParts(obj)
if (impPartList):
if (visibleOnly):
vizParts = list()
for imp in impPartList:
if imp.isDerivedFrom("PartDesign::Body"):
if hasattr(imp,'ViewObject') and imp.ViewObject.isVisible() and \
hasattr(imp.Tip,'ViewObject') and imp.Tip.ViewObject.isVisible():
gv = globalVisibility(doc, imp)
if gv:
vizParts.append(imp)
else:
if hasattr(imp,'ViewObject') and imp.ViewObject.isVisible():
gv = globalVisibility(doc, imp)
if gv:
vizParts.append(imp)
impPartsOut.extend(vizParts)
else:
impPartsOut.extend(impPartList)
return impPartsOut

def filterImpParts(obj):
impPartsOut = list()
if obj.isDerivedFrom("Sketcher::SketchObject"):
pass
elif obj.isDerivedFrom("PartDesign::Body"):
# we want bodies that are top level in the document or top level in a container(App::Part)
# we don't want bodies that are inside other bodies.
if ((not(obj.InList)) or \
((len(obj.InList) == 1) and (obj.InList[0].hasExtension("App::GroupExtension")))): #top of group
impPartsOut.append(obj)
elif obj.hasExtension("App::GroupExtension"): # App::Part container. GroupEx contents are already in list,
pass # don't need to find them
elif obj.isDerivedFrom("PartDesign::Feature"):
if not obj.getParentGeoFeatureGroup(): # this is v016 PD::F. 017+ would have PGFG = Body
if ((not obj.InList) or
((len(obj.InList) == 1) and (hasattr(obj.InList[0], "Group")))): # not part of any other object
if (
hasattr(obj,"ViewObject") and
obj.ViewObject.isVisible() and
hasattr(obj,"Shape") and
len(obj.Shape.Faces) > 0
):
impPartsOut.append(obj)
elif obj.isDerivedFrom("Part::Feature"):
if not(obj.InList):
impPartsOut.append(obj) # top levelwithin Document
elif (len(obj.InList) == 1) and (obj.InList[0].hasExtension("App::GroupExtension")):
obj.Placement = plmGlobal
impPartsOut.append(obj) # top level within Group
elif a2plib.isA2pPart(obj): # imported part
impPartsOut.append(obj)
else:
pass # more odd PF cases?? BaseFeature in body??
else:
pass # garbage objects - Origins, Axis, etc
return impPartsOut

def importPartFromFile(_doc, filename, importToCache=False):
doc = _doc
#-------------------------------------------
Expand Down Expand Up @@ -217,21 +145,6 @@ def importPartFromFile(_doc, filename, importToCache=False):
if all([ 'importPart' in obj.Content for obj in importableObjects]) == 1:
subAssemblyImport = True

'''
#-------------------------------------------
# Discover whether we are importing a subassembly or a single part
#-------------------------------------------
#if any([ 'importPart' in obj.Content for obj in importDoc.Objects]) and not len(visibleObjects) == 1:
subAssemblyImport = False
Msg("A2P importPartFromFile: importableObjects: {}\n".format(len(importableObjects)))
if len(importableObjects) == 1:
DebugMsg(A2P_DEBUG_3,"a2p importPartFromFile: first and only file: {}\n".format(importableObjects[0]))
else:
DebugMsg(A2P_DEBUG_3,"a2p importPartFromFile: importableObjects:\n{}\n".format(importableObjects))
if len(importableObjects) > 1:
subAssemblyImport = True
'''

#-------------------------------------------
# create new object
#-------------------------------------------
Expand Down Expand Up @@ -540,23 +453,45 @@ def duplicateImportedPart( part ):

class a2p_DuplicatePartCommand:
def Activated(self):
#====================================================
# Is there an open Doc ?
#====================================================
if FreeCAD.activeDocument() == None:
QtGui.QMessageBox.critical(
QtGui.QMessageBox.information(
QtGui.QApplication.activeWindow(),
"No active Document error",
"First please open an assembly file!"
u"No active Document error",
u"First please open an assembly file!"
)
return

#====================================================
# Is something been selected ?
#====================================================
selection = [s for s in FreeCADGui.Selection.getSelectionEx() if s.Document == FreeCAD.ActiveDocument ]
if len(selection) == 1:
PartMover( FreeCADGui.activeDocument().activeView(), duplicateImportedPart( selection[0].Object ) )
else:
QtGui.QMessageBox.critical(
if len(selection) != 1:
QtGui.QMessageBox.information(
QtGui.QApplication.activeWindow(),
"Selection error",
"Before duplicating, first please select a part!"
u"Selection error",
u"Before duplicating, first please select a part!"
)
return

#====================================================
# Is the selection an a2p part ?
#====================================================
obj = selection[0].Object
if not a2plib.isA2pPart(obj):
QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(),
u"Duplicate: Selection invalid!",
u"This object is no imported part!"
)
return

#====================================================
# Duplicate the part
#====================================================
PartMover( FreeCADGui.activeDocument().activeView(), duplicateImportedPart( selection[0].Object ) )


def GetResources(self):
return {
Expand All @@ -574,24 +509,42 @@ def GetResources(self):
class a2p_EditPartCommand:
def Activated(self):
doc = FreeCAD.activeDocument()
#====================================================
# Is there an open Doc ?
#====================================================
if doc == None:
QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(),
"No active document found!",
"Before editing a part, you have to open an assembly file."
u"No active document found!",
u"Before editing a part, you have to open an assembly file."
)
return

#====================================================
# Is something been selected ?
#====================================================
selection = [s for s in FreeCADGui.Selection.getSelection() if s.Document == FreeCAD.ActiveDocument ]
if not selection:
msg = \
'''
You must select a part to edit first.
'''
QtGui.QMessageBox.information(
QtGui.QApplication.activeWindow(),
"Selection Error",
msg
u"Selection Error",
u"You must select a part to edit first."
)
return

#====================================================
# Has the selected object an editable a2p file ?
#====================================================
obj = selection[0]
if not a2plib.isEditableA2pPart(obj):
QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(),
u"Edit: Selection invalid!",
u"This object is no imported part!"
)
return

#====================================================
# Does the file exist ?
#====================================================
obj = selection[0]
FreeCADGui.Selection.clearSelection() # very important! Avoid Editing the assembly the part was called from!
assemblyPath = os.path.normpath(os.path.split(doc.FileName)[0])
Expand All @@ -610,7 +563,10 @@ def Activated(self):
msg
)
return
#TODO: WF fails if "use folder" = false here

#====================================================
# Open the file for editing and switch the window
#====================================================
docs = []
for d in FreeCAD.listDocuments().values(): #dict_values not indexable, docs now is...
docs.append(d)
Expand All @@ -629,10 +585,6 @@ def Activated(self):
for s in sub:
mdi.setActiveSubWindow(s)
if FreeCAD.activeDocument().Name == name: break
# This does not work somehow...
# FreeCAD.setActiveDocument( name )
# FreeCAD.ActiveDocument=FreeCAD.getDocument( name )
# FreeCADGui.ActiveDocument=FreeCADGui.getDocument( name )


def GetResources(self):
Expand Down Expand Up @@ -690,19 +642,41 @@ def addSelection( self, docName, objName, sub, pnt ):

class a2p_MovePartCommand:
def Activated(self):
#====================================================
# Is there an open Doc ?
#====================================================
if FreeCAD.activeDocument() == None:
QtGui.QMessageBox.critical(
QtGui.QApplication.activeWindow(),
"No active Document error",
"First please open an assembly file!"
u"No active Document error",
u"First please open an assembly file!"
)
return


#====================================================
# Is something been selected ?
#====================================================
selection = [s for s in FreeCADGui.Selection.getSelectionEx() if s.Document == FreeCAD.ActiveDocument ]
if len(selection) == 1:
if len(selection) != 1:
QtGui.QMessageBox.information(
QtGui.QApplication.activeWindow(),
u"Selection error",
u"Before moving, first please select exact 1 part!"
)
return

#====================================================
# Move object, if possible
#====================================================
try:
PartMover( FreeCADGui.activeDocument().activeView(), selection[0].Object )
else:
PartMoverSelectionObserver()
except:
QtGui.QMessageBox.information(
QtGui.QApplication.activeWindow(),
u"Wrong selection",
u"Cannot move selected object!"
)


def GetResources(self):
return {
Expand Down
1 change: 1 addition & 0 deletions a2p_partlistglobals.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

BOM_SHEET_NAME = '_PARTSLIST_' #BOM = BillOfMaterials...
BOM_SHEET_LABEL = '#PARTSLIST#'
BOM_MAX_COLS = 10
BOM_MAX_LENGTH = 150


Expand Down
10 changes: 1 addition & 9 deletions a2p_rigid.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,9 @@
A2P_DEBUG_1,
A2P_DEBUG_2,
A2P_DEBUG_3,
)
import a2p_libDOF

from a2plib import (
PARTIAL_SOLVE_STAGE1,
PARTIAL_SOLVE_STAGE2,
PARTIAL_SOLVE_STAGE3,
PARTIAL_SOLVE_STAGE4,
PARTIAL_SOLVE_STAGE5,
PARTIAL_SOLVE_END
)
import a2p_libDOF

from a2p_libDOF import (
SystemOrigin,
Expand Down
Loading

0 comments on commit 46d4039

Please sign in to comment.