# Path: importerUtils.py
# def logInfo(msg, *args):
# 	if (__prmPrefOW__.GetBool("checkLogging", False)): _log("logInfo",    Console.PrintMessage, msg, args)
# 
# def getIconPath(fileName):
# 	return os.path.join(os.path.dirname(__file__), "Resources", "icons", fileName)
# 
# def getTableValue(table, col, row):
# 	try:
# 		return table.get(getCellRef(col, row))
# 	except:
# 		return None
# 
# def setTableValue(table, col, row, val):
# 	if (type(val) == str):
# 		table.set(getCellRef(col, row), val)
# 	else:
# 		if ((sys.version_info.major <= 2) and (type(val) == unicode)):
# 			table.set(getCellRef(col, row), "%s" %(val.encode("utf8")))
# 		else:
# 			table.set(getCellRef(col, row), str(val))
# 
# def logInfo(msg, *args):
# 	if (__prmPrefOW__.GetBool("checkLogging", False)): _log("logInfo",    Console.PrintMessage, msg, args)
# 
# def logWarning(msg, *args):
# 	if (__prmPrefOW__.GetBool("checkWarning", False)): _log("logWarning", Console.PrintWarning, msg, args)
# 
# def logError(msg, *args):
# 	if (__prmPrefOW__.GetBool("checkError", True)):    _log("logError",   Console.PrintError,   msg, args)
# 
# def getCellRef(col, row):
# 	if (isString(col)):
# 		return u"%s%d" %(col, row)
# 	return u"%s%d" %(int2col(col), row)
# 
# def setTableValue(table, col, row, val):
# 	if (type(val) == str):
# 		table.set(getCellRef(col, row), val)
# 	else:
# 		if ((sys.version_info.major <= 2) and (type(val) == unicode)):
# 			table.set(getCellRef(col, row), "%s" %(val.encode("utf8")))
# 		else:
# 			table.set(getCellRef(col, row), str(val))
# 
# def calcAliasname(name):
# 	alias = name.replace(':', '_')
# 	if (IS_CELL_REF.search(name)):
# 		return '%s_' %(alias)
# 	# 45, 48..57, 65..90, 97..122
# 	result = ''
# 	for c in alias:
# 		i = ord(c)
# 		if (i == 45) or (i > 47 and i < 58) or (i > 64 and i < 91) or (i > 96 and i < 123):
# 			result += c
# 		else:
# 			result += '_'
# 	if (result[0] == '_'):
# 		return 'd' + result
# 	return result
# 
# Path: importerClasses.py
# class ParameterTableModel(TableModel):
# 	def __init__(self, parent, mylist, *args):
# 		TableModel.__init__(self, parent, mylist, ['Variant', 'Source', 'Property', 'Parameter', 'Value', 'Units'], *args)
# 	def flags(self, index):
# 		if (index.column() == 0):
# 			return Qt.ItemIsEnabled | Qt.ItemIsEditable | Qt.ItemIsUserCheckable
# 		if (index.column() in [1, 2, 5]): # make object's name and property and unit column read only!
# 			return Qt.ItemIsEnabled
# 		return Qt.ItemIsEnabled |Qt.ItemIsEditable
# 
# class VariantTableModel(TableModel):
# 	def __init__(self, parent, values, *args):
# 		TableModel.__init__(self, parent, values[1:], values[0], *args)
# 	def flags(self, index):
# 		return Qt.ItemIsEnabled | Qt.ItemIsEditable
# 
# Path: importerConstants.py
# DIR_X  = VEC(1, 0, 0)
# 
# DIR_Y  = VEC(0, 1, 0)
# 
# DIR_Z  = VEC(0, 0, 1)


import os, re, sys, Part, FreeCAD, FreeCADGui
from importerUtils   import logInfo, getIconPath, getTableValue, setTableValue, logInfo, logWarning, logError, getCellRef, setTableValue, calcAliasname
from FreeCAD         import Vector as VEC
from importerClasses import ParameterTableModel, VariantTableModel
from math            import degrees, radians, pi, sqrt, cos, sin, atan
from PySide.QtCore   import *
from PySide.QtGui    import *
from importerConstants import DIR_X, DIR_Y, DIR_Z
	def delPart(self):
		table = self.form.tableView
		model = table.model()
		index = table.currentIndex()
		if (index.isValid()):
			row   = index.row()
			ret   =  QMessageBox.question(self.form, "FreeCAD - remove part variant",
				   u"Do you really want to remove '%s'?" %(model.data(model.index(row, 0), Qt.DisplayRole)),
				   QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
			if (ret == QMessageBox.Yes):
				model.removeRow(row)
		FreeCAD.ActiveDocument.recompute()
		return

	def addParam(self):
		parameters = self.getParameters()
		(prmName, ok) = QInputDialog.getItem(None, u"FreeCAD - add iPart parameter", u"Name of the parameter:", parameters)
		if (ok):
			table = self.form.tableView
			model = table.model()
			cols  = model.columnCount(table)
			index = table.currentIndex()
			if (index.isValid()):
				col = index.column() + 1
			else:
				col = cols
			if (model.insertColumn(col)):
				model.setHeaderData(col, Qt.Horizontal, prmName, Qt.DisplayRole)
				FreeCAD.ActiveDocument.recompute()
			else:

# Path: importerUtils.py
# def logInfo(msg, *args):
# 	if (__prmPrefOW__.GetBool("checkLogging", False)): _log("logInfo",    Console.PrintMessage, msg, args)
# 
# def getIconPath(fileName):
# 	return os.path.join(os.path.dirname(__file__), "Resources", "icons", fileName)
# 
# def getTableValue(table, col, row):
# 	try:
# 		return table.get(getCellRef(col, row))
# 	except:
# 		return None
# 
# def setTableValue(table, col, row, val):
# 	if (type(val) == str):
# 		table.set(getCellRef(col, row), val)
# 	else:
# 		if ((sys.version_info.major <= 2) and (type(val) == unicode)):
# 			table.set(getCellRef(col, row), "%s" %(val.encode("utf8")))
# 		else:
# 			table.set(getCellRef(col, row), str(val))
# 
# def logInfo(msg, *args):
# 	if (__prmPrefOW__.GetBool("checkLogging", False)): _log("logInfo",    Console.PrintMessage, msg, args)
# 
# def logWarning(msg, *args):
# 	if (__prmPrefOW__.GetBool("checkWarning", False)): _log("logWarning", Console.PrintWarning, msg, args)
# 
# def logError(msg, *args):
# 	if (__prmPrefOW__.GetBool("checkError", True)):    _log("logError",   Console.PrintError,   msg, args)
# 
# def getCellRef(col, row):
# 	if (isString(col)):
# 		return u"%s%d" %(col, row)
# 	return u"%s%d" %(int2col(col), row)
# 
# def setTableValue(table, col, row, val):
# 	if (type(val) == str):
# 		table.set(getCellRef(col, row), val)
# 	else:
# 		if ((sys.version_info.major <= 2) and (type(val) == unicode)):
# 			table.set(getCellRef(col, row), "%s" %(val.encode("utf8")))
# 		else:
# 			table.set(getCellRef(col, row), str(val))
# 
# def calcAliasname(name):
# 	alias = name.replace(':', '_')
# 	if (IS_CELL_REF.search(name)):
# 		return '%s_' %(alias)
# 	# 45, 48..57, 65..90, 97..122
# 	result = ''
# 	for c in alias:
# 		i = ord(c)
# 		if (i == 45) or (i > 47 and i < 58) or (i > 64 and i < 91) or (i > 96 and i < 123):
# 			result += c
# 		else:
# 			result += '_'
# 	if (result[0] == '_'):
# 		return 'd' + result
# 	return result
# 
# Path: importerClasses.py
# class ParameterTableModel(TableModel):
# 	def __init__(self, parent, mylist, *args):
# 		TableModel.__init__(self, parent, mylist, ['Variant', 'Source', 'Property', 'Parameter', 'Value', 'Units'], *args)
# 	def flags(self, index):
# 		if (index.column() == 0):
# 			return Qt.ItemIsEnabled | Qt.ItemIsEditable | Qt.ItemIsUserCheckable
# 		if (index.column() in [1, 2, 5]): # make object's name and property and unit column read only!
# 			return Qt.ItemIsEnabled
# 		return Qt.ItemIsEnabled |Qt.ItemIsEditable
# 
# class VariantTableModel(TableModel):
# 	def __init__(self, parent, values, *args):
# 		TableModel.__init__(self, parent, values[1:], values[0], *args)
# 	def flags(self, index):
# 		return Qt.ItemIsEnabled | Qt.ItemIsEditable
# 
# Path: importerConstants.py
# DIR_X  = VEC(1, 0, 0)
# 
# DIR_Y  = VEC(0, 1, 0)
# 
# DIR_Z  = VEC(0, 0, 1)


# Path: InventorViewProviders.py
import os, re, sys, Part, FreeCAD, FreeCADGui
from importerUtils   import logInfo, getIconPath, getTableValue, setTableValue, logInfo, logWarning, logError, getCellRef, setTableValue, calcAliasname
from FreeCAD         import Vector as VEC
from importerClasses import ParameterTableModel, VariantTableModel
from math            import degrees, radians, pi, sqrt, cos, sin, atan
from PySide.QtCore   import *
from PySide.QtGui    import *
from importerConstants import DIR_X, DIR_Y, DIR_Z

	def delPart(self):
		table = self.form.tableView
		model = table.model()
		index = table.currentIndex()
		if (index.isValid()):
			row   = index.row()
			ret   =  QMessageBox.question(self.form, "FreeCAD - remove part variant",
				   u"Do you really want to remove '%s'?" %(model.data(model.index(row, 0), Qt.DisplayRole)),
				   QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
			if (ret == QMessageBox.Yes):
				model.removeRow(row)
		FreeCAD.ActiveDocument.recompute()
		return

	def addParam(self):
		parameters = self.getParameters()
		(prmName, ok) = QInputDialog.getItem(None, u"FreeCAD - add iPart parameter", u"Name of the parameter:", parameters)
		if (ok):
			table = self.form.tableView
			model = table.model()
			cols  = model.columnCount(table)
			index = table.currentIndex()
			if (index.isValid()):
				col = index.column() + 1
			else:
				col = cols
			if (model.insertColumn(col)):
				model.setHeaderData(col, Qt.Horizontal, prmName, Qt.DisplayRole)
				FreeCAD.ActiveDocument.recompute()
			else:

				logError("Failed to insert column %d", row)