From 7c009c6deff0e421a0be7ba9b518c8601c58367f Mon Sep 17 00:00:00 2001 From: WandererFan Date: Thu, 14 Jan 2016 16:00:13 -0500 Subject: [PATCH] Add Mod/TechDraw/Gui --- src/Mod/TechDraw/Gui/AppTechDrawGui.cpp | 114 ++ src/Mod/TechDraw/Gui/AppTechDrawGuiPy.cpp | 217 +++ src/Mod/TechDraw/Gui/CMakeLists.txt | 191 +++ src/Mod/TechDraw/Gui/Command.cpp | 982 +++++++++++++ src/Mod/TechDraw/Gui/CommandCreateDims.cpp | 923 ++++++++++++ src/Mod/TechDraw/Gui/CommandDecorate.cpp | 160 +++ src/Mod/TechDraw/Gui/DlgPrefsDrawing.ui | 309 ++++ src/Mod/TechDraw/Gui/DlgPrefsDrawingImp.cpp | 79 ++ src/Mod/TechDraw/Gui/DlgPrefsDrawingImp.h | 50 + src/Mod/TechDraw/Gui/MDIViewPage.cpp | 1099 ++++++++++++++ src/Mod/TechDraw/Gui/MDIViewPage.h | 129 ++ src/Mod/TechDraw/Gui/PreCompiled.cpp | 24 + src/Mod/TechDraw/Gui/PreCompiled.h | 78 + src/Mod/TechDraw/Gui/QGCustomClip.cpp | 103 ++ src/Mod/TechDraw/Gui/QGCustomClip.h | 66 + src/Mod/TechDraw/Gui/QGCustomRect.cpp | 76 + src/Mod/TechDraw/Gui/QGCustomRect.h | 60 + src/Mod/TechDraw/Gui/QGCustomSvg.cpp | 65 + src/Mod/TechDraw/Gui/QGCustomSvg.h | 60 + src/Mod/TechDraw/Gui/QGCustomText.cpp | 103 ++ src/Mod/TechDraw/Gui/QGCustomText.h | 60 + src/Mod/TechDraw/Gui/QGIArrow.cpp | 112 ++ src/Mod/TechDraw/Gui/QGIArrow.h | 70 + src/Mod/TechDraw/Gui/QGIDrawingTemplate.cpp | 135 ++ src/Mod/TechDraw/Gui/QGIDrawingTemplate.h | 69 + src/Mod/TechDraw/Gui/QGIEdge.cpp | 179 +++ src/Mod/TechDraw/Gui/QGIEdge.h | 95 ++ src/Mod/TechDraw/Gui/QGIFace.cpp | 126 ++ src/Mod/TechDraw/Gui/QGIFace.h | 79 ++ src/Mod/TechDraw/Gui/QGIHatch.cpp | 193 +++ src/Mod/TechDraw/Gui/QGIHatch.h | 93 ++ src/Mod/TechDraw/Gui/QGIProjGroup.cpp | 231 +++ src/Mod/TechDraw/Gui/QGIProjGroup.h | 84 ++ src/Mod/TechDraw/Gui/QGISVGTemplate.cpp | 227 +++ src/Mod/TechDraw/Gui/QGISVGTemplate.h | 74 + src/Mod/TechDraw/Gui/QGITemplate.cpp | 75 + src/Mod/TechDraw/Gui/QGITemplate.h | 73 + src/Mod/TechDraw/Gui/QGIVertex.cpp | 134 ++ src/Mod/TechDraw/Gui/QGIVertex.h | 89 ++ src/Mod/TechDraw/Gui/QGIView.cpp | 379 +++++ src/Mod/TechDraw/Gui/QGIView.h | 112 ++ src/Mod/TechDraw/Gui/QGIViewAnnotation.cpp | 149 ++ src/Mod/TechDraw/Gui/QGIViewAnnotation.h | 75 + src/Mod/TechDraw/Gui/QGIViewClip.cpp | 192 +++ src/Mod/TechDraw/Gui/QGIViewClip.h | 74 + src/Mod/TechDraw/Gui/QGIViewCollection.cpp | 88 ++ src/Mod/TechDraw/Gui/QGIViewCollection.h | 69 + src/Mod/TechDraw/Gui/QGIViewDimension.cpp | 1263 +++++++++++++++++ src/Mod/TechDraw/Gui/QGIViewDimension.h | 133 ++ src/Mod/TechDraw/Gui/QGIViewPart.cpp | 654 +++++++++ src/Mod/TechDraw/Gui/QGIViewPart.h | 109 ++ src/Mod/TechDraw/Gui/QGIViewSection.cpp | 154 ++ src/Mod/TechDraw/Gui/QGIViewSection.h | 62 + src/Mod/TechDraw/Gui/QGIViewSymbol.cpp | 138 ++ src/Mod/TechDraw/Gui/QGIViewSymbol.h | 77 + src/Mod/TechDraw/Gui/QGVPage.cpp | 529 +++++++ src/Mod/TechDraw/Gui/QGVPage.h | 119 ++ src/Mod/TechDraw/Gui/TaskProjGroup.cpp | 413 ++++++ src/Mod/TechDraw/Gui/TaskProjGroup.h | 137 ++ src/Mod/TechDraw/Gui/TaskProjGroup.ui | 362 +++++ src/Mod/TechDraw/Gui/TemplateTextField.cpp | 61 + src/Mod/TechDraw/Gui/TemplateTextField.h | 64 + .../TechDraw/Gui/ViewProviderAnnotation.cpp | 86 ++ src/Mod/TechDraw/Gui/ViewProviderAnnotation.h | 61 + .../TechDraw/Gui/ViewProviderDimension.cpp | 86 ++ src/Mod/TechDraw/Gui/ViewProviderDimension.h | 62 + src/Mod/TechDraw/Gui/ViewProviderHatch.cpp | 86 ++ src/Mod/TechDraw/Gui/ViewProviderHatch.h | 61 + src/Mod/TechDraw/Gui/ViewProviderPage.cpp | 345 +++++ src/Mod/TechDraw/Gui/ViewProviderPage.h | 104 ++ .../TechDraw/Gui/ViewProviderProjGroup.cpp | 172 +++ src/Mod/TechDraw/Gui/ViewProviderProjGroup.h | 71 + .../Gui/ViewProviderProjGroupItem.cpp | 158 +++ .../TechDraw/Gui/ViewProviderProjGroupItem.h | 67 + src/Mod/TechDraw/Gui/ViewProviderSymbol.cpp | 86 ++ src/Mod/TechDraw/Gui/ViewProviderSymbol.h | 61 + src/Mod/TechDraw/Gui/ViewProviderTemplate.cpp | 89 ++ src/Mod/TechDraw/Gui/ViewProviderTemplate.h | 60 + src/Mod/TechDraw/Gui/ViewProviderView.cpp | 143 ++ src/Mod/TechDraw/Gui/ViewProviderView.h | 74 + src/Mod/TechDraw/Gui/ViewProviderViewClip.cpp | 147 ++ src/Mod/TechDraw/Gui/ViewProviderViewClip.h | 73 + src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp | 123 ++ src/Mod/TechDraw/Gui/ViewProviderViewPart.h | 61 + .../TechDraw/Gui/ViewProviderViewSection.cpp | 96 ++ .../TechDraw/Gui/ViewProviderViewSection.h | 61 + src/Mod/TechDraw/Gui/Workbench.cpp | 171 +++ src/Mod/TechDraw/Gui/Workbench.h | 51 + 88 files changed, 15154 insertions(+) create mode 100644 src/Mod/TechDraw/Gui/AppTechDrawGui.cpp create mode 100644 src/Mod/TechDraw/Gui/AppTechDrawGuiPy.cpp create mode 100644 src/Mod/TechDraw/Gui/CMakeLists.txt create mode 100644 src/Mod/TechDraw/Gui/Command.cpp create mode 100644 src/Mod/TechDraw/Gui/CommandCreateDims.cpp create mode 100644 src/Mod/TechDraw/Gui/CommandDecorate.cpp create mode 100644 src/Mod/TechDraw/Gui/DlgPrefsDrawing.ui create mode 100644 src/Mod/TechDraw/Gui/DlgPrefsDrawingImp.cpp create mode 100644 src/Mod/TechDraw/Gui/DlgPrefsDrawingImp.h create mode 100644 src/Mod/TechDraw/Gui/MDIViewPage.cpp create mode 100644 src/Mod/TechDraw/Gui/MDIViewPage.h create mode 100644 src/Mod/TechDraw/Gui/PreCompiled.cpp create mode 100644 src/Mod/TechDraw/Gui/PreCompiled.h create mode 100644 src/Mod/TechDraw/Gui/QGCustomClip.cpp create mode 100644 src/Mod/TechDraw/Gui/QGCustomClip.h create mode 100644 src/Mod/TechDraw/Gui/QGCustomRect.cpp create mode 100644 src/Mod/TechDraw/Gui/QGCustomRect.h create mode 100644 src/Mod/TechDraw/Gui/QGCustomSvg.cpp create mode 100644 src/Mod/TechDraw/Gui/QGCustomSvg.h create mode 100644 src/Mod/TechDraw/Gui/QGCustomText.cpp create mode 100644 src/Mod/TechDraw/Gui/QGCustomText.h create mode 100644 src/Mod/TechDraw/Gui/QGIArrow.cpp create mode 100644 src/Mod/TechDraw/Gui/QGIArrow.h create mode 100644 src/Mod/TechDraw/Gui/QGIDrawingTemplate.cpp create mode 100644 src/Mod/TechDraw/Gui/QGIDrawingTemplate.h create mode 100644 src/Mod/TechDraw/Gui/QGIEdge.cpp create mode 100644 src/Mod/TechDraw/Gui/QGIEdge.h create mode 100644 src/Mod/TechDraw/Gui/QGIFace.cpp create mode 100644 src/Mod/TechDraw/Gui/QGIFace.h create mode 100644 src/Mod/TechDraw/Gui/QGIHatch.cpp create mode 100644 src/Mod/TechDraw/Gui/QGIHatch.h create mode 100644 src/Mod/TechDraw/Gui/QGIProjGroup.cpp create mode 100644 src/Mod/TechDraw/Gui/QGIProjGroup.h create mode 100644 src/Mod/TechDraw/Gui/QGISVGTemplate.cpp create mode 100644 src/Mod/TechDraw/Gui/QGISVGTemplate.h create mode 100644 src/Mod/TechDraw/Gui/QGITemplate.cpp create mode 100644 src/Mod/TechDraw/Gui/QGITemplate.h create mode 100644 src/Mod/TechDraw/Gui/QGIVertex.cpp create mode 100644 src/Mod/TechDraw/Gui/QGIVertex.h create mode 100644 src/Mod/TechDraw/Gui/QGIView.cpp create mode 100644 src/Mod/TechDraw/Gui/QGIView.h create mode 100644 src/Mod/TechDraw/Gui/QGIViewAnnotation.cpp create mode 100644 src/Mod/TechDraw/Gui/QGIViewAnnotation.h create mode 100644 src/Mod/TechDraw/Gui/QGIViewClip.cpp create mode 100644 src/Mod/TechDraw/Gui/QGIViewClip.h create mode 100644 src/Mod/TechDraw/Gui/QGIViewCollection.cpp create mode 100644 src/Mod/TechDraw/Gui/QGIViewCollection.h create mode 100644 src/Mod/TechDraw/Gui/QGIViewDimension.cpp create mode 100644 src/Mod/TechDraw/Gui/QGIViewDimension.h create mode 100644 src/Mod/TechDraw/Gui/QGIViewPart.cpp create mode 100644 src/Mod/TechDraw/Gui/QGIViewPart.h create mode 100644 src/Mod/TechDraw/Gui/QGIViewSection.cpp create mode 100644 src/Mod/TechDraw/Gui/QGIViewSection.h create mode 100644 src/Mod/TechDraw/Gui/QGIViewSymbol.cpp create mode 100644 src/Mod/TechDraw/Gui/QGIViewSymbol.h create mode 100644 src/Mod/TechDraw/Gui/QGVPage.cpp create mode 100644 src/Mod/TechDraw/Gui/QGVPage.h create mode 100644 src/Mod/TechDraw/Gui/TaskProjGroup.cpp create mode 100644 src/Mod/TechDraw/Gui/TaskProjGroup.h create mode 100644 src/Mod/TechDraw/Gui/TaskProjGroup.ui create mode 100644 src/Mod/TechDraw/Gui/TemplateTextField.cpp create mode 100644 src/Mod/TechDraw/Gui/TemplateTextField.h create mode 100644 src/Mod/TechDraw/Gui/ViewProviderAnnotation.cpp create mode 100644 src/Mod/TechDraw/Gui/ViewProviderAnnotation.h create mode 100644 src/Mod/TechDraw/Gui/ViewProviderDimension.cpp create mode 100644 src/Mod/TechDraw/Gui/ViewProviderDimension.h create mode 100644 src/Mod/TechDraw/Gui/ViewProviderHatch.cpp create mode 100644 src/Mod/TechDraw/Gui/ViewProviderHatch.h create mode 100644 src/Mod/TechDraw/Gui/ViewProviderPage.cpp create mode 100644 src/Mod/TechDraw/Gui/ViewProviderPage.h create mode 100644 src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp create mode 100644 src/Mod/TechDraw/Gui/ViewProviderProjGroup.h create mode 100644 src/Mod/TechDraw/Gui/ViewProviderProjGroupItem.cpp create mode 100644 src/Mod/TechDraw/Gui/ViewProviderProjGroupItem.h create mode 100644 src/Mod/TechDraw/Gui/ViewProviderSymbol.cpp create mode 100644 src/Mod/TechDraw/Gui/ViewProviderSymbol.h create mode 100644 src/Mod/TechDraw/Gui/ViewProviderTemplate.cpp create mode 100644 src/Mod/TechDraw/Gui/ViewProviderTemplate.h create mode 100644 src/Mod/TechDraw/Gui/ViewProviderView.cpp create mode 100644 src/Mod/TechDraw/Gui/ViewProviderView.h create mode 100644 src/Mod/TechDraw/Gui/ViewProviderViewClip.cpp create mode 100644 src/Mod/TechDraw/Gui/ViewProviderViewClip.h create mode 100644 src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp create mode 100644 src/Mod/TechDraw/Gui/ViewProviderViewPart.h create mode 100644 src/Mod/TechDraw/Gui/ViewProviderViewSection.cpp create mode 100644 src/Mod/TechDraw/Gui/ViewProviderViewSection.h create mode 100644 src/Mod/TechDraw/Gui/Workbench.cpp create mode 100644 src/Mod/TechDraw/Gui/Workbench.h diff --git a/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp b/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp new file mode 100644 index 0000000000..a9d0118049 --- /dev/null +++ b/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp @@ -0,0 +1,114 @@ +/*************************************************************************** + * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2007 * + * * + * 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 +#endif + +#include +#include +#include +#include + +#include "Workbench.h" + +#include "DlgPrefsDrawingImp.h" +#include "ViewProviderPage.h" +#include "ViewProviderView.h" +#include "ViewProviderDimension.h" +#include "ViewProviderProjGroup.h" +#include "ViewProviderProjGroupItem.h" +#include "ViewProviderTemplate.h" +#include "ViewProviderViewPart.h" +#include "ViewProviderViewSection.h" +#include "ViewProviderAnnotation.h" +#include "ViewProviderSymbol.h" +#include "ViewProviderViewClip.h" +#include "ViewProviderHatch.h" +//#include "resources/qrc_Drawing.cpp" + +// use a different name to CreateCommand() +void CreateDrawingCommands(void); +void CreateDrawingCommandsDims(void); +void CreateDrawingCommandsDecorate(void); + +void loadDrawingResource() +{ + // add resources and reloads the translators + Q_INIT_RESOURCE(Drawing); + Gui::Translator::instance()->refresh(); +} + +/* registration table */ +extern struct PyMethodDef TechDrawGui_Import_methods[]; + + +/* Python entry */ +extern "C" { +void TechDrawGuiExport initTechDrawGui() +{ + if (!Gui::Application::Instance) { + PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application."); + return; + } + + (void) Py_InitModule("TechDrawGui", TechDrawGui_Import_methods); /* mod name, table ptr */ + Base::Console().Log("Loading GUI of Drawing module... done\n"); + + // instantiating the commands + CreateDrawingCommands(); + CreateDrawingCommandsDims(); + CreateDrawingCommandsDecorate(); + + TechDrawGui::Workbench::init(); + + //TODO: is this platform independent?? should osifont be added by installer? + //Load the osifont for Drawing View + // See https://code.google.com/p/osifont/ + QFontDatabase fontDB; + fontDB.addApplicationFont(QString::fromAscii(":/fonts/osifont.ttf")); + + TechDrawGui::ViewProviderDrawingPage::init(); + TechDrawGui::ViewProviderView::init(); + + TechDrawGui::ViewProviderTemplate::init(); + TechDrawGui::ViewProviderDimension::init(); + TechDrawGui::ViewProviderViewPart::init(); + TechDrawGui::ViewProviderProjGroupItem::init(); + TechDrawGui::ViewProviderProjGroup::init(); + TechDrawGui::ViewProviderViewSection::init(); + TechDrawGui::ViewProviderDrawingClip::init(); + TechDrawGui::ViewProviderAnnotation::init(); + TechDrawGui::ViewProviderSymbol::init(); + TechDrawGui::ViewProviderHatch::init(); + + // register preferences pages + new Gui::PrefPageProducer ("Drawing"); + + // add resources and reloads the translators + loadDrawingResource(); +} + +} // extern "C" { diff --git a/src/Mod/TechDraw/Gui/AppTechDrawGuiPy.cpp b/src/Mod/TechDraw/Gui/AppTechDrawGuiPy.cpp new file mode 100644 index 0000000000..46799aa1fe --- /dev/null +++ b/src/Mod/TechDraw/Gui/AppTechDrawGuiPy.cpp @@ -0,0 +1,217 @@ +/*************************************************************************** + * Copyright (c) 2006 Werner Mayer * + * * + * 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 +#endif + +#include "MDIViewPage.h" +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace TechDrawGui; + + +/* module functions */ +static PyObject * +open(PyObject *self, PyObject *args) +{ + char* Name; + if (!PyArg_ParseTuple(args, "et","utf-8",&Name)) + return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); + + PY_TRY { + Base::FileInfo file(EncodedName.c_str()); + if (file.hasExtension("svg") || file.hasExtension("svgz")) { + QString fileName = QString::fromUtf8(EncodedName.c_str()); +#if 0 + // Displaying the image in a view + MDIViewPage* view = new MDIViewPage(0, 0, Gui::getMainWindow()); //TODO: hack to get a compile + view->load(fileName); + view->setWindowIcon(Gui::BitmapFactory().pixmap("actions/techdraw-landscape")); + QFileInfo fi(fileName); + view->setWindowTitle(fi.fileName()); + view->resize( 400, 300 ); + Gui::getMainWindow()->addWindow(view); +#endif + } + else { + PyErr_SetString(Base::BaseExceptionFreeCADError, "unknown filetype"); + return NULL; + } + } PY_CATCH; + + Py_Return; +} + +/* module functions */ +static PyObject * +importer(PyObject *self, PyObject *args) +{ + char* Name; + const char* dummy; + if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&dummy)) + return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); + + PY_TRY { + Base::FileInfo file(EncodedName.c_str()); + if (file.hasExtension("svg") || file.hasExtension("svgz")) { + QString fileName = QString::fromUtf8(EncodedName.c_str()); + +#if 0 + // Displaying the image in a view + MDIViewPage* view = new MDIViewPage(0, 0, Gui::getMainWindow()); //TODO: hack to get a compile + view->load(fileName); + view->setWindowIcon(Gui::BitmapFactory().pixmap("actions/techdraw-landscape")); + QFileInfo fi(fileName); + view->setWindowTitle(fi.fileName()); + view->resize( 400, 300 ); + Gui::getMainWindow()->addWindow(view); +#endif + } else { + PyErr_SetString(Base::BaseExceptionFreeCADError, "unknown filetype"); + return NULL; + } + } PY_CATCH; + + Py_Return; +} + +static PyObject * +exporter(PyObject *self, PyObject *args) +{ + PyObject* object; + char* Name; + if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name)) + return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); + + PY_TRY { + Py::Sequence list(object); + for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { + PyObject* item = (*it).ptr(); + if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) { + App::DocumentObject* obj = static_cast(item)->getDocumentObjectPtr(); + if (obj->getTypeId().isDerivedFrom(TechDraw::DrawPage::getClassTypeId())) { + Base::FileInfo fi_out(EncodedName.c_str()); + Base::ofstream str_out(fi_out, std::ios::out | std::ios::binary); + if (!str_out) { + std::stringstream str; + str << "Cannot open file '" << EncodedName << "' for writing"; + PyErr_SetString(PyExc_IOError, str.str().c_str()); + return NULL; + } + if (fi_out.hasExtension("svg")) { +// std::string fn = static_cast(obj)->PageResult.getValue(); + std::string fn; + Base::FileInfo fi_in(fn); + Base::ifstream str_in(fi_in, std::ios::in | std::ios::binary); + if (!str_in) { + std::stringstream str; + str << "Cannot open file '" << fn << "' for reading"; + PyErr_SetString(PyExc_IOError, str.str().c_str()); + return NULL; + } + + str_in >> str_out.rdbuf(); + str_in.close(); + str_out.close(); + break; + } + else if (fi_out.hasExtension("dxf")) { + const std::vector& views = static_cast(obj)->Views.getValues(); + for (std::vector::const_iterator it = views.begin(); it != views.end(); ++it) { + if ((*it)->getTypeId().isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) { + TechDraw::DrawViewPart* view = static_cast(*it); + std::string viewName = view->Label.getValue(); + App::DocumentObject* link = view->Source.getValue(); + if (!link) { + PyErr_SetString(Base::BaseExceptionFreeCADError, "No object linked"); + return 0; + } + if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + PyErr_SetString(PyExc_TypeError, "Linked object is not a Part object"); + return 0; + } + TopoDS_Shape shape = static_cast(link)->Shape.getShape()._Shape; + if (!shape.IsNull()) { + Base::Vector3d dir = view->Direction.getValue(); + bool hidden = view->ShowHiddenLines.getValue(); + bool smooth = view->ShowSmoothLines.getValue(); + TechDraw::ProjectionAlgos::ExtractionType type = TechDraw::ProjectionAlgos::Plain; + if (hidden) type = (TechDraw::ProjectionAlgos::ExtractionType)(type|TechDraw::ProjectionAlgos::WithHidden); + if (smooth) type = (TechDraw::ProjectionAlgos::ExtractionType)(type|TechDraw::ProjectionAlgos::WithSmooth); + float scale = view->Scale.getValue(); + float tol = view->Tolerance.getValue(); + + TechDraw::ProjectionAlgos project(shape, dir); + str_out << project.getDXF(type, scale, tol); + break; // TODO: How to add several shapes? + } + } + } + str_out.close(); + break; + } + else { + PyErr_SetString(PyExc_TypeError, "Export of page object as this file format is not supported by Drawing module"); + return 0; + } + } + else { + PyErr_SetString(PyExc_TypeError, "Export of this object type is not supported by Drawing module"); + return 0; + } + } + } + } PY_CATCH; + + Py_Return; +} + +/* registration table */ +struct PyMethodDef TechDrawGui_Import_methods[] = { + {"open" ,open , METH_VARARGS}, /* method name, C func ptr, always-tuple */ + {"insert" ,importer, METH_VARARGS}, + {"export" ,exporter, METH_VARARGS}, + {NULL, NULL} /* end of table marker */ +}; diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt new file mode 100644 index 0000000000..5dca4481a7 --- /dev/null +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -0,0 +1,191 @@ +if(MSVC) + add_definitions(-DHAVE_ATANH -DHAVE_ASINH -DHAVE_ACOSH) +else(MSVC) + add_definitions(-DHAVE_LIMITS_H -DHAVE_CONFIG_H) +endif(MSVC) + +include_directories( + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/src + ${CMAKE_CURRENT_BINARY_DIR} + ${Boost_INCLUDE_DIRS} + ${COIN3D_INCLUDE_DIRS} + ${PYTHON_INCLUDE_DIRS} + ${QT_INCLUDE_DIR} + ${QT_USE_QTXML} + ${OCC_INCLUDE_DIR} + ${ZLIB_INCLUDE_DIR} + ${XercesC_INCLUDE_DIRS} +) +link_directories(${OCC_LIBRARY_DIR}) + +set(TechDrawGui_LIBS + Drawing + FreeCADGui +) + + +set(TechDrawGui_MOC_HDRS + MDIViewPage.h + QGVPage.h + QGITemplate.h + QGISVGTemplate.h + QGIDrawingTemplate.h + QGIView.h + QGIViewCollection.h + QGIViewDimension.h + QGIProjGroup.h + QGIViewPart.h + QGIViewSection.h + QGIViewAnnotation.h + QGIViewSymbol.h + QGIViewClip.h + TaskProjGroup.h + TemplateTextField.h + DlgPrefsDrawingImp.h +) + +fc_wrap_cpp(TechDrawGui_MOC_SRCS ${TechDrawGui_MOC_HDRS}) +SOURCE_GROUP("Moc" FILES ${TechDrawGui_MOC_SRCS}) + +qt4_add_resources(TechDrawGui_SRCS Resources/Drawing.qrc) + +set(TechDrawGui_UIC_SRCS + DlgPrefsDrawing.ui + TaskProjGroup.ui +) + +qt4_wrap_ui(TechDrawGui_UIC_HDRS ${TechDrawGui_UIC_SRCS}) + +SET(TechDrawGui_SRCS + ${TechDrawGui_SRCS} + AppTechDrawGui.cpp + AppTechDrawGuiPy.cpp + Command.cpp + CommandCreateDims.cpp + CommandDecorate.cpp + Resources/Drawing.qrc + PreCompiled.cpp + PreCompiled.h + Workbench.cpp + Workbench.h + TaskProjGroup.ui + TaskProjGroup.cpp + TaskProjGroup.h + DlgPrefsDrawing.ui + DlgPrefsDrawingImp.cpp + DlgPrefsDrawingImp.h + +) +SET(TechDrawGuiView_SRCS + MDIViewPage.cpp + MDIViewPage.h + QGVPage.cpp + QGVPage.h + QGCustomText.cpp + QGCustomText.h + QGCustomRect.cpp + QGCustomRect.h + QGCustomSvg.cpp + QGCustomSvg.h + QGCustomClip.cpp + QGCustomClip.h + QGIView.cpp + QGIView.h + QGIArrow.cpp + QGIArrow.h + QGIEdge.cpp + QGIEdge.h + QGIFace.cpp + QGIFace.h + QGISVGTemplate.cpp + QGISVGTemplate.h + QGIVertex.cpp + QGIVertex.h + QGIDrawingTemplate.cpp + QGIDrawingTemplate.h + QGITemplate.cpp + QGITemplate.h + QGIViewCollection.cpp + QGIViewCollection.h + QGIViewDimension.cpp + QGIViewDimension.h + QGIProjGroup.cpp + QGIProjGroup.h + QGIViewPart.cpp + QGIViewPart.h + QGIViewSection.cpp + QGIViewSection.h + QGIViewAnnotation.cpp + QGIViewAnnotation.h + QGIViewSymbol.cpp + QGIViewSymbol.h + QGIViewClip.cpp + QGIViewClip.h + QGIHatch.cpp + QGIHatch.h + TemplateTextField.cpp + TemplateTextField.h +) +SET(TechDrawGuiViewProvider_SRCS + ViewProviderPage.cpp + ViewProviderPage.h + ViewProviderView.cpp + ViewProviderView.h + ViewProviderProjGroupItem.cpp + ViewProviderProjGroupItem.h + ViewProviderTemplate.cpp + ViewProviderTemplate.h + ViewProviderDimension.cpp + ViewProviderDimension.h + ViewProviderViewPart.cpp + ViewProviderViewPart.h + ViewProviderProjGroup.cpp + ViewProviderProjGroup.h + ViewProviderViewSection.cpp + ViewProviderViewSection.h + ViewProviderAnnotation.cpp + ViewProviderAnnotation.h + ViewProviderSymbol.cpp + ViewProviderSymbol.h + ViewProviderViewClip.cpp + ViewProviderViewClip.h + ViewProviderHatch.cpp + ViewProviderHatch.h +) + +SOURCE_GROUP("Mod" FILES ${TechDrawGui_SRCS}) +SOURCE_GROUP("SVG-View" FILES ${TechDrawGuiView_SRCS}) +SOURCE_GROUP("ViewProvider" FILES ${TechDrawGuiViewProvider_SRCS}) + +SET(TechDrawGuiTaskDlgs_SRCS + TaskProjGroup.ui +) +SOURCE_GROUP("TaskDialogs" FILES ${TechDrawGuiTaskDlgs_SRCS}) + +if(MSVC) + #add_definitions(-D_PreComp_) + #GET_MSVC_PRECOMPILED_SOURCE("PreCompiled.cpp" PCH_SRCS ${TechDrawGui_SRCS} ${TechDrawGuiView_SRCS} ${TechDrawGuiViewProvider_SRCS}) + #ADD_MSVC_PRECOMPILED_HEADER(TechDrawGui PreCompiled.h PreCompiled.cpp PCH_SRCS) +endif(MSVC) + +add_library(TechDrawGui SHARED ${TechDrawGui_SRCS} ${TechDrawGuiView_SRCS} ${TechDrawGuiViewProvider_SRCS}) +target_link_libraries(TechDrawGui ${TechDrawGui_LIBS}) + +fc_target_copy_resource(TechDrawGui + ${CMAKE_SOURCE_DIR}/src/Mod/Drawing + ${CMAKE_BINARY_DIR}/Mod/Drawing + InitGui.py) + +SET(TechDrawGuiIcon_SVG + Resources/icons/preferences-drawing.svg +) + +fc_copy_sources(TechDrawGui "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Mod/Drawing" ${TechDrawGuiIcon_SVG}) + +INSTALL(FILES ${TechDrawGuiIcon_SVG} DESTINATION "${CMAKE_INSTALL_DATADIR}/Mod/DrawingFem/Resources/icons") + +SET_BIN_DIR(TechDrawGui TechDrawGui /Mod/Drawing) +SET_PYTHON_PREFIX_SUFFIX(TechDrawGui) + +INSTALL(TARGETS TechDrawGui DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp new file mode 100644 index 0000000000..aeb9208a2a --- /dev/null +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -0,0 +1,982 @@ +/*************************************************************************** + * * + * 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 * + * Copyright (c) 2014 Luke Parry * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +# include +# include +# include +# include +#endif + +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include "MDIViewPage.h" +#include "TaskDialog.h" +#include "TaskProjGroup.h" +#include "ViewProviderPage.h" + +using namespace TechDrawGui; +using namespace std; + +bool isDrawingPageActive(Gui::Document *doc) +{ + if (doc) + // checks if a Sketch Viewprovider is in Edit and is in no special mode + if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom(TechDrawGui::ViewProviderDrawingPage::getClassTypeId())) + return true; + return false; +} + +//TODO: check if obsolete. +//=========================================================================== +// CmdDrawingOpen +//=========================================================================== + +DEF_STD_CMD(CmdDrawingOpen); + +CmdDrawingOpen::CmdDrawingOpen() + : Command("Drawing_Open") +{ + sAppModule = "Drawing"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Open SVG..."); + sToolTipText = QT_TR_NOOP("Open a scalable vector graphic"); + sWhatsThis = "Drawing_Open"; + sStatusTip = sToolTipText; + sPixmap = "actions/document-new"; +} + + +void CmdDrawingOpen::activated(int iMsg) +{ + // Reading an image + QString filename = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), QObject::tr("Choose an SVG file to open"), QString::null, + QString::fromLatin1("%1 (*.svg *.svgz)").arg(QObject::tr("Scalable Vector Graphic"))); + if (!filename.isEmpty()) + { + // load the file with the module + Command::doCommand(Command::Gui, "import Drawing, TechDrawGui"); + Command::doCommand(Command::Gui, "TechDrawGui.open(unicode(\"%s\",\"utf-8\"))", (const char*)filename.toUtf8()); + } +} + +//=========================================================================== +// Drawing_NewPageDef (default template) +//=========================================================================== + +DEF_STD_CMD(CmdDrawingNewPageDef); + +CmdDrawingNewPageDef::CmdDrawingNewPageDef() + : Command("Drawing_NewPageDef") +{ + sAppModule = "Drawing"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Insert new default drawing page"); + sToolTipText = QT_TR_NOOP("Insert new default drawing page"); + sWhatsThis = "Drawing_NewPageDef"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-new-default"; +} + +void CmdDrawingNewPageDef::activated(int iMsg) +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Drawing"); + + std::string defaultDir = App::Application::getResourceDir() + "Mod/Drawing/Templates"; + QString templateDir = QString::fromStdString(hGrp->GetASCII("TemplateDir", defaultDir.c_str())); + if (templateDir.isEmpty()) { //preference key can be present, but have null value + templateDir = QString::fromStdString(defaultDir); + } + std::string defaultFileName = "A4_Landscape.svg"; + QString templateFileName = QString::fromStdString(hGrp->GetASCII("TemplateFile",defaultFileName.c_str())); + if (templateFileName.isEmpty()) { + templateFileName = QString::fromStdString(defaultFileName); + } + templateFileName = templateDir + QString::fromUtf8("/") + templateFileName; + + std::string PageName = getUniqueObjectName("Page"); + std::string TemplateName = getUniqueObjectName("Template"); + + QFileInfo tfi(templateFileName); + if (tfi.isReadable()) { + Gui::WaitCursor wc; + openCommand("Drawing create page"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawPage','%s')",PageName.c_str()); + + // Create the Template Object to attach to the page + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawSVGTemplate','%s')",TemplateName.c_str()); + + //TODO: why is "Template" property set twice? + doCommand(Doc,"App.activeDocument().%s.Template = '%s'",TemplateName.c_str(), templateFileName.toStdString().c_str()); + doCommand(Doc,"App.activeDocument().%s.Template = App.activeDocument().%s",PageName.c_str(),TemplateName.c_str()); + + commitCommand(); + TechDraw::DrawPage* fp = dynamic_cast(getDocument()->getObject(PageName.c_str())); + Gui::ViewProvider* vp = Gui::Application::Instance->getDocument(getDocument())->getViewProvider(fp); + TechDrawGui::ViewProviderDrawingPage* dvp = dynamic_cast(vp); + if (dvp) { + dvp->show(); + } + else { + Base::Console().Log("INFO - Template: %s for Page: %s NOT Found\n", PageName.c_str(),TemplateName.c_str()); + } + } + else { + QMessageBox::critical(Gui::getMainWindow(), + QLatin1String("No template"), + QLatin1String("No default template found")); + } +} + +//=========================================================================== +// Drawing_NewPage (with template choice) +//=========================================================================== + +DEF_STD_CMD(CmdDrawingNewPage); + +CmdDrawingNewPage::CmdDrawingNewPage() + : Command("Drawing_NewPage") +{ + sAppModule = "Drawing"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Insert new drawing page from template"); + sToolTipText = QT_TR_NOOP("Insert new drawing page from template"); + sWhatsThis = "Drawing_NewPage"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-new-pick"; +} + +void CmdDrawingNewPage::activated(int iMsg) +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Drawing"); + + std::string defaultDir = App::Application::getResourceDir() + "Mod/Drawing/Templates"; + QString templateDir = QString::fromStdString(hGrp->GetASCII("TemplateDir", defaultDir.c_str())); + + //TODO: Some templates are too complex for regex? + QString templateFileName = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), + QString::fromUtf8(QT_TR_NOOP("Select a Template File")), + templateDir, + QString::fromUtf8(QT_TR_NOOP("Template (*.svg *.dxf)"))); + + if (templateFileName.isEmpty()) { + QMessageBox::critical(Gui::getMainWindow(), + QLatin1String("No template"), + QLatin1String("Must select a valid template file")); + return; + } + + std::string PageName = getUniqueObjectName("Page"); + std::string TemplateName = getUniqueObjectName("Template"); + + QFileInfo tfi(templateFileName); + if (tfi.isReadable()) { + Gui::WaitCursor wc; + openCommand("Drawing create page"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawPage','%s')",PageName.c_str()); + + // Create the Template Object to attach to the page + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawSVGTemplate','%s')",TemplateName.c_str()); + + //why is "Template" property set twice? -wf + // once to set DrawSVGTemplate.Template to OS template file name + doCommand(Doc,"App.activeDocument().%s.Template = '%s'",TemplateName.c_str(), templateFileName.toStdString().c_str()); + // once to set Page.Template to DrawSVGTemplate.Name + doCommand(Doc,"App.activeDocument().%s.Template = App.activeDocument().%s",PageName.c_str(),TemplateName.c_str()); + // consider renaming DrawSVGTemplate.Template property? + + commitCommand(); + TechDraw::DrawPage* fp = dynamic_cast(getDocument()->getObject(PageName.c_str())); + Gui::ViewProvider* vp = Gui::Application::Instance->getDocument(getDocument())->getViewProvider(fp); + TechDrawGui::ViewProviderDrawingPage* dvp = dynamic_cast(vp); + if (dvp) { + dvp->show(); + } + else { + Base::Console().Log("INFO - Template: %s for Page: %s NOT Found\n", PageName.c_str(),TemplateName.c_str()); + } + } + else { + QMessageBox::critical(Gui::getMainWindow(), + QLatin1String("No template"), + QLatin1String("Template file is invalid")); + } +} + +//TODO: check if obsolete +//=========================================================================== +// Drawing_NewA3Landscape +//=========================================================================== + +DEF_STD_CMD_A(CmdDrawingNewA3Landscape); + +CmdDrawingNewA3Landscape::CmdDrawingNewA3Landscape() + : Command("Drawing_NewA3Landscape") +{ + sAppModule = "Drawing"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Insert new A3 landscape drawing"); + sToolTipText = QT_TR_NOOP("Insert new A3 landscape drawing"); + sWhatsThis = "Drawing_NewA3Landscape"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-landscape-A3"; +} + +void CmdDrawingNewA3Landscape::activated(int iMsg) +{ + std::string FeatName = getUniqueObjectName("Page"); + + openCommand("Create page"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawPage','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Template = 'A3_Landscape.svg'",FeatName.c_str()); +// doCommand(Doc,"App.activeDocument().recompute()"); + commitCommand(); +} + +bool CmdDrawingNewA3Landscape::isActive(void) +{ + if (getActiveGuiDocument()) + return true; + else + return false; +} + + +//=========================================================================== +// Drawing_NewView +//=========================================================================== + +DEF_STD_CMD(CmdDrawingNewView); + +CmdDrawingNewView::CmdDrawingNewView() + : Command("Drawing_NewView") +{ + sAppModule = "Drawing"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Insert view in drawing"); + sToolTipText = QT_TR_NOOP("Insert a new View of a Part in the active drawing"); + sWhatsThis = "Drawing_NewView"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-view"; +} + +void CmdDrawingNewView::activated(int iMsg) +{ + std::vector shapes = getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); + if (shapes.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select a Part object.")); + return; + } + +// std::vector pages = getSelection().getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + if (pages.empty()) { + //pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + //if (pages.empty()){ + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"), + QObject::tr("Create a page first.")); + return; + //} + } + + Gui::WaitCursor wc; + const std::vector selectedProjections = getSelection().getObjectsOfType(TechDraw::DrawView::getClassTypeId()); + float newX = 10.0; + float newY = 10.0; + float newScale = 1.0; + float newRotation = 0.0; + Base::Vector3d newDirection(0.0, 0.0, 1.0); + if (!selectedProjections.empty()) { + const TechDraw::DrawView* const myView = dynamic_cast(selectedProjections.front()); + + newX = myView->X.getValue(); + newY = myView->Y.getValue(); + newScale = myView->Scale.getValue(); + newRotation = myView->Rotation.getValue(); + + // The "Direction" property does not belong to TechDraw::DrawView, but to one of the + // many child classes that are projecting objects into the drawing. Therefore, we get the + // property by name. + const App::PropertyVector* const propDirection = dynamic_cast(myView->getPropertyByName("Direction")); + if (propDirection) { + newDirection = propDirection->getValue(); + } + } + + std::string PageName = pages.front()->getNameInDocument(); + + openCommand("Create view"); + for (std::vector::iterator it = shapes.begin(); it != shapes.end(); ++it) { + std::string FeatName = getUniqueObjectName("View"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewPart','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),(*it)->getNameInDocument()); + doCommand(Doc,"App.activeDocument().%s.Direction = (%e,%e,%e)",FeatName.c_str(), newDirection.x, newDirection.y, newDirection.z); + doCommand(Doc,"App.activeDocument().%s.X = %e",FeatName.c_str(), newX); + doCommand(Doc,"App.activeDocument().%s.Y = %e",FeatName.c_str(), newY); + doCommand(Doc,"App.activeDocument().%s.Scale = %e",FeatName.c_str(), newScale); + doCommand(Doc,"App.activeDocument().%s.Rotation = %e",FeatName.c_str(), newRotation); + //doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + TechDraw::DrawPage *page = dynamic_cast(pages.front()); + //TODO: page->addView sb Python function?? + page->addView(page->getDocument()->getObject(FeatName.c_str())); + } + updateActive(); + commitCommand(); +} +//=========================================================================== +// Drawing_NewViewSection +//=========================================================================== + +DEF_STD_CMD(CmdDrawingNewViewSection); + +CmdDrawingNewViewSection::CmdDrawingNewViewSection() + : Command("Drawing_NewViewSection") +{ + sAppModule = "Drawing"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Insert section view in drawing"); + sToolTipText = QT_TR_NOOP("Insert a new Section View of a Part in the active drawing"); + sWhatsThis = "Drawing_NewViewSecton"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-viewsection"; +} + +void CmdDrawingNewViewSection::activated(int iMsg) +{ + std::vector shapes = getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); + if (shapes.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select a Part object.")); + return; + } + + std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::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(); + + openCommand("Create view"); + for (std::vector::iterator it = shapes.begin(); it != shapes.end(); ++it) { + std::string FeatName = getUniqueObjectName("View"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewSection','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),(*it)->getNameInDocument()); + doCommand(Doc,"App.activeDocument().%s.Direction = (0.0,0.0,1.0)",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.X = 10.0",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Y = 10.0",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Scale = 1.0",FeatName.c_str()); +// doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",PageName.c_str(),); + TechDraw::DrawPage *page = dynamic_cast(pages.front()); + page->addView(page->getDocument()->getObject(FeatName.c_str())); + } + updateActive(); + commitCommand(); +} + + +//=========================================================================== +// Drawing_ProjGroup +//=========================================================================== + +DEF_STD_CMD_A(CmdDrawingProjGroup); + +CmdDrawingProjGroup::CmdDrawingProjGroup() + : Command("Drawing_ProjGroup") +{ + sAppModule = "Drawing"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Insert Projection Group"); + sToolTipText = QT_TR_NOOP("Insert 2D Projections of a 3D part into the active drawing"); + sWhatsThis = "Drawing_ProjGroup"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-projgroup"; +} + +void CmdDrawingProjGroup::activated(int iMsg) +{ + // Check that a Part::Feature is in the Selection + std::vector shapes = getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); + if (shapes.size() != 1) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select exactly one Part object.")); + return; + } + + // Check if a Drawing Page is in the Selection. + TechDraw::DrawPage *page; + const std::vector selPages = getSelection().getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + if (!selPages.empty()) { + page = dynamic_cast(selPages.front()); + } else { + // Check that any page object exists in Document + const std::vector docPages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + if (!docPages.empty()) { + page = dynamic_cast(docPages.front()); + } else { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No Drawing Page found"), + QObject::tr("Create a Drawing Page first.")); + return; + } + } +// TODO: is there a way to use "Active Page" instead of pages.front? if a second page is in the document, we will always +// use page#1 if there isn't a page in the selection. + + openCommand("Create Projection Group"); + std::string multiViewName = getUniqueObjectName("cView"); + std::string SourceName = (*shapes.begin())->getNameInDocument(); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawProjGroup','%s')",multiViewName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",multiViewName.c_str(),SourceName.c_str()); + doCommand(Doc,"App.activeDocument().%s.X = %f", multiViewName.c_str(), page->getPageWidth() / 2); + doCommand(Doc,"App.activeDocument().%s.Y = %f", multiViewName.c_str(), page->getPageHeight() / 2); + doCommand(Doc,"App.activeDocument().%s.Scale = 1.0",multiViewName.c_str()); + + App::DocumentObject *docObj = getDocument()->getObject(multiViewName.c_str()); + TechDraw::DrawProjGroup *multiView = dynamic_cast(docObj); + + // set the anchor + App::DocumentObject* anchorView = multiView->addProjection("Front"); + std::string anchorName = anchorView->getNameInDocument(); + doCommand(Doc,"App.activeDocument().%s.Anchor = App.activeDocument().%s",multiViewName.c_str(),anchorName.c_str()); + + // create the rest of the desired views + Gui::Control().showDialog(new TaskDlgProjGroup(multiView)); + + // add the multiView to the page + page->addView(getDocument()->getObject(multiViewName.c_str())); + + updateActive(); + commitCommand(); +} + +bool CmdDrawingProjGroup::isActive(void) +{ + if (Gui::Control().activeDialog()) + return false; + return true; +} + + +//=========================================================================== +// Drawing_OpenBrowserView +//=========================================================================== + +DEF_STD_CMD_A(CmdDrawingOpenBrowserView); + +CmdDrawingOpenBrowserView::CmdDrawingOpenBrowserView() + : Command("Drawing_OpenBrowserView") +{ + // seting the + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Open &browser view"); + sToolTipText = QT_TR_NOOP("Opens the selected page in a browser view"); + sWhatsThis = "Drawing_OpenBrowserView"; + sStatusTip = QT_TR_NOOP("Opens the selected page in a browser view"); + sPixmap = "actions/techdraw-openbrowser"; +} + +void CmdDrawingOpenBrowserView::activated(int iMsg) +{ + unsigned int n = getSelection().countObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + if (n != 1) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select one Page object.")); + return; + } + std::vector Sel = getSelection().getSelection(); + doCommand(Doc,"PageName = App.activeDocument().%s.PageResult",Sel[0].FeatName); + doCommand(Doc,"import WebGui"); + doCommand(Doc,"WebGui.openBrowser(PageName)"); +} + +bool CmdDrawingOpenBrowserView::isActive(void) +{ + return (getActiveGuiDocument() ? true : false); +} + +//=========================================================================== +// Drawing_Annotation +//=========================================================================== + +DEF_STD_CMD_A(CmdDrawingAnnotation); + +CmdDrawingAnnotation::CmdDrawingAnnotation() + : Command("Drawing_Annotation") +{ + // setting the Gui eye-candy + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("&Annotation"); + sToolTipText = QT_TR_NOOP("Inserts an Annotation in the active drawing"); + sWhatsThis = "Drawing_Annotation"; + sStatusTip = QT_TR_NOOP("Inserts an Annotation in the active drawing"); + sPixmap = "actions/techdraw-annotation"; +} + +void CmdDrawingAnnotation::activated(int iMsg) +{ +// std::vector pages = getSelection().getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + if (pages.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"), + QObject::tr("Create a page first.")); + return; + } + std::string PageName = pages.front()->getNameInDocument(); + std::string FeatName = getUniqueObjectName("Annotation"); + openCommand("Create Annotation"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewAnnotation','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.X = 10.0",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Y = 10.0",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Scale = 7.0",FeatName.c_str()); + //doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + TechDraw::DrawPage *page = dynamic_cast(pages.front()); + page->addView(page->getDocument()->getObject(FeatName.c_str())); + updateActive(); + commitCommand(); +} + +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_Clip"; + sStatusTip = QT_TR_NOOP("Inserts a clip group in the active drawing"); + sPixmap = "actions/techdraw-clip"; +} + +void CmdDrawingClip::activated(int iMsg) +{ + +// std::vector pages = getSelection().getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + if (pages.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"), + QObject::tr("Create a page first.")); + return; + } + + std::string PageName = pages.front()->getNameInDocument(); + std::string FeatName = getUniqueObjectName("Clip"); + openCommand("Create Clip"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewClip','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.ShowFrame = True",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Height = 30.0",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Width = 30.0",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.ShowLabels = False",FeatName.c_str()); + TechDraw::DrawPage *page = dynamic_cast(pages.front()); + page->addView(page->getDocument()->getObject(FeatName.c_str())); + updateActive(); + commitCommand(); +} + +bool CmdDrawingClip::isActive(void) +{ + return (getActiveGuiDocument() ? true : false); +} + +//=========================================================================== +// Drawing_ClipPlus +//=========================================================================== + +DEF_STD_CMD_A(CmdDrawingClipPlus); + +CmdDrawingClipPlus::CmdDrawingClipPlus() + : Command("Drawing_ClipPlus") +{ + // seting the + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("&ClipPlus"); + sToolTipText = QT_TR_NOOP("Add a View to a clip group in the active drawing"); + sWhatsThis = "Drawing_ClipPlus"; + sStatusTip = QT_TR_NOOP("Adds a View into a clip group in the active drawing"); + sPixmap = "actions/techdraw-clipplus"; +} + +void CmdDrawingClipPlus::activated(int iMsg) +{ + + std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + if (pages.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"), + QObject::tr("Create a page first.")); + return; + } + + std::vector views = getSelection().getObjectsOfType(TechDraw::DrawView::getClassTypeId()); + if (views.size() != 2) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select exactly one Clip and one View object.")); + return; + } + + TechDraw::DrawViewClip* clip; + TechDraw::DrawView* view; + std::vector::iterator it = views.begin(); + for (; it != views.end(); it++) { + if ((*it)->isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId())) { + clip = dynamic_cast ((*it)); + } else { + view = dynamic_cast ((*it)); + } + } + + if (!view) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select exactly one Drawing View object.")); + return; + } + if (!clip) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select exactly one Clip object.")); + return; + } + + openCommand("ClipPlus"); + clip->addView(view); + updateActive(); + commitCommand(); +} + +bool CmdDrawingClipPlus::isActive(void) +{ + return (getActiveGuiDocument() ? true : false); +} + +//=========================================================================== +// Drawing_ClipMinus +//=========================================================================== + +DEF_STD_CMD_A(CmdDrawingClipMinus); + +CmdDrawingClipMinus::CmdDrawingClipMinus() + : Command("Drawing_ClipMinus") +{ + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("&ClipMinus"); + sToolTipText = QT_TR_NOOP("Remove a View from a clip group in the active drawing"); + sWhatsThis = "Drawing_ClipMinus"; + sStatusTip = QT_TR_NOOP("Remove a View from a clip group in the active drawing"); + sPixmap = "actions/techdraw-clipminus"; +} + +void CmdDrawingClipMinus::activated(int iMsg) +{ + + std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + if (pages.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"), + QObject::tr("Create a page first.")); + return; + } + + std::vector views = getSelection().getObjectsOfType(TechDraw::DrawView::getClassTypeId()); + if (views.size() != 2) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select exactly one Clip and one View object.")); + return; + } + + TechDraw::DrawViewClip* clip; + TechDraw::DrawView* view; + std::vector::iterator it = views.begin(); + for (; it != views.end(); it++) { + if ((*it)->isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId())) { + clip = dynamic_cast ((*it)); + } else { + view = dynamic_cast ((*it)); + } + } + + if (!view) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select exactly one Drawing View object.")); + return; + } + if (!clip) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select exactly one Clip object.")); + return; + } + + openCommand("ClipMinus"); + clip->removeView(view); + updateActive(); + commitCommand(); +} + +bool CmdDrawingClipMinus::isActive(void) +{ + return (getActiveGuiDocument() ? true : false); +} + + +//=========================================================================== +// Drawing_Symbol +//=========================================================================== + +DEF_STD_CMD_A(CmdDrawingSymbol); + +CmdDrawingSymbol::CmdDrawingSymbol() + : Command("Drawing_Symbol") +{ + // setting the Gui eye-candy + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Insert SVG &Symbol"); + sToolTipText = QT_TR_NOOP("Inserts a symbol from a svg file in the active drawing"); + sWhatsThis = "Drawing_Symbol"; + sStatusTip = QT_TR_NOOP("Inserts a symbol from a svg file in the active drawing"); + sPixmap = "actions/techdraw-symbol"; +} + +void CmdDrawingSymbol::activated(int iMsg) +{ +// std::vector pages = getSelection().getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + if (pages.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"), + QObject::tr("Create a page first.")); + return; + } + // Reading an image + QString filename = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), QObject::tr("Choose an SVG file to open"), QString::null, + QString::fromLatin1("%1 (*.svg *.svgz)").arg(QObject::tr("Scalable Vector Graphic"))); + if (!filename.isEmpty()) + { + std::string PageName = pages.front()->getNameInDocument(); + std::string FeatName = getUniqueObjectName("Symbol"); + openCommand("Create Symbol"); + doCommand(Doc,"import Drawing"); + doCommand(Doc,"f = open(unicode(\"%s\",'utf-8'),'r')",(const char*)filename.toUtf8()); + doCommand(Doc,"svg = f.read()"); + doCommand(Doc,"f.close()"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewSymbol','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.X = 10.0",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Y = 10.0",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Symbol = svg",FeatName.c_str()); + //doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + TechDraw::DrawPage *page = dynamic_cast(pages.front()); + page->addView(page->getDocument()->getObject(FeatName.c_str())); + updateActive(); + commitCommand(); + } +} + +bool CmdDrawingSymbol::isActive(void) +{ + return (getActiveGuiDocument() ? true : false); +} + + +//=========================================================================== +// Drawing_ExportPage +//=========================================================================== + +DEF_STD_CMD_A(CmdDrawingExportPage); + +CmdDrawingExportPage::CmdDrawingExportPage() + : Command("Drawing_ExportPage") +{ + // seting the + sGroup = QT_TR_NOOP("File"); + sMenuText = QT_TR_NOOP("&Export page..."); + sToolTipText = QT_TR_NOOP("Export a page to an SVG file"); + sWhatsThis = "Drawing_ExportPage"; + sStatusTip = QT_TR_NOOP("Export a page to an SVG file"); + sPixmap = "actions/saveSVG"; +} + +void CmdDrawingExportPage::activated(int iMsg) +{ + std::vector pages = getSelection().getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + if (pages.empty()) { // no Pages in Selection + pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + if (pages.empty()) { // no Pages in Document + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No pages found"), + QObject::tr("Create a drawing page first.")); + return; + } + } + + unsigned int n = getSelection().countObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + if (n > 1) { // too many Pages + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select only one Page object.")); + return; + } + + TechDraw::DrawPage* page = dynamic_cast(pages.front()); + + Gui::Document* activeGui = Gui::Application::Instance->getDocument(page->getDocument()); + Gui::ViewProvider* vp = activeGui->getViewProvider(page); + ViewProviderDrawingPage* dvp = dynamic_cast(vp); + + if (dvp && dvp->getMDIViewPage()) { + dvp->getMDIViewPage()->saveSVG(); + } else { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No Drawing View"), + QObject::tr("Open Drawing View before attempting export to SVG.")); + return; + } + +} + +bool CmdDrawingExportPage::isActive(void) +{ + return (getActiveGuiDocument() ? true : false); +} + +//=========================================================================== +// Drawing_ProjectShape +//=========================================================================== + +DEF_STD_CMD_A(CmdDrawingProjectShape); + +CmdDrawingProjectShape::CmdDrawingProjectShape() + : Command("Drawing_ProjectShape") +{ + // seting the + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Project shape..."); + sToolTipText = QT_TR_NOOP("Project shape onto a user-defined plane"); + sStatusTip = QT_TR_NOOP("Project shape onto a user-defined plane"); + sWhatsThis = "Drawing_ProjectShape"; +} + +void CmdDrawingProjectShape::activated(int iMsg) +{ + Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog(); + if (!dlg) { + dlg = new TechDrawGui::TaskProjection(); + dlg->setButtonPosition(Gui::TaskView::TaskDialog::South); + } + Gui::Control().showDialog(dlg); +} + +bool CmdDrawingProjectShape::isActive(void) +{ + int ct = Gui::Selection().countObjectsOfType(Part::Feature::getClassTypeId()); + return (ct > 0 && !Gui::Control().activeDialog()); +} + + + +//=========================================================================== +// Drawing_Draft_View +//=========================================================================== + +DEF_STD_CMD_A(CmdDrawingDraftView); + +CmdDrawingDraftView::CmdDrawingDraftView() + : Command("Drawing_DraftView") +{ + // seting the + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("&Draft View"); + sToolTipText = QT_TR_NOOP("Inserts a Draft view of the selected object(s) in the active drawing"); + sWhatsThis = "Drawing_DraftView"; + sStatusTip = QT_TR_NOOP("Inserts a Draft view of the selected object(s) in the active drawing"); + sPixmap = "actions/techdraw-draft-view"; +} + +void CmdDrawingDraftView::activated(int iMsg) +{ + addModule(Gui,"Draft"); + doCommand(Gui,"Gui.runCommand(\"Draft_Drawing\")"); +} + +bool CmdDrawingDraftView::isActive(void) +{ + return (getActiveGuiDocument() ? true : false); +} + +void CreateDrawingCommands(void) +{ + Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); + +// rcCmdMgr.addCommand(new CmdDrawingOpen()); + rcCmdMgr.addCommand(new CmdDrawingNewPageDef()); + rcCmdMgr.addCommand(new CmdDrawingNewPage()); + rcCmdMgr.addCommand(new CmdDrawingNewA3Landscape()); + rcCmdMgr.addCommand(new CmdDrawingNewView()); + rcCmdMgr.addCommand(new CmdDrawingNewViewSection()); + rcCmdMgr.addCommand(new CmdDrawingProjGroup()); +// rcCmdMgr.addCommand(new CmdDrawingOpenBrowserView()); + rcCmdMgr.addCommand(new CmdDrawingAnnotation()); + rcCmdMgr.addCommand(new CmdDrawingClip()); + rcCmdMgr.addCommand(new CmdDrawingClipPlus()); + rcCmdMgr.addCommand(new CmdDrawingClipMinus()); + rcCmdMgr.addCommand(new CmdDrawingSymbol()); + rcCmdMgr.addCommand(new CmdDrawingExportPage()); + rcCmdMgr.addCommand(new CmdDrawingProjectShape()); + rcCmdMgr.addCommand(new CmdDrawingDraftView()); +} diff --git a/src/Mod/TechDraw/Gui/CommandCreateDims.cpp b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp new file mode 100644 index 0000000000..a2b2420fa1 --- /dev/null +++ b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp @@ -0,0 +1,923 @@ +/*************************************************************************** + * Copyright (c) 2014 Luke Parry * + * * + * 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 +#endif //#ifndef _PreComp_ + +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include + +# include + +# include +# include +# include +# include +# include +# include + +# include "MDIViewPage.h" +# include "TaskDialog.h" +# include "ViewProviderPage.h" + +using namespace TechDrawGui; +using namespace std; + +//internal functions +bool _checkSelection(Gui::Command* cmd); +int _isValidSingleEdge(Gui::Command* cmd, bool trueDim=true); +bool _isValidVertexes(Gui::Command* cmd); +int _isValidEdgeToEdge(Gui::Command* cmd, bool trueDim=true); +bool _isTrueAllowed(TechDraw::DrawViewPart* objFeat, const std::vector &SubNames); + +enum EdgeType{ + isInvalid, + isHorizontal, + isVertical, + isDiagonal, + isCircle, + isCurve, + isAngle + }; + +//=========================================================================== +// Drawing_NewDimension +//=========================================================================== + +DEF_STD_CMD(CmdDrawingNewDimension); + +CmdDrawingNewDimension::CmdDrawingNewDimension() + : Command("Drawing_NewDimension") +{ + sAppModule = "Drawing"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Insert a dimension into the drawing"); + sToolTipText = QT_TR_NOOP("Insert a new dimension"); + sWhatsThis = "Drawing_NewDimension"; + sStatusTip = sToolTipText; + sPixmap = "Dimension"; +} + +void CmdDrawingNewDimension::activated(int iMsg) +{ + bool result = _checkSelection(this); + if (!result) + return; + + std::vector selection = getSelection().getSelectionEx(); + TechDraw::DrawViewPart * objFeat = dynamic_cast(selection[0].getObject()); + const std::vector &SubNames = selection[0].getSubNames(); + + TechDraw::DrawViewDimension *dim = 0; + std::string FeatName = getUniqueObjectName("Dimension"); + std::string dimType; + bool centerLine = false; + + std::vector objs; + std::vector subs; + + //selected edge(s) must have valid reference to Source edge for True Dimension + //otherwise Dimension must be Projected + bool trueDimAllowed = _isTrueAllowed(objFeat,SubNames); + int edgeType = _isValidSingleEdge(this,trueDimAllowed); + + if (edgeType) { + if (edgeType < isCircle) { + dimType = "Distance"; + objs.push_back(objFeat); + subs.push_back(SubNames[0]); + } else if (edgeType == isCircle) { + dimType = "Radius"; + centerLine = true; + } else { + dimType = "Radius"; + } + } else if (_isValidVertexes(this)) { + dimType = "Distance"; + objs.push_back(objFeat); + objs.push_back(objFeat); + subs.push_back(SubNames[0]); + subs.push_back(SubNames[1]); + } else if (_isValidEdgeToEdge(this)) { + int edgeCase = _isValidEdgeToEdge(this); + objs.push_back(objFeat); + objs.push_back(objFeat); + subs.push_back(SubNames[0]); + subs.push_back(SubNames[1]); + switch (edgeCase) { + //TODO: This didn't have the breaks in it before 17 May, but didn't + // seem to crash either, so should check whether execution can even + // get here -Ian- + case isHorizontal: + dimType = "DistanceX"; + break; + case isVertical: + dimType = "DistanceY"; + break; + case isDiagonal: + dimType = "Distance"; + break; + case isAngle: + dimType = "Angle"; + default: + break; + } + } else { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"), + QObject::tr("Can't make a Dimension from this selection")); + return; + } + + openCommand("Create Dimension"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDimension','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Type = '%s'",FeatName.c_str() + ,dimType.c_str()); + + if (centerLine) { + doCommand(Doc,"App.activeDocument().%s.CentreLines = True", FeatName.c_str()); + } else { + doCommand(Doc,"App.activeDocument().%s.CentreLines = False", FeatName.c_str()); + } + + std::string contentStr; + if (dimType == "Angle") { + contentStr = "%value%\x00b0"; + } else if (dimType == "Radius") { + contentStr = "r%value%"; + } + doCommand(Doc,"App.activeDocument().%s.FormatSpec = '%s'",FeatName.c_str() + ,contentStr.c_str()); + + dim = dynamic_cast(getDocument()->getObject(FeatName.c_str())); + dim->References.setValues(objs, subs); + + // make a True dimension if you can, Projected otherwise + if (trueDimAllowed) { + doCommand(Doc,"App.activeDocument().%s.ProjectionType = 'True'",FeatName.c_str()); + } else { + doCommand(Doc,"App.activeDocument().%s.ProjectionType = 'Projected'",FeatName.c_str()); + } + + dim->execute(); + + std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + TechDraw::DrawPage *page = dynamic_cast(pages.front()); + page->addView(page->getDocument()->getObject(FeatName.c_str())); + + commitCommand(); + + //Horrible hack to force Tree update + double x = objFeat->X.getValue(); + objFeat->X.setValue(x); +} + +//=========================================================================== +// Drawing_NewRadiusDimension +//=========================================================================== + +DEF_STD_CMD(CmdDrawingNewRadiusDimension); + +CmdDrawingNewRadiusDimension::CmdDrawingNewRadiusDimension() + : Command("Drawing_NewRadiusDimension") +{ + sAppModule = "Drawing"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Insert a new radius dimension into the drawing"); + sToolTipText = QT_TR_NOOP("Insert a new radius dimension feature for the selected view"); + sWhatsThis = "Drawing_NewRadiusDimension"; + sStatusTip = sToolTipText; + sPixmap = "Dimension_Radius"; +} + +void CmdDrawingNewRadiusDimension::activated(int iMsg) +{ + bool result = _checkSelection(this); + if (!result) + return; + + std::vector selection = getSelection().getSelectionEx(); + TechDraw::DrawViewPart * objFeat = dynamic_cast(selection[0].getObject()); + const std::vector &SubNames = selection[0].getSubNames(); + + TechDraw::DrawViewDimension *dim = 0; + std::string FeatName = getUniqueObjectName("Dimension"); + bool centerLine = false; + + std::vector objs; + std::vector subs; + + //selected edge(s) must have valid reference to Source edge for True Dimension + //otherwise Dimension must be Projected + bool trueDimAllowed = _isTrueAllowed(objFeat,SubNames); + int edgeType = _isValidSingleEdge(this,trueDimAllowed); + if (edgeType == isCircle) { + centerLine = true; + objs.push_back(objFeat); + subs.push_back(SubNames[0]); + } else { + std::stringstream edgeMsg; + edgeMsg << "Can't make a radius Dimension from this selection (edge type: " << edgeType << ")"; + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"), + QObject::tr(edgeMsg.str().c_str())); + return; + } + + openCommand("Create Dimension"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDimension','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Type = '%s'",FeatName.c_str() + ,"Radius"); + + if (centerLine) { + doCommand(Doc,"App.activeDocument().%s.CentreLines = True", FeatName.c_str()); + } else { + doCommand(Doc,"App.activeDocument().%s.CentreLines = False", FeatName.c_str()); + } + + doCommand(Doc, "App.activeDocument().%s.FormatSpec = 'r%%value%%'", FeatName.c_str()); + + dim = dynamic_cast(getDocument()->getObject(FeatName.c_str())); + dim->References.setValues(objs, subs); + + if (trueDimAllowed) { + doCommand(Doc,"App.activeDocument().%s.ProjectionType = 'True'",FeatName.c_str()); + } else { + doCommand(Doc,"App.activeDocument().%s.ProjectionType = 'Projected'",FeatName.c_str()); + } + + dim->execute(); + + std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + TechDraw::DrawPage *page = dynamic_cast(pages.front()); + page->addView(page->getDocument()->getObject(FeatName.c_str())); + + commitCommand(); + + //Horrible hack to force Tree update + double x = objFeat->X.getValue(); + objFeat->X.setValue(x); +} + +//=========================================================================== +// Drawing_NewDiameterDimension +//=========================================================================== + +DEF_STD_CMD(CmdDrawingNewDiameterDimension); + +CmdDrawingNewDiameterDimension::CmdDrawingNewDiameterDimension() + : Command("Drawing_NewDiameterDimension") +{ + sAppModule = "Drawing"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Insert a new diameter dimension into the drawing"); + sToolTipText = QT_TR_NOOP("Insert a new diameter dimension feature for the selected view"); + sWhatsThis = "Drawing_NewDiameterDimension"; + sStatusTip = sToolTipText; + sPixmap = "Dimension_Diameter"; +} + +void CmdDrawingNewDiameterDimension::activated(int iMsg) +{ + bool result = _checkSelection(this); + if (!result) + return; + + std::vector selection = getSelection().getSelectionEx(); + TechDraw::DrawViewPart * objFeat = dynamic_cast(selection[0].getObject()); + const std::vector &SubNames = selection[0].getSubNames(); + + TechDraw::DrawViewDimension *dim = 0; + std::string FeatName = getUniqueObjectName("Dimension"); + bool centerLine = false; + + std::vector objs; + std::vector subs; + + //selected edge(s) must have valid reference to Source edge for True Dimension + //otherwise Dimension must be Projected + bool trueDimAllowed = _isTrueAllowed(objFeat,SubNames); + + int edgeType = _isValidSingleEdge(this,trueDimAllowed); + if (edgeType == isCircle) { + centerLine = true; + objs.push_back(objFeat); + subs.push_back(SubNames[0]); + } else { + std::stringstream edgeMsg; + edgeMsg << "Can't make a diameter Dimension from this selection (edge type: " << edgeType << ")"; + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"), + QObject::tr(edgeMsg.str().c_str())); + return; + } + + openCommand("Create Dimension"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDimension','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Type = '%s'",FeatName.c_str() + ,"Diameter"); + + if (centerLine) { + doCommand(Doc,"App.activeDocument().%s.CentreLines = True", FeatName.c_str()); + } else { + doCommand(Doc,"App.activeDocument().%s.CentreLines = False", FeatName.c_str()); + } + + doCommand(Doc, "App.activeDocument().%s.FormatSpec = '\u00d8%%value%%'", FeatName.c_str()); // \u00d8 is Capital O with stroke + + dim = dynamic_cast(getDocument()->getObject(FeatName.c_str())); + dim->References.setValues(objs, subs); + + // make a True dimension if you can, Projected otherwise + if (trueDimAllowed) { + doCommand(Doc,"App.activeDocument().%s.ProjectionType = 'True'",FeatName.c_str()); + } else { + doCommand(Doc,"App.activeDocument().%s.ProjectionType = 'Projected'",FeatName.c_str()); + } + + dim->execute(); + + std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + TechDraw::DrawPage *page = dynamic_cast(pages.front()); + page->addView(page->getDocument()->getObject(FeatName.c_str())); + + commitCommand(); + + //Horrible hack to force Tree update + double x = objFeat->X.getValue(); + objFeat->X.setValue(x); +} + + +//=========================================================================== +// Drawing_NewLengthDimension +//=========================================================================== + +DEF_STD_CMD(CmdDrawingNewLengthDimension); + +CmdDrawingNewLengthDimension::CmdDrawingNewLengthDimension() + : Command("Drawing_NewLengthDimension") +{ + sAppModule = "Drawing"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Insert a new length dimension into the drawing"); + sToolTipText = QT_TR_NOOP("Insert a new length dimension"); + sWhatsThis = "Drawing_NewLengthDimension"; + sStatusTip = sToolTipText; + sPixmap = "Dimension_Length"; +} + +void CmdDrawingNewLengthDimension::activated(int iMsg) +{ + bool result = _checkSelection(this); + if (!result) + return; + + std::vector selection = getSelection().getSelectionEx(); + TechDraw::DrawViewPart * objFeat = dynamic_cast(selection[0].getObject()); + const std::vector &SubNames = selection[0].getSubNames(); + + TechDraw::DrawViewDimension *dim = 0; + std::string FeatName = getUniqueObjectName("Dimension"); + std::string dimType; + + std::vector objs; + std::vector subs; + + //selected edge(s) must have valid reference to Source edge for True Dimension + //otherwise Dimension must be Projected + bool trueDimAllowed = _isTrueAllowed(objFeat,SubNames); + int edgeType = _isValidSingleEdge(this,trueDimAllowed); + if ((edgeType == isHorizontal) || + (edgeType == isVertical) || + (edgeType == isDiagonal)) { + objs.push_back(objFeat); + subs.push_back(SubNames[0]); + } else if (_isValidVertexes(this)) { + objs.push_back(objFeat); + objs.push_back(objFeat); + subs.push_back(SubNames[0]); + subs.push_back(SubNames[1]); + } else if ((_isValidEdgeToEdge(this) == isHorizontal) || + (_isValidEdgeToEdge(this) == isVertical) || + (_isValidEdgeToEdge(this) == isVertical)) { + objs.push_back(objFeat); + objs.push_back(objFeat); + subs.push_back(SubNames[0]); + subs.push_back(SubNames[1]); + } else { + std::stringstream edgeMsg; + edgeMsg << "Can't make a length Dimension from this selection (edge type: " << edgeType << ")"; + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"), + QObject::tr(edgeMsg.str().c_str())); + return; + } + + openCommand("Create Dimension"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDimension','%s')", FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Type = '%s'", FeatName.c_str() + , "Distance"); + dim = dynamic_cast(getDocument()->getObject(FeatName.c_str())); + dim->References.setValues(objs, subs); + + doCommand(Doc, "App.activeDocument().%s.FormatSpec = '%%value%%'", FeatName.c_str()); + + // make a True dimension if you can, Projected otherwise + if (trueDimAllowed) { + doCommand(Doc,"App.activeDocument().%s.ProjectionType = 'True'",FeatName.c_str()); + } else { + doCommand(Doc,"App.activeDocument().%s.ProjectionType = 'Projected'",FeatName.c_str()); + } + + dim->execute(); + + std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + TechDraw::DrawPage *page = dynamic_cast(pages.front()); + page->addView(page->getDocument()->getObject(FeatName.c_str())); + + commitCommand(); + + //Horrible hack to force Tree update + double x = objFeat->X.getValue(); + objFeat->X.setValue(x); +} + +//=========================================================================== +// Drawing_NewDistanceXDimension +//=========================================================================== + +DEF_STD_CMD(CmdDrawingNewDistanceXDimension); + +CmdDrawingNewDistanceXDimension::CmdDrawingNewDistanceXDimension() + : Command("Drawing_NewDistanceXDimension") +{ + sAppModule = "Drawing"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Insert a new horizontal dimension into the drawing"); + sToolTipText = QT_TR_NOOP("Insert a new horizontal-distance dimension"); + sWhatsThis = "Drawing_NewDistanceXDimension"; + sStatusTip = sToolTipText; + sPixmap = "Dimension_Horizontal"; +} + +void CmdDrawingNewDistanceXDimension::activated(int iMsg) +{ + bool result = _checkSelection(this); + if (!result) + return; + + std::vector selection = getSelection().getSelectionEx(); + TechDraw::DrawViewPart * objFeat = dynamic_cast(selection[0].getObject()); + const std::vector &SubNames = selection[0].getSubNames(); + + TechDraw::DrawViewDimension *dim = 0; + std::string FeatName = getUniqueObjectName("Dimension"); + std::string dimType; + + std::vector objs; + std::vector subs; + + //selected edge(s) must have valid reference to Source edge for True Dimension + //otherwise Dimension must be Projected + bool trueDimAllowed = _isTrueAllowed(objFeat,SubNames); + int edgeType = _isValidSingleEdge(this,trueDimAllowed); + if ((edgeType == isHorizontal) || + (edgeType == isDiagonal)) { + objs.push_back(objFeat); + subs.push_back(SubNames[0]); + } else if (_isValidVertexes(this)) { + objs.push_back(objFeat); + objs.push_back(objFeat); + subs.push_back(SubNames[0]); + subs.push_back(SubNames[1]); + } else if (_isValidEdgeToEdge(this) == isHorizontal) { + objs.push_back(objFeat); + objs.push_back(objFeat); + subs.push_back(SubNames[0]); + subs.push_back(SubNames[1]); + } else { + std::stringstream edgeMsg; + edgeMsg << "Can't make a horizontal Dimension from this selection (edge type: " << edgeType << ")"; + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"), + QObject::tr(edgeMsg.str().c_str())); + return; + } + + openCommand("Create Dimension"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDimension','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Type = '%s'",FeatName.c_str() + ,"DistanceX"); + + dim = dynamic_cast(getDocument()->getObject(FeatName.c_str())); + dim->References.setValues(objs, subs); + + doCommand(Doc, "App.activeDocument().%s.FormatSpec = '%%value%%'", FeatName.c_str()); + + // make a True dimension if you can, Projected otherwise + if (trueDimAllowed) { + doCommand(Doc,"App.activeDocument().%s.ProjectionType = 'True'",FeatName.c_str()); + } else { + doCommand(Doc,"App.activeDocument().%s.ProjectionType = 'Projected'",FeatName.c_str()); + } + + dim->execute(); + + std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + TechDraw::DrawPage *page = dynamic_cast(pages.front()); + page->addView(page->getDocument()->getObject(FeatName.c_str())); + + commitCommand(); + + //Horrible hack to force Tree update + double x = objFeat->X.getValue(); + objFeat->X.setValue(x); +} + + +//=========================================================================== +// Drawing_NewDistanceYDimension +//=========================================================================== + +DEF_STD_CMD(CmdDrawingNewDistanceYDimension); + +CmdDrawingNewDistanceYDimension::CmdDrawingNewDistanceYDimension() + : Command("Drawing_NewDistanceYDimension") +{ + sAppModule = "Drawing"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Insert a new vertical dimension into the drawing"); + sToolTipText = QT_TR_NOOP("Insert a new vertical distance dimension"); + sWhatsThis = "Drawing_NewDistanceYDimension"; + sStatusTip = sToolTipText; + sPixmap = "Dimension_Vertical"; +} + +void CmdDrawingNewDistanceYDimension::activated(int iMsg) +{ + bool result = _checkSelection(this); + if (!result) + return; + + std::vector selection = getSelection().getSelectionEx(); + TechDraw::DrawViewPart * objFeat = dynamic_cast(selection[0].getObject()); + const std::vector &SubNames = selection[0].getSubNames(); + + TechDraw::DrawViewDimension *dim = 0; + std::string FeatName = getUniqueObjectName("Dimension"); + std::string dimType; + + std::vector objs; + std::vector subs; + + //selected edge(s) must have valid reference to Source edge for True Dimension + //otherwise Dimension must be Projected + bool trueDimAllowed = _isTrueAllowed(objFeat,SubNames); + int edgeType = _isValidSingleEdge(this,trueDimAllowed); + if ((edgeType == isVertical) || + (edgeType == isDiagonal)) { + objs.push_back(objFeat); + subs.push_back(SubNames[0]); + } else if (_isValidVertexes(this)) { + objs.push_back(objFeat); + objs.push_back(objFeat); + subs.push_back(SubNames[0]); + subs.push_back(SubNames[1]); + } else if (_isValidEdgeToEdge(this) == isVertical) { + objs.push_back(objFeat); + objs.push_back(objFeat); + subs.push_back(SubNames[0]); + subs.push_back(SubNames[1]); + } else { + std::stringstream edgeMsg; + edgeMsg << "Can't make a vertical Dimension from this selection (edge type: " << edgeType << ")"; + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"), + QObject::tr(edgeMsg.str().c_str())); + return; + } + + openCommand("Create Dimension"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDimension','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Type = '%s'",FeatName.c_str() + ,"DistanceY"); + dim = dynamic_cast(getDocument()->getObject(FeatName.c_str())); + dim->References.setValues(objs, subs); + + doCommand(Doc, "App.activeDocument().%s.FormatSpec = '%%value%%'", FeatName.c_str()); + + // make a True dimension if you can, Projected otherwise + if (trueDimAllowed) { + doCommand(Doc,"App.activeDocument().%s.ProjectionType = 'True'",FeatName.c_str()); + } else { + doCommand(Doc,"App.activeDocument().%s.ProjectionType = 'Projected'",FeatName.c_str()); + } + + dim->execute(); + + std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + TechDraw::DrawPage *page = dynamic_cast(pages.front()); + page->addView(page->getDocument()->getObject(FeatName.c_str())); + + commitCommand(); + + //Horrible hack to force Tree update + double x = objFeat->X.getValue(); + objFeat->X.setValue(x); +} + + +//=========================================================================== +// Drawing_NewAngleDimension +//=========================================================================== + +DEF_STD_CMD(CmdDrawingNewAngleDimension); + +CmdDrawingNewAngleDimension::CmdDrawingNewAngleDimension() + : Command("Drawing_NewAngleDimension") +{ + sAppModule = "Drawing"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Insert a new angle dimension into the drawing"); + sToolTipText = QT_TR_NOOP("Insert a new angle dimension"); + sWhatsThis = "Drawing_NewAngleDimension"; + sStatusTip = sToolTipText; + sPixmap = "Dimension_Angle"; +} + +void CmdDrawingNewAngleDimension::activated(int iMsg) +{ + bool result = _checkSelection(this); + if (!result) + return; + + std::vector selection = getSelection().getSelectionEx(); + TechDraw::DrawViewPart * objFeat = dynamic_cast(selection[0].getObject()); + const std::vector &SubNames = selection[0].getSubNames(); + + TechDraw::DrawViewDimension *dim = 0; + std::string FeatName = getUniqueObjectName("Dimension"); + + std::vector objs; + std::vector subs; + + //selected edge(s) must have valid reference to Source edge for True Dimension + //otherwise Dimension must be Projected + bool trueDimAllowed = _isTrueAllowed(objFeat,SubNames); + int edgeType = _isValidEdgeToEdge(this,trueDimAllowed); + if (edgeType == isAngle) { + objs.push_back(objFeat); + objs.push_back(objFeat); + subs.push_back(SubNames[0]); + subs.push_back(SubNames[1]); + } else { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"), + QObject::tr("Can't make an angle Dimension from this selection")); + return; + } + + openCommand("Create Dimension"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDimension','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Type = '%s'",FeatName.c_str() + ,"Angle"); + + doCommand(Doc,"App.activeDocument().%s.FormatSpec = '%s'",FeatName.c_str() + ,"%value%\u00b0"); // \u00b0 is degree sign + + dim = dynamic_cast(getDocument()->getObject(FeatName.c_str())); + dim->References.setValues(objs, subs); + + // make a True dimension if you can, Projected otherwise + if (trueDimAllowed) { + doCommand(Doc,"App.activeDocument().%s.ProjectionType = 'True'",FeatName.c_str()); + } else { + doCommand(Doc,"App.activeDocument().%s.ProjectionType = 'Projected'",FeatName.c_str()); + } + + dim->execute(); + + std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + TechDraw::DrawPage *page = dynamic_cast(pages.front()); + page->addView(page->getDocument()->getObject(FeatName.c_str())); + + commitCommand(); + + //Horrible hack to force Tree update + double x = objFeat->X.getValue(); + objFeat->X.setValue(x); +} + +void CreateDrawingCommandsDims(void) +{ + Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); + + rcCmdMgr.addCommand(new CmdDrawingNewDimension()); + rcCmdMgr.addCommand(new CmdDrawingNewRadiusDimension()); + rcCmdMgr.addCommand(new CmdDrawingNewDiameterDimension()); + rcCmdMgr.addCommand(new CmdDrawingNewLengthDimension()); + rcCmdMgr.addCommand(new CmdDrawingNewDistanceXDimension()); + rcCmdMgr.addCommand(new CmdDrawingNewDistanceYDimension()); + rcCmdMgr.addCommand(new CmdDrawingNewAngleDimension()); +} + +//=========================================================================== +// Selection Validation Helpers +//=========================================================================== + +//! common checks of Selection for Dimension commands +bool _checkSelection(Gui::Command* cmd) { + std::vector selection = cmd->getSelection().getSelectionEx(); + if (selection.size() == 0) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), + QObject::tr("Select an object first")); + return false; + } + + TechDraw::DrawViewPart * objFeat = dynamic_cast(selection[0].getObject()); + if(!objFeat) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), + QObject::tr("No Feature in selection")); + return false; + } + + const std::vector &SubNames = selection[0].getSubNames(); + if (SubNames.size() != 1 && SubNames.size() != 2){ + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), + QObject::tr("Wrong number of objects selected")); + return false; + } + + std::vector pages = cmd->getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + if (pages.empty()){ + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), + QObject::tr("Create a page to insert.")); + return false; + } + return true; +} + +//! verify that Selection contains a valid Geometry for a single Edge Dimension (True or Projected) +int _isValidSingleEdge(Gui::Command* cmd, bool trueDim) { + int edgeType = isInvalid; + std::vector selection = cmd->getSelection().getSelectionEx(); + TechDraw::DrawViewPart * objFeat = dynamic_cast(selection[0].getObject()); + const std::vector &SubNames = selection[0].getSubNames(); + if (SubNames.size() == 1) { //only 1 subshape selected + if (DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge") { //the Name starts with "Edge" + int GeoId = DrawUtil::getIndexFromName(SubNames[0]); + DrawingGeometry::BaseGeom* geom = NULL; + if (trueDim) { + int ref = objFeat->getEdgeRefByIndex(GeoId); + geom = objFeat->getCompleteEdge(ref); //project edge onto its shape to get 2D geom + } else { + geom = objFeat->getProjEdgeByIndex(GeoId); + } + if (!geom) { + Base::Console().Error("Logic Error: no geometry for GeoId: %d\n",GeoId); + return isInvalid; + } + + if(geom->geomType == DrawingGeometry::GENERIC) { + DrawingGeometry::Generic* gen1 = static_cast(geom); + if(gen1->points.size() > 2) { //the edge is a polyline + return isInvalid; + } + Base::Vector2D line = gen1->points.at(1) - gen1->points.at(0); + if(fabs(line.fY) < FLT_EPSILON ) { + edgeType = isHorizontal; + } else if(fabs(line.fX) < FLT_EPSILON) { + edgeType = isVertical; + } else { + edgeType = isDiagonal; + } + } else if (geom->geomType == DrawingGeometry::CIRCLE || + geom->geomType == DrawingGeometry::ELLIPSE || + geom->geomType == DrawingGeometry::ARCOFCIRCLE || + geom->geomType == DrawingGeometry::ARCOFELLIPSE ) { + edgeType = isCircle; + } else if (geom->geomType == DrawingGeometry::BSPLINE) { + edgeType = isCurve; + } else { + edgeType = isInvalid; + } + } + } + return edgeType; +} + +//! verify that Selection contains valid geometries for a Vertex to Vertex Dimension +bool _isValidVertexes(Gui::Command* cmd) { + std::vector selection = cmd->getSelection().getSelectionEx(); + const std::vector &SubNames = selection[0].getSubNames(); + if(SubNames.size() == 2) { //there are 2 + if (DrawUtil::getGeomTypeFromName(SubNames[0]) == "Vertex" && //they both start with "Vertex" + DrawUtil::getGeomTypeFromName(SubNames[1]) == "Vertex") { + return true; + } + } + return false; +} + +//! verify that the Selection contains valid geometries for an Edge to Edge Dimension +int _isValidEdgeToEdge(Gui::Command* cmd, bool trueDim) { +//TODO: can the edges be in 2 different features?? + int edgeType = isInvalid; + std::vector selection = cmd->getSelection().getSelectionEx(); + TechDraw::DrawViewPart* objFeat0 = dynamic_cast(selection[0].getObject()); + //TechDraw::DrawViewPart* objFeat1 = dynamic_cast(selection[1].getObject()); + const std::vector &SubNames = selection[0].getSubNames(); + if(SubNames.size() == 2) { //there are 2 + if (DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" && //they both start with "Edge" + DrawUtil::getGeomTypeFromName(SubNames[1]) == "Edge") { + int GeoId0 = DrawUtil::getIndexFromName(SubNames[0]); + int GeoId1 = DrawUtil::getIndexFromName(SubNames[1]); + DrawingGeometry::BaseGeom* geom0 = NULL; + DrawingGeometry::BaseGeom* geom1 = NULL; + if (trueDim) { + int ref0 = objFeat0->getEdgeRefByIndex(GeoId0); + int ref1 = objFeat0->getEdgeRefByIndex(GeoId1); + geom0 = objFeat0->getCompleteEdge(ref0); + geom1 = objFeat0->getCompleteEdge(ref1); + } else { + geom0 = objFeat0->getProjEdgeByIndex(GeoId0); + geom1 = objFeat0->getProjEdgeByIndex(GeoId1); + } + if ((!geom0) || (!geom1)) { + Base::Console().Error("Logic Error: no geometry for GeoId: %d or GeoId: %d\n",GeoId0,GeoId1); + return isInvalid; + } + + if(geom0->geomType == DrawingGeometry::GENERIC && + geom1->geomType == DrawingGeometry::GENERIC) { + DrawingGeometry::Generic *gen0 = static_cast(geom0); + DrawingGeometry::Generic *gen1 = static_cast(geom1); + if(gen0->points.size() > 2 || + gen1->points.size() > 2) { //the edge is a polyline + return isInvalid; + } + Base::Vector2D line0 = gen0->points.at(1) - gen0->points.at(0); + Base::Vector2D line1 = gen1->points.at(1) - gen1->points.at(0); + double xprod = fabs(line0.fX * line1.fY - line0.fY * line1.fX); + if(xprod > FLT_EPSILON) { //edges are not parallel + return isAngle; + } + if(fabs(line0.fX) < FLT_EPSILON && fabs(line1.fX) < FLT_EPSILON) { + edgeType = isHorizontal; + } else if(fabs(line0.fY) < FLT_EPSILON && fabs(line1.fY) < FLT_EPSILON) { + edgeType = isVertical; + } else { + edgeType = isDiagonal; + } + } else { + return isInvalid; + } + } + } + return edgeType; +} + +//! verify that each SubName has a corresponding Edge geometry in objFeat->Source +bool _isTrueAllowed(TechDraw::DrawViewPart* objFeat, const std::vector &SubNames) +{ + std::vector::const_iterator it = SubNames.begin(); + bool trueDimAllowed = true; + for (; it != SubNames.end(); it++) { + int idx = DrawUtil::getIndexFromName((*it)); + int ref = objFeat->getEdgeRefByIndex(idx); + if (ref < 0) { + trueDimAllowed = false; + } + } + return trueDimAllowed; +} diff --git a/src/Mod/TechDraw/Gui/CommandDecorate.cpp b/src/Mod/TechDraw/Gui/CommandDecorate.cpp new file mode 100644 index 0000000000..13c1390935 --- /dev/null +++ b/src/Mod/TechDraw/Gui/CommandDecorate.cpp @@ -0,0 +1,160 @@ +/*************************************************************************** + * Copyright (c) 2014 Luke Parry * + * * + * 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 +#endif //#ifndef _PreComp_ + +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include + +# include + +# include +# include +# include + +# include "MDIViewPage.h" +# include "ViewProviderPage.h" + +using namespace TechDrawGui; +using namespace std; + +//internal functions +bool _checkSelectionHatch(Gui::Command* cmd); + +//=========================================================================== +// Drawing_NewHatch +//=========================================================================== + +DEF_STD_CMD(CmdDrawingNewHatch); + +CmdDrawingNewHatch::CmdDrawingNewHatch() + : Command("Drawing_NewHatch") +{ + sAppModule = "Drawing"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Insert a hatched area into a view"); + sToolTipText = QT_TR_NOOP("Insert a hatched area into a view"); + sWhatsThis = "Drawing_NewHatch"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-hatch"; +} + +void CmdDrawingNewHatch::activated(int iMsg) +{ + if (!_checkSelectionHatch(this)) { + return; + } + + std::vector selection = getSelection().getSelectionEx(); + TechDraw::DrawViewPart * objFeat = dynamic_cast(selection[0].getObject()); + const std::vector &SubNames = selection[0].getSubNames(); + + TechDraw::DrawHatch *hatch = 0; + std::string FeatName = getUniqueObjectName("Hatch"); + + std::vector objs; + std::vector subs; + + std::vector::const_iterator itSub = SubNames.begin(); + for (; itSub != SubNames.end(); itSub++) { + objs.push_back(objFeat); + subs.push_back((*itSub)); + } + + openCommand("Create Hatch"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawHatch','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.PartView = App.activeDocument().%s",FeatName.c_str(),objFeat->getNameInDocument()); + commitCommand(); + + hatch = dynamic_cast(getDocument()->getObject(FeatName.c_str())); + hatch->Edges.setValues(objs, subs); + + hatch->execute(); + + std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + TechDraw::DrawPage *page = dynamic_cast(pages.front()); + page->addView(page->getDocument()->getObject(FeatName.c_str())); + + //Horrible hack to force Tree update ??still required?? + double x = objFeat->X.getValue(); + objFeat->X.setValue(x); +} + +void CreateDrawingCommandsDecorate(void) +{ + Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); + + rcCmdMgr.addCommand(new CmdDrawingNewHatch()); + //rcCmdMgr.addCommand(new CmdDrawingHideLabels()); +} + +//=========================================================================== +// Selection Validation Helpers +//=========================================================================== + +bool _checkSelectionHatch(Gui::Command* cmd) { + std::vector selection = cmd->getSelection().getSelectionEx(); + if (selection.size() == 0) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), + QObject::tr("Select an object first")); + return false; + } + + TechDraw::DrawViewPart * objFeat = dynamic_cast(selection[0].getObject()); + if(!objFeat) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), + QObject::tr("No Feature in selection")); + return false; + } + + std::vector pages = cmd->getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + if (pages.empty()){ + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), + QObject::tr("Create a page to insert.")); + return false; + } + +// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"), +// QObject::tr("Can't make a Hatched area from this selection")); +// return false; + + //TODO: if selection != set of closed edges, return false + return true; +} diff --git a/src/Mod/TechDraw/Gui/DlgPrefsDrawing.ui b/src/Mod/TechDraw/Gui/DlgPrefsDrawing.ui new file mode 100644 index 0000000000..1cdc58d398 --- /dev/null +++ b/src/Mod/TechDraw/Gui/DlgPrefsDrawing.ui @@ -0,0 +1,309 @@ + + + TechDrawGui::DlgPrefsDrawingImp + + + + 0 + 0 + 601 + 550 + + + + Drawing + + + + + 20 + 30 + 561 + 471 + + + + + + + Colors + + + + + 20 + 20 + 191 + 128 + + + + + + + + 28 + 173 + 28 + + + + SelectColor + + + Mod/Drawing/Colors + + + + + + + HiddenColor + + + Mod/Drawing/Colors + + + + + + + + 0 + 0 + 0 + + + + NormalColor + + + Mod/Drawing/Colors + + + + + + + PreSelected + + + + + + + Normal + + + + + + + Hidden + + + + + + + Selected + + + + + + + + 255 + 255 + 20 + + + + PreSelectColor + + + Mod/Drawing/Colors + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + Font + + + + + 20 + 30 + 301 + 41 + + + + + + + Label Font + + + + + + + LabelFont + + + Mod/Drawing + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + + + + + Templates + + + + + 20 + 30 + 531 + 80 + + + + + + + Gui::FileChooser::Directory + + + TemplateDir + + + /Mod/Drawing + + + + + + + Default Template + + + + + + + Template Directory + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + TemplateFile + + + Mod/Drawing + + + + + + + + + + + + + Gui::FileChooser + QWidget +
Gui/FileDialog.h
+
+ + Gui::ColorButton + QPushButton +
Gui/Widgets.h
+
+ + Gui::PrefFileChooser + Gui::FileChooser +
Gui/PrefWidgets.h
+
+ + Gui::PrefColorButton + Gui::ColorButton +
Gui/PrefWidgets.h
+
+ + Gui::PrefLineEdit + QLineEdit +
Gui/PrefWidgets.h
+
+
+ + +
diff --git a/src/Mod/TechDraw/Gui/DlgPrefsDrawingImp.cpp b/src/Mod/TechDraw/Gui/DlgPrefsDrawingImp.cpp new file mode 100644 index 0000000000..afb2d8e3a5 --- /dev/null +++ b/src/Mod/TechDraw/Gui/DlgPrefsDrawingImp.cpp @@ -0,0 +1,79 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Author: WandererFan * + * Based on src/Mod/FEM/Gui/DlgSettingsFEMImp.cpp * + * * + * 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" + +#include "DlgPrefsDrawingImp.h" +#include + +using namespace TechDrawGui; + +DlgPrefsDrawingImp::DlgPrefsDrawingImp( QWidget* parent ) + : PreferencePage( parent ) +{ + this->setupUi(this); +} + +DlgPrefsDrawingImp::~DlgPrefsDrawingImp() +{ + // no need to delete child widgets, Qt does it all for us +} + +void DlgPrefsDrawingImp::saveSettings() +{ + pcb_Normal->onSave(); + pcb_Select->onSave(); + pcb_PreSelect->onSave(); + pcb_Hidden->onSave(); + le_LabelFont->onSave(); + le_DefTemplate->onSave(); + pfc_DefDir->onSave(); +} + +void DlgPrefsDrawingImp::loadSettings() +{ + pcb_Normal->onRestore(); + pcb_Select->onRestore(); + pcb_PreSelect->onRestore(); + pcb_Hidden->onRestore(); + le_LabelFont->onRestore(); + le_DefTemplate->onRestore(); + pfc_DefDir->onRestore(); +} + +/** + * Sets the strings of the subwidgets using the current language. + */ +void DlgPrefsDrawingImp::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + retranslateUi(this); + } + else { + QWidget::changeEvent(e); + } +} + +#include "moc_DlgPrefsDrawingImp.cpp" diff --git a/src/Mod/TechDraw/Gui/DlgPrefsDrawingImp.h b/src/Mod/TechDraw/Gui/DlgPrefsDrawingImp.h new file mode 100644 index 0000000000..1ab64c3a44 --- /dev/null +++ b/src/Mod/TechDraw/Gui/DlgPrefsDrawingImp.h @@ -0,0 +1,50 @@ + /************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Author: WandererFan * + * Based on src/Mod/FEM/Gui/DlgPrefsDrawingImp.cpp * + * * + * 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_DLGPREFSDRAWINGIMP_H +#define DRAWINGGUI_DLGPREFSDRAWINGIMP_H + +#include "ui_DlgPrefsDrawing.h" +#include + +namespace TechDrawGui { + +class DlgPrefsDrawingImp : public Gui::Dialog::PreferencePage, public Ui_DlgPrefsDrawingImp +{ + Q_OBJECT + +public: + DlgPrefsDrawingImp( QWidget* parent = 0 ); + ~DlgPrefsDrawingImp(); + +protected: + void saveSettings(); + void loadSettings(); + void changeEvent(QEvent *e); +}; + +} // namespace TechDrawGui + +#endif // DRAWINGGUI_DLGPREFSDRAWINGIMP_H diff --git a/src/Mod/TechDraw/Gui/MDIViewPage.cpp b/src/Mod/TechDraw/Gui/MDIViewPage.cpp new file mode 100644 index 0000000000..654b89b2de --- /dev/null +++ b/src/Mod/TechDraw/Gui/MDIViewPage.cpp @@ -0,0 +1,1099 @@ +/*************************************************************************** + * Copyright (c) 2007 Jürgen Riegel * + * Copyright (c) 2013 Luke Parry * + * * + * 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 +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif // #ifndef _PreComp_ + +#include "MDIViewPage.h" + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "QGIDrawingTemplate.h" +#include "QGIView.h" +#include "QGIViewPart.h" +#include "QGIViewDimension.h" +#include "QGIViewClip.h" +#include "ViewProviderPage.h" +#include "QGVPage.h" + + +using namespace TechDrawGui; + +/* TRANSLATOR TechDrawGui::MDIViewPage */ + +MDIViewPage::MDIViewPage(ViewProviderDrawingPage *pageVp, Gui::Document* doc, QWidget* parent) + : Gui::MDIView(doc, parent), pageGui(pageVp) +{ + m_view = new QGVPage(pageVp); + + m_backgroundAction = new QAction(tr("&Background"), this); + m_backgroundAction->setEnabled(false); + m_backgroundAction->setCheckable(true); + m_backgroundAction->setChecked(true); + connect(m_backgroundAction, SIGNAL(toggled(bool)), m_view, SLOT(setViewBackground(bool))); + + m_exportSVGAction = new QAction(tr("&Export SVG"), this); + connect(m_exportSVGAction, SIGNAL(triggered()), this, SLOT(saveSVG())); + + m_outlineAction = new QAction(tr("&Outline"), this); + m_outlineAction->setEnabled(false); + m_outlineAction->setCheckable(true); + m_outlineAction->setChecked(false); + connect(m_outlineAction, SIGNAL(toggled(bool)), m_view, SLOT(setViewOutline(bool))); //in QGVPage + + m_nativeAction = new QAction(tr("&Native"), this); + m_nativeAction->setCheckable(true); + m_nativeAction->setChecked(false); +#ifndef QT_NO_OPENGL + m_glAction = new QAction(tr("&OpenGL"), this); + m_glAction->setCheckable(true); +#endif + m_imageAction = new QAction(tr("&Image"), this); + m_imageAction->setCheckable(true); + +#ifndef QT_NO_OPENGL + m_highQualityAntialiasingAction = new QAction(tr("&High Quality Antialiasing"), this); + m_highQualityAntialiasingAction->setEnabled(false); + m_highQualityAntialiasingAction->setCheckable(true); + m_highQualityAntialiasingAction->setChecked(false); + connect(m_highQualityAntialiasingAction, SIGNAL(toggled(bool)), + m_view, SLOT(setHighQualityAntialiasing(bool))); +#endif + + isSlectionBlocked = false; + + QActionGroup *rendererGroup = new QActionGroup(this); + rendererGroup->addAction(m_nativeAction); +#ifndef QT_NO_OPENGL + rendererGroup->addAction(m_glAction); +#endif + rendererGroup->addAction(m_imageAction); + connect(rendererGroup, SIGNAL(triggered(QAction *)), + this, SLOT(setRenderer(QAction *))); + + setWindowTitle(tr("dummy[*]")); //Yuck. prevents "QWidget::setWindowModified: The window title does not contain a '[*]' placeholder" + setCentralWidget(m_view); + + m_orientation = QPrinter::Landscape; + m_pageSize = QPrinter::A4; + + // Connect Signals and Slots + QObject::connect( + m_view->scene(), SIGNAL(selectionChanged()), + this , SLOT (selectionChanged()) + ); + + + // A fresh page is added and we iterate through its collected children and add these to Canvas View + // if docobj is a featureviewcollection (ex orthogroup), add its child views. if there are ever children that have children, + // we'll have to make this recursive. -WF + const std::vector &grp = pageGui->getPageObject()->Views.getValues(); + std::vector childViews; + for (std::vector::const_iterator it = grp.begin();it != grp.end(); ++it) { + attachView(*it); + TechDraw::DrawViewCollection* collect = dynamic_cast(*it); + if (collect) { + childViews = collect->Views.getValues(); + for (std::vector::iterator itChild = childViews.begin();itChild != childViews.end(); ++itChild) { + attachView(*itChild); + } + } + } + //when restoring, it is possible for a Dimension to be loaded before the ViewPart it applies to + //therefore we need to make sure parentage of the graphics representation is set properly. bit of a kludge. + setDimensionGroups(); + + App::DocumentObject *obj = pageGui->getPageObject()->Template.getValue(); + if(obj && obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) { + TechDraw::DrawTemplate *pageTemplate = dynamic_cast(obj); + attachTemplate(pageTemplate); + } + +} + +MDIViewPage::~MDIViewPage() +{ + // Safely remove graphicview items that have built up TEMP SOLUTION + for(QList::iterator it = deleteItems.begin(); it != deleteItems.end(); ++it) { + (*it)->deleteLater(); + } + deleteItems.clear(); + + delete m_view; +} + +void MDIViewPage::setDimensionGroups(void) +{ + const std::vector &allItems = m_view->getViews(); + std::vector::const_iterator itInspect; + int dimItemType = QGI::UserType + 106; + + for (itInspect = allItems.begin(); itInspect != allItems.end(); itInspect++) { + if (((*itInspect)->type() == dimItemType) && (!(*itInspect)->group())) { + QGIView* parent = m_view->findParent((*itInspect)); + if (parent) { + QGIViewDimension* dim = dynamic_cast((*itInspect)); + m_view->addDimToParent(dim,parent); + } + } + } +} +void MDIViewPage::findPrinterSettings(const QString& fileName) +{ + if (fileName.indexOf(QLatin1String("Portrait"), Qt::CaseInsensitive) >= 0) { + m_orientation = QPrinter::Portrait; + } + else { + m_orientation = QPrinter::Landscape; + } + + QMap pageSizes; + pageSizes[QPrinter::A0] = QString::fromLatin1("A0"); + pageSizes[QPrinter::A1] = QString::fromLatin1("A1"); + pageSizes[QPrinter::A2] = QString::fromLatin1("A2"); + pageSizes[QPrinter::A3] = QString::fromLatin1("A3"); + pageSizes[QPrinter::A4] = QString::fromLatin1("A4"); + pageSizes[QPrinter::A5] = QString::fromLatin1("A5"); + pageSizes[QPrinter::A6] = QString::fromLatin1("A6"); + pageSizes[QPrinter::A7] = QString::fromLatin1("A7"); + pageSizes[QPrinter::A8] = QString::fromLatin1("A8"); + pageSizes[QPrinter::A9] = QString::fromLatin1("A9"); + pageSizes[QPrinter::B0] = QString::fromLatin1("B0"); + pageSizes[QPrinter::B1] = QString::fromLatin1("B1"); + pageSizes[QPrinter::B2] = QString::fromLatin1("B2"); + pageSizes[QPrinter::B3] = QString::fromLatin1("B3"); + pageSizes[QPrinter::B4] = QString::fromLatin1("B4"); + pageSizes[QPrinter::B5] = QString::fromLatin1("B5"); + pageSizes[QPrinter::B6] = QString::fromLatin1("B6"); + pageSizes[QPrinter::B7] = QString::fromLatin1("B7"); + pageSizes[QPrinter::B8] = QString::fromLatin1("B8"); + pageSizes[QPrinter::B9] = QString::fromLatin1("B9"); + pageSizes[QPrinter::Letter] = QString::fromLatin1("Letter"); + pageSizes[QPrinter::Legal] = QString::fromLatin1("Legal"); + for (QMap::iterator it = pageSizes.begin(); it != pageSizes.end(); ++it) { + if (fileName.startsWith(it.value(), Qt::CaseInsensitive)) { + m_pageSize = it.key(); + break; + } + } +} + +void MDIViewPage::setDocumentObject(const std::string& name) +{ + m_objectName = name; +} + +void MDIViewPage::closeEvent(QCloseEvent* ev) +{ + MDIView::closeEvent(ev); + if (!ev->isAccepted()) + return; + + // when closing the view from GUI notify the view provider to mark it invisible + if (_pcDocument && !m_objectName.empty()) { + App::Document* doc = _pcDocument->getDocument(); + if (doc) { + App::DocumentObject* obj = doc->getObject(m_objectName.c_str()); + Gui::ViewProvider* vp = _pcDocument->getViewProvider(obj); + if (vp) + vp->hide(); + } + } +} + +void MDIViewPage::contextMenuEvent(QContextMenuEvent *event) +{ + QMenu menu; + menu.addAction(m_backgroundAction); + menu.addAction(m_outlineAction); + menu.addAction(m_exportSVGAction); + QMenu* submenu = menu.addMenu(tr("&Renderer")); + submenu->addAction(m_nativeAction); + submenu->addAction(m_glAction); + submenu->addAction(m_imageAction); + submenu->addSeparator(); + submenu->addAction(m_highQualityAntialiasingAction); + menu.exec(event->globalPos()); +} + +void MDIViewPage::attachTemplate(TechDraw::DrawTemplate *obj) +{ + m_view->setPageTemplate(obj); + double width = obj->Width.getValue(); + double height = obj->Height.getValue(); + m_view->scene()->setSceneRect(QRectF(-1.,-height,width+1.,height)); //the +/- 1 is because of the way the template is define??? +} + +int MDIViewPage::attachView(App::DocumentObject *obj) +{ + QGIView *qview = 0; + if(obj->getTypeId().isDerivedFrom(TechDraw::DrawViewSection::getClassTypeId()) ) { + TechDraw::DrawViewSection *viewSect = dynamic_cast(obj); + qview = m_view->addViewSection(viewSect); + } else if (obj->getTypeId().isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId()) ) { + TechDraw::DrawViewPart *viewPart = dynamic_cast(obj); + qview = m_view->addViewPart(viewPart); + } else if (obj->getTypeId().isDerivedFrom(TechDraw::DrawProjGroup::getClassTypeId()) ) { + TechDraw::DrawProjGroup *view = dynamic_cast(obj); + qview = m_view->addProjectionGroup(view); + } else if (obj->getTypeId().isDerivedFrom(TechDraw::DrawViewCollection::getClassTypeId()) ) { + TechDraw::DrawViewCollection *collection = dynamic_cast(obj); + qview = m_view->addDrawView(collection); + } else if(obj->getTypeId().isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId()) ) { + TechDraw::DrawViewDimension *viewDim = dynamic_cast(obj); + qview = m_view->addViewDimension(viewDim); + } else if(obj->getTypeId().isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId()) ) { + TechDraw::DrawViewAnnotation *viewDim = dynamic_cast(obj); + qview = m_view->addDrawViewAnnotation(viewDim); + } else if(obj->getTypeId().isDerivedFrom(TechDraw::DrawViewSymbol::getClassTypeId()) ) { + TechDraw::DrawViewSymbol *viewSym = dynamic_cast(obj); + qview = m_view->addDrawViewSymbol(viewSym); + } else if(obj->getTypeId().isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId()) ) { + TechDraw::DrawViewClip *viewClip = dynamic_cast(obj); + qview = m_view->addDrawViewClip(viewClip); + } else { + Base::Console().Log("Logic Error - Unknown view type in MDIViewPage::attachView\n"); + } + + if(!qview) + return -1; + else + return m_view->getViews().size(); +} + +void MDIViewPage::preSelectionChanged(const QPoint &pos) +{ + QObject *obj = QObject::sender(); + + if(!obj) + return; + + // Check if an edge was preselected + QGIEdge *edge = dynamic_cast(obj); + QGIVertex *vert = dynamic_cast(obj); + if(edge) { + + // Find the parent view that this edges is contained within + QGI *parent = edge->parentItem(); + if(!parent) + return; + + QGIView *viewItem = dynamic_cast(parent); + if(!viewItem) + return; + + TechDraw::DrawView *viewObj = viewItem->getViewObject(); + std::stringstream ss; + //ss << "Edge" << edge->getReference(); + ss << "Edge" << edge->getProjIndex(); + //bool accepted = + static_cast (Gui::Selection().setPreselect(viewObj->getDocument()->getName() + ,viewObj->getNameInDocument() + ,ss.str().c_str() + ,pos.x() + ,pos.y() + ,0)); + + } else if(vert) { + // Find the parent view that this edges is contained within + //WF: sb Vertex?? + QGI *parent = vert->parentItem(); + if(!parent) + return; + + QGIView *viewItem = dynamic_cast(parent); + if(!viewItem) + return; + + TechDraw::DrawView *viewObj = viewItem->getViewObject(); + std::stringstream ss; + ss << "Edge" << vert->getReference(); //WF: sb Vertex?? + //bool accepted = + static_cast (Gui::Selection().setPreselect(viewObj->getDocument()->getName() + ,viewObj->getNameInDocument() + ,ss.str().c_str() + ,pos.x() + ,pos.y() + ,0)); + } else { + // Check if an edge was preselected + //WF: sb View? + QGIView *view = qobject_cast(obj); + + if(!view) + return; + TechDraw::DrawView *viewObj = view->getViewObject(); + Gui::Selection().setPreselect(viewObj->getDocument()->getName() + ,viewObj->getNameInDocument() + ,"" + ,pos.x() + ,pos.y() + ,0); + } +} + +void MDIViewPage::blockSelection(const bool state) +{ + isSlectionBlocked = state; +} + +void MDIViewPage::clearSelection() +{ + blockSelection(true); + std::vector views = m_view->getViews(); + + // Iterate through all views and unselect all + for (std::vector::iterator it = views.begin(); it != views.end(); ++it) { + QGIView *item = *it; + item->setSelected(false); + item->updateView(); + } + + blockSelection(false); +} + +void MDIViewPage::selectFeature(App::DocumentObject *obj, const bool isSelected) +{ + // Update QGVPage's selection based on Selection made outside Drawing Interace + QGIView *view = m_view->findView(obj); + + blockSelection(true); + if(view) { + view->setSelected(isSelected); + view->updateView(); + } + blockSelection(false); +} + +void MDIViewPage::selectionChanged() +{ + if(isSlectionBlocked) + return; + + QList selection = m_view->scene()->selectedItems(); + + bool block = blockConnection(true); // avoid to be notified by itself + + Gui::Selection().clearSelection(); + for (QList::iterator it = selection.begin(); it != selection.end(); ++it) { + // All selectable items must be of QGIView type + + QGIView *itemView = dynamic_cast(*it); + if(itemView == 0) { + QGIEdge *edge = dynamic_cast(*it); + if(edge) { + + // Find the parent view that this edges is contained within + QGI *parent = edge->parentItem(); + if(!parent) + return; + + QGIView *viewItem = dynamic_cast(parent); + if(!viewItem) + return; + + TechDraw::DrawView *viewObj = viewItem->getViewObject(); + + std::stringstream ss; + //ss << "Edge" << edge->getReference(); + ss << "Edge" << edge->getProjIndex(); + //bool accepted = + static_cast (Gui::Selection().addSelection(viewObj->getDocument()->getName(), + viewObj->getNameInDocument(), + ss.str().c_str())); + } + + QGIVertex *vert = dynamic_cast(*it); + if(vert) { + // Find the parent view that this edges is contained within + //WF: sb Vertex + QGI *parent = vert->parentItem(); + if(!parent) + return; + + QGIView *viewItem = dynamic_cast(parent); + if(!viewItem) + return; + + TechDraw::DrawView *viewObj = viewItem->getViewObject(); + + std::stringstream ss; + ss << "Vertex" << vert->getProjIndex(); + //bool accepted = + static_cast (Gui::Selection().addSelection(viewObj->getDocument()->getName(), + viewObj->getNameInDocument(), + ss.str().c_str())); + + } + + QGIDatumLabel *dimLabel = dynamic_cast(*it); + if(dimLabel) { + // Find the parent view (dimLabel->dim->view) + + QGI *dimParent = dimLabel->parentItem(); + + if(!dimParent) + return; + + QGIView *dimItem = dynamic_cast(dimParent); + + if(!dimItem) + return; + + TechDraw::DrawView *dimObj = dimItem->getViewObject(); + + //bool accepted = + static_cast (Gui::Selection().addSelection(dimObj->getDocument()->getName(),dimObj->getNameInDocument())); + + } + continue; + + } else { + + TechDraw::DrawView *viewObj = itemView->getViewObject(); + + std::string doc_name = viewObj->getDocument()->getName(); + std::string obj_name = viewObj->getNameInDocument(); + + Gui::Selection().addSelection(doc_name.c_str(), obj_name.c_str()); + } + + } + + blockConnection(block); +} + +void MDIViewPage::updateTemplate(bool forceUpdate) +{ + App::DocumentObject *templObj = pageGui->getPageObject()->Template.getValue(); + // TODO: what if template has been deleted? templObj will be NULL. segfault? + if (!templObj) { + Base::Console().Log("INFO - MDIViewPage::updateTemplate - Page: %s has NO template!!\n",pageGui->getPageObject()->getNameInDocument()); + return; + } + + if(pageGui->getPageObject()->Template.isTouched() || templObj->isTouched()) { + // Template is touched so update + + if(forceUpdate || + (templObj && templObj->isTouched() && templObj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) ) { + + QGITemplate *qItemTemplate = m_view->getTemplate(); + + if(qItemTemplate) { + TechDraw::DrawTemplate *pageTemplate = dynamic_cast(templObj); + qItemTemplate->setTemplate(pageTemplate); + qItemTemplate->updateView(); + } + } + } + + // m_view->setPageFeature(pageFeature); redundant +} + +void MDIViewPage::updateDrawing(bool forceUpdate) +{ + // We cannot guarantee if the number of graphical representations (QGIVxxxx) have changed so check the number + // Why? + const std::vector &graphicsList = m_view->getViews(); + const std::vector &pageChildren = pageGui->getPageObject()->Views.getValues(); + + // Count total # DocumentObjects in Page + unsigned int docObjCount = 0; + for(std::vector::const_iterator it = pageChildren.begin(); it != pageChildren.end(); ++it) { + App::DocumentObject *docObj = *it; + if(docObj->getTypeId().isDerivedFrom(TechDraw::DrawViewCollection::getClassTypeId())) { + TechDraw::DrawViewCollection *collection = dynamic_cast(docObj); + docObjCount += collection->countChildren(); // Include self + } + docObjCount += 1; + } + + if(graphicsList.size() < docObjCount) { + // there are more DocumentObjects than graphical representations (QGIVxxxx's) + // Find which DocumentObjects have no graphical representation (QGIVxxxx) + // Iterate over DocumentObjects without graphical representations and create the QGIVxxxx + // TODO think of a better algorithm to deal with any changes to views list + std::vector notFnd; + findMissingViews(pageChildren, notFnd); + for(std::vector::const_iterator it = notFnd.begin(); it != notFnd.end(); ++it) { + attachView(*it); + } + } else if(graphicsList.size() > docObjCount) { + // There are more graphical representations (QGIVxxxx) than DocumentObjects + // Remove the orphans + std::vector::const_iterator itGraphics = graphicsList.begin(); + std::vector newGraphicsList; + bool fnd = false; + while(itGraphics != graphicsList.end()) { + fnd = orphanExists((*itGraphics)->getViewName(), pageChildren); + if(fnd) { + newGraphicsList.push_back(*itGraphics); + } else { + if (m_view->scene() == (*itGraphics)->scene()) { + (*itGraphics)->hide(); + m_view->scene()->removeItem(*itGraphics); + } else { // this "shouldn't" happen, but it does + Base::Console().Log("ERROR - MDIViewPage::updateDrawing - %s already removed from QGraphicsScene\n", + (*itGraphics)->getViewName()); + } + deleteItems.append(*itGraphics); // delete in the destructor when completly safe. TEMP SOLUTION + } + itGraphics++; + } + + // Update the QGVPage (QGraphicsView) list of QGIVxxxx + m_view->setViews(newGraphicsList); + } + + // Update all the QGIVxxxx + const std::vector &upviews = m_view->getViews(); + for(std::vector::const_iterator it = upviews.begin(); it != upviews.end(); ++it) { + if((*it)->getViewObject()->isTouched() || + forceUpdate) { + (*it)->updateView(forceUpdate); + } + } +} + +void MDIViewPage::findMissingViews(const std::vector &list, std::vector &missing) +{ + for(std::vector::const_iterator it = list.begin(); it != list.end(); ++it) { + + if(!hasQView(*it)) + missing.push_back(*it); + + if((*it)->getTypeId().isDerivedFrom(TechDraw::DrawViewCollection::getClassTypeId())) { + std::vector missingChildViews; + TechDraw::DrawViewCollection *collection = dynamic_cast(*it); + // Find Child Views recursively + findMissingViews(collection->Views.getValues(), missingChildViews); + + // Append the views to current missing list + for(std::vector::const_iterator it = missingChildViews.begin(); it != missingChildViews.end(); ++it) { + missing.push_back(*it); + } + } + } +} + +/// Helper function +bool MDIViewPage::hasQView(App::DocumentObject *obj) +{ + const std::vector &views = m_view->getViews(); + std::vector::const_iterator qview = views.begin(); + + while(qview != views.end()) { + // Unsure if we can compare pointers so rely on name + if(strcmp((*qview)->getViewObject()->getNameInDocument(), obj->getNameInDocument()) == 0) { + return true; + } + qview++; + } + + return false; +} + +/// Helper function +bool MDIViewPage::orphanExists(const char *viewName, const std::vector &list) +{ + for(std::vector::const_iterator it = list.begin(); it != list.end(); ++it) { + + //Check child objects too recursively + if((*it)->isDerivedFrom(TechDraw::DrawViewCollection::getClassTypeId())) { + TechDraw::DrawViewCollection *collection = dynamic_cast(*it); + if(orphanExists(viewName, collection->Views.getValues())) + return true; + } + + // Unsure if we can compare pointers so rely on name + if(strcmp(viewName, (*it)->getNameInDocument()) == 0) { + return true; + } + } + return false; +} + + +void MDIViewPage::setRenderer(QAction *action) +{ +#ifndef QT_NO_OPENGL + m_highQualityAntialiasingAction->setEnabled(false); +#endif + + if (action == m_nativeAction) + m_view->setRenderer(QGVPage::Native); +#ifndef QT_NO_OPENGL + else if (action == m_glAction) { + m_highQualityAntialiasingAction->setEnabled(true); + m_view->setRenderer(QGVPage::OpenGL); + } +#endif + else if (action == m_imageAction) { + m_view->setRenderer(QGVPage::Image); + } +} +bool MDIViewPage::onMsg(const char* pMsg, const char** ppReturn) +{ + if (strcmp("ViewFit",pMsg) == 0) { + viewAll(); + return true; + } else if (strcmp("Redo", pMsg) == 0 ) { + getAppDocument()->redo(); + Gui::Command::updateActive(); + return true; + } else if (strcmp("Save", pMsg) == 0 ) { + getAppDocument()->save(); + Gui::Command::updateActive(); + return true; + } else if (strcmp("SaveAs", pMsg) == 0 ) { + getAppDocument()->saveAs(""); + Gui::Command::updateActive(); + return true; + } else if (strcmp("Undo", pMsg) == 0 ) { + getAppDocument()->undo(); + Gui::Command::updateActive(); + return true; + } + else if(strcmp("Undo",pMsg) == 0 ) { + Gui::Document *doc = getGuiDocument(); + if (doc) { + doc->undo(1); + return true; + } + } + else if(strcmp("Redo",pMsg) == 0 ) { + Gui::Document *doc = getGuiDocument(); + if (doc) { + doc->redo(1); + return true; + } + } + return false; +} + +bool MDIViewPage::onHasMsg(const char* pMsg) const +{ + if (strcmp("ViewFit",pMsg) == 0) + return true; + else if(strcmp("Redo", pMsg) == 0 && getAppDocument()->getAvailableRedos() > 0) + return true; + else if(strcmp("Undo", pMsg) == 0 && getAppDocument()->getAvailableUndos() > 0) + return true; + else if (strcmp("Print",pMsg) == 0) + return true; + else if (strcmp("Save",pMsg) == 0) + return true; + else if (strcmp("SaveAs",pMsg) == 0) + return true; + else if (strcmp("PrintPreview",pMsg) == 0) + return true; + else if (strcmp("PrintPdf",pMsg) == 0) + return true; + return false; +} + +void MDIViewPage::onRelabel(Gui::Document *pDoc) +{ + if (!bIsPassive && pDoc) { + QString cap = QString::fromLatin1("%1 : %2[*]") + .arg(QString::fromUtf8(pDoc->getDocument()->Label.getValue())) + .arg(objectName()); + setWindowTitle(cap); + } +} + +void MDIViewPage::printPdf() +{ + Gui::FileOptionsDialog dlg(this, 0); + dlg.setFileMode(QFileDialog::AnyFile); + dlg.setAcceptMode(QFileDialog::AcceptSave); + dlg.setWindowTitle(tr("Export PDF")); + dlg.setFilters(QStringList() << QString::fromLatin1("%1 (*.pdf)").arg(tr("PDF file"))); + + QGridLayout *gridLayout; + QGridLayout *formLayout; + QGroupBox *groupBox; + QListWidget *listWidget; + QListWidgetItem* item; + QWidget *form = new QWidget(&dlg); + form->resize(40, 300); + formLayout = new QGridLayout(form); + groupBox = new QGroupBox(form); + gridLayout = new QGridLayout(groupBox); + listWidget = new QListWidget(groupBox); + gridLayout->addWidget(listWidget, 0, 0, 1, 1); + formLayout->addWidget(groupBox, 0, 0, 1, 1); + + groupBox->setTitle(tr("Page sizes")); + item = new QListWidgetItem(tr("A0"), listWidget); + item->setData(Qt::UserRole, QVariant(QPrinter::A0)); + item = new QListWidgetItem(tr("A1"), listWidget); + item->setData(Qt::UserRole, QVariant(QPrinter::A1)); + item = new QListWidgetItem(tr("A2"), listWidget); + item->setData(Qt::UserRole, QVariant(QPrinter::A2)); + item = new QListWidgetItem(tr("A3"), listWidget); + item->setData(Qt::UserRole, QVariant(QPrinter::A3)); + item = new QListWidgetItem(tr("A4"), listWidget); + item->setData(Qt::UserRole, QVariant(QPrinter::A4)); + item = new QListWidgetItem(tr("A5"), listWidget); + item->setData(Qt::UserRole, QVariant(QPrinter::A5)); + item = new QListWidgetItem(tr("Letter"), listWidget); + item->setData(Qt::UserRole, QVariant(QPrinter::Letter)); + item = new QListWidgetItem(tr("Legal"), listWidget); + item->setData(Qt::UserRole, QVariant(QPrinter::Legal)); + //listWidget->item(4)->setSelected(true); // by default A4 + int index = 4; // by default A4 + for (int i=0; icount(); i++) { + if (listWidget->item(i)->data(Qt::UserRole).toInt() == m_pageSize) { + index = i; + break; + } + } + listWidget->item(index)->setSelected(true); + dlg.setOptionsWidget(Gui::FileOptionsDialog::ExtensionRight, form, false); + + if (dlg.exec() == QDialog::Accepted) { + Gui::WaitCursor wc; + QString filename = dlg.selectedFiles().front(); + QPrinter printer(QPrinter::HighResolution); + printer.setFullPage(true); + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setOutputFileName(filename); + printer.setOrientation(m_orientation); + QList items = listWidget->selectedItems(); + if (items.size() == 1) { + int AX = items.front()->data(Qt::UserRole).toInt(); + printer.setPaperSize(QPrinter::PageSize(AX)); + } + + print(&printer); + } +} + +void MDIViewPage::print() +{ + QPrinter printer(QPrinter::HighResolution); + printer.setFullPage(true); + printer.setPageSize(m_pageSize); + printer.setOrientation(m_orientation); + QPrintDialog dlg(&printer, this); + if (dlg.exec() == QDialog::Accepted) { + print(&printer); + } +} + +void MDIViewPage::printPreview() +{ + QPrinter printer(QPrinter::HighResolution); + printer.setFullPage(true); + printer.setPageSize(m_pageSize); + printer.setOrientation(m_orientation); + + QPrintPreviewDialog dlg(&printer, this); + connect(&dlg, SIGNAL(paintRequested (QPrinter *)), + this, SLOT(print(QPrinter *))); + dlg.exec(); +} + + +void MDIViewPage::print(QPrinter* printer) +{ + // As size of the render area paperRect() should be used. When performing a real + // print pageRect() may also work but the output is cropped at the bottom part. + // So, independent whether pageRect() or paperRect() is used there is no scaling effect. + // However, when using a different paper size as set in the drawing template (e.g. + // DIN A5 instead of DIN A4) then the output is scaled. + // + // When creating a PDF file there seems to be no difference between pageRect() and + // paperRect(). + // + // When showing the preview of a print paperRect() must be used because with pageRect() + // a certain scaling effect can be observed and the content becomes smaller. + QPaintEngine::Type paintType = printer->paintEngine()->type(); + if (printer->outputFormat() == QPrinter::NativeFormat) { + int w = printer->widthMM(); + int h = printer->heightMM(); + QPrinter::PaperSize realPaperSize = getPageSize(w, h); + QPrinter::PaperSize curPaperSize = printer->paperSize(); + + // for the preview a 'Picture' paint engine is used which we don't + // care if it uses wrong printer settings + bool doPrint = paintType != QPaintEngine::Picture; + + if (doPrint && printer->orientation() != m_orientation) { + int ret = QMessageBox::warning(this, tr("Different orientation"), + tr("The printer uses a different orientation than the drawing.\n" + "Do you want to continue?"), + QMessageBox::Yes | QMessageBox::No); + if (ret != QMessageBox::Yes) + return; + } + else if (doPrint && realPaperSize != m_pageSize) { + int ret = QMessageBox::warning(this, tr("Different paper size"), + tr("The printer uses a different paper size than the drawing.\n" + "Do you want to continue?"), + QMessageBox::Yes | QMessageBox::No); + if (ret != QMessageBox::Yes) + return; + } + else if (doPrint && curPaperSize != m_pageSize) { + int ret = QMessageBox::warning(this, tr("Different paper size"), + tr("The printer uses a different paper size than the drawing.\n" + "Do you want to continue?"), + QMessageBox::Yes | QMessageBox::No); + if (ret != QMessageBox::Yes) + return; + } + } + + QPainter p(printer); + if (!p.isActive() && !printer->outputFileName().isEmpty()) { + qApp->setOverrideCursor(Qt::ArrowCursor); + QMessageBox::critical(this, tr("Opening file failed"), + tr("Can't open file '%1' for writing.").arg(printer->outputFileName())); + qApp->restoreOverrideCursor(); + return; + } + + QRect rect = printer->paperRect(); +#ifdef Q_OS_WIN32 + // On Windows the preview looks broken when using paperRect as render area. + // Although the picture is scaled when using pageRect, it looks just fine. + if (paintType == QPaintEngine::Picture) + rect = printer->pageRect(); +#endif + + //bool block = + static_cast (blockConnection(true)); // avoid to be notified by itself + Gui::Selection().clearSelection(); + + m_view->toggleEdit(false); + m_view->scene()->update(); + + Gui::Selection().clearSelection(); + + m_view->scene()->render(&p, rect); + + // Reset + m_view->toggleEdit(true); +} + +//QPrinter::PageSize is obsolete. Use QPrinter::PaperSize instead. +QPrinter::PageSize MDIViewPage::getPageSize(int w, int h) const +{ + static const float paperSizes[][2] = { + {210, 297}, // A4 + {176, 250}, // B5 + {215.9f, 279.4f}, // Letter + {215.9f, 355.6f}, // Legal + {190.5f, 254}, // Executive + {841, 1189}, // A0 + {594, 841}, // A1 + {420, 594}, // A2 + {297, 420}, // A3 + {148, 210}, // A5 + {105, 148}, // A6 + {74, 105}, // A7 + {52, 74}, // A8 + {37, 52}, // A8 + {1000, 1414}, // B0 + {707, 1000}, // B1 + {31, 44}, // B10 + {500, 707}, // B2 + {353, 500}, // B3 + {250, 353}, // B4 + {125, 176}, // B6 + {88, 125}, // B7 + {62, 88}, // B8 + {33, 62}, // B9 + {163, 229}, // C5E + {105, 241}, // US Common + {110, 220}, // DLE + {210, 330}, // Folio + {431.8f, 279.4f}, // Ledger + {279.4f, 431.8f} // Tabloid + }; + + QPrinter::PageSize ps = QPrinter::Custom; + for (int i=0; i<30; i++) { + if (std::abs(paperSizes[i][0]-w) <= 1 && + std::abs(paperSizes[i][1]-h) <= 1) { + ps = static_cast(i); + break; + } + else + if (std::abs(paperSizes[i][0]-h) <= 1 && + std::abs(paperSizes[i][1]-w) <= 1) { + ps = static_cast(i); + break; + } + } + + return ps; +} + +void MDIViewPage::viewAll() +{ + m_view->fitInView(m_view->scene()->sceneRect(), Qt::KeepAspectRatio); +} + +void MDIViewPage::onSelectionChanged(const Gui::SelectionChanges& msg) +{ + if (msg.Type == Gui::SelectionChanges::ClrSelection) { + + } + else if (msg.Type == Gui::SelectionChanges::AddSelection || + msg.Type == Gui::SelectionChanges::RmvSelection) { + //bool select = (msg.Type == Gui::SelectionChanges::AddSelection); + // Check if it is a view object + } + else if (msg.Type == Gui::SelectionChanges::SetSelection) { + // do nothing here + } +} + +void MDIViewPage::saveSVG() +{ + QStringList filter; + filter << QObject::tr("SVG (*.svg)"); + filter << QObject::tr("All Files (*.*)"); + QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QObject::tr("Export page as SVG"), + QString(), filter.join(QLatin1String(";;"))); + if (fn.isEmpty()) { + return; + } + + TechDraw::DrawPage *page = pageGui->getPageObject(); + const QString docName = QString::fromUtf8(page->getDocument()->getName()); + const QString pageName = QString::fromUtf8(page->getNameInDocument()); + QString svgDescription = tr("Drawing page: ") + + pageName + + tr(" exported from FreeCAD document: ") + + docName; + + //int width = page->getPageWidth(); + //int height = page->getPageHeight(); + //Base::Console().Message("TRACE - saveSVG - page width: %d height: %d\n",width,height); //A4 297x210 + QSvgGenerator svgGen; + svgGen.setFileName(fn); + svgGen.setSize(QSize((int) page->getPageWidth(), (int)page->getPageHeight())); + svgGen.setViewBox(QRect(0, 0, page->getPageWidth(), page->getPageHeight())); + //TODO: Exported Svg file is not quite right. (blockConnection(true)); // avoid to be notified by itself + Gui::Selection().clearSelection(); + + m_view->toggleEdit(false); //fiddle cache, cosmetic lines, vertices, etc + m_view->scene()->update(); + + Gui::Selection().clearSelection(); + QPainter p; + + p.begin(&svgGen); + m_view->scene()->render(&p); + p.end(); + + m_view->toggleEdit(true); + m_view->scene()->update(); +} + +PyObject* MDIViewPage::getPyObject() +{ + Py_Return; +} + +#include "moc_MDIViewPage.cpp" diff --git a/src/Mod/TechDraw/Gui/MDIViewPage.h b/src/Mod/TechDraw/Gui/MDIViewPage.h new file mode 100644 index 0000000000..3883ea1f6c --- /dev/null +++ b/src/Mod/TechDraw/Gui/MDIViewPage.h @@ -0,0 +1,129 @@ +/*************************************************************************** + * Copyright (c) 2007 Jürgen Riegel * + * * + * 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_DRAWINGVIEW_H +#define DRAWINGGUI_DRAWINGVIEW_H + +#include +#include + +#include +#include + +QT_BEGIN_NAMESPACE +class QSlider; +class QAction; +class QActionGroup; +class QFile; +class QPopupMenu; +class QToolBar; +class QSvgWidget; +class QScrollArea; +class QPrinter; +QT_END_NAMESPACE +namespace TechDraw { +class DrawPage; +class DrawTemplate; +} + +namespace TechDrawGui +{ + +class ViewProviderDrawingPage; +class QGVPage; +class QGIView; + +class TechDrawGuiExport MDIViewPage : public Gui::MDIView, public Gui::SelectionObserver +{ + Q_OBJECT + +public: + MDIViewPage(ViewProviderDrawingPage *page, Gui::Document* doc, QWidget* parent = 0); + virtual ~MDIViewPage(); + +public Q_SLOTS: + void setRenderer(QAction *action); + void viewAll(); + void saveSVG(void); + void selectionChanged(); + +public: + /// Observer message from the Selection + void onSelectionChanged(const Gui::SelectionChanges& msg); + void preSelectionChanged(const QPoint &pos); + void selectFeature(App::DocumentObject *obj, bool state); + void clearSelection(); + void blockSelection(bool isBlocked); + + void attachTemplate(TechDraw::DrawTemplate *obj); + void updateTemplate(bool force = false); + void updateDrawing(bool force = false); + + bool onMsg(const char* pMsg,const char** ppReturn); + bool onHasMsg(const char* pMsg) const; + void onRelabel(Gui::Document *pDoc); + + void print(); + void print(QPrinter* printer); + void printPdf(); + void printPreview(); + + void setDocumentObject(const std::string&); + PyObject* getPyObject(); + +protected: + void findMissingViews( const std::vector &list, std::vector &missing); + bool hasQView(App::DocumentObject *obj); + bool orphanExists(const char *viewName, const std::vector &list); + int attachView(App::DocumentObject *obj); + void contextMenuEvent(QContextMenuEvent *event); + void closeEvent(QCloseEvent*); + void findPrinterSettings(const QString&); + QPrinter::PageSize getPageSize(int w, int h) const; + void setDimensionGroups(void); + +private: + QAction *m_nativeAction; + QAction *m_glAction; + QAction *m_exportSVGAction; + QAction *m_imageAction; + QAction *m_highQualityAntialiasingAction; + QAction *m_backgroundAction; + QAction *m_outlineAction; + + std::string m_objectName; + bool isSlectionBlocked; + QGVPage *m_view; + + QString m_currentPath; + QPrinter::Orientation m_orientation; + QPrinter::PageSize m_pageSize; + ViewProviderDrawingPage *pageGui; + + QList deleteItems; +}; + + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_DRAWINGVIEW_H diff --git a/src/Mod/TechDraw/Gui/PreCompiled.cpp b/src/Mod/TechDraw/Gui/PreCompiled.cpp new file mode 100644 index 0000000000..90814f0b6c --- /dev/null +++ b/src/Mod/TechDraw/Gui/PreCompiled.cpp @@ -0,0 +1,24 @@ +/*************************************************************************** + * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2007 * + * * + * 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" diff --git a/src/Mod/TechDraw/Gui/PreCompiled.h b/src/Mod/TechDraw/Gui/PreCompiled.h new file mode 100644 index 0000000000..7e32f7b439 --- /dev/null +++ b/src/Mod/TechDraw/Gui/PreCompiled.h @@ -0,0 +1,78 @@ +/*************************************************************************** + * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2007 * + * * + * 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_PRECOMPILED_H +#define DRAWINGGUI_PRECOMPILED_H + +#include + +// Importing of App classes +#ifdef FC_OS_WIN32 +//# define DrawingAppExport __declspec(dllimport) +# define DrawingExport __declspec(dllimport) +# define PartExport __declspec(dllimport) +# define TechDrawGuiExport __declspec(dllexport) +#else // for Linux +# define DrawingExport +# define PartExport +# define TechDrawGuiExport +#endif + +#ifdef _MSC_VER +# pragma warning(disable : 4005) +#endif + +#ifdef _PreComp_ + +// Python +#include + +// standard +#include +#include +#include + +// STL +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef FC_OS_WIN32 +# include +#endif + + +// Qt Toolkit +#ifndef __Qt4All__ +# include +#endif + +#endif //_PreComp_ + +#endif // DRAWINGGUI_PRECOMPILED_H diff --git a/src/Mod/TechDraw/Gui/QGCustomClip.cpp b/src/Mod/TechDraw/Gui/QGCustomClip.cpp new file mode 100644 index 0000000000..da2e63f7b6 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGCustomClip.cpp @@ -0,0 +1,103 @@ +/*************************************************************************** + * Copyright (c) 2015 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 +#endif + +#include +#include +#include +#include + +#include +#include "QGCustomClip.h" + +using namespace TechDrawGui; + +QGCustomClip::QGCustomClip() +{ + setHandlesChildEvents(false); //not sure if needs to handle events for Views in Group??? + setCacheMode(QGI::NoCache); + setAcceptHoverEvents(false); + setFlag(QGI::ItemIsSelectable, false); + setFlag(QGI::ItemIsMovable, false); + setFlag(QGI::ItemClipsChildrenToShape, true); + m_rect = QRectF(0.,0.,10.,10.); +} + +void QGCustomClip::centerAt(QPointF centerPos) +{ + QRectF box = boundingRect(); + double width = box.width(); + double height = box.height(); + double newX = centerPos.x() - width/2.; + double newY = centerPos.y() - height/2.; + setPos(newX,newY); +} + +void QGCustomClip::centerAt(double cX, double cY) +{ + QRectF box = boundingRect(); + double width = box.width(); + double height = box.height(); + double newX = cX - width/2.; + double newY = cY - height/2.; + setPos(newX,newY); +} + +void QGCustomClip::setRect(QRectF r) +{ + //prepareGeometryChange();?? + m_rect = r; +} + +void QGCustomClip::setRect(double x, double y, double w, double h) +{ + QRectF r(x,y,w,h); + setRect(r); +} + + +QRectF QGCustomClip::rect() +{ + return m_rect; +} + +void QGCustomClip::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { + QStyleOptionGraphicsItem myOption(*option); + myOption.state &= ~QStyle::State_Selected; + + QGIGroup::paint (painter, &myOption, widget); +} + +QRectF QGCustomClip::boundingRect() const //sb shape()? +{ + return m_rect; +} + diff --git a/src/Mod/TechDraw/Gui/QGCustomClip.h b/src/Mod/TechDraw/Gui/QGCustomClip.h new file mode 100644 index 0000000000..6b97acd18f --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGCustomClip.h @@ -0,0 +1,66 @@ +/*************************************************************************** + * Copyright (c) 2015 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_QGCUSTOMCLIP_H +#define DRAWINGGUI_QGCUSTOMCLIP_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QPainter; +class QStyleOptionGraphicsItem; +QT_END_NAMESPACE + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGCustomClip : public QGIGroup +{ +public: + explicit QGCustomClip(void); + ~QGCustomClip() {} + + enum {Type = QGI::UserType + 132}; + int type() const { return Type;} + virtual QRectF boundingRect() const; + + void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); + virtual void centerAt(QPointF centerPos); + virtual void centerAt(double cX, double cY); + virtual void setRect(QRectF r); + virtual void setRect(double x, double y, double w, double h); + virtual QRectF rect(); + + +protected: + +private: + QRectF m_rect; + +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGCUSTOMCLIP_H + diff --git a/src/Mod/TechDraw/Gui/QGCustomRect.cpp b/src/Mod/TechDraw/Gui/QGCustomRect.cpp new file mode 100644 index 0000000000..9a75ee95b4 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGCustomRect.cpp @@ -0,0 +1,76 @@ +/*************************************************************************** + * Copyright (c) 2015 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 +#endif + +#include +#include +#include +#include + +#include +#include +#include "QGCustomRect.h" + +using namespace TechDrawGui; + +QGCustomRect::QGCustomRect() +{ + setCacheMode(QGI::NoCache); +} + +void QGCustomRect::centerAt(QPointF centerPos) +{ + QRectF box = boundingRect(); + double width = box.width(); + double height = box.height(); + double newX = centerPos.x() - width/2.; + double newY = centerPos.y() - height/2.; + setPos(newX,newY); +} + +void QGCustomRect::centerAt(double cX, double cY) +{ + QRectF box = boundingRect(); + double width = box.width(); + double height = box.height(); + double newX = cX - width/2.; + double newY = cY - height/2.; + setPos(newX,newY); +} + + +void QGCustomRect::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { + QStyleOptionGraphicsItem myOption(*option); + myOption.state &= ~QStyle::State_Selected; + + QGraphicsRectItem::paint (painter, &myOption, widget); +} + diff --git a/src/Mod/TechDraw/Gui/QGCustomRect.h b/src/Mod/TechDraw/Gui/QGCustomRect.h new file mode 100644 index 0000000000..e5d0d939d4 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGCustomRect.h @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (c) 2015 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_QGCUSTOMRECT_H +#define DRAWINGGUI_QGCUSTOMRECT_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QPainter; +class QStyleOptionGraphicsItem; +QT_END_NAMESPACE + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGCustomRect : public QGraphicsRectItem +{ +public: + explicit QGCustomRect(void); + ~QGCustomRect() {} + + enum {Type = QGI::UserType + 133}; + int type() const { return Type;} + + virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); + virtual void centerAt(QPointF centerPos); + virtual void centerAt(double cX, double cY); + +protected: + +private: + +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGCUSTOMRECT_H + diff --git a/src/Mod/TechDraw/Gui/QGCustomSvg.cpp b/src/Mod/TechDraw/Gui/QGCustomSvg.cpp new file mode 100644 index 0000000000..ff3c438e47 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGCustomSvg.cpp @@ -0,0 +1,65 @@ +/*************************************************************************** + * Copyright (c) 2015 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 +#endif + +#include +#include "QGCustomSvg.h" + +using namespace TechDrawGui; + +QGCustomSvg::QGCustomSvg() +{ + setCacheMode(QGI::NoCache); +} + +void QGCustomSvg::centerAt(QPointF centerPos) +{ + QRectF box = boundingRect(); + double width = box.width(); + double height = box.height(); + double newX = centerPos.x() - width/2.; + double newY = centerPos.y() - height/2.; + setPos(newX,newY); +} + +void QGCustomSvg::centerAt(double cX, double cY) +{ + QRectF box = boundingRect(); + double width = box.width(); + double height = box.height(); + double newX = cX - width/2.; + double newY = cY - height/2.; + setPos(newX,newY); +} + +void QGCustomSvg::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { + QStyleOptionGraphicsItem myOption(*option); + myOption.state &= ~QStyle::State_Selected; + + QGraphicsSvgItem::paint (painter, &myOption, widget); +} + diff --git a/src/Mod/TechDraw/Gui/QGCustomSvg.h b/src/Mod/TechDraw/Gui/QGCustomSvg.h new file mode 100644 index 0000000000..a6daddec29 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGCustomSvg.h @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (c) 2015 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_QGCUSTOMSVG_H +#define DRAWINGGUI_QGCUSTOMSVG_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QPainter; +class QStyleOptionGraphicsItem; +QT_END_NAMESPACE + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGCustomSvg : public QGraphicsSvgItem +{ +public: + explicit QGCustomSvg(void); + ~QGCustomSvg() {} + + enum {Type = QGI::UserType + 131}; + int type() const { return Type;} + + virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); + virtual void centerAt(QPointF centerPos); + virtual void centerAt(double cX, double cY); + +protected: + +private: + +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGCUSTOMSVG_H + diff --git a/src/Mod/TechDraw/Gui/QGCustomText.cpp b/src/Mod/TechDraw/Gui/QGCustomText.cpp new file mode 100644 index 0000000000..3e42f68d8b --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGCustomText.cpp @@ -0,0 +1,103 @@ +/*************************************************************************** + * Copyright (c) 2015 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 +#include +#endif + +#include +#include +#include +#include + +#include +#include +#include "QGCustomText.h" + +using namespace TechDrawGui; + +QGCustomText::QGCustomText() +{ + setCacheMode(QGI::NoCache); +} + +void QGCustomText::centerAt(QPointF centerPos) +{ + QRectF box = boundingRect(); + double width = box.width(); + double height = box.height(); + double newX = centerPos.x() - width/2.; + double newY = centerPos.y() - height/2.; + setPos(newX,newY); +} + +void QGCustomText::centerAt(double cX, double cY) +{ + QRectF box = boundingRect(); + double width = box.width(); + double height = box.height(); + double newX = cX - width/2.; + double newY = cY - height/2.; + setPos(newX,newY); +} + +void QGCustomText::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { + QStyleOptionGraphicsItem myOption(*option); + myOption.state &= ~QStyle::State_Selected; + + //svg text is much larger than screen text. scene units(mm) vs points. + //need to scale text if going to svg. + //TODO: magic translation happens? approx: right ~8mm down: 12mm + (3mm per mm of text height) + //SVG transform matrix translation values are different for same font size + different fonts (osifont vs Ubuntu vs Arial)??? + // scale values are same for same font size + different fonts. + //double svgScale = 2.835; //72dpi/(25.4mm/in) + //double svgScale = 3.84; //96dpi/(25mm/in) + double svgScale = 2.88; //72dpi/(25mm/in) Qt logicalDpiY() is int + double svgMagicX = 8.0; + //double svgMagicY = 7.5; //idk + double fontSize = font().pointSizeF(); + //double ty = (12.0/svgScale + 3.0*fontSize/svgScale) + (svgMagicY/svgScale); + double ty = (12.0/svgScale + 3.0*fontSize/svgScale); + QPointF svgMove(-svgMagicX/svgScale,-ty); + + QPaintDevice* hw = painter->device(); + //QPaintDeviceMetrics hwm(hw); + //QPrinter* pr = dynamic_cast(hw); //printer does not rescale vs screen? + QSvgGenerator* svg = dynamic_cast(hw); + if (svg) { + painter->scale(svgScale,svgScale); + painter->translate(svgMove); + } else { + painter->scale(1.0,1.0); + } + + QGraphicsTextItem::paint (painter, &myOption, widget); +} diff --git a/src/Mod/TechDraw/Gui/QGCustomText.h b/src/Mod/TechDraw/Gui/QGCustomText.h new file mode 100644 index 0000000000..32a8912268 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGCustomText.h @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (c) 2015 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_QGCUSTOMTEXT_H +#define DRAWINGGUI_QGCUSTOMTEXT_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QPainter; +class QStyleOptionGraphicsItem; +QT_END_NAMESPACE + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGCustomText : public QGraphicsTextItem +{ +public: + explicit QGCustomText(void); + ~QGCustomText() {} + + enum {Type = QGI::UserType + 130}; + int type() const { return Type;} + + virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); + virtual void centerAt(QPointF centerPos); + virtual void centerAt(double cX, double cY); + +protected: + +private: + +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGCUSTOMTEXT_H + diff --git a/src/Mod/TechDraw/Gui/QGIArrow.cpp b/src/Mod/TechDraw/Gui/QGIArrow.cpp new file mode 100644 index 0000000000..5e7dfb1240 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIArrow.cpp @@ -0,0 +1,112 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * * + * 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 "QGIView.h" +#include "QGIArrow.h" + +using namespace TechDrawGui; + +QGIArrow::QGIArrow(QGraphicsScene *scene) +{ + isFlipped = false; + + if(scene) { + scene->addItem(this); + } + + // Set Cache Mode + setCacheMode(QGI::NoCache); + +} + +QPainterPath QGIArrow::shape() const +{ + return path(); +} + +void QGIArrow::setHighlighted(bool state) +{ + QPen myPen = pen(); + QBrush myBrush = brush(); + if(state) { + myPen.setColor(Qt::blue); + myBrush.setColor(Qt::blue); + } else { + myPen.setColor(Qt::black); + myBrush.setColor(Qt::black); + } + setBrush(myBrush); + setPen(myPen); +} + +QVariant QGIArrow::itemChange(GraphicsItemChange change, const QVariant &value) +{ + return QGraphicsPathItem::itemChange(change, value); +} + +void QGIArrow::flip(bool state) { + isFlipped = state; +} + +void QGIArrow::draw() { + // the center is the end point on a dimension + QPainterPath path; + QPen pen(Qt::black); + pen.setWidth(1); + + QBrush brush(Qt::black); + //setPen(pen); + setBrush(brush); + + float length = -5.; //TODO: Arrow heads sb preference? size & type? + + if(isFlipped) + length *= -1; + path.moveTo(QPointF(0.,0.)); + path.lineTo(QPointF(length,-0.6)); + path.lineTo(QPointF(length, 0.6)); + + path.closeSubpath(); +// path.moveTo(QPointF(-1,1)); +// path.lineTo(QPointF(1,-1)); + setPath(path); + +} + +void QGIArrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + QStyleOptionGraphicsItem myOption(*option); + myOption.state &= ~QStyle::State_Selected; + QGraphicsPathItem::paint(painter, &myOption, widget); +} diff --git a/src/Mod/TechDraw/Gui/QGIArrow.h b/src/Mod/TechDraw/Gui/QGIArrow.h new file mode 100644 index 0000000000..92532b7cf2 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIArrow.h @@ -0,0 +1,70 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * * + * 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_QGRAPHICSITEMARROW_H +#define DRAWINGGUI_QGRAPHICSITEMARROW_H + +# include + +QT_BEGIN_NAMESPACE +class QPainter; +class QStyleOptionGraphicsItem; +QT_END_NAMESPACE + +namespace TechDrawGeometry { +class BaseGeom; +} + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGIArrow : public QGraphicsPathItem +{ +public: + explicit QGIArrow(QGraphicsScene *scene = 0 ); + ~QGIArrow() {} + + enum {Type = QGI::UserType + 109}; + int type() const { return Type;} + +public: + void draw(); + void setHighlighted(bool state); + void flip(bool state); + QPainterPath shape() const; + virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); + +protected: + // Preselection events: +// void hoverEnterEvent(QGraphicsSceneHoverEvent *event); +// void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + // Selection detection + QVariant itemChange(GraphicsItemChange change, const QVariant &value); + +private: + QPen m_pen; + bool isFlipped; +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGRAPHICSITEMARROW_H diff --git a/src/Mod/TechDraw/Gui/QGIDrawingTemplate.cpp b/src/Mod/TechDraw/Gui/QGIDrawingTemplate.cpp new file mode 100644 index 0000000000..676ec1f807 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIDrawingTemplate.cpp @@ -0,0 +1,135 @@ +/*************************************************************************** + * Copyright (c) 2012-2014 Luke Parry * + * * + * 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 +# include +#endif + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "QGIDrawingTemplate.h" + +using namespace TechDrawGui; + +QGIDrawingTemplate::QGIDrawingTemplate(QGraphicsScene *scene) : QGITemplate(scene), + pathItem(0) +{ + pathItem = new QGraphicsPathItem; + + // Invert the Y for the QGraphicsPathItem with Y pointing upwards + QTransform qtrans; + qtrans.scale(1., -1.); + + pathItem->setTransform(qtrans); + + addToGroup(pathItem); +} + +QGIDrawingTemplate::~QGIDrawingTemplate() +{ + pathItem = 0; +} + +QVariant QGIDrawingTemplate::itemChange(GraphicsItemChange change, const QVariant &value) +{ + return QGIGroup::itemChange(change, value); +} + + +void QGIDrawingTemplate::clearContents() +{ + +} + +TechDraw::DrawParametricTemplate * QGIDrawingTemplate::getParametricTemplate() +{ + if(pageTemplate && pageTemplate->isDerivedFrom(TechDraw::DrawParametricTemplate::getClassTypeId())) + return static_cast(pageTemplate); + else + return 0; +} + +void QGIDrawingTemplate::draw() +{ + + TechDraw::DrawParametricTemplate *tmplte = getParametricTemplate(); + if(!tmplte) { + throw Base::Exception("Template Feuature not set for QGIDrawingTemplate"); + } + + + // Clear the previous geometry stored + + // Get a list of geometry and iterate + const std::vector &geoms = tmplte->getGeometry(); + + std::vector::const_iterator it = geoms.begin(); + + QPainterPath path; + + // Draw Edges + // iterate through all the geometries + for(; it != geoms.end(); ++it) { + switch((*it)->geomType) { + case DrawingGeometry::GENERIC: { + + DrawingGeometry::Generic *geom = static_cast(*it); + + path.moveTo(geom->points[0].fX, geom->points[0].fY); + std::vector::const_iterator it = geom->points.begin(); + + for(++it; it != geom->points.end(); ++it) { + path.lineTo((*it).fX, (*it).fY); + } + break; + } + default: + break; + } + } + + pathItem->setPath(path); +} + +void QGIDrawingTemplate::updateView(bool update) +{ + draw(); +} + +#include "moc_QGIDrawingTemplate.cpp" diff --git a/src/Mod/TechDraw/Gui/QGIDrawingTemplate.h b/src/Mod/TechDraw/Gui/QGIDrawingTemplate.h new file mode 100644 index 0000000000..c43f5d503e --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIDrawingTemplate.h @@ -0,0 +1,69 @@ +/*************************************************************************** + * Copyright (c) 2012-2014 Luke Parry * + * * + * 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_QGRAPHICSITEMDRAWINGTEMPLATE_H +#define DRAWINGGUI_QGRAPHICSITEMDRAWINGTEMPLATE_H + +#include "QGITemplate.h" + +QT_BEGIN_NAMESPACE +class QGraphicsScene; +class QGraphicsSceneMouseEvent; +class QGraphicsPathItem; +QT_END_NAMESPACE + +namespace TechDraw { +class DrawParametricTemplate; +} + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGIDrawingTemplate : public QGITemplate +{ + Q_OBJECT + +public: + QGIDrawingTemplate(QGraphicsScene *); + ~QGIDrawingTemplate(); + + enum {Type = QGI::UserType + 151}; + int type() const { return Type;} + + void clearContents(); + void draw(); + virtual void updateView(bool update = false); + +Q_SIGNALS: + void dirty(); + +protected: + TechDraw::DrawParametricTemplate * getParametricTemplate(); + +protected: + virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); + QGraphicsPathItem *pathItem; +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGRAPHICSITEMDRAWINGTEMPLATE_H diff --git a/src/Mod/TechDraw/Gui/QGIEdge.cpp b/src/Mod/TechDraw/Gui/QGIEdge.cpp new file mode 100644 index 0000000000..6cc0d1b192 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIEdge.cpp @@ -0,0 +1,179 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * * + * 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 +#endif + +#include +#include +#include +#include + +#include +#include "QGIView.h" +#include "QGIEdge.h" + +using namespace TechDrawGui; + +QGIEdge::QGIEdge(int index) : + projIndex(index) +{ + setCacheMode(QGI::NoCache); + setFlag(QGI::ItemIsSelectable, true); + setFlag(QGI::ItemSendsScenePositionChanges, true); + setFlag(QGI::ItemSendsGeometryChanges,true); + setAcceptHoverEvents(true); + + strokeWidth = 1.; + + isCosmetic = false; + isHighlighted = false; + isHiddenEdge = false; + isSmoothEdge = false; + + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Drawing/Colors"); + App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("NormalColor", 0x00000000)); + m_colNormal = fcColor.asQColor(); + fcColor.setPackedValue(hGrp->GetUnsigned("SelectColor", 0x0000FF00)); + m_colSel = fcColor.asQColor(); + fcColor.setPackedValue(hGrp->GetUnsigned("PreSelectColor", 0x00080800)); + m_colPre = fcColor.asQColor(); + fcColor.setPackedValue(hGrp->GetUnsigned("HiddenColor", 0x08080800)); + m_colHid = fcColor.asQColor(); + + m_pen.setStyle(Qt::SolidLine); + m_pen.setCapStyle(Qt::RoundCap); + + m_pen.setCosmetic(isCosmetic); + setPrettyNormal(); +} + +QRectF QGIEdge::boundingRect() const +{ + return shape().controlPointRect(); +} + +QPainterPath QGIEdge::shape() const +{ + QPainterPath outline; + QPainterPathStroker stroker; + stroker.setWidth(2.0); + outline = stroker.createStroke(path()); + return outline; +} + + +QVariant QGIEdge::itemChange(GraphicsItemChange change, const QVariant &value) +{ + if (change == ItemSelectedHasChanged && scene()) { + if(isSelected()) { + setPrettySel(); + } else { + setPrettyNormal(); + } + } + return QGI::itemChange(change, value); +} + +void QGIEdge::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + setPrettyPre(); + QGraphicsPathItem::hoverEnterEvent(event); +} + +void QGIEdge::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + QGIView *view = dynamic_cast (parentItem()); //this is temp for debug?? + assert(view != 0); + + if(!isSelected() && !isHighlighted) { + setPrettyNormal(); + } + QGraphicsPathItem::hoverLeaveEvent(event); +} + +void QGIEdge::setCosmetic(bool state) +{ + m_pen.setCosmetic(state); + update(); +} + +void QGIEdge::setHighlighted(bool b) +{ + isHighlighted = b; + if(isHighlighted) { + setPrettySel(); + } else { + setPrettyNormal(); + } +} + +void QGIEdge::setPrettyNormal() { + if (isHiddenEdge) { + m_colCurrent = m_colHid; + } else { + m_colCurrent = m_colNormal; + } + update(); +} + +void QGIEdge::setPrettyPre() { + m_colCurrent = m_colPre; + update(); +} + +void QGIEdge::setPrettySel() { + m_colCurrent = m_colSel; + update(); +} + +void QGIEdge::setStrokeWidth(float width) { + strokeWidth = width; + update(); +} + +void QGIEdge::setHiddenEdge(bool b) { + isHiddenEdge = b; + if (b) m_colCurrent = m_colHid; + update(); + //TODO: need some fiddling here so hidden edges don't get selected?? is it ok to select a hidden edge? + //wf: probably bad drafing practice to dimension a hidden line +} + +void QGIEdge::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { + QStyleOptionGraphicsItem myOption(*option); + myOption.state &= ~QStyle::State_Selected; + + m_pen.setWidthF(strokeWidth); + m_pen.setColor(m_colCurrent); + setPen(m_pen); + QGraphicsPathItem::paint (painter, &myOption, widget); +} diff --git a/src/Mod/TechDraw/Gui/QGIEdge.h b/src/Mod/TechDraw/Gui/QGIEdge.h new file mode 100644 index 0000000000..8c663b28b7 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIEdge.h @@ -0,0 +1,95 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * * + * 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_QGRAPHICSITEMEDGE_H +#define DRAWINGGUI_QGRAPHICSITEMEDGE_H + +# include + +QT_BEGIN_NAMESPACE +class QPainter; +class QStyleOptionGraphicsItem; +QT_END_NAMESPACE + +namespace TechDrawGeometry { +class BaseGeom; +} + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGIEdge : public QGraphicsPathItem +{ +public: +// explicit QGIEdge(int ref = -1); + explicit QGIEdge(int index); + ~QGIEdge() {} + + enum {Type = QGI::UserType + 103}; + + int type() const { return Type;} + QRectF boundingRect() const; + QPainterPath shape() const; + virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); + + int getReference() const { return reference; } + void setReference(int ref) {reference = ref; } + int getProjIndex() const { return projIndex; } + + void setHighlighted(bool state); + void setCosmetic(bool state); + void setStrokeWidth(float width); + void setPrettyNormal(); + void setPrettyPre(); + void setPrettySel(); + void setHiddenEdge(bool b); + bool getHiddenEdge() { return(isHiddenEdge); } + void setSmoothEdge(bool b) { isSmoothEdge = b; } + bool getSmoothEdge() { return(isSmoothEdge); } + +protected: + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + QVariant itemChange(GraphicsItemChange change, const QVariant &value); + + int projIndex; //index of edge in Projection. must exist. + int reference; //index of edge in DrawViewPart Source. may not exist(-1). + + bool isHighlighted; + bool isCosmetic; + bool isHiddenEdge; + bool isSmoothEdge; + +private: + float strokeWidth; + float strokeScale; + QPen m_pen; + QColor m_colCurrent; + QColor m_colNormal; + QColor m_colPre; + QColor m_colSel; + QColor m_colHid; +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGRAPHICSITEMEDGE_H diff --git a/src/Mod/TechDraw/Gui/QGIFace.cpp b/src/Mod/TechDraw/Gui/QGIFace.cpp new file mode 100644 index 0000000000..457113248f --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIFace.cpp @@ -0,0 +1,126 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * * + * 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 +#include +#endif + +#include +#include +#include +#include + +#include "QGIView.h" +#include "QGIFace.h" + +using namespace TechDrawGui; + +QGIFace::QGIFace(int ref) : + reference(ref), + //m_fill(Qt::NoBrush) + //m_fill(Qt::CrossPattern) + m_fill(Qt::Dense3Pattern) + //m_fill(Qt::Dense6Pattern) +{ + setCacheMode(QGI::NoCache); + setAcceptHoverEvents(true); + + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Drawing/Colors"); + App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("NormalColor", 0x00000000)); + m_colNormal = fcColor.asQColor(); + fcColor.setPackedValue(hGrp->GetUnsigned("SelectColor", 0x0000FF00)); + m_colSel = fcColor.asQColor(); + fcColor.setPackedValue(hGrp->GetUnsigned("PreSelectColor", 0x00080800)); + m_colPre = fcColor.asQColor(); + + //m_pen.setStyle(Qt::NoPen); + m_brush.setStyle(m_fill); + setPrettyNormal(); +} + +QVariant QGIFace::itemChange(GraphicsItemChange change, const QVariant &value) +{ + if (change == ItemSelectedHasChanged && scene()) { + if(isSelected()) { + setPrettySel(); + } else { + setPrettyNormal(); + } + } + return QGI::itemChange(change, value); +} + +void QGIFace::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + setPrettyPre(); +} + +void QGIFace::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + QGIView *view = dynamic_cast (parentItem()); + + if(!isSelected() && !view->isSelected()) { + setPrettyNormal(); + } +} + +void QGIFace::setPrettyNormal() { + m_pen.setColor(m_colNormal); + m_brush.setColor(m_colNormal); + setPen(m_pen); + setBrush(m_brush); +} + +void QGIFace::setPrettyPre() { + m_pen.setColor(m_colPre); + m_brush.setColor(m_colPre); + setPen(m_pen); + setBrush(m_brush); +} + +void QGIFace::setPrettySel() { + m_pen.setColor(m_colSel); + m_brush.setColor(m_colSel); + setPen(m_pen); + setBrush(m_brush); +} + +void QGIFace::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { + QStyleOptionGraphicsItem myOption(*option); + //myOption.state &= ~QStyle::State_Selected; //temp for debugging + + //m_pen.setColor(m_colCurrent); + setPen(m_pen); + setBrush(m_brush); + QGraphicsPathItem::paint (painter, &myOption, widget); +} + diff --git a/src/Mod/TechDraw/Gui/QGIFace.h b/src/Mod/TechDraw/Gui/QGIFace.h new file mode 100644 index 0000000000..b687be32a4 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIFace.h @@ -0,0 +1,79 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * * + * 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_QGRAPHICSITEMFACE_H +#define DRAWINGGUI_QGRAPHICSITEMFACE_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QPainter; +class QStyleOptionGraphicsItem; +QT_END_NAMESPACE + +namespace TechDrawGeometry { +class BaseGeom; +} + +namespace TechDrawGui +{ + +class QGIFace : public QGraphicsPathItem +{ +public: + explicit QGIFace(int ref = -1); + ~QGIFace() {} + + enum {Type = QGI::UserType + 104}; + int type() const { return Type;} + virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); + +public: +// QPainterPath shape() const; + int getReference() const { return reference; } + void setPrettyNormal(); + void setPrettyPre(); + void setPrettySel(); + +protected: + // Preselection events: + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + // Selection detection + QVariant itemChange(GraphicsItemChange change, const QVariant &value); + +protected: + int reference; + +private: + QPen m_pen; + QBrush m_brush; + QColor m_colNormal; + QColor m_colPre; + QColor m_colSel; + Qt::BrushStyle m_fill; +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGRAPHICSITEMFACE_H diff --git a/src/Mod/TechDraw/Gui/QGIHatch.cpp b/src/Mod/TechDraw/Gui/QGIHatch.cpp new file mode 100644 index 0000000000..adae4e4c9b --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIHatch.cpp @@ -0,0 +1,193 @@ +/*************************************************************************** + * Copyright (c) 2015 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 +#endif + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "QGIView.h" +#include "QGIHatch.h" + +using namespace TechDrawGui; + +QGIHatch::QGIHatch(std::string parentHatch) : + m_hatch(parentHatch), + m_fill(Qt::NoBrush), + m_lastFill("") + //m_fill(Qt::Dense3Pattern) + //m_fill(Qt::CrossPattern) + //m_fill(Qt::Dense6Pattern) +{ + setHandlesChildEvents(false); + setFlag(QGI::ItemIsMovable, false); + setAcceptHoverEvents(true); + setCacheMode(QGI::NoCache); + + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Drawing/Colors"); + App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("NormalColor", 0x00000000)); + m_colNormal = fcColor.asQColor(); + fcColor.setPackedValue(hGrp->GetUnsigned("SelectColor", 0x0000FF00)); + m_colSel = fcColor.asQColor(); + fcColor.setPackedValue(hGrp->GetUnsigned("PreSelectColor", 0x00080800)); + m_colPre = fcColor.asQColor(); + + m_pen.setCosmetic(true); + m_pen.setWidthF(1.); + //m_pen.setStyle(Qt::NoPen); + m_pen.setColor(m_colNormal); + m_brush.setStyle(m_fill); + setPrettyNormal(); +} + +QGIHatch::~QGIHatch() +{ +} + +#if 0 +void QGIHatch::draw() +{ + const std::vector &objects = hatch->Edges.getValues(); + //const std::vector &SubNames = hatch->Edges.getSubValues(); + //const TechDraw::DrawViewPart *refObj = static_cast(objects[0]); + + //for edgeName in SubNames + // iEdge = _getIndexFromName(edgeName) //from CommandCreateDims.cpp + // geom = refObj->getEdgeGeomByRef(iEdge) + // subPath = drawPainterPath(geom) //from qgiViewPart + // m_path.addPath(subPath) + //m_path = m_path.simplified() //???? + //m_face->setPath(m_path); +} +#endif + +QVariant QGIHatch::itemChange(GraphicsItemChange change, const QVariant &value) +{ + if (change == ItemSelectedHasChanged && scene()) { + if(isSelected()) { + setPrettySel(); + } else { + setPrettyNormal(); + } + } + return QGI::itemChange(change, value); +} + +void QGIHatch::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + setPrettyPre(); +} + +void QGIHatch::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + QGIView *view = dynamic_cast (parentItem()); + + if(!isSelected() && !view->isSelected()) { + setPrettyNormal(); + } +} + +void QGIHatch::setPrettyNormal() +{ + m_pen.setColor(m_colNormal); + m_brush.setColor(m_colNormal); + setPen(m_pen); + setBrush(m_brush); +} + +void QGIHatch::setPrettyPre() +{ + m_pen.setColor(m_colPre); + m_brush.setColor(m_colPre); + setPen(m_pen); + setBrush(m_brush); +} + +void QGIHatch::setPrettySel() +{ + m_pen.setColor(m_colSel); + m_brush.setColor(m_colSel); + setPen(m_pen); + setBrush(m_brush); +} + +void QGIHatch::setFill(std::string fillSpec) +{ + if (fillSpec.empty()) { + return; + } + + if (fillSpec == m_lastFill) { + return; + } + + QString qs(QString::fromStdString(fillSpec)); + m_lastFill = fillSpec; + //QString qs(QString::fromUtf8("../src/Mod/Drawing/patterns/simple.svg")); + //QString qs(QString::fromUtf8("../src/Mod/Drawing/patterns/square.svg")); + QSvgRenderer renderer(qs); + //QBitmap pixMap(64,64); //this size is scene units (mm) instead of pixels? + QBitmap pixMap(renderer.defaultSize()); + pixMap.fill(Qt::white); //try Qt::transparent? + QPainter painter(&pixMap); + renderer.render(&painter); //svg texture -> bitmap + + m_texture = pixMap; + m_brush = QBrush(m_texture); + m_brush.setStyle(Qt::TexturePattern); +} + +void QGIHatch::setColor(App::Color c) +{ + m_colNormal = c.asQColor(); +} + +void QGIHatch::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { + QStyleOptionGraphicsItem myOption(*option); + myOption.state &= ~QStyle::State_Selected; + painter->setRenderHints( QPainter::Antialiasing | QPainter::SmoothPixmapTransform ); //doesn't seem to change much + setPen(m_pen); + setBrush(m_brush); + QGraphicsPathItem::paint (painter, &myOption, widget); +} diff --git a/src/Mod/TechDraw/Gui/QGIHatch.h b/src/Mod/TechDraw/Gui/QGIHatch.h new file mode 100644 index 0000000000..1da40c8d9a --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIHatch.h @@ -0,0 +1,93 @@ +/*************************************************************************** + * Copyright (c) 2015 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_QGRAPHICSITEMHATCH_H +#define DRAWINGGUI_QGRAPHICSITEMHATCH_H + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QPainter; +class QStyleOptionGraphicsItem; +QT_END_NAMESPACE + +namespace App { +class Color; +} + +namespace TechDraw { +class DrawHatch; +} + +namespace TechDrawGeometry { +class BaseGeom; +} + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGIHatch : public QGraphicsPathItem +{ + +public: + explicit QGIHatch(std::string parentHatch); + ~QGIHatch(); + + enum {Type = QGI::UserType + 122}; + int type() const { return Type;} + virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); + +public: + std::string getHatchName() const { return m_hatch; } + void setPrettyNormal(); + void setPrettyPre(); + void setPrettySel(); + void setFill(std::string fillSpec); + void setColor(App::Color c); + +protected: + // Preselection events: + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + // Selection detection + QVariant itemChange(GraphicsItemChange change, const QVariant &value); + +protected: + std::string m_hatch; + +private: + QPen m_pen; + QBrush m_brush; + QColor m_colNormal; + QColor m_colPre; + QColor m_colSel; + QBitmap m_texture; + Qt::BrushStyle m_fill; + std::string m_lastFill; +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGRAPHICSITEMHATCH_H diff --git a/src/Mod/TechDraw/Gui/QGIProjGroup.cpp b/src/Mod/TechDraw/Gui/QGIProjGroup.cpp new file mode 100644 index 0000000000..2f1b6e5750 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIProjGroup.cpp @@ -0,0 +1,231 @@ +/*************************************************************************** + * Copyright (c) 2012-2013 Luke Parry * + * * + * 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 +# include +# include +#endif + +#include +#include +#include +#include + +#include +#include + +#include "QGIProjGroup.h" + +using namespace TechDrawGui; + +QGIProjGroup::QGIProjGroup(const QPoint &pos, QGraphicsScene *scene) + :QGIViewCollection(pos, scene) +{ + setPos(pos); + origin = new QGIGroup(); + origin->setParentItem(this); + + // In place to ensure correct drawing and bounding box calculations + m_backgroundItem = new QGraphicsRectItem(); + m_backgroundItem->setPen(QPen(QColor(Qt::black))); + + //addToGroup(m_backgroundItem); + setFlag(ItemIsSelectable, false); + setFlag(ItemIsMovable, true); + setFiltersChildEvents(true); + borderVisible = false; +} + +QGIProjGroup::~QGIProjGroup() +{ +//TODO: if the QGIVO is deleted, should we clean up any remaining QGIVParts?? +} + +TechDraw::DrawProjGroup * QGIProjGroup::getDrawView(void) const +{ + App::DocumentObject *obj = getViewObject(); + return dynamic_cast(obj); +} + +bool QGIProjGroup::sceneEventFilter(QGI * watched, QEvent *event) +{ +// i want to handle events before the child item that would ordinarily receive them + if(event->type() == QEvent::GraphicsSceneMousePress || + event->type() == QEvent::GraphicsSceneMouseMove || + event->type() == QEvent::GraphicsSceneMouseRelease) { + + QGIView *qAnchor = getAnchorQItem(); + if(qAnchor && watched == qAnchor) { + QGraphicsSceneMouseEvent *mEvent = dynamic_cast(event); + + switch(event->type()) { + case QEvent::GraphicsSceneMousePress: + // TODO - Perhaps just pass the mouse event on to the anchor somehow? + if (scene()) { + scene()->clearSelection(); + qAnchor->setSelected(true); + } + mousePressEvent(mEvent); + break; + case QEvent::GraphicsSceneMouseMove: + mouseMoveEvent(mEvent); + break; + case QEvent::GraphicsSceneMouseRelease: + mouseReleaseEvent(mEvent); + break; + default: + break; + } + return true; + } + } + + return false; +} +QVariant QGIProjGroup::itemChange(GraphicsItemChange change, const QVariant &value) +{ + if(change == ItemChildAddedChange && scene()) { + QGI *childItem = value.value(); + QGIView* gView = dynamic_cast(childItem); + if(gView) { + TechDraw::DrawView *fView = gView->getViewObject(); + if(fView->getTypeId().isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) { + TechDraw::DrawProjGroupItem *projItemPtr = static_cast(fView); + QString type = QString::fromAscii(projItemPtr->Type.getValueAsString()); + + if (type == QString::fromAscii("Front")) { + gView->setLocked(true); + installSceneEventFilter(gView); + App::DocumentObject *docObj = getViewObject(); + TechDraw::DrawProjGroup *projectionGroup = dynamic_cast(docObj); + projectionGroup->Anchor.setValue(fView); + updateView(); + } else if ( type == QString::fromAscii("Top") || + type == QString::fromAscii("Bottom")) { + gView->alignTo(origin, QString::fromAscii("Vertical")); + } else if ( type == QString::fromAscii("Left") || + type == QString::fromAscii("Right") || + type == QString::fromAscii("Rear") ) { + gView->alignTo(origin, QString::fromAscii("Horizontal")); + } else if ( type == QString::fromAscii("FrontTopRight") || + type == QString::fromAscii("FrontBottomLeft") ) { + gView->alignTo(origin, QString::fromAscii("45slash")); + } else if ( type == QString::fromAscii("FrontTopLeft") || + type == QString::fromAscii("FrontBottomRight") ) { + gView->alignTo(origin, QString::fromAscii("45backslash")); + } + } + } + } + return QGIView::itemChange(change, value); +} + + +void QGIProjGroup::mousePressEvent(QGraphicsSceneMouseEvent * event) +{ + QGIView *qAnchor = getAnchorQItem(); + if(qAnchor) { + QPointF transPos = qAnchor->mapFromScene(event->scenePos()); + if(qAnchor->shape().contains(transPos)) { + //QGIViewCollection::mousePressEvent(event); + mousePos = event->screenPos(); + } + } + event->accept(); +} + +void QGIProjGroup::mouseMoveEvent(QGraphicsSceneMouseEvent * event) +{ + QGIView *qAnchor = getAnchorQItem(); + if(scene() && qAnchor && (qAnchor == scene()->mouseGrabberItem())) { + if((mousePos - event->screenPos()).manhattanLength() > 5) { //if the mouse has moved more than 5, process the mouse event + QGIViewCollection::mouseMoveEvent(event); + } + + } + event->accept(); +} + +void QGIProjGroup::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) +{ + if(scene()) { + QGIView *qAnchor = getAnchorQItem(); + if((mousePos - event->screenPos()).manhattanLength() < 5) { + if(qAnchor && qAnchor->shape().contains(event->pos())) { + qAnchor->mouseReleaseEvent(event); + } + } else if(scene() && qAnchor && (qAnchor == scene()->mouseGrabberItem())) { + // End of Drag + Gui::Command::openCommand("Drag Projection Group"); + //TODO: See if these commands actually handle the horizontal/vertical constraints properly... + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.X = %f", + getViewObject()->getNameInDocument(), x()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Y = %f", + getViewObject()->getNameInDocument(), getY());// inverts Y + Gui::Command::commitCommand(); + //Gui::Command::updateActive(); + } + } + QGIViewCollection::mouseReleaseEvent(event); +} + + +QGIView * QGIProjGroup::getAnchorQItem() const +{ + // Get the currently assigned anchor view + App::DocumentObject *anchorObj = getDrawView()->Anchor.getValue(); + TechDraw::DrawView *anchorView = dynamic_cast(anchorObj); + + // Locate the anchor view's qgraphicsitemview + QList list = childItems(); + + for (QList::iterator it = list.begin(); it != list.end(); ++it) { + QGIView *view = dynamic_cast(*it); + if(view && strcmp(view->getViewName(), anchorView->getNameInDocument()) == 0) { + return view; + } + } + return 0; +} + +void QGIProjGroup::updateView(bool update) +{ + m_backgroundItem->setRect(boundingRect()); + return QGIViewCollection::updateView(update); +} + +void QGIProjGroup::drawBorder() +{ +//QGIProjGroup does not have a border! +// Base::Console().Message("TRACE - QGIProjGroup::drawBorder - doing nothing!!\n"); +} + +#include "moc_QGIProjGroup.cpp" diff --git a/src/Mod/TechDraw/Gui/QGIProjGroup.h b/src/Mod/TechDraw/Gui/QGIProjGroup.h new file mode 100644 index 0000000000..3c23b6f0f8 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIProjGroup.h @@ -0,0 +1,84 @@ +/*************************************************************************** + * Copyright (c) 2012-2013 Luke Parry * + * * + * 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_QGIProjGroup_H +#define DRAWINGGUI_QGIProjGroup_H + +#include +#include +#include + +#include "QGIViewCollection.h" + +QT_BEGIN_NAMESPACE +class QGraphicsScene; +class QGraphicsSceneMouseEvent; +class QEvent; +QT_END_NAMESPACE + +namespace TechDraw { +class DrawView; +} + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGIProjGroup : public QGIViewCollection +{ + Q_OBJECT + +public: + QGIProjGroup(const QPoint &position, QGraphicsScene *scene); + ~QGIProjGroup(); + + enum {Type = QGI::UserType + 113}; + int type() const { return Type;} + + void alignTo(QGIProjGroup *, const QString &alignment); + + virtual void updateView(bool update = false); + virtual void drawBorder(void); + +Q_SIGNALS: + void dirty(); + +protected: + virtual bool sceneEventFilter(QGI * watched, QEvent *event); + virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); + // Mouse handling + virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event ); + virtual void mousePressEvent(QGraphicsSceneMouseEvent * event); + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event); + QGIView * getAnchorQItem() const; + +private: + /// Convenience function + TechDraw::DrawProjGroup * getDrawView(void) const; + + QGraphicsRectItem * m_backgroundItem; + QGI *origin; + QPoint mousePos; +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGIProjGroup_H diff --git a/src/Mod/TechDraw/Gui/QGISVGTemplate.cpp b/src/Mod/TechDraw/Gui/QGISVGTemplate.cpp new file mode 100644 index 0000000000..28fc09d64f --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGISVGTemplate.cpp @@ -0,0 +1,227 @@ +/*************************************************************************** + * Copyright (c) 2012-2014 Luke Parry * + * * + * 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 +#endif // #ifndef _PreComp_ + +#include +#include +#include +#include +#include + +#include +#include + +#include "QGISVGTemplate.h" + +using namespace TechDrawGui; + +QGISVGTemplate::QGISVGTemplate(QGraphicsScene *scene) + : QGITemplate(scene) +{ + m_svgRender = new QSvgRenderer(); + + m_svgItem = new QGraphicsSvgItem(); + m_svgItem->setSharedRenderer(m_svgRender); + + m_svgItem->setFlags(QGI::ItemClipsToShape); + m_svgItem->setCacheMode(QGI::NoCache); + + addToGroup(m_svgItem); +} + +QGISVGTemplate::~QGISVGTemplate() +{ + clearContents(); + delete m_svgRender; +} + +QVariant QGISVGTemplate::itemChange(GraphicsItemChange change, + const QVariant &value) +{ + return QGIGroup::itemChange(change, value); +} + + +void QGISVGTemplate::clearContents() +{ + for (std::vector::iterator it = textFields.begin(); + it != textFields.end(); ++it) { + delete *it; + } + textFields.clear(); +} + +void QGISVGTemplate::openFile(const QFile &file) +{ + +} + +void QGISVGTemplate::load(const QString &fileName) +{ + clearContents(); + + if (fileName.isEmpty()){ + return; + } + + QFile file(fileName); + if (!file.exists()) { + return; + } + m_svgRender->load(file.fileName()); + + QSize size = m_svgRender->defaultSize(); + //Base::Console().Log("size of svg document <%i,%i>", size.width(), size.height()); + m_svgItem->setSharedRenderer(m_svgRender); + + TechDraw::DrawSVGTemplate *tmplte = getSVGTemplate(); + + + //std::string temp = tmplte->Template.getValue(); + std::string temp = tmplte->PageResult.getValue(); //fixes non-drawing of restored template + if (temp.empty()) + return; + + Base::FileInfo fi(temp); + + // make a temp file for FileIncluded Property + std::string tempName = tmplte->PageResult.getExchangeTempFile(); + std::ostringstream ofile; + std::string tempendl = "--endOfLine--"; + std::string line; + + std::ifstream ifile (fi.filePath().c_str()); + while (!ifile.eof()) + { + std::getline(ifile,line); + // check if the marker in the template is found + if(line.find("") == std::string::npos) { + // if not - write through + ofile << line << tempendl; + } + } + + std::string outfragment(ofile.str()); + + // Find text tags with freecad:editable attribute and their matching tspans + // keep tagRegex in sync with App/DrawSVGTemplate.cpp + boost::regex tagRegex("]*freecad:editable=[^>]*)>[^<]*]*>([^<]*)"); + + // Smaller regexes for parsing matches to tagRegex + boost::regex editableNameRegex("freecad:editable=\"(.*?)\""); + boost::regex xRegex("x=\"([\\d.-]+)\""); + boost::regex yRegex("y=\"([\\d.-]+)\""); + //Note: some templates have fancy Transform clauses and don't use absolute x,y to position editableFields. + // editableFields will be in the wrong place in this case. + + std::string::const_iterator begin, end; + begin = outfragment.begin(); + end = outfragment.end(); + boost::match_results tagMatch, nameMatch, xMatch, yMatch; + + //TODO: Find location of special fields (first/third angle) and make graphics items for them + + // and update the sketch + while (boost::regex_search(begin, end, tagMatch, tagRegex)) { + if ( boost::regex_search(tagMatch[1].first, tagMatch[1].second, nameMatch, editableNameRegex) && + boost::regex_search(tagMatch[1].first, tagMatch[1].second, xMatch, xRegex) && + boost::regex_search(tagMatch[1].first, tagMatch[1].second, yMatch, yRegex) ) { + + QString xStr = QString::fromStdString(xMatch[1].str()); + QString yStr = QString::fromStdString(yMatch[1].str()); + QString editableName = QString::fromStdString(nameMatch[1].str()); + + double x = xStr.toDouble(); + double y = yStr.toDouble(); + + //TODO: this should probably be configurable without a code change + double editClickBoxSize = 1.5; + QColor editClickBoxColor = Qt::green; + + double width = editClickBoxSize; + double height = editClickBoxSize; + + TemplateTextField *item = new TemplateTextField(this, tmplte, nameMatch[1].str()); + float pad = 1; + item->setRect(x - pad, -tmplte->getHeight() + y - height - pad, + width + 2 * pad, height + 2 * pad); + + QPen myPen; + QBrush myBrush(editClickBoxColor,Qt::SolidPattern); + myPen.setStyle(Qt::SolidLine); + myPen.setColor(editClickBoxColor); + myPen.setWidth(0); // 0 means "cosmetic pen" - always 1px + item->setPen(myPen); + item->setBrush(myBrush); + + item->setZValue(100); + addToGroup(item); + textFields.push_back(item); + } + + begin = tagMatch[0].second; + } + + double xaspect, yaspect; + xaspect = tmplte->getWidth() / (double) size.width(); + yaspect = tmplte->getHeight() / (double) size.height(); + + QTransform qtrans; + qtrans.translate(0.f, -tmplte->getHeight()); + qtrans.scale(xaspect , yaspect); + m_svgItem->setTransform(qtrans); +} + +TechDraw::DrawSVGTemplate * QGISVGTemplate::getSVGTemplate() +{ + if(pageTemplate && pageTemplate->isDerivedFrom(TechDraw::DrawSVGTemplate::getClassTypeId())) + return static_cast(pageTemplate); + else + return 0; +} + +void QGISVGTemplate::draw() +{ + TechDraw::DrawSVGTemplate *tmplte = getSVGTemplate(); + if(!tmplte) + throw Base::Exception("Template Feature not set for QGISVGTemplate"); + + load(QString::fromUtf8(tmplte->PageResult.getValue())); +} + +void QGISVGTemplate::updateView(bool update) +{ + draw(); +} + +#include "moc_QGISVGTemplate.cpp" diff --git a/src/Mod/TechDraw/Gui/QGISVGTemplate.h b/src/Mod/TechDraw/Gui/QGISVGTemplate.h new file mode 100644 index 0000000000..99fe424e06 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGISVGTemplate.h @@ -0,0 +1,74 @@ +/*************************************************************************** + * Copyright (c) 2012-2014 Luke Parry * + * * + * 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_QGRAPHICSITEMSVGTEMPLATE_H +#define DRAWINGGUI_QGRAPHICSITEMSVGTEMPLATE_H + +#include "QGITemplate.h" + +QT_BEGIN_NAMESPACE +class QGraphicsScene; +class QGraphicsSceneMouseEvent; +class QGraphicsSvgItem; +class QSvgRenderer; +QT_END_NAMESPACE + +namespace TechDraw { +class DrawSVGTemplate; +} + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGISVGTemplate : public QGITemplate +{ + Q_OBJECT + +public: + QGISVGTemplate(QGraphicsScene *); + ~QGISVGTemplate(); + + enum {Type = QGI::UserType + 153}; + int type() const { return Type; } + + /// Currently just frees up textFields + void clearContents(); + void draw(); + virtual void updateView(bool update = false); + +Q_SIGNALS: + void dirty(); + +protected: + void openFile(const QFile &file); + void load (const QString & fileName); + +protected: + TechDraw::DrawSVGTemplate * getSVGTemplate(); + QGraphicsSvgItem *m_svgItem; + QSvgRenderer *m_svgRender; + virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); +}; // class QGISVGTemplate + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGRAPHICSITEMSVGTEMPLATE_H diff --git a/src/Mod/TechDraw/Gui/QGITemplate.cpp b/src/Mod/TechDraw/Gui/QGITemplate.cpp new file mode 100644 index 0000000000..7cf6bef613 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGITemplate.cpp @@ -0,0 +1,75 @@ +/*************************************************************************** + * Copyright (c) 2012-2014 Luke Parry * + * * + * 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 "QGITemplate.h" + +using namespace TechDrawGui; + +QGITemplate::QGITemplate(QGraphicsScene *scene) : QGIGroup(), + pageTemplate(0) +{ + setHandlesChildEvents(false); + setCacheMode(QGI::NoCache); + setZValue(-1000); //Template is situated in background + + scene->addItem(this); +} + +QGITemplate::~QGITemplate() +{ + pageTemplate = 0; +} + +QVariant QGITemplate::itemChange(GraphicsItemChange change, const QVariant &value) +{ + return QGIGroup::itemChange(change, value); +} + +void QGITemplate::setTemplate(TechDraw::DrawTemplate *obj) +{ + if(obj == 0) + return; + + pageTemplate = obj; +} + +void QGITemplate::clearContents() +{ + +} + +void QGITemplate::updateView(bool update) +{ + draw(); +} + +#include "moc_QGITemplate.cpp" diff --git a/src/Mod/TechDraw/Gui/QGITemplate.h b/src/Mod/TechDraw/Gui/QGITemplate.h new file mode 100644 index 0000000000..d661aaee6a --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGITemplate.h @@ -0,0 +1,73 @@ +/*************************************************************************** + * Copyright (c) 2012-2014 Luke Parry * + * * + * 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_QGRAPHICSITEMTEMPLATE_H +#define DRAWINGGUI_QGRAPHICSITEMTEMPLATE_H + +#include +#include + +#include "TemplateTextField.h" + +QT_BEGIN_NAMESPACE +class QGraphicsScene; +QT_END_NAMESPACE + +namespace TechDraw { +class DrawTemplate; +} + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGITemplate : public QObject, public QGIGroup +{ + Q_OBJECT + +public: + QGITemplate(QGraphicsScene *); + ~QGITemplate(); + + enum {Type = QGI::UserType + 150}; + int type() const { return Type;} + + void clearContents(); + + void setTemplate(TechDraw::DrawTemplate *obj); + TechDraw::DrawTemplate * getTemplate() { return pageTemplate; } + + inline qreal getY() { return y() * -1; } + + virtual void updateView(bool update = false); + + virtual void draw() = 0; + +protected: + virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); + TechDraw::DrawTemplate *pageTemplate; + + std::vector textFields; +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGRAPHICSITEMTEMPLATE_H diff --git a/src/Mod/TechDraw/Gui/QGIVertex.cpp b/src/Mod/TechDraw/Gui/QGIVertex.cpp new file mode 100644 index 0000000000..4871f6072e --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIVertex.cpp @@ -0,0 +1,134 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * * + * 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 +#endif + +#include +#include +#include +#include + +#include "QGIView.h" +#include "QGIVertex.h" + +using namespace TechDrawGui; + +QGIVertex::QGIVertex(int index) : + projIndex(index), + m_radius(2), + m_fill(Qt::SolidPattern) +{ + setCacheMode(QGI::NoCache); + setFlag(QGI::ItemIsSelectable, true); + setFlag(QGI::ItemSendsScenePositionChanges, true); + setFlag(QGI::ItemSendsGeometryChanges,true); + setAcceptHoverEvents(true); + + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Drawing/Colors"); + App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("NormalColor", 0x00000000)); + m_colNormal = fcColor.asQColor(); + fcColor.setPackedValue(hGrp->GetUnsigned("SelectColor", 0x0000FF00)); + m_colSel = fcColor.asQColor(); + fcColor.setPackedValue(hGrp->GetUnsigned("PreSelectColor", 0x00080800)); + m_colPre = fcColor.asQColor(); + + m_brush.setStyle(m_fill); + setPrettyNormal(); +} + +QVariant QGIVertex::itemChange(GraphicsItemChange change, const QVariant &value) +{ + if (change == ItemSelectedHasChanged && scene()) { + if(isSelected()) { + setPrettySel(); + } else { + setPrettyNormal(); + } + } + return QGI::itemChange(change, value); +} + +void QGIVertex::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + setPrettyPre(); +} + +void QGIVertex::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + QGIView *view = dynamic_cast (parentItem()); + assert(view != 0); + + if(!isSelected() && !isHighlighted) { + setPrettyNormal(); + } +} + +void QGIVertex::setHighlighted(bool b) +{ + isHighlighted = b; + if(isHighlighted) { + setPrettySel(); + } else { + setPrettyNormal(); + } + update(); +} + +void QGIVertex::setPrettyNormal() { + m_colCurrent = m_colNormal; + update(); +} + +void QGIVertex::setPrettyPre() { + m_colCurrent = m_colPre; + update(); +} + +void QGIVertex::setPrettySel() { + m_colCurrent = m_colSel; + update(); +} + +void QGIVertex::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + QStyleOptionGraphicsItem myOption(*option); + myOption.state &= ~QStyle::State_Selected; + + m_pen.setColor(m_colCurrent); + setPen(m_pen); + m_brush.setColor(m_colCurrent); + m_brush.setStyle(m_fill); + setBrush(m_brush); + setRect(-m_radius,-m_radius,2.*m_radius,2.*m_radius); + QGraphicsEllipseItem::paint (painter, &myOption, widget); +} + + diff --git a/src/Mod/TechDraw/Gui/QGIVertex.h b/src/Mod/TechDraw/Gui/QGIVertex.h new file mode 100644 index 0000000000..219d07c1db --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIVertex.h @@ -0,0 +1,89 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * * + * 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_QGRAPHICSITEMVERTEX_H +#define DRAWINGGUI_QGRAPHICSITEMVERTEX_H + +# include + +QT_BEGIN_NAMESPACE +class QPainter; +class QStyleOptionGraphicsItem; +QT_END_NAMESPACE + +namespace TechDrawGeometry { +class BaseGeom; +} + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGIVertex : public QGraphicsEllipseItem +{ +public: + //explicit QGIVertex(int ref = -1); + explicit QGIVertex(int index); + ~QGIVertex() {} + + enum {Type = QGI::UserType + 105}; + int type() const { return Type;} + virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); + + int getReference() const { return reference; } + void setReference(int ref) {reference = ref; } + int getProjIndex() const { return projIndex; } + + float getRadius() { return m_radius; } + void setRadius(float r) { m_radius = r; } + Qt::BrushStyle getFill() { return m_fill; } + void setFill(Qt::BrushStyle f) { m_fill = f; } + + void setHighlighted(bool isHighlighted); + void setPrettyNormal(); + void setPrettyPre(); + void setPrettySel(); + +protected: + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + QVariant itemChange(GraphicsItemChange change, const QVariant &value); + + int projIndex; //index of vertex in Projection. must exist. + int reference; //index of vertex in DrawView Source. may not exist(-1). + + bool isHighlighted; + +private: + QPen m_pen; + QBrush m_brush; + QColor m_colCurrent; + QColor m_colNormal; + QColor m_colPre; + QColor m_colSel; + float m_radius; + Qt::BrushStyle m_fill; +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGRAPHICSITEMVERTEX_H + diff --git a/src/Mod/TechDraw/Gui/QGIView.cpp b/src/Mod/TechDraw/Gui/QGIView.cpp new file mode 100644 index 0000000000..702d6dda24 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIView.cpp @@ -0,0 +1,379 @@ +/*************************************************************************** + * Copyright (c) 2012-2013 Luke Parry * + * * + * 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 +#include +#include +#include +#include +#include +#include +#include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include "../App/DrawView.h" +#include "../App/DrawViewClip.h" +#include "QGIView.h" +#include "QGCustomClip.h" +#include "QGIViewClip.h" + +using namespace TechDrawGui; + +void _debugRect(char* text, QRectF r); + +QGIView::QGIView(const QPoint &pos, QGraphicsScene *scene) + :QGIGroup(), + locked(false), + borderVisible(true), + m_innerView(false) +{ + setFlag(QGI::ItemIsSelectable,true); + setFlag(QGI::ItemSendsScenePositionChanges, true); + setFlag(QGI::ItemSendsGeometryChanges,true); + setAcceptHoverEvents(true); + setPos(pos); + + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Drawing/Colors"); + App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("NormalColor", 0x00000000)); + m_colNormal = fcColor.asQColor(); + fcColor.setPackedValue(hGrp->GetUnsigned("SelectColor", 0x0000FF00)); + m_colSel = fcColor.asQColor(); + fcColor.setPackedValue(hGrp->GetUnsigned("PreSelectColor", 0x00080800)); + m_colPre = fcColor.asQColor(); + + m_colCurrent = m_colNormal; + m_pen.setColor(m_colCurrent); + + hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Drawing"); + std::string fontName = hGrp->GetASCII("LabelFont", "osifont"); + m_font.setFamily(QString::fromStdString(fontName)); + m_font.setPointSize(5.0); //scene units (mm), not points + + //Add object to scene + scene->addItem(this); + + m_label = new QGraphicsTextItem(); + addToGroup(m_label); + m_label->setFont(m_font); + + m_border = new QGraphicsRectItem(); + addToGroup(m_border); + m_decorPen.setStyle(Qt::DashLine); + m_decorPen.setWidth(0); // 0 => 1px "cosmetic pen" +} + +QGIView::~QGIView() +{ + +} + +void QGIView::alignTo(QGI *item, const QString &alignment) +{ + alignHash.clear(); + alignHash.insert(alignment, item); +} + +QVariant QGIView::itemChange(GraphicsItemChange change, const QVariant &value) +{ + if(change == ItemPositionChange && scene()) { + QPointF newPos = value.toPointF(); + + if(locked){ + newPos.setX(pos().x()); + newPos.setY(pos().y()); + } + + // TODO find a better data structure for this + if(alignHash.size() == 1) { + QGI *item = alignHash.begin().value(); + QString alignMode = alignHash.begin().key(); + + if(alignMode == QString::fromAscii("Vertical")) { + newPos.setX(item->pos().x()); + } else if(alignMode == QString::fromAscii("Horizontal")) { + newPos.setY(item->pos().y()); + } else if(alignMode == QString::fromAscii("45slash")) { + double dist = ( (newPos.x() - item->pos().x()) + + (item->pos().y() - newPos.y()) ) / 2.0; + + newPos.setX( item->pos().x() + dist); + newPos.setY( item->pos().y() - dist ); + } else if(alignMode == QString::fromAscii("45backslash")) { + double dist = ( (newPos.x() - item->pos().x()) + + (newPos.y() - item->pos().y()) ) / 2.0; + + newPos.setX( item->pos().x() + dist); + newPos.setY( item->pos().y() + dist ); + } + } + return newPos; + } + + if (change == ItemSelectedHasChanged && scene()) { + if(isSelected()) { + m_colCurrent = m_colSel; + } else { + m_colCurrent = m_colNormal; + } + drawBorder(); + } + + return QGIGroup::itemChange(change, value); +} + +void QGIView::mousePressEvent(QGraphicsSceneMouseEvent * event) +{ + if(locked) { + event->ignore(); + } else { + QGI::mousePressEvent(event); + } +} + +void QGIView::mouseMoveEvent(QGraphicsSceneMouseEvent * event) +{ + QGI::mouseMoveEvent(event); +} + +void QGIView::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) +{ + if(!locked && isSelected()) { + if (!isInnerView()) { + double tempX = x(), + tempY = getY(); + getViewObject()->X.setValue(tempX); + getViewObject()->Y.setValue(tempY); + } else { + getViewObject()->X.setValue(x()); + getViewObject()->Y.setValue(getYInClip(y())); + } + } + QGI::mouseReleaseEvent(event); +} + +void QGIView::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + // TODO don't like this but only solution at the minute + if (isSelected()) { + m_colCurrent = m_colSel; + } else { + m_colCurrent = m_colPre; + //if(shape().contains(event->pos())) { // TODO don't like this for determining preselect + // m_colCurrent = m_colPre; + //} + } + drawBorder(); + //update(); +} + +void QGIView::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + if(isSelected()) { + m_colCurrent = m_colSel; + } else { + m_colCurrent = m_colNormal; + } + drawBorder(); + //update(); +} + +void QGIView::setPosition(qreal x, qreal y) +{ + if (!isInnerView()) { + setPos(x,-y); //position on page + } else { + setPos(x,getYInClip(y)); //position in Clip + } +} + +double QGIView::getYInClip(double y) +{ + QGCustomClip* parentClip = dynamic_cast(parentItem()); + if (parentClip) { + QGIViewClip* parentView = dynamic_cast(parentClip->parentItem()); + TechDraw::DrawViewClip* parentFeat = dynamic_cast(parentView->getViewObject()); + double newY = parentFeat->Height.getValue() - y; + return newY; + } else { + Base::Console().Log("Logic Error - getYInClip called for child (%s) not in Clip\n",getViewName()); + } + return 0; +} + +void QGIView::updateView(bool update) +{ + if (update || + getViewObject()->X.isTouched() || + getViewObject()->Y.isTouched()) { + double featX = getViewObject()->X.getValue(); + double featY = getViewObject()->Y.getValue(); + setPosition(featX,featY); + } + + if (update || + getViewObject()->Rotation.isTouched()) { + //NOTE: QPainterPaths have to be rotated individually. This transform handles everything else. + double rot = getViewObject()->Rotation.getValue(); + QPointF centre = boundingRect().center(); + setTransform(QTransform().translate(centre.x(), centre.y()).rotate(-rot).translate(-centre.x(), -centre.y())); + } + + if (update) + QGI::update(); +} + +const char * QGIView::getViewName() const +{ + return viewName.c_str(); +} + +TechDraw::DrawView * QGIView::getViewObject() const +{ + return viewObj; +} + +void QGIView::setViewFeature(TechDraw::DrawView *obj) +{ + if(obj == 0) + return; + + viewObj = obj; + viewName = obj->getNameInDocument(); + + // Set the QGIGroup initial position based on the DrawView + float x = obj->X.getValue(); + float y = obj->Y.getValue(); + setPosition(x, y); + + Q_EMIT dirty(); +} + +void QGIView::toggleCache(bool state) +{ + // TODO: huh? IR //temp for devl. chaching was hiding problems WF + setCacheMode((state)? NoCache : NoCache); +} + + +void QGIView::toggleBorder(bool state) +{ + borderVisible = state; + drawBorder(); +} +void QGIView::drawBorder() +{ + if (!borderVisible) { + return; + } + + //double margin = 2.0; + prepareGeometryChange(); + m_label->hide(); + m_border->hide(); + + m_label->setDefaultTextColor(m_colCurrent); + m_label->setFont(m_font); + QString labelStr = QString::fromUtf8(getViewObject()->Label.getValue()); + m_label->setPlainText(labelStr); + QRectF labelArea = m_label->boundingRect(); + double labelWidth = m_label->boundingRect().width(); + double labelHeight = m_label->boundingRect().height(); + + m_border->hide(); + m_decorPen.setColor(m_colCurrent); + m_border->setPen(m_decorPen); + + QRectF displayArea = customChildrenBoundingRect(); + double displayWidth = displayArea.width(); + double displayHeight = displayArea.height(); + + double frameWidth = displayWidth; + if (labelWidth > displayWidth) { + frameWidth = labelWidth; + } + double frameHeight = labelHeight + displayHeight; + QPointF displayCenter = displayArea.center(); + + m_label->setX(displayCenter.x() - labelArea.width()/2.); + m_label->setY(displayArea.bottom()); + + QRectF frameArea = QRectF(displayCenter.x() - frameWidth/2., + displayArea.top(), + frameWidth, + frameHeight); + m_border->setRect(frameArea); + m_border->setPos(0.,0.); + + m_label->show(); + m_border->show(); +} + +void QGIView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + QStyleOptionGraphicsItem myOption(*option); + myOption.state &= ~QStyle::State_Selected; + + if(!borderVisible){ + m_label->hide(); + m_border->hide(); + } + QGIGroup::paint(painter, &myOption, widget); +} + +QRectF QGIView::customChildrenBoundingRect() { + QList children = childItems(); + int dimItemType = QGI::UserType + 106; + QRectF result; + for (QList::iterator it = children.begin(); it != children.end(); ++it) { + if ((*it)->type() >= QGI::UserType) { + if ((*it)->type() != dimItemType) { //Dimensions don't count towards bRect + result = result.united((*it)->boundingRect()); + } + } + } + return result; +} + +void _debugRect(char* text, QRectF r) { + Base::Console().Message("TRACE - %s - rect: (%.3f,%.3f) x (%.3f,%.3f)\n",text, + r.left(),r.top(),r.right(),r.bottom()); +} + +#include "moc_QGIView.cpp" diff --git a/src/Mod/TechDraw/Gui/QGIView.h b/src/Mod/TechDraw/Gui/QGIView.h new file mode 100644 index 0000000000..1e8fe77738 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIView.h @@ -0,0 +1,112 @@ +/*************************************************************************** + * Copyright (c) 2012-2013 Luke Parry * + * * + * 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_QGRAPHICSITEMVIEW_H +#define DRAWINGGUI_QGRAPHICSITEMVIEW_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QGraphicsScene; +class QGraphicsSceneMouseEvent; +QT_END_NAMESPACE + +namespace TechDraw { +class DrawView; +} + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGIView : public QObject, public QGIGroup +{ + Q_OBJECT + +public: + QGIView(const QPoint &position, QGraphicsScene *scene); + ~QGIView(); + + enum {Type = QGI::UserType + 101}; + int type() const { return Type;} + + const char * getViewName() const; + void setViewFeature(TechDraw::DrawView *obj); + TechDraw::DrawView * getViewObject() const; + + virtual void toggleBorder(bool state = true); + virtual void drawBorder(void); + + /// Methods to ensure that Y-Coordinates are orientated correctly. + void setPosition(qreal x, qreal y); + inline qreal getY() { return y() * -1; } + bool isInnerView() { return m_innerView; } + void isInnerView(bool state) { m_innerView = state; } + double getYInClip(double y); + + void alignTo(QGI *, const QString &alignment); + void setLocked(bool state = true) { locked = true; } + + virtual void toggleCache(bool state); + virtual void updateView(bool update = false); + virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); + //virtual QPainterPath shape(void) const; + + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event); + +Q_SIGNALS: + void dirty(); + +protected: + virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); + // Mouse handling + virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event ); + virtual void mousePressEvent(QGraphicsSceneMouseEvent * event); + // Preselection events: + virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + virtual QRectF customChildrenBoundingRect(void); + + TechDraw::DrawView *viewObj; + std::string viewName; + + QHash alignHash; + bool locked; + bool borderVisible; + bool m_innerView; //View is inside another View + + QPen m_pen; + QBrush m_brush; + QColor m_colCurrent; + QColor m_colNormal; + QColor m_colPre; + QColor m_colSel; + QFont m_font; + QGraphicsTextItem* m_label; + QGraphicsRectItem* m_border; + QPen m_decorPen; +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGRAPHICSITEMVIEW_H diff --git a/src/Mod/TechDraw/Gui/QGIViewAnnotation.cpp b/src/Mod/TechDraw/Gui/QGIViewAnnotation.cpp new file mode 100644 index 0000000000..cf6e5163c6 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIViewAnnotation.cpp @@ -0,0 +1,149 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * 2014 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 +#include +#include +#include +#include +#endif + +#include + +#include +#include +#include +#include + +#include "../App/DrawViewAnnotation.h" +#include "QGIViewAnnotation.h" +#include "QGCustomText.h" + +using namespace TechDrawGui; + +QGIViewAnnotation::QGIViewAnnotation(const QPoint &pos, QGraphicsScene *scene) + :QGIView(pos, scene) +{ + setHandlesChildEvents(false); + setCacheMode(QGI::NoCache); + setAcceptHoverEvents(true); + setFlag(QGI::ItemIsMovable, true); + + m_textItem = new QGCustomText(); + addToGroup(m_textItem); + m_textItem->setPos(0.,0.); +} + +QGIViewAnnotation::~QGIViewAnnotation() +{ + // m_textItem belongs to this group and will be deleted by Qt +} + +QVariant QGIViewAnnotation::itemChange(GraphicsItemChange change, const QVariant &value) +{ + return QGIView::itemChange(change, value); +} + +void QGIViewAnnotation::setViewAnnoFeature(TechDraw::DrawViewAnnotation *obj) +{ + // called from QGVPage. (once) + setViewFeature(static_cast(obj)); +} + +void QGIViewAnnotation::updateView(bool update) +{ + if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId())) + return; + + TechDraw::DrawViewAnnotation *viewAnno = dynamic_cast(getViewObject()); + + if (update || + viewAnno->isTouched() || + viewAnno->Text.isTouched() || + viewAnno->Font.isTouched() || + viewAnno->TextColor.isTouched() || + viewAnno->TextSize.isTouched() ) { + + draw(); + } + + QGIView::updateView(update); +} + +void QGIViewAnnotation::draw() +{ + drawAnnotation(); + if (borderVisible) { + drawBorder(); + } +} + +void QGIViewAnnotation::drawAnnotation() +{ + if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId())) + return; + + TechDraw::DrawViewAnnotation *viewAnno = dynamic_cast(getViewObject()); + + // get the Text values + const std::vector& annoText = viewAnno->Text.getValues(); + std::stringstream ss; + for(std::vector::const_iterator it = annoText.begin(); it != annoText.end(); it++) { + if (it == annoText.begin()) { + ss << *it; + } else { + ss << "\n" << *it ; + } + } + + QFont font; + font.setFamily(QString::fromUtf8(viewAnno->Font.getValue())); + font.setPointSizeF(viewAnno->TextSize.getValue()); //scene units (mm), not points + m_textItem->setFont(font); + + App::Color c = viewAnno->TextColor.getValue(); + m_textItem->setDefaultTextColor(c.asQColor()); + + prepareGeometryChange(); + QString qs = QString::fromUtf8(ss.str().c_str()); + m_textItem->setPlainText(qs); + m_textItem->adjustSize(); + m_textItem->setPos(0.,0.); +} + +QRectF QGIViewAnnotation::boundingRect() const +{ + return childrenBoundingRect(); +} + +#include "moc_QGIViewAnnotation.cpp" + diff --git a/src/Mod/TechDraw/Gui/QGIViewAnnotation.h b/src/Mod/TechDraw/Gui/QGIViewAnnotation.h new file mode 100644 index 0000000000..4550c2ca6a --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIViewAnnotation.h @@ -0,0 +1,75 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * 2014 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_QGRAPHICSITEMVIEWANNOTATION_H +#define DRAWINGGUI_QGRAPHICSITEMVIEWANNOTATION_H + +#include +#include + +#include "QGIView.h" +#include "QGCustomText.h" + +namespace TechDraw { +class DrawViewAnnotation; +} + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGIViewAnnotation : public QGIView +{ + Q_OBJECT + +public: + + explicit QGIViewAnnotation(const QPoint &position, QGraphicsScene *scene); + ~QGIViewAnnotation(); + + enum {Type = QGI::UserType + 120}; + int type() const { return Type;} + + void updateView(bool update = false); + void setViewAnnoFeature(TechDraw::DrawViewAnnotation *obj); + + virtual void draw(); + virtual QRectF boundingRect() const; + +Q_SIGNALS: + void hover(bool state); + void selected(bool state); + +protected: + void drawAnnotation(); + QVariant itemChange(GraphicsItemChange change, const QVariant &value); + +protected: + QGCustomText *m_textItem; + QColor m_colNormal; + QColor m_colSel; + QColor m_colPre; +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGRAPHICSITEMVIEWANNOTATION_H diff --git a/src/Mod/TechDraw/Gui/QGIViewClip.cpp b/src/Mod/TechDraw/Gui/QGIViewClip.cpp new file mode 100644 index 0000000000..0214a18630 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIViewClip.cpp @@ -0,0 +1,192 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * 2014 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 +#include +#include +#include +#include +#include // std::find +#endif + +#include + +#include +#include +#include +#include + +#include "../App/DrawViewClip.h" +#include "QGIViewClip.h" + +using namespace TechDrawGui; + +QGIViewClip::QGIViewClip(const QPoint &pos, QGraphicsScene *scene) + :QGIView(pos, scene) +{ + setHandlesChildEvents(false); + setCacheMode(QGI::NoCache); + setAcceptHoverEvents(true); + setFlag(QGI::ItemIsSelectable, true); + setFlag(QGI::ItemIsMovable, true); + + m_cliparea = new QGCustomClip(); + addToGroup(m_cliparea); + m_cliparea->setPos(0.,0.); + m_cliparea->setRect(0.,0.,5.,5.); + + m_frame = new QGCustomRect(); + addToGroup(m_frame); + m_frame->setPos(0.,0.); + m_frame->setRect(0.,0.,5.,5.); +} + +QGIViewClip::~QGIViewClip() +{ +} + +QVariant QGIViewClip::itemChange(GraphicsItemChange change, const QVariant &value) +{ + return QGIView::itemChange(change, value); +} + +void QGIViewClip::updateView(bool update) +{ + if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId())) + return; + + TechDraw::DrawViewClip *viewClip = dynamic_cast(getViewObject()); + + if (update || + viewClip->isTouched() || + viewClip->Height.isTouched() || + viewClip->Width.isTouched() || + viewClip->ShowFrame.isTouched()) { + + draw(); + } + + QGIView::updateView(update); +} + +void QGIViewClip::draw() +{ + drawClip(); + if (borderVisible) { + drawBorder(); + } +} + +void QGIViewClip::drawClip() +{ + if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId())) + return; + + TechDraw::DrawViewClip *viewClip = dynamic_cast(getViewObject()); + + prepareGeometryChange(); + double h = viewClip->Height.getValue(); + double w = viewClip->Width.getValue(); + QRectF r = QRectF(0,0,w,h); + m_frame->setRect(r); + m_frame->setPos(0.,0.); + if (viewClip->ShowFrame.getValue()) { + m_frame->show(); + } else { + m_frame->hide(); + } + + m_cliparea->setRect(r.adjusted(-1,-1,1,1)); //TODO: clip just outside frame or just inside?? + + std::vector childNames = viewClip->getChildViewNames(); + //for all child Views in Clip, add the graphics representation of the View to the Clip group + for(std::vector::iterator it = childNames.begin(); it != childNames.end(); it++) { + QGIView* qgiv = getQGIVByName((*it)); + if (qgiv) { + //TODO: why is qgiv never already in a group? + if (qgiv->group() != m_cliparea) { + double x = qgiv->getViewObject()->X.getValue(); + double y = qgiv->getViewObject()->Y.getValue(); + m_cliparea->addToGroup(qgiv); + qgiv->isInnerView(true); + qgiv->setPosition(x,y); + if (viewClip->ShowLabels.getValue()) { + qgiv->toggleBorder(true); + } else { + qgiv->toggleBorder(false); + } + } + } else { + Base::Console().Warning("Logic error? - drawClip() - qgiv for %s not found\n",(*it).c_str()); //gview for feature !exist + } + } + + //for all graphic views in qgigroup, remove from qgigroup the ones that aren't in ViewClip + QList qgItems = m_cliparea->childItems(); + QList::iterator it = qgItems.begin(); + for (; it != qgItems.end(); it++) { + QGIView* qv = dynamic_cast((*it)); + if (qv) { + std::string qvName = std::string(qv->getViewName()); + if (std::find(childNames.begin(),childNames.end(),qvName) == childNames.end()) { + m_cliparea->removeFromGroup(qv); + removeFromGroup(qv); + qv->isInnerView(false); + qv->toggleBorder(true); + } + } + } +} + +QGIView* QGIViewClip::getQGIVByName(std::string name) //should probably be method in MDIViewPage?? but qgiv can't get drawingView? or QGVPage! +{ + QList qgItems = scene()->items(); + QList::iterator it = qgItems.begin(); + for (; it != qgItems.end(); it++) { + QGIView* qv = dynamic_cast((*it)); + if (qv) { + const char* qvName = qv->getViewName(); + if(name.compare(qvName) == 0) { + return (qv); + } + } + } + return 0; +} + +QRectF QGIViewClip::boundingRect() const +{ + return childrenBoundingRect(); +} + +#include "moc_QGIViewClip.cpp" + diff --git a/src/Mod/TechDraw/Gui/QGIViewClip.h b/src/Mod/TechDraw/Gui/QGIViewClip.h new file mode 100644 index 0000000000..c2ee02b3e5 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIViewClip.h @@ -0,0 +1,74 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * * + * 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_QGRAPHICSITEMCLIP_H +#define DRAWINGGUI_QGRAPHICSITEMCLIP_H + +#include +#include + +#include "QGIView.h" +#include "QGCustomRect.h" +#include "QGCustomClip.h" + +namespace TechDraw { +class DrawViewPart; +} + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGIViewClip : public QGIView +{ + Q_OBJECT + +public: + + explicit QGIViewClip(const QPoint &position, QGraphicsScene *scene); + ~QGIViewClip(); + + enum {Type = QGI::UserType + 123}; + int type() const { return Type;} + + virtual void updateView(bool update = false); + + virtual void draw(); + virtual QRectF boundingRect() const; + +Q_SIGNALS: + void selected(bool state); + void dirty(); + +protected: + void drawClip(); + virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); + QGIView* getQGIVByName(std::string name); + +private: + QGCustomRect* m_frame; + QGCustomClip* m_cliparea; + +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGRAPHICSITEMCLIP_H diff --git a/src/Mod/TechDraw/Gui/QGIViewCollection.cpp b/src/Mod/TechDraw/Gui/QGIViewCollection.cpp new file mode 100644 index 0000000000..a9e216881f --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIViewCollection.cpp @@ -0,0 +1,88 @@ +/*************************************************************************** + * Copyright (c) 2012-2013 Luke Parry * + * * + * 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 +# include +#endif + +#include +#include +#include +#include + +#include "../App/DrawViewCollection.h" +#include "QGIViewCollection.h" + +using namespace TechDrawGui; + +QGIViewCollection::QGIViewCollection(const QPoint &pos, QGraphicsScene *scene) :QGIView(pos, scene) +{ + setFlags(QGI::ItemIsSelectable); + setPos(pos); + + setHandlesChildEvents(false); + + //setCacheMode(QGI::NoCache); + setAcceptHoverEvents(true); + setFlag(QGI::ItemIsMovable, true); +} + +QGIViewCollection::~QGIViewCollection() +{ + +} + +QVariant QGIViewCollection::itemChange(GraphicsItemChange change, const QVariant &value) +{ + + return QGIGroup::itemChange(change, value); +} + +void QGIViewCollection::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) +{ + if(scene() && this == scene()->mouseGrabberItem()) { + Gui::Command::openCommand("Drag View Collection"); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.X = %f", + getViewObject()->getNameInDocument(), x()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Y = %f", + getViewObject()->getNameInDocument(), getY()); + Gui::Command::commitCommand(); + //Gui::Command::updateActive(); + } + QGI::mouseReleaseEvent(event); +} + +void QGIViewCollection::updateView(bool update) +{ + return QGIView::updateView(update); +} + +#include "moc_QGIViewCollection.cpp" diff --git a/src/Mod/TechDraw/Gui/QGIViewCollection.h b/src/Mod/TechDraw/Gui/QGIViewCollection.h new file mode 100644 index 0000000000..60db29a851 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIViewCollection.h @@ -0,0 +1,69 @@ +/*************************************************************************** + * Copyright (c) 2012-2013 Luke Parry * + * * + * 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_QGRAPHICSITEMVIEWCOLLECTION_H +#define _DRAWINGGUI_QGRAPHICSITEMVIEWCOLLECTION_H + +#include +#include +#include + +#include "QGIView.h" + +QT_BEGIN_NAMESPACE +class QGraphicsScene; +class QGraphicsSceneMouseEvent; +QT_END_NAMESPACE + +namespace TechDraw { +class DrawView; +class DrawViewCollection; +} + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGIViewCollection : public QGIView +{ + Q_OBJECT + +public: + QGIViewCollection(const QPoint &position, QGraphicsScene *scene); + ~QGIViewCollection(); + + enum {Type = QGI::UserType + 110}; + int type() const { return Type;} + + virtual void updateView(bool update = false); + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event); + +Q_SIGNALS: + void dirty(); + +protected: + virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); + +}; + +} // namespace MDIViewPageGui + +#endif // _DRAWINGGUI_QGRAPHICSITEMVIEWCOLLECTION_H diff --git a/src/Mod/TechDraw/Gui/QGIViewDimension.cpp b/src/Mod/TechDraw/Gui/QGIViewDimension.cpp new file mode 100644 index 0000000000..407df32eb5 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIViewDimension.cpp @@ -0,0 +1,1263 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * * + * 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 + # include + # include + # include + # include + # include + # include + # include + # include + + # include + # include + # include + # include + # include + # include +#endif + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include "QGIViewDimension.h" +#include "QGIArrow.h" + +using namespace TechDrawGui; + +enum SnapMode{ + NoSnap, + VerticalSnap, + HorizontalSnap + }; + +QGIDatumLabel::QGIDatumLabel(int ref, QGraphicsScene *scene ) : reference(ref) +{ + if(scene) { + scene->addItem(this); + } + posX = 0; + posY = 0; + + setCacheMode(QGI::NoCache); + setFlag(ItemSendsGeometryChanges, true); + setFlag(ItemIsMovable, true); + setFlag(ItemIsSelectable, true); + setAcceptHoverEvents(true); + + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Drawing/Colors"); + App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("NormalColor", 0x00000000)); + m_colNormal = fcColor.asQColor(); + fcColor.setPackedValue(hGrp->GetUnsigned("SelectColor", 0x0000FF00)); + m_colSel = fcColor.asQColor(); + fcColor.setPackedValue(hGrp->GetUnsigned("PreSelectColor", 0x00080800)); + m_colPre = fcColor.asQColor(); +} + +QVariant QGIDatumLabel::itemChange(GraphicsItemChange change, const QVariant &value) +{ + if (change == ItemSelectedHasChanged && scene()) { + if(isSelected()) { + Q_EMIT selected(true); + setDefaultTextColor(m_colSel); + } else { + Q_EMIT selected(false); + setDefaultTextColor(m_colNormal); + } + update(); + } else if(change == ItemPositionHasChanged && scene()) { + setLabelCenter(); + Q_EMIT dragging(); + } + + return QGI::itemChange(change, value); +} + +void QGIDatumLabel::setPosFromCenter(const double &xCenter, const double &yCenter) +{ + //set label's Qt position(top,left) given boundingRect center point + setPos(xCenter - boundingRect().width() / 2., yCenter - boundingRect().height() / 2.); +} + +void QGIDatumLabel::setLabelCenter() +{ + //save label's bRect center (posX,posY) given Qt position (top,left) + posX = x() + boundingRect().width() / 2.; + posY = y() + boundingRect().height() / 2.; +} + +void QGIDatumLabel::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + Q_EMIT hover(true); + setDefaultTextColor(m_colPre); + update(); +} + +void QGIDatumLabel::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + QGIView *view = dynamic_cast (parentItem()); + assert(view != 0); + + Q_EMIT hover(false); + if(!isSelected() && !view->isSelected()) { + setDefaultTextColor(m_colNormal); + update(); + } +} + +void QGIDatumLabel::mouseReleaseEvent( QGraphicsSceneMouseEvent * event) +{ + if(scene() && this == scene()->mouseGrabberItem()) { + Q_EMIT dragFinished(); + } + QGI::mouseReleaseEvent(event); +} + +QGIViewDimension::QGIViewDimension(const QPoint &pos, QGraphicsScene *scene) : + QGIView(pos, scene), + hasHover(false) +{ + setHandlesChildEvents(false); + setFlag(QGI::ItemIsMovable, false); + setCacheMode(QGI::NoCache); + + QGIDatumLabel *dlabel = new QGIDatumLabel(); + QGraphicsPathItem *arrws = new QGraphicsPathItem(); + QGraphicsPathItem *clines = new QGraphicsPathItem(); + + datumLabel = dlabel; + arrows = arrws; + centreLines = clines; + + // connecting the needed slots and signals + QObject::connect( + dlabel, SIGNAL(dragging()), + this , SLOT (datumLabelDragged())); + + QObject::connect( + dlabel, SIGNAL(dragFinished()), + this , SLOT (datumLabelDragFinished())); + + QObject::connect( + dlabel, SIGNAL(selected(bool)), + this , SLOT (select(bool))); + + QObject::connect( + dlabel, SIGNAL(hover(bool)), + this , SLOT (hover(bool))); + + pen.setCosmetic(true); + pen.setWidthF(1.); + + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Drawing/Colors"); + App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("NormalColor", 0x00000000)); + m_colNormal = fcColor.asQColor(); + fcColor.setPackedValue(hGrp->GetUnsigned("SelectColor", 0x0000FF00)); + m_colSel = fcColor.asQColor(); + fcColor.setPackedValue(hGrp->GetUnsigned("PreSelectColor", 0x00080800)); + m_colPre = fcColor.asQColor(); + + addToGroup(arrows); + addToGroup(datumLabel); + addToGroup(centreLines); + + toggleBorder(false); +} + +QGIViewDimension::~QGIViewDimension() +{ +} + +void QGIViewDimension::setViewPartFeature(TechDraw::DrawViewDimension *obj) +{ + if(obj == 0) + return; + + setViewFeature(static_cast(obj)); + + // Set the QGIGroup Properties based on the DrawView + float x = obj->X.getValue(); + float y = obj->Y.getValue(); + + QGIDatumLabel *dLabel = static_cast(datumLabel); + dLabel->setPosFromCenter(x, y); + + updateDim(); + draw(); + Q_EMIT dirty(); +} + +void QGIViewDimension::select(bool state) +{ + setSelected(state); + draw(); +} + +void QGIViewDimension::hover(bool state) +{ + hasHover = state; + draw(); +} + +void QGIViewDimension::updateView(bool update) +{ + if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) + return; + TechDraw::DrawViewDimension *dim = dynamic_cast(getViewObject()); + + std::vector refs = dim->References.getValues(); + + QGIDatumLabel *dLabel = dynamic_cast(datumLabel); + + // Identify what changed to prevent complete redraw + if(dim->Fontsize.isTouched() || + dim->Font.isTouched()) { + + + QFont font = dLabel->font(); + font.setPointSizeF(dim->Fontsize.getValue()); //scene units (mm), not points + font.setFamily(QString::fromAscii(dim->Font.getValue())); + + dLabel->setFont(font); + dLabel->setLabelCenter(); + + } else if(dim->X.isTouched() || + dim->Y.isTouched()) { + dLabel->setPosFromCenter(dim->X.getValue(), dim->Y.getValue()); + updateDim(); + + } else { + updateDim(); + } + + draw(); + + Q_EMIT dirty(); +} + +void QGIViewDimension::updateDim() +{ + if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) + return; + + const TechDraw::DrawViewDimension *dim = dynamic_cast(getViewObject()); + + QString labelText = QString::fromStdString(dim->getFormatedValue()); + + QGIDatumLabel *dLabel = dynamic_cast(datumLabel); + + QFont font = dLabel->font(); + font.setPointSizeF(dim->Fontsize.getValue()); //scene units (mm), not points + font.setFamily(QString::fromAscii(dim->Font.getValue())); + + dLabel->setPlainText(labelText); + dLabel->setFont(font); + dLabel->setPosFromCenter(dLabel->X(),dLabel->Y()); +} + +void QGIViewDimension::datumLabelDragged() +{ + draw(); +} + +void QGIViewDimension::datumLabelDragFinished() +{ + if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) + return; + + TechDraw::DrawViewDimension *dim = dynamic_cast(getViewObject()); + QGIDatumLabel *datumLbl = dynamic_cast(datumLabel); + + double x = datumLbl->X(), + y = datumLbl->Y(); + Gui::Command::openCommand("Drag Dimension"); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.X = %f", dim->getNameInDocument(), x); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Y = %f", dim->getNameInDocument(), y); + Gui::Command::commitCommand(); +} + + +void QGIViewDimension::draw() +{ + if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) + return; + + TechDraw::DrawViewDimension *dim = dynamic_cast(getViewObject()); + QGIDatumLabel *lbl = dynamic_cast(datumLabel); + const TechDraw::DrawViewPart *refObj = dim->getViewPart(); + if(!refObj->hasGeometry()) { //nothing to draw yet + return; + } + pen.setStyle(Qt::SolidLine); + + // Crude method of determining state [TODO] improve + if(isSelected()) { + pen.setColor(m_colSel); + } else if (hasHover) { + pen.setColor(m_colPre); + } else { + pen.setColor(m_colNormal); + } + + QString labelText = lbl->toPlainText(); + Base::Vector3d lblCenter(lbl->X(), lbl->Y(), 0); + + //we always draw based on Projected geometry. + //const std::vector &objects = dim->References.getValues(); + const std::vector &SubNames = dim->References.getSubValues(); + + const char *dimType = dim->Type.getValueAsString(); + + if(strcmp(dimType, "Distance") == 0 || + strcmp(dimType, "DistanceX") == 0 || + strcmp(dimType, "DistanceY") == 0) { + Base::Vector3d distStart, distEnd; + if((dim->References.getValues().size() == 1) && + (DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge")) { + int idx = DrawUtil::getIndexFromName(SubNames[0]); + DrawingGeometry::BaseGeom* geom = refObj->getProjEdgeByIndex(idx); + if (!geom) { + Base::Console().Log("INFO - qgivd::draw - no geom for projected edge: %d of %d\n", + idx,refObj->getEdgeGeometry().size()); + return; + } + if (geom->geomType == DrawingGeometry::GENERIC) { + DrawingGeometry::Generic *gen = static_cast(geom); + Base::Vector2D pnt1 = gen->points.at(0); + Base::Vector2D pnt2 = gen->points.at(1); + distStart = Base::Vector3d(pnt1.fX, pnt1.fY, 0.); + distEnd = Base::Vector3d(pnt2.fX, pnt2.fY, 0.); + } else { + throw Base::Exception("FVD::draw - Original edge not found or is invalid type (1)"); + } + } else if(dim->References.getValues().size() == 2 && + DrawUtil::getGeomTypeFromName(SubNames[0]) == "Vertex" && + DrawUtil::getGeomTypeFromName(SubNames[1]) == "Vertex") { + int idx0 = DrawUtil::getIndexFromName(SubNames[0]); + int idx1 = DrawUtil::getIndexFromName(SubNames[1]); + DrawingGeometry::Vertex *v0 = refObj->getProjVertexByIndex(idx0); + DrawingGeometry::Vertex *v1 = refObj->getProjVertexByIndex(idx1); + if (!v0 || !v1) { + //Ugh. this is probably because the document is restoring. check log. + Base::Console().Log("INFO - qgivd::draw - no geom for projected edge: %d or %d of %d\n", + idx0,idx1,refObj->getEdgeGeometry().size()); + return; + } + distStart = Base::Vector3d (v0->pnt.fX, v0->pnt.fY, 0.); + distEnd = Base::Vector3d (v1->pnt.fX, v1->pnt.fY, 0.); + } else if(dim->References.getValues().size() == 2 && + DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" && + DrawUtil::getGeomTypeFromName(SubNames[1]) == "Edge") { + int idx0 = DrawUtil::getIndexFromName(SubNames[0]); + int idx1 = DrawUtil::getIndexFromName(SubNames[1]); + DrawingGeometry::BaseGeom* geom0 = refObj->getProjEdgeByIndex(idx0); + DrawingGeometry::BaseGeom* geom1 = refObj->getProjEdgeByIndex(idx1); + if (!geom0 || !geom1) { + Base::Console().Log("INFO - qgivd::draw - no geom for projected edge: %d or %d of %d\n", + idx0,idx1,refObj->getEdgeGeometry().size()); + return; + } + if ( (geom0->geomType == DrawingGeometry::GENERIC) && + (geom1->geomType == DrawingGeometry::GENERIC) ){ + DrawingGeometry::Generic *gen0 = static_cast(geom0); + DrawingGeometry::Generic *gen1 = static_cast(geom1); + Base::Vector2D pnt1, pnt2; + Base::Vector3d edge1Start, edge1End, edge2Start, edge2End; + pnt1 = gen0->points.at(0); + pnt2 = gen0->points.at(1); + edge1Start = Base::Vector3d(pnt1.fX, pnt1.fY, 0); + edge1End = Base::Vector3d(pnt2.fX, pnt2.fY, 0); + pnt1 = gen1->points.at(0); + pnt2 = gen1->points.at(1); + edge2Start = Base::Vector3d(pnt1.fX, pnt1.fY, 0); + edge2End = Base::Vector3d(pnt2.fX, pnt2.fY, 0); + + // figure out which end of each edge to use for distance calculation (wf- calculation? sb drawing?) + Base::Vector3d lin1 = edge1End - edge1Start; //vector from edge1Start to edge2End + Base::Vector3d lin2 = edge2End - edge2Start; + + Base::Vector3d labelV1 = lblCenter - edge1Start; //vector from edge1Start to lblCenter + Base::Vector3d labelV2 = lblCenter - edge2Start; + + if(lin1.x * labelV1.x + lin1.y * labelV1.y > 0.) //dotprod > 0 ==> angle(lin1,labelV1) < PI/2?? + distStart = edge1End; + else + distStart = edge1Start; + + if(lin2.x * labelV2.x + lin2.y * labelV2.y > 0.) + distEnd = edge2End; + else + distEnd = edge2Start; + } else { + //TODO: Exception here seems drastic. Can we fail more gracefully? + throw Base::Exception("FVD::draw -Invalid reference for dimension type (1)"); + } + } + + Base::Vector3d dir, norm; + if (strcmp(dimType, "Distance") == 0 ) { + dir = (distEnd-distStart); + } else if (strcmp(dimType, "DistanceX") == 0 ) { + dir = Base::Vector3d ( ((distEnd.x - distStart.x >= FLT_EPSILON) ? 1 : -1) , 0, 0); + } else if (strcmp(dimType, "DistanceY") == 0 ) { + dir = Base::Vector3d (0, ((distEnd.y - distStart.y >= FLT_EPSILON) ? 1 : -1) , 0); + } + + dir.Normalize(); + norm = Base::Vector3d (-dir.y,dir.x, 0); + + // Get magnitude of angle between dir and horizontal + float angle = atan2f(dir.y,dir.x); + if (angle > M_PI_2+M_PI/12) { + angle -= (float)M_PI; + } else if (angle <= -M_PI_2+M_PI/12) { + angle += (float)M_PI; + } + + // when the datum line(dimension line??) is not parallel to (distStart-distEnd) the projection of + // (distStart-distEnd) on norm is not zero, distEnd is considered as reference and distStart + // is replaced by its projection distStart_ + float normproj12 = (distEnd-distStart).x * norm.x + (distEnd-distStart).y * norm.y; + Base::Vector3d distStart_ = distStart + norm * normproj12; + + //Base::Vector3d midpos = (distStart_ + distEnd) / 2; + + QFontMetrics fm(lbl->font()); + int w = fm.width(labelText); + //int h = fm.height(); + + Base::Vector3d vec = lblCenter - distEnd; + float length = vec.x * norm.x + vec.y * norm.y; + + float margin = 3.f; + float scaler = 1.; + + float offset1 = (length + normproj12 < 0) ? -margin : margin; + float offset2 = (length < 0) ? -margin : margin; + + Base::Vector3d ext1End = distStart_ + norm * (length + offset1 * scaler); //extension line 1 end + Base::Vector3d ext2End = distEnd + norm * (length + offset2 * scaler); + + // Calculate the start/end for the Dimension lines + Base::Vector3d dim1Tip = distStart_ + norm * length; //dim line 1 tip + Base::Vector3d dim1Tail = lblCenter - dir * (w / 2 + margin); //dim line 1 tail + Base::Vector3d dim2Tip = lblCenter + dir * (w / 2 + margin); + Base::Vector3d dim2Tail = distEnd + norm * length; + + // Add a small margin + //distStart_ += norm * margin * 0.5; + // distEnd += norm * margin * 0.5; + + bool flipTriang = false; + + Base::Vector3d del1 = (dim2Tip-dim1Tip); + Base::Vector3d del2 = (dim1Tail-dim1Tip); + float dot1 = del1.x * dir.x + del1.y * dir.y; + float dot2 = del2.x * dir.x + del2.y * dir.y; + + //Compare to see if Dimension text is larger than dimension + if (dot1 > (dim2Tail - dim1Tip).Length()) { + // Increase Margin to improve visability + float tmpMargin = 10.f * scaler; + dim2Tip = dim2Tail; + if(dot2 > (dim2Tail - dim1Tip).Length()) { + dim2Tip = dim1Tail; + dim1Tail = dim1Tip - dir * tmpMargin; + flipTriang = true; + } + } else if (dot2 < 0.f) { + float tmpMargin = 10.f * scaler; + dim1Tail = dim1Tip; + if(dot1 < 0.f) { + dim1Tail = dim2Tip; + dim2Tip = dim2Tail + dir * tmpMargin; + flipTriang = true; + } + } + + // Extension lines + QPainterPath path; + path.moveTo(distStart.x, distStart.y); + path.lineTo(ext1End.x, ext1End.y); + + path.moveTo(distEnd.x, distEnd.y); + path.lineTo(ext2End.x, ext2End.y); + + //Dimension lines + path.moveTo(dim1Tip.x, dim1Tip.y); + path.lineTo(dim1Tail.x, dim1Tail.y); + + path.moveTo(dim2Tip.x, dim2Tip.y); + path.lineTo(dim2Tail.x, dim2Tail.y); + + QGraphicsPathItem *arrw = dynamic_cast (arrows); + arrw->setPath(path); + arrw->setPen(pen); + + // Note Bounding Box size is not the same width or height as text (only used for finding center) + float bbX = lbl->boundingRect().width(); + float bbY = lbl->boundingRect().height(); + lbl->setTransformOriginPoint(bbX / 2, bbY /2); + lbl->setRotation(angle * 180 / M_PI); + + + if(arw.size() != 2) { + prepareGeometryChange(); + for(std::vector::iterator it = arw.begin(); it != arw.end(); ++it) { + removeFromGroup(*it); + delete (*it); + } + arw.clear(); + + // These items are added to the scene-graph so should be handled by the canvas + QGIArrow *ar1 = new QGIArrow(); //arrowhead + QGIArrow *ar2 = new QGIArrow(); + arw.push_back(ar1); + arw.push_back(ar2); + + ar1->draw(); + ar2->flip(true); + ar2->draw(); + + addToGroup(arw.at(0)); + addToGroup(arw.at(1)); + } + + QGIArrow *ar1 = dynamic_cast(arw.at(0)); + QGIArrow *ar2 = dynamic_cast(arw.at(1)); + + angle = atan2f(dir[1],dir[0]); + float arrowAngle = angle * 180 / M_PI; + arrowAngle -= 180.; + if(flipTriang){ + ar1->setRotation(arrowAngle + 180.); + ar2->setRotation(arrowAngle + 180.); + } else { + ar1->setRotation(arrowAngle); + ar2->setRotation(arrowAngle); + } + + ar1->setPos(dim1Tip.x, dim1Tip.y); + ar2->setPos(dim2Tail.x, dim2Tail.y); + + ar1->setHighlighted(isSelected() || hasHover); + ar2->setHighlighted(isSelected() || hasHover); + + } else if(strcmp(dimType, "Diameter") == 0) { + // terminology: Dimension Text, Dimension Line(s), Extension Lines, Arrowheads + // was datumLabel, datum line/parallel line, perpendicular line, arw + Base::Vector3d arrow1Tip, arrow2Tip, dirDimLine, centre; //was p1,p2,dir + QGIDatumLabel *label = dynamic_cast(datumLabel); + Base::Vector3d lblCenter(label->X(), label->Y(), 0); + double radius; + + if(dim->References.getValues().size() == 1 && + DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge") { + int idx = DrawUtil::getIndexFromName(SubNames[0]); + DrawingGeometry::BaseGeom *geom = refObj->getProjEdgeByIndex(idx); + if(!geom) { + Base::Console().Log("INFO - qgivd::draw - no geom for projected edge: %d of %d\n", + idx,refObj->getEdgeGeometry().size()); + return; + //throw Base::Exception("Edge couldn't be found for diameter dimension"); + } + if( (geom->geomType == DrawingGeometry::CIRCLE) || + (geom->geomType == DrawingGeometry::ARCOFCIRCLE) ) { + DrawingGeometry::Circle *circ = static_cast(geom); + radius = circ->radius; + centre = Base::Vector3d (circ->center.fX, circ->center.fY, 0); + } else { + throw Base::Exception("FVD::draw - Original edge not found or is invalid type (2)"); + } + } else { + throw Base::Exception("FVD ::draw - Invalid reference for dimension type (2)"); + } + // Note Bounding Box size is not the same width or height as text (only used for finding center) + float bbX = label->boundingRect().width(); + float bbY = label->boundingRect().height(); + + dirDimLine = (lblCenter - centre).Normalize(); //if lblCenter == centre, this is (0,0,0)?? + if (fabs(dirDimLine.Length()) < (Precision::Confusion())) { + dirDimLine = Base::Vector3d(-1.0,0.0,0.0); + } + + //this is for inner placement only? recalced for outer? + arrow1Tip = centre - dirDimLine * radius; //endpoint of diameter arrowhead1 + arrow2Tip = centre + dirDimLine * radius; //endpoint of diameter arrowhead2 + + QFontMetrics fm(label->font()); + + int w = fm.width(labelText); + //int h = fm.height(); + + float margin = 5.f; + + // Calculate the dimension line endpoints + // recalced for vert & horizontal snap & inner placement. not used for nosnap outer? + Base::Vector3d dLine1Tail = lblCenter - dirDimLine * (margin + w / 2); //position of tail of 1st dimension line + Base::Vector3d dLine2Tail = lblCenter + dirDimLine * (margin + w / 2); + + bool outerPlacement = false; + if ((lblCenter-centre).Length() > radius) { //label is outside circle + outerPlacement = true; + } + + // Reset transformation origin for datum label + label->setTransformOriginPoint(bbX / 2, bbY /2); + + int posMode = NoSnap; + QPainterPath path; + + if(outerPlacement) { + // Select whether to snap vertically or hoziontally given tolerance + Base::Vector3d v = (lblCenter-arrow1Tip); + + double angle = atan2(v.y, v.x); + double tolerance = 15.0; //deg + + tolerance *= M_PI / 180; + if( (angle > -tolerance && angle < tolerance) || //angle = 0 or 180 (+/- 15) + (angle > (M_PI - tolerance) || angle < (-M_PI + tolerance)) ) { + posMode = HorizontalSnap; + } else if( (angle < ( M_PI / 2. + tolerance) && angle > ( M_PI / 2. - tolerance)) || //angle = 90 or 270 (+/- 15) + (angle < (-M_PI / 2. + tolerance) && angle > (-M_PI / 2. - tolerance)) ) { + posMode = VerticalSnap; + } + + if(posMode == VerticalSnap) { + float tip = (lblCenter.y > centre.y) ? margin: -margin; + tip *= 0.5; + + arrow1Tip.x = centre.x - radius; //to left, on circle cl + arrow1Tip.y = lblCenter.y; + + arrow2Tip.x = centre.x + radius; + arrow2Tip.y = lblCenter.y; + + dLine1Tail = lblCenter; + dLine1Tail.x -= (margin + w / 2); //to left, on label cl + + dLine2Tail = lblCenter; + dLine2Tail.x += (margin + w / 2); + + // Extension line 1 + path.moveTo(centre.x - radius, centre.y); + path.lineTo(arrow1Tip.x, arrow1Tip.y + tip); + + // Left Arrow + path.moveTo(arrow1Tip.x, arrow1Tip.y); //dimension line, not arrowhead + path.lineTo(dLine1Tail.x, dLine1Tail.y); + + // Extension line 2 + path.moveTo(centre.x + radius, centre.y); + path.lineTo(arrow2Tip.x, arrow2Tip.y + tip); + + // Right arrow + path.moveTo(dLine2Tail.x, dLine2Tail.y); + path.lineTo(arrow2Tip.x, arrow2Tip.y); + + label->setRotation(0.); + + } else if(posMode == HorizontalSnap) { + // Snapped Horizontally + + float tip = (lblCenter.x > centre.x) ? margin: -margin; + tip *= 0.5; + + arrow1Tip.y = centre.y - radius; + arrow1Tip.x = lblCenter.x; + + arrow2Tip.y = centre.y + radius; + arrow2Tip.x = lblCenter.x; + + dLine1Tail = lblCenter; + dLine1Tail.y -= (margin + w / 2); + + dLine2Tail = lblCenter; + dLine2Tail.y += (margin + w / 2); + + // Extension lines + path.moveTo(centre.x, centre.y - radius); + path.lineTo(arrow1Tip.x + tip, arrow1Tip.y); + + path.moveTo(arrow1Tip.x, arrow1Tip.y); + path.lineTo(dLine1Tail.x, dLine1Tail.y); + + // Extension lines + path.moveTo(centre.x, centre.y + radius); + path.lineTo(arrow2Tip.x + tip, arrow2Tip.y); + + path.moveTo(dLine2Tail.x, dLine2Tail.y); + path.lineTo(arrow2Tip.x, arrow2Tip.y); + + label->setRotation(90.); + + } else { //NoSnap + float tip = (margin + w / 2); + tip = (lblCenter.x < centre.x) ? tip : -tip; + + arrow1Tip = lblCenter; + arrow1Tip.x += tip; + + + Base::Vector3d p3 = arrow1Tip; + p3.x += (lblCenter.x < centre.x) ? margin : - margin; + + arrow2Tip = centre + (p3 - centre).Normalize() * radius; + + path.moveTo(arrow1Tip.x, arrow1Tip.y); + path.lineTo(p3[0], p3[1]); + + path.lineTo(arrow2Tip.x, arrow2Tip.y); + + label->setRotation(0.); + } + } else { //NOT outerplacement ie dimLines are inside circle + //text always rightside up inside circle + label->setRotation(0); + dLine1Tail = centre - dirDimLine * margin; + dLine2Tail = centre + dirDimLine * margin; + + path.moveTo(arrow1Tip.x, arrow1Tip.y); + path.lineTo(dLine1Tail.x, dLine1Tail.y); + + path.moveTo(dLine2Tail.x, dLine2Tail.y); + path.lineTo(arrow2Tip.x, arrow2Tip.y); + } + + QGraphicsPathItem *arrw = dynamic_cast (arrows); + arrw->setPath(path); + arrw->setPen(pen); + + // Add or remove centre lines + QGraphicsPathItem *clines = dynamic_cast (centreLines); + QPainterPath clpath; + + if(dim->CentreLines.getValue()) { + // Add centre lines to the circle + + double clDist = margin; // Centre Line Size + if( margin / radius > 0.2) { + // Tolerance if centre line is greater than 0.3x radius then set to limit + clDist = radius * 0.2; + } + // Vertical Line + clpath.moveTo(centre.x, centre.y + clDist); + clpath.lineTo(centre.x, centre.y - clDist); + + // Vertical Line + clpath.moveTo(centre.x - clDist, centre.y); + clpath.lineTo(centre.x + clDist, centre.y); + + QPen clPen(QColor(128,128,128)); // TODO: centre line colour preference? + clines->setPen(clPen); + } + + clines->setPath(clpath); + + // Create Two Arrows always (but sometimes hide one!) + if(arw.size() != 2) { + prepareGeometryChange(); + for(std::vector::iterator it = arw.begin(); it != arw.end(); ++it) { + removeFromGroup(*it); + delete (*it); + } + arw.clear(); + + // These items are added to the scene-graph so should be handled by the canvas + QGIArrow *ar1 = new QGIArrow(); + QGIArrow *ar2 = new QGIArrow(); + arw.push_back(ar1); + arw.push_back(ar2); + + ar1->draw(); + ar2->flip(true); + ar2->draw(); + addToGroup(arw.at(0)); + addToGroup(arw.at(1)); + } + + QGIArrow *ar1 = dynamic_cast(arw.at(0)); + QGIArrow *ar2 = dynamic_cast(arw.at(1)); + + float arAngle = atan2(dirDimLine.y, dirDimLine.x) * 180 / M_PI; + + ar1->setHighlighted(isSelected() || hasHover); + ar2->setHighlighted(isSelected() || hasHover); + ar2->show(); + + if(outerPlacement) { + if(posMode > NoSnap) { + ar1->setPos(arrow2Tip.x, arrow2Tip.y); //arrow 1's endpoint is arrow2Tip!? + ar2->setPos(arrow1Tip.x, arrow1Tip.y); + ar1->setRotation((posMode == HorizontalSnap) ? 90 : 0); + ar2->setRotation((posMode == HorizontalSnap) ? 90 : 0); + } else { + Base::Vector3d vec = (arrow2Tip - centre).Normalize(); + float arAngle = atan2(-vec.y, -vec.x) * 180 / M_PI; + ar1->setPos(arrow2Tip.x, arrow2Tip.y); + ar1->setRotation(arAngle); + ar2->hide(); //only 1 arrowhead for NoSnap + outerplacement (ie a leader) + } + } else { + ar1->setRotation(arAngle); + ar2->setRotation(arAngle); + + ar1->setPos(arrow2Tip.x, arrow2Tip.y); + ar2->show(); + ar2->setPos(arrow1Tip.x, arrow1Tip.y); + } + + } else if(strcmp(dimType, "Radius") == 0) { + // preferred terminology: Dimension Text, Dimension Line(s), Extension Lines, Arrowheads + // radius gets 1 dimension line from the dimension text to a point on the curve + QGIDatumLabel *label = dynamic_cast(datumLabel); + Base::Vector3d lblCenter(label->X(), label->Y(),0.0); + + Base::Vector3d pointOnCurve,curveCenter; + double radius; + if(dim->References.getValues().size() == 1 && + DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge") { + int idx = DrawUtil::getIndexFromName(SubNames[0]); + DrawingGeometry::BaseGeom* geom = refObj->getProjEdgeByIndex(idx); + if(!geom) { + Base::Console().Log("INFO - qgivd::draw - no geom for projected edge: %d of %d\n", + idx,refObj->getEdgeGeometry().size()); + return; + } + if (geom->geomType == DrawingGeometry::CIRCLE) { + DrawingGeometry::Circle *circ = static_cast(geom); + radius = circ->radius; + curveCenter = Base::Vector3d(circ->center.fX,circ->center.fY,0.0); + pointOnCurve = Base::Vector3d(curveCenter.x + radius, curveCenter.y,0.0); + } else if (geom->geomType == DrawingGeometry::ARCOFCIRCLE) { + DrawingGeometry::AOC *circ = static_cast(geom); + radius = circ->radius; + curveCenter = Base::Vector3d(circ->center.fX,circ->center.fY,0.0); + pointOnCurve = Base::Vector3d(circ->midPnt.fX, circ->midPnt.fY,0.0); + } else { + throw Base::Exception("FVD::draw - Original edge not found or is invalid type (3)"); + } + } else { + throw Base::Exception("FVD::draw - Invalid reference for dimension type (3)"); + } + + Base::Vector3d dirDimLine = (lblCenter - pointOnCurve).Normalize(); + if (fabs(dirDimLine.Length()) < (Precision::Confusion())) { + dirDimLine = Base::Vector3d(-1.0,0.0,0.0); + } + + QFontMetrics fm(label->font()); + int w = fm.width(labelText); + float margin = 5.f; + // Note Bounding Box size is not the same width or height as text (only used for finding center) + float bbX = label->boundingRect().width(); + float bbY = label->boundingRect().height(); + label->setTransformOriginPoint(bbX / 2, bbY /2); + label->setRotation(0.0); //label is always right side up + + Base::Vector3d dLineStart = lblCenter - dirDimLine * (margin + w / 2); //startpoint of radius dimension line + QPainterPath dLinePath; //radius dimension line path + dLinePath.moveTo(dLineStart.x, dLineStart.y); + dLinePath.lineTo(pointOnCurve.x, pointOnCurve.y); + + QGraphicsPathItem *arrw = dynamic_cast (arrows); + arrw->setPath(dLinePath); + arrw->setPen(pen); + + // Add or remove centre lines (wf - this is centermark, not centerlines) + QGraphicsPathItem *clines = dynamic_cast (centreLines); + QPainterPath clpath; + if(dim->CentreLines.getValue()) { + // Add centre lines to the circle + double clDist = margin; // Centre Line Size + if( margin / radius > 0.2) { + // Tolerance if centre line is greater than 0.3x radius then set to limit + clDist = radius * 0.2; + } + // Vertical Line + clpath.moveTo(curveCenter.x, curveCenter.y + clDist); + clpath.lineTo(curveCenter.x, curveCenter.y - clDist); + // Horizontal Line + clpath.moveTo(curveCenter.x - clDist, curveCenter.y); + clpath.lineTo(curveCenter.x + clDist, curveCenter.y); + QPen clPen(QColor(128,128,128)); // TODO: centre line preference? + clines->setPen(clPen); + } + clines->setPath(clpath); + + // Always create Two Arrows (but sometimes hide 1!) + QGIArrow *ar1; + QGIArrow *ar2; + if(arw.size() != 2) { + prepareGeometryChange(); + for(std::vector::iterator it = arw.begin(); it != arw.end(); ++it) { + removeFromGroup(*it); + delete (*it); + } + arw.clear(); + + // These items are added to the scene-graph so should be handled by the canvas + ar1 = new QGIArrow(); + ar2 = new QGIArrow(); + arw.push_back(ar1); + arw.push_back(ar2); + + ar1->flip(true); + ar1->draw(); + ar2->draw(); + addToGroup(arw.at(0)); + addToGroup(arw.at(1)); + } + + ar1 = dynamic_cast(arw.at(0)); + ar2 = dynamic_cast(arw.at(1)); + + Base::Vector3d ar1Pos = pointOnCurve; + float arAngle = atan2(dirDimLine.y, dirDimLine.x) * 180 / M_PI; + + ar1->setPos(ar1Pos.x, ar1Pos.y); + ar1->setRotation(arAngle); + ar1->setHighlighted(isSelected() || hasHover); + ar1->show(); + ar2->setRotation(arAngle); + ar2->setHighlighted(isSelected() || hasHover); + ar2->hide(); + + } else if(strcmp(dimType, "Angle") == 0) { + // Only use two straight line edeges for angle + if(dim->References.getValues().size() == 2 && + DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" && + DrawUtil::getGeomTypeFromName(SubNames[1]) == "Edge") { + int idx0 = DrawUtil::getIndexFromName(SubNames[0]); + int idx1 = DrawUtil::getIndexFromName(SubNames[1]); + DrawingGeometry::BaseGeom* geom0 = refObj->getProjEdgeByIndex(idx0); + DrawingGeometry::BaseGeom* geom1 = refObj->getProjEdgeByIndex(idx1); + if (!geom0 || !geom1) { + Base::Console().Log("INFO - qgivd::draw - no geom for projected edge: %d or %d of %d\n", + idx0,idx1,refObj->getEdgeGeometry().size()); + return; + } + if ( (geom0->geomType == DrawingGeometry::GENERIC) && + (geom1->geomType == DrawingGeometry::GENERIC) ) { + DrawingGeometry::Generic *gen0 = static_cast(geom0); + DrawingGeometry::Generic *gen1 = static_cast(geom1); + + // Get Points for line + Base::Vector2D pnt1, pnt2; + Base::Vector3d p1S, p1E, p2S, p2E; + pnt1 = gen0->points.at(0); + pnt2 = gen0->points.at(1); + + p1S = Base::Vector3d(pnt1.fX, pnt1.fY, 0); + p1E = Base::Vector3d(pnt2.fX, pnt2.fY, 0); + + pnt1 = gen1->points.at(0); + pnt2 = gen1->points.at(1); + + p2S = Base::Vector3d(pnt1.fX, pnt1.fY, 0); + p2E = Base::Vector3d(pnt2.fX, pnt2.fY, 0); + + Base::Vector3d dir1 = p1E - p1S; + Base::Vector3d dir2 = p2E - p2S; + + double det = dir1.x*dir2.y - dir1.y*dir2.x; + if ((det > 0 ? det : -det) < 1e-10) + return; + double c1 = dir1.y*p1S.x - dir1.x*p1S.y; + double c2 = dir2.y*p2S.x - dir2.x*p2S.y; + double x = (dir1.x*c2 - dir2.x*c1)/det; + double y = (dir1.y*c2 - dir2.y*c1)/det; + + Base::Vector3d p0(x,y,0); + + // Get directions with outwards orientation and check if coincident + dir1 = ((p1E - p0).Length() > (p1S - p0).Length()) ? p1E - p0 : p1S - p0; + dir2 = ((p2E - p0).Length() > (p2S - p0).Length()) ? p2E - p0 : p2S - p0; + + // Qt y coordinates are flipped + dir1.y *= -1.; + dir2.y *= -1.; + + Base::Vector3d labelVec = (lblCenter - p0); + + double labelangle = atan2(-labelVec.y, labelVec.x); + + double startangle = atan2(dir1.y,dir1.x); + double range = atan2(-dir1.y*dir2.x+dir1.x*dir2.y, + dir1.x*dir2.x+dir1.y*dir2.y); + + double endangle = startangle + range; + + // Obtain the Label Position and measure the length between intersection + QGIDatumLabel *label = dynamic_cast(datumLabel); + Base::Vector3d lblCenter(label->X(), label->Y(), 0); + + float bbX = label->boundingRect().width(); + float bbY = label->boundingRect().height(); + + // Get font height + QFontMetrics fm(label->font()); + + int h = fm.height(); + double length = labelVec.Length(); + length -= h * 0.6; // Adjust the length so the label isn't over the line + + // Find the end points for dim lines + Base::Vector3d p1 = ((p1E - p0).Length() > (p1S - p0).Length()) ? p1E : p1S; + Base::Vector3d p2 = ((p2E - p0).Length() > (p2S - p0).Length()) ? p2E : p2S; + + // add an offset from the ends (add 1mm from end) + p1 += (p1-p0).Normalize() * 5.; + p2 += (p2-p0).Normalize() * 5.; + + Base::Vector3d ar1Pos = p0; + Base::Vector3d ar2Pos = p0; + + ar1Pos += Base::Vector3d(cos(startangle) * length, -sin(startangle) * length, 0.); + ar2Pos += Base::Vector3d(cos(endangle) * length , -sin(endangle) * length, 0.); + + // Draw the path + QPainterPath path; + + // Only draw extension lines if outside arc + if(length > (p1-p0).Length()) { + path.moveTo(p1.x, p1.y); + p1 = ar1Pos + (p1-p0).Normalize() * 5.; + path.lineTo(p1.x, p1.y); + } + + if(length > (p2-p0).Length()) { + path.moveTo(p2.x, p2.y); + p2 = ar2Pos + (p2-p0).Normalize() * 5.; + path.lineTo(p2.x, p2.y); + } + + + bool isOutside = true; + + // TODO find a better solution for this. Addmitedely not tidy + // ############### + // Treat zero as positive to be consistent for horizontal lines + if(std::abs(startangle) < FLT_EPSILON) + startangle = 0; + + if(std::abs(endangle) < FLT_EPSILON) + endangle = 0; + + if(startangle >= 0 && endangle >= 0) { + // Both are in positive side + double langle = labelangle; + if(labelangle < 0) + langle += M_PI * 2; + if(endangle - startangle > 0) { + if(langle > startangle && langle < endangle) + isOutside = false; + } else { + if(langle < startangle && langle > endangle) + isOutside = false; + } + } else if(startangle < 0 && endangle < 0) { + // Both are in positive side + double langle = labelangle; + if(labelangle > 0) + langle -= M_PI * 2; + if(endangle - startangle < 0) { + if(langle > endangle && langle < startangle) // clockwise + isOutside = false; + } else { + if(langle < endangle && langle > startangle) // anticlockwise + isOutside = false; + } + } else if(startangle >= 0 && endangle < 0) { + if(labelangle < startangle && labelangle > endangle) // clockwise + isOutside = false; + + } else if(startangle < 0 && endangle >= 0) { + // Both are in positive side + + if(labelangle > startangle && labelangle < endangle) // clockwise + isOutside = false; + } + + // ############### +// Base::Console().Log("<%f, %f, %f>\n", startangle, endangle, labelangle); + + QRectF arcRect(p0.x - length, p0.y - length, 2. * length, 2. * length); + path.arcMoveTo(arcRect, endangle * 180 / M_PI); + if(isOutside) { + if(labelangle > endangle) + { + path.arcTo(arcRect, endangle * 180 / M_PI, (labelangle - endangle) * 180 / M_PI); // chosen a nominal value for 10 degrees + path.arcMoveTo(arcRect,startangle * 180 / M_PI); + path.arcTo(arcRect, startangle * 180 / M_PI, -10); + } else { + path.arcTo(arcRect, endangle * 180 / M_PI, 10); // chosen a nominal value for 10 degrees + path.arcMoveTo(arcRect,startangle * 180 / M_PI); + path.arcTo(arcRect, startangle * 180 / M_PI, (labelangle - startangle) * 180 / M_PI); + } + + + } else { + path.arcTo(arcRect, endangle * 180 / M_PI, -range * 180 / M_PI); + } + + QGraphicsPathItem *arrw = dynamic_cast (arrows); + arrw->setPath(path); + arrw->setPen(pen); + + // Add the arrows + if(arw.size() != 2) { + prepareGeometryChange(); + for(std::vector::iterator it = arw.begin(); it != arw.end(); ++it) { + removeFromGroup(*it); + delete (*it); + } + arw.clear(); + + // These items are added to the scene-graph so should be handled by the canvas + QGIArrow *ar1 = new QGIArrow(); + QGIArrow *ar2 = new QGIArrow(); + arw.push_back(ar1); + arw.push_back(ar2); + + ar1->flip(true); + ar1->draw(); + ar2->draw(); + + addToGroup(arw.at(0)); + addToGroup(arw.at(1)); + } + + QGIArrow *ar1 = dynamic_cast(arw.at(0)); + QGIArrow *ar2 = dynamic_cast(arw.at(1)); + + Base::Vector3d norm1 = p1-p0; //(-dir1.y, dir1.x, 0.); + Base::Vector3d norm2 = p2-p0; //(-dir2.y, dir2.x, 0.); + + Base::Vector3d avg = (norm1 + norm2) / 2.; + + norm1 = norm1.ProjToLine(avg, norm1); + norm2 = norm2.ProjToLine(avg, norm2); + + ar1->setPos(ar1Pos.x,ar1Pos.y ); + ar2->setPos(ar2Pos.x,ar2Pos.y ); + + float ar1angle = atan2(-norm1.y, -norm1.x) * 180 / M_PI; + float ar2angle = atan2(norm2.y, norm2.x) * 180 / M_PI; + + if(isOutside) { + ar1->setRotation(ar1angle + 180.); + ar2->setRotation(ar2angle + 180.); + } else { + ar1->setRotation(ar1angle); + ar2->setRotation(ar2angle); + } + + ar1->setHighlighted(isSelected() || hasHover); + ar2->setHighlighted(isSelected() || hasHover); + + // Set the angle of the datum text + + Base::Vector3d labelNorm(-labelVec.y, labelVec.x, 0.); + double lAngle = atan2(labelNorm.y, labelNorm.x); + + if (lAngle > M_PI_2+M_PI/12) { + lAngle -= M_PI; + } else if (lAngle <= -M_PI_2+M_PI/12) { + lAngle += M_PI; + } + + label->setTransformOriginPoint(bbX / 2., bbY /2.); + + label->setRotation(lAngle * 180 / M_PI); + + } else { + throw Base::Exception("FVD::draw - Invalid reference for dimension type (4)"); + } + } //endif 2 Edges + } //endif Distance/Diameter/Radius/Angle + + // redraw the Dimension and the parent View + update(); + if (parentItem()) { + //TODO: parent redraw still required with new frame/label?? + parentItem()->update(); + } + +} + +void QGIViewDimension::drawBorder(void) +{ +//Dimensions have no border! +// Base::Console().Message("TRACE - QGIViewDimension::drawBorder - doing nothing!\n"); +} + +QVariant QGIViewDimension::itemChange(GraphicsItemChange change, const QVariant &value) +{ + if (change == ItemSelectedHasChanged && scene()) { + QGIDatumLabel *dLabel = dynamic_cast(datumLabel); + + if(isSelected()) { + dLabel->setSelected(true); + } else { + dLabel->setSelected(false); + } + draw(); + } + return QGIView::itemChange(change, value); +} + +void QGIViewDimension::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + QStyleOptionGraphicsItem myOption(*option); + myOption.state &= ~QStyle::State_Selected; + QGIView::paint(painter, &myOption, widget); +} + +#include "moc_QGIViewDimension.cpp" diff --git a/src/Mod/TechDraw/Gui/QGIViewDimension.h b/src/Mod/TechDraw/Gui/QGIViewDimension.h new file mode 100644 index 0000000000..70f5eb5dbb --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIViewDimension.h @@ -0,0 +1,133 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * * + * 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_QGRAPHICSITEMVIEWDIMENSION_H +#define DRAWINGGUI_QGRAPHICSITEMVIEWDIMENSION_H + +#include +#include +#include +#include "QGIView.h" +#include "QGCustomText.h" + +namespace TechDraw { +class DrawViewDimension; +} + +namespace TechDrawGeometry { +class BaseGeom; +} + +namespace TechDrawGui +{ + +class QGIDatumLabel : public QGCustomText +{ +Q_OBJECT +public: + explicit QGIDatumLabel(int ref = -1, QGraphicsScene *scene = 0 ); + ~QGIDatumLabel() {} + + enum {Type = QGI::UserType + 107}; + int type() const { return Type;} + + void setLabelCenter(); + void setPosFromCenter(const double &xCenter, const double &yCenter); + double X() const { return posX; } + double Y() const { return posY; } + +Q_SIGNALS: + void dragging(); + void hover(bool state); + void selected(bool state); + void dragFinished(); + +protected: + // Preselection events: + void mouseReleaseEvent( QGraphicsSceneMouseEvent * event); + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + // Selection detection + QVariant itemChange(GraphicsItemChange change, const QVariant &value); + +protected: + int reference; + double posX; + double posY; + +private: + int strokeWidth; + QPen m_pen; + QColor m_colNormal; + QColor m_colPre; + QColor m_colSel; +}; + +class TechDrawGuiExport QGIViewDimension : public QGIView +{ + Q_OBJECT + +public: + enum {Type = QGI::UserType + 106}; + + explicit QGIViewDimension(const QPoint &position, QGraphicsScene *scene); + ~QGIViewDimension(); + + void setViewPartFeature(TechDraw::DrawViewDimension *obj); + int type() const { return Type;} + + virtual void drawBorder(); + virtual void updateView(bool update = false); + virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); + +Q_SIGNALS: + void dirty(); + +public Q_SLOTS: + void datumLabelDragged(void); + void datumLabelDragFinished(void); + void select(bool state); + void hover(bool state); + void updateDim(void); + +protected: + void draw(); + // Selection detection + virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); + +protected: + bool hasHover; + QGI *datumLabel; //dimension text + QGI *arrows; //dimension lines + extension lines + QGI *centreLines; + + std::vector arw; //arrowheads + std::vector projGeom; + QPen pen; + QColor m_colNormal; + QColor m_colPre; + QColor m_colSel; +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGRAPHICSITEMVIEWDIMENSION_H diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.cpp b/src/Mod/TechDraw/Gui/QGIViewPart.cpp new file mode 100644 index 0000000000..4194b679c5 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIViewPart.cpp @@ -0,0 +1,654 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * * + * 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 +#include +#include +#include +#include +#include +#endif // #ifndef _PreComp_ + + +#include +#include +#include +#include +#include +#include + +#include "../App/DrawUtil.h" +#include "../App/DrawViewPart.h" +#include "../App/DrawHatch.h" +#include "QGIViewPart.h" + +using namespace TechDrawGui; + +void _dumpPath(const char* text,QPainterPath path); + +const float lineScaleFactor = 1.; // temp fiddle for devel +const float vertexScaleFactor = 2.; // temp fiddle for devel + +QGIViewPart::QGIViewPart(const QPoint &pos, QGraphicsScene *scene) + :QGIView(pos, scene) +{ + setHandlesChildEvents(false); + setCacheMode(QGI::NoCache); + setAcceptHoverEvents(true); + setFlag(QGI::ItemIsMovable, true); + + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Drawing/Colors"); + App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("HiddenColor", 0x08080800)); + m_colHid = fcColor.asQColor(); +} + +QGIViewPart::~QGIViewPart() +{ + tidy(); +} + +QVariant QGIViewPart::itemChange(GraphicsItemChange change, const QVariant &value) +{ + if (change == ItemSelectedHasChanged && scene()) { + QList items = childItems(); + for(QList::iterator it = items.begin(); it != items.end(); ++it) { + QGIEdge *edge = dynamic_cast(*it); + QGIVertex *vert = dynamic_cast(*it); + if(edge) { + edge->setHighlighted(isSelected()); + } else if(vert){ + vert->setHighlighted(isSelected()); + } + } + } else if(change == ItemSceneChange && scene()) { + tidy(); + } + return QGIView::itemChange(change, value); +} + +void QGIViewPart::tidy() +{ + //Delete any leftover items + for(QList::iterator it = deleteItems.begin(); it != deleteItems.end(); ++it) { + delete *it; + } + deleteItems.clear(); +} + +void QGIViewPart::setViewPartFeature(TechDraw::DrawViewPart *obj) +{ + // called from QGVPage + setViewFeature(static_cast(obj)); +} + +QPainterPath QGIViewPart::drawPainterPath(DrawingGeometry::BaseGeom *baseGeom) const +{ + QPainterPath path; + + switch(baseGeom->geomType) { + case DrawingGeometry::CIRCLE: { + DrawingGeometry::Circle *geom = static_cast(baseGeom); + + double x = geom->center.fX - geom->radius; + double y = geom->center.fY - geom->radius; + + path.addEllipse(x, y, geom->radius * 2, geom->radius * 2); //topleft@(x,y) radx,rady + //Base::Console().Message("TRACE -drawPainterPath - making an CIRCLE @(%.3f,%.3f) R:%.3f\n",x, y, geom->radius); + + } break; + case DrawingGeometry::ARCOFCIRCLE: { + DrawingGeometry::AOC *geom = static_cast(baseGeom); + + //double x = geom->center.fX - geom->radius; + //double y = geom->center.fY - geom->radius; + pathArc(path, geom->radius, geom->radius, 0., geom->largeArc, geom->cw, + geom->endPnt.fX, geom->endPnt.fY, + geom->startPnt.fX, geom->startPnt.fY); + //Base::Console().Message("TRACE -drawPainterPath - making an ARCOFCIRCLE @(%.3f,%.3f) R:%.3f\n",x, y, geom->radius); + } break; + case DrawingGeometry::ELLIPSE: { + DrawingGeometry::Ellipse *geom = static_cast(baseGeom); + + // Calculate start and end points as ellipse with theta = 0 and pi + double startX = geom->center.fX + geom->major * cos(geom->angle), + startY = geom->center.fY + geom->major * sin(geom->angle), + endX = geom->center.fX - geom->major * cos(geom->angle), + endY = geom->center.fY - geom->major * sin(geom->angle); + + pathArc(path, geom->major, geom->minor, geom->angle, false, false, + endX, endY, startX, startY); + + pathArc(path, geom->major, geom->minor, geom->angle, false, false, + startX, startY, endX, endY); + + //Base::Console().Message("TRACE -drawPainterPath - making an ELLIPSE @(%.3f,%.3f) R1:%.3f R2:%.3f\n",x, y, geom->major, geom->minor); + } break; + case DrawingGeometry::ARCOFELLIPSE: { + DrawingGeometry::AOE *geom = static_cast(baseGeom); + + pathArc(path, geom->major, geom->minor, geom->angle, geom->largeArc, geom->cw, + geom->endPnt.fX, geom->endPnt.fY, + geom->startPnt.fX, geom->startPnt.fY); + //Base::Console().Message("TRACE -drawPainterPath - making an ARCOFELLIPSE R1:%.3f R2:%.3f From: (%.3f,%.3f) To: (%.3f,%.3f)\n",geom->major, geom->minor,geom->startPnt.fX, geom->startPnt.fY,geom->endPnt.fX, geom->endPnt.fY); + + } break; + case DrawingGeometry::BSPLINE: { + DrawingGeometry::BSpline *geom = static_cast(baseGeom); + + std::vector::const_iterator it = geom->segments.begin(); + + // Move painter to the beginning of our first segment + path.moveTo(it->pnts[0].fX, it->pnts[0].fY); + //Base::Console().Message("TRACE -drawPainterPath - making an BSPLINE From: (%.3f,%.3f)\n",it->pnts[0].fX,it->pnts[0].fY); + + for ( ; it != geom->segments.end(); ++it) { + // At this point, the painter is either at the beginning + // of the first segment, or end of the last + if ( it->poles == 2 ) { + // Degree 1 bezier = straight line... + path.lineTo(it->pnts[1].fX, it->pnts[1].fY); + + } else if ( it->poles == 3 ) { + path.quadTo(it->pnts[1].fX, it->pnts[1].fY, + it->pnts[2].fX, it->pnts[2].fY); + + } else if ( it->poles == 4 ) { + path.cubicTo(it->pnts[1].fX, it->pnts[1].fY, + it->pnts[2].fX, it->pnts[2].fY, + it->pnts[3].fX, it->pnts[3].fY); + } else { //can only handle lines,quads,cubes + Base::Console().Error("Bad pole count (%d) for BezierSegment of BSpline geometry\n",it->poles); + path.lineTo(it->pnts[1].fX, it->pnts[1].fY); //show something for debugging + } + } + } break; + case DrawingGeometry::GENERIC: { + DrawingGeometry::Generic *geom = static_cast(baseGeom); + + path.moveTo(geom->points[0].fX, geom->points[0].fY); + std::vector::const_iterator it = geom->points.begin(); + //Base::Console().Message("TRACE -drawPainterPath - making an GENERIC From: (%.3f,%.3f)\n",geom->points[0].fX, geom->points[0].fY); + for(++it; it != geom->points.end(); ++it) { + path.lineTo((*it).fX, (*it).fY); + //Base::Console().Message(">>>> To: (%.3f,%.3f)\n",(*it).fX, (*it).fY); + } + } break; + default: + Base::Console().Error("Error - drawPainterPath - UNKNOWN geomType: %d\n",baseGeom->geomType); + break; + } + + double rot = getViewObject()->Rotation.getValue(); + if (rot) { + QTransform t; + t.rotate(-rot); + path = t.map(path); + } + + return path; +} + +void QGIViewPart::updateView(bool update) +{ + if (getViewObject() == 0 || + !getViewObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) { + return; + } + + QGIView::updateView(update); + + TechDraw::DrawViewPart *viewPart = dynamic_cast(getViewObject()); + + if(update || + viewPart->isTouched() || + viewPart->Source.isTouched() || + viewPart->Direction.isTouched() || + viewPart->Tolerance.isTouched() || + viewPart->Scale.isTouched() || + viewPart->ShowHiddenLines.isTouched()) { + // Remove all existing graphical representations (QGIxxxx) otherwise BRect only grows, never shrinks? + prepareGeometryChange(); + QList items = childItems(); + for(QList::iterator it = items.begin(); it != items.end(); ++it) { + if (dynamic_cast (*it) || + dynamic_cast(*it) || + dynamic_cast(*it) || + dynamic_cast(*it)) { + removeFromGroup(*it); + scene()->removeItem(*it); + + // We store these and delete till later to prevent rendering crash ISSUE + deleteItems.append(*it); + } + } + draw(); + } else if(viewPart->LineWidth.isTouched() || + viewPart->HiddenWidth.isTouched()) { + QList items = childItems(); + for(QList::iterator it = items.begin(); it != items.end(); ++it) { + QGIEdge *edge = dynamic_cast(*it); + if(edge && edge->getHiddenEdge()) { + edge->setStrokeWidth(viewPart->HiddenWidth.getValue() * lineScaleFactor); + } else { + edge->setStrokeWidth(viewPart->LineWidth.getValue() * lineScaleFactor); + } + } + } +} + +void QGIViewPart::draw() { + drawViewPart(); + drawBorder(); +} + +void QGIViewPart::drawViewPart() +{ + if ( getViewObject() == 0 || + !getViewObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) { + return; + } + + TechDraw::DrawViewPart *viewPart = dynamic_cast(getViewObject()); + + float lineWidth = viewPart->LineWidth.getValue() * lineScaleFactor; + float lineWidthHid = viewPart->HiddenWidth.getValue() * lineScaleFactor; + + prepareGeometryChange(); + +#if MOD_TECHDRAW_HANDLE_FACES + // Draw Faces + const std::vector &faceGeoms = part->getFaceGeometry(); + const std::vector &faceRefs = part->getFaceReferences(); + std::vector::const_iterator fit = faceGeoms.begin(); + QGIFace* face; + QPen facePen; + for(int i = 0 ; fit != faceGeoms.end(); fit++, i++) { + std::vector faceWires = (*fit)->wires; + QPainterPath facePath; + for(std::vector::iterator wire = faceWires.begin(); wire != faceWires.end(); wire++) { + QPainterPath wirePath; + QPointF shapePos; + for(std::vector::iterator baseGeom = (*wire)->geoms.begin(); + baseGeom != (*wire)->geoms.end(); + baseGeom++) { + QPainterPath edgePath = drawPainterPath(*baseGeom); + //If the current end point matches the shape end point the new edge path needs reversing + QPointF shapePos = (wirePath.currentPosition()- edgePath.currentPosition()); + if(sqrt(shapePos.x() * shapePos.x() + shapePos.y()*shapePos.y()) < 0.05) { + edgePath = edgePath.toReversed(); + } + wirePath.connectPath(edgePath); + wirePath.setFillRule(Qt::WindingFill); + } + facePath.addPath(wirePath); + } + + //debug a path + //std::stringstream faceId; + //faceId << "facePath" << i; + //_dumpPath(faceId.str().c_str(),facePath); + + QGIFace *fitem = new QGIFace(-1); + // TODO: DrawingGeometry::Face has no easy method of determining hidden/visible??? + // Hide any edges that are hidden if option is set. +// if((*fit)->extractType == DrawingGeometry::WithHidden && !part->ShowHiddenLines.getValue()) +// graphicsItem->hide(); + addToGroup(fitem); + fitem->setPos(0.0,0.0); + //QPainterPath simplePath = facePath.simplified(); + //simplePath.setFillRule(Qt::WindingFill); + //fitem->setPath(simplePath); + fitem->setPath(facePath); + fitem->setFlag(QGI::ItemIsSelectable, true); + } +#endif //#if MOD_TECHDRAW_HANDLE_FACES + + // Draw Hatches + std::vector hatchObjs = viewPart->getHatches(); + if (!hatchObjs.empty()) { + std::vector::iterator itHatch = hatchObjs.begin(); + for(; itHatch != hatchObjs.end(); itHatch++) { + //if hatchdirection == viewPartdirection { + TechDraw::DrawHatch* feat = (*itHatch); + const std::vector &edgeNames = feat->Edges.getSubValues(); + std::vector::const_iterator itEdge = edgeNames.begin(); + std::vector unChained; + + //get all edge geometries for this hatch + for (; itEdge != edgeNames.end(); itEdge++) { + int idxEdge = DrawUtil::getIndexFromName((*itEdge)); + DrawingGeometry::BaseGeom* edgeGeom = viewPart->getProjEdgeByIndex(idxEdge); + if (!edgeGeom) { + Base::Console().Log("Error - qgivp::drawViewPart - edgeGeom: %d is NULL\n",idxEdge); + } + unChained.push_back(edgeGeom); + } + + //chain edges tail to nose into a closed region + std::vector chained = DrawingGeometry::chainGeoms(unChained); + + //iterate through the chain to make QPainterPath + std::vector::iterator itChain = chained.begin(); + QPainterPath hatchPath; + for (; itChain != chained.end(); itChain++) { + QPainterPath subPath; + if ((*itChain)->reversed) { + subPath = drawPainterPath((*itChain)).toReversed(); + } else { + subPath = drawPainterPath((*itChain)); + } + hatchPath.connectPath(subPath); + //_dumpPath("subpath",subPath); + } + + QGIHatch* hatch = new QGIHatch(feat->getNameInDocument()); + addToGroup(hatch); + hatch->setPos(0.0,0.0); + hatch->setPath(hatchPath); + hatch->setFill(feat->HatchPattern.getValue()); + hatch->setColor(feat->HatchColor.getValue()); + //_dumpPath("hatchPath",hatchPath); + hatch->setFlag(QGI::ItemIsSelectable, true); + } + } + + // Draw Edges + const std::vector &geoms = viewPart->getEdgeGeometry(); + const std::vector &refs = viewPart->getEdgeReferences(); + std::vector::const_iterator it = geoms.begin(); + QGIEdge* item; + + for(int i = 0 ; it != geoms.end(); ++it, i++) { + //TODO: investigate if an Edge can be both Hidden and Smooth??? + if(((*it)->extractType == DrawingGeometry::Plain) || + (((*it)->extractType == DrawingGeometry::WithHidden) && viewPart->ShowHiddenLines.getValue()) || + ((*it)->extractType == DrawingGeometry::WithSmooth)) { +// (((*it)->extractType == DrawingGeometry::WithSmooth) && part->ShowSmoothLines.getValue())) { + //item = new QGIEdge(refs.at(i)); + item = new QGIEdge(i); + item->setReference(refs.at(i)); + addToGroup(item); //item is at scene(0,0), not group(0,0) + item->setPos(0.0,0.0); + item->setStrokeWidth(lineWidth); + if((*it)->extractType == DrawingGeometry::WithHidden) { + item->setStrokeWidth(lineWidthHid); + item->setHiddenEdge(true); + } else if((*it)->extractType == DrawingGeometry::WithSmooth) { + item->setSmoothEdge(true); + } + item->setPath(drawPainterPath(*it)); + item->setFlag(QGI::ItemIsSelectable, true); + item->setAcceptHoverEvents(true); + + //debug a path + //QPainterPath edgePath=drawPainterPath(*it); + //item->setPath(edgePath); + //std::stringstream edgeId; + //edgeId << "edge" << i; + //_dumpPath(edgeId.str().c_str(),edgePath); + } + } + + // Draw Vertexs: + const std::vector &verts = viewPart->getVertexGeometry(); + const std::vector &vertRefs = viewPart->getVertexReferences(); + std::vector::const_iterator vert = verts.begin(); + + for(int i = 0 ; vert != verts.end(); ++vert, i++) { + QGIVertex *item = new QGIVertex(i); + item->setReference(vertRefs.at(i)); + addToGroup(item); + item->setPos((*vert)->pnt.fX, (*vert)->pnt.fY); //this is in ViewPart coords + item->setRadius(lineWidth * vertexScaleFactor); + } +} + +std::vector QGIViewPart::getHatchesForView(TechDraw::DrawViewPart* viewPart) +{ + std::vector docObjs = viewPart->getDocument()->getObjectsOfType(TechDraw::DrawHatch::getClassTypeId()); + std::vector hatchObjs; + std::string viewName = viewPart->getNameInDocument(); + std::vector::iterator itDoc = docObjs.begin(); + for(; itDoc != docObjs.end(); itDoc++) { + TechDraw::DrawHatch* hatch = dynamic_cast(*itDoc); + if (viewName.compare((hatch->PartView.getValue())->getNameInDocument()) == 0) { + hatchObjs.push_back(hatch); + } + } + return hatchObjs; +} + +// As called by arc of ellipse case: +// pathArc(path, geom->major, geom->minor, geom->angle, geom->largeArc, geom->cw, +// geom->endPnt.fX, geom->endPnt.fY, +// geom->startPnt.fX, geom->startPnt.fY); +void QGIViewPart::pathArc(QPainterPath &path, double rx, double ry, double x_axis_rotation, + bool large_arc_flag, bool sweep_flag, + double x, double y, + double curx, double cury) const +{ + double sin_th, cos_th; + double a00, a01, a10, a11; + double x0, y0, x1, y1, xc, yc; + double d, sfactor, sfactor_sq; + double th0, th1, th_arc; + int i, n_segs; + double dx, dy, dx1, dy1, Pr1, Pr2, Px, Py, check; + + rx = qAbs(rx); + ry = qAbs(ry); + + sin_th = qSin(x_axis_rotation); + cos_th = qCos(x_axis_rotation); + + dx = (curx - x) / 2.0; + dy = (cury - y) / 2.0; + dx1 = cos_th * dx + sin_th * dy; + dy1 = -sin_th * dx + cos_th * dy; + Pr1 = rx * rx; + Pr2 = ry * ry; + Px = dx1 * dx1; + Py = dy1 * dy1; + /* Spec : check if radii are large enough */ + check = Px / Pr1 + Py / Pr2; + if (check > 1) { + rx = rx * qSqrt(check); + ry = ry * qSqrt(check); + } + + a00 = cos_th / rx; + a01 = sin_th / rx; + a10 = -sin_th / ry; + a11 = cos_th / ry; + x0 = a00 * curx + a01 * cury; + y0 = a10 * curx + a11 * cury; + x1 = a00 * x + a01 * y; + y1 = a10 * x + a11 * y; + /* (x0, y0) is current point in transformed coordinate space. + (x1, y1) is new point in transformed coordinate space. + + The arc fits a unit-radius circle in this space. + */ + d = (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0); + sfactor_sq = 1.0 / d - 0.25; + if (sfactor_sq < 0) + sfactor_sq = 0; + + sfactor = qSqrt(sfactor_sq); + + if (sweep_flag == large_arc_flag) + sfactor = -sfactor; + + xc = 0.5 * (x0 + x1) - sfactor * (y1 - y0); + yc = 0.5 * (y0 + y1) + sfactor * (x1 - x0); + /* (xc, yc) is center of the circle. */ + + th0 = qAtan2(y0 - yc, x0 - xc); + th1 = qAtan2(y1 - yc, x1 - xc); + + th_arc = th1 - th0; + if (th_arc < 0 && sweep_flag) + th_arc += 2 * M_PI; + else if (th_arc > 0 && !sweep_flag) + th_arc -= 2 * M_PI; + + n_segs = qCeil(qAbs(th_arc / (M_PI * 0.5 + 0.001))); + + path.moveTo(curx, cury); + + for (i = 0; i < n_segs; i++) { + pathArcSegment(path, xc, yc, + th0 + i * th_arc / n_segs, + th0 + (i + 1) * th_arc / n_segs, + rx, ry, x_axis_rotation); + } +} + +void QGIViewPart::pathArcSegment(QPainterPath &path, + double xc, double yc, + double th0, double th1, + double rx, double ry, double xAxisRotation) const +{ + double sinTh, cosTh; + double a00, a01, a10, a11; + double x1, y1, x2, y2, x3, y3; + double t; + double thHalf; + + sinTh = qSin(xAxisRotation); + cosTh = qCos(xAxisRotation); + + a00 = cosTh * rx; + a01 = -sinTh * ry; + a10 = sinTh * rx; + a11 = cosTh * ry; + + thHalf = 0.5 * (th1 - th0); + t = (8.0 / 3.0) * qSin(thHalf * 0.5) * qSin(thHalf * 0.5) / qSin(thHalf); + x1 = xc + qCos(th0) - t * qSin(th0); + y1 = yc + qSin(th0) + t * qCos(th0); + x3 = xc + qCos(th1); + y3 = yc + qSin(th1); + x2 = x3 + t * qSin(th1); + y2 = y3 - t * qCos(th1); + + path.cubicTo(a00 * x1 + a01 * y1, a10 * x1 + a11 * y1, + a00 * x2 + a01 * y2, a10 * x2 + a11 * y2, + a00 * x3 + a01 * y3, a10 * x3 + a11 * y3); +} + +QGIEdge * QGIViewPart::findRefEdge(int idx) +{ + QList items = childItems(); + for(QList::iterator it = items.begin(); it != items.end(); it++) { + QGIEdge *edge = dynamic_cast(*it); + if(edge && edge->getReference() == idx) + return edge; + } + return 0; +} + +QGIVertex * QGIViewPart::findRefVertex(int idx) +{ + QList items = childItems(); + for(QList::iterator it = items.begin(); it != items.end(); it++) { + QGIVertex *vert = dynamic_cast(*it); + if(vert && vert->getReference() == idx) + return vert; + } + return 0; +} + +void QGIViewPart::toggleCache(bool state) +{ + QList items = childItems(); + for(QList::iterator it = items.begin(); it != items.end(); it++) { + //(*it)->setCacheMode((state)? DeviceCoordinateCache : NoCache); //TODO: fiddle cache settings if req'd for performance + (*it)->setCacheMode((state)? NoCache : NoCache); + (*it)->update(); + } +} + +void QGIViewPart::toggleCosmeticLines(bool state) +{ + QList items = childItems(); + for(QList::iterator it = items.begin(); it != items.end(); it++) { + QGIEdge *edge = dynamic_cast(*it); + if(edge) { + edge->setCosmetic(state); + } + } +} + +void QGIViewPart::toggleVertices(bool state) +{ + QList items = childItems(); + for(QList::iterator it = items.begin(); it != items.end(); it++) { + QGIVertex *vert = dynamic_cast(*it); + if(vert) { + if(state) + vert->show(); + else + vert->hide(); + } + } +} + +QRectF QGIViewPart::boundingRect() const +{ + //return childrenBoundingRect().adjusted(-2.,-2.,2.,6.); //just a bit bigger than the children need + return childrenBoundingRect(); +} + +void _dumpPath(const char* text,QPainterPath path) +{ + QPainterPath::Element elem; + Base::Console().Message(">>>%s has %d elements\n",text,path.elementCount()); + char* typeName; + for(int iElem = 0; iElem < path.elementCount(); iElem++) { + elem = path.elementAt(iElem); + if(elem.isMoveTo()) { + typeName = "MoveTo"; + } else if (elem.isLineTo()) { + typeName = "LineTo"; + } else if (elem.isCurveTo()) { + typeName = "CurveTo"; + } else { + typeName = "Unknown"; + } + Base::Console().Message(">>>>> element %d: type:%d/%s pos(%.3f,%.3f) M:%d L:%d C:%d\n",iElem, + elem.type,typeName,elem.x,elem.y,elem.isMoveTo(),elem.isLineTo(),elem.isCurveTo()); + } +} + + +#include "moc_QGIViewPart.cpp" diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.h b/src/Mod/TechDraw/Gui/QGIViewPart.h new file mode 100644 index 0000000000..fa7829b37b --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIViewPart.h @@ -0,0 +1,109 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * * + * 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_QGRAPHICSITEMVIEWPART_H +#define DRAWINGGUI_QGRAPHICSITEMVIEWPART_H + +#include +#include + +#include "QGIView.h" +#include "QGIFace.h" +#include "QGIEdge.h" +#include "QGIVertex.h" +#include "QGIHatch.h" + +namespace TechDraw { +class DrawViewPart; +class DrawHatch; +} + +namespace TechDrawGeometry { +class BaseGeom; +} + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGIViewPart : public QGIView +{ + Q_OBJECT + +public: + + explicit QGIViewPart(const QPoint &position, QGraphicsScene *scene); + ~QGIViewPart(); + + enum {Type = QGI::UserType + 102}; + int type() const { return Type;} + + + void toggleCache(bool state); + void toggleCosmeticLines(bool state); + void toggleVertices(bool state); + void setViewPartFeature(TechDraw::DrawViewPart *obj); + virtual void updateView(bool update = false); + void tidy(); + + virtual void draw(); + virtual QRectF boundingRect() const; + +Q_SIGNALS: + void selected(bool state); + void dirty(); + +protected: + QGIEdge * findRefEdge(int i); + QGIVertex * findRefVertex(int idx); + + /// Helper for pathArc() + /*! + * x_axis_rotation is in radian + */ + void pathArcSegment(QPainterPath &path, double xc, double yc, double th0, + double th1,double rx, double ry, double xAxisRotation) const; + + /// Draws an arc using QPainterPath path + /*! + * x_axis_rotation is in radian + */ + void pathArc(QPainterPath &path, double rx, double ry, double x_axis_rotation, + bool large_arc_flag, bool sweep_flag, + double x, double y, + double curx, double cury) const; + + QPainterPath drawPainterPath(DrawingGeometry::BaseGeom *baseGeom) const; + std::vector getHatchesForView(TechDraw::DrawViewPart* viewPart); + void drawViewPart(); + + virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); + +protected: + QColor m_colHid; + +private: + QList deleteItems; +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGRAPHICSITEMVIEWPART_H diff --git a/src/Mod/TechDraw/Gui/QGIViewSection.cpp b/src/Mod/TechDraw/Gui/QGIViewSection.cpp new file mode 100644 index 0000000000..ced2203aa4 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIViewSection.cpp @@ -0,0 +1,154 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * * + * 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 +#include +#include +#include +#include +#endif + +#include + +#include + +#include "../App/DrawViewSection.h" +#include "QGIViewSection.h" + +using namespace TechDrawGui; + +QGIViewSection::QGIViewSection(const QPoint &pos, QGraphicsScene *scene) :QGIViewPart(pos, scene) +{ +} + +QGIViewSection::~QGIViewSection() +{ + +} + +void QGIViewSection::draw() +{ + QGIViewPart::draw(); + drawSectionFace(); +} + +void QGIViewSection::drawSectionFace() +{ + if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewSection::getClassTypeId())) + return; + + TechDraw::DrawViewSection *part = dynamic_cast(getViewObject()); + if (!part->hasGeometry()) { + return; + } + + //Base::Console().Log("drawing section face\n"); + + // Get the section face from the feature + std::vector faceGeoms; + part->getSectionSurface(faceGeoms); + if (faceGeoms.empty()) { + Base::Console().Log("INFO - QGIViewSection::drawSectionFace - No Face available. Check Section plane.\n"); + return; + } + +#if MOD_TECHDRAW_HANDLE_FACES + // Draw Faces + std::vector::const_iterator fit = faceGeoms.begin(); + + QGI *graphicsItem = 0; + QPen facePen; + +//TODO: check if this is the same logic as QGIVPart + for(int i = 0 ; fit != faceGeoms.end(); ++fit, i++) { + std::vector faceWires = (*fit)->wires; + QPainterPath facePath; + for(std::vector::iterator wire = faceWires.begin(); wire != faceWires.end(); ++wire) { + QPainterPath wirePath; + QPointF shapePos; + for(std::vector::iterator baseGeom = (*wire)->geoms.begin(); baseGeom != (*wire)->geoms.end(); ++baseGeom) { + //Save the start Position + QPainterPath edgePath = drawPainterPath(*baseGeom); + + // If the current end point matches the shape end point the new edge path needs reversing + QPointF shapePos = (wirePath.currentPosition()- edgePath.currentPosition()); + if(sqrt(shapePos.x() * shapePos.x() + shapePos.y()*shapePos.y()) < 0.05) { + edgePath = edgePath.toReversed(); + } + wirePath.connectPath(edgePath); + wirePath.setFillRule(Qt::WindingFill); + } + facePath.addPath(wirePath); + } + + QGIFace *item = new QGIFace(-1); + + item->setPath(facePath); + // item->setStrokeWidth(lineWidth); + + QBrush faceBrush(QBrush(QColor(0,0,255,40))); + + item->setBrush(faceBrush); + facePen.setColor(Qt::black); + item->setPen(facePen); + item->moveBy(x(), y()); + graphicsItem = dynamic_cast(item); + + if(graphicsItem) { + // Hide any edges that are hidden if option is set. + // if((*fit)->extractType == DrawingGeometry::WithHidden && !part->ShowHiddenLines.getValue()) + // graphicsItem->hide(); + + addToGroup(graphicsItem); + graphicsItem->setFlag(QGI::ItemIsSelectable, true); + } + } +#endif +} + +void QGIViewSection::updateView(bool update) +{ + // Iterate + if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) + return; + + TechDraw::DrawViewSection *viewPart = dynamic_cast(getViewObject()); + + if(update || + viewPart->SectionNormal.isTouched() || + viewPart->SectionOrigin.isTouched()) { + QGIViewPart::updateView(true); + } else { + QGIViewPart::updateView(); + } +} + +#include "moc_QGIViewSection.cpp" diff --git a/src/Mod/TechDraw/Gui/QGIViewSection.h b/src/Mod/TechDraw/Gui/QGIViewSection.h new file mode 100644 index 0000000000..dc5681080b --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIViewSection.h @@ -0,0 +1,62 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * * + * 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_QGRAPHICSITEMVIEWSECTION_H +#define DRAWINGGUI_QGRAPHICSITEMVIEWSECTION_H + +#include "QGIViewPart.h" + +namespace TechDraw { +class DrawViewSection; +} + +namespace TechDrawGeometry { +class BaseGeom; +} + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGIViewSection : public QGIViewPart +{ + Q_OBJECT + +public: + + explicit QGIViewSection(const QPoint &position, QGraphicsScene *scene); + ~QGIViewSection(); + + virtual void draw(); + void updateView(bool update = false); + enum {Type = QGI::UserType + 108}; + int type() const { return Type;} + +Q_SIGNALS: + void dirty(); + +protected: + void drawSectionFace(); +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGRAPHICSITEMVIEWPART_H diff --git a/src/Mod/TechDraw/Gui/QGIViewSymbol.cpp b/src/Mod/TechDraw/Gui/QGIViewSymbol.cpp new file mode 100644 index 0000000000..fde0314434 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIViewSymbol.cpp @@ -0,0 +1,138 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * 2014 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/DrawViewSymbol.h" +#include "QGIViewSymbol.h" + +using namespace TechDrawGui; + +QGIViewSymbol::QGIViewSymbol(const QPoint &pos, QGraphicsScene *scene) :QGIView(pos, scene) +{ + setHandlesChildEvents(false); + setCacheMode(QGI::NoCache); + setAcceptHoverEvents(true); + setFlag(QGI::ItemIsMovable, true); + + m_svgRender = new QSvgRenderer(); + + m_svgItem = new QGCustomSvg(); + addToGroup(m_svgItem); + m_svgItem->setPos(0.,0.); +} + +QGIViewSymbol::~QGIViewSymbol() +{ + // m_svgItem belongs to this group and will be deleted by Qt + delete(m_svgRender); +} + +QVariant QGIViewSymbol::itemChange(GraphicsItemChange change, const QVariant &value) +{ + + return QGIView::itemChange(change, value); +} + +void QGIViewSymbol::setViewSymbolFeature(TechDraw::DrawViewSymbol *obj) +{ + // called from QGVPage. (once) + setViewFeature(static_cast(obj)); +} + +void QGIViewSymbol::updateView(bool update) +{ + if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewSymbol::getClassTypeId())) + return; + + TechDraw::DrawViewSymbol *viewSymbol = dynamic_cast(getViewObject()); + + if (update || + viewSymbol->isTouched() || + viewSymbol->Symbol.isTouched()) { + draw(); + } + + if (viewSymbol->Scale.isTouched()) { + setScale(viewSymbol->Scale.getValue()); + draw(); + } + + QGIView::updateView(update); +} + +void QGIViewSymbol::draw() +{ + drawSvg(); + if (borderVisible) { + drawBorder(); + } +} + +void QGIViewSymbol::drawSvg() +{ + if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewSymbol::getClassTypeId())) + return; + + TechDraw::DrawViewSymbol *viewSymbol = dynamic_cast(getViewObject()); + + QString qs(QString::fromUtf8(viewSymbol->Symbol.getValue())); + QByteArray qba; + qba.append(qs); + if (!load(&qba)) { + Base::Console().Error("QGIViewSymbol::drawSvg - Could not load %s.Symbol into renderer\n", viewSymbol->getNameInDocument()); + } + m_svgItem->setPos(0.,0.); +} + +QRectF QGIViewSymbol::boundingRect() const +{ + return childrenBoundingRect(); +} + +bool QGIViewSymbol::load(QByteArray *svgBytes) +{ + bool success = m_svgRender->load(*svgBytes); + m_svgItem->setSharedRenderer(m_svgRender); + return(success); +} + +#include "moc_QGIViewSymbol.cpp" + diff --git a/src/Mod/TechDraw/Gui/QGIViewSymbol.h b/src/Mod/TechDraw/Gui/QGIViewSymbol.h new file mode 100644 index 0000000000..d6f26e9b66 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIViewSymbol.h @@ -0,0 +1,77 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * 2014 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_QGRAPHICSITEMVIEWSYMBOL_H +#define DRAWINGGUI_QGRAPHICSITEMVIEWSYMBOL_H + +#include +#include +#include +#include +#include +#include + +#include "QGIView.h" +#include "QGCustomSvg.h" + +namespace TechDraw { +class DrawViewSymbol; +} + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGIViewSymbol : public QGIView +{ + Q_OBJECT + +public: + explicit QGIViewSymbol(const QPoint &position, QGraphicsScene *scene); + ~QGIViewSymbol(); + + enum {Type = QGI::UserType + 121}; + int type() const { return Type;} + + void updateView(bool update = false); + void setViewSymbolFeature(TechDraw::DrawViewSymbol *obj); + + virtual void draw(); + virtual QRectF boundingRect() const; + +Q_SIGNALS: + void hover(bool state); + void selected(bool state); + +protected: + bool load(QByteArray *svgString); + void drawSvg(); + + QVariant itemChange(GraphicsItemChange change, const QVariant &value); + + QGCustomSvg *m_svgItem; + QSvgRenderer *m_svgRender; +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGRAPHICSITEMVIEWSYMBOL_H diff --git a/src/Mod/TechDraw/Gui/QGVPage.cpp b/src/Mod/TechDraw/Gui/QGVPage.cpp new file mode 100644 index 0000000000..29a82e236b --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVPage.cpp @@ -0,0 +1,529 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * * + * 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 +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ViewProviderPage.h" + +#include "QGIDrawingTemplate.h" +#include "QGISVGTemplate.h" +#include "QGIViewCollection.h" +#include "QGIViewDimension.h" +#include "QGIProjGroup.h" +#include "QGIViewPart.h" +#include "QGIViewSection.h" +#include "QGIViewAnnotation.h" +#include "QGIViewSymbol.h" +#include "QGIViewClip.h" + +#include "QGVPage.h" + +using namespace TechDrawGui; + +QGVPage::QGVPage(ViewProviderDrawingPage *vp, QWidget *parent) + : QGraphicsView(parent) + , pageTemplate(0) + , m_renderer(Native) + , drawBkg(true) + , m_backgroundItem(0) + , m_outlineItem(0) + , pageGui(0) +{ + assert(vp); + pageGui = vp; + const char* name = vp->getPageObject()->getNameInDocument(); + setObjectName(QString::fromLocal8Bit(name)); + + setScene(new QGraphicsScene(this)); + //setViewportUpdateMode(QGraphicsView::FullViewportUpdate); + setCacheMode(QGraphicsView::CacheBackground); + setTransformationAnchor(AnchorUnderMouse); + + setDragMode(ScrollHandDrag); + setCursor(QCursor(Qt::ArrowCursor)); + setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); + + m_backgroundItem = new QGraphicsRectItem(); + m_backgroundItem->setCacheMode(QGI::NoCache); + m_backgroundItem->setZValue(-999999); +// scene()->addItem(m_backgroundItem); // TODO IF SEGFAULTS WITH DRAW ENABLE THIS (REDRAWS ARE SLOWER :s) + + // Prepare background check-board pattern + QLinearGradient gradient; + gradient.setStart(0, 0); + gradient.setFinalStop(0, height()); + gradient.setColorAt(0., QColor(72, 72, 72)); + gradient.setColorAt(1., QColor(150, 150, 150)); + bkgBrush = new QBrush(QColor::fromRgb(70,70,70)); + + resetCachedContent(); +} +QGVPage::~QGVPage() +{ + delete bkgBrush; + delete m_backgroundItem; +} + +void QGVPage::drawBackground(QPainter *p, const QRectF &) +{ + if(!drawBkg) + return; + + p->save(); + p->resetTransform(); + + + p->setBrush(*bkgBrush); + p->drawRect(viewport()->rect()); + + if(!pageGui) { + return; + } + + // Default to A3 landscape, though this is currently relevant + // only for opening corrupt docs, etc. + float pageWidth = 420, + pageHeight = 297; + + if ( pageGui->getPageObject()->hasValidTemplate() ) { + pageWidth = pageGui->getPageObject()->getPageWidth(); + pageHeight = pageGui->getPageObject()->getPageHeight(); + } + + // Draw the white page + QRectF paperRect(0, -pageHeight, pageWidth, pageHeight); + QPolygon poly = mapFromScene(paperRect); + + QBrush pageBrush(Qt::white); + p->setBrush(pageBrush); + + p->drawRect(poly.boundingRect()); + + p->restore(); + +} + +int QGVPage::addView(QGIView * view) { + views.push_back(view); + + // Find if it belongs to a parent + QGIView *parent = 0; + parent = findParent(view); + + QPointF viewPos(view->getViewObject()->X.getValue(), + view->getViewObject()->Y.getValue() * -1); + + if(parent) { + // Transfer the child vierw to the parent + QPointF posRef(0.,0.); + + QPointF mapPos = view->mapToItem(parent, posRef); //setPos is called later. this doesn't do anything? + view->moveBy(-mapPos.x(), -mapPos.y()); + + parent->addToGroup(view); + } + + view->setPos(viewPos); + + return views.size(); +} + +QGIView * QGVPage::addViewPart(TechDraw::DrawViewPart *part) +{ + QGIViewPart *viewPart = new QGIViewPart(QPoint(0,0), scene()); + viewPart->setViewPartFeature(part); + + addView(viewPart); + return viewPart; +} + +QGIView * QGVPage::addViewSection(TechDraw::DrawViewPart *part) +{ + QGIViewSection *viewSection = new QGIViewSection(QPoint(0,0), scene()); + viewSection->setViewPartFeature(part); + + addView(viewSection); + return viewSection; +} + +QGIView * QGVPage::addProjectionGroup(TechDraw::DrawProjGroup *view) { + QGIViewCollection *qview = new QGIProjGroup(QPoint(0,0), scene()); + qview->setViewFeature(view); + addView(qview); + return qview; +} + +QGIView * QGVPage::addDrawView(TechDraw::DrawView *view) +{ + QGIView *qview = new QGIView(QPoint(0,0), scene()); + qview->setViewFeature(view); + addView(qview); + return qview; +} + +QGIView * QGVPage::addDrawViewCollection(TechDraw::DrawViewCollection *view) +{ + QGIViewCollection *qview = new QGIViewCollection(QPoint(0,0), scene()); + qview->setViewFeature(view); + addView(qview); + return qview; +} + +// TODO change to (App?) annotation object ?? +QGIView * QGVPage::addDrawViewAnnotation(TechDraw::DrawViewAnnotation *view) +{ + // This essentially adds a null view feature to ensure view size is consistent + QGIViewAnnotation *qview = new QGIViewAnnotation(QPoint(0,0), this->scene()); + qview->setViewAnnoFeature(view); + + addView(qview); + return qview; +} + +QGIView * QGVPage::addDrawViewSymbol(TechDraw::DrawViewSymbol *view) +{ + QPoint qp(view->X.getValue(),view->Y.getValue()); + // This essentially adds a null view feature to ensure view size is consistent + QGIViewSymbol *qview = new QGIViewSymbol(qp, scene()); + qview->setViewFeature(view); + + addView(qview); + return qview; +} + +QGIView * QGVPage::addDrawViewClip(TechDraw::DrawViewClip *view) +{ + QPoint qp(view->X.getValue(),view->Y.getValue()); + QGIViewClip *qview = new QGIViewClip(qp, scene()); + qview->setViewFeature(view); + + addView(qview); + return qview; +} + +QGIView * QGVPage::addViewDimension(TechDraw::DrawViewDimension *dim) +{ + QGIViewDimension *dimGroup = new QGIViewDimension(QPoint(0,0), scene()); + dimGroup->setViewPartFeature(dim); + + // TODO consider changing dimension feature to use another property for label position + // Instead of calling addView - the view must for now be added manually + + //Note dimension X,Y is different from other views -> can't use addView + views.push_back(dimGroup); + + // Find if it belongs to a parent + QGIView *parent = 0; + parent = findParent(dimGroup); + + if(parent) { + addDimToParent(dimGroup,parent); + } + + return dimGroup; +} + +void QGVPage::addDimToParent(QGIViewDimension* dim, QGIView* parent) +{ + assert(dim); + assert(parent); //blow up if we don't have Dimension or Parent + QPointF posRef(0.,0.); + QPointF mapPos = dim->mapToItem(parent, posRef); + dim->moveBy(-mapPos.x(), -mapPos.y()); + parent->addToGroup(dim); + dim->setZValue(50.0); +} + +QGIView * QGVPage::findView(App::DocumentObject *obj) const +{ + if(scene()) { + const std::vector qviews = views; + for(std::vector::const_iterator it = qviews.begin(); it != qviews.end(); ++it) { + TechDraw::DrawView *fview = (*it)->getViewObject(); + if(fview && strcmp(obj->getNameInDocument(), fview->getNameInDocument()) == 0) + return *it; + } + } + return 0; +} + +QGIView * QGVPage::findParent(QGIView *view) const +{ + const std::vector qviews = views; + TechDraw::DrawView *myView = view->getViewObject(); + + //If type is dimension we check references first + TechDraw::DrawViewDimension *dim = 0; + dim = dynamic_cast(myView); + + if(dim) { + std::vector objs = dim->References.getValues(); + + if(objs.size() > 0) { + std::vector objs = dim->References.getValues(); + // Attach the dimension to the first object's group + for(std::vector::const_iterator it = qviews.begin(); it != qviews.end(); ++it) { + TechDraw::DrawView *viewObj = (*it)->getViewObject(); + if(strcmp(viewObj->getNameInDocument(), objs.at(0)->getNameInDocument()) == 0) { + return *it; + } + } + } + } + + // Check if part of view collection + for(std::vector::const_iterator it = qviews.begin(); it != qviews.end(); ++it) { + QGIViewCollection *grp = 0; + grp = dynamic_cast(*it); + if(grp) { + TechDraw::DrawViewCollection *collection = 0; + collection = dynamic_cast(grp->getViewObject()); + if(collection) { + std::vector objs = collection->Views.getValues(); + for( std::vector::iterator it = objs.begin(); it != objs.end(); ++it) { + if(strcmp(myView->getNameInDocument(), (*it)->getNameInDocument()) == 0) + + return grp; + } + } + } + } + + // Not found a parent + return 0; +} + +void QGVPage::setPageFeature(TechDraw::DrawPage *page) +{ + //redundant +#if 0 + // TODO verify if the pointer should even be used. Not really safe + pageFeat = page; + + float pageWidth = pageGui->getPageObject()->getPageWidth(); + float pageHeight = pageGui->getPageObject()->getPageHeight(); + + QRectF paperRect(0, -pageHeight, pageWidth, pageHeight); + + QBrush brush(Qt::white); + + m_backgroundItem->setBrush(brush); + m_backgroundItem->setRect(paperRect); + + QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(); + shadow->setBlurRadius(10.0); + shadow->setColor(Qt::white); + shadow->setOffset(0,0); + m_backgroundItem->setGraphicsEffect(shadow); + + QRectF myRect = paperRect; + myRect.adjust(-20,-20,20,20); + setSceneRect(myRect); +#endif +} + +void QGVPage::setPageTemplate(TechDraw::DrawTemplate *obj) +{ + // Remove currently set background template + // Assign a base template class and create object dependent on + removeTemplate(); + + if(obj->isDerivedFrom(TechDraw::DrawParametricTemplate::getClassTypeId())) { + //TechDraw::DrawParametricTemplate *dwgTemplate = static_cast(obj); + QGIDrawingTemplate *qTempItem = new QGIDrawingTemplate(scene()); + pageTemplate = qTempItem; + } else if(obj->isDerivedFrom(TechDraw::DrawSVGTemplate::getClassTypeId())) { + //TechDraw::DrawSVGTemplate *dwgTemplate = static_cast(obj); + QGISVGTemplate *qTempItem = new QGISVGTemplate(scene()); + pageTemplate = qTempItem; + } + pageTemplate->setTemplate(obj); + pageTemplate->updateView(); +} + +QGITemplate* QGVPage::getTemplate() const +{ + return pageTemplate; +} + +void QGVPage::removeTemplate() +{ + if(pageTemplate) { + scene()->removeItem(pageTemplate); + pageTemplate->deleteLater(); + pageTemplate = 0; + } +} +void QGVPage::setRenderer(RendererType type) +{ + m_renderer = type; + + if (m_renderer == OpenGL) { +#ifndef QT_NO_OPENGL + setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); +#endif + } else { + setViewport(new QWidget); + } +} + +void QGVPage::setHighQualityAntialiasing(bool highQualityAntialiasing) +{ +#ifndef QT_NO_OPENGL + setRenderHint(QPainter::HighQualityAntialiasing, highQualityAntialiasing); +#else + Q_UNUSED(highQualityAntialiasing); +#endif +} + +void QGVPage::setViewBackground(bool enable) +{ + if (!m_backgroundItem) + return; + + m_backgroundItem->setVisible(enable); +} + +void QGVPage::setViewOutline(bool enable) +{ + if (!m_outlineItem) + return; + + m_outlineItem->setVisible(enable); +} + +void QGVPage::toggleEdit(bool enable) +{ +// TODO: needs fiddling to handle items that don't inherit QGIViewPart: Annotation, Symbol, Templates, Edges, Faces, Vertices,... + QList list = scene()->items(); + + for (QList::iterator it = list.begin(); it != list.end(); ++it) { + QGIView *itemView = dynamic_cast(*it); + if(itemView) { + QGIViewPart *viewPart = dynamic_cast(*it); + itemView->setSelected(false); + if(viewPart) { + viewPart->toggleCache(enable); + viewPart->toggleCosmeticLines(enable); + viewPart->toggleVertices(enable); + viewPart->toggleBorder(enable); + setViewBackground(enable); + } else { + itemView->toggleBorder(enable); + } + //itemView->updateView(true); + } + + QGI *item = dynamic_cast(*it); + if(item) { + //item->setCacheMode((enable) ? QGI::DeviceCoordinateCache : QGI::NoCache); + item->setCacheMode((enable) ? QGI::NoCache : QGI::NoCache); + item->update(); + } + } + scene()->update(); + update(); + viewport()->repaint(); +} + + +void QGVPage::paintEvent(QPaintEvent *event) +{ + if (m_renderer == Image) { + if (m_image.size() != viewport()->size()) { + m_image = QImage(viewport()->size(), QImage::Format_ARGB32_Premultiplied); + } + + QPainter imagePainter(&m_image); + QGraphicsView::render(&imagePainter); + imagePainter.end(); + + QPainter p(viewport()); + p.drawImage(0, 0, m_image); + + } else { + QGraphicsView::paintEvent(event); + } +} + +void QGVPage::wheelEvent(QWheelEvent *event) +{ + qreal factor = std::pow(1.2, -event->delta() / 240.0); + scale(factor, factor); + event->accept(); +} +void QGVPage::enterEvent(QEvent *event) +{ + QGraphicsView::enterEvent(event); + viewport()->setCursor(Qt::ArrowCursor); +} + +void QGVPage::mousePressEvent(QMouseEvent *event) +{ + QGraphicsView::mousePressEvent(event); + viewport()->setCursor(Qt::ClosedHandCursor); +} + +void QGVPage::mouseReleaseEvent(QMouseEvent *event) +{ + QGraphicsView::mouseReleaseEvent(event); + viewport()->setCursor(Qt::ArrowCursor); +} + +#include "moc_QGVPage.cpp" diff --git a/src/Mod/TechDraw/Gui/QGVPage.h b/src/Mod/TechDraw/Gui/QGVPage.h new file mode 100644 index 0000000000..bca124916a --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVPage.h @@ -0,0 +1,119 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * * + * 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_CANVASVIEW_H +#define DRAWINGGUI_CANVASVIEW_H + +#include + +namespace TechDraw { +class DrawViewPart; +class DrawProjGroup; +class DrawViewDimension; +class DrawPage; +class DrawTemplate; +class DrawViewAnnotation; +class DrawViewSymbol; +class DrawViewClip; +class DrawHatch; +} + +namespace TechDrawGui +{ +class QGIView; +class QGIViewDimension; +class QGITemplate; +class QGIHatch; +class ViewProviderDrawingPage; + +class TechDrawGuiExport QGVPage : public QGraphicsView +{ + Q_OBJECT + +public: + enum RendererType { Native, OpenGL, Image }; + + QGVPage(ViewProviderDrawingPage *vp, QWidget *parent = 0); + ~QGVPage(); + + void setRenderer(RendererType type = Native); + void drawBackground(QPainter *p, const QRectF &rect); + + QGIView * addViewDimension(TechDraw::DrawViewDimension *dim); + QGIView * addProjectionGroup(TechDraw::DrawProjGroup *view); + QGIView * addViewPart(TechDraw::DrawViewPart *part); + QGIView * addViewSection(TechDraw::DrawViewPart *part); + QGIView * addDrawView(TechDraw::DrawView *view); + QGIView * addDrawViewCollection(TechDraw::DrawViewCollection *view); + QGIView * addDrawViewAnnotation(TechDraw::DrawViewAnnotation *view); + QGIView * addDrawViewSymbol(TechDraw::DrawViewSymbol *view); + QGIView * addDrawViewClip(TechDraw::DrawViewClip *view); + + QGIView * findView(App::DocumentObject *obj) const; + QGIView * findParent(QGIView *) const; + + void addDimToParent(QGIViewDimension* dim, QGIView* parent); + const std::vector & getViews() const { return views; } + int addView(QGIView * view); + void setViews(const std::vector &view) {views = view; } + void setPageFeature(TechDraw::DrawPage *page); + void setPageTemplate(TechDraw::DrawTemplate *pageTemplate); + + QGITemplate * getTemplate() const; + void removeTemplate(); + + void toggleEdit(bool enable); + + +public Q_SLOTS: + void setHighQualityAntialiasing(bool highQualityAntialiasing); + void setViewBackground(bool enable); + void setViewOutline(bool enable); + +protected: + void wheelEvent(QWheelEvent *event); + void paintEvent(QPaintEvent *event); + void enterEvent(QEvent *event); + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + + static QColor SelectColor; + static QColor PreselectColor; + + QGITemplate *pageTemplate; + std::vector views; + +private: + RendererType m_renderer; + + bool drawBkg; + TechDraw::DrawPage *pageFeat; + QGraphicsRectItem *m_backgroundItem; + QGraphicsRectItem *m_outlineItem; + QBrush *bkgBrush; + QImage m_image; + ViewProviderDrawingPage *pageGui; +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_CANVASVIEW_H diff --git a/src/Mod/TechDraw/Gui/TaskProjGroup.cpp b/src/Mod/TechDraw/Gui/TaskProjGroup.cpp new file mode 100644 index 0000000000..7e6c0125b5 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskProjGroup.cpp @@ -0,0 +1,413 @@ +/*************************************************************************** + * Copyright (c) 2014 Joe Dowsett * + * Copyright (c) 2014 Luke Parry * + * * + * 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 // #ifndef _PreComp_ + +#include + +#include +#include +#include + +#include + +#include +#include + +#include +#include + +#include "TaskProjGroup.h" +#include "ui_TaskProjGroup.h" + +using namespace Gui; +using namespace TechDrawGui; + +//TODO: Look into this, seems we might be able to delete it now? IR +#if 0 // needed for Qt's lupdate utility + qApp->translate("QObject", "Make axonometric..."); + qApp->translate("QObject", "Edit axonometric settings..."); + qApp->translate("QObject", "Make orthographic"); +#endif + + +TaskProjGroup::TaskProjGroup(TechDraw::DrawProjGroup* featView) : ui(new Ui_TaskProjGroup), + multiView(featView) +{ + ui->setupUi(this); + + blockUpdate = true; + + setFractionalScale(multiView->Scale.getValue()); + + ui->cmbScaleType->setCurrentIndex(multiView->ScaleType.getValue()); + + // Initially toggle view checkboxes if needed + setupViewCheckboxes(true); + + blockUpdate = false; + + // Rotation buttons + // Note we don't do the custom one here, as it's handled by [a different function that's held up in customs] + connect(ui->butTopRotate, SIGNAL(clicked()), this, SLOT(rotateButtonClicked(void))); + connect(ui->butCWRotate, SIGNAL(clicked()), this, SLOT(rotateButtonClicked(void))); + connect(ui->butRightRotate, SIGNAL(clicked()), this, SLOT(rotateButtonClicked(void))); + connect(ui->butDownRotate, SIGNAL(clicked()), this, SLOT(rotateButtonClicked(void))); + connect(ui->butLeftRotate, SIGNAL(clicked()), this, SLOT(rotateButtonClicked(void))); + connect(ui->butCCWRotate, SIGNAL(clicked()), this, SLOT(rotateButtonClicked(void))); + + // Slot for Scale Type + connect(ui->cmbScaleType, SIGNAL(currentIndexChanged(int)), this, SLOT(scaleTypeChanged(int))); + connect(ui->scaleNum, SIGNAL(textEdited(const QString &)), this, SLOT(scaleManuallyChanged(const QString &))); + connect(ui->scaleDenom, SIGNAL(textEdited(const QString &)), this, SLOT(scaleManuallyChanged(const QString &))); + + // Slot for Projection Type (layout) + connect(ui->projection, SIGNAL(currentIndexChanged(int)), this, SLOT(projectionTypeChanged(int))); +} + +TaskProjGroup::~TaskProjGroup() +{ + delete ui; +} + +void TaskProjGroup::viewToggled(bool toggle) +{ + // Obtain name of checkbox + QString viewName = sender()->objectName(); + int index = viewName.mid(7).toInt(); + const char *viewNameCStr = viewChkIndexToCStr(index); + + //Gui::Command::openCommand("Toggle orthographic view"); //TODO: Is this for undo? + + if ( toggle && !multiView->hasProjection( viewNameCStr ) ) { + multiView->addProjection( viewNameCStr ); + } else if ( !toggle && multiView->hasProjection( viewNameCStr ) ) { + multiView->removeProjection( viewNameCStr ); + } + + /// Called to notify the GUI that the scale has changed + Gui::Command::commitCommand(); + Gui::Command::updateActive(); +} + +void TaskProjGroup::rotateButtonClicked(void) +{ + if ( multiView && ui ) { + const QObject *clicked = sender(); + + // Any translation/scale/etc applied here will be ignored, as + // DrawProjGroup::setFrontViewOrientation() only + // uses it to set Direction and XAxisDirection. + Base::Matrix4D m = multiView->viewOrientationMatrix.getValue(); + + // TODO: Construct these directly + Base::Matrix4D t; + + //TODO: Consider changing the vectors around depending on whether we're in First or Third angle mode - might be more intuitive? IR + if ( clicked == ui->butTopRotate ) { + t.rotX(M_PI / -2); + } else if ( clicked == ui->butCWRotate ) { + t.rotY(M_PI / -2); + } else if ( clicked == ui->butRightRotate) { + t.rotZ(M_PI / 2); + } else if ( clicked == ui->butDownRotate) { + t.rotX(M_PI / 2); + } else if ( clicked == ui->butLeftRotate) { + t.rotZ(M_PI / -2); + } else if ( clicked == ui->butCCWRotate) { + t.rotY(M_PI / 2); + } + m *= t; + + multiView->setFrontViewOrientation(m); + Gui::Command::updateActive(); + } +} + +void TaskProjGroup::projectionTypeChanged(int index) +{ + if(blockUpdate) + return; + + Gui::Command::openCommand("Update projection type"); + if(index == 0) { + //layout per Page (Document) + Gui::Command::doCommand(Gui::Command::Doc, + "App.activeDocument().%s.ProjectionType = '%s'", + multiView->getNameInDocument(), "Document"); + } else if(index == 1) { + // First Angle layout + Gui::Command::doCommand(Gui::Command::Doc, + "App.activeDocument().%s.ProjectionType = '%s'", + multiView->getNameInDocument(), "First Angle"); + } else if(index == 2) { + // Third Angle layout + Gui::Command::doCommand(Gui::Command::Doc, + "App.activeDocument().%s.ProjectionType = '%s'", + multiView->getNameInDocument(), "Third Angle"); + } else { + Gui::Command::abortCommand(); + Base::Console().Log("Error - TaskProjGroup::projectionTypeChanged - unknown projection layout: %d\n", + index); + return; + } + + // Update checkboxes so checked state matches the drawing + setupViewCheckboxes(); + + Gui::Command::commitCommand(); + Gui::Command::updateActive(); +} + +void TaskProjGroup::scaleTypeChanged(int index) +{ + if(blockUpdate) + return; + + Gui::Command::openCommand("Update projection scale type"); + if(index == 0) { + //Automatic Scale Type + Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.ScaleType = '%s'", multiView->getNameInDocument() + , "Document"); + } else if(index == 1) { + // Document Scale Type + Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.ScaleType = '%s'", multiView->getNameInDocument() + , "Automatic"); + } else if(index == 2) { + // Custom Scale Type + Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.ScaleType = '%s'", multiView->getNameInDocument() + , "Custom"); + } else { + Gui::Command::abortCommand(); + Base::Console().Log("Error - TaskProjGroup::scaleTypeChanged - unknown scale type: %d\n",index); + return; + } + Gui::Command::commitCommand(); + Gui::Command::updateActive(); +} + +// ** David Eppstein / UC Irvine / 8 Aug 1993 +// Reworked 2015 IR to add the power of logarithms! +void TaskProjGroup::nearestFraction(double val, int &n, int &d) const +{ + int exponent = std::floor(std::log10(val)); + if (exponent > 1 || exponent < -1) { + val *= std::pow(10, -exponent); + } + + n = 1; // numerator + d = 1; // denominator + double fraction = n / d; + //double m = fabs(fraction - val); + + while (fabs(fraction - val) > 0.001) { + if (fraction < val) { + ++n; + } else { + ++d; + n = (int) round(val * d); + } + fraction = n / (double) d; + } + + if (exponent > 1) { + n *= std::pow(10, exponent); + } else if (exponent < -1) { + d *= std::pow(10, -exponent); + } +} + +void TaskProjGroup::updateTask() +{ + // Update the scale type + blockUpdate = true; + ui->cmbScaleType->setCurrentIndex(multiView->ScaleType.getValue()); + + // Update the scale value + setFractionalScale(multiView->Scale.getValue()); + + blockUpdate = false; +} + + +void TaskProjGroup::setFractionalScale(double newScale) +{ + blockUpdate = true; + int num, den; + + nearestFraction(newScale, num, den); + + ui->scaleNum->setText(QString::number(num)); + ui->scaleDenom->setText(QString::number(den)); + blockUpdate = false; +} + +void TaskProjGroup::scaleManuallyChanged(const QString & text) +{ + //TODO: See what this is about - shouldn't be simplifying the scale ratio while it's being edited... IR + if(blockUpdate) + return; + + bool ok1, ok2; + + int a = ui->scaleNum->text().toInt(&ok1); + int b = ui->scaleDenom->text().toInt(&ok2); + + double scale = (double) a / (double) b; + if (ok1 && ok2) { + // If we were not in Custom, switch to Custom in two steps + bool switchToCustom = (strcmp(multiView->ScaleType.getValueAsString(), "Custom") != 0); + if(switchToCustom) { + // First, send out command to put us into custom scale + scaleTypeChanged(ui->cmbScaleType->findText(QString::fromLatin1("Custom"))); + switchToCustom = true; + } + + Gui::Command::openCommand("Update custom scale"); + Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.Scale = %f", multiView->getNameInDocument() + , scale); + Gui::Command::commitCommand(); + Gui::Command::updateActive(); + + if(switchToCustom) { + // Second, update the GUI + ui->cmbScaleType->setCurrentIndex(ui->cmbScaleType->findText(QString::fromLatin1("Custom"))); + } + } +} + +void TaskProjGroup::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(this); + } +} + +const char * TaskProjGroup::viewChkIndexToCStr(int index) +{ + // Third Angle: FTL T FTRight + // L F Right Rear + // FBL B FBRight + // + // First Angle: FBRight B FBL + // Right F L Rear + // FTRight T FTL + assert (multiView != NULL); + + bool thirdAngle = multiView->usedProjectionType().isValue("Third Angle"); + switch(index) { + case 0: return (thirdAngle ? "FrontTopLeft" : "FrontBottomRight"); + case 1: return (thirdAngle ? "Top" : "Bottom"); + case 2: return (thirdAngle ? "FrontTopRight" : "FrontBottomLeft"); + case 3: return (thirdAngle ? "Left" : "Right"); + case 4: return (thirdAngle ? "Front" : "Front"); + case 5: return (thirdAngle ? "Right" : "Left"); + case 6: return (thirdAngle ? "Rear" : "Rear"); + case 7: return (thirdAngle ? "FrontBottomLeft" : "FrontTopRight"); + case 8: return (thirdAngle ? "Bottom" : "Top"); + case 9: return (thirdAngle ? "FrontBottomRight" : "FrontTopLeft"); + default: return NULL; + } +} +void TaskProjGroup::setupViewCheckboxes(bool addConnections) +{ + if ( multiView == NULL ) { + return; + } + + // There must be a better way to construct this list... + QCheckBox * viewCheckboxes[] = { ui->chkView0, + ui->chkView1, + ui->chkView2, + ui->chkView3, + ui->chkView4, + ui->chkView5, + ui->chkView6, + ui->chkView7, + ui->chkView8, + ui->chkView9 }; + + + for (int i = 0; i < 10; ++i) { + QCheckBox *box = viewCheckboxes[i]; + if (addConnections) { + connect(box, SIGNAL(toggled(bool)), this, SLOT(viewToggled(bool))); + } + + const char *viewStr = viewChkIndexToCStr(i); + if ( viewStr != NULL && multiView->hasProjection(viewStr) ) { + box->setCheckState(Qt::Checked); + } else { + box->setCheckState(Qt::Unchecked); + } + } +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//TODO: Do we really need to hang on to the TaskDlgProjGroup in this class? IR +TaskDlgProjGroup::TaskDlgProjGroup(TechDraw::DrawProjGroup* featView) : TaskDialog(), + multiView(featView) +{ + viewProvider = dynamic_cast(featView); + widget = new TaskProjGroup(featView); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-projgroup"), + widget->windowTitle(), true, 0); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); +} + +TaskDlgProjGroup::~TaskDlgProjGroup() +{ +} + +void TaskDlgProjGroup::update() +{ + widget->updateTask(); +} + +//==== calls from the TaskView =============================================================== +void TaskDlgProjGroup::open() +{ +} + +void TaskDlgProjGroup::clicked(int) +{ +} + +bool TaskDlgProjGroup::accept() +{ + return true;//!widget->user_input(); +} + +bool TaskDlgProjGroup::reject() +{ + return true; +} + + +#include "moc_TaskProjGroup.cpp" + diff --git a/src/Mod/TechDraw/Gui/TaskProjGroup.h b/src/Mod/TechDraw/Gui/TaskProjGroup.h new file mode 100644 index 0000000000..68d72a8ee5 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskProjGroup.h @@ -0,0 +1,137 @@ +/*************************************************************************** + * Copyright (c) 2011 Joe Dowsett * + * Copyright (c) 2014 Luke Parry * + * * + * 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 GUI_TASKVIEW_TASKVIEWGROUP_H +#define GUI_TASKVIEW_TASKVIEWGROUP_H + +#include +#include +#include + +#include "ui_TaskProjGroup.h" + +#include "ViewProviderProjGroup.h" +#include "../App/DrawProjGroup.h" + + +class Ui_TaskProjGroup; + +namespace App { + class Document; + class DocumentObject; +} + +namespace TechDraw { + class DrawViewPart; + class DrawProjGroup; +} + +namespace TechDrawGui +{ + +class TaskProjGroup : public QWidget +{ + Q_OBJECT + +public: + TaskProjGroup(TechDraw::DrawProjGroup* featView); + ~TaskProjGroup(); + +public: + void updateTask(); + void nearestFraction(double val, int &a, int &b) const; + /// Sets the numerator and denominator widgets to match newScale + void setFractionalScale(double newScale); + +protected Q_SLOTS: + void viewToggled(bool toggle); + + /// Requests appropriate rotation of our DrawProjGroup + void rotateButtonClicked(void); + + void projectionTypeChanged(int index); + void scaleTypeChanged(int index); + void scaleManuallyChanged(const QString & text); + +protected: + void changeEvent(QEvent *e); + + /// Connects and updates state of view checkboxes to match the state of multiView + /*! + * If addConnections is true, then also sets up Qt connections + * between checkboxes and viewToggled() + */ + void setupViewCheckboxes(bool addConnections = false); + +private: + //class Private; + Ui_TaskProjGroup * ui; + bool blockUpdate; + /// Translate a view checkbox index into represented view string, depending on projection type + const char * viewChkIndexToCStr(int index); + +protected: + ViewProviderProjGroup *viewProvider; + TechDraw::DrawProjGroup* multiView; +}; + +/// Simulation dialog for the TaskView +class TaskDlgProjGroup : public Gui::TaskView::TaskDialog +{ + Q_OBJECT + +public: + TaskDlgProjGroup(TechDraw::DrawProjGroup* featView); + ~TaskDlgProjGroup(); + + const ViewProviderProjGroup * getViewProvider() const { return viewProvider; } + TechDraw::DrawProjGroup * getMultiView() const { return multiView; } +public: + /// is called the TaskView when the dialog is opened + virtual void open(); + /// is called by the framework if an button is clicked which has no accept or reject role + virtual void clicked(int); + /// is called by the framework if the dialog is accepted (Ok) + virtual bool accept(); + /// is called by the framework if the dialog is rejected (Cancel) + virtual bool reject(); + /// is called by the framework if the user presses the help button + virtual void helpRequested() { return;} + virtual bool isAllowedAlterDocument(void) const + { return false; } + + void update(); + +protected: + const ViewProviderProjGroup *viewProvider; + TechDraw::DrawProjGroup *multiView; + +private: + TaskProjGroup * widget; + Gui::TaskView::TaskBox* taskbox; +}; + +} //namespace TechDrawGui + +#endif // #ifndef GUI_TASKVIEW_TASKVIEWGROUP_H + diff --git a/src/Mod/TechDraw/Gui/TaskProjGroup.ui b/src/Mod/TechDraw/Gui/TaskProjGroup.ui new file mode 100644 index 0000000000..a9b023b4ad --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskProjGroup.ui @@ -0,0 +1,362 @@ + + + TechDrawGui::TaskProjGroup + + + + 0 + 0 + 342 + 431 + + + + + 0 + 0 + + + + + 250 + 0 + + + + Projection Group + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + QLayout::SetDefaultConstraint + + + + + + + Projection + + + + + + + false + + + + Document + + + + + First Angle + + + + + Third Angle + + + + + + + + + + + + Scale + + + + + + + + Document + + + + + Automatic + + + + + Custom + + + + + + + + + + + + Custom Scale + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + + + + : + + + + + + + + + + + + Qt::Horizontal + + + + + + + + + View From + + + Qt::AlignBottom|Qt::AlignHCenter + + + + + + + + + + + Spin CW + + + + + + + > + + + + + + + Spin CCW + + + + + + + /\ + + + + + + + false + + + Match 3D + + + + + + + < + + + + + + + \/ + + + + + + + + + + + Secondary Projections + + + + + + + + + + + true + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + + + + true + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/TemplateTextField.cpp b/src/Mod/TechDraw/Gui/TemplateTextField.cpp new file mode 100644 index 0000000000..6351783fdc --- /dev/null +++ b/src/Mod/TechDraw/Gui/TemplateTextField.cpp @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (c) Ian Rees (ian.rees@gmail.com) 2015 * + * * + * 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 +#endif // #ifndef _PreCmp_ + +#include "TemplateTextField.h" + +//#include + +using namespace TechDrawGui; + +TemplateTextField::TemplateTextField(QGI *parent, + TechDraw::DrawTemplate *myTmplte, + const std::string &myFieldName) + : QGraphicsRectItem(parent), tmplte(myTmplte), fieldNameStr(myFieldName) +{ +} + + +TemplateTextField::~TemplateTextField() +{ +} + +void TemplateTextField::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + //TODO: Add a command to change template text, and call it from here + bool ok; + QString curStr = QString::fromUtf8(tmplte->EditableTexts[fieldNameStr].c_str()); + QString newStr = QInputDialog::getText(NULL, QObject::tr("Change template text"), + QObject::tr("Enter a new value for ") + + QString::fromUtf8(fieldNameStr.c_str()), + QLineEdit::Normal, curStr, &ok); + if (ok && !newStr.isEmpty()) { + tmplte->EditableTexts.setValue(fieldNameStr, newStr.toUtf8().constData()); + } +} + diff --git a/src/Mod/TechDraw/Gui/TemplateTextField.h b/src/Mod/TechDraw/Gui/TemplateTextField.h new file mode 100644 index 0000000000..977c09914b --- /dev/null +++ b/src/Mod/TechDraw/Gui/TemplateTextField.h @@ -0,0 +1,64 @@ +/*************************************************************************** + * Copyright (c) Ian Rees (ian.rees@gmail.com) 2015 * + * * + * 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_TEMPLATETEXTFIELD_H +#define DRAWINGGUI_TEMPLATETEXTFIELD_H + +//TODO Precompiled header + +#include + +#include "../App/DrawTemplate.h" + +QT_BEGIN_NAMESPACE +class QGI; +QT_END_NAMESPACE + +namespace TechDrawGui +{ + /// QGraphicsRectItem-derived class for the text fields in title blocks + /*! + * This essentially just a way for us to make a rectangular area which + * will give us a text editing dialog when clicked so that an appropriate + * Property in the Drawing's template can be modified. + * Dear English, I'm sorry. + */ + class TechDrawGuiExport TemplateTextField : public QGraphicsRectItem + { + public: + TemplateTextField(QGI *parent, + TechDraw::DrawTemplate *myTmplte, + const std::string &myFieldName); + + ~TemplateTextField(); + + /// Returns the field name that this TemplateTextField represents + std::string fieldName() const { return fieldNameStr; } + protected: + virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); + TechDraw::DrawTemplate *tmplte; + std::string fieldNameStr; + }; +} // namespace TechDrawGui + +#endif // #ifndef DRAWINGGUI_TEMPLATETEXTFIELD_H + diff --git a/src/Mod/TechDraw/Gui/ViewProviderAnnotation.cpp b/src/Mod/TechDraw/Gui/ViewProviderAnnotation.cpp new file mode 100644 index 0000000000..06f6e00db2 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderAnnotation.cpp @@ -0,0 +1,86 @@ +/*************************************************************************** + * Copyright (c) 2004 Jürgen Riegel * + * Copyright (c) 2012 Luke Parry * + * * + * 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 "ViewProviderAnnotation.h" + +using namespace TechDrawGui; + +PROPERTY_SOURCE(TechDrawGui::ViewProviderAnnotation, Gui::ViewProviderDocumentObject) + +//************************************************************************** +// Construction/Destruction + +ViewProviderAnnotation::ViewProviderAnnotation() +{ + sPixmap = "Annotation"; +} + +ViewProviderAnnotation::~ViewProviderAnnotation() +{ +} + +void ViewProviderAnnotation::attach(App::DocumentObject *pcFeat) +{ + // call parent attach method + ViewProviderDocumentObject::attach(pcFeat); +} + +void ViewProviderAnnotation::setDisplayMode(const char* ModeName) +{ + ViewProviderDocumentObject::setDisplayMode(ModeName); +} + +std::vector ViewProviderAnnotation::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList = ViewProviderDocumentObject::getDisplayModes(); + + return StrList; +} + +void ViewProviderAnnotation::updateData(const App::Property*) +{ +} + +TechDraw::DrawViewAnnotation* ViewProviderAnnotation::getViewObject() const +{ + return dynamic_cast(pcObject); +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderAnnotation.h b/src/Mod/TechDraw/Gui/ViewProviderAnnotation.h new file mode 100644 index 0000000000..7527159ff1 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderAnnotation.h @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (c) 2004 Jürgen Riegel * + * Copyright (c) 2012 Luke Parry * + * * + * 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_VIEWPROVIDERANNOTATION_H +#define DRAWINGGUI_VIEWPROVIDERANNOTATION_H + +#include + +namespace TechDraw{ + class DrawViewAnnotation; +} + +namespace TechDrawGui { + + +class TechDrawGuiExport ViewProviderAnnotation : public Gui::ViewProviderDocumentObject +{ + PROPERTY_HEADER(TechDrawGui::ViewProviderAnnotation); + +public: + /// constructor + ViewProviderAnnotation(); + /// destructor + virtual ~ViewProviderAnnotation(); + + + 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::DrawViewAnnotation* getViewObject() const; +}; + +} // namespace TechDrawGui + + +#endif // DRAWINGGUI_VIEWPROVIDERANNOTATION_H diff --git a/src/Mod/TechDraw/Gui/ViewProviderDimension.cpp b/src/Mod/TechDraw/Gui/ViewProviderDimension.cpp new file mode 100644 index 0000000000..39e86ed649 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderDimension.cpp @@ -0,0 +1,86 @@ +/*************************************************************************** + * Copyright (c) 2004 Jürgen Riegel * + * Copyright (c) 2012 Luke Parry * + * * + * 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 "ViewProviderDimension.h" + +using namespace TechDrawGui; + +PROPERTY_SOURCE(TechDrawGui::ViewProviderDimension, TechDrawGui::ViewProviderView) + +//************************************************************************** +// Construction/Destruction + +ViewProviderDimension::ViewProviderDimension() +{ + sPixmap = "Dimension"; +} + +ViewProviderDimension::~ViewProviderDimension() +{ +} + +void ViewProviderDimension::attach(App::DocumentObject *pcFeat) +{ + // call parent attach method + ViewProviderView::attach(pcFeat); +} + +void ViewProviderDimension::setDisplayMode(const char* ModeName) +{ + ViewProviderView::setDisplayMode(ModeName); +} + +std::vector ViewProviderDimension::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList = ViewProviderView::getDisplayModes(); + + return StrList; +} + +void ViewProviderDimension::updateData(const App::Property*) +{ +} + +TechDraw::DrawViewDimension* ViewProviderDimension::getViewObject() const +{ + return dynamic_cast(pcObject); +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderDimension.h b/src/Mod/TechDraw/Gui/ViewProviderDimension.h new file mode 100644 index 0000000000..cd10419451 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderDimension.h @@ -0,0 +1,62 @@ +/*************************************************************************** + * Copyright (c) 2004 Jürgen Riegel * + * Copyright (c) 2012 Luke Parry * + * * + * 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_VIEWPROVIDERDIMENSION_H +#define DRAWINGGUI_VIEWPROVIDERDIMENSION_H + +#include +#include "ViewProviderView.h" + +namespace TechDraw{ + class DrawViewDimension; +} + +namespace TechDrawGui { + + +class TechDrawGuiExport ViewProviderDimension : public ViewProviderView +{ + PROPERTY_HEADER(TechDrawGui::ViewProviderDimension); + +public: + /// constructor + ViewProviderDimension(); + /// destructor + virtual ~ViewProviderDimension(); + + + 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::DrawViewDimension* getViewObject() const; +}; + +} // namespace TechDrawGui + + +#endif // DRAWINGGUI_VIEWPROVIDERDIMENSION_H diff --git a/src/Mod/TechDraw/Gui/ViewProviderHatch.cpp b/src/Mod/TechDraw/Gui/ViewProviderHatch.cpp new file mode 100644 index 0000000000..73d76f0992 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderHatch.cpp @@ -0,0 +1,86 @@ +/*************************************************************************** + * Copyright (c) 2004 Jürgen Riegel * + * Copyright (c) 2015 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 "ViewProviderHatch.h" + +using namespace TechDrawGui; + +PROPERTY_SOURCE(TechDrawGui::ViewProviderHatch, Gui::ViewProviderDocumentObject) + +//************************************************************************** +// Construction/Destruction + +ViewProviderHatch::ViewProviderHatch() +{ + sPixmap = "Hatch"; +} + +ViewProviderHatch::~ViewProviderHatch() +{ +} + +void ViewProviderHatch::attach(App::DocumentObject *pcFeat) +{ + // call parent attach method + ViewProviderDocumentObject::attach(pcFeat); +} + +void ViewProviderHatch::setDisplayMode(const char* ModeName) +{ + ViewProviderDocumentObject::setDisplayMode(ModeName); +} + +std::vector ViewProviderHatch::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList = ViewProviderDocumentObject::getDisplayModes(); + + return StrList; +} + +void ViewProviderHatch::updateData(const App::Property*) +{ +} + +TechDraw::DrawHatch* ViewProviderHatch::getViewObject() const +{ + return dynamic_cast(pcObject); +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderHatch.h b/src/Mod/TechDraw/Gui/ViewProviderHatch.h new file mode 100644 index 0000000000..324b12a215 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderHatch.h @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (c) 2004 Jürgen Riegel * + * Copyright (c) 2015 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_VIEWPROVIDERHATCH_H +#define DRAWINGGUI_VIEWPROVIDERHATCH_H + +#include + +namespace TechDraw{ + class DrawHatch; +} + +namespace TechDrawGui { + + +class TechDrawGuiExport ViewProviderHatch : public Gui::ViewProviderDocumentObject +{ + PROPERTY_HEADER(TechDrawGui::ViewProviderHatch); + +public: + /// constructor + ViewProviderHatch(); + /// destructor + virtual ~ViewProviderHatch(); + + + 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::DrawHatch* getViewObject() const; +}; + +} // namespace TechDrawGui + + +#endif // DRAWINGGUI_VIEWPROVIDERHATCH_H diff --git a/src/Mod/TechDraw/Gui/ViewProviderPage.cpp b/src/Mod/TechDraw/Gui/ViewProviderPage.cpp new file mode 100644 index 0000000000..fadda1be98 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderPage.cpp @@ -0,0 +1,345 @@ +/*************************************************************************** + * Copyright (c) 2004 Jürgen Riegel * + * Copyright (c) 2012 Luke Parry * + * * + * 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 +#endif + +/// Here the FreeCAD includes sorted by Base,App,Gui...... +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include "MDIViewPage.h" +#include "ViewProviderPage.h" +#include +#include +#include +#include +#include +#include + +using namespace TechDrawGui; + +PROPERTY_SOURCE(TechDrawGui::ViewProviderDrawingPage, Gui::ViewProviderDocumentObject) + + +//************************************************************************** +// Construction/Destruction + +ViewProviderDrawingPage::ViewProviderDrawingPage() + : view(0), + restoreState(false) +{ + sPixmap = "Page"; + +// ADD_PROPERTY(HintScale,(10.0)); +// ADD_PROPERTY(HintOffsetX,(10.0)); +// ADD_PROPERTY(HintOffsetY,(10.0)); + + // do not show this in the property editor + Visibility.StatusBits.set(3, true); + DisplayMode.StatusBits.set(3, true); +} + +ViewProviderDrawingPage::~ViewProviderDrawingPage() +{ +} + +void ViewProviderDrawingPage::attach(App::DocumentObject *pcFeat) +{ + ViewProviderDocumentObject::attach(pcFeat); +} + +void ViewProviderDrawingPage::setDisplayMode(const char* ModeName) +{ + ViewProviderDocumentObject::setDisplayMode(ModeName); +} + +std::vector ViewProviderDrawingPage::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList = ViewProviderDocumentObject::getDisplayModes(); + StrList.push_back("Drawing"); + return StrList; +} + +void ViewProviderDrawingPage::show(void) +{ + showMDIViewPage(); +} + +void ViewProviderDrawingPage::hide(void) +{ + // hiding the drawing page should not affect its children but closes the MDI view + // therefore do not call the method of its direct base class + ViewProviderDocumentObject::hide(); + if (view) { + view->parentWidget()->deleteLater(); + } +} + +void ViewProviderDrawingPage::updateData(const App::Property* prop) +{ + if (prop == &(getPageObject()->Views)) { + if(view) { + view->updateDrawing(); + } + } else if (prop == &(getPageObject()->Template)) { + if(view) { + view->updateTemplate(); + } + } + + Gui::ViewProviderDocumentObject::updateData(prop); +} + +bool ViewProviderDrawingPage::onDelete(const std::vector &items) +{ + if (!view.isNull()) { + // TODO: if DrawingPage has children, they should be deleted too, since they are useless without the page. + // logic is in the "this object has links are you sure" dialog + Gui::getMainWindow()->removeWindow(view); + Gui::getMainWindow()->activatePreviousWindow(); + view->deleteLater(); // Delete the drawing view; + } else { + // MDIViewPage is not displayed yet so don't try to delete it! + Base::Console().Log("INFO - ViewProviderDrawingPage::onDelete - Page object deleted when viewer not displayed\n"); + } + Gui::Selection().clearSelection(); + return ViewProviderDocumentObject::onDelete(items); +} + +void ViewProviderDrawingPage::setupContextMenu(QMenu* menu, QObject* receiver, const char* member) +{ + Gui::ViewProviderDocumentObject::setupContextMenu(menu, receiver, member); + QAction* act = menu->addAction(QObject::tr("Show drawing"), receiver, member); +// act->setData(QVariant(1)); // Removed to resolve compile after cb16fec6bb67cec15be3fc2aeb251ab524134073 //this is edit ModNum + act->setData(QVariant((int) ViewProvider::Default)); +} + +bool ViewProviderDrawingPage::setEdit(int ModNum) +{ + if (ModNum == ViewProvider::Default) { + showMDIViewPage(); // show the drawing + Gui::getMainWindow()->setActiveWindow(view); + return false; + } else { + Gui::ViewProviderDocumentObject::setEdit(ModNum); + } + return true; +} + +bool ViewProviderDrawingPage::doubleClicked(void) +{ + showMDIViewPage(); + Gui::getMainWindow()->setActiveWindow(view); + return true; +} + +bool ViewProviderDrawingPage::showMDIViewPage() +{ + if (isRestoring()) { + return true; + } + + if (view.isNull()){ + Gui::Document* doc = Gui::Application::Instance->getDocument + (pcObject->getDocument()); + view = new MDIViewPage(this, doc, Gui::getMainWindow()); + view->setWindowTitle(QObject::tr("Drawing viewer") + QString::fromAscii("[*]")); + view->setWindowIcon(Gui::BitmapFactory().pixmap("actions/techdraw-landscape")); + view->updateDrawing(true); + // view->updateTemplate(true); //TODO: I don't think this is necessary? Ends up triggering a reload of SVG template, but the MDIViewPage constructor does too. + Gui::getMainWindow()->addWindow(view); + view->viewAll(); + } else { + view->updateDrawing(true); + view->updateTemplate(true); + } + return true; +} + +std::vector ViewProviderDrawingPage::claimChildren(void) const +{ + std::vector temp; + + // Attach the template if it exists + App::DocumentObject *templateFeat = 0; + templateFeat = getPageObject()->Template.getValue(); + + if(templateFeat) { + temp.push_back(templateFeat); + } + + // Collect any child views + // for Page, valid children are any View except: DrawProjGroupItem + // DrawViewDimension + // any FeatuerView in a DrawViewClip + // DrawHatch + + const std::vector &views = getPageObject()->Views.getValues(); + + try { + for(std::vector::const_iterator it = views.begin(); it != views.end(); ++it) { + TechDraw::DrawView* featView = dynamic_cast (*it); + App::DocumentObject *docObj = *it; + // Don't collect if dimension, projection group item, hatch or member of ClipGroup as these should be grouped elsewhere + if(docObj->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId()) || + docObj->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId()) || + docObj->isDerivedFrom(TechDraw::DrawHatch::getClassTypeId()) || + (featView && featView->isInClip()) ) + continue; + else + temp.push_back(*it); + } + return temp; + } catch (...) { + std::vector tmp; + return tmp; + } +} + +void ViewProviderDrawingPage::unsetEdit(int ModNum) +{ + static_cast(showMDIViewPage()); + return; +} + + +MDIViewPage* ViewProviderDrawingPage::getMDIViewPage() +{ + if (view.isNull()) { + Base::Console().Log("INFO - ViewProviderDrawingPage::getMDIViewPage has no view!\n"); + return 0; + } else { + return view; + } +} + +void ViewProviderDrawingPage::onSelectionChanged(const Gui::SelectionChanges& msg) +{ + if(!view.isNull()) { + if(msg.Type == Gui::SelectionChanges::SetSelection) { + view->clearSelection(); + std::vector objs = Gui::Selection().getSelection(msg.pDocName); + + for (std::vector::iterator it = objs.begin(); it != objs.end(); ++it) { + Gui::SelectionSingleton::SelObj selObj = *it; + + if(selObj.pObject == getPageObject()) + continue; + + std::string str = msg.pSubName; + // If it's a subfeature, dont select feature + if (!str.empty()) { + if (DrawUtil::getGeomTypeFromName(str) == "Edge" || + DrawUtil::getGeomTypeFromName(str) == "Vertex") { + //TODO: handle Faces + // TODO implement me + } else { + view->selectFeature(selObj.pObject, true); + } + } + + } + } else { + bool selectState = (msg.Type == Gui::SelectionChanges::AddSelection) ? true : false; + Gui::Document* doc = Gui::Application::Instance->getDocument(pcObject->getDocument()); + App::DocumentObject *obj = doc->getDocument()->getObject(msg.pObjectName); + if(obj) { + + std::string str = msg.pSubName; + // If it's a subfeature, dont select feature + if (!str.empty()) { + if (DrawUtil::getGeomTypeFromName(str) == "Edge" || + DrawUtil::getGeomTypeFromName(str) == "Vertex") { + // TODO implement me + } else { + view->selectFeature(obj, selectState); + } + } + } + } + } +} + +void ViewProviderDrawingPage::onChanged(const App::Property *prop) +{ + if (prop == &(getPageObject()->Views)) { + if(view) { + view->updateDrawing(); + } + } else if (prop == &(getPageObject()->Template)) { + if(view) { + view->updateTemplate(); + } + } + + Gui::ViewProviderDocumentObject::onChanged(prop); +} + +void ViewProviderDrawingPage::startRestoring() +{ + restoreState = true; + Gui::ViewProviderDocumentObject::startRestoring(); +} + +void ViewProviderDrawingPage::finishRestoring() +{ + restoreState = false; + static_cast(showMDIViewPage()); + Gui::ViewProviderDocumentObject::finishRestoring(); +} + + +TechDraw::DrawPage* ViewProviderDrawingPage::getPageObject() const +{ + return dynamic_cast(pcObject); +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderPage.h b/src/Mod/TechDraw/Gui/ViewProviderPage.h new file mode 100644 index 0000000000..c72cd72204 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderPage.h @@ -0,0 +1,104 @@ +/*************************************************************************** + * Copyright (c) 2004 Jürgen Riegel * + * Copyright (c) 2012 Luke Parry * + * * + * 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_VIEWPROVIDERPAGE_H +#define DRAWINGGUI_VIEWPROVIDERPAGE_H + +#include +#include +#include +#include + +#include "MDIViewPage.h" + +namespace TechDraw{ + class DrawPage; +} + +namespace Gui { //TODO: Inventor here?? + class SoFCSelection; +} + +namespace TechDrawGui { + +class MDIViewPage; + +class TechDrawGuiExport ViewProviderDrawingPage : public Gui::ViewProviderDocumentObject, + public Gui::SelectionObserver +{ + PROPERTY_HEADER(TechDrawGui::ViewProviderDrawingPage); + +public: + /// constructor + ViewProviderDrawingPage(); + /// destructor + virtual ~ViewProviderDrawingPage(); + + //App::PropertyFloat HintScale; + //App::PropertyFloat HintOffsetX; + //App::PropertyFloat HintOffsetY; + + 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; + /// Hides the view provider + virtual void hide(void); + /// Shows the view provider + virtual void show(void); + + void onSelectionChanged(const Gui::SelectionChanges& msg); + + /// Claim all the views for the page + std::vector claimChildren(void) const; + + /// Is called by the tree if the user double click on the object + virtual bool doubleClicked(void); + void setupContextMenu(QMenu*, QObject*, const char*); + virtual bool onDelete(const std::vector &); + virtual void onChanged(const App::Property *prop); + virtual void updateData(const App::Property* prop); + virtual void startRestoring(); + virtual void finishRestoring(); + bool isRestoring(void) {return restoreState;} + + TechDraw::DrawPage* getPageObject() const; + void unsetEdit(int ModNum); + MDIViewPage* getMDIViewPage(); + +protected: + bool setEdit(int ModNum); + bool showMDIViewPage(); + +private: + QPointer view; + bool restoreState; +}; + +} // namespace TechDrawGui + + +#endif // DRAWINGGUI_VIEWPROVIDERPAGE_H + diff --git a/src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp b/src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp new file mode 100644 index 0000000000..32703e64c3 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp @@ -0,0 +1,172 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * * + * 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_ +# ifdef FC_OS_WIN32 +# include +# endif +# include +# include +#endif + +/// Here the FreeCAD includes sorted by Base,App,Gui...... +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "TaskProjGroup.h" +#include "ViewProviderProjGroup.h" + +using namespace TechDrawGui; + +PROPERTY_SOURCE(TechDrawGui::ViewProviderProjGroup, Gui::ViewProviderDocumentObject) + +//************************************************************************** +// Construction/Destruction + +ViewProviderProjGroup::ViewProviderProjGroup() +{ + sPixmap = "ProjGroup"; +} + +ViewProviderProjGroup::~ViewProviderProjGroup() +{ +} + +void ViewProviderProjGroup::attach(App::DocumentObject *pcFeat) +{ + // call parent attach method + ViewProviderDocumentObject::attach(pcFeat); +} + +void ViewProviderProjGroup::setDisplayMode(const char* ModeName) +{ + ViewProviderDocumentObject::setDisplayMode(ModeName); +} + +std::vector ViewProviderProjGroup::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList = ViewProviderDocumentObject::getDisplayModes(); + StrList.push_back("Drawing"); + return StrList; +} + +void ViewProviderProjGroup::updateData(const App::Property* prop) +{ + Gui::ViewProviderDocumentObject::updateData(prop); + + if(prop == &(getObject()->Scale) || + prop == &(getObject()->ScaleType) || + prop == &(getObject()->Views) || + prop == &(getObject()->ProjectionType)) { + + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + TaskDlgProjGroup *projDlg = qobject_cast(dlg); + + if (projDlg && + projDlg->getViewProvider() == dynamic_cast(getObject()) ) { + projDlg->update(); + } + } + + } + + +void ViewProviderProjGroup::setupContextMenu(QMenu* menu, QObject* receiver, const char* member) +{ + //QAction* act; + //act = menu->addAction(QObject::tr("Show drawing"), receiver, member); +} + +bool ViewProviderProjGroup::setEdit(int ModNum) +{ + // When double-clicking on the item for this sketch the + // object unsets and sets its edit mode without closing + // the task panel + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + TaskDlgProjGroup *projDlg = qobject_cast(dlg); + if (projDlg && projDlg->getViewProvider() != this) + projDlg = 0; // another sketch left open its task panel + + // clear the selection (convenience) + Gui::Selection().clearSelection(); + + // start the edit dialog + if (projDlg) + Gui::Control().showDialog(projDlg); + else + Gui::Control().showDialog(new TaskDlgProjGroup(getObject())); + + return true; +} + +void ViewProviderProjGroup::unsetEdit(int ModNum) +{ + Gui::Control().closeDialog(); +} + +bool ViewProviderProjGroup::doubleClicked(void) +{ + setEdit(0); + return true; +} + +std::vector ViewProviderProjGroup::claimChildren(void) const +{ + // Collect any child fields + std::vector temp; + const std::vector &views = getObject()->Views.getValues(); + try { + for(std::vector::const_iterator it = views.begin(); it != views.end(); ++it) { + temp.push_back(*it); + } + return temp; + } catch (...) { + std::vector tmp; + return tmp; + } +} + + +TechDraw::DrawProjGroup* ViewProviderProjGroup::getObject() const +{ + return dynamic_cast(pcObject); +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderProjGroup.h b/src/Mod/TechDraw/Gui/ViewProviderProjGroup.h new file mode 100644 index 0000000000..c2e930c118 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderProjGroup.h @@ -0,0 +1,71 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * * + * 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_VIEWPROVIDERVIEWGROUP_H +#define DRAWINGGUI_VIEWPROVIDERVIEWGROUP_H + +#include +#include + +#include + +namespace TechDraw{ + class DrawProjGroup; +} + +namespace TechDrawGui { + + +class TechDrawGuiExport ViewProviderProjGroup : public Gui::ViewProviderDocumentObject +{ + PROPERTY_HEADER(TechDrawGui::ViewProviderProjGroup); + +public: + + ViewProviderProjGroup(); /// constructor + ~ViewProviderProjGroup(); /// destructor + + 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; + + /// Claim all the views for the page + std::vector claimChildren(void) const; + + /// Is called by the tree if the user double click on the object + virtual bool doubleClicked(void); + void setupContextMenu(QMenu*, QObject*, const char*); + virtual void updateData(const App::Property*); + + TechDraw::DrawProjGroup* getObject() const; + void unsetEdit(int ModNum); + +protected: + bool setEdit(int ModNum); + +}; + +} // namespace TechDrawGui + +#endif // DRAWINGGUI_VIEWPROVIDERVIEWGROUP_H diff --git a/src/Mod/TechDraw/Gui/ViewProviderProjGroupItem.cpp b/src/Mod/TechDraw/Gui/ViewProviderProjGroupItem.cpp new file mode 100644 index 0000000000..c8413e6174 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderProjGroupItem.cpp @@ -0,0 +1,158 @@ +/*************************************************************************** + * Copyright (c) 2014 Luke Parry * + * * + * 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 +#include +#include +#include +#include + + +#include + +#include "ViewProviderProjGroupItem.h" + +using namespace TechDrawGui; + +PROPERTY_SOURCE(TechDrawGui::ViewProviderProjGroupItem, TechDrawGui::ViewProviderViewPart) + +//************************************************************************** +// Construction/Destruction + +ViewProviderProjGroupItem::ViewProviderProjGroupItem() +{ + +} + +ViewProviderProjGroupItem::~ViewProviderProjGroupItem() +{ +} + +void ViewProviderProjGroupItem::attach(App::DocumentObject *pcFeat) +{ + // call parent attach method + ViewProviderViewPart::attach(pcFeat); +} + +void ViewProviderProjGroupItem::setDisplayMode(const char* ModeName) +{ + ViewProviderDocumentObject::setDisplayMode(ModeName); +} + +std::vector ViewProviderProjGroupItem::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList = ViewProviderDocumentObject::getDisplayModes(); + StrList.push_back("Drawing"); + return StrList; +} + +void ViewProviderProjGroupItem::updateData(const App::Property* prop) +{ + Gui::ViewProviderDocumentObject::updateData(prop); + TechDraw::DrawProjGroupItem* proj = getObject(); + + if(proj) { + // Set the icon pixmap depending on the orientation + std::string projType = proj->Type.getValueAsString(); + + //TODO: Once we know that ProjType is valid, sPixMap = "Proj" + projType + + if(strcmp(projType.c_str(), "Front") == 0) { + sPixmap = "ProjFront"; + } else if(strcmp(projType.c_str(), "Rear") == 0) { + sPixmap = "ProjRear"; + } else if(strcmp(projType.c_str(), "Right") == 0) { + sPixmap = "ProjRight"; + } else if(strcmp(projType.c_str(), "Left") == 0) { + sPixmap = "ProjLeft"; + } else if(strcmp(projType.c_str(), "Top") == 0) { + sPixmap = "ProjTop"; + } else if(strcmp(projType.c_str(), "Bottom") == 0) { + sPixmap = "ProjBottom"; + } else if(strcmp(projType.c_str(), "FrontTopLeft") == 0) { + sPixmap = "ProjFrontTopLeft"; + } else if(strcmp(projType.c_str(), "FrontTopRight") == 0) { + sPixmap = "ProjFrontTopRight"; + } else if(strcmp(projType.c_str(), "FrontBottomRight") == 0) { + sPixmap = "ProjFrontBottomRight"; + } else if(strcmp(projType.c_str(), "FrontBottomLeft") == 0) { + sPixmap = "ProjFrontBottomLeft"; + } + } + } + + +void ViewProviderProjGroupItem::setupContextMenu(QMenu* menu, QObject* receiver, const char* member) +{ + //QAction* act; + //act = menu->addAction(QObject::tr("Show drawing"), receiver, member); +} + +bool ViewProviderProjGroupItem::setEdit(int ModNum) +{ + doubleClicked(); + return true; +} + +void ViewProviderProjGroupItem::unsetEdit(int ModNum) +{ + Gui::Control().closeDialog(); +} + +bool ViewProviderProjGroupItem::doubleClicked(void) +{ + return true; +} + +bool ViewProviderProjGroupItem::onDelete(const std::vector &subList) +{ + + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.removeObject(\"%s\")" + ,getObject()->getNameInDocument()); + Gui::Command::commitCommand(); + Gui::Command::updateActive(); + return false; + +} + +TechDraw::DrawProjGroupItem* ViewProviderProjGroupItem::getObject() const +{ + return dynamic_cast(pcObject); +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderProjGroupItem.h b/src/Mod/TechDraw/Gui/ViewProviderProjGroupItem.h new file mode 100644 index 0000000000..aac27b2d33 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderProjGroupItem.h @@ -0,0 +1,67 @@ +/*************************************************************************** + * Copyright (c) 2014 Luke Parry * + * * + * 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_VIEWPROVIDERVIEWGROUPITEM_H +#define DRAWINGGUI_VIEWPROVIDERVIEWGROUPITEM_H + +#include "ViewProviderViewPart.h" + +namespace TechDraw{ + class DrawProjGroupItem; +} + +namespace TechDrawGui { + + +class TechDrawGuiExport ViewProviderProjGroupItem: public ViewProviderViewPart +{ + PROPERTY_HEADER(TechDrawGui::ViewProviderProjGroupItem); + +public: + + ViewProviderProjGroupItem(); + ~ViewProviderProjGroupItem(); + + 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; + + /// Is called by the tree if the user double click on the object + virtual bool doubleClicked(void); + void setupContextMenu(QMenu*, QObject*, const char*); + virtual void updateData(const App::Property*); + + bool onDelete(const std::vector &subList); + + TechDraw::DrawProjGroupItem* getObject() const; + void unsetEdit(int ModNum); + +protected: + bool setEdit(int ModNum); + +}; + +} // namespace TechDrawGui + +#endif // DRAWINGGUI_VIEWPROVIDERVIEWGROUPITEM_H diff --git a/src/Mod/TechDraw/Gui/ViewProviderSymbol.cpp b/src/Mod/TechDraw/Gui/ViewProviderSymbol.cpp new file mode 100644 index 0000000000..64e5307563 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderSymbol.cpp @@ -0,0 +1,86 @@ +/*************************************************************************** + * Copyright (c) 2004 Jürgen Riegel * + * Copyright (c) 2012 Luke Parry * + * * + * 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 "ViewProviderSymbol.h" + +using namespace TechDrawGui; + +PROPERTY_SOURCE(TechDrawGui::ViewProviderSymbol, Gui::ViewProviderDocumentObject) + +//************************************************************************** +// Construction/Destruction + +ViewProviderSymbol::ViewProviderSymbol() +{ + sPixmap = "Symbol"; +} + +ViewProviderSymbol::~ViewProviderSymbol() +{ +} + +void ViewProviderSymbol::attach(App::DocumentObject *pcFeat) +{ + // call parent attach method + ViewProviderDocumentObject::attach(pcFeat); +} + +void ViewProviderSymbol::setDisplayMode(const char* ModeName) +{ + ViewProviderDocumentObject::setDisplayMode(ModeName); +} + +std::vector ViewProviderSymbol::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList = ViewProviderDocumentObject::getDisplayModes(); + + return StrList; +} + +void ViewProviderSymbol::updateData(const App::Property*) +{ +} + +TechDraw::DrawViewSymbol* ViewProviderSymbol::getViewObject() const +{ + return dynamic_cast(pcObject); +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderSymbol.h b/src/Mod/TechDraw/Gui/ViewProviderSymbol.h new file mode 100644 index 0000000000..49e1e98817 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderSymbol.h @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (c) 2004 Jürgen Riegel * + * Copyright (c) 2012 Luke Parry * + * * + * 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_VIEWPROVIDERSYMBOL_H +#define DRAWINGGUI_VIEWPROVIDERSYMBOL_H + +#include + +namespace TechDraw{ + class DrawViewSymbol; +} + +namespace TechDrawGui { + + +class TechDrawGuiExport ViewProviderSymbol : public Gui::ViewProviderDocumentObject +{ + PROPERTY_HEADER(TechDrawGui::ViewProviderSymbol); + +public: + /// constructor + ViewProviderSymbol(); + /// destructor + virtual ~ViewProviderSymbol(); + + + 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::DrawViewSymbol* getViewObject() const; +}; + +} // namespace TechDrawGui + + +#endif // DRAWINGGUI_VIEWPROVIDERSYMBOL_H diff --git a/src/Mod/TechDraw/Gui/ViewProviderTemplate.cpp b/src/Mod/TechDraw/Gui/ViewProviderTemplate.cpp new file mode 100644 index 0000000000..c1cbed9d8e --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderTemplate.cpp @@ -0,0 +1,89 @@ +/*************************************************************************** + * Copyright (c) 2014 Luke Parry * + * * + * 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_ +# ifdef FC_OS_WIN32 +# include +# endif +#endif + +/// Here the FreeCAD includes sorted by Base,App,Gui...... +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "ViewProviderTemplate.h" + +using namespace TechDrawGui; + +PROPERTY_SOURCE(TechDrawGui::ViewProviderTemplate, Gui::ViewProviderDocumentObject) + +//************************************************************************** +// Construction/Destruction + +ViewProviderTemplate::ViewProviderTemplate() +{ + sPixmap = "PageTemplate"; +} + +ViewProviderTemplate::~ViewProviderTemplate() +{ +} + +void ViewProviderTemplate::attach(App::DocumentObject *pcFeat) +{ + // call parent attach method + ViewProviderDocumentObject::attach(pcFeat); +} + +void ViewProviderTemplate::setDisplayMode(const char* ModeName) +{ + ViewProviderDocumentObject::setDisplayMode(ModeName); +} + +std::vector ViewProviderTemplate::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList = ViewProviderDocumentObject::getDisplayModes(); + + return StrList; +} + +void ViewProviderTemplate::updateData(const App::Property* prop) +{ + Base::Console().Log("ViewProviderTemplate::updateData(%s)",prop->getName()); +} + +TechDraw::DrawTemplate* ViewProviderTemplate::getTemplate() const +{ + return dynamic_cast(pcObject); +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderTemplate.h b/src/Mod/TechDraw/Gui/ViewProviderTemplate.h new file mode 100644 index 0000000000..dbb7dbf87c --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderTemplate.h @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (c) 2014 Luke Parry * + * * + * 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_VIEWPROVIDERTEMPLATE_H +#define DRAWINGGUI_VIEWPROVIDERTEMPLATE_H + +#include + +namespace TechDraw{ + class DrawTemplate; +} + +namespace TechDrawGui { + +class TechDrawGuiExport ViewProviderTemplate : public Gui::ViewProviderDocumentObject +{ + PROPERTY_HEADER(TechDrawGui::ViewProviderTemplate); + +public: + /// constructor + ViewProviderTemplate(); + /// destructor + virtual ~ViewProviderTemplate(); + + 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*); + +public: + TechDraw::DrawTemplate* getTemplate() const; +}; + +} // namespace TechDrawGui + + +#endif // DRAWINGGUI_VIEWPROVIDERTEMPLATE_H + diff --git a/src/Mod/TechDraw/Gui/ViewProviderView.cpp b/src/Mod/TechDraw/Gui/ViewProviderView.cpp new file mode 100644 index 0000000000..0cfdfac025 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderView.cpp @@ -0,0 +1,143 @@ +/*************************************************************************** + * Copyright (c) 2004 Jürgen Riegel * + * Copyright (c) 2012 Luke Parry * + * * + * 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 +#include "ViewProviderView.h" + + +using namespace TechDrawGui; + +PROPERTY_SOURCE(TechDrawGui::ViewProviderView, Gui::ViewProviderDocumentObject) + +ViewProviderView::ViewProviderView() +{ + sPixmap = "View"; + + // Do not show in property editor + DisplayMode.StatusBits.set(3, true); +} + +ViewProviderView::~ViewProviderView() +{ +} + +void ViewProviderView::attach(App::DocumentObject *pcFeat) +{ + // call parent attach method + ViewProviderDocumentObject::attach(pcFeat); +} + +void ViewProviderView::setDisplayMode(const char* ModeName) +{ + ViewProviderDocumentObject::setDisplayMode(ModeName); +} + +std::vector ViewProviderView::getDisplayModes(void) const +{ + std::vector StrList = ViewProviderDocumentObject::getDisplayModes(); + return StrList; +} + +void ViewProviderView::show(void) +{ + ViewProviderDocumentObject::show(); + + App::DocumentObject* obj = getObject(); + if (!obj || obj->isRestoring()) + return; + if (obj->getTypeId().isDerivedFrom(TechDraw::DrawView::getClassTypeId())) { + // The 'Visible' property is marked as 'Output'. To update the drawing on recompute + // the parent page object is touched. + static_cast(obj)->Visible.setValue(true); + std::vector inp = obj->getInList(); + for (std::vector::iterator it = inp.begin(); it != inp.end(); ++it) + (*it)->touch(); + } +} + +void ViewProviderView::hide(void) +{ + ViewProviderDocumentObject::hide(); + + App::DocumentObject* obj = getObject(); + if (!obj || obj->isRestoring()) + return; + if (obj->getTypeId().isDerivedFrom(TechDraw::DrawView::getClassTypeId())) { + // The 'Visible' property is marked as 'Output'. To update the drawing on recompute + // the parent page object is touched. + static_cast(obj)->Visible.setValue(false); + std::vector inp = obj->getInList(); + for (std::vector::iterator it = inp.begin(); it != inp.end(); ++it) + (*it)->touch(); + } +} + +bool ViewProviderView::isShow(void) const +{ + return Visibility.getValue(); +} + +void ViewProviderView::startRestoring() +{ + // do nothing +} + +void ViewProviderView::finishRestoring() +{ + // do nothing +} + +void ViewProviderView::updateData(const App::Property*) +{ +} + +TechDraw::DrawView* ViewProviderView::getViewObject() const +{ + return dynamic_cast(pcObject); +} + +bool ViewProviderView::onDelete(const std::vector &items) +{ + //int viewCount = + static_cast (getViewObject()->findParentPage()->removeView(getViewObject())); + Gui::Selection().clearSelection(); + return ViewProviderDocumentObject::onDelete(items); +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderView.h b/src/Mod/TechDraw/Gui/ViewProviderView.h new file mode 100644 index 0000000000..368f579a04 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderView.h @@ -0,0 +1,74 @@ +/*************************************************************************** + * Copyright (c) 2004 Jürgen Riegel * + * Copyright (c) 2012 Luke Parry * + * * + * 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_VIEWPROVIDERVIEW_H +#define DRAWINGGUI_VIEWPROVIDERVIEW_H + +#include +#include + +namespace TechDraw{ + class DrawView; +} + +namespace TechDrawGui { + + +class TechDrawGuiExport ViewProviderView : public Gui::ViewProviderDocumentObject +{ + PROPERTY_HEADER(TechDrawGui::ViewProviderView); + +public: + /// constructor + ViewProviderView(); + /// destructor + virtual ~ViewProviderView(); + + + 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*); + /// Hide the object in the view + virtual void hide(void); + /// Show the object in the view + virtual void show(void); + virtual bool isShow(void) const; + + /** @name Restoring view provider from document load */ + //@{ + virtual void startRestoring(); + virtual void finishRestoring(); + //@} + virtual bool onDelete(const std::vector &items); + TechDraw::DrawView* getViewObject() const; +}; + +} // namespace TechDrawGui + + +#endif // DRAWINGGUI_VIEWPROVIDERVIEW_H + diff --git a/src/Mod/TechDraw/Gui/ViewProviderViewClip.cpp b/src/Mod/TechDraw/Gui/ViewProviderViewClip.cpp new file mode 100644 index 0000000000..2c5ac4caaf --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderViewClip.cpp @@ -0,0 +1,147 @@ +/*************************************************************************** + * Copyright (c) 2004 Jürgen Riegel * + * Copyright (c) 2012 Luke Parry * + * * + * 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_ +# ifdef FC_OS_WIN32 +# include +# endif +#endif + +/// Here the FreeCAD includes sorted by Base,App,Gui...... +#include +#include +#include +#include +#include +#include +#include +//#include +#include + +#include +#include "ViewProviderView.h" +#include "ViewProviderViewClip.h" + + +using namespace TechDrawGui; + +PROPERTY_SOURCE(TechDrawGui::ViewProviderDrawingClip, TechDrawGui::ViewProviderView) + +ViewProviderDrawingClip::ViewProviderDrawingClip() +{ + sPixmap = "actions/techdraw-clip"; + + // Do not show in property editor + DisplayMode.StatusBits.set(3, true); +} + +ViewProviderDrawingClip::~ViewProviderDrawingClip() +{ +} + +void ViewProviderDrawingClip::attach(App::DocumentObject *pcFeat) +{ + // call parent attach method + ViewProviderDocumentObject::attach(pcFeat); +} + +void ViewProviderDrawingClip::setDisplayMode(const char* ModeName) +{ + ViewProviderDocumentObject::setDisplayMode(ModeName); +} + +std::vector ViewProviderDrawingClip::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList; + return StrList; +} + +std::vector ViewProviderDrawingClip::claimChildren(void) const +{ + // Collect any child views + // for Clip, valid children are any View in Views + const std::vector &views = getObject()->Views.getValues(); + return views; +} + +void ViewProviderDrawingClip::show(void) +{ + ViewProviderView::show(); + + App::DocumentObject* obj = getObject(); + if (!obj || obj->isRestoring()) + return; + if (obj->getTypeId().isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId())) { + // The 'Visible' property is marked as 'Output'. To update the drawing on recompute + // the parent page object is touched. + static_cast(obj)->Visible.setValue(true); + std::vector inp = obj->getInList(); + for (std::vector::iterator it = inp.begin(); it != inp.end(); ++it) + (*it)->touch(); + } +} + +void ViewProviderDrawingClip::hide(void) +{ + ViewProviderView::hide(); + + App::DocumentObject* obj = getObject(); + if (!obj || obj->isRestoring()) + return; + if (obj->getTypeId().isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId())) { + // The 'Visible' property is marked as 'Output'. To update the drawing on recompute + // the parent page object is touched. + static_cast(obj)->Visible.setValue(false); + std::vector inp = obj->getInList(); + for (std::vector::iterator it = inp.begin(); it != inp.end(); ++it) + (*it)->touch(); + } +} + +bool ViewProviderDrawingClip::isShow(void) const +{ + return Visibility.getValue(); +} + +void ViewProviderDrawingClip::startRestoring() +{ + // do nothing +} + +void ViewProviderDrawingClip::finishRestoring() +{ + // do nothing +} + +void ViewProviderDrawingClip::updateData(const App::Property*) +{ +} + +TechDraw::DrawViewClip* ViewProviderDrawingClip::getObject() const +{ + return dynamic_cast(pcObject); +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderViewClip.h b/src/Mod/TechDraw/Gui/ViewProviderViewClip.h new file mode 100644 index 0000000000..1b27ac4b2c --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderViewClip.h @@ -0,0 +1,73 @@ +/*************************************************************************** + * Copyright (c) 2004 Jürgen Riegel * + * Copyright (c) 2012 Luke Parry * + * * + * 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_VIEWPROVIDERCLIP_H +#define DRAWINGGUI_VIEWPROVIDERCLIP_H + +#include +#include "ViewProviderView.h" + +namespace TechDraw{ + class DrawViewClip; +} + +namespace TechDrawGui { + +class TechDrawGuiExport ViewProviderDrawingClip : public ViewProviderView +{ + PROPERTY_HEADER(TechDrawGui::ViewProviderDrawingClip); + +public: + /// constructor + ViewProviderDrawingClip(); + /// destructor + virtual ~ViewProviderDrawingClip(); + + + 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::DrawViewClip* getObject() const; + + /// Hide the object in the view + virtual void hide(void); + /// Show the object in the view + virtual void show(void); + virtual bool isShow(void) const; + std::vector claimChildren(void) const; + + /** @name Restoring view provider from document load */ + //@{ + virtual void startRestoring(); + virtual void finishRestoring(); + //@} +}; +} // namespace TechDrawGui + + +#endif // DRAWINGGUI_VIEWPROVIDERCLIP_H + diff --git a/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp b/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp new file mode 100644 index 0000000000..5c4aeb44be --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp @@ -0,0 +1,123 @@ +/*************************************************************************** + * Copyright (c) 2014 Luke Parry * + * * + * 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_ +# ifdef FC_OS_WIN32 +# include +# endif +#endif + +/// Here the FreeCAD includes sorted by Base,App,Gui...... +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include "ViewProviderViewPart.h" + +using namespace TechDrawGui; + +PROPERTY_SOURCE(TechDrawGui::ViewProviderViewPart, TechDrawGui::ViewProviderView) + +//************************************************************************** +// Construction/Destruction + +ViewProviderViewPart::ViewProviderViewPart() +{ + sPixmap = "View"; +} + +ViewProviderViewPart::~ViewProviderViewPart() +{ +} + +void ViewProviderViewPart::attach(App::DocumentObject *pcFeat) +{ + // call parent attach method + ViewProviderDocumentObject::attach(pcFeat); +} + +void ViewProviderViewPart::setDisplayMode(const char* ModeName) +{ + ViewProviderDocumentObject::setDisplayMode(ModeName); +} + +std::vector ViewProviderViewPart::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList = ViewProviderDocumentObject::getDisplayModes(); + + return StrList; +} + + +std::vector ViewProviderViewPart::claimChildren(void) const +{ + // Collect any child Document Objects and put them in the right place in the Feature tree + // valid children of a ViewPart are: + // - Dimensions + // - Hatches + std::vector temp; + const std::vector &views = getViewPart()->getInList(); + try { + for(std::vector::const_iterator it = views.begin(); it != views.end(); ++it) { + if((*it)->getTypeId().isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) { + TechDraw::DrawViewDimension *dim = dynamic_cast(*it); + const std::vector &refs = dim->References.getValues(); + for(std::vector::const_iterator it = refs.begin(); it != refs.end(); ++it) { + if(strcmp(getViewPart()->getNameInDocument(), (*it)->getNameInDocument()) == 0) { //wf: isn't this test redundant? + temp.push_back(dim); // if a dim is in the inlist, + // it's a child of this ViewPart?? + } + } + } else if ((*it)->getTypeId().isDerivedFrom(TechDraw::DrawHatch::getClassTypeId())) { + temp.push_back((*it)); + } + } + return temp; + } catch (...) { + std::vector tmp; + return tmp; + } +} + + +void ViewProviderViewPart::updateData(const App::Property*) +{ +} + +TechDraw::DrawViewPart* ViewProviderViewPart::getViewPart() const +{ + return dynamic_cast(pcObject); +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderViewPart.h b/src/Mod/TechDraw/Gui/ViewProviderViewPart.h new file mode 100644 index 0000000000..e724baf0d8 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderViewPart.h @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (c) 2013 Luke Parry * + * * + * 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_VIEWPROVIDERVIEWPART_H +#define DRAWINGGUI_VIEWPROVIDERVIEWPART_H + +#include "ViewProviderView.h" + +namespace TechDraw{ + class DrawViewPart; +} + +namespace TechDrawGui { + +class TechDrawGuiExport ViewProviderViewPart : public ViewProviderView +{ + PROPERTY_HEADER(TechDrawGui::ViewProviderViewPart); + +public: + /// constructor + ViewProviderViewPart(); + /// destructor + virtual ~ViewProviderViewPart(); + + 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*); + +public: + virtual std::vector claimChildren(void) const; + + TechDraw::DrawViewPart* getViewPart() const; +}; + +} // namespace TechDrawGui + + +#endif // DRAWINGGUI_VIEWPROVIDERVIEWPART_H diff --git a/src/Mod/TechDraw/Gui/ViewProviderViewSection.cpp b/src/Mod/TechDraw/Gui/ViewProviderViewSection.cpp new file mode 100644 index 0000000000..a94f647df6 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderViewSection.cpp @@ -0,0 +1,96 @@ +/*************************************************************************** + * Copyright (c) 2004 Jürgen Riegel * + * Copyright (c) 2012 Luke Parry * + * * + * 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_ +# ifdef FC_OS_WIN32 +# include +# endif +#endif + +/// Here the FreeCAD includes sorted by Base,App,Gui...... +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "ViewProviderViewSection.h" + +using namespace TechDrawGui; + +PROPERTY_SOURCE(TechDrawGui::ViewProviderViewSection, TechDrawGui::ViewProviderViewPart) + +//************************************************************************** +// Construction/Destruction + +ViewProviderViewSection::ViewProviderViewSection() +{ + sPixmap = "Section"; +} + +ViewProviderViewSection::~ViewProviderViewSection() +{ +} + +void ViewProviderViewSection::attach(App::DocumentObject *pcFeat) +{ + // call parent attach method + ViewProviderDocumentObject::attach(pcFeat); +} + +void ViewProviderViewSection::setDisplayMode(const char* ModeName) +{ + ViewProviderDocumentObject::setDisplayMode(ModeName); +} + +std::vector ViewProviderViewSection::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList = ViewProviderDocumentObject::getDisplayModes(); + + return StrList; +} + +void ViewProviderViewSection::updateData(const App::Property* prop) +{ + //Base::Console().Log("ViewProviderViewSection::updateData - Update View: %s\n",prop->getName()); + // +} + +std::vector ViewProviderViewSection::claimChildren(void) const +{ + return ViewProviderViewPart::claimChildren(); +} + +TechDraw::DrawView* ViewProviderViewSection::getViewObject() const +{ + return dynamic_cast(pcObject); +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderViewSection.h b/src/Mod/TechDraw/Gui/ViewProviderViewSection.h new file mode 100644 index 0000000000..dd2e6b5a37 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderViewSection.h @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (c) 2004 Jürgen Riegel * + * Copyright (c) 2013 Luke Parry * + * * + * 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_VIEWPROVIDERVIEWSECTION_H +#define DRAWINGGUI_VIEWPROVIDERVIEWSECTION_H + +#include "ViewProviderViewPart.h" + +namespace TechDraw{ + class DrawView; +} + +namespace TechDrawGui { + + +class TechDrawGuiExport ViewProviderViewSection : public ViewProviderViewPart +{ + PROPERTY_HEADER(TechDrawGui::ViewProviderViewSection); + +public: + /// constructor + ViewProviderViewSection(); + /// destructor + virtual ~ViewProviderViewSection(); + + + virtual void attach(App::DocumentObject *); + virtual void setDisplayMode(const char* ModeName); + /// returns a list of all possible modes + virtual std::vector getDisplayModes(void) const; + virtual void updateData(const App::Property*); + virtual std::vector claimChildren(void) const; + + TechDraw::DrawView* getViewObject() const; +}; + +} // namespace TechDrawGui + + +#endif // DRAWINGGUI_VIEWPROVIDERVIEW_H diff --git a/src/Mod/TechDraw/Gui/Workbench.cpp b/src/Mod/TechDraw/Gui/Workbench.cpp new file mode 100644 index 0000000000..d9aa5f829b --- /dev/null +++ b/src/Mod/TechDraw/Gui/Workbench.cpp @@ -0,0 +1,171 @@ +/*************************************************************************** + * Copyright (c) 2005 Werner Mayer * + * Copyright (c) 2013 Luke Parry * + * * + * 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 "Workbench.h" +#include +#include + +using namespace TechDrawGui; + +#if 0 // needed for Qt's lupdate utility +// qApp->translate("Workbench", "Drawing"); + qApp->translate("Workbench", "Drawing Pages"); + qApp->translate("Workbench", "Drawing Views"); + qApp->translate("Workbench", "Drawing Dimensions"); +#endif + +/// @namespace TechDrawGui @class Workbench +TYPESYSTEM_SOURCE(TechDrawGui::Workbench, Gui::StdWorkbench) + +Workbench::Workbench() +{ +} + +Workbench::~Workbench() +{ +} + +Gui::MenuItem* Workbench::setupMenuBar() const +{ + Gui::MenuItem* root = StdWorkbench::setupMenuBar(); + Gui::MenuItem* item = root->findItem("&Windows"); + + Gui::MenuItem* draw = new Gui::MenuItem; + root->insertItem(item, draw); + draw->setCommand("Drawing"); + //*draw << "Drawing_Open"; + //*part << "Drawing_NewA3Landscape"; + *draw << "Drawing_NewPageDef"; + *draw << "Drawing_NewPage"; + *draw << "Drawing_NewView"; + *draw << "Drawing_ProjGroup"; + //*part << "Drawing_OpenBrowserView"; + *draw << "Drawing_NewViewSection"; + *draw << "Drawing_Annotation"; + *draw << "Drawing_Symbol"; + *draw << "Drawing_Clip"; + *draw << "Drawing_ClipPlus"; + *draw << "Drawing_ClipMinus"; + *draw << "Drawing_NewDimension"; + //*part << "Drawing_DraftView"; + *draw << "Drawing_ExportPage"; + *draw << "Separator"; + *draw << "Drawing_ProjectShape"; + + return root; +} + +Gui::ToolBarItem* Workbench::setupToolBars() const +{ + Gui::ToolBarItem* root = StdWorkbench::setupToolBars(); + Gui::ToolBarItem* pages = new Gui::ToolBarItem(root); + pages->setCommand("Drawing Pages"); + *pages << "Drawing_NewPageDef"; + *pages << "Drawing_NewPage"; + + Gui::ToolBarItem *views = new Gui::ToolBarItem(root); + views->setCommand("Drawing Views"); + *views << "Drawing_NewView"; + *views << "Drawing_ProjGroup"; + *views << "Drawing_NewViewSection"; + *views << "Drawing_Annotation"; + + Gui::ToolBarItem *clips = new Gui::ToolBarItem(root); + clips->setCommand("Drawing Clips"); + *clips << "Drawing_Clip"; + *clips << "Drawing_ClipPlus"; + *clips << "Drawing_ClipMinus"; + + Gui::ToolBarItem *dims = new Gui::ToolBarItem(root); + dims->setCommand("Drawing Dimensions"); +// *dims << "Drawing_NewDimension" + *dims << "Drawing_NewLengthDimension"; + *dims << "Drawing_NewDistanceXDimension"; + *dims << "Drawing_NewDistanceYDimension"; + *dims << "Drawing_NewRadiusDimension"; + *dims << "Drawing_NewDiameterDimension"; + *dims << "Drawing_NewAngleDimension"; + + Gui::ToolBarItem *file = new Gui::ToolBarItem(root); + file->setCommand("Drawing File Access"); + *file << "Drawing_ExportPage"; + *file << "Drawing_Symbol"; + + Gui::ToolBarItem *decor = new Gui::ToolBarItem(root); + decor->setCommand("Drawing Decoration"); + *decor << "Drawing_NewHatch"; + return root; +} + +Gui::ToolBarItem* Workbench::setupCommandBars() const +{ + Gui::ToolBarItem* root = new Gui::ToolBarItem; + Gui::ToolBarItem *pages = new Gui::ToolBarItem(root); + pages->setCommand("Drawing Pages"); + *pages << "Drawing_NewPageDef"; + *pages << "Drawing_NewPage"; + + Gui::ToolBarItem *views = new Gui::ToolBarItem(root); + views->setCommand("Views"); + *views << "Drawing_NewView"; + *views << "Drawing_ProjGroup"; + *views << "Drawing_NewViewSection"; + *views << "Drawing_Annotation"; + + Gui::ToolBarItem *clips = new Gui::ToolBarItem(root); + clips->setCommand("Drawing Clips"); + *clips << "Drawing_Clip"; + *clips << "Drawing_ClipPlus"; + *clips << "Drawing_ClipMinus"; + + Gui::ToolBarItem *dims = new Gui::ToolBarItem(root); + dims->setCommand("Drawing Dimensions"); +// *dims << "Drawing_NewDimension"; + *dims << "Drawing_NewLengthDimension"; + *dims << "Drawing_NewDistanceXDimension"; + *dims << "Drawing_NewDistanceYDimension"; + *dims << "Drawing_NewRadiusDimension"; + *dims << "Drawing_NewDiameterDimension"; + *dims << "Drawing_NewAngleDimension"; + + Gui::ToolBarItem *file = new Gui::ToolBarItem(root); + file->setCommand("Drawing File Access"); + *file << "Drawing_ExportPage"; + *file << "Drawing_Symbol"; + + Gui::ToolBarItem *decor = new Gui::ToolBarItem(root); + decor->setCommand("Drawing Decoration"); + *decor << "Drawing_NewHatch"; + +// *img << "Drawing_OpenBrowserView"; +// *img << "Drawing_DraftView"; + + return root; +} diff --git a/src/Mod/TechDraw/Gui/Workbench.h b/src/Mod/TechDraw/Gui/Workbench.h new file mode 100644 index 0000000000..8a04d3116c --- /dev/null +++ b/src/Mod/TechDraw/Gui/Workbench.h @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright (c) 2005 Werner Mayer * + * * + * 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 TECHDRAW_WORKBENCH_H +#define TECHDRAW_WORKBENCH_H + +#include + +namespace TechDrawGui { + +/** + * @author Werner Mayer + */ +class TechDrawGuiExport Workbench : public Gui::StdWorkbench +{ + TYPESYSTEM_HEADER(); + +public: + Workbench(); + virtual ~Workbench(); + +protected: + Gui::MenuItem* setupMenuBar() const; + Gui::ToolBarItem* setupToolBars() const; + Gui::ToolBarItem* setupCommandBars() const; +}; + +} // namespace TechDrawGui + + +#endif // TECHDRAW_WORKBENCH_H