diff --git a/src/Mod/TechDraw/App/AppTechDraw.cpp b/src/Mod/TechDraw/App/AppTechDraw.cpp index 0ff8b8b3b2..d1b33c8e4f 100644 --- a/src/Mod/TechDraw/App/AppTechDraw.cpp +++ b/src/Mod/TechDraw/App/AppTechDraw.cpp @@ -42,6 +42,9 @@ #include "DrawViewBalloon.h" #include "DrawLeaderLine.h" #include "DrawRichAnno.h" +#include "DrawTile.h" +#include "DrawTileWeld.h" +#include "DrawWeldSymbol.h" #include "Cosmetic.h" #include "PropertyGeomFormatList.h" #include "PropertyCenterLineList.h" @@ -100,6 +103,9 @@ PyMOD_INIT_FUNC(TechDraw) TechDraw::DrawViewDraft ::init(); TechDraw::DrawViewArch ::init(); TechDraw::DrawViewImage ::init(); + TechDraw::DrawTile ::init(); + TechDraw::DrawTileWeld ::init(); + TechDraw::DrawWeldSymbol ::init(); TechDraw::PropertyGeomFormatList::init(); TechDraw::GeomFormat ::init(); @@ -119,5 +125,8 @@ PyMOD_INIT_FUNC(TechDraw) TechDraw::DrawViewSymbolPython::init(); TechDraw::DrawLeaderLinePython::init(); TechDraw::DrawRichAnnoPython ::init(); + TechDraw::DrawTilePython ::init(); + TechDraw::DrawTileWeldPython ::init(); + TechDraw::DrawWeldSymbolPython::init(); PyMOD_Return(mod); } diff --git a/src/Mod/TechDraw/App/CMakeLists.txt b/src/Mod/TechDraw/App/CMakeLists.txt index a6611d0e17..aa8fe00e31 100644 --- a/src/Mod/TechDraw/App/CMakeLists.txt +++ b/src/Mod/TechDraw/App/CMakeLists.txt @@ -63,6 +63,9 @@ generate_from_xml(GeomFormatPy) generate_from_xml(CenterLinePy) generate_from_xml(CosmeticEdgePy) generate_from_xml(CosmeticVertexPy) +generate_from_xml(DrawTilePy) +generate_from_xml(DrawTileWeldPy) +generate_from_xml(DrawWeldSymbolPy) SET(Draw_SRCS DrawPage.cpp @@ -117,6 +120,12 @@ SET(Draw_SRCS DrawRichAnno.h QDomNodeModel.cpp QDomNodeModel.h + DrawTile.cpp + DrawTile.h + DrawTileWeld.cpp + DrawTileWeld.h + DrawWeldSymbol.cpp + DrawWeldSymbol.h ) SET(TechDraw_SRCS @@ -196,6 +205,12 @@ SET(Python_SRCS CosmeticEdgePyImp.cpp CosmeticVertexPy.xml CosmeticVertexPyImp.cpp + DrawTilePy.xml + DrawTilePyImp.cpp + DrawTileWeldPy.xml + DrawTileWeldPyImp.cpp + DrawWeldSymbolPy.xml + DrawWeldSymbolPyImp.cpp ) SOURCE_GROUP("Mod" FILES ${TechDraw_SRCS}) @@ -225,6 +240,13 @@ ADD_CUSTOM_COMMAND(TARGET TechDraw COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/src/Mod/TechDraw/Templates ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Mod/TechDraw/Templates +) + +ADD_CUSTOM_COMMAND(TARGET TechDraw + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_SOURCE_DIR}/src/Mod/TechDraw/Symbols + ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Mod/TechDraw/Symbols ) SET_BIN_DIR(TechDraw TechDraw /Mod/TechDraw) diff --git a/src/Mod/TechDraw/App/DrawLeaderLine.cpp b/src/Mod/TechDraw/App/DrawLeaderLine.cpp index 81f4b3628f..b24dd49c61 100644 --- a/src/Mod/TechDraw/App/DrawLeaderLine.cpp +++ b/src/Mod/TechDraw/App/DrawLeaderLine.cpp @@ -187,6 +187,52 @@ void DrawLeaderLine::adjustLastSegment(void) WayPoints.setValues(wp); } +//middle of last line segment +Base::Vector3d DrawLeaderLine::getTileOrigin(void) const +{ + Base::Vector3d result; + std::vector wp = WayPoints.getValues(); + if (wp.size() > 1) { + Base::Vector3d last = wp.rbegin()[0]; + Base::Vector3d second = wp.rbegin()[1]; + result = (last + second) / 2.0; + } else { + Base::Console().Warning("DLL::getTileOrigin - no waypoints\n"); + } + return result; +} + +//start of last line segment +Base::Vector3d DrawLeaderLine::getKinkPoint(void) const +{ + Base::Vector3d result; + std::vector wp = WayPoints.getValues(); + if (wp.size() > 1) { + Base::Vector3d second = wp.rbegin()[1]; + result = second; + } else { + Base::Console().Warning("DLL::getKinkPoint - no waypoints\n"); + } + + return result; +} + +//end of last line segment +Base::Vector3d DrawLeaderLine::getTailPoint(void) const +{ + Base::Vector3d result; + std::vector wp = WayPoints.getValues(); + if (!wp.empty()) { + Base::Vector3d last = wp.rbegin()[0]; + result = last; + } else { + Base::Console().Warning("DLL::getTailPoint - no waypoints\n"); + } + + return result; +} + + bool DrawLeaderLine::getDefAuto(void) const { Base::Reference hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> diff --git a/src/Mod/TechDraw/App/DrawLeaderLine.h b/src/Mod/TechDraw/App/DrawLeaderLine.h index 7f73fd0991..634b4f24d0 100644 --- a/src/Mod/TechDraw/App/DrawLeaderLine.h +++ b/src/Mod/TechDraw/App/DrawLeaderLine.h @@ -66,6 +66,10 @@ public: void adjustLastSegment(void); bool getDefAuto(void) const; + Base::Vector3d getTileOrigin(void) const; + Base::Vector3d getKinkPoint(void) const; + Base::Vector3d getTailPoint(void) const; + protected: virtual void onChanged(const App::Property* prop) override; diff --git a/src/Mod/TechDraw/App/DrawTile.cpp b/src/Mod/TechDraw/App/DrawTile.cpp new file mode 100644 index 0000000000..65bb6e45b8 --- /dev/null +++ b/src/Mod/TechDraw/App/DrawTile.cpp @@ -0,0 +1,118 @@ +/*************************************************************************** + * Copyright (c) 2019 Wanderer Fan * + * * + * 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 + +#include +#include +#include +#include + +#include "DrawUtil.h" + +#include // generated from DrawTilePy.xml +#include "DrawTile.h" + +using namespace TechDraw; + +//=========================================================================== +// DrawTile - attachable tile +//=========================================================================== + +PROPERTY_SOURCE(TechDraw::DrawTile, App::DocumentObject) + +DrawTile::DrawTile(void) +{ + static const char *group = "Tile"; + + Base::Vector3d defOrg(0.0, 0.0, 0.0); + ADD_PROPERTY_TYPE(TileParent,(0),group,(App::PropertyType)(App::Prop_None), + "Object to which this tile is attached"); + ADD_PROPERTY_TYPE(TileRow, (0), group, App::Prop_None, "Row in parent"); + ADD_PROPERTY_TYPE(TileColumn, (0), group, App::Prop_None, "Column in parent"); + ADD_PROPERTY_TYPE(TileOrigin, (defOrg), group, App::Prop_None, "Width limit before auto wrap"); +} + +DrawTile::~DrawTile() +{ +} + +void DrawTile::onChanged(const App::Property* prop) +{ + if (!isRestoring()) { + //nothing in particular + } + DocumentObject::onChanged(prop); + +} + +short DrawTile::mustExecute() const +{ + return DocumentObject::mustExecute(); +} + +App::DocumentObjectExecReturn *DrawTile::execute(void) +{ +// Base::Console().Message("DT::execute()\n"); + return DocumentObject::execute(); +} + +DrawView* DrawTile::getParent(void) const +{ + Base::Console().Message("DT::getParent() - %s\n", getNameInDocument()); + DrawView* result = nullptr; + App::DocumentObject* baseObj = TileParent.getValue(); + if (baseObj != nullptr) { + DrawView* cast = dynamic_cast(baseObj); + if (cast != nullptr) { + result = cast; + } + } + return result; +} + +PyObject *DrawTile::getPyObject(void) +{ + if (PythonObject.is(Py::_None())) { + // ref counter is set to 1 + PythonObject = Py::Object(new DrawTilePy(this),true); + } + return Py::new_reference_to(PythonObject); +} + +// Python Drawing feature --------------------------------------------------------- + +namespace App { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawTilePython, TechDraw::DrawTile) +template<> const char* TechDraw::DrawTilePython::getViewProviderName(void) const { + return "TechDrawGui::ViewProviderTile"; +} +/// @endcond + +// explicit template instantiation +template class TechDrawExport FeaturePythonT; +} + diff --git a/src/Mod/TechDraw/App/DrawTile.h b/src/Mod/TechDraw/App/DrawTile.h new file mode 100644 index 0000000000..6b80bd6e75 --- /dev/null +++ b/src/Mod/TechDraw/App/DrawTile.h @@ -0,0 +1,65 @@ +/*************************************************************************** + * Copyright (c) 2019 Wanderer Fan * + * * + * 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_DrawTile_h_ +#define _TechDraw_DrawTile_h_ + +# include +# include + +#include "DrawView.h" + +namespace TechDraw +{ + +class TechDrawExport DrawTile : public App::DocumentObject +{ + PROPERTY_HEADER(TechDraw::DrawTile); + +public: + DrawTile(); + virtual ~DrawTile(); + + App::PropertyLink TileParent; //eg DrawWeldSymbol + App::PropertyInteger TileRow; + App::PropertyInteger TileColumn; + App::PropertyVector TileOrigin; //sb call to TileParent - WeldingSymbol + + virtual short mustExecute() const; + virtual App::DocumentObjectExecReturn *execute(void); + + virtual const char* getViewProviderName(void) const { + return "TechDrawGui::ViewProviderTile"; + } + virtual PyObject *getPyObject(void); + virtual DrawView* getParent(void) const; + +protected: + virtual void onChanged(const App::Property* prop); + +private: +}; + +typedef App::FeaturePythonT DrawTilePython; + +} //namespace TechDraw +#endif diff --git a/src/Mod/TechDraw/App/DrawTilePy.xml b/src/Mod/TechDraw/App/DrawTilePy.xml new file mode 100644 index 0000000000..c0a466bd90 --- /dev/null +++ b/src/Mod/TechDraw/App/DrawTilePy.xml @@ -0,0 +1,18 @@ + + + + + + Feature for adding tiles to leader lines + + + + diff --git a/src/Mod/TechDraw/App/DrawTilePyImp.cpp b/src/Mod/TechDraw/App/DrawTilePyImp.cpp new file mode 100644 index 0000000000..ae48cfe9fd --- /dev/null +++ b/src/Mod/TechDraw/App/DrawTilePyImp.cpp @@ -0,0 +1,54 @@ +/*************************************************************************** + * Copyright (c) 2019 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 + +#include +#include +#include + +#include "DrawTile.h" + +// inclusion of the generated files (generated out of DrawTilePy.xml) +#include +#include +#include + +using namespace TechDraw; + +// returns a string which represents the object e.g. when printed in python +std::string DrawTilePy::representation(void) const +{ + return std::string(""); +} + +PyObject *DrawTilePy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int DrawTilePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Mod/TechDraw/App/DrawTileWeld.cpp b/src/Mod/TechDraw/App/DrawTileWeld.cpp new file mode 100644 index 0000000000..851d356743 --- /dev/null +++ b/src/Mod/TechDraw/App/DrawTileWeld.cpp @@ -0,0 +1,103 @@ +/*************************************************************************** + * Copyright (c) 2019 Wanderer Fan * + * * + * 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 + +#include +#include +#include +#include + +#include "DrawUtil.h" + +#include // generated from DrawTileWeldPy.xml +#include "DrawTileWeld.h" + +using namespace TechDraw; + +//=========================================================================== +// DrawTileWeld - attachable tile +//=========================================================================== + +PROPERTY_SOURCE(TechDraw::DrawTileWeld, TechDraw::DrawTile) + +DrawTileWeld::DrawTileWeld(void) +{ + static const char *group = "TileWeld"; + + ADD_PROPERTY_TYPE(LeftText,(""),group,(App::PropertyType)(App::Prop_None), + "Text LHS"); + ADD_PROPERTY_TYPE(RightText, (0), group, App::Prop_None, "Text RHS"); + ADD_PROPERTY_TYPE(CenterText, (0), group, App::Prop_None, "Text above Symbol"); + ADD_PROPERTY_TYPE(SymbolFile, (""), group, App::Prop_None, "Svg Symbol File"); +} + +DrawTileWeld::~DrawTileWeld() +{ +} + +void DrawTileWeld::onChanged(const App::Property* prop) +{ + if (!isRestoring()) { + //nothing in particular + } + DrawTile::onChanged(prop); + +} + +short DrawTileWeld::mustExecute() const +{ + return DrawTile::mustExecute(); +} + +App::DocumentObjectExecReturn *DrawTileWeld::execute(void) +{ +// Base::Console().Message("DT::execute()\n"); + return DrawTile::execute(); +} + +PyObject *DrawTileWeld::getPyObject(void) +{ + if (PythonObject.is(Py::_None())) { + // ref counter is set to 1 + PythonObject = Py::Object(new DrawTileWeldPy(this),true); + } + return Py::new_reference_to(PythonObject); +} + +// Python Drawing feature --------------------------------------------------------- + +namespace App { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawTileWeldPython, TechDraw::DrawTileWeld) +template<> const char* TechDraw::DrawTileWeldPython::getViewProviderName(void) const { + return "TechDrawGui::ViewProviderTile"; +} +/// @endcond + +// explicit template instantiation +template class TechDrawExport FeaturePythonT; +} + diff --git a/src/Mod/TechDraw/App/DrawTileWeld.h b/src/Mod/TechDraw/App/DrawTileWeld.h new file mode 100644 index 0000000000..a8070e5c8b --- /dev/null +++ b/src/Mod/TechDraw/App/DrawTileWeld.h @@ -0,0 +1,68 @@ +/*************************************************************************** + * Copyright (c) 2019 Wanderer Fan * + * * + * 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_DrawTileWeld_h_ +#define _TechDraw_DrawTileWeld_h_ + +#include +#include +#include +#include + +#include "DrawTile.h" + + +namespace TechDraw +{ + +class TechDrawExport DrawTileWeld : public TechDraw::DrawTile +{ + PROPERTY_HEADER(TechDraw::DrawTileWeld); + +public: + DrawTileWeld(); + virtual ~DrawTileWeld(); + + App::PropertyString LeftText; + App::PropertyString RightText; + App::PropertyString CenterText; + App::PropertyFileIncluded SymbolFile; + + virtual short mustExecute() const; + virtual App::DocumentObjectExecReturn *execute(void); + + virtual const char* getViewProviderName(void) const { + return "TechDrawGui::ViewProviderTile"; + } + virtual PyObject *getPyObject(void); + virtual QRectF getRect() const { return QRectF(0,0,1,1);} + +protected: + virtual void onChanged(const App::Property* prop); + +private: +}; + +typedef App::FeaturePythonT DrawTileWeldPython; + +} //namespace TechDraw +#endif diff --git a/src/Mod/TechDraw/App/DrawTileWeldPy.xml b/src/Mod/TechDraw/App/DrawTileWeldPy.xml new file mode 100644 index 0000000000..a93e13ef0a --- /dev/null +++ b/src/Mod/TechDraw/App/DrawTileWeldPy.xml @@ -0,0 +1,18 @@ + + + + + + Feature for adding welding tiles to leader lines + + + + diff --git a/src/Mod/TechDraw/App/DrawTileWeldPyImp.cpp b/src/Mod/TechDraw/App/DrawTileWeldPyImp.cpp new file mode 100644 index 0000000000..5fb4342a2d --- /dev/null +++ b/src/Mod/TechDraw/App/DrawTileWeldPyImp.cpp @@ -0,0 +1,54 @@ +/*************************************************************************** + * Copyright (c) 2019 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 + +#include +#include +#include + +#include "DrawTileWeld.h" + +// inclusion of the generated files (generated out of DrawTileWeldPy.xml) +#include +#include +#include + +using namespace TechDraw; + +// returns a string which represents the object e.g. when printed in python +std::string DrawTileWeldPy::representation(void) const +{ + return std::string(""); +} + +PyObject *DrawTileWeldPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int DrawTileWeldPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Mod/TechDraw/App/DrawWeldSymbol.cpp b/src/Mod/TechDraw/App/DrawWeldSymbol.cpp new file mode 100644 index 0000000000..7dd0fbfaa8 --- /dev/null +++ b/src/Mod/TechDraw/App/DrawWeldSymbol.cpp @@ -0,0 +1,136 @@ +/*************************************************************************** + * Copyright (c) 2019 Wanderer Fan * + * * + * 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 + +#include +#include +#include +#include +#include +#include + +#include "DrawUtil.h" + +#include // generated from DrawWeldSymbolPy.xml + +#include "DrawTile.h" +#include "DrawTileWeld.h" +#include "DrawWeldSymbol.h" + +using namespace TechDraw; + +//=========================================================================== +// DrawWeldSymbol - welding symbol +//=========================================================================== + +PROPERTY_SOURCE(TechDraw::DrawWeldSymbol, TechDraw::DrawView) + +DrawWeldSymbol::DrawWeldSymbol(void) +{ + static const char *group = "Weld Symbol"; + + ADD_PROPERTY_TYPE(Leader,(0),group,(App::PropertyType)(App::Prop_None), "Parent Leader"); + ADD_PROPERTY_TYPE(AllAround, (false), group, App::Prop_None, "All Around Symbol on/off"); + ADD_PROPERTY_TYPE(FieldWeld, (false), group, App::Prop_None, "Field Weld Symbol on/off"); + ADD_PROPERTY_TYPE(TailText, (""), group, App::Prop_None, "Text at tail of symbol"); + + Caption.setStatus(App::Property::Hidden,true); + Scale.setStatus(App::Property::Hidden,true); + ScaleType.setStatus(App::Property::Hidden,true); + +} + +DrawWeldSymbol::~DrawWeldSymbol() +{ +} + +void DrawWeldSymbol::onChanged(const App::Property* prop) +{ + if (!isRestoring()) { + //nothing in particular + } + DrawView::onChanged(prop); +} + +short DrawWeldSymbol::mustExecute() const +{ + return DrawView::mustExecute(); +} + +App::DocumentObjectExecReturn *DrawWeldSymbol::execute(void) +{ +// Base::Console().Message("DWS::execute()\n"); + if (!keepUpdated()) { + return App::DocumentObject::StdReturn; + } + + + return DrawView::execute(); +} + +std::vector DrawWeldSymbol::getTiles(void) const +{ +// Base::Console().Message("DWS::getTiles()\n"); + std::vector temp; + std::vector result; + + std::vector tiles = getInList(); + if (!tiles.empty()) { + for(std::vector::iterator it = tiles.begin(); it != tiles.end(); it++) { + if ((*it)->getTypeId().isDerivedFrom(TechDraw::DrawTileWeld::getClassTypeId())) { + App::DocumentObject* doTemp = (*it); + DrawTileWeld* temp = static_cast(doTemp); + result.push_back(temp); + } + } + } +// Base::Console().Message("DWS::getTiles - returns: %d tiles\n",result.size()); + return result; +} + +PyObject *DrawWeldSymbol::getPyObject(void) +{ + if (PythonObject.is(Py::_None())) { + // ref counter is set to 1 + PythonObject = Py::Object(new DrawWeldSymbolPy(this),true); + } + return Py::new_reference_to(PythonObject); +} + +// Python Drawing feature --------------------------------------------------------- + +namespace App { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawWeldSymbolPython, TechDraw::DrawWeldSymbol) +template<> const char* TechDraw::DrawWeldSymbolPython::getViewProviderName(void) const { + return "TechDrawGui::ViewProviderWeld"; +} +/// @endcond + +// explicit template instantiation +template class TechDrawExport FeaturePythonT; +} + diff --git a/src/Mod/TechDraw/App/DrawWeldSymbol.h b/src/Mod/TechDraw/App/DrawWeldSymbol.h new file mode 100644 index 0000000000..0ab74871ea --- /dev/null +++ b/src/Mod/TechDraw/App/DrawWeldSymbol.h @@ -0,0 +1,72 @@ +/*************************************************************************** + * Copyright (c) 2019 Wanderer Fan * + * * + * 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_DrawWeldSymbol_h_ +#define _TechDraw_DrawWeldSymbol_h_ + +# include +# include + +#include "DrawView.h" + + +namespace TechDraw +{ +class DrawTile; +class DrawTileWeld; + +class TechDrawExport DrawWeldSymbol : public TechDraw::DrawView +{ + PROPERTY_HEADER(TechDraw::DrawWeldSymbol); + +public: + DrawWeldSymbol(); + virtual ~DrawWeldSymbol(); + + App::PropertyLink Leader; +// App::PropertyLinkList Tiles; + App::PropertyBool AllAround; + App::PropertyBool FieldWeld; + App::PropertyString TailText; + + virtual short mustExecute() const; + virtual App::DocumentObjectExecReturn *execute(void); + + virtual const char* getViewProviderName(void) const { + return "TechDrawGui::ViewProviderWeld"; + } + virtual PyObject *getPyObject(void); + virtual QRectF getRect() const { return QRectF(0,0,1,1);} + + std::vector getTiles(void) const; +// void addTile(App::DocumentObject* d); + +protected: + virtual void onChanged(const App::Property* prop); + +private: +}; + +typedef App::FeaturePythonT DrawWeldSymbolPython; + +} //namespace TechDraw +#endif diff --git a/src/Mod/TechDraw/App/DrawWeldSymbolPy.xml b/src/Mod/TechDraw/App/DrawWeldSymbolPy.xml new file mode 100644 index 0000000000..165fac160c --- /dev/null +++ b/src/Mod/TechDraw/App/DrawWeldSymbolPy.xml @@ -0,0 +1,18 @@ + + + + + + Feature for adding welding tiles to leader lines + + + + diff --git a/src/Mod/TechDraw/App/DrawWeldSymbolPyImp.cpp b/src/Mod/TechDraw/App/DrawWeldSymbolPyImp.cpp new file mode 100644 index 0000000000..578ad3f703 --- /dev/null +++ b/src/Mod/TechDraw/App/DrawWeldSymbolPyImp.cpp @@ -0,0 +1,67 @@ +/*************************************************************************** + * Copyright (c) 2019 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 + +#include +#include +#include + +#include "DrawWeldSymbol.h" + +// inclusion of the generated files (generated out of DrawWeldSymbolPy.xml) +#include +#include +#include + +using namespace TechDraw; + +// returns a string which represents the object e.g. when printed in python +std::string DrawWeldSymbolPy::representation(void) const +{ + return std::string(""); +} + +//PyObject* DrawWeldSymbolPy::getTiles(PyObject *args) +//{ +// const char* fileSpec; +// PyObject* pTile +// if (!PyArg_ParseTuple(args, "O", &pTile)) { +// throw Py::TypeError("getTiles expected DrawTile"); +// } +// auto dws = getDrawWeldSymbolPtr(); +//// auto dt = pTile->getDrawTilePtr(); +////TODO: finish this! +// Py_Return; +//} + +PyObject *DrawWeldSymbolPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int DrawWeldSymbolPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Mod/TechDraw/CMakeLists.txt b/src/Mod/TechDraw/CMakeLists.txt index 1d28eda752..2a4c8c3a86 100644 --- a/src/Mod/TechDraw/CMakeLists.txt +++ b/src/Mod/TechDraw/CMakeLists.txt @@ -24,7 +24,7 @@ SET(TechDraw_LineGroupFile ) add_custom_target(TechDraw_Data ALL - SOURCES ${TechDraw_Scripts} ${TechDraw_PATFile} ${TechDraw_LineGroupFile} +SOURCES ${TechDraw_Scripts} ${TechDraw_PATFile} ${TechDraw_LineGroupFile} ) fc_target_copy_resource(TechDraw_Data @@ -86,6 +86,15 @@ INSTALL( PATTERN "*.svg*" ) +INSTALL( + DIRECTORY + Symbols + DESTINATION + ${CMAKE_INSTALL_DATADIR}/Mod/TechDraw + FILES_MATCHING + PATTERN "*.svg*" +) + #unit test files SET(TDTest_SRCS diff --git a/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp b/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp index fba82bd380..d5511b046e 100644 --- a/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp +++ b/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp @@ -58,6 +58,8 @@ #include "ViewProviderImage.h" #include "ViewProviderRichAnno.h" #include "ViewProviderLeader.h" +#include "ViewProviderTile.h" +#include "ViewProviderWeld.h" // use a different name to CreateCommand() @@ -134,6 +136,8 @@ PyMOD_INIT_FUNC(TechDrawGui) TechDrawGui::ViewProviderImage::init(); TechDrawGui::ViewProviderLeader::init(); TechDrawGui::ViewProviderRichAnno::init(); + TechDrawGui::ViewProviderTile::init(); + TechDrawGui::ViewProviderWeld::init(); // register preferences pages new Gui::PrefPageProducer ("TechDraw"); diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index f39360856f..e31c45a3ec 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -55,6 +55,7 @@ set(TechDrawGui_MOC_HDRS TaskCosVertex.h TaskCenterLine.h TaskLineDecor.h + TaskWeldingSymbol.h QGEPath.h QGTracker.h QGILeaderLine.h @@ -63,6 +64,7 @@ set(TechDrawGui_MOC_HDRS mrichtextedit.h mtextedit.h TaskBalloon.h + QGIWeldSymbol.h ) fc_wrap_cpp(TechDrawGui_MOC_SRCS ${TechDrawGui_MOC_HDRS}) @@ -91,6 +93,7 @@ set(TechDrawGui_UIC_SRCS TaskCL2Lines.ui TaskLineDecor.ui TaskRestoreLines.ui + TaskWeldingSymbol.ui ) if(BUILD_QT5) @@ -168,6 +171,9 @@ SET(TechDrawGui_SRCS TaskLineDecor.h TaskRestoreLines.ui TaskCL2Lines.ui + TaskWeldingSymbol.ui + TaskWeldingSymbol.cpp + TaskWeldingSymbol.h DrawGuiUtil.cpp DrawGuiUtil.h Rez.cpp @@ -261,6 +267,10 @@ SET(TechDrawGuiView_SRCS QGIRichAnno.h QGMText.h QGMText.cpp + QGIWeldSymbol.h + QGIWeldSymbol.cpp + QGITile.h + QGITile.cpp TemplateTextField.cpp TemplateTextField.h ZVALUE.h @@ -302,6 +312,10 @@ SET(TechDrawGuiViewProvider_SRCS ViewProviderLeader.h ViewProviderRichAnno.cpp ViewProviderRichAnno.h + ViewProviderTile.cpp + ViewProviderTile.h + ViewProviderWeld.cpp + ViewProviderWeld.h ) SOURCE_GROUP("MRTE" FILES ${MRTE_SRCS}) @@ -323,6 +337,7 @@ SET(TechDrawGuiTaskDlgs_SRCS TaskLineDecor.ui TaskRestoreLines.ui TaskCL2Lines.ui + TaskWeldingSymbol.ui ) SOURCE_GROUP("TaskDialogs" FILES ${TechDrawGuiTaskDlgs_SRCS}) diff --git a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp index f3801c7a1f..f6c4d09909 100644 --- a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp +++ b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp @@ -48,6 +48,8 @@ #include #include #include +#include +#include #include #include #include @@ -60,6 +62,7 @@ #include "TaskCosVertex.h" #include "TaskCenterLine.h" #include "TaskLineDecor.h" +#include "TaskWeldingSymbol.h" #include "ViewProviderPage.h" #include "ViewProviderViewPart.h" #include "QGVPage.h" @@ -1279,6 +1282,61 @@ bool CmdTechDrawShowAll::isActive(void) return (havePage && haveView); } +//=========================================================================== +// TechDraw_WeldSymbol +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawWeldSymbol); + +CmdTechDrawWeldSymbol::CmdTechDrawWeldSymbol() + : Command("TechDraw_WeldSymbol") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add welding information to a leader"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_WeldSymbol"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-weldsymbol"; +} + +void CmdTechDrawWeldSymbol::activated(int iMsg) +{ + Q_UNUSED(iMsg); + + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + if (dlg != nullptr) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"), + QObject::tr("Close active task dialog and try again.")); + return; + } + + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + + std::vector leaders = getSelection(). + getObjectsOfType(TechDraw::DrawLeaderLine::getClassTypeId()); + if (leaders.size() != 1) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select exactly one Leader line.")); + return; + } + TechDraw::DrawLeaderLine* baseFeat = nullptr; + baseFeat = static_cast (leaders.front()); + + Gui::Control().showDialog(new TaskDlgWeldingSymbol(baseFeat)); +} + +bool CmdTechDrawWeldSymbol::isActive(void) +{ + bool havePage = DrawGuiUtil::needPage(this); + bool haveView = DrawGuiUtil::needView(this, false); + return (havePage && haveView); +} + + void CreateTechDrawCommandsAnnotate(void) { Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); @@ -1297,6 +1355,7 @@ void CreateTechDrawCommandsAnnotate(void) rcCmdMgr.addCommand(new CmdTechDrawCosmeticEraser()); rcCmdMgr.addCommand(new CmdTechDrawDecorateLine()); rcCmdMgr.addCommand(new CmdTechDrawShowAll()); + rcCmdMgr.addCommand(new CmdTechDrawWeldSymbol()); } //=========================================================================== diff --git a/src/Mod/TechDraw/Gui/MDIViewPage.cpp b/src/Mod/TechDraw/Gui/MDIViewPage.cpp index 0e089079ed..a153cb62f1 100644 --- a/src/Mod/TechDraw/Gui/MDIViewPage.cpp +++ b/src/Mod/TechDraw/Gui/MDIViewPage.cpp @@ -84,6 +84,7 @@ #include #include #include +#include #include "Rez.h" #include "QGIDrawingTemplate.h" @@ -365,6 +366,9 @@ bool MDIViewPage::attachView(App::DocumentObject *obj) } else if (typeId.isDerivedFrom(TechDraw::DrawRichAnno::getClassTypeId()) ) { qview = m_view->addRichAnno( static_cast(obj) ); + } else if (typeId.isDerivedFrom(TechDraw::DrawWeldSymbol::getClassTypeId()) ) { + qview = m_view->addWeldSymbol( static_cast(obj) ); + } else if (typeId.isDerivedFrom(TechDraw::DrawHatch::getClassTypeId()) ) { //Hatch is not attached like other Views (since it isn't really a View) return true; diff --git a/src/Mod/TechDraw/Gui/QGCustomText.cpp b/src/Mod/TechDraw/Gui/QGCustomText.cpp index c6796977d1..d35eafb2d5 100644 --- a/src/Mod/TechDraw/Gui/QGCustomText.cpp +++ b/src/Mod/TechDraw/Gui/QGCustomText.cpp @@ -49,7 +49,8 @@ using namespace TechDrawGui; -QGCustomText::QGCustomText() +QGCustomText::QGCustomText(QGraphicsItem* parent) : + QGraphicsTextItem(parent) { setCacheMode(QGraphicsItem::NoCache); setAcceptHoverEvents(false); @@ -64,12 +65,6 @@ QGCustomText::QGCustomText() void QGCustomText::centerAt(QPointF centerPos) { centerAt(centerPos.x(),centerPos.y()); -// 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) @@ -82,8 +77,52 @@ void QGCustomText::centerAt(double cX, double cY) setPos(newX,newY); } +void QGCustomText::justifyLeftAt(QPointF centerPos, bool vCenter) +{ + justifyLeftAt(centerPos.x(),centerPos.y(), vCenter); +} + +void QGCustomText::justifyLeftAt(double cX, double cY, bool vCenter) +{ + QRectF box = boundingRect(); + double height = box.height(); + double newY = cY - height; + if (vCenter) { + newY = cY - height/2.; + } + setPos(cX,newY); +} + +void QGCustomText::justifyRightAt(QPointF centerPos, bool vCenter) +{ + justifyRightAt(centerPos.x(),centerPos.y(), vCenter); +} + +void QGCustomText::justifyRightAt(double cX, double cY, bool vCenter) +{ + QRectF box = boundingRect(); + double width = box.width(); + double height = box.height(); + double newX = cX - width; + double newY = cY - height; + if (vCenter) { + newY = cY - height/2.; + } + setPos(newX,newY); +} + +double QGCustomText::getHeight(void) +{ + return boundingRect().height(); +} + +double QGCustomText::getWidth(void) +{ + return boundingRect().width(); +} QVariant QGCustomText::itemChange(GraphicsItemChange change, const QVariant &value) { +// Base::Console().Message("QGCT::itemChange - this: %X change: %d\n", this, change); if (change == ItemSelectedHasChanged && scene()) { if(isSelected()) { setPrettySel(); @@ -112,18 +151,20 @@ void QGCustomText::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) } void QGCustomText::setPrettyNormal() { -// m_colCurrent = getNormalColor(); m_colCurrent = m_colNormal; + setDefaultTextColor(m_colNormal); update(); } void QGCustomText::setPrettyPre() { m_colCurrent = getPreColor(); + setDefaultTextColor(m_colCurrent); update(); } void QGCustomText::setPrettySel() { m_colCurrent = getSelectColor(); + setDefaultTextColor(m_colCurrent); update(); } @@ -131,31 +172,19 @@ void QGCustomText::paint ( QPainter * painter, const QStyleOptionGraphicsItem * QStyleOptionGraphicsItem myOption(*option); myOption.state &= ~QStyle::State_Selected; +// painter->setPen(Qt::green); // painter->drawRect(boundingRect()); //good for debugging - setDefaultTextColor(m_colCurrent); QGraphicsTextItem::paint (painter, &myOption, widget); } -QColor QGCustomText::getNormalColor() +QColor QGCustomText::getNormalColor() //preference! { QColor result; - QGIView *parent; - QGraphicsItem* qparent = parentItem(); - if (qparent == nullptr) { - parent = nullptr; - } else { - parent = dynamic_cast (qparent); - } - - if (parent != nullptr) { - result = parent->getNormalColor(); - } else { - Base::Reference hGrp = getParmGroup(); - App::Color fcColor; - fcColor.setPackedValue(hGrp->GetUnsigned("NormalColor", 0x00000000)); - result = fcColor.asValue(); - } + Base::Reference hGrp = getParmGroup(); + App::Color fcColor; + fcColor.setPackedValue(hGrp->GetUnsigned("NormalColor", 0x00000000)); + result = fcColor.asValue(); return result; } diff --git a/src/Mod/TechDraw/Gui/QGCustomText.h b/src/Mod/TechDraw/Gui/QGCustomText.h index b2ad795ef5..a5397bd4c5 100644 --- a/src/Mod/TechDraw/Gui/QGCustomText.h +++ b/src/Mod/TechDraw/Gui/QGCustomText.h @@ -41,24 +41,34 @@ namespace TechDrawGui class TechDrawGuiExport QGCustomText : public QGraphicsTextItem { public: - explicit QGCustomText(void); + explicit QGCustomText(QGraphicsItem* parent = nullptr); ~QGCustomText() {} enum {Type = QGraphicsItem::UserType + 130}; int type() const { return Type;} + virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); void setHighlighted(bool state); virtual void setPrettyNormal(); virtual void setPrettyPre(); virtual void setPrettySel(); - virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); virtual void centerAt(QPointF centerPos); virtual void centerAt(double cX, double cY); + virtual void justifyLeftAt(QPointF centerPos, bool vCenter = true); + virtual void justifyLeftAt(double cX, double cY, bool vCenter = true); + virtual void justifyRightAt(QPointF centerPos, bool vCenter = true); + virtual void justifyRightAt(double cX, double cY, bool vCenter = true); + + virtual double getHeight(void); + virtual double getWidth(void); + virtual QColor getNormalColor(void); virtual QColor getPreColor(void); virtual QColor getSelectColor(void); - virtual void setColor(QColor c) { m_colNormal = c; } + virtual void setColor(QColor c) { m_colNormal = c; + setDefaultTextColor(c); } + void makeMark(double x, double y); void makeMark(Base::Vector3d v); diff --git a/src/Mod/TechDraw/Gui/QGIArrow.cpp b/src/Mod/TechDraw/Gui/QGIArrow.cpp index 001ef5739b..0de92f8d27 100644 --- a/src/Mod/TechDraw/Gui/QGIArrow.cpp +++ b/src/Mod/TechDraw/Gui/QGIArrow.cpp @@ -49,8 +49,10 @@ QGIArrow::QGIArrow() : m_dirMode(false), m_dir(Base::Vector3d(1.0,0.0,0.0)) { + isFlipped = false; + setFill(Qt::SolidPattern); m_brush.setStyle(m_fill); - + setCacheMode(QGraphicsItem::NoCache); setAcceptHoverEvents(false); setFlag(QGraphicsItem::ItemIsSelectable, false); @@ -60,6 +62,7 @@ QGIArrow::QGIArrow() : void QGIArrow::draw() { QPainterPath path; if (m_style == 0) { + setFill(Qt::SolidPattern); if (m_dirMode) { path = makeFilledTriangle(getDirection(), m_size,m_size/6.0); } else { diff --git a/src/Mod/TechDraw/Gui/QGIDecoration.cpp b/src/Mod/TechDraw/Gui/QGIDecoration.cpp index 876cc19aba..be44a56862 100644 --- a/src/Mod/TechDraw/Gui/QGIDecoration.cpp +++ b/src/Mod/TechDraw/Gui/QGIDecoration.cpp @@ -83,8 +83,43 @@ void QGIDecoration::setStyle(Qt::PenStyle s) void QGIDecoration::setColor(QColor c) { + m_colNormal = c; m_colCurrent = c; m_pen.setColor(m_colCurrent); + m_brush.setColor(m_colCurrent); +} + +QColor QGIDecoration::prefNormalColor() +{ + QColor result; + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors"); + App::Color fcColor; + fcColor.setPackedValue(hGrp->GetUnsigned("NormalColor", 0x00000000)); + result = fcColor.asValue(); + return result; +} + +QColor QGIDecoration::prefPreColor() +{ + QColor result; + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors"); + App::Color fcColor; + fcColor.setPackedValue(hGrp->GetUnsigned("PreSelectColor", 0x00000000)); + result = fcColor.asValue(); + return result; +} + +QColor QGIDecoration::prefSelectColor() +{ + QColor result; + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors"); + App::Color fcColor; + fcColor.setPackedValue(hGrp->GetUnsigned("SelectColor", 0x00000000)); + result = fcColor.asValue(); + return result; } void QGIDecoration::makeMark(double x, double y) diff --git a/src/Mod/TechDraw/Gui/QGIDecoration.h b/src/Mod/TechDraw/Gui/QGIDecoration.h index 00659959f8..b7697b6466 100644 --- a/src/Mod/TechDraw/Gui/QGIDecoration.h +++ b/src/Mod/TechDraw/Gui/QGIDecoration.h @@ -52,13 +52,22 @@ public: void setWidth(double w); void setStyle(Qt::PenStyle s); void setColor(QColor c); + QColor getColor(void) { return m_colNormal; } + void setFill(Qt::BrushStyle bs) { m_brushCurrent = bs; } void makeMark(double x, double y); void makeMark(Base::Vector3d v); protected: + void setPrettyNormal(); + void setPrettyPre(); + void setPrettySel(); + virtual QColor prefNormalColor(void); + virtual QColor prefPreColor(void); + virtual QColor prefSelectColor(void); QPen m_pen; QBrush m_brush; QColor m_colCurrent; + QColor m_colNormal; double m_width; Qt::PenStyle m_styleCurrent; Qt::BrushStyle m_brushCurrent; diff --git a/src/Mod/TechDraw/Gui/QGIEdge.cpp b/src/Mod/TechDraw/Gui/QGIEdge.cpp index 6a3f3dd081..2506845048 100644 --- a/src/Mod/TechDraw/Gui/QGIEdge.cpp +++ b/src/Mod/TechDraw/Gui/QGIEdge.cpp @@ -48,6 +48,7 @@ QGIEdge::QGIEdge(int index) : { m_width = 1.0; setCosmetic(isCosmetic); + setFill(Qt::NoBrush); } //NOTE this refers to Qt cosmetic lines diff --git a/src/Mod/TechDraw/Gui/QGILeaderLine.cpp b/src/Mod/TechDraw/Gui/QGILeaderLine.cpp index 2829661b63..a6589a3f4d 100644 --- a/src/Mod/TechDraw/Gui/QGILeaderLine.cpp +++ b/src/Mod/TechDraw/Gui/QGILeaderLine.cpp @@ -361,6 +361,7 @@ void QGILeaderLine::draw() return; } + m_line->setFill(Qt::NoBrush); m_line->setStyle(m_lineStyle); double scaler = 1.0; m_line->setWidth(scaler * m_lineWidth); @@ -498,6 +499,11 @@ void QGILeaderLine::abandonEdit(void) restoreState(); } +double QGILeaderLine::getLineWidth(void) +{ + return m_lineWidth; +} + TechDraw::DrawLeaderLine* QGILeaderLine::getFeature(void) { TechDraw::DrawLeaderLine* result = @@ -548,6 +554,7 @@ void QGILeaderLine::paint ( QPainter * painter, const QStyleOptionGraphicsItem * QStyleOptionGraphicsItem myOption(*option); myOption.state &= ~QStyle::State_Selected; +// painter->setPen(Qt::blue); // painter->drawRect(boundingRect()); //good for debugging QGIView::paint (painter, &myOption, widget); diff --git a/src/Mod/TechDraw/Gui/QGILeaderLine.h b/src/Mod/TechDraw/Gui/QGILeaderLine.h index 2be3c2a96e..0db864b315 100644 --- a/src/Mod/TechDraw/Gui/QGILeaderLine.h +++ b/src/Mod/TechDraw/Gui/QGILeaderLine.h @@ -82,6 +82,8 @@ public: void abandonEdit(void); void closeEdit(void); + + double getLineWidth(void); public Q_SLOTS: void onLineEditFinished(QPointF attach, std::vector deltas); //QGEPath is finished editing points diff --git a/src/Mod/TechDraw/Gui/QGIPrimPath.cpp b/src/Mod/TechDraw/Gui/QGIPrimPath.cpp index dc01533e0c..a6a1a7d013 100644 --- a/src/Mod/TechDraw/Gui/QGIPrimPath.cpp +++ b/src/Mod/TechDraw/Gui/QGIPrimPath.cpp @@ -42,7 +42,9 @@ using namespace TechDrawGui; QGIPrimPath::QGIPrimPath(): m_width(0), - m_capStyle(Qt::RoundCap) + m_capStyle(Qt::RoundCap), + m_fill(Qt::NoBrush) +// m_fill(Qt::SolidPattern) { setCacheMode(QGraphicsItem::NoCache); setFlag(QGraphicsItem::ItemIsSelectable, true); @@ -129,6 +131,11 @@ void QGIPrimPath::paint ( QPainter * painter, const QStyleOptionGraphicsItem * o m_pen.setColor(m_colCurrent); m_pen.setStyle(m_styleCurrent); setPen(m_pen); + + m_brush.setColor(m_colCurrent); + m_brush.setStyle(m_fill); + setBrush(m_brush); + QGraphicsPathItem::paint (painter, &myOption, widget); } @@ -256,15 +263,21 @@ Qt::PenCapStyle QGIPrimPath::prefCapStyle() void QGIPrimPath::mousePressEvent(QGraphicsSceneMouseEvent * event) { + //wf: this seems a bit of a hack. does it mess up selection of QGIPP?? QGIView *parent; QGraphicsItem* qparent = parentItem(); if (qparent != nullptr) { parent = dynamic_cast (qparent); if (parent != nullptr) { +// Base::Console().Message("QGIPP::mousePressEvent - passing event to QGIV parent\n"); parent->mousePressEvent(event); } else { +// qparent->mousePressEvent(event); //protected! + QGraphicsPathItem::mousePressEvent(event); Base::Console().Log("QGIPP::mousePressEvent - no QGIView parent\n"); } + } else { +// Base::Console().Message("QGIPP::mousePressEvent - passing event to ancestor\n"); + QGraphicsPathItem::mousePressEvent(event); } - QGraphicsPathItem::mousePressEvent(event); } diff --git a/src/Mod/TechDraw/Gui/QGIPrimPath.h b/src/Mod/TechDraw/Gui/QGIPrimPath.h index 25babf8075..6e4c5be519 100644 --- a/src/Mod/TechDraw/Gui/QGIPrimPath.h +++ b/src/Mod/TechDraw/Gui/QGIPrimPath.h @@ -58,6 +58,8 @@ public: void setStyle(int s); virtual void setNormalColor(QColor c); virtual void setCapStyle(Qt::PenCapStyle c); + Qt::BrushStyle getFill() { return m_fill; } + void setFill(Qt::BrushStyle f) { m_fill = f; } protected: virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; @@ -79,6 +81,9 @@ protected: Qt::PenStyle m_styleCurrent; double m_width; Qt::PenCapStyle m_capStyle; + QBrush m_brush; + Qt::BrushStyle m_fill; + private: diff --git a/src/Mod/TechDraw/Gui/QGITile.cpp b/src/Mod/TechDraw/Gui/QGITile.cpp new file mode 100644 index 0000000000..629f8dcdd6 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGITile.cpp @@ -0,0 +1,351 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +#include +#include +#include +#include +#endif + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include "Rez.h" +#include "DrawGuiUtil.h" +#include "QGIView.h" +#include "QGITile.h" + +using namespace TechDrawGui; + +QGITile::QGITile(TechDraw::DrawTile* feat) : + m_tileFeat(feat), + m_textL(QString()), + m_textR(QString()), + m_textC(QString()), + m_textSize(0.0), + m_row(0), + m_col(0), + m_scale(1.0) +{ + m_qgSvg = new QGCustomSvg(); + m_qgSvg->setParentItem(this); + m_effect = new QGraphicsColorizeEffect(); + m_qgTextL = new QGCustomText(); + m_qgTextL->setParentItem(this); + m_qgTextR = new QGCustomText(); + m_qgTextR->setParentItem(this); + m_qgTextC = new QGCustomText(); + m_qgTextC->setParentItem(this); + + m_wide = getSymbolWidth(); + m_high = getFontSize(); + m_textSize = getFontSize(); + m_textL = QString(); + m_textR = QString(); + m_textC = QString(); + m_fontName = getTextFont(); + m_font = QFont(m_fontName); + +// setHandlesChildEvents(true); //qt4 + setFiltersChildEvents(true); //qt5 + setAcceptHoverEvents(true); + setFlag(QGraphicsItem::ItemIsSelectable, false); + setFlag(QGraphicsItem::ItemIsMovable, false); + setFlag(QGraphicsItem::ItemSendsScenePositionChanges, false); + setFlag(QGraphicsItem::ItemSendsGeometryChanges,true); + setFlag(QGraphicsItem::ItemStacksBehindParent, true); + + m_colNormal = prefNormalColor(); + m_colCurrent = m_colNormal; +} + +QVariant QGITile::itemChange(GraphicsItemChange change, const QVariant &value) +{ +// Base::Console().Message("QGIT::itemChange(%d)\n", change); + return QGIDecoration::itemChange(change, value); +} + +void QGITile::draw(void) +{ +// Base::Console().Message("QGIT::draw()\n"); + prepareGeometryChange(); + m_wide = getSymbolWidth(); + m_high = getSymbolHeight() * scaleToFont(); + + makeText(); + makeSymbol(); + + double textWidthL = m_qgTextL->boundingRect().width(); + double textWidthR = m_qgTextR->boundingRect().width(); + double totalWidth = m_wide + textWidthL + textWidthR; + + double x = m_origin.x() + m_col * totalWidth; //bit of a hack. sb 0.5 of prev tile + 0.5 of this tile + double y = m_origin.y() - (m_row * m_high) - (m_high * 0.5); //inverted y!! + setPos(x,y); +} + +void QGITile::makeSymbol(void) +{ +// Base::Console().Message("QGIT::makeSymbol()\n"); + m_effect->setColor(m_colCurrent); + + m_qgSvg->setGraphicsEffect(m_effect); + QFile svgFile(m_svgPath); + if(svgFile.open(QIODevice::ReadOnly)) { + QByteArray qba = svgFile.readAll(); + if (!m_qgSvg->load(&qba)) { + Base::Console().Error("Error - Could not load SVG renderer with %s\n", qPrintable(m_svgPath)); + } + svgFile.close(); + } else { + Base::Console().Error("Error - Could not open file %s\n", qPrintable(m_svgPath)); + } + + m_qgSvg->setScale(scaleToFont()); + m_qgSvg->centerAt(0.0, 0.0); //(0,0) is based on symbol size +} + +void QGITile::makeText(void) +{ +// Base::Console().Message("QGIT::makeText()\n"); + prepareGeometryChange(); + m_font.setPixelSize(getFontSize()); + double verticalFudge = 0.10; //% of textHeight + + m_qgTextL->setFont(m_font); + m_qgTextL->setPlainText(m_textL); + m_qgTextL->setColor(m_colCurrent); + double textWidth = m_qgTextL->boundingRect().width(); + double charWidth = textWidth / m_textL.size(); //not good for non-ASCII chars + double hMargin = (m_wide / 2.0) + (charWidth / 2.0); + + double textHeightL = m_qgTextL->boundingRect().height(); + double offsetAdjustL = 0.0; + if (m_row < 0) { + offsetAdjustL = -textHeightL * verticalFudge; + } else { + offsetAdjustL = textHeightL * verticalFudge; + } + double offset = (textHeightL * verticalFudge * m_row) + offsetAdjustL; + m_qgTextL->justifyRightAt(-hMargin, -offset, true); + + m_qgTextR->setFont(m_font); + m_qgTextR->setPlainText(m_textR); + m_qgTextR->setColor(m_colCurrent); + textWidth = m_qgTextR->boundingRect().width(); + charWidth = textWidth / m_textR.size(); + double textHeightR = m_qgTextR->boundingRect().height(); + double offsetAdjustR = 0.0; + if (m_row < 0) { + offsetAdjustR = -textHeightR * verticalFudge; + } else { + offsetAdjustR = textHeightR * verticalFudge; + } + offset = (textHeightR * verticalFudge * m_row) + offsetAdjustR; + m_qgTextR->justifyLeftAt(hMargin, -offset, true); + + m_qgTextC->setFont(m_font); + m_qgTextC->setPlainText(m_textC); + m_qgTextC->setColor(m_colCurrent); + double textHeightC = m_qgTextC->boundingRect().height(); + textHeightC = textHeightC; + int rowAdjustC = m_row; + if (m_row >= 0) { + rowAdjustC++; + } + double offsetAdjustC = textHeightC * verticalFudge; + if (m_row < 0) { + offsetAdjustC = - offsetAdjustC; + } + offset = (textHeightC * rowAdjustC) - offsetAdjustC; + m_qgTextC->centerAt(0.0, -offset); +} + +void QGITile::setTilePosition(QPointF org, int r, int c) +{ + m_origin = org; + m_row = r; + m_col = c; +} + +void QGITile::setTileScale(double s) +{ + m_scale = s; +} + +void QGITile::setTileTextLeft(std::string s) +{ + m_textL = QString::fromUtf8(s.c_str()); +} + +void QGITile::setTileTextRight(std::string s) +{ + m_textR = QString::fromUtf8(s.c_str()); +} + +void QGITile::setTileTextCenter(std::string s) +{ + m_textC = QString::fromUtf8(s.c_str()); +} + +//using label font and dimension font size. could change later +//void QGITile::setFont(QFont f, double fsize) +//{ +// m_font = f; +// m_textSize = fsize; +//} + +void QGITile::setSymbolFile(std::string s) +{ +// Base::Console().Message("QGIT::setSymbolFile(%s)\n",s.c_str()); + if (!s.empty()) { + m_svgPath = QString::fromUtf8(s.c_str()); + } +} + +void QGITile::setPrettyNormal() { + m_colCurrent = m_colNormal; + + m_effect->setColor(m_colNormal); + m_qgTextL->setColor(m_colNormal); + m_qgTextR->setColor(m_colNormal); + m_qgTextC->setColor(m_colNormal); + + draw(); +} + +void QGITile::setPrettyPre() { + m_colCurrent = prefPreColor(); + + m_effect->setColor(m_colCurrent); + m_qgTextL->setColor(m_colCurrent); + m_qgTextR->setColor(m_colCurrent); + m_qgTextC->setColor(m_colCurrent); + + draw(); +} + +void QGITile::setPrettySel() { + m_colCurrent = prefSelectColor(); + + m_effect->setColor(m_colCurrent); + m_qgTextL->setColor(m_colCurrent); + m_qgTextR->setColor(m_colCurrent); + m_qgTextC->setColor(m_colCurrent); + + draw(); +} + + +//TODO: this is Pen, not Brush. sb Brush to colour background +QColor QGITile::getTileColor(void) const +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors"); + App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("TileColor", 0x00000000)); + return fcColor.asValue(); +} + +double QGITile::getSymbolWidth(void) const +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> + GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); + double w = hGrp->GetFloat("SymbolSize",64); +// symbols are only nominally 64x64. they actually have a "border" of 4 - 0.5*stroke(0.5) +// so we'll say effectively 62x62? 60 x 60 +// double w = 64.0; + double fudge = 4.0; //allowance for tile border + w = w - fudge; + return w; +} + +double QGITile::getSymbolHeight(void) const +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> + GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); + double h = hGrp->GetFloat("SymbolSize",64); + double fudge = 4.0; + h = h - fudge; +// double h = 60.0; + return h; +} + +double QGITile::getSymbolFactor(void) const +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> + GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations"); + double s = hGrp->GetFloat("SymbolFactor",1.25); +// double s = 1.25; + return s; +} + +double QGITile::getFontSize(void) const +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter(). + GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); + double sizeMM = hGrp->GetFloat("FontSize", QGIView::DefaultFontSizeInMM); + double fontSize = QGIView::calculateFontPixelSize(sizeMM); + return fontSize; +} + +//factor to scale symbol to match font size +double QGITile::scaleToFont(void) const +{ + double fpx = getFontSize(); + double spx = getSymbolHeight(); + double factor = getSymbolFactor(); + double sf = (fpx / spx) * factor; + return sf; +} + +QString QGITile::getTextFont(void) const +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter(). + GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Labels"); + std::string fontName = hGrp->GetASCII("LabelFont", "osifont"); + return QString::fromStdString(fontName); +} + +void QGITile::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { + QStyleOptionGraphicsItem myOption(*option); + myOption.state &= ~QStyle::State_Selected; + +// painter->setPen(Qt::magenta); +// painter->drawRect(boundingRect()); //good for debugging + + QGIDecoration::paint (painter, &myOption, widget); +} + +QRectF QGITile::boundingRect() const +{ + return childrenBoundingRect(); +} + diff --git a/src/Mod/TechDraw/Gui/QGITile.h b/src/Mod/TechDraw/Gui/QGITile.h new file mode 100644 index 0000000000..b04d859d31 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGITile.h @@ -0,0 +1,114 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef TECHDRAWGUI_QGITILE_H +#define TECHDRAWGUI_QGITILE_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "QGIArrow.h" +#include "QGCustomText.h" +#include "QGCustomRect.h" +#include "QGCustomSvg.h" +#include "QGIDecoration.h" + +namespace TechDraw { +class DrawTile; +class DrawTileWeld; +} + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGITile : public QGIDecoration +{ +public: + explicit QGITile(TechDraw::DrawTile* tileFeat); + ~QGITile(void) {} + + enum {Type = QGraphicsItem::UserType + 325}; + int type(void) const { return Type;} + + virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); + virtual QRectF boundingRect() const; + + void setTileTextLeft(std::string s); + void setTileTextRight(std::string s); + void setTileTextCenter(std::string s); + void setFont(QFont f, double fsize); + void setSymbolFile(std::string s); + void setTilePosition(QPointF org, int row, int col); + void setTileScale(double s); +// double getSymbolScale(void) const; + virtual void draw(void); + +protected: + virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); + + QColor getTileColor(void) const; + void setPrettyNormal(); + void setPrettyPre(); + void setPrettySel(); + + double getSymbolWidth(void) const; + double getSymbolHeight(void) const; + double getSymbolFactor(void) const; + QString getTextFont(void) const; + double getFontSize(void) const; + double scaleToFont(void) const; + void makeSymbol(void); + void makeText(void); + +private: + TechDraw::DrawTile* m_tileFeat; + QGCustomText* m_qgTextL; + QGCustomText* m_qgTextR; + QGCustomText* m_qgTextC; + QGCustomSvg* m_qgSvg; + QGraphicsColorizeEffect* m_effect; + QString m_svgPath; + QString m_textL; + QString m_textR; + QString m_textC; + QString m_fontName; + QFont m_font; + double m_textSize; + int m_row; + int m_col; + QPointF m_origin; + double m_wide; + double m_high; + double m_scale; +}; + +} + +#endif // TECHDRAWGUI_QGITILE_H diff --git a/src/Mod/TechDraw/Gui/QGIUserTypes.h b/src/Mod/TechDraw/Gui/QGIUserTypes.h index fa573c94e6..9c7f2fb8b1 100644 --- a/src/Mod/TechDraw/Gui/QGIUserTypes.h +++ b/src/Mod/TechDraw/Gui/QGIUserTypes.h @@ -47,6 +47,8 @@ QGIRichAnno: 233 QGMText: 300 QGEPath: 301 QGMarker: 302 +QGITile: 325 +QGIWeldSymbol: 340 */ /* diff --git a/src/Mod/TechDraw/Gui/QGIVertex.cpp b/src/Mod/TechDraw/Gui/QGIVertex.cpp index 5583493da3..7f23b76bf3 100644 --- a/src/Mod/TechDraw/Gui/QGIVertex.cpp +++ b/src/Mod/TechDraw/Gui/QGIVertex.cpp @@ -35,15 +35,16 @@ #include //#include +#include "QGIPrimPath.h" #include "QGIVertex.h" using namespace TechDrawGui; QGIVertex::QGIVertex(int index) : projIndex(index), - m_radius(2), - m_fill(Qt::SolidPattern) + m_radius(2) { + m_fill = Qt::SolidPattern; m_brush.setStyle(m_fill); setRadius(m_radius); @@ -62,8 +63,11 @@ void QGIVertex::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QStyleOptionGraphicsItem myOption(*option); myOption.state &= ~QStyle::State_Selected; - m_brush.setColor(m_colCurrent); - m_brush.setStyle(m_fill); - setBrush(m_brush); +// painter->setPen(Qt::blue); +// painter->drawRect(boundingRect()); //good for debugging + +// m_brush.setColor(m_colCurrent); +// m_brush.setStyle(m_fill); +// setBrush(m_brush); QGIPrimPath::paint (painter, &myOption, widget); } diff --git a/src/Mod/TechDraw/Gui/QGIVertex.h b/src/Mod/TechDraw/Gui/QGIVertex.h index 542ebdef70..ecf1d068b7 100644 --- a/src/Mod/TechDraw/Gui/QGIVertex.h +++ b/src/Mod/TechDraw/Gui/QGIVertex.h @@ -42,14 +42,14 @@ public: float getRadius() { return m_radius; } virtual void setRadius(float r); - Qt::BrushStyle getFill() { return m_fill; } - void setFill(Qt::BrushStyle f) { m_fill = f; } +/* Qt::BrushStyle getFill() { return m_fill; }*/ +/* void setFill(Qt::BrushStyle f) { m_fill = f; }*/ protected: int projIndex; float m_radius; - QBrush m_brush; - Qt::BrushStyle m_fill; +/* QBrush m_brush;*/ +/* Qt::BrushStyle m_fill;*/ private: }; diff --git a/src/Mod/TechDraw/Gui/QGIView.cpp b/src/Mod/TechDraw/Gui/QGIView.cpp index b91eec3f88..415b291155 100644 --- a/src/Mod/TechDraw/Gui/QGIView.cpp +++ b/src/Mod/TechDraw/Gui/QGIView.cpp @@ -82,7 +82,8 @@ QGIView::QGIView() :QGraphicsItemGroup(), viewObj(nullptr), m_locked(false), - m_innerView(false) + m_innerView(false), + m_selectState(0) { setCacheMode(QGraphicsItem::NoCache); setHandlesChildEvents(false); @@ -215,8 +216,10 @@ QVariant QGIView::itemChange(GraphicsItemChange change, const QVariant &value) if (change == ItemSelectedHasChanged && scene()) { if(isSelected()) { m_colCurrent = getSelectColor(); + m_selectState = 2; } else { m_colCurrent = getNormalColor(); + m_selectState = 0; } drawBorder(); } @@ -257,8 +260,10 @@ void QGIView::hoverEnterEvent(QGraphicsSceneHoverEvent *event) // TODO don't like this but only solution at the minute (MLP) if (isSelected()) { m_colCurrent = getSelectColor(); + m_selectState = 2; } else { m_colCurrent = getPreColor(); + m_selectState = 1; } drawBorder(); } @@ -268,8 +273,10 @@ void QGIView::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_UNUSED(event); if(isSelected()) { m_colCurrent = getSelectColor(); + m_selectState = 1; } else { m_colCurrent = getNormalColor(); + m_selectState = 0; } drawBorder(); } @@ -622,6 +629,7 @@ bool QGIView::getFrameState(void) return result; } +//TODO: change name to prefNormalColor() QColor QGIView::getNormalColor() { Base::Reference hGrp = getParmGroupCol(); diff --git a/src/Mod/TechDraw/Gui/QGIView.h b/src/Mod/TechDraw/Gui/QGIView.h index f82a8901d0..e24b3bdd44 100644 --- a/src/Mod/TechDraw/Gui/QGIView.h +++ b/src/Mod/TechDraw/Gui/QGIView.h @@ -105,9 +105,12 @@ public: void alignTo(QGraphicsItem*, const QString &alignment); void setLocked(bool b) { m_locked = b; } - virtual QColor getNormalColor(void); - virtual QColor getPreColor(void); - virtual QColor getSelectColor(void); + virtual QColor getNormalColor(void); //preference + virtual QColor getPreColor(void); //preference + virtual QColor getSelectColor(void); //preference + virtual QColor getCurrentColor(void) { return m_colCurrent; } + virtual QColor getSettingColor(void) { return m_colSetting; } + virtual void setSettingColor(QColor c) { m_colSetting = c; } static Gui::ViewProvider* getViewProvider(App::DocumentObject* obj); static QGVPage* getGraphicsView(TechDraw::DrawView* dv); @@ -156,6 +159,7 @@ protected: QColor m_colNormal; QColor m_colPre; QColor m_colSel; + QColor m_colSetting; QFont m_font; QGCustomLabel* m_label; QGCustomBorder* m_border; @@ -165,6 +169,7 @@ protected: double m_lockWidth; double m_lockHeight; + int m_selectState; }; } // namespace diff --git a/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp new file mode 100644 index 0000000000..f7b3e9cf6c --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp @@ -0,0 +1,441 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ + #include + #include + # include + # include + # include + # include + # include + + # include + # include + # include + # include + + # include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include "Rez.h" +#include "ZVALUE.h" +#include "ViewProviderWeld.h" +#include "MDIViewPage.h" +#include "DrawGuiUtil.h" +#include "QGVPage.h" +#include "QGIPrimPath.h" +#include "QGITile.h" +#include "QGILeaderLine.h" +#include "QGIVertex.h" +#include "QGCustomText.h" + +#include "QGIWeldSymbol.h" + +using namespace TechDraw; +using namespace TechDrawGui; + + +//************************************************************** +QGIWeldSymbol::QGIWeldSymbol(QGILeaderLine* myParent, + TechDraw::DrawWeldSymbol* weld) : + m_weldFeat(weld), + m_qgLead(myParent), + m_blockDraw(false) +{ +// setHandlesChildEvents(true); //qt4 deprecated in qt5 + setFiltersChildEvents(true); //qt5 + setFlag(QGraphicsItem::ItemIsMovable, false); + + setCacheMode(QGraphicsItem::NoCache); + + setParentItem(m_qgLead); + setViewFeature(weld); + m_leadFeat = m_qgLead->getFeature(); + setZValue(ZVALUE::DIMENSION); + + m_tailText = new QGCustomText(); + addToGroup(m_tailText); + m_colCurrent = getNormalColor(); //preference + m_colSetting = m_colCurrent; +} + +QVariant QGIWeldSymbol::itemChange(GraphicsItemChange change, const QVariant &value) +{ +// Base::Console().Message("QGIWS::itemChange(%d)\n", change); + if (change == ItemSelectedHasChanged && scene()) { + if(isSelected()) { + setPrettySel(); + } else { + setPrettyNormal(); + } + draw(); + } else if(change == ItemSceneChange && scene()) { + // nothing special! + } + return QGIView::itemChange(change, value); +} + +void QGIWeldSymbol::updateView(bool update) +{ +// Base::Console().Message("QGIWS::updateView() %s\n",m_weldFeat->getNameInDocument()); + Q_UNUSED(update); + if ( m_weldFeat == nullptr ) { + Base::Console().Warning("QGIWS::updateView - no feature!\n"); + return; + } + draw(); +} + +void QGIWeldSymbol::draw() +{ +// Base::Console().Message("QGIWS::draw()- %s\n", m_weldFeat->getNameInDocument()); + if (!isVisible()) { + return; + } + + removeDecorations(); + + std::vector tiles = m_weldFeat->getTiles(); + for (auto& t: tiles) { + if (t != nullptr) { + QGITile* qt = new QGITile(t); + qt->setParentItem(this); + m_tiles.push_back(qt); + drawTile(t, qt); + } + } + + if (m_weldFeat->AllAround.getValue()) { + drawAllAround(); + } + + if (m_weldFeat->FieldWeld.getValue()) { + drawFieldFlag(); + } + + if (strlen(m_weldFeat->TailText.getValue()) != 0) { + drawProcessText(); + } +} + +void QGIWeldSymbol::drawTile(TechDraw::DrawTileWeld* dtw, + QGITile* tile) +{ +// Base::Console().Message("QGIWS::drawTile()\n"); + double featScale = m_leadFeat->getScale(); + + std::string tileTextL = dtw->LeftText.getValue(); + std::string tileTextR = dtw->RightText.getValue(); + std::string tileTextC = dtw->CenterText.getValue(); + tile->setSymbolFile(dtw->SymbolFile.getValue()); + int tileRow = dtw->TileRow.getValue(); + int tileCol = dtw->TileColumn.getValue(); + tile->setTileScale(featScale); + + QPointF org = getTileOrigin(); + tile->setTilePosition(org, tileRow, tileCol); + tile->setColor(getCurrentColor()); + tile->setTileTextLeft(tileTextL); + tile->setTileTextRight(tileTextR); + tile->setTileTextCenter(tileTextC); + tile->setZValue(ZVALUE::DIMENSION); + tile->draw(); +} + +void QGIWeldSymbol::drawAllAround(void) +{ +// Base::Console().Message("QGIWS::drawAllAround()\n"); + m_allAround = new QGIVertex(-1); + m_allAround->setParentItem(this); + + m_allAround->setFlag(QGraphicsItem::ItemIsSelectable, false); + m_allAround->setFlag(QGraphicsItem::ItemIsMovable, false); + m_allAround->setAcceptHoverEvents(false); + + m_allAround->setNormalColor(getCurrentColor()); + + m_allAround->setFill(Qt::NoBrush); + m_allAround->setRadius(calculateFontPixelSize(getDimFontSize())); + double width = m_qgLead->getLineWidth(); + m_allAround->setWidth(width); + m_allAround->setZValue(ZVALUE::DIMENSION); + + QPointF allAroundPos = getKinkPoint(); + m_allAround->setPos(allAroundPos); +} + +void QGIWeldSymbol::drawProcessText(void) +{ +// Base::Console().Message("QGIWS::drawProcessText()\n"); + m_tailText = new QGCustomText(); + m_tailText->setParentItem(this); + + m_font.setFamily(getPrefFont()); + m_font.setPixelSize(calculateFontPixelSize(getDimFontSize())); + + m_tailText->setFont(m_font); + std::string tText = m_weldFeat->TailText.getValue(); + m_tailText->setPlainText( + QString::fromUtf8(tText.c_str())); + m_tailText->setColor(getCurrentColor()); + m_tailText->setZValue(ZVALUE::DIMENSION); + + QPointF textPos = getTailPoint(); + + double textWidth = m_tailText->boundingRect().width(); + double charWidth = textWidth / tText.size(); + double hMargin = charWidth + getPrefArrowSize(); + + if (isTextRightSide()) { + m_tailText->justifyLeftAt(textPos.x() + hMargin, textPos.y(), true); + } else { + m_tailText->justifyRightAt(textPos.x() - hMargin, textPos.y(), true); + } +} + +void QGIWeldSymbol::drawFieldFlag() +{ +// Base::Console().Message("QGIWS::drawFieldFlag()\n"); + std::vector flagPoints = { QPointF(0.0, 0.0), + QPointF(0.0, -3.0), + QPointF(-2.0, -2.5), + QPointF(0.0, -2.0) }; + //flag sb about 2x text? + double scale = calculateFontPixelSize(getDimFontSize()) / 2.0; + QPainterPath path; + path.moveTo(flagPoints.at(0) * scale); + int i = 1; + int stop = flagPoints.size(); + for ( ; i < stop; i++) { + path.lineTo(flagPoints.at(i) * scale); + } + + m_fieldFlag = new QGIPrimPath(); + m_fieldFlag->setParentItem(this); + + m_fieldFlag->setFlag(QGraphicsItem::ItemIsSelectable, false); + m_fieldFlag->setFlag(QGraphicsItem::ItemIsMovable, false); + m_fieldFlag->setAcceptHoverEvents(false); + m_fieldFlag->setPath(path); + + m_fieldFlag->setNormalColor(getCurrentColor()); + m_fieldFlag->setFill(Qt::SolidPattern); + double width = m_qgLead->getLineWidth(); + m_fieldFlag->setWidth(width); + m_fieldFlag->setZValue(ZVALUE::DIMENSION); + + QPointF fieldFlagPos = getKinkPoint(); + m_fieldFlag->setPos(fieldFlagPos); +} + +void QGIWeldSymbol::removeDecorations() +{ +// Base::Console().Message("QGIWS::removeDecorations()\n"); + QList children = childItems(); + for (auto& c:children) { + QGITile* tile = dynamic_cast(c); + QGIPrimPath* prim = dynamic_cast(c); //allAround, fieldFlag + if (tile) { + tile->setParentItem(nullptr); + scene()->removeItem(tile); + delete tile; + } else if (prim) { + prim->setParentItem(nullptr); + scene()->removeItem(prim); + delete prim; + } + } + if (m_tailText != nullptr) { + m_tailText->setParentItem(nullptr); + scene()->removeItem(m_tailText); + delete m_tailText; + } + std::vector noTiles; + m_tiles = noTiles; +} + +void QGIWeldSymbol::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + Q_UNUSED(event); + if (isSelected()) { + setPrettySel(); + m_colCurrent = getSelectColor(); + } else { + m_colCurrent = getPreColor(); + setPrettyPre(); + } + QGIView::hoverEnterEvent(event); +} + +void QGIWeldSymbol::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + Q_UNUSED(event); + if(isSelected()) { + m_colCurrent = getSelectColor(); + setPrettySel(); + } else { + m_colCurrent = m_colNormal; + setPrettyNormal(); + } + QGIView::hoverLeaveEvent(event); +} + +void QGIWeldSymbol::drawBorder() +{ +////Weld Symbols have no border! +// QGIView::drawBorder(); //good for debugging +} + +void QGIWeldSymbol::setPrettyNormal() +{ + for (auto t: m_tiles) { + t->setColor(m_colNormal); + t->draw(); + } + m_fieldFlag->setPrettyNormal(); + m_allAround->setPrettyNormal(); + m_tailText->setPrettyNormal(); +} + +void QGIWeldSymbol::setPrettyPre() +{ +// Base::Console().Message("QGIWS::setPrettyPre()\n"); + for (auto t: m_tiles) { + t->setColor(getPreColor()); + t->draw(); + } + m_fieldFlag->setPrettyPre(); + m_allAround->setPrettyPre(); + m_tailText->setPrettyPre(); +} + +void QGIWeldSymbol::setPrettySel() +{ +// Base::Console().Message("QGIWS::setPrettySel()\n"); + for (auto t: m_tiles) { + t->setColor(getSelectColor()); + t->draw(); + } + m_fieldFlag->setPrettySel(); + m_allAround->setPrettySel(); + m_tailText->setPrettySel(); +} + +QPointF QGIWeldSymbol::getTileOrigin(void) +{ + Base::Vector3d org = m_leadFeat->getTileOrigin(); + QPointF result(org.x, org.y); + return result; +} + +QPointF QGIWeldSymbol::getKinkPoint(void) +{ + Base::Vector3d org = m_leadFeat->getKinkPoint(); + QPointF result(org.x, org.y); + return result; +} + +QPointF QGIWeldSymbol::getTailPoint(void) +{ + Base::Vector3d org = m_leadFeat->getTailPoint(); + QPointF result(org.x, org.y); + return result; +} + +bool QGIWeldSymbol::isTextRightSide() +{ + bool result = true; + Base::Vector3d tail = m_leadFeat->getTailPoint(); + Base::Vector3d kink = m_leadFeat->getKinkPoint(); + if (tail.x < kink.x) { //tail is to left + result = false; + } + return result; +} + +TechDraw::DrawWeldSymbol* QGIWeldSymbol::getFeature(void) +{ + TechDraw::DrawWeldSymbol* result = + static_cast(getViewObject()); + return result; +} + +//preference +QColor QGIWeldSymbol::getNormalColor() +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/LeaderLines"); + App::Color fcColor; + fcColor.setPackedValue(hGrp->GetUnsigned("Color", 0x00000000)); + m_colNormal = fcColor.asValue(); + return m_colNormal; +} + +double QGIWeldSymbol::getPrefArrowSize() +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter(). + GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); + double size = Rez::guiX(hGrp->GetFloat("ArrowSize", 3.5)); + return size; +} + + +QRectF QGIWeldSymbol::boundingRect() const +{ + return customChildrenBoundingRect(); +} + +QPainterPath QGIWeldSymbol::shape() const +{ + return QGraphicsItemGroup::shape(); +} + +void QGIWeldSymbol::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { + QStyleOptionGraphicsItem myOption(*option); + myOption.state &= ~QStyle::State_Selected; + +// painter->setPen(Qt::red); +// painter->drawRect(boundingRect()); //good for debugging + + QGIView::paint (painter, &myOption, widget); +} + +#include diff --git a/src/Mod/TechDraw/Gui/QGIWeldSymbol.h b/src/Mod/TechDraw/Gui/QGIWeldSymbol.h new file mode 100644 index 0000000000..8fd9c80b6f --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIWeldSymbol.h @@ -0,0 +1,120 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef DRAWINGGUI_QGRAPHICSITEMWELDSYMBOL_H +#define DRAWINGGUI_QGRAPHICSITEMWELDSYMBOL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "QGIView.h" + +namespace TechDraw { +class DrawWeldSymbol; +class DrawWeldSymbol; +class DrawView; +} + +namespace TechDrawGui +{ +class QGIPrimPath; +class QGITile; +class QGIVertex; +class QGCustomText; + +//******************************************************************* + +class TechDrawGuiExport QGIWeldSymbol : public QGIView +{ + Q_OBJECT + +public: + enum {Type = QGraphicsItem::UserType + 340}; + + explicit QGIWeldSymbol(QGILeaderLine* myParent = nullptr, + TechDraw::DrawWeldSymbol* lead = nullptr); + ~QGIWeldSymbol() = default; + + int type() const override { return Type;} + virtual void paint( QPainter * painter, + const QStyleOptionGraphicsItem * option, + QWidget * widget = 0 ) override; + virtual QRectF boundingRect() const override; + virtual QPainterPath shape(void) const override; + double getEdgeFuzz(void) const; + + virtual void drawBorder() override; + virtual void updateView(bool update = false) override; + + virtual TechDraw::DrawWeldSymbol* getFeature(void); + QPointF getTileOrigin(void); + QPointF getKinkPoint(void); + QPointF getTailPoint(void); + bool isTextRightSide(void); + + virtual void setPrettyNormal(); + virtual void setPrettySel(); + virtual void setPrettyPre(); + +protected: + virtual QVariant itemChange( GraphicsItemChange change, + const QVariant &value ) override; + virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; + virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; + + virtual void draw() override; + void drawTile(TechDraw::DrawTileWeld* dtw, + QGITile* tile); + void drawAllAround(void); + void drawProcessText(void); + void drawFieldFlag(); + void removeDecorations(); + +protected: + virtual QColor getNormalColor() override; + double getPrefArrowSize(); + + TechDraw::DrawWeldSymbol* m_weldFeat; + TechDraw::DrawLeaderLine* m_leadFeat; + + QGILeaderLine* m_qgLead; + std::vector m_tiles; + QGCustomText* m_tailText; + QGIPrimPath* m_fieldFlag; + QGIVertex* m_allAround; + + QFont m_font; + + bool m_blockDraw; //prevent redraws while updating. +}; + +} + +#endif // DRAWINGGUI_QGRAPHICSITEMWELDSYMBOL_H diff --git a/src/Mod/TechDraw/Gui/QGVPage.cpp b/src/Mod/TechDraw/Gui/QGVPage.cpp index 30775824f5..3cabcef82d 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.cpp +++ b/src/Mod/TechDraw/Gui/QGVPage.cpp @@ -75,6 +75,7 @@ #include #include #include +#include #include #include "Rez.h" @@ -96,6 +97,7 @@ #include "QGIFace.h" #include "QGILeaderLine.h" #include "QGIRichAnno.h" +#include "QGIWeldSymbol.h" #include "ZVALUE.h" #include "ViewProviderPage.h" @@ -545,6 +547,34 @@ QGIView * QGVPage::addRichAnno(TechDraw::DrawRichAnno* anno) return annoGroup; } +QGIView * QGVPage::addWeldSymbol(TechDraw::DrawWeldSymbol* weld) +{ +// Base::Console().Message("QGVP::addWeldSymbol()\n"); + QGIWeldSymbol* weldGroup = nullptr; + TechDraw::DrawView* parentDV = nullptr; + + App::DocumentObject* parentObj = weld->Leader.getValue(); + if (parentObj != nullptr) { + parentDV = dynamic_cast(parentObj); + } else { + Base::Console().Message("QGVP::addWeldSymbol - no parent doc obj\n"); + } + if (parentDV != nullptr) { + QGIView* parentQV = findQViewForDocObj(parentObj); + QGILeaderLine* leadParent = dynamic_cast(parentQV); + if (leadParent != nullptr) { + weldGroup = new QGIWeldSymbol(leadParent, weld); + weldGroup->updateView(true); + } else { + Base::Console().Message("QGVP::addWeldSymbol - no parent QGILL\n"); + } + } else { + Base::Console().Message("QGVP::addWeldSymbol - parent is not DV!\n"); + } + return weldGroup; +} + + //! find the graphic for a DocumentObject QGIView * QGVPage::findQViewForDocObj(App::DocumentObject *obj) const { diff --git a/src/Mod/TechDraw/Gui/QGVPage.h b/src/Mod/TechDraw/Gui/QGVPage.h index 52904916ac..65f350730f 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.h +++ b/src/Mod/TechDraw/Gui/QGVPage.h @@ -45,6 +45,7 @@ class DrawViewImage; class DrawLeaderLine; class DrawViewBalloon; class DrawRichAnno; +class DrawWeldSymbol; } namespace TechDrawGui @@ -84,6 +85,7 @@ public: QGIView * addDrawViewImage(TechDraw::DrawViewImage *view); QGIView * addViewLeader(TechDraw::DrawLeaderLine* view); QGIView * addRichAnno(TechDraw::DrawRichAnno* anno); + QGIView * addWeldSymbol(TechDraw::DrawWeldSymbol* weld); QGIView* findQViewForDocObj(App::DocumentObject *obj) const; QGIView* getQGIVByName(std::string name); diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index 207cd03eef..0c0c5060e1 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -73,6 +73,8 @@ icons/actions/techdraw-linedecor.svg icons/actions/techdraw-facedecor.svg icons/actions/techdraw-showall.svg + icons/actions/techdraw-weldsymbol.svg + icons/actions/techdraw-tile.svg icons/actions/section-up.svg icons/actions/section-down.svg icons/actions/section-left.svg diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-tile.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-tile.svg new file mode 100644 index 0000000000..e746e04f5a --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-tile.svg @@ -0,0 +1,158 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-weldsymbol.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-weldsymbol.svg new file mode 100644 index 0000000000..578a705c73 --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-weldsymbol.svg @@ -0,0 +1,171 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp new file mode 100644 index 0000000000..917f2d9478 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp @@ -0,0 +1,533 @@ +/*************************************************************************** + * Copyright (c) 2019 Wandererfan +#include +#include + +#endif // #ifndef _PreComp_ + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "DrawGuiStd.h" +#include "QGVPage.h" +#include "QGIView.h" +#include "QGIPrimPath.h" +#include "QGILeaderLine.h" +#include "MDIViewPage.h" +#include "ViewProviderPage.h" +#include "ViewProviderViewPart.h" +#include "Rez.h" + +#include "TaskWeldingSymbol.h" + +using namespace Gui; +using namespace TechDraw; +using namespace TechDrawGui; + +//ctor for creation +TaskWeldingSymbol::TaskWeldingSymbol(TechDraw::DrawLeaderLine* leader) : + ui(new Ui_TaskWeldingSymbol), + m_leadFeat(leader), + m_arrowCount(0), + m_otherCount(0) +{ +// Base::Console().Message("TWS::TWS() - create mode\n"); + if (m_leadFeat == nullptr) { + //should be caught in CMD caller + Base::Console().Error("TaskWeldingSymbol - bad parameters. Can not proceed.\n"); + return; + } + + ui->setupUi(this); + connect(ui->pbArrow0, SIGNAL(clicked(bool)), + this, SLOT(onArrow0Clicked(bool))); + connect(ui->pbArrow1, SIGNAL(clicked(bool)), + this, SLOT(onArrow1Clicked(bool))); + connect(ui->pbOther0, SIGNAL(clicked(bool)), + this, SLOT(onOther0Clicked(bool))); + connect(ui->pbOther1, SIGNAL(clicked(bool)), + this, SLOT(onOther1Clicked(bool))); + connect(ui->fcSymbolDir, SIGNAL(fileNameSelected(const QString&)), + this, SLOT(onDirectorySelected(const QString&))); + + setUiPrimary(); +} + +TaskWeldingSymbol::~TaskWeldingSymbol() +{ + delete ui; +} + +void TaskWeldingSymbol::updateTask() +{ +// blockUpdate = true; + +// blockUpdate = false; +} + +void TaskWeldingSymbol::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(this); + } +} + +void TaskWeldingSymbol::setUiPrimary() +{ +// Base::Console().Message("TWS::setUiPrimary()\n"); + setWindowTitle(QObject::tr("Create Welding Symbol")); + m_currDir = QString::fromUtf8(prefSymbolDir().c_str()); + ui->fcSymbolDir->setFileName(m_currDir); + loadSymbolNames(m_currDir); + + ui->lwSymbols->setViewMode(QListView::IconMode); + ui->lwSymbols->setFlow(QListView::LeftToRight); + ui->lwSymbols->setWrapping(true); + ui->lwSymbols->setDragEnabled(true); + ui->lwSymbols->setSelectionMode(QAbstractItemView::SingleSelection); + ui->lwSymbols->setAcceptDrops(false); +} + +void TaskWeldingSymbol::setUiEdit() +{ +// Base::Console().Message("TWS::setUiEdit()\n"); + setWindowTitle(QObject::tr("Edit Welding Symbol")); +} + +void TaskWeldingSymbol::onArrow0Clicked(bool b) +{ +// Base::Console().Message("TWS::OnArrow0Clicked()\n"); + Q_UNUSED(b); + Qt::KeyboardModifiers km = QApplication::keyboardModifiers(); + if (km & Qt::ControlModifier) { + ui->pbArrow0->setText(QString::fromUtf8("Add")); + ui->pbArrow0->setIcon(QIcon()); + removePendingTile(0,0); + return; + } + + QListWidgetItem* sourceItem = ui->lwSymbols->currentItem(); + QString targetText = sourceItem->text(); + TechDrawGui::Tile2Add newTile; + + QString iconPath = m_currDir + + targetText + + QString::fromUtf8(".svg") ; + + QIcon targetIcon(iconPath); + QSize iconSize(32,32); + ui->pbArrow0->setIcon(targetIcon); + ui->pbArrow0->setIconSize(iconSize); + ui->pbArrow0->setText(QString()); + + newTile.arrowSide = true; + newTile.symbolPath = Base::Tools::toStdString(iconPath); + newTile.leftText = Base::Tools::toStdString(ui->leLeftText->text()); + newTile.centerText = Base::Tools::toStdString(ui->leCenterText->text()); + newTile.rightText = Base::Tools::toStdString(ui->leRightText->text()); + newTile.row = 0; + newTile.col = 0; + m_tiles2Add.push_back(newTile); + m_arrowCount++; +} + +void TaskWeldingSymbol::onArrow1Clicked(bool b) +{ +// Base::Console().Message("TWS::OnArrow1Clicked()\n"); + Q_UNUSED(b); + Qt::KeyboardModifiers km = QApplication::keyboardModifiers(); + if (km & Qt::ControlModifier) { + ui->pbArrow1->setText(QString::fromUtf8("Add")); + ui->pbArrow1->setIcon(QIcon()); + removePendingTile(0,1); + return; + } + + QListWidgetItem* sourceItem = ui->lwSymbols->currentItem(); + QString targetText = sourceItem->text(); + TechDrawGui::Tile2Add newTile; + + QString iconPath = m_currDir + + targetText + + QString::fromUtf8(".svg") ; + + QIcon targetIcon(iconPath); + QSize iconSize(32,32); + ui->pbArrow1->setIcon(targetIcon); + ui->pbArrow1->setIconSize(iconSize); + ui->pbArrow1->setText(QString()); + + newTile.arrowSide = true; + newTile.symbolPath = Base::Tools::toStdString(iconPath); + newTile.leftText = Base::Tools::toStdString(ui->leLeftText->text()); + newTile.centerText = Base::Tools::toStdString(ui->leCenterText->text()); + newTile.rightText = Base::Tools::toStdString(ui->leRightText->text()); + newTile.row = 0; + newTile.col = 1; + m_tiles2Add.push_back(newTile); + m_arrowCount++; +} + +void TaskWeldingSymbol::onOther0Clicked(bool b) +{ +// Base::Console().Message("TWS::onOther0Clicked()\n"); + Q_UNUSED(b); + Qt::KeyboardModifiers km = QApplication::keyboardModifiers(); + if (km & Qt::ControlModifier) { + ui->pbOther0->setText(QString::fromUtf8("Add")); + ui->pbOther0->setIcon(QIcon()); + removePendingTile(-1,0); + return; + } + + QListWidgetItem* sourceItem = ui->lwSymbols->currentItem(); + QString targetText = sourceItem->text(); + TechDrawGui::Tile2Add newTile; + + QString iconPath = m_currDir + + targetText + + QString::fromUtf8(".svg") ; + + QIcon targetIcon(iconPath); + QSize iconSize(32,32); + ui->pbOther0->setIcon(targetIcon); + ui->pbOther0->setIconSize(iconSize); + ui->pbOther0->setText(QString()); + + newTile.arrowSide = false; + newTile.symbolPath = Base::Tools::toStdString(iconPath); + newTile.leftText = Base::Tools::toStdString(ui->leLeftText->text()); + newTile.centerText = Base::Tools::toStdString(ui->leCenterText->text()); + newTile.rightText = Base::Tools::toStdString(ui->leRightText->text()); + newTile.row = -1; + newTile.col = 0; + m_tiles2Add.push_back(newTile); + m_otherCount++; +} + +void TaskWeldingSymbol::onOther1Clicked(bool b) +{ +// Base::Console().Message("TWS::onOther1Clicked()\n"); + Q_UNUSED(b); + Qt::KeyboardModifiers km = QApplication::keyboardModifiers(); + if (km & Qt::ControlModifier) { + ui->pbOther1->setText(QString::fromUtf8("Add")); + ui->pbOther1->setIcon(QIcon()); + removePendingTile(-1,1); + return; + } + + QListWidgetItem* sourceItem = ui->lwSymbols->currentItem(); + QString targetText = sourceItem->text(); + TechDrawGui::Tile2Add newTile; + + QString iconPath = m_currDir + + targetText + + QString::fromUtf8(".svg") ; + + QIcon targetIcon(iconPath); + QSize iconSize(32,32); + ui->pbOther1->setIcon(targetIcon); + ui->pbOther1->setIconSize(iconSize); + ui->pbOther1->setText(QString()); + + newTile.arrowSide = false; + newTile.symbolPath = Base::Tools::toStdString(iconPath); + newTile.leftText = Base::Tools::toStdString(ui->leLeftText->text()); + newTile.centerText = Base::Tools::toStdString(ui->leCenterText->text()); + newTile.rightText = Base::Tools::toStdString(ui->leRightText->text()); + newTile.row = -1; + newTile.col = 1; + m_tiles2Add.push_back(newTile); + m_otherCount++; +} + +void TaskWeldingSymbol::onDirectorySelected(const QString& newDir) +{ +// Base::Console().Message("TWS::onDirectorySelected(%s)\n", qPrintable(newDir)); + m_currDir = newDir + QString::fromUtf8("/"); + loadSymbolNames(m_currDir); +} + +void TaskWeldingSymbol::removePendingTile(int row, int col) +{ +// Base::Console().Message("TWS::removePendingIcon(%d, %d) - tiles in: %d\n", +// row, col, m_tiles2Add.size()); + std::vector newList; + for (auto& t: m_tiles2Add) { + if ((t.row == row) && + (t.col == col) ) { + continue; + } else { + newList.push_back(t); + } + } + m_tiles2Add = newList; +} + + +void TaskWeldingSymbol::blockButtons(bool b) +{ + Q_UNUSED(b); +} + +void TaskWeldingSymbol::loadSymbolNames(QString pathToSymbols) +{ + //fill selection list with names and icons + QDir symbolDir(pathToSymbols); + symbolDir.setFilter(QDir::Files); + QStringList fileNames = symbolDir.entryList(); + + for (auto& fn: fileNames) { + QListWidgetItem* item = new QListWidgetItem(fn, ui->lwSymbols); + QFileInfo fi(fn); + item->setText(fi.baseName()); + QIcon symbolIcon(pathToSymbols + fn); + item->setIcon(symbolIcon); + ui->lwSymbols->addItem(item); + } + ui->lwSymbols->setCurrentRow(0); + ui->lwSymbols->setAcceptDrops(false); //have to do this every time you update the items +} + +//****************************************************************************** +App::DocumentObject* TaskWeldingSymbol::createWeldingSymbol(void) +{ +// Base::Console().Message("TWS::createWeldingSymbol()\n"); + Gui::Command::openCommand("Create WeldSymbol"); + + std::string symbolName = m_leadFeat->getDocument()->getUniqueObjectName("DrawWeldSymbol"); + std::string symbolType = "TechDraw::DrawWeldSymbol"; + + TechDraw::DrawPage* page = m_leadFeat->findParentPage(); + std::string pageName = page->getNameInDocument(); + + Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')", + symbolType.c_str(),symbolName.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)", + pageName.c_str(), symbolName.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.Leader = App.activeDocument().%s", + symbolName.c_str(),m_leadFeat->getNameInDocument()); + + bool allAround = ui->rbAllAround->isChecked(); + std::string allAroundText = allAround ? "True" : "False"; + Command::doCommand(Command::Doc,"App.activeDocument().%s.AllAround = %s", + symbolName.c_str(), allAroundText.c_str()); + + bool fieldWeld = ui->rbFieldWeld->isChecked(); + std::string fieldWeldText = fieldWeld ? "True" : "False"; + Command::doCommand(Command::Doc,"App.activeDocument().%s.FieldWeld = %s", + symbolName.c_str(), fieldWeldText.c_str()); + + std::string tailText = Base::Tools::toStdString(ui->leProcessText->text()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.TailText = '%s'", + symbolName.c_str(), tailText.c_str()); + + App::DocumentObject* newObj = m_leadFeat->getDocument()->getObject(symbolName.c_str()); + if (newObj == nullptr) { + throw Base::RuntimeError("TaskWeldingSymbol - new symbol object not found"); + } + newObj->recomputeFeature(); + Gui::Command::updateActive(); + Gui::Command::commitCommand(); + return newObj; +} + +std::vector TaskWeldingSymbol::createTiles(void) +{ +// Base::Console().Message("TWS::createTiles()\n"); + Gui::Command::openCommand("Create Welding Tiles"); + std::vector tileFeats; + std::string tileType("TechDraw::DrawTileWeld"); + for (auto& t: m_tiles2Add) { + std::string tileName = m_leadFeat->getDocument()->getUniqueObjectName("DrawTileWeld"); + Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')", + tileType.c_str(),tileName.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.TileRow = %d", + tileName.c_str(), t.row); + Command::doCommand(Command::Doc,"App.activeDocument().%s.TileColumn = %d", + tileName.c_str(), t.col); + Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = '%s'", + tileName.c_str(), t.symbolPath.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.LeftText = '%s'", + tileName.c_str(), t.leftText.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.RightText = '%s'", + tileName.c_str(), t.rightText.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.CenterText = '%s'", + tileName.c_str(), t.centerText.c_str()); + + App::DocumentObject* newTile = m_leadFeat->getDocument()->getObject(tileName.c_str()); + if (newTile == nullptr) { + throw Base::RuntimeError("TaskWeldingSymbol - new tile object not found"); + } + tileFeats.push_back(newTile); + } + + Gui::Command::updateActive(); + Gui::Command::commitCommand(); + return tileFeats; +} + +void TaskWeldingSymbol::updateWeldingSymbol(void) +{ +// Base::Console().Message("TWS::updateWeldingSymbol()\n"); + Gui::Command::openCommand("Edit WeldingSymbol"); + m_weldFeat->requestPaint(); + + Gui::Command::updateActive(); + Gui::Command::commitCommand(); +} + +void TaskWeldingSymbol::saveButtons(QPushButton* btnOK, + QPushButton* btnCancel) +{ + m_btnOK = btnOK; + m_btnCancel = btnCancel; +} + +void TaskWeldingSymbol::enableTaskButtons(bool b) +{ + m_btnOK->setEnabled(b); + m_btnCancel->setEnabled(b); +} + +std::string TaskWeldingSymbol::prefSymbolDir() +{ + std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/Symbols/Welding/AWS/"; + Base::Reference hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> + GetGroup("Preferences")->GetGroup("Mod/TechDraw/Files"); + + std::string symbolDir = hGrp->GetASCII("WeldingDir", defaultDir.c_str()); + return symbolDir; +} + +//****************************************************************************** + +bool TaskWeldingSymbol::accept() +{ +// Base::Console().Message("TWS::accept()\n"); + std::vector tileFeats = createTiles(); + App::DocumentObject* weldFeat = createWeldingSymbol(); + for (auto& obj: tileFeats) { + TechDraw::DrawTileWeld* tile = dynamic_cast(obj); + tile->TileParent.setValue(weldFeat); + } + weldFeat->recomputeFeature(); +// weldFeat->requestPaint(); //not a dv! + + Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + + return true; +} + +bool TaskWeldingSymbol::reject() +{ +// Base::Console().Message("TWS::reject()\n"); + //nothing to remove. + + Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().recompute()"); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + + return false; +} +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +TaskDlgWeldingSymbol::TaskDlgWeldingSymbol(TechDraw::DrawLeaderLine* leader) + : TaskDialog() +{ + widget = new TaskWeldingSymbol(leader); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-weldsymbol"), + widget->windowTitle(), true, 0); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); +} + +TaskDlgWeldingSymbol::~TaskDlgWeldingSymbol() +{ +} + +void TaskDlgWeldingSymbol::update() +{ +// widget->updateTask(); +} + +void TaskDlgWeldingSymbol::modifyStandardButtons(QDialogButtonBox* box) +{ + QPushButton* btnOK = box->button(QDialogButtonBox::Ok); + QPushButton* btnCancel = box->button(QDialogButtonBox::Cancel); + widget->saveButtons(btnOK, btnCancel); +} + +//==== calls from the TaskView =============================================================== +void TaskDlgWeldingSymbol::open() +{ +} + +void TaskDlgWeldingSymbol::clicked(int) +{ +} + +bool TaskDlgWeldingSymbol::accept() +{ + widget->accept(); + return true; +} + +bool TaskDlgWeldingSymbol::reject() +{ + widget->reject(); + return true; +} + +#include diff --git a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.h b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.h new file mode 100644 index 0000000000..a935545f62 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.h @@ -0,0 +1,178 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef TECHDRAWGUI_TASKWELDINGSYMBOL_H +#define TECHDRAWGUI_TASKWELDINGSYMBOL_H + +#include + +#include +#include +#include +#include + +#include + + +class Ui_TaskWeldingSymbol; +class Ui_TaskCL2Lines; + +namespace App { +class DocumentObject; +} + +namespace TechDraw +{ +class DrawPage; +class DrawView; +class DrawLeaderLine; +class DrawWeldSymbol; +} + +namespace TechDraw +{ +class Face; +} + +namespace TechDrawGui +{ +class QGVPage; +class QGIView; +class QGILeaderLine; +class QGIWeldSymbol; +class MDIViewPage; +//class ViewProviderWeld; + +class Tile2Add +{ +public: + Tile2Add() {}; + ~Tile2Add() = default; + bool arrowSide; // or is row enough? + int row; + int col; + std::string leftText; + std::string centerText; + std::string rightText; + std::string symbolPath; +}; + +class TaskWeldingSymbol : public QWidget +{ + Q_OBJECT + +public: + TaskWeldingSymbol(TechDraw::DrawLeaderLine* baseFeat); + ~TaskWeldingSymbol(); + +public Q_SLOTS: + void onArrow0Clicked(bool b); + void onArrow1Clicked(bool b); + void onOther0Clicked(bool b); + void onOther1Clicked(bool b); + void onDirectorySelected(const QString& newDir); + +public: + virtual bool accept(); + virtual bool reject(); + void updateTask(); + void saveButtons(QPushButton* btnOK, + QPushButton* btnCancel); + void enableTaskButtons(bool b); + void setFlipped(bool b); + +protected Q_SLOTS: + +protected: + void changeEvent(QEvent *e); + + void blockButtons(bool b); + void setUiPrimary(void); + void setUiEdit(); + + void turnOnArrow(); + void turnOnOther(); + void removePendingTile(int row, int col); + + + App::DocumentObject* createWeldingSymbol(void); + void updateWeldingSymbol(void); + std::vector createTiles(void); + + void loadSymbolNames(QString pathToSymbols); + + std::string prefSymbolDir(); + QString m_currDir; + + +private: + Ui_TaskWeldingSymbol * ui; + + TechDraw::DrawLeaderLine* m_leadFeat; + TechDraw::DrawWeldSymbol* m_weldFeat; + + std::vector m_tiles2Add; + + QPushButton* m_btnOK; + QPushButton* m_btnCancel; + + int m_arrowCount; + int m_otherCount; +}; + + +class TaskDlgWeldingSymbol : public Gui::TaskView::TaskDialog +{ + Q_OBJECT + +public: + TaskDlgWeldingSymbol(TechDraw::DrawLeaderLine* leader); + ~TaskDlgWeldingSymbol(); + +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(); + + void modifyStandardButtons(QDialogButtonBox* box); + +protected: + +private: + TaskWeldingSymbol* widget; + Gui::TaskView::TaskBox* taskbox; + +}; + +} //namespace TechDrawGui + +#endif // #ifndef TECHDRAWGUI_TASKWELDINGSYMBOL_H diff --git a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.ui b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.ui new file mode 100644 index 0000000000..711dd4c0e2 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.ui @@ -0,0 +1,398 @@ + + + TaskWeldingSymbol + + + + 0 + 0 + 409 + 578 + + + + + 0 + 0 + + + + + 250 + 0 + + + + Welding Symbol + + + + :/icons/actions/techdraw-weldsymbol.svg:/icons/actions/techdraw-weldsymbol.svg + + + + + + + 0 + 0 + + + + QFrame::Box + + + QFrame::Raised + + + + + + + + + + + 0 + 0 + + + + + 0 + 32 + + + + + 0 + 32 + + + + Add an Arrow Side Symbol + + + + + + Add + + + + + + + + 0 + 0 + + + + + 0 + 32 + + + + + 0 + 32 + + + + Add an Arrow Side Symbol + + + Add + + + + + + + + + QFrame::Plain + + + 5 + + + Qt::Horizontal + + + + + + + + + + 0 + 0 + + + + + 0 + 32 + + + + + 0 + 32 + + + + Add an Other Side Symbol + + + Add + + + + + + + + 0 + 0 + + + + + 0 + 32 + + + + + 0 + 32 + + + + Add an Other Side Symbol + + + Add + + + + + + + + + + + + 0 + 0 + + + + + 0 + 128 + + + + + 16777215 + 256 + + + + + 0 + 64 + + + + + 0 + 128 + + + + Select a symbol + + + QListView::Static + + + QListView::LeftToRight + + + true + + + QListView::Adjust + + + + 64 + 64 + + + + QListView::IconMode + + + false + + + false + + + -1 + + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Left Text + + + + + + + Text before symbol + + + + + + + Center Text + + + + + + + Text above/below symbol + + + + + + + Right Text + + + + + + + Text after symbol + + + + + + + + + + + + + Qt::Horizontal + + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Symbol Directory + + + + + + + Pick a directory of welding symbols + + + Gui::FileChooser::Directory + + + *.svg + + + + + + + Process Text + + + + + + + Text at end of symbol + + + + + + + Show on site flag + + + Field Weld + + + false + + + + + + + show perimeter circle + + + All Around + + + false + + + + + + + + + + + + + Gui::FileChooser + QWidget +
Gui/FileDialog.h
+
+
+ + + + +
diff --git a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp index a91b8a8da3..9dbc73ba9c 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp @@ -88,9 +88,17 @@ void ViewProviderDrawingView::attach(App::DocumentObject *pcFeat) connectGuiRepaint = feature->signalGuiPaint.connect(bnd); //TODO: would be good to start the QGIV creation process here, but no guarantee we actually have // MDIVP or QGVP yet. + // but parent page might. we may not be part of the document yet though! + // :( we're not part of the page yet either! } else { Base::Console().Warning("VPDV::attach has no Feature!\n"); } +// TechDraw::DrawView* view = static_cast(pcFeat); +// TechDraw::DrawPage* page = view->findParentPage(); +// TechDraw::DrawPage* page = feature->findParentPage(); +// Base::Console().Message("VPDV::attach(%X) - parent: %X\n", +// pcFeat, page); +// pcFeat->getNameInDocument(), page->getNameInDocument()); } void ViewProviderDrawingView::setDisplayMode(const char* ModeName) @@ -232,7 +240,7 @@ MDIViewPage* ViewProviderDrawingView::getMDIViewPage() const { MDIViewPage* result = nullptr; Gui::Document* guiDoc = Gui::Application::Instance->getDocument(getViewObject()->getDocument()); - Gui::ViewProvider* vp = guiDoc->getViewProvider(getViewObject()->findParentPage()); + Gui::ViewProvider* vp = guiDoc->getViewProvider(getViewObject()->findParentPage()); //if not in page.views, !@#$% ViewProviderPage* dvp = dynamic_cast(vp); if (dvp) { result = dvp->getMDIViewPage(); @@ -256,6 +264,9 @@ void ViewProviderDrawingView::onGuiRepaint(const TechDraw::DrawView* dv) } else { //we are not part of the Gui page yet. ask page to add us. //TODO: this bit causes trouble. Should move QGIV creation to attach? // is MDIVP/QGVP available at attach time? + // wf: mdivp/qgvp is not necessarily directly available at attach time. It should be available + // via the parent DrawPage since the DP is created before any views. +// Base::Console().Message("VPDV::onGuiRepaint - no QGIV for: %s\n",dv->getNameInDocument()); MDIViewPage* page = getMDIViewPage(); if (page != nullptr) { page->addView(dv); diff --git a/src/Mod/TechDraw/Gui/ViewProviderLeader.cpp b/src/Mod/TechDraw/Gui/ViewProviderLeader.cpp index 050a9131cd..83e4b1e5b8 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderLeader.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderLeader.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include "MDIViewPage.h" #include "QGVPage.h" @@ -153,12 +154,15 @@ std::vector ViewProviderLeader::claimChildren(void) const // Collect any child Document Objects and put them in the right place in the Feature tree // valid children of a ViewLeader are: // - Rich Annotations + // - Weld Symbols std::vector temp; const std::vector &views = getFeature()->getInList(); try { for(std::vector::const_iterator it = views.begin(); it != views.end(); ++it) { if ((*it)->getTypeId().isDerivedFrom(TechDraw::DrawRichAnno::getClassTypeId())) { temp.push_back((*it)); + } else if ((*it)->getTypeId().isDerivedFrom(TechDraw::DrawWeldSymbol::getClassTypeId())) { + temp.push_back((*it)); } } return temp; diff --git a/src/Mod/TechDraw/Gui/ViewProviderPage.cpp b/src/Mod/TechDraw/Gui/ViewProviderPage.cpp index beba8cea54..f1bb574649 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderPage.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderPage.cpp @@ -58,6 +58,7 @@ #include #include #include +#include #include #include "MDIViewPage.h" @@ -283,10 +284,11 @@ std::vector ViewProviderPage::claimChildren(void) const // for Page, valid children are any View except: DrawProjGroupItem // DrawViewDimension // DrawViewBalloon - // DrawLeader - // DrawRichAnno (if not a child of View) + // DrawLeaderLine + // DrawRichAnno // any FeatuerView in a DrawViewClip // DrawHatch + // DrawWeldSymbol const std::vector &views = getDrawPage()->Views.getValues(); @@ -312,6 +314,7 @@ std::vector ViewProviderPage::claimChildren(void) const docObj->isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId()) || docObj->isDerivedFrom(TechDraw::DrawRichAnno::getClassTypeId()) || docObj->isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId()) || + docObj->isDerivedFrom(TechDraw::DrawWeldSymbol::getClassTypeId()) || (featView && featView->isInClip()) ) continue; else diff --git a/src/Mod/TechDraw/Gui/ViewProviderTile.cpp b/src/Mod/TechDraw/Gui/ViewProviderTile.cpp new file mode 100644 index 0000000000..90fdec3170 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderTile.cpp @@ -0,0 +1,90 @@ +/*************************************************************************** + * Copyright (c) 2019 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#ifndef _PreComp_ +#endif + +/// Here the FreeCAD includes sorted by Base,App,Gui...... +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ViewProviderTile.h" + +using namespace TechDrawGui; + +PROPERTY_SOURCE(TechDrawGui::ViewProviderTile, Gui::ViewProviderDocumentObject) + +//************************************************************************** +// Construction/Destruction + +ViewProviderTile::ViewProviderTile() +{ + sPixmap = "actions/techdraw-tile"; +} + +ViewProviderTile::~ViewProviderTile() +{ +} + +void ViewProviderTile::attach(App::DocumentObject *pcFeat) +{ + // call parent attach method + ViewProviderDocumentObject::attach(pcFeat); +} + +void ViewProviderTile::setDisplayMode(const char* ModeName) +{ + ViewProviderDocumentObject::setDisplayMode(ModeName); +} + +std::vector ViewProviderTile::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList = ViewProviderDocumentObject::getDisplayModes(); + + return StrList; +} + +void ViewProviderTile::updateData(const App::Property* prop) +{ + ViewProviderDocumentObject::updateData(prop); +} + +//TechDraw::DrawTile* ViewProviderTile::getViewObject() const +//{ +// return dynamic_cast(pcObject); +//} + +TechDraw::DrawTile* ViewProviderTile::getFeature() const +{ + return dynamic_cast(pcObject); +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderTile.h b/src/Mod/TechDraw/Gui/ViewProviderTile.h new file mode 100644 index 0000000000..d791202b8f --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderTile.h @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright (c) 2019 Wanderer Fan * + * * + * 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_VIEWPROVIDERTILE_H +#define DRAWINGGUI_VIEWPROVIDERTILE_H + +#include + +#include + +namespace TechDrawGui { + + +class TechDrawGuiExport ViewProviderTile : public Gui::ViewProviderDocumentObject +{ + PROPERTY_HEADER(TechDrawGui::ViewProviderTile); + +public: + /// constructor + ViewProviderTile(); + /// destructor + virtual ~ViewProviderTile(); + + + virtual void attach(App::DocumentObject *); + virtual void setDisplayMode(const char* ModeName); + virtual bool useNewSelectionModel(void) const {return false;} + /// returns a list of all possible modes + virtual std::vector getDisplayModes(void) const; + virtual void updateData(const App::Property*); + +/* virtual TechDraw::DrawTile* getViewObject() const;*/ + virtual TechDraw::DrawTile* getFeature() const; +}; + +} // namespace TechDrawGui + + +#endif // DRAWINGGUI_VIEWPROVIDERTILE_H diff --git a/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp b/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp index 1c445eb6d5..347c6013f4 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include diff --git a/src/Mod/TechDraw/Gui/ViewProviderWeld.cpp b/src/Mod/TechDraw/Gui/ViewProviderWeld.cpp new file mode 100644 index 0000000000..f74656befc --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderWeld.cpp @@ -0,0 +1,110 @@ +/*************************************************************************** + * Copyright (c) 2019 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#ifndef _PreComp_ +#endif + +/// Here the FreeCAD includes sorted by Base,App,Gui...... +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ViewProviderWeld.h" + +using namespace TechDrawGui; + +PROPERTY_SOURCE(TechDrawGui::ViewProviderWeld, TechDrawGui::ViewProviderDrawingView) + +//************************************************************************** +// Construction/Destruction + +ViewProviderWeld::ViewProviderWeld() +{ + sPixmap = "actions/techdraw-weldsymbol"; +} + +ViewProviderWeld::~ViewProviderWeld() +{ +} + +void ViewProviderWeld::attach(App::DocumentObject *pcFeat) +{ + // call parent attach method + ViewProviderDrawingView::attach(pcFeat); +} + +void ViewProviderWeld::setDisplayMode(const char* ModeName) +{ + ViewProviderDrawingView::setDisplayMode(ModeName); +} + +std::vector ViewProviderWeld::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList = ViewProviderDrawingView::getDisplayModes(); + + return StrList; +} + +void ViewProviderWeld::updateData(const App::Property* prop) +{ + ViewProviderDrawingView::updateData(prop); +} + +std::vector ViewProviderWeld::claimChildren(void) const +{ + // Collect any child Document Objects and put them in the right place in the Feature tree + // valid children of a DrawWeldSymbol are: + // - DrawTiles + std::vector temp; + const std::vector &tiles = getFeature()->getInList(); + try { + for(std::vector::const_iterator it = tiles.begin(); it != tiles.end(); ++it) { + if ((*it)->getTypeId().isDerivedFrom(TechDraw::DrawTile::getClassTypeId())) { + temp.push_back((*it)); + } + } + return temp; + } catch (...) { + std::vector tmp; + return tmp; + } +} + +TechDraw::DrawWeldSymbol* ViewProviderWeld::getViewObject() const +{ + return dynamic_cast(pcObject); +} + +TechDraw::DrawWeldSymbol* ViewProviderWeld::getFeature() const +{ + return getViewObject(); +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderWeld.h b/src/Mod/TechDraw/Gui/ViewProviderWeld.h new file mode 100644 index 0000000000..49adea59f7 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderWeld.h @@ -0,0 +1,63 @@ +/*************************************************************************** + * Copyright (c) 2019 Wanderer Fan * + * * + * 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_VIEWPROVIDERWELD_H +#define DRAWINGGUI_VIEWPROVIDERWELD_H + +#include + +#include "ViewProviderDrawingView.h" +#include +#include +#include + + +namespace TechDrawGui { + + +class TechDrawGuiExport ViewProviderWeld : public ViewProviderDrawingView +{ + PROPERTY_HEADER(TechDrawGui::ViewProviderWeld); + +public: + /// constructor + ViewProviderWeld(); + /// destructor + virtual ~ViewProviderWeld(); + + virtual void attach(App::DocumentObject *); + virtual void setDisplayMode(const char* ModeName); + virtual bool useNewSelectionModel(void) const {return false;} + /// returns a list of all possible modes + virtual std::vector getDisplayModes(void) const; + virtual void updateData(const App::Property*); + virtual std::vector claimChildren(void) const; + + virtual TechDraw::DrawWeldSymbol* getViewObject() const; + virtual TechDraw::DrawWeldSymbol* getFeature() const; +}; + +} // namespace TechDrawGui + + +#endif // DRAWINGGUI_VIEWPROVIDERWELD_H diff --git a/src/Mod/TechDraw/Gui/Workbench.cpp b/src/Mod/TechDraw/Gui/Workbench.cpp index cd58e4d122..1ed47127a3 100644 --- a/src/Mod/TechDraw/Gui/Workbench.cpp +++ b/src/Mod/TechDraw/Gui/Workbench.cpp @@ -87,6 +87,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const *draw << "TechDraw_Image"; *draw << "TechDraw_ToggleFrame"; // *decor << "TechDraw_RedrawPage"; + *draw << "Separator"; *draw << "TechDraw_Annotation"; *draw << "TechDraw_LeaderLine"; *draw << "TechDraw_RichAnno"; @@ -99,7 +100,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const *draw << "TechDraw_CosmeticEraser"; *draw << "TechDraw_DecorateLine"; *draw << "TechDraw_ShowAll"; - + *draw << "TechDraw_WeldSymbol"; return root; } @@ -168,6 +169,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const *anno << "TechDraw_CosmeticEraser"; *anno << "TechDraw_DecorateLine"; *anno << "TechDraw_ShowAll"; + *anno << "TechDraw_WeldSymbol"; return root; } @@ -234,6 +236,7 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const *anno << "TechDraw_CosmeticEraser"; *anno << "TechDraw_DecorateLine"; *anno << "TechDraw_ShowAll"; + *anno << "TechDraw_WeldSymbol"; return root; } diff --git a/src/Mod/TechDraw/Symbols/Welding/AWS/SquareDown.svg b/src/Mod/TechDraw/Symbols/Welding/AWS/SquareDown.svg new file mode 100644 index 0000000000..29770b5e48 --- /dev/null +++ b/src/Mod/TechDraw/Symbols/Welding/AWS/SquareDown.svg @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Symbols/Welding/AWS/SquareUp.svg b/src/Mod/TechDraw/Symbols/Welding/AWS/SquareUp.svg new file mode 100644 index 0000000000..d65822c61a --- /dev/null +++ b/src/Mod/TechDraw/Symbols/Welding/AWS/SquareUp.svg @@ -0,0 +1,171 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/src/Mod/TechDraw/Symbols/Welding/AWS/VDown.svg b/src/Mod/TechDraw/Symbols/Welding/AWS/VDown.svg new file mode 100644 index 0000000000..932dbdb008 --- /dev/null +++ b/src/Mod/TechDraw/Symbols/Welding/AWS/VDown.svg @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/Mod/TechDraw/Symbols/Welding/AWS/VUp.svg b/src/Mod/TechDraw/Symbols/Welding/AWS/VUp.svg new file mode 100644 index 0000000000..180cdcdb74 --- /dev/null +++ b/src/Mod/TechDraw/Symbols/Welding/AWS/VUp.svg @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Symbols/Welding/AWS/beadDown.svg b/src/Mod/TechDraw/Symbols/Welding/AWS/beadDown.svg new file mode 100644 index 0000000000..d299798c52 --- /dev/null +++ b/src/Mod/TechDraw/Symbols/Welding/AWS/beadDown.svg @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + diff --git a/src/Mod/TechDraw/Symbols/Welding/AWS/beadUp.svg b/src/Mod/TechDraw/Symbols/Welding/AWS/beadUp.svg new file mode 100644 index 0000000000..62e7048ed3 --- /dev/null +++ b/src/Mod/TechDraw/Symbols/Welding/AWS/beadUp.svg @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + diff --git a/src/Mod/TechDraw/Symbols/Welding/AWS/filletDown.svg b/src/Mod/TechDraw/Symbols/Welding/AWS/filletDown.svg new file mode 100644 index 0000000000..2e16d297ce --- /dev/null +++ b/src/Mod/TechDraw/Symbols/Welding/AWS/filletDown.svg @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + diff --git a/src/Mod/TechDraw/Symbols/Welding/AWS/filletUp.svg b/src/Mod/TechDraw/Symbols/Welding/AWS/filletUp.svg new file mode 100644 index 0000000000..448cefc1b1 --- /dev/null +++ b/src/Mod/TechDraw/Symbols/Welding/AWS/filletUp.svg @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + diff --git a/src/Mod/TechDraw/Symbols/Welding/AWS/filletUpPlain.svg b/src/Mod/TechDraw/Symbols/Welding/AWS/filletUpPlain.svg new file mode 100644 index 0000000000..49de22b4eb --- /dev/null +++ b/src/Mod/TechDraw/Symbols/Welding/AWS/filletUpPlain.svg @@ -0,0 +1,30 @@ + + + + + + + image/svg+xml + + + + + + + diff --git a/src/Mod/TechDraw/Symbols/Welding/AWS/plug.svg b/src/Mod/TechDraw/Symbols/Welding/AWS/plug.svg new file mode 100644 index 0000000000..944ce43b0e --- /dev/null +++ b/src/Mod/TechDraw/Symbols/Welding/AWS/plug.svg @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + +