From 789912d745e0e63e708b3df6b08077e2a368347a Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 10 Sep 2023 12:33:49 +0200 Subject: [PATCH] Drawing: Apply clang format --- src/Mod/Drawing/App/AppDrawing.cpp | 11 +- src/Mod/Drawing/App/AppDrawingPy.cpp | 383 +++++---- src/Mod/Drawing/App/DrawingExport.cpp | 574 +++++++------- src/Mod/Drawing/App/DrawingExport.h | 12 +- src/Mod/Drawing/App/FeatureClip.cpp | 67 +- src/Mod/Drawing/App/FeatureClip.h | 7 +- src/Mod/Drawing/App/FeaturePage.cpp | 139 ++-- src/Mod/Drawing/App/FeaturePage.h | 7 +- src/Mod/Drawing/App/FeatureProjection.cpp | 83 +- src/Mod/Drawing/App/FeatureProjection.h | 31 +- src/Mod/Drawing/App/FeatureView.cpp | 51 +- src/Mod/Drawing/App/FeatureView.h | 14 +- src/Mod/Drawing/App/FeatureViewAnnotation.cpp | 54 +- src/Mod/Drawing/App/FeatureViewAnnotation.h | 15 +- src/Mod/Drawing/App/FeatureViewPart.cpp | 99 ++- src/Mod/Drawing/App/FeatureViewPart.h | 21 +- .../Drawing/App/FeatureViewSpreadsheet.cpp | 111 ++- src/Mod/Drawing/App/FeatureViewSpreadsheet.h | 23 +- src/Mod/Drawing/App/FeatureViewSymbol.cpp | 62 +- src/Mod/Drawing/App/FeatureViewSymbol.h | 13 +- src/Mod/Drawing/App/PageGroup.cpp | 11 +- src/Mod/Drawing/App/PageGroup.h | 8 +- src/Mod/Drawing/App/PreCompiled.cpp | 2 +- src/Mod/Drawing/App/PreCompiled.h | 29 +- src/Mod/Drawing/App/ProjectionAlgos.cpp | 197 +++-- src/Mod/Drawing/App/ProjectionAlgos.h | 37 +- src/Mod/Drawing/CMakeLists.txt | 2 +- src/Mod/Drawing/DrawingExample.py | 69 +- src/Mod/Drawing/DrawingGlobal.h | 10 +- src/Mod/Drawing/DrawingPatterns.py | 231 +++--- src/Mod/Drawing/DrawingTests.py | 23 +- src/Mod/Drawing/Gui/AppDrawingGui.cpp | 5 +- src/Mod/Drawing/Gui/AppDrawingGuiPy.cpp | 96 ++- src/Mod/Drawing/Gui/Command.cpp | 531 +++++++------ src/Mod/Drawing/Gui/DrawingView.cpp | 288 ++++--- src/Mod/Drawing/Gui/DrawingView.h | 58 +- src/Mod/Drawing/Gui/PreCompiled.cpp | 2 +- src/Mod/Drawing/Gui/PreCompiled.h | 10 +- src/Mod/Drawing/Gui/Resources/Drawing.qrc | 4 +- src/Mod/Drawing/Gui/TaskDialog.cpp | 109 +-- src/Mod/Drawing/Gui/TaskDialog.h | 15 +- src/Mod/Drawing/Gui/TaskOrthoViews.cpp | 743 ++++++++++-------- src/Mod/Drawing/Gui/TaskOrthoViews.h | 224 +++--- src/Mod/Drawing/Gui/ViewProviderPage.cpp | 35 +- src/Mod/Drawing/Gui/ViewProviderPage.h | 30 +- src/Mod/Drawing/Gui/ViewProviderView.cpp | 48 +- src/Mod/Drawing/Gui/ViewProviderView.h | 26 +- src/Mod/Drawing/Gui/Workbench.cpp | 11 +- src/Mod/Drawing/Gui/Workbench.h | 9 +- src/Mod/Drawing/Init.py | 49 +- src/Mod/Drawing/InitGui.py | 66 +- src/Mod/Drawing/drawing.dox | 1 - 52 files changed, 2650 insertions(+), 2106 deletions(-) diff --git a/src/Mod/Drawing/App/AppDrawing.cpp b/src/Mod/Drawing/App/AppDrawing.cpp index 23dc007792..21556f4fef 100644 --- a/src/Mod/Drawing/App/AppDrawing.cpp +++ b/src/Mod/Drawing/App/AppDrawing.cpp @@ -26,7 +26,8 @@ #include "PageGroup.h" -namespace Drawing { +namespace Drawing +{ extern PyObject* initModule(); } @@ -36,9 +37,9 @@ PyMOD_INIT_FUNC(Drawing) // load dependent module try { Base::Interpreter().loadModule("Part"); - //Base::Interpreter().loadModule("Mesh"); + // Base::Interpreter().loadModule("Mesh"); } - catch(const Base::Exception& e) { + catch (const Base::Exception& e) { PyErr_SetString(PyExc_ImportError, e.what()); PyMOD_Return(nullptr); } @@ -49,7 +50,7 @@ PyMOD_INIT_FUNC(Drawing) // NOTE: To finish the initialization of our own type objects we must // call PyType_Ready, otherwise we run into a segmentation fault, later on. // This function is responsible for adding inherited slots from a type's base class. - + // clang-format off Drawing::FeaturePage ::init(); Drawing::FeatureView ::init(); Drawing::FeatureViewPart ::init(); @@ -61,6 +62,6 @@ PyMOD_INIT_FUNC(Drawing) Drawing::FeatureViewSymbol ::init(); Drawing::FeatureClip ::init(); Drawing::FeatureViewSpreadsheet ::init(); - + // clang-format on PyMOD_Return(mod); } diff --git a/src/Mod/Drawing/App/AppDrawingPy.cpp b/src/Mod/Drawing/App/AppDrawingPy.cpp index 9b4c153f72..055daf2495 100644 --- a/src/Mod/Drawing/App/AppDrawingPy.cpp +++ b/src/Mod/Drawing/App/AppDrawingPy.cpp @@ -22,7 +22,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include #endif #include @@ -36,85 +36,97 @@ using namespace std; -using Part::TopoShapePy; using Part::TopoShape; +using Part::TopoShapePy; -namespace Drawing { +namespace Drawing +{ - /** Copies a Python dictionary of Python strings to a C++ container. - * - * After the function call, the key-value pairs of the Python - * dictionary are copied into the target buffer as C++ pairs - * (pair). - * - * @param sourceRange is a Python dictionary (Py::Dict). Both, the - * keys and the values must be Python strings. - * - * @param targetIt refers to where the data should be inserted. Must - * be of concept output iterator. - */ - template - void copy(Py::Dict sourceRange, OutputIt targetIt) - { +/** Copies a Python dictionary of Python strings to a C++ container. + * + * After the function call, the key-value pairs of the Python + * dictionary are copied into the target buffer as C++ pairs + * (pair). + * + * @param sourceRange is a Python dictionary (Py::Dict). Both, the + * keys and the values must be Python strings. + * + * @param targetIt refers to where the data should be inserted. Must + * be of concept output iterator. + */ +template +void copy(Py::Dict sourceRange, OutputIt targetIt) +{ string key; string value; for (const auto& keyPy : sourceRange.keys()) { - key = Py::String(keyPy); - value = Py::String(sourceRange[keyPy]); - *targetIt = {key, value}; - ++targetIt; + key = Py::String(keyPy); + value = Py::String(sourceRange[keyPy]); + *targetIt = {key, value}; + ++targetIt; } - } +} -class Module : public Py::ExtensionModule +class Module: public Py::ExtensionModule { public: - Module() : Py::ExtensionModule("Drawing") + Module() + : Py::ExtensionModule("Drawing") { - add_varargs_method("project",&Module::project, - "[visiblyG0,visiblyG1,hiddenG0,hiddenG1] = project(TopoShape[,App.Vector Direction, string type])\n" - " -- Project a shape and return the visible/invisible parts of it." - ); - add_varargs_method("projectEx",&Module::projectEx, - "[V,V1,VN,VO,VI,H,H1,HN,HO,HI] = projectEx(TopoShape[,App.Vector Direction, string type])\n" - " -- Project a shape and return the all parts of it." - ); - add_keyword_method("projectToSVG",&Module::projectToSVG, - "string = projectToSVG(TopoShape[, App.Vector direction, string type, float tolerance, dict vStyle, dict v0Style, dict v1Style, dict hStyle, dict h0Style, dict h1Style])\n" - " -- Project a shape and return the SVG representation as string." - ); - add_varargs_method("projectToDXF",&Module::projectToDXF, - "string = projectToDXF(TopoShape[,App.Vector Direction, string type])\n" - " -- Project a shape and return the DXF representation as string." - ); - add_varargs_method("removeSvgTags",&Module::removeSvgTags, + add_varargs_method("project", + &Module::project, + "[visiblyG0,visiblyG1,hiddenG0,hiddenG1] = " + "project(TopoShape[,App.Vector Direction, string type])\n" + " -- Project a shape and return the visible/invisible parts of it."); + add_varargs_method("projectEx", + &Module::projectEx, + "[V,V1,VN,VO,VI,H,H1,HN,HO,HI] = projectEx(TopoShape[,App.Vector " + "Direction, string type])\n" + " -- Project a shape and return the all parts of it."); + add_keyword_method( + "projectToSVG", + &Module::projectToSVG, + "string = projectToSVG(TopoShape[, App.Vector direction, string type, float tolerance, " + "dict vStyle, dict v0Style, dict v1Style, dict hStyle, dict h0Style, dict h1Style])\n" + " -- Project a shape and return the SVG representation as string."); + add_varargs_method("projectToDXF", + &Module::projectToDXF, + "string = projectToDXF(TopoShape[,App.Vector Direction, string type])\n" + " -- Project a shape and return the DXF representation as string."); + add_varargs_method( + "removeSvgTags", + &Module::removeSvgTags, "string = removeSvgTags(string) -- Removes the opening and closing svg tags\n" - "and other metatags from a svg code, making it embeddable" - ); - initialize("This module is the Drawing module."); // register with Python + "and other metatags from a svg code, making it embeddable"); + initialize("This module is the Drawing module.");// register with Python } - virtual ~Module() {} + virtual ~Module() + {} private: - virtual Py::Object invoke_method_varargs(void *method_def, const Py::Tuple &args) + virtual Py::Object invoke_method_varargs(void* method_def, const Py::Tuple& args) { try { return Py::ExtensionModule::invoke_method_varargs(method_def, args); } - catch (const Standard_Failure &e) { + catch (const Standard_Failure& e) { std::string str; Standard_CString msg = e.GetMessageString(); str += typeid(e).name(); str += " "; - if (msg) {str += msg;} - else {str += "No OCCT Exception Message";} + if (msg) { + str += msg; + } + else { + str += "No OCCT Exception Message"; + } Base::Console().Error("%s\n", str.c_str()); throw Py::Exception(Part::PartExceptionOCCError, str); } - catch (const Base::Exception &e) { + catch (const Base::Exception& e) { std::string str; str += "FreeCAD exception thrown ("; str += e.what(); @@ -122,7 +134,7 @@ private: e.ReportException(); throw Py::RuntimeError(str); } - catch (const std::exception &e) { + catch (const std::exception& e) { std::string str; str += "C++ exception thrown ("; str += e.what(); @@ -133,53 +145,63 @@ private: } Py::Object project(const Py::Tuple& args) { - PyObject *pcObjShape; - PyObject *pcObjDir=nullptr; + PyObject* pcObjShape; + PyObject* pcObjDir = nullptr; - if (!PyArg_ParseTuple(args.ptr(), "O!|O!", - &(Part::TopoShapePy::Type), &pcObjShape, - &(Base::VectorPy::Type), &pcObjDir)) + if (!PyArg_ParseTuple(args.ptr(), + "O!|O!", + &(Part::TopoShapePy::Type), + &pcObjShape, + &(Base::VectorPy::Type), + &pcObjDir)) { throw Py::Exception(); + } Part::TopoShapePy* pShape = static_cast(pcObjShape); - Base::Vector3d Vector(0,0,1); - if (pcObjDir) + Base::Vector3d Vector(0, 0, 1); + if (pcObjDir) { Vector = *static_cast(pcObjDir)->getVectorPtr(); + } - ProjectionAlgos Alg(pShape->getTopoShapePtr()->getShape(),Vector); + ProjectionAlgos Alg(pShape->getTopoShapePtr()->getShape(), Vector); Py::List list; - list.append(Py::Object(new Part::TopoShapePy(new Part::TopoShape(Alg.V)) , true)); + list.append(Py::Object(new Part::TopoShapePy(new Part::TopoShape(Alg.V)), true)); list.append(Py::Object(new Part::TopoShapePy(new Part::TopoShape(Alg.V1)), true)); - list.append(Py::Object(new Part::TopoShapePy(new Part::TopoShape(Alg.H)) , true)); + list.append(Py::Object(new Part::TopoShapePy(new Part::TopoShape(Alg.H)), true)); list.append(Py::Object(new Part::TopoShapePy(new Part::TopoShape(Alg.H1)), true)); return list; } Py::Object projectEx(const Py::Tuple& args) { - PyObject *pcObjShape; - PyObject *pcObjDir=nullptr; + PyObject* pcObjShape; + PyObject* pcObjDir = nullptr; - if (!PyArg_ParseTuple(args.ptr(), "O!|O!", - &(TopoShapePy::Type), &pcObjShape, - &(Base::VectorPy::Type), &pcObjDir)) + if (!PyArg_ParseTuple(args.ptr(), + "O!|O!", + &(TopoShapePy::Type), + &pcObjShape, + &(Base::VectorPy::Type), + &pcObjDir)) { throw Py::Exception(); + } TopoShapePy* pShape = static_cast(pcObjShape); - Base::Vector3d Vector(0,0,1); - if (pcObjDir) + Base::Vector3d Vector(0, 0, 1); + if (pcObjDir) { Vector = *static_cast(pcObjDir)->getVectorPtr(); + } - ProjectionAlgos Alg(pShape->getTopoShapePtr()->getShape(),Vector); + ProjectionAlgos Alg(pShape->getTopoShapePtr()->getShape(), Vector); Py::List list; - list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.V)) , true)); + list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.V)), true)); list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.V1)), true)); list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.VN)), true)); list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.VO)), true)); list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.VI)), true)); - list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.H)) , true)); + list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.H)), true)); list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.H1)), true)); list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.HN)), true)); list.append(Py::Object(new TopoShapePy(new TopoShape(Alg.HO)), true)); @@ -189,140 +211,165 @@ private: } Py::Object projectToSVG(const Py::Tuple& args, const Py::Dict& keys) - { - static const std::array argNames {"topoShape", - "direction", - "type", - "tolerance", - "vStyle", - "v0Style", - "v1Style", - "hStyle", - "h0Style", - "h1Style", - nullptr}; - PyObject *pcObjShape = nullptr; - PyObject *pcObjDir = nullptr; - const char *extractionTypePy = nullptr; - ProjectionAlgos::ExtractionType extractionType = ProjectionAlgos::Plain; - const float tol = 0.1f; - PyObject* vStylePy = nullptr; - ProjectionAlgos::XmlAttributes vStyle; - PyObject* v0StylePy = nullptr; - ProjectionAlgos::XmlAttributes v0Style; - PyObject* v1StylePy = nullptr; - ProjectionAlgos::XmlAttributes v1Style; - PyObject* hStylePy = nullptr; - ProjectionAlgos::XmlAttributes hStyle; - PyObject* h0StylePy = nullptr; - ProjectionAlgos::XmlAttributes h0Style; - PyObject* h1StylePy = nullptr; - ProjectionAlgos::XmlAttributes h1Style; - - // Get the arguments + { + static const std::array argNames {"topoShape", + "direction", + "type", + "tolerance", + "vStyle", + "v0Style", + "v1Style", + "hStyle", + "h0Style", + "h1Style", + nullptr}; + PyObject* pcObjShape = nullptr; + PyObject* pcObjDir = nullptr; + const char* extractionTypePy = nullptr; + ProjectionAlgos::ExtractionType extractionType = ProjectionAlgos::Plain; + const float tol = 0.1f; + PyObject* vStylePy = nullptr; + ProjectionAlgos::XmlAttributes vStyle; + PyObject* v0StylePy = nullptr; + ProjectionAlgos::XmlAttributes v0Style; + PyObject* v1StylePy = nullptr; + ProjectionAlgos::XmlAttributes v1Style; + PyObject* hStylePy = nullptr; + ProjectionAlgos::XmlAttributes hStyle; + PyObject* h0StylePy = nullptr; + ProjectionAlgos::XmlAttributes h0Style; + PyObject* h1StylePy = nullptr; + ProjectionAlgos::XmlAttributes h1Style; - if (!Base::Wrapped_ParseTupleAndKeywords( - args.ptr(), keys.ptr(), - "O!|O!sfOOOOOO", - argNames, - &(TopoShapePy::Type), &pcObjShape, - &(Base::VectorPy::Type), &pcObjDir, - &extractionTypePy, &tol, - &vStylePy, &v0StylePy, &v1StylePy, - &hStylePy, &h0StylePy, &h1StylePy)) - - throw Py::Exception(); + // Get the arguments - // Convert all arguments into the right format + if (!Base::Wrapped_ParseTupleAndKeywords(args.ptr(), + keys.ptr(), + "O!|O!sfOOOOOO", + argNames, + &(TopoShapePy::Type), + &pcObjShape, + &(Base::VectorPy::Type), + &pcObjDir, + &extractionTypePy, + &tol, + &vStylePy, + &v0StylePy, + &v1StylePy, + &hStylePy, + &h0StylePy, + &h1StylePy)) { - TopoShapePy* pShape = static_cast(pcObjShape); - - Base::Vector3d directionVector(0,0,1); - if (pcObjDir) - directionVector = static_cast(pcObjDir)->value(); - - if (extractionTypePy && string(extractionTypePy) == "ShowHiddenLines") - extractionType = ProjectionAlgos::WithHidden; - - if (vStylePy) - copy(Py::Dict(vStylePy), inserter(vStyle, vStyle.begin())); - if (v0StylePy) - copy(Py::Dict(v0StylePy), inserter(v0Style, v0Style.begin())); - if (v1StylePy) - copy(Py::Dict(v1StylePy), inserter(v1Style, v1Style.begin())); - if (hStylePy) - copy(Py::Dict(hStylePy), inserter(hStyle, hStyle.begin())); - if (h0StylePy) - copy(Py::Dict(h0StylePy), inserter(h0Style, h0Style.begin())); - if (h1StylePy) - copy(Py::Dict(h1StylePy), inserter(h1Style, h1Style.begin())); - - // Execute the SVG generation - - ProjectionAlgos Alg(pShape->getTopoShapePtr()->getShape(), - directionVector); - Py::String result(Alg.getSVG(extractionType, tol, - vStyle, v0Style, v1Style, - hStyle, h0Style, h1Style)); - return result; + throw Py::Exception(); } + // Convert all arguments into the right format + + TopoShapePy* pShape = static_cast(pcObjShape); + + Base::Vector3d directionVector(0, 0, 1); + if (pcObjDir) { + directionVector = static_cast(pcObjDir)->value(); + } + + if (extractionTypePy && string(extractionTypePy) == "ShowHiddenLines") { + extractionType = ProjectionAlgos::WithHidden; + } + + if (vStylePy) { + copy(Py::Dict(vStylePy), inserter(vStyle, vStyle.begin())); + } + if (v0StylePy) { + copy(Py::Dict(v0StylePy), inserter(v0Style, v0Style.begin())); + } + if (v1StylePy) { + copy(Py::Dict(v1StylePy), inserter(v1Style, v1Style.begin())); + } + if (hStylePy) { + copy(Py::Dict(hStylePy), inserter(hStyle, hStyle.begin())); + } + if (h0StylePy) { + copy(Py::Dict(h0StylePy), inserter(h0Style, h0Style.begin())); + } + if (h1StylePy) { + copy(Py::Dict(h1StylePy), inserter(h1Style, h1Style.begin())); + } + + // Execute the SVG generation + + ProjectionAlgos Alg(pShape->getTopoShapePtr()->getShape(), directionVector); + Py::String result( + Alg.getSVG(extractionType, tol, vStyle, v0Style, v1Style, hStyle, h0Style, h1Style)); + return result; + } + Py::Object projectToDXF(const Py::Tuple& args) { - PyObject *pcObjShape; - PyObject *pcObjDir=nullptr; - const char *type=nullptr; - float scale=1.0f; - float tol=0.1f; + PyObject* pcObjShape; + PyObject* pcObjDir = nullptr; + const char* type = nullptr; + float scale = 1.0f; + float tol = 0.1f; - if (!PyArg_ParseTuple(args.ptr(), "O!|O!sff", - &(TopoShapePy::Type), &pcObjShape, - &(Base::VectorPy::Type), &pcObjDir, &type, &scale, &tol)) + if (!PyArg_ParseTuple(args.ptr(), + "O!|O!sff", + &(TopoShapePy::Type), + &pcObjShape, + &(Base::VectorPy::Type), + &pcObjDir, + &type, + &scale, + &tol)) { throw Py::Exception(); + } TopoShapePy* pShape = static_cast(pcObjShape); - Base::Vector3d Vector(0,0,1); - if (pcObjDir) + Base::Vector3d Vector(0, 0, 1); + if (pcObjDir) { Vector = static_cast(pcObjDir)->value(); - ProjectionAlgos Alg(pShape->getTopoShapePtr()->getShape(),Vector); + } + ProjectionAlgos Alg(pShape->getTopoShapePtr()->getShape(), Vector); bool hidden = false; - if (type && std::string(type) == "ShowHiddenLines") + if (type && std::string(type) == "ShowHiddenLines") { hidden = true; + } - Py::String result(Alg.getDXF(hidden?ProjectionAlgos::WithHidden:ProjectionAlgos::Plain, scale, tol)); + Py::String result( + Alg.getDXF(hidden ? ProjectionAlgos::WithHidden : ProjectionAlgos::Plain, scale, tol)); return result; } Py::Object removeSvgTags(const Py::Tuple& args) { const char* svgcode; - if (!PyArg_ParseTuple(args.ptr(), "s",&svgcode)) + if (!PyArg_ParseTuple(args.ptr(), "s", &svgcode)) { throw Py::Exception(); + } std::string svg(svgcode); std::string empty = ""; std::string endline = "--endOfLine--"; std::string linebreak = "\\n"; // removing linebreaks for regex to work - boost::regex e1 ("\\n"); + boost::regex e1("\\n"); svg = boost::regex_replace(svg, e1, endline); // removing starting xml definition - boost::regex e2 ("<\\?xml.*?\\?>"); + boost::regex e2("<\\?xml.*?\\?>"); svg = boost::regex_replace(svg, e2, empty); // removing starting svg tag - boost::regex e3 (""); + boost::regex e3(""); svg = boost::regex_replace(svg, e3, empty); // removing sodipodi tags -- DANGEROUS, some sodipodi tags are single, better leave it - //boost::regex e4 (""); - //svg = boost::regex_replace(svg, e4, empty); + // boost::regex e4 (""); + // svg = boost::regex_replace(svg, e4, empty); // removing metadata tags - boost::regex e5 (""); + boost::regex e5(""); svg = boost::regex_replace(svg, e5, empty); // removing closing svg tags - boost::regex e6 (""); + boost::regex e6(""); svg = boost::regex_replace(svg, e6, empty); // restoring linebreaks - boost::regex e7 ("--endOfLine--"); + boost::regex e7("--endOfLine--"); svg = boost::regex_replace(svg, e7, linebreak); Py::String result(svg); return result; @@ -334,4 +381,4 @@ PyObject* initModule() return Base::Interpreter().addModule(new Module); } -} // namespace Drawing +}// namespace Drawing diff --git a/src/Mod/Drawing/App/DrawingExport.cpp b/src/Mod/Drawing/App/DrawingExport.cpp index 3c49621981..67341c6610 100644 --- a/src/Mod/Drawing/App/DrawingExport.cpp +++ b/src/Mod/Drawing/App/DrawingExport.cpp @@ -22,34 +22,34 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include +#include +#include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# if OCC_VERSION_HEX < 0x070600 -# include -# endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if OCC_VERSION_HEX < 0x070600 +#include +#endif #endif #include @@ -67,17 +67,17 @@ using namespace std; TopoDS_Edge DrawingOutput::asCircle(const BRepAdaptor_Curve& c) const { - double curv=0; + double curv = 0; gp_Pnt pnt, center; try { // approximate the circle center from three positions - BRepLProp_CLProps prop(c,c.FirstParameter(),2,Precision::Confusion()); + BRepLProp_CLProps prop(c, c.FirstParameter(), 2, Precision::Confusion()); curv += prop.Curvature(); prop.CentreOfCurvature(pnt); center.ChangeCoord().Add(pnt.Coord()); - prop.SetParameter(0.5*(c.FirstParameter()+c.LastParameter())); + prop.SetParameter(0.5 * (c.FirstParameter() + c.LastParameter())); curv += prop.Curvature(); prop.CentreOfCurvature(pnt); center.ChangeCoord().Add(pnt.Coord()); @@ -106,8 +106,9 @@ TopoDS_Edge DrawingOutput::asCircle(const BRepAdaptor_Curve& c) const for (int i = nodes.Lower(); i <= nodes.Upper(); i++) { gp_Pnt p = nodes(i); double dist = p.Distance(center); - if (std::abs(dist - radius) > 0.001) + if (std::abs(dist - radius) > 0.001) { return TopoDS_Edge(); + } } gp_Circ circ; @@ -142,7 +143,7 @@ TopoDS_Edge DrawingOutput::asBSpline(const BRepAdaptor_Curve& c, int maxDegree) Standard_Integer maxSegment = 50; Handle(BRepAdaptor_HCurve) hCurve = new BRepAdaptor_HCurve(c); // approximate the curve using a tolerance - Approx_Curve3d approx(hCurve,tol3D,GeomAbs_C0,maxSegment,maxDegree); + Approx_Curve3d approx(hCurve, tol3D, GeomAbs_C0, maxSegment, maxDegree); if (approx.IsDone() && approx.HasResult()) { // have the result Handle(Geom_BSplineCurve) spline = approx.Curve(); @@ -154,15 +155,14 @@ TopoDS_Edge DrawingOutput::asBSpline(const BRepAdaptor_Curve& c, int maxDegree) } SVGOutput::SVGOutput() -{ -} +{} std::string SVGOutput::exportEdges(const TopoDS_Shape& input) { std::stringstream result; TopExp_Explorer edges(input, TopAbs_EDGE); - for (int i = 1 ; edges.More(); edges.Next(),i++) { + for (int i = 1; edges.More(); edges.Next(), i++) { const TopoDS_Edge& edge = TopoDS::Edge(edges.Current()); BRepAdaptor_Curve adapt(edge); if (adapt.GetType() == GeomAbs_Circle) { @@ -172,14 +172,14 @@ std::string SVGOutput::exportEdges(const TopoDS_Shape& input) printEllipse(adapt, i, result); } else if (adapt.GetType() == GeomAbs_BSplineCurve) { -// TopoDS_Edge circle = asCircle(adapt); -// if (circle.IsNull()) { - printBSpline(adapt, i, result); -// } -// else { -// BRepAdaptor_Curve adapt_circle(circle); -// printCircle(adapt_circle, result); -// } + // TopoDS_Edge circle = asCircle(adapt); + // if (circle.IsNull()) { + printBSpline(adapt, i, result); + // } + // else { + // BRepAdaptor_Curve adapt_circle(circle); + // printCircle(adapt_circle, result); + // } } else if (adapt.GetType() == GeomAbs_BezierCurve) { printBezier(adapt, i, result); @@ -196,81 +196,77 @@ std::string SVGOutput::exportEdges(const TopoDS_Shape& input) void SVGOutput::printCircle(const BRepAdaptor_Curve& c, std::ostream& out) { gp_Circ circ = c.Circle(); - const gp_Pnt& p= circ.Location(); + const gp_Pnt& p = circ.Location(); double r = circ.Radius(); double f = c.FirstParameter(); double l = c.LastParameter(); gp_Pnt s = c.Value(f); - gp_Pnt m = c.Value((l+f)/2.0); + gp_Pnt m = c.Value((l + f) / 2.0); gp_Pnt e = c.Value(l); - gp_Vec v1(m,s); - gp_Vec v2(m,e); - gp_Vec v3(0,0,1); - double a = v3.DotCross(v1,v2); + gp_Vec v1(m, s); + gp_Vec v2(m, e); + gp_Vec v3(0, 0, 1); + double a = v3.DotCross(v1, v2); // a full circle - if (fabs(l-f) > 1.0 && s.SquareDistance(e) < 0.001) { - out << ""; + if (fabs(l - f) > 1.0 && s.SquareDistance(e) < 0.001) { + out << ""; } // arc of circle else { // See also https://developer.mozilla.org/en/SVG/Tutorial/Paths - char xar = '0'; // x-axis-rotation - char las = (l-f > D_PI) ? '1' : '0'; // large-arc-flag - char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1) - out << ""; + char xar = '0'; // x-axis-rotation + char las = (l - f > D_PI) ? '1' : '0';// large-arc-flag + char swp = (a < 0) ? '1' : '0';// sweep-flag, i.e. clockwise (0) or counter-clockwise (1) + out << ""; } } void SVGOutput::printEllipse(const BRepAdaptor_Curve& c, int id, std::ostream& out) { gp_Elips ellp = c.Ellipse(); - const gp_Pnt& p= ellp.Location(); + const gp_Pnt& p = ellp.Location(); double r1 = ellp.MajorRadius(); double r2 = ellp.MinorRadius(); double f = c.FirstParameter(); double l = c.LastParameter(); gp_Pnt s = c.Value(f); - gp_Pnt m = c.Value((l+f)/2.0); + gp_Pnt m = c.Value((l + f) / 2.0); gp_Pnt e = c.Value(l); // If the minor radius is very small compared to the major radius // the geometry actually degenerates to a line - double ratio = std::min(r1,r2)/std::max(r1,r2); + double ratio = std::min(r1, r2) / std::max(r1, r2); if (ratio < 0.001) { printGeneric(c, id, out); return; } - gp_Vec v1(m,s); - gp_Vec v2(m,e); - gp_Vec v3(0,0,1); - double a = v3.DotCross(v1,v2); - + gp_Vec v1(m, s); + gp_Vec v2(m, e); + gp_Vec v3(0, 0, 1); + double a = v3.DotCross(v1, v2); + // a full ellipse // See also https://developer.mozilla.org/en/SVG/Tutorial/Paths gp_Dir xaxis = ellp.XAxis().Direction(); - Standard_Real angle = xaxis.AngleWithRef(gp_Dir(1,0,0),gp_Dir(0,0,-1)); + Standard_Real angle = xaxis.AngleWithRef(gp_Dir(1, 0, 0), gp_Dir(0, 0, -1)); angle = Base::toDegrees(angle); - if (fabs(l-f) > 1.0 && s.SquareDistance(e) < 0.001) { - out << "" << std::endl; - out << "" << std::endl; + if (fabs(l - f) > 1.0 && s.SquareDistance(e) < 0.001) { + out << "" + << std::endl; + out << "" << std::endl; out << "" << std::endl; } // arc of ellipse else { - char las = (l-f > D_PI) ? '1' : '0'; // large-arc-flag - char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1) - out << "" << std::endl; + char las = (l - f > D_PI) ? '1' : '0';// large-arc-flag + char swp = (a < 0) ? '1' : '0';// sweep-flag, i.e. clockwise (0) or counter-clockwise (1) + out << "" << std::endl; } } @@ -301,28 +297,27 @@ void SVGOutput::printBezier(const BRepAdaptor_Curve& c, int id, std::ostream& ou gp_Pnt p1 = bezier->Pole(1); str << p1.X() << "," << p1.Y(); if (bezier->Degree() == 3) { - if (poles != 4) + if (poles != 4) { Standard_Failure::Raise("do it the generic way"); + } gp_Pnt p2 = bezier->Pole(2); gp_Pnt p3 = bezier->Pole(3); gp_Pnt p4 = bezier->Pole(4); - str << " C" - << p2.X() << "," << p2.Y() << " " - << p3.X() << "," << p3.Y() << " " + str << " C" << p2.X() << "," << p2.Y() << " " << p3.X() << "," << p3.Y() << " " << p4.X() << "," << p4.Y() << " "; } else if (bezier->Degree() == 2) { - if (poles != 3) + if (poles != 3) { Standard_Failure::Raise("do it the generic way"); + } gp_Pnt p2 = bezier->Pole(2); gp_Pnt p3 = bezier->Pole(3); - str << " Q" - << p2.X() << "," << p2.Y() << " " - << p3.X() << "," << p3.Y() << " "; + str << " Q" << p2.X() << "," << p2.Y() << " " << p3.X() << "," << p3.Y() << " "; } else if (bezier->Degree() == 1) { - if (poles != 2) + if (poles != 2) { Standard_Failure::Raise("do it the generic way"); + } gp_Pnt p2 = bezier->Pole(2); str << " L" << p2.X() << "," << p2.Y() << " "; } @@ -347,11 +342,12 @@ void SVGOutput::printBSpline(const BRepAdaptor_Curve& c, int id, std::ostream& o Standard_Integer maxDegree = 3, maxSegment = 100; Handle(BRepAdaptor_HCurve) hCurve = new BRepAdaptor_HCurve(c); // approximate the curve using a tolerance - Approx_Curve3d approx(hCurve,tol3D,GeomAbs_C0,maxSegment,maxDegree); + Approx_Curve3d approx(hCurve, tol3D, GeomAbs_C0, maxSegment, maxDegree); if (approx.IsDone() && approx.HasResult()) { // have the result spline = approx.Curve(); - } else { + } + else { printGeneric(c, id, out); return; } @@ -359,7 +355,7 @@ void SVGOutput::printBSpline(const BRepAdaptor_Curve& c, int id, std::ostream& o GeomConvert_BSplineCurveToBezierCurve crt(spline); Standard_Integer arcs = crt.NbArcs(); str << "NbPoles(); if (i == 1) { @@ -367,28 +363,27 @@ void SVGOutput::printBSpline(const BRepAdaptor_Curve& c, int id, std::ostream& o str << p1.X() << "," << p1.Y(); } if (bezier->Degree() == 3) { - if (poles != 4) + if (poles != 4) { Standard_Failure::Raise("do it the generic way"); + } gp_Pnt p2 = bezier->Pole(2); gp_Pnt p3 = bezier->Pole(3); gp_Pnt p4 = bezier->Pole(4); - str << " C" - << p2.X() << "," << p2.Y() << " " - << p3.X() << "," << p3.Y() << " " + str << " C" << p2.X() << "," << p2.Y() << " " << p3.X() << "," << p3.Y() << " " << p4.X() << "," << p4.Y() << " "; } else if (bezier->Degree() == 2) { - if (poles != 3) + if (poles != 3) { Standard_Failure::Raise("do it the generic way"); + } gp_Pnt p2 = bezier->Pole(2); gp_Pnt p3 = bezier->Pole(3); - str << " Q" - << p2.X() << "," << p2.Y() << " " - << p3.X() << "," << p3.Y() << " "; + str << " Q" << p2.X() << "," << p2.Y() << " " << p3.X() << "," << p3.Y() << " "; } else if (bezier->Degree() == 1) { - if (poles != 2) + if (poles != 2) { Standard_Failure::Raise("do it the generic way"); + } gp_Pnt p2 = bezier->Pole(2); str << " L" << p2.X() << "," << p2.Y() << " "; } @@ -412,24 +407,25 @@ void SVGOutput::printGeneric(const BRepAdaptor_Curve& bac, int id, std::ostream& if (!polygon.IsNull()) { const TColgp_Array1OfPnt& nodes = polygon->Nodes(); char c = 'M'; - out << "" << endl; - } else if (bac.GetType() == GeomAbs_Line) { - //BRep_Tool::Polygon3D assumes the edge has polygon representation - ie already been "tessellated" - //this is not true for all edges, especially "floating edges" + } + else if (bac.GetType() == GeomAbs_Line) { + // BRep_Tool::Polygon3D assumes the edge has polygon representation - ie already been + // "tessellated" this is not true for all edges, especially "floating edges" double f = bac.FirstParameter(); double l = bac.LastParameter(); gp_Pnt s = bac.Value(f); gp_Pnt e = bac.Value(l); char c = 'M'; - out << "" << endl; } } @@ -437,15 +433,14 @@ void SVGOutput::printGeneric(const BRepAdaptor_Curve& bac, int id, std::ostream& // ---------------------------------------------------------------------------- DXFOutput::DXFOutput() -{ -} +{} std::string DXFOutput::exportEdges(const TopoDS_Shape& input) { std::stringstream result; TopExp_Explorer edges(input, TopAbs_EDGE); - for (int i = 1 ; edges.More(); edges.Next(),i++) { + for (int i = 1; edges.More(); edges.Next(), i++) { const TopoDS_Edge& edge = TopoDS::Edge(edges.Current()); BRepAdaptor_Curve adapt(edge); if (adapt.GetType() == GeomAbs_Circle) { @@ -466,53 +461,52 @@ std::string DXFOutput::exportEdges(const TopoDS_Shape& input) return result.str(); } -void DXFOutput::printHeader( std::ostream& out) +void DXFOutput::printHeader(std::ostream& out) { - out << 0 << endl; - out << "SECTION" << endl; - out << 2 << endl; - out << "ENTITIES" << endl; + out << 0 << endl; + out << "SECTION" << endl; + out << 2 << endl; + out << "ENTITIES" << endl; } void DXFOutput::printCircle(const BRepAdaptor_Curve& c, std::ostream& out) { gp_Circ circ = c.Circle(); - //const gp_Ax1& axis = c->Axis(); - const gp_Pnt& p= circ.Location(); + // const gp_Ax1& axis = c->Axis(); + const gp_Pnt& p = circ.Location(); double r = circ.Radius(); double f = c.FirstParameter(); double l = c.LastParameter(); gp_Pnt s = c.Value(f); - gp_Pnt m = c.Value((l+f)/2.0); + gp_Pnt m = c.Value((l + f) / 2.0); gp_Pnt e = c.Value(l); - gp_Vec v1(m,s); - gp_Vec v2(m,e); - gp_Vec v3(0,0,1); - double a = v3.DotCross(v1,v2); + gp_Vec v1(m, s); + gp_Vec v2(m, e); + gp_Vec v3(0, 0, 1); + double a = v3.DotCross(v1, v2); // a full circle if (s.SquareDistance(e) < 0.001) { - //out << ""; - out << 0 << endl; - out << "CIRCLE" << endl; - out << 8 << endl; // Group code for layer name - out << "sheet_layer" << endl; // Layer number - out << "100" << endl; + // out << ""; + out << 0 << endl; + out << "CIRCLE" << endl; + out << 8 << endl; // Group code for layer name + out << "sheet_layer" << endl;// Layer number + out << "100" << endl; out << "AcDbEntity" << endl; - out << "100" << endl; - out << "AcDbCircle" << endl; - out << 10 << endl; // Centre X - out << p.X() << endl; // X in WCS coordinates - out << 20 << endl; - out << p.Y() << endl; // Y in WCS coordinates - out << 30 << endl; - out << 0 << endl; // Z in WCS coordinates-leaving flat - out << 40 << endl; // - out << r << endl; // Radius - } - + out << "100" << endl; + out << "AcDbCircle" << endl; + out << 10 << endl; // Centre X + out << p.X() << endl;// X in WCS coordinates + out << 20 << endl; + out << p.Y() << endl;// Y in WCS coordinates + out << 30 << endl; + out << 0 << endl; // Z in WCS coordinates-leaving flat + out << 40 << endl;// + out << r << endl; // Radius + } // arc of circle @@ -525,121 +519,122 @@ void DXFOutput::printCircle(const BRepAdaptor_Curve& c, std::ostream& out) << " A" << r << " " << r << " " << xar << " " << las << " " << swp << " " << e.X() << " " << e.Y() << "\" />";*/ - double ax = s.X() - p.X(); - double ay = s.Y() - p.Y(); - double bx = e.X() - p.X(); - double by = e.Y() - p.Y(); - - double start_angle = atan2(ay, ax) * 180/D_PI; - double end_angle = atan2(by, bx) * 180/D_PI; - - - if(a > 0){ - double temp = start_angle; - start_angle = end_angle; - end_angle = temp;} - out << 0 << endl; - out << "ARC" << endl; - out << 8 << endl; // Group code for layer name - out << "sheet_layer" << endl; // Layer number - out << "100" << endl; - out << "AcDbEntity" << endl; - out << "100" << endl; - out << "AcDbCircle" << endl; - out << 10 << endl; // Centre X - out << p.X() << endl; // X in WCS coordinates - out << 20 << endl; - out << p.Y() << endl; // Y in WCS coordinates - out << 30 << endl; - out << 0 << endl; // Z in WCS coordinates - out << 40 << endl; // - out << r << endl; // Radius - out << "100" << endl; - out << "AcDbArc" << endl; - out << 50 << endl; - out << start_angle << endl; // Start angle - out << 51 << endl; - out << end_angle << endl; // End angle + double ax = s.X() - p.X(); + double ay = s.Y() - p.Y(); + double bx = e.X() - p.X(); + double by = e.Y() - p.Y(); + double start_angle = atan2(ay, ax) * 180 / D_PI; + double end_angle = atan2(by, bx) * 180 / D_PI; + if (a > 0) { + double temp = start_angle; + start_angle = end_angle; + end_angle = temp; + } + out << 0 << endl; + out << "ARC" << endl; + out << 8 << endl; // Group code for layer name + out << "sheet_layer" << endl;// Layer number + out << "100" << endl; + out << "AcDbEntity" << endl; + out << "100" << endl; + out << "AcDbCircle" << endl; + out << 10 << endl; // Centre X + out << p.X() << endl;// X in WCS coordinates + out << 20 << endl; + out << p.Y() << endl;// Y in WCS coordinates + out << 30 << endl; + out << 0 << endl; // Z in WCS coordinates + out << 40 << endl;// + out << r << endl; // Radius + out << "100" << endl; + out << "AcDbArc" << endl; + out << 50 << endl; + out << start_angle << endl;// Start angle + out << 51 << endl; + out << end_angle << endl;// End angle } } void DXFOutput::printEllipse(const BRepAdaptor_Curve& c, int /*id*/, std::ostream& out) { gp_Elips ellp = c.Ellipse(); - const gp_Pnt& p= ellp.Location(); + const gp_Pnt& p = ellp.Location(); double r1 = ellp.MajorRadius(); double r2 = ellp.MinorRadius(); - double dp = ellp.Axis().Direction().Dot(gp_Vec(0,0,1)); + double dp = ellp.Axis().Direction().Dot(gp_Vec(0, 0, 1)); // a full ellipse - /* if (s.SquareDistance(e) < 0.001) { - out << ""; + /* if (s.SquareDistance(e) < 0.001) { + out << ""; + } + // arc of ellipse + else { + // See also https://developer.mozilla.org/en/SVG/Tutorial/Paths + gp_Dir xaxis = ellp.XAxis().Direction(); + Standard_Real angle = xaxis.Angle(gp_Dir(1,0,0)); + angle = Base::toDegrees(angle); + char las = (l-f > D_PI) ? '1' : '0'; // large-arc-flag + char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1) + out << ""; + }*/ + gp_Dir xaxis = ellp.XAxis().Direction(); + double angle = xaxis.AngleWithRef(gp_Dir(1, 0, 0), gp_Dir(0, 0, -1)); + // double rotation = Base::toDegrees(angle); + + double start_angle = c.FirstParameter(); + double end_angle = c.LastParameter(); + + double major_x; + double major_y; + + major_x = r1 * cos(angle); + major_y = r1 * sin(angle); + + double ratio = r2 / r1; + + if (dp < 0) { + double temp = start_angle; + start_angle = end_angle; + end_angle = temp; } - // arc of ellipse - else { - // See also https://developer.mozilla.org/en/SVG/Tutorial/Paths - gp_Dir xaxis = ellp.XAxis().Direction(); - Standard_Real angle = xaxis.Angle(gp_Dir(1,0,0)); - angle = Base::toDegrees(angle); - char las = (l-f > D_PI) ? '1' : '0'; // large-arc-flag - char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1) - out << ""; - }*/ - gp_Dir xaxis = ellp.XAxis().Direction(); - double angle = xaxis.AngleWithRef(gp_Dir(1,0,0),gp_Dir(0,0,-1)); - //double rotation = Base::toDegrees(angle); - - double start_angle = c.FirstParameter(); - double end_angle = c.LastParameter(); - - double major_x;double major_y; - - major_x = r1 * cos(angle); - major_y = r1 * sin(angle); - - double ratio = r2/r1; - - if(dp < 0){ - double temp = start_angle; - start_angle = end_angle; - end_angle = temp; - } - out << 0 << endl; - out << "ELLIPSE" << endl; - out << 8 << endl; // Group code for layer name - out << "sheet_layer" << endl; // Layer number - out << "100" << endl; + out << 0 << endl; + out << "ELLIPSE" << endl; + out << 8 << endl; // Group code for layer name + out << "sheet_layer" << endl;// Layer number + out << "100" << endl; out << "AcDbEntity" << endl; - out << "100" << endl; - out << "AcDbEllipse" << endl; - out << 10 << endl; // Centre X - out << p.X() << endl; // X in WCS coordinates - out << 20 << endl; - out << p.Y() << endl; // Y in WCS coordinates - out << 30 << endl; - out << 0 << endl; // Z in WCS coordinates - out << 11 << endl; // - out << major_x << endl; // Major X - out << 21 << endl; - out << major_y << endl; // Major Y - out << 31 << endl; - out << 0 << endl; // Major Z - out << 40 << endl; // - out << ratio << endl; // Ratio - out << 41 << endl; - out << start_angle << endl; // Start angle - out << 42 << endl; - out << end_angle << endl; // End angle + out << "100" << endl; + out << "AcDbEllipse" << endl; + out << 10 << endl; // Centre X + out << p.X() << endl;// X in WCS coordinates + out << 20 << endl; + out << p.Y() << endl;// Y in WCS coordinates + out << 30 << endl; + out << 0 << endl; // Z in WCS coordinates + out << 11 << endl; // + out << major_x << endl;// Major X + out << 21 << endl; + out << major_y << endl;// Major Y + out << 31 << endl; + out << 0 << endl; // Major Z + out << 40 << endl; // + out << ratio << endl;// Ratio + out << 41 << endl; + out << start_angle << endl;// Start angle + out << 42 << endl; + out << end_angle << endl;// End angle } -void DXFOutput::printBSpline(const BRepAdaptor_Curve& c, int id, std::ostream& out) //Not even close yet- DF +void DXFOutput::printBSpline(const BRepAdaptor_Curve& c, + int id, + std::ostream& out)// Not even close yet- DF { try { std::stringstream str; @@ -648,62 +643,71 @@ void DXFOutput::printBSpline(const BRepAdaptor_Curve& c, int id, std::ostream& o Standard_Integer maxDegree = 3, maxSegment = 50; Handle(BRepAdaptor_HCurve) hCurve = new BRepAdaptor_HCurve(c); // approximate the curve using a tolerance - Approx_Curve3d approx(hCurve,tol3D,GeomAbs_C0,maxSegment,maxDegree); + Approx_Curve3d approx(hCurve, tol3D, GeomAbs_C0, maxSegment, maxDegree); if (approx.IsDone() && approx.HasResult()) { // have the result spline = approx.Curve(); - } else { + } + else { printGeneric(c, id, out); return; } - - //GeomConvert_BSplineCurveToBezierCurve crt(spline); - //GeomConvert_BSplineCurveKnotSplitting crt(spline,0); - //Standard_Integer arcs = crt.NbArcs(); - //Standard_Integer arcs = crt.NbSplits()-1; + + // GeomConvert_BSplineCurveToBezierCurve crt(spline); + // GeomConvert_BSplineCurveKnotSplitting crt(spline,0); + // Standard_Integer arcs = crt.NbArcs(); + // Standard_Integer arcs = crt.NbSplits()-1; Standard_Integer m = 0; if (spline->IsPeriodic()) { - m = spline->NbPoles() + 2*spline->Degree() - spline->Multiplicity(1) + 2; + m = spline->NbPoles() + 2 * spline->Degree() - spline->Multiplicity(1) + 2; } else { - for (int i=1; i<= spline->NbKnots(); i++) + for (int i = 1; i <= spline->NbKnots(); i++) { m += spline->Multiplicity(i); + } } - TColStd_Array1OfReal knotsequence(1,m); + TColStd_Array1OfReal knotsequence(1, m); spline->KnotSequence(knotsequence); - TColgp_Array1OfPnt poles(1,spline->NbPoles()); + TColgp_Array1OfPnt poles(1, spline->NbPoles()); spline->Poles(poles); str << 0 << endl << "SPLINE" << endl - << 8 << endl // Group code for layer name - << "sheet_layer" << endl // Layer name - << "100" << endl + << 8 << endl // Group code for layer name + << "sheet_layer" << endl// Layer name + << "100" << endl << "AcDbEntity" << endl - << "100" << endl - << "AcDbSpline" << endl + << "100" << endl + << "AcDbSpline" << endl << 70 << endl - << spline->IsRational()*4 << endl //flags - << 71 << endl << spline->Degree() << endl - << 72 << endl << knotsequence.Length() << endl - << 73 << endl << poles.Length() << endl - << 74 << endl << 0 << endl; //fitpoints + << spline->IsRational() * 4 << endl// flags + << 71 << endl + << spline->Degree() << endl + << 72 << endl + << knotsequence.Length() << endl + << 73 << endl + << poles.Length() << endl + << 74 << endl + << 0 << endl;// fitpoints - for (int i = knotsequence.Lower() ; i <= knotsequence.Upper(); i++) { + for (int i = knotsequence.Lower(); i <= knotsequence.Upper(); i++) { str << 40 << endl << knotsequence(i) << endl; } for (int i = poles.Lower(); i <= poles.Upper(); i++) { gp_Pnt pole = poles(i); - str << 10 << endl << pole.X() << endl - << 20 << endl << pole.Y() << endl - << 30 << endl << pole.Z() << endl; + str << 10 << endl + << pole.X() << endl + << 20 << endl + << pole.Y() << endl + << 30 << endl + << pole.Z() << endl; if (spline->IsRational()) { str << 41 << endl << spline->Weight(i) << endl; } } - //str << "\" />"; + // str << "\" />"; out << str.str(); } catch (Standard_Failure&) { @@ -723,24 +727,24 @@ void DXFOutput::printGeneric(const BRepAdaptor_Curve& c, int /*id*/, std::ostrea gp_Vec VE; c.D1(uEnd, PE, VE); - out << "0" << endl; - out << "LINE" << endl; - out << "8" << endl; // Group code for layer name - out << "sheet_layer" << endl; // Layer name - out << "100" << endl; + out << "0" << endl; + out << "LINE" << endl; + out << "8" << endl; // Group code for layer name + out << "sheet_layer" << endl;// Layer name + out << "100" << endl; out << "AcDbEntity" << endl; - out << "100" << endl; - out << "AcDbLine" << endl; - out << "10" << endl; // Start point of line - out << PS.X() << endl; // X in WCS coordinates - out << "20" << endl; - out << PS.Y() << endl; // Y in WCS coordinates - out << "30" << endl; - out << "0" << endl; // Z in WCS coordinates - out << "11" << endl; // End point of line - out << PE.X() << endl; // X in WCS coordinates - out << "21" << endl; - out << PE.Y() << endl; // Y in WCS coordinates - out << "31" << endl; - out << "0" << endl; // Z in WCS coordinates + out << "100" << endl; + out << "AcDbLine" << endl; + out << "10" << endl; // Start point of line + out << PS.X() << endl;// X in WCS coordinates + out << "20" << endl; + out << PS.Y() << endl;// Y in WCS coordinates + out << "30" << endl; + out << "0" << endl; // Z in WCS coordinates + out << "11" << endl; // End point of line + out << PE.X() << endl;// X in WCS coordinates + out << "21" << endl; + out << PE.Y() << endl;// Y in WCS coordinates + out << "31" << endl; + out << "0" << endl;// Z in WCS coordinates } diff --git a/src/Mod/Drawing/App/DrawingExport.h b/src/Mod/Drawing/App/DrawingExport.h index 56d0806856..20c2e3bf5a 100644 --- a/src/Mod/Drawing/App/DrawingExport.h +++ b/src/Mod/Drawing/App/DrawingExport.h @@ -23,9 +23,9 @@ #ifndef DRAWING_EXPORT_H #define DRAWING_EXPORT_H -#include -#include #include +#include +#include class TopoDS_Shape; @@ -43,7 +43,7 @@ public: TopoDS_Edge asBSpline(const BRepAdaptor_Curve&, int maxDegree) const; }; -class DrawingExport SVGOutput : public DrawingOutput +class DrawingExport SVGOutput: public DrawingOutput { public: SVGOutput(); @@ -58,7 +58,7 @@ private: }; /* dxf output section - Dan Falck 2011/09/25 */ -class DrawingExport DXFOutput : public DrawingOutput +class DrawingExport DXFOutput: public DrawingOutput { public: DXFOutput(); @@ -72,6 +72,6 @@ private: void printGeneric(const BRepAdaptor_Curve&, int id, std::ostream&); }; -} //namespace Drawing +}// namespace Drawing -#endif // DRAWING_EXPORT_H +#endif// DRAWING_EXPORT_H diff --git a/src/Mod/Drawing/App/FeatureClip.cpp b/src/Mod/Drawing/App/FeatureClip.cpp index f7714a6854..df4515ad58 100644 --- a/src/Mod/Drawing/App/FeatureClip.cpp +++ b/src/Mod/Drawing/App/FeatureClip.cpp @@ -22,8 +22,8 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include +#include +#include #endif #include "FeatureClip.h" @@ -39,25 +39,50 @@ using namespace std; PROPERTY_SOURCE(Drawing::FeatureClip, App::DocumentObjectGroup) -FeatureClip::FeatureClip(void) +FeatureClip::FeatureClip(void) { - static const char *group = "Drawing view"; + static const char* group = "Drawing view"; App::PropertyType hidden = (App::PropertyType)(App::Prop_Hidden); - ADD_PROPERTY_TYPE(ViewResult ,(""),group,hidden,"Resulting SVG view of this clip"); - ADD_PROPERTY_TYPE(X ,(10),group,App::Prop_None ,"The left margin of the view area of this clip"); - ADD_PROPERTY_TYPE(Y ,(10),group,App::Prop_None ,"The top margin of the view area of this clip"); - ADD_PROPERTY_TYPE(Height ,(10),group,App::Prop_None ,"The height of the view area of this clip"); - ADD_PROPERTY_TYPE(Width ,(10),group,App::Prop_None ,"The width of the view area of this clip"); - ADD_PROPERTY_TYPE(ShowFrame ,(0),group,App::Prop_None,"Specifies if the clip frame appears on the page or not"); - // The 'Visible' property is handled by the view provider exclusively. It has the 'Output' flag set to - // avoid to call the execute() method. The view provider touches the page object, instead. - App::PropertyType propType = static_cast(App::Prop_Hidden|App::Prop_Output); - ADD_PROPERTY_TYPE(Visible, (true),group,propType,"Control whether frame is visible in page object"); + ADD_PROPERTY_TYPE(ViewResult, (""), group, hidden, "Resulting SVG view of this clip"); + ADD_PROPERTY_TYPE(X, + (10), + group, + App::Prop_None, + "The left margin of the view area of this clip"); + ADD_PROPERTY_TYPE(Y, + (10), + group, + App::Prop_None, + "The top margin of the view area of this clip"); + ADD_PROPERTY_TYPE(Height, + (10), + group, + App::Prop_None, + "The height of the view area of this clip"); + ADD_PROPERTY_TYPE(Width, + (10), + group, + App::Prop_None, + "The width of the view area of this clip"); + ADD_PROPERTY_TYPE(ShowFrame, + (0), + group, + App::Prop_None, + "Specifies if the clip frame appears on the page or not"); + // The 'Visible' property is handled by the view provider exclusively. It has the 'Output' flag + // set to avoid to call the execute() method. The view provider touches the page object, + // instead. + App::PropertyType propType = + static_cast(App::Prop_Hidden | App::Prop_Output); + ADD_PROPERTY_TYPE(Visible, + (true), + group, + propType, + "Control whether frame is visible in page object"); } FeatureClip::~FeatureClip() -{ -} +{} /// get called by the container when a Property was changed void FeatureClip::onChanged(const App::Property* prop) @@ -65,7 +90,7 @@ void FeatureClip::onChanged(const App::Property* prop) App::DocumentObjectGroup::onChanged(prop); } -App::DocumentObjectExecReturn *FeatureClip::execute(void) +App::DocumentObjectExecReturn* FeatureClip::execute(void) { ostringstream svg; @@ -79,7 +104,7 @@ App::DocumentObjectExecReturn *FeatureClip::execute(void) // show clip frame on the page if needed if (ShowFrame.getValue()) { - svg << "" << endl; // get through the children and collect all the views - const vector &Grp = Group.getValues(); - for (vector::const_iterator It= Grp.begin();It!=Grp.end();++It) { + const vector& Grp = Group.getValues(); + for (vector::const_iterator It = Grp.begin(); It != Grp.end(); ++It) { if ((*It)->getTypeId().isDerivedFrom(Drawing::FeatureView::getClassTypeId())) { - Drawing::FeatureView *View = static_cast(*It); + Drawing::FeatureView* View = static_cast(*It); svg << View->ViewResult.getValue() << endl; } } diff --git a/src/Mod/Drawing/App/FeatureClip.h b/src/Mod/Drawing/App/FeatureClip.h index 9c83d7b84f..30b4f342c8 100644 --- a/src/Mod/Drawing/App/FeatureClip.h +++ b/src/Mod/Drawing/App/FeatureClip.h @@ -53,11 +53,12 @@ public: /** @name methods override Feature */ //@{ /// recalculate the Feature - virtual App::DocumentObjectExecReturn *execute(void); + virtual App::DocumentObjectExecReturn* execute(void); //@} /// returns the type name of the ViewProvider - virtual const char* getViewProviderName(void) const { + virtual const char* getViewProviderName(void) const + { return "DrawingGui::ViewProviderDrawingClip"; } @@ -66,7 +67,7 @@ protected: }; -} //namespace Drawing +}// namespace Drawing #endif diff --git a/src/Mod/Drawing/App/FeaturePage.cpp b/src/Mod/Drawing/App/FeaturePage.cpp index 5e801fe276..f736b704c7 100644 --- a/src/Mod/Drawing/App/FeaturePage.cpp +++ b/src/Mod/Drawing/App/FeaturePage.cpp @@ -22,20 +22,20 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include +#include +#include +#include +#include -# include +#include #endif #include #include #include -#include "FeaturePage.h" #include "FeatureClip.h" +#include "FeaturePage.h" #include "FeatureView.h" @@ -48,18 +48,26 @@ using namespace std; PROPERTY_SOURCE(Drawing::FeaturePage, App::DocumentObjectGroup) -FeaturePage::FeaturePage(void) : numChildren(0) +FeaturePage::FeaturePage(void) + : numChildren(0) { - static const char *group = "Drawing view"; + static const char* group = "Drawing view"; - ADD_PROPERTY_TYPE(PageResult, (nullptr), group, App::Prop_Output, "Resulting SVG document of that page"); + ADD_PROPERTY_TYPE(PageResult, + (nullptr), + group, + App::Prop_Output, + "Resulting SVG document of that page"); ADD_PROPERTY_TYPE(Template, (""), group, App::Prop_None, "Template for the page"); - ADD_PROPERTY_TYPE(EditableTexts, (""), group, App::Prop_None, "Substitution values for the editable strings in the template"); + ADD_PROPERTY_TYPE(EditableTexts, + (""), + group, + App::Prop_None, + "Substitution values for the editable strings in the template"); } FeaturePage::~FeaturePage() -{ -} +{} void FeaturePage::onBeforeChange(const App::Property* prop) { @@ -78,19 +86,23 @@ void FeaturePage::onChanged(const App::Property* prop) // When loading a document the included file // doesn't need to exist at this point. Base::FileInfo fi(PageResult.getValue()); - if (!fi.exists()) + if (!fi.exists()) { return; + } } - } else if (prop == &EditableTexts) { + } + else if (prop == &EditableTexts) { if (!this->isRestoring()) { this->execute(); return; } - } else if (prop == &Template) { + } + else if (prop == &Template) { if (!this->isRestoring()) { EditableTexts.setValues(getEditableTextsFromTemplate()); } - } else if (prop == &Group) { + } + else if (prop == &Group) { if (Group.getSize() != numChildren) { numChildren = Group.getSize(); touch(); @@ -103,29 +115,33 @@ void FeaturePage::onChanged(const App::Property* prop) void FeaturePage::onDocumentRestored() { // Needs to be tmp. set because otherwise the custom text gets overridden (#0002064) - this->StatusBits.set(App::Restore); // the 'Restore' flag + this->StatusBits.set(App::Restore);// the 'Restore' flag Base::FileInfo templateInfo(Template.getValue()); if (!templateInfo.exists()) { Base::FileInfo fi(Template.getValue()); - if (fi.fileName().empty()) + if (fi.fileName().empty()) { fi.setFile(PageResult.getValue()); - std::string path = App::Application::getResourceDir() + "Mod/Drawing/Templates/" + fi.fileName(); + } + std::string path = + App::Application::getResourceDir() + "Mod/Drawing/Templates/" + fi.fileName(); // try to find the template in user dir/Templates first Base::FileInfo tempfi(App::Application::getUserAppDataDir() + "Templates/" + fi.fileName()); - if (tempfi.exists()) + if (tempfi.exists()) { path = tempfi.filePath(); + } Template.setValue(path); } - this->StatusBits.reset(App::Restore); // the 'Restore' flag + this->StatusBits.reset(App::Restore);// the 'Restore' flag } -App::DocumentObjectExecReturn *FeaturePage::execute(void) +App::DocumentObjectExecReturn* FeaturePage::execute(void) { std::string temp = Template.getValue(); - if (temp.empty()) + if (temp.empty()) { return App::DocumentObject::StdReturn; + } Base::FileInfo fi(temp); if (!fi.isReadable()) { @@ -133,54 +149,64 @@ App::DocumentObjectExecReturn *FeaturePage::execute(void) fi.setFile(App::Application::getResourceDir() + "Mod/Drawing/Templates/" + fi.fileName()); // try the redirect if (!fi.isReadable()) { - Base::Console().Log("FeaturePage::execute() not able to open %s!\n",Template.getValue()); + Base::Console().Log("FeaturePage::execute() not able to open %s!\n", + Template.getValue()); std::string error = std::string("Cannot open file ") + Template.getValue(); return new App::DocumentObjectExecReturn(error); } } - if (std::string(PageResult.getValue()).empty()) + if (std::string(PageResult.getValue()).empty()) { PageResult.setValue(fi.filePath().c_str()); + } // open Template file string line; - ifstream file (fi.filePath().c_str()); + ifstream file(fi.filePath().c_str()); // make a temp file for FileIncluded Property string tempName = PageResult.getExchangeTempFile(); ostringstream ofile; string tempendl = "--endOfLine--"; - while (getline (file,line)) - { + while (getline(file, line)) { // check if the marker in the template is found - if(line.find("") == string::npos) + if (line.find("") == string::npos) { // if not - write through ofile << line << tempendl; - else - { + } + else { // get through the children and collect all the views - const std::vector &Grp = Group.getValues(); - for (std::vector::const_iterator It= Grp.begin();It!=Grp.end();++It) { - if ( (*It)->getTypeId().isDerivedFrom(Drawing::FeatureView::getClassTypeId()) ) { - Drawing::FeatureView *View = static_cast(*It); + const std::vector& Grp = Group.getValues(); + for (std::vector::const_iterator It = Grp.begin(); + It != Grp.end(); + ++It) { + if ((*It)->getTypeId().isDerivedFrom(Drawing::FeatureView::getClassTypeId())) { + Drawing::FeatureView* View = static_cast(*It); if (View->Visible.getValue()) { ofile << View->ViewResult.getValue(); ofile << tempendl << tempendl << tempendl; } - } else if ( (*It)->getTypeId().isDerivedFrom(Drawing::FeatureClip::getClassTypeId()) ) { - Drawing::FeatureClip *Clip = static_cast(*It); + } + else if ((*It)->getTypeId().isDerivedFrom(Drawing::FeatureClip::getClassTypeId())) { + Drawing::FeatureClip* Clip = static_cast(*It); if (Clip->Visible.getValue()) { ofile << Clip->ViewResult.getValue(); ofile << tempendl << tempendl << tempendl; } - } else if ( (*It)->getTypeId().isDerivedFrom(App::DocumentObjectGroup::getClassTypeId()) ) { + } + else if ((*It)->getTypeId().isDerivedFrom( + App::DocumentObjectGroup::getClassTypeId())) { // getting children inside subgroups too - App::DocumentObjectGroup *SubGroup = static_cast(*It); - const std::vector &SubGrp = SubGroup->Group.getValues(); - for (std::vector::const_iterator Grit= SubGrp.begin();Grit!=SubGrp.end();++Grit) { - if ( (*Grit)->getTypeId().isDerivedFrom(Drawing::FeatureView::getClassTypeId()) ) { - Drawing::FeatureView *SView = static_cast(*Grit); + App::DocumentObjectGroup* SubGroup = + static_cast(*It); + const std::vector& SubGrp = SubGroup->Group.getValues(); + for (std::vector::const_iterator Grit = SubGrp.begin(); + Grit != SubGrp.end(); + ++Grit) { + if ((*Grit)->getTypeId().isDerivedFrom( + Drawing::FeatureView::getClassTypeId())) { + Drawing::FeatureView* SView = static_cast(*Grit); if (SView->Visible.getValue()) { ofile << SView->ViewResult.getValue(); ofile << tempendl << tempendl << tempendl; @@ -198,7 +224,7 @@ App::DocumentObjectExecReturn *FeaturePage::execute(void) string outfragment(ofile.str()); const std::vector& editText = EditableTexts.getValues(); if (!editText.empty()) { - boost::regex e1 ("(.*?)"); + boost::regex e1("(.*?)"); string::const_iterator begin, end; begin = outfragment.begin(); end = outfragment.end(); @@ -210,9 +236,14 @@ App::DocumentObjectExecReturn *FeaturePage::execute(void) while (boost::regex_search(begin, end, what, e1)) { if (count < editText.size()) { // change values of editable texts - boost::regex e2 ("((.*?)()"); + boost::regex e2("((.*?)()"); std::back_insert_iterator out(newfragment); - boost::regex_replace(out, begin, what[0].second, e2, "$1>"+editText[count]+"$3"); + boost::regex_replace(out, + begin, + what[0].second, + e2, + "$1>" + editText[count] + "$3"); } count++; begin = what[0].second; @@ -224,7 +255,7 @@ App::DocumentObjectExecReturn *FeaturePage::execute(void) } // restoring linebreaks and saving the file - boost::regex e3 ("--endOfLine--"); + boost::regex e3("--endOfLine--"); string fmt = "\\n"; outfragment = boost::regex_replace(outfragment, e3, fmt); ofstream outfinal(tempName.c_str()); @@ -236,8 +267,9 @@ App::DocumentObjectExecReturn *FeaturePage::execute(void) return App::DocumentObject::StdReturn; } -std::vector FeaturePage::getEditableTextsFromTemplate(void) const { - //getting editable texts from "freecad:editable" attributes in SVG template +std::vector FeaturePage::getEditableTextsFromTemplate(void) const +{ + // getting editable texts from "freecad:editable" attributes in SVG template std::vector eds; @@ -246,20 +278,21 @@ std::vector FeaturePage::getEditableTextsFromTemplate(void) const { Base::FileInfo tfi(temp); if (!tfi.isReadable()) { // if there is a old absolute template file set use a redirect - tfi.setFile(App::Application::getResourceDir() + "Mod/Drawing/Templates/" + tfi.fileName()); + tfi.setFile(App::Application::getResourceDir() + "Mod/Drawing/Templates/" + + tfi.fileName()); // try the redirect if (!tfi.isReadable()) { return eds; } } string tline, tfrag; - ifstream tfile (tfi.filePath().c_str()); - while (getline (tfile,tline)) { + ifstream tfile(tfi.filePath().c_str()); + while (getline(tfile, tline)) { tfrag += tline; tfrag += "--endOfLine--"; } tfile.close(); - boost::regex e ("(.*?)"); + boost::regex e("(.*?)"); string::const_iterator tbegin, tend; tbegin = tfrag.begin(); tend = tfrag.end(); diff --git a/src/Mod/Drawing/App/FeaturePage.h b/src/Mod/Drawing/App/FeaturePage.h index b5c7f17b86..77ae6224b9 100644 --- a/src/Mod/Drawing/App/FeaturePage.h +++ b/src/Mod/Drawing/App/FeaturePage.h @@ -49,11 +49,12 @@ public: /** @name methods override Feature */ //@{ /// recalculate the Feature - virtual App::DocumentObjectExecReturn *execute(void); + virtual App::DocumentObjectExecReturn* execute(void); //@} /// returns the type name of the ViewProvider - virtual const char* getViewProviderName(void) const { + virtual const char* getViewProviderName(void) const + { return "DrawingGui::ViewProviderDrawingPage"; } virtual std::vector getEditableTextsFromTemplate(void) const; @@ -69,7 +70,7 @@ private: }; -} //namespace Drawing +}// namespace Drawing #endif diff --git a/src/Mod/Drawing/App/FeatureProjection.cpp b/src/Mod/Drawing/App/FeatureProjection.cpp index 6c5de821ef..39d7a6d3d5 100644 --- a/src/Mod/Drawing/App/FeatureProjection.cpp +++ b/src/Mod/Drawing/App/FeatureProjection.cpp @@ -22,11 +22,11 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include -# include -# include -# include +#include +#include +#include #endif #include "FeatureProjection.h" @@ -37,38 +37,43 @@ using namespace Drawing; PROPERTY_SOURCE(Drawing::FeatureProjection, Part::Feature) -FeatureProjection::FeatureProjection() +FeatureProjection::FeatureProjection() { - static const char *group = "Projection"; - ADD_PROPERTY_TYPE(Source ,(nullptr),group,App::Prop_None,"Shape to project"); - ADD_PROPERTY_TYPE(Direction, (Base::Vector3d(0, 0, 1)), group, App::Prop_None, + static const char* group = "Projection"; + ADD_PROPERTY_TYPE(Source, (nullptr), group, App::Prop_None, "Shape to project"); + ADD_PROPERTY_TYPE(Direction, + (Base::Vector3d(0, 0, 1)), + group, + App::Prop_None, "Projection direction"); - ADD_PROPERTY_TYPE(VCompound ,(true),group,App::Prop_None,"Projection parameter"); - ADD_PROPERTY_TYPE(Rg1LineVCompound ,(true),group,App::Prop_None,"Projection parameter"); - ADD_PROPERTY_TYPE(RgNLineVCompound ,(true),group,App::Prop_None,"Projection parameter"); - ADD_PROPERTY_TYPE(OutLineVCompound ,(true),group,App::Prop_None,"Projection parameter"); - ADD_PROPERTY_TYPE(IsoLineVCompound ,(true),group,App::Prop_None,"Projection parameter"); - ADD_PROPERTY_TYPE(HCompound ,(true),group,App::Prop_None,"Projection parameter"); - ADD_PROPERTY_TYPE(Rg1LineHCompound ,(true),group,App::Prop_None,"Projection parameter"); - ADD_PROPERTY_TYPE(RgNLineHCompound ,(true),group,App::Prop_None,"Projection parameter"); - ADD_PROPERTY_TYPE(OutLineHCompound ,(true),group,App::Prop_None,"Projection parameter"); - ADD_PROPERTY_TYPE(IsoLineHCompound ,(true),group,App::Prop_None,"Projection parameter"); + ADD_PROPERTY_TYPE(VCompound, (true), group, App::Prop_None, "Projection parameter"); + ADD_PROPERTY_TYPE(Rg1LineVCompound, (true), group, App::Prop_None, "Projection parameter"); + ADD_PROPERTY_TYPE(RgNLineVCompound, (true), group, App::Prop_None, "Projection parameter"); + ADD_PROPERTY_TYPE(OutLineVCompound, (true), group, App::Prop_None, "Projection parameter"); + ADD_PROPERTY_TYPE(IsoLineVCompound, (true), group, App::Prop_None, "Projection parameter"); + ADD_PROPERTY_TYPE(HCompound, (true), group, App::Prop_None, "Projection parameter"); + ADD_PROPERTY_TYPE(Rg1LineHCompound, (true), group, App::Prop_None, "Projection parameter"); + ADD_PROPERTY_TYPE(RgNLineHCompound, (true), group, App::Prop_None, "Projection parameter"); + ADD_PROPERTY_TYPE(OutLineHCompound, (true), group, App::Prop_None, "Projection parameter"); + ADD_PROPERTY_TYPE(IsoLineHCompound, (true), group, App::Prop_None, "Projection parameter"); } FeatureProjection::~FeatureProjection() -{ -} +{} -App::DocumentObjectExecReturn *FeatureProjection::execute(void) +App::DocumentObjectExecReturn* FeatureProjection::execute(void) { App::DocumentObject* link = Source.getValue(); - if (!link) + if (!link) { return new App::DocumentObjectExecReturn("No object linked"); - if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) + } + if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { return new App::DocumentObjectExecReturn("Linked object is not a Part object"); + } const TopoDS_Shape& shape = static_cast(link)->Shape.getShape().getShape(); - if (shape.IsNull()) + if (shape.IsNull()) { return new App::DocumentObjectExecReturn("Linked shape object is empty"); + } try { const Base::Vector3d& dir = Direction.getValue(); @@ -77,26 +82,36 @@ App::DocumentObjectExecReturn *FeatureProjection::execute(void) TopoDS_Compound comp; BRep_Builder builder; builder.MakeCompound(comp); - if (!alg.V.IsNull() && VCompound.getValue()) + if (!alg.V.IsNull() && VCompound.getValue()) { builder.Add(comp, alg.V); - if (!alg.V1.IsNull() && Rg1LineVCompound.getValue()) + } + if (!alg.V1.IsNull() && Rg1LineVCompound.getValue()) { builder.Add(comp, alg.V1); - if (!alg.VN.IsNull() && RgNLineVCompound.getValue()) + } + if (!alg.VN.IsNull() && RgNLineVCompound.getValue()) { builder.Add(comp, alg.VN); - if (!alg.VO.IsNull() && OutLineVCompound.getValue()) + } + if (!alg.VO.IsNull() && OutLineVCompound.getValue()) { builder.Add(comp, alg.VO); - if (!alg.VI.IsNull() && IsoLineVCompound.getValue()) + } + if (!alg.VI.IsNull() && IsoLineVCompound.getValue()) { builder.Add(comp, alg.VI); - if (!alg.H.IsNull() && HCompound.getValue()) + } + if (!alg.H.IsNull() && HCompound.getValue()) { builder.Add(comp, alg.H); - if (!alg.H1.IsNull() && Rg1LineHCompound.getValue()) + } + if (!alg.H1.IsNull() && Rg1LineHCompound.getValue()) { builder.Add(comp, alg.H1); - if (!alg.HN.IsNull() && RgNLineHCompound.getValue()) + } + if (!alg.HN.IsNull() && RgNLineHCompound.getValue()) { builder.Add(comp, alg.HN); - if (!alg.HO.IsNull() && OutLineHCompound.getValue()) + } + if (!alg.HO.IsNull() && OutLineHCompound.getValue()) { builder.Add(comp, alg.HO); - if (!alg.HI.IsNull() && IsoLineHCompound.getValue()) + } + if (!alg.HI.IsNull() && IsoLineHCompound.getValue()) { builder.Add(comp, alg.HI); + } Shape.setValue(comp); return App::DocumentObject::StdReturn; diff --git a/src/Mod/Drawing/App/FeatureProjection.h b/src/Mod/Drawing/App/FeatureProjection.h index afc3645154..acf5a17b50 100644 --- a/src/Mod/Drawing/App/FeatureProjection.h +++ b/src/Mod/Drawing/App/FeatureProjection.h @@ -34,7 +34,7 @@ namespace Drawing /** Base class of all View Features in the drawing module */ -class DrawingExport FeatureProjection : public Part::Feature +class DrawingExport FeatureProjection: public Part::Feature { PROPERTY_HEADER(Drawing::FeatureProjection); @@ -43,28 +43,27 @@ public: FeatureProjection(); virtual ~FeatureProjection(); - App::PropertyLink Source; + App::PropertyLink Source; App::PropertyVector Direction; - App::PropertyBool VCompound; - App::PropertyBool Rg1LineVCompound; - App::PropertyBool RgNLineVCompound; - App::PropertyBool OutLineVCompound; - App::PropertyBool IsoLineVCompound; - App::PropertyBool HCompound; - App::PropertyBool Rg1LineHCompound; - App::PropertyBool RgNLineHCompound; - App::PropertyBool OutLineHCompound; - App::PropertyBool IsoLineHCompound; + App::PropertyBool VCompound; + App::PropertyBool Rg1LineVCompound; + App::PropertyBool RgNLineVCompound; + App::PropertyBool OutLineVCompound; + App::PropertyBool IsoLineVCompound; + App::PropertyBool HCompound; + App::PropertyBool Rg1LineHCompound; + App::PropertyBool RgNLineHCompound; + App::PropertyBool OutLineHCompound; + App::PropertyBool IsoLineHCompound; /** @name methods override feature */ //@{ /// recalculate the Feature - virtual App::DocumentObjectExecReturn *execute(void); + virtual App::DocumentObjectExecReturn* execute(void); //@} }; -} //namespace Drawing +}// namespace Drawing - -#endif // DRAWING_FEATUREPROJECTION +#endif// DRAWING_FEATUREPROJECTION diff --git a/src/Mod/Drawing/App/FeatureView.cpp b/src/Mod/Drawing/App/FeatureView.cpp index a2e691be8d..dc81841caa 100644 --- a/src/Mod/Drawing/App/FeatureView.cpp +++ b/src/Mod/Drawing/App/FeatureView.cpp @@ -22,8 +22,8 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include +#include +#include #endif #include @@ -40,21 +40,34 @@ using namespace Drawing; PROPERTY_SOURCE(Drawing::FeatureView, App::DocumentObject) -FeatureView::FeatureView(void) +FeatureView::FeatureView(void) { static const char* group = "Drawing view"; - ADD_PROPERTY_TYPE(X, (0), group, App::Prop_None, + ADD_PROPERTY_TYPE(X, + (0), + group, + App::Prop_None, "X position of the view on the drawing in modelling units (mm)"); - ADD_PROPERTY_TYPE(Y, (0), group, App::Prop_None, + ADD_PROPERTY_TYPE(Y, + (0), + group, + App::Prop_None, "Y position of the view on the drawing in modelling units (mm)"); ADD_PROPERTY_TYPE(Scale, (1.0), group, App::Prop_None, "Scale factor of the view"); - ADD_PROPERTY_TYPE(Rotation, (0), group, App::Prop_None, + ADD_PROPERTY_TYPE(Rotation, + (0), + group, + App::Prop_None, "Rotation of the view in degrees counterclockwise"); - // The 'Visible' property is handled by the view provider exclusively. It has the 'Output' flag set to - // avoid to call the execute() method. The view provider touches the page object, instead. + // The 'Visible' property is handled by the view provider exclusively. It has the 'Output' flag + // set to avoid to call the execute() method. The view provider touches the page object, + // instead. App::PropertyType propType = static_cast(App::Prop_Hidden | App::Prop_Output); - ADD_PROPERTY_TYPE(Visible, (true), group, propType, + ADD_PROPERTY_TYPE(Visible, + (true), + group, + propType, "Control whether view is visible in page object"); App::PropertyType type = (App::PropertyType)(App::Prop_Hidden); @@ -62,10 +75,9 @@ FeatureView::FeatureView(void) } FeatureView::~FeatureView() -{ -} +{} -App::DocumentObjectExecReturn *FeatureView::recompute(void) +App::DocumentObjectExecReturn* FeatureView::recompute(void) { try { return App::DocumentObject::recompute(); @@ -73,12 +85,14 @@ App::DocumentObjectExecReturn *FeatureView::recompute(void) catch (Standard_Failure& e) { App::DocumentObjectExecReturn* ret = new App::DocumentObjectExecReturn(e.GetMessageString()); - if (ret->Why.empty()) ret->Why = "Unknown OCC exception"; + if (ret->Why.empty()) { + ret->Why = "Unknown OCC exception"; + } return ret; } } -App::DocumentObjectExecReturn *FeatureView::execute(void) +App::DocumentObjectExecReturn* FeatureView::execute(void) { return App::DocumentObject::StdReturn; } @@ -86,14 +100,17 @@ App::DocumentObjectExecReturn *FeatureView::execute(void) // Python Drawing feature --------------------------------------------------------- -namespace App { +namespace App +{ /// @cond DOXERR PROPERTY_SOURCE_TEMPLATE(Drawing::FeatureViewPython, Drawing::FeatureView) -template<> const char* Drawing::FeatureViewPython::getViewProviderName(void) const { +template<> +const char* Drawing::FeatureViewPython::getViewProviderName(void) const +{ return "DrawingGui::ViewProviderDrawingViewPython"; } /// @endcond // explicit template instantiation template class DrawingExport FeaturePythonT; -} +}// namespace App diff --git a/src/Mod/Drawing/App/FeatureView.h b/src/Mod/Drawing/App/FeatureView.h index 58179e5752..36c3244c23 100644 --- a/src/Mod/Drawing/App/FeatureView.h +++ b/src/Mod/Drawing/App/FeatureView.h @@ -34,7 +34,7 @@ namespace Drawing /** Base class of all View Features in the drawing module */ -class DrawingExport FeatureView : public App::DocumentObject +class DrawingExport FeatureView: public App::DocumentObject { PROPERTY_HEADER(Drawing::FeatureView); @@ -43,12 +43,13 @@ public: FeatureView(void); virtual ~FeatureView(); - App::PropertyFloat X,Y,Scale,Rotation; + App::PropertyFloat X, Y, Scale, Rotation; App::PropertyString ViewResult; App::PropertyBool Visible; /// returns the type name of the ViewProvider - virtual const char* getViewProviderName(void) const { + virtual const char* getViewProviderName(void) const + { return "DrawingGui::ViewProviderDrawingView"; } @@ -56,15 +57,14 @@ protected: /** @name methods override Feature */ //@{ /// recalculate the Feature - virtual App::DocumentObjectExecReturn *recompute(void); - virtual App::DocumentObjectExecReturn *execute(void); + virtual App::DocumentObjectExecReturn* recompute(void); + virtual App::DocumentObjectExecReturn* execute(void); //@} }; using FeatureViewPython = App::FeaturePythonT; -} //namespace Drawing - +}// namespace Drawing #endif diff --git a/src/Mod/Drawing/App/FeatureViewAnnotation.cpp b/src/Mod/Drawing/App/FeatureViewAnnotation.cpp index a0e5095465..360a151568 100644 --- a/src/Mod/Drawing/App/FeatureViewAnnotation.cpp +++ b/src/Mod/Drawing/App/FeatureViewAnnotation.cpp @@ -22,8 +22,8 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include +#include +#include #endif #include "FeatureViewAnnotation.h" @@ -39,36 +39,39 @@ using namespace std; PROPERTY_SOURCE(Drawing::FeatureViewAnnotation, Drawing::FeatureView) -FeatureViewAnnotation::FeatureViewAnnotation(void) +FeatureViewAnnotation::FeatureViewAnnotation(void) { - static const char *vgroup = "Drawing view"; + static const char* vgroup = "Drawing view"; - ADD_PROPERTY_TYPE(Text ,(""),vgroup,App::Prop_None,"The text to be displayed"); - ADD_PROPERTY_TYPE(Font ,("Sans"),vgroup,App::Prop_None,"The name of the font to use"); - ADD_PROPERTY_TYPE(TextColor, (0.0f, 0.0f, 0.0f), vgroup, App::Prop_None, + ADD_PROPERTY_TYPE(Text, (""), vgroup, App::Prop_None, "The text to be displayed"); + ADD_PROPERTY_TYPE(Font, ("Sans"), vgroup, App::Prop_None, "The name of the font to use"); + ADD_PROPERTY_TYPE(TextColor, + (0.0f, 0.0f, 0.0f), + vgroup, + App::Prop_None, "The color of the text"); } FeatureViewAnnotation::~FeatureViewAnnotation() -{ -} +{} -App::DocumentObjectExecReturn *FeatureViewAnnotation::execute(void) +App::DocumentObjectExecReturn* FeatureViewAnnotation::execute(void) { - stringstream result,hr,hg,hb; + stringstream result, hr, hg, hb; const App::Color& c = TextColor.getValue(); - hr << hex << setfill('0') << setw(2) << (int)(255.0*c.r); - hg << hex << setfill('0') << setw(2) << (int)(255.0*c.g); - hb << hex << setfill('0') << setw(2) << (int)(255.0*c.b); + hr << hex << setfill('0') << setw(2) << (int)(255.0 * c.r); + hg << hex << setfill('0') << setw(2) << (int)(255.0 * c.g); + hb << hex << setfill('0') << setw(2) << (int)(255.0 * c.b); - result << "" << endl - << "" << endl; + result << "" << endl + << "" << endl; - for (vector::const_iterator it = Text.getValues().begin(); it != Text.getValues().end(); ++it) { + for (vector::const_iterator it = Text.getValues().begin(); it != Text.getValues().end(); + ++it) { result << "" << it->c_str() << "" << endl; } @@ -82,14 +85,17 @@ App::DocumentObjectExecReturn *FeatureViewAnnotation::execute(void) // Python Drawing feature --------------------------------------------------------- -namespace App { +namespace App +{ /// @cond DOXERR PROPERTY_SOURCE_TEMPLATE(Drawing::FeatureViewAnnotationPython, Drawing::FeatureViewAnnotation) -template<> const char* Drawing::FeatureViewAnnotationPython::getViewProviderName(void) const { +template<> +const char* Drawing::FeatureViewAnnotationPython::getViewProviderName(void) const +{ return "DrawingGui::ViewProviderDrawingView"; } /// @endcond // explicit template instantiation template class DrawingExport FeaturePythonT; -} +}// namespace App diff --git a/src/Mod/Drawing/App/FeatureViewAnnotation.h b/src/Mod/Drawing/App/FeatureViewAnnotation.h index f5031fdfee..bc9c6dbca5 100644 --- a/src/Mod/Drawing/App/FeatureViewAnnotation.h +++ b/src/Mod/Drawing/App/FeatureViewAnnotation.h @@ -35,7 +35,7 @@ namespace Drawing /** Base class of all View Features in the drawing module */ -class DrawingExport FeatureViewAnnotation : public FeatureView +class DrawingExport FeatureViewAnnotation: public FeatureView { PROPERTY_HEADER(Drawing::FeatureView); @@ -44,18 +44,19 @@ public: FeatureViewAnnotation(void); virtual ~FeatureViewAnnotation(); - App::PropertyStringList Text; - App::PropertyString Font; - App::PropertyColor TextColor; + App::PropertyStringList Text; + App::PropertyString Font; + App::PropertyColor TextColor; /** @name methods override Feature */ //@{ /// recalculate the Feature - virtual App::DocumentObjectExecReturn *execute(void); + virtual App::DocumentObjectExecReturn* execute(void); //@} /// returns the type name of the ViewProvider - virtual const char* getViewProviderName(void) const { + virtual const char* getViewProviderName(void) const + { return "DrawingGui::ViewProviderDrawingView"; } }; @@ -63,7 +64,7 @@ public: using FeatureViewAnnotationPython = App::FeaturePythonT; -} //namespace Drawing +}// namespace Drawing #endif diff --git a/src/Mod/Drawing/App/FeatureViewPart.cpp b/src/Mod/Drawing/App/FeatureViewPart.cpp index d7ebc33871..0c8d91eb20 100644 --- a/src/Mod/Drawing/App/FeatureViewPart.cpp +++ b/src/Mod/Drawing/App/FeatureViewPart.cpp @@ -22,8 +22,8 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include +#include +#include #endif #include @@ -44,59 +44,88 @@ App::PropertyFloatConstraint::Constraints FeatureViewPart::floatRange = {0.01, 5 PROPERTY_SOURCE(Drawing::FeatureViewPart, Drawing::FeatureView) -FeatureViewPart::FeatureViewPart(void) +FeatureViewPart::FeatureViewPart(void) { - static const char *group = "Shape view"; - static const char *vgroup = "Drawing view"; + static const char* group = "Shape view"; + static const char* vgroup = "Drawing view"; - ADD_PROPERTY_TYPE(Direction ,(0,0,1.0),group,App::Prop_None,"Projection direction"); - ADD_PROPERTY_TYPE(Source ,(nullptr),group,App::Prop_None,"Shape to view"); - ADD_PROPERTY_TYPE(ShowHiddenLines ,(false),group,App::Prop_None,"Control the appearance of the dashed hidden lines"); - ADD_PROPERTY_TYPE(ShowSmoothLines ,(false),group,App::Prop_None,"Control the appearance of the smooth lines"); - ADD_PROPERTY_TYPE(LineWidth,(0.35),vgroup,App::Prop_None,"The thickness of the viewed lines"); - ADD_PROPERTY_TYPE(HiddenWidth,(0.15),vgroup,App::Prop_None,"The thickness of the hidden lines, if enabled"); - ADD_PROPERTY_TYPE(Tolerance,(0.05),vgroup,App::Prop_None,"The tessellation tolerance"); + ADD_PROPERTY_TYPE(Direction, (0, 0, 1.0), group, App::Prop_None, "Projection direction"); + ADD_PROPERTY_TYPE(Source, (nullptr), group, App::Prop_None, "Shape to view"); + ADD_PROPERTY_TYPE(ShowHiddenLines, + (false), + group, + App::Prop_None, + "Control the appearance of the dashed hidden lines"); + ADD_PROPERTY_TYPE(ShowSmoothLines, + (false), + group, + App::Prop_None, + "Control the appearance of the smooth lines"); + ADD_PROPERTY_TYPE(LineWidth, + (0.35), + vgroup, + App::Prop_None, + "The thickness of the viewed lines"); + ADD_PROPERTY_TYPE(HiddenWidth, + (0.15), + vgroup, + App::Prop_None, + "The thickness of the hidden lines, if enabled"); + ADD_PROPERTY_TYPE(Tolerance, (0.05), vgroup, App::Prop_None, "The tessellation tolerance"); Tolerance.setConstraints(&floatRange); } FeatureViewPart::~FeatureViewPart() -{ -} +{} -App::DocumentObjectExecReturn *FeatureViewPart::execute(void) +App::DocumentObjectExecReturn* FeatureViewPart::execute(void) { std::stringstream result; std::string ViewName = Label.getValue(); App::DocumentObject* link = Source.getValue(); - if (!link) + if (!link) { return new App::DocumentObjectExecReturn("No object linked"); - if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) + } + if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { return new App::DocumentObjectExecReturn("Linked object is not a Part object"); + } TopoDS_Shape shape = static_cast(link)->Shape.getShape().getShape(); - if (shape.IsNull()) + if (shape.IsNull()) { return new App::DocumentObjectExecReturn("Linked shape object is empty"); + } Base::Vector3d Dir = Direction.getValue(); bool hidden = ShowHiddenLines.getValue(); bool smooth = ShowSmoothLines.getValue(); try { - ProjectionAlgos Alg(shape,Dir); - result << "" << endl; + ProjectionAlgos Alg(shape, Dir); + result << "" << endl; ProjectionAlgos::ExtractionType type = ProjectionAlgos::Plain; - if (hidden) type = (ProjectionAlgos::ExtractionType)(type|ProjectionAlgos::WithHidden); - if (smooth) type = (ProjectionAlgos::ExtractionType)(type|ProjectionAlgos::WithSmooth); + if (hidden) { + type = (ProjectionAlgos::ExtractionType)(type | ProjectionAlgos::WithHidden); + } + if (smooth) { + type = (ProjectionAlgos::ExtractionType)(type | ProjectionAlgos::WithSmooth); + } ProjectionAlgos::XmlAttributes visible_style = { - {"stroke-width", to_string(this->LineWidth.getValue() / this->Scale.getValue())} - }; + {"stroke-width", to_string(this->LineWidth.getValue() / this->Scale.getValue())}}; ProjectionAlgos::XmlAttributes hidden_style = { - {"stroke-width", to_string(this->HiddenWidth.getValue() / this->Scale.getValue()) } - }; - result << Alg.getSVG(type, this->Tolerance.getValue(), visible_style, visible_style, visible_style, hidden_style, hidden_style, hidden_style); + {"stroke-width", to_string(this->HiddenWidth.getValue() / this->Scale.getValue())}}; + result << Alg.getSVG(type, + this->Tolerance.getValue(), + visible_style, + visible_style, + visible_style, + hidden_style, + hidden_style, + hidden_style); result << "" << endl; @@ -111,17 +140,19 @@ App::DocumentObjectExecReturn *FeatureViewPart::execute(void) } - // Python Drawing feature --------------------------------------------------------- -namespace App { +namespace App +{ /// @cond DOXERR PROPERTY_SOURCE_TEMPLATE(Drawing::FeatureViewPartPython, Drawing::FeatureViewPart) -template<> const char* Drawing::FeatureViewPartPython::getViewProviderName(void) const { +template<> +const char* Drawing::FeatureViewPartPython::getViewProviderName(void) const +{ return "DrawingGui::ViewProviderDrawingView"; } /// @endcond // explicit template instantiation template class DrawingExport FeaturePythonT; -} +}// namespace App diff --git a/src/Mod/Drawing/App/FeatureViewPart.h b/src/Mod/Drawing/App/FeatureViewPart.h index 10ecefa725..91d8d5bb79 100644 --- a/src/Mod/Drawing/App/FeatureViewPart.h +++ b/src/Mod/Drawing/App/FeatureViewPart.h @@ -35,7 +35,7 @@ namespace Drawing /** Base class of all View Features in the drawing module */ -class DrawingExport FeatureViewPart : public FeatureView +class DrawingExport FeatureViewPart: public FeatureView { PROPERTY_HEADER(Part::FeatureViewPart); @@ -44,23 +44,24 @@ public: FeatureViewPart(void); virtual ~FeatureViewPart(); - App::PropertyLink Source; + App::PropertyLink Source; App::PropertyVector Direction; - App::PropertyBool ShowHiddenLines; - App::PropertyBool ShowSmoothLines; - App::PropertyFloat LineWidth; - App::PropertyFloat HiddenWidth; - App::PropertyFloatConstraint Tolerance; + App::PropertyBool ShowHiddenLines; + App::PropertyBool ShowSmoothLines; + App::PropertyFloat LineWidth; + App::PropertyFloat HiddenWidth; + App::PropertyFloatConstraint Tolerance; /** @name methods override Feature */ //@{ /// recalculate the Feature - virtual App::DocumentObjectExecReturn *execute(void); + virtual App::DocumentObjectExecReturn* execute(void); //@} /// returns the type name of the ViewProvider - virtual const char* getViewProviderName(void) const { + virtual const char* getViewProviderName(void) const + { return "DrawingGui::ViewProviderDrawingView"; } @@ -71,7 +72,7 @@ private: using FeatureViewPartPython = App::FeaturePythonT; -} //namespace Drawing +}// namespace Drawing #endif diff --git a/src/Mod/Drawing/App/FeatureViewSpreadsheet.cpp b/src/Mod/Drawing/App/FeatureViewSpreadsheet.cpp index 86b669ee02..718d23adc1 100644 --- a/src/Mod/Drawing/App/FeatureViewSpreadsheet.cpp +++ b/src/Mod/Drawing/App/FeatureViewSpreadsheet.cpp @@ -22,8 +22,8 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include +#include +#include #endif #include @@ -43,53 +43,67 @@ using namespace Drawing; PROPERTY_SOURCE(Drawing::FeatureViewSpreadsheet, Drawing::FeatureView) -FeatureViewSpreadsheet::FeatureViewSpreadsheet(void) +FeatureViewSpreadsheet::FeatureViewSpreadsheet(void) { - static const char *vgroup = "Drawing view"; + static const char* vgroup = "Drawing view"; - ADD_PROPERTY_TYPE(CellStart ,("A1"),vgroup,App::Prop_None,"The top left cell of the range to display"); - ADD_PROPERTY_TYPE(CellEnd ,("B2"),vgroup,App::Prop_None,"The bottom right cell of the range to display"); - ADD_PROPERTY_TYPE(Font ,("Sans"),vgroup,App::Prop_None,"The name of the font to use"); - ADD_PROPERTY_TYPE(Color,(0.0f,0.0f,0.0f),vgroup,App::Prop_None,"The default color of the text and lines"); - ADD_PROPERTY_TYPE(Source ,(nullptr),vgroup,App::Prop_None,"Spreadsheet to view"); - ADD_PROPERTY_TYPE(LineWidth,(0.35),vgroup,App::Prop_None,"The thickness of the cell lines"); - ADD_PROPERTY_TYPE(FontSize,(12.0),vgroup,App::Prop_None,"The size of the text"); + ADD_PROPERTY_TYPE(CellStart, + ("A1"), + vgroup, + App::Prop_None, + "The top left cell of the range to display"); + ADD_PROPERTY_TYPE(CellEnd, + ("B2"), + vgroup, + App::Prop_None, + "The bottom right cell of the range to display"); + ADD_PROPERTY_TYPE(Font, ("Sans"), vgroup, App::Prop_None, "The name of the font to use"); + ADD_PROPERTY_TYPE(Color, + (0.0f, 0.0f, 0.0f), + vgroup, + App::Prop_None, + "The default color of the text and lines"); + ADD_PROPERTY_TYPE(Source, (nullptr), vgroup, App::Prop_None, "Spreadsheet to view"); + ADD_PROPERTY_TYPE(LineWidth, (0.35), vgroup, App::Prop_None, "The thickness of the cell lines"); + ADD_PROPERTY_TYPE(FontSize, (12.0), vgroup, App::Prop_None, "The size of the text"); } FeatureViewSpreadsheet::~FeatureViewSpreadsheet() -{ -} +{} -App::DocumentObjectExecReturn *FeatureViewSpreadsheet::execute(void) +App::DocumentObjectExecReturn* FeatureViewSpreadsheet::execute(void) { // quick tests App::DocumentObject* link = Source.getValue(); std::string scellstart = CellStart.getValue(); std::string scellend = CellEnd.getValue(); - if (!link) + if (!link) { return new App::DocumentObjectExecReturn("No spreadsheet linked"); - if (!link->getTypeId().isDerivedFrom(Spreadsheet::Sheet::getClassTypeId())) + } + if (!link->getTypeId().isDerivedFrom(Spreadsheet::Sheet::getClassTypeId())) { return new App::DocumentObjectExecReturn("The linked object is not a spreadsheet"); - if ( (scellstart.empty()) || (scellend.empty()) ) + } + if ((scellstart.empty()) || (scellend.empty())) { return new App::DocumentObjectExecReturn("Empty cell value"); - + } + // build a list of available columns: A, B, C, ... AA, AB, ... ZY, ZZ. std::string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; std::vector availcolumns; - for (int i=0; i<26; ++i) { + for (int i = 0; i < 26; ++i) { std::stringstream s; s << alphabet[i]; availcolumns.push_back(s.str()); } - for (int i=0; i<26; ++i) { - for (int j=0; i<26; ++i) { + for (int i = 0; i < 26; ++i) { + for (int j = 0; i < 26; ++i) { std::stringstream s; s << alphabet[i] << alphabet[j]; availcolumns.push_back(s.str()); } } - + // build rows range and columns range std::vector columns; std::vector rows; @@ -106,7 +120,8 @@ App::DocumentObjectExecReturn *FeatureViewSpreadsheet::execute(void) std::string endcol = scellend.substr(0, i); bool valid = false; for (std::vector::const_iterator j = availcolumns.begin(); - j != availcolumns.end(); ++j) { + j != availcolumns.end(); + ++j) { if ((*j) == startcol) { if ((*j) != endcol) { valid = true; @@ -130,13 +145,14 @@ App::DocumentObjectExecReturn *FeatureViewSpreadsheet::execute(void) } } } - } catch (std::exception&) { + } + catch (std::exception&) { return new App::DocumentObjectExecReturn("Invalid cell range"); } - + // create the containing group std::string ViewName = Label.getValue(); - std::stringstream result,hr,hg,hb; + std::stringstream result, hr, hg, hb; const App::Color& c = Color.getValue(); hr << std::hex << std::setfill('0') << std::setw(2) << (int)(255.0 * c.r); hg << std::hex << std::setfill('0') << std::setw(2) << (int)(255.0 * c.g); @@ -152,8 +168,8 @@ App::DocumentObjectExecReturn *FeatureViewSpreadsheet::execute(void) float cellheight = 100; float cellwidth = 100; std::string celltext; - Spreadsheet::Sheet* sheet = static_cast(link); - std::vector skiplist; + Spreadsheet::Sheet* sheet = static_cast(link); + std::vector skiplist; for (std::vector::const_iterator col = columns.begin(); col != columns.end(); ++col) { // create a group for each column @@ -170,14 +186,18 @@ App::DocumentObjectExecReturn *FeatureViewSpreadsheet::execute(void) App::Property* prop = sheet->getPropertyByName(address.toString().c_str()); std::stringstream field; if (prop) { - if (prop->isDerivedFrom((App::PropertyQuantity::getClassTypeId()))) + if (prop->isDerivedFrom((App::PropertyQuantity::getClassTypeId()))) { field << static_cast(prop)->getValue(); - else if (prop->isDerivedFrom((App::PropertyFloat::getClassTypeId()))) + } + else if (prop->isDerivedFrom((App::PropertyFloat::getClassTypeId()))) { field << static_cast(prop)->getValue(); - else if (prop->isDerivedFrom((App::PropertyString::getClassTypeId()))) + } + else if (prop->isDerivedFrom((App::PropertyString::getClassTypeId()))) { field << static_cast(prop)->getValue(); - else + } + else { assert(0); + } celltext = field.str(); } // get colors, style, alignment and span @@ -206,24 +226,30 @@ App::DocumentObjectExecReturn *FeatureViewSpreadsheet::execute(void) } if (cell->getStyle(st)) { for (std::set::const_iterator i = st.begin(); i != st.end(); ++i) { - if ((*i) == "bold") + if ((*i) == "bold") { textstyle = textstyle + "font-weight: bold; "; - else if ((*i) == "italic") + } + else if ((*i) == "italic") { textstyle = textstyle + "font-style: italic; "; - else if ((*i) == "underline") + } + else if ((*i) == "underline") { textstyle = textstyle + "text-decoration: underline; "; + } } } if (cell->getSpans(rowspan, colspan)) { for (int i = 0; i < colspan; ++i) { for (int j = 0; j < rowspan; ++j) { App::CellAddress nextcell(address.row() + j, address.col() + i); - if (i > 0) + if (i > 0) { cellwidth = cellwidth + sheet->getColumnWidth(nextcell.col()); - if (j > 0) + } + if (j > 0) { cellheight = cellheight + sheet->getRowHeight(nextcell.row()); - if ((i > 0) || (j > 0)) + } + if ((i > 0) || (j > 0)) { skiplist.push_back(nextcell.toString()); + } } } } @@ -235,18 +261,21 @@ App::DocumentObjectExecReturn *FeatureViewSpreadsheet::execute(void) << cellwidth << "\" height=\"" << cellheight << "\" style=\"fill:" << bcolor << ";stroke-width:" << LineWidth.getValue() / Scale.getValue() << ";stroke:#" << hr.str() << hg.str() << hb.str() << ";\" />" << std::endl; - if (alignment & Spreadsheet::Cell::ALIGNMENT_LEFT) + if (alignment & Spreadsheet::Cell::ALIGNMENT_LEFT) { result << " " << celltext << "" << std::endl; diff --git a/src/Mod/Drawing/App/FeatureViewSpreadsheet.h b/src/Mod/Drawing/App/FeatureViewSpreadsheet.h index 673f18df26..bb9f33b319 100644 --- a/src/Mod/Drawing/App/FeatureViewSpreadsheet.h +++ b/src/Mod/Drawing/App/FeatureViewSpreadsheet.h @@ -34,7 +34,7 @@ namespace Drawing /** Base class of all View Features in the drawing module */ -class DrawingExport FeatureViewSpreadsheet : public FeatureView +class DrawingExport FeatureViewSpreadsheet: public FeatureView { PROPERTY_HEADER(Drawing::FeatureView); @@ -42,27 +42,28 @@ public: /// Constructor FeatureViewSpreadsheet(void); virtual ~FeatureViewSpreadsheet(); - App::PropertyLink Source; - App::PropertyString CellStart; - App::PropertyString CellEnd; - App::PropertyString Font; - App::PropertyColor Color; - App::PropertyFloat LineWidth; - App::PropertyFloat FontSize; + App::PropertyLink Source; + App::PropertyString CellStart; + App::PropertyString CellEnd; + App::PropertyString Font; + App::PropertyColor Color; + App::PropertyFloat LineWidth; + App::PropertyFloat FontSize; /** @name methods override Feature */ //@{ /// recalculate the Feature - virtual App::DocumentObjectExecReturn *execute(void); + virtual App::DocumentObjectExecReturn* execute(void); //@} /// returns the type name of the ViewProvider - virtual const char* getViewProviderName(void) const { + virtual const char* getViewProviderName(void) const + { return "DrawingGui::ViewProviderDrawingView"; } }; -} //namespace Drawing +}// namespace Drawing #endif diff --git a/src/Mod/Drawing/App/FeatureViewSymbol.cpp b/src/Mod/Drawing/App/FeatureViewSymbol.cpp index 65dbf603ad..76c3542580 100644 --- a/src/Mod/Drawing/App/FeatureViewSymbol.cpp +++ b/src/Mod/Drawing/App/FeatureViewSymbol.cpp @@ -22,11 +22,11 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include +#include +#include +#include -# include +#include #endif #include "FeatureViewSymbol.h" @@ -42,18 +42,20 @@ using namespace std; PROPERTY_SOURCE(Drawing::FeatureViewSymbol, Drawing::FeatureView) -FeatureViewSymbol::FeatureViewSymbol(void) +FeatureViewSymbol::FeatureViewSymbol(void) { - static const char *vgroup = "Drawing view"; - - ADD_PROPERTY_TYPE(Symbol,(""),vgroup,App::Prop_Hidden,"The SVG code defining this symbol"); - ADD_PROPERTY_TYPE(EditableTexts,(""),vgroup,App::Prop_None,"Substitution values for the editable strings in this symbol"); + static const char* vgroup = "Drawing view"; + ADD_PROPERTY_TYPE(Symbol, (""), vgroup, App::Prop_Hidden, "The SVG code defining this symbol"); + ADD_PROPERTY_TYPE(EditableTexts, + (""), + vgroup, + App::Prop_None, + "Substitution values for the editable strings in this symbol"); } FeatureViewSymbol::~FeatureViewSymbol() -{ -} +{} /// get called by the container when a Property was changed void FeatureViewSymbol::onChanged(const App::Property* prop) @@ -63,7 +65,7 @@ void FeatureViewSymbol::onChanged(const App::Property* prop) std::vector eds; std::string svg = Symbol.getValue(); if (!svg.empty()) { - boost::regex e ("(.*?)"); + boost::regex e("(.*?)"); std::string::const_iterator tbegin, tend; tbegin = svg.begin(); tend = svg.end(); @@ -79,13 +81,13 @@ void FeatureViewSymbol::onChanged(const App::Property* prop) Drawing::FeatureView::onChanged(prop); } -App::DocumentObjectExecReturn *FeatureViewSymbol::execute(void) +App::DocumentObjectExecReturn* FeatureViewSymbol::execute(void) { std::string svg = Symbol.getValue(); const std::vector& editText = EditableTexts.getValues(); - + if (!editText.empty()) { - boost::regex e1 ("(.*?)"); + boost::regex e1("(.*?)"); string::const_iterator begin, end; begin = svg.begin(); end = svg.end(); @@ -98,9 +100,14 @@ App::DocumentObjectExecReturn *FeatureViewSymbol::execute(void) if (count < editText.size()) { // change values of editable texts. Also strip the "freecad:editable" // attribute so it isn't detected by the page - boost::regex e2 ("((.*?)()"); + boost::regex e2("((.*?)()"); std::back_insert_iterator out(newsvg); - boost::regex_replace(out, begin, what[0].second, e2, "$1$3>"+editText[count]+"$5"); + boost::regex_replace(out, + begin, + what[0].second, + e2, + "$1$3>" + editText[count] + "$5"); } count++; begin = what[0].second; @@ -110,13 +117,13 @@ App::DocumentObjectExecReturn *FeatureViewSymbol::execute(void) newsvg.insert(newsvg.end(), begin, end); svg = newsvg; } - + std::stringstream result; - result << "" << endl - << svg << endl - << "" << endl; + result << "" << endl + << svg << endl + << "" << endl; // Apply the resulting fragment ViewResult.setValue(result.str().c_str()); @@ -126,14 +133,17 @@ App::DocumentObjectExecReturn *FeatureViewSymbol::execute(void) // Python Drawing feature --------------------------------------------------------- -namespace App { +namespace App +{ /// @cond DOXERR PROPERTY_SOURCE_TEMPLATE(Drawing::FeatureViewSymbolPython, Drawing::FeatureViewSymbol) -template<> const char* Drawing::FeatureViewSymbolPython::getViewProviderName(void) const { +template<> +const char* Drawing::FeatureViewSymbolPython::getViewProviderName(void) const +{ return "DrawingGui::ViewProviderDrawingView"; } /// @endcond // explicit template instantiation template class DrawingExport FeaturePythonT; -} +}// namespace App diff --git a/src/Mod/Drawing/App/FeatureViewSymbol.h b/src/Mod/Drawing/App/FeatureViewSymbol.h index 9c1552e8f4..0a5bc9ba85 100644 --- a/src/Mod/Drawing/App/FeatureViewSymbol.h +++ b/src/Mod/Drawing/App/FeatureViewSymbol.h @@ -35,7 +35,7 @@ namespace Drawing /** Base class of all View Features in the drawing module */ -class DrawingExport FeatureViewSymbol : public FeatureView +class DrawingExport FeatureViewSymbol: public FeatureView { PROPERTY_HEADER(Drawing::FeatureView); @@ -44,17 +44,18 @@ public: FeatureViewSymbol(void); virtual ~FeatureViewSymbol(); - App::PropertyString Symbol; - App::PropertyStringList EditableTexts; + App::PropertyString Symbol; + App::PropertyStringList EditableTexts; /** @name methods override Feature */ //@{ /// recalculate the Feature - virtual App::DocumentObjectExecReturn *execute(void); + virtual App::DocumentObjectExecReturn* execute(void); //@} /// returns the type name of the ViewProvider - virtual const char* getViewProviderName(void) const { + virtual const char* getViewProviderName(void) const + { return "DrawingGui::ViewProviderDrawingView"; } @@ -65,7 +66,7 @@ protected: using FeatureViewSymbolPython = App::FeaturePythonT; -} //namespace Drawing +}// namespace Drawing #endif diff --git a/src/Mod/Drawing/App/PageGroup.cpp b/src/Mod/Drawing/App/PageGroup.cpp index f36a740619..7ed22957fb 100644 --- a/src/Mod/Drawing/App/PageGroup.cpp +++ b/src/Mod/Drawing/App/PageGroup.cpp @@ -22,7 +22,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include #endif #include "PageGroup.h" @@ -36,12 +36,11 @@ using namespace Drawing; PROPERTY_SOURCE(Drawing::PageGroup, App::DocumentObjectGroup) -PageGroup::PageGroup(void) +PageGroup::PageGroup(void) { - static const char *group = "Drawings"; - ADD_PROPERTY_TYPE(Pages,(nullptr),group,App::Prop_None,"List of pages"); + static const char* group = "Drawings"; + ADD_PROPERTY_TYPE(Pages, (nullptr), group, App::Prop_None, "List of pages"); } PageGroup::~PageGroup() -{ -} +{} diff --git a/src/Mod/Drawing/App/PageGroup.h b/src/Mod/Drawing/App/PageGroup.h index 3c4d9078a6..5fcb83d487 100644 --- a/src/Mod/Drawing/App/PageGroup.h +++ b/src/Mod/Drawing/App/PageGroup.h @@ -33,7 +33,7 @@ namespace Drawing /** Base class of all View Features in the drawing module */ -class DrawingExport PageGroup : public App::DocumentObjectGroup +class DrawingExport PageGroup: public App::DocumentObjectGroup { PROPERTY_HEADER(Drawing::PageGroup); @@ -45,14 +45,14 @@ public: App::PropertyLinkList Pages; /// returns the type name of the ViewProvider - virtual const char* getViewProviderName(void) const { + virtual const char* getViewProviderName(void) const + { return "DrawingGui::ViewProviderDrawing"; } }; -} //namespace Drawing - +}// namespace Drawing #endif diff --git a/src/Mod/Drawing/App/PreCompiled.cpp b/src/Mod/Drawing/App/PreCompiled.cpp index 3139e21f64..6758517493 100644 --- a/src/Mod/Drawing/App/PreCompiled.cpp +++ b/src/Mod/Drawing/App/PreCompiled.cpp @@ -20,4 +20,4 @@ * * ***************************************************************************/ -#include "PreCompiled.h" +#include "PreCompiled.h" diff --git a/src/Mod/Drawing/App/PreCompiled.h b/src/Mod/Drawing/App/PreCompiled.h index 897ad95b1a..735bdb2463 100644 --- a/src/Mod/Drawing/App/PreCompiled.h +++ b/src/Mod/Drawing/App/PreCompiled.h @@ -32,7 +32,6 @@ #include #include #include -#include #include // boost @@ -40,26 +39,20 @@ // OpenCasCade #include -#include -#include #include #include #include -#include #include -#include -#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include #include #include -#include #include #include #include @@ -69,9 +62,15 @@ #include #include #include +#include +#include +#include +#include +#include +#include #if OCC_VERSION_HEX < 0x070600 -# include +#include #endif -#endif // _PreComp_ +#endif// _PreComp_ #endif diff --git a/src/Mod/Drawing/App/ProjectionAlgos.cpp b/src/Mod/Drawing/App/ProjectionAlgos.cpp index 5fd5ede54e..529cff254a 100644 --- a/src/Mod/Drawing/App/ProjectionAlgos.cpp +++ b/src/Mod/Drawing/App/ProjectionAlgos.cpp @@ -22,25 +22,25 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif #include -#include "ProjectionAlgos.h" #include "DrawingExport.h" +#include "ProjectionAlgos.h" using namespace Drawing; @@ -51,60 +51,61 @@ using namespace std; //=========================================================================== -ProjectionAlgos::ProjectionAlgos(const TopoDS_Shape &Input, const Base::Vector3d &Dir) - : Input(Input), Direction(Dir) +ProjectionAlgos::ProjectionAlgos(const TopoDS_Shape& Input, const Base::Vector3d& Dir) + : Input(Input) + , Direction(Dir) { execute(); } ProjectionAlgos::~ProjectionAlgos() -{ -} +{} -//added by tanderson. aka blobfish. -//projection algorithms build a 2d curve(pcurve) but no 3d curve. -//this causes problems with meshing algorithms after save and load. -static const TopoDS_Shape& build3dCurves(const TopoDS_Shape &shape) +// added by tanderson. aka blobfish. +// projection algorithms build a 2d curve(pcurve) but no 3d curve. +// this causes problems with meshing algorithms after save and load. +static const TopoDS_Shape& build3dCurves(const TopoDS_Shape& shape) { - TopExp_Explorer it; - for (it.Init(shape, TopAbs_EDGE); it.More(); it.Next()) - BRepLib::BuildCurve3d(TopoDS::Edge(it.Current())); - return shape; + TopExp_Explorer it; + for (it.Init(shape, TopAbs_EDGE); it.More(); it.Next()) { + BRepLib::BuildCurve3d(TopoDS::Edge(it.Current())); + } + return shape; } void ProjectionAlgos::execute(void) { - Handle( HLRBRep_Algo ) brep_hlr = new HLRBRep_Algo; + Handle(HLRBRep_Algo) brep_hlr = new HLRBRep_Algo; brep_hlr->Add(Input); - gp_Ax2 transform(gp_Pnt(0,0,0),gp_Dir(Direction.x,Direction.y,Direction.z)); - HLRAlgo_Projector projector( transform ); + gp_Ax2 transform(gp_Pnt(0, 0, 0), gp_Dir(Direction.x, Direction.y, Direction.z)); + HLRAlgo_Projector projector(transform); brep_hlr->Projector(projector); brep_hlr->Update(); brep_hlr->Hide(); // extracting the result sets: - HLRBRep_HLRToShape shapes( brep_hlr ); + HLRBRep_HLRToShape shapes(brep_hlr); - V = build3dCurves(shapes.VCompound ());// hard edge visibly + V = build3dCurves(shapes.VCompound()); // hard edge visibly V1 = build3dCurves(shapes.Rg1LineVCompound());// Smoth edges visibly VN = build3dCurves(shapes.RgNLineVCompound());// contour edges visibly VO = build3dCurves(shapes.OutLineVCompound());// contours apparents visibly VI = build3dCurves(shapes.IsoLineVCompound());// isoparamtriques visibly - H = build3dCurves(shapes.HCompound ());// hard edge invisibly + H = build3dCurves(shapes.HCompound()); // hard edge invisibly H1 = build3dCurves(shapes.Rg1LineHCompound());// Smoth edges invisibly HN = build3dCurves(shapes.RgNLineHCompound());// contour edges invisibly HO = build3dCurves(shapes.OutLineHCompound());// contours apparents invisibly HI = build3dCurves(shapes.IsoLineHCompound());// isoparamtriques invisibly } -string ProjectionAlgos::getSVG(ExtractionType type, - double tolerance, - XmlAttributes V_style, - XmlAttributes V0_style, - XmlAttributes V1_style, - XmlAttributes H_style, - XmlAttributes H0_style, +string ProjectionAlgos::getSVG(ExtractionType type, + double tolerance, + XmlAttributes V_style, + XmlAttributes V0_style, + XmlAttributes V1_style, + XmlAttributes H_style, + XmlAttributes H0_style, XmlAttributes H1_style) { stringstream result; @@ -118,14 +119,12 @@ string ProjectionAlgos::getSVG(ExtractionType type, H_style.insert({"stroke-dasharray", "0.2,0.1)"}); H_style.insert({"fill", "none"}); H_style.insert({"transform", "scale(1,-1)"}); - BRepMesh_IncrementalMesh(H,tolerance); - result << "" << endl - << output.exportEdges(H) - << "" << endl; + BRepMesh_IncrementalMesh(H, tolerance); + result << "" << endl << output.exportEdges(H) << "" << endl; } if (!HO.IsNull() && (type & WithHidden)) { H0_style.insert({"stroke", "rgb(0, 0, 0)"}); @@ -135,14 +134,12 @@ string ProjectionAlgos::getSVG(ExtractionType type, H0_style.insert({"stroke-dasharray", "0.02,0.1)"}); H0_style.insert({"fill", "none"}); H0_style.insert({"transform", "scale(1,-1)"}); - BRepMesh_IncrementalMesh(HO,tolerance); - result << "" << endl - << output.exportEdges(HO) - << "" << endl; + BRepMesh_IncrementalMesh(HO, tolerance); + result << "" << endl << output.exportEdges(HO) << "" << endl; } if (!VO.IsNull()) { V0_style.insert({"stroke", "rgb(0, 0, 0)"}); @@ -151,14 +148,12 @@ string ProjectionAlgos::getSVG(ExtractionType type, V0_style.insert({"stroke-linejoin", "miter"}); V0_style.insert({"fill", "none"}); V0_style.insert({"transform", "scale(1,-1)"}); - BRepMesh_IncrementalMesh(VO,tolerance); - result << "" << endl - << output.exportEdges(VO) - << "" << endl; + BRepMesh_IncrementalMesh(VO, tolerance); + result << "" << endl << output.exportEdges(VO) << "" << endl; } if (!V.IsNull()) { V_style.insert({"stroke", "rgb(0, 0, 0)"}); @@ -167,14 +162,12 @@ string ProjectionAlgos::getSVG(ExtractionType type, V_style.insert({"stroke-linejoin", "miter"}); V_style.insert({"fill", "none"}); V_style.insert({"transform", "scale(1,-1)"}); - BRepMesh_IncrementalMesh(V,tolerance); - result << "" << endl - << output.exportEdges(V) - << "" << endl; + BRepMesh_IncrementalMesh(V, tolerance); + result << "" << endl << output.exportEdges(V) << "" << endl; } if (!V1.IsNull() && (type & WithSmooth)) { V1_style.insert({"stroke", "rgb(0, 0, 0)"}); @@ -183,14 +176,12 @@ string ProjectionAlgos::getSVG(ExtractionType type, V1_style.insert({"stroke-linejoin", "miter"}); V1_style.insert({"fill", "none"}); V1_style.insert({"transform", "scale(1,-1)"}); - BRepMesh_IncrementalMesh(V1,tolerance); - result << "" << endl - << output.exportEdges(V1) - << "" << endl; + BRepMesh_IncrementalMesh(V1, tolerance); + result << "" << endl << output.exportEdges(V1) << "" << endl; } if (!H1.IsNull() && (type & WithSmooth) && (type & WithHidden)) { H1_style.insert({"stroke", "rgb(0, 0, 0)"}); @@ -200,14 +191,12 @@ string ProjectionAlgos::getSVG(ExtractionType type, H1_style.insert({"stroke-dasharray", "0.09,0.05)"}); H1_style.insert({"fill", "none"}); H1_style.insert({"transform", "scale(1,-1)"}); - BRepMesh_IncrementalMesh(H1,tolerance); - result << "" << endl - << output.exportEdges(H1) - << "" << endl; + BRepMesh_IncrementalMesh(H1, tolerance); + result << "" << endl << output.exportEdges(H1) << "" << endl; } return result.str(); } @@ -220,34 +209,34 @@ string ProjectionAlgos::getDXF(ExtractionType type, double /*scale*/, double tol DXFOutput output; if (!H.IsNull() && (type & WithHidden)) { - //float width = 0.15f/scale; - BRepMesh_IncrementalMesh(H,tolerance); - result << output.exportEdges(H); + // float width = 0.15f/scale; + BRepMesh_IncrementalMesh(H, tolerance); + result << output.exportEdges(H); } if (!HO.IsNull() && (type & WithHidden)) { - //float width = 0.15f/scale; - BRepMesh_IncrementalMesh(HO,tolerance); - result << output.exportEdges(HO); + // float width = 0.15f/scale; + BRepMesh_IncrementalMesh(HO, tolerance); + result << output.exportEdges(HO); } if (!VO.IsNull()) { - //float width = 0.35f/scale; - BRepMesh_IncrementalMesh(VO,tolerance); - result << output.exportEdges(VO); + // float width = 0.35f/scale; + BRepMesh_IncrementalMesh(VO, tolerance); + result << output.exportEdges(VO); } if (!V.IsNull()) { - //float width = 0.35f/scale; - BRepMesh_IncrementalMesh(V,tolerance); - result << output.exportEdges(V); + // float width = 0.35f/scale; + BRepMesh_IncrementalMesh(V, tolerance); + result << output.exportEdges(V); } if (!V1.IsNull() && (type & WithSmooth)) { - //float width = 0.35f/scale; - BRepMesh_IncrementalMesh(V1,tolerance); - result << output.exportEdges(V1); + // float width = 0.35f/scale; + BRepMesh_IncrementalMesh(V1, tolerance); + result << output.exportEdges(V1); } if (!H1.IsNull() && (type & WithSmooth) && (type & WithHidden)) { - //float width = 0.15f/scale; - BRepMesh_IncrementalMesh(H1,tolerance); - result << output.exportEdges(H1); + // float width = 0.15f/scale; + BRepMesh_IncrementalMesh(H1, tolerance); + result << output.exportEdges(H1); } return result.str(); diff --git a/src/Mod/Drawing/App/ProjectionAlgos.h b/src/Mod/Drawing/App/ProjectionAlgos.h index bd0a6ef106..0f5deed905 100644 --- a/src/Mod/Drawing/App/ProjectionAlgos.h +++ b/src/Mod/Drawing/App/ProjectionAlgos.h @@ -23,8 +23,8 @@ #ifndef _ProjectionAlgos_h_ #define _ProjectionAlgos_h_ -#include #include +#include #include #include @@ -41,44 +41,47 @@ class DrawingExport ProjectionAlgos { public: /// Constructor - ProjectionAlgos(const TopoDS_Shape &Input,const Base::Vector3d &Dir); + ProjectionAlgos(const TopoDS_Shape& Input, const Base::Vector3d& Dir); virtual ~ProjectionAlgos(); void execute(void); - enum ExtractionType { + enum ExtractionType + { Plain = 0, WithHidden = 1, WithSmooth = 2 }; - using XmlAttributes = std::map; + using XmlAttributes = std::map; - std::string getSVG(ExtractionType type, double tolerance=0.05, - XmlAttributes V_style=XmlAttributes(), - XmlAttributes V0_style=XmlAttributes(), - XmlAttributes V1_style=XmlAttributes(), - XmlAttributes H_style=XmlAttributes(), - XmlAttributes H0_style=XmlAttributes(), - XmlAttributes H1_style=XmlAttributes()); - std::string getDXF(ExtractionType type, double scale, double tolerance);//added by Dan Falck 2011/09/25 + std::string getSVG(ExtractionType type, + double tolerance = 0.05, + XmlAttributes V_style = XmlAttributes(), + XmlAttributes V0_style = XmlAttributes(), + XmlAttributes V1_style = XmlAttributes(), + XmlAttributes H_style = XmlAttributes(), + XmlAttributes H0_style = XmlAttributes(), + XmlAttributes H1_style = XmlAttributes()); + std::string + getDXF(ExtractionType type, double scale, double tolerance);// added by Dan Falck 2011/09/25 - const TopoDS_Shape &Input; - const Base::Vector3d &Direction; + const TopoDS_Shape& Input; + const Base::Vector3d& Direction; - TopoDS_Shape V ;// hard edge visibly + TopoDS_Shape V; // hard edge visibly TopoDS_Shape V1;// Smoth edges visibly TopoDS_Shape VN;// contour edges visibly TopoDS_Shape VO;// contours apparents visibly TopoDS_Shape VI;// isoparamtriques visibly - TopoDS_Shape H ;// hard edge invisibly + TopoDS_Shape H; // hard edge invisibly TopoDS_Shape H1;// Smoth edges invisibly TopoDS_Shape HN;// contour edges invisibly TopoDS_Shape HO;// contours apparents invisibly TopoDS_Shape HI;// isoparamtriques invisibly }; -} //namespace Drawing +}// namespace Drawing #endif diff --git a/src/Mod/Drawing/CMakeLists.txt b/src/Mod/Drawing/CMakeLists.txt index b5d8d4cccc..61a537f62a 100644 --- a/src/Mod/Drawing/CMakeLists.txt +++ b/src/Mod/Drawing/CMakeLists.txt @@ -63,7 +63,7 @@ INSTALL( Templates DESTINATION ${CMAKE_INSTALL_DATADIR}/Mod/Drawing - FILES_MATCHING + FILES_MATCHING PATTERN "*.svg*" PATTERN "*.dxf*" ) diff --git a/src/Mod/Drawing/DrawingExample.py b/src/Mod/Drawing/DrawingExample.py index e04e1f4f30..c7e5229a03 100644 --- a/src/Mod/Drawing/DrawingExample.py +++ b/src/Mod/Drawing/DrawingExample.py @@ -1,62 +1,83 @@ # example how to use the scripting API of the drawing module -# +# # first of all you need the Part and the Drawing module: import FreeCAD, Part, Drawing # create a small sample part -Part.show(Part.makeBox(100,100,100).cut(Part.makeCylinder(80,100)).cut(Part.makeBox(90,40,100)).cut(Part.makeBox(20,85,100))) +Part.show( + Part.makeBox(100, 100, 100) + .cut(Part.makeCylinder(80, 100)) + .cut(Part.makeBox(90, 40, 100)) + .cut(Part.makeBox(20, 85, 100)) +) # direct projection. The G0 means hard edge, the G1 is tangend continues. Shape = App.ActiveDocument.Shape.Shape -[visiblyG0,visiblyG1,hiddenG0,hiddenG1] = Drawing.project(Shape) +[visiblyG0, visiblyG1, hiddenG0, hiddenG1] = Drawing.project(Shape) print("visible edges:", len(visiblyG0.Edges)) print("hidden edges:", len(hiddenG0.Edges)) # all was projected on the Z-plane: -print("Bnd Box shape: X=",Shape.BoundBox.XLength," Y=",Shape.BoundBox.YLength," Z=",Shape.BoundBox.ZLength) -print("Bnd Box project: X=",visiblyG0.BoundBox.XLength," Y=",visiblyG0.BoundBox.YLength," Z=",visiblyG0.BoundBox.ZLength) +print( + "Bnd Box shape: X=", + Shape.BoundBox.XLength, + " Y=", + Shape.BoundBox.YLength, + " Z=", + Shape.BoundBox.ZLength, +) +print( + "Bnd Box project: X=", + visiblyG0.BoundBox.XLength, + " Y=", + visiblyG0.BoundBox.YLength, + " Z=", + visiblyG0.BoundBox.ZLength, +) # different projection vector -[visiblyG0,visiblyG1,hiddenG0,hiddenG1] = Drawing.project(Shape,Base.Vector(1,1,1)) +[visiblyG0, visiblyG1, hiddenG0, hiddenG1] = Drawing.project(Shape, Base.Vector(1, 1, 1)) # project to SVG -resultSVG = Drawing.projectToSVG(Shape,App.Vector(1,1,1)) +resultSVG = Drawing.projectToSVG(Shape, App.Vector(1, 1, 1)) print(resultSVG) # And now the parametric way -# +# # insert a Page object and assign a template -App.activeDocument().addObject('Drawing::FeaturePage','Page') -App.activeDocument().Page.Template = App.ConfigGet('AppHomePath')+'Mod/Drawing/Templates/A3_Landscape.svg' +App.activeDocument().addObject("Drawing::FeaturePage", "Page") +App.activeDocument().Page.Template = ( + App.ConfigGet("AppHomePath") + "Mod/Drawing/Templates/A3_Landscape.svg" +) # create a view on the "Shape" object, define the position and scale and assign it to a Page -App.activeDocument().addObject('Drawing::FeatureViewPart','View') +App.activeDocument().addObject("Drawing::FeatureViewPart", "View") App.activeDocument().View.Source = App.activeDocument().Shape -App.activeDocument().View.Direction = (0.0,0.0,1.0) +App.activeDocument().View.Direction = (0.0, 0.0, 1.0) App.activeDocument().View.X = 10.0 App.activeDocument().View.Y = 10.0 App.activeDocument().Page.addObject(App.activeDocument().View) -# create a second view on the same object but the view is +# create a second view on the same object but the view is # rotatet 90 degrees. -App.activeDocument().addObject('Drawing::FeatureViewPart','ViewRot') +App.activeDocument().addObject("Drawing::FeatureViewPart", "ViewRot") App.activeDocument().ViewRot.Source = App.activeDocument().Shape -App.activeDocument().ViewRot.Direction = (0.0,0.0,1.0) +App.activeDocument().ViewRot.Direction = (0.0, 0.0, 1.0) App.activeDocument().ViewRot.X = 290.0 App.activeDocument().ViewRot.Y = 30.0 App.activeDocument().ViewRot.Scale = 1.0 App.activeDocument().ViewRot.Rotation = 90.0 -App.activeDocument().Page.addObject(App.activeDocument().ViewRot) +App.activeDocument().Page.addObject(App.activeDocument().ViewRot) # create a third view on the same object but with an isometric # view direction. Also the hidden lines are activated. -App.activeDocument().addObject('Drawing::FeatureViewPart','ViewIso') +App.activeDocument().addObject("Drawing::FeatureViewPart", "ViewIso") App.activeDocument().ViewIso.Source = App.activeDocument().Shape -App.activeDocument().ViewIso.Direction = (1.0,1.0,1.0) +App.activeDocument().ViewIso.Direction = (1.0, 1.0, 1.0) App.activeDocument().ViewIso.X = 335.0 App.activeDocument().ViewIso.Y = 140.0 App.activeDocument().ViewIso.ShowHiddenLines = True -App.activeDocument().Page.addObject(App.activeDocument().ViewIso) +App.activeDocument().Page.addObject(App.activeDocument().ViewIso) # change something and update. # The update process change the view and the page @@ -71,14 +92,14 @@ ViewSVG = App.activeDocument().View.ViewResult print(ViewSVG) # get the hole result page (its a file in the document temp dir, only read allowed) -print("Resulting SVG document: ",App.activeDocument().Page.PageResult) -file = open(App.activeDocument().Page.PageResult,"r") -print("Result page is ",len(file.readlines())," lines long") +print("Resulting SVG document: ", App.activeDocument().Page.PageResult) +file = open(App.activeDocument().Page.PageResult, "r") +print("Result page is ", len(file.readlines()), " lines long") # important, give free the file! del file # insert a view with your own content: -App.activeDocument().addObject('Drawing::FeatureView','ViewSelf') +App.activeDocument().addObject("Drawing::FeatureView", "ViewSelf") App.activeDocument().ViewSelf.ViewResult = """ fragment from a name and path data""" - - name,scale,thickness = decodeName(name,scale,thickness) + + name, scale, thickness = decodeName(name, scale, thickness) if not (name in Patterns): return None - pname = name + "_" + str(scale).replace(".","") + "_" + str(thickness).replace(".","") + pname = name + "_" + str(scale).replace(".", "") + "_" + str(thickness).replace(".", "") data = Patterns[name] - template=''' - ''' - t = template.replace("$name",pname) - t = t.replace("$scale",str(scale)) - t = t.replace("$thickness",str(thickness)) - t = t.replace("$color",color) - t = t.replace("$path",data) - t = t.replace("\n","") + """ + t = template.replace("$name", pname) + t = t.replace("$scale", str(scale)) + t = t.replace("$thickness", str(thickness)) + t = t.replace("$color", color) + t = t.replace("$path", data) + t = t.replace("\n", "") return t -def buildTextureImage(name,scale=5,thickness=1,color="#000000",size=64): - +def buildTextureImage(name, scale=5, thickness=1, color="#000000", size=64): + """buildTextureImage(name,scale,thickness,color="#000000",size=64) builds a 64x64 SVG image filled with the given texture""" - - name,scale,thickness = decodeName(name,scale,thickness) + + name, scale, thickness = decodeName(name, scale, thickness) if not (name in Patterns): return None s = str(size) - template = '''$pattern''' - pat = buildPattern(name,scale,thickness,color) - t = template.replace("\n","") - t = t.replace("$pattern",pat+"\n") - t = t.replace("$name",name+"_"+str(scale).replace(".","")+"_"+str(thickness).replace(".","")) + template = ( + '''$pattern""" + ) + pat = buildPattern(name, scale, thickness, color) + t = template.replace("\n", "") + t = t.replace("$pattern", pat + "\n") + t = t.replace( + "$name", name + "_" + str(scale).replace(".", "") + "_" + str(thickness).replace(".", "") + ) return t -def buildSwatch(name,scale=5,thickness=1,color="#000000",size=64): - +def buildSwatch(name, scale=5, thickness=1, color="#000000", size=64): + """buildSwatch(name,scale,thickness,color="#000000",size=64) builds a 64x64 SVG image filled with the given texture, a white background and a border, to serve as a sample""" - - name,scale,thickness = decodeName(name,scale,thickness) + + name, scale, thickness = decodeName(name, scale, thickness) if not (name in Patterns): return None s = str(size) - template = '''$pattern''' - pat = buildPattern(name,scale,thickness,color) - t = template.replace("\n","") - t = t.replace("$pattern",pat+"\n") - t = t.replace("$name",name+"_"+str(scale).replace(".","")+"_"+str(thickness).replace(".","")) + template = ( + '''$pattern""" + ) + pat = buildPattern(name, scale, thickness, color) + t = template.replace("\n", "") + t = t.replace("$pattern", pat + "\n") + t = t.replace( + "$name", name + "_" + str(scale).replace(".", "") + "_" + str(thickness).replace(".", "") + ) return t -def buildFileSwatch(name,scale=5,thickness=1,color="#000000",size=64,png=False): +def buildFileSwatch(name, scale=5, thickness=1, color="#000000", size=64, png=False): """buildFileSwatch(name,scale,thickness,color="#000000",size=64,png=False) builds a 64x64 SVG image filled with the given texture, a white background and a border, to serve as a sample. The image is saved as a temp file, the filepath is returned""" - s = buildSwatch(name,scale,thickness,color,size) + s = buildSwatch(name, scale, thickness, color, size) if s: import tempfile + tf = tempfile.mkstemp(suffix=".svg")[1] - f = open(tf,"wb") + f = open(tf, "wb") f.write(s) f.close() if png: # we use imagemagick's convert because Qt4 doesn't support SVG patterns... import os + if os.system("convert -version") == 0: - ptf = os.path.splitext(tf)[0]+".png" - os.system('convert "'+tf+'" "'+ptf+'"') + ptf = os.path.splitext(tf)[0] + ".png" + os.system('convert "' + tf + '" "' + ptf + '"') return ptf else: return tf return None -def saveTestImage(filename,scales=[2.5,5],thicknesses=[0.1,0.2,1]): - +def saveTestImage(filename, scales=[2.5, 5], thicknesses=[0.1, 0.2, 1]): + """saveTestImage(filename,scales=[2.5,5],thicknesses=[0.1,0.2,1]) builds a test SVG file showing all available patterns at given scales and thicknesses""" - + maxcols = 6 row = 0 col = 0 - pats = '\n' - cont = '\n' - template = '''$patterns$content''' + pats = "\n" + cont = "\n" + template = """$patterns$content""" for name in Patterns.keys(): for thickness in thicknesses: for scale in scales: - pats += buildPattern(name,scale,thickness) - pats += '\n' - subtemplate='''''' - st = subtemplate.replace("$xpos",str(64*col + 8*col + 8)) - st = st.replace("$ypos",str(64*row + 8*row + 8)) - st = st.replace("$pattern",name+"_"+str(scale)+"_"+str(thickness)) - st = st.replace("\n","") + pats += buildPattern(name, scale, thickness) + pats += "\n" + subtemplate = """""" + st = subtemplate.replace("$xpos", str(64 * col + 8 * col + 8)) + st = st.replace("$ypos", str(64 * row + 8 * row + 8)) + st = st.replace("$pattern", name + "_" + str(scale) + "_" + str(thickness)) + st = st.replace("\n", "") cont += st - cont += '\n' - if col == maxcols-1: + cont += "\n" + if col == maxcols - 1: col = 0 row += 1 else: col += 1 - t = template.replace("\n","") - t = t.replace("$patterns",pats) - t = t.replace("$content",cont) - t = t.replace("$width",str(8+maxcols*72)) - t = t.replace("$height",str(80+row*72)) - f = open(filename,"wb") + t = template.replace("\n", "") + t = t.replace("$patterns", pats) + t = t.replace("$content", cont) + t = t.replace("$width", str(8 + maxcols * 72)) + t = t.replace("$height", str(80 + row * 72)) + f = open(filename, "wb") f.write(t) f.close() - - -def decodeName(name,scale,thickness): - + + +def decodeName(name, scale, thickness): + """decodeName(name,scale,thickness) : decodes names written in the form 'name_5_1'""" - + name = name.split("_") if len(name) > 1: try: @@ -279,11 +310,11 @@ def decodeName(name,scale,thickness): thickness = float(name[2]) except Exception: pass - return name[0],scale,thickness + return name[0], scale, thickness def getPatternNames(): - + """getPatternNames : returns available pattern names""" - + return Patterns.keys() diff --git a/src/Mod/Drawing/DrawingTests.py b/src/Mod/Drawing/DrawingTests.py index 458a8bcd17..261d20e965 100644 --- a/src/Mod/Drawing/DrawingTests.py +++ b/src/Mod/Drawing/DrawingTests.py @@ -1,35 +1,38 @@ import Part, Drawing + Part.open("D:/_Projekte/FreeCAD/FreeCADData/Schenkel.stp") -App.activeDocument().addObject('Drawing::FeaturePage','Page') -App.activeDocument().Page.Template = 'D:/_Projekte/FreeCAD/FreeCAD_0.9_LibPack7/Mod/Drawing/Templates/A3_Landscape.svg' -App.activeDocument().addObject('Drawing::FeatureViewPart','View') +App.activeDocument().addObject("Drawing::FeaturePage", "Page") +App.activeDocument().Page.Template = ( + "D:/_Projekte/FreeCAD/FreeCAD_0.9_LibPack7/Mod/Drawing/Templates/A3_Landscape.svg" +) +App.activeDocument().addObject("Drawing::FeatureViewPart", "View") App.activeDocument().View.Source = App.activeDocument().Schenkel -App.activeDocument().View.Direction = (0.0,1.0,0.0) +App.activeDocument().View.Direction = (0.0, 1.0, 0.0) App.activeDocument().View.X = 30.0 App.activeDocument().View.Y = 30.0 App.activeDocument().View.Scale = 1.0 App.activeDocument().Page.addObject(App.activeDocument().View) -App.activeDocument().addObject('Drawing::FeatureViewPart','View1') +App.activeDocument().addObject("Drawing::FeatureViewPart", "View1") App.activeDocument().View1.Source = App.activeDocument().Schenkel -App.activeDocument().View1.Direction = (0.0,0.0,1.0) +App.activeDocument().View1.Direction = (0.0, 0.0, 1.0) App.activeDocument().View1.X = 70.0 App.activeDocument().View1.Y = 30.0 App.activeDocument().View1.Scale = 1.0 App.activeDocument().Page.addObject(App.activeDocument().View1) -App.activeDocument().addObject('Drawing::FeatureViewPart','View2') +App.activeDocument().addObject("Drawing::FeatureViewPart", "View2") App.activeDocument().View2.Source = App.activeDocument().Schenkel -App.activeDocument().View2.Direction = (1.0,0.0,0.0) +App.activeDocument().View2.Direction = (1.0, 0.0, 0.0) App.activeDocument().View2.X = 70.0 App.activeDocument().View2.Y = 200.0 App.activeDocument().View2.Rotation = 90.0 App.activeDocument().View2.Scale = 1.0 App.activeDocument().Page.addObject(App.activeDocument().View2) -App.activeDocument().addObject('Drawing::FeatureViewPart','View3') +App.activeDocument().addObject("Drawing::FeatureViewPart", "View3") App.activeDocument().View3.Source = App.activeDocument().Schenkel -App.activeDocument().View3.Direction = (1.0,1.0,1.0) +App.activeDocument().View3.Direction = (1.0, 1.0, 1.0) App.activeDocument().View3.X = 280.0 App.activeDocument().View3.Y = 90.0 App.activeDocument().View3.Scale = 1.0 diff --git a/src/Mod/Drawing/Gui/AppDrawingGui.cpp b/src/Mod/Drawing/Gui/AppDrawingGui.cpp index db634f5d26..ce4f17fe8f 100644 --- a/src/Mod/Drawing/Gui/AppDrawingGui.cpp +++ b/src/Mod/Drawing/Gui/AppDrawingGui.cpp @@ -27,9 +27,9 @@ #include #include -#include "Workbench.h" #include "ViewProviderPage.h" #include "ViewProviderView.h" +#include "Workbench.h" // use a different name to CreateCommand() @@ -43,7 +43,8 @@ void loadDrawingResource() Gui::Translator::instance()->refresh(); } -namespace DrawingGui { +namespace DrawingGui +{ extern PyObject* initModule(); } diff --git a/src/Mod/Drawing/Gui/AppDrawingGuiPy.cpp b/src/Mod/Drawing/Gui/AppDrawingGuiPy.cpp index e8bee5f466..f0d2db8925 100644 --- a/src/Mod/Drawing/Gui/AppDrawingGuiPy.cpp +++ b/src/Mod/Drawing/Gui/AppDrawingGuiPy.cpp @@ -22,9 +22,9 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include -# include +#include #endif #include @@ -42,41 +42,42 @@ #include "DrawingView.h" -namespace DrawingGui { -class Module : public Py::ExtensionModule +namespace DrawingGui +{ +class Module: public Py::ExtensionModule { public: - Module() : Py::ExtensionModule("DrawingGui") + Module() + : Py::ExtensionModule("DrawingGui") { - add_varargs_method("open",&Module::open - ); - add_varargs_method("insert",&Module::importer - ); - add_varargs_method("export",&Module::exporter - ); - initialize("This module is the DrawingGui module."); // register with Python + add_varargs_method("open", &Module::open); + add_varargs_method("insert", &Module::importer); + add_varargs_method("export", &Module::exporter); + initialize("This module is the DrawingGui module.");// register with Python } - virtual ~Module() {} + virtual ~Module() + {} private: - virtual Py::Object invoke_method_varargs(void *method_def, const Py::Tuple &args) + virtual Py::Object invoke_method_varargs(void* method_def, const Py::Tuple& args) { try { return Py::ExtensionModule::invoke_method_varargs(method_def, args); } - catch (const Base::Exception &e) { + catch (const Base::Exception& e) { throw Py::RuntimeError(e.what()); } - catch (const std::exception &e) { + catch (const std::exception& e) { throw Py::RuntimeError(e.what()); } } Py::Object open(const Py::Tuple& args) { char* Name; - if (!PyArg_ParseTuple(args.ptr(), "et","utf-8",&Name)) + if (!PyArg_ParseTuple(args.ptr(), "et", "utf-8", &Name)) { throw Py::Exception(); + } std::string EncodedName = std::string(Name); PyMem_Free(Name); @@ -90,7 +91,7 @@ private: view->setWindowIcon(Gui::BitmapFactory().pixmap("actions/drawing-landscape")); QFileInfo fi(fileName); view->setWindowTitle(fi.fileName()); - view->resize( 400, 300 ); + view->resize(400, 300); Gui::getMainWindow()->addWindow(view); } else { @@ -103,8 +104,9 @@ private: { char* Name; const char* dummy; - if (!PyArg_ParseTuple(args.ptr(), "et|s","utf-8",&Name,&dummy)) + if (!PyArg_ParseTuple(args.ptr(), "et|s", "utf-8", &Name, &dummy)) { throw Py::Exception(); + } std::string EncodedName = std::string(Name); PyMem_Free(Name); @@ -118,9 +120,10 @@ private: view->setWindowIcon(Gui::BitmapFactory().pixmap("actions/drawing-landscape")); QFileInfo fi(fileName); view->setWindowTitle(fi.fileName()); - view->resize( 400, 300 ); + view->resize(400, 300); Gui::getMainWindow()->addWindow(view); - } else { + } + else { throw Py::Exception(PyExc_IOError, "unknown filetype"); } @@ -130,8 +133,9 @@ private: { PyObject* object; char* Name; - if (!PyArg_ParseTuple(args.ptr(), "Oet",&object,"utf-8",&Name)) + if (!PyArg_ParseTuple(args.ptr(), "Oet", &object, "utf-8", &Name)) { throw Py::Exception(); + } std::string EncodedName = std::string(Name); PyMem_Free(Name); @@ -140,7 +144,8 @@ private: for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { PyObject* item = (*it).ptr(); if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) { - App::DocumentObject* obj = static_cast(item)->getDocumentObjectPtr(); + App::DocumentObject* obj = + static_cast(item)->getDocumentObjectPtr(); if (obj->getTypeId().isDerivedFrom(Drawing::FeaturePage::getClassTypeId())) { Base::FileInfo fi_out(EncodedName.c_str()); Base::ofstream str_out(fi_out, std::ios::out | std::ios::binary); @@ -150,7 +155,8 @@ private: throw Py::Exception(PyExc_IOError, str.str().c_str()); } if (fi_out.hasExtension("svg")) { - std::string fn = static_cast(obj)->PageResult.getValue(); + std::string fn = + static_cast(obj)->PageResult.getValue(); Base::FileInfo fi_in(fn); Base::ifstream str_in(fi_in, std::ios::in | std::ios::binary); if (!str_in) { @@ -165,31 +171,45 @@ private: break; } else if (fi_out.hasExtension("dxf")) { - const std::vector& views = static_cast(obj)->Group.getValues(); - for (std::vector::const_iterator it = views.begin(); it != views.end(); ++it) { - if ((*it)->getTypeId().isDerivedFrom(Drawing::FeatureViewPart::getClassTypeId())) { - Drawing::FeatureViewPart* view = static_cast(*it); + const std::vector& views = + static_cast(obj)->Group.getValues(); + for (std::vector::const_iterator it = views.begin(); + it != views.end(); + ++it) { + if ((*it)->getTypeId().isDerivedFrom( + Drawing::FeatureViewPart::getClassTypeId())) { + Drawing::FeatureViewPart* view = + static_cast(*it); App::DocumentObject* link = view->Source.getValue(); if (!link) { throw Py::ValueError("No object linked"); } - if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + if (!link->getTypeId().isDerivedFrom( + Part::Feature::getClassTypeId())) { throw Py::TypeError("Linked object is not a Part object"); } - TopoDS_Shape shape = static_cast(link)->Shape.getShape().getShape(); + TopoDS_Shape shape = + static_cast(link)->Shape.getShape().getShape(); if (!shape.IsNull()) { Base::Vector3d dir = view->Direction.getValue(); bool hidden = view->ShowHiddenLines.getValue(); bool smooth = view->ShowSmoothLines.getValue(); - Drawing::ProjectionAlgos::ExtractionType type = Drawing::ProjectionAlgos::Plain; - if (hidden) type = (Drawing::ProjectionAlgos::ExtractionType)(type|Drawing::ProjectionAlgos::WithHidden); - if (smooth) type = (Drawing::ProjectionAlgos::ExtractionType)(type|Drawing::ProjectionAlgos::WithSmooth); + Drawing::ProjectionAlgos::ExtractionType type = + Drawing::ProjectionAlgos::Plain; + if (hidden) { + type = (Drawing::ProjectionAlgos::ExtractionType)( + type | Drawing::ProjectionAlgos::WithHidden); + } + if (smooth) { + type = (Drawing::ProjectionAlgos::ExtractionType)( + type | Drawing::ProjectionAlgos::WithSmooth); + } float scale = view->Scale.getValue(); float tol = view->Tolerance.getValue(); Drawing::ProjectionAlgos project(shape, dir); str_out << project.getDXF(type, scale, tol); - break; // TODO: How to add several shapes? + break;// TODO: How to add several shapes? } } } @@ -197,11 +217,13 @@ private: break; } else { - throw Py::TypeError("Export of page object as this file format is not supported by Drawing module"); + throw Py::TypeError("Export of page object as this file format is not " + "supported by Drawing module"); } } else { - throw Py::TypeError("Export of this object type is not supported by Drawing module"); + throw Py::TypeError( + "Export of this object type is not supported by Drawing module"); } } } @@ -215,4 +237,4 @@ PyObject* initModule() return Base::Interpreter().addModule(new Module); } -} // namespace DrawingGui +}// namespace DrawingGui diff --git a/src/Mod/Drawing/Gui/Command.cpp b/src/Mod/Drawing/Gui/Command.cpp index e4dec8a8bc..001fcbeb9f 100644 --- a/src/Mod/Drawing/Gui/Command.cpp +++ b/src/Mod/Drawing/Gui/Command.cpp @@ -11,15 +11,15 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include +#include +#include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include #endif #include @@ -52,25 +52,27 @@ using namespace std; DEF_STD_CMD(CmdDrawingOpen) CmdDrawingOpen::CmdDrawingOpen() - : Command("Drawing_Open") + : Command("Drawing_Open") { - sAppModule = "Drawing"; - sGroup = QT_TR_NOOP("Drawing"); - sMenuText = QT_TR_NOOP("Open SVG..."); - sToolTipText = QT_TR_NOOP("Open a scalable vector graphic"); - sWhatsThis = "Drawing_Open"; - sStatusTip = sToolTipText; - sPixmap = "actions/document-new"; + sAppModule = "Drawing"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Open SVG..."); + sToolTipText = QT_TR_NOOP("Open a scalable vector graphic"); + sWhatsThis = "Drawing_Open"; + sStatusTip = sToolTipText; + sPixmap = "actions/document-new"; } void CmdDrawingOpen::activated(int iMsg) { Q_UNUSED(iMsg); // Reading an image - QString filename = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), QObject::tr("Choose an SVG file to open"), QString(), + QString filename = Gui::FileDialog::getOpenFileName( + Gui::getMainWindow(), + QObject::tr("Choose an SVG file to open"), + QString(), QString::fromLatin1("%1 (*.svg *.svgz)").arg(QObject::tr("Scalable Vector Graphic"))); - if (!filename.isEmpty()) - { + if (!filename.isEmpty()) { filename = Base::Tools::escapeEncodeFilename(filename); // load the file with the module Command::doCommand(Command::Gui, "import Drawing, DrawingGui"); @@ -85,14 +87,14 @@ void CmdDrawingOpen::activated(int iMsg) DEF_STD_CMD_ACL(CmdDrawingNewPage) CmdDrawingNewPage::CmdDrawingNewPage() - : Command("Drawing_NewPage") + : Command("Drawing_NewPage") { - sAppModule = "Drawing"; - sGroup = QT_TR_NOOP("Drawing"); - sMenuText = QT_TR_NOOP("Insert new drawing"); - sToolTipText = QT_TR_NOOP("Insert new drawing"); - sWhatsThis = "Drawing_NewPage"; - sStatusTip = sToolTipText; + sAppModule = "Drawing"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Insert new drawing"); + sToolTipText = QT_TR_NOOP("Insert new drawing"); + sWhatsThis = "Drawing_NewPage"; + sStatusTip = sToolTipText; } void CmdDrawingNewPage::activated(int iMsg) @@ -101,26 +103,31 @@ void CmdDrawingNewPage::activated(int iMsg) QAction* a = qAsConst(pcAction)->actions()[iMsg]; std::string FeatName = getUniqueObjectName( - QCoreApplication::translate("Drawing_NewPage", "Page").toStdString().c_str()); + QCoreApplication::translate("Drawing_NewPage", "Page").toStdString().c_str()); QFileInfo tfi(a->property("Template").toString()); if (tfi.isReadable()) { QString filename = Base::Tools::escapeEncodeFilename(tfi.filePath()); openCommand("Create page"); - doCommand(Doc,"App.activeDocument().addObject('Drawing::FeaturePage','%s')",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Template = '%s'",FeatName.c_str(), (const char*)filename.toUtf8()); - doCommand(Doc,"App.activeDocument().recompute()"); - doCommand(Doc,"Gui.activeDocument().getObject('%s').show()",FeatName.c_str()); + doCommand(Doc, + "App.activeDocument().addObject('Drawing::FeaturePage','%s')", + FeatName.c_str()); + doCommand(Doc, + "App.activeDocument().%s.Template = '%s'", + FeatName.c_str(), + (const char*)filename.toUtf8()); + doCommand(Doc, "App.activeDocument().recompute()"); + doCommand(Doc, "Gui.activeDocument().getObject('%s').show()", FeatName.c_str()); commitCommand(); } else { QMessageBox::critical(Gui::getMainWindow(), - QLatin1String("No template"), - QLatin1String("No template available for this page size")); + QLatin1String("No template"), + QLatin1String("No template available for this page size")); } } -Gui::Action * CmdDrawingNewPage::createAction(void) +Gui::Action* CmdDrawingNewPage::createAction(void) { Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); pcAction->setDropDownMenu(true); @@ -135,7 +142,7 @@ Gui::Action * CmdDrawingNewPage::createAction(void) std::string path = App::Application::getResourceDir(); path += "Mod/Drawing/Templates/"; QDir dir(QString::fromUtf8(path.c_str()), QString::fromLatin1("*.svg")); - for (unsigned int i=0; i -1) { QString paper = rx.cap(1); @@ -162,11 +169,13 @@ Gui::Action * CmdDrawingNewPage::createAction(void) lastPaper = paper; lastId = id; - QFile file(QString::fromLatin1(":/icons/actions/drawing-%1-%2%3.svg").arg(orientation.toLower(), paper).arg(id)); + QFile file(QString::fromLatin1(":/icons/actions/drawing-%1-%2%3.svg") + .arg(orientation.toLower(), paper) + .arg(id)); QAction* a = pcAction->addAction(QString()); if (file.open(QFile::ReadOnly)) { QByteArray data = file.readAll(); - a->setIcon(Gui::BitmapFactory().pixmapFromSvg(data, QSize(64,64))); + a->setIcon(Gui::BitmapFactory().pixmapFromSvg(data, QSize(64, 64))); } a->setProperty("TemplatePaper", paper); @@ -204,57 +213,51 @@ void CmdDrawingNewPage::languageChange() { Command::languageChange(); - if (!_pcAction) + if (!_pcAction) { return; + } Gui::ActionGroup* pcAction = qobject_cast(_pcAction); QList a = pcAction->actions(); for (QList::iterator it = a.begin(); it != a.end(); ++it) { - if ((*it)->isSeparator()) + if ((*it)->isSeparator()) { continue; + } QString paper = (*it)->property("TemplatePaper").toString(); int id = (*it)->property("TemplateId").toInt(); QString orientation = (*it)->property("TemplateOrientation").toString(); - if (orientation.compare(QLatin1String("landscape"), Qt::CaseInsensitive) == 0) + if (orientation.compare(QLatin1String("landscape"), Qt::CaseInsensitive) == 0) { orientation = QCoreApplication::translate("Drawing_NewPage", "Landscape"); - else if (orientation.compare(QLatin1String("portrait"), Qt::CaseInsensitive) == 0) + } + else if (orientation.compare(QLatin1String("portrait"), Qt::CaseInsensitive) == 0) { orientation = QCoreApplication::translate("Drawing_NewPage", "Portrait"); + } QString info = (*it)->property("TemplateInfo").toString(); if (info.isEmpty()) { - (*it)->setText(QCoreApplication::translate( - "Drawing_NewPage", "%1%2 %3") - .arg(paper, - QString::number(id), - orientation)); - (*it)->setToolTip(QCoreApplication::translate( - "Drawing_NewPage", "Insert new %1%2 %3 drawing") - .arg(paper, - QString::number(id), - orientation)); + (*it)->setText(QCoreApplication::translate("Drawing_NewPage", "%1%2 %3") + .arg(paper, QString::number(id), orientation)); + (*it)->setToolTip( + QCoreApplication::translate("Drawing_NewPage", "Insert new %1%2 %3 drawing") + .arg(paper, QString::number(id), orientation)); } else { - (*it)->setText(QCoreApplication::translate( - "Drawing_NewPage", "%1%2 %3 (%4)") - .arg(paper, - QString::number(id), - orientation, - info)); - (*it)->setToolTip(QCoreApplication::translate( - "Drawing_NewPage", "Insert new %1%2 %3 (%4) drawing") - .arg(paper, - QString::number(id), - orientation, - info)); + (*it)->setText(QCoreApplication::translate("Drawing_NewPage", "%1%2 %3 (%4)") + .arg(paper, QString::number(id), orientation, info)); + (*it)->setToolTip( + QCoreApplication::translate("Drawing_NewPage", "Insert new %1%2 %3 (%4) drawing") + .arg(paper, QString::number(id), orientation, info)); } } } bool CmdDrawingNewPage::isActive(void) { - if (getActiveGuiDocument()) + if (getActiveGuiDocument()) { return true; - else + } + else { return false; + } } //=========================================================================== @@ -264,15 +267,15 @@ bool CmdDrawingNewPage::isActive(void) DEF_STD_CMD_A(CmdDrawingNewA3Landscape) CmdDrawingNewA3Landscape::CmdDrawingNewA3Landscape() - : Command("Drawing_NewA3Landscape") + : Command("Drawing_NewA3Landscape") { - sAppModule = "Drawing"; - sGroup = QT_TR_NOOP("Drawing"); - sMenuText = QT_TR_NOOP("Insert new A3 landscape drawing"); - sToolTipText = QT_TR_NOOP("Insert new A3 landscape drawing"); - sWhatsThis = "Drawing_NewA3Landscape"; - sStatusTip = sToolTipText; - sPixmap = "actions/drawing-landscape-A3"; + sAppModule = "Drawing"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Insert new A3 landscape drawing"); + sToolTipText = QT_TR_NOOP("Insert new A3 landscape drawing"); + sWhatsThis = "Drawing_NewA3Landscape"; + sStatusTip = sToolTipText; + sPixmap = "actions/drawing-landscape-A3"; } void CmdDrawingNewA3Landscape::activated(int iMsg) @@ -281,18 +284,20 @@ void CmdDrawingNewA3Landscape::activated(int iMsg) std::string FeatName = getUniqueObjectName("Page"); openCommand("Create page"); - doCommand(Doc,"App.activeDocument().addObject('Drawing::FeaturePage','%s')",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Template = 'A3_Landscape.svg'",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().recompute()"); + doCommand(Doc, "App.activeDocument().addObject('Drawing::FeaturePage','%s')", FeatName.c_str()); + doCommand(Doc, "App.activeDocument().%s.Template = 'A3_Landscape.svg'", FeatName.c_str()); + doCommand(Doc, "App.activeDocument().recompute()"); commitCommand(); } bool CmdDrawingNewA3Landscape::isActive(void) { - if (getActiveGuiDocument()) + if (getActiveGuiDocument()) { return true; - else + } + else { return false; + } } @@ -303,45 +308,51 @@ bool CmdDrawingNewA3Landscape::isActive(void) DEF_STD_CMD(CmdDrawingNewView) CmdDrawingNewView::CmdDrawingNewView() - : Command("Drawing_NewView") + : Command("Drawing_NewView") { - sAppModule = "Drawing"; - sGroup = QT_TR_NOOP("Drawing"); - sMenuText = QT_TR_NOOP("Insert view in drawing"); - sToolTipText = QT_TR_NOOP("Insert a new View of a Part in the active drawing"); - sWhatsThis = "Drawing_NewView"; - sStatusTip = sToolTipText; - sPixmap = "actions/drawing-view"; + sAppModule = "Drawing"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Insert view in drawing"); + sToolTipText = QT_TR_NOOP("Insert a new View of a Part in the active drawing"); + sWhatsThis = "Drawing_NewView"; + sStatusTip = sToolTipText; + sPixmap = "actions/drawing-view"; } void CmdDrawingNewView::activated(int iMsg) { Q_UNUSED(iMsg); - std::vector shapes = getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); + std::vector shapes = + getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); if (shapes.empty()) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select a Part object.")); + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("Wrong selection"), + QObject::tr("Select a Part object.")); return; } - - std::vector pages = getSelection().getObjectsOfType(Drawing::FeaturePage::getClassTypeId()); + + std::vector pages = + getSelection().getObjectsOfType(Drawing::FeaturePage::getClassTypeId()); if (pages.empty()) { pages = this->getDocument()->getObjectsOfType(Drawing::FeaturePage::getClassTypeId()); - if (pages.empty()){ - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"), - QObject::tr("Create a page first.")); + if (pages.empty()) { + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("No page found"), + QObject::tr("Create a page first.")); return; } } - const std::vector selectedProjections = getSelection().getObjectsOfType(Drawing::FeatureView::getClassTypeId()); + const std::vector selectedProjections = + getSelection().getObjectsOfType(Drawing::FeatureView::getClassTypeId()); float newX = 10.0; float newY = 10.0; float newScale = 1.0; float newRotation = 0.0; Base::Vector3d newDirection(0.0, 0.0, 1.0); if (!selectedProjections.empty()) { - const Drawing::FeatureView* const myView = static_cast(selectedProjections.front()); + const Drawing::FeatureView* const myView = + static_cast(selectedProjections.front()); newX = myView->X.getValue(); newY = myView->Y.getValue(); @@ -351,7 +362,8 @@ void CmdDrawingNewView::activated(int iMsg) // The "Direction" property does not belong to Drawing::FeatureView, but to one of the // many child classes that are projecting objects into the drawing. Therefore, we get the // property by name. - const App::PropertyVector* const propDirection = dynamic_cast(myView->getPropertyByName("Direction")); + const App::PropertyVector* const propDirection = + dynamic_cast(myView->getPropertyByName("Direction")); if (propDirection) { newDirection = propDirection->getValue(); } @@ -360,16 +372,30 @@ void CmdDrawingNewView::activated(int iMsg) std::string PageName = pages.front()->getNameInDocument(); openCommand("Create view"); - for (std::vector::iterator it = shapes.begin(); it != shapes.end(); ++it) { + for (std::vector::iterator it = shapes.begin(); it != shapes.end(); + ++it) { std::string FeatName = getUniqueObjectName("View"); - doCommand(Doc,"App.activeDocument().addObject('Drawing::FeatureViewPart','%s')",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),(*it)->getNameInDocument()); - doCommand(Doc,"App.activeDocument().%s.Direction = (%e,%e,%e)",FeatName.c_str(), newDirection.x, newDirection.y, newDirection.z); - doCommand(Doc,"App.activeDocument().%s.X = %e",FeatName.c_str(), newX); - doCommand(Doc,"App.activeDocument().%s.Y = %e",FeatName.c_str(), newY); - doCommand(Doc,"App.activeDocument().%s.Scale = %e",FeatName.c_str(), newScale); - doCommand(Doc,"App.activeDocument().%s.Rotation = %e",FeatName.c_str(), newRotation); - doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + doCommand(Doc, + "App.activeDocument().addObject('Drawing::FeatureViewPart','%s')", + FeatName.c_str()); + doCommand(Doc, + "App.activeDocument().%s.Source = App.activeDocument().%s", + FeatName.c_str(), + (*it)->getNameInDocument()); + doCommand(Doc, + "App.activeDocument().%s.Direction = (%e,%e,%e)", + FeatName.c_str(), + newDirection.x, + newDirection.y, + newDirection.z); + doCommand(Doc, "App.activeDocument().%s.X = %e", FeatName.c_str(), newX); + doCommand(Doc, "App.activeDocument().%s.Y = %e", FeatName.c_str(), newY); + doCommand(Doc, "App.activeDocument().%s.Scale = %e", FeatName.c_str(), newScale); + doCommand(Doc, "App.activeDocument().%s.Rotation = %e", FeatName.c_str(), newRotation); + doCommand(Doc, + "App.activeDocument().%s.addObject(App.activeDocument().%s)", + PageName.c_str(), + FeatName.c_str()); } updateActive(); commitCommand(); @@ -382,33 +408,37 @@ void CmdDrawingNewView::activated(int iMsg) DEF_STD_CMD_A(CmdDrawingOrthoViews) CmdDrawingOrthoViews::CmdDrawingOrthoViews() - : Command("Drawing_OrthoViews") + : Command("Drawing_OrthoViews") { - sAppModule = "Drawing"; - sGroup = QT_TR_NOOP("Drawing"); - sMenuText = QT_TR_NOOP("Insert orthographic views"); - sToolTipText = QT_TR_NOOP("Insert an orthographic projection of a part in the active drawing"); - sWhatsThis = "Drawing_OrthoView"; - sStatusTip = sToolTipText; - sPixmap = "actions/drawing-orthoviews"; + sAppModule = "Drawing"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Insert orthographic views"); + sToolTipText = QT_TR_NOOP("Insert an orthographic projection of a part in the active drawing"); + sWhatsThis = "Drawing_OrthoView"; + sStatusTip = sToolTipText; + sPixmap = "actions/drawing-orthoviews"; } void CmdDrawingOrthoViews::activated(int iMsg) { Q_UNUSED(iMsg); - const std::vector shapes = getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); + const std::vector shapes = + getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); if (shapes.size() != 1) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select exactly one Part object.")); + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("Wrong selection"), + QObject::tr("Select exactly one Part object.")); return; } // Check that a page object exists. TaskDlgOrthoViews will then check for a selected page object // and use that, otherwise it will use the first page in the document. - const std::vector pages = this->getDocument()->getObjectsOfType(Drawing::FeaturePage::getClassTypeId()); + const std::vector pages = + this->getDocument()->getObjectsOfType(Drawing::FeaturePage::getClassTypeId()); if (pages.empty()) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"), - QObject::tr("Create a page first.")); + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("No page found"), + QObject::tr("Create a page first.")); return; } @@ -419,8 +449,9 @@ void CmdDrawingOrthoViews::activated(int iMsg) bool CmdDrawingOrthoViews::isActive(void) { - if (Gui::Control().activeDialog()) + if (Gui::Control().activeDialog()) { return false; + } return true; } @@ -432,15 +463,15 @@ bool CmdDrawingOrthoViews::isActive(void) DEF_STD_CMD_A(CmdDrawingOpenBrowserView) CmdDrawingOpenBrowserView::CmdDrawingOpenBrowserView() - : Command("Drawing_OpenBrowserView") + : Command("Drawing_OpenBrowserView") { // setting the - sGroup = QT_TR_NOOP("Drawing"); - sMenuText = QT_TR_NOOP("Open &browser view"); - sToolTipText = QT_TR_NOOP("Opens the selected page in a browser view"); - sWhatsThis = "Drawing_OpenBrowserView"; - sStatusTip = QT_TR_NOOP("Opens the selected page in a browser view"); - sPixmap = "actions/drawing-openbrowser"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Open &browser view"); + sToolTipText = QT_TR_NOOP("Opens the selected page in a browser view"); + sWhatsThis = "Drawing_OpenBrowserView"; + sStatusTip = QT_TR_NOOP("Opens the selected page in a browser view"); + sPixmap = "actions/drawing-openbrowser"; } void CmdDrawingOpenBrowserView::activated(int iMsg) @@ -448,14 +479,15 @@ void CmdDrawingOpenBrowserView::activated(int iMsg) Q_UNUSED(iMsg); unsigned int n = getSelection().countObjectsOfType(Drawing::FeaturePage::getClassTypeId()); if (n != 1) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select one Page object.")); + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("Wrong selection"), + QObject::tr("Select one Page object.")); return; } std::vector Sel = getSelection().getSelection(); - doCommand(Doc,"PageName = App.activeDocument().%s.PageResult",Sel[0].FeatName); - doCommand(Doc,"import WebGui"); - doCommand(Doc,"WebGui.openBrowser(PageName)"); + doCommand(Doc, "PageName = App.activeDocument().%s.PageResult", Sel[0].FeatName); + doCommand(Doc, "import WebGui"); + doCommand(Doc, "WebGui.openBrowser(PageName)"); } bool CmdDrawingOpenBrowserView::isActive(void) @@ -470,37 +502,44 @@ bool CmdDrawingOpenBrowserView::isActive(void) DEF_STD_CMD_A(CmdDrawingAnnotation) CmdDrawingAnnotation::CmdDrawingAnnotation() - : Command("Drawing_Annotation") + : Command("Drawing_Annotation") { // setting the - sGroup = QT_TR_NOOP("Drawing"); - sMenuText = QT_TR_NOOP("&Annotation"); - sToolTipText = QT_TR_NOOP("Inserts an Annotation view in the active drawing"); - sWhatsThis = "Drawing_Annotation"; - sStatusTip = QT_TR_NOOP("Inserts an Annotation view in the active drawing"); - sPixmap = "actions/drawing-annotation"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("&Annotation"); + sToolTipText = QT_TR_NOOP("Inserts an Annotation view in the active drawing"); + sWhatsThis = "Drawing_Annotation"; + sStatusTip = QT_TR_NOOP("Inserts an Annotation view in the active drawing"); + sPixmap = "actions/drawing-annotation"; } void CmdDrawingAnnotation::activated(int iMsg) { Q_UNUSED(iMsg); - std::vector pages = getSelection().getObjectsOfType(Drawing::FeaturePage::getClassTypeId()); + std::vector pages = + getSelection().getObjectsOfType(Drawing::FeaturePage::getClassTypeId()); if (pages.empty()) { pages = this->getDocument()->getObjectsOfType(Drawing::FeaturePage::getClassTypeId()); - if (pages.empty()){ - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"), - QObject::tr("Create a page first.")); + if (pages.empty()) { + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("No page found"), + QObject::tr("Create a page first.")); return; } } std::string PageName = pages.front()->getNameInDocument(); std::string FeatName = getUniqueObjectName("Annotation"); openCommand("Create Annotation"); - doCommand(Doc,"App.activeDocument().addObject('Drawing::FeatureViewAnnotation','%s')",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.X = 10.0",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Y = 10.0",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Scale = 7.0",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + doCommand(Doc, + "App.activeDocument().addObject('Drawing::FeatureViewAnnotation','%s')", + FeatName.c_str()); + doCommand(Doc, "App.activeDocument().%s.X = 10.0", FeatName.c_str()); + doCommand(Doc, "App.activeDocument().%s.Y = 10.0", FeatName.c_str()); + doCommand(Doc, "App.activeDocument().%s.Scale = 7.0", FeatName.c_str()); + doCommand(Doc, + "App.activeDocument().%s.addObject(App.activeDocument().%s)", + PageName.c_str(), + FeatName.c_str()); updateActive(); commitCommand(); } @@ -518,34 +557,39 @@ bool CmdDrawingAnnotation::isActive(void) DEF_STD_CMD_A(CmdDrawingClip) CmdDrawingClip::CmdDrawingClip() - : Command("Drawing_Clip") + : Command("Drawing_Clip") { // setting the - sGroup = QT_TR_NOOP("Drawing"); - sMenuText = QT_TR_NOOP("&Clip"); - sToolTipText = QT_TR_NOOP("Inserts a clip group in the active drawing"); - sWhatsThis = "Drawing_Annotation"; - sStatusTip = QT_TR_NOOP("Inserts a clip group in the active drawing"); - sPixmap = "actions/drawing-clip"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("&Clip"); + sToolTipText = QT_TR_NOOP("Inserts a clip group in the active drawing"); + sWhatsThis = "Drawing_Annotation"; + sStatusTip = QT_TR_NOOP("Inserts a clip group in the active drawing"); + sPixmap = "actions/drawing-clip"; } void CmdDrawingClip::activated(int iMsg) { Q_UNUSED(iMsg); - std::vector pages = getSelection().getObjectsOfType(Drawing::FeaturePage::getClassTypeId()); + std::vector pages = + getSelection().getObjectsOfType(Drawing::FeaturePage::getClassTypeId()); if (pages.empty()) { pages = this->getDocument()->getObjectsOfType(Drawing::FeaturePage::getClassTypeId()); - if (pages.empty()){ - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"), - QObject::tr("Create a page first.")); + if (pages.empty()) { + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("No page found"), + QObject::tr("Create a page first.")); return; } } std::string PageName = pages.front()->getNameInDocument(); std::string FeatName = getUniqueObjectName("Clip"); openCommand("Create Clip"); - doCommand(Doc,"App.activeDocument().addObject('Drawing::FeatureClip','%s')",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + doCommand(Doc, "App.activeDocument().addObject('Drawing::FeatureClip','%s')", FeatName.c_str()); + doCommand(Doc, + "App.activeDocument().%s.addObject(App.activeDocument().%s)", + PageName.c_str(), + FeatName.c_str()); updateActive(); commitCommand(); } @@ -563,45 +607,56 @@ bool CmdDrawingClip::isActive(void) DEF_STD_CMD_A(CmdDrawingSymbol) CmdDrawingSymbol::CmdDrawingSymbol() - : Command("Drawing_Symbol") + : Command("Drawing_Symbol") { // setting the - sGroup = QT_TR_NOOP("Drawing"); - sMenuText = QT_TR_NOOP("&Symbol"); - sToolTipText = QT_TR_NOOP("Inserts a symbol from a svg file in the active drawing"); - sWhatsThis = "Drawing_Symbol"; - sStatusTip = QT_TR_NOOP("Inserts a symbol from a svg file in the active drawing"); - sPixmap = "actions/drawing-symbol"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("&Symbol"); + sToolTipText = QT_TR_NOOP("Inserts a symbol from a svg file in the active drawing"); + sWhatsThis = "Drawing_Symbol"; + sStatusTip = QT_TR_NOOP("Inserts a symbol from a svg file in the active drawing"); + sPixmap = "actions/drawing-symbol"; } void CmdDrawingSymbol::activated(int iMsg) { Q_UNUSED(iMsg); - std::vector pages = getSelection().getObjectsOfType(Drawing::FeaturePage::getClassTypeId()); + std::vector pages = + getSelection().getObjectsOfType(Drawing::FeaturePage::getClassTypeId()); if (pages.empty()) { pages = this->getDocument()->getObjectsOfType(Drawing::FeaturePage::getClassTypeId()); - if (pages.empty()){ - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"), - QObject::tr("Create a page first.")); + if (pages.empty()) { + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("No page found"), + QObject::tr("Create a page first.")); return; } } // Reading an image - QString filename = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), QObject::tr("Choose an SVG file to open"), QString(), + QString filename = Gui::FileDialog::getOpenFileName( + Gui::getMainWindow(), + QObject::tr("Choose an SVG file to open"), + QString(), QString::fromLatin1("%1 (*.svg *.svgz)").arg(QObject::tr("Scalable Vector Graphic"))); - if (!filename.isEmpty()) - { + if (!filename.isEmpty()) { std::string PageName = pages.front()->getNameInDocument(); std::string FeatName = getUniqueObjectName("Symbol"); filename = Base::Tools::escapeEncodeFilename(filename); openCommand("Create Symbol"); - doCommand(Doc,"import Drawing"); - doCommand(Doc,"f = open(\"%s\",'r')",(const char*)filename.toUtf8()); - doCommand(Doc,"svg = f.read()"); - doCommand(Doc,"f.close()"); - doCommand(Doc,"App.activeDocument().addObject('Drawing::FeatureViewSymbol','%s')",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Symbol = Drawing.removeSvgTags(svg)",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + doCommand(Doc, "import Drawing"); + doCommand(Doc, "f = open(\"%s\",'r')", (const char*)filename.toUtf8()); + doCommand(Doc, "svg = f.read()"); + doCommand(Doc, "f.close()"); + doCommand(Doc, + "App.activeDocument().addObject('Drawing::FeatureViewSymbol','%s')", + FeatName.c_str()); + doCommand(Doc, + "App.activeDocument().%s.Symbol = Drawing.removeSvgTags(svg)", + FeatName.c_str()); + doCommand(Doc, + "App.activeDocument().%s.addObject(App.activeDocument().%s)", + PageName.c_str(), + FeatName.c_str()); updateActive(); commitCommand(); } @@ -620,15 +675,15 @@ bool CmdDrawingSymbol::isActive(void) DEF_STD_CMD_A(CmdDrawingExportPage) CmdDrawingExportPage::CmdDrawingExportPage() - : Command("Drawing_ExportPage") + : Command("Drawing_ExportPage") { // setting the - sGroup = QT_TR_NOOP("File"); - sMenuText = QT_TR_NOOP("&Export page..."); - sToolTipText = QT_TR_NOOP("Export a page to an SVG file"); - sWhatsThis = "Drawing_ExportPage"; - sStatusTip = QT_TR_NOOP("Export a page to an SVG file"); - sPixmap = "document-save"; + sGroup = QT_TR_NOOP("File"); + sMenuText = QT_TR_NOOP("&Export page..."); + sToolTipText = QT_TR_NOOP("Export a page to an SVG file"); + sWhatsThis = "Drawing_ExportPage"; + sStatusTip = QT_TR_NOOP("Export a page to an SVG file"); + sPixmap = "document-save"; } void CmdDrawingExportPage::activated(int iMsg) @@ -636,8 +691,9 @@ void CmdDrawingExportPage::activated(int iMsg) Q_UNUSED(iMsg); unsigned int n = getSelection().countObjectsOfType(Drawing::FeaturePage::getClassTypeId()); if (n != 1) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select one Page object.")); + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("Wrong selection"), + QObject::tr("Select one Page object.")); return; } @@ -645,17 +701,20 @@ void CmdDrawingExportPage::activated(int iMsg) filter << QString::fromLatin1("%1 (*.svg)").arg(QObject::tr("Scalable Vector Graphic")); filter << QString::fromLatin1("%1 (*.*)").arg(QObject::tr("All Files")); - QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QObject::tr("Export page"), QString(), filter.join(QLatin1String(";;"))); + QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), + QObject::tr("Export page"), + QString(), + filter.join(QLatin1String(";;"))); if (!fn.isEmpty()) { std::vector Sel = getSelection().getSelection(); openCommand("Drawing export page"); - doCommand(Doc,"PageFile = open(App.activeDocument().%s.PageResult,'r')",Sel[0].FeatName); + doCommand(Doc, "PageFile = open(App.activeDocument().%s.PageResult,'r')", Sel[0].FeatName); std::string fname = (const char*)fn.toUtf8(); fname = Base::Tools::escapeEncodeFilename(fname); - doCommand(Doc,"OutFile = open(\"%s\",'w')",fname.c_str()); - doCommand(Doc,"OutFile.write(PageFile.read())"); - doCommand(Doc,"del OutFile,PageFile"); + doCommand(Doc, "OutFile = open(\"%s\",'w')", fname.c_str()); + doCommand(Doc, "OutFile.write(PageFile.read())"); + doCommand(Doc, "del OutFile,PageFile"); commitCommand(); } @@ -673,14 +732,14 @@ bool CmdDrawingExportPage::isActive(void) DEF_STD_CMD_A(CmdDrawingProjectShape) CmdDrawingProjectShape::CmdDrawingProjectShape() - : Command("Drawing_ProjectShape") + : Command("Drawing_ProjectShape") { // setting the - sGroup = QT_TR_NOOP("Drawing"); - sMenuText = QT_TR_NOOP("Project shape..."); - sToolTipText = QT_TR_NOOP("Project shape onto a user-defined plane"); - sStatusTip = QT_TR_NOOP("Project shape onto a user-defined plane"); - sWhatsThis = "Drawing_ProjectShape"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("Project shape..."); + sToolTipText = QT_TR_NOOP("Project shape onto a user-defined plane"); + sStatusTip = QT_TR_NOOP("Project shape onto a user-defined plane"); + sWhatsThis = "Drawing_ProjectShape"; } void CmdDrawingProjectShape::activated(int iMsg) @@ -701,7 +760,6 @@ bool CmdDrawingProjectShape::isActive(void) } - //=========================================================================== // Drawing_Draft_View //=========================================================================== @@ -709,22 +767,23 @@ bool CmdDrawingProjectShape::isActive(void) DEF_STD_CMD_A(CmdDrawingDraftView) CmdDrawingDraftView::CmdDrawingDraftView() - : Command("Drawing_DraftView") + : Command("Drawing_DraftView") { // setting the - sGroup = QT_TR_NOOP("Drawing"); - sMenuText = QT_TR_NOOP("&Draft View"); - sToolTipText = QT_TR_NOOP("Inserts a Draft view of the selected object(s) in the active drawing"); - sWhatsThis = "Drawing_DraftView"; - sStatusTip = QT_TR_NOOP("Inserts a Draft view of the selected object(s) in the active drawing"); - sPixmap = "actions/drawing-draft-view"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("&Draft View"); + sToolTipText = + QT_TR_NOOP("Inserts a Draft view of the selected object(s) in the active drawing"); + sWhatsThis = "Drawing_DraftView"; + sStatusTip = QT_TR_NOOP("Inserts a Draft view of the selected object(s) in the active drawing"); + sPixmap = "actions/drawing-draft-view"; } void CmdDrawingDraftView::activated(int iMsg) { Q_UNUSED(iMsg); - addModule(Gui,"Draft"); - doCommand(Gui,"Gui.runCommand(\"Draft_Drawing\")"); + addModule(Gui, "Draft"); + doCommand(Gui, "Gui.runCommand(\"Draft_Drawing\")"); } bool CmdDrawingDraftView::isActive(void) @@ -740,39 +799,51 @@ bool CmdDrawingDraftView::isActive(void) DEF_STD_CMD_A(CmdDrawingSpreadsheetView) CmdDrawingSpreadsheetView::CmdDrawingSpreadsheetView() - : Command("Drawing_SpreadsheetView") + : Command("Drawing_SpreadsheetView") { // setting the - sGroup = QT_TR_NOOP("Drawing"); - sMenuText = QT_TR_NOOP("&Spreadsheet View"); - sToolTipText = QT_TR_NOOP("Inserts a view of a selected spreadsheet in the active drawing"); - sWhatsThis = "Drawing_SpreadsheetView"; - sStatusTip = QT_TR_NOOP("Inserts a view of a selected spreadsheet in the active drawing"); - sPixmap = "actions/drawing-spreadsheet"; + sGroup = QT_TR_NOOP("Drawing"); + sMenuText = QT_TR_NOOP("&Spreadsheet View"); + sToolTipText = QT_TR_NOOP("Inserts a view of a selected spreadsheet in the active drawing"); + sWhatsThis = "Drawing_SpreadsheetView"; + sStatusTip = QT_TR_NOOP("Inserts a view of a selected spreadsheet in the active drawing"); + sPixmap = "actions/drawing-spreadsheet"; } void CmdDrawingSpreadsheetView::activated(int iMsg) { Q_UNUSED(iMsg); - const std::vector spreads = getSelection().getObjectsOfType(Spreadsheet::Sheet::getClassTypeId()); + const std::vector spreads = + getSelection().getObjectsOfType(Spreadsheet::Sheet::getClassTypeId()); if (spreads.size() != 1) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select exactly one Spreadsheet object.")); + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("Wrong selection"), + QObject::tr("Select exactly one Spreadsheet object.")); return; } - const std::vector pages = this->getDocument()->getObjectsOfType(Drawing::FeaturePage::getClassTypeId()); + const std::vector pages = + this->getDocument()->getObjectsOfType(Drawing::FeaturePage::getClassTypeId()); if (pages.empty()) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"), - QObject::tr("Create a page first.")); + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("No page found"), + QObject::tr("Create a page first.")); return; } std::string SpreadName = spreads.front()->getNameInDocument(); std::string PageName = pages.front()->getNameInDocument(); openCommand("Create spreadsheet view"); std::string FeatName = getUniqueObjectName("View"); - doCommand(Doc,"App.activeDocument().addObject('Drawing::FeatureViewSpreadsheet','%s')",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),SpreadName.c_str()); - doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + doCommand(Doc, + "App.activeDocument().addObject('Drawing::FeatureViewSpreadsheet','%s')", + FeatName.c_str()); + doCommand(Doc, + "App.activeDocument().%s.Source = App.activeDocument().%s", + FeatName.c_str(), + SpreadName.c_str()); + doCommand(Doc, + "App.activeDocument().%s.addObject(App.activeDocument().%s)", + PageName.c_str(), + FeatName.c_str()); updateActive(); commitCommand(); } @@ -785,7 +856,7 @@ bool CmdDrawingSpreadsheetView::isActive(void) void CreateDrawingCommands(void) { - Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); + Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager(); rcCmdMgr.addCommand(new CmdDrawingOpen()); rcCmdMgr.addCommand(new CmdDrawingNewPage()); diff --git a/src/Mod/Drawing/Gui/DrawingView.cpp b/src/Mod/Drawing/Gui/DrawingView.cpp index 4219870b6a..6e95da4124 100644 --- a/src/Mod/Drawing/Gui/DrawingView.cpp +++ b/src/Mod/Drawing/Gui/DrawingView.cpp @@ -22,27 +22,27 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif @@ -59,7 +59,7 @@ using namespace DrawingGui; -SvgView::SvgView(QWidget *parent) +SvgView::SvgView(QWidget* parent) : QGraphicsView(parent) , m_renderer(Native) , m_svgItem(nullptr) @@ -83,7 +83,7 @@ SvgView::SvgView(QWidget *parent) setBackgroundBrush(tilePixmap); } -void SvgView::drawBackground(QPainter *p, const QRectF &) +void SvgView::drawBackground(QPainter* p, const QRectF&) { p->save(); p->resetTransform(); @@ -91,12 +91,13 @@ void SvgView::drawBackground(QPainter *p, const QRectF &) p->restore(); } -void SvgView::openFile(const QFile &file) +void SvgView::openFile(const QFile& file) { - if (!file.exists()) + if (!file.exists()) { return; + } - QGraphicsScene *s = scene(); + QGraphicsScene* s = scene(); bool drawBackground = (m_backgroundItem ? m_backgroundItem->isVisible() : true); bool drawOutline = (m_outlineItem ? m_outlineItem->isVisible() : false); @@ -140,7 +141,8 @@ void SvgView::setRenderer(RendererType type) #ifndef QT_NO_OPENGL setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); #endif - } else { + } + else { setViewport(new QWidget); } } @@ -156,21 +158,23 @@ void SvgView::setHighQualityAntialiasing(bool highQualityAntialiasing) void SvgView::setViewBackground(bool enable) { - if (!m_backgroundItem) + if (!m_backgroundItem) { return; + } m_backgroundItem->setVisible(enable); } void SvgView::setViewOutline(bool enable) { - if (!m_outlineItem) + if (!m_outlineItem) { return; + } m_outlineItem->setVisible(enable); } -void SvgView::paintEvent(QPaintEvent *event) +void SvgView::paintEvent(QPaintEvent* event) { if (m_renderer == Image) { if (m_image.size() != viewport()->size()) { @@ -183,17 +187,18 @@ void SvgView::paintEvent(QPaintEvent *event) QPainter p(viewport()); p.drawImage(0, 0, m_image); - - } else { + } + else { QGraphicsView::paintEvent(event); } } -void SvgView::wheelEvent(QWheelEvent *event) +void SvgView::wheelEvent(QWheelEvent* event) { int delta = -event->angleDelta().y(); - if (m_invertZoom) + if (m_invertZoom) { delta = -delta; + } qreal factor = std::pow(1.2, delta / 240.0); scale(factor, factor); event->accept(); @@ -204,7 +209,8 @@ void SvgView::wheelEvent(QWheelEvent *event) /* TRANSLATOR DrawingGui::DrawingView */ DrawingView::DrawingView(Gui::Document* doc, QWidget* parent) - : Gui::MDIView(doc, parent), m_view(new SvgView) + : Gui::MDIView(doc, parent) + , m_view(new SvgView) { m_backgroundAction = new QAction(tr("&Background"), this); m_backgroundAction->setEnabled(false); @@ -233,41 +239,42 @@ DrawingView::DrawingView(Gui::Document* doc, QWidget* parent) m_highQualityAntialiasingAction->setEnabled(false); m_highQualityAntialiasingAction->setCheckable(true); m_highQualityAntialiasingAction->setChecked(false); - connect(m_highQualityAntialiasingAction, SIGNAL(toggled(bool)), - m_view, SLOT(setHighQualityAntialiasing(bool))); + connect(m_highQualityAntialiasingAction, + SIGNAL(toggled(bool)), + m_view, + SLOT(setHighQualityAntialiasing(bool))); #endif - QActionGroup *rendererGroup = new QActionGroup(this); + QActionGroup* rendererGroup = new QActionGroup(this); rendererGroup->addAction(m_nativeAction); #ifndef QT_NO_OPENGL rendererGroup->addAction(m_glAction); #endif rendererGroup->addAction(m_imageAction); - connect(rendererGroup, SIGNAL(triggered(QAction *)), - this, SLOT(setRenderer(QAction *))); + connect(rendererGroup, SIGNAL(triggered(QAction*)), this, SLOT(setRenderer(QAction*))); setCentralWidget(m_view); - //setWindowTitle(tr("SVG Viewer")); + // setWindowTitle(tr("SVG Viewer")); m_orientation = QPageLayout::Landscape; m_pageSize = QPageSize::A4; - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath - ("User parameter:BaseApp/Preferences/View"); + ParameterGrp::handle hGrp = + App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); bool on = hGrp->GetBool("InvertZoom", true); m_view->setZoomInverted(on); } DrawingView::~DrawingView() -{ -} +{} -void DrawingView::load (const QString & fileName) +void DrawingView::load(const QString& fileName) { if (!fileName.isEmpty()) { QFile file(fileName); if (!file.exists()) { - QMessageBox::critical(this, tr("Open SVG File"), - tr("Could not open file '%1'.").arg(fileName)); + QMessageBox::critical(this, + tr("Open SVG File"), + tr("Could not open file '%1'.").arg(fileName)); m_outlineAction->setEnabled(false); m_backgroundAction->setEnabled(false); @@ -278,7 +285,7 @@ void DrawingView::load (const QString & fileName) if (!fileName.startsWith(QLatin1String(":/"))) { m_currentPath = fileName; - //setWindowTitle(tr("%1 - SVG Viewer").arg(m_currentPath)); + // setWindowTitle(tr("%1 - SVG Viewer").arg(m_currentPath)); } m_outlineAction->setEnabled(true); @@ -318,7 +325,9 @@ void DrawingView::findPrinterSettings(const QString& fileName) pageSizes[QPageSize::B7] = QString::fromLatin1("B7"); pageSizes[QPageSize::B8] = QString::fromLatin1("B8"); pageSizes[QPageSize::B9] = QString::fromLatin1("B9"); - for (QMap::iterator it = pageSizes.begin(); it != pageSizes.end(); ++it) { + for (QMap::iterator it = pageSizes.begin(); + it != pageSizes.end(); + ++it) { if (fileName.startsWith(it.value(), Qt::CaseInsensitive)) { m_pageSize = it.key(); break; @@ -334,8 +343,9 @@ void DrawingView::setDocumentObject(const std::string& name) void DrawingView::closeEvent(QCloseEvent* ev) { MDIView::closeEvent(ev); - if (!ev->isAccepted()) + if (!ev->isAccepted()) { return; + } // when closing the view from GUI notify the view provider to mark it invisible if (_pcDocument && !m_objectName.empty()) { @@ -343,13 +353,14 @@ void DrawingView::closeEvent(QCloseEvent* ev) if (doc) { App::DocumentObject* obj = doc->getObject(m_objectName.c_str()); Gui::ViewProvider* vp = _pcDocument->getViewProvider(obj); - if (vp) + if (vp) { vp->hide(); + } } } } -void DrawingView::contextMenuEvent(QContextMenuEvent *event) +void DrawingView::contextMenuEvent(QContextMenuEvent* event) { QMenu menu; menu.addAction(this->m_backgroundAction); @@ -363,14 +374,15 @@ void DrawingView::contextMenuEvent(QContextMenuEvent *event) menu.exec(event->globalPos()); } -void DrawingView::setRenderer(QAction *action) +void DrawingView::setRenderer(QAction* action) { #ifndef QT_NO_OPENGL m_highQualityAntialiasingAction->setEnabled(false); #endif - if (action == m_nativeAction) + if (action == m_nativeAction) { m_view->setRenderer(SvgView::Native); + } #ifndef QT_NO_OPENGL else if (action == m_glAction) { m_highQualityAntialiasingAction->setEnabled(true); @@ -382,35 +394,35 @@ void DrawingView::setRenderer(QAction *action) } } -bool DrawingView::onMsg(const char* pMsg, const char** ) +bool DrawingView::onMsg(const char* pMsg, const char**) { - if (strcmp("ViewFit",pMsg) == 0) { + if (strcmp("ViewFit", pMsg) == 0) { viewAll(); return true; } - else if (strcmp("Save",pMsg) == 0) { - Gui::Document *doc = getGuiDocument(); + else if (strcmp("Save", pMsg) == 0) { + Gui::Document* doc = getGuiDocument(); if (doc) { doc->save(); return true; } } - else if (strcmp("SaveAs",pMsg) == 0) { - Gui::Document *doc = getGuiDocument(); + else if (strcmp("SaveAs", pMsg) == 0) { + Gui::Document* doc = getGuiDocument(); if (doc) { doc->saveAs(); return true; } } - else if(strcmp("Undo",pMsg) == 0 ) { - Gui::Document *doc = getGuiDocument(); + else if (strcmp("Undo", pMsg) == 0) { + Gui::Document* doc = getGuiDocument(); if (doc) { doc->undo(1); return true; } } - else if(strcmp("Redo",pMsg) == 0 ) { - Gui::Document *doc = getGuiDocument(); + else if (strcmp("Redo", pMsg) == 0) { + Gui::Document* doc = getGuiDocument(); if (doc) { doc->redo(1); return true; @@ -421,35 +433,41 @@ bool DrawingView::onMsg(const char* pMsg, const char** ) bool DrawingView::onHasMsg(const char* pMsg) const { - if (strcmp("ViewFit",pMsg) == 0) + if (strcmp("ViewFit", pMsg) == 0) { return true; - else if (strcmp("Save",pMsg) == 0) + } + else if (strcmp("Save", pMsg) == 0) { return getGuiDocument() != nullptr; - else if (strcmp("SaveAs",pMsg) == 0) + } + else if (strcmp("SaveAs", pMsg) == 0) { return getGuiDocument() != nullptr; - else if (strcmp("Undo",pMsg) == 0) { + } + else if (strcmp("Undo", pMsg) == 0) { App::Document* doc = getAppDocument(); return doc && doc->getAvailableUndos() > 0; } - else if (strcmp("Redo",pMsg) == 0) { + else if (strcmp("Redo", pMsg) == 0) { App::Document* doc = getAppDocument(); return doc && doc->getAvailableRedos() > 0; } - else if (strcmp("Print",pMsg) == 0) + else if (strcmp("Print", pMsg) == 0) { return true; - else if (strcmp("PrintPreview",pMsg) == 0) + } + else if (strcmp("PrintPreview", pMsg) == 0) { return true; - else if (strcmp("PrintPdf",pMsg) == 0) + } + else if (strcmp("PrintPdf", pMsg) == 0) { return true; + } return false; } -void DrawingView::onRelabel(Gui::Document *pDoc) +void DrawingView::onRelabel(Gui::Document* pDoc) { if (!bIsPassive && pDoc) { - QString cap = QString::fromLatin1("%1 : %2[*]") - .arg(QString::fromUtf8(pDoc->getDocument()->Label.getValue()), - objectName()); + QString cap = + QString::fromLatin1("%1 : %2[*]") + .arg(QString::fromUtf8(pDoc->getDocument()->Label.getValue()), objectName()); setWindowTitle(cap); } } @@ -462,12 +480,12 @@ void DrawingView::printPdf() dlg.setWindowTitle(tr("Export PDF")); dlg.setNameFilters(QStringList() << QString::fromLatin1("%1 (*.pdf)").arg(tr("PDF file"))); - QGridLayout *gridLayout; - QGridLayout *formLayout; - QGroupBox *groupBox; - QListWidget *listWidget; + QGridLayout* gridLayout; + QGridLayout* formLayout; + QGroupBox* groupBox; + QListWidget* listWidget; QListWidgetItem* item; - QWidget *form = new QWidget(&dlg); + QWidget* form = new QWidget(&dlg); form->resize(40, 300); formLayout = new QGridLayout(form); groupBox = new QGroupBox(form); @@ -489,8 +507,8 @@ void DrawingView::printPdf() item->setData(Qt::UserRole, QVariant(QPageSize::A4)); item = new QListWidgetItem(tr("A5"), listWidget); item->setData(Qt::UserRole, QVariant(QPageSize::A5)); - int index = 4; // by default A4 - for (int i=0; icount(); i++) { + int index = 4;// by default A4 + for (int i = 0; i < listWidget->count(); i++) { if (listWidget->item(i)->data(Qt::UserRole).toInt() == m_pageSize) { index = i; break; @@ -540,8 +558,7 @@ void DrawingView::printPreview() printer.setPageOrientation(m_orientation); QPrintPreviewDialog dlg(&printer, this); - connect(&dlg, SIGNAL(paintRequested (QPrinter *)), - this, SLOT(print(QPrinter *))); + connect(&dlg, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*))); dlg.exec(); } @@ -570,35 +587,46 @@ void DrawingView::print(QPrinter* printer) bool doPrint = paintType != QPaintEngine::Picture; if (doPrint && printer->pageLayout().orientation() != this->m_orientation) { - int ret = QMessageBox::warning(this, tr("Different orientation"), + int ret = QMessageBox::warning( + this, + tr("Different orientation"), tr("The printer uses a different orientation than the drawing.\n" "Do you want to continue?"), - QMessageBox::Yes | QMessageBox::No); - if (ret != QMessageBox::Yes) + QMessageBox::Yes | QMessageBox::No); + if (ret != QMessageBox::Yes) { return; + } } else if (doPrint && realPaperSize != this->m_pageSize) { - int ret = QMessageBox::warning(this, tr("Different paper size"), + int ret = QMessageBox::warning( + this, + tr("Different paper size"), tr("The printer uses a different paper size than the drawing.\n" "Do you want to continue?"), - QMessageBox::Yes | QMessageBox::No); - if (ret != QMessageBox::Yes) + QMessageBox::Yes | QMessageBox::No); + if (ret != QMessageBox::Yes) { return; + } } else if (doPrint && curPaperSize != this->m_pageSize) { - int ret = QMessageBox::warning(this, tr("Different paper size"), + int ret = QMessageBox::warning( + this, + tr("Different paper size"), tr("The printer uses a different paper size than the drawing.\n" "Do you want to continue?"), - QMessageBox::Yes | QMessageBox::No); - if (ret != QMessageBox::Yes) + QMessageBox::Yes | QMessageBox::No); + if (ret != QMessageBox::Yes) { return; + } } } QPainter p(printer); if (!p.isActive() && !printer->outputFileName().isEmpty()) { qApp->setOverrideCursor(Qt::ArrowCursor); - QMessageBox::critical(this, tr("Opening file failed"), + QMessageBox::critical( + this, + tr("Opening file failed"), tr("Can't open file '%1' for writing.").arg(printer->outputFileName())); qApp->restoreOverrideCursor(); return; @@ -607,8 +635,9 @@ void DrawingView::print(QPrinter* printer) #ifdef Q_OS_WIN32 // On Windows the preview looks broken when using paperRect as render area. // Although the picture is scaled when using pageRect, it looks just fine. - if (paintType == QPaintEngine::Picture) + if (paintType == QPaintEngine::Picture) { rect = printer->pageLayout().paintRectPixels(printer->resolution()); + } #endif this->m_view->scene()->render(&p, rect); p.end(); @@ -617,48 +646,45 @@ void DrawingView::print(QPrinter* printer) QPageSize::PageSizeId DrawingView::getPageSize(int w, int h) const { static const float paperSizes[][2] = { - {210, 297}, // A4 - {176, 250}, // B5 - {215.9f, 279.4f}, // Letter - {215.9f, 355.6f}, // Legal - {190.5f, 254}, // Executive - {841, 1189}, // A0 - {594, 841}, // A1 - {420, 594}, // A2 - {297, 420}, // A3 - {148, 210}, // A5 - {105, 148}, // A6 - {74, 105}, // A7 - {52, 74}, // A8 - {37, 52}, // A8 - {1000, 1414}, // B0 - {707, 1000}, // B1 - {31, 44}, // B10 - {500, 707}, // B2 - {353, 500}, // B3 - {250, 353}, // B4 - {125, 176}, // B6 - {88, 125}, // B7 - {62, 88}, // B8 - {33, 62}, // B9 - {163, 229}, // C5E - {105, 241}, // US Common - {110, 220}, // DLE - {210, 330}, // Folio - {431.8f, 279.4f}, // Ledger + {210, 297}, // A4 + {176, 250}, // B5 + {215.9f, 279.4f},// Letter + {215.9f, 355.6f},// Legal + {190.5f, 254}, // Executive + {841, 1189}, // A0 + {594, 841}, // A1 + {420, 594}, // A2 + {297, 420}, // A3 + {148, 210}, // A5 + {105, 148}, // A6 + {74, 105}, // A7 + {52, 74}, // A8 + {37, 52}, // A8 + {1000, 1414}, // B0 + {707, 1000}, // B1 + {31, 44}, // B10 + {500, 707}, // B2 + {353, 500}, // B3 + {250, 353}, // B4 + {125, 176}, // B6 + {88, 125}, // B7 + {62, 88}, // B8 + {33, 62}, // B9 + {163, 229}, // C5E + {105, 241}, // US Common + {110, 220}, // DLE + {210, 330}, // Folio + {431.8f, 279.4f},// Ledger {279.4f, 431.8f} // Tabloid }; QPageSize::PageSizeId ps = QPageSize::Custom; - for (int i=0; i<30; i++) { - if (std::abs(paperSizes[i][0]-w) <= 1 && - std::abs(paperSizes[i][1]-h) <= 1) { + for (int i = 0; i < 30; i++) { + if (std::abs(paperSizes[i][0] - w) <= 1 && std::abs(paperSizes[i][1] - h) <= 1) { ps = static_cast(i); break; } - else - if (std::abs(paperSizes[i][0]-h) <= 1 && - std::abs(paperSizes[i][1]-w) <= 1) { + else if (std::abs(paperSizes[i][0] - h) <= 1 && std::abs(paperSizes[i][1] - w) <= 1) { ps = static_cast(i); break; diff --git a/src/Mod/Drawing/Gui/DrawingView.h b/src/Mod/Drawing/Gui/DrawingView.h index d7c43b07fc..837d3d5237 100644 --- a/src/Mod/Drawing/Gui/DrawingView.h +++ b/src/Mod/Drawing/Gui/DrawingView.h @@ -45,19 +45,25 @@ QT_END_NAMESPACE namespace DrawingGui { -class DrawingGuiExport SvgView : public QGraphicsView +class DrawingGuiExport SvgView: public QGraphicsView { Q_OBJECT public: - enum RendererType { Native, OpenGL, Image }; + enum RendererType + { + Native, + OpenGL, + Image + }; - SvgView(QWidget *parent = nullptr); + SvgView(QWidget* parent = nullptr); - void openFile(const QFile &file); + void openFile(const QFile& file); void setRenderer(RendererType type = Native); - void drawBackground(QPainter *p, const QRectF &rect); - void setZoomInverted(bool on) { + void drawBackground(QPainter* p, const QRectF& rect); + void setZoomInverted(bool on) + { m_invertZoom = on; } @@ -67,21 +73,21 @@ public Q_SLOTS: void setViewOutline(bool enable); protected: - void wheelEvent(QWheelEvent *event); - void paintEvent(QPaintEvent *event); + void wheelEvent(QWheelEvent* event); + void paintEvent(QPaintEvent* event); private: RendererType m_renderer; - QGraphicsItem *m_svgItem; - QGraphicsRectItem *m_backgroundItem; - QGraphicsRectItem *m_outlineItem; + QGraphicsItem* m_svgItem; + QGraphicsRectItem* m_backgroundItem; + QGraphicsRectItem* m_outlineItem; QImage m_image; bool m_invertZoom; }; -class DrawingGuiExport DrawingView : public Gui::MDIView +class DrawingGuiExport DrawingView: public Gui::MDIView { Q_OBJECT @@ -90,14 +96,14 @@ public: virtual ~DrawingView(); public Q_SLOTS: - void load(const QString &path = QString()); - void setRenderer(QAction *action); + void load(const QString& path = QString()); + void setRenderer(QAction* action); void viewAll(); public: - bool onMsg(const char* pMsg,const char** ppReturn); + bool onMsg(const char* pMsg, const char** ppReturn); bool onHasMsg(const char* pMsg) const; - void onRelabel(Gui::Document *pDoc); + void onRelabel(Gui::Document* pDoc); void print(); void printPdf(); void printPreview(); @@ -106,20 +112,20 @@ public: PyObject* getPyObject(); protected: - void contextMenuEvent(QContextMenuEvent *event); + void contextMenuEvent(QContextMenuEvent* event); void closeEvent(QCloseEvent*); void findPrinterSettings(const QString&); QPageSize::PageSizeId getPageSize(int w, int h) const; private: - QAction *m_nativeAction; - QAction *m_glAction; - QAction *m_imageAction; - QAction *m_highQualityAntialiasingAction; - QAction *m_backgroundAction; - QAction *m_outlineAction; + QAction* m_nativeAction; + QAction* m_glAction; + QAction* m_imageAction; + QAction* m_highQualityAntialiasingAction; + QAction* m_backgroundAction; + QAction* m_outlineAction; - SvgView *m_view; + SvgView* m_view; std::string m_objectName; QString m_currentPath; @@ -127,6 +133,6 @@ private: QPageSize::PageSizeId m_pageSize; }; -} // namespace DrawingViewGui +}// namespace DrawingGui -#endif // DRAWINGGUI_DRAWINGVIEW_H +#endif// DRAWINGGUI_DRAWINGVIEW_H diff --git a/src/Mod/Drawing/Gui/PreCompiled.cpp b/src/Mod/Drawing/Gui/PreCompiled.cpp index 3139e21f64..6758517493 100644 --- a/src/Mod/Drawing/Gui/PreCompiled.cpp +++ b/src/Mod/Drawing/Gui/PreCompiled.cpp @@ -20,4 +20,4 @@ * * ***************************************************************************/ -#include "PreCompiled.h" +#include "PreCompiled.h" diff --git a/src/Mod/Drawing/Gui/PreCompiled.h b/src/Mod/Drawing/Gui/PreCompiled.h index 855f8a5968..f283d98b42 100644 --- a/src/Mod/Drawing/Gui/PreCompiled.h +++ b/src/Mod/Drawing/Gui/PreCompiled.h @@ -26,7 +26,7 @@ #include #ifdef _MSC_VER -# pragma warning(disable : 4005) +#pragma warning(disable : 4005) #endif #ifdef _PreComp_ @@ -55,15 +55,15 @@ #include #include #include -#include #include -#include +#include #include #include +#include #include #include #include -#endif //_PreComp_ +#endif//_PreComp_ -#endif // DRAWINGGUI_PRECOMPILED_H +#endif// DRAWINGGUI_PRECOMPILED_H diff --git a/src/Mod/Drawing/Gui/Resources/Drawing.qrc b/src/Mod/Drawing/Gui/Resources/Drawing.qrc index e23bd017e3..6f9b3e8460 100644 --- a/src/Mod/Drawing/Gui/Resources/Drawing.qrc +++ b/src/Mod/Drawing/Gui/Resources/Drawing.qrc @@ -1,5 +1,5 @@ - + icons/Page.svg icons/Pages.svg icons/View.svg @@ -26,4 +26,4 @@ icons/actions/drawing-draft-view.svg icons/actions/drawing-spreadsheet.svg - + diff --git a/src/Mod/Drawing/Gui/TaskDialog.cpp b/src/Mod/Drawing/Gui/TaskDialog.cpp index 8ac2ad756d..e20caf20af 100644 --- a/src/Mod/Drawing/Gui/TaskDialog.cpp +++ b/src/Mod/Drawing/Gui/TaskDialog.cpp @@ -22,8 +22,8 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include +#include +#include #endif #include @@ -43,26 +43,24 @@ using namespace DrawingGui; TaskProjection::TaskProjection() { - QString texts[10] = - { - tr("Visible sharp edges"), - tr("Visible smooth edges"), - tr("Visible sewn edges"), - tr("Visible outline edges"), - tr("Visible isoparameters"), - tr("Hidden sharp edges"), - tr("Hidden smooth edges"), - tr("Hidden sewn edges"), - tr("Hidden outline edges"), - tr("Hidden isoparameters") - }; + QString texts[10] = {tr("Visible sharp edges"), + tr("Visible smooth edges"), + tr("Visible sewn edges"), + tr("Visible outline edges"), + tr("Visible isoparameters"), + tr("Hidden sharp edges"), + tr("Hidden smooth edges"), + tr("Hidden sewn edges"), + tr("Hidden outline edges"), + tr("Hidden isoparameters")}; widget = new QWidget(); - QVBoxLayout *mainLayout = new QVBoxLayout; + QVBoxLayout* mainLayout = new QVBoxLayout; - for (int i=0; i<10; i++) { + for (int i = 0; i < 10; i++) { QCheckBox* cb = new QCheckBox(); - if (i < 5) + if (i < 5) { cb->setChecked(true); + } cb->setText(texts[i]); mainLayout->addWidget(cb); boxes.push_back(cb); @@ -70,8 +68,7 @@ TaskProjection::TaskProjection() widget->setLayout(mainLayout); - taskbox = new Gui::TaskView::TaskBox( - QPixmap(), tr("Project shapes"), false, nullptr); + taskbox = new Gui::TaskView::TaskBox(QPixmap(), tr("Project shapes"), false, nullptr); taskbox->groupLayout()->addWidget(widget); Content.push_back(taskbox); } @@ -85,54 +82,76 @@ bool TaskProjection::accept() { Gui::Document* document = Gui::Application::Instance->activeDocument(); if (!document) { - QMessageBox::warning(widget, tr("No active document"), - tr("There is currently no active document to complete the operation")); + QMessageBox::warning(widget, + tr("No active document"), + tr("There is currently no active document to complete the operation")); return true; } - std::list mdis = document->getMDIViewsOfType(Gui::View3DInventor::getClassTypeId()); + std::list mdis = + document->getMDIViewsOfType(Gui::View3DInventor::getClassTypeId()); if (mdis.empty()) { - QMessageBox::warning(widget, tr("No active view"), - tr("There is currently no active view to complete the operation")); + QMessageBox::warning(widget, + tr("No active view"), + tr("There is currently no active view to complete the operation")); return false; } - Gui::View3DInventorViewer* viewer = static_cast(mdis.front())->getViewer(); + Gui::View3DInventorViewer* viewer = + static_cast(mdis.front())->getViewer(); SbVec3f pnt, dir; viewer->getNearPlane(pnt, dir); - float x=0, y=1,z=1; - dir.getValue(x,y,z); + float x = 0, y = 1, z = 1; + dir.getValue(x, y, z); std::vector shapes = Gui::Selection().getObjectsOfType(); Gui::Command::openCommand("Project shape"); - Gui::Command::addModule(Gui::Command::Doc,"Drawing"); + Gui::Command::addModule(Gui::Command::Doc, "Drawing"); for (std::vector::iterator it = shapes.begin(); it != shapes.end(); ++it) { const char* object = (*it)->getNameInDocument(); + Gui::Command::doCommand( + Gui::Command::Doc, + "FreeCAD.ActiveDocument.addObject('Drawing::FeatureProjection','%s_proj')", + object); + Gui::Command::doCommand( + Gui::Command::Doc, + "FreeCAD.ActiveDocument.ActiveObject.Direction=FreeCAD.Vector(%f,%f,%f)", + x, + y, + z); + Gui::Command::doCommand( + Gui::Command::Doc, + "FreeCAD.ActiveDocument.ActiveObject.Source=FreeCAD.ActiveDocument.%s", + object); Gui::Command::doCommand(Gui::Command::Doc, - "FreeCAD.ActiveDocument.addObject('Drawing::FeatureProjection','%s_proj')", object); + "FreeCAD.ActiveDocument.ActiveObject.VCompound=%s", + (boxes[0]->isChecked() ? "True" : "False")); Gui::Command::doCommand(Gui::Command::Doc, - "FreeCAD.ActiveDocument.ActiveObject.Direction=FreeCAD.Vector(%f,%f,%f)", x,y,z); + "FreeCAD.ActiveDocument.ActiveObject.Rg1LineVCompound=%s", + (boxes[1]->isChecked() ? "True" : "False")); Gui::Command::doCommand(Gui::Command::Doc, - "FreeCAD.ActiveDocument.ActiveObject.Source=FreeCAD.ActiveDocument.%s", object); + "FreeCAD.ActiveDocument.ActiveObject.RgNLineVCompound=%s", + (boxes[2]->isChecked() ? "True" : "False")); Gui::Command::doCommand(Gui::Command::Doc, - "FreeCAD.ActiveDocument.ActiveObject.VCompound=%s", (boxes[0]->isChecked() ? "True" : "False")); + "FreeCAD.ActiveDocument.ActiveObject.OutLineVCompound=%s", + (boxes[3]->isChecked() ? "True" : "False")); Gui::Command::doCommand(Gui::Command::Doc, - "FreeCAD.ActiveDocument.ActiveObject.Rg1LineVCompound=%s", (boxes[1]->isChecked() ? "True" : "False")); + "FreeCAD.ActiveDocument.ActiveObject.IsoLineVCompound=%s", + (boxes[4]->isChecked() ? "True" : "False")); Gui::Command::doCommand(Gui::Command::Doc, - "FreeCAD.ActiveDocument.ActiveObject.RgNLineVCompound=%s", (boxes[2]->isChecked() ? "True" : "False")); + "FreeCAD.ActiveDocument.ActiveObject.HCompound=%s", + (boxes[5]->isChecked() ? "True" : "False")); Gui::Command::doCommand(Gui::Command::Doc, - "FreeCAD.ActiveDocument.ActiveObject.OutLineVCompound=%s", (boxes[3]->isChecked() ? "True" : "False")); + "FreeCAD.ActiveDocument.ActiveObject.Rg1LineHCompound=%s", + (boxes[6]->isChecked() ? "True" : "False")); Gui::Command::doCommand(Gui::Command::Doc, - "FreeCAD.ActiveDocument.ActiveObject.IsoLineVCompound=%s", (boxes[4]->isChecked() ? "True" : "False")); + "FreeCAD.ActiveDocument.ActiveObject.RgNLineHCompound=%s", + (boxes[7]->isChecked() ? "True" : "False")); Gui::Command::doCommand(Gui::Command::Doc, - "FreeCAD.ActiveDocument.ActiveObject.HCompound=%s", (boxes[5]->isChecked() ? "True" : "False")); + "FreeCAD.ActiveDocument.ActiveObject.OutLineHCompound=%s", + (boxes[8]->isChecked() ? "True" : "False")); Gui::Command::doCommand(Gui::Command::Doc, - "FreeCAD.ActiveDocument.ActiveObject.Rg1LineHCompound=%s", (boxes[6]->isChecked() ? "True" : "False")); - Gui::Command::doCommand(Gui::Command::Doc, - "FreeCAD.ActiveDocument.ActiveObject.RgNLineHCompound=%s", (boxes[7]->isChecked() ? "True" : "False")); - Gui::Command::doCommand(Gui::Command::Doc, - "FreeCAD.ActiveDocument.ActiveObject.OutLineHCompound=%s", (boxes[8]->isChecked() ? "True" : "False")); - Gui::Command::doCommand(Gui::Command::Doc, - "FreeCAD.ActiveDocument.ActiveObject.IsoLineHCompound=%s", (boxes[9]->isChecked() ? "True" : "False")); + "FreeCAD.ActiveDocument.ActiveObject.IsoLineHCompound=%s", + (boxes[9]->isChecked() ? "True" : "False")); } Gui::Command::updateActive(); Gui::Command::commitCommand(); diff --git a/src/Mod/Drawing/Gui/TaskDialog.h b/src/Mod/Drawing/Gui/TaskDialog.h index ad87e17ce2..1eb5833141 100644 --- a/src/Mod/Drawing/Gui/TaskDialog.h +++ b/src/Mod/Drawing/Gui/TaskDialog.h @@ -37,7 +37,7 @@ namespace DrawingGui /** * Embed the panel into a task dialog. */ -class TaskProjection : public Gui::TaskView::TaskDialog +class TaskProjection: public Gui::TaskView::TaskDialog { Q_OBJECT @@ -49,9 +49,13 @@ public: bool accept(); virtual QDialogButtonBox::StandardButtons getStandardButtons() const - { return QDialogButtonBox::Ok | QDialogButtonBox::Cancel; } + { + return QDialogButtonBox::Ok | QDialogButtonBox::Cancel; + } virtual bool isAllowedAlterDocument(void) const - { return true; } + { + return true; + } private: QWidget* widget; @@ -59,8 +63,7 @@ private: Gui::TaskView::TaskBox* taskbox; }; -} //namespace DrawingGui +}// namespace DrawingGui - -#endif // DRAWINGGUI_TASKDIALOG +#endif// DRAWINGGUI_TASKDIALOG diff --git a/src/Mod/Drawing/Gui/TaskOrthoViews.cpp b/src/Mod/Drawing/Gui/TaskOrthoViews.cpp index 513b11b6d1..397ab5473c 100644 --- a/src/Mod/Drawing/Gui/TaskOrthoViews.cpp +++ b/src/Mod/Drawing/Gui/TaskOrthoViews.cpp @@ -22,8 +22,8 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include +#include +#include #endif #include @@ -42,90 +42,103 @@ using namespace DrawingGui; using namespace std; namespace bp = boost::placeholders; -#if 0 // needed for Qt's lupdate utility +#if 0// needed for Qt's lupdate utility qApp->translate("QObject", "Make axonometric..."); qApp->translate("QObject", "Edit axonometric settings..."); qApp->translate("QObject", "Make orthographic"); #endif - - -void pagesize(string & page_template, int dims[4], int block[4]) +void pagesize(string& page_template, int dims[4], int block[4]) { - dims[0] = 10; // default to A4_Landscape with 10mm margins + dims[0] = 10;// default to A4_Landscape with 10mm margins dims[1] = 10; dims[2] = 287; dims[3] = 200; - block[0] = block[1] = 0; // default to no title block + block[0] = block[1] = 0;// default to no title block block[2] = block[3] = 0; int t0, t1, t2, t3 = 0; - //code below copied from FeaturePage.cpp + // code below copied from FeaturePage.cpp Base::FileInfo fi(page_template); - if (!fi.isReadable()) - { + if (!fi.isReadable()) { fi.setFile(App::Application::getResourceDir() + "Mod/Drawing/Templates/" + fi.fileName()); - if (!fi.isReadable()) //if so then really shouldn't have been able to get this far, but just in case... + if (!fi.isReadable()) {// if so then really shouldn't have been able to get this far, but + // just in case... return; + } } // open Template file string line; - ifstream file (fi.filePath().c_str()); + ifstream file(fi.filePath().c_str()); - try - { - while (getline (file,line)) - { - if (line.find("" - getline (file,line); + try { + while (getline(file, line)) { + if (line.find("" + getline(file, line); - if (line.find("" + if (line.find("" + } break; } - if (line.find("metadata") != string::npos) //give up if we meet a metadata tag + if (line.find("metadata") != string::npos) {// give up if we meet a metadata tag break; + } } } - catch (Standard_Failure&) - { } - - - if (t3 != 0) - { - block[2] = t2 - t0; // block width - block[3] = t3 - t1; // block height - - if (t0 <= dims[0]) // title block on left - block[0] = -1; - else if (t2 >= dims[2]) // title block on right - block[0] = 1; - - if (t1 <= dims[1]) // title block at top - block[1] = 1; - else if (t3 >= dims[3]) // title block at bottom - block[1] = -1; + catch (Standard_Failure&) { } - dims[2] -= dims[0]; // width - dims[3] -= dims[1]; // height + + if (t3 != 0) { + block[2] = t2 - t0;// block width + block[3] = t3 - t1;// block height + + if (t0 <= dims[0]) {// title block on left + block[0] = -1; + } + else if (t2 >= dims[2]) {// title block on right + block[0] = 1; + } + + if (t1 <= dims[1]) {// title block at top + block[1] = 1; + } + else if (t3 >= dims[3]) {// title block at bottom + block[1] = -1; + } + } + + dims[2] -= dims[0];// width + dims[3] -= dims[1];// height } - /////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// -orthoview::orthoview(App::Document * parent, App::DocumentObject * part, App::DocumentObject * page, Base::BoundBox3d * partbox) +orthoview::orthoview(App::Document* parent, + App::DocumentObject* part, + App::DocumentObject* page, + Base::BoundBox3d* partbox) { parent_doc = parent; myname = parent_doc->getUniqueObjectName("Ortho"); @@ -136,8 +149,9 @@ orthoview::orthoview(App::Document * parent, App::DocumentObject * part, App::Do cy = partbox->GetCenter().y; cz = partbox->GetCenter().z; - this_view = static_cast (parent_doc->addObject("Drawing::FeatureViewPart", myname.c_str())); - static_cast(page)->addObject(this_view); + this_view = static_cast( + parent_doc->addObject("Drawing::FeatureViewPart", myname.c_str())); + static_cast(page)->addObject(this_view); this_view->Source.setValue(part); pageX = 0; @@ -155,8 +169,7 @@ orthoview::orthoview(App::Document * parent, App::DocumentObject * part, App::Do } orthoview::~orthoview() -{ -} +{} void orthoview::set_data(int r_x, int r_y) { @@ -164,7 +177,7 @@ void orthoview::set_data(int r_x, int r_y) rel_y = r_y; char label[15]; - sprintf(label, "Ortho_%i_%i", rel_x, rel_y); // label name for view, based on relative position + sprintf(label, "Ortho_%i_%i", rel_x, rel_y);// label name for view, based on relative position this_view->Label.setValue(label); ortho = ((rel_x * rel_y) == 0); @@ -177,8 +190,7 @@ void orthoview::deleteme() void orthoview::setPos(float px, float py) { - if (px != 0 && py !=0) - { + if (px != 0 && py != 0) { pageX = px; pageY = py; } @@ -219,8 +231,8 @@ void orthoview::smooth(bool state) void orthoview::set_projection(const gp_Ax2& cs) { - gp_Ax2 actual_cs; - gp_Dir actual_X; + gp_Ax2 actual_cs; + gp_Dir actual_X; // coord system & directions for desired projection X_dir = cs.XDirection(); @@ -244,13 +256,15 @@ void orthoview::set_projection(const gp_Ax2& cs) // angle between desired projection and actual projection float rotation = X_dir.Angle(actual_X); - if (rotation != 0 && abs(M_PI - rotation) > 0.05) - if (!Z_dir.IsEqual(actual_X.Crossed(X_dir), 0.05)) + if (rotation != 0 && abs(M_PI - rotation) > 0.05) { + if (!Z_dir.IsEqual(actual_X.Crossed(X_dir), 0.05)) { rotation = -rotation; + } + } calcCentre(); - //this_view->Direction.setValue(Z_dir.X(), Z_dir.Y(), Z_dir.Z()); + // this_view->Direction.setValue(Z_dir.X(), Z_dir.Y(), Z_dir.Z()); this_view->Direction.setValue(x, y, z); this_view->Rotation.setValue(180 * rotation / M_PI); } @@ -259,7 +273,7 @@ void orthoview::set_projection(const gp_Ax2& cs) /////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// -OrthoViews::OrthoViews(App::Document* doc, const char * pagename, const char * partname) +OrthoViews::OrthoViews(App::Document* doc, const char* pagename, const char* partname) { horiz = nullptr; vert = nullptr; @@ -274,7 +288,7 @@ OrthoViews::OrthoViews(App::Document* doc, const char * pagename, const char * p Gui::Application::Instance->showViewProvider(page); load_page(); - min_space = 15; // should be preferenced + min_space = 15;// should be preferenced min_r_x = max_r_x = 0; min_r_y = max_r_y = 0; @@ -291,16 +305,17 @@ OrthoViews::OrthoViews(App::Document* doc, const char * pagename, const char * p scale = 0; num_gaps_x = num_gaps_y = 0; - this->connectDocumentDeletedObject = doc->signalDeletedObject.connect(boost::bind - (&OrthoViews::slotDeletedObject, this, bp::_1)); - this->connectApplicationDeletedDocument = App::GetApplication().signalDeleteDocument.connect(boost::bind - (&OrthoViews::slotDeletedDocument, this, bp::_1)); + this->connectDocumentDeletedObject = + doc->signalDeletedObject.connect(boost::bind(&OrthoViews::slotDeletedObject, this, bp::_1)); + this->connectApplicationDeletedDocument = App::GetApplication().signalDeleteDocument.connect( + boost::bind(&OrthoViews::slotDeletedDocument, this, bp::_1)); } OrthoViews::~OrthoViews() { - for (int i = views.size() - 1; i >= 0; i--) + for (int i = views.size() - 1; i >= 0; i--) { delete views[i]; + } try { page->recomputeFeature(); @@ -322,7 +337,7 @@ void OrthoViews::slotDeletedObject(const App::DocumentObject& Obj) Gui::Control().closeDialog(); } else { - for (std::vector::iterator it = views.begin(); it != views.end(); ++it) { + for (std::vector::iterator it = views.begin(); it != views.end(); ++it) { if ((*it)->getViewPart() == &Obj) { views.erase(it); break; @@ -338,22 +353,19 @@ void OrthoViews::load_page() page_dims = large; // process page dims for title block data - if (block[0] != 0) - { + if (block[0] != 0) { title = true; // max vertical space avoiding title block - small_v[1] = large[1]; // y margin same as large page - small_v[3] = large[3]; // y size same as large page - small_v[2] = large[2] - block[2]; // x width same as large width - block width - if (block[0] == -1) - { - small_v[0] = large[0] + block[2]; // x margin same as large + block width + small_v[1] = large[1]; // y margin same as large page + small_v[3] = large[3]; // y size same as large page + small_v[2] = large[2] - block[2];// x width same as large width - block width + if (block[0] == -1) { + small_v[0] = large[0] + block[2];// x margin same as large + block width horiz = &min_r_x; } - else - { - small_v[0] = large[0]; // x margin same as large + else { + small_v[0] = large[0];// x margin same as large horiz = &max_r_x; } @@ -361,22 +373,22 @@ void OrthoViews::load_page() small_h[0] = large[0]; small_h[2] = large[2]; small_h[3] = large[3] - block[3]; - if (block[1] == 1) - { + if (block[1] == 1) { small_h[1] = large[1] + block[3]; vert = &max_r_y; } - else - { + else { small_h[1] = large[1]; vert = &min_r_y; } } - else + else { title = false; + } } -void OrthoViews::calc_layout_size() // calculate the real world size of given view layout, assuming no space +void OrthoViews::calc_layout_size()// calculate the real world size of given view layout, assuming + // no space { // note that views in relative positions x = -4, -2, 0 , 2 etc etc // have width = orientated part width @@ -391,44 +403,65 @@ void OrthoViews::calc_layout_size() // calculate the rea layout_height += (ceil(max_r_y / 2.0) + ceil(-min_r_y / 2.0)) * depth; } -void OrthoViews::choose_page() // chooses which bit of page space to use depending upon layout & titleblock +void OrthoViews::choose_page()// chooses which bit of page space to use depending upon layout & + // titleblock { - int h = abs(*horiz); // how many views in direction of title block (horiz points to min_r_x or max_r_x) - int v = abs(*vert); - float layout_corner_width = (1 + floor(h / 2.0)) * width + ceil(h / 2.0) * depth; // from (0, 0) view inclusively, how wide and tall is the layout in the direction of the title block + int h = abs( + *horiz);// how many views in direction of title block (horiz points to min_r_x or max_r_x) + int v = abs(*vert); + float layout_corner_width = (1 + floor(h / 2.0)) * width + + ceil(h / 2.0) * depth;// from (0, 0) view inclusively, how wide and tall is the layout in + // the direction of the title block float layout_corner_height = (1 + floor(v / 2.0)) * height + ceil(v / 2.0) * depth; - float rel_space_x = layout_corner_width / layout_width - 1.0 * block[2] / large[2]; // relative to respective sizes, how much space between (0, 0) and title block, - float rel_space_y = layout_corner_height / layout_height - 1.0 * block[3] / large[3]; // can be -ve if block extends into / beyond (0, 0) view + float rel_space_x = layout_corner_width / layout_width + - 1.0 * block[2] / large[2];// relative to respective sizes, how much space between (0, 0) + // and title block, + float rel_space_y = layout_corner_height / layout_height + - 1.0 * block[3] + / large[3];// can be -ve if block extends into / beyond (0, 0) view float view_x, view_y, v_x_r, v_y_r; - bool interferes = false; + bool interferes = false; float a, b; - for (int i = min_r_x; i <= max_r_x; i++) - for (int j = min_r_y; j <= max_r_y; j++) - if (index(i, j) != -1) // is there a view in this position? + for (int i = min_r_x; i <= max_r_x; i++) { + for (int j = min_r_y; j <= max_r_y; j++) { + if (index(i, j) != -1)// is there a view in this position? { - a = i * block[0] * 0.5; // reflect i and j so as +ve is in direction of title block ## + a = i * block[0] + * 0.5;// reflect i and j so as +ve is in direction of title block ## b = j * block[1] * 0.5; - view_x = ceil(a + 0.5) * width + ceil(a) * depth; // extreme coords of view in direction of block, measured from far corner of (0, 0) view, - view_y = ceil(b + 0.5) * height + ceil(b) * depth; // can be -ve if view is on opposite side of (0, 0) from title block - v_x_r = view_x / layout_width; // make relative + view_x = ceil(a + 0.5) * width + + ceil(a) * depth;// extreme coords of view in direction of block, measured from + // far corner of (0, 0) view, + view_y = ceil(b + 0.5) * height + + ceil(b) * depth;// can be -ve if view is on opposite side + // of (0, 0) from title block + v_x_r = view_x / layout_width;// make relative v_y_r = view_y / layout_height; - if (v_x_r > rel_space_x && v_y_r > rel_space_y) // ## so that can use > in this condition regardless of position of block + if (v_x_r > rel_space_x + && v_y_r > rel_space_y) {// ## so that can use > in this condition regardless of + // position of block interferes = true; + } } + } + } - if (!interferes) + if (!interferes) { page_dims = large; - else - { - if (min(small_h[2] / layout_width, small_h[3] / layout_height) > min(small_v[2] / layout_width, small_v[3] / layout_height)) + } + else { + if (min(small_h[2] / layout_width, small_h[3] / layout_height) + > min(small_v[2] / layout_width, small_v[3] / layout_height)) { page_dims = small_h; - else + } + else { page_dims = small_v; + } } } -void OrthoViews::calc_scale() // compute scale required to meet minimum space requirements +void OrthoViews::calc_scale()// compute scale required to meet minimum space requirements { float scale_x, scale_y, working_scale; @@ -437,23 +470,28 @@ void OrthoViews::calc_scale() // compute scale req working_scale = min(scale_x, scale_y); - //which gives the largest scale for which the min_space requirements can be met, but we want a 'sensible' scale, rather than 0.28457239... - //eg if working_scale = 0.115, then we want to use 0.1, similarly 7.65 -> 5, and 76.5 -> 50 + // which gives the largest scale for which the min_space requirements can be met, but we want a + // 'sensible' scale, rather than 0.28457239... eg if working_scale = 0.115, then we want to use + // 0.1, similarly 7.65 -> 5, and 76.5 -> 50 - float exponent = floor(log10(working_scale)); //if working_scale = a * 10^b, what is b? - working_scale *= pow(10, -exponent); //now find what 'a' is. + float exponent = floor(log10(working_scale));// if working_scale = a * 10^b, what is b? + working_scale *= pow(10, -exponent); // now find what 'a' is. - float valid_scales[2][8] = {{1, 1.25, 2, 2.5, 3.75, 5, 7.5, 10}, //equate to 1:10, 1:8, 1:5, 1:4, 3:8, 1:2, 3:4, 1:1 - {1, 1.5, 2, 3, 4, 5, 8, 10}}; //equate to 1:1, 3:2, 2:1, 3:1, 4:1, 5:1, 8:1, 10:1 + float valid_scales[2][8] = { + {1, 1.25, 2, 2.5, 3.75, 5, 7.5, 10},// equate to 1:10, 1:8, 1:5, 1:4, 3:8, 1:2, 3:4, 1:1 + {1, 1.5, 2, 3, 4, 5, 8, 10}}; // equate to 1:1, 3:2, 2:1, 3:1, 4:1, 5:1, 8:1, 10:1 int i = 7; - while (valid_scales[(exponent>=0)][i] > working_scale) //choose closest value smaller than 'a' from list. - i -= 1; //choosing top list if exponent -ve, bottom list for +ve exponent + while (valid_scales[(exponent >= 0)][i] + > working_scale) {// choose closest value smaller than 'a' from list. + i -= 1; // choosing top list if exponent -ve, bottom list for +ve exponent + } - scale = valid_scales[(exponent>=0)][i] * pow(10, exponent); //now have the appropriate scale, reapply the *10^b + scale = valid_scales[(exponent >= 0)][i] + * pow(10, exponent);// now have the appropriate scale, reapply the *10^b } -void OrthoViews::calc_offsets() // calcs SVG coords for centre of upper left view +void OrthoViews::calc_offsets()// calcs SVG coords for centre of upper left view { // space_x is the empty clear white space between views // gap_x is the centre - centre distance between views @@ -464,42 +502,46 @@ void OrthoViews::calc_offsets() // calcs SVG coords gap_x = space_x + scale * (width + depth) * 0.5; gap_y = space_y + scale * (height + depth) * 0.5; - if (min_r_x % 2 == 0) + if (min_r_x % 2 == 0) { offset_x = page_dims[0] + space_x + 0.5 * scale * width; - else + } + else { offset_x = page_dims[0] + space_x + 0.5 * scale * depth; + } - if (max_r_y % 2 == 0) + if (max_r_y % 2 == 0) { offset_y = page_dims[1] + space_y + 0.5 * scale * height; - else + } + else { offset_y = page_dims[1] + space_y + 0.5 * scale * depth; + } } -void OrthoViews::set_views() // process all views - scale & positions +void OrthoViews::set_views()// process all views - scale & positions { float x; float y; - for (unsigned int i = 0; i < views.size(); i++) - { + for (unsigned int i = 0; i < views.size(); i++) { x = offset_x + (views[i]->rel_x - min_r_x) * gap_x; y = offset_y + (max_r_y - views[i]->rel_y) * gap_y; - if (views[i]->auto_scale) + if (views[i]->auto_scale) { views[i]->setScale(scale); + } views[i]->setPos(x, y); } } -void OrthoViews::process_views() // update scale and positions of views +void OrthoViews::process_views()// update scale and positions of views { - if (autodims) - { + if (autodims) { calc_layout_size(); - if (title) + if (title) { choose_page(); + } calc_scale(); calc_offsets(); @@ -513,8 +555,9 @@ void OrthoViews::set_hidden(bool state) { hidden = state; - for (unsigned int i = 0; i < views.size(); i++) + for (unsigned int i = 0; i < views.size(); i++) { views[i]->hidden(hidden); + } parent_doc->recompute(); } @@ -523,86 +566,90 @@ void OrthoViews::set_smooth(bool state) { smooth = state; - for (unsigned int i = 0; i < views.size(); i++) + for (unsigned int i = 0; i < views.size(); i++) { views[i]->smooth(smooth); + } parent_doc->recompute(); } -void OrthoViews::set_primary(gp_Dir facing, gp_Dir right) // set the orientation of the primary view +void OrthoViews::set_primary(gp_Dir facing, gp_Dir right)// set the orientation of the primary view { primary.SetDirection(facing); primary.SetXDirection(right); gp_Dir up = primary.YDirection(); // compute dimensions of part when orientated according to primary view - width = abs(right.X() * bbox.LengthX() + right.Y() * bbox.LengthY() + right.Z() * bbox.LengthZ()); + width = + abs(right.X() * bbox.LengthX() + right.Y() * bbox.LengthY() + right.Z() * bbox.LengthZ()); height = abs(up.X() * bbox.LengthX() + up.Y() * bbox.LengthY() + up.Z() * bbox.LengthZ()); - depth = abs(facing.X() * bbox.LengthX() + facing.Y() * bbox.LengthY() + facing.Z() * bbox.LengthZ()); + depth = abs(facing.X() * bbox.LengthX() + facing.Y() * bbox.LengthY() + + facing.Z() * bbox.LengthZ()); - if (views.size() == 0) + if (views.size() == 0) { add_view(0, 0); - else - { + } + else { views[0]->set_projection(primary); - set_all_orientations(); // reorient all other views appropriately + set_all_orientations();// reorient all other views appropriately process_views(); } } -void OrthoViews::set_orientation(int index) // set orientation of single view +void OrthoViews::set_orientation(int index)// set orientation of single view { - double rotation; - int n; // how many 90* rotations from primary view? - gp_Dir dir; // rotate about primary x axis (if in a relative y position) or y axis? - gp_Ax2 cs; + double rotation; + int n; // how many 90* rotations from primary view? + gp_Dir dir;// rotate about primary x axis (if in a relative y position) or y axis? + gp_Ax2 cs; - if (views[index]->ortho) - { - if (views[index]->rel_x != 0) - { + if (views[index]->ortho) { + if (views[index]->rel_x != 0) { dir = primary.YDirection(); n = views[index]->rel_x; } - else - { + else { dir = primary.XDirection(); n = -views[index]->rel_y; } - rotation = n * rotate_coeff * M_PI / 2; // rotate_coeff is -1 or 1 for 1st or 3rd angle + rotation = n * rotate_coeff * M_PI / 2;// rotate_coeff is -1 or 1 for 1st or 3rd angle cs = primary.Rotated(gp_Ax1(gp_Pnt(0, 0, 0), dir), rotation); views[index]->set_projection(cs); } } -void OrthoViews::set_all_orientations() // set orientations of all views (ie projection or primary changed) +void OrthoViews::set_all_orientations()// set orientations of all views (ie projection or primary + // changed) { - for (unsigned int i = 1; i < views.size(); i++) // start from 1 - the 0 is the primary view + for (unsigned int i = 1; i < views.size(); i++)// start from 1 - the 0 is the primary view { - if (views[i]->ortho) + if (views[i]->ortho) { set_orientation(i); - else + } + else { set_Axo(views[i]->rel_x, views[i]->rel_y); + } } } -void OrthoViews::set_projection(int proj) // 1 = 1st angle, 3 = 3rd angle +void OrthoViews::set_projection(int proj)// 1 = 1st angle, 3 = 3rd angle { - if (proj == 3) + if (proj == 3) { rotate_coeff = 1; - else if (proj == 1) + } + else if (proj == 1) { rotate_coeff = -1; + } set_all_orientations(); process_views(); } -void OrthoViews::add_view(int rel_x, int rel_y) // add a new view to the layout +void OrthoViews::add_view(int rel_x, int rel_y)// add a new view to the layout { - if (index(rel_x, rel_y) == -1) - { - orthoview * view = new orthoview(parent_doc, part, page, & bbox); + if (index(rel_x, rel_y) == -1) { + orthoview* view = new orthoview(parent_doc, part, page, &bbox); view->set_data(rel_x, rel_y); views.push_back(view); @@ -618,21 +665,22 @@ void OrthoViews::add_view(int rel_x, int rel_y) // add a new view to views[i]->hidden(hidden); views[i]->smooth(smooth); - if (views[i]->ortho) + if (views[i]->ortho) { set_orientation(i); - else + } + else { set_Axo(rel_x, rel_y); + } process_views(); } } -void OrthoViews::del_view(int rel_x, int rel_y) // remove a view from the layout +void OrthoViews::del_view(int rel_x, int rel_y)// remove a view from the layout { int num = index(rel_x, rel_y); - if (num > 0) - { + if (num > 0) { { boost::signals2::shared_connection_block blocker(connectDocumentDeletedObject); views[num]->deleteme(); @@ -643,9 +691,9 @@ void OrthoViews::del_view(int rel_x, int rel_y) // remove a view fro min_r_x = max_r_x = 0; min_r_y = max_r_y = 0; - for (unsigned int i = 1; i < views.size(); i++) // start from 1 - the 0 is the primary view + for (unsigned int i = 1; i < views.size(); i++)// start from 1 - the 0 is the primary view { - min_r_x = min(min_r_x, views[i]->rel_x); // calculate extremes from remaining views + min_r_x = min(min_r_x, views[i]->rel_x);// calculate extremes from remaining views max_r_x = max(max_r_x, views[i]->rel_x); min_r_y = min(min_r_y, views[i]->rel_y); max_r_y = max(max_r_y, views[i]->rel_y); @@ -661,7 +709,7 @@ void OrthoViews::del_view(int rel_x, int rel_y) // remove a view fro void OrthoViews::del_all() { boost::signals2::shared_connection_block blocker(connectDocumentDeletedObject); - for (int i = views.size() - 1; i >= 0; i--) // count downwards to delete from back + for (int i = views.size() - 1; i >= 0; i--)// count downwards to delete from back { views[i]->deleteme(); delete views[i]; @@ -669,36 +717,38 @@ void OrthoViews::del_all() } } -int OrthoViews::is_Ortho(int rel_x, int rel_y) // is the view at r_x, r_y an ortho or axo one? +int OrthoViews::is_Ortho(int rel_x, int rel_y)// is the view at r_x, r_y an ortho or axo one? { int result = index(rel_x, rel_y); - if (result != -1) + if (result != -1) { result = views[result]->ortho; + } return result; } -int OrthoViews::index(int rel_x, int rel_y) // index in vector of view, -1 if doesn't exist +int OrthoViews::index(int rel_x, int rel_y)// index in vector of view, -1 if doesn't exist { int index = -1; - for (unsigned int i = 0; i < views.size(); i++) - if (views[i]->rel_x == rel_x && views[i]->rel_y == rel_y) - { + for (unsigned int i = 0; i < views.size(); i++) { + if (views[i]->rel_x == rel_x && views[i]->rel_y == rel_y) { index = i; break; } + } return index; } -void OrthoViews::set_Axo_scale(int rel_x, int rel_y, float axo_scale) // set an axo scale independent of ortho ones +void OrthoViews::set_Axo_scale(int rel_x, + int rel_y, + float axo_scale)// set an axo scale independent of ortho ones { int num = index(rel_x, rel_y); - if (num != -1 && !views[num]->ortho) - { + if (num != -1 && !views[num]->ortho) { views[num]->auto_scale = false; views[num]->setScale(axo_scale); views[num]->setPos(); @@ -706,38 +756,41 @@ void OrthoViews::set_Axo_scale(int rel_x, int rel_y, float axo_scale) // s } } -void OrthoViews::set_Axo(int rel_x, int rel_y, gp_Dir up, gp_Dir right, bool away, int axo, bool tri) // set custom axonometric view +void OrthoViews::set_Axo(int rel_x, + int rel_y, + gp_Dir up, + gp_Dir right, + bool away, + int axo, + bool tri)// set custom axonometric view { - double rotations[2]; + double rotations[2]; - if (axo == 0) - { + if (axo == 0) { rotations[0] = -0.7853981633974476; rotations[1] = -0.6154797086703873; } - else if (axo == 1) - { + else if (axo == 1) { rotations[0] = -0.7853981633974476; rotations[1] = -0.2712637537260206; } - else if (tri) - { + else if (tri) { rotations[0] = -1.3088876392502007; rotations[1] = -0.6156624905260762; } - else - { + else { rotations[0] = 1.3088876392502007 - M_PI / 2; rotations[1] = -0.6156624905260762; } - if (away) - rotations[1] = - rotations[1]; + if (away) { + rotations[1] = -rotations[1]; + } - gp_Ax2 cs = gp_Ax2(gp_Pnt(0, 0, 0), right); + gp_Ax2 cs = gp_Ax2(gp_Pnt(0, 0, 0), right); cs.SetYDirection(up); cs.Rotate(gp_Ax1(gp_Pnt(0, 0, 0), up), rotations[0]); - gp_Dir dir; + gp_Dir dir; dir = cs.XDirection(); cs.Rotate(gp_Ax1(gp_Pnt(0, 0, 0), dir), rotations[1]); @@ -757,47 +810,49 @@ void OrthoViews::set_Axo(int rel_x, int rel_y, gp_Dir up, gp_Dir right, bool awa parent_doc->recompute(); } -void OrthoViews::set_Axo(int rel_x, int rel_y) // set view to default axo projection +void OrthoViews::set_Axo(int rel_x, int rel_y)// set view to default axo projection { int num = index(rel_x, rel_y); - if (num != -1) - { - gp_Dir up = primary.YDirection(); // default to view from up and right + if (num != -1) { + gp_Dir up = primary.YDirection();// default to view from up and right gp_Dir right = primary.XDirection(); bool away = false; - if (rel_x * rel_y != 0) // but change default if it's a diagonal position + if (rel_x * rel_y != 0)// but change default if it's a diagonal position { - if (rotate_coeff == 1) // third angle + if (rotate_coeff == 1)// third angle { away = (rel_y < 0); - if (rel_x < 0) + if (rel_x < 0) { right = primary.Direction(); - else + } + else { right = primary.XDirection(); + } } - else // first angle + else// first angle { away = (rel_y > 0); - if (rel_x > 0) + if (rel_x > 0) { right = primary.Direction(); - else + } + else { right = primary.XDirection(); + } } } set_Axo(rel_x, rel_y, up, right, away); } } -void OrthoViews::set_Ortho(int rel_x, int rel_y) // return view to orthographic +void OrthoViews::set_Ortho(int rel_x, int rel_y)// return view to orthographic { int num = index(rel_x, rel_y); - if (num != -1 && rel_x * rel_y == 0) - { + if (num != -1 && rel_x * rel_y == 0) { views[num]->ortho = true; views[num]->setScale(scale); views[num]->auto_scale = true; @@ -808,12 +863,18 @@ void OrthoViews::set_Ortho(int rel_x, int rel_y) // return view to or } } -bool OrthoViews::get_Axo(int rel_x, int rel_y, int & axo, gp_Dir & up, gp_Dir & right, bool & away, bool & tri, float & axo_scale) +bool OrthoViews::get_Axo(int rel_x, + int rel_y, + int& axo, + gp_Dir& up, + gp_Dir& right, + bool& away, + bool& tri, + float& axo_scale) { int num = index(rel_x, rel_y); - if (num != -1 && !views[num]->ortho) - { + if (num != -1 && !views[num]->ortho) { axo = views[num]->axo; up = views[num]->up; right = views[num]->right; @@ -822,21 +883,22 @@ bool OrthoViews::get_Axo(int rel_x, int rel_y, int & axo, gp_Dir & up, gp_Dir & axo_scale = views[num]->getScale(); return true; } - else + else { return false; + } } void OrthoViews::auto_dims(bool setting) { autodims = setting; - if (autodims) + if (autodims) { process_views(); + } } -void OrthoViews::set_configs(float configs[5]) // for autodims off, set scale & positionings +void OrthoViews::set_configs(float configs[5])// for autodims off, set scale & positionings { - if (!autodims) - { + if (!autodims) { scale = configs[0]; offset_x = configs[1]; offset_y = configs[2]; @@ -846,7 +908,7 @@ void OrthoViews::set_configs(float configs[5]) // for autodims off, } } -void OrthoViews::get_configs(float configs[5]) // get scale & positionings +void OrthoViews::get_configs(float configs[5])// get scale & positionings { configs[0] = scale; configs[1] = offset_x; @@ -859,22 +921,24 @@ void OrthoViews::get_configs(float configs[5]) // get scale & posit /////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// -TaskOrthoViews::TaskOrthoViews(QWidget *parent) - : ui(new Ui_TaskOrthoViews) +TaskOrthoViews::TaskOrthoViews(QWidget* parent) + : ui(new Ui_TaskOrthoViews) { Q_UNUSED(parent); ui->setupUi(this); - std::vector obj = Gui::Selection().getObjectsOfType(Part::Feature::getClassTypeId()); - const char * part = obj.front()->getNameInDocument(); + std::vector obj = + Gui::Selection().getObjectsOfType(Part::Feature::getClassTypeId()); + const char* part = obj.front()->getNameInDocument(); - App::Document * doc = App::GetApplication().getActiveDocument(); - std::vector pages = Gui::Selection().getObjectsOfType(Drawing::FeaturePage::getClassTypeId()); + App::Document* doc = App::GetApplication().getActiveDocument(); + std::vector pages = + Gui::Selection().getObjectsOfType(Drawing::FeaturePage::getClassTypeId()); if (pages.empty()) { pages = doc->getObjectsOfType(Drawing::FeaturePage::getClassTypeId()); } std::string PageName = pages.front()->getNameInDocument(); - const char * page = PageName.c_str(); + const char* page = PageName.c_str(); // ********************************************************************** @@ -884,28 +948,30 @@ TaskOrthoViews::TaskOrthoViews(QWidget *parent) // ********************************************************************** // [x+2][y+2] - c_boxes[0][2] = ui->cb02; //left most, x = -2, y = 0 + c_boxes[0][2] = ui->cb02;// left most, x = -2, y = 0 c_boxes[1][1] = ui->cb11; c_boxes[1][2] = ui->cb12; c_boxes[1][3] = ui->cb13; - c_boxes[2][0] = ui->cb20; //top most, x = 0, y = -2 + c_boxes[2][0] = ui->cb20;// top most, x = 0, y = -2 c_boxes[2][1] = ui->cb21; - c_boxes[2][2] = ui->cb22; //centre (primary view) checkbox x = y = 0. + c_boxes[2][2] = ui->cb22;// centre (primary view) checkbox x = y = 0. c_boxes[2][3] = ui->cb23; - c_boxes[2][4] = ui->cb24; //bottom most, x = 0, y = 2 + c_boxes[2][4] = ui->cb24;// bottom most, x = 0, y = 2 c_boxes[3][1] = ui->cb31; c_boxes[3][2] = ui->cb32; c_boxes[3][3] = ui->cb33; - c_boxes[4][2] = ui->cb42; //right most, x = 2, y = 0 + c_boxes[4][2] = ui->cb42;// right most, x = 2, y = 0 - for (int i=0; i < 5; i++) - { - for (int j=0; j < 5; j++) - { - if ((abs(i-2) + abs(j-2)) < 3) //if i,j combination corresponds to valid check box, then proceed with: + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { + if ((abs(i - 2) + abs(j - 2)) + < 3)// if i,j combination corresponds to valid check box, then proceed with: { connect(c_boxes[i][j], SIGNAL(toggled(bool)), this, SLOT(cb_toggled(bool))); - connect(c_boxes[i][j], SIGNAL(customContextMenuRequested(const QPoint&)),this, SLOT(ShowContextMenu(const QPoint&))); + connect(c_boxes[i][j], + SIGNAL(customContextMenuRequested(const QPoint&)), + this, + SLOT(ShowContextMenu(const QPoint&))); } } } @@ -917,9 +983,11 @@ TaskOrthoViews::TaskOrthoViews(QWidget *parent) inputs[3] = ui->spacing_h_3; inputs[4] = ui->spacing_v_4; - for (int i=0; i < 5; i++) - { - connect(inputs[i], SIGNAL(textEdited(const QString &)), this, SLOT(data_entered(const QString &))); + for (int i = 0; i < 5; i++) { + connect(inputs[i], + SIGNAL(textEdited(const QString&)), + this, + SLOT(data_entered(const QString&))); connect(inputs[i], SIGNAL(returnPressed()), this, SLOT(text_return())); } @@ -936,10 +1004,13 @@ TaskOrthoViews::TaskOrthoViews(QWidget *parent) connect(ui->axoRight, SIGNAL(activated(int)), this, SLOT(change_axo(int))); connect(ui->vert_flip, SIGNAL(clicked()), this, SLOT(axo_button())); connect(ui->tri_flip, SIGNAL(clicked()), this, SLOT(axo_button())); - connect(ui->axoScale, SIGNAL(textEdited(const QString &)), this, SLOT(axo_scale(const QString &))); + connect(ui->axoScale, + SIGNAL(textEdited(const QString&)), + this, + SLOT(axo_scale(const QString&))); connect(ui->axoScale, SIGNAL(returnPressed()), this, SLOT(text_return())); - ui->tabWidget->setTabEnabled(1,false); + ui->tabWidget->setTabEnabled(1, false); gp_Dir facing = gp_Dir(1, 0, 0); gp_Dir right = gp_Dir(0, 1, 0); @@ -947,7 +1018,7 @@ TaskOrthoViews::TaskOrthoViews(QWidget *parent) orthos->set_primary(facing, right); txt_return = false; -} //end of constructor +}// end of constructor TaskOrthoViews::~TaskOrthoViews() { @@ -964,29 +1035,28 @@ void TaskOrthoViews::ShowContextMenu(const QPoint& pos) letter = name.toStdString()[1]; int dy = letter - '0' - 2; - if (c_boxes[dx + 2][dy + 2]->isChecked()) - { + if (c_boxes[dx + 2][dy + 2]->isChecked()) { QString str_1 = QObject::tr("Make axonometric..."); QString str_2 = QObject::tr("Edit axonometric settings..."); QString str_3 = QObject::tr("Make orthographic"); QPoint globalPos = c_boxes[dx + 2][dy + 2]->mapToGlobal(pos); QMenu myMenu; - if (orthos->is_Ortho(dx, -dy)) + if (orthos->is_Ortho(dx, -dy)) { myMenu.addAction(str_1); - else - { + } + else { myMenu.addAction(str_2); - if (dx * dy == 0) + if (dx * dy == 0) { myMenu.addAction(str_3); + } } - QAction * selectedItem = myMenu.exec(globalPos); - if (selectedItem) - { + QAction* selectedItem = myMenu.exec(globalPos); + if (selectedItem) { QString text = selectedItem->text(); - if (text == str_1) // make axo + if (text == str_1)// make axo { orthos->set_Axo(dx, -dy); axo_r_x = dx; @@ -995,7 +1065,7 @@ void TaskOrthoViews::ShowContextMenu(const QPoint& pos) ui->tabWidget->setCurrentIndex(1); setup_axo_tab(); } - else if (text == str_2) // edit axo + else if (text == str_2)// edit axo { axo_r_x = dx; axo_r_y = dy; @@ -1003,11 +1073,10 @@ void TaskOrthoViews::ShowContextMenu(const QPoint& pos) ui->tabWidget->setCurrentIndex(1); setup_axo_tab(); } - else if (text == str_3) // make ortho + else if (text == str_3)// make ortho { orthos->set_Ortho(dx, -dy); - if (dx == axo_r_x && dy == axo_r_y) - { + if (dx == axo_r_x && dy == axo_r_y) { axo_r_x = 0; axo_r_y = 0; ui->tabWidget->setTabEnabled(1, false); @@ -1017,7 +1086,7 @@ void TaskOrthoViews::ShowContextMenu(const QPoint& pos) } } -void TaskOrthoViews::changeEvent(QEvent *e) +void TaskOrthoViews::changeEvent(QEvent* e) { if (e->type() == QEvent::LanguageChange) { ui->retranslateUi(this); @@ -1033,10 +1102,9 @@ void TaskOrthoViews::cb_toggled(bool toggle) letter = name.toStdString()[1]; int dy = letter - '0' - 2; - if (toggle) - { + if (toggle) { orthos->add_view(dx, -dy); - if (dx * dy != 0) // adding an axo view + if (dx * dy != 0)// adding an axo view { axo_r_x = dx; axo_r_y = dy; @@ -1045,11 +1113,11 @@ void TaskOrthoViews::cb_toggled(bool toggle) setup_axo_tab(); } } - else // removing a view + else// removing a view { - if (!orthos->is_Ortho(dx, -dy)) // is it an axo one? + if (!orthos->is_Ortho(dx, -dy))// is it an axo one? { - if (dx == axo_r_x && dy == axo_r_y) // is it the one currently being edited? + if (dx == axo_r_x && dy == axo_r_y)// is it the one currently being edited? { axo_r_x = 0; axo_r_y = 0; @@ -1064,7 +1132,7 @@ void TaskOrthoViews::cb_toggled(bool toggle) void TaskOrthoViews::projectionChanged(int index) { - int proj = 3 - 2 * index; // index = 0 = third angle + int proj = 3 - 2 * index;// index = 0 = third angle orthos->set_projection(proj); set_configs(); @@ -1072,22 +1140,24 @@ void TaskOrthoViews::projectionChanged(int index) void TaskOrthoViews::setPrimary(int /*dir*/) { - int p_sel = ui->view_from->currentIndex(); // index for entry selected for 'view from' - int r_sel = ui->axis_right->currentIndex(); // index for entry selected for 'rightwards axis' + int p_sel = ui->view_from->currentIndex(); // index for entry selected for 'view from' + int r_sel = ui->axis_right->currentIndex();// index for entry selected for 'rightwards axis' - int p_vec[3] = {0, 0, 0}; // will be the vector for 'view from' - int r_vec[3] = {0, 0, 0}; // will be vector for 'rightwards axis' + int p_vec[3] = {0, 0, 0};// will be the vector for 'view from' + int r_vec[3] = {0, 0, 0};// will be vector for 'rightwards axis' int r[2] = {0, 1}; - int pos = 1 - 2 * int(p_sel / 3); // 1 if p_sel = 0, 1, 2 or -1 if p_sel = 3, 4, 5 - p_sel = p_sel % 3; // p_sel = 0, 1, 2 + int pos = 1 - 2 * int(p_sel / 3);// 1 if p_sel = 0, 1, 2 or -1 if p_sel = 3, 4, 5 + p_sel = p_sel % 3; // p_sel = 0, 1, 2 p_vec[p_sel] = pos; - for (int i = p_sel; i < 2; i++) // make r[2] to be, {0, 1}, {0, 2}, or {1, 2} depending upon p_sel + for (int i = p_sel; i < 2; + i++) {// make r[2] to be, {0, 1}, {0, 2}, or {1, 2} depending upon p_sel r[i] += 1; + } - pos = 1 - 2 * int(r_sel / 2); // 1 if r_sel = 0, 1 or -1 if r_sel = 3, 4 - r_sel = r_sel % 2; // r_sel = 0, 1 + pos = 1 - 2 * int(r_sel / 2);// 1 if r_sel = 0, 1 or -1 if r_sel = 3, 4 + r_sel = r_sel % 2; // r_sel = 0, 1 r_vec[r[r_sel]] = pos; gp_Dir facing = gp_Dir(p_vec[0], p_vec[1], p_vec[2]); @@ -1096,13 +1166,14 @@ void TaskOrthoViews::setPrimary(int /*dir*/) orthos->set_primary(facing, right); // update rightwards combobox in case of 'view from' change - if (sender() == ui->view_from) - { + if (sender() == ui->view_from) { disconnect(ui->axis_right, SIGNAL(currentIndexChanged(int)), this, SLOT(setPrimary(int))); QStringList items; - items << QString::fromUtf8("X +ve") << QString::fromUtf8("Y +ve") << QString::fromUtf8("Z +ve"); - items << QString::fromUtf8("X -ve") << QString::fromUtf8("Y -ve") << QString::fromUtf8("Z -ve"); + items << QString::fromUtf8("X +ve") << QString::fromUtf8("Y +ve") + << QString::fromUtf8("Z +ve"); + items << QString::fromUtf8("X -ve") << QString::fromUtf8("Y -ve") + << QString::fromUtf8("Z -ve"); items.removeAt(p_sel + 3); items.removeAt(p_sel); @@ -1129,30 +1200,31 @@ void TaskOrthoViews::smooth(int i) void TaskOrthoViews::toggle_auto(int i) { - if (i == 2) //auto scale switched on + if (i == 2)// auto scale switched on { orthos->auto_dims(true); ui->label_4->setEnabled(false); ui->label_5->setEnabled(false); ui->label_6->setEnabled(false); - for (int j = 0; j < 5; j++) - inputs[j]->setEnabled(false); //disable user input boxes + for (int j = 0; j < 5; j++) { + inputs[j]->setEnabled(false);// disable user input boxes + } } - else - { + else { orthos->auto_dims(false); ui->label_4->setEnabled(true); ui->label_5->setEnabled(true); ui->label_6->setEnabled(true); - for (int j = 0; j < 5; j++) - inputs[j]->setEnabled(true); //enable user input boxes + for (int j = 0; j < 5; j++) { + inputs[j]->setEnabled(true);// enable user input boxes + } set_configs(); } } -void TaskOrthoViews::data_entered(const QString & text) +void TaskOrthoViews::data_entered(const QString& text) { bool ok; QString name = sender()->objectName().right(1); @@ -1161,13 +1233,11 @@ void TaskOrthoViews::data_entered(const QString & text) float value = text.toFloat(&ok); - if (ok) - { + if (ok) { data[index] = value; orthos->set_configs(data); } - else - { + else { inputs[index]->setText(QString::number(data[index])); return; } @@ -1180,33 +1250,41 @@ void TaskOrthoViews::clean_up() void TaskOrthoViews::setup_axo_tab() { - int axo; - gp_Dir up, right; - bool away, tri; - float axo_scale; - int up_n, right_n; + int axo; + gp_Dir up, right; + bool away, tri; + float axo_scale; + int up_n, right_n; orthos->get_Axo(axo_r_x, -axo_r_y, axo, up, right, away, tri, axo_scale); // convert gp_Dirs into selections of comboboxes - if (up.X() != 0) + if (up.X() != 0) { up_n = (up.X() == -1) ? 3 : 0; - else if (up.Y() != 0) + } + else if (up.Y() != 0) { up_n = (up.Y() == -1) ? 4 : 1; - else + } + else { up_n = (up.Z() == -1) ? 5 : 2; + } - if (right.X() != 0) + if (right.X() != 0) { right_n = (right.X() == -1) ? 3 : 0; - else if (right.Y() != 0) + } + else if (right.Y() != 0) { right_n = (right.Y() == -1) ? 4 : 1; - else + } + else { right_n = (right.Z() == -1) ? 5 : 2; + } - if (right_n > (up_n % 3 + 3)) + if (right_n > (up_n % 3 + 3)) { right_n -= 2; - else if (right_n > up_n) + } + else if (right_n > up_n) { right_n -= 1; + } QStringList items; items << QString::fromUtf8("X +ve") << QString::fromUtf8("Y +ve") << QString::fromUtf8("Z +ve"); @@ -1227,19 +1305,20 @@ void TaskOrthoViews::setup_axo_tab() void TaskOrthoViews::change_axo(int /*p*/) { - int u_sel = ui->axoUp->currentIndex(); // index for entry selected for 'view from' - int r_sel = ui->axoRight->currentIndex(); // index for entry selected for 'rightwards axis' + int u_sel = ui->axoUp->currentIndex(); // index for entry selected for 'view from' + int r_sel = ui->axoRight->currentIndex();// index for entry selected for 'rightwards axis' - int u_vec[3] = {0, 0, 0}; // will be the vector for 'view from' - int r_vec[3] = {0, 0, 0}; // will be vector for 'rightwards axis' + int u_vec[3] = {0, 0, 0};// will be the vector for 'view from' + int r_vec[3] = {0, 0, 0};// will be vector for 'rightwards axis' int r[2] = {0, 1}; - int pos = 1 - 2 * int(u_sel / 3); // 1 if p_sel = 0,1,2 or -1 if p_sel = 3,4,5 - u_sel = u_sel % 3; // p_sel = 0,1,2 + int pos = 1 - 2 * int(u_sel / 3);// 1 if p_sel = 0,1,2 or -1 if p_sel = 3,4,5 + u_sel = u_sel % 3; // p_sel = 0,1,2 u_vec[u_sel] = pos; - for (int i = u_sel; i < 2; i++) + for (int i = u_sel; i < 2; i++) { r[i] += 1; + } pos = 1 - 2 * int(r_sel / 2); r_sel = r_sel % 2; @@ -1248,12 +1327,20 @@ void TaskOrthoViews::change_axo(int /*p*/) gp_Dir up = gp_Dir(u_vec[0], u_vec[1], u_vec[2]); gp_Dir right = gp_Dir(r_vec[0], r_vec[1], r_vec[2]); - orthos->set_Axo(axo_r_x, -axo_r_y, up, right, ui->vert_flip->isChecked(), ui->axoProj->currentIndex(), ui->tri_flip->isChecked()); + orthos->set_Axo(axo_r_x, + -axo_r_y, + up, + right, + ui->vert_flip->isChecked(), + ui->axoProj->currentIndex(), + ui->tri_flip->isChecked()); - if (ui->axoProj->currentIndex() == 2) + if (ui->axoProj->currentIndex() == 2) { ui->tri_flip->setEnabled(true); - else + } + else { ui->tri_flip->setEnabled(false); + } QStringList items; @@ -1272,33 +1359,36 @@ void TaskOrthoViews::axo_button() change_axo(); } -void TaskOrthoViews::axo_scale(const QString & text) +void TaskOrthoViews::axo_scale(const QString& text) { bool ok; float value = text.toFloat(&ok); - if (ok) + if (ok) { orthos->set_Axo_scale(axo_r_x, -axo_r_y, value); + } } void TaskOrthoViews::set_configs() { orthos->get_configs(data); - for (int i = 0; i < 5; i++) + for (int i = 0; i < 5; i++) { inputs[i]->setText(QString::number(data[i])); + } } bool TaskOrthoViews::user_input() { - if (txt_return) - { - txt_return = false; // return was pressed while text box had focus - ui->label_7->setFocus(); // move focus out of text box - return true; // return that we were editing + if (txt_return) { + txt_return = false; // return was pressed while text box had focus + ui->label_7->setFocus();// move focus out of text box + return true; // return that we were editing + } + else { + return false;// return that we weren't editing ---> treat as clicking OK... we can close the + // GUI } - else - return false; // return that we weren't editing ---> treat as clicking OK... we can close the GUI } void TaskOrthoViews::text_return() @@ -1315,33 +1405,33 @@ TaskDlgOrthoViews::TaskDlgOrthoViews() : TaskDialog() { widget = new TaskOrthoViews(); - taskbox = new Gui::TaskView::TaskBox( - Gui::BitmapFactory().pixmap("actions/drawing-orthoviews"), widget->windowTitle(), true, nullptr); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/drawing-orthoviews"), + widget->windowTitle(), + true, + nullptr); taskbox->groupLayout()->addWidget(widget); Content.push_back(taskbox); } TaskDlgOrthoViews::~TaskDlgOrthoViews() -{ -} +{} //==== calls from the TaskView =============================================================== void TaskDlgOrthoViews::open() -{ -} +{} void TaskDlgOrthoViews::clicked(int) -{ -} +{} bool TaskDlgOrthoViews::accept() { bool check = widget->user_input(); App::Document* doc = App::GetApplication().getDocument(this->getDocumentName().c_str()); - if (doc) + if (doc) { doc->commitTransaction(); + } return !check; } @@ -1349,8 +1439,9 @@ bool TaskDlgOrthoViews::reject() { widget->clean_up(); App::Document* doc = App::GetApplication().getDocument(this->getDocumentName().c_str()); - if (doc) + if (doc) { doc->abortTransaction(); + } return true; } diff --git a/src/Mod/Drawing/Gui/TaskOrthoViews.h b/src/Mod/Drawing/Gui/TaskOrthoViews.h index d680770beb..aa79cecdc8 100644 --- a/src/Mod/Drawing/Gui/TaskOrthoViews.h +++ b/src/Mod/Drawing/Gui/TaskOrthoViews.h @@ -36,175 +36,198 @@ #include -namespace DrawingGui { +namespace DrawingGui +{ class Ui_TaskOrthoViews; class orthoview { public: - orthoview(App::Document * parent, App::DocumentObject * part, App::DocumentObject * page, Base::BoundBox3d * partbox); + orthoview(App::Document* parent, + App::DocumentObject* part, + App::DocumentObject* page, + Base::BoundBox3d* partbox); ~orthoview(); - void set_data(int r_x, int r_y); - void set_projection(const gp_Ax2& cs); - void setPos(float = 0, float = 0); - void setScale(float newscale); - float getScale(); - void deleteme(); - void hidden(bool); - void smooth(bool); + void set_data(int r_x, int r_y); + void set_projection(const gp_Ax2& cs); + void setPos(float = 0, float = 0); + void setScale(float newscale); + float getScale(); + void deleteme(); + void hidden(bool); + void smooth(bool); - App::DocumentObject* getViewPart() { + App::DocumentObject* getViewPart() + { return this_view; } private: - void calcCentre(); + void calcCentre(); -public: // these aren't used by orthoView, but just informational, hence public - bool ortho; // orthonometric? or axonometric - bool auto_scale; // scale for axonometric has not been manually changed? - int rel_x, rel_y; // relative position of this view - bool away, tri; // binary parameters for axonometric view - int axo; // 0 / 1 / 2 = iso / di / tri metric - gp_Dir up, right; // directions prior to rotations (ie, what was used to orientate the projection) +public: // these aren't used by orthoView, but just informational, hence public + bool ortho; // orthonometric? or axonometric + bool auto_scale; // scale for axonometric has not been manually changed? + int rel_x, rel_y;// relative position of this view + bool away, tri; // binary parameters for axonometric view + int axo; // 0 / 1 / 2 = iso / di / tri metric + gp_Dir up, + right;// directions prior to rotations (ie, what was used to orientate the projection) private: - App::Document * parent_doc; - Drawing::FeatureViewPart * this_view; + App::Document* parent_doc; + Drawing::FeatureViewPart* this_view; - std::string myname; - float x, y; // 2D projection coords of bbox centre relative to origin - float cx, cy, cz; // coords of bbox centre in 3D space - float pageX, pageY; // required coords of centre of bbox projection on page - float scale; // scale of projection - gp_Dir X_dir, Y_dir, Z_dir; // directions of projection, X_dir makes x on page, Y_dir is y on page, Z_dir is out of page + std::string myname; + float x, y; // 2D projection coords of bbox centre relative to origin + float cx, cy, cz; // coords of bbox centre in 3D space + float pageX, pageY; // required coords of centre of bbox projection on page + float scale; // scale of projection + gp_Dir X_dir, Y_dir, Z_dir;// directions of projection, X_dir makes x on page, Y_dir is y on + // page, Z_dir is out of page }; class OrthoViews { public: - OrthoViews(App::Document*, const char * pagename, const char * partname); + OrthoViews(App::Document*, const char* pagename, const char* partname); ~OrthoViews(); - void set_primary(gp_Dir facing, gp_Dir right); - void add_view(int rel_x, int rel_y); - void del_view(int rel_x, int rel_y); - void del_all(); - void set_projection(int proj); - void set_hidden(bool state); - void set_smooth(bool state); - void set_Axo(int rel_x, int rel_y, gp_Dir up, gp_Dir right, bool away = false, int axo = 0, bool tri = false); - void set_Axo(int rel_x, int rel_y); - void set_Axo_scale(int rel_x, int rel_y, float axo_scale); - void set_Ortho(int rel_x, int rel_y); - int is_Ortho(int rel_x, int rel_y); - bool get_Axo(int rel_x, int rel_y, int & axo, gp_Dir & up, gp_Dir & right, bool & away, bool & tri, float & axo_scale); - void auto_dims(bool setting); - void set_configs(float configs[5]); - void get_configs(float configs[5]); + void set_primary(gp_Dir facing, gp_Dir right); + void add_view(int rel_x, int rel_y); + void del_view(int rel_x, int rel_y); + void del_all(); + void set_projection(int proj); + void set_hidden(bool state); + void set_smooth(bool state); + void set_Axo(int rel_x, + int rel_y, + gp_Dir up, + gp_Dir right, + bool away = false, + int axo = 0, + bool tri = false); + void set_Axo(int rel_x, int rel_y); + void set_Axo_scale(int rel_x, int rel_y, float axo_scale); + void set_Ortho(int rel_x, int rel_y); + int is_Ortho(int rel_x, int rel_y); + bool get_Axo(int rel_x, + int rel_y, + int& axo, + gp_Dir& up, + gp_Dir& right, + bool& away, + bool& tri, + float& axo_scale); + void auto_dims(bool setting); + void set_configs(float configs[5]); + void get_configs(float configs[5]); private: - void set_orientation(int index); - void load_page(); // get page / titleblock dims from template - void choose_page(); // determine correct portion of page to use to avoid interference with title block - void set_all_orientations(); // update orientations of all views following change in primary view - void calc_layout_size(); // what's the real world size of chosen layout, excluding spaces - void calc_offsets(); - void set_views(); - void calc_scale(); - void process_views(); - int index(int rel_x, int rel_y); - void slotDeletedObject(const App::DocumentObject& Obj); - void slotDeletedDocument(const App::Document& Obj); + void set_orientation(int index); + void load_page();// get page / titleblock dims from template + void + choose_page();// determine correct portion of page to use to avoid interference with title block + void set_all_orientations();// update orientations of all views following change in primary view + void calc_layout_size(); // what's the real world size of chosen layout, excluding spaces + void calc_offsets(); + void set_views(); + void calc_scale(); + void process_views(); + int index(int rel_x, int rel_y); + void slotDeletedObject(const App::DocumentObject& Obj); + void slotDeletedDocument(const App::Document& Obj); private: - std::vector views; - Base::BoundBox3d bbox; - App::Document * parent_doc; - App::DocumentObject * part; - App::DocumentObject * page; + std::vector views; + Base::BoundBox3d bbox; + App::Document* parent_doc; + App::DocumentObject* part; + App::DocumentObject* page; - int large[4]; // arrays containing page size info [margin_x, margin_y, size_x, size_y] = [x1, y1, x2-x1, y2-y1] - int small_h[4], small_v[4]; // page size avoiding title block, using maximum horizontal / vertical space - int * page_dims; // points to one of above arrays for which set of page dimensions to use - int block[4]; // title block info [corner x, corner y, width, height], eg [-1, 1, w, h] is in top left corner - bool title; - int * horiz, * vert; // points to min or max r_x / r_y depending upon which corner title block is in + int large[4];// arrays containing page size info [margin_x, margin_y, size_x, size_y] = [x1, y1, + // x2-x1, y2-y1] + int small_h[4], + small_v[4];// page size avoiding title block, using maximum horizontal / vertical space + int* page_dims;// points to one of above arrays for which set of page dimensions to use + int block[4];// title block info [corner x, corner y, width, height], eg [-1, 1, w, h] is in top + // left corner + bool title; + int *horiz, + *vert;// points to min or max r_x / r_y depending upon which corner title block is in - int rotate_coeff; // 1st (= -1) or 3rd (= 1) angle - int min_r_x, max_r_x; // extreme relative positions of views - int min_r_y, max_r_y; // " " " - float width, height, depth; // of non-scaled primary view - float layout_width, layout_height; // of non-scaled layout without spaces - float gap_x, gap_y, min_space; // required spacing between views - float offset_x, offset_y; // coords of centre of upper left view - float scale; - int num_gaps_x, num_gaps_y; // how many gaps between views/edges? = num of views in given direction + 1 - gp_Ax2 primary; // coord system of primary view + int rotate_coeff; // 1st (= -1) or 3rd (= 1) angle + int min_r_x, max_r_x; // extreme relative positions of views + int min_r_y, max_r_y; // " " " + float width, height, depth; // of non-scaled primary view + float layout_width, layout_height;// of non-scaled layout without spaces + float gap_x, gap_y, min_space; // required spacing between views + float offset_x, offset_y; // coords of centre of upper left view + float scale; + int num_gaps_x, + num_gaps_y;// how many gaps between views/edges? = num of views in given direction + 1 + gp_Ax2 primary;// coord system of primary view - bool hidden, smooth; - bool autodims; + bool hidden, smooth; + bool autodims; boost::signals2::scoped_connection connectDocumentDeletedObject; boost::signals2::scoped_connection connectApplicationDeletedDocument; }; - - -class TaskOrthoViews : public QWidget//: public Gui::TaskView::TaskBox +class TaskOrthoViews: public QWidget//: public Gui::TaskView::TaskBox { Q_OBJECT public: - TaskOrthoViews(QWidget *parent = nullptr); + TaskOrthoViews(QWidget* parent = nullptr); ~TaskOrthoViews(); bool user_input(); void clean_up(); protected Q_SLOTS: - void ShowContextMenu(const QPoint & pos); + void ShowContextMenu(const QPoint& pos); void setPrimary(int dir); void cb_toggled(bool toggle); void projectionChanged(int index); void hidden(int i); void smooth(int i); void toggle_auto(int i); - void data_entered(const QString & text); + void data_entered(const QString& text); void change_axo(int p = 3); void axo_button(); - void axo_scale(const QString & text); + void axo_scale(const QString& text); void text_return(); protected: - void changeEvent(QEvent * e); + void changeEvent(QEvent* e); private: void setup_axo_tab(); void set_configs(); private: - //class Private; - Ui_TaskOrthoViews * ui; + // class Private; + Ui_TaskOrthoViews* ui; - OrthoViews * orthos; - QCheckBox * c_boxes[5][5]; // matrix of pointers to gui checkboxes - QLineEdit * inputs[5]; // pointers to manual position/scale boxes + OrthoViews* orthos; + QCheckBox* c_boxes[5][5];// matrix of pointers to gui checkboxes + QLineEdit* inputs[5]; // pointers to manual position/scale boxes - float data[5]; // scale, x_pos, y_pos, horiz, vert - int axo_r_x, axo_r_y; // relative position of axo view currently being edited - bool txt_return; // flag to show if return was pressed while editing a text box; + float data[5]; // scale, x_pos, y_pos, horiz, vert + int axo_r_x, axo_r_y;// relative position of axo view currently being edited + bool txt_return; // flag to show if return was pressed while editing a text box; }; ////////////////////////////////////////////////////////////// - /// simulation dialog for the TaskView -class TaskDlgOrthoViews : public Gui::TaskView::TaskDialog +class TaskDlgOrthoViews: public Gui::TaskView::TaskDialog { Q_OBJECT @@ -219,12 +242,11 @@ public: void clicked(int); private: - TaskOrthoViews * widget; + TaskOrthoViews* widget; Gui::TaskView::TaskBox* taskbox; }; -} //namespace DrawingGui +}// namespace DrawingGui -#endif // GUI_TASKVIEW_OrthoViews_H - +#endif// GUI_TASKVIEW_OrthoViews_H diff --git a/src/Mod/Drawing/Gui/ViewProviderPage.cpp b/src/Mod/Drawing/Gui/ViewProviderPage.cpp index 46d80d2b06..f8ddd3930e 100644 --- a/src/Mod/Drawing/Gui/ViewProviderPage.cpp +++ b/src/Mod/Drawing/Gui/ViewProviderPage.cpp @@ -22,8 +22,8 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include +#include +#include #endif #include @@ -45,12 +45,12 @@ PROPERTY_SOURCE(DrawingGui::ViewProviderDrawingPage, Gui::ViewProviderDocumentOb // Construction/Destruction ViewProviderDrawingPage::ViewProviderDrawingPage() - : view(nullptr) + : view(nullptr) { sPixmap = "Page"; - ADD_PROPERTY(HintScale,(10.0)); - ADD_PROPERTY(HintOffsetX,(10.0)); - ADD_PROPERTY(HintOffsetY,(10.0)); + ADD_PROPERTY(HintScale, (10.0)); + ADD_PROPERTY(HintOffsetX, (10.0)); + ADD_PROPERTY(HintOffsetY, (10.0)); // do not show this in the property editor Visibility.setStatus(App::Property::Hidden, true); @@ -58,10 +58,9 @@ ViewProviderDrawingPage::ViewProviderDrawingPage() } ViewProviderDrawingPage::~ViewProviderDrawingPage() -{ -} +{} -void ViewProviderDrawingPage::attach(App::DocumentObject *pcFeat) +void ViewProviderDrawingPage::attach(App::DocumentObject* pcFeat) { // call parent attach method ViewProviderDocumentObject::attach(pcFeat); @@ -109,25 +108,26 @@ void ViewProviderDrawingPage::updateData(const App::Property* prop) if (std::string(getPageObject()->PageResult.getValue()) != "") { if (view) { view->load(QString::fromUtf8(getPageObject()->PageResult.getValue())); - if (view->isHidden()) + if (view->isHidden()) { QTimer::singleShot(300, view, SLOT(viewAll())); - else + } + else { view->viewAll(); + } } } } else if (pcObject && prop == &pcObject->Label) { - if (view){ + if (view) { const char* objname = pcObject->Label.getValue(); view->setObjectName(QString::fromUtf8(objname)); - Gui::Document* doc = Gui::Application::Instance->getDocument - (pcObject->getDocument()); + Gui::Document* doc = Gui::Application::Instance->getDocument(pcObject->getDocument()); view->onRelabel(doc); } } } -bool ViewProviderDrawingPage::onDelete(const std::vector & items) +bool ViewProviderDrawingPage::onDelete(const std::vector& items) { if (view) { view->parentWidget()->deleteLater(); @@ -157,9 +157,8 @@ bool ViewProviderDrawingPage::doubleClicked(void) DrawingView* ViewProviderDrawingPage::showDrawingView() { - if (!view){ - Gui::Document* doc = Gui::Application::Instance->getDocument - (this->pcObject->getDocument()); + if (!view) { + Gui::Document* doc = Gui::Application::Instance->getDocument(this->pcObject->getDocument()); view = new DrawingView(doc, Gui::getMainWindow()); view->setWindowIcon(Gui::BitmapFactory().pixmap("actions/drawing-landscape")); diff --git a/src/Mod/Drawing/Gui/ViewProviderPage.h b/src/Mod/Drawing/Gui/ViewProviderPage.h index d646d3549b..017ba4d941 100644 --- a/src/Mod/Drawing/Gui/ViewProviderPage.h +++ b/src/Mod/Drawing/Gui/ViewProviderPage.h @@ -30,14 +30,16 @@ #include "DrawingView.h" -namespace Drawing{ - class FeaturePage; +namespace Drawing +{ +class FeaturePage; } -namespace DrawingGui { +namespace DrawingGui +{ -class DrawingGuiExport ViewProviderDrawingPage : public Gui::ViewProviderDocumentObjectGroup +class DrawingGuiExport ViewProviderDrawingPage: public Gui::ViewProviderDocumentObjectGroup { PROPERTY_HEADER(DrawingGui::ViewProviderDrawingPage); @@ -47,13 +49,16 @@ public: /// destructor virtual ~ViewProviderDrawingPage(); - App::PropertyFloat HintScale; - App::PropertyFloat HintOffsetX; - App::PropertyFloat HintOffsetY; + App::PropertyFloat HintScale; + App::PropertyFloat HintOffsetX; + App::PropertyFloat HintOffsetY; - virtual void attach(App::DocumentObject *); + virtual void attach(App::DocumentObject*); virtual void setDisplayMode(const char* ModeName); - virtual bool useNewSelectionModel(void) const {return false;} + virtual bool useNewSelectionModel(void) const + { + return false; + } /// returns a list of all possible modes virtual std::vector getDisplayModes(void) const; /// Hides the view provider @@ -65,7 +70,7 @@ public: virtual bool doubleClicked(void); void setupContextMenu(QMenu*, QObject*, const char*); virtual void updateData(const App::Property*); - virtual bool onDelete(const std::vector &); + virtual bool onDelete(const std::vector&); Drawing::FeaturePage* getPageObject() const; @@ -77,8 +82,7 @@ private: QPointer view; }; -} // namespace DrawingGui +}// namespace DrawingGui -#endif // DRAWINGGUI_VIEWPROVIDERPAGE_H - +#endif// DRAWINGGUI_VIEWPROVIDERPAGE_H diff --git a/src/Mod/Drawing/Gui/ViewProviderView.cpp b/src/Mod/Drawing/Gui/ViewProviderView.cpp index 2a20ca8c62..441329b620 100644 --- a/src/Mod/Drawing/Gui/ViewProviderView.cpp +++ b/src/Mod/Drawing/Gui/ViewProviderView.cpp @@ -42,10 +42,9 @@ ViewProviderDrawingView::ViewProviderDrawingView() } ViewProviderDrawingView::~ViewProviderDrawingView() -{ -} +{} -void ViewProviderDrawingView::attach(App::DocumentObject *pcFeat) +void ViewProviderDrawingView::attach(App::DocumentObject* pcFeat) { // call parent attach method ViewProviderDocumentObject::attach(pcFeat); @@ -67,15 +66,17 @@ void ViewProviderDrawingView::show(void) ViewProviderDocumentObject::show(); App::DocumentObject* obj = getObject(); - if (!obj || obj->isRestoring()) + if (!obj || obj->isRestoring()) { return; + } if (obj->getTypeId().isDerivedFrom(Drawing::FeatureView::getClassTypeId())) { // The 'Visible' property is marked as 'Output'. To update the drawing on recompute // the parent page object is touched. static_cast(obj)->Visible.setValue(true); std::vector inp = obj->getInList(); - for (std::vector::iterator it = inp.begin(); it != inp.end(); ++it) + for (std::vector::iterator it = inp.begin(); it != inp.end(); ++it) { (*it)->touch(); + } } } @@ -84,15 +85,17 @@ void ViewProviderDrawingView::hide(void) ViewProviderDocumentObject::hide(); App::DocumentObject* obj = getObject(); - if (!obj || obj->isRestoring()) + if (!obj || obj->isRestoring()) { return; + } if (obj->getTypeId().isDerivedFrom(Drawing::FeatureView::getClassTypeId())) { // The 'Visible' property is marked as 'Output'. To update the drawing on recompute // the parent page object is touched. static_cast(obj)->Visible.setValue(false); std::vector inp = obj->getInList(); - for (std::vector::iterator it = inp.begin(); it != inp.end(); ++it) + for (std::vector::iterator it = inp.begin(); it != inp.end(); ++it) { (*it)->touch(); + } } } @@ -112,19 +115,20 @@ void ViewProviderDrawingView::finishRestoring() } void ViewProviderDrawingView::updateData(const App::Property*) -{ -} +{} // Python viewprovider ----------------------------------------------------------------------- -namespace Gui { +namespace Gui +{ /// @cond DOXERR -PROPERTY_SOURCE_TEMPLATE(DrawingGui::ViewProviderDrawingViewPython, DrawingGui::ViewProviderDrawingView) +PROPERTY_SOURCE_TEMPLATE(DrawingGui::ViewProviderDrawingViewPython, + DrawingGui::ViewProviderDrawingView) /// @endcond // explicit template instantiation template class DrawingGuiExport ViewProviderPythonFeatureT; -} +}// namespace Gui // ---------------------------------------------------------------------------- @@ -140,10 +144,9 @@ ViewProviderDrawingClip::ViewProviderDrawingClip() } ViewProviderDrawingClip::~ViewProviderDrawingClip() -{ -} +{} -void ViewProviderDrawingClip::attach(App::DocumentObject *pcFeat) +void ViewProviderDrawingClip::attach(App::DocumentObject* pcFeat) { // call parent attach method ViewProviderDocumentObject::attach(pcFeat); @@ -166,15 +169,17 @@ void ViewProviderDrawingClip::show(void) ViewProviderDocumentObjectGroup::show(); App::DocumentObject* obj = getObject(); - if (!obj || obj->isRestoring()) + if (!obj || obj->isRestoring()) { return; + } if (obj->getTypeId().isDerivedFrom(Drawing::FeatureClip::getClassTypeId())) { // The 'Visible' property is marked as 'Output'. To update the drawing on recompute // the parent page object is touched. static_cast(obj)->Visible.setValue(true); std::vector inp = obj->getInList(); - for (std::vector::iterator it = inp.begin(); it != inp.end(); ++it) + for (std::vector::iterator it = inp.begin(); it != inp.end(); ++it) { (*it)->touch(); + } } } @@ -183,15 +188,17 @@ void ViewProviderDrawingClip::hide(void) ViewProviderDocumentObjectGroup::hide(); App::DocumentObject* obj = getObject(); - if (!obj || obj->isRestoring()) + if (!obj || obj->isRestoring()) { return; + } if (obj->getTypeId().isDerivedFrom(Drawing::FeatureClip::getClassTypeId())) { // The 'Visible' property is marked as 'Output'. To update the drawing on recompute // the parent page object is touched. static_cast(obj)->Visible.setValue(false); std::vector inp = obj->getInList(); - for (std::vector::iterator it = inp.begin(); it != inp.end(); ++it) + for (std::vector::iterator it = inp.begin(); it != inp.end(); ++it) { (*it)->touch(); + } } } @@ -211,5 +218,4 @@ void ViewProviderDrawingClip::finishRestoring() } void ViewProviderDrawingClip::updateData(const App::Property*) -{ -} +{} diff --git a/src/Mod/Drawing/Gui/ViewProviderView.h b/src/Mod/Drawing/Gui/ViewProviderView.h index 91295a0f6a..93f14f2805 100644 --- a/src/Mod/Drawing/Gui/ViewProviderView.h +++ b/src/Mod/Drawing/Gui/ViewProviderView.h @@ -26,10 +26,11 @@ #include -namespace DrawingGui { +namespace DrawingGui +{ -class DrawingGuiExport ViewProviderDrawingView : public Gui::ViewProviderDocumentObject +class DrawingGuiExport ViewProviderDrawingView: public Gui::ViewProviderDocumentObject { PROPERTY_HEADER(DrawingGui::ViewProviderDrawingView); @@ -40,9 +41,12 @@ public: virtual ~ViewProviderDrawingView(); - virtual void attach(App::DocumentObject *); + virtual void attach(App::DocumentObject*); virtual void setDisplayMode(const char* ModeName); - virtual bool useNewSelectionModel(void) const {return false;} + 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*); @@ -61,7 +65,7 @@ public: using ViewProviderDrawingViewPython = Gui::ViewProviderPythonFeatureT; -class DrawingGuiExport ViewProviderDrawingClip : public Gui::ViewProviderDocumentObjectGroup +class DrawingGuiExport ViewProviderDrawingClip: public Gui::ViewProviderDocumentObjectGroup { PROPERTY_HEADER(DrawingGui::ViewProviderDrawingClip); @@ -72,9 +76,12 @@ public: virtual ~ViewProviderDrawingClip(); - virtual void attach(App::DocumentObject *); + virtual void attach(App::DocumentObject*); virtual void setDisplayMode(const char* ModeName); - virtual bool useNewSelectionModel(void) const {return false;} + 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*); @@ -91,8 +98,7 @@ public: //@} }; -} // namespace DrawingGui +}// namespace DrawingGui -#endif // DRAWINGGUI_VIEWPROVIDERVIEW_H - +#endif// DRAWINGGUI_VIEWPROVIDERVIEW_H diff --git a/src/Mod/Drawing/Gui/Workbench.cpp b/src/Mod/Drawing/Gui/Workbench.cpp index 51d7f17129..77a056194a 100644 --- a/src/Mod/Drawing/Gui/Workbench.cpp +++ b/src/Mod/Drawing/Gui/Workbench.cpp @@ -30,7 +30,7 @@ using namespace DrawingGui; -#if 0 // needed for Qt's lupdate utility +#if 0// needed for Qt's lupdate utility qApp->translate("Workbench", "Drawing"); #endif @@ -38,12 +38,10 @@ using namespace DrawingGui; TYPESYSTEM_SOURCE(DrawingGui::Workbench, Gui::StdWorkbench) Workbench::Workbench() -{ -} +{} Workbench::~Workbench() -{ -} +{} Gui::MenuItem* Workbench::setupMenuBar() const { @@ -100,7 +98,7 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const *img << "Drawing_Open"; img = new Gui::ToolBarItem(root); img->setCommand("Drawing types"); - //*img << "Drawing_NewA3Landscape"; + //*img << "Drawing_NewA3Landscape"; *img << "Drawing_NewPage"; *img << "Drawing_OrthoViews"; *img << "Drawing_OpenBrowserView"; @@ -112,4 +110,3 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const *img << "Drawing_NewView"; return root; } - diff --git a/src/Mod/Drawing/Gui/Workbench.h b/src/Mod/Drawing/Gui/Workbench.h index 595c81ff91..9a40b5e1c5 100644 --- a/src/Mod/Drawing/Gui/Workbench.h +++ b/src/Mod/Drawing/Gui/Workbench.h @@ -26,12 +26,13 @@ #include -namespace DrawingGui { +namespace DrawingGui +{ /** * @author Werner Mayer */ -class Workbench : public Gui::StdWorkbench +class Workbench: public Gui::StdWorkbench { TYPESYSTEM_HEADER(); @@ -45,7 +46,7 @@ protected: Gui::ToolBarItem* setupCommandBars() const; }; -} // namespace DrawingGui +}// namespace DrawingGui -#endif // DRAWING_WORKBENCH_H +#endif// DRAWING_WORKBENCH_H diff --git a/src/Mod/Drawing/Init.py b/src/Mod/Drawing/Init.py index 9cf4409c5e..2e33f58f43 100644 --- a/src/Mod/Drawing/Init.py +++ b/src/Mod/Drawing/Init.py @@ -1,29 +1,28 @@ # FreeCAD init script of the Image module # (c) 2001 Juergen Riegel -#*************************************************************************** -#* (c) Juergen Riegel (juergen.riegel@web.de) 2002 * -#* * -#* This file is part of the FreeCAD CAx development system. * -#* * -#* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU Lesser General Public License (LGPL) * -#* as published by the Free Software Foundation; either version 2 of * -#* the License, or (at your option) any later version. * -#* for detail see the LICENCE text file. * -#* * -#* FreeCAD 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 Lesser General Public License for more details. * -#* * -#* You should have received a copy of the GNU Library General Public * -#* License along with FreeCAD; if not, write to the Free Software * -#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -#* USA * -#* * -#* Juergen Riegel 2002 * -#***************************************************************************/ +# *************************************************************************** +# * (c) Juergen Riegel (juergen.riegel@web.de) 2002 * +# * * +# * This file is part of the FreeCAD CAx development system. * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * FreeCAD 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 Lesser General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with FreeCAD; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# * Juergen Riegel 2002 * +# ***************************************************************************/ -FreeCAD.Console.PrintLog("Drawing became obsolete in 0.17; " - "consider using TechDraw instead.\n") +FreeCAD.Console.PrintLog("Drawing became obsolete in 0.17; " "consider using TechDraw instead.\n") diff --git a/src/Mod/Drawing/InitGui.py b/src/Mod/Drawing/InitGui.py index f94611e92c..3d23166921 100644 --- a/src/Mod/Drawing/InitGui.py +++ b/src/Mod/Drawing/InitGui.py @@ -5,52 +5,56 @@ # This is the second one of three init scripts, the third one # runs when the gui is up -#*************************************************************************** -#* (c) Juergen Riegel (juergen.riegel@web.de) 2002 -#* * -#* This file is part of the FreeCAD CAx development system. * -#* * -#* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU Lesser General Public License (LGPL) * -#* as published by the Free Software Foundation; either version 2 of * -#* the License, or (at your option) any later version. * -#* for detail see the LICENCE text file. * -#* * -#* FreeCAD 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 Lesser General Public License for more details. * -#* * -#* You should have received a copy of the GNU Library General Public * -#* License along with FreeCAD; if not, write to the Free Software * -#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -#* USA * -#* * -#* Juergen Riegel 2002 * -#***************************************************************************/ +# *************************************************************************** +# * (c) Juergen Riegel (juergen.riegel@web.de) 2002 +# * * +# * This file is part of the FreeCAD CAx development system. * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * FreeCAD 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 Lesser General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with FreeCAD; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# * Juergen Riegel 2002 * +# ***************************************************************************/ -class DrawingWorkbench (Workbench): +class DrawingWorkbench(Workbench): "Drawing workbench object" + def __init__(self): - self.__class__.Icon = FreeCAD.getResourceDir() + "Mod/Drawing/Resources/icons/DrawingWorkbench.svg" + self.__class__.Icon = ( + FreeCAD.getResourceDir() + "Mod/Drawing/Resources/icons/DrawingWorkbench.svg" + ) self.__class__.MenuText = "Drawing" self.__class__.ToolTip = "Drawing workbench" - def Initialize(self): # load the module import DrawingGui def Activated(self): - FreeCAD.Console.PrintWarning("Drawing became obsolete in 0.17; " - "consider using TechDraw instead.\n") + FreeCAD.Console.PrintWarning( + "Drawing became obsolete in 0.17; " "consider using TechDraw instead.\n" + ) def GetClassName(self): return "DrawingGui::Workbench" - + + Gui.addWorkbench(DrawingWorkbench()) # Append the open handler -FreeCAD.addImportType("Drawing (*.svg *.svgz)","DrawingGui") -FreeCAD.addExportType("Drawing (*.svg *.svgz *.dxf)","DrawingGui") +FreeCAD.addImportType("Drawing (*.svg *.svgz)", "DrawingGui") +FreeCAD.addExportType("Drawing (*.svg *.svgz *.dxf)", "DrawingGui") diff --git a/src/Mod/Drawing/drawing.dox b/src/Mod/Drawing/drawing.dox index ba7999f256..e8a0920e43 100644 --- a/src/Mod/Drawing/drawing.dox +++ b/src/Mod/Drawing/drawing.dox @@ -2,4 +2,3 @@ * \ingroup CWORKBENCHES * \brief Manages output of 2D sheets from FreeCAD documents */ -