Skip to content

Commit

Permalink
pI: Add closeProject() for nonGUI mode
Browse files Browse the repository at this point in the history
  • Loading branch information
podestplatz committed Aug 6, 2019
1 parent f72fb9a commit 27ca9d9
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions bcfplugin/programmaticInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from bcfplugin.frontend.viewController import CamType
from bcfplugin import FREECAD, GUI

__all__ = [ "CamType", "deleteObject", "openProject",
__all__ = [ "CamType", "deleteObject", "openProject", "closeProject",
"getTopics", "getComments", "getViewpoints", "openIfcFile",
"getRelevantIfcFiles", "getAdditionalDocumentReferences",
"activateViewpoint", "addCurrentViewpoint",
Expand Down Expand Up @@ -118,6 +118,14 @@ def isProjectOpen():
return True


def saveProject(dstFile):

""" Save the current state of the working directory to `dstfile` """

bcfRootPath = reader.bcfDir
writer.zipToBcfFile(bcfRootPath, dstFile)


def openProject(bcfFile):

""" Reads in the given bcfFile and makes it available to the plugin.
Expand All @@ -142,6 +150,30 @@ def openProject(bcfFile):
return OperationResults.SUCCESS


def closeProject():

global curProject

if util.getDirtyBit():

answer = "x"
while answer not in "ny " and answer != "":
answer = input("Do you want to save your changes before exiting?"\
"([y]|n)")

if answer == "y" or answer == " " or answer == "":
currentDir = os.path.dirname(os.path.abspath(__file__))
print("Current directory: {}".format(currentDir))
file = input("File to save to: ")
if os.path.isabs(file):
saveProject(file)
else:
saveProject(os.path.join(currentDir, file))

del curProject
util.deleteTmp()


def _searchRealTopic(topic: Topic):

""" Searches `curProject` for `topic` and returns the result
Expand Down Expand Up @@ -369,14 +401,6 @@ def setModDateAuthor(element, author="", addUpdate=True):
writer.addProjectUpdate(curProject, element._modAuthor, oldDate)


def saveProject(dstFile):

""" Save the current state of the working directory to `dstfile` """

bcfRootPath = reader.bcfDir
writer.zipToBcfFile(bcfRootPath, dstFile)


def getProjectName():

""" Return the name of the open project """
Expand Down Expand Up @@ -1175,4 +1199,3 @@ def modifyElement(element, author=""):
projectBackup)



0 comments on commit 27ca9d9

Please sign in to comment.