Text Leader initial version

This commit is contained in:
wandererfan
2019-04-14 15:09:04 -04:00
committed by WandererFan
parent 3be0cbca58
commit 7f07195f93
56 changed files with 9642 additions and 50 deletions

View File

@@ -40,6 +40,8 @@
#include "DrawViewImage.h"
#include "DrawViewDetail.h"
#include "DrawViewBalloon.h"
#include "DrawLeaderLine.h"
#include "DrawTextLeader.h"
namespace TechDraw {
extern PyObject* initModule();
@@ -80,7 +82,8 @@ PyMOD_INIT_FUNC(TechDraw)
TechDraw::DrawProjGroupItem ::init();
TechDraw::DrawViewDetail ::init();
TechDraw::DrawViewBalloon ::init();
TechDraw::DrawLeaderLine ::init();
TechDraw::DrawTextLeader ::init();
TechDraw::DrawTemplate ::init();
TechDraw::DrawParametricTemplate::init();
@@ -99,5 +102,7 @@ PyMOD_INIT_FUNC(TechDraw)
TechDraw::DrawViewMultiPython ::init();
TechDraw::DrawTemplatePython ::init();
TechDraw::DrawViewSymbolPython::init();
TechDraw::DrawLeaderLinePython::init();
TechDraw::DrawTextLeaderPython::init();
PyMOD_Return(mod);
}

View File

@@ -44,6 +44,9 @@ generate_from_xml(DrawViewCollectionPy)
generate_from_xml(DrawProjGroupPy)
generate_from_xml(DrawProjGroupItemPy)
generate_from_xml(DrawViewAnnotationPy)
generate_from_xml(DrawLeaderLinePy)
generate_from_xml(DrawTextLeaderPy)
SET(Draw_SRCS
DrawPage.cpp
@@ -91,7 +94,12 @@ SET(Draw_SRCS
DrawViewImage.cpp
DrawViewImage.h
DrawViewDetail.cpp
DrawViewDetail.h)
DrawViewDetail.h
DrawLeaderLine.cpp
DrawLeaderLine.h
DrawTextLeader.cpp
DrawTextLeader.h
)
SET(TechDraw_SRCS
AppTechDraw.cpp
@@ -147,7 +155,12 @@ SET(Python_SRCS
DrawProjGroupItemPy.xml
DrawProjGroupItemPyImp.cpp
DrawViewAnnotationPy.xml
DrawViewAnnotationPyImp.cpp)
DrawViewAnnotationPyImp.cpp
DrawLeaderLinePy.xml
DrawLeaderLinePyImp.cpp
DrawTextLeaderPy.xml
DrawTextLeaderPyImp.cpp
)
SOURCE_GROUP("Mod" FILES ${TechDraw_SRCS})
SOURCE_GROUP("Features" FILES ${Draw_SRCS})

View File

@@ -0,0 +1,193 @@
/***************************************************************************
* Copyright (c) 2019 Wanderer Fan <wandererfan@gmail.com> *
* *
* 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_
#endif
#include <App/Application.h>
#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/Parameter.h>
#include "DrawPage.h"
#include "DrawView.h"
#include "DrawUtil.h"
#include <Mod/TechDraw/App/DrawLeaderLinePy.h> // generated from DrawLeaderLinePy.xml
#include "DrawLeaderLine.h"
using namespace TechDraw;
//===========================================================================
// DrawLeaderLine - Base class for drawing leader based features
//===========================================================================
PROPERTY_SOURCE(TechDraw::DrawLeaderLine, TechDraw::DrawView)
DrawLeaderLine::DrawLeaderLine(void)
{
static const char *group = "Leader";
ADD_PROPERTY_TYPE(LeaderParent,(0),group,(App::PropertyType)(App::Prop_None),
"View to which this leader is attached");
LeaderParent.setScope(App::LinkScope::Global);
ADD_PROPERTY_TYPE(WayPoints,(Base::Vector3d()) ,group, App::Prop_None,
"Intermediate points for Leader line");
ADD_PROPERTY_TYPE(StartSymbol, (-1), group, App::Prop_None, "Symbol (arrowhead) for start of line");
ADD_PROPERTY_TYPE(EndSymbol, (-1), group, App::Prop_None, "Symbol (arrowhead) for end of line");
ADD_PROPERTY_TYPE(Scalable ,(false),group,App::Prop_None,"Scale line with LeaderParent");
//hide the DrawView properties that don't apply to Leader
ScaleType.setStatus(App::Property::ReadOnly,true);
ScaleType.setStatus(App::Property::Hidden,true);
Scale.setStatus(App::Property::ReadOnly,true);
Scale.setStatus(App::Property::Hidden,true);
Rotation.setStatus(App::Property::ReadOnly,true);
Rotation.setStatus(App::Property::Hidden,true);
//generally, lines/leaders are not meant to move around.
LockPosition.setValue(true);
}
DrawLeaderLine::~DrawLeaderLine()
{
}
void DrawLeaderLine::onChanged(const App::Property* prop)
{
if (!isRestoring()) {
//nothing in particular
}
DrawView::onChanged(prop);
}
short DrawLeaderLine::mustExecute() const
{
bool result = 0;
if (!isRestoring()) {
result = (LeaderParent.isTouched()); //Property changed
}
if (result) {
return result;
}
const App::DocumentObject* docObj = getBaseObject();
if (docObj != nullptr) {
result = docObj->isTouched(); //object property points to is touched
}
if (result) {
return result;
}
return DrawView::mustExecute();
}
App::DocumentObjectExecReturn *DrawLeaderLine::execute(void)
{
// Base::Console().Message("DL::execute()\n");
if (!keepUpdated()) {
return App::DocumentObject::StdReturn;
}
return DrawView::execute();
}
DrawView* DrawLeaderLine::getBaseView(void) const
{
DrawView* result = nullptr;
App::DocumentObject* baseObj = LeaderParent.getValue();
if (baseObj != nullptr) {
DrawView* cast = dynamic_cast<DrawView*>(baseObj);
if (cast != nullptr) {
result = cast;
}
}
return result;
}
App::DocumentObject* DrawLeaderLine::getBaseObject(void) const
{
App::DocumentObject* result = nullptr;
DrawView* view = getBaseView();
if (view != nullptr) {
result = view;
}
return result;
}
bool DrawLeaderLine::keepUpdated(void)
{
bool result = false;
DrawView* view = getBaseView();
if (view != nullptr) {
result = view->keepUpdated();
}
return result;
}
double DrawLeaderLine::getScale(void)
{
double result = 1.0;
DrawView* parent = getBaseView();
if (parent != nullptr) {
result = parent->getScale();
} else {
//TARFU
Base::Console().Log("DrawLeaderLine - %s - scale not found. Using 1.0. \n", getNameInDocument());
}
return result;
}
Base::Vector3d DrawLeaderLine::getAttachPoint(void)
{
Base::Vector3d result(X.getValue(),
Y.getValue(),
0.0);
return result;
}
PyObject *DrawLeaderLine::getPyObject(void)
{
if (PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::Object(new DrawLeaderLinePy(this),true);
}
return Py::new_reference_to(PythonObject);
}
// Python Drawing feature ---------------------------------------------------------
namespace App {
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawLeaderLinePython, TechDraw::DrawLeaderLine)
template<> const char* TechDraw::DrawLeaderLinePython::getViewProviderName(void) const {
return "TechDrawGui::ViewProviderLeader";
}
/// @endcond
// explicit template instantiation
template class TechDrawExport FeaturePythonT<TechDraw::DrawLeaderLine>;
}

View File

@@ -0,0 +1,75 @@
/***************************************************************************
* Copyright (c) 2019 Wanderer Fan <wandererfan@gmail.com> *
* *
* 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 *
* *
***************************************************************************/
#ifndef _TechDraw_DrawLeaderLine_h_
#define _TechDraw_DrawLeaderLine_h_
#include <tuple>
# include <App/DocumentObject.h>
# include <App/FeaturePython.h>
# include <App/PropertyLinks.h>
#include "DrawView.h"
namespace TechDraw
{
class TechDrawExport DrawLeaderLine : public TechDraw::DrawView
{
PROPERTY_HEADER(TechDraw::DrawLeaderLine);
public:
DrawLeaderLine();
virtual ~DrawLeaderLine();
App::PropertyLink LeaderParent;
App::PropertyVectorList WayPoints;
App::PropertyInteger StartSymbol;
App::PropertyInteger EndSymbol;
App::PropertyBool Scalable;
virtual short mustExecute() const;
virtual App::DocumentObjectExecReturn *execute(void);
virtual const char* getViewProviderName(void) const {
return "TechDrawGui::ViewProviderLeader";
}
virtual PyObject *getPyObject(void);
virtual QRectF getRect() const { return QRectF(0,0,1,1);}
Base::Vector3d getAttachPoint(void);
DrawView* getBaseView(void) const;
virtual App::DocumentObject* getBaseObject(void) const;
bool keepUpdated(void);
double getScale(void);
protected:
virtual void onChanged(const App::Property* prop);
private:
};
typedef App::FeaturePythonT<DrawLeaderLine> DrawLeaderLinePython;
} //namespace TechDraw
#endif

View 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="DrawLeaderLinePy"
Twin="DrawLeaderLine"
TwinPointer="DrawLeaderLine"
Include="Mod/TechDraw/App/DrawLeaderLine.h"
Namespace="TechDraw"
FatherInclude="Mod/TechDraw/App/DrawViewPy.h"
FatherNamespace="TechDraw">
<Documentation>
<Author Licence="LGPL" Name="WandererFan" EMail="wandererfan@gmail.com" />
<UserDocu>Feature for adding leaders to Technical Drawings</UserDocu>
</Documentation>
<CustomAttributes />
</PythonExport>
</GenerateModel>

View File

@@ -0,0 +1,54 @@
/***************************************************************************
* Copyright (c) 2019 WandererFan (wandererfan@gmail.com) *
* *
* 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_
#endif
#include <Base/Console.h>
#include <Base/PyObjectBase.h>
#include <Base/Vector3D.h>
#include "DrawLeaderLine.h"
// inclusion of the generated files (generated out of DrawLeaderLinePy.xml)
#include <Base/VectorPy.h>
#include <Mod/TechDraw/App/DrawLeaderLinePy.h>
#include <Mod/TechDraw/App/DrawLeaderLinePy.cpp>
using namespace TechDraw;
// returns a string which represents the object e.g. when printed in python
std::string DrawLeaderLinePy::representation(void) const
{
return std::string("<DrawLeaderLine object>");
}
PyObject *DrawLeaderLinePy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int DrawLeaderLinePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}

View File

@@ -0,0 +1,112 @@
/***************************************************************************
* Copyright (c) 2019 Wanderer Fan <wandererfan@gmail.com> *
* *
* 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_
#endif
#include <App/Application.h>
#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/Parameter.h>
#include "DrawUtil.h"
#include <Mod/TechDraw/App/DrawTextLeaderPy.h> // generated from DrawTextLeaderPy.xml
#include "DrawTextLeader.h"
using namespace TechDraw;
//===========================================================================
// DrawTextLeader - DrawLeaderLine + movable text block
//===========================================================================
PROPERTY_SOURCE(TechDraw::DrawTextLeader, TechDraw::DrawLeaderLine)
DrawTextLeader::DrawTextLeader(void)
{
static const char *group = "Text Leader";
ADD_PROPERTY_TYPE(LeaderText, (""), group, App::Prop_None, "Leader text");
Base::Vector3d pos(0.0,0.0,0.0);
ADD_PROPERTY_TYPE(TextPosition, (pos), group, App::Prop_None, "Text position relative to parent");
}
DrawTextLeader::~DrawTextLeader()
{
}
void DrawTextLeader::onChanged(const App::Property* prop)
{
if (!isRestoring()) {
//nothing in particular
}
DrawView::onChanged(prop);
}
short DrawTextLeader::mustExecute() const
{
bool result = 0;
if (!isRestoring()) {
result = (LeaderText.isTouched());
}
if (result) {
return result;
}
return DrawView::mustExecute();
}
App::DocumentObjectExecReturn *DrawTextLeader::execute(void)
{
// Base::Console().Message("DTL::execute()\n");
if (!keepUpdated()) {
return App::DocumentObject::StdReturn;
}
return DrawView::execute();
}
PyObject *DrawTextLeader::getPyObject(void)
{
if (PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::Object(new DrawTextLeaderPy(this),true);
}
return Py::new_reference_to(PythonObject);
}
// Python Drawing feature ---------------------------------------------------------
namespace App {
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawTextLeaderPython, TechDraw::DrawTextLeader)
template<> const char* TechDraw::DrawTextLeaderPython::getViewProviderName(void) const {
return "TechDrawGui::ViewProviderTextLeader";
}
/// @endcond
// explicit template instantiation
template class TechDrawExport FeaturePythonT<TechDraw::DrawTextLeader>;
}

View File

@@ -0,0 +1,64 @@
/***************************************************************************
* Copyright (c) 2019 Wanderer Fan <wandererfan@gmail.com> *
* *
* 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 *
* *
***************************************************************************/
#ifndef _TechDraw_DrawTextLeader_h_
#define _TechDraw_DrawTextLeader_h_
# include <App/DocumentObject.h>
# include <App/FeaturePython.h>
#include "DrawLeaderLine.h"
namespace TechDraw
{
class TechDrawExport DrawTextLeader : public TechDraw::DrawLeaderLine
{
PROPERTY_HEADER(TechDraw::DrawTextLeader);
public:
DrawTextLeader();
virtual ~DrawTextLeader();
App::PropertyString LeaderText;
App::PropertyVector TextPosition;
virtual short mustExecute() const;
virtual App::DocumentObjectExecReturn *execute(void);
virtual const char* getViewProviderName(void) const {
return "TechDrawGui::ViewProviderTextLeader";
}
virtual PyObject *getPyObject(void);
virtual QRectF getRect() const { return QRectF(0,0,1,1);}
protected:
virtual void onChanged(const App::Property* prop);
private:
};
typedef App::FeaturePythonT<DrawTextLeader> DrawTextLeaderPython;
} //namespace TechDraw
#endif

View 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="DrawLeaderLinePy"
Name="DrawTextLeaderPy"
Twin="DrawTextLeader"
TwinPointer="DrawTextLeader"
Include="Mod/TechDraw/App/DrawTextLeader.h"
Namespace="TechDraw"
FatherInclude="Mod/TechDraw/App/DrawLeaderLinePy.h"
FatherNamespace="TechDraw">
<Documentation>
<Author Licence="LGPL" Name="WandererFan" EMail="wandererfan@gmail.com" />
<UserDocu>Feature for adding text leaders to Technical Drawings</UserDocu>
</Documentation>
<CustomAttributes />
</PythonExport>
</GenerateModel>

View File

@@ -0,0 +1,54 @@
/***************************************************************************
* Copyright (c) 2019 WandererFan (wandererfan@gmail.com) *
* *
* 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_
#endif
#include <Base/Console.h>
#include <Base/PyObjectBase.h>
#include <Base/Vector3D.h>
#include "DrawTextLeader.h"
// inclusion of the generated files (generated out of DrawTextLeaderPy.xml)
#include <Base/VectorPy.h>
#include <Mod/TechDraw/App/DrawTextLeaderPy.h>
#include <Mod/TechDraw/App/DrawTextLeaderPy.cpp>
using namespace TechDraw;
// returns a string which represents the object e.g. when printed in python
std::string DrawTextLeaderPy::representation(void) const
{
return std::string("<DrawTextLeader object>");
}
PyObject *DrawTextLeaderPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int DrawTextLeaderPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}

View File

@@ -45,6 +45,7 @@
#include "DrawViewClip.h"
#include "DrawProjGroup.h"
#include "DrawProjGroupItem.h"
#include "DrawLeaderLine.h"
#include "DrawUtil.h"
#include <Mod/TechDraw/App/DrawViewPy.h> // generated from DrawViewPy.xml
@@ -91,7 +92,6 @@ DrawView::~DrawView()
App::DocumentObjectExecReturn *DrawView::execute(void)
{
// Base::Console().Message("DV::execute() - %s\n",getNameInDocument());
handleXYLock();
requestPaint();
return App::DocumentObject::execute();
@@ -287,10 +287,11 @@ bool DrawView::checkFit(TechDraw::DrawPage* p) const
return result;
}
void DrawView::setPosition(double x, double y)
void DrawView::setPosition(double x, double y, bool force)
{
// Base::Console().Message("DV::setPosition(%.3f,%.3f) - \n",x,y,getNameInDocument());
if (!isLocked()) {
if ( (!isLocked()) ||
(force) ) {
X.setValue(x);
Y.setValue(y);
}
@@ -307,6 +308,26 @@ double DrawView::getScale(void) const
return result;
}
//return list of Leaders which reference this DV
std::vector<TechDraw::DrawLeaderLine*> DrawView::getLeaders() const
{
std::vector<TechDraw::DrawLeaderLine*> result;
std::vector<App::DocumentObject*> children = getInList();
for (std::vector<App::DocumentObject*>::iterator it = children.begin(); it != children.end(); ++it) {
if ((*it)->getTypeId().isDerivedFrom(DrawLeaderLine::getClassTypeId())) {
TechDraw::DrawLeaderLine* lead = dynamic_cast<TechDraw::DrawLeaderLine*>(*it);
result.push_back(lead);
}
}
return result;
}
void DrawView::addRandomVertex(Base::Vector3d pos)
{
(void) pos;
Base::Console().Message("DV::addRandomVertex()\n");
}
void DrawView::Restore(Base::XMLReader &reader)
{
// this is temporary code for backwards compat (within v0.17). can probably be deleted once there are no development

View File

@@ -37,6 +37,7 @@ namespace TechDraw
class DrawPage;
class DrawViewClip;
class DrawLeaderLine;
/** Base class of all View Features in the drawing module
*/
@@ -77,11 +78,11 @@ public:
//return PyObject as DrawViewPy
virtual PyObject *getPyObject(void) override;
DrawPage* findParentPage() const;
virtual DrawPage* findParentPage() const;
virtual QRectF getRect() const; //must be overridden by derived class
virtual double autoScale(double w, double h) const;
virtual bool checkFit(DrawPage*) const;
virtual void setPosition(double x, double y);
virtual void setPosition(double x, double y, bool force = false);
bool keepUpdated(void);
boost::signals2::signal<void (const DrawView*)> signalGuiPaint;
virtual double getScale(void) const;
@@ -89,6 +90,8 @@ public:
void requestPaint(void);
virtual void handleXYLock(void);
virtual bool isLocked(void) const;
virtual void addRandomVertex(Base::Vector3d pos);
std::vector<TechDraw::DrawLeaderLine*> getLeaders() const;
protected:
virtual void onChanged(const App::Property* prop) override;