Skip to content

Commit

Permalink
[TD]Add parameters to control drawing update
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Aug 30, 2019
1 parent 364d051 commit 5bed53f
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 21 deletions.
39 changes: 32 additions & 7 deletions src/Mod/TechDraw/App/DrawPage.cpp
Expand Up @@ -78,7 +78,7 @@ DrawPage::DrawPage(void)

Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/General");
bool autoUpdate = hGrp->GetBool("KeepPagesUpToDate", 1l);
bool autoUpdate = hGrp->GetBool("KeepPagesUpToDate", true); //this is the default value for new pages!

ADD_PROPERTY_TYPE(KeepUpdated, (autoUpdate), group, (App::PropertyType)(App::Prop_Output), "Keep page in sync with model");
ADD_PROPERTY_TYPE(Template, (0), group, (App::PropertyType)(App::Prop_None), "Attached Template");
Expand Down Expand Up @@ -324,14 +324,23 @@ void DrawPage::requestPaint(void)
signalGuiPaint(this);
}

//this doesn't work right because there is no guaranteed of the restoration order
void DrawPage::onDocumentRestored()
{
//control drawing updates on restore based on Preference
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/General");
bool autoUpdate = hGrp->GetBool("KeepPagesUpToDate", 1l);
KeepUpdated.setValue(autoUpdate);
if (GlobalUpdateDrawings() &&
KeepUpdated.getValue()) {
updateAllViews();
} else if (!GlobalUpdateDrawings() &&
AllowPageOverride() &&
KeepUpdated.getValue()) {
updateAllViews();
}

App::DocumentObject::onDocumentRestored();
}

void DrawPage::updateAllViews()
{
std::vector<App::DocumentObject*> featViews = getAllViews();
std::vector<App::DocumentObject*>::const_iterator it = featViews.begin();
//first, make sure all the Parts have been executed so GeometryObjects exist
Expand All @@ -349,7 +358,6 @@ void DrawPage::onDocumentRestored()
dim->recomputeFeature();
}
}
App::DocumentObject::onDocumentRestored();
}

std::vector<App::DocumentObject*> DrawPage::getAllViews(void)
Expand Down Expand Up @@ -439,6 +447,23 @@ void DrawPage::handleChangedPropertyType(
}
}

bool DrawPage::GlobalUpdateDrawings(void)
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/General");
bool result = hGrp->GetBool("GlobalUpdateDrawings", true);
return result;
}

bool DrawPage::AllowPageOverride(void)
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/General");
bool result = hGrp->GetBool("AllowPageOverride", true);
return result;
}


// Python Drawing feature ---------------------------------------------------------

namespace App {
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/TechDraw/App/DrawPage.h
Expand Up @@ -97,6 +97,10 @@ class TechDrawExport DrawPage: public App::DocumentObject
DrawViewPart *balloonParent; //could be many balloons on page?

int getNextBalloonIndex(void);

void updateAllViews(void);
static bool GlobalUpdateDrawings(void);
static bool AllowPageOverride(void);

protected:
void onBeforeChange(const App::Property* prop) override;
Expand Down
14 changes: 13 additions & 1 deletion src/Mod/TechDraw/App/DrawView.cpp
Expand Up @@ -365,10 +365,22 @@ void DrawView::handleChangedPropertyType(
bool DrawView::keepUpdated(void)
{
bool result = false;

bool pageUpdate = false;
TechDraw::DrawPage *page = findParentPage();
if(page) {
result = page->KeepUpdated.getValue();
pageUpdate = page->KeepUpdated.getValue();
}

if (DrawPage::GlobalUpdateDrawings() &&
pageUpdate) {
result = true;
} else if (!DrawPage::GlobalUpdateDrawings() &&
DrawPage::AllowPageOverride() &&
pageUpdate) {
result = true;
}

return result;
}

Expand Down
76 changes: 65 additions & 11 deletions src/Mod/TechDraw/Gui/DlgPrefsTechDraw.ui
Expand Up @@ -7,12 +7,15 @@
<x>0</x>
<y>0</y>
<width>558</width>
<height>935</height>
<height>1095</height>
</rect>
</property>
<property name="windowTitle">
<string>TechDraw General</string>
</property>
<property name="toolTip">
<string>Default value for new Page</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<widget class="QGroupBox" name="gbMisc">
Expand Down Expand Up @@ -141,40 +144,91 @@
</widget>
</item>
<item row="4" column="0">
<widget class="Gui::PrefCheckBox" name="cb_PageUpdate">
<widget class="Gui::PrefCheckBox" name="cb_AutoDist">
<property name="toolTip">
<string>Update Pages as scheduled or skip</string>
<string>Automatically distribute secondary views.</string>
</property>
<property name="text">
<string>Keep Pages Up to Date</string>
<string>AutoDistribute Secondary Views</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>KeepPagesUpToDate</cstring>
<cstring>AutoDist</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/General</cstring>
<cstring>/Mod/TechDraw/General</cstring>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="Gui::PrefCheckBox" name="cb_AutoDist">
<widget class="QLabel" name="label_12">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Drawing Updates</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="Gui::PrefCheckBox" name="cb_Global">
<property name="toolTip">
<string>Automatically distribute secondary views.</string>
<string>Update drawings with changes in 3D model</string>
</property>
<property name="text">
<string>AutoDistribute Secondary Views</string>
<string>Update with 3D (Global Policy)</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>AutoDist</cstring>
<cstring>GlobalUpdateDrawings</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/General</cstring>
<cstring>Mod/TechDraw/General</cstring>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="Gui::PrefCheckBox" name="cb_Override">
<property name="toolTip">
<string>Allow Page to override Global update setting</string>
</property>
<property name="text">
<string>Allow Page Override</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>AllowPageOverride</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/General</cstring>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="Gui::PrefCheckBox" name="cb_PageUpdate">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Update Pages as scheduled or skip updates. This is the default setting for new Pages.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Keep Page Up to Date (default)</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>KeepPagesUpToDate</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/General</cstring>
</property>
</widget>
</item>
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/TechDraw/Gui/DlgPrefsTechDrawImp.cpp
Expand Up @@ -50,6 +50,8 @@ void DlgPrefsTechDrawImp::saveSettings()
cb_Faces->onSave();
cb_SectionEdges->onSave();
cb_PageUpdate->onSave();
cb_Global->onSave();
cb_Override->onSave();
cb_AutoDist->onSave();

pcb_Normal->onSave();
Expand Down Expand Up @@ -81,6 +83,8 @@ void DlgPrefsTechDrawImp::loadSettings()
cb_Faces->onRestore();
cb_SectionEdges->onRestore();
cb_PageUpdate->onRestore();
cb_Global->onRestore();
cb_Override->onRestore();
cb_AutoDist->onRestore();

pcb_Normal->onRestore();
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/TechDraw/Gui/ViewProviderPage.cpp
Expand Up @@ -259,8 +259,8 @@ bool ViewProviderPage::showMDIViewPage()
Gui::getMainWindow()->addWindow(m_mdiView);
m_mdiView->viewAll(); //this is empty function
m_mdiView->showMaximized();
if(!getDrawPage()->KeepUpdated.getValue())
getDrawPage()->KeepUpdated.setValue(true);
// if(!getDrawPage()->KeepUpdated.getValue())
// getDrawPage()->KeepUpdated.setValue(true);
} else {
m_mdiView->updateDrawing(true);
m_mdiView->redrawAllViews();
Expand Down

0 comments on commit 5bed53f

Please sign in to comment.