Add Python functionality for DrawHatch
This commit is contained in:
parent
91526af69c
commit
707ef236f3
|
@ -35,6 +35,7 @@ generate_from_xml(DrawSVGTemplatePy)
|
||||||
generate_from_xml(DrawViewSymbolPy)
|
generate_from_xml(DrawViewSymbolPy)
|
||||||
generate_from_xml(DrawViewClipPy)
|
generate_from_xml(DrawViewClipPy)
|
||||||
generate_from_xml(DrawViewDimensionPy)
|
generate_from_xml(DrawViewDimensionPy)
|
||||||
|
generate_from_xml(DrawHatchPy)
|
||||||
|
|
||||||
SET(Draw_SRCS
|
SET(Draw_SRCS
|
||||||
DrawPage.cpp
|
DrawPage.cpp
|
||||||
|
@ -104,7 +105,8 @@ SET(Python_SRCS
|
||||||
DrawViewClipPyImp.cpp
|
DrawViewClipPyImp.cpp
|
||||||
DrawViewDimensionPy.xml
|
DrawViewDimensionPy.xml
|
||||||
DrawViewDimensionPyImp.cpp
|
DrawViewDimensionPyImp.cpp
|
||||||
)
|
DrawHatchPy.xml
|
||||||
|
DrawHatchPyImp.cpp)
|
||||||
|
|
||||||
SOURCE_GROUP("Mod" FILES ${TechDraw_SRCS})
|
SOURCE_GROUP("Mod" FILES ${TechDraw_SRCS})
|
||||||
SOURCE_GROUP("Features" FILES ${Draw_SRCS})
|
SOURCE_GROUP("Features" FILES ${Draw_SRCS})
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
|
|
||||||
#include "DrawHatch.h"
|
#include "DrawHatch.h"
|
||||||
|
|
||||||
|
#include "DrawHatchPy.h" // generated from DrawHatchPy.xml
|
||||||
|
|
||||||
using namespace TechDraw;
|
using namespace TechDraw;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -97,6 +99,15 @@ App::DocumentObjectExecReturn *DrawHatch::execute(void)
|
||||||
return App::DocumentObject::StdReturn;
|
return App::DocumentObject::StdReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyObject *DrawHatch::getPyObject(void)
|
||||||
|
{
|
||||||
|
if (PythonObject.is(Py::_None())) {
|
||||||
|
// ref counter is set to 1
|
||||||
|
PythonObject = Py::Object(new DrawHatchPy(this),true);
|
||||||
|
}
|
||||||
|
return Py::new_reference_to(PythonObject);
|
||||||
|
}
|
||||||
|
|
||||||
// Python Drawing feature ---------------------------------------------------------
|
// Python Drawing feature ---------------------------------------------------------
|
||||||
|
|
||||||
namespace App {
|
namespace App {
|
||||||
|
|
|
@ -55,9 +55,8 @@ public:
|
||||||
virtual const char* getViewProviderName(void) const {
|
virtual const char* getViewProviderName(void) const {
|
||||||
return "TechDrawGui::ViewProviderHatch";
|
return "TechDrawGui::ViewProviderHatch";
|
||||||
}
|
}
|
||||||
|
//return PyObject as DrawHatchPy
|
||||||
//DrawViewPart* getViewPart() const;
|
virtual PyObject *getPyObject(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onChanged(const App::Property* prop);
|
void onChanged(const App::Property* prop);
|
||||||
|
|
||||||
|
|
18
src/Mod/TechDraw/App/DrawHatchPy.xml
Normal file
18
src/Mod/TechDraw/App/DrawHatchPy.xml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
|
||||||
|
<PythonExport
|
||||||
|
Father="DrawViewPy"
|
||||||
|
Name="DrawHatchPy"
|
||||||
|
Twin="DrawHatch"
|
||||||
|
TwinPointer="DrawHatch"
|
||||||
|
Include="Mod/TechDraw/App/DrawHatch.h"
|
||||||
|
Namespace="TechDraw"
|
||||||
|
FatherInclude="Mod/TechDraw/App/DrawViewPy.h"
|
||||||
|
FatherNamespace="TechDraw">
|
||||||
|
<Documentation>
|
||||||
|
<Author Licence="LGPL" Name="WandererFan" EMail="wandererfan@gmail.com" />
|
||||||
|
<UserDocu>Feature for creating and manipulating Technical Drawing Hatch areas</UserDocu>
|
||||||
|
</Documentation>
|
||||||
|
<CustomAttributes />
|
||||||
|
</PythonExport>
|
||||||
|
</GenerateModel>
|
32
src/Mod/TechDraw/App/DrawHatchPyImp.cpp
Normal file
32
src/Mod/TechDraw/App/DrawHatchPyImp.cpp
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
|
||||||
|
#include "PreCompiled.h"
|
||||||
|
|
||||||
|
#include "Mod/TechDraw/App/DrawHatch.h"
|
||||||
|
|
||||||
|
// inclusion of the generated files (generated out of DrawHatchPy.xml)
|
||||||
|
#include "DrawHatchPy.h"
|
||||||
|
#include "DrawHatchPy.cpp"
|
||||||
|
|
||||||
|
using namespace TechDraw;
|
||||||
|
|
||||||
|
// returns a string which represents the object e.g. when printed in python
|
||||||
|
std::string DrawHatchPy::representation(void) const
|
||||||
|
{
|
||||||
|
return std::string("<DrawHatch object>");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PyObject *DrawHatchPy::getCustomAttributes(const char* /*attr*/) const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DrawHatchPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -72,6 +72,7 @@ DrawPage::DrawPage(void)
|
||||||
ProjectionType.setEnums(ProjectionTypeEnums);
|
ProjectionType.setEnums(ProjectionTypeEnums);
|
||||||
ADD_PROPERTY(ProjectionType, ((long)0));
|
ADD_PROPERTY(ProjectionType, ((long)0));
|
||||||
ADD_PROPERTY_TYPE(Scale ,(1.0), group, App::Prop_None, "Scale factor for this Page");
|
ADD_PROPERTY_TYPE(Scale ,(1.0), group, App::Prop_None, "Scale factor for this Page");
|
||||||
|
//TODO: Page should create itself with default Template instead of Cmd figuring it out?
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawPage::~DrawPage()
|
DrawPage::~DrawPage()
|
||||||
|
@ -156,7 +157,7 @@ PyObject *DrawPage::getPyObject(void)
|
||||||
PythonObject = Py::Object(new DrawPagePy(this),true);
|
PythonObject = Py::Object(new DrawPagePy(this),true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Py::new_reference_to(PythonObject);
|
return Py::new_reference_to(PythonObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DrawPage::hasValidTemplate() const
|
bool DrawPage::hasValidTemplate() const
|
||||||
|
@ -272,4 +273,3 @@ void DrawPage::onDocumentRestored()
|
||||||
recompute();
|
recompute();
|
||||||
App::DocumentObject::onDocumentRestored();
|
App::DocumentObject::onDocumentRestored();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,19 +98,22 @@ void CmdTechDrawNewHatch::activated(int iMsg)
|
||||||
subs.push_back((*itSub));
|
subs.push_back((*itSub));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: this should be the active page or a selected page? not first page
|
||||||
|
std::vector<App::DocumentObject*> pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
||||||
|
TechDraw::DrawPage *page = dynamic_cast<TechDraw::DrawPage *>(pages.front());
|
||||||
|
std::string PageName = page->getNameInDocument();
|
||||||
|
|
||||||
openCommand("Create Hatch");
|
openCommand("Create Hatch");
|
||||||
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawHatch','%s')",FeatName.c_str());
|
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawHatch','%s')",FeatName.c_str());
|
||||||
doCommand(Doc,"App.activeDocument().%s.PartView = App.activeDocument().%s",FeatName.c_str(),objFeat->getNameInDocument());
|
doCommand(Doc,"App.activeDocument().%s.PartView = App.activeDocument().%s",FeatName.c_str(),objFeat->getNameInDocument());
|
||||||
commitCommand();
|
|
||||||
|
|
||||||
hatch = dynamic_cast<TechDraw::DrawHatch *>(getDocument()->getObject(FeatName.c_str()));
|
hatch = dynamic_cast<TechDraw::DrawHatch *>(getDocument()->getObject(FeatName.c_str()));
|
||||||
hatch->Edges.setValues(objs, subs);
|
hatch->Edges.setValues(objs, subs);
|
||||||
|
//should this be: doCommand(Doc,"App..Feat..Edges = [(App...%s,%s),(App..%s,%s),...]",objs[0]->getNameInDocument(),subs[0],...);
|
||||||
|
//seems very unwieldy
|
||||||
|
|
||||||
hatch->execute();
|
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
|
||||||
|
commitCommand();
|
||||||
std::vector<App::DocumentObject*> pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
|
||||||
TechDraw::DrawPage *page = dynamic_cast<TechDraw::DrawPage *>(pages.front());
|
|
||||||
page->addView(page->getDocument()->getObject(FeatName.c_str()));
|
|
||||||
|
|
||||||
//Horrible hack to force Tree update ??still required??
|
//Horrible hack to force Tree update ??still required??
|
||||||
double x = objFeat->X.getValue();
|
double x = objFeat->X.getValue();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user