diff --git a/src/Mod/TechDraw/App/AppTechDraw.cpp b/src/Mod/TechDraw/App/AppTechDraw.cpp index 3edf96b1e..30af66945 100644 --- a/src/Mod/TechDraw/App/AppTechDraw.cpp +++ b/src/Mod/TechDraw/App/AppTechDraw.cpp @@ -29,10 +29,10 @@ #include "DrawProjGroupItem.h" #include "DrawProjGroup.h" #include "DrawViewSymbol.h" -//#include "DrawProjection.h" #include "DrawViewClip.h" #include "DrawHatch.h" #include "DrawViewDraft.h" +#include "DrawViewSpreadsheet.h" extern struct PyMethodDef TechDraw_methods[]; @@ -48,7 +48,6 @@ void TechDrawExport initTechDraw() try { Base::Interpreter().loadModule("Part"); Base::Interpreter().loadModule("Measure"); - //Base::Interpreter().loadModule("Mesh"); } catch(const Base::Exception& e) { PyErr_SetString(PyExc_ImportError, e.what()); @@ -66,9 +65,9 @@ void TechDrawExport initTechDraw() TechDraw::DrawView ::init(); TechDraw::DrawViewCollection ::init(); TechDraw::DrawViewPart ::init(); - //TechDraw::DrawProjection ::init(); TechDraw::DrawViewAnnotation ::init(); TechDraw::DrawViewSymbol ::init(); + TechDraw::DrawViewSpreadsheet ::init(); TechDraw::DrawViewSection ::init(); TechDraw::DrawViewDimension ::init(); diff --git a/src/Mod/TechDraw/App/CMakeLists.txt b/src/Mod/TechDraw/App/CMakeLists.txt index 697b46503..1da2a490c 100644 --- a/src/Mod/TechDraw/App/CMakeLists.txt +++ b/src/Mod/TechDraw/App/CMakeLists.txt @@ -22,7 +22,7 @@ link_directories(${OCC_LIBRARY_DIR}) set(TechDrawLIBS Measure Part - FreeCADApp + Spreadsheet ) generate_from_xml(DrawPagePy) @@ -51,6 +51,8 @@ SET(Draw_SRCS DrawViewAnnotation.h DrawViewSymbol.cpp DrawViewSymbol.h + DrawViewSpreadsheet.cpp + DrawViewSpreadsheet.h DrawViewClip.cpp DrawViewClip.h DrawProjGroup.cpp diff --git a/src/Mod/TechDraw/App/DrawView.h b/src/Mod/TechDraw/App/DrawView.h index 2676b1261..0a125b75d 100644 --- a/src/Mod/TechDraw/App/DrawView.h +++ b/src/Mod/TechDraw/App/DrawView.h @@ -25,6 +25,7 @@ #include #include +#include #include namespace TechDraw diff --git a/src/Mod/TechDraw/App/DrawViewSpreadsheet.cpp b/src/Mod/TechDraw/App/DrawViewSpreadsheet.cpp new file mode 100644 index 000000000..472554b54 --- /dev/null +++ b/src/Mod/TechDraw/App/DrawViewSpreadsheet.cpp @@ -0,0 +1,330 @@ +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2015 * + * Copyright (c) 2016 WandererFan (wandererfan@gmail.com) * + * * + * 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 * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#ifndef _PreComp_ +# include +#endif + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "DrawViewSpreadsheet.h" + +#include +#include + +using namespace TechDraw; +using namespace std; + + +//=========================================================================== +// DrawViewSpreadsheet +//=========================================================================== + +PROPERTY_SOURCE(TechDraw::DrawViewSpreadsheet, TechDraw::DrawViewSymbol) + +DrawViewSpreadsheet::DrawViewSpreadsheet(void) +{ + static const char *vgroup = "Spreadsheet"; + + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw"); + std::string fontName = hGrp->GetASCII("LabelFont", "osifont"); + + ADD_PROPERTY_TYPE(Source ,(0),vgroup,App::Prop_None,"Spreadsheet to view"); + ADD_PROPERTY_TYPE(CellStart ,("A1"),vgroup,App::Prop_None,"The top left cell of the range to display"); + ADD_PROPERTY_TYPE(CellEnd ,("B2"),vgroup,App::Prop_None,"The bottom right cell of the range to display"); + ADD_PROPERTY_TYPE(Font ,((fontName.c_str())),vgroup,App::Prop_None,"The name of the font to use"); + ADD_PROPERTY_TYPE(TextColor,(0.0f,0.0f,0.0f),vgroup,App::Prop_None,"The default color of the text and lines"); + ADD_PROPERTY_TYPE(TextSize,(12.0),vgroup,App::Prop_None,"The size of the text"); + ADD_PROPERTY_TYPE(LineWidth,(0.35),vgroup,App::Prop_None,"The thickness of the cell lines"); + //ADD_PROPERTY_TYPE(Symbol,(""),vgroup,App::Prop_Hidden,"The SVG image of this spreadsheet"); + + EditableTexts.setStatus(App::Property::Hidden,true); + +} + +DrawViewSpreadsheet::~DrawViewSpreadsheet() +{ +} + +void DrawViewSpreadsheet::onChanged(const App::Property* prop) +{ + if (!isRestoring()) { + if (prop == &Source || + prop == &CellStart || + prop == &CellEnd || + prop == &Font || + prop == &TextSize || + prop == &TextColor || + prop == &LineWidth) { + try { + App::DocumentObjectExecReturn *ret = recompute(); + delete ret; + } + catch (...) { + } + } + } + TechDraw::DrawView::onChanged(prop); +} + +App::DocumentObjectExecReturn *DrawViewSpreadsheet::execute(void) +{ + App::DocumentObject* link = Source.getValue(); + std::string scellstart = CellStart.getValue(); + std::string scellend = CellEnd.getValue(); + if (!link) + return new App::DocumentObjectExecReturn("No spreadsheet linked"); + if (!link->getTypeId().isDerivedFrom(Spreadsheet::Sheet::getClassTypeId())) + return new App::DocumentObjectExecReturn("The linked object is not a spreadsheet"); + if ( (scellstart.empty()) || (scellend.empty()) ) + return new App::DocumentObjectExecReturn("Empty cell value"); + + Symbol.setValue(getSheetImage()); + + return TechDraw::DrawView::execute(); +} + +std::vector DrawViewSpreadsheet::getAvailColumns(void) +{ + // build a list of available colums: A, B, C, ... AA, AB, ... ZY, ZZ. + std::string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + std::vector availcolumns; + for (int i=0; i<26; ++i) { + std::stringstream s; + s << alphabet[i]; + availcolumns.push_back(s.str()); + } + for (int i=0; i<26; ++i) { + for (int j=0; i<26; ++i) { + std::stringstream s; + s << alphabet[i] << alphabet[j]; + availcolumns.push_back(s.str()); + } + } + return availcolumns; +} + +//note: newlines need to be double escaped for python, but single for C++ +std::string DrawViewSpreadsheet::getSVGHead(void) +{ + std::string head = std::string("\n"); + return head; +} + +std::string DrawViewSpreadsheet::getSVGTail(void) +{ + std::string tail = "\n"; + return tail; +} + +std::string DrawViewSpreadsheet::getSheetImage(void) +{ + std::stringstream result; + + App::DocumentObject* link = Source.getValue(); + std::string scellstart = CellStart.getValue(); + std::string scellend = CellEnd.getValue(); + + std::vector availcolumns = getAvailColumns(); + + // build rows range and columns range + std::vector columns; + std::vector rows; + try { + for (unsigned int i=0; i::const_iterator j = availcolumns.begin(); j != availcolumns.end(); ++j) { + if ( (*j) == startcol) { + if ( (*j) != endcol) { + valid = true; + } + } else { + if (valid) { + if ( (*j) == endcol) { + columns.push_back((*j)); + valid = false; + } else { + columns.push_back((*j)); + } + } + } + } + int endrow = std::atoi(scellend.substr(i,scellend.length()-1).c_str()); + for (int j=rows.back()+1; j<=endrow; ++j) { + rows.push_back(j); + } + } + } + } catch (std::exception) { + Base::Console().Error("Invalid cell range for %s\n",getNameInDocument()); + return result.str(); + } + + // create the containing group + std::string ViewName = Label.getValue(); + + result << getSVGHead(); + + App::Color c = TextColor.getValue(); + result << "" << endl; + + // fill the cells + float rowoffset = 0.0; + float coloffset = 0.0; + float cellheight = 100; + float cellwidth = 100; + std::string celltext; + Spreadsheet::Sheet* sheet = static_cast(link); + std::vector skiplist; + for (std::vector::const_iterator col = columns.begin(); col != columns.end(); ++col) { + // create a group for each column + result << " " << endl; + for (std::vector::const_iterator row = rows.begin(); row != rows.end(); ++row) { + // get cell size + std::stringstream srow; + srow << (*row); + App::CellAddress address((*col) + srow.str()); + cellwidth = sheet->getColumnWidth(address.col()); + cellheight = sheet->getRowHeight(address.row()); + celltext = ""; + // get the text + App::Property* prop = sheet->getPropertyByName(address.toString().c_str()); + std::stringstream field; + if (prop != 0) { + if (prop->isDerivedFrom((App::PropertyQuantity::getClassTypeId()))) + field << static_cast(prop)->getValue(); + else if (prop->isDerivedFrom((App::PropertyFloat::getClassTypeId()))) + field << static_cast(prop)->getValue(); + else if (prop->isDerivedFrom((App::PropertyString::getClassTypeId()))) + field << static_cast(prop)->getValue(); + else + assert(0); + celltext = field.str(); + } + // get colors, style, alignment and span + int alignment; + std::string bcolor = "none"; + std::string fcolor = c.asCSSString(); + std::string textstyle = ""; + Spreadsheet::Cell* cell = sheet->getCell(address); + if (cell) { + App::Color f,b; + std::set st; + int colspan, rowspan; + if (cell->getBackground(b)) { + bcolor = b.asCSSString(); + } + if (cell->getForeground(f)) { + fcolor = f.asCSSString(); + } + if (cell->getStyle(st)) { + for (std::set::const_iterator i = st.begin(); i != st.end(); ++i) { + if ((*i) == "bold") + textstyle = textstyle + "font-weight: bold; "; + else if ((*i) == "italic") + textstyle = textstyle + "font-style: italic; "; + else if ((*i) == "underline") + textstyle = textstyle + "text-decoration: underline; "; + } + } + if (cell->getSpans(rowspan,colspan)) { + for (int i=0; i 0) + cellwidth = cellwidth + sheet->getColumnWidth(nextcell.col()); + if (j > 0) + cellheight = cellheight + sheet->getRowHeight(nextcell.row()); + if ( (i > 0) || (j > 0) ) + skiplist.push_back(nextcell.toString()); + } + } + } + cell->getAlignment(alignment); + } + // skip cell if found in skiplist + if (std::find(skiplist.begin(), skiplist.end(), address.toString()) == skiplist.end()) { + result << " " << endl; + if (alignment & Spreadsheet::Cell::ALIGNMENT_LEFT) + result << " " << celltext << "" << endl; + } + rowoffset = rowoffset + cellheight; + } + result << " " << endl; + rowoffset = 0.0; + coloffset = coloffset + cellwidth; + } + + // close the containing group + result << "" << endl; + + result << getSVGTail(); + + return result.str(); +} + +// Python Drawing feature --------------------------------------------------------- + +namespace App { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawViewSpreadsheetPython, TechDraw::DrawViewSpreadsheet) +template<> const char* TechDraw::DrawViewSpreadsheetPython::getViewProviderName(void) const { + return "TechDrawGui::ViewProviderSpreadsheet"; +} +/// @endcond + +// explicit template instantiation +template class TechDrawExport FeaturePythonT; +} diff --git a/src/Mod/TechDraw/App/DrawViewSpreadsheet.h b/src/Mod/TechDraw/App/DrawViewSpreadsheet.h new file mode 100644 index 000000000..dc229f17a --- /dev/null +++ b/src/Mod/TechDraw/App/DrawViewSpreadsheet.h @@ -0,0 +1,80 @@ +/*************************************************************************** + * Copyright (c) 2016 WandererFan (wandererfan@gmail.com) * + * * + * 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 _DrawViewSpreadsheet_h_ +#define _DrawViewSpreadsheet_h_ + + +#include +#include +#include "App/PropertyStandard.h" +#include +#include + +#include "DrawViewSymbol.h" + +namespace TechDraw +{ + + +class TechDrawExport DrawViewSpreadsheet : public TechDraw::DrawViewSymbol +{ + PROPERTY_HEADER(TechDraw::DrawViewSpreadsheet); + +public: + DrawViewSpreadsheet(void); + virtual ~DrawViewSpreadsheet(); + App::PropertyLink Source; + App::PropertyString CellStart; + App::PropertyString CellEnd; + App::PropertyString Font; + App::PropertyColor TextColor; + App::PropertyFloat LineWidth; + App::PropertyFloat TextSize; + + + virtual App::DocumentObjectExecReturn *execute(void); + std::string getSheetImage(void); + + virtual const char* getViewProviderName(void) const { + return "TechDrawGui::ViewProviderSpreadsheet"; + } + +protected: + virtual void onChanged(const App::Property* prop); + std::vector getAvailColumns(void); + std::string getSVGHead(void); + std::string getSVGTail(void); + +private: +}; + +typedef App::FeaturePythonT DrawViewSpreadsheetPython; + + +} //namespace TechDraw + + +#endif diff --git a/src/Mod/TechDraw/App/DrawViewSymbol.cpp b/src/Mod/TechDraw/App/DrawViewSymbol.cpp index 950564edd..a1a636407 100644 --- a/src/Mod/TechDraw/App/DrawViewSymbol.cpp +++ b/src/Mod/TechDraw/App/DrawViewSymbol.cpp @@ -116,20 +116,6 @@ App::DocumentObjectExecReturn *DrawViewSymbol::execute(void) svg = newsvg; } //TODO: shouldn't there be a Symbol.setValue(svg) here??? -wf -#if 0 - std::stringstream result; - result << "" << endl - << svg << endl - << "" << endl; - - // Apply the resulting fragment - // no more ViewResult! Need to xlate SVG to Geometry object??? - //ViewResult.setValue(result.str().c_str()); -#endif - - //return App::DocumentObject::StdReturn; return DrawView::execute(); } diff --git a/src/Mod/TechDraw/App/PreCompiled.h b/src/Mod/TechDraw/App/PreCompiled.h index 409a3ab44..b6f6d956f 100644 --- a/src/Mod/TechDraw/App/PreCompiled.h +++ b/src/Mod/TechDraw/App/PreCompiled.h @@ -32,11 +32,13 @@ # define PartExport __declspec(dllimport) # define MeasureExport __declspec(dllimport) # define MeshExport __declspec(dllimport) +# define SpreadsheetExport __declspec(dllimport) #else // for Linux # define TechDrawExport # define MeasureExport -# define PartExport -# define MeshExport +# define PartExport +# define MeshExport +# define SpreadsheetExport #endif #ifdef _PreComp_ @@ -122,7 +124,7 @@ #include #endif - + #include #include #include @@ -141,7 +143,7 @@ #include #include -#include +#include #include #include #include @@ -235,4 +237,3 @@ #endif // _PreComp_ #endif - diff --git a/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp b/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp index 31563427c..1e665a22b 100644 --- a/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp +++ b/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp @@ -46,7 +46,8 @@ #include "ViewProviderAnnotation.h" #include "ViewProviderSymbol.h" #include "ViewProviderViewClip.h" -#include "ViewProviderHatch.h" +#include "ViewProviderHatch.h" +#include "ViewProviderSpreadsheet.h" //#include "resources/qrc_TechDraw.cpp" // use a different name to CreateCommand() @@ -103,6 +104,7 @@ void TechDrawGuiExport initTechDrawGui() TechDrawGui::ViewProviderAnnotation::init(); TechDrawGui::ViewProviderSymbol::init(); TechDrawGui::ViewProviderHatch::init(); + TechDrawGui::ViewProviderSpreadsheet::init(); // register preferences pages new Gui::PrefPageProducer ("TechDraw"); diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index 13dee0662..d4af8a26f 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -39,6 +39,7 @@ set(TechDrawGui_MOC_HDRS QGIViewSection.h QGIViewAnnotation.h QGIViewSymbol.h + QGIViewSpreadsheet.h QGIViewClip.h TaskProjGroup.h DlgPrefsTechDrawImp.h @@ -123,6 +124,8 @@ SET(TechDrawGuiView_SRCS QGIViewAnnotation.h QGIViewSymbol.cpp QGIViewSymbol.h + QGIViewSpreadsheet.cpp + QGIViewSpreadsheet.h QGIViewClip.cpp QGIViewClip.h QGIHatch.cpp @@ -152,6 +155,8 @@ SET(TechDrawGuiViewProvider_SRCS ViewProviderAnnotation.h ViewProviderSymbol.cpp ViewProviderSymbol.h + ViewProviderSpreadsheet.cpp + ViewProviderSpreadsheet.h ViewProviderViewClip.cpp ViewProviderViewClip.h ViewProviderHatch.cpp diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index 4c00e45ff..5c22a232f 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -51,6 +51,7 @@ #include #include +#include #include #include @@ -806,6 +807,54 @@ bool CmdTechDrawDraftView::isActive(void) return hasActiveDocument(); } +//=========================================================================== +// TechDraw_Spreadheet +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawSpreadsheet); + +CmdTechDrawSpreadsheet::CmdTechDrawSpreadsheet() + : Command("TechDraw_Spreadsheet") +{ + // seting the + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Spreadsheet"); + sToolTipText = QT_TR_NOOP("Inserts a view of a selected spreadsheet into a drawing"); + sWhatsThis = "TechDraw_Spreadsheet"; + sStatusTip = QT_TR_NOOP("Inserts a view of a selected spreadsheet into a drawing"); + sPixmap = "actions/techdraw-spreadsheet"; +} + +void CmdTechDrawSpreadsheet::activated(int iMsg) +{ + const std::vector spreads = getSelection().getObjectsOfType(Spreadsheet::Sheet::getClassTypeId()); + if (spreads.size() != 1) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select exactly one Spreadsheet object.")); + return; + } + std::string SpreadName = spreads.front()->getNameInDocument(); + + TechDraw::DrawPage* page = _findPage(this); + if (!page) { + return; + } + std::string PageName = page->getNameInDocument(); + + openCommand("Create spreadsheet view"); + std::string FeatName = getUniqueObjectName("Sheet"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewSpreadsheet','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),SpreadName.c_str()); + doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + updateActive(); + commitCommand(); +} + +bool CmdTechDrawSpreadsheet::isActive(void) +{ + return (getActiveGuiDocument() ? true : false); +} + //=========================================================================== // TechDraw_ExportPage @@ -867,4 +916,5 @@ void CreateTechDrawCommands(void) rcCmdMgr.addCommand(new CmdTechDrawSymbol()); rcCmdMgr.addCommand(new CmdTechDrawExportPage()); rcCmdMgr.addCommand(new CmdTechDrawDraftView()); + rcCmdMgr.addCommand(new CmdTechDrawSpreadsheet()); } diff --git a/src/Mod/TechDraw/Gui/MDIViewPage.cpp b/src/Mod/TechDraw/Gui/MDIViewPage.cpp index 128c63b56..199196c4c 100644 --- a/src/Mod/TechDraw/Gui/MDIViewPage.cpp +++ b/src/Mod/TechDraw/Gui/MDIViewPage.cpp @@ -86,6 +86,7 @@ #include #include #include +#include "../App/DrawViewSpreadsheet.h" #include "QGIDrawingTemplate.h" #include "QGIView.h" @@ -332,6 +333,8 @@ int MDIViewPage::attachView(App::DocumentObject *obj) } else if(obj->getTypeId().isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId()) ) { TechDraw::DrawViewClip *viewClip = dynamic_cast(obj); qview = m_view->addDrawViewClip(viewClip); + } else if(obj->getTypeId().isDerivedFrom(TechDraw::DrawViewSpreadsheet::getClassTypeId()) ) { + qview = m_view->addDrawViewSpreadsheet( dynamic_cast(obj) ); } else if(obj->getTypeId().isDerivedFrom(TechDraw::DrawHatch::getClassTypeId()) ) { //Hatch is not attached like other Views (since it isn't really a View) } else { diff --git a/src/Mod/TechDraw/Gui/PreCompiled.h b/src/Mod/TechDraw/Gui/PreCompiled.h index 215cbcb2e..0209ae2be 100644 --- a/src/Mod/TechDraw/Gui/PreCompiled.h +++ b/src/Mod/TechDraw/Gui/PreCompiled.h @@ -32,10 +32,12 @@ # define TechDrawExport __declspec(dllimport) # define PartExport __declspec(dllimport) # define TechDrawGuiExport __declspec(dllexport) +# define SpreadsheetExport __declspec(dllimport) #else // for Linux # define TechDrawExport # define PartExport # define TechDrawGuiExport +# define SpreadsheetExport #endif #ifdef _MSC_VER @@ -43,8 +45,8 @@ #endif #ifdef _PreComp_ - -// Python + +// Python #include // standard @@ -72,7 +74,7 @@ #ifndef __Qt4All__ # include #endif - + #endif //_PreComp_ #endif // DRAWINGGUI_PRECOMPILED_H diff --git a/src/Mod/TechDraw/Gui/QGIView.cpp b/src/Mod/TechDraw/Gui/QGIView.cpp index 1d934eb8d..126174b8d 100644 --- a/src/Mod/TechDraw/Gui/QGIView.cpp +++ b/src/Mod/TechDraw/Gui/QGIView.cpp @@ -87,7 +87,8 @@ QGIView::QGIView(const QPoint &pos, QGraphicsScene *scene) m_font.setPointSize(5.0); //scene units (mm), not points //Add object to scene - scene->addItem(this); + if(scene) // TODO: Get rid of the ctor args as in the refactor attempt + scene->addItem(this); m_label = new QGraphicsTextItem(); addToGroup(m_label); @@ -99,10 +100,6 @@ QGIView::QGIView(const QPoint &pos, QGraphicsScene *scene) m_decorPen.setWidth(0); // 0 => 1px "cosmetic pen" } -QGIView::~QGIView() -{ - -} void QGIView::alignTo(QGraphicsItem*item, const QString &alignment) { @@ -357,6 +354,7 @@ void QGIView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q QGraphicsItemGroup::paint(painter, &myOption, widget); } +//This should count everything except Frame,Label,Dimension - custom or not QRectF QGIView::customChildrenBoundingRect() { QList children = childItems(); int dimItemType = QGraphicsItem::UserType + 106; diff --git a/src/Mod/TechDraw/Gui/QGIView.h b/src/Mod/TechDraw/Gui/QGIView.h index 2547d5fcb..4cf3615a7 100644 --- a/src/Mod/TechDraw/Gui/QGIView.h +++ b/src/Mod/TechDraw/Gui/QGIView.h @@ -45,7 +45,7 @@ class TechDrawGuiExport QGIView : public QObject, public QGraphicsItemGroup public: QGIView(const QPoint &position, QGraphicsScene *scene); - ~QGIView(); + virtual ~QGIView() = default; enum {Type = QGraphicsItem::UserType + 101}; int type() const { return Type;} diff --git a/src/Mod/TechDraw/Gui/QGIViewSpreadsheet.cpp b/src/Mod/TechDraw/Gui/QGIViewSpreadsheet.cpp new file mode 100644 index 000000000..bda89b688 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIViewSpreadsheet.cpp @@ -0,0 +1,67 @@ +/*************************************************************************** + * Copyright (c) 2016 wandererfan * + * * + * 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 * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +#include +#include +#include +#include +#include +#include +#include +#include +#endif + +#include + +#include +#include +#include +#include + +#include "../App/DrawView.h" +#include "../App/DrawViewSpreadsheet.h" +#include "QGIViewSpreadsheet.h" + +using namespace TechDrawGui; + +QGIViewSpreadsheet::QGIViewSpreadsheet() : QGIViewSymbol(QPoint(), nullptr) +{ + setHandlesChildEvents(false); + setCacheMode(QGraphicsItem::NoCache); + setAcceptHoverEvents(true); + setFlag(QGraphicsItem::ItemIsMovable, true); +} + +QGIViewSpreadsheet::~QGIViewSpreadsheet() +{ +} + +void QGIViewSpreadsheet::setViewFeature(TechDraw::DrawViewSpreadsheet *obj) +{ + // called from QGVPage. (once) + QGIView::setViewFeature(static_cast(obj)); +} + + +#include "moc_QGIViewSpreadsheet.cpp" diff --git a/src/Mod/TechDraw/Gui/QGIViewSpreadsheet.h b/src/Mod/TechDraw/Gui/QGIViewSpreadsheet.h new file mode 100644 index 000000000..6888bc142 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIViewSpreadsheet.h @@ -0,0 +1,65 @@ +/*************************************************************************** + * Copyright (c) 2016 wandererfan * + * * + * 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 DRAWINGGUI_QGRAPHICSITEMVIEWSPREADSHEET_H +#define DRAWINGGUI_QGRAPHICSITEMVIEWSPREADSHEET_H + +#include +#include +#include +#include +#include +#include + +#include "QGIViewSymbol.h" +#include "QGIView.h" + +namespace TechDraw { +class DrawViewSpreadsheet; +} + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGIViewSpreadsheet : public QGIViewSymbol +{ + Q_OBJECT + +public: + explicit QGIViewSpreadsheet(); + ~QGIViewSpreadsheet(); + + enum {Type = QGraphicsItem::UserType + 124}; + int type() const { return Type;} + + //void updateView(bool update = false); + void setViewFeature(TechDraw::DrawViewSpreadsheet *obj); + +protected: + //void drawSvg(); + +protected: +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGRAPHICSITEMVIEWSPREADSHEET_H diff --git a/src/Mod/TechDraw/Gui/QGIViewSymbol.cpp b/src/Mod/TechDraw/Gui/QGIViewSymbol.cpp index 0b3a89078..8e0f39776 100644 --- a/src/Mod/TechDraw/Gui/QGIViewSymbol.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewSymbol.cpp @@ -114,13 +114,20 @@ void QGIViewSymbol::drawSvg() TechDraw::DrawViewSymbol *viewSymbol = dynamic_cast(getViewObject()); QString qs(QString::fromUtf8(viewSymbol->Symbol.getValue())); + + symbolToSvg(qs); +} + +void QGIViewSymbol::symbolToSvg(QString qs) +{ if (qs.isEmpty()) { return; } + QByteArray qba; qba.append(qs); if (!load(&qba)) { - Base::Console().Error("QGIViewSymbol::drawSvg - Could not load %s.Symbol into renderer\n", viewSymbol->getNameInDocument()); + Base::Console().Error("Error - Could not load Symbol into SVG renderer for %s\n", getViewObject()->getNameInDocument()); } m_svgItem->setPos(0.,0.); } diff --git a/src/Mod/TechDraw/Gui/QGIViewSymbol.h b/src/Mod/TechDraw/Gui/QGIViewSymbol.h index fbfcb54eb..1b94996e1 100644 --- a/src/Mod/TechDraw/Gui/QGIViewSymbol.h +++ b/src/Mod/TechDraw/Gui/QGIViewSymbol.h @@ -64,8 +64,8 @@ Q_SIGNALS: protected: bool load(QByteArray *svgString); - void drawSvg(); - + virtual void drawSvg(); + void symbolToSvg(QString qs); QVariant itemChange(GraphicsItemChange change, const QVariant &value); QGCustomSvg *m_svgItem; diff --git a/src/Mod/TechDraw/Gui/QGVPage.cpp b/src/Mod/TechDraw/Gui/QGVPage.cpp index cf5d14979..8514ecb75 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.cpp +++ b/src/Mod/TechDraw/Gui/QGVPage.cpp @@ -57,6 +57,7 @@ #include #include #include "../App/DrawHatch.h" +#include "../App/DrawViewSpreadsheet.h" #include "QGIDrawingTemplate.h" @@ -69,6 +70,7 @@ #include "QGIViewAnnotation.h" #include "QGIViewSymbol.h" #include "QGIViewClip.h" +#include "QGIViewSpreadsheet.h" #include "ZVALUE.h" #include "QGVPage.h" @@ -256,6 +258,16 @@ QGIView * QGVPage::addDrawViewClip(TechDraw::DrawViewClip *view) return qview; } +QGIView * QGVPage::addDrawViewSpreadsheet(TechDraw::DrawViewSpreadsheet *view) +{ + QGIViewSpreadsheet *qview(new QGIViewSpreadsheet); + + qview->setViewFeature(view); + + addView(qview); + return qview; +} + QGIView * QGVPage::addViewDimension(TechDraw::DrawViewDimension *dim) { QGIViewDimension *dimGroup = new QGIViewDimension(QPoint(0,0), scene()); diff --git a/src/Mod/TechDraw/Gui/QGVPage.h b/src/Mod/TechDraw/Gui/QGVPage.h index 1fcc422c0..ed44b5430 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.h +++ b/src/Mod/TechDraw/Gui/QGVPage.h @@ -38,6 +38,7 @@ class DrawViewSymbol; class DrawViewClip; class DrawHatch; class DrawViewCollection; +class DrawViewSpreadsheet; } namespace TechDrawGui @@ -69,6 +70,7 @@ public: QGIView * addDrawViewAnnotation(TechDraw::DrawViewAnnotation *view); QGIView * addDrawViewSymbol(TechDraw::DrawViewSymbol *view); QGIView * addDrawViewClip(TechDraw::DrawViewClip *view); + QGIView * addDrawViewSpreadsheet(TechDraw::DrawViewSpreadsheet *view); QGIView * findView(App::DocumentObject *obj) const; QGIView * findParent(QGIView *) const; diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index 4123ef78c..ad141145f 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -6,6 +6,7 @@ icons/TechDraw_Tree_PageTemplate.svg icons/TechDraw_Tree_ProjGroup.svg icons/TechDraw_Tree_Section.svg + icons/TechDraw_Tree_Spreadsheet.svg icons/TechDraw_Tree_Symbol.svg icons/TechDraw_Tree_View.svg icons/TechDraw_Pages.svg @@ -42,5 +43,6 @@ icons/actions/techdraw-hatch.svg icons/actions/techdraw-toggleframe.svg icons/actions/techdraw-projgroup.svg + icons/actions/techdraw-spreadsheet.svg diff --git a/src/Mod/TechDraw/Gui/Resources/icons/TechDraw_Tree_Spreadsheet.svg b/src/Mod/TechDraw/Gui/Resources/icons/TechDraw_Tree_Spreadsheet.svg new file mode 100644 index 000000000..d6cb866ec --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/TechDraw_Tree_Spreadsheet.svg @@ -0,0 +1,704 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-spreadsheet.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-spreadsheet.svg new file mode 100644 index 000000000..d6cb866ec --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-spreadsheet.svg @@ -0,0 +1,704 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/ViewProviderSpreadsheet.cpp b/src/Mod/TechDraw/Gui/ViewProviderSpreadsheet.cpp new file mode 100644 index 000000000..96e6e994c --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderSpreadsheet.cpp @@ -0,0 +1,85 @@ +/*************************************************************************** + * Copyright (c) 2016 wandererfan * + * * + * 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 * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#ifndef _PreComp_ +#endif + +/// Here the FreeCAD includes sorted by Base,App,Gui...... +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "ViewProviderSpreadsheet.h" + +using namespace TechDrawGui; + +PROPERTY_SOURCE(TechDrawGui::ViewProviderSpreadsheet, Gui::ViewProviderDocumentObject) + +//************************************************************************** +// Construction/Destruction + +ViewProviderSpreadsheet::ViewProviderSpreadsheet() +{ + sPixmap = "TechDraw_Tree_Spreadsheet"; +} + +ViewProviderSpreadsheet::~ViewProviderSpreadsheet() +{ +} + +void ViewProviderSpreadsheet::attach(App::DocumentObject *pcFeat) +{ + // call parent attach method + ViewProviderDocumentObject::attach(pcFeat); +} + +void ViewProviderSpreadsheet::setDisplayMode(const char* ModeName) +{ + ViewProviderDocumentObject::setDisplayMode(ModeName); +} + +std::vector ViewProviderSpreadsheet::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList = ViewProviderDocumentObject::getDisplayModes(); + + return StrList; +} + +void ViewProviderSpreadsheet::updateData(const App::Property*) +{ +} + +TechDraw::DrawViewSpreadsheet* ViewProviderSpreadsheet::getViewObject() const +{ + return dynamic_cast(pcObject); +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderSpreadsheet.h b/src/Mod/TechDraw/Gui/ViewProviderSpreadsheet.h new file mode 100644 index 000000000..4c8bd69a8 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderSpreadsheet.h @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (c) 2016 wandererfan * + * * + * 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 DRAWINGGUI_VIEWPROVIDERSPREADSHEET_H +#define DRAWINGGUI_VIEWPROVIDERSPREADSHEET_H + +#include + +namespace TechDraw{ + class DrawViewSpreadsheet; +} + +namespace TechDrawGui { + + +class TechDrawGuiExport ViewProviderSpreadsheet : public Gui::ViewProviderDocumentObject +{ + PROPERTY_HEADER(TechDrawGui::ViewProviderSpreadsheet); + +public: + /// constructor + ViewProviderSpreadsheet(); + /// destructor + virtual ~ViewProviderSpreadsheet(); + + + virtual void attach(App::DocumentObject *); + virtual void setDisplayMode(const char* ModeName); + virtual bool useNewSelectionModel(void) const {return false;} + /// returns a list of all possible modes + virtual std::vector getDisplayModes(void) const; + virtual void updateData(const App::Property*); + + TechDraw::DrawViewSpreadsheet* getViewObject() const; +}; + +} // namespace TechDrawGui + + +#endif // DRAWINGGUI_VIEWPROVIDERSPREADSHEET_H diff --git a/src/Mod/TechDraw/Gui/Workbench.cpp b/src/Mod/TechDraw/Gui/Workbench.cpp index ff4aec0ca..0c38c2443 100644 --- a/src/Mod/TechDraw/Gui/Workbench.cpp +++ b/src/Mod/TechDraw/Gui/Workbench.cpp @@ -67,6 +67,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const *draw << "TechDraw_NewViewSection"; *draw << "TechDraw_Annotation"; *draw << "TechDraw_Symbol"; + *draw << "TechDraw_Spreadsheet"; *draw << "TechDraw_Clip"; *draw << "TechDraw_ClipPlus"; *draw << "TechDraw_ClipMinus"; @@ -98,6 +99,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const *views << "TechDraw_NewViewSection"; *views << "TechDraw_Annotation"; *views << "TechDraw_DraftView"; + *views << "TechDraw_Spreadsheet"; Gui::ToolBarItem *clips = new Gui::ToolBarItem(root); clips->setCommand("TechDraw Clips"); @@ -143,6 +145,7 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const *views << "TechDraw_NewViewSection"; *views << "TechDraw_Annotation"; *views << "TechDraw_DraftView"; + *views << "TechDraw_Spreadsheet"; Gui::ToolBarItem *clips = new Gui::ToolBarItem(root); clips->setCommand("TechDraw Clips");