From 2dc62d783e8ba168f2c9c91a682726acd1ba96bc Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Wed, 2 May 2012 18:16:41 -0300 Subject: [PATCH] Added 0000602 : Annotations object for Drawing pages --- src/Mod/Drawing/App/AppDrawing.cpp | 2 + src/Mod/Drawing/App/CMakeLists.txt | 2 + src/Mod/Drawing/App/FeatureViewAnnotation.cpp | 103 +++ src/Mod/Drawing/App/FeatureViewAnnotation.h | 73 ++ src/Mod/Drawing/App/Makefile.am | 2 + src/Mod/Drawing/Gui/Command.cpp | 29 + src/Mod/Drawing/Gui/Resources/Drawing.qrc | 1 + src/Mod/Drawing/Gui/Resources/Makefile.am | 1 + .../icons/actions/drawing-annotation.svg | 722 ++++++++++++++++++ src/Mod/Drawing/Gui/Workbench.cpp | 2 + 10 files changed, 937 insertions(+) create mode 100644 src/Mod/Drawing/App/FeatureViewAnnotation.cpp create mode 100644 src/Mod/Drawing/App/FeatureViewAnnotation.h create mode 100755 src/Mod/Drawing/Gui/Resources/icons/actions/drawing-annotation.svg diff --git a/src/Mod/Drawing/App/AppDrawing.cpp b/src/Mod/Drawing/App/AppDrawing.cpp index 86aafb420..a581668ba 100644 --- a/src/Mod/Drawing/App/AppDrawing.cpp +++ b/src/Mod/Drawing/App/AppDrawing.cpp @@ -20,6 +20,7 @@ #include "FeaturePage.h" #include "FeatureView.h" #include "FeatureViewPart.h" +#include "FeatureViewAnnotation.h" #include "FeatureProjection.h" #include "PageGroup.h" @@ -57,6 +58,7 @@ void DrawingExport initDrawing() Drawing::FeatureProjection ::init(); Drawing::FeatureViewPartPython ::init(); Drawing::FeatureViewPython ::init(); + Drawing::FeatureViewAnnotation ::init(); } } // extern "C" diff --git a/src/Mod/Drawing/App/CMakeLists.txt b/src/Mod/Drawing/App/CMakeLists.txt index 3258959f8..98767a24a 100644 --- a/src/Mod/Drawing/App/CMakeLists.txt +++ b/src/Mod/Drawing/App/CMakeLists.txt @@ -27,6 +27,8 @@ SET(Features_SRCS FeatureView.h FeatureViewPart.cpp FeatureViewPart.h + FeatureViewAnnotation.cpp + FeatureViewAnnotation.h PageGroup.cpp PageGroup.h ) diff --git a/src/Mod/Drawing/App/FeatureViewAnnotation.cpp b/src/Mod/Drawing/App/FeatureViewAnnotation.cpp new file mode 100644 index 000000000..50d78add5 --- /dev/null +++ b/src/Mod/Drawing/App/FeatureViewAnnotation.cpp @@ -0,0 +1,103 @@ +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2012 * + * * + * 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 "FeatureViewAnnotation.h" + +using namespace Drawing; +using namespace std; + + +//=========================================================================== +// FeatureViewAnnotation +//=========================================================================== + +PROPERTY_SOURCE(Drawing::FeatureViewAnnotation, Drawing::FeatureView) + + +FeatureViewAnnotation::FeatureViewAnnotation(void) +{ + static const char *vgroup = "Drawing view"; + + ADD_PROPERTY_TYPE(Text ,(""),vgroup,App::Prop_None,"The text to be displayed"); + ADD_PROPERTY_TYPE(Font ,("Sans"),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 color of the text"); +} + +FeatureViewAnnotation::~FeatureViewAnnotation() +{ +} + +App::DocumentObjectExecReturn *FeatureViewAnnotation::execute(void) +{ + std::stringstream result,hr,hg,hb; + const App::Color& c = TextColor.getValue(); + hr << hex << setfill('0') << setw(2) << (int)(255.0*c.r); + hg << hex << setfill('0') << setw(2) << (int)(255.0*c.g); + hb << hex << setfill('0') << setw(2) << (int)(255.0*c.b); + + result << "" << endl; + + int index=0; + for (std::vector::const_iterator it = Text.getValues().begin(); it != Text.getValues().end(); ++it) { + result << "" << it->c_str() << "" << endl; + index++; + } + + result << "" << endl; + + // Apply the resulting fragment + ViewResult.setValue(result.str().c_str()); + + return App::DocumentObject::StdReturn; +} + +// Python Drawing feature --------------------------------------------------------- + +namespace App { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(Drawing::FeatureViewAnnotationPython, Drawing::FeatureViewAnnotation) +template<> const char* Drawing::FeatureViewAnnotationPython::getViewProviderName(void) const { + return "DrawingGui::ViewProviderDrawingView"; +} +/// @endcond + +// explicit template instantiation +template class DrawingExport FeaturePythonT; +} diff --git a/src/Mod/Drawing/App/FeatureViewAnnotation.h b/src/Mod/Drawing/App/FeatureViewAnnotation.h new file mode 100644 index 000000000..8bd68cf40 --- /dev/null +++ b/src/Mod/Drawing/App/FeatureViewAnnotation.h @@ -0,0 +1,73 @@ +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net 2012) * + * * + * 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 _FeatureViewAnnotation_h_ +#define _FeatureViewAnnotation_h_ + + +#include +#include +#include "FeatureView.h" +#include + + +namespace Drawing +{ + + +/** Base class of all View Features in the drawing module + */ +class DrawingExport FeatureViewAnnotation : public FeatureView +{ + PROPERTY_HEADER(Drawing::FeatureView); + +public: + /// Constructor + FeatureViewAnnotation(void); + virtual ~FeatureViewAnnotation(); + + App::PropertyStringList Text; + App::PropertyString Font; + App::PropertyColor TextColor; + + /** @name methods overide Feature */ + //@{ + /// recalculate the Feature + virtual App::DocumentObjectExecReturn *execute(void); + //@} + + /// returns the type name of the ViewProvider + virtual const char* getViewProviderName(void) const { + return "DrawingGui::ViewProviderDrawingView"; + } +}; + +typedef App::FeaturePythonT FeatureViewAnnotationPython; + + +} //namespace Drawing + + +#endif diff --git a/src/Mod/Drawing/App/Makefile.am b/src/Mod/Drawing/App/Makefile.am index 790f1ddcc..462017c0f 100644 --- a/src/Mod/Drawing/App/Makefile.am +++ b/src/Mod/Drawing/App/Makefile.am @@ -13,6 +13,8 @@ libDrawing_la_SOURCES=\ FeatureView.h \ FeatureViewPart.cpp \ FeatureViewPart.h \ + FeatureViewAnnotation.cpp \ + FeatureViewAnnotation.h \ PageGroup.cpp \ PageGroup.h \ ProjectionAlgos.cpp \ diff --git a/src/Mod/Drawing/Gui/Command.cpp b/src/Mod/Drawing/Gui/Command.cpp index 2dc1a4957..4da43412c 100644 --- a/src/Mod/Drawing/Gui/Command.cpp +++ b/src/Mod/Drawing/Gui/Command.cpp @@ -354,6 +354,34 @@ bool CmdDrawingOpenBrowserView::isActive(void) return (getActiveGuiDocument() ? true : false); } +//=========================================================================== +// Drawing_Annotation +//=========================================================================== + +DEF_STD_CMD_A(CmdDrawingAnnotation); + +CmdDrawingAnnotation::CmdDrawingAnnotation() + : Command("Drawing_Annotation") +{ + // seting the + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("&Annotation"); + sToolTipText = QT_TR_NOOP("Inserts an Annotation view in the active document"); + sWhatsThis = "Drawing_Annotation"; + sStatusTip = QT_TR_NOOP("Inserts an Annotation view in the active document"); + sPixmap = "actions/drawing-annotation"; +} + +void CmdDrawingAnnotation::activated(int iMsg) +{ + doCommand(Doc,"AnnotationView = App.activeDocument().addObject(\"Drawing::FeatureViewAnnotation\",\"ViewAnnotation\")"); + doCommand(Doc,"AnnotationView.Scale = 7.0"); +} + +bool CmdDrawingAnnotation::isActive(void) +{ + return (getActiveGuiDocument() ? true : false); +} //=========================================================================== // Drawing_ExportPage @@ -451,6 +479,7 @@ void CreateDrawingCommands(void) rcCmdMgr.addCommand(new CmdDrawingNewView()); rcCmdMgr.addCommand(new CmdDrawingOrthoViews()); rcCmdMgr.addCommand(new CmdDrawingOpenBrowserView()); + rcCmdMgr.addCommand(new CmdDrawingAnnotation()); rcCmdMgr.addCommand(new CmdDrawingExportPage()); rcCmdMgr.addCommand(new CmdDrawingProjectShape()); } diff --git a/src/Mod/Drawing/Gui/Resources/Drawing.qrc b/src/Mod/Drawing/Gui/Resources/Drawing.qrc index 5d5d80ca3..fad40eb81 100644 --- a/src/Mod/Drawing/Gui/Resources/Drawing.qrc +++ b/src/Mod/Drawing/Gui/Resources/Drawing.qrc @@ -16,6 +16,7 @@ icons/actions/drawing-view.svg icons/actions/drawing-orthoviews.svg icons/actions/drawing-openbrowser.svg + icons/actions/drawing-annotation.svg translations/Drawing_af.qm translations/Drawing_de.qm translations/Drawing_es.qm diff --git a/src/Mod/Drawing/Gui/Resources/Makefile.am b/src/Mod/Drawing/Gui/Resources/Makefile.am index a6063f8ea..e42a14b03 100644 --- a/src/Mod/Drawing/Gui/Resources/Makefile.am +++ b/src/Mod/Drawing/Gui/Resources/Makefile.am @@ -20,6 +20,7 @@ EXTRA_DIST = \ icons/actions/drawing-portrait-A4.svg \ icons/actions/drawing-orthoviews.svg \ icons/actions/drawing-openbrowser.svg \ + icons/actions/drawing-annotation.svg \ icons/Page.svg \ icons/Pages.svg \ icons/View.svg \ diff --git a/src/Mod/Drawing/Gui/Resources/icons/actions/drawing-annotation.svg b/src/Mod/Drawing/Gui/Resources/icons/actions/drawing-annotation.svg new file mode 100755 index 000000000..b45e42a48 --- /dev/null +++ b/src/Mod/Drawing/Gui/Resources/icons/actions/drawing-annotation.svg @@ -0,0 +1,722 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + Ab + + + diff --git a/src/Mod/Drawing/Gui/Workbench.cpp b/src/Mod/Drawing/Gui/Workbench.cpp index d4816ada2..b7bd8bbce 100644 --- a/src/Mod/Drawing/Gui/Workbench.cpp +++ b/src/Mod/Drawing/Gui/Workbench.cpp @@ -62,6 +62,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const *part << "Drawing_NewView"; *part << "Drawing_OrthoViews"; *part << "Drawing_OpenBrowserView"; + *part << "Drawing_Annotation"; *part << "Drawing_ExportPage"; return root; @@ -78,6 +79,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const *part << "Drawing_NewView"; *part << "Drawing_OrthoViews"; *part << "Drawing_OpenBrowserView"; + *part << "Drawing_Annotation"; *part << "Drawing_ExportPage"; return root; }