Part Design: Workbench: commonize construciton of default part and body
This commit is contained in:
parent
f35871f6b9
commit
c161ffaf44
|
@ -102,6 +102,16 @@ Workbench::~Workbench()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void buildDefaultPartAndBody(const App::Document* doc)
|
||||||
|
{
|
||||||
|
// This adds both the base planes and the body
|
||||||
|
std::string PartName = doc->getUniqueObjectName("Part");
|
||||||
|
//// create a PartDesign Part for now, can be later any kind of Part or an empty one
|
||||||
|
Gui::Command::addModule(Gui::Command::Doc, "PartDesignGui");
|
||||||
|
Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().Tip = App.activeDocument().addObject('App::Part','%s')", PartName.c_str());
|
||||||
|
Gui::Command::doCommand(Gui::Command::Doc, "PartDesignGui.setUpPart(App.activeDocument().%s)", PartName.c_str());
|
||||||
|
Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('Part',App.activeDocument().%s)", PartName.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
PartDesign::Body *Workbench::setUpPart(const App::Part *part)
|
PartDesign::Body *Workbench::setUpPart(const App::Part *part)
|
||||||
{
|
{
|
||||||
|
@ -183,12 +193,10 @@ void Workbench::_doMigration(const App::Document* doc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always create at least the first body, even if the document is empty
|
// Always create at least the first body, even if the document is empty
|
||||||
// This adds both the base planes and the body
|
buildDefaultPartAndBody(doc);
|
||||||
Gui::Command::runCommand(Gui::Command::Doc, "FreeCADGui.runCommand('PartDesign_Body')");
|
|
||||||
PartDesign::Body *activeBody = Gui::Application::Instance->activeView()->getActiveObject<PartDesign::Body*>(PDBODYKEY);
|
PartDesign::Body *activeBody = Gui::Application::Instance->activeView()->getActiveObject<PartDesign::Body*>(PDBODYKEY);
|
||||||
assert(activeBody);
|
assert(activeBody);
|
||||||
|
|
||||||
|
|
||||||
// Create one Body for every root and put the appropriate features into it
|
// Create one Body for every root and put the appropriate features into it
|
||||||
for (std::vector<App::DocumentObject*>::iterator r = roots.begin(); r != roots.end(); r++) {
|
for (std::vector<App::DocumentObject*>::iterator r = roots.begin(); r != roots.end(); r++) {
|
||||||
if (r != roots.begin()) {
|
if (r != roots.begin()) {
|
||||||
|
@ -349,16 +357,8 @@ void Workbench::_switchToDocument(const App::Document* doc)
|
||||||
if (!doc->Tip.getValue())
|
if (!doc->Tip.getValue())
|
||||||
{
|
{
|
||||||
if (doc->countObjects() == 0){
|
if (doc->countObjects() == 0){
|
||||||
std::string PartName = doc->getUniqueObjectName("Part");
|
buildDefaultPartAndBody(doc);
|
||||||
//// create a PartDesign Part for now, can be later any kind of Part or an empty one
|
|
||||||
Gui::Command::addModule(Gui::Command::Doc, "PartDesignGui");
|
|
||||||
Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().Tip = App.activeDocument().addObject('App::Part','%s')", PartName.c_str());
|
|
||||||
Gui::Command::doCommand(Gui::Command::Doc, "PartDesignGui.setUpPart(App.activeDocument().%s)", PartName.c_str());
|
|
||||||
Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('Part',App.activeDocument().%s)", PartName.c_str());
|
|
||||||
|
|
||||||
activeBody = Gui::Application::Instance->activeView()->getActiveObject<PartDesign::Body*>(PDBODYKEY);
|
activeBody = Gui::Application::Instance->activeView()->getActiveObject<PartDesign::Body*>(PDBODYKEY);
|
||||||
|
|
||||||
// body have to be created
|
|
||||||
assert(activeBody);
|
assert(activeBody);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user