From 45844c2fd23bd3d6ebd0b549adaaaa57499921d3 Mon Sep 17 00:00:00 2001 From: blobfish Date: Mon, 4 May 2015 14:49:12 -0400 Subject: [PATCH] Part Design: Gui: Workbench: assign activePart and activeBody when doc has tip --- src/Mod/PartDesign/Gui/Workbench.cpp | 76 +++++++--------------------- 1 file changed, 19 insertions(+), 57 deletions(-) diff --git a/src/Mod/PartDesign/Gui/Workbench.cpp b/src/Mod/PartDesign/Gui/Workbench.cpp index d3ba901be..a33ae9157 100644 --- a/src/Mod/PartDesign/Gui/Workbench.cpp +++ b/src/Mod/PartDesign/Gui/Workbench.cpp @@ -350,7 +350,6 @@ void Workbench::_switchToDocument(const App::Document* doc) if (doc == NULL) return; PartDesign::Body* activeBody = NULL; - App::Part* activePart = NULL; std::vector bodies = doc->getObjectsOfType(PartDesign::Body::getClassTypeId()); // No tip, so build up structure or migrate @@ -370,70 +369,33 @@ void Workbench::_switchToDocument(const App::Document* doc) } else { - activeBody = Gui::Application::Instance->activeView()->getActiveObject(PDBODYKEY); - assert(activeBody); - activePart = Gui::Application::Instance->activeView()->getActiveObject("Part"); - assert(activePart); - - // document change not implemented yet - assert(activePart->getDocument() == doc); - - //// Find active body - //for (std::vector::const_iterator b = bodies.begin(); b != bodies.end(); b++) { - // PartDesign::Body* body = static_cast(*b); - // if (body->IsActive.getValue()) { - // activeBody = body; - // break; - // } - //} - - //// Do the base planes exist in this document? - //bool found = false; - //std::vector planes = doc->getObjectsOfType(App::Plane::getClassTypeId()); - //for (std::vector::const_iterator p = planes.begin(); p != planes.end(); p++) { - // for (unsigned i = 0; i < 3; i++) { - // if (strcmp(PartDesignGui::BaseplaneNames[i], (*p)->getNameInDocument()) == 0) { - // found = true; - // break; - // } - // } - // if (found) break; - //} - - //if (!found) { - // // Add the planes ... - // Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", PartDesignGui::BaseplaneNames[0]); - // Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("XY-Plane").toStdString().c_str()); - // Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", PartDesignGui::BaseplaneNames[1]); - // Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(1,0,0),90))"); - // Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("XZ-Plane").toStdString().c_str()); - // Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", PartDesignGui::BaseplaneNames[2]); - // Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(0,1,0),90))"); - // Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("YZ-Plane").toStdString().c_str()); - // // ... and put them in the 'Origin' group - // Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::DocumentObjectGroup','%s')", QObject::tr("Origin").toStdString().c_str()); - // for (unsigned i = 0; i < 3; i++) - // Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().Origin.addObject(App.activeDocument().getObject('%s'))", PartDesignGui::BaseplaneNames[i]); - // // TODO: Fold the group (is that possible through the Python interface?) - //} + App::Part *docPart = dynamic_cast(doc->Tip.getValue()); + assert(docPart); + App::Part *viewPart = Gui::Application::Instance->activeView()->getActiveObject("Part"); + if (viewPart != docPart) + Gui::Application::Instance->activeView()->setActiveObject(docPart, "Part"); + if (docPart->countObjectsOfType(PartDesign::Body::getClassTypeId()) < 1) + setUpPart(docPart); + + PartDesign::Body *tempBody = dynamic_cast (docPart->getObjectsOfType(PartDesign::Body::getClassTypeId()).front()); + assert(tempBody); + PartDesign::Body *viewBody = Gui::Application::Instance->activeView()->getActiveObject(PDBODYKEY); + activeBody = viewBody; + if (!viewBody) + activeBody = tempBody; + else if (!docPart->hasObject(viewBody)) + activeBody = tempBody; + + if (activeBody != viewBody) + Gui::Application::Instance->activeView()->setActiveObject(activeBody, PDBODYKEY); } - //// If there is only one body, make it active - //if ((activeBody == NULL) && (bodies.size() == 1)) - // activeBody = static_cast(bodies.front()); - - //// add the non PartDesign feature group to the Part - //if( groupCreated && doc->Tip.getValue() != NULL) - // Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().Tip.addObject(App.activeDocument().NonBodyFeatures)"); - if (activeBody == NULL) { QMessageBox::critical(Gui::getMainWindow(), QObject::tr("Could not create body"), QObject::tr("No body was found in this document, and none could be created. Please report this bug." "We recommend you do not use this document with the PartDesign workbench until the bug has been fixed." )); } - - std::string bodyName = activeBody->getNameInDocument(); } void Workbench::slotActiveDocument(const Gui::Document& Doc)