diff --git a/src/Mod/TechDraw/App/DrawView.cpp b/src/Mod/TechDraw/App/DrawView.cpp index 4e7d0e7c6f..930b454956 100644 --- a/src/Mod/TechDraw/App/DrawView.cpp +++ b/src/Mod/TechDraw/App/DrawView.cpp @@ -92,6 +92,7 @@ DrawView::~DrawView() App::DocumentObjectExecReturn *DrawView::execute(void) { + requestPaint(); return App::DocumentObject::StdReturn; //DO::execute returns 0 } @@ -137,13 +138,12 @@ void DrawView::onChanged(const App::Property* prop) Scale.purgeTouched(); } } - } -// } - } - if (prop == &X || //nothing needs to be calculated, just the graphic needs to be shifted. - prop == &Y) { - requestPaint(); + } } +// if (prop == &X || //nothing needs to be calculated, just the graphic needs to be shifted. +// prop == &Y) { +// requestPaint(); +// } } App::DocumentObject::onChanged(prop); } @@ -153,7 +153,9 @@ short DrawView::mustExecute() const short result = 0; if (!isRestoring()) { result = (Scale.isTouched() || - ScaleType.isTouched() ); + ScaleType.isTouched() || + X.isTouched() || + Y.isTouched() ); } if ((bool) result) { return result; @@ -207,6 +209,23 @@ bool DrawView::isInClip() return false; } +DrawViewClip* DrawView::getClipGroup(void) +{ + std::vector parent = getInList(); + App::DocumentObject* obj = nullptr; + DrawViewClip* result = nullptr; + for (std::vector::iterator it = parent.begin(); it != parent.end(); ++it) { + if ((*it)->getTypeId().isDerivedFrom(DrawViewClip::getClassTypeId())) { + obj = (*it); + result = dynamic_cast(obj); + break; + + } + } + return result; +} + + double DrawView::autoScale(double w, double h) const { double fudgeFactor = 0.90; diff --git a/src/Mod/TechDraw/App/DrawView.h b/src/Mod/TechDraw/App/DrawView.h index 0d389b6030..c615984298 100644 --- a/src/Mod/TechDraw/App/DrawView.h +++ b/src/Mod/TechDraw/App/DrawView.h @@ -36,6 +36,7 @@ namespace TechDraw { class DrawPage; +class DrawViewClip; /** Base class of all View Features in the drawing module */ @@ -67,6 +68,7 @@ public: void Restore(Base::XMLReader &reader) override; bool isInClip(); + DrawViewClip* getClipGroup(void); /// returns the type name of the ViewProvider virtual const char* getViewProviderName(void) const override { diff --git a/src/Mod/TechDraw/App/DrawViewClip.cpp b/src/Mod/TechDraw/App/DrawViewClip.cpp index 4b72116e2d..cf2a74cd43 100644 --- a/src/Mod/TechDraw/App/DrawViewClip.cpp +++ b/src/Mod/TechDraw/App/DrawViewClip.cpp @@ -78,8 +78,8 @@ void DrawViewClip::addView(DrawView *view) std::vector newViews(currViews); newViews.push_back(view); Views.setValues(newViews); - view->X.setValue(Width.getValue()/2.0); - view->Y.setValue(Height.getValue()/2.0); + view->X.setValue(0.0); //position in centre of clip group frame + view->Y.setValue(0.0); auto page = findParentPage(); //get Page to release child relationship in tree page->Views.touch(); } diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index d5e44de011..2a9fed5130 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -778,14 +778,9 @@ void CmdTechDrawClipPlus::activated(int iMsg) std::string ClipName = clip->getNameInDocument(); std::string ViewName = view->getNameInDocument(); - double newX = clip->Width.getValue() / 2.0; - double newY = clip->Height.getValue() / 2.0; - openCommand("ClipPlus"); doCommand(Doc,"App.activeDocument().%s.ViewObject.Visibility = False",ViewName.c_str()); doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",ClipName.c_str(),ViewName.c_str()); - doCommand(Doc,"App.activeDocument().%s.X = %.3f",ViewName.c_str(),newX); - doCommand(Doc,"App.activeDocument().%s.Y = %.3f",ViewName.c_str(),newY); doCommand(Doc,"App.activeDocument().%s.ViewObject.Visibility = True",ViewName.c_str()); updateActive(); commitCommand(); diff --git a/src/Mod/TechDraw/Gui/QGCustomClip.cpp b/src/Mod/TechDraw/Gui/QGCustomClip.cpp index 81cc055897..bb3ffb7932 100644 --- a/src/Mod/TechDraw/Gui/QGCustomClip.cpp +++ b/src/Mod/TechDraw/Gui/QGCustomClip.cpp @@ -35,6 +35,8 @@ #include #include +#include "ZVALUE.h" +#include "QGICMark.h" #include "QGCustomClip.h" using namespace TechDrawGui; @@ -47,6 +49,7 @@ QGCustomClip::QGCustomClip() setFlag(QGraphicsItem::ItemIsSelectable, false); setFlag(QGraphicsItem::ItemIsMovable, false); setFlag(QGraphicsItem::ItemClipsChildrenToShape, true); +// setFlag(QGraphicsItem::ItemClipsChildrenToShape, false); //good for debugging m_rect = QRectF(0.,0.,10.,10.); } @@ -96,3 +99,19 @@ QRectF QGCustomClip::boundingRect() const //sb shape()? return m_rect; } +void QGCustomClip::makeMark(double x, double y) +{ + QGICMark* cmItem = new QGICMark(-1); + cmItem->setParentItem(this); + cmItem->setPos(x,y); + cmItem->setThick(1.0); + cmItem->setSize(40.0); + cmItem->setZValue(ZVALUE::VERTEX); +} + +void QGCustomClip::makeMark(Base::Vector3d v) +{ + makeMark(v.x,v.y); +} + + diff --git a/src/Mod/TechDraw/Gui/QGCustomClip.h b/src/Mod/TechDraw/Gui/QGCustomClip.h index b35c536863..ab3fb5e3bc 100644 --- a/src/Mod/TechDraw/Gui/QGCustomClip.h +++ b/src/Mod/TechDraw/Gui/QGCustomClip.h @@ -27,6 +27,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE class QPainter; class QStyleOptionGraphicsItem; @@ -51,7 +53,8 @@ public: virtual void setRect(QRectF r); virtual void setRect(double x, double y, double w, double h); virtual QRectF rect(); - + void makeMark(double x, double y); + void makeMark(Base::Vector3d v); protected: diff --git a/src/Mod/TechDraw/Gui/QGIView.cpp b/src/Mod/TechDraw/Gui/QGIView.cpp index af747d747b..26cbc8f192 100644 --- a/src/Mod/TechDraw/Gui/QGIView.cpp +++ b/src/Mod/TechDraw/Gui/QGIView.cpp @@ -51,6 +51,7 @@ #include "Rez.h" #include "ZVALUE.h" +#include "DrawGuiUtil.h" #include "QGCustomBorder.h" #include "QGCustomLabel.h" #include "QGIView.h" @@ -67,6 +68,7 @@ #include #include #include +#include using namespace TechDrawGui; @@ -118,12 +120,14 @@ 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()) { - newPos = value.toPointF(); +// if(change == ItemPositionChange && scene()) { + if(change == ItemPositionHasChanged && scene()) { + newPos = value.toPointF(); //position within parent! if(locked){ newPos.setX(pos().x()); newPos.setY(pos().y()); } + // TODO find a better data structure for this // this is just a pair isn't it? if (getViewObject()->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) { @@ -209,31 +213,49 @@ void QGIView::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void QGIView::setPosition(qreal x, qreal y) { + double newX = x; + double newY; + double oldX = pos().x(); + double oldY = pos().y(); if (!isInnerView()) { - setPos(x,-y); //position on page + newY = -y; } else { - setPos(x,getYInClip(y)); //position in Clip + newY = getYInClip(y); + } + if ( (TechDraw::DrawUtil::fpCompare(newX,oldX)) && + (TechDraw::DrawUtil::fpCompare(newY,oldY)) ) { + return; + } else { + setPos(newX,newY); } } +//is this needed anymore??? double QGIView::getYInClip(double y) { + return -y; +} + +QGIViewClip* QGIView::getClipGroup(void) +{ + if (!getViewObject()->isInClip()) { + Base::Console().Log( "Logic Error - getClipGroup called for child " + "(%s) not in Clip\n", getViewName() ); + return nullptr; + } + + QGIViewClip* result = nullptr; auto parentClip( dynamic_cast( parentItem() ) ); if (parentClip) { auto parentView( dynamic_cast( parentClip->parentItem() ) ); if (parentView) { - auto parentFeat( dynamic_cast(parentView->getViewObject()) ); - if (parentFeat) { - return Rez::guiX(parentFeat->Height.getValue()) - y; - } + result = parentView; } } - - Base::Console().Log( "Logic Error - getYInClip called for child " - "(%s) not in Clip\n", getViewName() ); - return 0; + return result; } + void QGIView::updateView(bool update) { if (getViewObject()->LockPosition.getValue()) { @@ -242,7 +264,7 @@ void QGIView::updateView(bool update) setFlag(QGraphicsItem::ItemIsMovable, true); } - if (getViewObject()->X.isTouched() || + if (getViewObject()->X.isTouched() || //change in feat position getViewObject()->Y.isTouched()) { double featX = Rez::guiX(getViewObject()->X.getValue()); double featY = Rez::guiX(getViewObject()->Y.getValue()); diff --git a/src/Mod/TechDraw/Gui/QGIView.h b/src/Mod/TechDraw/Gui/QGIView.h index 07966744a9..e005916755 100644 --- a/src/Mod/TechDraw/Gui/QGIView.h +++ b/src/Mod/TechDraw/Gui/QGIView.h @@ -47,6 +47,7 @@ class QGCustomLabel; class QGCustomText; class QGICaption; class MDIViewPage; +class QGIViewClip; class TechDrawGuiExport QGIView : public QGraphicsItemGroup { @@ -88,6 +89,8 @@ public: void isInnerView(bool state) { m_innerView = state; } double getYInClip(double y); /** @} */ + QGIViewClip* getClipGroup(void); + void alignTo(QGraphicsItem*, const QString &alignment); void setLocked(bool /*state*/ = true) { locked = true; } diff --git a/src/Mod/TechDraw/Gui/QGIViewClip.cpp b/src/Mod/TechDraw/Gui/QGIViewClip.cpp index 6978d7c97e..79c954ebbf 100644 --- a/src/Mod/TechDraw/Gui/QGIViewClip.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewClip.cpp @@ -37,6 +37,7 @@ #include "Rez.h" #include "QGCustomRect.h" #include "QGCustomClip.h" +#include "DrawGuiUtil.h" #include "QGIViewClip.h" using namespace TechDrawGui; @@ -109,8 +110,8 @@ void QGIViewClip::drawClip() prepareGeometryChange(); double h = viewClip->Height.getValue(); double w = viewClip->Width.getValue(); - QRectF r = QRectF(0,0,Rez::guiX(w),Rez::guiX(h)); - m_frame->setRect(r); + QRectF r = QRectF(-Rez::guiX(w)/2.0,-Rez::guiX(h)/2.0,Rez::guiX(w),Rez::guiX(h)); + m_frame->setRect(r); // (-50,-50) -> (50,50) m_frame->setPos(0.,0.); if (viewClip->ShowFrame.getValue()) { m_frame->show(); @@ -118,8 +119,13 @@ void QGIViewClip::drawClip() m_frame->hide(); } - m_cliparea->setRect(r.adjusted(-1,-1,1,1)); //TODO: clip just outside frame or just inside?? + //probably a slicker way to do this? + QPointF midFrame = m_frame->boundingRect().center(); + QPointF midMapped = mapFromItem(m_frame,midFrame); + QPointF clipOrigin = mapToItem(m_cliparea,midMapped); + m_cliparea->setRect(r.adjusted(-1,-1,1,1)); + std::vector childNames = viewClip->getChildViewNames(); //for all child Views in Clip, add the graphics representation of the View to the Clip group for(std::vector::iterator it = childNames.begin(); it != childNames.end(); it++) { @@ -131,9 +137,9 @@ void QGIViewClip::drawClip() scene()->removeItem(qgiv); m_cliparea->addToGroup(qgiv); qgiv->isInnerView(true); - double x = qgiv->getViewObject()->X.getValue(); - double y = qgiv->getViewObject()->Y.getValue(); - qgiv->setPosition(Rez::guiX(x),Rez::guiX(y)); + double x = Rez::guiX(qgiv->getViewObject()->X.getValue()); + double y = Rez::guiX(qgiv->getViewObject()->Y.getValue()); + qgiv->setPosition(clipOrigin.x() + x, clipOrigin.y() + y); if (viewClip->ShowLabels.getValue()) { qgiv->toggleBorder(true); } else { diff --git a/src/Mod/TechDraw/Gui/QGIViewClip.h b/src/Mod/TechDraw/Gui/QGIViewClip.h index 8b64d27295..4a9a9ab95f 100644 --- a/src/Mod/TechDraw/Gui/QGIViewClip.h +++ b/src/Mod/TechDraw/Gui/QGIViewClip.h @@ -46,6 +46,8 @@ public: virtual void updateView(bool update = false) override; virtual void draw() override; + QGCustomRect* getFrame(void) {return m_frame;} + QGCustomClip* getClipArea(void) {return m_cliparea;} protected: void drawClip(); diff --git a/src/Mod/TechDraw/Gui/ViewProviderViewClip.cpp b/src/Mod/TechDraw/Gui/ViewProviderViewClip.cpp index 06e84224b1..14e34732fb 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderViewClip.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderViewClip.cpp @@ -59,18 +59,6 @@ ViewProviderViewClip::~ViewProviderViewClip() void ViewProviderViewClip::updateData(const App::Property* prop) { - //Base::Console().Log("ViewProviderViewClip::updateData - Update View: %s\n",prop->getName()); - if (prop == &(getViewObject()->Height) || - prop == &(getViewObject()->Width) || - prop == &(getViewObject()->ShowFrame) || - prop == &(getViewObject()->ShowLabels) || - prop == &(getViewObject()->Views) ) { - // redraw QGIVP - QGIView* qgiv = getQView(); - if (qgiv) { - qgiv->updateView(true); - } - } ViewProviderDrawingView::updateData(prop); }