From 9de6ff802a666dff03692fdc5dd41987cb7ed873 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Fri, 8 Feb 2019 19:42:23 -0500 Subject: [PATCH] Restore secondary ortho view movement to v017 style - this should also complete the fix for #3809 --- src/Mod/TechDraw/App/DrawProjGroup.cpp | 18 +++++----- src/Mod/TechDraw/App/DrawProjGroupItem.cpp | 33 ++++++++++------- src/Mod/TechDraw/App/DrawProjGroupItem.h | 2 +- src/Mod/TechDraw/App/DrawView.cpp | 33 ++++++++++------- src/Mod/TechDraw/App/DrawViewCollection.cpp | 1 + src/Mod/TechDraw/Gui/QGIProjGroup.cpp | 31 +++++++--------- src/Mod/TechDraw/Gui/QGIView.cpp | 36 +++++++++++++------ src/Mod/TechDraw/Gui/QGIView.h | 4 +-- .../TechDraw/Gui/ViewProviderDrawingView.cpp | 3 +- .../TechDraw/Gui/ViewProviderProjGroup.cpp | 15 ++++---- 10 files changed, 100 insertions(+), 76 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawProjGroup.cpp b/src/Mod/TechDraw/App/DrawProjGroup.cpp index 865535e82a..d18ae50ca5 100644 --- a/src/Mod/TechDraw/App/DrawProjGroup.cpp +++ b/src/Mod/TechDraw/App/DrawProjGroup.cpp @@ -96,7 +96,6 @@ void DrawProjGroup::onChanged(const App::Property* prop) if (!sourceObjs.empty()) { if (!hasAnchor()) { // if we have a Source, but no Anchor, make an anchor -// Base::Console().Message("TRACE - DPG::onChanged - adding Front\n"); Anchor.setValue(addProjection("Front")); Anchor.purgeTouched(); //don't need to mark this } @@ -133,7 +132,6 @@ void DrawProjGroup::onChanged(const App::Property* prop) Base::Console().Warning("DPG: Projection Groups do not rotate. Change ignored.\n"); } } - } TechDraw::DrawViewCollection::onChanged(prop); @@ -141,6 +139,7 @@ void DrawProjGroup::onChanged(const App::Property* prop) App::DocumentObjectExecReturn *DrawProjGroup::execute(void) { +// Base::Console().Message("DPG::execute()\n"); if (!keepUpdated()) { return App::DocumentObject::StdReturn; } @@ -183,6 +182,7 @@ short DrawProjGroup::mustExecute() const ProjectionType.isTouched() || Anchor.isTouched() || AutoDistribute.isTouched() || + LockPosition.isTouched()|| spacingX.isTouched() || spacingY.isTouched(); } @@ -324,7 +324,6 @@ DrawProjGroupItem* DrawProjGroup::getProjItem(const char *viewProjType) const return result; } - bool DrawProjGroup::checkViewProjType(const char *in) { if ( strcmp(in, "Front") == 0 || @@ -379,12 +378,13 @@ App::DocumentObject * DrawProjGroup::addProjection(const char *viewProjType) } else { //Front view->LockPosition.setValue(true); //lock "Front" position within DPG (note not Page!). view->LockPosition.setStatus(App::Property::ReadOnly,true); //Front should stay locked. + App::GetApplication().signalChangePropertyEditor(view->LockPosition); + view->LockPosition.purgeTouched(); + requestPaint(); } addView(view); //from DrawViewCollection - if (view != getAnchor()) { //anchor is done elsewhere - view->recomputeFeature(); - } + requestPaint(); } return view; @@ -521,7 +521,8 @@ Base::Vector3d DrawProjGroup::getXYPosition(const char *viewTypeCStr) //TODO: bounding boxes do not take view orientation into account // ie X&Y widths might be swapped on page - if (AutoDistribute.getValue()) { +// if (AutoDistribute.getValue()) { + if (true) { std::vector position(idxCount); int idx = 0; for (;idx < idxCount; idx++) { @@ -627,7 +628,6 @@ Base::Vector3d DrawProjGroup::getXYPosition(const char *viewTypeCStr) return result; } - int DrawProjGroup::getViewIndex(const char *viewTypeCStr) const { int result = 4; //default to front view's position @@ -848,7 +848,6 @@ TechDraw::DrawProjGroupItem* DrawProjGroup::getAnchor(void) return result; } - void DrawProjGroup::setAnchorDirection(const Base::Vector3d dir) { App::DocumentObject* docObj = Anchor.getValue(); @@ -869,7 +868,6 @@ Base::Vector3d DrawProjGroup::getAnchorDirection(void) return result; } - //************************************* //* view direction manipulation routines //************************************* diff --git a/src/Mod/TechDraw/App/DrawProjGroupItem.cpp b/src/Mod/TechDraw/App/DrawProjGroupItem.cpp index c785739371..9d787e70b7 100644 --- a/src/Mod/TechDraw/App/DrawProjGroupItem.cpp +++ b/src/Mod/TechDraw/App/DrawProjGroupItem.cpp @@ -102,6 +102,9 @@ void DrawProjGroupItem::onChanged(const App::Property *prop) bool DrawProjGroupItem::isLocked(void) const { bool isLocked = DrawView::isLocked(); + if (isAnchor()) { //Anchor view is always locked to DPG + return true; + } DrawProjGroup* parent = getPGroup(); if (parent != nullptr) { isLocked = isLocked || parent->LockPosition.getValue(); @@ -117,26 +120,32 @@ App::DocumentObjectExecReturn *DrawProjGroupItem::execute(void) } App::DocumentObjectExecReturn * ret = DrawViewPart::execute(); - delete ret; - - autoPosition(); - requestPaint(); + if (ret != nullptr) { + return ret; + } else { + autoPosition(); + requestPaint(); + delete ret; + } return App::DocumentObject::StdReturn; } void DrawProjGroupItem::autoPosition() { +// Base::Console().Message("DPGI::autoPosition(%s)\n",getNameInDocument()); auto pgroup = getPGroup(); Base::Vector3d newPos; - if ((pgroup != nullptr) && - (pgroup->AutoDistribute.getValue()) && - (!LockPosition.getValue())) { - newPos = pgroup->getXYPosition(Type.getValueAsString()); - X.setValue(newPos.x); - Y.setValue(newPos.y); + if (pgroup != nullptr) { + if (pgroup->AutoDistribute.getValue()) { + if (!LockPosition.getValue()) { + newPos = pgroup->getXYPosition(Type.getValueAsString()); + X.setValue(newPos.x); + Y.setValue(newPos.y); + } + } } requestPaint(); - purgeTouched(); + purgeTouched(); //prevents "still touched after recompute" message } void DrawProjGroupItem::onDocumentRestored() @@ -160,7 +169,7 @@ DrawProjGroup* DrawProjGroupItem::getPGroup() const return result; } -bool DrawProjGroupItem::isAnchor(void) +bool DrawProjGroupItem::isAnchor(void) const { bool result = false; auto group = getPGroup(); diff --git a/src/Mod/TechDraw/App/DrawProjGroupItem.h b/src/Mod/TechDraw/App/DrawProjGroupItem.h index 38c30e7624..4e3966ac56 100644 --- a/src/Mod/TechDraw/App/DrawProjGroupItem.h +++ b/src/Mod/TechDraw/App/DrawProjGroupItem.h @@ -78,7 +78,7 @@ public: virtual double getScale(void) const override; void autoPosition(void); - bool isAnchor(void); + bool isAnchor(void) const; protected: diff --git a/src/Mod/TechDraw/App/DrawView.cpp b/src/Mod/TechDraw/App/DrawView.cpp index ff1c951892..7b1e363ea9 100644 --- a/src/Mod/TechDraw/App/DrawView.cpp +++ b/src/Mod/TechDraw/App/DrawView.cpp @@ -141,6 +141,8 @@ void DrawView::onChanged(const App::Property* prop) } } else if (prop == &LockPosition) { handleXYLock(); + LockPosition.purgeTouched(); + requestPaint(); } } App::DocumentObject::onChanged(prop); @@ -159,21 +161,27 @@ void DrawView::handleXYLock(void) X.setStatus(App::Property::ReadOnly,true); App::GetApplication().signalChangePropertyEditor(X); X.purgeTouched(); + requestPaint(); + } + if (!Y.testStatus(App::Property::ReadOnly)) { + Y.setStatus(App::Property::ReadOnly,true); + App::GetApplication().signalChangePropertyEditor(Y); + Y.purgeTouched(); + requestPaint(); } - Y.setStatus(App::Property::ReadOnly,true); - App::GetApplication().signalChangePropertyEditor(Y); - Y.purgeTouched(); - requestPaint(); } else { if (X.testStatus(App::Property::ReadOnly)) { X.setStatus(App::Property::ReadOnly,false); App::GetApplication().signalChangePropertyEditor(X); X.purgeTouched(); + requestPaint(); + } + if (Y.testStatus(App::Property::ReadOnly)) { + Y.setStatus(App::Property::ReadOnly,false); + App::GetApplication().signalChangePropertyEditor(Y); + Y.purgeTouched(); + requestPaint(); } - Y.setStatus(App::Property::ReadOnly,false); - App::GetApplication().signalChangePropertyEditor(Y); - Y.purgeTouched(); - requestPaint(); } } @@ -182,11 +190,9 @@ short DrawView::mustExecute() const short result = 0; if (!isRestoring()) { result = (Scale.isTouched() || - ScaleType.isTouched() ); - if (!isLocked()) { - result = result || X.isTouched() || - Y.isTouched() ; - } + ScaleType.isTouched() || + X.isTouched() || + Y.isTouched() ); } if ((bool) result) { return result; @@ -287,6 +293,7 @@ bool DrawView::checkFit(TechDraw::DrawPage* p) const void DrawView::setPosition(double x, double y) { +// Base::Console().Message("DV::setPosition(%.3f,%.3f) - \n",x,y,getNameInDocument()); if (!isLocked()) { X.setValue(x); Y.setValue(y); diff --git a/src/Mod/TechDraw/App/DrawViewCollection.cpp b/src/Mod/TechDraw/App/DrawViewCollection.cpp index 0dcedd2f75..f23409cd48 100644 --- a/src/Mod/TechDraw/App/DrawViewCollection.cpp +++ b/src/Mod/TechDraw/App/DrawViewCollection.cpp @@ -157,6 +157,7 @@ void DrawViewCollection::onDocumentRestored() void DrawViewCollection::lockChildren(void) { +// Base::Console().Message("DVC::lockChildren()\n"); for (auto& v:Views.getValues()) { TechDraw::DrawView *view = dynamic_cast(v); if (!view) { diff --git a/src/Mod/TechDraw/Gui/QGIProjGroup.cpp b/src/Mod/TechDraw/Gui/QGIProjGroup.cpp index 69a74b38be..936545ce52 100644 --- a/src/Mod/TechDraw/Gui/QGIProjGroup.cpp +++ b/src/Mod/TechDraw/Gui/QGIProjGroup.cpp @@ -42,6 +42,7 @@ #include #include "Rez.h" +#include "DrawGuiUtil.h" #include "QGIProjGroup.h" using namespace TechDrawGui; @@ -63,7 +64,6 @@ QGIProjGroup::QGIProjGroup() borderVisible = false; } - TechDraw::DrawProjGroup * QGIProjGroup::getDrawView(void) const { App::DocumentObject *obj = getViewObject(); @@ -118,12 +118,8 @@ QVariant QGIProjGroup::itemChange(GraphicsItemChange change, const QVariant &val if (type == QString::fromLatin1("Front")) { gView->setLocked(true); //this locks in GUI only - fView->LockPosition.setValue(true); //lock in App also + gView->alignTo(m_origin, QString::fromLatin1("None")); installSceneEventFilter(gView); - App::DocumentObject *docObj = getViewObject(); - TechDraw::DrawProjGroup *projectionGroup = dynamic_cast(docObj); - projectionGroup->Anchor.setValue(fView); - updateView(); } else if ( type == QString::fromLatin1("Top") || type == QString::fromLatin1("Bottom")) { gView->alignTo(m_origin, QString::fromLatin1("Vertical")); @@ -131,7 +127,13 @@ QVariant QGIProjGroup::itemChange(GraphicsItemChange change, const QVariant &val type == QString::fromLatin1("Right") || type == QString::fromLatin1("Rear") ) { gView->alignTo(m_origin, QString::fromLatin1("Horizontal")); - } + } else if ( type == QString::fromLatin1("FrontTopRight") || + type == QString::fromLatin1("FrontBottomLeft") ) { + gView->alignTo(m_origin, QString::fromLatin1("45slash")); + } else if ( type == QString::fromLatin1("FrontTopLeft") || + type == QString::fromLatin1("FrontBottomRight") ) { + gView->alignTo(m_origin, QString::fromLatin1("45backslash")); + } } } } @@ -168,24 +170,17 @@ void QGIProjGroup::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) QGIView *qAnchor = getAnchorQItem(); if((mousePos - event->screenPos()).manhattanLength() < 5) { if(qAnchor && qAnchor->shape().contains(event->pos())) { - qAnchor->mouseReleaseEvent(event); + event->ignore(); + qAnchor->mouseReleaseEvent(event); } - } else if(scene() && qAnchor && (qAnchor == scene()->mouseGrabberItem())) { + } else if(scene() && qAnchor) { // End of Drag - Gui::Command::openCommand("Drag Projection Group"); - //TODO: See if these commands actually handle the horizontal/vertical constraints properly... - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.X = %f", - getViewName(), Rez::appX(x())); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Y = %f", - getViewName(), Rez::appX(getY()));// inverts Y - Gui::Command::commitCommand(); - //Gui::Command::updateActive(); + getViewObject()->setPosition(Rez::appX(x()),Rez::appX(getY())); } } QGIViewCollection::mouseReleaseEvent(event); } - QGIView * QGIProjGroup::getAnchorQItem() const { // Get the currently assigned anchor view diff --git a/src/Mod/TechDraw/Gui/QGIView.cpp b/src/Mod/TechDraw/Gui/QGIView.cpp index 26cbc8f192..ce991a6172 100644 --- a/src/Mod/TechDraw/Gui/QGIView.cpp +++ b/src/Mod/TechDraw/Gui/QGIView.cpp @@ -78,7 +78,7 @@ const float labelCaptionFudge = 0.2f; // temp fiddle for devel QGIView::QGIView() :QGraphicsItemGroup(), viewObj(nullptr), - locked(false), + m_locked(false), borderVisible(true), m_innerView(false) { @@ -120,12 +120,13 @@ void QGIView::alignTo(QGraphicsItem*item, const QString &alignment) QVariant QGIView::itemChange(GraphicsItemChange change, const QVariant &value) { QPointF newPos(0.0,0.0); -// if(change == ItemPositionChange && scene()) { - if(change == ItemPositionHasChanged && scene()) { + if(change == ItemPositionChange && scene()) { +// if(change == ItemPositionHasChanged && scene()) { newPos = value.toPointF(); //position within parent! - if(locked){ + if(m_locked){ newPos.setX(pos().x()); newPos.setY(pos().y()); + return newPos; } // TODO find a better data structure for this @@ -133,14 +134,30 @@ QVariant QGIView::itemChange(GraphicsItemChange change, const QVariant &value) if (getViewObject()->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) { TechDraw::DrawProjGroupItem* dpgi = static_cast(getViewObject()); TechDraw::DrawProjGroup* dpg = dpgi->getPGroup(); - if ((dpg != nullptr) && dpg->AutoDistribute.getValue()) { + if (dpg != nullptr) { if(alignHash.size() == 1) { //if aligned. - QGraphicsItem*item = alignHash.begin().value(); + QGraphicsItem* item = alignHash.begin().value(); QString alignMode = alignHash.begin().key(); if(alignMode == QString::fromLatin1("Vertical")) { newPos.setX(item->pos().x()); } else if(alignMode == QString::fromLatin1("Horizontal")) { newPos.setY(item->pos().y()); + } else if(alignMode == QString::fromLatin1("45slash")) { + //this logic is wrong since the constained movement direction is not necessarily 45* + Base::Console().Message("QGIV::itemChange - oblique BL-TR\n"); +// double dist = ( (newPos.x() - item->pos().x()) + +// (item->pos().y() - newPos.y()) ) / 2.0; + +// newPos.setX( item->pos().x() + dist); +// newPos.setY( item->pos().y() - dist ); + } else if(alignMode == QString::fromLatin1("45backslash")) { + //this logic is wrong since the constained movement direction is not necessarily 45* + Base::Console().Message("QGIV::itemChange - oblique TL-BR\n"); +// double dist = ( (newPos.x() - item->pos().x()) + +// (newPos.y() - item->pos().y()) ) / 2.0; + +// newPos.setX( item->pos().x() + dist); +// newPos.setY( item->pos().y() + dist ); } } } @@ -162,7 +179,7 @@ QVariant QGIView::itemChange(GraphicsItemChange change, const QVariant &value) void QGIView::mousePressEvent(QGraphicsSceneMouseEvent * event) { - if(locked) { + if(m_locked) { event->ignore(); } else { QGraphicsItem::mousePressEvent(event); @@ -176,7 +193,7 @@ void QGIView::mouseMoveEvent(QGraphicsSceneMouseEvent * event) void QGIView::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) { - if(!locked && isSelected()) { + if(!m_locked) { if (!isInnerView()) { double tempX = x(), tempY = getY(); @@ -255,10 +272,9 @@ QGIViewClip* QGIView::getClipGroup(void) return result; } - void QGIView::updateView(bool update) { - if (getViewObject()->LockPosition.getValue()) { + if (getViewObject()->isLocked()) { setFlag(QGraphicsItem::ItemIsMovable, false); } else { setFlag(QGraphicsItem::ItemIsMovable, true); diff --git a/src/Mod/TechDraw/Gui/QGIView.h b/src/Mod/TechDraw/Gui/QGIView.h index 5557dab002..3210a08479 100644 --- a/src/Mod/TechDraw/Gui/QGIView.h +++ b/src/Mod/TechDraw/Gui/QGIView.h @@ -92,7 +92,7 @@ public: void alignTo(QGraphicsItem*, const QString &alignment); - void setLocked(bool /*state*/ = true) { locked = true; } + void setLocked(bool b) { m_locked = b; } virtual QColor getNormalColor(void); virtual QColor getPreColor(void); @@ -124,7 +124,7 @@ protected: QHash alignHash; //std::string alignMode; //QGIView* alignAnchor; - bool locked; + bool m_locked; bool borderVisible; bool m_visibility; bool m_innerView; //View is inside another View diff --git a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp index 32fe47afe8..328a7a980e 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp @@ -66,7 +66,8 @@ ViewProviderDrawingView::ViewProviderDrawingView() ADD_PROPERTY_TYPE(KeepLabel ,(false),group,App::Prop_None,"Keep Label on Page even if toggled off"); - // Do not show in property editor why? wf + // Do not show in property editor why? wf WF: because DisplayMode applies only to coin and we + // don't use coin. DisplayMode.setStatus(App::Property::ReadOnly,true); m_docReady = true; } diff --git a/src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp b/src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp index 1ed0ddc2cd..7e1364ce85 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp @@ -89,19 +89,16 @@ std::vector ViewProviderProjGroup::getDisplayModes(void) const void ViewProviderProjGroup::updateData(const App::Property* prop) { - Gui::ViewProviderDocumentObject::updateData(prop); + ViewProviderDrawingView::updateData(prop); if(prop == &(getObject()->Scale) || prop == &(getObject()->ScaleType) || prop == &(getObject()->Views) || - prop == &(getObject()->ProjectionType)) { - - Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); - TaskDlgProjGroup *projDlg = qobject_cast(dlg); - - if (projDlg && - projDlg->getViewProvider() == dynamic_cast(getObject()) ) { - projDlg->update(); + prop == &(getObject()->ProjectionType) || + prop == &(getObject()->LockPosition) ) { + QGIView* qgiv = getQView(); + if (qgiv) { + qgiv->updateView(true); } }