Skip to content

Commit

Permalink
Fix #3810 X/Y Property Update on Locked View
Browse files Browse the repository at this point in the history
- fixes x/y update when position locked for simple
  Views and ProjectionGroups.
  • Loading branch information
WandererFan authored and wwmayer committed Feb 14, 2019
1 parent 97614e0 commit a0e3ab1
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 41 deletions.
3 changes: 1 addition & 2 deletions src/Mod/TechDraw/App/DrawProjGroup.cpp
Expand Up @@ -85,7 +85,6 @@ DrawProjGroup::~DrawProjGroup()
{
}


void DrawProjGroup::onChanged(const App::Property* prop)
{
//TODO: For some reason, when the projection type is changed, the isometric views show change appropriately, but the orthographic ones don't... Or vice-versa. WF: why would you change from 1st to 3rd in mid drawing?
Expand Down Expand Up @@ -136,7 +135,7 @@ void DrawProjGroup::onChanged(const App::Property* prop)
}

}

TechDraw::DrawViewCollection::onChanged(prop);
}

Expand Down
18 changes: 14 additions & 4 deletions src/Mod/TechDraw/App/DrawProjGroupItem.cpp
Expand Up @@ -29,8 +29,10 @@
#include <gp_Ax2.hxx>
#include <gp_Ax3.hxx>
#include <gp_Trsf.hxx>

#include <App/Application.h>
#include <App/DocumentObject.h>
#include <Base/Console.h>
#include <Base/Writer.h>

#include "GeometryObject.h"
#include "DrawUtil.h"
Expand Down Expand Up @@ -72,6 +74,10 @@ DrawProjGroupItem::DrawProjGroupItem(void)
ScaleType.setStatus(App::Property::ReadOnly,true);
}

DrawProjGroupItem::~DrawProjGroupItem()
{
}

short DrawProjGroupItem::mustExecute() const
{
short result = 0;
Expand All @@ -91,11 +97,16 @@ short DrawProjGroupItem::mustExecute() const
void DrawProjGroupItem::onChanged(const App::Property *prop)
{
TechDraw::DrawViewPart::onChanged(prop);

}

DrawProjGroupItem::~DrawProjGroupItem()
bool DrawProjGroupItem::isLocked(void) const
{
bool isLocked = DrawView::isLocked();
DrawProjGroup* parent = getPGroup();
if (parent != nullptr) {
isLocked = isLocked || parent->LockPosition.getValue();
}
return isLocked;
}

App::DocumentObjectExecReturn *DrawProjGroupItem::execute(void)
Expand Down Expand Up @@ -234,7 +245,6 @@ double DrawProjGroupItem::getScale(void) const
return result;
}


void DrawProjGroupItem::unsetupObject()
{
if (getPGroup() != nullptr) {
Expand Down
1 change: 1 addition & 0 deletions src/Mod/TechDraw/App/DrawProjGroupItem.h
Expand Up @@ -83,6 +83,7 @@ class TechDrawExport DrawProjGroupItem : public TechDraw::DrawViewPart

protected:
void onChanged(const App::Property* prop) override;
virtual bool isLocked(void) const override;

private:
static const char* TypeEnums[];
Expand Down
58 changes: 48 additions & 10 deletions src/Mod/TechDraw/App/DrawView.cpp
Expand Up @@ -72,10 +72,9 @@ DrawView::DrawView(void):
mouseMove(false)
{
static const char *group = "Base";

ADD_PROPERTY_TYPE(X ,(0),group,App::Prop_None,"X position of the view on the page in modelling units (mm)");
ADD_PROPERTY_TYPE(Y ,(0),group,App::Prop_None,"Y position of the view on the page in modelling units (mm)");
ADD_PROPERTY_TYPE(LockPosition ,(false),group,App::Prop_None,"Prevent View from moving in Gui");
ADD_PROPERTY_TYPE(X ,(0),group,App::Prop_None,"X position of the view on the page in internal units (mm)");
ADD_PROPERTY_TYPE(Y ,(0),group,App::Prop_None,"Y position of the view on the page in internal units (mm)");
ADD_PROPERTY_TYPE(LockPosition ,(false),group,App::Prop_None,"Lock View position to parent Page or Group");
ADD_PROPERTY_TYPE(Rotation ,(0),group,App::Prop_None,"Rotation of the view on the page in degrees counterclockwise");

ScaleType.setEnums(ScaleTypeEnums);
Expand All @@ -92,8 +91,9 @@ DrawView::~DrawView()

App::DocumentObjectExecReturn *DrawView::execute(void)
{
handleXYLock();
requestPaint();
return App::DocumentObject::StdReturn; //DO::execute returns 0
return App::DocumentObject::execute();
}

void DrawView::checkScale(void)
Expand Down Expand Up @@ -139,19 +139,54 @@ void DrawView::onChanged(const App::Property* prop)
}
}
}
} else if (prop == &LockPosition) {
handleXYLock();
}
}
App::DocumentObject::onChanged(prop);
}

bool DrawView::isLocked(void) const
{
return LockPosition.getValue();
}

//override this for View inside a group (ex DPGI in DPG)
void DrawView::handleXYLock(void)
{
if (isLocked()) {
if (!X.testStatus(App::Property::ReadOnly)) {
X.setStatus(App::Property::ReadOnly,true);
App::GetApplication().signalChangePropertyEditor(X);
X.purgeTouched();
}
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();
}
Y.setStatus(App::Property::ReadOnly,false);
App::GetApplication().signalChangePropertyEditor(Y);
Y.purgeTouched();
requestPaint();
}
}

short DrawView::mustExecute() const
{
short result = 0;
if (!isRestoring()) {
result = (Scale.isTouched() ||
ScaleType.isTouched() ||
X.isTouched() ||
Y.isTouched() );
ScaleType.isTouched() );
if (!isLocked()) {
result = result || X.isTouched() ||
Y.isTouched() ;
}
}
if ((bool) result) {
return result;
Expand All @@ -168,6 +203,7 @@ QRectF DrawView::getRect() const

void DrawView::onDocumentRestored()
{
handleXYLock();
DrawView::execute();
}

Expand Down Expand Up @@ -251,8 +287,10 @@ bool DrawView::checkFit(TechDraw::DrawPage* p) const

void DrawView::setPosition(double x, double y)
{
X.setValue(x);
Y.setValue(y);
if (!isLocked()) {
X.setValue(x);
Y.setValue(y);
}
}

//TODO: getScale is no longer needed and could revert to Scale.getValue
Expand Down
4 changes: 3 additions & 1 deletion src/Mod/TechDraw/App/DrawView.h
Expand Up @@ -87,9 +87,11 @@ class TechDrawExport DrawView : public App::DocumentObject
virtual double getScale(void) const;
void checkScale(void);
void requestPaint(void);
virtual void handleXYLock(void);
virtual bool isLocked(void) const;

protected:
void onChanged(const App::Property* prop) override;
virtual void onChanged(const App::Property* prop) override;
std::string pageFeatName;
bool autoPos;
bool mouseMove;
Expand Down
60 changes: 36 additions & 24 deletions src/Mod/TechDraw/App/DrawViewCollection.cpp
Expand Up @@ -27,6 +27,7 @@
#endif

#include <App/Document.h>
#include <App/DocumentObject.h>

#include <Base/Console.h>
#include <Base/Exception.h>
Expand All @@ -45,15 +46,40 @@ PROPERTY_SOURCE(TechDraw::DrawViewCollection, TechDraw::DrawView)
DrawViewCollection::DrawViewCollection()
{
nowUnsetting = false;
static const char *group = "Drawing view";
ADD_PROPERTY_TYPE(Views ,(0), group, App::Prop_None,"Attached Views");
static const char *group = "Collection";
ADD_PROPERTY_TYPE(Views ,(0), group, App::Prop_None,"Collection Views");
Views.setScope(App::LinkScope::Global);
}

DrawViewCollection::~DrawViewCollection()
{
}

void DrawViewCollection::onChanged(const App::Property* prop)
{
TechDraw::DrawView::onChanged(prop);
}

short DrawViewCollection::mustExecute() const
{
if (Views.isTouched()) {
return 1;
} else {
return TechDraw::DrawView::mustExecute();
}
}

App::DocumentObjectExecReturn *DrawViewCollection::execute(void)
{
if (!keepUpdated()) {
return App::DocumentObject::StdReturn;
}

lockChildren();

return DrawView::execute();
}

int DrawViewCollection::addView(DrawView *view)
{
// Add the new view to the collection
Expand Down Expand Up @@ -106,15 +132,6 @@ void DrawViewCollection::rebuildViewList()
Views.setValues(newViews);
}

short DrawViewCollection::mustExecute() const
{
if (Views.isTouched()) {
return 1;
} else {
return TechDraw::DrawView::mustExecute();
}
}

int DrawViewCollection::countChildren()
{
//Count the children recursively if needed
Expand All @@ -138,9 +155,15 @@ void DrawViewCollection::onDocumentRestored()
DrawView::execute();
}

void DrawViewCollection::onChanged(const App::Property* prop)
void DrawViewCollection::lockChildren(void)
{
TechDraw::DrawView::onChanged(prop);
for (auto& v:Views.getValues()) {
TechDraw::DrawView *view = dynamic_cast<TechDraw::DrawView *>(v);
if (!view) {
throw Base::ValueError("DrawViewCollection::lockChildren bad View\n");
}
view->handleXYLock();
}
}

void DrawViewCollection::unsetupObject()
Expand All @@ -162,17 +185,6 @@ void DrawViewCollection::unsetupObject()
Views.setValues(emptyViews);
}


App::DocumentObjectExecReturn *DrawViewCollection::execute(void)
{
if (!keepUpdated()) {
return App::DocumentObject::StdReturn;
}

return DrawView::execute();
}


QRectF DrawViewCollection::getRect() const
{
QRectF result;
Expand Down
1 change: 1 addition & 0 deletions src/Mod/TechDraw/App/DrawViewCollection.h
Expand Up @@ -52,6 +52,7 @@ class TechDrawExport DrawViewCollection : public DrawView
bool isUnsetting(void) { return nowUnsetting; }

int countChildren();
void lockChildren(void);

virtual void onDocumentRestored();
virtual App::DocumentObjectExecReturn *execute(void);
Expand Down

0 comments on commit a0e3ab1

Please sign in to comment.