diff --git a/src/Mod/Assembly/App/AppAssemblyPy.cpp b/src/Mod/Assembly/App/AppAssemblyPy.cpp index 5d2997e5e..7be456d55 100644 --- a/src/Mod/Assembly/App/AppAssemblyPy.cpp +++ b/src/Mod/Assembly/App/AppAssemblyPy.cpp @@ -22,11 +22,58 @@ #include "PreCompiled.h" -#ifndef _PreComp_ -# include +#ifndef _PreComp_ +# include #endif +#include +#include + +#include +#include +#include +#include + +#include + +// pointer to the active assembly object +PartDesign::Body *ActivePartObject =0; +Gui::Document *ActiveGuiDoc =0; +Gui::ViewProviderDocumentObject *ActiveVp =0; + + + +static PyObject * setActivePart(PyObject *self, PyObject *args) +{ + PyObject *object=0; + if (PyArg_ParseTuple(args,"|O!",&(PartDesign::BodyPy::Type), &object)&& object) { + PartDesign::Body* Item = static_cast(object)->getBodyPtr(); + // Should be set! + assert(Item); + + // get the gui document of the Assembly Item + if(ActivePartObject){ + + ActiveGuiDoc->signalHighlightObject(*ActiveVp,Gui::Blue,false); + ActivePartObject = 0; + + } + ActivePartObject = Item; + ActiveGuiDoc = Gui::Application::Instance->getDocument(Item->getDocument()); + ActiveVp = dynamic_cast (ActiveGuiDoc->getViewProvider(Item)) ; + ActiveGuiDoc->signalHighlightObject(*ActiveVp,Gui::Blue,true); + + }else{ + ActiveGuiDoc->signalHighlightObject(*ActiveVp,Gui::Blue,false); + ActivePartObject = 0; + } + + Py_Return; +} /* registration table */ struct PyMethodDef Assembly_methods[] = { + {"setActivePart" ,setActivePart ,METH_VARARGS, + "setActivePart(BodyObject) -- Set the PartBody object in work."}, + {NULL, NULL} /* end of table marker */ }; diff --git a/src/Mod/Assembly/App/AppAssemblyPy.cpp.orig b/src/Mod/Assembly/App/AppAssemblyPy.cpp.orig new file mode 100644 index 000000000..fa76945b1 --- /dev/null +++ b/src/Mod/Assembly/App/AppAssemblyPy.cpp.orig @@ -0,0 +1,86 @@ +/*************************************************************************** + * Copyright (c) 2008 Jürgen Riegel (juergen.riegel@web.de) * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +#endif + +<<<<<<< 8ef3abc971814e64ef79a85812dd1a5827ba955f:src/Mod/Assembly/App/AppAssemblyPy.cpp +/* registration table */ +struct PyMethodDef Assembly_methods[] = { + {NULL, NULL} /* end of table marker */ +======= +#include +#include + +#include +#include +#include +#include + +#include + +// pointer to the active assembly object +PartDesign::Body *ActivePartObject =0; +Gui::Document *ActiveGuiDoc =0; +Gui::ViewProviderDocumentObject *ActiveVp =0; + + + +static PyObject * setActivePart(PyObject *self, PyObject *args) +{ + PyObject *object=0; + if (PyArg_ParseTuple(args,"|O!",&(PartDesign::BodyPy::Type), &object)&& object) { + PartDesign::Body* Item = static_cast(object)->getBodyPtr(); + // Should be set! + assert(Item); + + // get the gui document of the Assembly Item + if(ActivePartObject){ + + ActiveGuiDoc->signalHighlightObject(*ActiveVp,Gui::Blue,false); + ActivePartObject = 0; + + } + ActivePartObject = Item; + ActiveGuiDoc = Gui::Application::Instance->getDocument(Item->getDocument()); + ActiveVp = dynamic_cast (ActiveGuiDoc->getViewProvider(Item)) ; + ActiveGuiDoc->signalHighlightObject(*ActiveVp,Gui::Blue,true); + + }else{ + ActiveGuiDoc->signalHighlightObject(*ActiveVp,Gui::Blue,false); + ActivePartObject = 0; + } + + Py_Return; +} + +/* registration table */ +struct PyMethodDef PartDesignGui_Import_methods[] = { + {"setActivePart" ,setActivePart ,METH_VARARGS, + "setActivePart(BodyObject) -- Set the PartBody object in work."}, + + {NULL, NULL} /* end of table marker */ +>>>>>>> implement active body in PartDesign:src/Mod/PartDesign/Gui/AppPartDesignGuiPy.cpp +}; diff --git a/src/Mod/Assembly/Gui/Command.cpp b/src/Mod/Assembly/Gui/Command.cpp index b626b2e66..6397d6ae0 100644 --- a/src/Mod/Assembly/Gui/Command.cpp +++ b/src/Mod/Assembly/Gui/Command.cpp @@ -82,27 +82,29 @@ void CmdAssemblyAddNewPart::activated(int iMsg) Command::addModule(App,"PartDesign"); Command::addModule(Gui,"PartDesignGui"); -#if 1 // test code for children nesting - Command::addModule(App,"Part"); - std::string BodyName = getUniqueObjectName("Box"); - doCommand(Doc,"App.activeDocument().addObject('Part::Box','%s')",BodyName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Model = App.activeDocument().%s ",PartName.c_str(),BodyName.c_str(),BodyName.c_str()); -#else std::string BodyName = getUniqueObjectName("Body"); // add the standard planes std::string Plane1Name = BodyName + "_PlaneXY"; std::string Plane2Name = BodyName + "_PlaneYZ"; std::string Plane3Name = BodyName + "_PlaneXZ"; - doCommand(Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane1Name.c_str()); - doCommand(Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane2Name.c_str()); - doCommand(Doc,"App.activeDocument().%s.Placement = App.Placement(App.Vector(0.000000,0.000000,0.000000),App.Rotation(-0.707107,0.000000,0.000000,-0.707107))",Plane2Name.c_str()); - doCommand(Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane3Name.c_str()); - doCommand(Doc,"App.activeDocument().%s.Annotation = [App.activeDocument().%s,App.activeDocument().%s,App.activeDocument().%s] ",PartName.c_str(),Plane1Name.c_str(),Plane2Name.c_str(),Plane3Name.c_str()); + //doCommand(Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane1Name.c_str()); + //doCommand(Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane2Name.c_str()); + //doCommand(Doc,"App.activeDocument().%s.Placement = App.Placement(App.Vector(0.000000,0.000000,0.000000),App.Rotation(-0.707107,0.000000,0.000000,-0.707107))",Plane2Name.c_str()); + //doCommand(Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane3Name.c_str()); + //doCommand(Doc,"App.activeDocument().%s.Annotation = [App.activeDocument().%s,App.activeDocument().%s,App.activeDocument().%s] ",PartName.c_str(),Plane1Name.c_str(),Plane2Name.c_str(),Plane3Name.c_str()); // add the main body doCommand(Doc,"App.activeDocument().addObject('PartDesign::Body','%s')",BodyName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Model = App.activeDocument().%s ",PartName.c_str(),BodyName.c_str(),BodyName.c_str()); -#endif # + doCommand(Doc,"App.activeDocument().%s.Model = App.activeDocument().%s ",PartName.c_str(),BodyName.c_str()); + +#if 0 // test code for children nesting + Command::addModule(App,"Part"); + std::string BoxName = getUniqueObjectName("Box"); + doCommand(Doc,"App.activeDocument().addObject('Part::Box','%s')",BoxName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Model = App.activeDocument().%s ",BodyName.c_str(),BoxName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Tip = App.activeDocument().%s ",BodyName.c_str(),BoxName.c_str()); +#endif + this->updateActive(); } diff --git a/src/Mod/Assembly/Gui/Workbench.cpp b/src/Mod/Assembly/Gui/Workbench.cpp index 8b183a449..2831e0a6c 100644 --- a/src/Mod/Assembly/Gui/Workbench.cpp +++ b/src/Mod/Assembly/Gui/Workbench.cpp @@ -128,6 +128,8 @@ void Workbench::activated() void Workbench::deactivated() { + Gui::Command::doCommand(Gui::Command::Doc,"AssemblyGui.setActiveAssembly(None)"); + Gui::Workbench::deactivated(); removeTaskWatcher(); diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index ed1711256..3b581f4aa 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -49,7 +49,7 @@ #include "FeatureMirroring.h" #include "FeatureRevolution.h" #include "PartFeatures.h" -#include "Body.h" +#include "BodyBase.h" #include "PrimitiveFeature.h" #include "Part2DObject.h" #include "CustomFeature.h" @@ -219,7 +219,7 @@ PyMODINIT_FUNC initPart() Part::Feature ::init(); Part::FeatureExt ::init(); - Part::Body ::init(); + Part::BodyBase ::init(); Part::FeaturePython ::init(); Part::FeatureGeometrySet ::init(); Part::CustomFeature ::init(); diff --git a/src/Mod/Part/App/Body.cpp b/src/Mod/Part/App/BodyBase.cpp similarity index 88% rename from src/Mod/Part/App/Body.cpp rename to src/Mod/Part/App/BodyBase.cpp index 1596c49da..8a5510f2f 100644 --- a/src/Mod/Part/App/Body.cpp +++ b/src/Mod/Part/App/BodyBase.cpp @@ -27,23 +27,21 @@ #include -#include "Body.h" +#include "BodyBase.h" -using namespace Part; - namespace Part { -PROPERTY_SOURCE(Part::Body, Part::Feature) +PROPERTY_SOURCE(Part::BodyBase, Part::Feature) -Body::Body() +BodyBase::BodyBase() { ADD_PROPERTY(Model,(0)); ADD_PROPERTY(Tip ,(0)); } -short Body::mustExecute() const +short BodyBase::mustExecute() const { //if (Sketch.isTouched() || // Length.isTouched()) @@ -51,7 +49,7 @@ short Body::mustExecute() const return 0; } -App::DocumentObjectExecReturn *Body::execute(void) +App::DocumentObjectExecReturn *BodyBase::execute(void) { return App::DocumentObject::StdReturn; diff --git a/src/Mod/Part/App/Body.h b/src/Mod/Part/App/BodyBase.h similarity index 88% rename from src/Mod/Part/App/Body.h rename to src/Mod/Part/App/BodyBase.h index d5e91d428..e17bf9ad0 100644 --- a/src/Mod/Part/App/Body.h +++ b/src/Mod/Part/App/BodyBase.h @@ -21,8 +21,8 @@ ***************************************************************************/ -#ifndef PART_Body_H -#define PART_Body_H +#ifndef PART_BodyBase_H +#define PART_BodyBase_H #include #include @@ -36,12 +36,12 @@ namespace Part * in edit or active on a workbench, the body shows only the * resulting shape to the outside (Tip link). */ -class PartExport Body : public Part::Feature +class PartExport BodyBase : public Part::Feature { - PROPERTY_HEADER(PartDesign::Body); + PROPERTY_HEADER(PartDesign::BodyBase); public: - Body(); + BodyBase(); App::PropertyLinkList Model; App::PropertyLink Tip; @@ -53,7 +53,7 @@ public: short mustExecute() const; /// returns the type name of the view provider //const char* getViewProviderName(void) const { - // return "PartDesignGui::ViewProviderBody"; + // return "PartDesignGui::ViewProviderBodyBase"; //} //@} }; @@ -61,4 +61,4 @@ public: } //namespace Part -#endif // PART_Body_H +#endif // PART_BodyBase_H diff --git a/src/Mod/Part/App/BodyBasePy.xml b/src/Mod/Part/App/BodyBasePy.xml new file mode 100644 index 000000000..94b232fce --- /dev/null +++ b/src/Mod/Part/App/BodyBasePy.xml @@ -0,0 +1,17 @@ + + + + + + Base class of all Body objects + + + diff --git a/src/Mod/Part/App/BodyBasePyImp.cpp b/src/Mod/Part/App/BodyBasePyImp.cpp new file mode 100644 index 000000000..4f20f75a6 --- /dev/null +++ b/src/Mod/Part/App/BodyBasePyImp.cpp @@ -0,0 +1,29 @@ + +#include "PreCompiled.h" + +#include "Mod/Part/App/BodyBase.h" + +// inclusion of the generated files (generated out of ItemPy.xml) +#include "BodyBasePy.h" +#include "BodyBasePy.cpp" + +using namespace Part; + +// returns a string which represents the object e.g. when printed in python +std::string BodyBasePy::representation(void) const +{ + return std::string(""); +} + + +PyObject *BodyBasePy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int BodyBasePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} + + diff --git a/src/Mod/Part/App/CMakeLists.txt b/src/Mod/Part/App/CMakeLists.txt index 4b6efbf1d..1328cac34 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -40,6 +40,7 @@ endif(FREETYPE_FOUND) generate_from_xml(ArcPy) generate_from_xml(ArcOfCirclePy) generate_from_xml(ArcOfParabolaPy) +generate_from_xml(BodyBasePy) generate_from_xml(CirclePy) generate_from_xml(ArcOfEllipsePy) generate_from_xml(EllipsePy) @@ -134,8 +135,8 @@ SET(Features_SRCS FeatureGeometrySet.cpp CustomFeature.cpp CustomFeature.h - Body.h - Body.cpp + BodyBase.h + BodyBase.cpp ) SOURCE_GROUP("Features" FILES ${Features_SRCS}) @@ -154,6 +155,8 @@ SET(Python_SRCS ArcOfCirclePyImp.cpp ArcOfParabolaPy.xml ArcOfParabolaPyImp.cpp + BodyBasePy.xml + BodyBasePyImp.cpp CirclePy.xml CirclePyImp.cpp ArcOfEllipsePy.xml diff --git a/src/Mod/PartDesign/App/Body.cpp b/src/Mod/PartDesign/App/Body.cpp index a5939fdf3..f435afc0e 100644 --- a/src/Mod/PartDesign/App/Body.cpp +++ b/src/Mod/PartDesign/App/Body.cpp @@ -35,7 +35,7 @@ using namespace PartDesign; namespace PartDesign { -PROPERTY_SOURCE(PartDesign::Body, Part::Body) +PROPERTY_SOURCE(PartDesign::Body, Part::BodyBase) Body::Body() { diff --git a/src/Mod/PartDesign/App/Body.h b/src/Mod/PartDesign/App/Body.h index b895425c3..b66fc752d 100644 --- a/src/Mod/PartDesign/App/Body.h +++ b/src/Mod/PartDesign/App/Body.h @@ -25,13 +25,13 @@ #define PARTDESIGN_Body_H #include -#include +#include namespace PartDesign { -class Body : public Part::Body +class Body : public Part::BodyBase { PROPERTY_HEADER(PartDesign::Body); diff --git a/src/Mod/PartDesign/App/BodyPy.xml b/src/Mod/PartDesign/App/BodyPy.xml new file mode 100644 index 000000000..ab251ac73 --- /dev/null +++ b/src/Mod/PartDesign/App/BodyPy.xml @@ -0,0 +1,17 @@ + + + + + + PartDesign body class + + + diff --git a/src/Mod/PartDesign/App/BodyPyImp.cpp b/src/Mod/PartDesign/App/BodyPyImp.cpp new file mode 100644 index 000000000..aa592537a --- /dev/null +++ b/src/Mod/PartDesign/App/BodyPyImp.cpp @@ -0,0 +1,30 @@ + +#include "PreCompiled.h" + +#include "Mod/PartDesign/App/Body.h" + +// inclusion of the generated files (generated out of ItemPy.xml) +#include "BodyPy.h" +#include "BodyPy.cpp" + +using namespace PartDesign; + +// returns a string which represents the object e.g. when printed in python +std::string BodyPy::representation(void) const +{ + return std::string(""); +} + + + +PyObject *BodyPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int BodyPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} + + diff --git a/src/Mod/PartDesign/App/CMakeLists.txt b/src/Mod/PartDesign/App/CMakeLists.txt index 8340a38a1..51500d14c 100644 --- a/src/Mod/PartDesign/App/CMakeLists.txt +++ b/src/Mod/PartDesign/App/CMakeLists.txt @@ -7,6 +7,8 @@ endif(MSVC) include_directories( ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/src + ${CMAKE_BINARY_DIR}/src + ${CMAKE_CURRENT_BINARY_DIR} ${Boost_INCLUDE_DIRS} ${OCC_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} @@ -16,6 +18,9 @@ include_directories( ) link_directories(${OCC_LIBRARY_DIR}) +generate_from_xml(BodyPy) + + set(PartDesign_LIBS ${OCC_LIBRARIES} ${OCC_DEBUG_LIBRARIES} @@ -88,12 +93,21 @@ SET(Module_SRCS ) SOURCE_GROUP("Module" FILES ${Module_SRCS}) + +SET(Python_SRCS + BodyPy.xml + BodyPyImp.cpp + +) +SOURCE_GROUP("Python" FILES ${Python_SRCS}) + SET(PartDesign_SRCS ${Features_SRCS} ${FeaturesTransformed_SRCS} ${FeaturesSketchBased_SRCS} ${FeaturesDressUp_SRCS} ${Module_SRCS} + ${Python_SRCS} ) SET(PartDesign_Scripts