diff --git a/src/Mod/TechDraw/App/DrawPage.cpp b/src/Mod/TechDraw/App/DrawPage.cpp index 933eee49c4..48513ad96f 100644 --- a/src/Mod/TechDraw/App/DrawPage.cpp +++ b/src/Mod/TechDraw/App/DrawPage.cpp @@ -62,16 +62,13 @@ DrawPage::DrawPage(void) nowUnsetting = false; forceRedraw(false); - ADD_PROPERTY_TYPE(KeepUpdated, - (Preferences::keepPagesUpToDate()), - group, - (App::PropertyType)(App::Prop_Output), - "Keep page in sync with model"); - ADD_PROPERTY_TYPE( - Template, (nullptr), group, (App::PropertyType)(App::Prop_None), "Attached Template"); + ADD_PROPERTY_TYPE(KeepUpdated, (Preferences::keepPagesUpToDate()), group, + (App::PropertyType)(App::Prop_Output), "Keep page in sync with model"); + ADD_PROPERTY_TYPE(Template, (nullptr), group, (App::PropertyType)(App::Prop_None), + "Attached Template"); Template.setScope(App::LinkScope::Global); - ADD_PROPERTY_TYPE( - Views, (nullptr), group, (App::PropertyType)(App::Prop_None), "Attached Views"); + ADD_PROPERTY_TYPE(Views, (nullptr), group, (App::PropertyType)(App::Prop_None), + "Attached Views"); Views.setScope(App::LinkScope::Global); // Projection Properties @@ -84,24 +81,16 @@ DrawPage::DrawPage(void) ->GetGroup("Preferences") ->GetGroup("Mod/TechDraw/General"); double defScale = hGrp->GetFloat("DefaultScale", 1.0); - ADD_PROPERTY_TYPE(Scale, - (defScale), - group, - (App::PropertyType)(App::Prop_None), + ADD_PROPERTY_TYPE(Scale, (defScale), group, (App::PropertyType)(App::Prop_None), "Scale factor for this Page"); - ADD_PROPERTY_TYPE(NextBalloonIndex, - (1), - group, - (App::PropertyType)(App::Prop_None), + ADD_PROPERTY_TYPE(NextBalloonIndex, (1), group, (App::PropertyType)(App::Prop_None), "Auto-numbering for Balloons"); Scale.setConstraints(&scaleRange); - balloonParent = nullptr; } -DrawPage::~DrawPage() -{} +DrawPage::~DrawPage() {} void DrawPage::onBeforeChange(const App::Property* prop) { @@ -113,8 +102,8 @@ void DrawPage::onChanged(const App::Property* prop) if ((prop == &KeepUpdated) && KeepUpdated.getValue()) { if (!isRestoring() && !isUnsetting()) { //would be nice if this message was displayed immediately instead of after the recomputeFeature - Base::Console().Message( - "Rebuilding Views for: %s/%s\n", getNameInDocument(), Label.getValue()); + Base::Console().Message("Rebuilding Views for: %s/%s\n", getNameInDocument(), + Label.getValue()); updateAllViews(); purgeTouched(); } @@ -131,8 +120,7 @@ void DrawPage::onChanged(const App::Property* prop) if (!isRestoring()) { const std::vector& vals = Views.getValues(); for (std::vector::const_iterator it = vals.begin(); - it < vals.end(); - ++it) { + it < vals.end(); ++it) { TechDraw::DrawView* view = dynamic_cast(*it); if (view && view->ScaleType.isValue("Page")) { if (std::abs(view->Scale.getValue() - Scale.getValue()) > FLT_EPSILON) { @@ -159,10 +147,7 @@ void DrawPage::onChanged(const App::Property* prop) } //Page is just a container. It doesn't "do" anything. -App::DocumentObjectExecReturn* DrawPage::execute(void) -{ - return App::DocumentObject::execute(); -} +App::DocumentObjectExecReturn* DrawPage::execute(void) { return App::DocumentObject::execute(); } // this is now irrelevant, b/c DP::execute doesn't do anything. short DrawPage::mustExecute() const @@ -329,10 +314,7 @@ int DrawPage::removeView(App::DocumentObject* docObj) return Views.getSize(); } -void DrawPage::requestPaint(void) -{ - signalGuiPaint(this); -} +void DrawPage::requestPaint(void) { signalGuiPaint(this); } //this doesn't work right because there is no guaranteed of the restoration order void DrawPage::onDocumentRestored() @@ -417,8 +399,7 @@ void DrawPage::unsetupObject() if (v->isAttachedToDocument()) { std::string viewName = v->getNameInDocument(); Base::Interpreter().runStringArg("App.getDocument(\"%s\").removeObject(\"%s\")", - docName.c_str(), - viewName.c_str()); + docName.c_str(), viewName.c_str()); } } std::vector emptyViews;//probably superfluous @@ -432,8 +413,8 @@ void DrawPage::unsetupObject() App::DocumentObject* tmp = Template.getValue(); if (tmp) { std::string templateName = Template.getValue()->getNameInDocument(); - Base::Interpreter().runStringArg( - "App.getDocument(\"%s\").removeObject(\"%s\")", docName.c_str(), templateName.c_str()); + Base::Interpreter().runStringArg("App.getDocument(\"%s\").removeObject(\"%s\")", + docName.c_str(), templateName.c_str()); } Template.setValue(nullptr); } diff --git a/src/Mod/TechDraw/App/DrawPage.h b/src/Mod/TechDraw/App/DrawPage.h index 72a0031c68..3c2952c050 100644 --- a/src/Mod/TechDraw/App/DrawPage.h +++ b/src/Mod/TechDraw/App/DrawPage.h @@ -48,31 +48,29 @@ public: App::PropertyBool KeepUpdated; App::PropertyFloatConstraint Scale; - App::PropertyEnumeration ProjectionType; // First or Third Angle + App::PropertyEnumeration ProjectionType;// First or Third Angle - App::PropertyInteger NextBalloonIndex; + App::PropertyInteger NextBalloonIndex; /** @name methods override Feature */ //@{ /// recalculate the Feature - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; //@} - void handleChangedPropertyType( - Base::XMLReader &reader, const char * TypeName, App::Property * prop) override; + void handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName, + App::Property* prop) override; - int addView(App::DocumentObject *docObj); + int addView(App::DocumentObject* docObj); int removeView(App::DocumentObject* docObj); short mustExecute() const override; - boost::signals2::signal signalGuiPaint; + boost::signals2::signal signalGuiPaint; /// returns the type name of the ViewProvider - const char* getViewProviderName() const override { - return "TechDrawGui::ViewProviderPage"; - } + const char* getViewProviderName() const override { return "TechDrawGui::ViewProviderPage"; } - PyObject *getPyObject() override; + PyObject* getPyObject() override; -//App::DocumentObjectExecReturn * recompute(void); + //App::DocumentObjectExecReturn * recompute(void); /// Check whether we've got a valid template /*! @@ -93,8 +91,7 @@ public: int getOrientation() const; bool isUnsetting() { return nowUnsetting; } void requestPaint(); - std::vector getAllViews() ; - DrawViewPart *balloonParent; //could be many balloons on page? + std::vector getAllViews(); int getNextBalloonIndex(); @@ -102,7 +99,7 @@ public: static bool GlobalUpdateDrawings(); static bool AllowPageOverride(); void forceRedraw(bool b) { m_forceRedraw = b; } - bool forceRedraw() { return m_forceRedraw; } + bool forceRedraw() { return m_forceRedraw; } void redrawCommand(); bool canUpdate() const; @@ -121,13 +118,11 @@ private: static const char* ProjectionTypeEnums[]; bool nowUnsetting; static App::PropertyFloatConstraint::Constraints scaleRange; - }; using DrawPagePython = App::FeaturePythonT; -} //namespace TechDraw +}//namespace TechDraw #endif - diff --git a/src/Mod/TechDraw/App/DrawViewBalloon.cpp b/src/Mod/TechDraw/App/DrawViewBalloon.cpp index c9430ca2ec..da5298ef0e 100644 --- a/src/Mod/TechDraw/App/DrawViewBalloon.cpp +++ b/src/Mod/TechDraw/App/DrawViewBalloon.cpp @@ -23,27 +23,26 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include +#include +#include +#include +#include #endif #include #include #include -#include "DrawViewBalloon.h" #include "ArrowPropEnum.h" +#include "DrawViewBalloon.h" #include "DrawViewPart.h" #include "Preferences.h" using namespace TechDraw; -App::PropertyFloatConstraint::Constraints DrawViewBalloon::SymbolScaleRange = { Precision::Confusion(), - std::numeric_limits::max(), - (0.1) }; +App::PropertyFloatConstraint::Constraints DrawViewBalloon::SymbolScaleRange = { + Precision::Confusion(), std::numeric_limits::max(), (0.1)}; //=========================================================================== // DrawViewBalloon @@ -58,116 +57,113 @@ App::PropertyFloatConstraint::Constraints DrawViewBalloon::SymbolScaleRange = { PROPERTY_SOURCE(TechDraw::DrawViewBalloon, TechDraw::DrawView) -const char* DrawViewBalloon::balloonTypeEnums[]= {"Circular", - "None", - "Triangle", - "Inspection", - "Hexagon", - "Square", - "Rectangle", - "Line", - nullptr}; +const char* DrawViewBalloon::balloonTypeEnums[] = {"Circular", "None", "Triangle", + "Inspection", "Hexagon", "Square", + "Rectangle", "Line", nullptr}; DrawViewBalloon::DrawViewBalloon() { ADD_PROPERTY_TYPE(Text, (""), "", App::Prop_None, "The text to be displayed"); - ADD_PROPERTY_TYPE(SourceView, (nullptr), "", (App::PropertyType)(App::Prop_None), "Source view for balloon"); + ADD_PROPERTY_TYPE(SourceView, (nullptr), "", (App::PropertyType)(App::Prop_None), + "Source view for balloon"); ADD_PROPERTY_TYPE(OriginX, (0), "", (App::PropertyType)(App::Prop_None), "Balloon origin x"); ADD_PROPERTY_TYPE(OriginY, (0), "", (App::PropertyType)(App::Prop_None), "Balloon origin y"); EndType.setEnums(ArrowPropEnum::ArrowTypeEnums); - ADD_PROPERTY_TYPE(EndType, (prefEnd()), "", (App::PropertyType)(App::Prop_None), "End symbol for the balloon line"); + ADD_PROPERTY_TYPE(EndType, (prefEnd()), "", (App::PropertyType)(App::Prop_None), + "End symbol for the balloon line"); - ADD_PROPERTY_TYPE(EndTypeScale, (1.0), "", (App::PropertyType)(App::Prop_None), "End symbol scale factor"); + ADD_PROPERTY_TYPE(EndTypeScale, (1.0), "", (App::PropertyType)(App::Prop_None), + "End symbol scale factor"); EndTypeScale.setConstraints(&SymbolScaleRange); BubbleShape.setEnums(balloonTypeEnums); - ADD_PROPERTY_TYPE(BubbleShape, (prefShape()), "", (App::PropertyType)(App::Prop_None), "Shape of the balloon bubble"); + ADD_PROPERTY_TYPE(BubbleShape, (prefShape()), "", (App::PropertyType)(App::Prop_None), + "Shape of the balloon bubble"); - ADD_PROPERTY_TYPE(ShapeScale, (1.0), "", (App::PropertyType)(App::Prop_None), "Balloon shape scale"); + ADD_PROPERTY_TYPE(ShapeScale, (1.0), "", (App::PropertyType)(App::Prop_None), + "Balloon shape scale"); ShapeScale.setConstraints(&SymbolScaleRange); - ADD_PROPERTY_TYPE(TextWrapLen, (-1), "", (App::PropertyType)(App::Prop_None), "Text wrap length; -1 means no wrap"); + ADD_PROPERTY_TYPE(TextWrapLen, (-1), "", (App::PropertyType)(App::Prop_None), + "Text wrap length; -1 means no wrap"); ADD_PROPERTY_TYPE(KinkLength, (prefKinkLength()), "", (App::PropertyType)(App::Prop_None), - "Distance from symbol to leader kink"); + "Distance from symbol to leader kink"); SourceView.setScope(App::LinkScope::Global); Rotation.setStatus(App::Property::Hidden, true); Caption.setStatus(App::Property::Hidden, true); } -DrawViewBalloon::~DrawViewBalloon() -{ - -} +DrawViewBalloon::~DrawViewBalloon() {} void DrawViewBalloon::onChanged(const App::Property* prop) { if (!isRestoring()) { - if ( (prop == &EndType) || - (prop == &BubbleShape) || - (prop == &ShapeScale) || - (prop == &Text) || - (prop == &KinkLength) || - (prop == &EndTypeScale) || - (prop == &OriginX) || - (prop == &OriginY) ) { + if ((prop == &EndType) || (prop == &BubbleShape) || (prop == &ShapeScale) || (prop == &Text) + || (prop == &KinkLength) || (prop == &EndTypeScale) || (prop == &OriginX) + || (prop == &OriginY)) { requestPaint(); } } DrawView::onChanged(prop); } -void DrawViewBalloon::handleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName) +void DrawViewBalloon::handleChangedPropertyName(Base::XMLReader& reader, const char* TypeName, + const char* PropName) { Base::Type type = Base::Type::fromName(TypeName); // was sourceView in the past, now is SourceView if (SourceView.getClassTypeId() == type && strcmp(PropName, "sourceView") == 0) { SourceView.Restore(reader); - } else if (BubbleShape.getClassTypeId() == type && strcmp(PropName, "Symbol") == 0) { + } + else if (BubbleShape.getClassTypeId() == type && strcmp(PropName, "Symbol") == 0) { // was Symbol, then Shape in the past, now is BubbleShape BubbleShape.Restore(reader); - } else if (BubbleShape.getClassTypeId() == type && strcmp(PropName, "Shape") == 0) { + } + else if (BubbleShape.getClassTypeId() == type && strcmp(PropName, "Shape") == 0) { // was Symbol, then Shape in the past, now is BubbleShape BubbleShape.Restore(reader); - } else if (ShapeScale.getClassTypeId() == type && strcmp(PropName, "SymbolScale") == 0) { + } + else if (ShapeScale.getClassTypeId() == type && strcmp(PropName, "SymbolScale") == 0) { // was SymbolScale in the past, now is ShapeScale ShapeScale.Restore(reader); - } else { + } + else { DrawView::handleChangedPropertyName(reader, TypeName, PropName); } } -void DrawViewBalloon::handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop) +void DrawViewBalloon::handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName, + App::Property* prop) // transforms properties that had been changed { // also check for changed properties of the base class DrawView::handleChangedPropertyType(reader, TypeName, prop); // property OriginX had the App::PropertyFloat and was changed to App::PropertyDistance - if ( (prop == &OriginX) && - (strcmp(TypeName, "App::PropertyFloat") == 0) ) { + if ((prop == &OriginX) && (strcmp(TypeName, "App::PropertyFloat") == 0)) { App::PropertyFloat OriginXProperty; // restore the PropertyFloat to be able to set its value OriginXProperty.Restore(reader); OriginX.setValue(OriginXProperty.getValue()); - } else if ( (prop == &OriginX) && - (strcmp(TypeName, "App::PropertyLength") == 0) ) { + } + else if ((prop == &OriginX) && (strcmp(TypeName, "App::PropertyLength") == 0)) { App::PropertyLength OriginXProperty; // restore the PropertyFloat to be able to set its value OriginXProperty.Restore(reader); OriginX.setValue(OriginXProperty.getValue()); - // property OriginY had the App::PropertyFloat and was changed to App::PropertyDistance - } else if ( (prop == &OriginY) && - (strcmp(TypeName, "App::PropertyFloat") == 0) ) { + // property OriginY had the App::PropertyFloat and was changed to App::PropertyDistance + } + else if ((prop == &OriginY) && (strcmp(TypeName, "App::PropertyFloat") == 0)) { App::PropertyFloat OriginYProperty; // restore the PropertyFloat to be able to set its value OriginYProperty.Restore(reader); OriginY.setValue(OriginYProperty.getValue()); - } else if ( (prop == &OriginY) && - (strcmp(TypeName, "App::PropertyLength") == 0) ) { + } + else if ((prop == &OriginY) && (strcmp(TypeName, "App::PropertyLength") == 0)) { App::PropertyLength OriginYProperty; // restore the PropertyLength to be able to set its value OriginYProperty.Restore(reader); @@ -182,15 +178,16 @@ short DrawViewBalloon::mustExecute() const return 1; } - auto dvp = getViewPart(); - if (dvp && dvp->isTouched()) { + auto dv = getParentView(); + if (dv && dv->isTouched()) { return 1; } return DrawView::mustExecute(); } -void DrawViewBalloon::handleXYLock() { +void DrawViewBalloon::handleXYLock() +{ bool on = isLocked(); if (!OriginX.testStatus(App::Property::ReadOnly)) { OriginX.setStatus(App::Property::ReadOnly, on); @@ -204,14 +201,14 @@ void DrawViewBalloon::handleXYLock() { } -DrawViewPart* DrawViewBalloon::getViewPart() const +DrawView* DrawViewBalloon::getParentView() const { App::DocumentObject* obj = SourceView.getValue(); - DrawViewPart* result = dynamic_cast(obj); + DrawView* result = dynamic_cast(obj); return result; } -App::DocumentObjectExecReturn *DrawViewBalloon::execute() +App::DocumentObjectExecReturn* DrawViewBalloon::execute() { requestPaint(); return App::DocumentObject::execute(); @@ -227,23 +224,25 @@ void DrawViewBalloon::setOrigin(Base::Vector3d newOrigin) double DrawViewBalloon::prefKinkLength() const { - Base::Reference hGrp = App::GetApplication().GetUserParameter(). - GetGroup("BaseApp")->GetGroup("Preferences")-> - GetGroup("Mod/TechDraw/Dimensions"); + Base::Reference hGrp = App::GetApplication() + .GetUserParameter() + .GetGroup("BaseApp") + ->GetGroup("Preferences") + ->GetGroup("Mod/TechDraw/Dimensions"); return hGrp->GetFloat("BalloonKink", 5.0); } int DrawViewBalloon::prefShape() const { - Base::Reference hGrp = App::GetApplication().GetUserParameter() - .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations"); + Base::Reference hGrp = App::GetApplication() + .GetUserParameter() + .GetGroup("BaseApp") + ->GetGroup("Preferences") + ->GetGroup("Mod/TechDraw/Decorations"); return hGrp->GetInt("BalloonShape", 0); } -int DrawViewBalloon::prefEnd() const -{ - return Preferences::balloonArrow(); -} +int DrawViewBalloon::prefEnd() const { return Preferences::balloonArrow(); } QPointF DrawViewBalloon::getOrigin() { @@ -268,7 +267,7 @@ Base::Vector3d DrawViewBalloon::getOriginOffset() const double oy = OriginY.getValue(); Base::Vector3d org(ox, oy, 0.0); Base::Vector3d offset = pos - org; - return offset; + return offset; } /* diff --git a/src/Mod/TechDraw/App/DrawViewBalloon.h b/src/Mod/TechDraw/App/DrawViewBalloon.h index f9ad15110d..733dd440d5 100644 --- a/src/Mod/TechDraw/App/DrawViewBalloon.h +++ b/src/Mod/TechDraw/App/DrawViewBalloon.h @@ -32,14 +32,16 @@ class TopoDS_Shape; -namespace Measure { +namespace Measure +{ class Measurement; } -namespace TechDraw { +namespace TechDraw +{ class DrawViewPart; -class TechDrawExport DrawViewBalloon : public TechDraw::DrawView +class TechDrawExport DrawViewBalloon: public TechDraw::DrawView { PROPERTY_HEADER_WITH_OVERRIDE(TechDraw::DrawViewBalloon); @@ -48,31 +50,29 @@ public: DrawViewBalloon(); ~DrawViewBalloon() override; - App::PropertyLink SourceView; - App::PropertyString Text; - App::PropertyEnumeration EndType; - App::PropertyEnumeration BubbleShape; + App::PropertyLink SourceView; + App::PropertyString Text; + App::PropertyEnumeration EndType; + App::PropertyEnumeration BubbleShape; App::PropertyFloatConstraint ShapeScale; App::PropertyFloatConstraint EndTypeScale; - App::PropertyDistance OriginX; - App::PropertyDistance OriginY; - App::PropertyFloat TextWrapLen; - App::PropertyDistance KinkLength; + App::PropertyDistance OriginX; + App::PropertyDistance OriginY; + App::PropertyFloat TextWrapLen; + App::PropertyDistance KinkLength; short mustExecute() const override; - DrawViewPart* getViewPart() const; - QPointF origin; //WF never used?? + DrawView* getParentView() const; + QPointF origin;//WF never used?? QPointF getOrigin(); void setOrigin(QPointF p); //virtual PyObject *getPyObject(void); - App::DocumentObjectExecReturn *execute() override; + App::DocumentObjectExecReturn* execute() override; - const char* getViewProviderName() const override { - return "TechDrawGui::ViewProviderBalloon"; - } + const char* getViewProviderName() const override { return "TechDrawGui::ViewProviderBalloon"; } static const char* balloonTypeEnums[]; @@ -87,17 +87,14 @@ public: protected: void onChanged(const App::Property* prop) override; - void handleChangedPropertyType(Base::XMLReader &reader, - const char *TypeName, - App::Property * prop) override; - void handleChangedPropertyName(Base::XMLReader &reader, - const char * TypeName, - const char *PropName) override; + void handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName, + App::Property* prop) override; + void handleChangedPropertyName(Base::XMLReader& reader, const char* TypeName, + const char* PropName) override; private: static App::PropertyFloatConstraint::Constraints SymbolScaleRange; - }; -} //namespace TechDraw +}//namespace TechDraw #endif diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index 0390a9d837..35b483372c 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -982,7 +982,7 @@ bool _checkDrawViewPartBalloon(Gui::Command* cmd) return true; } -bool _checkDirectPlacement(const QGIViewPart* viewPart, const std::vector& subNames, +bool _checkDirectPlacement(const QGIView* view, const std::vector& subNames, QPointF& placement) { // Let's see, if we can help speed up the placement of the balloon: @@ -997,6 +997,12 @@ bool _checkDirectPlacement(const QGIViewPart* viewPart, const std::vector(view); + if (!viewPart) { + //not a view of a part, so no geometry to attach to + return false; + } + std::string geoType = TechDraw::DrawUtil::getGeomTypeFromName(subNames[0]); if (geoType == "Vertex") { int index = TechDraw::DrawUtil::getIndexFromName(subNames[0]); @@ -1040,13 +1046,13 @@ void CmdTechDrawBalloon::activated(int iMsg) bool result = _checkSelectionBalloon(this, 1); if (!result) return; - result = _checkDrawViewPartBalloon(this); - if (!result) - return; + // result = _checkDrawViewPartBalloon(this); + // if (!result) + // return; std::vector selection = getSelection().getSelectionEx(); - auto objFeat(dynamic_cast(selection[0].getObject())); + auto objFeat(dynamic_cast(selection[0].getObject())); if (!objFeat) { return; } @@ -1054,23 +1060,21 @@ void CmdTechDrawBalloon::activated(int iMsg) TechDraw::DrawPage* page = objFeat->findParentPage(); std::string PageName = page->getNameInDocument(); - page->balloonParent = objFeat; - Gui::Document* guiDoc = Gui::Application::Instance->getDocument(page->getDocument()); ViewProviderPage* pageVP = dynamic_cast(guiDoc->getViewProvider(page)); - ViewProviderViewPart* partVP = - dynamic_cast(guiDoc->getViewProvider(objFeat)); + ViewProviderDrawingView* viewVP = + dynamic_cast(guiDoc->getViewProvider(objFeat)); - if (pageVP && partVP) { + if (pageVP && viewVP) { QGVPage* viewPage = pageVP->getQGVPage(); QGSPage* scenePage = pageVP->getQGSPage(); if (viewPage) { - viewPage->startBalloonPlacing(); + viewPage->startBalloonPlacing(objFeat); - QGIViewPart* viewPart = dynamic_cast(partVP->getQView()); + QGIView* view = dynamic_cast(viewVP->getQView()); QPointF placement; - if (viewPart - && _checkDirectPlacement(viewPart, selection[0].getSubNames(), placement)) { + if (view && _checkDirectPlacement(view, selection[0].getSubNames(), placement)) { + //this creates the balloon if something is already selected scenePage->createBalloon(placement, objFeat); } } @@ -1080,7 +1084,7 @@ void CmdTechDrawBalloon::activated(int iMsg) bool CmdTechDrawBalloon::isActive() { bool havePage = DrawGuiUtil::needPage(this); - bool haveView = DrawGuiUtil::needView(this); + bool haveView = DrawGuiUtil::needView(this, false); return (havePage && haveView); } diff --git a/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp b/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp index d8470e0963..091b48ab8e 100644 --- a/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp +++ b/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp @@ -22,9 +22,9 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include +#include +#include +#include #endif #include @@ -63,100 +63,100 @@ using namespace TechDrawGui; using namespace TechDraw; -namespace TechDrawGui { - //LineAttributes activeAttributes; // container holding global line attributes +namespace TechDrawGui +{ +//LineAttributes activeAttributes; // container holding global line attributes - //internal helper functions - lineAttributes& _getActiveLineAttributes(); - Base::Vector3d _circleCenter(Base::Vector3d p1, Base::Vector3d p2, Base::Vector3d p3); - void _createThreadCircle(std::string Name, TechDraw::DrawViewPart* objFeat, float factor); - void _createThreadLines(std::vector SubNames, TechDraw::DrawViewPart* objFeat, float factor); - void _setLineAttributes(TechDraw::CosmeticEdge* cosEdge); - void _setLineAttributes(TechDraw::CenterLine* cosEdge); - void _setLineAttributes(TechDraw::CosmeticEdge* cosEdge, int style, float weight, App::Color color); - void _setLineAttributes(TechDraw::CenterLine* cosEdge, int style, float weight, App::Color color); - float _getAngle(Base::Vector3d center, Base::Vector3d point); - std::vector _getVertexPoints(std::vector SubNames, TechDraw::DrawViewPart* objFeat); - bool _checkSel(Gui::Command* cmd, - std::vector& selection, - TechDraw::DrawViewPart*& objFeat, - std::string message); - std::string _createBalloon(Gui::Command* cmd, TechDraw::DrawViewPart* objFeat); +//internal helper functions +lineAttributes& _getActiveLineAttributes(); +Base::Vector3d _circleCenter(Base::Vector3d p1, Base::Vector3d p2, Base::Vector3d p3); +void _createThreadCircle(std::string Name, TechDraw::DrawViewPart* objFeat, float factor); +void _createThreadLines(std::vector SubNames, TechDraw::DrawViewPart* objFeat, + float factor); +void _setLineAttributes(TechDraw::CosmeticEdge* cosEdge); +void _setLineAttributes(TechDraw::CenterLine* cosEdge); +void _setLineAttributes(TechDraw::CosmeticEdge* cosEdge, int style, float weight, App::Color color); +void _setLineAttributes(TechDraw::CenterLine* cosEdge, int style, float weight, App::Color color); +float _getAngle(Base::Vector3d center, Base::Vector3d point); +std::vector _getVertexPoints(std::vector SubNames, + TechDraw::DrawViewPart* objFeat); +bool _checkSel(Gui::Command* cmd, std::vector& selection, + TechDraw::DrawViewPart*& objFeat, std::string message); +std::string _createBalloon(Gui::Command* cmd, TechDraw::DrawViewPart* objFeat); - //=========================================================================== - // TechDraw_ExtensionHoleCircle - //=========================================================================== +//=========================================================================== +// TechDraw_ExtensionHoleCircle +//=========================================================================== - void execHoleCircle(Gui::Command* cmd) { - //create centerlines of a hole/bolt circle - std::vector selection; - TechDraw::DrawViewPart* objFeat; - if (!_checkSel(cmd, selection, objFeat, "TechDraw Hole Circle")) - return; - const std::vector SubNames = selection[0].getSubNames(); - std::vector Circles; - for (const std::string& Name : SubNames) { - int GeoId = TechDraw::DrawUtil::getIndexFromName(Name); - std::string GeoType = TechDraw::DrawUtil::getGeomTypeFromName(Name); - TechDraw::BaseGeomPtr geom = objFeat->getGeomByIndex(GeoId); - if (GeoType == "Edge") { - if (geom->geomType == TechDraw::CIRCLE || - geom->geomType == TechDraw::ARCOFCIRCLE) { - TechDraw::CirclePtr cgen = std::static_pointer_cast(geom); - Circles.push_back(cgen); - } +void execHoleCircle(Gui::Command* cmd) +{ + //create centerlines of a hole/bolt circle + std::vector selection; + TechDraw::DrawViewPart* objFeat; + if (!_checkSel(cmd, selection, objFeat, "TechDraw Hole Circle")) + return; + const std::vector SubNames = selection[0].getSubNames(); + std::vector Circles; + for (const std::string& Name : SubNames) { + int GeoId = TechDraw::DrawUtil::getIndexFromName(Name); + std::string GeoType = TechDraw::DrawUtil::getGeomTypeFromName(Name); + TechDraw::BaseGeomPtr geom = objFeat->getGeomByIndex(GeoId); + if (GeoType == "Edge") { + if (geom->geomType == TechDraw::CIRCLE || geom->geomType == TechDraw::ARCOFCIRCLE) { + TechDraw::CirclePtr cgen = std::static_pointer_cast(geom); + Circles.push_back(cgen); } } - if (Circles.size() <= 2) { - QMessageBox::warning(Gui::getMainWindow(), - QObject::tr("TechDraw Hole Circle"), - QObject::tr("Fewer than three circles selected")); - return; - } - Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Bolt Circle Centerlines")); - double scale = objFeat->getScale(); - Base::Vector3d bigCenter = _circleCenter(Circles[0]->center, - Circles[1]->center, - Circles[2]->center); - float bigRadius = (Circles[0]->center - bigCenter).Length(); - TechDraw::BaseGeomPtr bigCircle = std::make_shared(bigCenter / scale, bigRadius / scale); - std::string bigCircleTag = objFeat->addCosmeticEdge(bigCircle); - TechDraw::CosmeticEdge* ceCircle = objFeat->getCosmeticEdge(bigCircleTag); - _setLineAttributes(ceCircle); - for (const TechDraw::CirclePtr& oneCircle : Circles) { - Base::Vector3d oneCircleCenter = oneCircle->center; - float oneRadius = oneCircle->radius; - Base::Vector3d delta = (oneCircle->center - bigCenter).Normalize() * (oneRadius + 2); - Base::Vector3d startPt = oneCircleCenter + delta; - Base::Vector3d endPt = oneCircleCenter - delta; - startPt.y = -startPt.y; - endPt.y = -endPt.y; - std::string oneLineTag = objFeat->addCosmeticEdge(startPt / scale, endPt / scale); - TechDraw::CosmeticEdge* ceLine = objFeat->getCosmeticEdge(oneLineTag); - _setLineAttributes(ceLine); - } - cmd->getSelection().clearSelection(); - objFeat->refreshCEGeoms(); - objFeat->requestPaint(); - Gui::Command::commitCommand(); } + if (Circles.size() <= 2) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("TechDraw Hole Circle"), + QObject::tr("Fewer than three circles selected")); + return; + } + Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Bolt Circle Centerlines")); + double scale = objFeat->getScale(); + Base::Vector3d bigCenter = + _circleCenter(Circles[0]->center, Circles[1]->center, Circles[2]->center); + float bigRadius = (Circles[0]->center - bigCenter).Length(); + TechDraw::BaseGeomPtr bigCircle = + std::make_shared(bigCenter / scale, bigRadius / scale); + std::string bigCircleTag = objFeat->addCosmeticEdge(bigCircle); + TechDraw::CosmeticEdge* ceCircle = objFeat->getCosmeticEdge(bigCircleTag); + _setLineAttributes(ceCircle); + for (const TechDraw::CirclePtr& oneCircle : Circles) { + Base::Vector3d oneCircleCenter = oneCircle->center; + float oneRadius = oneCircle->radius; + Base::Vector3d delta = (oneCircle->center - bigCenter).Normalize() * (oneRadius + 2); + Base::Vector3d startPt = oneCircleCenter + delta; + Base::Vector3d endPt = oneCircleCenter - delta; + startPt.y = -startPt.y; + endPt.y = -endPt.y; + std::string oneLineTag = objFeat->addCosmeticEdge(startPt / scale, endPt / scale); + TechDraw::CosmeticEdge* ceLine = objFeat->getCosmeticEdge(oneLineTag); + _setLineAttributes(ceLine); + } + cmd->getSelection().clearSelection(); + objFeat->refreshCEGeoms(); + objFeat->requestPaint(); + Gui::Command::commitCommand(); } +}// namespace TechDrawGui DEF_STD_CMD_A(CmdTechDrawExtensionHoleCircle) CmdTechDrawExtensionHoleCircle::CmdTechDrawExtensionHoleCircle() : Command("TechDraw_ExtensionHoleCircle") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Add Bolt Circle Centerlines"); - sToolTipText = QT_TR_NOOP("Add centerlines to a circular pattern of circles:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add Bolt Circle Centerlines"); + sToolTipText = QT_TR_NOOP("Add centerlines to a circular pattern of circles:
\ - Specify the line attributes (optional)
\ - Select three or more circles forming a circular pattern
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionHoleCircle"; - sStatusTip = sMenuText; - sPixmap = "TechDraw_ExtensionHoleCircle"; + sWhatsThis = "TechDraw_ExtensionHoleCircle"; + sStatusTip = sMenuText; + sPixmap = "TechDraw_ExtensionHoleCircle"; } void CmdTechDrawExtensionHoleCircle::activated(int iMsg) @@ -177,7 +177,8 @@ bool CmdTechDrawExtensionHoleCircle::isActive() // TechDraw_ExtensionCircleCenterLines //=========================================================================== -void execCircleCenterLines(Gui::Command* cmd) { +void execCircleCenterLines(Gui::Command* cmd) +{ // create circle centerlines std::vector selection; TechDraw::DrawViewPart* objFeat; @@ -191,8 +192,7 @@ void execCircleCenterLines(Gui::Command* cmd) { TechDraw::BaseGeomPtr geom = objFeat->getGeomByIndex(GeoId); std::string GeoType = TechDraw::DrawUtil::getGeomTypeFromName(Name); if (GeoType == "Edge") { - if (geom->geomType == TechDraw::CIRCLE || - geom->geomType == TechDraw::ARCOFCIRCLE) { + if (geom->geomType == TechDraw::CIRCLE || geom->geomType == TechDraw::ARCOFCIRCLE) { TechDraw::CirclePtr cgen = std::static_pointer_cast(geom); Base::Vector3d center = cgen->center; center.y = -center.y; @@ -221,16 +221,16 @@ DEF_STD_CMD_A(CmdTechDrawExtensionCircleCenterLines) CmdTechDrawExtensionCircleCenterLines::CmdTechDrawExtensionCircleCenterLines() : Command("TechDraw_ExtensionCircleCenterLines") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Add Circle Centerlines"); - sToolTipText = QT_TR_NOOP("Add centerlines to circles and arcs:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add Circle Centerlines"); + sToolTipText = QT_TR_NOOP("Add centerlines to circles and arcs:
\ - Specify the line attributes (optional)
\ - Select one or more circles or arcs
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionCircleCenterLines"; - sStatusTip = sMenuText; - sPixmap = "TechDraw_ExtensionCircleCenterLines"; + sWhatsThis = "TechDraw_ExtensionCircleCenterLines"; + sStatusTip = sMenuText; + sPixmap = "TechDraw_ExtensionCircleCenterLines"; } void CmdTechDrawExtensionCircleCenterLines::activated(int iMsg) @@ -255,36 +255,37 @@ DEF_STD_CMD_ACL(CmdTechDrawExtensionCircleCenterLinesGroup) CmdTechDrawExtensionCircleCenterLinesGroup::CmdTechDrawExtensionCircleCenterLinesGroup() : Command("TechDraw_ExtensionCircleCenterLinesGroup") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Add Circle Centerlines"); - sToolTipText = QT_TR_NOOP("Add centerlines to circles and arcs:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add Circle Centerlines"); + sToolTipText = QT_TR_NOOP("Add centerlines to circles and arcs:
\ - Specify the line attributes (optional)
\ - Select one or more circles or arcs
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionCircleCenterLinesGroup"; - sStatusTip = sMenuText; + sWhatsThis = "TechDraw_ExtensionCircleCenterLinesGroup"; + sStatusTip = sMenuText; } -void CmdTechDrawExtensionCircleCenterLinesGroup::activated(int iMsg) { +void CmdTechDrawExtensionCircleCenterLinesGroup::activated(int iMsg) +{ Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog(); if (dlg) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"), - QObject::tr("Close active task dialog and try again.")); + QObject::tr("Close active task dialog and try again.")); return; } Gui::ActionGroup* pcAction = qobject_cast(_pcAction); pcAction->setIcon(pcAction->actions().at(iMsg)->icon()); switch (iMsg) { - case 0: //circle centerlines - execCircleCenterLines(this); - break; - case 1: //bolt circle centerlines - execHoleCircle(this); - break; - default: - Base::Console().Message("CMD::CVGrp - invalid iMsg: %d\n", iMsg); + case 0://circle centerlines + execCircleCenterLines(this); + break; + case 1://bolt circle centerlines + execHoleCircle(this); + break; + default: + Base::Console().Message("CMD::CVGrp - invalid iMsg: %d\n", iMsg); }; } @@ -323,17 +324,19 @@ void CmdTechDrawExtensionCircleCenterLinesGroup::languageChange() QList a = pcAction->actions(); QAction* arc1 = a[0]; - arc1->setText(QApplication::translate("CmdTechDrawExtensionCircleCenterLines", "Add Circle Centerlines")); + arc1->setText( + QApplication::translate("CmdTechDrawExtensionCircleCenterLines", "Add Circle Centerlines")); arc1->setToolTip(QApplication::translate("CmdTechDrawExtensionCircleCenterLines", -"Add centerlines to circles and arcs:
\ + "Add centerlines to circles and arcs:
\ - Specify the line attributes (optional)
\ - Select one or more circles or arcs
\ - Click this tool")); arc1->setStatusTip(arc1->text()); QAction* arc2 = a[1]; - arc2->setText(QApplication::translate("CmdTechDrawExtensionHoleCircle", "Add Bolt Circle Centerlines")); + arc2->setText( + QApplication::translate("CmdTechDrawExtensionHoleCircle", "Add Bolt Circle Centerlines")); arc2->setToolTip(QApplication::translate("CmdTechDrawExtensionHoleCircle", -"Add centerlines to a circular pattern of circles:
\ + "Add centerlines to a circular pattern of circles:
\ - Specify the line attributes (optional)
\ - Select three or more circles forming a circular pattern
\ - Click this tool")); @@ -351,7 +354,8 @@ bool CmdTechDrawExtensionCircleCenterLinesGroup::isActive() // TechDraw_ExtensionThreadHoleSide //=========================================================================== -void execThreadHoleSide(Gui::Command* cmd) { +void execThreadHoleSide(Gui::Command* cmd) +{ // add cosmetic thread to side view of hole std::vector selection; TechDraw::DrawViewPart* objFeat; @@ -373,16 +377,16 @@ DEF_STD_CMD_A(CmdTechDrawExtensionThreadHoleSide) CmdTechDrawExtensionThreadHoleSide::CmdTechDrawExtensionThreadHoleSide() : Command("TechDraw_ExtensionThreadHoleSide") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Add Cosmetic Thread Hole Side View"); - sToolTipText = QT_TR_NOOP("Add a cosmetic thread to the side view of a hole:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add Cosmetic Thread Hole Side View"); + sToolTipText = QT_TR_NOOP("Add a cosmetic thread to the side view of a hole:
\ - Specify the line attributes (optional)
\ - Select two parallel lines
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionThreadHoleSide"; - sStatusTip = sMenuText; - sPixmap = "TechDraw_ExtensionThreadHoleSide"; + sWhatsThis = "TechDraw_ExtensionThreadHoleSide"; + sStatusTip = sMenuText; + sPixmap = "TechDraw_ExtensionThreadHoleSide"; } void CmdTechDrawExtensionThreadHoleSide::activated(int iMsg) @@ -402,7 +406,8 @@ bool CmdTechDrawExtensionThreadHoleSide::isActive() // TechDraw_ExtensionThreadBoltSide //=========================================================================== -void execThreadBoltSide(Gui::Command* cmd) { +void execThreadBoltSide(Gui::Command* cmd) +{ // add cosmetic thread to side view of bolt std::vector selection; TechDraw::DrawViewPart* objFeat; @@ -424,16 +429,16 @@ DEF_STD_CMD_A(CmdTechDrawExtensionThreadBoltSide) CmdTechDrawExtensionThreadBoltSide::CmdTechDrawExtensionThreadBoltSide() : Command("TechDraw_ExtensionThreadBoltSide") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Add Cosmetic Thread Bolt Side View"); - sToolTipText = QT_TR_NOOP("Add a cosmetic thread to the side view of a bolt/screw/rod:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add Cosmetic Thread Bolt Side View"); + sToolTipText = QT_TR_NOOP("Add a cosmetic thread to the side view of a bolt/screw/rod:
\ - Specify the line attributes (optional)
\ - Select two parallel lines
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionThreadBoltSide"; - sStatusTip = sMenuText; - sPixmap = "TechDraw_ExtensionThreadBoltSide"; + sWhatsThis = "TechDraw_ExtensionThreadBoltSide"; + sStatusTip = sMenuText; + sPixmap = "TechDraw_ExtensionThreadBoltSide"; } void CmdTechDrawExtensionThreadBoltSide::activated(int iMsg) @@ -453,7 +458,8 @@ bool CmdTechDrawExtensionThreadBoltSide::isActive() // TechDraw_ExtensionThreadHoleBottom //=========================================================================== -void execThreadHoleBottom(Gui::Command* cmd) { +void execThreadHoleBottom(Gui::Command* cmd) +{ // add cosmetic thread to bottom view of hole std::vector selection; TechDraw::DrawViewPart* objFeat; @@ -475,16 +481,16 @@ DEF_STD_CMD_A(CmdTechDrawExtensionThreadHoleBottom) CmdTechDrawExtensionThreadHoleBottom::CmdTechDrawExtensionThreadHoleBottom() : Command("TechDraw_ExtensionThreadHoleBottom") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Add Cosmetic Thread Hole Bottom View"); - sToolTipText = QT_TR_NOOP("Add a cosmetic thread to the top or bottom view of holes:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add Cosmetic Thread Hole Bottom View"); + sToolTipText = QT_TR_NOOP("Add a cosmetic thread to the top or bottom view of holes:
\ - Specify the line attributes (optional)
\ - Select one or more circles
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionThreadHoleBottom"; - sStatusTip = sMenuText; - sPixmap = "TechDraw_ExtensionThreadHoleBottom"; + sWhatsThis = "TechDraw_ExtensionThreadHoleBottom"; + sStatusTip = sMenuText; + sPixmap = "TechDraw_ExtensionThreadHoleBottom"; } void CmdTechDrawExtensionThreadHoleBottom::activated(int iMsg) @@ -504,7 +510,8 @@ bool CmdTechDrawExtensionThreadHoleBottom::isActive() // TechDraw_ExtensionThreadBoltBottom //=========================================================================== -void execThreadBoltBottom(Gui::Command* cmd) { +void execThreadBoltBottom(Gui::Command* cmd) +{ // add cosmetic thread to bottom view of bolt std::vector selection; TechDraw::DrawViewPart* objFeat; @@ -526,16 +533,17 @@ DEF_STD_CMD_A(CmdTechDrawExtensionThreadBoltBottom) CmdTechDrawExtensionThreadBoltBottom::CmdTechDrawExtensionThreadBoltBottom() : Command("TechDraw_ExtensionThreadBoltBottom") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Add Cosmetic Thread Bolt Bottom View"); - sToolTipText = QT_TR_NOOP("Add a cosmetic thread to the top or bottom view of bolts/screws/rods:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add Cosmetic Thread Bolt Bottom View"); + sToolTipText = + QT_TR_NOOP("Add a cosmetic thread to the top or bottom view of bolts/screws/rods:
\ - Specify the line attributes (optional)
\ - Select one or more circles
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionThreadBoltBottom"; - sStatusTip = sMenuText; - sPixmap = "TechDraw_ExtensionThreadBoltBottom"; + sWhatsThis = "TechDraw_ExtensionThreadBoltBottom"; + sStatusTip = sMenuText; + sPixmap = "TechDraw_ExtensionThreadBoltBottom"; } void CmdTechDrawExtensionThreadBoltBottom::activated(int iMsg) @@ -560,15 +568,15 @@ DEF_STD_CMD_ACL(CmdTechDrawExtensionThreadsGroup) CmdTechDrawExtensionThreadsGroup::CmdTechDrawExtensionThreadsGroup() : Command("TechDraw_ExtensionThreadsGroup") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Add Cosmetic Thread Hole Side View"); - sToolTipText = QT_TR_NOOP("Add a cosmetic thread to the side view of a hole:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add Cosmetic Thread Hole Side View"); + sToolTipText = QT_TR_NOOP("Add a cosmetic thread to the side view of a hole:
\ - Specify the line attributes (optional)
\ - Select two parallel lines
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionThreadsGroup"; - sStatusTip = sMenuText; + sWhatsThis = "TechDraw_ExtensionThreadsGroup"; + sStatusTip = sMenuText; } void CmdTechDrawExtensionThreadsGroup::activated(int iMsg) @@ -577,27 +585,27 @@ void CmdTechDrawExtensionThreadsGroup::activated(int iMsg) Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog(); if (dlg) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"), - QObject::tr("Close active task dialog and try again.")); + QObject::tr("Close active task dialog and try again.")); return; } Gui::ActionGroup* pcAction = qobject_cast(_pcAction); pcAction->setIcon(pcAction->actions().at(iMsg)->icon()); switch (iMsg) { - case 0: //thread hole side view - execThreadHoleSide(this); - break; - case 1: //thread hole bottom view - execThreadHoleBottom(this); - break; - case 2: //thread bolt side view - execThreadBoltSide(this); - break; - case 3: //thread bolt bottom view - execThreadBoltBottom(this); - break; - default: - Base::Console().Message("CMD::CVGrp - invalid iMsg: %d\n", iMsg); + case 0://thread hole side view + execThreadHoleSide(this); + break; + case 1://thread hole bottom view + execThreadHoleBottom(this); + break; + case 2://thread bolt side view + execThreadBoltSide(this); + break; + case 3://thread bolt bottom view + execThreadBoltBottom(this); + break; + default: + Base::Console().Message("CMD::CVGrp - invalid iMsg: %d\n", iMsg); }; } @@ -644,33 +652,40 @@ void CmdTechDrawExtensionThreadsGroup::languageChange() QList a = pcAction->actions(); QAction* arc1 = a[0]; - arc1->setText(QApplication::translate("CmdTechDrawExtensionThreadHoleSide", "Add Cosmetic Thread Hole Side View")); + arc1->setText(QApplication::translate("CmdTechDrawExtensionThreadHoleSide", + "Add Cosmetic Thread Hole Side View")); arc1->setToolTip(QApplication::translate("CmdTechDrawExtensionThreadHoleSide", -"Add a cosmetic thread to the side view of a hole:
\ + "Add a cosmetic thread to the side view of a hole:
\ - Specify the line attributes (optional)
\ - Select two parallel lines
\ - Click this tool")); arc1->setStatusTip(arc1->text()); QAction* arc2 = a[1]; - arc2->setText(QApplication::translate("CmdTechDrawExtensionThreadHoleBottom", "Add Cosmetic Thread Hole Bottom View")); - arc2->setToolTip(QApplication::translate("CmdTechDrawExtensionThreadHoleBottom", -"Add a cosmetic thread to the top or bottom view of holes:
\ + arc2->setText(QApplication::translate("CmdTechDrawExtensionThreadHoleBottom", + "Add Cosmetic Thread Hole Bottom View")); + arc2->setToolTip( + QApplication::translate("CmdTechDrawExtensionThreadHoleBottom", + "Add a cosmetic thread to the top or bottom view of holes:
\ - Specify the line attributes (optional)
\ - Select one or more circles
\ - Click this tool")); arc2->setStatusTip(arc2->text()); QAction* arc3 = a[2]; - arc3->setText(QApplication::translate("CmdTechDrawExtensionThreadBoltSide", "Add Cosmetic Thread Bolt Side View")); - arc3->setToolTip(QApplication::translate("CmdTechDrawExtensionThreadBoltSide", -"Add a cosmetic thread to the side view of a bolt/screw/rod:
\ + arc3->setText(QApplication::translate("CmdTechDrawExtensionThreadBoltSide", + "Add Cosmetic Thread Bolt Side View")); + arc3->setToolTip( + QApplication::translate("CmdTechDrawExtensionThreadBoltSide", + "Add a cosmetic thread to the side view of a bolt/screw/rod:
\ - Specify the line attributes (optional)
\ - Select two parallel lines
\ - Click this tool")); arc3->setStatusTip(arc3->text()); QAction* arc4 = a[3]; - arc4->setText(QApplication::translate("CmdTechDrawExtensionThreadBoltBottom", "Add Cosmetic Thread Bolt Bottom View")); - arc4->setToolTip(QApplication::translate("CmdTechDrawExtensionThreadBoltBottom", -"Add a cosmetic thread to the top or bottom view of bolts/screws/rods:
\ + arc4->setText(QApplication::translate("CmdTechDrawExtensionThreadBoltBottom", + "Add Cosmetic Thread Bolt Bottom View")); + arc4->setToolTip(QApplication::translate( + "CmdTechDrawExtensionThreadBoltBottom", + "Add a cosmetic thread to the top or bottom view of bolts/screws/rods:
\ - Specify the line attributes (optional)
\ - Select one or more circles
\ - Click this tool")); @@ -693,16 +708,17 @@ DEF_STD_CMD_A(CmdTechDrawExtensionSelectLineAttributes) CmdTechDrawExtensionSelectLineAttributes::CmdTechDrawExtensionSelectLineAttributes() : Command("TechDraw_ExtensionSelectLineAttributes") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Select Line Attributes, Cascade Spacing and Delta Distance"); - sToolTipText = QT_TR_NOOP("Select the attributes for new cosmetic lines and centerlines, and specify the cascade spacing and delta distance:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Select Line Attributes, Cascade Spacing and Delta Distance"); + sToolTipText = QT_TR_NOOP( + "Select the attributes for new cosmetic lines and centerlines, and specify the cascade spacing and delta distance:
\ - Click this tool
\ - Specify the attributes, spacing and distance in the dialog box
\ - Press OK"); - sWhatsThis = "TechDraw_ExtensionSelectLineAttributes"; - sStatusTip = sMenuText; - sPixmap = "TechDraw_ExtensionSelectLineAttributes"; + sWhatsThis = "TechDraw_ExtensionSelectLineAttributes"; + sStatusTip = sMenuText; + sPixmap = "TechDraw_ExtensionSelectLineAttributes"; } void CmdTechDrawExtensionSelectLineAttributes::activated(int iMsg) @@ -727,19 +743,20 @@ DEF_STD_CMD_A(CmdTechDrawExtensionChangeLineAttributes) CmdTechDrawExtensionChangeLineAttributes::CmdTechDrawExtensionChangeLineAttributes() : Command("TechDraw_ExtensionChangeLineAttributes") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Change Line Attributes"); - sToolTipText = QT_TR_NOOP("Change the attributes of cosmetic lines and centerlines:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Change Line Attributes"); + sToolTipText = QT_TR_NOOP("Change the attributes of cosmetic lines and centerlines:
\ - Specify the line attributes (optional)
\ - Select one or more lines
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionChangeLineAttributes"; - sStatusTip = sMenuText; - sPixmap = "TechDraw_ExtensionChangeLineAttributes"; + sWhatsThis = "TechDraw_ExtensionChangeLineAttributes"; + sStatusTip = sMenuText; + sPixmap = "TechDraw_ExtensionChangeLineAttributes"; } -void CmdTechDrawExtensionChangeLineAttributes::activated(int iMsg) { +void CmdTechDrawExtensionChangeLineAttributes::activated(int iMsg) +{ // change attributes (type, width, color) of a cosmetic or centerline Q_UNUSED(iMsg); std::vector selection; @@ -786,15 +803,16 @@ DEF_STD_CMD_A(CmdTechDrawExtensionVertexAtIntersection) CmdTechDrawExtensionVertexAtIntersection::CmdTechDrawExtensionVertexAtIntersection() : Command("TechDraw_ExtensionVertexAtIntersection") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Add Cosmetic Intersection Vertex(es)"); - sToolTipText = QT_TR_NOOP("Add cosmetic vertex(es) at the intersection(s) of selected edges:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add Cosmetic Intersection Vertex(es)"); + sToolTipText = + QT_TR_NOOP("Add cosmetic vertex(es) at the intersection(s) of selected edges:
\ - Select two edges (lines, circles and/or arcs)
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionVertexAtIntersection"; - sStatusTip = sMenuText; - sPixmap = "TechDraw_ExtensionVertexAtIntersection"; + sWhatsThis = "TechDraw_ExtensionVertexAtIntersection"; + sStatusTip = sMenuText; + sPixmap = "TechDraw_ExtensionVertexAtIntersection"; } void CmdTechDrawExtensionVertexAtIntersection::activated(int iMsg) @@ -845,7 +863,8 @@ bool CmdTechDrawExtensionVertexAtIntersection::isActive() // TechDraw_ExtensionDrawCosmArc //=========================================================================== -void execDrawCosmArc(Gui::Command* cmd) { +void execDrawCosmArc(Gui::Command* cmd) +{ //draw a cosmetic arc of circle std::vector selection; TechDraw::DrawViewPart* objFeat; @@ -860,7 +879,8 @@ void execDrawCosmArc(Gui::Command* cmd) { float arcRadius = (vertexPoints[1] - vertexPoints[0]).Length(); float angle1 = _getAngle(vertexPoints[0], vertexPoints[1]); float angle2 = _getAngle(vertexPoints[0], vertexPoints[2]); - TechDraw::BaseGeomPtr baseGeo = std::make_shared(vertexPoints[0] / scale, arcRadius / scale, -angle2, -angle1); + TechDraw::BaseGeomPtr baseGeo = std::make_shared( + vertexPoints[0] / scale, arcRadius / scale, -angle2, -angle1); std::string arcTag = objFeat->addCosmeticEdge(baseGeo); TechDraw::CosmeticEdge* arcEdge = objFeat->getCosmeticEdge(arcTag); _setLineAttributes(arcEdge); @@ -876,18 +896,18 @@ DEF_STD_CMD_A(CmdTechDrawExtensionDrawCosmArc) CmdTechDrawExtensionDrawCosmArc::CmdTechDrawExtensionDrawCosmArc() : Command("TechDraw_ExtensionDrawCosmArc") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Add Cosmetic Arc"); - sToolTipText = QT_TR_NOOP("Add a cosmetic counter clockwise arc based on three vertexes:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add Cosmetic Arc"); + sToolTipText = QT_TR_NOOP("Add a cosmetic counter clockwise arc based on three vertexes:
\ - Specify the line attributes (optional)
\ - Select vertex 1 (center point)
\ - Select vertex 2 (radius and start angle)
\ - Select vertex 3 (end angle)
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionDrawCosmArc"; - sStatusTip = sMenuText; - sPixmap = "TechDraw_ExtensionDrawCosmArc"; + sWhatsThis = "TechDraw_ExtensionDrawCosmArc"; + sStatusTip = sMenuText; + sPixmap = "TechDraw_ExtensionDrawCosmArc"; } void CmdTechDrawExtensionDrawCosmArc::activated(int iMsg) @@ -908,7 +928,8 @@ bool CmdTechDrawExtensionDrawCosmArc::isActive() // TechDraw_ExtensionDrawCosmCircle //=========================================================================== -void execDrawCosmCircle(Gui::Command* cmd) { +void execDrawCosmCircle(Gui::Command* cmd) +{ //draw a cosmetic circle std::vector selection; TechDraw::DrawViewPart* objFeat; @@ -921,7 +942,8 @@ void execDrawCosmCircle(Gui::Command* cmd) { if (vertexPoints.size() >= 2) { double scale = objFeat->getScale(); float circleRadius = (vertexPoints[1] - vertexPoints[0]).Length(); - TechDraw::BaseGeomPtr baseGeo = std::make_shared(vertexPoints[0] / scale, circleRadius / scale); + TechDraw::BaseGeomPtr baseGeo = + std::make_shared(vertexPoints[0] / scale, circleRadius / scale); std::string cicleTag = objFeat->addCosmeticEdge(baseGeo); TechDraw::CosmeticEdge* circleEdge = objFeat->getCosmeticEdge(cicleTag); _setLineAttributes(circleEdge); @@ -937,17 +959,17 @@ DEF_STD_CMD_A(CmdTechDrawExtensionDrawCosmCircle) CmdTechDrawExtensionDrawCosmCircle::CmdTechDrawExtensionDrawCosmCircle() : Command("TechDraw_ExtensionDrawCosmCircle") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Add Cosmetic Circle"); - sToolTipText = QT_TR_NOOP("Add a cosmetic circle based on two vertexes:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add Cosmetic Circle"); + sToolTipText = QT_TR_NOOP("Add a cosmetic circle based on two vertexes:
\ - Specify the line attributes (optional)
\ - Select vertex 1 (center point)
\ - Select vertex 2 (radius)
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionDrawCosmCircle"; - sStatusTip = sMenuText; - sPixmap = "TechDraw_ExtensionDrawCosmCircle"; + sWhatsThis = "TechDraw_ExtensionDrawCosmCircle"; + sStatusTip = sMenuText; + sPixmap = "TechDraw_ExtensionDrawCosmCircle"; } void CmdTechDrawExtensionDrawCosmCircle::activated(int iMsg) @@ -968,7 +990,8 @@ bool CmdTechDrawExtensionDrawCosmCircle::isActive() // TechDraw_ExtensionDrawCosmCircle3Points //=========================================================================== -void execDrawCosmCircle3Points(Gui::Command* cmd) { +void execDrawCosmCircle3Points(Gui::Command* cmd) +{ //draw a cosmetic circle through 3 points std::vector selection; TechDraw::DrawViewPart* objFeat; @@ -978,12 +1001,10 @@ void execDrawCosmCircle3Points(Gui::Command* cmd) { const std::vector SubNames = selection[0].getSubNames(); std::vector vertexPoints; vertexPoints = _getVertexPoints(SubNames, objFeat); - if (vertexPoints.size() >= 3) - { + if (vertexPoints.size() >= 3) { double scale = objFeat->getScale(); - Base::Vector3d circleCenter = _circleCenter(vertexPoints[0], - vertexPoints[1], - vertexPoints[2]); + Base::Vector3d circleCenter = + _circleCenter(vertexPoints[0], vertexPoints[1], vertexPoints[2]); float circleRadius = (vertexPoints[0] - circleCenter).Length(); TechDraw::BaseGeomPtr theCircle = std::make_shared(circleCenter / scale, circleRadius / scale); @@ -1002,16 +1023,16 @@ DEF_STD_CMD_A(CmdTechDrawExtensionDrawCosmCircle3Points) CmdTechDrawExtensionDrawCosmCircle3Points::CmdTechDrawExtensionDrawCosmCircle3Points() : Command("TechDraw_ExtensionDrawCosmCircle3Points") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Add Cosmetic Circle 3 Points"); - sToolTipText = QT_TR_NOOP("Add a cosmetic circle based on three vertexes:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add Cosmetic Circle 3 Points"); + sToolTipText = QT_TR_NOOP("Add a cosmetic circle based on three vertexes:
\ - Specify the line attributes (optional)
\ - Select 3 vertexes
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionDrawCosmCircle3Points"; - sStatusTip = sMenuText; - sPixmap = "TechDraw_ExtensionDrawCosmCircle3Points"; + sWhatsThis = "TechDraw_ExtensionDrawCosmCircle3Points"; + sStatusTip = sMenuText; + sPixmap = "TechDraw_ExtensionDrawCosmCircle3Points"; } void CmdTechDrawExtensionDrawCosmCircle3Points::activated(int iMsg) @@ -1037,16 +1058,16 @@ DEF_STD_CMD_ACL(CmdTechDrawExtensionDrawCirclesGroup) CmdTechDrawExtensionDrawCirclesGroup::CmdTechDrawExtensionDrawCirclesGroup() : Command("TechDraw_ExtensionDrawCirclesGroup") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Add Cosmetic Circle"); - sToolTipText = QT_TR_NOOP("Add a cosmetic circle based on two vertexes:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add Cosmetic Circle"); + sToolTipText = QT_TR_NOOP("Add a cosmetic circle based on two vertexes:
\ - Specify the line attributes (optional)
\ - Select vertex 1 (center point)
\ - Select vertex 2 (radius)
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionDrawCirclesGroup"; - sStatusTip = sMenuText; + sWhatsThis = "TechDraw_ExtensionDrawCirclesGroup"; + sStatusTip = sMenuText; } void CmdTechDrawExtensionDrawCirclesGroup::activated(int iMsg) @@ -1055,24 +1076,24 @@ void CmdTechDrawExtensionDrawCirclesGroup::activated(int iMsg) Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog(); if (dlg) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"), - QObject::tr("Close active task dialog and try again.")); + QObject::tr("Close active task dialog and try again.")); return; } Gui::ActionGroup* pcAction = qobject_cast(_pcAction); pcAction->setIcon(pcAction->actions().at(iMsg)->icon()); switch (iMsg) { - case 0: //draw cosmetic circle - execDrawCosmCircle(this); - break; - case 1: //draw cosmetic arc - execDrawCosmArc(this); - break; - case 2: //draw cosmetic circle 3 points - execDrawCosmCircle3Points(this); - break; - default: - Base::Console().Message("CMD::CVGrp - invalid iMsg: %d\n", iMsg); + case 0://draw cosmetic circle + execDrawCosmCircle(this); + break; + case 1://draw cosmetic arc + execDrawCosmArc(this); + break; + case 2://draw cosmetic circle 3 points + execDrawCosmCircle3Points(this); + break; + default: + Base::Console().Message("CMD::CVGrp - invalid iMsg: %d\n", iMsg); }; } @@ -1115,9 +1136,10 @@ void CmdTechDrawExtensionDrawCirclesGroup::languageChange() QList a = pcAction->actions(); QAction* arc1 = a[0]; - arc1->setText(QApplication::translate("CmdTechDrawExtensionDrawCosmCircle", "Add Cosmetic Circle")); + arc1->setText( + QApplication::translate("CmdTechDrawExtensionDrawCosmCircle", "Add Cosmetic Circle")); arc1->setToolTip(QApplication::translate("CmdTechDrawExtensionDrawCosmCircle", -"Add a cosmetic circle based on two vertexes:
\ + "Add a cosmetic circle based on two vertexes:
\ - Specify the line attributes (optional)
\ - Select vertex 1 (center point)
\ - Select vertex 2 (radius)
\ @@ -1125,8 +1147,9 @@ void CmdTechDrawExtensionDrawCirclesGroup::languageChange() arc1->setStatusTip(arc1->text()); QAction* arc2 = a[1]; arc2->setText(QApplication::translate("CmdTechDrawExtensionDrawCosmArc", "Add Cosmetic Arc")); - arc2->setToolTip(QApplication::translate("CmdTechDrawExtensionDrawCosmArc", -"Add a cosmetic counter clockwise arc based on three vertexes:
\ + arc2->setToolTip( + QApplication::translate("CmdTechDrawExtensionDrawCosmArc", + "Add a cosmetic counter clockwise arc based on three vertexes:
\ - Specify the line attributes (optional)
\ - Select vertex 1 (center point)
\ - Select vertex 2 (radius and start angle)
\ @@ -1134,9 +1157,10 @@ void CmdTechDrawExtensionDrawCirclesGroup::languageChange() - Click this tool")); arc2->setStatusTip(arc2->text()); QAction* arc3 = a[2]; - arc3->setText(QApplication::translate("CmdTechDrawExtensionDrawCosmCircle3Points", "Add Cosmetic Circle 3 Points")); + arc3->setText(QApplication::translate("CmdTechDrawExtensionDrawCosmCircle3Points", + "Add Cosmetic Circle 3 Points")); arc3->setToolTip(QApplication::translate("CmdTechDrawExtensionDrawCosmCircle3Points", -"Add a cosmetic circle based on three vertexes:
\ + "Add a cosmetic circle based on three vertexes:
\ - Specify the line attributes (optional)
\ - Select three vertexes
\ - Click this tool")); @@ -1154,7 +1178,8 @@ bool CmdTechDrawExtensionDrawCirclesGroup::isActive() // TechDraw_ExtensionLineParallel //=========================================================================== -void execLineParallelPerpendicular(Gui::Command* cmd, bool isParallel) { +void execLineParallelPerpendicular(Gui::Command* cmd, bool isParallel) +{ // create a line parallel or perpendicular to another line std::vector selection; TechDraw::DrawViewPart* objFeat; @@ -1201,16 +1226,16 @@ DEF_STD_CMD_A(CmdTechDrawExtensionLineParallel) CmdTechDrawExtensionLineParallel::CmdTechDrawExtensionLineParallel() : Command("TechDraw_ExtensionLineParallel") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Add Cosmetic Parallel Line"); - sToolTipText = QT_TR_NOOP("Add a cosmetic line parallel to another line through a vertex:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add Cosmetic Parallel Line"); + sToolTipText = QT_TR_NOOP("Add a cosmetic line parallel to another line through a vertex:
\ - Select a line
\ - Select a vertex
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionLineParallel"; - sStatusTip = sMenuText; - sPixmap = "TechDraw_ExtensionLineParallel"; + sWhatsThis = "TechDraw_ExtensionLineParallel"; + sStatusTip = sMenuText; + sPixmap = "TechDraw_ExtensionLineParallel"; } void CmdTechDrawExtensionLineParallel::activated(int iMsg) @@ -1235,16 +1260,17 @@ DEF_STD_CMD_A(CmdTechDrawExtensionLinePerpendicular) CmdTechDrawExtensionLinePerpendicular::CmdTechDrawExtensionLinePerpendicular() : Command("TechDraw_ExtensionLinePerpendicular") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Add Cosmetic Perpendicular Line"); - sToolTipText = QT_TR_NOOP("Add a cosmetic line perpendicular to another line through a vertex:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add Cosmetic Perpendicular Line"); + sToolTipText = + QT_TR_NOOP("Add a cosmetic line perpendicular to another line through a vertex:
\ - Select a line
\ - Select a vertex
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionLinePerpendicular"; - sStatusTip = sMenuText; - sPixmap = "TechDraw_ExtensionLinePerpendicular"; + sWhatsThis = "TechDraw_ExtensionLinePerpendicular"; + sStatusTip = sMenuText; + sPixmap = "TechDraw_ExtensionLinePerpendicular"; } void CmdTechDrawExtensionLinePerpendicular::activated(int iMsg) @@ -1269,15 +1295,15 @@ DEF_STD_CMD_ACL(CmdTechDrawExtensionLinePPGroup) CmdTechDrawExtensionLinePPGroup::CmdTechDrawExtensionLinePPGroup() : Command("TechDraw_ExtensionLinePPGroup") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Add Cosmetic Parallel Line"); - sToolTipText = QT_TR_NOOP("Add a cosmetic line parallel to another line through a vertex:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add Cosmetic Parallel Line"); + sToolTipText = QT_TR_NOOP("Add a cosmetic line parallel to another line through a vertex:
\ - Select a line
\ - Select a vertex
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionLinePPGroup"; - sStatusTip = sMenuText; + sWhatsThis = "TechDraw_ExtensionLinePPGroup"; + sStatusTip = sMenuText; } void CmdTechDrawExtensionLinePPGroup::activated(int iMsg) @@ -1286,21 +1312,21 @@ void CmdTechDrawExtensionLinePPGroup::activated(int iMsg) Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog(); if (dlg) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"), - QObject::tr("Close active task dialog and try again.")); + QObject::tr("Close active task dialog and try again.")); return; } Gui::ActionGroup* pcAction = qobject_cast(_pcAction); pcAction->setIcon(pcAction->actions().at(iMsg)->icon()); switch (iMsg) { - case 0: //create parallel line - execLineParallelPerpendicular(this, true); - break; - case 1: //create perpendicular line - execLineParallelPerpendicular(this, false); - break; - default: - Base::Console().Message("CMD::CVGrp - invalid iMsg: %d\n", iMsg); + case 0://create parallel line + execLineParallelPerpendicular(this, true); + break; + case 1://create perpendicular line + execLineParallelPerpendicular(this, false); + break; + default: + Base::Console().Message("CMD::CVGrp - invalid iMsg: %d\n", iMsg); }; } @@ -1339,17 +1365,21 @@ void CmdTechDrawExtensionLinePPGroup::languageChange() QList a = pcAction->actions(); QAction* arc1 = a[0]; - arc1->setText(QApplication::translate("CmdTechDrawExtensionLineParallel", "Add Cosmetic Parallel Line")); - arc1->setToolTip(QApplication::translate("CmdTechDrawExtensionLineParallel", -"Add a cosmetic line parallel to another line through a vertex:
\ + arc1->setText( + QApplication::translate("CmdTechDrawExtensionLineParallel", "Add Cosmetic Parallel Line")); + arc1->setToolTip( + QApplication::translate("CmdTechDrawExtensionLineParallel", + "Add a cosmetic line parallel to another line through a vertex:
\ - Select a line
\ - Select a vertex
\ - Click this tool")); arc1->setStatusTip(arc1->text()); QAction* arc2 = a[1]; - arc2->setText(QApplication::translate("CmdTechDrawExtensionLinePerpendicular", "Add Cosmetic Perpendicular Line")); - arc2->setToolTip(QApplication::translate("CmdTechDrawExtensionLinePerpendicular", -"Add a cosmetic line perpendicular to another line through a vertex:
\ + arc2->setText(QApplication::translate("CmdTechDrawExtensionLinePerpendicular", + "Add Cosmetic Perpendicular Line")); + arc2->setToolTip(QApplication::translate( + "CmdTechDrawExtensionLinePerpendicular", + "Add a cosmetic line perpendicular to another line through a vertex:
\ - Select a line
\ - Select a vertex
\ - Click this tool")); @@ -1372,18 +1402,19 @@ DEF_STD_CMD_A(CmdTechDrawExtensionLockUnlockView) CmdTechDrawExtensionLockUnlockView::CmdTechDrawExtensionLockUnlockView() : Command("TechDraw_ExtensionLockUnlockView") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Lock/Unlock View"); - sToolTipText = QT_TR_NOOP("Lock or unlock the position of a view:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Lock/Unlock View"); + sToolTipText = QT_TR_NOOP("Lock or unlock the position of a view:
\ - Select a single view
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionLockUnlockView"; - sStatusTip = sMenuText; - sPixmap = "TechDraw_ExtensionLockUnlockView"; + sWhatsThis = "TechDraw_ExtensionLockUnlockView"; + sStatusTip = sMenuText; + sPixmap = "TechDraw_ExtensionLockUnlockView"; } -void CmdTechDrawExtensionLockUnlockView::activated(int iMsg) { +void CmdTechDrawExtensionLockUnlockView::activated(int iMsg) +{ // lock/unlock a selected view Q_UNUSED(iMsg); std::vector selection; @@ -1415,30 +1446,30 @@ DEF_STD_CMD_A(CmdTechDrawExtensionPositionSectionView) CmdTechDrawExtensionPositionSectionView::CmdTechDrawExtensionPositionSectionView() : Command("TechDraw_ExtensionPositionSectionView") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Position Section View"); - sToolTipText = QT_TR_NOOP("Orthogonally align a section view with its source view:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Position Section View"); + sToolTipText = QT_TR_NOOP("Orthogonally align a section view with its source view:
\ - Select a single section view
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionPositionSectionView"; - sStatusTip = sMenuText; - sPixmap = "TechDraw_ExtensionPositionSectionView"; + sWhatsThis = "TechDraw_ExtensionPositionSectionView"; + sStatusTip = sMenuText; + sPixmap = "TechDraw_ExtensionPositionSectionView"; } -void CmdTechDrawExtensionPositionSectionView::activated(int iMsg) { +void CmdTechDrawExtensionPositionSectionView::activated(int iMsg) +{ // position a section view Q_UNUSED(iMsg); //Base::Console().Message("PositionSectionView started\n"); auto selection = getSelection().getSelectionEx(); if (selection.empty()) { - QMessageBox::warning(Gui::getMainWindow(), - QObject::tr("TechDraw Position Section View"), - QObject::tr("Selection is empty")); + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("TechDraw Position Section View"), + QObject::tr("Selection is empty")); return; } - double xPos=0.0, yPos=0.0; + double xPos = 0.0, yPos = 0.0; TechDraw::DrawViewPart* baseView; auto objFeat = selection[0].getObject(); if (objFeat && objFeat->isDerivedFrom(TechDraw::DrawViewSection::getClassTypeId())) { @@ -1447,7 +1478,8 @@ void CmdTechDrawExtensionPositionSectionView::activated(int iMsg) { if (baseView && baseView->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) { std::vector parentViews = baseView->getInList(); if (!parentViews.empty()) { - TechDraw::DrawProjGroup* groupBase = dynamic_cast(parentViews[0]); + TechDraw::DrawProjGroup* groupBase = + dynamic_cast(parentViews[0]); if (groupBase) { xPos = groupBase->X.getValue(); yPos = groupBase->Y.getValue(); @@ -1477,7 +1509,8 @@ bool CmdTechDrawExtensionPositionSectionView::isActive() // TechDraw_ExtensionExtendLine //=========================================================================== -void execExtendShortenLine(Gui::Command* cmd, bool extend) { +void execExtendShortenLine(Gui::Command* cmd, bool extend) +{ // extend or shorten a cosmetic line or a centerline std::vector selection; TechDraw::DrawViewPart* objFeat; @@ -1493,7 +1526,8 @@ void execExtendShortenLine(Gui::Command* cmd, bool extend) { TechDraw::BaseGeomPtr baseGeo = objFeat->getGeomByIndex(num); if (baseGeo) { if (baseGeo->geomType == TechDraw::GENERIC) { - TechDraw::GenericPtr genLine = std::static_pointer_cast(baseGeo); + TechDraw::GenericPtr genLine = + std::static_pointer_cast(baseGeo); Base::Vector3d P0 = genLine->points.at(0); Base::Vector3d P1 = genLine->points.at(1); bool isCenterLine = false; @@ -1533,8 +1567,10 @@ void execExtendShortenLine(Gui::Command* cmd, bool extend) { if (isCenterLine) { centerEdge->m_extendBy += activeDimAttributes.getLineStretch(); objFeat->refreshCLGeoms(); - } else { - std::string lineTag = objFeat->addCosmeticEdge(startPt / scale, endPt / scale); + } + else { + std::string lineTag = + objFeat->addCosmeticEdge(startPt / scale, endPt / scale); TechDraw::CosmeticEdge* lineEdge = objFeat->getCosmeticEdge(lineTag); _setLineAttributes(lineEdge, oldStyle, oldWeight, oldColor); objFeat->refreshCEGeoms(); @@ -1553,16 +1589,16 @@ DEF_STD_CMD_A(CmdTechDrawExtensionExtendLine) CmdTechDrawExtensionExtendLine::CmdTechDrawExtensionExtendLine() : Command("TechDraw_ExtensionExtendLine") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Extend Line"); - sToolTipText = QT_TR_NOOP("Extend a cosmetic line or centerline at both ends:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Extend Line"); + sToolTipText = QT_TR_NOOP("Extend a cosmetic line or centerline at both ends:
\ - Specify the delta distance (optional)
\ - Select a single line
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionExtendLine"; - sStatusTip = sMenuText; - sPixmap = "TechDraw_ExtensionExtendLine"; + sWhatsThis = "TechDraw_ExtensionExtendLine"; + sStatusTip = sMenuText; + sPixmap = "TechDraw_ExtensionExtendLine"; } void CmdTechDrawExtensionExtendLine::activated(int iMsg) @@ -1588,16 +1624,16 @@ DEF_STD_CMD_A(CmdTechDrawExtensionShortenLine) CmdTechDrawExtensionShortenLine::CmdTechDrawExtensionShortenLine() : Command("TechDraw_ExtensionShortenLine") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Shorten Line"); - sToolTipText = QT_TR_NOOP("Shorten a cosmetic line or centerline at both ends:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Shorten Line"); + sToolTipText = QT_TR_NOOP("Shorten a cosmetic line or centerline at both ends:
\ - Specify the delta distance (optional)
\ - Select a single line
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionShortenLine"; - sStatusTip = sMenuText; - sPixmap = "TechDraw_ExtensionShortenLine"; + sWhatsThis = "TechDraw_ExtensionShortenLine"; + sStatusTip = sMenuText; + sPixmap = "TechDraw_ExtensionShortenLine"; } void CmdTechDrawExtensionShortenLine::activated(int iMsg) @@ -1623,15 +1659,15 @@ DEF_STD_CMD_ACL(CmdTechDrawExtendShortenLineGroup) CmdTechDrawExtendShortenLineGroup::CmdTechDrawExtendShortenLineGroup() : Command("TechDraw_ExtensionExtendShortenLineGroup") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Extend Line"); - sToolTipText = QT_TR_NOOP("Extend a cosmetic line or centerline at both ends:
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Extend Line"); + sToolTipText = QT_TR_NOOP("Extend a cosmetic line or centerline at both ends:
\ - Specify the delta distance (optional)
\ - Select a single line
\ - Click this tool"); - sWhatsThis = "TechDraw_ExtensionExtendShortenLineGroup"; - sStatusTip = sMenuText; + sWhatsThis = "TechDraw_ExtensionExtendShortenLineGroup"; + sStatusTip = sMenuText; } void CmdTechDrawExtendShortenLineGroup::activated(int iMsg) @@ -1640,21 +1676,21 @@ void CmdTechDrawExtendShortenLineGroup::activated(int iMsg) Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog(); if (dlg) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"), - QObject::tr("Close active task dialog and try again.")); + QObject::tr("Close active task dialog and try again.")); return; } Gui::ActionGroup* pcAction = qobject_cast(_pcAction); pcAction->setIcon(pcAction->actions().at(iMsg)->icon()); switch (iMsg) { - case 0: //extend a line - execExtendShortenLine(this, true); - break; - case 1: //shorten line - execExtendShortenLine(this, false); - break; - default: - Base::Console().Message("CMD::CVGrp - invalid iMsg: %d\n", iMsg); + case 0://extend a line + execExtendShortenLine(this, true); + break; + case 1://shorten line + execExtendShortenLine(this, false); + break; + default: + Base::Console().Message("CMD::CVGrp - invalid iMsg: %d\n", iMsg); }; } @@ -1694,16 +1730,16 @@ void CmdTechDrawExtendShortenLineGroup::languageChange() QAction* arc1 = a[0]; arc1->setText(QApplication::translate("CmdTechDrawExtensionExtendLine", "Extend Line")); - arc1->setToolTip(QApplication::translate("CmdTechDrawExtensionExtendLine", -"Extend a cosmetic line or centerline at both ends:
\ + arc1->setToolTip(QApplication::translate( + "CmdTechDrawExtensionExtendLine", "Extend a cosmetic line or centerline at both ends:
\ - Specify the delta distance (optional)
\ - Select a single line
\ - Click this tool")); arc1->setStatusTip(arc1->text()); QAction* arc2 = a[1]; arc2->setText(QApplication::translate("CmdTechDrawExtensionShortenLine", "Shorten Line")); - arc2->setToolTip(QApplication::translate("CmdTechDrawExtensionShortenLine", -"Shorten a cosmetic line or centerline at both ends:
\ + arc2->setToolTip(QApplication::translate( + "CmdTechDrawExtensionShortenLine", "Shorten a cosmetic line or centerline at both ends:
\ - Specify the delta distance (optional)
\ - Select a single line
\ - Click this tool")); @@ -1724,16 +1760,16 @@ bool CmdTechDrawExtendShortenLineGroup::isActive() DEF_STD_CMD_A(CmdTechDrawExtensionAreaAnnotation) CmdTechDrawExtensionAreaAnnotation::CmdTechDrawExtensionAreaAnnotation() - : Command("TechDraw_ExtensionAreaAnnotation") + : Command("TechDraw_ExtensionAreaAnnotation") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Calculate the area of selected faces"); - sToolTipText = QT_TR_NOOP("Select several faces
\ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Calculate the area of selected faces"); + sToolTipText = QT_TR_NOOP("Select several faces
\ - click this tool"); - sWhatsThis = "TechDraw_ExtensionAreaAnnotation"; - sStatusTip = sToolTipText; - sPixmap = "TechDraw_ExtensionAreaAnnotation"; + sWhatsThis = "TechDraw_ExtensionAreaAnnotation"; + sStatusTip = sToolTipText; + sPixmap = "TechDraw_ExtensionAreaAnnotation"; } void CmdTechDrawExtensionAreaAnnotation::activated(int iMsg) @@ -1754,19 +1790,19 @@ void CmdTechDrawExtensionAreaAnnotation::activated(int iMsg) // We filter arcs, circles etc. which are not allowed. for (const TechDraw::BaseGeomPtr& geoPtr : faceEdges) if (geoPtr->geomType != TechDraw::GENERIC) - throw Base::TypeError("CmdTechDrawAreaAnnotation - forbidden border element found\n"); + throw Base::TypeError( + "CmdTechDrawAreaAnnotation - forbidden border element found\n"); // We create a list of all points along the boundary of the face. // The edges form a closed polygon, but their start- and endpoints may be interchanged. std::vector facePoints; TechDraw::GenericPtr firstEdge = - std::static_pointer_cast(faceEdges[0]); + std::static_pointer_cast(faceEdges[0]); facePoints.push_back(firstEdge->points.at(0)); facePoints.push_back(firstEdge->points.at(1)); - for (long unsigned int n = 1; n < faceEdges.size() - 1; n++) - { + for (long unsigned int n = 1; n < faceEdges.size() - 1; n++) { TechDraw::GenericPtr nextEdge = - std::static_pointer_cast(faceEdges[n]); - if ((nextEdge->points.at(0)-facePoints.back()).Length() < 0.01) + std::static_pointer_cast(faceEdges[n]); + if ((nextEdge->points.at(0) - facePoints.back()).Length() < 0.01) facePoints.push_back(nextEdge->points.at(1)); else facePoints.push_back(nextEdge->points.at(0)); @@ -1776,14 +1812,13 @@ void CmdTechDrawExtensionAreaAnnotation::activated(int iMsg) faceArea = 0.0; xCenter = xCenter + facePoints[0].x; yCenter = yCenter + facePoints[0].y; - for (long unsigned int n = 0; n < facePoints.size() - 1; n++) - { - faceArea = faceArea + facePoints[n].x * facePoints[n+1].y - - facePoints[n].y * facePoints[n+1].x; - xCenter = xCenter + facePoints[n+1].x; - yCenter = yCenter + facePoints[n+1].y; + for (long unsigned int n = 0; n < facePoints.size() - 1; n++) { + faceArea = faceArea + facePoints[n].x * facePoints[n + 1].y + - facePoints[n].y * facePoints[n + 1].x; + xCenter = xCenter + facePoints[n + 1].x; + yCenter = yCenter + facePoints[n + 1].y; } - faceArea = abs(faceArea)/2.0; + faceArea = abs(faceArea) / 2.0; totalArea = totalArea + faceArea; totalPoints = totalPoints + facePoints.size(); } @@ -1791,16 +1826,17 @@ void CmdTechDrawExtensionAreaAnnotation::activated(int iMsg) // if area calculation was successful, start the command Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Calculate Face Area")); // at first we create the balloon - std::string balloonName = _createBalloon(this, objFeat); + std::string balloonName = _createBalloon(this, objFeat); TechDraw::DrawViewBalloon* balloon = nullptr; - balloon = dynamic_cast(this->getDocument()->getObject(balloonName.c_str())); + balloon = dynamic_cast( + this->getDocument()->getObject(balloonName.c_str())); if (!balloon) throw Base::TypeError("CmdTechDrawNewBalloon - balloon not found\n"); // the balloon has been created successfully // calculate needed variables double scale = objFeat->getScale(); double scale2 = scale * scale; - totalArea = totalArea / scale2; //convert from view scale to internal mm2 + totalArea = totalArea / scale2;//convert from view scale to internal mm2 //make area unit-aware Base::Quantity asQuantity; @@ -1810,12 +1846,12 @@ void CmdTechDrawExtensionAreaAnnotation::activated(int iMsg) std::string sUserString = Base::Tools::toStdString(qUserString); if (totalPoints != 0 && scale != 0.0) { - xCenter = (xCenter/totalPoints)/scale; - yCenter = (yCenter/totalPoints)/scale; + xCenter = (xCenter / totalPoints) / scale; + yCenter = (yCenter / totalPoints) / scale; } // set the attributes in the data tab's fields - balloon->SourceView.setValue(objFeat); + // balloon->SourceView.setValue(objFeat); balloon->BubbleShape.setValue("Rectangle"); balloon->EndType.setValue("None"); balloon->KinkLength.setValue(0.0); @@ -1829,8 +1865,7 @@ void CmdTechDrawExtensionAreaAnnotation::activated(int iMsg) TechDraw::DrawPage* page = objFeat->findParentPage(); Gui::Document* guiDoc = Gui::Application::Instance->getDocument(page->getDocument()); auto viewProvider = static_cast(guiDoc->getViewProvider(balloon)); - if (viewProvider) - { + if (viewProvider) { // view provider successfully found, // set the attributes in the view tab's fields viewProvider->Fontsize.setValue(2.0); @@ -1853,188 +1888,202 @@ bool CmdTechDrawExtensionAreaAnnotation::isActive() //=========================================================================== // internal helper routines //=========================================================================== -namespace TechDrawGui { +namespace TechDrawGui +{ - lineAttributes& _getActiveLineAttributes() - { - static lineAttributes attributes; - return attributes; +lineAttributes& _getActiveLineAttributes() +{ + static lineAttributes attributes; + return attributes; +} + +std::string _createBalloon(Gui::Command* cmd, TechDraw::DrawViewPart* objFeat) +// create a new balloon, return it's name as string +{ + std::string featName; + TechDraw::DrawPage* page = objFeat->findParentPage(); + Gui::Document* guiDoc = Gui::Application::Instance->getDocument(page->getDocument()); + ViewProviderPage* pageVP = dynamic_cast(guiDoc->getViewProvider(page)); + if (pageVP) { + QGSPage* scenePage = pageVP->getQGSPage(); + featName = scenePage->getDrawPage()->getDocument()->getUniqueObjectName("Balloon"); + std::string pageName = scenePage->getDrawPage()->getNameInDocument(); + cmd->doCommand(cmd->Doc, + "App.activeDocument().addObject('TechDraw::DrawViewBalloon', '%s')", + featName.c_str()); + cmd->doCommand(cmd->Doc, "App.activeDocument().%s.SourceView = (App.activeDocument().%s)", + featName.c_str(), objFeat->getNameInDocument()); + + cmd->doCommand(cmd->Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", + pageName.c_str(), featName.c_str()); + } + return featName; +} + +bool _checkSel(Gui::Command* cmd, std::vector& selection, + TechDraw::DrawViewPart*& objFeat, std::string message) +{ + // check selection of getSelectionEx() and selection[0].getObject() + selection = cmd->getSelection().getSelectionEx(); + if (selection.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr(message.c_str()), + QObject::tr("Selection is empty")); + return false; } - std::string _createBalloon(Gui::Command* cmd, TechDraw::DrawViewPart* objFeat) - // create a new balloon, return it's name as string - { - std::string featName; - TechDraw::DrawPage* page = objFeat->findParentPage(); - page->balloonParent = objFeat; - Gui::Document* guiDoc = Gui::Application::Instance->getDocument(page->getDocument()); - ViewProviderPage* pageVP = dynamic_cast(guiDoc->getViewProvider(page)); - if (pageVP) { - QGSPage* scenePage = pageVP->getQGSPage(); - featName = scenePage->getDrawPage()->getDocument()->getUniqueObjectName("Balloon"); - std::string pageName = scenePage->getDrawPage()->getNameInDocument(); - cmd->doCommand(cmd->Doc, "App.activeDocument().addObject('TechDraw::DrawViewBalloon', '%s')", - featName.c_str()); - cmd->doCommand(cmd->Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", - pageName.c_str(), featName.c_str()); - } - return featName; + objFeat = dynamic_cast(selection[0].getObject()); + if (!objFeat) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr(message.c_str()), + QObject::tr("No object selected")); + return false; } - bool _checkSel(Gui::Command* cmd, - std::vector& selection, - TechDraw::DrawViewPart*& objFeat, - std::string message) { - // check selection of getSelectionEx() and selection[0].getObject() - selection = cmd->getSelection().getSelectionEx(); - if (selection.empty()) { - QMessageBox::warning(Gui::getMainWindow(), - QObject::tr(message.c_str()), - QObject::tr("Selection is empty")); - return false; - } + return true; +} - objFeat = dynamic_cast(selection[0].getObject()); - if (!objFeat) { - QMessageBox::warning(Gui::getMainWindow(), - QObject::tr(message.c_str()), - QObject::tr("No object selected")); - return false; - } - - return true; - } - - std::vector _getVertexPoints(std::vector SubNames, TechDraw::DrawViewPart* objFeat) { - // get vertex points as Vector3d - std::vector vertexPoints; - for (const std::string& Name : SubNames) { - std::string GeoType = TechDraw::DrawUtil::getGeomTypeFromName(Name); - if (GeoType == "Vertex") { - int GeoId = TechDraw::DrawUtil::getIndexFromName(Name); - TechDraw::VertexPtr vert = objFeat->getProjVertexByIndex(GeoId); - Base::Vector3d onePoint(vert->point().x, vert->point().y, 0); - vertexPoints.push_back(onePoint); - } - } - return vertexPoints; - } - - float _getAngle(Base::Vector3d center, Base::Vector3d point) { - // get angle between x-axis and the vector from center to point - const auto Pi180 = 180.0 / M_PI; - Base::Vector3d vecCP = point - center; - float dy = vecCP.y; - float sign = -1.0; - if (dy < 0.0) - sign = -sign; - float angle = acos(vecCP.Normalize().x) * Pi180 * sign; - if (angle < 0.0) - angle = 360 + angle; - return angle; - } - - Base::Vector3d _circleCenter(Base::Vector3d p1, Base::Vector3d p2, Base::Vector3d p3) { - Base::Vector2d v1(p1.x, p1.y); - Base::Vector2d v2(p2.x, p2.y); - Base::Vector2d v3(p3.x, p3.y); - Base::Vector2d c = Part::Geom2dCircle::getCircleCenter(v1, v2, v3); - return Base::Vector3d(c.x, c.y, 0.0); - } - - void _createThreadCircle(std::string Name, TechDraw::DrawViewPart* objFeat, float factor) { - // create the 3/4 arc symbolizing a thread from top seen - double scale = objFeat->getScale(); - int GeoId = TechDraw::DrawUtil::getIndexFromName(Name); - TechDraw::BaseGeomPtr geom = objFeat->getGeomByIndex(GeoId); +std::vector _getVertexPoints(std::vector SubNames, + TechDraw::DrawViewPart* objFeat) +{ + // get vertex points as Vector3d + std::vector vertexPoints; + for (const std::string& Name : SubNames) { std::string GeoType = TechDraw::DrawUtil::getGeomTypeFromName(Name); - - if (GeoType == "Edge" && geom->geomType == TechDraw::CIRCLE) { - TechDraw::CirclePtr cgen = std::static_pointer_cast (geom); - Base::Vector3d center = cgen->center; - float radius = cgen->radius; - TechDraw::BaseGeomPtr threadArc = - std::make_shared(center / scale, radius * factor / scale, 255.0, 165.0); - std::string arcTag = objFeat->addCosmeticEdge(threadArc); - TechDraw::CosmeticEdge* arc = objFeat->getCosmeticEdge(arcTag); - _setLineAttributes(arc); + if (GeoType == "Vertex") { + int GeoId = TechDraw::DrawUtil::getIndexFromName(Name); + TechDraw::VertexPtr vert = objFeat->getProjVertexByIndex(GeoId); + Base::Vector3d onePoint(vert->point().x, vert->point().y, 0); + vertexPoints.push_back(onePoint); } } + return vertexPoints; +} - void _createThreadLines(std::vector SubNames, TechDraw::DrawViewPart* objFeat, float factor) { - // create symbolizing lines of a thread from the side seen - double scale = objFeat->getScale(); - std::string GeoType0 = TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]); - std::string GeoType1 = TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]); - if ((GeoType0 == "Edge") && (GeoType1 == "Edge")) { - int GeoId0 = TechDraw::DrawUtil::getIndexFromName(SubNames[0]); - int GeoId1 = TechDraw::DrawUtil::getIndexFromName(SubNames[1]); - TechDraw::BaseGeomPtr geom0 = objFeat->getGeomByIndex(GeoId0); - TechDraw::BaseGeomPtr geom1 = objFeat->getGeomByIndex(GeoId1); - if (geom0->geomType != TechDraw::GENERIC || geom1->geomType != TechDraw::GENERIC) { - QMessageBox::warning(Gui::getMainWindow(), - QObject::tr("TechDraw Thread Hole Side"), - QObject::tr("Please select two straight lines")); - return; - } +float _getAngle(Base::Vector3d center, Base::Vector3d point) +{ + // get angle between x-axis and the vector from center to point + const auto Pi180 = 180.0 / M_PI; + Base::Vector3d vecCP = point - center; + float dy = vecCP.y; + float sign = -1.0; + if (dy < 0.0) + sign = -sign; + float angle = acos(vecCP.Normalize().x) * Pi180 * sign; + if (angle < 0.0) + angle = 360 + angle; + return angle; +} - TechDraw::GenericPtr line0 = std::static_pointer_cast (geom0); - TechDraw::GenericPtr line1 = std::static_pointer_cast (geom1); - Base::Vector3d start0 = line0->points.at(0); - Base::Vector3d end0 = line0->points.at(1); - Base::Vector3d start1 = line1->points.at(0); - Base::Vector3d end1 = line1->points.at(1); - if (DrawUtil::circulation(start0, end0, start1) != DrawUtil::circulation(end0, end1, start1)) { - Base::Vector3d help1 = start1; - Base::Vector3d help2 = end1; - start1 = help2; - end1 = help1; - } - start0.y = -start0.y; - end0.y = -end0.y; - start1.y = -start1.y; - end1.y = -end1.y; - float kernelDiam = (start1 - start0).Length(); - float kernelFactor = (kernelDiam * factor - kernelDiam) / 2; - Base::Vector3d delta = (start1 - start0).Normalize() * kernelFactor; - std::string line0Tag = objFeat->addCosmeticEdge((start0 - delta) / scale, (end0 - delta) / scale); - std::string line1Tag = objFeat->addCosmeticEdge((start1 + delta) / scale, (end1 + delta) / scale); - TechDraw::CosmeticEdge* cosTag0 = objFeat->getCosmeticEdge(line0Tag); - TechDraw::CosmeticEdge* cosTag1 = objFeat->getCosmeticEdge(line1Tag); - _setLineAttributes(cosTag0); - _setLineAttributes(cosTag1); - } - } +Base::Vector3d _circleCenter(Base::Vector3d p1, Base::Vector3d p2, Base::Vector3d p3) +{ + Base::Vector2d v1(p1.x, p1.y); + Base::Vector2d v2(p2.x, p2.y); + Base::Vector2d v3(p3.x, p3.y); + Base::Vector2d c = Part::Geom2dCircle::getCircleCenter(v1, v2, v3); + return Base::Vector3d(c.x, c.y, 0.0); +} - void _setLineAttributes(TechDraw::CosmeticEdge* cosEdge) { - // set line attributes of a cosmetic edge - cosEdge->m_format.m_style = _getActiveLineAttributes().getStyle(); - cosEdge->m_format.m_weight = _getActiveLineAttributes().getWidthValue(); - cosEdge->m_format.m_color = _getActiveLineAttributes().getColorValue(); - } +void _createThreadCircle(std::string Name, TechDraw::DrawViewPart* objFeat, float factor) +{ + // create the 3/4 arc symbolizing a thread from top seen + double scale = objFeat->getScale(); + int GeoId = TechDraw::DrawUtil::getIndexFromName(Name); + TechDraw::BaseGeomPtr geom = objFeat->getGeomByIndex(GeoId); + std::string GeoType = TechDraw::DrawUtil::getGeomTypeFromName(Name); - void _setLineAttributes(TechDraw::CenterLine* cosEdge) { - // set line attributes of a cosmetic edge - cosEdge->m_format.m_style = _getActiveLineAttributes().getStyle(); - cosEdge->m_format.m_weight = _getActiveLineAttributes().getWidthValue(); - cosEdge->m_format.m_color = _getActiveLineAttributes().getColorValue(); - } - - void _setLineAttributes(TechDraw::CosmeticEdge* cosEdge, int style, float weight, App::Color color) { - // set line attributes of a cosmetic edge - cosEdge->m_format.m_style = style; - cosEdge->m_format.m_weight = weight; - cosEdge->m_format.m_color = color; - } - - void _setLineAttributes(TechDraw::CenterLine* cosEdge, int style, float weight, App::Color color) { - // set line attributes of a centerline - cosEdge->m_format.m_style = style; - cosEdge->m_format.m_weight = weight; - cosEdge->m_format.m_color = color; + if (GeoType == "Edge" && geom->geomType == TechDraw::CIRCLE) { + TechDraw::CirclePtr cgen = std::static_pointer_cast(geom); + Base::Vector3d center = cgen->center; + float radius = cgen->radius; + TechDraw::BaseGeomPtr threadArc = + std::make_shared(center / scale, radius * factor / scale, 255.0, 165.0); + std::string arcTag = objFeat->addCosmeticEdge(threadArc); + TechDraw::CosmeticEdge* arc = objFeat->getCosmeticEdge(arcTag); + _setLineAttributes(arc); } } +void _createThreadLines(std::vector SubNames, TechDraw::DrawViewPart* objFeat, + float factor) +{ + // create symbolizing lines of a thread from the side seen + double scale = objFeat->getScale(); + std::string GeoType0 = TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]); + std::string GeoType1 = TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]); + if ((GeoType0 == "Edge") && (GeoType1 == "Edge")) { + int GeoId0 = TechDraw::DrawUtil::getIndexFromName(SubNames[0]); + int GeoId1 = TechDraw::DrawUtil::getIndexFromName(SubNames[1]); + TechDraw::BaseGeomPtr geom0 = objFeat->getGeomByIndex(GeoId0); + TechDraw::BaseGeomPtr geom1 = objFeat->getGeomByIndex(GeoId1); + if (geom0->geomType != TechDraw::GENERIC || geom1->geomType != TechDraw::GENERIC) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("TechDraw Thread Hole Side"), + QObject::tr("Please select two straight lines")); + return; + } + + TechDraw::GenericPtr line0 = std::static_pointer_cast(geom0); + TechDraw::GenericPtr line1 = std::static_pointer_cast(geom1); + Base::Vector3d start0 = line0->points.at(0); + Base::Vector3d end0 = line0->points.at(1); + Base::Vector3d start1 = line1->points.at(0); + Base::Vector3d end1 = line1->points.at(1); + if (DrawUtil::circulation(start0, end0, start1) + != DrawUtil::circulation(end0, end1, start1)) { + Base::Vector3d help1 = start1; + Base::Vector3d help2 = end1; + start1 = help2; + end1 = help1; + } + start0.y = -start0.y; + end0.y = -end0.y; + start1.y = -start1.y; + end1.y = -end1.y; + float kernelDiam = (start1 - start0).Length(); + float kernelFactor = (kernelDiam * factor - kernelDiam) / 2; + Base::Vector3d delta = (start1 - start0).Normalize() * kernelFactor; + std::string line0Tag = + objFeat->addCosmeticEdge((start0 - delta) / scale, (end0 - delta) / scale); + std::string line1Tag = + objFeat->addCosmeticEdge((start1 + delta) / scale, (end1 + delta) / scale); + TechDraw::CosmeticEdge* cosTag0 = objFeat->getCosmeticEdge(line0Tag); + TechDraw::CosmeticEdge* cosTag1 = objFeat->getCosmeticEdge(line1Tag); + _setLineAttributes(cosTag0); + _setLineAttributes(cosTag1); + } +} + +void _setLineAttributes(TechDraw::CosmeticEdge* cosEdge) +{ + // set line attributes of a cosmetic edge + cosEdge->m_format.m_style = _getActiveLineAttributes().getStyle(); + cosEdge->m_format.m_weight = _getActiveLineAttributes().getWidthValue(); + cosEdge->m_format.m_color = _getActiveLineAttributes().getColorValue(); +} + +void _setLineAttributes(TechDraw::CenterLine* cosEdge) +{ + // set line attributes of a cosmetic edge + cosEdge->m_format.m_style = _getActiveLineAttributes().getStyle(); + cosEdge->m_format.m_weight = _getActiveLineAttributes().getWidthValue(); + cosEdge->m_format.m_color = _getActiveLineAttributes().getColorValue(); +} + +void _setLineAttributes(TechDraw::CosmeticEdge* cosEdge, int style, float weight, App::Color color) +{ + // set line attributes of a cosmetic edge + cosEdge->m_format.m_style = style; + cosEdge->m_format.m_weight = weight; + cosEdge->m_format.m_color = color; +} + +void _setLineAttributes(TechDraw::CenterLine* cosEdge, int style, float weight, App::Color color) +{ + // set line attributes of a centerline + cosEdge->m_format.m_style = style; + cosEdge->m_format.m_weight = weight; + cosEdge->m_format.m_color = color; +} +}// namespace TechDrawGui + //------------------------------------------------------------------------------ void CreateTechDrawCommandsExtensions() { diff --git a/src/Mod/TechDraw/Gui/QGIViewAnnotation.cpp b/src/Mod/TechDraw/Gui/QGIViewAnnotation.cpp index 517484ccb2..0872a488d0 100644 --- a/src/Mod/TechDraw/Gui/QGIViewAnnotation.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewAnnotation.cpp @@ -23,18 +23,18 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include +#include +#include +#include +#include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include #endif #include @@ -45,11 +45,10 @@ #include #include "DlgStringListEditor.h" -#include "QGIViewAnnotation.h" #include "QGCustomText.h" +#include "QGIViewAnnotation.h" #include "Rez.h" - using namespace TechDrawGui; QGIViewAnnotation::QGIViewAnnotation() @@ -66,27 +65,23 @@ QGIViewAnnotation::QGIViewAnnotation() //QObject::connect(QGraphicsTextItem::document(), SIGNAL(contentsChanged()), m_textItem, SLOT(updateText())); //not tested addToGroup(m_textItem); m_textItem->setPos(0., 0.); - } -void QGIViewAnnotation::setViewAnnoFeature(TechDraw::DrawViewAnnotation *obj) +void QGIViewAnnotation::setViewAnnoFeature(TechDraw::DrawViewAnnotation* obj) { // called from QGVPage. (once) - setViewFeature(static_cast(obj)); + setViewFeature(static_cast(obj)); } void QGIViewAnnotation::updateView(bool update) { - auto viewAnno( dynamic_cast(getViewObject()) ); - if (!viewAnno) + auto viewAnno(dynamic_cast(getViewObject())); + if (!viewAnno) { return; + } - if (update || - viewAnno->isTouched() || - viewAnno->Text.isTouched() || - viewAnno->Font.isTouched() || - viewAnno->TextColor.isTouched() || - viewAnno->TextSize.isTouched() ) { + if (update || viewAnno->isTouched() || viewAnno->Text.isTouched() || viewAnno->Font.isTouched() + || viewAnno->TextColor.isTouched() || viewAnno->TextSize.isTouched()) { draw(); } @@ -96,6 +91,7 @@ void QGIViewAnnotation::updateView(bool update) void QGIViewAnnotation::draw() { + // Base::Console().Message("QGIVA::draw()\n"); if (!isVisible()) { return; } @@ -103,14 +99,14 @@ void QGIViewAnnotation::draw() drawAnnotation(); QGIView::draw(); rotateView(); - } //TODO: text is positioned slightly high (and left??) on page save to SVG file void QGIViewAnnotation::drawAnnotation() { - auto viewAnno( dynamic_cast(getViewObject()) ); + // Base::Console().Message("QGIVA::drawAnnotation()\n"); + auto viewAnno(dynamic_cast(getViewObject())); if (!viewAnno) { return; } @@ -141,13 +137,14 @@ void QGIViewAnnotation::drawAnnotation() c = TechDraw::Preferences::getAccessibleColor(c); ss << "color:" << c.asHexString() << "; "; ss << "}\n\n\n\n

"; - for(std::vector::const_iterator it = annoText.begin(); it != annoText.end(); it++) { + for (std::vector::const_iterator it = annoText.begin(); it != annoText.end(); + it++) { if (it != annoText.begin()) { ss << "
"; } //"less than" symbol chops off line. need to use html sub. - std::string lt = std::regex_replace((*it), std::regex("<"), "<"); + std::string lt = std::regex_replace((*it), std::regex("<"), "<"); ss << lt; } ss << "

\n\n "; @@ -171,12 +168,13 @@ void QGIViewAnnotation::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) { Q_UNUSED(event); - TechDraw::DrawViewAnnotation *annotation = dynamic_cast(getViewObject()); + TechDraw::DrawViewAnnotation* annotation = + dynamic_cast(getViewObject()); if (!annotation) { return; } - const std::vector &values = annotation->Text.getValues(); + const std::vector& values = annotation->Text.getValues(); DlgStringListEditor dlg(values, Gui::getMainWindow()); dlg.setWindowTitle(QString::fromUtf8("Annotation Text Editor")); if (dlg.exec() == QDialog::Accepted) { diff --git a/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp b/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp index 5b567e06a9..5e3b287bcb 100644 --- a/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp @@ -176,10 +176,7 @@ void QGIBalloonLabel::hoverLeaveEvent(QGraphicsSceneHoverEvent* event) QGraphicsItem::hoverLeaveEvent(event); } -QRectF QGIBalloonLabel::boundingRect() const -{ - return childrenBoundingRect(); -} +QRectF QGIBalloonLabel::boundingRect() const { return childrenBoundingRect(); } void QGIBalloonLabel::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) @@ -206,10 +203,7 @@ void QGIBalloonLabel::setLabelCenter() posY = y() + m_labelText->boundingRect().height() / 2.; } -void QGIBalloonLabel::setFont(QFont font) -{ - m_labelText->setFont(font); -} +void QGIBalloonLabel::setFont(QFont font) { m_labelText->setFont(font); } void QGIBalloonLabel::setDimString(QString text) { @@ -224,20 +218,11 @@ void QGIBalloonLabel::setDimString(QString text, qreal maxWidth) m_labelText->setTextWidth(maxWidth); } -void QGIBalloonLabel::setPrettySel() -{ - m_labelText->setPrettySel(); -} +void QGIBalloonLabel::setPrettySel() { m_labelText->setPrettySel(); } -void QGIBalloonLabel::setPrettyPre() -{ - m_labelText->setPrettyPre(); -} +void QGIBalloonLabel::setPrettyPre() { m_labelText->setPrettyPre(); } -void QGIBalloonLabel::setPrettyNormal() -{ - m_labelText->setPrettyNormal(); -} +void QGIBalloonLabel::setPrettyNormal() { m_labelText->setPrettyNormal(); } void QGIBalloonLabel::setColor(QColor color) { @@ -247,11 +232,7 @@ void QGIBalloonLabel::setColor(QColor color) //************************************************************** QGIViewBalloon::QGIViewBalloon() - : dvBalloon(nullptr), - hasHover(false), - m_lineWidth(0.0), - m_obtuse(false), - parent(nullptr), + : dvBalloon(nullptr), hasHover(false), m_lineWidth(0.0), m_obtuse(false), parent(nullptr), m_dragInProgress(false) { m_ctrl = false; @@ -417,7 +398,7 @@ void QGIViewBalloon::updateBalloon(bool obtuse) if (!vp) { return; } - const TechDraw::DrawViewPart* refObj = balloon->getViewPart(); + const TechDraw::DrawView* refObj = balloon->getParentView(); if (!refObj) { return; } @@ -496,23 +477,19 @@ void QGIViewBalloon::balloonLabelDragFinished() //set feature position (x, y) from graphic position double x = Rez::appX(balloonLabel->X() / scale), y = Rez::appX(balloonLabel->Y() / scale); Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Drag Balloon")); - Gui::Command::doCommand( - Gui::Command::Doc, "App.ActiveDocument.%s.X = %f", dvb->getNameInDocument(), x); - Gui::Command::doCommand( - Gui::Command::Doc, "App.ActiveDocument.%s.Y = %f", dvb->getNameInDocument(), -y); + Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.X = %f", + dvb->getNameInDocument(), x); + Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Y = %f", + dvb->getNameInDocument(), -y); // for the case that origin was also dragged, calc new origin and update feature if (m_originDragged) { Base::Vector3d pos(x, -y, 0.0); Base::Vector3d newOrg = pos - m_saveOffset; - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.OriginX = %f", - dvb->getNameInDocument(), - newOrg.x); - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.OriginY = %f", - dvb->getNameInDocument(), - newOrg.y); + Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.OriginX = %f", + dvb->getNameInDocument(), newOrg.x); + Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.OriginY = %f", + dvb->getNameInDocument(), newOrg.y); } Gui::Command::commitCommand(); @@ -584,13 +561,14 @@ void QGIViewBalloon::placeBalloon(QPointF pos) void QGIViewBalloon::draw() { + // Base::Console().Message("QGIVB::draw()\n"); // just redirect drawBalloon(false); } void QGIViewBalloon::drawBalloon(bool dragged) { - // Base::Console().Message("QGIVB::draw()\n"); + // Base::Console().Message("QGIVB::drawBalloon(%d)\n", dragged); if (!isVisible()) { return; } @@ -606,15 +584,15 @@ void QGIViewBalloon::drawBalloon(bool dragged) balloonLabel->show(); show(); - const TechDraw::DrawViewPart* refObj = balloon->getViewPart(); + const TechDraw::DrawView* refObj = balloon->getParentView(); if (!refObj) { return; } - if (!refObj->hasGeometry()) {// nothing to draw yet (restoring) - balloonLabel->hide(); - hide(); - return; - } + // if (!refObj->hasGeometry()) {// nothing to draw yet (restoring) + // balloonLabel->hide(); + // hide(); + // return; + // } auto vp = static_cast(getViewProvider(getViewObject())); if (!vp) { @@ -672,10 +650,8 @@ void QGIViewBalloon::drawBalloon(bool dragged) double balloonRadius = sqrt(pow((textHeight / 2.0), 2) + pow((textWidth / 2.0), 2)); balloonRadius = balloonRadius * scale; balloonPath.moveTo(lblCenter.x, lblCenter.y); - balloonPath.addEllipse(lblCenter.x - balloonRadius, - lblCenter.y - balloonRadius, - balloonRadius * 2, - balloonRadius * 2); + balloonPath.addEllipse(lblCenter.x - balloonRadius, lblCenter.y - balloonRadius, + balloonRadius * 2, balloonRadius * 2); offsetLR = balloonRadius; } else if (strcmp(balloonType, "None") == 0) { @@ -695,10 +671,8 @@ void QGIViewBalloon::drawBalloon(bool dragged) } } textWidth = (textWidth * scale) + Rez::guiX(2.0); - balloonPath.addRect(lblCenter.x - (textWidth / 2.0), - lblCenter.y - (textHeight / 2.0), - textWidth, - textHeight); + balloonPath.addRect(lblCenter.x - (textWidth / 2.0), lblCenter.y - (textHeight / 2.0), + textWidth, textHeight); offsetLR = (textWidth / 2.0); } else if (strcmp(balloonType, "Triangle") == 0) { @@ -725,19 +699,11 @@ void QGIViewBalloon::drawBalloon(bool dragged) QPointF textBoxCorner(lblCenter.x - (textWidth / 2.0), lblCenter.y - (textHeight / 2.0)); balloonPath.moveTo(textBoxCorner); balloonPath.lineTo(textBoxCorner.x() + textWidth, textBoxCorner.y()); - balloonPath.arcTo(textBoxCorner.x() + textWidth - (textHeight / 2.0), - textBoxCorner.y(), - textHeight, - textHeight, - 90, - -180); + balloonPath.arcTo(textBoxCorner.x() + textWidth - (textHeight / 2.0), textBoxCorner.y(), + textHeight, textHeight, 90, -180); balloonPath.lineTo(textBoxCorner.x(), textBoxCorner.y() + textHeight); - balloonPath.arcTo(textBoxCorner.x() - (textHeight / 2), - textBoxCorner.y(), - textHeight, - textHeight, - -90, - -180); + balloonPath.arcTo(textBoxCorner.x() - (textHeight / 2), textBoxCorner.y(), textHeight, + textHeight, -90, -180); offsetLR = (textWidth / 2.0) + (textHeight / 2.0); } else if (strcmp(balloonType, "Square") == 0) { @@ -970,10 +936,7 @@ QColor QGIViewBalloon::prefNormalColor() return getNormalColor(); } -int QGIViewBalloon::prefDefaultArrow() const -{ - return Preferences::balloonArrow(); -} +int QGIViewBalloon::prefDefaultArrow() const { return Preferences::balloonArrow(); } //should this be an object property or global preference? diff --git a/src/Mod/TechDraw/Gui/QGSPage.cpp b/src/Mod/TechDraw/Gui/QGSPage.cpp index 5464a566a2..a902f1b617 100644 --- a/src/Mod/TechDraw/Gui/QGSPage.cpp +++ b/src/Mod/TechDraw/Gui/QGSPage.cpp @@ -22,14 +22,14 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include #endif #include @@ -61,7 +61,6 @@ #include #include -#include "QGSPage.h" #include "MDIViewPage.h" #include "QGIDrawingTemplate.h" #include "QGILeaderLine.h" @@ -80,6 +79,7 @@ #include "QGIViewSpreadsheet.h" #include "QGIViewSymbol.h" #include "QGIWeldSymbol.h" +#include "QGSPage.h" #include "Rez.h" #include "ViewProviderPage.h" #include "ZVALUE.h" @@ -96,31 +96,31 @@ using namespace Gui; using namespace TechDraw; using namespace TechDrawGui; -QGSPage::QGSPage(ViewProviderPage *vpPage, QWidget *parent) - : QGraphicsScene(parent), - pageTemplate(nullptr), - m_vpPage(nullptr) +QGSPage::QGSPage(ViewProviderPage* vpPage, QWidget* parent) + : QGraphicsScene(parent), pageTemplate(nullptr), m_vpPage(nullptr) { assert(vpPage); m_vpPage = vpPage; - setItemIndexMethod(QGraphicsScene::BspTreeIndex); //the default -// setItemIndexMethod(QGraphicsScene::NoIndex); //sometimes faster + setItemIndexMethod(QGraphicsScene::BspTreeIndex);//the default + // setItemIndexMethod(QGraphicsScene::NoIndex); //sometimes faster } void QGSPage::addChildrenToPage() { -// Base::Console().Message("QGSP::addChildrenToPage()\n"); - // A fresh page is added and we iterate through its collected children and add these to Canvas View -MLP - // if docobj is a featureviewcollection (ex orthogroup), add its child views. if there are ever children that have children, - // we'll have to make this recursive. -WF - const std::vector &grp = m_vpPage->getDrawPage()->Views.getValues(); + // Base::Console().Message("QGSP::addChildrenToPage()\n"); + // A fresh page is added and we iterate through its collected children and add these to Canvas View -MLP + // if docobj is a featureviewcollection (ex orthogroup), add its child views. if there are ever children that have children, + // we'll have to make this recursive. -WF + const std::vector& grp = m_vpPage->getDrawPage()->Views.getValues(); std::vector childViews; - for (std::vector::const_iterator it = grp.begin();it != grp.end(); ++it) { + for (std::vector::const_iterator it = grp.begin(); it != grp.end(); + ++it) { attachView(*it); - TechDraw::DrawViewCollection* collect = dynamic_cast(*it); + TechDraw::DrawViewCollection* collect = dynamic_cast(*it); if (collect) { childViews = collect->Views.getValues(); - for (std::vector::iterator itChild = childViews.begin();itChild != childViews.end(); ++itChild) { + for (std::vector::iterator itChild = childViews.begin(); + itChild != childViews.end(); ++itChild) { attachView(*itChild); } } @@ -132,43 +132,45 @@ void QGSPage::addChildrenToPage() setLeaderGroups(); setRichAnnoGroups(); - App::DocumentObject *obj = m_vpPage->getDrawPage()->Template.getValue(); - auto pageTemplate( dynamic_cast(obj) ); - if( pageTemplate ) { + App::DocumentObject* obj = m_vpPage->getDrawPage()->Template.getValue(); + auto pageTemplate(dynamic_cast(obj)); + if (pageTemplate) { attachTemplate(pageTemplate); matchSceneRectToTemplate(); } -// viewAll(); + // viewAll(); } //********** template related routines ********* -void QGSPage::attachTemplate(TechDraw::DrawTemplate *obj) +void QGSPage::attachTemplate(TechDraw::DrawTemplate* obj) { -// Base::Console().Message("QGSP::attachTemplate()\n"); + // Base::Console().Message("QGSP::attachTemplate()\n"); setPageTemplate(obj); } void QGSPage::updateTemplate(bool forceUpdate) { -// Base::Console().Message("QGSP::updateTemplate()\n"); - App::DocumentObject *templObj = m_vpPage->getDrawPage()->Template.getValue(); + // Base::Console().Message("QGSP::updateTemplate()\n"); + App::DocumentObject* templObj = m_vpPage->getDrawPage()->Template.getValue(); // TODO: what if template has been deleted? templObj will be NULL. segfault? if (!templObj) { return; } - if(m_vpPage->getDrawPage()->Template.isTouched() || templObj->isTouched()) { + if (m_vpPage->getDrawPage()->Template.isTouched() || templObj->isTouched()) { // Template is touched so update - if(forceUpdate || - (templObj && templObj->isTouched() && templObj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) ) { + if (forceUpdate + || (templObj && templObj->isTouched() + && templObj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId()))) { - QGITemplate *qItemTemplate = getTemplate(); + QGITemplate* qItemTemplate = getTemplate(); - if(qItemTemplate) { - TechDraw::DrawTemplate *pageTemplate = dynamic_cast(templObj); + if (qItemTemplate) { + TechDraw::DrawTemplate* pageTemplate = + dynamic_cast(templObj); qItemTemplate->setTemplate(pageTemplate); qItemTemplate->updateView(); } @@ -178,11 +180,11 @@ void QGSPage::updateTemplate(bool forceUpdate) QPointF QGSPage::getTemplateCenter() { - App::DocumentObject *obj = m_vpPage->getDrawPage()->Template.getValue(); - auto pageTemplate( dynamic_cast(obj) ); + App::DocumentObject* obj = m_vpPage->getDrawPage()->Template.getValue(); + auto pageTemplate(dynamic_cast(obj)); if (pageTemplate) { - double cx = Rez::guiX(pageTemplate->Width.getValue())/2.0; - double cy = -Rez::guiX(pageTemplate->Height.getValue())/2.0; + double cx = Rez::guiX(pageTemplate->Width.getValue()) / 2.0; + double cy = -Rez::guiX(pageTemplate->Height.getValue()) / 2.0; return QPointF(cx, cy); } return QPointF(0.0, 0.0); @@ -190,39 +192,37 @@ QPointF QGSPage::getTemplateCenter() void QGSPage::matchSceneRectToTemplate(void) { -// Base::Console().Message("QGSP::matchSceneRectToTemplate()\n"); - App::DocumentObject *obj = m_vpPage->getDrawPage()->Template.getValue(); - auto pageTemplate( dynamic_cast(obj) ); - if( pageTemplate ) { + // Base::Console().Message("QGSP::matchSceneRectToTemplate()\n"); + App::DocumentObject* obj = m_vpPage->getDrawPage()->Template.getValue(); + auto pageTemplate(dynamic_cast(obj)); + if (pageTemplate) { //make sceneRect 1 pagesize bigger in every direction - double width = Rez::guiX(pageTemplate->Width.getValue()); - double height = Rez::guiX(pageTemplate->Height.getValue()); - setSceneRect(QRectF(-width, -2.0 * height, 3.0*width, 3.0*height)); + double width = Rez::guiX(pageTemplate->Width.getValue()); + double height = Rez::guiX(pageTemplate->Height.getValue()); + setSceneRect(QRectF(-width, -2.0 * height, 3.0 * width, 3.0 * height)); } } -void QGSPage::setPageTemplate(TechDraw::DrawTemplate *templateFeat) +void QGSPage::setPageTemplate(TechDraw::DrawTemplate* templateFeat) { -// Base::Console().Message("QGSP::setPageTemplate()\n"); + // Base::Console().Message("QGSP::setPageTemplate()\n"); removeTemplate(); - if(templateFeat->isDerivedFrom(TechDraw::DrawParametricTemplate::getClassTypeId())) { + if (templateFeat->isDerivedFrom(TechDraw::DrawParametricTemplate::getClassTypeId())) { pageTemplate = new QGIDrawingTemplate(this); - } else if(templateFeat->isDerivedFrom(TechDraw::DrawSVGTemplate::getClassTypeId())) { + } + else if (templateFeat->isDerivedFrom(TechDraw::DrawSVGTemplate::getClassTypeId())) { pageTemplate = new QGISVGTemplate(this); } pageTemplate->setTemplate(templateFeat); pageTemplate->updateView(); } -QGITemplate* QGSPage::getTemplate() const -{ - return pageTemplate; -} +QGITemplate* QGSPage::getTemplate() const { return pageTemplate; } void QGSPage::removeTemplate() { - if(pageTemplate) { + if (pageTemplate) { removeItem(pageTemplate); pageTemplate->deleteLater(); pageTemplate = nullptr; @@ -232,11 +232,11 @@ void QGSPage::removeTemplate() //******* QGIView related routines //! retrieve the QGIView objects currently in the scene -std::vector QGSPage::getViews() const +std::vector QGSPage::getViews() const { std::vector result; QList items = this->items(); - for (auto& v:items) { + for (auto& v : items) { QGIView* qv = dynamic_cast(v); if (qv) { result.push_back(qv); @@ -245,7 +245,7 @@ std::vector QGSPage::getViews() const return result; } -int QGSPage::addQView(QGIView *view) +int QGSPage::addQView(QGIView* view) { //don't add twice! QGIView* existing = getQGIVByName(view->getViewName()); @@ -253,13 +253,13 @@ int QGSPage::addQView(QGIView *view) addItem(view); // Find if it belongs to a parent - QGIView *parent = nullptr; + QGIView* parent = nullptr; parent = findParent(view); QPointF viewPos(Rez::guiX(view->getViewObject()->X.getValue()), Rez::guiX(view->getViewObject()->Y.getValue() * -1)); - if(parent) { + if (parent) { // move child view to center of parent QPointF posRef(0., 0.); QPointF mapPos = view->mapToItem(parent, posRef); @@ -274,7 +274,7 @@ int QGSPage::addQView(QGIView *view) return 0; } -int QGSPage::removeQView(QGIView *view) +int QGSPage::removeQView(QGIView* view) { if (view) { removeQViewFromScene(view); @@ -289,8 +289,8 @@ int QGSPage::removeQViewByName(const char* name) QString qsName = QString::fromUtf8(name); bool found = false; QGIView* ourItem = nullptr; - for (auto& i:items) { - if (qsName == i->data(1).toString()) { //is there a QGIV with this name in scene? + for (auto& i : items) { + if (qsName == i->data(1).toString()) {//is there a QGIV with this name in scene? found = true; ourItem = i; break; @@ -304,82 +304,83 @@ int QGSPage::removeQViewByName(const char* name) balloon->disconnect(); } removeQViewFromScene(ourItem); - delete ourItem; //commenting this prevents crash but means a small memory waste. - //alternate fix(?) is to change indexing/caching option in scene/view + delete ourItem;//commenting this prevents crash but means a small memory waste. + //alternate fix(?) is to change indexing/caching option in scene/view } return 0; } -void QGSPage::removeQViewFromScene(QGIView *view) +void QGSPage::removeQViewFromScene(QGIView* view) { QGIView* qgParent = dynamic_cast(view->parentItem()); if (qgParent) { qgParent->removeChild(view); - } else { + } + else { removeItem(view); } } -bool QGSPage::addView(const App::DocumentObject *obj) +bool QGSPage::addView(const App::DocumentObject* obj) { return attachView(const_cast(obj)); } -bool QGSPage::attachView(App::DocumentObject *obj) +bool QGSPage::attachView(App::DocumentObject* obj) { -// Base::Console().Message("QGSP::attachView(%s)\n", obj->getNameInDocument()); + // Base::Console().Message("QGSP::attachView(%s)\n", obj->getNameInDocument()); QGIView* existing = findQViewForDocObj(obj); if (existing) - return true; + return true; auto typeId(obj->getTypeId()); - QGIView *qview(nullptr); + QGIView* qview(nullptr); - if (typeId.isDerivedFrom(TechDraw::DrawViewSection::getClassTypeId()) ) { - qview = addViewSection( static_cast(obj) ); - - } else if (typeId.isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId()) ) { - qview = addViewPart( static_cast(obj) ); - - } else if (typeId.isDerivedFrom(TechDraw::DrawProjGroup::getClassTypeId()) ) { - qview = addProjectionGroup( static_cast(obj) ); - - } else if (typeId.isDerivedFrom(TechDraw::DrawViewCollection::getClassTypeId()) ) { - qview = addDrawView( static_cast(obj) ); - - } else if (typeId.isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId()) ) { - qview = addViewDimension( static_cast(obj) ); - - } else if (typeId.isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId()) ) { - qview = addViewBalloon( static_cast(obj) ); - - } else if (typeId.isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId()) ) { - qview = addDrawViewAnnotation( static_cast(obj) ); - - } else if (typeId.isDerivedFrom(TechDraw::DrawViewSymbol::getClassTypeId()) ) { - qview = addDrawViewSymbol( static_cast(obj) ); - - } else if (typeId.isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId()) ) { - qview = addDrawViewClip( static_cast(obj) ); - - } else if (typeId.isDerivedFrom(TechDraw::DrawViewSpreadsheet::getClassTypeId()) ) { - qview = addDrawViewSpreadsheet( static_cast(obj) ); - - } else if (typeId.isDerivedFrom(TechDraw::DrawViewImage::getClassTypeId()) ) { - qview = addDrawViewImage( static_cast(obj) ); - - } else if (typeId.isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId()) ) { - qview = addViewLeader( static_cast(obj) ); - - } else if (typeId.isDerivedFrom(TechDraw::DrawRichAnno::getClassTypeId()) ) { - qview = addRichAnno( static_cast(obj) ); - - } else if (typeId.isDerivedFrom(TechDraw::DrawWeldSymbol::getClassTypeId()) ) { - qview = addWeldSymbol( static_cast(obj) ); - - } else if (typeId.isDerivedFrom(TechDraw::DrawHatch::getClassTypeId()) ) { + if (typeId.isDerivedFrom(TechDraw::DrawViewSection::getClassTypeId())) { + qview = addViewSection(static_cast(obj)); + } + else if (typeId.isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) { + qview = addViewPart(static_cast(obj)); + } + else if (typeId.isDerivedFrom(TechDraw::DrawProjGroup::getClassTypeId())) { + qview = addProjectionGroup(static_cast(obj)); + } + else if (typeId.isDerivedFrom(TechDraw::DrawViewCollection::getClassTypeId())) { + qview = addDrawView(static_cast(obj)); + } + else if (typeId.isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) { + qview = addViewDimension(static_cast(obj)); + } + else if (typeId.isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId())) { + qview = addViewBalloon(static_cast(obj)); + } + else if (typeId.isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId())) { + qview = addDrawViewAnnotation(static_cast(obj)); + } + else if (typeId.isDerivedFrom(TechDraw::DrawViewSymbol::getClassTypeId())) { + qview = addDrawViewSymbol(static_cast(obj)); + } + else if (typeId.isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId())) { + qview = addDrawViewClip(static_cast(obj)); + } + else if (typeId.isDerivedFrom(TechDraw::DrawViewSpreadsheet::getClassTypeId())) { + qview = addDrawViewSpreadsheet(static_cast(obj)); + } + else if (typeId.isDerivedFrom(TechDraw::DrawViewImage::getClassTypeId())) { + qview = addDrawViewImage(static_cast(obj)); + } + else if (typeId.isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId())) { + qview = addViewLeader(static_cast(obj)); + } + else if (typeId.isDerivedFrom(TechDraw::DrawRichAnno::getClassTypeId())) { + qview = addRichAnno(static_cast(obj)); + } + else if (typeId.isDerivedFrom(TechDraw::DrawWeldSymbol::getClassTypeId())) { + qview = addWeldSymbol(static_cast(obj)); + } + else if (typeId.isDerivedFrom(TechDraw::DrawHatch::getClassTypeId())) { //Hatch is not attached like other Views (since it isn't really a View) return true; } @@ -387,10 +388,10 @@ bool QGSPage::attachView(App::DocumentObject *obj) return (qview != nullptr); } -QGIView * QGSPage::addViewPart(TechDraw::DrawViewPart *partFeat) +QGIView* QGSPage::addViewPart(TechDraw::DrawViewPart* partFeat) { -// Base::Console().Message("QGSP::addViewPart(%s)\n", part->getNameInDocument()); - auto viewPart( new QGIViewPart ); + // Base::Console().Message("QGSP::addViewPart(%s)\n", part->getNameInDocument()); + auto viewPart(new QGIViewPart); viewPart->setViewPartFeature(partFeat); @@ -398,9 +399,9 @@ QGIView * QGSPage::addViewPart(TechDraw::DrawViewPart *partFeat) return viewPart; } -QGIView * QGSPage::addViewSection(DrawViewSection *sectionFeat) +QGIView* QGSPage::addViewSection(DrawViewSection* sectionFeat) { - auto viewSection( new QGIViewSection ); + auto viewSection(new QGIViewSection); viewSection->setViewPartFeature(sectionFeat); @@ -408,36 +409,36 @@ QGIView * QGSPage::addViewSection(DrawViewSection *sectionFeat) return viewSection; } -QGIView * QGSPage::addProjectionGroup(TechDraw::DrawProjGroup *projGroupFeat) +QGIView* QGSPage::addProjectionGroup(TechDraw::DrawProjGroup* projGroupFeat) { - auto qview( new QGIProjGroup ); + auto qview(new QGIProjGroup); qview->setViewFeature(projGroupFeat); addQView(qview); return qview; } -QGIView * QGSPage::addDrawView(TechDraw::DrawView *view) +QGIView* QGSPage::addDrawView(TechDraw::DrawView* view) { - auto qview( new QGIView ); + auto qview(new QGIView); qview->setViewFeature(view); addQView(qview); return qview; } -QGIView * QGSPage::addDrawViewCollection(TechDraw::DrawViewCollection *collectionFeat) +QGIView* QGSPage::addDrawViewCollection(TechDraw::DrawViewCollection* collectionFeat) { - auto qview( new QGIViewCollection ); + auto qview(new QGIViewCollection); qview->setViewFeature(collectionFeat); addQView(qview); return qview; } -QGIView * QGSPage::addDrawViewAnnotation(TechDraw::DrawViewAnnotation *annoFeat) +QGIView* QGSPage::addDrawViewAnnotation(TechDraw::DrawViewAnnotation* annoFeat) { - auto qview( new QGIViewAnnotation ); + auto qview(new QGIViewAnnotation); qview->setViewAnnoFeature(annoFeat); @@ -445,9 +446,9 @@ QGIView * QGSPage::addDrawViewAnnotation(TechDraw::DrawViewAnnotation *annoFeat) return qview; } -QGIView * QGSPage::addDrawViewSymbol(TechDraw::DrawViewSymbol *symbolFeat) +QGIView* QGSPage::addDrawViewSymbol(TechDraw::DrawViewSymbol* symbolFeat) { - auto qview( new QGIViewSymbol ); + auto qview(new QGIViewSymbol); qview->setViewFeature(symbolFeat); @@ -455,9 +456,9 @@ QGIView * QGSPage::addDrawViewSymbol(TechDraw::DrawViewSymbol *symbolFeat) return qview; } -QGIView * QGSPage::addDrawViewClip(TechDraw::DrawViewClip *view) +QGIView* QGSPage::addDrawViewClip(TechDraw::DrawViewClip* view) { - auto qview( new QGIViewClip ); + auto qview(new QGIViewClip); qview->setPosition(Rez::guiX(view->X.getValue()), Rez::guiX(view->Y.getValue())); qview->setViewFeature(view); @@ -466,9 +467,9 @@ QGIView * QGSPage::addDrawViewClip(TechDraw::DrawViewClip *view) return qview; } -QGIView * QGSPage::addDrawViewSpreadsheet(TechDraw::DrawViewSpreadsheet *sheetFeat) +QGIView* QGSPage::addDrawViewSpreadsheet(TechDraw::DrawViewSpreadsheet* sheetFeat) { - auto qview( new QGIViewSpreadsheet ); + auto qview(new QGIViewSpreadsheet); qview->setViewFeature(sheetFeat); @@ -476,9 +477,9 @@ QGIView * QGSPage::addDrawViewSpreadsheet(TechDraw::DrawViewSpreadsheet *sheetFe return qview; } -QGIView * QGSPage::addDrawViewImage(TechDraw::DrawViewImage *imageFeat) +QGIView* QGSPage::addDrawViewImage(TechDraw::DrawViewImage* imageFeat) { - auto qview( new QGIViewImage ); + auto qview(new QGIViewImage); qview->setViewFeature(imageFeat); @@ -486,16 +487,16 @@ QGIView * QGSPage::addDrawViewImage(TechDraw::DrawViewImage *imageFeat) return qview; } -QGIView * QGSPage::addViewBalloon(TechDraw::DrawViewBalloon *balloonFeat) +QGIView* QGSPage::addViewBalloon(TechDraw::DrawViewBalloon* balloonFeat) { -// Base::Console().Message("QGSP::addViewBalloon(%s)\n", balloon->getNameInDocument()); - auto vBalloon( new QGIViewBalloon ); + // Base::Console().Message("QGSP::addViewBalloon(%s)\n", balloonFeat->getNameInDocument()); + auto vBalloon(new QGIViewBalloon); addItem(vBalloon); vBalloon->setViewPartFeature(balloonFeat); - QGIView *parent = nullptr; + QGIView* parent = nullptr; parent = findParent(vBalloon); if (parent) { @@ -507,9 +508,9 @@ QGIView * QGSPage::addViewBalloon(TechDraw::DrawViewBalloon *balloonFeat) void QGSPage::addBalloonToParent(QGIViewBalloon* balloon, QGIView* parent) { -// Base::Console().Message("QGSP::addBalloonToParent()\n"); + // Base::Console().Message("QGSP::addBalloonToParent()\n"); assert(balloon); - assert(parent); //blow up if we don't have Dimension or Parent + assert(parent);//blow up if we don't have Dimension or Parent QPointF posRef(0., 0.); QPointF mapPos = balloon->mapToItem(parent, posRef); balloon->moveBy(-mapPos.x(), -mapPos.y()); @@ -518,19 +519,23 @@ void QGSPage::addBalloonToParent(QGIViewBalloon* balloon, QGIView* parent) } //origin is in scene coordinates from QGViewPage -void QGSPage::createBalloon(QPointF origin, DrawViewPart *parent) +void QGSPage::createBalloon(QPointF origin, DrawView* parent) { -// Base::Console().Message("QGSP::createBalloon(%s)\n", DrawUtil::formatVector(origin).c_str()); + // Base::Console().Message("QGSP::createBalloon(%s)\n", DrawUtil::formatVector(origin).c_str()); std::string featName = getDrawPage()->getDocument()->getUniqueObjectName("Balloon"); std::string pageName = getDrawPage()->getNameInDocument(); Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Balloon")); - Command::doCommand(Command::Doc, "App.activeDocument().addObject('TechDraw::DrawViewBalloon', '%s')", featName.c_str()); - TechDraw::DrawViewBalloon *balloon = dynamic_cast(getDrawPage()->getDocument()->getObject(featName.c_str())); + Command::doCommand(Command::Doc, + "App.activeDocument().addObject('TechDraw::DrawViewBalloon', '%s')", + featName.c_str()); + TechDraw::DrawViewBalloon* balloon = dynamic_cast( + getDrawPage()->getDocument()->getObject(featName.c_str())); if (!balloon) { throw Base::TypeError("QGSP::createBalloon - balloon not found\n"); } - Command::doCommand(Command::Doc, "App.activeDocument().%s.SourceView = (App.activeDocument().%s)", + Command::doCommand(Command::Doc, + "App.activeDocument().%s.SourceView = (App.activeDocument().%s)", featName.c_str(), parent->getNameInDocument()); QGIView* qgParent = getQGIVByName(parent->getNameInDocument()); @@ -549,24 +554,25 @@ void QGSPage::createBalloon(QPointF origin, DrawViewPart *parent) int idx = getDrawPage()->getNextBalloonIndex(); balloon->Text.setValue(std::to_string(idx).c_str()); - Command::doCommand(Command::Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", pageName.c_str(), featName.c_str()); + Command::doCommand(Command::Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", + pageName.c_str(), featName.c_str()); Gui::Command::commitCommand(); } -QGIView * QGSPage::addViewDimension(TechDraw::DrawViewDimension *dimFeat) +QGIView* QGSPage::addViewDimension(TechDraw::DrawViewDimension* dimFeat) { - auto dimGroup( new QGIViewDimension ); + auto dimGroup(new QGIViewDimension); addItem(dimGroup); dimGroup->setViewPartFeature(dimFeat); // Find if it belongs to a parent - QGIView *parent = nullptr; + QGIView* parent = nullptr; parent = findParent(dimGroup); - if(parent) { + if (parent) { addDimToParent(dimGroup, parent); } @@ -575,9 +581,9 @@ QGIView * QGSPage::addViewDimension(TechDraw::DrawViewDimension *dimFeat) void QGSPage::addDimToParent(QGIViewDimension* dim, QGIView* parent) { -// Base::Console().Message("QGSP::addDimToParent()\n"); + // Base::Console().Message("QGSP::addDimToParent()\n"); assert(dim); - assert(parent); //blow up if we don't have Dimension or Parent + assert(parent);//blow up if we don't have Dimension or Parent QPointF posRef(0., 0.); QPointF mapPos = dim->mapToItem(parent, posRef); dim->moveBy(-mapPos.x(), -mapPos.y()); @@ -585,18 +591,18 @@ void QGSPage::addDimToParent(QGIViewDimension* dim, QGIView* parent) dim->setZValue(ZVALUE::DIMENSION); } -QGIView * QGSPage::addViewLeader(TechDraw::DrawLeaderLine *leaderFeat) +QGIView* QGSPage::addViewLeader(TechDraw::DrawLeaderLine* leaderFeat) { -// Base::Console().Message("QGSP::addViewLeader(%s)\n", leader->getNameInDocument()); + // Base::Console().Message("QGSP::addViewLeader(%s)\n", leader->getNameInDocument()); QGILeaderLine* leaderGroup = new QGILeaderLine(); addItem(leaderGroup); leaderGroup->setLeaderFeature(leaderFeat); - QGIView *parent = nullptr; + QGIView* parent = nullptr; parent = findParent(leaderGroup); - if(parent) { + if (parent) { addLeaderToParent(leaderGroup, parent); } @@ -607,18 +613,18 @@ QGIView * QGSPage::addViewLeader(TechDraw::DrawLeaderLine *leaderFeat) void QGSPage::addLeaderToParent(QGILeaderLine* lead, QGIView* parent) { -// Base::Console().Message("QGSP::addLeaderToParent()\n"); + // Base::Console().Message("QGSP::addLeaderToParent()\n"); parent->addToGroup(lead); lead->setZValue(ZVALUE::DIMENSION); } -QGIView * QGSPage::addRichAnno(TechDraw::DrawRichAnno* richFeat) +QGIView* QGSPage::addRichAnno(TechDraw::DrawRichAnno* richFeat) { QGIRichAnno* annoGroup = new QGIRichAnno(); addItem(annoGroup); annoGroup->setViewFeature(richFeat); - QGIView *parent = findParent(annoGroup); + QGIView* parent = findParent(annoGroup); if (parent) addAnnoToParent(annoGroup, parent); @@ -629,31 +635,32 @@ QGIView * QGSPage::addRichAnno(TechDraw::DrawRichAnno* richFeat) void QGSPage::addAnnoToParent(QGIRichAnno* anno, QGIView* parent) { -// Base::Console().Message("QGSP::addAnnoToParent()\n"); + // Base::Console().Message("QGSP::addAnnoToParent()\n"); parent->addToGroup(anno); anno->setZValue(ZVALUE::DIMENSION); } -QGIView * QGSPage::addWeldSymbol(TechDraw::DrawWeldSymbol* weldFeat) +QGIView* QGSPage::addWeldSymbol(TechDraw::DrawWeldSymbol* weldFeat) { -// Base::Console().Message("QGSP::addWeldSymbol()\n"); + // Base::Console().Message("QGSP::addWeldSymbol()\n"); QGIWeldSymbol* weldGroup = nullptr; - TechDraw::DrawView* parentDV = nullptr; + TechDraw::DrawView* parentDV = nullptr; App::DocumentObject* parentObj = weldFeat->Leader.getValue(); if (parentObj) { - parentDV = dynamic_cast(parentObj); - } else { -// Base::Console().Message("QGSP::addWeldSymbol - no parent doc obj\n"); + parentDV = dynamic_cast(parentObj); + } + else { + // Base::Console().Message("QGSP::addWeldSymbol - no parent doc obj\n"); } if (parentDV) { QGIView* parentQV = findQViewForDocObj(parentObj); QGILeaderLine* leadParent = dynamic_cast(parentQV); if (leadParent) { weldGroup = new QGIWeldSymbol(leadParent); - weldGroup->setFeature(weldFeat); //for QGIWS - weldGroup->setViewFeature(weldFeat); //for QGIV + weldGroup->setFeature(weldFeat); //for QGIWS + weldGroup->setViewFeature(weldFeat);//for QGIV weldGroup->updateView(true); } } @@ -662,7 +669,7 @@ QGIView * QGSPage::addWeldSymbol(TechDraw::DrawWeldSymbol* weldFeat) void QGSPage::setDimensionGroups(void) { - const std::vector &allItems = getViews(); + const std::vector& allItems = getViews(); int dimItemType = QGraphicsItem::UserType + 106; for (auto& item : allItems) { @@ -678,7 +685,7 @@ void QGSPage::setDimensionGroups(void) void QGSPage::setBalloonGroups(void) { - const std::vector &allItems = getViews(); + const std::vector& allItems = getViews(); int balloonItemType = QGraphicsItem::UserType + 140; for (auto& item : allItems) { @@ -694,8 +701,8 @@ void QGSPage::setBalloonGroups(void) void QGSPage::setLeaderGroups(void) { -// Base::Console().Message("QGSP::setLeaderGroups()\n"); - const std::vector &allItems = getViews(); + // Base::Console().Message("QGSP::setLeaderGroups()\n"); + const std::vector& allItems = getViews(); int leadItemType = QGraphicsItem::UserType + 232; //make sure that qgileader belongs to correct parent. @@ -713,8 +720,8 @@ void QGSPage::setLeaderGroups(void) void QGSPage::setRichAnnoGroups(void) { -// Base::Console().Message("QGSP::setRichAnnoGroups()\n"); - const std::vector &allItems = getViews(); + // Base::Console().Message("QGSP::setRichAnnoGroups()\n"); + const std::vector& allItems = getViews(); int annoItemType = QGraphicsItem::UserType + 233; //make sure that qgirichanno belongs to correct parent. @@ -730,13 +737,13 @@ void QGSPage::setRichAnnoGroups(void) } //! find the graphic for a DocumentObject -QGIView * QGSPage::findQViewForDocObj(App::DocumentObject *obj) const +QGIView* QGSPage::findQViewForDocObj(App::DocumentObject* obj) const { -// Base::Console().Message("QGSP::findQViewForDocObj(%s)\n", obj->getNameInDocument()); - if(obj) { - const std::vector qviews = getViews(); - for(std::vector::const_iterator it = qviews.begin(); it != qviews.end(); ++it) { - if(strcmp(obj->getNameInDocument(), (*it)->getViewName()) == 0) + // Base::Console().Message("QGSP::findQViewForDocObj(%s)\n", obj->getNameInDocument()); + if (obj) { + const std::vector qviews = getViews(); + for (std::vector::const_iterator it = qviews.begin(); it != qviews.end(); ++it) { + if (strcmp(obj->getNameInDocument(), (*it)->getViewName()) == 0) return *it; } } @@ -752,7 +759,7 @@ QGIView* QGSPage::getQGIVByName(std::string name) QGIView* qv = dynamic_cast((*it)); if (qv) { const char* qvName = qv->getViewName(); - if(name.compare(qvName) == 0) { + if (name.compare(qvName) == 0) { return (qv); } } @@ -761,22 +768,23 @@ QGIView* QGSPage::getQGIVByName(std::string name) } //find the parent of a QGIV based on the corresponding feature's parentage -QGIView *QGSPage::findParent(QGIView *view) const +QGIView* QGSPage::findParent(QGIView* view) const { -// Base::Console().Message("QGSP::findParent(%s)\n", view->getViewName()); - const std::vector qviews = getViews(); - TechDraw::DrawView *myFeat = view->getViewObject(); + // Base::Console().Message("QGSP::findParent(%s)\n", view->getViewName()); + const std::vector qviews = getViews(); + TechDraw::DrawView* myFeat = view->getViewObject(); //If type is dimension we check references first - TechDraw::DrawViewDimension *dim = nullptr; - dim = dynamic_cast(myFeat); + TechDraw::DrawViewDimension* dim = nullptr; + dim = dynamic_cast(myFeat); if (dim) { - std::vector objs = dim->References2D.getValues(); + std::vector objs = dim->References2D.getValues(); if (!objs.empty()) { - std::vector objs = dim->References2D.getValues(); + std::vector objs = dim->References2D.getValues(); // Attach the dimension to the first object's group - for (std::vector::const_iterator it = qviews.begin(); it != qviews.end(); ++it) { + for (std::vector::const_iterator it = qviews.begin(); it != qviews.end(); + ++it) { if (strcmp((*it)->getViewName(), objs.at(0)->getNameInDocument()) == 0) { return *it; } @@ -785,15 +793,16 @@ QGIView *QGSPage::findParent(QGIView *view) const } //If type is balloon we check references first - TechDraw::DrawViewBalloon *balloon = nullptr; - balloon = dynamic_cast(myFeat); + TechDraw::DrawViewBalloon* balloon = nullptr; + balloon = dynamic_cast(myFeat); if (balloon) { - App::DocumentObject *obj = balloon->SourceView.getValue(); + App::DocumentObject* obj = balloon->SourceView.getValue(); if (obj) { - // Attach the dimension to the first object's group - for (std::vector::const_iterator it = qviews.begin(); it != qviews.end(); ++it) { + // Attach the Balloon to the first object's group + for (std::vector::const_iterator it = qviews.begin(); it != qviews.end(); + ++it) { if (strcmp((*it)->getViewName(), obj->getNameInDocument()) == 0) { return *it; } @@ -802,45 +811,48 @@ QGIView *QGSPage::findParent(QGIView *view) const } //If type is LeaderLine we check LeaderParent - TechDraw::DrawLeaderLine *lead = nullptr; - lead = dynamic_cast(myFeat); + TechDraw::DrawLeaderLine* lead = nullptr; + lead = dynamic_cast(myFeat); - if (lead) { - App::DocumentObject* obj = lead->LeaderParent.getValue(); - if (obj) { - std::string parentName = obj->getNameInDocument(); - for(std::vector::const_iterator it = qviews.begin(); it != qviews.end(); ++it) { - if(strcmp((*it)->getViewName(), parentName.c_str()) == 0) { - return *it; - } - } - } - } + if (lead) { + App::DocumentObject* obj = lead->LeaderParent.getValue(); + if (obj) { + std::string parentName = obj->getNameInDocument(); + for (std::vector::const_iterator it = qviews.begin(); it != qviews.end(); + ++it) { + if (strcmp((*it)->getViewName(), parentName.c_str()) == 0) { + return *it; + } + } + } + } - //if type is a RichTextAnno we check AnnoParent - TechDraw::DrawRichAnno* anno = dynamic_cast(myFeat); - if (anno) { - App::DocumentObject* obj = anno->AnnoParent.getValue(); - if (obj) { - std::string parentName = obj->getNameInDocument(); - for(std::vector::const_iterator it = qviews.begin(); it != qviews.end(); ++it) { - if(strcmp((*it)->getViewName(), parentName.c_str()) == 0) { - return *it; - } - } - } - } + //if type is a RichTextAnno we check AnnoParent + TechDraw::DrawRichAnno* anno = dynamic_cast(myFeat); + if (anno) { + App::DocumentObject* obj = anno->AnnoParent.getValue(); + if (obj) { + std::string parentName = obj->getNameInDocument(); + for (std::vector::const_iterator it = qviews.begin(); it != qviews.end(); + ++it) { + if (strcmp((*it)->getViewName(), parentName.c_str()) == 0) { + return *it; + } + } + } + } // Check if part of view collection - for (std::vector::const_iterator it = qviews.begin(); it != qviews.end(); ++it) { - QGIViewCollection *grp = nullptr; - grp = dynamic_cast(*it); + for (std::vector::const_iterator it = qviews.begin(); it != qviews.end(); ++it) { + QGIViewCollection* grp = nullptr; + grp = dynamic_cast(*it); if (grp) { - TechDraw::DrawViewCollection *collection = nullptr; - collection = dynamic_cast(grp->getViewObject()); + TechDraw::DrawViewCollection* collection = nullptr; + collection = dynamic_cast(grp->getViewObject()); if (collection) { - std::vector objs = collection->Views.getValues(); - for (std::vector::iterator it = objs.begin(); it != objs.end(); ++it) { + std::vector objs = collection->Views.getValues(); + for (std::vector::iterator it = objs.begin(); + it != objs.end(); ++it) { if (strcmp(myFeat->getNameInDocument(), (*it)->getNameInDocument()) == 0) return grp; @@ -852,14 +864,14 @@ QGIView *QGSPage::findParent(QGIView *view) const return nullptr; } -bool QGSPage::hasQView(App::DocumentObject *obj) +bool QGSPage::hasQView(App::DocumentObject* obj) { - const std::vector &views = getViews(); - std::vector::const_iterator qview = views.begin(); + const std::vector& views = getViews(); + std::vector::const_iterator qview = views.begin(); - while(qview != views.end()) { + while (qview != views.end()) { // Unsure if we can compare pointers so rely on name - if(strcmp((*qview)->getViewName(), obj->getNameInDocument()) == 0) { + if (strcmp((*qview)->getViewName(), obj->getNameInDocument()) == 0) { return true; } qview++; @@ -870,39 +882,43 @@ bool QGSPage::hasQView(App::DocumentObject *obj) void QGSPage::refreshViews() { -// Base::Console().Message("QGSP::refreshViews()\n"); + // Base::Console().Message("QGSP::refreshViews()\n"); QList list = items(); QList qgiv; //find only QGIV's - for (auto q: list) { + for (auto q : list) { QString viewFamily = QString::fromUtf8("QGIV"); if (viewFamily == q->data(0).toString()) { qgiv.push_back(q); } } - for (auto q: qgiv) { - QGIView *itemView = dynamic_cast(q); - if(itemView) { + for (auto q : qgiv) { + QGIView* itemView = dynamic_cast(q); + if (itemView) { itemView->updateView(true); } } } -void QGSPage::findMissingViews(const std::vector &list, std::vector &missing) +void QGSPage::findMissingViews(const std::vector& list, + std::vector& missing) { - for(std::vector::const_iterator it = list.begin(); it != list.end(); ++it) { + for (std::vector::const_iterator it = list.begin(); it != list.end(); + ++it) { - if(!hasQView(*it)) - missing.push_back(*it); + if (!hasQView(*it)) + missing.push_back(*it); - if((*it)->getTypeId().isDerivedFrom(TechDraw::DrawViewCollection::getClassTypeId())) { + if ((*it)->getTypeId().isDerivedFrom(TechDraw::DrawViewCollection::getClassTypeId())) { std::vector missingChildViews; - TechDraw::DrawViewCollection *collection = dynamic_cast(*it); + TechDraw::DrawViewCollection* collection = + dynamic_cast(*it); // Find Child Views recursively findMissingViews(collection->Views.getValues(), missingChildViews); // Append the views to current missing list - for(std::vector::const_iterator it = missingChildViews.begin(); it != missingChildViews.end(); ++it) { + for (std::vector::const_iterator it = missingChildViews.begin(); + it != missingChildViews.end(); ++it) { missing.push_back(*it); } } @@ -925,10 +941,10 @@ void QGSPage::fixOrphans(bool force) if (!thisPage->getNameInDocument()) return; - std::vector pChildren = thisPage->getAllViews(); + std::vector pChildren = thisPage->getAllViews(); // if dv doesn't have a graphic, make one - for (auto& dv: pChildren) { + for (auto& dv : pChildren) { if (dv->isRemoving()) continue; QGIView* qv = findQViewForDocObj(dv); @@ -939,26 +955,26 @@ void QGSPage::fixOrphans(bool force) std::vector qvss = getViews(); // qvss may contain an item and its child item(s) and to avoid to access a deleted item a QPointer is needed std::vector> qvs; - std::for_each(qvss.begin(), qvss.end(), [&qvs](QGIView* v) { - qvs.emplace_back(v); - }); + std::for_each(qvss.begin(), qvss.end(), [&qvs](QGIView* v) { qvs.emplace_back(v); }); App::Document* doc = m_vpPage->getDrawPage()->getDocument(); - for (auto& qv: qvs) { + for (auto& qv : qvs) { if (!qv) - continue; // already deleted? + continue;// already deleted? App::DocumentObject* obj = doc->getObject(qv->getViewName()); if (!obj) { //no DrawView anywhere in Document removeQView(qv); - } else { + } + else { //DrawView exists in Document. Does it belong to this DrawPage? int numParentPages = qv->getViewObject()->countParentPages(); if (numParentPages == 0) { //DrawView does not belong to any DrawPage //remove QGItem from QGScene removeQView(qv); - } else if (numParentPages == 1) { + } + else if (numParentPages == 1) { //Does DrawView belong to this DrawPage? TechDraw::DrawPage* parentPage = qv->getViewObject()->findParentPage(); if (thisPage != parentPage) { @@ -966,13 +982,15 @@ void QGSPage::fixOrphans(bool force) //remove QGItem from QGScene removeQView(qv); } - } else if (numParentPages > 1) { + } + else if (numParentPages > 1) { //DrawView belongs to multiple DrawPages //check if this MDIViewPage corresponds to any parent DrawPage //if not, delete the QGItem - std::vector potentialParentPages = qv->getViewObject()->findAllParentPages(); + std::vector potentialParentPages = + qv->getViewObject()->findAllParentPages(); bool found = false; - for (auto p: potentialParentPages) { + for (auto p : potentialParentPages) { if (thisPage == p) { found = true; break; @@ -986,22 +1004,24 @@ void QGSPage::fixOrphans(bool force) } } - setRichAnnoGroups(); //hack to fix QGIRA parentage; + setRichAnnoGroups();//hack to fix QGIRA parentage; } -bool QGSPage::orphanExists(const char *viewName, const std::vector &list) +bool QGSPage::orphanExists(const char* viewName, const std::vector& list) { - for(std::vector::const_iterator it = list.begin(); it != list.end(); ++it) { + for (std::vector::const_iterator it = list.begin(); it != list.end(); + ++it) { //Check child objects too recursively - if((*it)->isDerivedFrom(TechDraw::DrawViewCollection::getClassTypeId())) { - TechDraw::DrawViewCollection *collection = dynamic_cast(*it); - if(orphanExists(viewName, collection->Views.getValues())) + if ((*it)->isDerivedFrom(TechDraw::DrawViewCollection::getClassTypeId())) { + TechDraw::DrawViewCollection* collection = + dynamic_cast(*it); + if (orphanExists(viewName, collection->Views.getValues())) return true; } // Unsure if we can compare pointers so rely on name - if(strcmp(viewName, (*it)->getNameInDocument()) == 0) { + if (strcmp(viewName, (*it)->getNameInDocument()) == 0) { return true; } } @@ -1011,10 +1031,10 @@ bool QGSPage::orphanExists(const char *viewName, const std::vector &upviews = getViews(); - for(std::vector::const_iterator it = upviews.begin(); it != upviews.end(); ++it) { - (*it)->updateView(true); + // Base::Console().Message("QGSP::redrawAllViews() - views: %d\n", getViews().size()); + const std::vector& upviews = getViews(); + for (std::vector::const_iterator it = upviews.begin(); it != upviews.end(); ++it) { + (*it)->updateView(true); } } @@ -1022,10 +1042,10 @@ void QGSPage::redrawAllViews() void QGSPage::redraw1View(TechDraw::DrawView* dView) { std::string dvName = dView->getNameInDocument(); - const std::vector &upviews = getViews(); - for(std::vector::const_iterator it = upviews.begin(); it != upviews.end(); ++it) { + const std::vector& upviews = getViews(); + for (std::vector::const_iterator it = upviews.begin(); it != upviews.end(); ++it) { std::string qgivName = (*it)->getViewName(); - if(dvName == qgivName) { + if (dvName == qgivName) { (*it)->updateView(true); } } @@ -1035,10 +1055,10 @@ void QGSPage::setExporting(bool enable) { QList sceneItems = items(); std::vector dvps; - for (auto& qgi:sceneItems) { - QGIViewPart* qgiPart = dynamic_cast(qgi); - QGIRichAnno* qgiRTA = dynamic_cast(qgi); - if(qgiPart) { + for (auto& qgi : sceneItems) { + QGIViewPart* qgiPart = dynamic_cast(qgi); + QGIRichAnno* qgiRTA = dynamic_cast(qgi); + if (qgiPart) { qgiPart->setExporting(enable); dvps.push_back(qgiPart); } @@ -1046,7 +1066,7 @@ void QGSPage::setExporting(bool enable) qgiRTA->setExporting(enable); } } - for (auto& v: dvps) { + for (auto& v : dvps) { v->draw(); } } @@ -1055,14 +1075,12 @@ void QGSPage::saveSvg(QString filename) { // TODO: We only have m_vpPage because constructor gets passed a view provider... //NOTE: this makes wrong size pages in low-Rez - TechDraw::DrawPage *page( m_vpPage->getDrawPage() ); + TechDraw::DrawPage* page(m_vpPage->getDrawPage()); - const QString docName( QString::fromUtf8(page->getDocument()->getName()) ); - const QString pageName( QString::fromUtf8(page->getNameInDocument()) ); - QString svgDescription = QString::fromUtf8("Drawing page: ") + - pageName + - QString::fromUtf8(" exported from FreeCAD document: ") + - docName; + const QString docName(QString::fromUtf8(page->getDocument()->getName())); + const QString pageName(QString::fromUtf8(page->getNameInDocument())); + QString svgDescription = QString::fromUtf8("Drawing page: ") + pageName + + QString::fromUtf8(" exported from FreeCAD document: ") + docName; QSvgGenerator svgGen; QTemporaryFile temporaryFile; @@ -1093,7 +1111,7 @@ void QGSPage::saveSvg(QString filename) // Here we temporarily hide the page template, because Qt would otherwise convert the SVG template // texts into series of paths, making the later document edits practically unfeasible. // We will insert the SVG template ourselves in the final XML postprocessing operation. - QGISVGTemplate *svgTemplate = dynamic_cast(pageTemplate); + QGISVGTemplate* svgTemplate = dynamic_cast(pageTemplate); bool templateVisible = false; if (svgTemplate) { templateVisible = svgTemplate->isVisible(); @@ -1101,10 +1119,10 @@ void QGSPage::saveSvg(QString filename) } refreshViews(); -// viewport()->repaint(); + // viewport()->repaint(); - double width = Rez::guiX(page->getPageWidth()); - double height = Rez::guiX(page->getPageHeight()); + double width = Rez::guiX(page->getPageWidth()); + double height = Rez::guiX(page->getPageHeight()); QRectF sourceRect(0.0, -height, width, height); QRectF targetRect(0.0, 0.0, width, height); @@ -1112,7 +1130,7 @@ void QGSPage::saveSvg(QString filename) QPainter p; p.begin(&svgGen); - render(&p, targetRect, sourceRect); //note: scene render, not item render! + render(&p, targetRect, sourceRect);//note: scene render, not item render! p.end(); m_vpPage->setFrameState(saveState); @@ -1123,7 +1141,7 @@ void QGSPage::saveSvg(QString filename) } refreshViews(); -// viewport()->repaint(); + // viewport()->repaint(); temporaryFile.close(); postProcessXml(temporaryFile, filename, pageName); @@ -1135,7 +1153,8 @@ static void removeEmptyGroups(QDomElement e) QDomElement next = e.nextSiblingElement(); if (e.hasChildNodes()) { removeEmptyGroups(e.firstChildElement()); - } else if (e.tagName() == QLatin1String("g")) { + } + else if (e.tagName() == QLatin1String("g")) { e.parentNode().removeChild(e); } e = next; @@ -1157,37 +1176,31 @@ void QGSPage::postProcessXml(QTemporaryFile& temporaryFile, QString fileName, QS } file.close(); - QDomElement exportDocElem = exportDoc.documentElement(); //root + QDomElement exportDocElem = exportDoc.documentElement();//root // Insert Freecad SVG namespace into namespace declarations exportDocElem.setAttribute(QString::fromUtf8("xmlns:freecad"), QString::fromUtf8(FREECAD_SVG_NS_URI)); // Insert all namespaces used by TechDraw's page template SVGs - exportDocElem.setAttribute(QString::fromUtf8("xmlns:svg"), - QString::fromUtf8(SVG_NS_URI)); - exportDocElem.setAttribute(QString::fromUtf8("xmlns:cc"), - QString::fromUtf8(CC_NS_URI)); - exportDocElem.setAttribute(QString::fromUtf8("xmlns:dc"), - QString::fromUtf8(DC_NS_URI)); - exportDocElem.setAttribute(QString::fromUtf8("xmlns:rdf"), - QString::fromUtf8(RDF_NS_URI)); + exportDocElem.setAttribute(QString::fromUtf8("xmlns:svg"), QString::fromUtf8(SVG_NS_URI)); + exportDocElem.setAttribute(QString::fromUtf8("xmlns:cc"), QString::fromUtf8(CC_NS_URI)); + exportDocElem.setAttribute(QString::fromUtf8("xmlns:dc"), QString::fromUtf8(DC_NS_URI)); + exportDocElem.setAttribute(QString::fromUtf8("xmlns:rdf"), QString::fromUtf8(RDF_NS_URI)); exportDocElem.setAttribute(QString::fromUtf8("xmlns:inkscape"), - QString::fromUtf8(INKSCAPE_NS_URI)); + QString::fromUtf8(INKSCAPE_NS_URI)); exportDocElem.setAttribute(QString::fromUtf8("xmlns:sodipodi"), - QString::fromUtf8(SODIPODI_NS_URI)); + QString::fromUtf8(SODIPODI_NS_URI)); // Create the root group which will host the drawing group and the template group QDomElement rootGroup = exportDoc.createElement(QString::fromUtf8("g")); rootGroup.setAttribute(QString::fromUtf8("id"), pageName); - rootGroup.setAttribute(QString::fromUtf8("inkscape:groupmode"), - QString::fromUtf8("layer")); - rootGroup.setAttribute(QString::fromUtf8("inkscape:label"), - QString::fromUtf8("TechDraw")); + rootGroup.setAttribute(QString::fromUtf8("inkscape:groupmode"), QString::fromUtf8("layer")); + rootGroup.setAttribute(QString::fromUtf8("inkscape:label"), QString::fromUtf8("TechDraw")); // Now insert our template - QGISVGTemplate *svgTemplate = dynamic_cast(pageTemplate); + QGISVGTemplate* svgTemplate = dynamic_cast(pageTemplate); if (svgTemplate) { - DrawSVGTemplate *drawTemplate = svgTemplate->getSVGTemplate(); + DrawSVGTemplate* drawTemplate = svgTemplate->getSVGTemplate(); if (drawTemplate) { QFile templateResultFile(QString::fromUtf8(drawTemplate->PageResult.getValue())); if (templateResultFile.open(QIODevice::ReadOnly)) { @@ -1205,11 +1218,14 @@ void QGSPage::postProcessXml(QTemporaryFile& temporaryFile, QString fileName, QS // Scale the template group correctly #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) - templateGroup.setAttribute(QString::fromUtf8("transform"), + templateGroup.setAttribute( + QString::fromUtf8("transform"), QString().sprintf("scale(%f, %f)", Rez::guiX(1.0), Rez::guiX(1.0))); #else templateGroup.setAttribute(QString::fromUtf8("transform"), - QString::fromLatin1("scale(%1, %2)").arg(Rez::guiX(1.0), 0, 'f').arg(Rez::guiX(1.0), 0, 'f')); + QString::fromLatin1("scale(%1, %2)") + .arg(Rez::guiX(1.0), 0, 'f') + .arg(Rez::guiX(1.0), 0, 'f')); #endif // Finally, transfer all template document child nodes under the template group @@ -1235,12 +1251,13 @@ void QGSPage::postProcessXml(QTemporaryFile& temporaryFile, QString fileName, QS removeEmptyGroups(exportDocElem); // Time to save our product - QFile outFile( fileName ); - if( !outFile.open( QIODevice::WriteOnly | QIODevice::Text ) ) { - Base::Console().Error("QGSP::ppxml - failed to open file for writing: %s\n", qPrintable(fileName) ); + QFile outFile(fileName); + if (!outFile.open(QIODevice::WriteOnly | QIODevice::Text)) { + Base::Console().Error("QGSP::ppxml - failed to open file for writing: %s\n", + qPrintable(fileName)); } - QTextStream stream( &outFile ); + QTextStream stream(&outFile); stream.setGenerateByteOrderMark(false); stream.setCodec("UTF-8"); @@ -1248,15 +1265,15 @@ void QGSPage::postProcessXml(QTemporaryFile& temporaryFile, QString fileName, QS outFile.close(); } -TechDraw::DrawPage* QGSPage::getDrawPage() -{ - return m_vpPage->getDrawPage(); -} +TechDraw::DrawPage* QGSPage::getDrawPage() { return m_vpPage->getDrawPage(); } QColor QGSPage::getBackgroundColor() { - Base::Reference hGrp = App::GetApplication().GetUserParameter() - .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors"); + Base::Reference hGrp = App::GetApplication() + .GetUserParameter() + .GetGroup("BaseApp") + ->GetGroup("Preferences") + ->GetGroup("Mod/TechDraw/Colors"); App::Color fcColor; fcColor.setPackedValue(hGrp->GetUnsigned("Background", 0x70707000)); return fcColor.asValue(); diff --git a/src/Mod/TechDraw/Gui/QGSPage.h b/src/Mod/TechDraw/Gui/QGSPage.h index c63c19fbd0..99f7249656 100644 --- a/src/Mod/TechDraw/Gui/QGSPage.h +++ b/src/Mod/TechDraw/Gui/QGSPage.h @@ -31,11 +31,13 @@ class QTemporaryFile; class QLabel; -namespace App { +namespace App +{ class DocumentObject; } -namespace TechDraw { +namespace TechDraw +{ class DrawView; class DrawViewPart; class DrawViewSection; @@ -54,7 +56,7 @@ class DrawLeaderLine; class DrawViewBalloon; class DrawRichAnno; class DrawWeldSymbol; -} +}// namespace TechDraw namespace TechDrawGui { @@ -67,31 +69,31 @@ class QGILeaderLine; class QGIRichAnno; class QGITile; -class TechDrawGuiExport QGSPage : public QGraphicsScene +class TechDrawGuiExport QGSPage: public QGraphicsScene { Q_OBJECT public: - explicit QGSPage(ViewProviderPage *vpPage, QWidget *parent = nullptr); + explicit QGSPage(ViewProviderPage* vpPage, QWidget* parent = nullptr); ~QGSPage() = default; - bool addView(const App::DocumentObject *obj); - bool attachView(App::DocumentObject *obj); - QGIView * addViewDimension(TechDraw::DrawViewDimension *dimFeat); - QGIView * addViewBalloon(TechDraw::DrawViewBalloon *balloonFeat); - QGIView * addProjectionGroup(TechDraw::DrawProjGroup *projGroupFeat); - QGIView * addViewPart(TechDraw::DrawViewPart *partFeat); - QGIView * addViewSection(TechDraw::DrawViewSection *sectionFeat); - QGIView * addDrawView(TechDraw::DrawView *viewFeat); - QGIView * addDrawViewCollection(TechDraw::DrawViewCollection *collectionFeat); - QGIView * addDrawViewAnnotation(TechDraw::DrawViewAnnotation *annoFeat); - QGIView * addDrawViewSymbol(TechDraw::DrawViewSymbol *symbolFeat); - QGIView * addDrawViewClip(TechDraw::DrawViewClip *clipFeat); - QGIView * addDrawViewSpreadsheet(TechDraw::DrawViewSpreadsheet *sheetFeat); - QGIView * addDrawViewImage(TechDraw::DrawViewImage *imageFeat); - QGIView * addViewLeader(TechDraw::DrawLeaderLine* leaderFeat); - QGIView * addRichAnno(TechDraw::DrawRichAnno* richFeat); - QGIView * addWeldSymbol(TechDraw::DrawWeldSymbol* weldFeat); + bool addView(const App::DocumentObject* obj); + bool attachView(App::DocumentObject* obj); + QGIView* addViewDimension(TechDraw::DrawViewDimension* dimFeat); + QGIView* addViewBalloon(TechDraw::DrawViewBalloon* balloonFeat); + QGIView* addProjectionGroup(TechDraw::DrawProjGroup* projGroupFeat); + QGIView* addViewPart(TechDraw::DrawViewPart* partFeat); + QGIView* addViewSection(TechDraw::DrawViewSection* sectionFeat); + QGIView* addDrawView(TechDraw::DrawView* viewFeat); + QGIView* addDrawViewCollection(TechDraw::DrawViewCollection* collectionFeat); + QGIView* addDrawViewAnnotation(TechDraw::DrawViewAnnotation* annoFeat); + QGIView* addDrawViewSymbol(TechDraw::DrawViewSymbol* symbolFeat); + QGIView* addDrawViewClip(TechDraw::DrawViewClip* clipFeat); + QGIView* addDrawViewSpreadsheet(TechDraw::DrawViewSpreadsheet* sheetFeat); + QGIView* addDrawViewImage(TechDraw::DrawViewImage* imageFeat); + QGIView* addViewLeader(TechDraw::DrawLeaderLine* leaderFeat); + QGIView* addRichAnno(TechDraw::DrawRichAnno* richFeat); + QGIView* addWeldSymbol(TechDraw::DrawWeldSymbol* weldFeat); void addChildrenToPage(); void fixOrphans(bool force = false); @@ -99,35 +101,36 @@ public: void redrawAllViews(); void redraw1View(TechDraw::DrawView* dView); - QGIView* findQViewForDocObj(App::DocumentObject *obj) const; + QGIView* findQViewForDocObj(App::DocumentObject* obj) const; QGIView* getQGIVByName(std::string name); - QGIView* findParent(QGIView *) const; - void findMissingViews( const std::vector &list, std::vector &missing); - bool hasQView(App::DocumentObject *obj); + QGIView* findParent(QGIView*) const; + void findMissingViews(const std::vector& list, + std::vector& missing); + bool hasQView(App::DocumentObject* obj); void addBalloonToParent(QGIViewBalloon* balloon, QGIView* parent); - void createBalloon(QPointF origin, TechDraw::DrawViewPart *parent); + void createBalloon(QPointF origin, TechDraw::DrawView* parent); void addDimToParent(QGIViewDimension* dim, QGIView* parent); void addLeaderToParent(QGILeaderLine* lead, QGIView* parent); void addAnnoToParent(QGIRichAnno* anno, QGIView* parent); - std::vector getViews() const; + std::vector getViews() const; - int addQView(QGIView * view); - int removeQView(QGIView *view); + int addQView(QGIView* view); + int removeQView(QGIView* view); int removeQViewByName(const char* name); - void removeQViewFromScene(QGIView *view); + void removeQViewFromScene(QGIView* view); - void setPageTemplate(TechDraw::DrawTemplate *templateFeat); - QGITemplate * getTemplate() const; + void setPageTemplate(TechDraw::DrawTemplate* templateFeat); + QGITemplate* getTemplate() const; void removeTemplate(); void matchSceneRectToTemplate(); - void attachTemplate(TechDraw::DrawTemplate *obj); + void attachTemplate(TechDraw::DrawTemplate* obj); void updateTemplate(bool force = false); QPointF getTemplateCenter(); - TechDraw::DrawPage * getDrawPage(); + TechDraw::DrawPage* getDrawPage(); void setExporting(bool enable); virtual void refreshViews(); @@ -143,13 +146,13 @@ public: protected: QColor getBackgroundColor(); - bool orphanExists(const char *viewName, const std::vector &list); + bool orphanExists(const char* viewName, const std::vector& list); private: - QGITemplate *pageTemplate; - ViewProviderPage *m_vpPage; + QGITemplate* pageTemplate; + ViewProviderPage* m_vpPage; }; -} // namespace +}// namespace TechDrawGui -#endif // TECHDRAWGUI_QGSCENE_H +#endif// TECHDRAWGUI_QGSCENE_H diff --git a/src/Mod/TechDraw/Gui/QGVNavStyle.cpp b/src/Mod/TechDraw/Gui/QGVNavStyle.cpp index df981f4fc5..aef7852edb 100644 --- a/src/Mod/TechDraw/Gui/QGVNavStyle.cpp +++ b/src/Mod/TechDraw/Gui/QGVNavStyle.cpp @@ -22,9 +22,9 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include +#include +#include +#include #endif #include @@ -32,24 +32,19 @@ #include #include -#include "QGVNavStyle.h" #include "QGSPage.h" +#include "QGVNavStyle.h" #include "QGVPage.h" using namespace TechDrawGui; -namespace TechDrawGui { - -QGVNavStyle::QGVNavStyle(QGVPage *qgvp) : - m_viewer(qgvp) +namespace TechDrawGui { - initialize(); -} -QGVNavStyle::~QGVNavStyle() -{ -} +QGVNavStyle::QGVNavStyle(QGVPage* qgvp) : m_viewer(qgvp) { initialize(); } + +QGVNavStyle::~QGVNavStyle() {} void QGVNavStyle::initialize() { @@ -59,15 +54,21 @@ void QGVNavStyle::initialize() this->ctrldown = false; this->shiftdown = false; this->altdown = false; - this->invertZoom = App::GetApplication().GetParameterGroupByPath - ("User parameter:BaseApp/Preferences/View")->GetBool("InvertZoom", true); - this->zoomAtCursor = App::GetApplication().GetParameterGroupByPath - ("User parameter:BaseApp/Preferences/View")->GetBool("ZoomAtCursor", true); - this->zoomStep = App::GetApplication().GetParameterGroupByPath - ("User parameter:BaseApp/Preferences/View")->GetFloat("ZoomStep", 0.2f); + this->invertZoom = App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") + ->GetBool("InvertZoom", true); + this->zoomAtCursor = App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") + ->GetBool("ZoomAtCursor", true); + this->zoomStep = App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") + ->GetFloat("ZoomStep", 0.2f); - Base::Reference hGrp = App::GetApplication().GetUserParameter() - .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/General"); + Base::Reference hGrp = App::GetApplication() + .GetUserParameter() + .GetGroup("BaseApp") + ->GetGroup("Preferences") + ->GetGroup("Mod/TechDraw/General"); m_reversePan = hGrp->GetInt("KbPan", 1); m_reverseScroll = hGrp->GetInt("KbScroll", 1); @@ -88,14 +89,15 @@ void QGVNavStyle::setAnchor() if (zoomAtCursor) { m_viewer->setResizeAnchor(QGraphicsView::AnchorUnderMouse); m_viewer->setTransformationAnchor(QGraphicsView::AnchorUnderMouse); - } else { + } + else { m_viewer->setResizeAnchor(QGraphicsView::AnchorViewCenter); m_viewer->setTransformationAnchor(QGraphicsView::AnchorViewCenter); } } } -void QGVNavStyle::handleEnterEvent(QEvent *event) +void QGVNavStyle::handleEnterEvent(QEvent* event) { Q_UNUSED(event); if (getViewer()->isBalloonPlacing()) { @@ -103,16 +105,16 @@ void QGVNavStyle::handleEnterEvent(QEvent *event) } } -void QGVNavStyle::handleFocusOutEvent(QFocusEvent *event) +void QGVNavStyle::handleFocusOutEvent(QFocusEvent* event) { Q_UNUSED(event); getViewer()->cancelBalloonPlacing(); } -void QGVNavStyle::handleKeyPressEvent(QKeyEvent *event) +void QGVNavStyle::handleKeyPressEvent(QKeyEvent* event) { - if(event->modifiers().testFlag(Qt::ControlModifier)) { - switch(event->key()) { + if (event->modifiers().testFlag(Qt::ControlModifier)) { + switch (event->key()) { case Qt::Key_Plus: { zoom(1.0 + zoomStep); event->accept(); @@ -129,8 +131,8 @@ void QGVNavStyle::handleKeyPressEvent(QKeyEvent *event) } } - if(event->modifiers().testFlag( Qt::NoModifier)) { - switch(event->key()) { + if (event->modifiers().testFlag(Qt::NoModifier)) { + switch (event->key()) { case Qt::Key_Left: { getViewer()->kbPanScroll(1, 0); event->accept(); @@ -168,11 +170,11 @@ void QGVNavStyle::handleKeyPressEvent(QKeyEvent *event) } } -void QGVNavStyle::handleKeyReleaseEvent(QKeyEvent *event) +void QGVNavStyle::handleKeyReleaseEvent(QKeyEvent* event) { -// Q_UNUSED(event); - if(event->modifiers().testFlag( Qt::NoModifier)) { - switch(event->key()) { + // Q_UNUSED(event); + if (event->modifiers().testFlag(Qt::NoModifier)) { + switch (event->key()) { case Qt::Key_Shift: { this->shiftdown = false; event->accept(); @@ -185,14 +187,15 @@ void QGVNavStyle::handleKeyReleaseEvent(QKeyEvent *event) } } -void QGVNavStyle::handleLeaveEvent(QEvent *event) +void QGVNavStyle::handleLeaveEvent(QEvent* event) { Q_UNUSED(event); if (getViewer()->isBalloonPlacing()) { int left_x; if (getViewer()->getBalloonCursorPos().x() < 32) left_x = 0; - else if (getViewer()->getBalloonCursorPos().x() > (getViewer()->contentsRect().right() - 32)) + else if (getViewer()->getBalloonCursorPos().x() + > (getViewer()->contentsRect().right() - 32)) left_x = getViewer()->contentsRect().right() - 32; else left_x = getViewer()->getBalloonCursorPos().x(); @@ -200,29 +203,30 @@ void QGVNavStyle::handleLeaveEvent(QEvent *event) int left_y; if (getViewer()->getBalloonCursorPos().y() < 32) left_y = 0; - else if (getViewer()->getBalloonCursorPos().y() > (getViewer()->contentsRect().bottom() - 32)) + else if (getViewer()->getBalloonCursorPos().y() + > (getViewer()->contentsRect().bottom() - 32)) left_y = getViewer()->contentsRect().bottom() - 32; else left_y = getViewer()->getBalloonCursorPos().y(); /* When cursor leave the page, display getViewer()->balloonCursor where it left */ - getViewer()->getBalloonCursor()->setGeometry(left_x ,left_y, 32, 32); + getViewer()->getBalloonCursor()->setGeometry(left_x, left_y, 32, 32); getViewer()->getBalloonCursor()->show(); } } -void QGVNavStyle::handleMousePressEvent(QMouseEvent *event) +void QGVNavStyle::handleMousePressEvent(QMouseEvent* event) { -// Base::Console().Message("QGVNS::handleMousePressEvent()\n"); + // Base::Console().Message("QGVNS::handleMousePressEvent()\n"); if (!panningActive && (event->button() == Qt::MiddleButton)) { startPan(event->pos()); event->accept(); } } -void QGVNavStyle::handleMouseMoveEvent(QMouseEvent *event) +void QGVNavStyle::handleMouseMoveEvent(QMouseEvent* event) { -// Base::Console().Message("QGVNS::handleMouseMoveEvent()\n"); + // Base::Console().Message("QGVNS::handleMouseMoveEvent()\n"); if (getViewer()->isBalloonPlacing()) { getViewer()->setBalloonCursorPos(event->pos()); } @@ -235,9 +239,9 @@ void QGVNavStyle::handleMouseMoveEvent(QMouseEvent *event) //NOTE: QGraphicsView::contextMenuEvent consumes the mouse release event for the //button that caused the event (typically RMB) -void QGVNavStyle::handleMouseReleaseEvent(QMouseEvent *event) +void QGVNavStyle::handleMouseReleaseEvent(QMouseEvent* event) { -// Base::Console().Message("QGVNS::handleMouseReleaseEvent()\n"); + // Base::Console().Message("QGVNS::handleMouseReleaseEvent()\n"); if (getViewer()->isBalloonPlacing()) { placeBalloon(event->pos()); } @@ -248,30 +252,27 @@ void QGVNavStyle::handleMouseReleaseEvent(QMouseEvent *event) } } -bool QGVNavStyle::allowContextMenu(QContextMenuEvent *event) +bool QGVNavStyle::allowContextMenu(QContextMenuEvent* event) { Q_UNUSED(event) -// Base::Console().Message("QGVNS::allowContextMenu()\n"); -// if (event->reason() == QContextMenuEvent::Mouse) { -// //must check for a button combination involving context menu button -// } + // Base::Console().Message("QGVNS::allowContextMenu()\n"); + // if (event->reason() == QContextMenuEvent::Mouse) { + // //must check for a button combination involving context menu button + // } return true; } -void QGVNavStyle::pseudoContextEvent() -{ - getViewer()->pseudoContextEvent(); -} +void QGVNavStyle::pseudoContextEvent() { getViewer()->pseudoContextEvent(); } -void QGVNavStyle::handleWheelEvent(QWheelEvent *event) +void QGVNavStyle::handleWheelEvent(QWheelEvent* event) { -//gets called once for every click of the wheel. the sign of event->angleDelta().y() -//gives the direction of wheel rotation. positive indicates rotation forwards away -//from the user; negative backwards toward the user. the magnitude of -//event->angleDelta().y() is 120 for most mice which represents 120/8 = 15 degrees of -//rotation. Some high resolution mice/trackpads report smaller values - ie a click is less than -//15 degrees of wheel rotation. -//https://doc.qt.io/qt-5/qwheelevent.html#angleDelta + //gets called once for every click of the wheel. the sign of event->angleDelta().y() + //gives the direction of wheel rotation. positive indicates rotation forwards away + //from the user; negative backwards toward the user. the magnitude of + //event->angleDelta().y() is 120 for most mice which represents 120/8 = 15 degrees of + //rotation. Some high resolution mice/trackpads report smaller values - ie a click is less than + //15 degrees of wheel rotation. + //https://doc.qt.io/qt-5/qwheelevent.html#angleDelta //to avoid overly sensitive behaviour in high resolution mice/touchpads, //save up wheel clicks until the wheel has rotated at least 15 degrees. constexpr int wheelDeltaThreshold = 120; @@ -281,7 +282,7 @@ void QGVNavStyle::handleWheelEvent(QWheelEvent *event) } m_wheelDeltaCounter = 0; //starting with -ve direction keeps us in sync with the behaviour of the 3d window - int rotationDirection = - event->angleDelta().y() / std::abs(event->angleDelta().y()); + int rotationDirection = -event->angleDelta().y() / std::abs(event->angleDelta().y()); if (invertZoom) { rotationDirection = -rotationDirection; } @@ -294,21 +295,19 @@ void QGVNavStyle::zoom(double factor) constexpr double minimumScale(0.01); QTransform transform = getViewer()->transform(); double xScale = transform.m11(); - if (xScale <= minimumScale && - factor < 1.0) { + if (xScale <= minimumScale && factor < 1.0) { //don't scale any smaller than this return; } setAnchor(); - getViewer()->scale(factor, - factor); + getViewer()->scale(factor, factor); m_zoomPending = false; } void QGVNavStyle::startZoom(QPoint p) { -// Base::Console().Message("QGVNS::startZoom(%s)\n", TechDraw::DrawUtil::formatVector(p).c_str()); + // Base::Console().Message("QGVNS::startZoom(%s)\n", TechDraw::DrawUtil::formatVector(p).c_str()); zoomOrigin = p; zoomingActive = true; m_zoomPending = false; @@ -317,7 +316,7 @@ void QGVNavStyle::startZoom(QPoint p) void QGVNavStyle::stopZoom() { -// Base::Console().Message("QGVNS::stopZoom()\n"); + // Base::Console().Message("QGVNS::stopZoom()\n"); zoomingActive = false; m_zoomPending = false; getViewer()->resetCursor(); @@ -352,19 +351,19 @@ void QGVNavStyle::startPan(QPoint p) void QGVNavStyle::pan(QPoint p) { - QScrollBar *horizontalScrollbar = getViewer()->horizontalScrollBar(); - QScrollBar *verticalScrollbar = getViewer()->verticalScrollBar(); + QScrollBar* horizontalScrollbar = getViewer()->horizontalScrollBar(); + QScrollBar* verticalScrollbar = getViewer()->verticalScrollBar(); QPoint direction = p - panOrigin; - horizontalScrollbar->setValue(horizontalScrollbar->value() - m_reversePan*direction.x()); - verticalScrollbar->setValue(verticalScrollbar->value() - m_reverseScroll*direction.y()); + horizontalScrollbar->setValue(horizontalScrollbar->value() - m_reversePan * direction.x()); + verticalScrollbar->setValue(verticalScrollbar->value() - m_reverseScroll * direction.y()); panOrigin = p; } void QGVNavStyle::stopPan() { -// Base::Console().Message("QGVNS::stopPan()\n"); + // Base::Console().Message("QGVNS::stopPan()\n"); panningActive = false; m_panPending = false; getViewer()->resetCursor(); @@ -384,27 +383,25 @@ void QGVNavStyle::stopClick() void QGVNavStyle::placeBalloon(QPoint p) { + // Base::Console().Message("QGVNS::placeBalloon()\n"); getViewer()->getBalloonCursor()->hide(); + //balloon was created in Command.cpp. Why are we doing it again? getViewer()->getScene()->createBalloon(getViewer()->mapToScene(p), - getViewer()->getDrawPage()->balloonParent); + getViewer()->getBalloonParent()); getViewer()->setBalloonPlacing(false); } //**************************************** -KeyCombination::KeyCombination() -{ -} +KeyCombination::KeyCombination() {} -KeyCombination::~KeyCombination() -{ -} +KeyCombination::~KeyCombination() {} void KeyCombination::addKey(int inKey) { bool found = false; //check for inKey already in keys if (!keys.empty()) { - for (auto& k: keys) { + for (auto& k : keys) { if (k == inKey) { found = true; } @@ -418,7 +415,7 @@ void KeyCombination::addKey(int inKey) void KeyCombination::removeKey(int inKey) { std::vector newKeys; - for (auto& k: keys) { + for (auto& k : keys) { if (k != inKey) { newKeys.push_back(k); } @@ -426,26 +423,20 @@ void KeyCombination::removeKey(int inKey) keys = newKeys; } -void KeyCombination::clear() -{ - keys.clear(); -} +void KeyCombination::clear() { keys.clear(); } -bool KeyCombination::empty() -{ - return keys.empty(); -} +bool KeyCombination::empty() { return keys.empty(); } //does inCombo match the keys we have in current combination bool KeyCombination::haveCombination(int inCombo) { bool matched = false; - int combo = 0; //no key + int combo = 0;//no key if (keys.size() < 2) { //not enough keys for a combination return false; } - for (auto& k: keys) { + for (auto& k : keys) { combo = combo | k; } if (combo == inCombo) { @@ -454,4 +445,4 @@ bool KeyCombination::haveCombination(int inCombo) return matched; } -} //namespace TechDrawGui +}//namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/QGVPage.cpp b/src/Mod/TechDraw/Gui/QGVPage.cpp index 0996a8d619..30c60e9e37 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.cpp +++ b/src/Mod/TechDraw/Gui/QGVPage.cpp @@ -22,18 +22,18 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif #include @@ -50,7 +50,6 @@ #include #include -#include "QGVPage.h" #include "MDIViewPage.h" #include "PreferencesGui.h" #include "QGSPage.h" @@ -64,6 +63,7 @@ #include "QGVNavStyleRevit.h" #include "QGVNavStyleTinkerCAD.h" #include "QGVNavStyleTouchpad.h" +#include "QGVPage.h" #include "Rez.h" #include "ViewProviderPage.h" @@ -83,20 +83,13 @@ #define PAN_HOT_X 7 #define PAN_HOT_Y 7 -static unsigned char pan_bitmap[PAN_BYTES] = -{ - 0xc0, 0x03, 0x60, 0x02, 0x20, 0x04, 0x10, 0x08, - 0x68, 0x16, 0x54, 0x2a, 0x73, 0xce, 0x01, 0x80, - 0x01, 0x80, 0x73, 0xce, 0x54, 0x2a, 0x68, 0x16, - 0x10, 0x08, 0x20, 0x04, 0x40, 0x02, 0xc0, 0x03 -}; +static unsigned char pan_bitmap[PAN_BYTES] = { + 0xc0, 0x03, 0x60, 0x02, 0x20, 0x04, 0x10, 0x08, 0x68, 0x16, 0x54, 0x2a, 0x73, 0xce, 0x01, 0x80, + 0x01, 0x80, 0x73, 0xce, 0x54, 0x2a, 0x68, 0x16, 0x10, 0x08, 0x20, 0x04, 0x40, 0x02, 0xc0, 0x03}; -static unsigned char pan_mask_bitmap[PAN_BYTES] = -{ - 0xc0, 0x03, 0xe0, 0x03, 0xe0, 0x07, 0xf0, 0x0f, 0xe8, 0x17, 0xdc, 0x3b, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xdc, 0x3b, 0xe8, 0x17, 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, - 0xc0, 0x03 -}; +static unsigned char pan_mask_bitmap[PAN_BYTES] = { + 0xc0, 0x03, 0xe0, 0x03, 0xe0, 0x07, 0xf0, 0x0f, 0xe8, 0x17, 0xdc, 0x3b, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xdc, 0x3b, 0xe8, 0x17, 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0xc0, 0x03}; /*** zoom-style cursor ******/ #define ZOOM_WIDTH 16 @@ -105,83 +98,83 @@ static unsigned char pan_mask_bitmap[PAN_BYTES] = #define ZOOM_HOT_X 5 #define ZOOM_HOT_Y 7 -static unsigned char zoom_bitmap[ZOOM_BYTES] = -{ - 0x00, 0x0f, 0x80, 0x1c, 0x40, 0x38, 0x20, 0x70, - 0x90, 0xe4, 0xc0, 0xcc, 0xf0, 0xfc, 0x00, 0x0c, - 0x00, 0x0c, 0xf0, 0xfc, 0xc0, 0xcc, 0x90, 0xe4, - 0x20, 0x70, 0x40, 0x38, 0x80, 0x1c, 0x00, 0x0f -}; +static unsigned char zoom_bitmap[ZOOM_BYTES] = { + 0x00, 0x0f, 0x80, 0x1c, 0x40, 0x38, 0x20, 0x70, 0x90, 0xe4, 0xc0, 0xcc, 0xf0, 0xfc, 0x00, 0x0c, + 0x00, 0x0c, 0xf0, 0xfc, 0xc0, 0xcc, 0x90, 0xe4, 0x20, 0x70, 0x40, 0x38, 0x80, 0x1c, 0x00, 0x0f}; -static unsigned char zoom_mask_bitmap[ZOOM_BYTES] = -{ - 0x00, 0x0f, 0x80, 0x1f, 0xc0, 0x3f, 0xe0, 0x7f, 0xf0, 0xff, 0xf0, 0xff, 0xf0, 0xff, 0x00, - 0x0f, 0x00, 0x0f, 0xf0, 0xff, 0xf0, 0xff, 0xf0, 0xff, 0xe0, 0x7f, 0xc0, 0x3f, 0x80, 0x1f, - 0x00, 0x0f -}; +static unsigned char zoom_mask_bitmap[ZOOM_BYTES] = { + 0x00, 0x0f, 0x80, 0x1f, 0xc0, 0x3f, 0xe0, 0x7f, 0xf0, 0xff, 0xf0, 0xff, 0xf0, 0xff, 0x00, 0x0f, + 0x00, 0x0f, 0xf0, 0xff, 0xf0, 0xff, 0xf0, 0xff, 0xe0, 0x7f, 0xc0, 0x3f, 0x80, 0x1f, 0x00, 0x0f}; using namespace Gui; using namespace TechDraw; using namespace TechDrawGui; -class QGVPage::Private : public ParameterGrp::ObserverType { +class QGVPage::Private: public ParameterGrp::ObserverType +{ public: /// handle to the viewer parameter group ParameterGrp::handle hGrp; QGVPage* page; - explicit Private(QGVPage* page) : page(page) { + explicit Private(QGVPage* page) : page(page) + { // attach parameter Observer - hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); + hGrp = App::GetApplication().GetParameterGroupByPath( + "User parameter:BaseApp/Preferences/View"); hGrp->Attach(this); } - void init() { + void init() + { page->m_atCursor = hGrp->GetBool("ZoomAtCursor", 1l); page->m_invertZoom = hGrp->GetBool("InvertZoom", 0l); page->m_zoomIncrement = hGrp->GetFloat("ZoomStep", 0.02); - auto hTDPref = App::GetApplication().GetUserParameter() - .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/General"); + auto hTDPref = App::GetApplication() + .GetUserParameter() + .GetGroup("BaseApp") + ->GetGroup("Preferences") + ->GetGroup("Mod/TechDraw/General"); page->m_reversePan = hTDPref->GetInt("KbPan", 1); page->m_reverseScroll = hTDPref->GetInt("KbScroll", 1); } /// Observer message from the ParameterGrp - void OnChange(ParameterGrp::SubjectType &rCaller, ParameterGrp::MessageType Reason) override { + void OnChange(ParameterGrp::SubjectType& rCaller, ParameterGrp::MessageType Reason) override + { const ParameterGrp& rGrp = static_cast(rCaller); if (strcmp(Reason, "NavigationStyle") == 0) { - std::string model = rGrp.GetASCII("NavigationStyle", CADNavigationStyle::getClassTypeId().getName()); + std::string model = + rGrp.GetASCII("NavigationStyle", CADNavigationStyle::getClassTypeId().getName()); page->setNavigationStyle(model); - } else if (strcmp(Reason, "InvertZoom") == 0) { + } + else if (strcmp(Reason, "InvertZoom") == 0) { page->m_invertZoom = rGrp.GetBool("InvertZoom", true); - } else if (strcmp(Reason, "ZoomStep") == 0) { + } + else if (strcmp(Reason, "ZoomStep") == 0) { page->m_zoomIncrement = rGrp.GetFloat("ZoomStep", 0.0f); - } else if (strcmp(Reason, "ZoomAtCursor") == 0) { + } + else if (strcmp(Reason, "ZoomAtCursor") == 0) { page->m_atCursor = rGrp.GetBool("ZoomAtCursor", true); if (page->m_atCursor) { page->setResizeAnchor(QGVPage::AnchorUnderMouse); page->setTransformationAnchor(QGVPage::AnchorUnderMouse); - } else { + } + else { page->setResizeAnchor(QGVPage::AnchorViewCenter); page->setTransformationAnchor(QGVPage::AnchorViewCenter); } } } - void detach() { - hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); + void detach() + { + hGrp = App::GetApplication().GetParameterGroupByPath( + "User parameter:BaseApp/Preferences/View"); hGrp->Detach(this); - } }; -QGVPage::QGVPage(ViewProviderPage *vpPage, QGSPage* scenePage, QWidget *parent) - : QGraphicsView(parent), - m_renderer(Native), - drawBkg(true), - m_vpPage(nullptr), - m_scene(scenePage), - balloonPlacing(false), - panningActive(false), - m_showGrid(false), - m_navStyle(nullptr), - d(new Private(this)) +QGVPage::QGVPage(ViewProviderPage* vpPage, QGSPage* scenePage, QWidget* parent) + : QGraphicsView(parent), m_renderer(Native), drawBkg(true), m_vpPage(nullptr), + m_scene(scenePage), balloonPlacing(false), panningActive(false), m_showGrid(false), + m_navStyle(nullptr), d(new Private(this)) { assert(vpPage); m_vpPage = vpPage; @@ -197,27 +190,29 @@ QGVPage::QGVPage(ViewProviderPage *vpPage, QGSPage* scenePage, QWidget *parent) setCacheMode(QGraphicsView::CacheBackground); setRenderer(Native); -// setRenderer(OpenGL); //gives rotten quality, don't use this + // setRenderer(OpenGL); //gives rotten quality, don't use this setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); d->init(); if (m_atCursor) { setResizeAnchor(AnchorUnderMouse); setTransformationAnchor(AnchorUnderMouse); - } else { + } + else { setResizeAnchor(AnchorViewCenter); setTransformationAnchor(AnchorViewCenter); } setAlignment(Qt::AlignCenter); -// setDragMode(ScrollHandDrag); + // setDragMode(ScrollHandDrag); setDragMode(QGraphicsView::NoDrag); resetCursor(); bkgBrush = new QBrush(getBackgroundColor()); balloonCursor = new QLabel(this); - balloonCursor->setPixmap(prepareCursorPixmap("TechDraw_Balloon.svg", balloonHotspot = QPoint(8, 59))); + balloonCursor->setPixmap( + prepareCursorPixmap("TechDraw_Balloon.svg", balloonHotspot = QPoint(8, 59))); balloonCursor->hide(); initNavigationStyle(); @@ -232,10 +227,7 @@ QGVPage::~QGVPage() d->detach(); } -void QGVPage::centerOnPage(void) -{ - centerOn(m_vpPage->getQGSPage()->getTemplateCenter()); -} +void QGVPage::centerOnPage(void) { centerOn(m_vpPage->getQGSPage()->getTemplateCenter()); } void QGVPage::initNavigationStyle() { @@ -245,7 +237,7 @@ void QGVPage::initNavigationStyle() void QGVPage::setNavigationStyle(std::string navParm) { -// Base::Console().Message("QGVP::setNavigationStyle(%s)\n", navParm.c_str()); + // Base::Console().Message("QGVP::setNavigationStyle(%s)\n", navParm.c_str()); if (m_navStyle) { delete m_navStyle; } @@ -263,34 +255,47 @@ void QGVPage::setNavigationStyle(std::string navParm) if (foundBlender != std::string::npos) { m_navStyle = static_cast(new QGVNavStyleBlender(this)); - } else if (foundCAD != std::string::npos) { + } + else if (foundCAD != std::string::npos) { m_navStyle = static_cast(new QGVNavStyleCAD(this)); - } else if (foundTouchPad != std::string::npos) { + } + else if (foundTouchPad != std::string::npos) { m_navStyle = static_cast(new QGVNavStyleTouchpad(this)); - } else if (foundInventor != std::string::npos) { + } + else if (foundInventor != std::string::npos) { m_navStyle = static_cast(new QGVNavStyleInventor(this)); - } else if (foundTinker != std::string::npos) { + } + else if (foundTinker != std::string::npos) { m_navStyle = static_cast(new QGVNavStyleTinkerCAD(this)); - } else if (foundGesture != std::string::npos) { + } + else if (foundGesture != std::string::npos) { m_navStyle = static_cast(new QGVNavStyleGesture(this)); - } else if (foundMaya != std::string::npos) { + } + else if (foundMaya != std::string::npos) { m_navStyle = static_cast(new QGVNavStyleMaya(this)); - } else if (foundOCC != std::string::npos) { + } + else if (foundOCC != std::string::npos) { m_navStyle = static_cast(new QGVNavStyleOCC(this)); - } else if (foundOpenSCAD != std::string::npos) { + } + else if (foundOpenSCAD != std::string::npos) { m_navStyle = static_cast(new QGVNavStyleOpenSCAD(this)); - } else if (foundRevit != std::string::npos) { + } + else if (foundRevit != std::string::npos) { m_navStyle = static_cast(new QGVNavStyleRevit(this)); - } else { + } + else { m_navStyle = new QGVNavStyle(this); } } -void QGVPage::startBalloonPlacing() +void QGVPage::startBalloonPlacing(DrawView* parent) { + // Base::Console().Message("QGVP::startBalloonPlacing(%s)\n", parent->getNameInDocument()); balloonPlacing = true; + m_balloonParent = parent; #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) - activateCursor(QCursor(balloonCursor->pixmap(Qt::ReturnByValue), balloonHotspot.x(), balloonHotspot.y())); + activateCursor( + QCursor(balloonCursor->pixmap(Qt::ReturnByValue), balloonHotspot.x(), balloonHotspot.y())); #else activateCursor(QCursor(*balloonCursor->pixmap(), balloonHotspot.x(), balloonHotspot.y())); #endif @@ -299,22 +304,23 @@ void QGVPage::startBalloonPlacing() void QGVPage::cancelBalloonPlacing() { balloonPlacing = false; + m_balloonParent = nullptr; balloonCursor->hide(); resetCursor(); } -void QGVPage::drawBackground(QPainter *painter, const QRectF &) +void QGVPage::drawBackground(QPainter* painter, const QRectF&) { -//Note: Background is not part of scene() - if(!drawBkg) + //Note: Background is not part of scene() + if (!drawBkg) return; - if(!m_vpPage) { + if (!m_vpPage) { return; } if (!m_vpPage->getDrawPage()) { -// Base::Console().Message("QGVP::drawBackground - no Page Feature!\n"); + // Base::Console().Message("QGVP::drawBackground - no Page Feature!\n"); return; } @@ -322,14 +328,14 @@ void QGVPage::drawBackground(QPainter *painter, const QRectF &) painter->resetTransform(); painter->setBrush(*bkgBrush); - painter->drawRect(viewport()->rect().adjusted(-2, -2, 2,2)); //just bigger than viewport to prevent artifacts + painter->drawRect( + viewport()->rect().adjusted(-2, -2, 2, 2));//just bigger than viewport to prevent artifacts // Default to A3 landscape, though this is currently relevant // only for opening corrupt docs, etc. - float pageWidth = 420, - pageHeight = 297; + float pageWidth = 420, pageHeight = 297; - if ( m_vpPage->getDrawPage()->hasValidTemplate() ) { + if (m_vpPage->getDrawPage()->hasValidTemplate()) { pageWidth = Rez::guiX(m_vpPage->getDrawPage()->getPageWidth()); pageHeight = Rez::guiX(m_vpPage->getDrawPage()->getPageHeight()); } @@ -352,11 +358,12 @@ void QGVPage::setRenderer(RendererType type) if (m_renderer == OpenGL) { #ifndef QT_NO_OPENGL -// setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); //QGLWidget is obsolete + // setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); //QGLWidget is obsolete setViewport(new QOpenGLWidget); setViewportUpdateMode(QGraphicsView::SmartViewportUpdate); #endif - } else { + } + else { setViewport(new QWidget); setViewportUpdateMode(QGraphicsView::FullViewportUpdate); } @@ -371,7 +378,7 @@ void QGVPage::setHighQualityAntialiasing(bool highQualityAntialiasing) #endif } -void QGVPage::paintEvent(QPaintEvent *event) +void QGVPage::paintEvent(QPaintEvent* event) { if (m_renderer == Image) { if (m_image.size() != viewport()->size()) { @@ -384,16 +391,17 @@ void QGVPage::paintEvent(QPaintEvent *event) QPainter p(viewport()); p.drawImage(0, 0, m_image); - - } else { + } + else { QGraphicsView::paintEvent(event); } } -void QGVPage::contextMenuEvent(QContextMenuEvent *event) +void QGVPage::contextMenuEvent(QContextMenuEvent* event) { if (m_navStyle->allowContextMenu(event)) { - QGraphicsView::contextMenuEvent(event); //this eats the event. mouseReleaseEvent will not be called. + QGraphicsView::contextMenuEvent( + event);//this eats the event. mouseReleaseEvent will not be called. return; } @@ -402,9 +410,8 @@ void QGVPage::contextMenuEvent(QContextMenuEvent *event) if (m_saveContextEvent) { delete m_saveContextEvent; } - m_saveContextEvent = new QContextMenuEvent(QContextMenuEvent::Mouse, - event->pos(), - event->globalPos()); + m_saveContextEvent = + new QContextMenuEvent(QContextMenuEvent::Mouse, event->pos(), event->globalPos()); } void QGVPage::pseudoContextEvent() @@ -414,13 +421,13 @@ void QGVPage::pseudoContextEvent() } } -void QGVPage::wheelEvent(QWheelEvent *event) +void QGVPage::wheelEvent(QWheelEvent* event) { m_navStyle->handleWheelEvent(event); event->accept(); } -void QGVPage::keyPressEvent(QKeyEvent *event) +void QGVPage::keyPressEvent(QKeyEvent* event) { m_navStyle->handleKeyPressEvent(event); if (!event->isAccepted()) { @@ -428,7 +435,7 @@ void QGVPage::keyPressEvent(QKeyEvent *event) } } -void QGVPage::keyReleaseEvent(QKeyEvent *event) +void QGVPage::keyReleaseEvent(QKeyEvent* event) { m_navStyle->handleKeyReleaseEvent(event); if (!event->isAccepted()) { @@ -436,7 +443,8 @@ void QGVPage::keyReleaseEvent(QKeyEvent *event) } } -void QGVPage::focusOutEvent(QFocusEvent *event) { +void QGVPage::focusOutEvent(QFocusEvent* event) +{ Q_UNUSED(event); m_navStyle->handleFocusOutEvent(event); } @@ -445,8 +453,8 @@ void QGVPage::kbPanScroll(int xMove, int yMove) { if (xMove != 0) { QScrollBar* hsb = horizontalScrollBar(); -// int hRange = hsb->maximum() - hsb->minimum(); //default here is 100? -// int hDelta = xMove/hRange + // int hRange = hsb->maximum() - hsb->minimum(); //default here is 100? + // int hDelta = xMove/hRange int hStep = hsb->singleStep() * xMove * m_reversePan; int hNow = hsb->value(); hsb->setValue(hNow + hStep); @@ -459,70 +467,72 @@ void QGVPage::kbPanScroll(int xMove, int yMove) } } -void QGVPage::enterEvent(QEvent *event) +void QGVPage::enterEvent(QEvent* event) { QGraphicsView::enterEvent(event); m_navStyle->handleEnterEvent(event); QGraphicsView::enterEvent(event); } -void QGVPage::leaveEvent(QEvent * event) +void QGVPage::leaveEvent(QEvent* event) { m_navStyle->handleLeaveEvent(event); QGraphicsView::leaveEvent(event); } -void QGVPage::mousePressEvent(QMouseEvent *event) +void QGVPage::mousePressEvent(QMouseEvent* event) { m_navStyle->handleMousePressEvent(event); QGraphicsView::mousePressEvent(event); } -void QGVPage::mouseMoveEvent(QMouseEvent *event) +void QGVPage::mouseMoveEvent(QMouseEvent* event) { m_navStyle->handleMouseMoveEvent(event); QGraphicsView::mouseMoveEvent(event); } -void QGVPage::mouseReleaseEvent(QMouseEvent *event) +void QGVPage::mouseReleaseEvent(QMouseEvent* event) { m_navStyle->handleMouseReleaseEvent(event); QGraphicsView::mouseReleaseEvent(event); resetCursor(); } -TechDraw::DrawPage* QGVPage::getDrawPage() -{ - return m_vpPage->getDrawPage(); -} +TechDraw::DrawPage* QGVPage::getDrawPage() { return m_vpPage->getDrawPage(); } QColor QGVPage::getBackgroundColor() { - Base::Reference hGrp = App::GetApplication().GetUserParameter() - .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors"); + Base::Reference hGrp = App::GetApplication() + .GetUserParameter() + .GetGroup("BaseApp") + ->GetGroup("Preferences") + ->GetGroup("Mod/TechDraw/Colors"); App::Color fcColor; fcColor.setPackedValue(hGrp->GetUnsigned("Background", 0x70707000)); return fcColor.asValue(); } -double QGVPage::getDevicePixelRatio() const { - for (Gui::MDIView *view : m_vpPage->getDocument()->getMDIViews()) { +double QGVPage::getDevicePixelRatio() const +{ + for (Gui::MDIView* view : m_vpPage->getDocument()->getMDIViews()) { if (view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) { - return static_cast(view)->getViewer()->devicePixelRatio(); + return static_cast(view)->getViewer()->devicePixelRatio(); } } return 1.0; } -QPixmap QGVPage::prepareCursorPixmap(const char *iconName, QPoint &hotspot) { +QPixmap QGVPage::prepareCursorPixmap(const char* iconName, QPoint& hotspot) +{ QPointF floatHotspot(hotspot); double pixelRatio = getDevicePixelRatio(); // Due to impossibility to query cursor size via Qt API, we stick to (32x32)*device_pixel_ratio // as FreeCAD Wiki suggests - see https://wiki.freecadweb.org/HiDPI_support#Custom_cursor_size - double cursorSize = 32.0*pixelRatio; + double cursorSize = 32.0 * pixelRatio; QPixmap pixmap = Gui::BitmapFactory().pixmapFromSvg(iconName, QSizeF(cursorSize, cursorSize)); pixmap.setDevicePixelRatio(pixelRatio); @@ -544,27 +554,23 @@ QPixmap QGVPage::prepareCursorPixmap(const char *iconName, QPoint &hotspot) { return pixmap; } -void QGVPage::activateCursor(QCursor cursor) { +void QGVPage::activateCursor(QCursor cursor) +{ this->setCursor(cursor); viewport()->setCursor(cursor); } -void QGVPage::resetCursor() { +void QGVPage::resetCursor() +{ this->setCursor(Qt::ArrowCursor); viewport()->setCursor(Qt::ArrowCursor); } -void QGVPage::setPanCursor() -{ - activateCursor(panCursor); -} +void QGVPage::setPanCursor() { activateCursor(panCursor); } -void QGVPage::setZoomCursor() -{ - activateCursor(zoomCursor); -} +void QGVPage::setZoomCursor() { activateCursor(zoomCursor); } -void QGVPage::drawForeground(QPainter *painter, const QRectF &rect) +void QGVPage::drawForeground(QPainter* painter, const QRectF& rect) { Q_UNUSED(rect); if (m_showGrid) { @@ -588,8 +594,8 @@ void QGVPage::makeGrid(int gridWidth, int gridHeight, double gridStep) //draw horizontal lines for (int i = 0; i < rows; i++) { vPos = i * step; - QPointF start (horizStart, -vPos); - QPointF end (width, -vPos); + QPointF start(horizStart, -vPos); + QPointF end(width, -vPos); grid.moveTo(start); grid.lineTo(end); } @@ -610,9 +616,10 @@ void QGVPage::makeGrid(int gridWidth, int gridHeight, double gridStep) std::string QGVPage::getNavStyleParameter() { - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath - ("User parameter:BaseApp/Preferences/View"); - std::string model = hGrp->GetASCII("NavigationStyle", NavigationStyle::getClassTypeId().getName()); + ParameterGrp::handle hGrp = + App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); + std::string model = + hGrp->GetASCII("NavigationStyle", NavigationStyle::getClassTypeId().getName()); return model; } @@ -624,7 +631,7 @@ Base::Type QGVPage::getStyleType(std::string model) void QGVPage::createStandardCursors(double dpr) { - (void) dpr; //avoid clang warning re unused parameter + (void)dpr;//avoid clang warning re unused parameter QBitmap cursor = QBitmap::fromData(QSize(PAN_WIDTH, PAN_HEIGHT), pan_bitmap); QBitmap mask = QBitmap::fromData(QSize(PAN_WIDTH, PAN_HEIGHT), pan_mask_bitmap); #if defined(Q_OS_WIN32) diff --git a/src/Mod/TechDraw/Gui/QGVPage.h b/src/Mod/TechDraw/Gui/QGVPage.h index b1a0459291..8dcf2a2533 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.h +++ b/src/Mod/TechDraw/Gui/QGVPage.h @@ -33,11 +33,13 @@ #include -namespace App { +namespace App +{ class DocumentObject; } -namespace TechDraw { +namespace TechDraw +{ class DrawView; class DrawViewPart; class DrawProjGroup; @@ -54,7 +56,7 @@ class DrawLeaderLine; class DrawViewBalloon; class DrawRichAnno; class DrawWeldSymbol; -} +}// namespace TechDraw namespace TechDrawGui { @@ -70,41 +72,46 @@ class QGIRichAnno; class QGITile; class QGVNavStyle; -class TechDrawGuiExport QGVPage : public QGraphicsView +class TechDrawGuiExport QGVPage: public QGraphicsView { Q_OBJECT public: - enum RendererType { Native, OpenGL, Image }; + enum RendererType + { + Native, + OpenGL, + Image + }; - QGVPage(ViewProviderPage *vpPage, QGSPage* scenePage, QWidget *parent = nullptr); + QGVPage(ViewProviderPage* vpPage, QGSPage* scenePage, QWidget* parent = nullptr); ~QGVPage(); void setRenderer(RendererType type = Native); - void drawBackground(QPainter *painter, const QRectF &rect) override; + void drawBackground(QPainter* painter, const QRectF& rect) override; - QGSPage* getScene() {return m_scene; } + QGSPage* getScene() { return m_scene; } - void startBalloonPlacing(); + void startBalloonPlacing(TechDraw::DrawView* parent); void cancelBalloonPlacing(); - TechDraw::DrawPage * getDrawPage(); + TechDraw::DrawPage* getDrawPage(); void setExporting(bool enable); void makeGrid(int width, int height, double step); - void showGrid(bool state) {m_showGrid = state;} - void updateViewport() {viewport()->repaint();} + void showGrid(bool state) { m_showGrid = state; } + void updateViewport() { viewport()->repaint(); } - bool isBalloonPlacing() const {return balloonPlacing; } - void setBalloonPlacing(bool isPlacing) {balloonPlacing = isPlacing;} + bool isBalloonPlacing() const { return balloonPlacing; } + void setBalloonPlacing(bool isPlacing) { balloonPlacing = isPlacing; } - QLabel* getBalloonCursor() const {return balloonCursor;} - void setBalloonCursor(QLabel* label) {balloonCursor = label;} + QLabel* getBalloonCursor() const { return balloonCursor; } + void setBalloonCursor(QLabel* label) { balloonCursor = label; } void kbPanScroll(int xMove = 1, int yMove = 1); - QPointF getBalloonCursorPos() const {return balloonCursorPos;} - void setBalloonCursorPos(QPoint pos) { balloonCursorPos = pos;} + QPointF getBalloonCursorPos() const { return balloonCursorPos; } + void setBalloonCursorPos(QPoint pos) { balloonCursorPos = pos; } void activateCursor(QCursor cursor); void resetCursor(); @@ -115,28 +122,30 @@ public: void centerOnPage(); + TechDraw::DrawView* getBalloonParent() { return m_balloonParent; } + public Q_SLOTS: void setHighQualityAntialiasing(bool highQualityAntialiasing); protected: - void wheelEvent(QWheelEvent *event) override; - void paintEvent(QPaintEvent *event) override; - void enterEvent(QEvent *event) override; - void leaveEvent(QEvent *event) override; - void mousePressEvent(QMouseEvent *event) override; - void mouseMoveEvent(QMouseEvent *event) override; - void mouseReleaseEvent(QMouseEvent *event) override; - void focusOutEvent(QFocusEvent *event) override; - void keyPressEvent(QKeyEvent *event) override; - void keyReleaseEvent(QKeyEvent *event) override; - void contextMenuEvent(QContextMenuEvent *event) override; + void wheelEvent(QWheelEvent* event) override; + void paintEvent(QPaintEvent* event) override; + void enterEvent(QEvent* event) override; + void leaveEvent(QEvent* event) override; + void mousePressEvent(QMouseEvent* event) override; + void mouseMoveEvent(QMouseEvent* event) override; + void mouseReleaseEvent(QMouseEvent* event) override; + void focusOutEvent(QFocusEvent* event) override; + void keyPressEvent(QKeyEvent* event) override; + void keyReleaseEvent(QKeyEvent* event) override; + void contextMenuEvent(QContextMenuEvent* event) override; QColor getBackgroundColor(); double getDevicePixelRatio() const; - QPixmap prepareCursorPixmap(const char *iconName, QPoint &hotspot); + QPixmap prepareCursorPixmap(const char* iconName, QPoint& hotspot); - void drawForeground(QPainter *painter, const QRectF &rect) override; + void drawForeground(QPainter* painter, const QRectF& rect) override; std::string getNavStyleParameter(); Base::Type getStyleType(std::string model); @@ -152,7 +161,7 @@ private: bool drawBkg; QBrush* bkgBrush; QImage m_image; - ViewProviderPage *m_vpPage; + ViewProviderPage* m_vpPage; bool m_atCursor; bool m_invertZoom; @@ -162,9 +171,10 @@ private: QGSPage* m_scene; bool balloonPlacing; - QLabel *balloonCursor; + QLabel* balloonCursor; QPoint balloonCursorPos; QPoint balloonHotspot; + TechDraw::DrawView* m_balloonParent;//temp field. used during balloon placing. QPoint panOrigin; bool panningActive; @@ -184,6 +194,6 @@ private: QContextMenuEvent* m_saveContextEvent; }; -} // namespace +}// namespace TechDrawGui -#endif // TECHDRAWGUI_QGVIEW_H +#endif// TECHDRAWGUI_QGVIEW_H diff --git a/src/Mod/TechDraw/Gui/ViewProviderAnnotation.cpp b/src/Mod/TechDraw/Gui/ViewProviderAnnotation.cpp index f1997f3a61..0f7c9c7e15 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderAnnotation.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderAnnotation.cpp @@ -25,8 +25,12 @@ #include "PreCompiled.h" #include -#include "ViewProviderAnnotation.h" + +#include +#include + #include "QGIView.h" +#include "ViewProviderAnnotation.h" using namespace TechDrawGui; @@ -35,24 +39,16 @@ PROPERTY_SOURCE(TechDrawGui::ViewProviderAnnotation, TechDrawGui::ViewProviderDr //************************************************************************** // Construction/Destruction -ViewProviderAnnotation::ViewProviderAnnotation() -{ - sPixmap = "actions/TechDraw_Annotation"; -} +ViewProviderAnnotation::ViewProviderAnnotation() { sPixmap = "actions/TechDraw_Annotation"; } -ViewProviderAnnotation::~ViewProviderAnnotation() -{ -} +ViewProviderAnnotation::~ViewProviderAnnotation() {} void ViewProviderAnnotation::updateData(const App::Property* prop) { - if (prop == &(getViewObject()->Text) || - prop == &(getViewObject()->Font) || - prop == &(getViewObject()->TextColor) || - prop == &(getViewObject()->TextSize) || - prop == &(getViewObject()->LineSpace) || - prop == &(getViewObject()->TextStyle) || - prop == &(getViewObject()->MaxWidth) ) { + if (prop == &(getViewObject()->Text) || prop == &(getViewObject()->Font) + || prop == &(getViewObject()->TextColor) || prop == &(getViewObject()->TextSize) + || prop == &(getViewObject()->LineSpace) || prop == &(getViewObject()->TextStyle) + || prop == &(getViewObject()->MaxWidth)) { // redraw QGIVP QGIView* qgiv = getQView(); if (qgiv) { @@ -63,6 +59,31 @@ void ViewProviderAnnotation::updateData(const App::Property* prop) ViewProviderDrawingView::updateData(prop); } +std::vector ViewProviderAnnotation::claimChildren() const +{ + // Collect any child Document Objects and put them in the right place in the Feature tree + // valid children of an Annotation are: + // - Balloons + // - Leaders + std::vector temp; + const std::vector& views = getViewObject()->getInList(); + try { + for (std::vector::const_iterator it = views.begin(); + it != views.end(); ++it) { + if ((*it)->getTypeId().isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId())) { + temp.push_back((*it)); + } + else if ((*it)->getTypeId().isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId())) { + temp.push_back((*it)); + } + } + return temp; + } + catch (...) { + return std::vector(); + } +} + TechDraw::DrawViewAnnotation* ViewProviderAnnotation::getViewObject() const { return dynamic_cast(pcObject); diff --git a/src/Mod/TechDraw/Gui/ViewProviderAnnotation.h b/src/Mod/TechDraw/Gui/ViewProviderAnnotation.h index e67446e59e..b32402c6f6 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderAnnotation.h +++ b/src/Mod/TechDraw/Gui/ViewProviderAnnotation.h @@ -31,10 +31,11 @@ #include "ViewProviderDrawingView.h" -namespace TechDrawGui { +namespace TechDrawGui +{ -class TechDrawGuiExport ViewProviderAnnotation : public ViewProviderDrawingView +class TechDrawGuiExport ViewProviderAnnotation: public ViewProviderDrawingView { PROPERTY_HEADER_WITH_OVERRIDE(TechDrawGui::ViewProviderAnnotation); @@ -44,13 +45,15 @@ public: /// destructor ~ViewProviderAnnotation() override; - bool useNewSelectionModel() const override {return false;} + bool useNewSelectionModel() const override { return false; } void updateData(const App::Property*) override; + std::vector claimChildren(void) const override; + TechDraw::DrawViewAnnotation* getViewObject() const override; }; -} // namespace TechDrawGui +}// namespace TechDrawGui -#endif // DRAWINGGUI_VIEWPROVIDERANNOTATION_H +#endif// DRAWINGGUI_VIEWPROVIDERANNOTATION_H