Skip to content

Commit

Permalink
Fix segfault on missing Anchor view
Browse files Browse the repository at this point in the history
- test script did not create Anchor(Front) view.  DPG/DVP did not
  handle missing Anchor properly
  • Loading branch information
WandererFan authored and wwmayer committed Mar 7, 2019
1 parent 198c225 commit 7189b8e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
16 changes: 9 additions & 7 deletions src/Mod/TechDraw/App/DrawProjGroup.cpp
Expand Up @@ -144,7 +144,7 @@ void DrawProjGroup::onChanged(const App::Property* prop)

App::DocumentObjectExecReturn *DrawProjGroup::execute(void)
{
Base::Console().Message("DPG::execute()\n");
// Base::Console().Message("DPG::execute()\n");
if (!keepUpdated()) {
return App::DocumentObject::StdReturn;
}
Expand All @@ -162,13 +162,13 @@ App::DocumentObjectExecReturn *DrawProjGroup::execute(void)

App::DocumentObject* docObj = Anchor.getValue();
if (docObj == nullptr) {
//no anchor yet. Should we create 1 here?
//no anchor yet. nothing to do.
return DrawViewCollection::execute();
}

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

for (auto& item: getViewsAsDPGI()) {
item->autoPosition();
Expand Down Expand Up @@ -366,7 +366,6 @@ App::DocumentObject * DrawProjGroup::addProjection(const char *viewProjType)
DrawProjGroupItem *view( nullptr );
std::pair<Base::Vector3d,Base::Vector3d> vecs;


if ( checkViewProjType(viewProjType) && !hasProjection(viewProjType) ) {
std::string FeatName = getDocument()->getUniqueObjectName("ProjItem");
auto docObj( getDocument()->addObject( "TechDraw::DrawProjGroupItem", //add to Document
Expand All @@ -384,7 +383,6 @@ App::DocumentObject * DrawProjGroup::addProjection(const char *viewProjType)
view->RotationVector.setValue(vecs.second);
view->recomputeFeature();
} else { //Front
//where do direction & Rotation Vector get set for front??? from cmd::newDPG
Anchor.setValue(view);
Anchor.purgeTouched();
view->LockPosition.setValue(true); //lock "Front" position within DPG (note not Page!).
Expand Down Expand Up @@ -462,6 +460,10 @@ std::pair<Base::Vector3d,Base::Vector3d> DrawProjGroup::getDirsFromFront(std::st

Base::Vector3d projDir, rotVec;
DrawProjGroupItem* anch = getAnchor();
if (anch == nullptr) {
Base::Console().Warning("DPG::getDirsFromFront - %s - No Anchor!\n",Label.getValue());
throw Base::RuntimeError("Project Group missing Anchor projection item");
}

Base::Vector3d dirAnch = anch->Direction.getValue();
Base::Vector3d rotAnch = anch->RotationVector.getValue();
Expand Down
12 changes: 10 additions & 2 deletions src/Mod/TechDraw/App/DrawViewPart.cpp
Expand Up @@ -239,10 +239,18 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
if (!keepUpdated()) {
return App::DocumentObject::StdReturn;
}

const std::vector<App::DocumentObject*>& links = Source.getValues();
if (links.empty()) {
Base::Console().Log("DVP::execute - %s - No Sources - creation time?\n",getNameInDocument());
return App::DocumentObject::StdReturn;
}

TopoDS_Shape shape = getSourceShape();
TopoDS_Shape shape = getSourceShape(); //if shape is null, it is probably obj creation time.
if (shape.IsNull()) {
return new App::DocumentObjectExecReturn("DVP - Linked shape object is invalid");
Base::Console().Log("DVP::execute - %s - source shape is invalid - creation time?\n",
getNameInDocument());
return App::DocumentObject::StdReturn;
}

gp_Pnt inputCenter;
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/TechDraw/Gui/Command.cpp
Expand Up @@ -548,8 +548,8 @@ void CmdTechDrawProjGroup::activated(int iMsg)

App::DocumentObject *docObj = getDocument()->getObject(multiViewName.c_str());
auto multiView( static_cast<TechDraw::DrawProjGroup *>(docObj) );
doCommand(Doc,"App.activeDocument().%s.addProjection('Front')",multiViewName.c_str());
multiView->Source.setValues(shapes);
doCommand(Doc,"App.activeDocument().%s.addProjection('Front')",multiViewName.c_str());

if (subFound) {
std::pair<Base::Vector3d,Base::Vector3d> dirs = DrawGuiUtil::getProjDirFromFace(partFeat,faceName);
Expand Down
8 changes: 8 additions & 0 deletions src/Mod/TechDraw/TDTest/DProjGroupTest.py
Expand Up @@ -42,9 +42,17 @@ def DProjGroupTest():
print("making a projection group")
group = FreeCAD.ActiveDocument.addObject('TechDraw::DrawProjGroup','ProjGroup')
rc = page.addView(group)
print("Group created")
group.Source = [fusion]

print("adding views")
frontView = group.addProjection("Front") ##need an Anchor
print("added Front")

#update group
group.Anchor.Direction = FreeCAD.Vector(0,0,1)
group.Anchor.RotationVector = FreeCAD.Vector(1,0,0)

leftView = group.addProjection("Left")
print("added Left")
topView = group.addProjection("Top")
Expand Down

0 comments on commit 7189b8e

Please sign in to comment.