Add Mod/TechDraw/Gui
This commit is contained in:
114
src/Mod/TechDraw/Gui/AppTechDrawGui.cpp
Normal file
114
src/Mod/TechDraw/Gui/AppTechDrawGui.cpp
Normal file
@@ -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 <Python.h>
|
||||
# include <QFontDatabase>
|
||||
#endif
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/Language/Translator.h>
|
||||
#include <Gui/WidgetFactory.h>
|
||||
|
||||
#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<TechDrawGui::DlgPrefsDrawingImp> ("Drawing");
|
||||
|
||||
// add resources and reloads the translators
|
||||
loadDrawingResource();
|
||||
}
|
||||
|
||||
} // extern "C" {
|
||||
217
src/Mod/TechDraw/Gui/AppTechDrawGuiPy.cpp
Normal file
217
src/Mod/TechDraw/Gui/AppTechDrawGuiPy.cpp
Normal file
@@ -0,0 +1,217 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2006 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* 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 <QFileInfo>
|
||||
# include <QIcon>
|
||||
# include <QImage>
|
||||
# include <sstream>
|
||||
#endif
|
||||
|
||||
#include "MDIViewPage.h"
|
||||
#include <Mod/Drawing/App/DrawPage.h>
|
||||
#include <Mod/Drawing/App/DrawViewPart.h>
|
||||
#include <Mod/Drawing/App/ProjectionAlgos.h>
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/FileInfo.h>
|
||||
#include <Base/Stream.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/DocumentObjectPy.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
|
||||
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<App::DocumentObjectPy*>(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<TechDraw::DrawPage*>(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<App::DocumentObject*>& views = static_cast<TechDraw::DrawPage*>(obj)->Views.getValues();
|
||||
for (std::vector<App::DocumentObject*>::const_iterator it = views.begin(); it != views.end(); ++it) {
|
||||
if ((*it)->getTypeId().isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
|
||||
TechDraw::DrawViewPart* view = static_cast<TechDraw::DrawViewPart*>(*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<Part::Feature*>(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 */
|
||||
};
|
||||
191
src/Mod/TechDraw/Gui/CMakeLists.txt
Normal file
191
src/Mod/TechDraw/Gui/CMakeLists.txt
Normal file
@@ -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})
|
||||
982
src/Mod/TechDraw/Gui/Command.cpp
Normal file
982
src/Mod/TechDraw/Gui/Command.cpp
Normal file
@@ -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 <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <sstream>
|
||||
# include <QCoreApplication>
|
||||
# include <QDir>
|
||||
# include <QFile>
|
||||
# include <QFileInfo>
|
||||
# include <QMessageBox>
|
||||
# include <QRegExp>
|
||||
#endif
|
||||
|
||||
#include <QStringBuilder>
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QPainter>
|
||||
#include <QSvgRenderer>
|
||||
#include <QSvgGenerator>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/PropertyGeo.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Gui/Action.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Control.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/FileDialog.h>
|
||||
#include <Gui/ViewProvider.h>
|
||||
#include <Gui/WaitCursor.h>
|
||||
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
#include <Mod/Drawing/App/DrawPage.h>
|
||||
#include <Mod/Drawing/App/DrawViewPart.h>
|
||||
#include <Mod/Drawing/App/DrawProjGroupItem.h>
|
||||
#include <Mod/Drawing/App/DrawProjGroup.h>
|
||||
#include <Mod/Drawing/App/DrawViewDimension.h>
|
||||
#include <Mod/Drawing/App/DrawViewClip.h>
|
||||
#include <Mod/Drawing/App/DrawViewAnnotation.h>
|
||||
#include <Mod/Drawing/App/DrawViewSymbol.h>
|
||||
#include <Mod/Drawing/Gui/QGVPage.h>
|
||||
|
||||
|
||||
#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<ParameterGrp> 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<TechDraw::DrawPage*>(getDocument()->getObject(PageName.c_str()));
|
||||
Gui::ViewProvider* vp = Gui::Application::Instance->getDocument(getDocument())->getViewProvider(fp);
|
||||
TechDrawGui::ViewProviderDrawingPage* dvp = dynamic_cast<TechDrawGui::ViewProviderDrawingPage*>(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<ParameterGrp> 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<TechDraw::DrawPage*>(getDocument()->getObject(PageName.c_str()));
|
||||
Gui::ViewProvider* vp = Gui::Application::Instance->getDocument(getDocument())->getViewProvider(fp);
|
||||
TechDrawGui::ViewProviderDrawingPage* dvp = dynamic_cast<TechDrawGui::ViewProviderDrawingPage*>(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<App::DocumentObject*> 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<App::DocumentObject*> pages = getSelection().getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
||||
std::vector<App::DocumentObject*> 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<App::DocumentObject*> 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<TechDraw::DrawView*>(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<App::PropertyVector*>(myView->getPropertyByName("Direction"));
|
||||
if (propDirection) {
|
||||
newDirection = propDirection->getValue();
|
||||
}
|
||||
}
|
||||
|
||||
std::string PageName = pages.front()->getNameInDocument();
|
||||
|
||||
openCommand("Create view");
|
||||
for (std::vector<App::DocumentObject*>::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<TechDraw::DrawPage *>(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<App::DocumentObject*> 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<App::DocumentObject*> 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<App::DocumentObject*>::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<TechDraw::DrawPage *>(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<App::DocumentObject*> 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<App::DocumentObject*> selPages = getSelection().getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
||||
if (!selPages.empty()) {
|
||||
page = dynamic_cast<TechDraw::DrawPage *>(selPages.front());
|
||||
} else {
|
||||
// Check that any page object exists in Document
|
||||
const std::vector<App::DocumentObject*> docPages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
||||
if (!docPages.empty()) {
|
||||
page = dynamic_cast<TechDraw::DrawPage *>(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<TechDraw::DrawProjGroup *>(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<Gui::SelectionSingleton::SelObj> 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<App::DocumentObject*> pages = getSelection().getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
||||
std::vector<App::DocumentObject*> 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<TechDraw::DrawPage *>(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<App::DocumentObject*> pages = getSelection().getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
||||
std::vector<App::DocumentObject*> 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<TechDraw::DrawPage *>(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<App::DocumentObject*> 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<App::DocumentObject*> 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<App::DocumentObject*>::iterator it = views.begin();
|
||||
for (; it != views.end(); it++) {
|
||||
if ((*it)->isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId())) {
|
||||
clip = dynamic_cast<TechDraw::DrawViewClip*> ((*it));
|
||||
} else {
|
||||
view = dynamic_cast<TechDraw::DrawView*> ((*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<App::DocumentObject*> 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<App::DocumentObject*> 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<App::DocumentObject*>::iterator it = views.begin();
|
||||
for (; it != views.end(); it++) {
|
||||
if ((*it)->isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId())) {
|
||||
clip = dynamic_cast<TechDraw::DrawViewClip*> ((*it));
|
||||
} else {
|
||||
view = dynamic_cast<TechDraw::DrawView*> ((*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<App::DocumentObject*> pages = getSelection().getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
||||
std::vector<App::DocumentObject*> 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<TechDraw::DrawPage *>(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<App::DocumentObject*> 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<TechDraw::DrawPage*>(pages.front());
|
||||
|
||||
Gui::Document* activeGui = Gui::Application::Instance->getDocument(page->getDocument());
|
||||
Gui::ViewProvider* vp = activeGui->getViewProvider(page);
|
||||
ViewProviderDrawingPage* dvp = dynamic_cast<ViewProviderDrawingPage*>(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());
|
||||
}
|
||||
923
src/Mod/TechDraw/Gui/CommandCreateDims.cpp
Normal file
923
src/Mod/TechDraw/Gui/CommandCreateDims.cpp
Normal file
@@ -0,0 +1,923 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2014 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QMessageBox>
|
||||
# include <iostream>
|
||||
# include <string>
|
||||
# include <sstream>
|
||||
# include <cstdlib>
|
||||
# include <exception>
|
||||
# include <boost/regex.hpp>
|
||||
#endif //#ifndef _PreComp_
|
||||
|
||||
# include <App/DocumentObject.h>
|
||||
# include <Gui/Action.h>
|
||||
# include <Gui/Application.h>
|
||||
# include <Gui/BitmapFactory.h>
|
||||
# include <Gui/Command.h>
|
||||
# include <Gui/Control.h>
|
||||
# include <Gui/Document.h>
|
||||
# include <Gui/Selection.h>
|
||||
# include <Gui/MainWindow.h>
|
||||
# include <Gui/FileDialog.h>
|
||||
# include <Gui/ViewProvider.h>
|
||||
|
||||
# include <Mod/Part/App/PartFeature.h>
|
||||
|
||||
# include <Mod/Drawing/App/DrawViewPart.h>
|
||||
# include <Mod/Drawing/App/DrawProjGroupItem.h>
|
||||
# include <Mod/Drawing/App/DrawProjGroup.h>
|
||||
# include <Mod/Drawing/App/DrawViewDimension.h>
|
||||
# include <Mod/Drawing/App/DrawPage.h>
|
||||
# include <Mod/Drawing/App/DrawUtil.h>
|
||||
|
||||
# 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<std::string> &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<Gui::SelectionObject> selection = getSelection().getSelectionEx();
|
||||
TechDraw::DrawViewPart * objFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
|
||||
const std::vector<std::string> &SubNames = selection[0].getSubNames();
|
||||
|
||||
TechDraw::DrawViewDimension *dim = 0;
|
||||
std::string FeatName = getUniqueObjectName("Dimension");
|
||||
std::string dimType;
|
||||
bool centerLine = false;
|
||||
|
||||
std::vector<App::DocumentObject *> objs;
|
||||
std::vector<std::string> 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<TechDraw::DrawViewDimension *>(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<App::DocumentObject*> pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
||||
TechDraw::DrawPage *page = dynamic_cast<TechDraw::DrawPage *>(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<Gui::SelectionObject> selection = getSelection().getSelectionEx();
|
||||
TechDraw::DrawViewPart * objFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
|
||||
const std::vector<std::string> &SubNames = selection[0].getSubNames();
|
||||
|
||||
TechDraw::DrawViewDimension *dim = 0;
|
||||
std::string FeatName = getUniqueObjectName("Dimension");
|
||||
bool centerLine = false;
|
||||
|
||||
std::vector<App::DocumentObject *> objs;
|
||||
std::vector<std::string> 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<TechDraw::DrawViewDimension *>(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<App::DocumentObject*> pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
||||
TechDraw::DrawPage *page = dynamic_cast<TechDraw::DrawPage *>(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<Gui::SelectionObject> selection = getSelection().getSelectionEx();
|
||||
TechDraw::DrawViewPart * objFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
|
||||
const std::vector<std::string> &SubNames = selection[0].getSubNames();
|
||||
|
||||
TechDraw::DrawViewDimension *dim = 0;
|
||||
std::string FeatName = getUniqueObjectName("Dimension");
|
||||
bool centerLine = false;
|
||||
|
||||
std::vector<App::DocumentObject *> objs;
|
||||
std::vector<std::string> 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<TechDraw::DrawViewDimension *>(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<App::DocumentObject*> pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
||||
TechDraw::DrawPage *page = dynamic_cast<TechDraw::DrawPage *>(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<Gui::SelectionObject> selection = getSelection().getSelectionEx();
|
||||
TechDraw::DrawViewPart * objFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
|
||||
const std::vector<std::string> &SubNames = selection[0].getSubNames();
|
||||
|
||||
TechDraw::DrawViewDimension *dim = 0;
|
||||
std::string FeatName = getUniqueObjectName("Dimension");
|
||||
std::string dimType;
|
||||
|
||||
std::vector<App::DocumentObject *> objs;
|
||||
std::vector<std::string> 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<TechDraw::DrawViewDimension *>(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<App::DocumentObject*> pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
||||
TechDraw::DrawPage *page = dynamic_cast<TechDraw::DrawPage *>(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<Gui::SelectionObject> selection = getSelection().getSelectionEx();
|
||||
TechDraw::DrawViewPart * objFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
|
||||
const std::vector<std::string> &SubNames = selection[0].getSubNames();
|
||||
|
||||
TechDraw::DrawViewDimension *dim = 0;
|
||||
std::string FeatName = getUniqueObjectName("Dimension");
|
||||
std::string dimType;
|
||||
|
||||
std::vector<App::DocumentObject *> objs;
|
||||
std::vector<std::string> 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<TechDraw::DrawViewDimension *>(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<App::DocumentObject*> pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
||||
TechDraw::DrawPage *page = dynamic_cast<TechDraw::DrawPage *>(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<Gui::SelectionObject> selection = getSelection().getSelectionEx();
|
||||
TechDraw::DrawViewPart * objFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
|
||||
const std::vector<std::string> &SubNames = selection[0].getSubNames();
|
||||
|
||||
TechDraw::DrawViewDimension *dim = 0;
|
||||
std::string FeatName = getUniqueObjectName("Dimension");
|
||||
std::string dimType;
|
||||
|
||||
std::vector<App::DocumentObject *> objs;
|
||||
std::vector<std::string> 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<TechDraw::DrawViewDimension *>(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<App::DocumentObject*> pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
||||
TechDraw::DrawPage *page = dynamic_cast<TechDraw::DrawPage *>(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<Gui::SelectionObject> selection = getSelection().getSelectionEx();
|
||||
TechDraw::DrawViewPart * objFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
|
||||
const std::vector<std::string> &SubNames = selection[0].getSubNames();
|
||||
|
||||
TechDraw::DrawViewDimension *dim = 0;
|
||||
std::string FeatName = getUniqueObjectName("Dimension");
|
||||
|
||||
std::vector<App::DocumentObject *> objs;
|
||||
std::vector<std::string> 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<TechDraw::DrawViewDimension *>(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<App::DocumentObject*> pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
||||
TechDraw::DrawPage *page = dynamic_cast<TechDraw::DrawPage *>(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<Gui::SelectionObject> 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<TechDraw::DrawViewPart *>(selection[0].getObject());
|
||||
if(!objFeat) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"),
|
||||
QObject::tr("No Feature in selection"));
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::vector<std::string> &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<App::DocumentObject*> 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<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
|
||||
TechDraw::DrawViewPart * objFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
|
||||
const std::vector<std::string> &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<DrawingGeometry::Generic *>(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<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
|
||||
const std::vector<std::string> &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<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
|
||||
TechDraw::DrawViewPart* objFeat0 = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
|
||||
//TechDraw::DrawViewPart* objFeat1 = dynamic_cast<TechDraw::DrawViewPart *>(selection[1].getObject());
|
||||
const std::vector<std::string> &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<DrawingGeometry::Generic *>(geom0);
|
||||
DrawingGeometry::Generic *gen1 = static_cast<DrawingGeometry::Generic *>(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<std::string> &SubNames)
|
||||
{
|
||||
std::vector<std::string>::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;
|
||||
}
|
||||
160
src/Mod/TechDraw/Gui/CommandDecorate.cpp
Normal file
160
src/Mod/TechDraw/Gui/CommandDecorate.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2014 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QMessageBox>
|
||||
# include <iostream>
|
||||
# include <string>
|
||||
# include <sstream>
|
||||
# include <cstdlib>
|
||||
# include <exception>
|
||||
# include <boost/regex.hpp>
|
||||
#endif //#ifndef _PreComp_
|
||||
|
||||
# include <App/DocumentObject.h>
|
||||
# include <Gui/Action.h>
|
||||
# include <Gui/Application.h>
|
||||
# include <Gui/BitmapFactory.h>
|
||||
# include <Gui/Command.h>
|
||||
# include <Gui/Control.h>
|
||||
# include <Gui/Document.h>
|
||||
# include <Gui/Selection.h>
|
||||
# include <Gui/MainWindow.h>
|
||||
# include <Gui/FileDialog.h>
|
||||
# include <Gui/ViewProvider.h>
|
||||
|
||||
# include <Mod/Part/App/PartFeature.h>
|
||||
|
||||
# include <Mod/Drawing/App/DrawViewPart.h>
|
||||
# include <Mod/Drawing/App/DrawHatch.h>
|
||||
# include <Mod/Drawing/App/DrawPage.h>
|
||||
|
||||
# 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<Gui::SelectionObject> selection = getSelection().getSelectionEx();
|
||||
TechDraw::DrawViewPart * objFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
|
||||
const std::vector<std::string> &SubNames = selection[0].getSubNames();
|
||||
|
||||
TechDraw::DrawHatch *hatch = 0;
|
||||
std::string FeatName = getUniqueObjectName("Hatch");
|
||||
|
||||
std::vector<App::DocumentObject *> objs;
|
||||
std::vector<std::string> subs;
|
||||
|
||||
std::vector<std::string>::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<TechDraw::DrawHatch *>(getDocument()->getObject(FeatName.c_str()));
|
||||
hatch->Edges.setValues(objs, subs);
|
||||
|
||||
hatch->execute();
|
||||
|
||||
std::vector<App::DocumentObject*> pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
||||
TechDraw::DrawPage *page = dynamic_cast<TechDraw::DrawPage *>(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<Gui::SelectionObject> 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<TechDraw::DrawViewPart *>(selection[0].getObject());
|
||||
if(!objFeat) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"),
|
||||
QObject::tr("No Feature in selection"));
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<App::DocumentObject*> 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;
|
||||
}
|
||||
309
src/Mod/TechDraw/Gui/DlgPrefsDrawing.ui
Normal file
309
src/Mod/TechDraw/Gui/DlgPrefsDrawing.ui
Normal file
@@ -0,0 +1,309 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TechDrawGui::DlgPrefsDrawingImp</class>
|
||||
<widget class="QWidget" name="TechDrawGui::DlgPrefsDrawingImp">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>601</width>
|
||||
<height>550</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Drawing</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="verticalLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>30</y>
|
||||
<width>561</width>
|
||||
<height>471</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="gb_Colors">
|
||||
<property name="title">
|
||||
<string>Colors</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="gridLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
<width>191</width>
|
||||
<height>128</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="3" column="2">
|
||||
<widget class="Gui::PrefColorButton" name="pcb_Select">
|
||||
<property name="color">
|
||||
<color>
|
||||
<red>28</red>
|
||||
<green>173</green>
|
||||
<blue>28</blue>
|
||||
</color>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>SelectColor</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>Mod/Drawing/Colors</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<widget class="Gui::PrefColorButton" name="pcb_Hidden">
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>HiddenColor</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>Mod/Drawing/Colors</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="Gui::PrefColorButton" name="pcb_Normal">
|
||||
<property name="color">
|
||||
<color>
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>NormalColor</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>Mod/Drawing/Colors</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="lbl_PreSelect">
|
||||
<property name="text">
|
||||
<string>PreSelected</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lbl_Normal">
|
||||
<property name="text">
|
||||
<string>Normal</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="lbl_Hidden">
|
||||
<property name="text">
|
||||
<string>Hidden</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="lbl_Select">
|
||||
<property name="text">
|
||||
<string>Selected</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="Gui::PrefColorButton" name="pcb_PreSelect">
|
||||
<property name="color">
|
||||
<color>
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
<blue>20</blue>
|
||||
</color>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>PreSelectColor</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>Mod/Drawing/Colors</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="gb_Font">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Font</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="gridLayoutWidget_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>30</y>
|
||||
<width>301</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="lbl_LabelFont">
|
||||
<property name="text">
|
||||
<string>Label Font</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="Gui::PrefLineEdit" name="le_LabelFont">
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>LabelFont</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>Mod/Drawing</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="gb_Templates">
|
||||
<property name="title">
|
||||
<string>Templates</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="gridLayoutWidget_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>30</y>
|
||||
<width>531</width>
|
||||
<height>80</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="1" column="2">
|
||||
<widget class="Gui::PrefFileChooser" name="pfc_DefDir">
|
||||
<property name="mode">
|
||||
<enum>Gui::FileChooser::Directory</enum>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>TemplateDir</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>/Mod/Drawing</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Default Template</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Template Directory</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="Gui::PrefLineEdit" name="le_DefTemplate">
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>TemplateFile</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>Mod/Drawing</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Gui::FileChooser</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>Gui/FileDialog.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Gui::ColorButton</class>
|
||||
<extends>QPushButton</extends>
|
||||
<header>Gui/Widgets.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Gui::PrefFileChooser</class>
|
||||
<extends>Gui::FileChooser</extends>
|
||||
<header>Gui/PrefWidgets.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Gui::PrefColorButton</class>
|
||||
<extends>Gui::ColorButton</extends>
|
||||
<header>Gui/PrefWidgets.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Gui::PrefLineEdit</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header>Gui/PrefWidgets.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
79
src/Mod/TechDraw/Gui/DlgPrefsDrawingImp.cpp
Normal file
79
src/Mod/TechDraw/Gui/DlgPrefsDrawingImp.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2015 FreeCAD Developers *
|
||||
* Author: WandererFan <wandererfan@gmail.com> *
|
||||
* 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 <Gui/PrefWidgets.h>
|
||||
|
||||
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"
|
||||
50
src/Mod/TechDraw/Gui/DlgPrefsDrawingImp.h
Normal file
50
src/Mod/TechDraw/Gui/DlgPrefsDrawingImp.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/**************************************************************************
|
||||
* Copyright (c) 2015 FreeCAD Developers *
|
||||
* Author: WandererFan <wandererfan@gmail.com> *
|
||||
* 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 <Gui/PropertyPage.h>
|
||||
|
||||
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
|
||||
1099
src/Mod/TechDraw/Gui/MDIViewPage.cpp
Normal file
1099
src/Mod/TechDraw/Gui/MDIViewPage.cpp
Normal file
File diff suppressed because it is too large
Load Diff
129
src/Mod/TechDraw/Gui/MDIViewPage.h
Normal file
129
src/Mod/TechDraw/Gui/MDIViewPage.h
Normal file
@@ -0,0 +1,129 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2007 Jürgen Riegel <juergen.riegel@web.de> *
|
||||
* *
|
||||
* 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 <Gui/MDIView.h>
|
||||
#include <Gui/Selection.h>
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QPrinter>
|
||||
|
||||
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<App::DocumentObject*> &list, std::vector<App::DocumentObject*> &missing);
|
||||
bool hasQView(App::DocumentObject *obj);
|
||||
bool orphanExists(const char *viewName, const std::vector<App::DocumentObject*> &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<QGIView *> deleteItems;
|
||||
};
|
||||
|
||||
|
||||
} // namespace MDIViewPageGui
|
||||
|
||||
#endif // DRAWINGGUI_DRAWINGVIEW_H
|
||||
24
src/Mod/TechDraw/Gui/PreCompiled.cpp
Normal file
24
src/Mod/TechDraw/Gui/PreCompiled.cpp
Normal file
@@ -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"
|
||||
78
src/Mod/TechDraw/Gui/PreCompiled.h
Normal file
78
src/Mod/TechDraw/Gui/PreCompiled.h
Normal file
@@ -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 <FCConfig.h>
|
||||
|
||||
// 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 <Python.h>
|
||||
|
||||
// standard
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
|
||||
// STL
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
#include <stack>
|
||||
#include <queue>
|
||||
#include <bitset>
|
||||
|
||||
#ifdef FC_OS_WIN32
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
// Qt Toolkit
|
||||
#ifndef __Qt4All__
|
||||
# include <Gui/Qt4All.h>
|
||||
#endif
|
||||
|
||||
#endif //_PreComp_
|
||||
|
||||
#endif // DRAWINGGUI_PRECOMPILED_H
|
||||
103
src/Mod/TechDraw/Gui/QGCustomClip.cpp
Normal file
103
src/Mod/TechDraw/Gui/QGCustomClip.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2015 WandererFan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <assert.h>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Material.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
|
||||
#include <qmath.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
66
src/Mod/TechDraw/Gui/QGCustomClip.h
Normal file
66
src/Mod/TechDraw/Gui/QGCustomClip.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2015 WandererFan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef DRAWINGGUI_QGCUSTOMCLIP_H
|
||||
#define DRAWINGGUI_QGCUSTOMCLIP_H
|
||||
|
||||
#include <QGI>
|
||||
#include <QPointF>
|
||||
#include <QRectF>
|
||||
|
||||
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
|
||||
|
||||
76
src/Mod/TechDraw/Gui/QGCustomRect.cpp
Normal file
76
src/Mod/TechDraw/Gui/QGCustomRect.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2015 WandererFan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <assert.h>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Material.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
|
||||
#include <qmath.h>
|
||||
#include <QRectF>
|
||||
#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);
|
||||
}
|
||||
|
||||
60
src/Mod/TechDraw/Gui/QGCustomRect.h
Normal file
60
src/Mod/TechDraw/Gui/QGCustomRect.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2015 WandererFan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef DRAWINGGUI_QGCUSTOMRECT_H
|
||||
#define DRAWINGGUI_QGCUSTOMRECT_H
|
||||
|
||||
#include <QGI>
|
||||
#include <QGraphicsRectItem>
|
||||
#include <QPointF>
|
||||
|
||||
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
|
||||
|
||||
65
src/Mod/TechDraw/Gui/QGCustomSvg.cpp
Normal file
65
src/Mod/TechDraw/Gui/QGCustomSvg.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2015 WandererFan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#endif
|
||||
|
||||
#include <QRectF>
|
||||
#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);
|
||||
}
|
||||
|
||||
60
src/Mod/TechDraw/Gui/QGCustomSvg.h
Normal file
60
src/Mod/TechDraw/Gui/QGCustomSvg.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2015 WandererFan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef DRAWINGGUI_QGCUSTOMSVG_H
|
||||
#define DRAWINGGUI_QGCUSTOMSVG_H
|
||||
|
||||
#include <QGI>
|
||||
#include <QGraphicsSvgItem>
|
||||
#include <QPointF>
|
||||
|
||||
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
|
||||
|
||||
103
src/Mod/TechDraw/Gui/QGCustomText.cpp
Normal file
103
src/Mod/TechDraw/Gui/QGCustomText.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2015 WandererFan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <assert.h>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QPaintDevice>
|
||||
#include <QPainter>
|
||||
#include <QPrinter>
|
||||
#include <QSvgGenerator>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Material.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
|
||||
#include <qmath.h>
|
||||
#include <QRectF>
|
||||
#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<QPrinter*>(hw); //printer does not rescale vs screen?
|
||||
QSvgGenerator* svg = dynamic_cast<QSvgGenerator*>(hw);
|
||||
if (svg) {
|
||||
painter->scale(svgScale,svgScale);
|
||||
painter->translate(svgMove);
|
||||
} else {
|
||||
painter->scale(1.0,1.0);
|
||||
}
|
||||
|
||||
QGraphicsTextItem::paint (painter, &myOption, widget);
|
||||
}
|
||||
60
src/Mod/TechDraw/Gui/QGCustomText.h
Normal file
60
src/Mod/TechDraw/Gui/QGCustomText.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2015 WandererFan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef DRAWINGGUI_QGCUSTOMTEXT_H
|
||||
#define DRAWINGGUI_QGCUSTOMTEXT_H
|
||||
|
||||
#include <QGI>
|
||||
#include <QGraphicsTextItem>
|
||||
#include <QPointF>
|
||||
|
||||
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
|
||||
|
||||
112
src/Mod/TechDraw/Gui/QGIArrow.cpp
Normal file
112
src/Mod/TechDraw/Gui/QGIArrow.cpp
Normal file
@@ -0,0 +1,112 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <assert.h>
|
||||
#include <QGraphicsScene>
|
||||
#include <QMenu>
|
||||
#include <QMouseEvent>
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#include <QPainterPathStroker>
|
||||
#include <QPainter>
|
||||
#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);
|
||||
}
|
||||
70
src/Mod/TechDraw/Gui/QGIArrow.h
Normal file
70
src/Mod/TechDraw/Gui/QGIArrow.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QGI>
|
||||
|
||||
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
|
||||
135
src/Mod/TechDraw/Gui/QGIDrawingTemplate.cpp
Normal file
135
src/Mod/TechDraw/Gui/QGIDrawingTemplate.cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012-2014 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QAction>
|
||||
# include <QContextMenuEvent>
|
||||
# include <QGraphicsScene>
|
||||
# include <QGraphicsSceneMouseEvent>
|
||||
# include <QMenu>
|
||||
# include <QMessageBox>
|
||||
# include <QMouseEvent>
|
||||
# include <QPainter>
|
||||
# include <strstream>
|
||||
#endif
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Tools2D.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/Command.h>
|
||||
|
||||
#include <Mod/Drawing/App/Geometry.h>
|
||||
#include <Mod/Drawing/App/DrawParametricTemplate.h>
|
||||
|
||||
#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<TechDraw::DrawParametricTemplate *>(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<DrawingGeometry::BaseGeom *> &geoms = tmplte->getGeometry();
|
||||
|
||||
std::vector<DrawingGeometry::BaseGeom *>::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<DrawingGeometry::Generic *>(*it);
|
||||
|
||||
path.moveTo(geom->points[0].fX, geom->points[0].fY);
|
||||
std::vector<Base::Vector2D>::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"
|
||||
69
src/Mod/TechDraw/Gui/QGIDrawingTemplate.h
Normal file
69
src/Mod/TechDraw/Gui/QGIDrawingTemplate.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012-2014 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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
|
||||
179
src/Mod/TechDraw/Gui/QGIEdge.cpp
Normal file
179
src/Mod/TechDraw/Gui/QGIEdge.cpp
Normal file
@@ -0,0 +1,179 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <assert.h>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QPainterPathStroker>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Material.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
|
||||
#include <qmath.h>
|
||||
#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<ParameterGrp> 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<QGIView *> (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);
|
||||
}
|
||||
95
src/Mod/TechDraw/Gui/QGIEdge.h
Normal file
95
src/Mod/TechDraw/Gui/QGIEdge.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QGI>
|
||||
|
||||
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
|
||||
126
src/Mod/TechDraw/Gui/QGIFace.cpp
Normal file
126
src/Mod/TechDraw/Gui/QGIFace.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QAction>
|
||||
#include <QApplication>
|
||||
#include <QContextMenuEvent>
|
||||
#include <QGraphicsScene>
|
||||
#include <QMouseEvent>
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QPainterPathStroker>
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Material.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
|
||||
#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<ParameterGrp> 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<QGIView *> (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);
|
||||
}
|
||||
|
||||
79
src/Mod/TechDraw/Gui/QGIFace.h
Normal file
79
src/Mod/TechDraw/Gui/QGIFace.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <Qt>
|
||||
#include <QGI>
|
||||
|
||||
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
|
||||
193
src/Mod/TechDraw/Gui/QGIHatch.cpp
Normal file
193
src/Mod/TechDraw/Gui/QGIHatch.cpp
Normal file
@@ -0,0 +1,193 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2015 WandererFan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <QPainterPathStroker>
|
||||
# include <QPainter>
|
||||
# include <strstream>
|
||||
# include <math.h>
|
||||
# include <QGraphicsPathItem>
|
||||
# include <QGraphicsTextItem>
|
||||
#endif
|
||||
|
||||
#include <QBitmap>
|
||||
#include <QImage>
|
||||
#include <QPainter>
|
||||
#include <QString>
|
||||
#include <QSvgRenderer>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Material.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Gui/Command.h>
|
||||
|
||||
#include <Mod/Drawing/App/DrawHatch.h>
|
||||
#include <Mod/Drawing/App/DrawViewPart.h>
|
||||
|
||||
#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<ParameterGrp> 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<App::DocumentObject*> &objects = hatch->Edges.getValues();
|
||||
//const std::vector<std::string> &SubNames = hatch->Edges.getSubValues();
|
||||
//const TechDraw::DrawViewPart *refObj = static_cast<const TechDraw::DrawViewPart*>(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<QGIView *> (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);
|
||||
}
|
||||
93
src/Mod/TechDraw/Gui/QGIHatch.h
Normal file
93
src/Mod/TechDraw/Gui/QGIHatch.h
Normal file
@@ -0,0 +1,93 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2015 WandererFan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef DRAWINGGUI_QGRAPHICSITEMHATCH_H
|
||||
#define DRAWINGGUI_QGRAPHICSITEMHATCH_H
|
||||
|
||||
#include <Qt>
|
||||
#include <QGI>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#include <QBitmap>
|
||||
|
||||
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
|
||||
231
src/Mod/TechDraw/Gui/QGIProjGroup.cpp
Normal file
231
src/Mod/TechDraw/Gui/QGIProjGroup.cpp
Normal file
@@ -0,0 +1,231 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012-2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QAction>
|
||||
# include <QContextMenuEvent>
|
||||
# include <QGraphicsScene>
|
||||
# include <QGraphicsSceneMouseEvent>
|
||||
# include <QList>
|
||||
# include <QMenu>
|
||||
# include <QMessageBox>
|
||||
# include <QMouseEvent>
|
||||
# include <QPainter>
|
||||
# include <strstream>
|
||||
#endif
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/Command.h>
|
||||
|
||||
#include <Mod/Drawing/App/DrawProjGroupItem.h>
|
||||
#include <Mod/Drawing/App/DrawProjGroup.h>
|
||||
|
||||
#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<TechDraw::DrawProjGroup *>(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<QGraphicsSceneMouseEvent*>(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<QGI*>();
|
||||
QGIView* gView = dynamic_cast<QGIView *>(childItem);
|
||||
if(gView) {
|
||||
TechDraw::DrawView *fView = gView->getViewObject();
|
||||
if(fView->getTypeId().isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) {
|
||||
TechDraw::DrawProjGroupItem *projItemPtr = static_cast<TechDraw::DrawProjGroupItem *>(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<TechDraw::DrawProjGroup *>(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<TechDraw::DrawView *>(anchorObj);
|
||||
|
||||
// Locate the anchor view's qgraphicsitemview
|
||||
QList<QGI *> list = childItems();
|
||||
|
||||
for (QList<QGI *>::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
QGIView *view = dynamic_cast<QGIView *>(*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"
|
||||
84
src/Mod/TechDraw/Gui/QGIProjGroup.h
Normal file
84
src/Mod/TechDraw/Gui/QGIProjGroup.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012-2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QGIGroup>
|
||||
#include <QObject>
|
||||
#include <App/PropertyLinks.h>
|
||||
|
||||
#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
|
||||
227
src/Mod/TechDraw/Gui/QGISVGTemplate.cpp
Normal file
227
src/Mod/TechDraw/Gui/QGISVGTemplate.cpp
Normal file
@@ -0,0 +1,227 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012-2014 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QFile>
|
||||
#include <QFont>
|
||||
#include <QPen>
|
||||
#include <QSvgRenderer>
|
||||
#include <QGraphicsSvgItem>
|
||||
#include <strstream>
|
||||
#include <boost/regex.hpp>
|
||||
#endif // #ifndef _PreComp_
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Gui/Command.h>
|
||||
|
||||
#include <Mod/Drawing/App/Geometry.h>
|
||||
#include <Mod/Drawing/App/DrawSVGTemplate.h>
|
||||
|
||||
#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<TemplateTextField *>::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("<!-- DrawingContent -->") == 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("<text([^>]*freecad:editable=[^>]*)>[^<]*<tspan[^>]*>([^<]*)</tspan>");
|
||||
|
||||
// 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<std::string::const_iterator> 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<TechDraw::DrawSVGTemplate *>(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"
|
||||
74
src/Mod/TechDraw/Gui/QGISVGTemplate.h
Normal file
74
src/Mod/TechDraw/Gui/QGISVGTemplate.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012-2014 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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
|
||||
75
src/Mod/TechDraw/Gui/QGITemplate.cpp
Normal file
75
src/Mod/TechDraw/Gui/QGITemplate.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012-2014 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QGraphicsScene>
|
||||
#endif
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Exception.h>
|
||||
|
||||
#include <Mod/Drawing/App/DrawTemplate.h>
|
||||
|
||||
#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"
|
||||
73
src/Mod/TechDraw/Gui/QGITemplate.h
Normal file
73
src/Mod/TechDraw/Gui/QGITemplate.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012-2014 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QGIGroup>
|
||||
#include <QObject>
|
||||
|
||||
#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<TemplateTextField *> textFields;
|
||||
};
|
||||
|
||||
} // namespace MDIViewPageGui
|
||||
|
||||
#endif // DRAWINGGUI_QGRAPHICSITEMTEMPLATE_H
|
||||
134
src/Mod/TechDraw/Gui/QGIVertex.cpp
Normal file
134
src/Mod/TechDraw/Gui/QGIVertex.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <assert.h>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Material.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
|
||||
#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<ParameterGrp> 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<QGIView *> (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);
|
||||
}
|
||||
|
||||
|
||||
89
src/Mod/TechDraw/Gui/QGIVertex.h
Normal file
89
src/Mod/TechDraw/Gui/QGIVertex.h
Normal file
@@ -0,0 +1,89 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QGI>
|
||||
|
||||
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
|
||||
|
||||
379
src/Mod/TechDraw/Gui/QGIView.cpp
Normal file
379
src/Mod/TechDraw/Gui/QGIView.cpp
Normal file
@@ -0,0 +1,379 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012-2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QAction>
|
||||
#include <QApplication>
|
||||
#include <QContextMenuEvent>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QPainterPathStroker>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#include <QTextOption>
|
||||
#include <QTransform>
|
||||
#include <strstream>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/Material.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/Command.h>
|
||||
|
||||
#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<ParameterGrp> 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<QGCustomClip*>(parentItem());
|
||||
if (parentClip) {
|
||||
QGIViewClip* parentView = dynamic_cast<QGIViewClip*>(parentClip->parentItem());
|
||||
TechDraw::DrawViewClip* parentFeat = dynamic_cast<TechDraw::DrawViewClip*>(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<QGI *> children = childItems();
|
||||
int dimItemType = QGI::UserType + 106;
|
||||
QRectF result;
|
||||
for (QList<QGI *>::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"
|
||||
112
src/Mod/TechDraw/Gui/QGIView.h
Normal file
112
src/Mod/TechDraw/Gui/QGIView.h
Normal file
@@ -0,0 +1,112 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012-2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QGIGroup>
|
||||
#include <QObject>
|
||||
#include <App/PropertyLinks.h>
|
||||
|
||||
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<QString, QGI *> 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
|
||||
149
src/Mod/TechDraw/Gui/QGIViewAnnotation.cpp
Normal file
149
src/Mod/TechDraw/Gui/QGIViewAnnotation.cpp
Normal file
@@ -0,0 +1,149 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* 2014 wandererfan <WandererFan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <cmath>
|
||||
#include <QGraphicsScene>
|
||||
#include <QMouseEvent>
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QGI>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#include <QGraphicsTextItem>
|
||||
#include <QPainterPathStroker>
|
||||
#include <QPainter>
|
||||
#include <QString>
|
||||
#include <QTextOption>
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
#include <qmath.h>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Material.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
|
||||
#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<TechDraw::DrawView *>(obj));
|
||||
}
|
||||
|
||||
void QGIViewAnnotation::updateView(bool update)
|
||||
{
|
||||
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId()))
|
||||
return;
|
||||
|
||||
TechDraw::DrawViewAnnotation *viewAnno = dynamic_cast<TechDraw::DrawViewAnnotation *>(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<TechDraw::DrawViewAnnotation *>(getViewObject());
|
||||
|
||||
// get the Text values
|
||||
const std::vector<std::string>& annoText = viewAnno->Text.getValues();
|
||||
std::stringstream ss;
|
||||
for(std::vector<std::string>::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"
|
||||
|
||||
75
src/Mod/TechDraw/Gui/QGIViewAnnotation.h
Normal file
75
src/Mod/TechDraw/Gui/QGIViewAnnotation.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* 2014 wandererfan <WandererFan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef DRAWINGGUI_QGRAPHICSITEMVIEWANNOTATION_H
|
||||
#define DRAWINGGUI_QGRAPHICSITEMVIEWANNOTATION_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QPainter>
|
||||
|
||||
#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
|
||||
192
src/Mod/TechDraw/Gui/QGIViewClip.cpp
Normal file
192
src/Mod/TechDraw/Gui/QGIViewClip.cpp
Normal file
@@ -0,0 +1,192 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* 2014 wandererfan <WandererFan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <cmath>
|
||||
#include <QGraphicsScene>
|
||||
#include <QMouseEvent>
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QGI>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#include <QGraphicsTextItem>
|
||||
#include <QPainterPathStroker>
|
||||
#include <QPainter>
|
||||
#include <QString>
|
||||
#include <QTextOption>
|
||||
#include <sstream>
|
||||
#include <algorithm> // std::find
|
||||
#endif
|
||||
|
||||
#include <qmath.h>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Material.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
|
||||
#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<TechDraw::DrawViewClip *>(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<TechDraw::DrawViewClip *>(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<std::string> childNames = viewClip->getChildViewNames();
|
||||
//for all child Views in Clip, add the graphics representation of the View to the Clip group
|
||||
for(std::vector<std::string>::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<QGI *> qgItems = m_cliparea->childItems();
|
||||
QList<QGI *>::iterator it = qgItems.begin();
|
||||
for (; it != qgItems.end(); it++) {
|
||||
QGIView* qv = dynamic_cast<QGIView*>((*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<QGI *> qgItems = scene()->items();
|
||||
QList<QGI *>::iterator it = qgItems.begin();
|
||||
for (; it != qgItems.end(); it++) {
|
||||
QGIView* qv = dynamic_cast<QGIView*>((*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"
|
||||
|
||||
74
src/Mod/TechDraw/Gui/QGIViewClip.h
Normal file
74
src/Mod/TechDraw/Gui/QGIViewClip.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QObject>
|
||||
#include <QPainter>
|
||||
|
||||
#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
|
||||
88
src/Mod/TechDraw/Gui/QGIViewCollection.cpp
Normal file
88
src/Mod/TechDraw/Gui/QGIViewCollection.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012-2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QAction>
|
||||
# include <QContextMenuEvent>
|
||||
# include <QGraphicsScene>
|
||||
# include <QGraphicsSceneMouseEvent>
|
||||
# include <QMenu>
|
||||
# include <QMessageBox>
|
||||
# include <QMouseEvent>
|
||||
# include <QPainter>
|
||||
# include <strstream>
|
||||
#endif
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/Command.h>
|
||||
|
||||
#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"
|
||||
69
src/Mod/TechDraw/Gui/QGIViewCollection.h
Normal file
69
src/Mod/TechDraw/Gui/QGIViewCollection.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012-2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QGIGroup>
|
||||
#include <QObject>
|
||||
#include <App/PropertyLinks.h>
|
||||
|
||||
#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
|
||||
1263
src/Mod/TechDraw/Gui/QGIViewDimension.cpp
Normal file
1263
src/Mod/TechDraw/Gui/QGIViewDimension.cpp
Normal file
File diff suppressed because it is too large
Load Diff
133
src/Mod/TechDraw/Gui/QGIViewDimension.h
Normal file
133
src/Mod/TechDraw/Gui/QGIViewDimension.h
Normal file
@@ -0,0 +1,133 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QObject>
|
||||
#include <QGraphicsView>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#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<QGI *> arw; //arrowheads
|
||||
std::vector<DrawingGeometry::BaseGeom *> projGeom;
|
||||
QPen pen;
|
||||
QColor m_colNormal;
|
||||
QColor m_colPre;
|
||||
QColor m_colSel;
|
||||
};
|
||||
|
||||
} // namespace MDIViewPageGui
|
||||
|
||||
#endif // DRAWINGGUI_QGRAPHICSITEMVIEWDIMENSION_H
|
||||
654
src/Mod/TechDraw/Gui/QGIViewPart.cpp
Normal file
654
src/Mod/TechDraw/Gui/QGIViewPart.cpp
Normal file
@@ -0,0 +1,654 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <cmath>
|
||||
#include <qmath.h>
|
||||
#include <strstream>
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QContextMenuEvent>
|
||||
#include <QGraphicsScene>
|
||||
#include <QMenu>
|
||||
#include <QMouseEvent>
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QPainterPathStroker>
|
||||
#include <QPainter>
|
||||
#include <QTextOption>
|
||||
#endif // #ifndef _PreComp_
|
||||
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/Material.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
|
||||
#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<ParameterGrp> 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<QGI *> items = childItems();
|
||||
for(QList<QGI *>::iterator it = items.begin(); it != items.end(); ++it) {
|
||||
QGIEdge *edge = dynamic_cast<QGIEdge *>(*it);
|
||||
QGIVertex *vert = dynamic_cast<QGIVertex *>(*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<QGI *>::iterator it = deleteItems.begin(); it != deleteItems.end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
deleteItems.clear();
|
||||
}
|
||||
|
||||
void QGIViewPart::setViewPartFeature(TechDraw::DrawViewPart *obj)
|
||||
{
|
||||
// called from QGVPage
|
||||
setViewFeature(static_cast<TechDraw::DrawView *>(obj));
|
||||
}
|
||||
|
||||
QPainterPath QGIViewPart::drawPainterPath(DrawingGeometry::BaseGeom *baseGeom) const
|
||||
{
|
||||
QPainterPath path;
|
||||
|
||||
switch(baseGeom->geomType) {
|
||||
case DrawingGeometry::CIRCLE: {
|
||||
DrawingGeometry::Circle *geom = static_cast<DrawingGeometry::Circle *>(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<DrawingGeometry::AOC *>(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<DrawingGeometry::Ellipse *>(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<DrawingGeometry::AOE *>(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<DrawingGeometry::BSpline *>(baseGeom);
|
||||
|
||||
std::vector<DrawingGeometry::BezierSegment>::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<DrawingGeometry::Generic *>(baseGeom);
|
||||
|
||||
path.moveTo(geom->points[0].fX, geom->points[0].fY);
|
||||
std::vector<Base::Vector2D>::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<TechDraw::DrawViewPart *>(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<QGI *> items = childItems();
|
||||
for(QList<QGI *>::iterator it = items.begin(); it != items.end(); ++it) {
|
||||
if (dynamic_cast<QGIEdge *> (*it) ||
|
||||
dynamic_cast<QGIFace *>(*it) ||
|
||||
dynamic_cast<QGIVertex *>(*it) ||
|
||||
dynamic_cast<QGIHatch *>(*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<QGI *> items = childItems();
|
||||
for(QList<QGI *>::iterator it = items.begin(); it != items.end(); ++it) {
|
||||
QGIEdge *edge = dynamic_cast<QGIEdge *>(*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<TechDraw::DrawViewPart *>(getViewObject());
|
||||
|
||||
float lineWidth = viewPart->LineWidth.getValue() * lineScaleFactor;
|
||||
float lineWidthHid = viewPart->HiddenWidth.getValue() * lineScaleFactor;
|
||||
|
||||
prepareGeometryChange();
|
||||
|
||||
#if MOD_TECHDRAW_HANDLE_FACES
|
||||
// Draw Faces
|
||||
const std::vector<DrawingGeometry::Face *> &faceGeoms = part->getFaceGeometry();
|
||||
const std::vector<int> &faceRefs = part->getFaceReferences();
|
||||
std::vector<DrawingGeometry::Face *>::const_iterator fit = faceGeoms.begin();
|
||||
QGIFace* face;
|
||||
QPen facePen;
|
||||
for(int i = 0 ; fit != faceGeoms.end(); fit++, i++) {
|
||||
std::vector<DrawingGeometry::Wire *> faceWires = (*fit)->wires;
|
||||
QPainterPath facePath;
|
||||
for(std::vector<DrawingGeometry::Wire *>::iterator wire = faceWires.begin(); wire != faceWires.end(); wire++) {
|
||||
QPainterPath wirePath;
|
||||
QPointF shapePos;
|
||||
for(std::vector<DrawingGeometry::BaseGeom *>::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<TechDraw::DrawHatch*> hatchObjs = viewPart->getHatches();
|
||||
if (!hatchObjs.empty()) {
|
||||
std::vector<TechDraw::DrawHatch*>::iterator itHatch = hatchObjs.begin();
|
||||
for(; itHatch != hatchObjs.end(); itHatch++) {
|
||||
//if hatchdirection == viewPartdirection {
|
||||
TechDraw::DrawHatch* feat = (*itHatch);
|
||||
const std::vector<std::string> &edgeNames = feat->Edges.getSubValues();
|
||||
std::vector<std::string>::const_iterator itEdge = edgeNames.begin();
|
||||
std::vector<DrawingGeometry::BaseGeom*> 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<DrawingGeometry::BaseGeom*> chained = DrawingGeometry::chainGeoms(unChained);
|
||||
|
||||
//iterate through the chain to make QPainterPath
|
||||
std::vector<DrawingGeometry::BaseGeom*>::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<DrawingGeometry::BaseGeom *> &geoms = viewPart->getEdgeGeometry();
|
||||
const std::vector<int> &refs = viewPart->getEdgeReferences();
|
||||
std::vector<DrawingGeometry::BaseGeom *>::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<DrawingGeometry::Vertex *> &verts = viewPart->getVertexGeometry();
|
||||
const std::vector<int> &vertRefs = viewPart->getVertexReferences();
|
||||
std::vector<DrawingGeometry::Vertex *>::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<TechDraw::DrawHatch*> QGIViewPart::getHatchesForView(TechDraw::DrawViewPart* viewPart)
|
||||
{
|
||||
std::vector<App::DocumentObject*> docObjs = viewPart->getDocument()->getObjectsOfType(TechDraw::DrawHatch::getClassTypeId());
|
||||
std::vector<TechDraw::DrawHatch*> hatchObjs;
|
||||
std::string viewName = viewPart->getNameInDocument();
|
||||
std::vector<App::DocumentObject*>::iterator itDoc = docObjs.begin();
|
||||
for(; itDoc != docObjs.end(); itDoc++) {
|
||||
TechDraw::DrawHatch* hatch = dynamic_cast<TechDraw::DrawHatch*>(*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<QGI *> items = childItems();
|
||||
for(QList<QGI *>::iterator it = items.begin(); it != items.end(); it++) {
|
||||
QGIEdge *edge = dynamic_cast<QGIEdge *>(*it);
|
||||
if(edge && edge->getReference() == idx)
|
||||
return edge;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
QGIVertex * QGIViewPart::findRefVertex(int idx)
|
||||
{
|
||||
QList<QGI *> items = childItems();
|
||||
for(QList<QGI *>::iterator it = items.begin(); it != items.end(); it++) {
|
||||
QGIVertex *vert = dynamic_cast<QGIVertex *>(*it);
|
||||
if(vert && vert->getReference() == idx)
|
||||
return vert;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void QGIViewPart::toggleCache(bool state)
|
||||
{
|
||||
QList<QGI *> items = childItems();
|
||||
for(QList<QGI *>::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<QGI *> items = childItems();
|
||||
for(QList<QGI *>::iterator it = items.begin(); it != items.end(); it++) {
|
||||
QGIEdge *edge = dynamic_cast<QGIEdge *>(*it);
|
||||
if(edge) {
|
||||
edge->setCosmetic(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QGIViewPart::toggleVertices(bool state)
|
||||
{
|
||||
QList<QGI *> items = childItems();
|
||||
for(QList<QGI *>::iterator it = items.begin(); it != items.end(); it++) {
|
||||
QGIVertex *vert = dynamic_cast<QGIVertex *>(*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"
|
||||
109
src/Mod/TechDraw/Gui/QGIViewPart.h
Normal file
109
src/Mod/TechDraw/Gui/QGIViewPart.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QObject>
|
||||
#include <QPainter>
|
||||
|
||||
#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 <TechDraw::DrawHatch *> getHatchesForView(TechDraw::DrawViewPart* viewPart);
|
||||
void drawViewPart();
|
||||
|
||||
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
|
||||
protected:
|
||||
QColor m_colHid;
|
||||
|
||||
private:
|
||||
QList<QGI *> deleteItems;
|
||||
};
|
||||
|
||||
} // namespace MDIViewPageGui
|
||||
|
||||
#endif // DRAWINGGUI_QGRAPHICSITEMVIEWPART_H
|
||||
154
src/Mod/TechDraw/Gui/QGIViewSection.cpp
Normal file
154
src/Mod/TechDraw/Gui/QGIViewSection.cpp
Normal file
@@ -0,0 +1,154 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <cmath>
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QContextMenuEvent>
|
||||
#include <QGraphicsScene>
|
||||
#include <QMenu>
|
||||
#include <QMouseEvent>
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QPainterPathStroker>
|
||||
#include <QPainter>
|
||||
#include <QTextOption>
|
||||
#include <strstream>
|
||||
#endif
|
||||
|
||||
#include <qmath.h>
|
||||
|
||||
#include <Base/Console.h>
|
||||
|
||||
#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<TechDraw::DrawViewSection *>(getViewObject());
|
||||
if (!part->hasGeometry()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Base::Console().Log("drawing section face\n");
|
||||
|
||||
// Get the section face from the feature
|
||||
std::vector<DrawingGeometry::Face *> 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<DrawingGeometry::Face *>::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<DrawingGeometry::Wire *> faceWires = (*fit)->wires;
|
||||
QPainterPath facePath;
|
||||
for(std::vector<DrawingGeometry::Wire *>::iterator wire = faceWires.begin(); wire != faceWires.end(); ++wire) {
|
||||
QPainterPath wirePath;
|
||||
QPointF shapePos;
|
||||
for(std::vector<DrawingGeometry::BaseGeom *>::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<QGI *>(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<TechDraw::DrawViewSection *>(getViewObject());
|
||||
|
||||
if(update ||
|
||||
viewPart->SectionNormal.isTouched() ||
|
||||
viewPart->SectionOrigin.isTouched()) {
|
||||
QGIViewPart::updateView(true);
|
||||
} else {
|
||||
QGIViewPart::updateView();
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_QGIViewSection.cpp"
|
||||
62
src/Mod/TechDraw/Gui/QGIViewSection.h
Normal file
62
src/Mod/TechDraw/Gui/QGIViewSection.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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
|
||||
138
src/Mod/TechDraw/Gui/QGIViewSymbol.cpp
Normal file
138
src/Mod/TechDraw/Gui/QGIViewSymbol.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* 2014 wandererfan <WandererFan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <cmath>
|
||||
#include <QGI>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QMenu>
|
||||
#include <QMouseEvent>
|
||||
#include <QString>
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
#include <qmath.h>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Material.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
|
||||
#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<TechDraw::DrawView *>(obj));
|
||||
}
|
||||
|
||||
void QGIViewSymbol::updateView(bool update)
|
||||
{
|
||||
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewSymbol::getClassTypeId()))
|
||||
return;
|
||||
|
||||
TechDraw::DrawViewSymbol *viewSymbol = dynamic_cast<TechDraw::DrawViewSymbol *>(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<TechDraw::DrawViewSymbol *>(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"
|
||||
|
||||
77
src/Mod/TechDraw/Gui/QGIViewSymbol.h
Normal file
77
src/Mod/TechDraw/Gui/QGIViewSymbol.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* 2014 wandererfan <WandererFan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef DRAWINGGUI_QGRAPHICSITEMVIEWSYMBOL_H
|
||||
#define DRAWINGGUI_QGRAPHICSITEMVIEWSYMBOL_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QPainter>
|
||||
#include <QString>
|
||||
#include <QByteArray>
|
||||
#include <QSvgRenderer>
|
||||
#include <QGraphicsSvgItem>
|
||||
|
||||
#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
|
||||
529
src/Mod/TechDraw/Gui/QGVPage.cpp
Normal file
529
src/Mod/TechDraw/Gui/QGVPage.cpp
Normal file
@@ -0,0 +1,529 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QAction>
|
||||
# include <QApplication>
|
||||
# include <QContextMenuEvent>
|
||||
# include <QFileInfo>
|
||||
# include <QFileDialog>
|
||||
# include <QGLWidget>
|
||||
# include <QGraphicsScene>
|
||||
# include <QGraphicsSvgItem>
|
||||
# include <QGraphicsEffect>
|
||||
# include <QMouseEvent>
|
||||
# include <QPainter>
|
||||
# include <QPaintEvent>
|
||||
# include <QSvgRenderer>
|
||||
# include <QSvgWidget>
|
||||
# include <QWheelEvent>
|
||||
# include <strstream>
|
||||
# include <cmath>
|
||||
#endif
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Stream.h>
|
||||
#include <Gui/FileDialog.h>
|
||||
#include <Gui/WaitCursor.h>
|
||||
|
||||
#include <Mod/Drawing/App/Geometry.h>
|
||||
#include <Mod/Drawing/App/DrawPage.h>
|
||||
#include <Mod/Drawing/App/DrawTemplate.h>
|
||||
#include <Mod/Drawing/App/DrawSVGTemplate.h>
|
||||
#include <Mod/Drawing/App/DrawParametricTemplate.h>
|
||||
#include <Mod/Drawing/App/DrawViewCollection.h>
|
||||
#include <Mod/Drawing/App/DrawViewDimension.h>
|
||||
#include <Mod/Drawing/App/DrawProjGroup.h>
|
||||
#include <Mod/Drawing/App/DrawViewPart.h>
|
||||
#include <Mod/Drawing/App/DrawViewAnnotation.h>
|
||||
#include <Mod/Drawing/App/DrawViewSymbol.h>
|
||||
#include <Mod/Drawing/App/DrawViewClip.h>
|
||||
|
||||
#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<QGIView *> qviews = views;
|
||||
for(std::vector<QGIView *>::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<QGIView *> qviews = views;
|
||||
TechDraw::DrawView *myView = view->getViewObject();
|
||||
|
||||
//If type is dimension we check references first
|
||||
TechDraw::DrawViewDimension *dim = 0;
|
||||
dim = dynamic_cast<TechDraw::DrawViewDimension *>(myView);
|
||||
|
||||
if(dim) {
|
||||
std::vector<App::DocumentObject *> objs = dim->References.getValues();
|
||||
|
||||
if(objs.size() > 0) {
|
||||
std::vector<App::DocumentObject *> objs = dim->References.getValues();
|
||||
// Attach the dimension to the first object's group
|
||||
for(std::vector<QGIView *>::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<QGIView *>::const_iterator it = qviews.begin(); it != qviews.end(); ++it) {
|
||||
QGIViewCollection *grp = 0;
|
||||
grp = dynamic_cast<QGIViewCollection *>(*it);
|
||||
if(grp) {
|
||||
TechDraw::DrawViewCollection *collection = 0;
|
||||
collection = dynamic_cast<TechDraw::DrawViewCollection *>(grp->getViewObject());
|
||||
if(collection) {
|
||||
std::vector<App::DocumentObject *> objs = collection->Views.getValues();
|
||||
for( std::vector<App::DocumentObject *>::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<TechDraw::DrawParametricTemplate *>(obj);
|
||||
QGIDrawingTemplate *qTempItem = new QGIDrawingTemplate(scene());
|
||||
pageTemplate = qTempItem;
|
||||
} else if(obj->isDerivedFrom(TechDraw::DrawSVGTemplate::getClassTypeId())) {
|
||||
//TechDraw::DrawSVGTemplate *dwgTemplate = static_cast<TechDraw::DrawSVGTemplate *>(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<QGI *> list = scene()->items();
|
||||
|
||||
for (QList<QGI *>::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
QGIView *itemView = dynamic_cast<QGIView *>(*it);
|
||||
if(itemView) {
|
||||
QGIViewPart *viewPart = dynamic_cast<QGIViewPart *>(*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<QGI *>(*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"
|
||||
119
src/Mod/TechDraw/Gui/QGVPage.h
Normal file
119
src/Mod/TechDraw/Gui/QGVPage.h
Normal file
@@ -0,0 +1,119 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QGraphicsView>
|
||||
|
||||
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<QGIView *> & getViews() const { return views; }
|
||||
int addView(QGIView * view);
|
||||
void setViews(const std::vector<QGIView *> &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<QGIView *> 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
|
||||
413
src/Mod/TechDraw/Gui/TaskProjGroup.cpp
Normal file
413
src/Mod/TechDraw/Gui/TaskProjGroup.cpp
Normal file
@@ -0,0 +1,413 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2014 Joe Dowsett <dowsettjoe[at]yahoo[dot]co[dot]uk> *
|
||||
* Copyright (c) 2014 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <cmath>
|
||||
#endif // #ifndef _PreComp_
|
||||
|
||||
#include <Base/Console.h>
|
||||
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/Command.h>
|
||||
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
|
||||
#include <Mod/Drawing/App/DrawPage.h>
|
||||
#include <Mod/Drawing/App/DrawViewPart.h>
|
||||
|
||||
#include <Mod/Drawing/App/DrawProjGroupItem.h>
|
||||
#include <Mod/Drawing/App/DrawProjGroup.h>
|
||||
|
||||
#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<const ViewProviderProjGroup *>(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"
|
||||
|
||||
137
src/Mod/TechDraw/Gui/TaskProjGroup.h
Normal file
137
src/Mod/TechDraw/Gui/TaskProjGroup.h
Normal file
@@ -0,0 +1,137 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2011 Joe Dowsett <j-dowsett[at]users.sourceforge.net> *
|
||||
* Copyright (c) 2014 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <Base/BoundBox.h>
|
||||
#include <Gui/TaskView/TaskView.h>
|
||||
#include <Gui/TaskView/TaskDialog.h>
|
||||
|
||||
#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
|
||||
|
||||
362
src/Mod/TechDraw/Gui/TaskProjGroup.ui
Normal file
362
src/Mod/TechDraw/Gui/TaskProjGroup.ui
Normal file
@@ -0,0 +1,362 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TechDrawGui::TaskProjGroup</class>
|
||||
<widget class="QWidget" name="TechDrawGui::TaskProjGroup">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>342</width>
|
||||
<height>431</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>250</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Projection Group</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetDefaultConstraint</enum>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Projection</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="projection">
|
||||
<property name="editable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Document</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>First Angle</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Third Angle</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Scale</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="cmbScaleType">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Document</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Automatic</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Custom</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Custom Scale</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="scaleNum">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="scaleDenom"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>View From</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="2" column="2">
|
||||
<widget class="QPushButton" name="butCWRotate">
|
||||
<property name="text">
|
||||
<string>Spin CW</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QPushButton" name="butRightRotate">
|
||||
<property name="text">
|
||||
<string>></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QPushButton" name="butCCWRotate">
|
||||
<property name="text">
|
||||
<string>Spin CCW</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="butTopRotate">
|
||||
<property name="text">
|
||||
<string>/\</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<widget class="QPushButton" name="pushButton_8">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Match 3D</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QPushButton" name="butLeftRotate">
|
||||
<property name="text">
|
||||
<string><</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QPushButton" name="butDownRotate">
|
||||
<property name="text">
|
||||
<string>\/</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_8">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Secondary Projections</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="5" column="2">
|
||||
<widget class="QCheckBox" name="chkView8">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QCheckBox" name="chkView4">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="3">
|
||||
<widget class="QCheckBox" name="chkView5">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="5">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QCheckBox" name="chkView3">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QCheckBox" name="chkView7">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QCheckBox" name="chkView1">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="3">
|
||||
<widget class="QCheckBox" name="chkView9">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QCheckBox" name="chkView2">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="4">
|
||||
<widget class="QCheckBox" name="chkView6">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QCheckBox" name="chkView0">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
61
src/Mod/TechDraw/Gui/TemplateTextField.cpp
Normal file
61
src/Mod/TechDraw/Gui/TemplateTextField.cpp
Normal file
@@ -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<QInputDialog>
|
||||
#include<QLineEdit>
|
||||
#endif // #ifndef _PreCmp_
|
||||
|
||||
#include "TemplateTextField.h"
|
||||
|
||||
//#include<QDebug>
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
64
src/Mod/TechDraw/Gui/TemplateTextField.h
Normal file
64
src/Mod/TechDraw/Gui/TemplateTextField.h
Normal file
@@ -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 <QGraphicsRectItem>
|
||||
|
||||
#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
|
||||
|
||||
86
src/Mod/TechDraw/Gui/ViewProviderAnnotation.cpp
Normal file
86
src/Mod/TechDraw/Gui/ViewProviderAnnotation.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
|
||||
* Copyright (c) 2012 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Sequencer.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <Gui/SoFCSelection.h>
|
||||
#include <Gui/Selection.h>
|
||||
|
||||
#include <Mod/Drawing/App/DrawViewAnnotation.h>
|
||||
#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<std::string> ViewProviderAnnotation::getDisplayModes(void) const
|
||||
{
|
||||
// get the modes of the father
|
||||
std::vector<std::string> StrList = ViewProviderDocumentObject::getDisplayModes();
|
||||
|
||||
return StrList;
|
||||
}
|
||||
|
||||
void ViewProviderAnnotation::updateData(const App::Property*)
|
||||
{
|
||||
}
|
||||
|
||||
TechDraw::DrawViewAnnotation* ViewProviderAnnotation::getViewObject() const
|
||||
{
|
||||
return dynamic_cast<TechDraw::DrawViewAnnotation*>(pcObject);
|
||||
}
|
||||
61
src/Mod/TechDraw/Gui/ViewProviderAnnotation.h
Normal file
61
src/Mod/TechDraw/Gui/ViewProviderAnnotation.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
|
||||
* Copyright (c) 2012 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <Gui/ViewProviderFeature.h>
|
||||
|
||||
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<std::string> getDisplayModes(void) const;
|
||||
virtual void updateData(const App::Property*);
|
||||
|
||||
TechDraw::DrawViewAnnotation* getViewObject() const;
|
||||
};
|
||||
|
||||
} // namespace TechDrawGui
|
||||
|
||||
|
||||
#endif // DRAWINGGUI_VIEWPROVIDERANNOTATION_H
|
||||
86
src/Mod/TechDraw/Gui/ViewProviderDimension.cpp
Normal file
86
src/Mod/TechDraw/Gui/ViewProviderDimension.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
|
||||
* Copyright (c) 2012 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Sequencer.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <Gui/SoFCSelection.h>
|
||||
#include <Gui/Selection.h>
|
||||
|
||||
#include <Mod/Drawing/App/DrawViewDimension.h>
|
||||
#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<std::string> ViewProviderDimension::getDisplayModes(void) const
|
||||
{
|
||||
// get the modes of the father
|
||||
std::vector<std::string> StrList = ViewProviderView::getDisplayModes();
|
||||
|
||||
return StrList;
|
||||
}
|
||||
|
||||
void ViewProviderDimension::updateData(const App::Property*)
|
||||
{
|
||||
}
|
||||
|
||||
TechDraw::DrawViewDimension* ViewProviderDimension::getViewObject() const
|
||||
{
|
||||
return dynamic_cast<TechDraw::DrawViewDimension*>(pcObject);
|
||||
}
|
||||
62
src/Mod/TechDraw/Gui/ViewProviderDimension.h
Normal file
62
src/Mod/TechDraw/Gui/ViewProviderDimension.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
|
||||
* Copyright (c) 2012 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <Gui/ViewProviderFeature.h>
|
||||
#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<std::string> getDisplayModes(void) const;
|
||||
virtual void updateData(const App::Property*);
|
||||
|
||||
TechDraw::DrawViewDimension* getViewObject() const;
|
||||
};
|
||||
|
||||
} // namespace TechDrawGui
|
||||
|
||||
|
||||
#endif // DRAWINGGUI_VIEWPROVIDERDIMENSION_H
|
||||
86
src/Mod/TechDraw/Gui/ViewProviderHatch.cpp
Normal file
86
src/Mod/TechDraw/Gui/ViewProviderHatch.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
|
||||
* Copyright (c) 2015 Wandererfan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
#endif
|
||||
|
||||
/// Here the FreeCAD includes sorted by Base,App,Gui......
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Sequencer.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <Gui/SoFCSelection.h>
|
||||
#include <Gui/Selection.h>
|
||||
|
||||
#include <Mod/Drawing/App/DrawHatch.h>
|
||||
#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<std::string> ViewProviderHatch::getDisplayModes(void) const
|
||||
{
|
||||
// get the modes of the father
|
||||
std::vector<std::string> StrList = ViewProviderDocumentObject::getDisplayModes();
|
||||
|
||||
return StrList;
|
||||
}
|
||||
|
||||
void ViewProviderHatch::updateData(const App::Property*)
|
||||
{
|
||||
}
|
||||
|
||||
TechDraw::DrawHatch* ViewProviderHatch::getViewObject() const
|
||||
{
|
||||
return dynamic_cast<TechDraw::DrawHatch*>(pcObject);
|
||||
}
|
||||
61
src/Mod/TechDraw/Gui/ViewProviderHatch.h
Normal file
61
src/Mod/TechDraw/Gui/ViewProviderHatch.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
|
||||
* Copyright (c) 2015 Wandererfan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef DRAWINGGUI_VIEWPROVIDERHATCH_H
|
||||
#define DRAWINGGUI_VIEWPROVIDERHATCH_H
|
||||
|
||||
#include <Gui/ViewProviderFeature.h>
|
||||
|
||||
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<std::string> getDisplayModes(void) const;
|
||||
virtual void updateData(const App::Property*);
|
||||
|
||||
TechDraw::DrawHatch* getViewObject() const;
|
||||
};
|
||||
|
||||
} // namespace TechDrawGui
|
||||
|
||||
|
||||
#endif // DRAWINGGUI_VIEWPROVIDERHATCH_H
|
||||
345
src/Mod/TechDraw/Gui/ViewProviderPage.cpp
Normal file
345
src/Mod/TechDraw/Gui/ViewProviderPage.cpp
Normal file
@@ -0,0 +1,345 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
|
||||
* Copyright (c) 2012 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QAction>
|
||||
# include <QMenu>
|
||||
# include <QTimer>
|
||||
#include <QPointer>
|
||||
#endif
|
||||
|
||||
/// Here the FreeCAD includes sorted by Base,App,Gui......
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Sequencer.h>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Control.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/ViewProvider.h>
|
||||
#include <Gui/ViewProviderDocumentObject.h>
|
||||
#include <Gui/ViewProviderDocumentObjectGroup.h>
|
||||
|
||||
|
||||
#include "MDIViewPage.h"
|
||||
#include "ViewProviderPage.h"
|
||||
#include <Mod/Drawing/App/DrawPage.h>
|
||||
#include <Mod/Drawing/App/DrawView.h>
|
||||
#include <Mod/Drawing/App/DrawProjGroupItem.h>
|
||||
#include <Mod/Drawing/App/DrawViewDimension.h>
|
||||
#include <Mod/Drawing/App/DrawHatch.h>
|
||||
#include <Mod/Drawing/App/DrawUtil.h>
|
||||
|
||||
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<std::string> ViewProviderDrawingPage::getDisplayModes(void) const
|
||||
{
|
||||
// get the modes of the father
|
||||
std::vector<std::string> 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<std::string> &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<App::DocumentObject*> ViewProviderDrawingPage::claimChildren(void) const
|
||||
{
|
||||
std::vector<App::DocumentObject*> 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<App::DocumentObject *> &views = getPageObject()->Views.getValues();
|
||||
|
||||
try {
|
||||
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
|
||||
TechDraw::DrawView* featView = dynamic_cast<TechDraw::DrawView*> (*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<App::DocumentObject*> tmp;
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderDrawingPage::unsetEdit(int ModNum)
|
||||
{
|
||||
static_cast<void>(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<Gui::SelectionSingleton::SelObj> objs = Gui::Selection().getSelection(msg.pDocName);
|
||||
|
||||
for (std::vector<Gui::SelectionSingleton::SelObj>::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<void>(showMDIViewPage());
|
||||
Gui::ViewProviderDocumentObject::finishRestoring();
|
||||
}
|
||||
|
||||
|
||||
TechDraw::DrawPage* ViewProviderDrawingPage::getPageObject() const
|
||||
{
|
||||
return dynamic_cast<TechDraw::DrawPage*>(pcObject);
|
||||
}
|
||||
104
src/Mod/TechDraw/Gui/ViewProviderPage.h
Normal file
104
src/Mod/TechDraw/Gui/ViewProviderPage.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
|
||||
* Copyright (c) 2012 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <QPointer>
|
||||
#include <Gui/ViewProviderFeature.h>
|
||||
#include <Gui/ViewProviderDocumentObjectGroup.h>
|
||||
#include <Gui/Selection.h>
|
||||
|
||||
#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<std::string> 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<App::DocumentObject*> 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<std::string> &);
|
||||
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<MDIViewPage> view;
|
||||
bool restoreState;
|
||||
};
|
||||
|
||||
} // namespace TechDrawGui
|
||||
|
||||
|
||||
#endif // DRAWINGGUI_VIEWPROVIDERPAGE_H
|
||||
|
||||
172
src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp
Normal file
172
src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp
Normal file
@@ -0,0 +1,172 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <windows.h>
|
||||
# endif
|
||||
# include <QAction>
|
||||
# include <QMenu>
|
||||
#endif
|
||||
|
||||
/// Here the FreeCAD includes sorted by Base,App,Gui......
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Sequencer.h>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/Control.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/SoFCSelection.h>
|
||||
#include <Gui/ViewProviderDocumentObject.h>
|
||||
|
||||
#include <Mod/Drawing/App/DrawProjGroup.h>
|
||||
|
||||
#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<std::string> ViewProviderProjGroup::getDisplayModes(void) const
|
||||
{
|
||||
// get the modes of the father
|
||||
std::vector<std::string> 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<TaskDlgProjGroup *>(dlg);
|
||||
|
||||
if (projDlg &&
|
||||
projDlg->getViewProvider() == dynamic_cast<const ViewProviderProjGroup *>(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<TaskDlgProjGroup *>(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<App::DocumentObject*> ViewProviderProjGroup::claimChildren(void) const
|
||||
{
|
||||
// Collect any child fields
|
||||
std::vector<App::DocumentObject*> temp;
|
||||
const std::vector<App::DocumentObject *> &views = getObject()->Views.getValues();
|
||||
try {
|
||||
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
|
||||
temp.push_back(*it);
|
||||
}
|
||||
return temp;
|
||||
} catch (...) {
|
||||
std::vector<App::DocumentObject*> tmp;
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TechDraw::DrawProjGroup* ViewProviderProjGroup::getObject() const
|
||||
{
|
||||
return dynamic_cast<TechDraw::DrawProjGroup*>(pcObject);
|
||||
}
|
||||
71
src/Mod/TechDraw/Gui/ViewProviderProjGroup.h
Normal file
71
src/Mod/TechDraw/Gui/ViewProviderProjGroup.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <Gui/ViewProviderFeature.h>
|
||||
#include <Gui/ViewProviderDocumentObject.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
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<std::string> getDisplayModes(void) const;
|
||||
|
||||
/// Claim all the views for the page
|
||||
std::vector<App::DocumentObject*> 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
|
||||
158
src/Mod/TechDraw/Gui/ViewProviderProjGroupItem.cpp
Normal file
158
src/Mod/TechDraw/Gui/ViewProviderProjGroupItem.cpp
Normal file
@@ -0,0 +1,158 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2014 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Sequencer.h>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Control.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/SoFCSelection.h>
|
||||
|
||||
|
||||
#include <Mod/Drawing/App/DrawProjGroupItem.h>
|
||||
|
||||
#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<std::string> ViewProviderProjGroupItem::getDisplayModes(void) const
|
||||
{
|
||||
// get the modes of the father
|
||||
std::vector<std::string> 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<std::string> &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<TechDraw::DrawProjGroupItem*>(pcObject);
|
||||
}
|
||||
67
src/Mod/TechDraw/Gui/ViewProviderProjGroupItem.h
Normal file
67
src/Mod/TechDraw/Gui/ViewProviderProjGroupItem.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2014 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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<std::string> 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<std::string> &subList);
|
||||
|
||||
TechDraw::DrawProjGroupItem* getObject() const;
|
||||
void unsetEdit(int ModNum);
|
||||
|
||||
protected:
|
||||
bool setEdit(int ModNum);
|
||||
|
||||
};
|
||||
|
||||
} // namespace TechDrawGui
|
||||
|
||||
#endif // DRAWINGGUI_VIEWPROVIDERVIEWGROUPITEM_H
|
||||
86
src/Mod/TechDraw/Gui/ViewProviderSymbol.cpp
Normal file
86
src/Mod/TechDraw/Gui/ViewProviderSymbol.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
|
||||
* Copyright (c) 2012 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Sequencer.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <Gui/SoFCSelection.h>
|
||||
#include <Gui/Selection.h>
|
||||
|
||||
#include <Mod/Drawing/App/DrawViewSymbol.h>
|
||||
#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<std::string> ViewProviderSymbol::getDisplayModes(void) const
|
||||
{
|
||||
// get the modes of the father
|
||||
std::vector<std::string> StrList = ViewProviderDocumentObject::getDisplayModes();
|
||||
|
||||
return StrList;
|
||||
}
|
||||
|
||||
void ViewProviderSymbol::updateData(const App::Property*)
|
||||
{
|
||||
}
|
||||
|
||||
TechDraw::DrawViewSymbol* ViewProviderSymbol::getViewObject() const
|
||||
{
|
||||
return dynamic_cast<TechDraw::DrawViewSymbol*>(pcObject);
|
||||
}
|
||||
61
src/Mod/TechDraw/Gui/ViewProviderSymbol.h
Normal file
61
src/Mod/TechDraw/Gui/ViewProviderSymbol.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
|
||||
* Copyright (c) 2012 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <Gui/ViewProviderFeature.h>
|
||||
|
||||
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<std::string> getDisplayModes(void) const;
|
||||
virtual void updateData(const App::Property*);
|
||||
|
||||
TechDraw::DrawViewSymbol* getViewObject() const;
|
||||
};
|
||||
|
||||
} // namespace TechDrawGui
|
||||
|
||||
|
||||
#endif // DRAWINGGUI_VIEWPROVIDERSYMBOL_H
|
||||
89
src/Mod/TechDraw/Gui/ViewProviderTemplate.cpp
Normal file
89
src/Mod/TechDraw/Gui/ViewProviderTemplate.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2014 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <windows.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/// Here the FreeCAD includes sorted by Base,App,Gui......
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Sequencer.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <Gui/SoFCSelection.h>
|
||||
#include <Gui/Selection.h>
|
||||
|
||||
#include <Mod/Drawing/App/DrawTemplate.h>
|
||||
#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<std::string> ViewProviderTemplate::getDisplayModes(void) const
|
||||
{
|
||||
// get the modes of the father
|
||||
std::vector<std::string> 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<TechDraw::DrawTemplate*>(pcObject);
|
||||
}
|
||||
60
src/Mod/TechDraw/Gui/ViewProviderTemplate.h
Normal file
60
src/Mod/TechDraw/Gui/ViewProviderTemplate.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2014 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <Gui/ViewProviderFeature.h>
|
||||
|
||||
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<std::string> getDisplayModes(void) const;
|
||||
virtual void updateData(const App::Property*);
|
||||
|
||||
public:
|
||||
TechDraw::DrawTemplate* getTemplate() const;
|
||||
};
|
||||
|
||||
} // namespace TechDrawGui
|
||||
|
||||
|
||||
#endif // DRAWINGGUI_VIEWPROVIDERTEMPLATE_H
|
||||
|
||||
143
src/Mod/TechDraw/Gui/ViewProviderView.cpp
Normal file
143
src/Mod/TechDraw/Gui/ViewProviderView.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
|
||||
* Copyright (c) 2012 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Sequencer.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <Gui/Selection.h>
|
||||
|
||||
#include <Mod/Drawing/App/DrawView.h>
|
||||
#include <Mod/Drawing/App/DrawViewClip.h>
|
||||
#include <Mod/Drawing/App/DrawPage.h>
|
||||
#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<std::string> ViewProviderView::getDisplayModes(void) const
|
||||
{
|
||||
std::vector<std::string> 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<TechDraw::DrawView*>(obj)->Visible.setValue(true);
|
||||
std::vector<App::DocumentObject*> inp = obj->getInList();
|
||||
for (std::vector<App::DocumentObject*>::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<TechDraw::DrawView*>(obj)->Visible.setValue(false);
|
||||
std::vector<App::DocumentObject*> inp = obj->getInList();
|
||||
for (std::vector<App::DocumentObject*>::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<TechDraw::DrawView*>(pcObject);
|
||||
}
|
||||
|
||||
bool ViewProviderView::onDelete(const std::vector<std::string> &items)
|
||||
{
|
||||
//int viewCount =
|
||||
static_cast<void> (getViewObject()->findParentPage()->removeView(getViewObject()));
|
||||
Gui::Selection().clearSelection();
|
||||
return ViewProviderDocumentObject::onDelete(items);
|
||||
}
|
||||
74
src/Mod/TechDraw/Gui/ViewProviderView.h
Normal file
74
src/Mod/TechDraw/Gui/ViewProviderView.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
|
||||
* Copyright (c) 2012 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <Gui/ViewProviderFeature.h>
|
||||
#include <Gui/ViewProviderDocumentObjectGroup.h>
|
||||
|
||||
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<std::string> 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<std::string> &items);
|
||||
TechDraw::DrawView* getViewObject() const;
|
||||
};
|
||||
|
||||
} // namespace TechDrawGui
|
||||
|
||||
|
||||
#endif // DRAWINGGUI_VIEWPROVIDERVIEW_H
|
||||
|
||||
147
src/Mod/TechDraw/Gui/ViewProviderViewClip.cpp
Normal file
147
src/Mod/TechDraw/Gui/ViewProviderViewClip.cpp
Normal file
@@ -0,0 +1,147 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
|
||||
* Copyright (c) 2012 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <windows.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/// Here the FreeCAD includes sorted by Base,App,Gui......
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Sequencer.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
//#include <Gui/SoFCSelection.h>
|
||||
#include <Gui/Selection.h>
|
||||
|
||||
#include <Mod/Drawing/App/DrawViewClip.h>
|
||||
#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<std::string> ViewProviderDrawingClip::getDisplayModes(void) const
|
||||
{
|
||||
// get the modes of the father
|
||||
std::vector<std::string> StrList;
|
||||
return StrList;
|
||||
}
|
||||
|
||||
std::vector<App::DocumentObject*> ViewProviderDrawingClip::claimChildren(void) const
|
||||
{
|
||||
// Collect any child views
|
||||
// for Clip, valid children are any View in Views
|
||||
const std::vector<App::DocumentObject *> &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<TechDraw::DrawViewClip*>(obj)->Visible.setValue(true);
|
||||
std::vector<App::DocumentObject*> inp = obj->getInList();
|
||||
for (std::vector<App::DocumentObject*>::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<TechDraw::DrawViewClip*>(obj)->Visible.setValue(false);
|
||||
std::vector<App::DocumentObject*> inp = obj->getInList();
|
||||
for (std::vector<App::DocumentObject*>::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<TechDraw::DrawViewClip*>(pcObject);
|
||||
}
|
||||
73
src/Mod/TechDraw/Gui/ViewProviderViewClip.h
Normal file
73
src/Mod/TechDraw/Gui/ViewProviderViewClip.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
|
||||
* Copyright (c) 2012 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <Gui/ViewProviderDocumentObjectGroup.h>
|
||||
#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<std::string> 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<App::DocumentObject*> claimChildren(void) const;
|
||||
|
||||
/** @name Restoring view provider from document load */
|
||||
//@{
|
||||
virtual void startRestoring();
|
||||
virtual void finishRestoring();
|
||||
//@}
|
||||
};
|
||||
} // namespace TechDrawGui
|
||||
|
||||
|
||||
#endif // DRAWINGGUI_VIEWPROVIDERCLIP_H
|
||||
|
||||
123
src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp
Normal file
123
src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2014 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <windows.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/// Here the FreeCAD includes sorted by Base,App,Gui......
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Sequencer.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <Gui/SoFCSelection.h>
|
||||
#include <Gui/Selection.h>
|
||||
|
||||
#include <Mod/Drawing/App/DrawViewPart.h>
|
||||
#include <Mod/Drawing/App/DrawViewDimension.h>
|
||||
#include <Mod/Drawing/App/DrawHatch.h>
|
||||
|
||||
#include<Mod/Drawing/App/DrawPage.h>
|
||||
#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<std::string> ViewProviderViewPart::getDisplayModes(void) const
|
||||
{
|
||||
// get the modes of the father
|
||||
std::vector<std::string> StrList = ViewProviderDocumentObject::getDisplayModes();
|
||||
|
||||
return StrList;
|
||||
}
|
||||
|
||||
|
||||
std::vector<App::DocumentObject*> 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<App::DocumentObject*> temp;
|
||||
const std::vector<App::DocumentObject *> &views = getViewPart()->getInList();
|
||||
try {
|
||||
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
|
||||
if((*it)->getTypeId().isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) {
|
||||
TechDraw::DrawViewDimension *dim = dynamic_cast<TechDraw::DrawViewDimension *>(*it);
|
||||
const std::vector<App::DocumentObject *> &refs = dim->References.getValues();
|
||||
for(std::vector<App::DocumentObject *>::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<App::DocumentObject*> tmp;
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ViewProviderViewPart::updateData(const App::Property*)
|
||||
{
|
||||
}
|
||||
|
||||
TechDraw::DrawViewPart* ViewProviderViewPart::getViewPart() const
|
||||
{
|
||||
return dynamic_cast<TechDraw::DrawViewPart*>(pcObject);
|
||||
}
|
||||
61
src/Mod/TechDraw/Gui/ViewProviderViewPart.h
Normal file
61
src/Mod/TechDraw/Gui/ViewProviderViewPart.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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<std::string> getDisplayModes(void) const;
|
||||
virtual void updateData(const App::Property*);
|
||||
|
||||
public:
|
||||
virtual std::vector<App::DocumentObject*> claimChildren(void) const;
|
||||
|
||||
TechDraw::DrawViewPart* getViewPart() const;
|
||||
};
|
||||
|
||||
} // namespace TechDrawGui
|
||||
|
||||
|
||||
#endif // DRAWINGGUI_VIEWPROVIDERVIEWPART_H
|
||||
96
src/Mod/TechDraw/Gui/ViewProviderViewSection.cpp
Normal file
96
src/Mod/TechDraw/Gui/ViewProviderViewSection.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
|
||||
* Copyright (c) 2012 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <windows.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/// Here the FreeCAD includes sorted by Base,App,Gui......
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Sequencer.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <Gui/SoFCSelection.h>
|
||||
#include <Gui/Selection.h>
|
||||
|
||||
#include <Mod/Drawing/App/DrawView.h>
|
||||
#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<std::string> ViewProviderViewSection::getDisplayModes(void) const
|
||||
{
|
||||
// get the modes of the father
|
||||
std::vector<std::string> 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<App::DocumentObject*> ViewProviderViewSection::claimChildren(void) const
|
||||
{
|
||||
return ViewProviderViewPart::claimChildren();
|
||||
}
|
||||
|
||||
TechDraw::DrawView* ViewProviderViewSection::getViewObject() const
|
||||
{
|
||||
return dynamic_cast<TechDraw::DrawView*>(pcObject);
|
||||
}
|
||||
61
src/Mod/TechDraw/Gui/ViewProviderViewSection.h
Normal file
61
src/Mod/TechDraw/Gui/ViewProviderViewSection.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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<std::string> getDisplayModes(void) const;
|
||||
virtual void updateData(const App::Property*);
|
||||
virtual std::vector<App::DocumentObject*> claimChildren(void) const;
|
||||
|
||||
TechDraw::DrawView* getViewObject() const;
|
||||
};
|
||||
|
||||
} // namespace TechDrawGui
|
||||
|
||||
|
||||
#endif // DRAWINGGUI_VIEWPROVIDERVIEW_H
|
||||
171
src/Mod/TechDraw/Gui/Workbench.cpp
Normal file
171
src/Mod/TechDraw/Gui/Workbench.cpp
Normal file
@@ -0,0 +1,171 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2005 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <qobject.h>
|
||||
#endif
|
||||
|
||||
#include "Workbench.h"
|
||||
#include <Gui/MenuManager.h>
|
||||
#include <Gui/ToolBarManager.h>
|
||||
|
||||
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;
|
||||
}
|
||||
51
src/Mod/TechDraw/Gui/Workbench.h
Normal file
51
src/Mod/TechDraw/Gui/Workbench.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2005 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* 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 <Gui/Workbench.h>
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user