Skip to content

Commit

Permalink
Merge pull request #286 from kbwbe/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
kbwbe authored Jun 8, 2019
2 parents 8265ab4 + 82e9f7a commit d372a9d
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 126 deletions.
2 changes: 1 addition & 1 deletion InitGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
__title__ = 'A2plus assembly Workbench - InitGui file'
__author__ = 'kbwbe'

A2P_VERSION = 'V0.4.23'
A2P_VERSION = 'V0.4.24'



Expand Down
2 changes: 1 addition & 1 deletion a2p_convertPart.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import a2plib
from a2p_MuxAssembly import createTopoInfo
from a2p_viewProviderProxies import *
from a2p_versionmanagement import SubAssemblyWalk, A2P_VERSION
from a2p_versionmanagement import A2P_VERSION
import a2p_solversystem
from a2plib import (
appVersionStr,
Expand Down
5 changes: 1 addition & 4 deletions a2p_importpart.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@
muxAssemblyWithTopoNames
)
from a2p_viewProviderProxies import *
from a2p_versionmanagement import (
SubAssemblyWalk,
A2P_VERSION
)
from a2p_versionmanagement import A2P_VERSION
import a2p_solversystem
from a2plib import (
appVersionStr,
Expand Down
121 changes: 1 addition & 120 deletions a2p_versionmanagement.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#***************************************************************************
#* *
#* Copyright (c) 2018 kbwbe *
#* Copyright (c) 2018,2019 kbwbe *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
Expand All @@ -20,124 +20,5 @@
#* *
#***************************************************************************

import FreeCAD, FreeCADGui, Part, Draft, math, MeshPart, Mesh, Drawing, time
import Spreadsheet, os
#from PyQt4 import QtGui,QtCore
from PySide import QtCore, QtGui
from FreeCAD import Base
from a2plib import *
App=FreeCAD
Gui=FreeCADGui

A2P_VERSION = 'V0.1'
#to be aligned with InitGui A2P Version

class SubAssemblyWalk():
'''
Class for walking through subassemblies,
creating missing properties,
checking for necessary update of importparts...
start it with method executeWalk(self)
'''

def __init__(self,startFile):
self.startFile = startFile
self.docsToBeClosed = []

def checkForSubAssembly(self,subFileName):
filename = findSourceFileInProject(subFileName) # path within subfile will be ignored..
if filename == None:
FreeCAD.Console.PrintMessage(
"SubassemblyCheck failed for {} ".format( subFileName )
)
return False

doc_already_open = filename in [ d.FileName for d in FreeCAD.listDocuments().values() ]
if doc_already_open:
doc = [ d for d in FreeCAD.listDocuments().values() if d.FileName == filename][0]
else:
doc = FreeCAD.openDocument(filename)

for obj in doc.Objects:
if hasattr(obj, 'sourceFile'):
if not doc_already_open:
FreeCAD.closeDocument(doc.Name)
return True

if not doc_already_open:
FreeCAD.closeDocument(doc.Name)
return False

def openSubAssembly(self,subFile): #recursive func!! This can consumpt the total memory of your computer
filename = findSourceFileInProject(subFile) # path within subfile will be ignored..
if filename == None:
FreeCAD.Console.PrintMessage( "Missing file {} ignored".format(subFile) )
return False

doc_already_open = filename in [ d.FileName for d in FreeCAD.listDocuments().values() ]
if doc_already_open:
doc = [ d for d in FreeCAD.listDocuments().values() if d.FileName == filename][0]
else:
doc = FreeCAD.openDocument(filename)

needUpdate = False

for obj in doc.Objects:
if hasattr(obj, 'sourceFile'):

# This Section: Add missing but necessary properties of this Version
if not hasattr( obj, 'a2p_Version'):
obj.addProperty("App::PropertyString", "a2p_Version","importPart").a2p_Version = 'V0.0'
obj.setEditorMode("a2p_Version",1)
needUpdate = True

if not hasattr( obj, 'muxInfo'):
obj.addProperty("App::PropertyStringList", "muxInfo","importPart").muxInfo = []
needUpdate = True

if not hasattr(obj, 'subassemblyImport'):
obj.addProperty("App::PropertyBool","subassemblyImport","importPart").subassemblyImport = False
obj.setEditorMode("subassemblyImport",1)
obj.subassemblyImport = self.checkForSubAssembly(obj.sourceFile)
needUpdate = True

if obj.subassemblyImport == True:
# This Section: Open subassemblies which this assembly depends on...
replacement = findSourceFileInProject(obj.sourceFile) # work in any case with files within projectFolder!
if replacement == None:
QtGui.QMessageBox.critical( QtGui.QApplication.activeWindow(),
"Source file not found",
"update of %s aborted!\nUnable to find %s" % (
obj.Name,
obj.sourceFile
)
)
else:
if obj.sourceFile != replacement:
obj.sourceFile = replacement # update Filepath, perhaps location changed due to new projectFile!
result = self.openSubAssembly(obj.sourceFile)
if result == True:
needUpdate = True

if obj.a2p_Version != A2P_VERSION:
needUpdate = True

if os.path.getmtime( obj.sourceFile ) > obj.timeLastImport:
needUpdate = True

if not needUpdate:
if doc not in self.docsToBeClosed:
self.docsToBeClosed.append(doc)

return needUpdate




def executeWalk(self):
self.docsToBeClosed = []
self.openSubAssembly(self.startFile)
for doc in self.docsToBeClosed:
if doc.FileName != self.startFile:
FreeCAD.closeDocument(doc.Name)

0 comments on commit d372a9d

Please sign in to comment.