Fix segfault on missing Anchor view
- test script did not create Anchor(Front) view. DPG/DVP did not handle missing Anchor properly
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -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();
|
||||
@@ -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
|
||||
@@ -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!).
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user