From e63eaf90755fb880441f3472d04c8d2387795fbc Mon Sep 17 00:00:00 2001 From: Sebastian Hoogen Date: Tue, 15 May 2012 18:01:15 +0200 Subject: [PATCH 1/2] add isNull() method to Rotation --- src/Base/RotationPy.xml | 8 ++++++++ src/Base/RotationPyImp.cpp | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Base/RotationPy.xml b/src/Base/RotationPy.xml index 02dc34ee8..111cfb74c 100644 --- a/src/Base/RotationPy.xml +++ b/src/Base/RotationPy.xml @@ -48,6 +48,14 @@ + + + + isNull() -> Bool + returns True if the rotation equals the unity matrix + + + The rotation elements (as quaternion) diff --git a/src/Base/RotationPyImp.cpp b/src/Base/RotationPyImp.cpp index 7abede54c..159952c7e 100644 --- a/src/Base/RotationPyImp.cpp +++ b/src/Base/RotationPyImp.cpp @@ -144,6 +144,17 @@ PyObject* RotationPy::toEuler(PyObject * args) return Py::new_reference_to(tuple); } +PyObject* RotationPy::isNull(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + Base::Rotation rot = * getRotationPtr(); + Base::Rotation nullrot(0,0,0,1); + Base::Rotation nullrotinv(0,0,0,-1); + bool null = (rot == nullrot) | (rot == nullrotinv); + return Py_BuildValue("O", (null ? Py_True : Py_False)); +} + Py::Tuple RotationPy::getQ(void) const { double q0, q1, q2, q3; From 1a79480bd61bda58381d48b1c1543f61273d2976 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Wed, 16 May 2012 16:31:02 -0300 Subject: [PATCH 2/2] Added 0000145 : Drawing clip objects --- src/Mod/Drawing/App/AppDrawing.cpp | 2 + src/Mod/Drawing/App/CMakeLists.txt | 2 + src/Mod/Drawing/App/FeatureClip.cpp | 111 +++ src/Mod/Drawing/App/FeatureClip.h | 71 ++ src/Mod/Drawing/App/FeaturePage.cpp | 7 +- src/Mod/Drawing/App/Makefile.am | 2 + src/Mod/Drawing/Gui/Command.cpp | 47 +- src/Mod/Drawing/Gui/Resources/Drawing.qrc | 1 + src/Mod/Drawing/Gui/Resources/Makefile.am | 1 + .../Resources/icons/actions/drawing-clip.svg | 710 ++++++++++++++++++ src/Mod/Drawing/Gui/Workbench.cpp | 4 + 11 files changed, 955 insertions(+), 3 deletions(-) create mode 100644 src/Mod/Drawing/App/FeatureClip.cpp create mode 100644 src/Mod/Drawing/App/FeatureClip.h create mode 100644 src/Mod/Drawing/Gui/Resources/icons/actions/drawing-clip.svg diff --git a/src/Mod/Drawing/App/AppDrawing.cpp b/src/Mod/Drawing/App/AppDrawing.cpp index a581668ba..016abf81b 100644 --- a/src/Mod/Drawing/App/AppDrawing.cpp +++ b/src/Mod/Drawing/App/AppDrawing.cpp @@ -22,6 +22,7 @@ #include "FeatureViewPart.h" #include "FeatureViewAnnotation.h" #include "FeatureProjection.h" +#include "FeatureClip.h" #include "PageGroup.h" extern struct PyMethodDef Drawing_methods[]; @@ -59,6 +60,7 @@ void DrawingExport initDrawing() Drawing::FeatureViewPartPython ::init(); Drawing::FeatureViewPython ::init(); Drawing::FeatureViewAnnotation ::init(); + Drawing::FeatureClip ::init(); } } // extern "C" diff --git a/src/Mod/Drawing/App/CMakeLists.txt b/src/Mod/Drawing/App/CMakeLists.txt index 98767a24a..00710b75e 100644 --- a/src/Mod/Drawing/App/CMakeLists.txt +++ b/src/Mod/Drawing/App/CMakeLists.txt @@ -29,6 +29,8 @@ SET(Features_SRCS FeatureViewPart.h FeatureViewAnnotation.cpp FeatureViewAnnotation.h + FeatureClip.cpp + FeatureClip.h PageGroup.cpp PageGroup.h ) diff --git a/src/Mod/Drawing/App/FeatureClip.cpp b/src/Mod/Drawing/App/FeatureClip.cpp new file mode 100644 index 000000000..c45229929 --- /dev/null +++ b/src/Mod/Drawing/App/FeatureClip.cpp @@ -0,0 +1,111 @@ +/*************************************************************************** + * Copyright (c) Yorik van Havre 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 +#include +#include + +#include "FeatureClip.h" +#include "FeatureView.h" + +using namespace Drawing; +using namespace std; + + +//=========================================================================== +// FeaturePage +//=========================================================================== + +PROPERTY_SOURCE(Drawing::FeatureClip, App::DocumentObjectGroup) + +FeatureClip::FeatureClip(void) +{ + static const char *group = "Drawing view"; + App::PropertyType hidden = (App::PropertyType)(App::Prop_Hidden); + ADD_PROPERTY_TYPE(ViewResult ,(""),group,hidden,"Resulting SVG view of this clip"); + ADD_PROPERTY_TYPE(X ,(10),group,App::Prop_None ,"The left margin of the view area of this clip"); + ADD_PROPERTY_TYPE(Y ,(10),group,App::Prop_None ,"The top margin of the view area of this clip"); + ADD_PROPERTY_TYPE(Height ,(10),group,App::Prop_None ,"The height of the view area of this clip"); + ADD_PROPERTY_TYPE(Width ,(10),group,App::Prop_None ,"The width of the view area of this clip"); + ADD_PROPERTY_TYPE(ShowFrame ,(0),group,App::Prop_None,"Specifies if the clip frame appears on the page or not"); +} + +FeatureClip::~FeatureClip() +{ +} + +/// get called by the container when a Property was changed +void FeatureClip::onChanged(const App::Property* prop) +{ + App::DocumentObjectGroup::onChanged(prop); +} + +App::DocumentObjectExecReturn *FeatureClip::execute(void) +{ + ostringstream svg; + + // creating clip path + svg << "" + << "" << endl; + + // show clip frame on the page if needed + + if (ShowFrame.getValue()) { + svg << "" << endl; + } + + // create clipped group + svg << "" << endl; + + // get through the children and collect all the views + const std::vector &Grp = Group.getValues(); + for (std::vector::const_iterator It= Grp.begin();It!=Grp.end();++It) { + if ((*It)->getTypeId().isDerivedFrom(Drawing::FeatureView::getClassTypeId())) { + Drawing::FeatureView *View = dynamic_cast(*It); + svg << View->ViewResult.getValue() << endl; + } + } + + // closing clipped group + svg << "" << endl; + + ViewResult.setValue(svg.str().c_str()); + return App::DocumentObject::StdReturn; +} diff --git a/src/Mod/Drawing/App/FeatureClip.h b/src/Mod/Drawing/App/FeatureClip.h new file mode 100644 index 000000000..ae1e6c0fc --- /dev/null +++ b/src/Mod/Drawing/App/FeatureClip.h @@ -0,0 +1,71 @@ +/*************************************************************************** + * Copyright (c) Yorik van Havre 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 _FeatureClip_h_ +#define _FeatureClip_h_ + + +#include +#include + +namespace Drawing +{ + +/** Base class of all View Features in the drawing module + */ +class DrawingExport FeatureClip: public App::DocumentObjectGroup +{ + PROPERTY_HEADER(Drawing::FeatureClip); + +public: + /// Constructor + FeatureClip(void); + virtual ~FeatureClip(); + + App::PropertyFloat X; + App::PropertyFloat Y; + App::PropertyFloat Width; + App::PropertyFloat Height; + App::PropertyBool ShowFrame; + App::PropertyString ViewResult; + + /** @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::ViewProviderDrawingPage"; + } + +protected: + void onChanged(const App::Property* prop); +}; + + +} //namespace Drawing + + +#endif diff --git a/src/Mod/Drawing/App/FeaturePage.cpp b/src/Mod/Drawing/App/FeaturePage.cpp index 684fe28cf..c1730ebc4 100644 --- a/src/Mod/Drawing/App/FeaturePage.cpp +++ b/src/Mod/Drawing/App/FeaturePage.cpp @@ -37,6 +37,7 @@ #include "FeaturePage.h" #include "FeatureView.h" +#include "FeatureClip.h" using namespace Drawing; using namespace std; @@ -124,10 +125,14 @@ App::DocumentObjectExecReturn *FeaturePage::execute(void) // get through the children and collect all the views const std::vector &Grp = Group.getValues(); for (std::vector::const_iterator It= Grp.begin();It!=Grp.end();++It) { - if ((*It)->getTypeId().isDerivedFrom(Drawing::FeatureView::getClassTypeId())) { + if ( (*It)->getTypeId().isDerivedFrom(Drawing::FeatureView::getClassTypeId()) ) { Drawing::FeatureView *View = dynamic_cast(*It); ofile << View->ViewResult.getValue(); ofile << tempendl << tempendl << tempendl; + } else if ( (*It)->getTypeId().isDerivedFrom(Drawing::FeatureClip::getClassTypeId()) ) { + Drawing::FeatureClip *Clip = dynamic_cast(*It); + ofile << Clip->ViewResult.getValue(); + ofile << tempendl << tempendl << tempendl; } } } diff --git a/src/Mod/Drawing/App/Makefile.am b/src/Mod/Drawing/App/Makefile.am index 462017c0f..098b9b786 100644 --- a/src/Mod/Drawing/App/Makefile.am +++ b/src/Mod/Drawing/App/Makefile.am @@ -15,6 +15,8 @@ libDrawing_la_SOURCES=\ FeatureViewPart.h \ FeatureViewAnnotation.cpp \ FeatureViewAnnotation.h \ + FeatureClip.cpp \ + FeatureClip.h \ PageGroup.cpp \ PageGroup.h \ ProjectionAlgos.cpp \ diff --git a/src/Mod/Drawing/Gui/Command.cpp b/src/Mod/Drawing/Gui/Command.cpp index 2f9345b97..7ed5a4641 100644 --- a/src/Mod/Drawing/Gui/Command.cpp +++ b/src/Mod/Drawing/Gui/Command.cpp @@ -366,9 +366,9 @@ CmdDrawingAnnotation::CmdDrawingAnnotation() // seting the sGroup = QT_TR_NOOP("Drawing"); sMenuText = QT_TR_NOOP("&Annotation"); - sToolTipText = QT_TR_NOOP("Inserts an Annotation view in the active document"); + sToolTipText = QT_TR_NOOP("Inserts an Annotation view in the active drawing"); sWhatsThis = "Drawing_Annotation"; - sStatusTip = QT_TR_NOOP("Inserts an Annotation view in the active document"); + sStatusTip = QT_TR_NOOP("Inserts an Annotation view in the active drawing"); sPixmap = "actions/drawing-annotation"; } @@ -398,6 +398,48 @@ bool CmdDrawingAnnotation::isActive(void) return (getActiveGuiDocument() ? true : false); } + +//=========================================================================== +// Drawing_Clip +//=========================================================================== + +DEF_STD_CMD_A(CmdDrawingClip); + +CmdDrawingClip::CmdDrawingClip() + : Command("Drawing_Clip") +{ + // seting the + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("&Clip"); + sToolTipText = QT_TR_NOOP("Inserts a clip group in the active drawing"); + sWhatsThis = "Drawing_Annotation"; + sStatusTip = QT_TR_NOOP("Inserts a clip group in the active drawing"); + sPixmap = "actions/drawing-clip"; +} + +void CmdDrawingClip::activated(int iMsg) +{ + + std::vector pages = this->getDocument()->getObjectsOfType(Drawing::FeaturePage::getClassTypeId()); + if (pages.empty()){ + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page to insert"), + QObject::tr("Create a page to insert.")); + return; + } + std::string PageName = pages.front()->getNameInDocument(); + std::string FeatName = getUniqueObjectName("Clip"); + openCommand("Create Clip"); + doCommand(Doc,"App.activeDocument().addObject('Drawing::FeatureClip','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + updateActive(); + commitCommand(); +} + +bool CmdDrawingClip::isActive(void) +{ + return (getActiveGuiDocument() ? true : false); +} + //=========================================================================== // Drawing_ExportPage //=========================================================================== @@ -495,6 +537,7 @@ void CreateDrawingCommands(void) rcCmdMgr.addCommand(new CmdDrawingOrthoViews()); rcCmdMgr.addCommand(new CmdDrawingOpenBrowserView()); rcCmdMgr.addCommand(new CmdDrawingAnnotation()); + rcCmdMgr.addCommand(new CmdDrawingClip()); 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 fad40eb81..bc0ae4cdf 100644 --- a/src/Mod/Drawing/Gui/Resources/Drawing.qrc +++ b/src/Mod/Drawing/Gui/Resources/Drawing.qrc @@ -17,6 +17,7 @@ icons/actions/drawing-orthoviews.svg icons/actions/drawing-openbrowser.svg icons/actions/drawing-annotation.svg + icons/actions/drawing-clip.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 e42a14b03..69b335394 100644 --- a/src/Mod/Drawing/Gui/Resources/Makefile.am +++ b/src/Mod/Drawing/Gui/Resources/Makefile.am @@ -21,6 +21,7 @@ EXTRA_DIST = \ icons/actions/drawing-orthoviews.svg \ icons/actions/drawing-openbrowser.svg \ icons/actions/drawing-annotation.svg \ + icons/actions/drawing-clip.svg \ icons/Page.svg \ icons/Pages.svg \ icons/View.svg \ diff --git a/src/Mod/Drawing/Gui/Resources/icons/actions/drawing-clip.svg b/src/Mod/Drawing/Gui/Resources/icons/actions/drawing-clip.svg new file mode 100644 index 000000000..dd58ec78a --- /dev/null +++ b/src/Mod/Drawing/Gui/Resources/icons/actions/drawing-clip.svg @@ -0,0 +1,710 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/src/Mod/Drawing/Gui/Workbench.cpp b/src/Mod/Drawing/Gui/Workbench.cpp index b7bd8bbce..e74f510e6 100644 --- a/src/Mod/Drawing/Gui/Workbench.cpp +++ b/src/Mod/Drawing/Gui/Workbench.cpp @@ -63,6 +63,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const *part << "Drawing_OrthoViews"; *part << "Drawing_OpenBrowserView"; *part << "Drawing_Annotation"; + *part << "Drawing_Clip"; *part << "Drawing_ExportPage"; return root; @@ -80,6 +81,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const *part << "Drawing_OrthoViews"; *part << "Drawing_OpenBrowserView"; *part << "Drawing_Annotation"; + *part << "Drawing_Clip"; *part << "Drawing_ExportPage"; return root; } @@ -97,6 +99,8 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const *img << "Drawing_NewPage"; *img << "Drawing_OrthoViews"; *img << "Drawing_OpenBrowserView"; + *img << "Drawing_Annotation"; + *img << "Drawing_Clip"; img = new Gui::ToolBarItem(root); img->setCommand("Views"); *img << "Drawing_NewView";