Create standard XY, XZ, YZ planes when running the PartDesign_Body command if they don't exist yet

This commit is contained in:
jrheinlaender 2013-03-31 17:43:37 +04:30 committed by Stefan Tröger
parent acd88878af
commit 7dee0b7018
3 changed files with 58 additions and 17 deletions

View File

@ -41,6 +41,7 @@
#include <algorithm>
#include <App/DocumentObjectGroup.h>
#include <App/Plane.h>
#include <Gui/Application.h>
#include <Gui/Command.h>
#include <Gui/Control.h>
@ -100,10 +101,48 @@ CmdPartDesignBody::CmdPartDesignBody()
void CmdPartDesignBody::activated(int iMsg)
{
std::string FeatName = getUniqueObjectName("Body");
openCommand("Add a body feature");
doCommand(Doc,"App.activeDocument().addObject('PartDesign::Body','%s')",FeatName.c_str());
std::string FeatName = getUniqueObjectName("Body");
// add the standard planes at the root of the feature tree
// first check if they already exist
// FIXME: If the user renames them, they won't be found...
bool found = false;
std::vector<App::DocumentObject*> planes = getDocument()->getObjectsOfType(App::Plane::getClassTypeId());
for (std::vector<App::DocumentObject*>::const_iterator p = planes.begin(); p != planes.end(); p++) {
if ((strcmp("Body_PlaneXY", (*p)->getNameInDocument()) == 0) ||
(strcmp("Body_PlaneYZ", (*p)->getNameInDocument()) == 0) ||
(strcmp("Body_PlaneXZ", (*p)->getNameInDocument()) == 0)) {
found = true;
break;
}
}
if (!found) {
// Add the planes ...
doCommand(Doc,"App.activeDocument().addObject('App::Plane','Body_PlaneXY')");
doCommand(Doc,"App.activeDocument().ActiveObject.Label = 'XY-Plane'");
doCommand(Doc,"App.activeDocument().addObject('App::Plane','Body_PlaneYZ')");
doCommand(Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(0,1,0),90))");
doCommand(Doc,"App.activeDocument().ActiveObject.Label = 'YZ-Plane'");
doCommand(Doc,"App.activeDocument().addObject('App::Plane','Body_PlaneXZ')");
doCommand(Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(1,0,0),90))");
doCommand(Doc,"App.activeDocument().ActiveObject.Label = 'XZ-Plane'");
// ... and put them in the 'Origin' group
doCommand(Doc,"App.activeDocument().addObject('App::DocumentObjectGroup','Origin')");
doCommand(Doc,"App.activeDocument().Origin.addObject(App.activeDocument().getObject('Body_PlaneXY'))");
doCommand(Doc,"App.activeDocument().Origin.addObject(App.activeDocument().getObject('Body_PlaneYZ'))");
doCommand(Doc,"App.activeDocument().Origin.addObject(App.activeDocument().getObject('Body_PlaneXZ'))");
// TODO: Fold the group (is that possible through the Python interface?)
}
// add the Body feature itself, and make it active
doCommand(Doc,"App.activeDocument().addObject('PartDesign::Body','%s')",FeatName.c_str());
doCommand(Gui,"PartDesignGui.setActivePart(App.ActiveDocument.ActiveObject)");
// Make the "Create sketch" prompt appear in the task panel
doCommand(Gui,"Gui.Selection.addSelection(App.ActiveDocument.ActiveObject)");
updateActive();
}
bool CmdPartDesignBody::isActive(void)
@ -960,7 +999,7 @@ bool CmdPartDesignDraft::isActive(void)
//===========================================================================
// Common functions for all Transformed features
//===========================================================================
;;;
void prepareTransformed(Gui::Command* cmd, const std::string& which,
std::vector<App::DocumentObject*>& features, std::string& FeatName,
std::vector<std::string>& selList, std::string& selNames)

View File

@ -153,7 +153,9 @@ void Workbench::activated()
// make the previously used active Body active again
PartDesign::Body* activeBody = NULL;
std::vector<App::DocumentObject*> bodies = App::GetApplication().getActiveDocument()->getObjectsOfType(PartDesign::Body::getClassTypeId());
App::Document* activeDocument = App::GetApplication().getActiveDocument();
if (activeDocument != NULL) {
std::vector<App::DocumentObject*> bodies = activeDocument->getObjectsOfType(PartDesign::Body::getClassTypeId());
for (std::vector<App::DocumentObject*>::const_iterator b = bodies.begin(); b != bodies.end(); b++) {
PartDesign::Body* body = static_cast<PartDesign::Body*>(*b);
if (body->IsActive.getValue()) {
@ -161,9 +163,12 @@ void Workbench::activated()
break;
}
}
// If there is only one body, make it active
if ((activeBody == NULL) && (bodies.size() == 1))
activeBody = static_cast<PartDesign::Body*>(bodies.front());
}
if (activeBody != NULL) {
Gui::Command::doCommand(Gui::Command::Doc,"import PartDesignGui");

View File

@ -21,10 +21,7 @@
#* *
#***************************************************************************
import FreeCADGui, PartDesignGui
import FreeCADGui
FreeCADGui.activateWorkbench("PartDesignWorkbench")
App.newDocument()
App.ActiveDocument.addObject("PartDesign::Body")
PartDesignGui.setActivePart(App.ActiveDocument.ActiveObject)
# Make the "Create sketch" prompt appear in the task panel
Gui.Selection.addSelection(App.ActiveDocument.ActiveObject)
FreeCADGui.runCommand('PartDesign_Body')