Extended macro with rockn's work and allowed a Private folder that wont be pushed

This commit is contained in:
Yorik van Havre 2015-11-25 10:46:56 -02:00
parent acb2da12b6
commit 8f864e4961
2 changed files with 104 additions and 26 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
*.pyc
*.fcstd1
*.FcStd1
Private

View file

@ -3,7 +3,7 @@
#***************************************************************************
#* *
#* Copyright (c) 2013 Yorik van Havre <yorik@uncreated.net> *
#* Copyright (c) 2013 Yorik van Havre <yorik@uncreated.net> *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
@ -33,14 +33,12 @@ FreeCAD Parts Library import macro
INSTALLATION
This script is made to be used as a FreeCAD macro, and to be placed
inside your macros folder (default is $HOME/.FreeCAD on mac/linux,
inside your macros folder (default is $HOME/.FreeCAD on mac/linux,
C:/Users/youruser/Application Data/FreeCAD on windows).
You must also edit this file and change the configuration line below
to reflect the location of your FreeCAD-library folder.
After it is installed on the above location, it will be available
in the macros menu.
in the macros menu. On first run, it will ask you for the location
of your library.
USAGE
@ -48,23 +46,21 @@ This macro adds a browser window to the FreeCAD interface, from
which you can browse and install items from the library.
'''
# CONFIGURATION - EDIT THE FOLLOWING LINE TO MATCH YOUR LIBRARY PATH
LIBRARYPATH = "/home/yorik/Sources/FreeCAD-library"
# END CONFIGURATION - THAT'S DONE, NO NEED TO EDIT ANYTHING MORE
import FreeCAD, FreeCADGui, Part, zipfile, tempfile, Mesh, os, subprocess
from PySide import QtGui, QtCore
s=FreeCAD.ParamGet('User parameter:Plugins/partlib').GetString('destination')
print s
param = FreeCAD.ParamGet('User parameter:Plugins/partlib')
s=param.GetString('destination')
print('User parameter:Plugins/partlib : destination : ',s)
if s<>'':
LIBRARYPATH = s
LIBRARYPATH = s
else:
pass
import FreeCAD, FreeCADGui, Part, zipfile, tempfile
from PySide import QtGui, QtCore
folderDialog = QtGui.QFileDialog.getExistingDirectory(None,u"Choose folder library")
param.SetString('destination',folderDialog)
s=param.GetString('destination')
LIBRARYPATH = s
global ExpFileSystemModel
class ExpFileSystemModel(QtGui.QFileSystemModel):
@ -93,8 +89,6 @@ class ExpDockWidget(QtGui.QDockWidget):
self.dirmodel.setNameFilters(["*.fcstd","*.FcStd","*.FCSTD","*.stp","*.STP","*.step","*.STEP", "*.brp", "*.BRP", "*.brep", "*.BREP"])
self.dirmodel.setNameFilterDisables(0)
container = QtGui.QWidget()
layout = QtGui.QVBoxLayout(container)
folder = QtGui.QTreeView()
folder.setModel(self.dirmodel)
folder.clicked[QtCore.QModelIndex].connect(self.clicked)
@ -105,13 +99,41 @@ class ExpDockWidget(QtGui.QDockWidget):
folder.hideColumn(2)
folder.hideColumn(3)
folder.setRootIndex(self.dirmodel.index(LIBRARYPATH))
layout.addWidget(folder)
self.preview = QtGui.QLabel()
self.preview.setFixedHeight(128)
layout.addWidget(self.preview)
layout.setAlignment(self.preview, QtCore.Qt.AlignHCenter)
formatLabel = QtGui.QLabel("Add to library")
savebutton = QtGui.QPushButton("Save")
icon = QtGui.QIcon.fromTheme("document-save")
savebutton.setIcon(icon)
savebutton.clicked.connect(self.addtolibrary)
pushbutton = QtGui.QPushButton("Push")
icon = QtGui.QIcon.fromTheme("document-export")
pushbutton.setIcon(icon)
pushbutton.clicked.connect(self.pushlibrary)
fcstdCB = QtGui.QCheckBox('FCStd')
fcstdCB.setCheckState(QtCore.Qt.Checked)
fcstdCB.setEnabled(False)
self.stepCB = QtGui.QCheckBox('STEP')
self.stepCB.setCheckState(QtCore.Qt.Checked)
self.stlCB = QtGui.QCheckBox('STL')
self.stlCB.setCheckState(QtCore.Qt.Checked)
container = QtGui.QWidget()
grid = QtGui.QGridLayout()
grid.setSpacing(10)
grid.addWidget(folder,0,0,1,3)
grid.addWidget(self.preview,1,0,5,1)
grid.addWidget(formatLabel,1,1,1,2)
grid.addWidget(fcstdCB,2,1,1,2)
grid.addWidget(self.stepCB,3,1,1,2)
grid.addWidget(self.stlCB,4,1,1,2)
grid.addWidget(savebutton,5,1,1,1)
grid.addWidget(pushbutton,5,2,1,1)
container.setLayout(grid)
self.setWidget(container)
def clicked(self, index):
path = self.dirmodel.filePath(index)
if path.lower().endswith(".fcstd"):
@ -137,6 +159,63 @@ class ExpDockWidget(QtGui.QDockWidget):
Part.show(Part.read(path))
elif path.lower().endswith(".fcstd"):
FreeCADGui.ActiveDocument.mergeProject(path)
FreeCADGui.SendMsgToActiveView("ViewFit")
def addtolibrary(self):
fileDialog = QtGui.QFileDialog.getSaveFileName(None,u"Choose category and set a filename without extension", LIBRARYPATH)
if fileDialog != '':
#filename = fileDialog[0].split("/")[-1]
#if filename.split(".")[-1].lowercase == "fcstd" or "stl
FCfilename = fileDialog[0] + ".fcstd"
FreeCAD.ActiveDocument.saveCopy(FCfilename)
if self.stepCB.isChecked() or self.stlCB.isChecked():
toexport = []
objs = FreeCAD.ActiveDocument.Objects
for obj in objs :
if obj.ViewObject.Visibility == True :
toexport.append(obj)
if self.stepCB.isChecked() :
STEPfilename = fileDialog[0] + ".step"
Part.export(toexport,STEPfilename)
if self.stlCB.isChecked() :
STLfilename = fileDialog[0] + ".stl"
Mesh.export(toexport,STLfilename)
def pushlibrary(self):
try:
import git
except:
FreeCAD.Console.PrintError("The Python Git module was not found. Please install the python-git package.\n")
return
try:
repo = git.Repo(LIBRARYPATH)
except:
FreeCAD.Console.PrintError("Your library is not a valid Git repository. Please fork/clone it first.\n")
return
pushOK = True
if not repo.remotes:
FreeCAD.Console.PrintWarning("Arch","Warning: no remote repository set. Unable to push")
pushOK = False
modified_files = repo.git.diff("--name-only").split()
untracked_files = repo.git.ls_files("--other","--exclude-standard").split()
import ArchServer
d = ArchServer._ArchGitDialog()
if not pushOK:
d.checkBox.setChecked(False)
d.checkBox.setEnabled(False)
d.label.setText(str(len(modified_files)+len(untracked_files))+" new and modified file(s)")
d.lineEdit.setText("Changed " + str(modified_files))
d.checkBox.hide()
d.radioButton.hide()
d.radioButton_2.hide()
r = d.exec_()
if r:
for o in modified_files + untracked_files:
repo.git.add(o)
repo.git.commit(m=d.lineEdit.text())
if d.checkBox.isChecked():
repo.git.push()
if QtCore.QDir(LIBRARYPATH).exists():
m = FreeCADGui.getMainWindow()
@ -151,5 +230,3 @@ if QtCore.QDir(LIBRARYPATH).exists():
else:
print "Library path ", LIBRARYPATH, "not found."
print "Please set the correct path to your Parts library in the macro script"