Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[TD]Transition to on demand page updates ph1
  • Loading branch information
WandererFan committed Oct 23, 2019
1 parent 820ad87 commit 5bb659e
Show file tree
Hide file tree
Showing 18 changed files with 342 additions and 224 deletions.
29 changes: 26 additions & 3 deletions src/Mod/TechDraw/App/DrawPage.cpp
Expand Up @@ -130,6 +130,7 @@ void DrawPage::onChanged(const App::Property* prop)
//would be nice if this message was displayed immediately instead of after the recomputeFeature
Base::Console().Message("Rebuilding Views for: %s/%s\n",getNameInDocument(),Label.getValue());
updateAllViews();
purgeTouched();
}
} else if (prop == &Template) {
if (!isRestoring() &&
Expand Down Expand Up @@ -176,6 +177,16 @@ App::DocumentObjectExecReturn *DrawPage::execute(void)
// this is now irrelevant, b/c DP::execute doesn't do anything.
short DrawPage::mustExecute() const
{
short result = 0;
if (!isRestoring()) {
result = (Views.isTouched() ||
Scale.isTouched() ||
ProjectionType.isTouched() ||
Template.isTouched());
if (result) {
return result;
}
}
return App::DocumentObject::mustExecute();
}

Expand Down Expand Up @@ -331,17 +342,27 @@ void DrawPage::onDocumentRestored()
App::DocumentObject::onDocumentRestored();
}

void DrawPage::redrawCommand()
{
// Base::Console().Message("DP::redrawCommand()\n");
forceRedraw(true);
updateAllViews();
forceRedraw(false);
}
//should really be called "updateMostViews". can still be problems to due execution order.
void DrawPage::updateAllViews()
{
// Base::Console().Message("DP::updateAllViews()\n");
std::vector<App::DocumentObject*> featViews = getAllViews();
std::vector<App::DocumentObject*>::const_iterator it = featViews.begin();
std::vector<App::DocumentObject*>::iterator it = featViews.begin();
//first, make sure all the Parts have been executed so GeometryObjects exist
for(; it != featViews.end(); ++it) {
TechDraw::DrawViewPart *part = dynamic_cast<TechDraw::DrawViewPart *>(*it);
if (part != nullptr &&
!part->hasGeometry()) {
TechDraw::DrawViewCollection *collect = dynamic_cast<TechDraw::DrawViewCollection*>(*it);
if (part != nullptr) {
part->recomputeFeature();
} else if (collect != nullptr) {
collect->recomputeFeature();
}
}
//second, make sure all the Dimensions have been executed so Measurements have References
Expand Down Expand Up @@ -448,6 +469,7 @@ void DrawPage::handleChangedPropertyType(
}
}

//allow/prevent drawing updates for all Pages
bool DrawPage::GlobalUpdateDrawings(void)
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
Expand All @@ -456,6 +478,7 @@ bool DrawPage::GlobalUpdateDrawings(void)
return result;
}

//allow/prevent a single page to update despite GlobalUpdateDrawings setting
bool DrawPage::AllowPageOverride(void)
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
Expand Down
1 change: 1 addition & 0 deletions src/Mod/TechDraw/App/DrawPage.h
Expand Up @@ -103,6 +103,7 @@ class TechDrawExport DrawPage: public App::DocumentObject
static bool AllowPageOverride(void);
void forceRedraw(bool b) { m_forceRedraw = b; }
bool forceRedraw(void) { return m_forceRedraw; }
void redrawCommand();

protected:
void onBeforeChange(const App::Property* prop) override;
Expand Down
71 changes: 55 additions & 16 deletions src/Mod/TechDraw/App/DrawProjGroup.cpp
Expand Up @@ -74,9 +74,11 @@ DrawProjGroup::DrawProjGroup(void)


ProjectionType.setEnums(ProjectionTypeEnums);
ADD_PROPERTY(ProjectionType, ((long)getDefProjConv()));
ADD_PROPERTY_TYPE(ProjectionType, ((long)getDefProjConv()), group,
App::Prop_None, "First or Third Angle projection");

ADD_PROPERTY_TYPE(AutoDistribute ,(autoDist),agroup,App::Prop_None,"Distribute Views Automatically or Manually");
ADD_PROPERTY_TYPE(AutoDistribute ,(autoDist),agroup,
App::Prop_None,"Distribute Views Automatically or Manually");
ADD_PROPERTY_TYPE(spacingX, (15), agroup, App::Prop_None, "Horizontal spacing between views");
ADD_PROPERTY_TYPE(spacingY, (15), agroup, App::Prop_None, "Vertical spacing between views");
Rotation.setStatus(App::Property::Hidden,true); //DPG does not rotate
Expand Down Expand Up @@ -108,8 +110,13 @@ void DrawProjGroup::onChanged(const App::Property* prop)
// }
}
if (prop == &Scale) {
updateChildren();
updateChildrenScale();
}

if (prop == &ProjectionType) {
updateChildrenEnforce();
}

if (prop == &Source) {
updateChildrenSource();
}
Expand Down Expand Up @@ -168,17 +175,8 @@ App::DocumentObjectExecReturn *DrawProjGroup::execute(void)
//no anchor yet. nothing to do.
return DrawViewCollection::execute();
}

// for (auto& v: Views.getValues()) { //is this needed here? Up to DPGI to keep up to date.
// v->recomputeFeature();
// }

for (auto& item: getViewsAsDPGI()) {
bool touched = item->isTouched();
item->autoPosition();
if(!touched)
item->purgeTouched();
}

autoPositionChildren();

return DrawViewCollection::execute();
}
Expand Down Expand Up @@ -853,16 +851,42 @@ void DrawProjGroup::makeViewBbs(DrawProjGroupItem *viewPtrs[10],
}
}

void DrawProjGroup::recomputeChildren(void)
{
// Base::Console().Message("DPG::recomputeChildren()\n");
for( const auto it : Views.getValues() ) {
auto view( dynamic_cast<DrawProjGroupItem *>(it) );
if (view == nullptr) {
throw Base::TypeError("Error: projection in DPG list is not a DPGI!");
} else {
view->recomputeFeature();
}
}
}

void DrawProjGroup::autoPositionChildren(void)
{
for( const auto it : Views.getValues() ) {
auto view( dynamic_cast<DrawProjGroupItem *>(it) );
if (view == nullptr) {
throw Base::TypeError("Error: projection in DPG list is not a DPGI!");
} else {
view->autoPosition();
}
}
}

/*!
* tell children DPGIs that parent DPG has changed Scale
*/
void DrawProjGroup::updateChildren(void)
void DrawProjGroup::updateChildrenScale(void)
{
// Base::Console().Message("DPG::updateChildrenScale\n");
for( const auto it : Views.getValues() ) {
auto view( dynamic_cast<DrawProjGroupItem *>(it) );
if (view == nullptr) {
//if an element in Views is not a DPGI, something really bad has happened somewhere
Base::Console().Log("PROBLEM - DPG::updateChildren - non DPGI entry in Views! %s\n",
Base::Console().Log("PROBLEM - DPG::updateChildrenScale - non DPGI entry in Views! %s\n",
getNameInDocument());
throw Base::TypeError("Error: projection in DPG list is not a DPGI!");
} else if(view->Scale.getValue()!=Scale.getValue()) {
Expand Down Expand Up @@ -906,6 +930,21 @@ void DrawProjGroup::updateChildrenLock(void)
}
}

void DrawProjGroup::updateChildrenEnforce(void)
{
for( const auto it : Views.getValues() ) {
auto view( dynamic_cast<DrawProjGroupItem *>(it) );
if (view == nullptr) {
//if an element in Views is not a DPGI, something really bad has happened somewhere
Base::Console().Log("PROBLEM - DPG::updateChildrenEnforce - non DPGI entry in Views! %s\n",
getNameInDocument());
throw Base::TypeError("Error: projection in DPG list is not a DPGI!");
} else {
view->enforceRecompute();
}
}
}

/*!
* check if ProjectionGroup fits on Page
*/
Expand Down
7 changes: 6 additions & 1 deletion src/Mod/TechDraw/App/DrawProjGroup.h
Expand Up @@ -127,6 +127,11 @@ class TechDrawExport DrawProjGroup : public TechDraw::DrawViewCollection
void dumpISO(char * title);
std::vector<DrawProjGroupItem*> getViewsAsDPGI();

void recomputeChildren(void);
void updateChildrenScale(void);
void autoPositionChildren(void);
void updateChildrenEnforce(void);

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

Expand Down Expand Up @@ -158,7 +163,7 @@ class TechDrawExport DrawProjGroup : public TechDraw::DrawViewCollection

/// Returns pointer to our page, or NULL if it couldn't be located
TechDraw::DrawPage * getPage(void) const;
void updateChildren(void);

void updateChildrenSource(void);
void updateChildrenLock(void);
int getViewIndex(const char *viewTypeCStr) const;
Expand Down
14 changes: 5 additions & 9 deletions src/Mod/TechDraw/App/DrawProjGroupItem.cpp
Expand Up @@ -133,24 +133,20 @@ bool DrawProjGroupItem::showLock(void) const

App::DocumentObjectExecReturn *DrawProjGroupItem::execute(void)
{
// Base::Console().Message("DPGI::execute(%s)\n",Label.getValue());
if (DrawUtil::checkParallel(Direction.getValue(),
RotationVector.getValue())) {
return new App::DocumentObjectExecReturn("DPGI: Direction and RotationVector are parallel");
}

App::DocumentObjectExecReturn * ret = DrawViewPart::execute();
if (ret != nullptr) {
return ret;
} else {
autoPosition();
delete ret;
}
return App::DocumentObject::StdReturn;
App::DocumentObjectExecReturn* ret = DrawViewPart::execute();
autoPosition();
return ret;
}

void DrawProjGroupItem::autoPosition()
{
// Base::Console().Message("DPGI::autoPosition(%s)\n",getNameInDocument());
// Base::Console().Message("DPGI::autoPosition(%s)\n",Label.getValue());
auto pgroup = getPGroup();
Base::Vector3d newPos;
if (pgroup != nullptr) {
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/TechDraw/App/DrawViewDetail.cpp
Expand Up @@ -144,7 +144,8 @@ void DrawViewDetail::onChanged(const App::Property* prop)
if ((prop == &Reference) ||
(prop == &Radius) ||
(prop == &AnchorPoint)) {
BaseView.getValue()->touch(); //hack. sb "update graphics"
// BaseView.getValue()->touch(); //hack. sb "update graphics"
enforceRecompute();
}

}
Expand Down
57 changes: 30 additions & 27 deletions src/Mod/TechDraw/App/DrawViewDimension.cpp
Expand Up @@ -93,22 +93,22 @@ enum RefType{

DrawViewDimension::DrawViewDimension(void)
{
ADD_PROPERTY_TYPE(References2D,(0,0),"",(App::PropertyType)(App::Prop_None),"Projected Geometry References");
ADD_PROPERTY_TYPE(References2D,(0,0),"",(App::Prop_None),"Projected Geometry References");
References2D.setScope(App::LinkScope::Global);
ADD_PROPERTY_TYPE(References3D,(0,0),"",(App::PropertyType)(App::Prop_None),"3D Geometry References");
ADD_PROPERTY_TYPE(References3D,(0,0),"",(App::Prop_None),"3D Geometry References");
References3D.setScope(App::LinkScope::Global);

ADD_PROPERTY_TYPE(FormatSpec,("") , "Format",(App::PropertyType)(App::Prop_None),"Dimension Format");
ADD_PROPERTY_TYPE(Arbitrary,(false) ,"Format",(App::PropertyType)(App::Prop_None),"Value overridden by user");
ADD_PROPERTY_TYPE(FormatSpec,("") , "Format", App::Prop_Output,"Dimension Format");
ADD_PROPERTY_TYPE(Arbitrary,(false) ,"Format", App::Prop_Output,"Value overridden by user");

Type.setEnums(TypeEnums); //dimension type: length, radius etc
ADD_PROPERTY(Type,((long)0));
MeasureType.setEnums(MeasureTypeEnums);
ADD_PROPERTY(MeasureType, ((long)1)); //Projected (or True) measurement
ADD_PROPERTY_TYPE(TheoreticalExact,(false),"",(App::PropertyType)(App::Prop_None),"Set for theoretical exact (basic) dimension");
ADD_PROPERTY_TYPE(OverTolerance ,(0.0),"",App::Prop_None,"+ Tolerance value");
ADD_PROPERTY_TYPE(UnderTolerance ,(0.0),"",App::Prop_None,"- Tolerance value");
ADD_PROPERTY_TYPE(Inverted,(false),"",(App::PropertyType)(App::Prop_None),"The dimensional value is displayed inverted");
ADD_PROPERTY_TYPE(TheoreticalExact,(false),"", App::Prop_Output,"Set for theoretical exact (basic) dimension");
ADD_PROPERTY_TYPE(OverTolerance ,(0.0),"", App::Prop_Output,"+ Tolerance value");
ADD_PROPERTY_TYPE(UnderTolerance ,(0.0),"", App::Prop_Output,"- Tolerance value");
ADD_PROPERTY_TYPE(Inverted,(false),"", App::Prop_Output,"The dimensional value is displayed inverted");

//hide the properties the user can't edit in the property editor
// References2D.setStatus(App::Property::Hidden,true);
Expand Down Expand Up @@ -160,19 +160,25 @@ void DrawViewDimension::onChanged(const App::Property* prop)
Base::Console().Warning("%s has no 3D References but is Type: True\n", getNameInDocument());
MeasureType.setValue("Projected");
}
}
if (prop == &References3D) { //have to rebuild the Measurement object
} else if (prop == &References3D) { //have to rebuild the Measurement object
clear3DMeasurements(); //Measurement object
if (!(References3D.getValues()).empty()) {
setAll3DMeasurement();
} else {
if (MeasureType.isValue("True")) { //empty 3dRefs, but True
MeasureType.touch(); //run MeasureType logic for this case
if (MeasureType.isValue("True")) { //empty 3dRefs, but True
MeasureType.touch(); //run MeasureType logic for this case
}
}
}
if (prop == &Type) {
} else if (prop == &Type) { //why??
FormatSpec.setValue(getDefaultFormatSpec().c_str());
} else if ( (prop == &FormatSpec) ||
(prop == &Arbitrary) ||
(prop == &MeasureType) ||
(prop == &TheoreticalExact) ||
(prop == &OverTolerance) ||
(prop == &UnderTolerance) ||
(prop == &Inverted) ) {
// nothing in particular
}
}

Expand All @@ -191,18 +197,15 @@ short DrawViewDimension::mustExecute() const
{
bool result = 0;
if (!isRestoring()) {
result = (References2D.isTouched() ||
result = (References2D.isTouched() ||
Type.isTouched() ||
FormatSpec.isTouched() ||
MeasureType.isTouched());
}
if (result) {
return result;
}

auto dvp = getViewPart();
if (dvp != nullptr) {
result = dvp->isTouched();
Arbitrary.isTouched() ||
MeasureType.isTouched() ||
TheoreticalExact.isTouched() ||
OverTolerance.isTouched() ||
UnderTolerance.isTouched() ||
Inverted.isTouched() );
}
if (result) {
return result;
Expand Down Expand Up @@ -572,18 +575,18 @@ std::string DrawViewDimension::getFormatedValue(int partial)
}
} else {
//handle single value schemes
QRegExp rxUnits(QString::fromUtf8(" \\D*$")); //space + any non digits at end of string
QRegExp rxUnits(QString::fromUtf8(" \\D*$")); //space + any non digits at end of string

QString userVal = userStr;
userVal.remove(rxUnits); //getUserString(defaultDecimals) without units
userVal.remove(rxUnits); //getUserString(defaultDecimals) without units

QLocale loc;
double userValNum = loc.toDouble(userVal);

// QString userUnits;
int pos = 0;
if ((pos = rxUnits.indexIn(userStr, 0)) != -1) {
userUnits = rxUnits.cap(0); //entire capture - non numerics at end of userString
userUnits = rxUnits.cap(0); //entire capture - non numerics at end of userString
}

//find the %x.y tag in FormatSpec
Expand Down

0 comments on commit 5bb659e

Please sign in to comment.