Skip to content

Commit

Permalink
Fix movement of Front View in ProjectionGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan authored and wwmayer committed Jan 21, 2019
1 parent 99c47b9 commit 90fd3ae
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 42 deletions.
37 changes: 9 additions & 28 deletions src/Mod/TechDraw/App/DrawProjGroup.cpp
Expand Up @@ -204,13 +204,6 @@ Base::BoundBox3d DrawProjGroup::getBoundingBox() const
bbox.Add(bb);
}
}
// This /should/ leave the centre of the bounding box at (0,0) except when
// we're in the process of updating the anchor view's position (eg called
// by moveToCentre())
if (anchorView) { //TODO: It looks like we might be getting called before an anchor view is set - weird...
bbox.MoveX(anchorView->X.getValue());
bbox.MoveY(anchorView->Y.getValue());
}
return bbox;
}

Expand Down Expand Up @@ -302,18 +295,6 @@ void DrawProjGroup::minimumBbViews(DrawProjGroupItem *viewPtrs[10],
height = row0h + row1h + row2h;
}


void DrawProjGroup::moveToCentre(void)
{
// Update the anchor view's X and Y to keep the bounding box centred on the origin
Base::BoundBox3d tempbbox = getBoundingBox();
DrawProjGroupItem *anchorView = dynamic_cast<DrawProjGroupItem *>(Anchor.getValue());
if (anchorView) {
anchorView->X.setValue((tempbbox.MinX + tempbbox.MaxX) / -2.0);
anchorView->Y.setValue((tempbbox.MinY + tempbbox.MaxY) / -2.0);
}
}

App::DocumentObject * DrawProjGroup::getProjObj(const char *viewProjType) const
{
for( auto it : Views.getValues() ) {
Expand Down Expand Up @@ -382,14 +363,16 @@ App::DocumentObject * DrawProjGroup::addProjection(const char *viewProjType)
view->Type.setValue( viewProjType );
view->Label.setValue( viewProjType );
view->Source.setValues( Source.getValues() );
if (strcmp(viewProjType, "Front") != 0 ) {
if (strcmp(viewProjType, "Front") != 0 ) { //not Front!
vecs = getDirsFromFront(view);
view->Direction.setValue(vecs.first);
view->RotationVector.setValue(vecs.second);
} 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.
}

addView(view); //from DrawViewCollection
moveToCentre();
if (view != getAnchor()) { //anchor is done elsewhere
view->recomputeFeature();
}
Expand All @@ -414,7 +397,6 @@ int DrawProjGroup::removeProjection(const char *viewProjType)
if ( strcmp(viewProjType, projPtr->Type.getValueAsString()) == 0 ) {
removeView(projPtr); // Remove from collection
getDocument()->removeObject( it->getNameInDocument() ); // Remove from the document
moveToCentre();
return Views.getValues().size();
}
}
Expand Down Expand Up @@ -517,7 +499,11 @@ std::pair<Base::Vector3d,Base::Vector3d> DrawProjGroup::getDirsFromFront(std::st

Base::Vector3d DrawProjGroup::getXYPosition(const char *viewTypeCStr)
{
Base::Vector3d result;
Base::Vector3d result(0.0,0.0,0.0);
//Front view position is always (0,0)
if (strcmp(viewTypeCStr, "Front") == 0 ) { // Front!
return result;
}
const int idxCount = 10;
DrawProjGroupItem *viewPtrs[idxCount];
arrangeViewPointers(viewPtrs);
Expand Down Expand Up @@ -779,11 +765,6 @@ void DrawProjGroup::updateChildren(void)
}
}

//void DrawProjGroup::updateChildren(const App::Property* prop)
//{
// view->....setValue(s)(prop->getValue(s));
//}

/*!
* tell children DPGIs that parent DPG has changed Source
*/
Expand Down
3 changes: 0 additions & 3 deletions src/Mod/TechDraw/App/DrawProjGroup.h
Expand Up @@ -130,9 +130,6 @@ class TechDrawExport DrawProjGroup : public TechDraw::DrawViewCollection
protected:
void onChanged(const App::Property* prop) override;

//! Moves anchor view to keep our bounding box centre on the origin
void moveToCentre();

/// Annoying helper - keep in sync with DrawProjGroupItem::TypeEnums
/*!
* \todo {See note regarding App::PropertyEnumeration on my wiki page http://freecadweb.org/wiki/User:Ian.rees}
Expand Down
4 changes: 0 additions & 4 deletions src/Mod/TechDraw/App/DrawView.cpp
Expand Up @@ -140,10 +140,6 @@ void DrawView::onChanged(const App::Property* prop)
}
}
}
// if (prop == &X || //nothing needs to be calculated, just the graphic needs to be shifted.
// prop == &Y) {
// requestPaint();
// }
}
App::DocumentObject::onChanged(prop);
}
Expand Down
14 changes: 8 additions & 6 deletions src/Mod/TechDraw/Gui/QGIProjGroup.cpp
Expand Up @@ -52,10 +52,11 @@ QGIProjGroup::QGIProjGroup()
m_origin->setParentItem(this);

// In place to ensure correct drawing and bounding box calculations
m_backgroundItem = new QGraphicsRectItem();
m_backgroundItem->setPen(QPen(QColor(Qt::black)));
// WF: obs? not even part of QGIGroup!
m_groupBackground = new QGraphicsRectItem();
m_groupBackground->setPen(QPen(QColor(Qt::black)));

//addToGroup(m_backgroundItem);
//addToGroup(m_groupBackground);
setFlag(ItemIsSelectable, false);
setFlag(ItemIsMovable, true);
setFiltersChildEvents(true);
Expand Down Expand Up @@ -116,7 +117,8 @@ QVariant QGIProjGroup::itemChange(GraphicsItemChange change, const QVariant &val
QString type = QString::fromLatin1(projItemPtr->Type.getValueAsString());

if (type == QString::fromLatin1("Front")) {
gView->setLocked(true);
gView->setLocked(true); //this locks in GUI only
fView->LockPosition.setValue(true); //lock in App also
installSceneEventFilter(gView);
App::DocumentObject *docObj = getViewObject();
TechDraw::DrawProjGroup *projectionGroup = dynamic_cast<TechDraw::DrawProjGroup *>(docObj);
Expand All @@ -136,7 +138,6 @@ QVariant QGIProjGroup::itemChange(GraphicsItemChange change, const QVariant &val
return QGIViewCollection::itemChange(change, value);
}


void QGIProjGroup::mousePressEvent(QGraphicsSceneMouseEvent * event)
{
QGIView *qAnchor = getAnchorQItem();
Expand Down Expand Up @@ -208,7 +209,7 @@ QGIView * QGIProjGroup::getAnchorQItem() const

void QGIProjGroup::updateView(bool update)
{
m_backgroundItem->setRect(boundingRect());
m_groupBackground->setRect(boundingRect());
return QGIViewCollection::updateView(update);
}

Expand All @@ -217,3 +218,4 @@ void QGIProjGroup::drawBorder()
//QGIProjGroup does not have a border!
// Base::Console().Message("TRACE - QGIProjGroup::drawBorder - doing nothing!!\n");
}

2 changes: 1 addition & 1 deletion src/Mod/TechDraw/Gui/QGIProjGroup.h
Expand Up @@ -67,7 +67,7 @@ class TechDrawGuiExport QGIProjGroup : public QGIViewCollection
/// Convenience function
TechDraw::DrawProjGroup * getDrawView(void) const;

QGraphicsRectItem *m_backgroundItem;
QGraphicsRectItem *m_groupBackground;
QGraphicsItem* m_origin;
QPoint mousePos;
};
Expand Down

0 comments on commit 90fd3ae

Please sign in to comment.