From 5bd5f3a9637c09a2537b5563c244c5db87b8a14a Mon Sep 17 00:00:00 2001 From: luz paz Date: Fri, 27 Nov 2020 11:09:50 -0500 Subject: [PATCH] Spreadsheet: Fix header uniformity + trailing whitespace [skip ci] --- src/Mod/Spreadsheet/App/PreCompiled.cpp | 2 +- src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp | 2 +- src/Mod/Spreadsheet/Gui/Command.cpp | 57 ++++---- src/Mod/Spreadsheet/Gui/LineEdit.cpp | 2 +- src/Mod/Spreadsheet/Gui/LineEdit.h | 22 +++ src/Mod/Spreadsheet/Gui/PreCompiled.cpp | 4 +- src/Mod/Spreadsheet/Gui/PreCompiled.h | 4 +- src/Mod/Spreadsheet/Gui/PropertiesDialog.cpp | 4 +- src/Mod/Spreadsheet/Gui/SheetModel.cpp | 10 +- src/Mod/Spreadsheet/Init.py | 8 +- src/Mod/Spreadsheet/InitGui.py | 16 +-- src/Mod/Spreadsheet/TestSpreadsheet.py | 35 +++-- src/Mod/Spreadsheet/importXLSX.py | 125 +++++++++--------- src/Mod/Spreadsheet/spreadsheet.dox | 7 +- 14 files changed, 172 insertions(+), 126 deletions(-) diff --git a/src/Mod/Spreadsheet/App/PreCompiled.cpp b/src/Mod/Spreadsheet/App/PreCompiled.cpp index 3e85848b9a..7b200a1bf2 100644 --- a/src/Mod/Spreadsheet/App/PreCompiled.cpp +++ b/src/Mod/Spreadsheet/App/PreCompiled.cpp @@ -21,4 +21,4 @@ ***************************************************************************/ -#include "PreCompiled.h" +#include "PreCompiled.h" diff --git a/src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp b/src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp index 35c750d5dc..a8f0736864 100644 --- a/src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp +++ b/src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp @@ -1,6 +1,6 @@ /*************************************************************************** - * Copyright (c) 2015 Eivind Kvedalen (eivind@kvedalen.name) * * Copyright (c) 2006 Werner Mayer * + * Copyright (c) 2015 Eivind Kvedalen * * * * This file is part of the FreeCAD CAx development system. * * * diff --git a/src/Mod/Spreadsheet/Gui/Command.cpp b/src/Mod/Spreadsheet/Gui/Command.cpp index 7c0036cdba..0e7b62ada1 100644 --- a/src/Mod/Spreadsheet/Gui/Command.cpp +++ b/src/Mod/Spreadsheet/Gui/Command.cpp @@ -1,12 +1,21 @@ /*************************************************************************** + * Copyright (c) 2002 Jürgen Riegel * + * Copyright (c) 2015 Eivind Kvedalen * * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Library General Public License as * - * published by the Free Software Foundation; either version 2 of the * - * License, or (at your option) any later version. * - * for detail see the LICENCE text file. * - * Jürgen Riegel 2002 * - * Eivind Kvedalen 2015 * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ @@ -43,14 +52,14 @@ #include "ViewProviderSpreadsheet.h" #include "PropertiesDialog.h" -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ using namespace SpreadsheetGui; using namespace Spreadsheet; using namespace Base; using namespace App; -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ DEF_STD_CMD_A(CmdSpreadsheetMergeCells) @@ -103,7 +112,7 @@ bool CmdSpreadsheetMergeCells::isActive() return false; } -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ DEF_STD_CMD_A(CmdSpreadsheetSplitCell) @@ -159,7 +168,7 @@ bool CmdSpreadsheetSplitCell::isActive() return false; } -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ DEF_STD_CMD_A(CmdSpreadsheetImport) @@ -199,7 +208,7 @@ bool CmdSpreadsheetImport::isActive() return getActiveGuiDocument() ? true : false; } -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ DEF_STD_CMD_A(CmdSpreadsheetExport) @@ -248,7 +257,7 @@ bool CmdSpreadsheetExport::isActive() return false; } -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ DEF_STD_CMD_A(CmdSpreadsheetAlignLeft) @@ -300,7 +309,7 @@ bool CmdSpreadsheetAlignLeft::isActive() return false; } -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ DEF_STD_CMD_A(CmdSpreadsheetAlignCenter) @@ -352,7 +361,7 @@ bool CmdSpreadsheetAlignCenter::isActive() return false; } -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ DEF_STD_CMD_A(CmdSpreadsheetAlignRight) @@ -404,7 +413,7 @@ bool CmdSpreadsheetAlignRight::isActive() return false; } -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ DEF_STD_CMD_A(CmdSpreadsheetAlignTop) @@ -456,7 +465,7 @@ bool CmdSpreadsheetAlignTop::isActive() return false; } -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ DEF_STD_CMD_A(CmdSpreadsheetAlignBottom) @@ -508,7 +517,7 @@ bool CmdSpreadsheetAlignBottom::isActive() return false; } -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ DEF_STD_CMD_A(CmdSpreadsheetAlignVCenter) @@ -560,7 +569,7 @@ bool CmdSpreadsheetAlignVCenter::isActive() return false; } -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ DEF_STD_CMD_A(CmdSpreadsheetStyleBold) @@ -634,7 +643,7 @@ bool CmdSpreadsheetStyleBold::isActive() return false; } -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ DEF_STD_CMD_A(CmdSpreadsheetStyleItalic) @@ -708,7 +717,7 @@ bool CmdSpreadsheetStyleItalic::isActive() return false; } -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ DEF_STD_CMD_A(CmdSpreadsheetStyleUnderline) @@ -781,7 +790,7 @@ bool CmdSpreadsheetStyleUnderline::isActive() return false; } -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ DEF_STD_CMD_A(CmdSpreadsheetSetAlias) @@ -845,7 +854,7 @@ bool CmdSpreadsheetSetAlias::isActive() return false; } -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ DEF_STD_CMD_A(CmdCreateSpreadsheet) @@ -878,7 +887,7 @@ bool CmdCreateSpreadsheet::isActive() return App::GetApplication().getActiveDocument(); } -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void CreateSpreadsheetCommands(void) { diff --git a/src/Mod/Spreadsheet/Gui/LineEdit.cpp b/src/Mod/Spreadsheet/Gui/LineEdit.cpp index bd171f84a1..8b9380d7c8 100644 --- a/src/Mod/Spreadsheet/Gui/LineEdit.cpp +++ b/src/Mod/Spreadsheet/Gui/LineEdit.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (c) Eivind Kvedalen (eivind@kvedalen.name) 2015 * + * Copyright (c) 2015 Eivind Kvedalen * * * * This file is part of the FreeCAD CAx development system. * * * diff --git a/src/Mod/Spreadsheet/Gui/LineEdit.h b/src/Mod/Spreadsheet/Gui/LineEdit.h index f32d6128d3..fa4e85185f 100644 --- a/src/Mod/Spreadsheet/Gui/LineEdit.h +++ b/src/Mod/Spreadsheet/Gui/LineEdit.h @@ -1,3 +1,25 @@ +/*************************************************************************** + * Copyright (c) 2015 Eivind Kvedalen * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + #ifndef LINEEDIT_H #define LINEEDIT_H diff --git a/src/Mod/Spreadsheet/Gui/PreCompiled.cpp b/src/Mod/Spreadsheet/Gui/PreCompiled.cpp index 93ebe29987..7b200a1bf2 100644 --- a/src/Mod/Spreadsheet/Gui/PreCompiled.cpp +++ b/src/Mod/Spreadsheet/Gui/PreCompiled.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2002 * + * Copyright (c) 2002 Jürgen Riegel * * * * This file is part of the FreeCAD CAx development system. * * * @@ -21,4 +21,4 @@ ***************************************************************************/ -#include "PreCompiled.h" +#include "PreCompiled.h" diff --git a/src/Mod/Spreadsheet/Gui/PreCompiled.h b/src/Mod/Spreadsheet/Gui/PreCompiled.h index 0abb83b767..6e3d669d22 100644 --- a/src/Mod/Spreadsheet/Gui/PreCompiled.h +++ b/src/Mod/Spreadsheet/Gui/PreCompiled.h @@ -1,6 +1,6 @@ /*************************************************************************** - * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2002 * - * Copyright (c) Eivind Kvedalen (eivind@kvedalen.name) 2015 * + * Copyright (c) 2002 Jürgen Riegel * + * Copyright (c) 2015 Eivind Kvedalen * * * * This file is part of the FreeCAD CAx development system. * * * diff --git a/src/Mod/Spreadsheet/Gui/PropertiesDialog.cpp b/src/Mod/Spreadsheet/Gui/PropertiesDialog.cpp index abcb214a05..a34b3c5552 100644 --- a/src/Mod/Spreadsheet/Gui/PropertiesDialog.cpp +++ b/src/Mod/Spreadsheet/Gui/PropertiesDialog.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (c) Eivind Kvedalen (eivind@kvedalen.name) 2015 * + * Copyright (c) 2015 Eivind Kvedalen * * * * This file is part of the FreeCAD CAx development system. * * * @@ -262,7 +262,7 @@ void PropertiesDialog::apply() std::string escapedstr = Base::Tools::escapedUnicodeFromUtf8(displayUnit.stringRep.c_str()); Gui::cmdAppObjectArgs(sheet, "setDisplayUnit('%s', '%s')", i->rangeString().c_str(), escapedstr.c_str()); - changes = true; + changes = true; } if (ranges.size() == 1 && ranges[0].size() == 1 && orgAlias != alias) { Gui::cmdAppObjectArgs(sheet, "setAlias('%s', '%s')", diff --git a/src/Mod/Spreadsheet/Gui/SheetModel.cpp b/src/Mod/Spreadsheet/Gui/SheetModel.cpp index 3e194258b3..f9a6b51521 100644 --- a/src/Mod/Spreadsheet/Gui/SheetModel.cpp +++ b/src/Mod/Spreadsheet/Gui/SheetModel.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (c) Eivind Kvedalen (eivind@kvedalen.name) 2015 * + * Copyright (c) 2015 Eivind Kvedalen * * * * This file is part of the FreeCAD CAx development system. * * * @@ -391,8 +391,8 @@ QVariant SheetModel::data(const QModelIndex &index, int role) const return QVariant(); } } - else if (prop->isDerivedFrom(App::PropertyFloat::getClassTypeId()) - || prop->isDerivedFrom(App::PropertyInteger::getClassTypeId())) + else if (prop->isDerivedFrom(App::PropertyFloat::getClassTypeId()) + || prop->isDerivedFrom(App::PropertyInteger::getClassTypeId())) { /* Number */ double d; @@ -454,7 +454,7 @@ QVariant SheetModel::data(const QModelIndex &index, int role) const if (cell->getForeground(color)) return QVariant::fromValue(QColor(255.0 * color.r, 255.0 * color.g, 255.0 * color.b, 255.0 * color.a)); - else + else return QVariant(QColor(textFgColor)); } case Qt::TextAlignmentRole: { @@ -537,7 +537,7 @@ bool SheetModel::setData(const QModelIndex & index, const QVariant & value, int std::string strAddress = address.toString(); str.replace(QString::fromUtf8("\\"), QString::fromUtf8("\\\\")); str.replace(QString::fromUtf8("'"), QString::fromUtf8("\\'")); - FCMD_OBJ_CMD(sheet,"set('" << strAddress << "','" << + FCMD_OBJ_CMD(sheet,"set('" << strAddress << "','" << str.toUtf8().constData() << "')"); #else sheet->setContent(address, str.toUtf8().constData()); diff --git a/src/Mod/Spreadsheet/Init.py b/src/Mod/Spreadsheet/Init.py index 7f5b581893..5654dca637 100644 --- a/src/Mod/Spreadsheet/Init.py +++ b/src/Mod/Spreadsheet/Init.py @@ -1,8 +1,5 @@ -# FreeCAD init script of the Spreadsheet module -# (c) 2001 Juergen Riegel - #*************************************************************************** -#* Copyright (c) 2002 Juergen Riegel * +#* Copyright (c) 2001,2002 Juergen Riegel * #* Copyright (c) 2013 Yorik van Havre * #* Copyright (c) 2013 Eivind Kvedalen * #* * @@ -26,6 +23,7 @@ #* * #***************************************************************************/ +# FreeCAD init script of the Spreadsheet module # Get the Parameter Group of this module @@ -37,7 +35,7 @@ ParGrp.SetString("WorkBenchName", "Spreadsheet") ParGrp.SetString("WorkBenchModule", "SpreadsheetWorkbench.py") # add Import/Export types -App.addImportType("Excel spreadsheet (*.xlsx)","importXLSX") +App.addImportType("Excel spreadsheet (*.xlsx)","importXLSX") App.__unit_test__ += [ "TestSpreadsheet" ] diff --git a/src/Mod/Spreadsheet/InitGui.py b/src/Mod/Spreadsheet/InitGui.py index ddc4630201..dda6423eb7 100644 --- a/src/Mod/Spreadsheet/InitGui.py +++ b/src/Mod/Spreadsheet/InitGui.py @@ -1,12 +1,5 @@ -# Spreadsheet gui init module -# (c) 2003 Juergen Riegel -# -# Gathering all the information to start FreeCAD -# This is the second one of three init scripts, the third one -# runs when the gui is up - #*************************************************************************** -#* Copyright (c) 2002 Juergen Riegel * +#* Copyright (c) 2002,2003 Juergen Riegel * #* Copyright (c) 2013 Eivind Kvedalen * #* * #* This file is part of the FreeCAD CAx development system. * @@ -26,9 +19,14 @@ #* License along with FreeCAD; if not, write to the Free Software * #* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * #* USA * -#* * #***************************************************************************/ +# Spreadsheet gui init module +# +# Gathering all the information to start FreeCAD +# This is the second one of three init scripts, the third one +# runs when the gui is up + class SpreadsheetWorkbench ( Workbench ): "Spreadsheet workbench object" diff --git a/src/Mod/Spreadsheet/TestSpreadsheet.py b/src/Mod/Spreadsheet/TestSpreadsheet.py index 0b6cee4efd..936a853f5a 100644 --- a/src/Mod/Spreadsheet/TestSpreadsheet.py +++ b/src/Mod/Spreadsheet/TestSpreadsheet.py @@ -1,6 +1,23 @@ -# (c) 2016 Werner Mayer -# (c) 2016 Eivind Kvedalen -# LGPL +#*************************************************************************** +#* Copyright (c) 2016 Werner Mayer * +#* Copyright (c) 2016 Eivind Kvedalen * +#* * +#* This program is free software; you can redistribute it and/or modify * +#* it under the terms of the GNU General Public License (GPL) * +#* as published by the Free Software Foundation; either version 2 of * +#* the License, or (at your option) any later version. * +#* for detail see the LICENCE text file. * +#* * +#* FreeCAD is distributed in the hope that it will be useful, * +#* but WITHOUT ANY WARRANTY; without even the implied warranty of * +#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +#* GNU Library General Public License for more details. * +#* * +#* You should have received a copy of the GNU Library General Public * +#* License along with FreeCAD; if not, write to the Free Software * +#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +#* USA * +#***************************************************************************/ import os import sys @@ -350,7 +367,7 @@ class SpreadsheetCases(unittest.TestCase): self.assertTrue(sheet.C27.startswith(u'ERR: Units must be equal')) self.assertMostlyEqual(sheet.D27, Units.Quantity("3 mm")) FreeCAD.closeDocument(doc.Name) - + def testRelationalOperators(self): """ Test relational operators """ sheet = self.doc.addObject('Spreadsheet::Sheet','Spreadsheet') @@ -650,7 +667,7 @@ class SpreadsheetCases(unittest.TestCase): self.assertEqual(sheet.A16, 1) self.assertEqual(sheet.A17, 0.5) self.assertEqual(sheet.A18, 0.5) - + def testRemoveRows(self): """ Removing rows -- check renaming of internal cells """ sheet = self.doc.addObject('Spreadsheet::Sheet','Spreadsheet') @@ -768,7 +785,7 @@ class SpreadsheetCases(unittest.TestCase): """ Object name is equal to property name (bug #2389) """ if not FreeCAD.GuiUp: return - + import FreeCADGui o = self.doc.addObject("Part::FeaturePython","Placement") FreeCADGui.Selection.addSelection(o) @@ -783,7 +800,7 @@ class SpreadsheetCases(unittest.TestCase): self.doc.recompute() sketch=self.doc.addObject('Sketcher::SketchObject','Sketch') sketch.addGeometry(Part.LineSegment(v(0,0,0),v(10,10,0)),False) - sketch.addConstraint(Sketcher.Constraint('Distance',0,65.285388)) + sketch.addConstraint(Sketcher.Constraint('Distance',0,65.285388)) sketch.setExpression('Constraints[0]', 'InvoluteGear.NumberOfTeeth') self.doc.recompute() self.assertIn('Up-to-date',sketch.State) @@ -798,7 +815,7 @@ class SpreadsheetCases(unittest.TestCase): self.doc.recompute() index=sketch.addGeometry(Part.LineSegment(v(0,0,0),v(10,10,0)),False) - sketch.addConstraint(Sketcher.Constraint('Distance',index,14.0)) + sketch.addConstraint(Sketcher.Constraint('Distance',index,14.0)) self.doc.recompute() sketch.setExpression('Constraints[0]', u'<>.Length') self.doc.recompute() @@ -838,7 +855,7 @@ class SpreadsheetCases(unittest.TestCase): def testMatrix(self): ''' Test Matrix/Vector/Placement/Rotation operations''' - + def plm_equal(plm1, plm2): from math import sqrt qpair = zip(plm1.Rotation.Q, plm2.Rotation.Q) diff --git a/src/Mod/Spreadsheet/importXLSX.py b/src/Mod/Spreadsheet/importXLSX.py index c96e1590f6..ba5a8db302 100644 --- a/src/Mod/Spreadsheet/importXLSX.py +++ b/src/Mod/Spreadsheet/importXLSX.py @@ -1,31 +1,30 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# -# importXLSX.py -# -# This library imports an Excel-XLSX-file into FreeCAD. -# -# Copyright (C) 2016 Ulrich Brammer -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, -# MA 02110-1301 USA +#*************************************************************************** +#* Copyright (c) 2016 Ulrich Brammer * +#* * +#* This program is free software; you can redistribute it and/or modify * +#* it under the terms of the GNU General Public License (GPL) * +#* as published by the Free Software Foundation; either version 2 of * +#* the License, or (at your option) any later version. * +#* for detail see the LICENCE text file. * +#* * +#* FreeCAD is distributed in the hope that it will be useful, * +#* but WITHOUT ANY WARRANTY; without even the implied warranty of * +#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +#* GNU Library General Public License for more details. * +#* * +#* You should have received a copy of the GNU Library General Public * +#* License along with FreeCAD; if not, write to the Free Software * +#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +#* USA * +#***************************************************************************/ + from __future__ import print_function -__title__="FreeCAD Spreadsheet Workbench - XLSX importer" -__author__ = "Ulrich Brammer " -__url__ = ["http://www.freecadweb.org"] +__title__ = "FreeCAD Spreadsheet Workbench - XLSX importer" +__author__ = "Ulrich Brammer " +__url__ = ["https://www.freecadweb.org"] ''' This library imports an Excel-XLSX-file into FreeCAD. @@ -94,10 +93,10 @@ branchLower ={ '=':None } -branchHigher = {'=':None} +branchHigher = {'=':None} -# Needed to get a reference from a string to a dict +# Needed to get a reference from a string to a dict treeDict = { 'branchLower':branchLower, 'branchHigher':branchHigher @@ -108,7 +107,7 @@ treeDict = { # levelchange: -1: tree down, 0, +1: tree up # replacement token # function-state: needed to do something special in the parser -# 0 = normal, 1 = the pi-case, 2 = angle-function, +# 0 = normal, 1 = the pi-case, 2 = angle-function, # 3 = IF-function, 4 = IF-truecase, 5 IF-falsecase @@ -153,13 +152,13 @@ tokenDic = { 'MIN' :( 0, 'min', 0), 'STDEVA':( 0, 'stddev',0), 'SUM' :( 0, 'sum', 0), - 'PI' :( 0, 'pi', 1) + 'PI' :( 0, 'pi', 1) } class exprNode(object): ''' This defines a tree class for expression parsing. - A tree is built, to step down into the levels of the expression.''' + A tree is built, to step down into the levels of the expression.''' def __init__(self, parent, state, actIndex): self.state = state #see comment: State used for Angle-functions and IF-function self.parent = parent # Parent tree node @@ -217,15 +216,15 @@ class FormulaTranslator(object): tokenComplete = True self.tokenList.append(theTok) self.getNextToken(theExpr) - - + + def isKey(self, theExpr): #print('look up: ', theExpr) keyToken = False lenExpr = len(theExpr) if theExpr[0] in sepToken: branch = sepToken[theExpr[0]] - + if branch is None: keyToken = True else: @@ -240,8 +239,8 @@ class FormulaTranslator(object): else: keyToken = True return keyToken - - + + def parseExpr(self, treeNode): token = self.tokenList[treeNode.lIndex] @@ -253,30 +252,30 @@ class FormulaTranslator(object): newToken = token funcState = 0 #print('treeNode.state: ', treeNode.state, ' my.index: ', treeNode.lIndex-1, ' ', token, ' fState: ', funcState) - + if token == ',': if (treeNode.state == 4): newToken = ':' - treeNode.state = 6 + treeNode.state = 6 if (treeNode.state == 3): newToken = '?' treeNode.state = 4 - + if funcState == 3: funcState = 0 newNode = exprNode(treeNode, 3, treeNode.lIndex) - self.parseIF(newNode) + self.parseIF(newNode) else: treeNode.result = treeNode.result + newToken - + if funcState == 2: funcState = 0 newNode = exprNode(treeNode, 2, treeNode.lIndex) - self.parseAngle(newNode) + self.parseAngle(newNode) treeNode.result = treeNode.result + ')' - elif funcState == 1: + elif funcState == 1: treeNode.lIndex += 2 # do skip the 2 parentheses of the PI() - + if lChange == -1: #print 'state: ', treeNode.state, 'parent.result: ', treeNode.parent.result, ' mine: ', treeNode.result treeNode.parent.result = treeNode.parent.result + treeNode.result @@ -286,12 +285,12 @@ class FormulaTranslator(object): #print(' Look up more token above') if treeNode.lIndex < len(self.tokenList): self.parseExpr(treeNode.parent) - + elif lChange == 1: #print('Go one level down') newNode = exprNode(treeNode, 1, treeNode.lIndex) - self.parseExpr(newNode) - treeNode.lIndex = newNode.lIndex + self.parseExpr(newNode) + treeNode.lIndex = newNode.lIndex else: if treeNode.lIndex < len(self.tokenList): #print('parse to the end') @@ -303,7 +302,7 @@ class FormulaTranslator(object): #print('IF state: ', treeNode.state) treeNode.result = treeNode.result + '(' treeNode.lIndex += 1 - self.parseExpr(treeNode) + self.parseExpr(treeNode) #print('IF result: ', treeNode.result) return @@ -311,7 +310,7 @@ class FormulaTranslator(object): #print('Angle state: ', treeNode.state) treeNode.result = treeNode.result + '(1rad*(' treeNode.lIndex += 1 - self.parseExpr(treeNode) + self.parseExpr(treeNode) #print('angle result: ', treeNode.result) @@ -331,7 +330,7 @@ def handleWorkSheet(theDom, actSheet, strList): rows = theDom.getElementsByTagName("row") for row in rows: handleCells(row.getElementsByTagName("c"), actSheet, strList) - + def handleCells(cellList, actCellSheet, sList): for cell in cellList: @@ -346,14 +345,14 @@ def handleCells(cellList, actCellSheet, sList): cellType = 'n' # FIXME: some cells don't have t and s attributes #print("reference: ", ref, ' Cell type: ', cellType) - + if cellType == 'inlineStr': iStringList = cell.getElementsByTagName("is") #print('iString: ', iStringList) for stringEle in iStringList: tElement = stringEle.getElementsByTagName('t')[0] theString = getText(tElement.childNodes) - + #print('theString: ', theString) actCellSheet.set(ref, theString) @@ -391,7 +390,7 @@ def handleWorkBook(theBook, sheetDict, Doc): #print("sheetFile: ", sheetFile) # add FreeCAD-spreadsheet sheetDict[sheetName] = (Doc.addObject('Spreadsheet::Sheet', sheetName), sheetFile) - + theAliases = theBook.getElementsByTagName("definedName") for theAlias in theAliases: aliAtts = theAlias.attributes @@ -420,39 +419,39 @@ def open(nameXLSX): if len(nameXLSX) > 0: z=zipfile.ZipFile(nameXLSX) - + theDoc = App.newDocument() - + sheetDict = dict() stringList = [] - + theBookFile=z.open('xl/workbook.xml') theBook = xml.dom.minidom.parse(theBookFile) handleWorkBook(theBook, sheetDict, theDoc) theBook.unlink() - + if 'xl/sharedStrings.xml' in z.namelist(): theStringFile=z.open('xl/sharedStrings.xml') theStrings = xml.dom.minidom.parse(theStringFile) handleStrings(theStrings, stringList) theStrings.unlink() - + for sheetSpec in sheetDict: #print("sheetSpec: ", sheetSpec) theSheet, sheetFile = sheetDict[sheetSpec] f=z.open('xl/worksheets/' + sheetFile) myDom = xml.dom.minidom.parse(f) - + handleWorkSheet(myDom, theSheet, stringList) myDom.unlink() - + z.close() # This is needed more than once, otherwise some references are not calculated! theDoc.recompute() theDoc.recompute() theDoc.recompute() return theDoc - + def insert(nameXLSX,docname): try: theDoc=App.getDocument(docname) @@ -468,22 +467,22 @@ def insert(nameXLSX,docname): theBook = xml.dom.minidom.parse(theBookFile) handleWorkBook(theBook, sheetDict, theDoc) theBook.unlink() - + if 'xl/sharedStrings.xml' in z.namelist(): theStringFile=z.open('xl/sharedStrings.xml') theStrings = xml.dom.minidom.parse(theStringFile) handleStrings(theStrings, stringList) theStrings.unlink() - + for sheetSpec in sheetDict: #print("sheetSpec: ", sheetSpec) theSheet, sheetFile = sheetDict[sheetSpec] f=z.open('xl/worksheets/' + sheetFile) myDom = xml.dom.minidom.parse(f) - + handleWorkSheet(myDom, theSheet, stringList) myDom.unlink() - + z.close() # This is needed more than once, otherwise some references are not calculated! theDoc.recompute() diff --git a/src/Mod/Spreadsheet/spreadsheet.dox b/src/Mod/Spreadsheet/spreadsheet.dox index f6abb89e2d..75bd7cb3e7 100644 --- a/src/Mod/Spreadsheet/spreadsheet.dox +++ b/src/Mod/Spreadsheet/spreadsheet.dox @@ -1,5 +1,8 @@ -/** \defgroup IMAGE Image - * \ingroup CWORKBENCHES +/** \defgroup SPREADSHEET Spreadsheet + * \ingroup CWORKBENCHES * \brief Tools to work with spreadsheets + +See \ref src/Mod/Draft/draft.dox as an example of how to populate this page + */