Fix View position in ClipGroup

This commit is contained in:
wandererfan
2018-11-17 09:29:55 -05:00
committed by wmayer
parent 7909ce83f9
commit ddfa510565
11 changed files with 105 additions and 46 deletions

View File

@@ -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<App::DocumentObject*> parent = getInList();
App::DocumentObject* obj = nullptr;
DrawViewClip* result = nullptr;
for (std::vector<App::DocumentObject*>::iterator it = parent.begin(); it != parent.end(); ++it) {
if ((*it)->getTypeId().isDerivedFrom(DrawViewClip::getClassTypeId())) {
obj = (*it);
result = dynamic_cast<DrawViewClip*>(obj);
break;
}
}
return result;
}
double DrawView::autoScale(double w, double h) const
{
double fudgeFactor = 0.90;

View File

@@ -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 {

View File

@@ -78,8 +78,8 @@ void DrawViewClip::addView(DrawView *view)
std::vector<App::DocumentObject *> 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();
}

View File

@@ -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();

View File

@@ -35,6 +35,8 @@
#include <Base/Console.h>
#include <Base/Parameter.h>
#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);
}

View File

@@ -27,6 +27,8 @@
#include <QPointF>
#include <QRectF>
#include <Base/Vector3D.h>
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:

View File

@@ -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 <Mod/TechDraw/App/DrawViewClip.h>
#include <Mod/TechDraw/App/DrawProjGroup.h>
#include <Mod/TechDraw/App/DrawProjGroupItem.h>
#include <Mod/TechDraw/App/DrawUtil.h>
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<QGCustomClip*>( parentItem() ) );
if (parentClip) {
auto parentView( dynamic_cast<QGIViewClip*>( parentClip->parentItem() ) );
if (parentView) {
auto parentFeat( dynamic_cast<TechDraw::DrawViewClip*>(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());

View File

@@ -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; }

View File

@@ -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<std::string> childNames = viewClip->getChildViewNames();
//for all child Views in Clip, add the graphics representation of the View to the Clip group
for(std::vector<std::string>::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 {

View File

@@ -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();

View File

@@ -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);
}