implement active body in PartDesign

This commit is contained in:
jriegel 2012-05-05 14:37:56 +02:00 committed by Stefan Tröger
parent 117238da50
commit b825571562
15 changed files with 281 additions and 36 deletions

View File

@ -22,11 +22,58 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <Python.h>
#ifndef _PreComp_
# include <Python.h>
#endif
#include <Base/PyObjectBase.h>
#include <Base/Console.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/Tree.h>
#include <Gui/ViewProviderDocumentObject.h>
#include <Mod/PartDesign/App/BodyPy.h>
// 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<PartDesign::BodyPy*>(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<Gui::ViewProviderDocumentObject*> (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 */
};

View File

@ -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 <Python.h>
#endif
<<<<<<< 8ef3abc971814e64ef79a85812dd1a5827ba955f:src/Mod/Assembly/App/AppAssemblyPy.cpp
/* registration table */
struct PyMethodDef Assembly_methods[] = {
{NULL, NULL} /* end of table marker */
=======
#include <Base/PyObjectBase.h>
#include <Base/Console.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/Tree.h>
#include <Gui/ViewProviderDocumentObject.h>
#include <Mod/PartDesign/App/BodyPy.h>
// 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<PartDesign::BodyPy*>(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<Gui::ViewProviderDocumentObject*> (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
};

View File

@ -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();
}

View File

@ -128,6 +128,8 @@ void Workbench::activated()
void Workbench::deactivated()
{
Gui::Command::doCommand(Gui::Command::Doc,"AssemblyGui.setActiveAssembly(None)");
Gui::Workbench::deactivated();
removeTaskWatcher();

View File

@ -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();

View File

@ -27,23 +27,21 @@
#include <Base/Placement.h>
#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;

View File

@ -21,8 +21,8 @@
***************************************************************************/
#ifndef PART_Body_H
#define PART_Body_H
#ifndef PART_BodyBase_H
#define PART_BodyBase_H
#include <App/PropertyStandard.h>
#include <Mod/Part/App/PartFeature.h>
@ -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

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="PartFeaturePy"
Name="BodyBasePy"
Twin="BodyBase"
TwinPointer="BodyBase"
Include="Mod/Part/App/BodyBase.h"
Namespace="Part"
FatherInclude="Mod/Part/App/PartFeaturePy.h"
FatherNamespace="Part">
<Documentation>
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />
<UserDocu>Base class of all Body objects</UserDocu>
</Documentation>
</PythonExport>
</GenerateModel>

View File

@ -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("<body object>");
}
PyObject *BodyBasePy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int BodyBasePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}

View File

@ -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

View File

@ -35,7 +35,7 @@ using namespace PartDesign;
namespace PartDesign {
PROPERTY_SOURCE(PartDesign::Body, Part::Body)
PROPERTY_SOURCE(PartDesign::Body, Part::BodyBase)
Body::Body()
{

View File

@ -25,13 +25,13 @@
#define PARTDESIGN_Body_H
#include <App/PropertyStandard.h>
#include <Mod/Part/App/Body.h>
#include <Mod/Part/App/BodyBase.h>
namespace PartDesign
{
class Body : public Part::Body
class Body : public Part::BodyBase
{
PROPERTY_HEADER(PartDesign::Body);

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="BodyBasePy"
Name="BodyPy"
Twin="Body"
TwinPointer="Body"
Include="Mod/PartDesign/App/Body.h"
Namespace="PartDesign"
FatherInclude="Mod/Part/App/BodyBasePy.h"
FatherNamespace="Part">
<Documentation>
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />
<UserDocu>PartDesign body class</UserDocu>
</Documentation>
</PythonExport>
</GenerateModel>

View File

@ -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("<body object>");
}
PyObject *BodyPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int BodyPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}

View File

@ -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