Assembly: Rename to setActiveBody and make link indeipendant Part initialization
This commit is contained in:
parent
271bb65cbd
commit
dc4fdc2c53
|
@ -31,7 +31,7 @@
|
|||
#include "GeoFeatureGroupPy.h"
|
||||
#include "FeaturePythonPyImp.h"
|
||||
|
||||
#define new DEBUG_CLIENTBLOCK
|
||||
// #define new DEBUG_CLIENTBLOCK
|
||||
using namespace App;
|
||||
|
||||
|
||||
|
@ -194,4 +194,4 @@ template<> PyObject* App::GeoFeatureGroupPython::getPyObject(void) {
|
|||
|
||||
// explicit template instantiation
|
||||
template class AppExport FeaturePythonT<App::GeoFeatureGroup>;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,11 @@
|
|||
#endif
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <App/Plane.h>
|
||||
|
||||
#include "Part.h"
|
||||
#include "PartPy.h"
|
||||
|
||||
//#define new DEBUG_CLIENTBLOCK
|
||||
using namespace App;
|
||||
|
||||
|
@ -36,13 +39,17 @@ using namespace App;
|
|||
PROPERTY_SOURCE(App::Part, App::GeoFeatureGroup)
|
||||
|
||||
|
||||
|
||||
//===========================================================================
|
||||
// Feature
|
||||
//===========================================================================
|
||||
|
||||
|
||||
const char* Part::BaseplaneTypes[3] = {"XY-Plane", "XZ-Plane", "YZ-Plane"};
|
||||
|
||||
Part::Part(void)
|
||||
{
|
||||
ADD_PROPERTY(Member,(0));
|
||||
ADD_PROPERTY(Type,(""));
|
||||
}
|
||||
|
||||
Part::~Part(void)
|
||||
|
@ -59,6 +66,7 @@ PyObject *Part::getPyObject()
|
|||
return Py::new_reference_to(PythonObject);
|
||||
}
|
||||
|
||||
|
||||
// Python feature ---------------------------------------------------------
|
||||
|
||||
// Not quit sure yet makeing Part derivable in Python is good Idea!
|
||||
|
|
|
@ -40,7 +40,7 @@ class AppExport Part : public App::GeoFeatureGroup
|
|||
PROPERTY_HEADER(App::Part);
|
||||
|
||||
public:
|
||||
PropertyLinkList Member;
|
||||
PropertyString Type;
|
||||
|
||||
/// Constructor
|
||||
Part(void);
|
||||
|
@ -54,7 +54,7 @@ public:
|
|||
|
||||
virtual PyObject *getPyObject(void);
|
||||
|
||||
|
||||
static const char* BaseplaneTypes[3];
|
||||
};
|
||||
|
||||
//typedef App::FeaturePythonT<Part> PartPython;
|
||||
|
|
|
@ -41,6 +41,7 @@ PROPERTY_SOURCE(App::Plane, App::GeoFeature)
|
|||
|
||||
Plane::Plane(void)
|
||||
{
|
||||
ADD_PROPERTY(PlaneType,(""));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,9 @@ public:
|
|||
/// Constructor
|
||||
Plane(void);
|
||||
virtual ~Plane();
|
||||
/// additional information about the plane usage (e.g. "BasePlane-xy" in a Part)
|
||||
PropertyString PlaneType;
|
||||
|
||||
|
||||
/// returns the type name of the ViewProvider
|
||||
virtual const char* getViewProviderName(void) const {
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#endif
|
||||
|
||||
#include <App/Part.h>
|
||||
#include <App/Plane.h>
|
||||
#include <App/Document.h>
|
||||
|
||||
/// Here the FreeCAD includes sorted by Base,App,Gui......
|
||||
|
@ -51,11 +52,9 @@ PROPERTY_SOURCE(Gui::ViewProviderPart, Gui::ViewProviderGeometryObject)
|
|||
/**
|
||||
* Creates the view provider for an object group.
|
||||
*/
|
||||
ViewProviderPart::ViewProviderPart() : visible(false)
|
||||
ViewProviderPart::ViewProviderPart()
|
||||
{
|
||||
#if 0
|
||||
setDefaultMode(SO_SWITCH_ALL);
|
||||
#endif
|
||||
ADD_PROPERTY(Workbench,("PartDesignWorkbench"));
|
||||
}
|
||||
|
||||
ViewProviderPart::~ViewProviderPart()
|
||||
|
@ -81,6 +80,17 @@ void ViewProviderPart::updateData(const App::Property* prop)
|
|||
|
||||
}
|
||||
|
||||
|
||||
bool ViewProviderPart::doubleClicked(void)
|
||||
{
|
||||
if(Workbench.getValue() != "")
|
||||
// assure the PartDesign workbench
|
||||
Gui::Command::assureWorkbench( Workbench.getValue() );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> ViewProviderPart::getDisplayModes(void) const
|
||||
{
|
||||
// empty
|
||||
|
@ -131,6 +141,51 @@ QIcon ViewProviderPart::getIcon() const
|
|||
return groupIcon;
|
||||
}
|
||||
|
||||
void ViewProviderPart::setUpPart(const App::Part *part)
|
||||
{
|
||||
// add the standard planes at the root of the Part
|
||||
// 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 = part->getObjectsOfType(App::Plane::getClassTypeId());
|
||||
for (std::vector<App::DocumentObject*>::const_iterator p = planes.begin(); p != planes.end(); p++) {
|
||||
for (unsigned i = 0; i < 3; i++) {
|
||||
if (strcmp(App::Part::BaseplaneTypes[i], dynamic_cast<App::Plane*>(*p)->PlaneType.getValue()) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) break;
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
// ... and put them in the 'Origin' group
|
||||
//Gui::Command::doCommand(Gui::Command::Doc,"OGroup = App.activeDocument().addObject('App::DocumentObjectGroup','%s')", "Origin");
|
||||
//Gui::Command::doCommand(Gui::Command::Doc,"OGroup.Label = '%s'", QObject::tr("Origin").toStdString().c_str());
|
||||
// Add the planes ...
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", App::Part::BaseplaneTypes[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().%s.addObject(App.activeDocument().ActiveObject)", part->getNameInDocument());
|
||||
//Gui::Command::doCommand(Gui::Command::Doc,"OGroup.addObject(App.activeDocument().ActiveObject)");
|
||||
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", App::Part::BaseplaneTypes[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().%s.addObject(App.activeDocument().ActiveObject)", part->getNameInDocument());
|
||||
//Gui::Command::doCommand(Gui::Command::Doc,"OGroup.addObject(App.activeDocument().ActiveObject)");
|
||||
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", App::Part::BaseplaneTypes[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());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", part->getNameInDocument());
|
||||
//Gui::Command::doCommand(Gui::Command::Doc,"OGroup.addObject(App.activeDocument().ActiveObject)");
|
||||
|
||||
//Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(OGroup)", part->getNameInDocument());
|
||||
// TODO: Fold the group (is that possible through the Python interface?)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Python feature -----------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -28,6 +28,11 @@
|
|||
#include "ViewProviderGeoFeatureGroup.h"
|
||||
#include "ViewProviderPythonFeature.h"
|
||||
|
||||
#include <App/PropertyStandard.h>
|
||||
#include <App/Part.h>
|
||||
|
||||
|
||||
|
||||
namespace Gui {
|
||||
|
||||
class GuiExport ViewProviderPart : public ViewProviderGeoFeatureGroup
|
||||
|
@ -40,11 +45,17 @@ public:
|
|||
/// destructor.
|
||||
virtual ~ViewProviderPart();
|
||||
|
||||
/// Name of the workbench which created that Part
|
||||
App::PropertyString Workbench;
|
||||
|
||||
void attach(App::DocumentObject *pcObject);
|
||||
void updateData(const App::Property*);
|
||||
void Restore(Base::XMLReader &reader);
|
||||
QIcon getIcon(void) const;
|
||||
/// returns a list of all possible modes
|
||||
|
||||
virtual bool doubleClicked(void);
|
||||
|
||||
std::vector<std::string> getDisplayModes(void) const;
|
||||
void hide(void);
|
||||
void show(void);
|
||||
|
@ -57,14 +68,15 @@ public:
|
|||
/// get called if the user drops some objects
|
||||
//virtual void drop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos);
|
||||
|
||||
/// helper to set up the standard content of a Part Object
|
||||
static void setUpPart(const App::Part *part);
|
||||
protected:
|
||||
/// get called by the container whenever a property has been changed
|
||||
void onChanged(const App::Property* prop);
|
||||
void getViewProviders(std::vector<ViewProviderDocumentObject*>&) const;
|
||||
|
||||
private:
|
||||
bool visible; // helper variable
|
||||
std::vector<ViewProvider*> nodes;
|
||||
|
||||
};
|
||||
|
||||
typedef ViewProviderPythonFeatureT<ViewProviderPart> ViewProviderPartPython;
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#include <Base/PyObjectBase.h>
|
||||
#include <Base/Console.h>
|
||||
|
||||
#include <App/PartPy.h>
|
||||
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/ViewProviderDocumentObject.h>
|
||||
|
@ -36,6 +38,8 @@
|
|||
#include <Mod/PartDesign/App/BodyPy.h>
|
||||
|
||||
#include "ViewProviderBody.h"
|
||||
#include "Workbench.h"
|
||||
|
||||
|
||||
namespace PartDesignGui {
|
||||
|
||||
|
@ -50,7 +54,7 @@ const char* BaseplaneNames[3] = {"BaseplaneXY", "BaseplaneXZ", "BaseplaneYZ"};
|
|||
|
||||
}
|
||||
|
||||
static PyObject * setActivePart(PyObject *self, PyObject *args)
|
||||
static PyObject * setActiveBody(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *object=0;
|
||||
if (PyArg_ParseTuple(args,"|O!",&(PartDesign::BodyPy::Type), &object)&& object) {
|
||||
|
@ -78,7 +82,7 @@ static PyObject * setActivePart(PyObject *self, PyObject *args)
|
|||
|
||||
Py_Return;
|
||||
}
|
||||
static PyObject * getActivePart(PyObject *, PyObject *)
|
||||
static PyObject * getActiveBody(PyObject *, PyObject *)
|
||||
{
|
||||
if (PartDesignGui::ActivePartObject == NULL) {
|
||||
return Py::_None();
|
||||
|
@ -87,13 +91,35 @@ static PyObject * getActivePart(PyObject *, PyObject *)
|
|||
return PartDesignGui::ActivePartObject->getPyObject();
|
||||
}
|
||||
|
||||
void setUpPart(App::Part *part);
|
||||
|
||||
static PyObject * setUpPart(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *object=0;
|
||||
if (! PyArg_ParseTuple(args,"O!",&(App::PartPy::Type), &object) )
|
||||
return NULL;
|
||||
|
||||
|
||||
App::Part* part = static_cast<App::PartPy*>(object)->getPartPtr();
|
||||
// Should be set!
|
||||
assert(part);
|
||||
|
||||
PartDesignGui::Workbench::setUpPart(part);
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
|
||||
/* registration table */
|
||||
struct PyMethodDef Assembly_methods[] = {
|
||||
{"setActivePart" ,setActivePart ,METH_VARARGS,
|
||||
"setActivePart(BodyObject) -- Set the PartBody object in work."},
|
||||
{"setActiveBody" ,setActiveBody ,METH_VARARGS,
|
||||
"setActiveBody(BodyObject) -- Set the PartBody object in work."},
|
||||
|
||||
{"getActivePart" ,getActivePart ,METH_NOARGS,
|
||||
"getActivePart() -- Get the PartBody object in work."},
|
||||
{"setActiveBody" ,getActiveBody ,METH_NOARGS,
|
||||
"setActiveBody() -- Get the PartBody object in work."},
|
||||
|
||||
{"setUpPart" ,setUpPart ,METH_VARARGS,
|
||||
"setUpPart(Part) -- Sets a empty part object up for usage in PartDesign."},
|
||||
|
||||
{NULL, NULL} /* end of table marker */
|
||||
};
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#include <Base/PyObjectBase.h>
|
||||
#include <Base/Console.h>
|
||||
|
||||
#include <App/PartPy.h>
|
||||
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/ViewProviderDocumentObject.h>
|
||||
|
@ -36,6 +38,8 @@
|
|||
#include <Mod/PartDesign/App/BodyPy.h>
|
||||
|
||||
#include "ViewProviderBody.h"
|
||||
#include "Workbench.h"
|
||||
|
||||
|
||||
namespace PartDesignGui {
|
||||
|
||||
|
@ -50,7 +54,7 @@ const char* BaseplaneNames[3] = {"BaseplaneXY", "BaseplaneXZ", "BaseplaneYZ"};
|
|||
|
||||
}
|
||||
|
||||
static PyObject * setActivePart(PyObject *self, PyObject *args)
|
||||
static PyObject * setActiveBody(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *object=0;
|
||||
if (PyArg_ParseTuple(args,"|O!",&(PartDesign::BodyPy::Type), &object)&& object) {
|
||||
|
@ -78,10 +82,12 @@ static PyObject * setActivePart(PyObject *self, PyObject *args)
|
|||
|
||||
Py_Return;
|
||||
}
|
||||
<<<<<<< 35072e8d22a22eaf711a74958d47b351d55292ae:src/Mod/Assembly/App/AppAssemblyPy.cpp
|
||||
<<<<<<< 394f4c51924312cf9cfcce09be5c3ba696a82cf4:src/Mod/Assembly/App/AppAssemblyPy.cpp
|
||||
static PyObject * getActivePart(PyObject *, PyObject *)
|
||||
=======
|
||||
|
||||
static PyObject * getActivePart(PyObject *, PyObject *)
|
||||
static PyObject * getActiveBody(PyObject *, PyObject *)
|
||||
>>>>>>> Assembly: Rename to setActiveBody and make link indeipendant Part initialization:src/Mod/PartDesign/Gui/AppPartDesignGuiPy.cpp
|
||||
{
|
||||
if (PartDesignGui::ActivePartObject == NULL) {
|
||||
return Py::_None();
|
||||
|
@ -90,18 +96,41 @@ static PyObject * getActivePart(PyObject *, PyObject *)
|
|||
return PartDesignGui::ActivePartObject->getPyObject();
|
||||
}
|
||||
|
||||
>>>>>>> getActivePart() python function as complement to setActivePart():src/Mod/PartDesign/Gui/AppPartDesignGuiPy.cpp
|
||||
void setUpPart(App::Part *part);
|
||||
|
||||
static PyObject * setUpPart(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *object=0;
|
||||
if (! PyArg_ParseTuple(args,"O!",&(App::PartPy::Type), &object) )
|
||||
return NULL;
|
||||
|
||||
|
||||
App::Part* part = static_cast<App::PartPy*>(object)->getPartPtr();
|
||||
// Should be set!
|
||||
assert(part);
|
||||
|
||||
PartDesignGui::Workbench::setUpPart(part);
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
|
||||
/* registration table */
|
||||
<<<<<<< 394f4c51924312cf9cfcce09be5c3ba696a82cf4:src/Mod/Assembly/App/AppAssemblyPy.cpp
|
||||
struct PyMethodDef Assembly_methods[] = {
|
||||
{"setActivePart" ,setActivePart ,METH_VARARGS,
|
||||
"setActivePart(BodyObject) -- Set the PartBody object in work."},
|
||||
|
||||
<<<<<<< 35072e8d22a22eaf711a74958d47b351d55292ae:src/Mod/Assembly/App/AppAssemblyPy.cpp
|
||||
{NULL, NULL} /* end of table marker */
|
||||
=======
|
||||
{"getActivePart" ,getActivePart ,METH_NOARGS,
|
||||
"getActivePart() -- Get the PartBody object in work."},
|
||||
struct PyMethodDef PartDesignGui_Import_methods[] = {
|
||||
{"setActiveBody" ,setActiveBody ,METH_VARARGS,
|
||||
"setActiveBody(BodyObject) -- Set the PartBody object in work."},
|
||||
|
||||
{NULL, NULL} /* end of table marker */
|
||||
>>>>>>> getActivePart() python function as complement to setActivePart():src/Mod/PartDesign/Gui/AppPartDesignGuiPy.cpp
|
||||
{"setActiveBody" ,getActiveBody ,METH_NOARGS,
|
||||
"setActiveBody() -- Get the PartBody object in work."},
|
||||
>>>>>>> Assembly: Rename to setActiveBody and make link indeipendant Part initialization:src/Mod/PartDesign/Gui/AppPartDesignGuiPy.cpp
|
||||
|
||||
{"setUpPart" ,setUpPart ,METH_VARARGS,
|
||||
"setUpPart(Part) -- Sets a empty part object up for usage in PartDesign."},
|
||||
|
||||
{NULL, NULL} /* end of table marker */
|
||||
};
|
||||
|
|
|
@ -25,7 +25,6 @@ set(AssemblyGui_LIBS
|
|||
#${ODE_LIBRARIES}
|
||||
Assembly
|
||||
PartGui
|
||||
PartDesignGui
|
||||
FreeCADGui
|
||||
)
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
#include <Gui/Command.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/DlgCheckableMessageBox.h>
|
||||
#include <Mod/PartDesign/Gui/Workbench.h>
|
||||
#include <App/Part.h>
|
||||
#include "Workbench.h"
|
||||
|
||||
|
@ -57,8 +56,11 @@ void switchToDocument(const App::Document* doc)
|
|||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Items = App.activeDocument().%s",ProductName.c_str(),RefName.c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Part','%s')",PartName.c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Item = App.activeDocument().%s",RefName.c_str(),PartName.c_str());
|
||||
PartDesignGui::Workbench::setUpPart(dynamic_cast<App::Part *>( doc->getObject(PartName.c_str())) );
|
||||
|
||||
Gui::Command::addModule(Gui::Command::Gui,"AssemblyGui");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"AssemblyGui.setActiveAssembly(App.activeDocument().%s)",ProductName.c_str());
|
||||
// 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,"PartDesignGui.setUpPart(App.activeDocument().%s)",PartName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ void CmdPartDesignBody::activated(int iMsg)
|
|||
//doCommand(Doc,"App.activeDocument().%s.Model = []",FeatName.c_str());
|
||||
//doCommand(Doc,"App.activeDocument().%s.Tip = None",FeatName.c_str());
|
||||
addModule(Gui,"PartDesignGui"); // import the Gui module only once a session
|
||||
doCommand(Gui,"PartDesignGui.setActivePart(App.ActiveDocument.%s)", FeatName.c_str());
|
||||
doCommand(Gui,"PartDesignGui.setActiveBody(App.ActiveDocument.%s)", FeatName.c_str());
|
||||
// Make the "Create sketch" prompt appear in the task panel
|
||||
doCommand(Gui,"Gui.Selection.clearSelection()");
|
||||
doCommand(Gui,"Gui.Selection.addSelection(App.ActiveDocument.%s)", FeatName.c_str());
|
||||
|
@ -174,7 +174,7 @@ void CmdPartDesignMoveTip::activated(int iMsg)
|
|||
// Switch to other body
|
||||
pcActiveBody = static_cast<PartDesign::Body*>(Part::BodyBase::findBodyOf(selFeature));
|
||||
if (pcActiveBody != NULL)
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"PartDesignGui.setActivePart(App.activeDocument().%s)",
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"PartDesignGui.setActiveBody(App.activeDocument().%s)",
|
||||
pcActiveBody->getNameInDocument());
|
||||
else
|
||||
return;
|
||||
|
@ -244,7 +244,7 @@ void CmdPartDesignDuplicateSelection::activated(int iMsg)
|
|||
// Switch to other body
|
||||
pcActiveBody = static_cast<PartDesign::Body*>(Part::BodyBase::findBodyOf(selFeature));
|
||||
if (pcActiveBody != NULL)
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"PartDesignGui.setActivePart(App.activeDocument().%s)",
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"PartDesignGui.setActiveBody(App.activeDocument().%s)",
|
||||
pcActiveBody->getNameInDocument());
|
||||
else
|
||||
return;
|
||||
|
|
|
@ -105,7 +105,7 @@ bool ViewProviderBody::doubleClicked(void)
|
|||
// assure the PartDesign workbench
|
||||
Gui::Command::assureWorkbench("PartDesignWorkbench");
|
||||
Gui::Command::addModule(Gui::Command::Gui,"PartDesignGui");
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"PartDesignGui.setActivePart(App.activeDocument().%s)",this->getObject()->getNameInDocument());
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"PartDesignGui.setActiveBody(App.activeDocument().%s)",this->getObject()->getNameInDocument());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include <Gui/ToolBarManager.h>
|
||||
#include <Gui/Control.h>
|
||||
#include <Gui/DlgCheckableMessageBox.h>
|
||||
#include <Gui/ViewProviderPart.h>
|
||||
|
||||
#include <Mod/Sketcher/Gui/Workbench.h>
|
||||
#include <Mod/Part/App/Part2DObject.h>
|
||||
|
@ -100,44 +101,7 @@ Workbench::~Workbench()
|
|||
|
||||
PartDesign::Body *Workbench::setUpPart(const App::Part *part)
|
||||
{
|
||||
// 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 = part->getObjectsOfType(App::Plane::getClassTypeId());
|
||||
for (std::vector<App::DocumentObject*>::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) {
|
||||
// ... and put them in the 'Origin' group
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"OGroup = App.activeDocument().addObject('App::DocumentObjectGroup','%s')", "Origin");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"OGroup.Label = '%s'", QObject::tr("Origin").toStdString().c_str());
|
||||
// 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,"OGroup.addObject(App.activeDocument().ActiveObject)");
|
||||
|
||||
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,"OGroup.addObject(App.activeDocument().ActiveObject)");
|
||||
|
||||
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());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"OGroup.addObject(App.activeDocument().ActiveObject)");
|
||||
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(OGroup)", part->getNameInDocument());
|
||||
// TODO: Fold the group (is that possible through the Python interface?)
|
||||
}
|
||||
|
||||
Gui::ViewProviderPart::setUpPart(part);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -408,7 +372,7 @@ void switchToDocument(const App::Document* doc)
|
|||
|
||||
if (activeBody != NULL) {
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"import PartDesignGui");
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"PartDesignGui.setActivePart(App.activeDocument().%s)", activeBody->getNameInDocument());
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"PartDesignGui.setActiveBody(App.activeDocument().%s)", activeBody->getNameInDocument());
|
||||
} else {
|
||||
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."
|
||||
|
@ -670,7 +634,7 @@ void Workbench::deactivated()
|
|||
removeTaskWatcher();
|
||||
// reset the active Body
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"import PartDesignGui");
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"PartDesignGui.setActivePart(None)");
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"PartDesignGui.setActiveBody(None)");
|
||||
|
||||
Gui::Workbench::deactivated();
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user