Skip to content

Commit a0e3ab1

Browse files
WandererFanwwmayer
authored andcommitted
Fix #3810 X/Y Property Update on Locked View
- fixes x/y update when position locked for simple Views and ProjectionGroups.
1 parent 97614e0 commit a0e3ab1

File tree

7 files changed

+104
-41
lines changed

7 files changed

+104
-41
lines changed

src/Mod/TechDraw/App/DrawProjGroup.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ DrawProjGroup::~DrawProjGroup()
8585
{
8686
}
8787

88-
8988
void DrawProjGroup::onChanged(const App::Property* prop)
9089
{
9190
//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?
@@ -136,7 +135,7 @@ void DrawProjGroup::onChanged(const App::Property* prop)
136135
}
137136

138137
}
139-
138+
140139
TechDraw::DrawViewCollection::onChanged(prop);
141140
}
142141

src/Mod/TechDraw/App/DrawProjGroupItem.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
#include <gp_Ax2.hxx>
3030
#include <gp_Ax3.hxx>
3131
#include <gp_Trsf.hxx>
32+
33+
#include <App/Application.h>
34+
#include <App/DocumentObject.h>
3235
#include <Base/Console.h>
33-
#include <Base/Writer.h>
3436

3537
#include "GeometryObject.h"
3638
#include "DrawUtil.h"
@@ -72,6 +74,10 @@ DrawProjGroupItem::DrawProjGroupItem(void)
7274
ScaleType.setStatus(App::Property::ReadOnly,true);
7375
}
7476

77+
DrawProjGroupItem::~DrawProjGroupItem()
78+
{
79+
}
80+
7581
short DrawProjGroupItem::mustExecute() const
7682
{
7783
short result = 0;
@@ -91,11 +97,16 @@ short DrawProjGroupItem::mustExecute() const
9197
void DrawProjGroupItem::onChanged(const App::Property *prop)
9298
{
9399
TechDraw::DrawViewPart::onChanged(prop);
94-
95100
}
96101

97-
DrawProjGroupItem::~DrawProjGroupItem()
102+
bool DrawProjGroupItem::isLocked(void) const
98103
{
104+
bool isLocked = DrawView::isLocked();
105+
DrawProjGroup* parent = getPGroup();
106+
if (parent != nullptr) {
107+
isLocked = isLocked || parent->LockPosition.getValue();
108+
}
109+
return isLocked;
99110
}
100111

101112
App::DocumentObjectExecReturn *DrawProjGroupItem::execute(void)
@@ -234,7 +245,6 @@ double DrawProjGroupItem::getScale(void) const
234245
return result;
235246
}
236247

237-
238248
void DrawProjGroupItem::unsetupObject()
239249
{
240250
if (getPGroup() != nullptr) {

src/Mod/TechDraw/App/DrawProjGroupItem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class TechDrawExport DrawProjGroupItem : public TechDraw::DrawViewPart
8383

8484
protected:
8585
void onChanged(const App::Property* prop) override;
86+
virtual bool isLocked(void) const override;
8687

8788
private:
8889
static const char* TypeEnums[];

src/Mod/TechDraw/App/DrawView.cpp

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ DrawView::DrawView(void):
7272
mouseMove(false)
7373
{
7474
static const char *group = "Base";
75-
76-
ADD_PROPERTY_TYPE(X ,(0),group,App::Prop_None,"X position of the view on the page in modelling units (mm)");
77-
ADD_PROPERTY_TYPE(Y ,(0),group,App::Prop_None,"Y position of the view on the page in modelling units (mm)");
78-
ADD_PROPERTY_TYPE(LockPosition ,(false),group,App::Prop_None,"Prevent View from moving in Gui");
75+
ADD_PROPERTY_TYPE(X ,(0),group,App::Prop_None,"X position of the view on the page in internal units (mm)");
76+
ADD_PROPERTY_TYPE(Y ,(0),group,App::Prop_None,"Y position of the view on the page in internal units (mm)");
77+
ADD_PROPERTY_TYPE(LockPosition ,(false),group,App::Prop_None,"Lock View position to parent Page or Group");
7978
ADD_PROPERTY_TYPE(Rotation ,(0),group,App::Prop_None,"Rotation of the view on the page in degrees counterclockwise");
8079

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

9392
App::DocumentObjectExecReturn *DrawView::execute(void)
9493
{
94+
handleXYLock();
9595
requestPaint();
96-
return App::DocumentObject::StdReturn; //DO::execute returns 0
96+
return App::DocumentObject::execute();
9797
}
9898

9999
void DrawView::checkScale(void)
@@ -139,19 +139,54 @@ void DrawView::onChanged(const App::Property* prop)
139139
}
140140
}
141141
}
142+
} else if (prop == &LockPosition) {
143+
handleXYLock();
142144
}
143145
}
144146
App::DocumentObject::onChanged(prop);
145147
}
146148

149+
bool DrawView::isLocked(void) const
150+
{
151+
return LockPosition.getValue();
152+
}
153+
154+
//override this for View inside a group (ex DPGI in DPG)
155+
void DrawView::handleXYLock(void)
156+
{
157+
if (isLocked()) {
158+
if (!X.testStatus(App::Property::ReadOnly)) {
159+
X.setStatus(App::Property::ReadOnly,true);
160+
App::GetApplication().signalChangePropertyEditor(X);
161+
X.purgeTouched();
162+
}
163+
Y.setStatus(App::Property::ReadOnly,true);
164+
App::GetApplication().signalChangePropertyEditor(Y);
165+
Y.purgeTouched();
166+
requestPaint();
167+
} else {
168+
if (X.testStatus(App::Property::ReadOnly)) {
169+
X.setStatus(App::Property::ReadOnly,false);
170+
App::GetApplication().signalChangePropertyEditor(X);
171+
X.purgeTouched();
172+
}
173+
Y.setStatus(App::Property::ReadOnly,false);
174+
App::GetApplication().signalChangePropertyEditor(Y);
175+
Y.purgeTouched();
176+
requestPaint();
177+
}
178+
}
179+
147180
short DrawView::mustExecute() const
148181
{
149182
short result = 0;
150183
if (!isRestoring()) {
151184
result = (Scale.isTouched() ||
152-
ScaleType.isTouched() ||
153-
X.isTouched() ||
154-
Y.isTouched() );
185+
ScaleType.isTouched() );
186+
if (!isLocked()) {
187+
result = result || X.isTouched() ||
188+
Y.isTouched() ;
189+
}
155190
}
156191
if ((bool) result) {
157192
return result;
@@ -168,6 +203,7 @@ QRectF DrawView::getRect() const
168203

169204
void DrawView::onDocumentRestored()
170205
{
206+
handleXYLock();
171207
DrawView::execute();
172208
}
173209

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

252288
void DrawView::setPosition(double x, double y)
253289
{
254-
X.setValue(x);
255-
Y.setValue(y);
290+
if (!isLocked()) {
291+
X.setValue(x);
292+
Y.setValue(y);
293+
}
256294
}
257295

258296
//TODO: getScale is no longer needed and could revert to Scale.getValue

src/Mod/TechDraw/App/DrawView.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ class TechDrawExport DrawView : public App::DocumentObject
8787
virtual double getScale(void) const;
8888
void checkScale(void);
8989
void requestPaint(void);
90+
virtual void handleXYLock(void);
91+
virtual bool isLocked(void) const;
9092

9193
protected:
92-
void onChanged(const App::Property* prop) override;
94+
virtual void onChanged(const App::Property* prop) override;
9395
std::string pageFeatName;
9496
bool autoPos;
9597
bool mouseMove;

src/Mod/TechDraw/App/DrawViewCollection.cpp

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#endif
2828

2929
#include <App/Document.h>
30+
#include <App/DocumentObject.h>
3031

3132
#include <Base/Console.h>
3233
#include <Base/Exception.h>
@@ -45,15 +46,40 @@ PROPERTY_SOURCE(TechDraw::DrawViewCollection, TechDraw::DrawView)
4546
DrawViewCollection::DrawViewCollection()
4647
{
4748
nowUnsetting = false;
48-
static const char *group = "Drawing view";
49-
ADD_PROPERTY_TYPE(Views ,(0), group, App::Prop_None,"Attached Views");
49+
static const char *group = "Collection";
50+
ADD_PROPERTY_TYPE(Views ,(0), group, App::Prop_None,"Collection Views");
5051
Views.setScope(App::LinkScope::Global);
5152
}
5253

5354
DrawViewCollection::~DrawViewCollection()
5455
{
5556
}
5657

58+
void DrawViewCollection::onChanged(const App::Property* prop)
59+
{
60+
TechDraw::DrawView::onChanged(prop);
61+
}
62+
63+
short DrawViewCollection::mustExecute() const
64+
{
65+
if (Views.isTouched()) {
66+
return 1;
67+
} else {
68+
return TechDraw::DrawView::mustExecute();
69+
}
70+
}
71+
72+
App::DocumentObjectExecReturn *DrawViewCollection::execute(void)
73+
{
74+
if (!keepUpdated()) {
75+
return App::DocumentObject::StdReturn;
76+
}
77+
78+
lockChildren();
79+
80+
return DrawView::execute();
81+
}
82+
5783
int DrawViewCollection::addView(DrawView *view)
5884
{
5985
// Add the new view to the collection
@@ -106,15 +132,6 @@ void DrawViewCollection::rebuildViewList()
106132
Views.setValues(newViews);
107133
}
108134

109-
short DrawViewCollection::mustExecute() const
110-
{
111-
if (Views.isTouched()) {
112-
return 1;
113-
} else {
114-
return TechDraw::DrawView::mustExecute();
115-
}
116-
}
117-
118135
int DrawViewCollection::countChildren()
119136
{
120137
//Count the children recursively if needed
@@ -138,9 +155,15 @@ void DrawViewCollection::onDocumentRestored()
138155
DrawView::execute();
139156
}
140157

141-
void DrawViewCollection::onChanged(const App::Property* prop)
158+
void DrawViewCollection::lockChildren(void)
142159
{
143-
TechDraw::DrawView::onChanged(prop);
160+
for (auto& v:Views.getValues()) {
161+
TechDraw::DrawView *view = dynamic_cast<TechDraw::DrawView *>(v);
162+
if (!view) {
163+
throw Base::ValueError("DrawViewCollection::lockChildren bad View\n");
164+
}
165+
view->handleXYLock();
166+
}
144167
}
145168

146169
void DrawViewCollection::unsetupObject()
@@ -162,17 +185,6 @@ void DrawViewCollection::unsetupObject()
162185
Views.setValues(emptyViews);
163186
}
164187

165-
166-
App::DocumentObjectExecReturn *DrawViewCollection::execute(void)
167-
{
168-
if (!keepUpdated()) {
169-
return App::DocumentObject::StdReturn;
170-
}
171-
172-
return DrawView::execute();
173-
}
174-
175-
176188
QRectF DrawViewCollection::getRect() const
177189
{
178190
QRectF result;

src/Mod/TechDraw/App/DrawViewCollection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class TechDrawExport DrawViewCollection : public DrawView
5252
bool isUnsetting(void) { return nowUnsetting; }
5353

5454
int countChildren();
55+
void lockChildren(void);
5556

5657
virtual void onDocumentRestored();
5758
virtual App::DocumentObjectExecReturn *execute(void);

0 commit comments

Comments
 (0)