Skip to content

Commit

Permalink
[TD] add missing update for Projection Group
Browse files Browse the repository at this point in the history
currently when changing the scale or spacing this change is not taken into account until one explicitly marked the ProjGroup for recomputation
  • Loading branch information
donovaly authored and WandererFan committed Jun 15, 2020
1 parent 4db7676 commit d2bc4a6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
48 changes: 34 additions & 14 deletions src/Mod/TechDraw/App/DrawProjGroup.cpp
Expand Up @@ -72,10 +72,10 @@ DrawProjGroup::DrawProjGroup(void) :
GetGroup("Preferences")->GetGroup("Mod/TechDraw/General");
bool autoDist = hGrp->GetBool("AutoDist",true);

ADD_PROPERTY_TYPE(Source ,(0), group, App::Prop_None,"Shape to view");
ADD_PROPERTY_TYPE(Source, (0), group, App::Prop_None, "Shape to view");
Source.setScope(App::LinkScope::Global);
Source.setAllowExternal(true);
ADD_PROPERTY_TYPE(XSource ,(0),group,App::Prop_None,"External 3D Shape to view");
ADD_PROPERTY_TYPE(XSource, (0), group,App::Prop_None, "External 3D Shape to view");

ADD_PROPERTY_TYPE(Anchor, (0), group, App::Prop_None, "The root view to align projections with");
Anchor.setScope(App::LinkScope::Global);
Expand All @@ -84,19 +84,18 @@ DrawProjGroup::DrawProjGroup(void) :
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(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
Caption.setStatus(App::Property::Hidden,true);
ADD_PROPERTY_TYPE(AutoDistribute, (autoDist), agroup,
App::Prop_None, "Distribute views automatically or manually");
ADD_PROPERTY_TYPE(spacingX, (15), agroup, App::Prop_None, "If AutoDistribute is on, this is the horizontal \nspacing between the borders of views \n(if label width is not wider than the object)");
ADD_PROPERTY_TYPE(spacingY, (15), agroup, App::Prop_None, "If AutoDistribute is on, this is the vertical \nspacing between the borders of views");
Rotation.setStatus(App::Property::Hidden, true); //DPG does not rotate
Caption.setStatus(App::Property::Hidden, true);
}

DrawProjGroup::~DrawProjGroup()
{
}


//TODO: this duplicates code in DVP
std::vector<App::DocumentObject*> DrawProjGroup::getAllSources(void) const
{
Expand All @@ -121,6 +120,8 @@ void DrawProjGroup::onChanged(const App::Property* prop)
if (prop == &Scale) {
if (!m_lockScale) {
updateChildrenScale();
// the whole group needs to be recomputed after the different children to take the spacingX/Y into account
updateViews();
}
}

Expand All @@ -133,6 +134,10 @@ void DrawProjGroup::onChanged(const App::Property* prop)
updateChildrenSource();
}

if ((prop == &spacingX) || (prop == &spacingY)) {
updateViews();
}

if (prop == &LockPosition) {
updateChildrenLock();
}
Expand Down Expand Up @@ -312,8 +317,8 @@ QRectF DrawProjGroup::getRect() const //this is current rect, not potent
arrangeViewPointers(viewPtrs);
double width, height;
minimumBbViews(viewPtrs, width, height); //this is scaled!
double xSpace = spacingX.getValue() * 3.0 * std::max(1.0,getScale());
double ySpace = spacingY.getValue() * 2.0 * std::max(1.0,getScale());
double xSpace = spacingX.getValue() * 3.0 * std::max(1.0, getScale());
double ySpace = spacingY.getValue() * 2.0 * std::max(1.0, getScale());
double rectW = 0.0;
double rectH = 0.0;
if ( !(DrawUtil::fpCompare(width, 0.0) &&
Expand Down Expand Up @@ -656,9 +661,9 @@ Base::Vector3d DrawProjGroup::getXYPosition(const char *viewTypeCStr)
int viewIndex = getViewIndex(viewTypeCStr);

//TODO: bounding boxes do not take view orientation into account
// ie X&Y widths might be swapped on page
// i.e. X&Y widths might be swapped on page

// if (AutoDistribute.getValue()) {
// if (AutoDistribute.getValue()) {
if (true) {
std::vector<Base::Vector3d> position(idxCount);
int idx = 0;
Expand Down Expand Up @@ -961,7 +966,7 @@ void DrawProjGroup::updateChildrenScale(void)
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()) {
} else if(view->Scale.getValue() != Scale.getValue()) {
view->Scale.setValue(Scale.getValue());
view->recomputeFeature();
}
Expand Down Expand Up @@ -1010,6 +1015,21 @@ void DrawProjGroup::updateChildrenLock(void)
}
}

void DrawProjGroup::updateViews(void) {
// this is intended to update the views in general, e.g. when the spacing changed
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::updateChildrenScale - non DPGI entry in Views! %s\n",
getNameInDocument());
throw Base::TypeError("Error: projection in DPG list is not a DPGI!");
}
else // the views are OK
view->recomputeFeature();
}
}

void DrawProjGroup::updateChildrenEnforce(void)
{
for( const auto it : Views.getValues() ) {
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/TechDraw/App/DrawProjGroup.h
Expand Up @@ -62,6 +62,7 @@ class TechDrawExport DrawProjGroup : public TechDraw::DrawViewCollection

App::PropertyEnumeration ProjectionType;

/// Whether projcetion group view are automatically distributed or not
App::PropertyBool AutoDistribute;
/// Default horizontal spacing between adjacent views on Drawing, in mm
App::PropertyLength spacingX;
Expand Down Expand Up @@ -175,6 +176,7 @@ class TechDrawExport DrawProjGroup : public TechDraw::DrawViewCollection

void updateChildrenSource(void);
void updateChildrenLock(void);
void updateViews(void);
int getViewIndex(const char *viewTypeCStr) const;
int getDefProjConv(void) const;
Base::Vector3d dir2vec(gp_Dir d);
Expand Down

0 comments on commit d2bc4a6

Please sign in to comment.