Skip to content

Commit

Permalink
Leader and RichText block improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed May 6, 2019
1 parent 7f07195 commit 6c69988
Show file tree
Hide file tree
Showing 45 changed files with 1,910 additions and 683 deletions.
6 changes: 3 additions & 3 deletions src/Mod/TechDraw/App/AppTechDraw.cpp
Expand Up @@ -41,7 +41,7 @@
#include "DrawViewDetail.h"
#include "DrawViewBalloon.h"
#include "DrawLeaderLine.h"
#include "DrawTextLeader.h"
#include "DrawRichAnno.h"

namespace TechDraw {
extern PyObject* initModule();
Expand Down Expand Up @@ -83,7 +83,7 @@ PyMOD_INIT_FUNC(TechDraw)
TechDraw::DrawViewDetail ::init();
TechDraw::DrawViewBalloon ::init();
TechDraw::DrawLeaderLine ::init();
TechDraw::DrawTextLeader ::init();
TechDraw::DrawRichAnno ::init();

TechDraw::DrawTemplate ::init();
TechDraw::DrawParametricTemplate::init();
Expand All @@ -103,6 +103,6 @@ PyMOD_INIT_FUNC(TechDraw)
TechDraw::DrawTemplatePython ::init();
TechDraw::DrawViewSymbolPython::init();
TechDraw::DrawLeaderLinePython::init();
TechDraw::DrawTextLeaderPython::init();
TechDraw::DrawRichAnnoPython::init();
PyMOD_Return(mod);
}
10 changes: 5 additions & 5 deletions src/Mod/TechDraw/App/CMakeLists.txt
Expand Up @@ -45,7 +45,7 @@ generate_from_xml(DrawProjGroupPy)
generate_from_xml(DrawProjGroupItemPy)
generate_from_xml(DrawViewAnnotationPy)
generate_from_xml(DrawLeaderLinePy)
generate_from_xml(DrawTextLeaderPy)
generate_from_xml(DrawRichAnnoPy)


SET(Draw_SRCS
Expand Down Expand Up @@ -97,8 +97,8 @@ SET(Draw_SRCS
DrawViewDetail.h
DrawLeaderLine.cpp
DrawLeaderLine.h
DrawTextLeader.cpp
DrawTextLeader.h
DrawRichAnno.cpp
DrawRichAnno.h
)

SET(TechDraw_SRCS
Expand Down Expand Up @@ -158,8 +158,8 @@ SET(Python_SRCS
DrawViewAnnotationPyImp.cpp
DrawLeaderLinePy.xml
DrawLeaderLinePyImp.cpp
DrawTextLeaderPy.xml
DrawTextLeaderPyImp.cpp
DrawRichAnnoPy.xml
DrawRichAnnoPyImp.cpp
)

SOURCE_GROUP("Mod" FILES ${TechDraw_SRCS})
Expand Down
43 changes: 39 additions & 4 deletions src/Mod/TechDraw/App/DrawLeaderLine.cpp
Expand Up @@ -57,6 +57,7 @@ DrawLeaderLine::DrawLeaderLine(void)
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");
ADD_PROPERTY_TYPE(AutoHorizontal ,(getDefAuto()),group,App::Prop_None,"Forces last line segment horizontal");

//hide the DrawView properties that don't apply to Leader
ScaleType.setStatus(App::Property::ReadOnly,true);
Expand All @@ -76,11 +77,9 @@ DrawLeaderLine::~DrawLeaderLine()

void DrawLeaderLine::onChanged(const App::Property* prop)
{
if (!isRestoring()) {
//nothing in particular
}
// if (!isRestoring()) {
// }
DrawView::onChanged(prop);

}

short DrawLeaderLine::mustExecute() const
Expand Down Expand Up @@ -113,6 +112,15 @@ App::DocumentObjectExecReturn *DrawLeaderLine::execute(void)
return DrawView::execute();
}

//this doesn't really work because LeaderParent is not available?
void DrawLeaderLine::onDocumentRestored(void)
{
// Base::Console().Message("DLL::onDocumentRestored()\n");
requestPaint();
DrawView::onDocumentRestored();
}


DrawView* DrawLeaderLine::getBaseView(void) const
{
DrawView* result = nullptr;
Expand Down Expand Up @@ -168,6 +176,33 @@ Base::Vector3d DrawLeaderLine::getAttachPoint(void)
return result;
}

void DrawLeaderLine::adjustLastSegment(void)
{
// Base::Console().Message("DLL::adjustLastSegment()\n");
bool adjust = AutoHorizontal.getValue();
std::vector<Base::Vector3d> wp = WayPoints.getValues();
if (adjust) {
if (wp.size() > 1) {
int iLast = wp.size() - 1;
int iPen = wp.size() - 2;
Base::Vector3d last = wp.at(iLast);
Base::Vector3d penUlt = wp.at(iPen);
last.y = penUlt.y;

This comment has been minimized.

Copy link
@dannystaple

dannystaple Nov 5, 2022

Trying to determine if this line is why I see https://forum.freecadweb.org/viewtopic.php?f=3&t=73207&p=638814#p638814. I realise it's been a few years, but @WandererFan do you remember why this Y manipulation is made?

This comment has been minimized.

Copy link
@WandererFan

WandererFan Nov 6, 2022

Author Contributor

It implements Auto Horizontal setting for final segment of leader by making the last two points have the same Y.

wp.at(iLast) = last;
}
}
WayPoints.setValues(wp);
}

bool DrawLeaderLine::getDefAuto(void) const
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->
GetGroup("Preferences")->GetGroup("Mod/TechDraw/LeaderLines");
bool result = hGrp->GetBool("AutoHorizontal",true);
return result;
}


PyObject *DrawLeaderLine::getPyObject(void)
{
if (PythonObject.is(Py::_None())) {
Expand Down
6 changes: 6 additions & 0 deletions src/Mod/TechDraw/App/DrawLeaderLine.h
Expand Up @@ -47,9 +47,12 @@ class TechDrawExport DrawLeaderLine : public TechDraw::DrawView
App::PropertyInteger StartSymbol;
App::PropertyInteger EndSymbol;
App::PropertyBool Scalable;
App::PropertyBool AutoHorizontal;

virtual short mustExecute() const;
virtual App::DocumentObjectExecReturn *execute(void);
virtual void onDocumentRestored(void) override;


virtual const char* getViewProviderName(void) const {
return "TechDrawGui::ViewProviderLeader";
Expand All @@ -62,6 +65,9 @@ class TechDrawExport DrawLeaderLine : public TechDraw::DrawView
virtual App::DocumentObject* getBaseObject(void) const;
bool keepUpdated(void);
double getScale(void);
void adjustLastSegment(void);
bool getDefAuto(void) const;


protected:
virtual void onChanged(const App::Property* prop);
Expand Down
Expand Up @@ -32,31 +32,35 @@

#include "DrawUtil.h"

#include <Mod/TechDraw/App/DrawTextLeaderPy.h> // generated from DrawTextLeaderPy.xml
#include "DrawTextLeader.h"
#include <Mod/TechDraw/App/DrawRichAnnoPy.h> // generated from DrawRichAnnoPy.xml
#include "DrawRichAnno.h"

using namespace TechDraw;

//===========================================================================
// DrawTextLeader - DrawLeaderLine + movable text block
// DrawRichAnno - movable rich text block
//===========================================================================

PROPERTY_SOURCE(TechDraw::DrawTextLeader, TechDraw::DrawLeaderLine)
PROPERTY_SOURCE(TechDraw::DrawRichAnno, TechDraw::DrawView)

DrawTextLeader::DrawTextLeader(void)
DrawRichAnno::DrawRichAnno(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");
static const char *group = "Text Block";

ADD_PROPERTY_TYPE(AnnoParent,(0),group,(App::PropertyType)(App::Prop_None),
"Object to which this annontation is attached");
ADD_PROPERTY_TYPE(AnnoText, (""), group, App::Prop_None, "Anno text");
// Base::Vector3d pos(0.0,0.0,0.0);
// ADD_PROPERTY_TYPE(TextPosition, (pos), group, App::Prop_None, "Anno position relative to parent");
ADD_PROPERTY_TYPE(ShowFrame, (true), group, App::Prop_None, "Outline rectangle on/off");
ADD_PROPERTY_TYPE(MaxWidth, (-1.0), group, App::Prop_None, "Width limit before auto wrap");
}

DrawTextLeader::~DrawTextLeader()
DrawRichAnno::~DrawRichAnno()
{
}

void DrawTextLeader::onChanged(const App::Property* prop)
void DrawRichAnno::onChanged(const App::Property* prop)
{
if (!isRestoring()) {
//nothing in particular
Expand All @@ -65,11 +69,11 @@ void DrawTextLeader::onChanged(const App::Property* prop)

}

short DrawTextLeader::mustExecute() const
short DrawRichAnno::mustExecute() const
{
bool result = 0;
if (!isRestoring()) {
result = (LeaderText.isTouched());
result = (AnnoText.isTouched());
}
if (result) {
return result;
Expand All @@ -78,20 +82,35 @@ short DrawTextLeader::mustExecute() const
return DrawView::mustExecute();
}

App::DocumentObjectExecReturn *DrawTextLeader::execute(void)
App::DocumentObjectExecReturn *DrawRichAnno::execute(void)
{
// Base::Console().Message("DTL::execute()\n");
// Base::Console().Message("DRA::execute()\n");
if (!keepUpdated()) {
return App::DocumentObject::StdReturn;
}
return DrawView::execute();
}

PyObject *DrawTextLeader::getPyObject(void)
DrawView* DrawRichAnno::getBaseView(void) const
{
// Base::Console().Message("DRA::getBaseView() - %s\n", getNameInDocument());
DrawView* result = nullptr;
App::DocumentObject* baseObj = AnnoParent.getValue();
if (baseObj != nullptr) {
DrawView* cast = dynamic_cast<DrawView*>(baseObj);
if (cast != nullptr) {
result = cast;
}
}
return result;
}


PyObject *DrawRichAnno::getPyObject(void)
{
if (PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::Object(new DrawTextLeaderPy(this),true);
PythonObject = Py::Object(new DrawRichAnnoPy(this),true);
}
return Py::new_reference_to(PythonObject);
}
Expand All @@ -100,13 +119,13 @@ PyObject *DrawTextLeader::getPyObject(void)

namespace App {
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawTextLeaderPython, TechDraw::DrawTextLeader)
template<> const char* TechDraw::DrawTextLeaderPython::getViewProviderName(void) const {
return "TechDrawGui::ViewProviderTextLeader";
PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawRichAnnoPython, TechDraw::DrawRichAnno)
template<> const char* TechDraw::DrawRichAnnoPython::getViewProviderName(void) const {
return "TechDrawGui::ViewProviderRichAnno";
}
/// @endcond

// explicit template instantiation
template class TechDrawExport FeaturePythonT<TechDraw::DrawTextLeader>;
template class TechDrawExport FeaturePythonT<TechDraw::DrawRichAnno>;
}

Expand Up @@ -20,45 +20,50 @@
* *
***************************************************************************/

#ifndef _TechDraw_DrawTextLeader_h_
#define _TechDraw_DrawTextLeader_h_
#ifndef _TechDraw_DrawRichAnno_h_
#define _TechDraw_DrawRichAnno_h_

# include <App/DocumentObject.h>
# include <App/FeaturePython.h>

#include "DrawLeaderLine.h"
#include "DrawView.h"


namespace TechDraw
{

class TechDrawExport DrawTextLeader : public TechDraw::DrawLeaderLine
class TechDrawExport DrawRichAnno : public TechDraw::DrawView
{
PROPERTY_HEADER(TechDraw::DrawTextLeader);
PROPERTY_HEADER(TechDraw::DrawRichAnno);

public:
DrawTextLeader();
virtual ~DrawTextLeader();
DrawRichAnno();
virtual ~DrawRichAnno();

App::PropertyString LeaderText;
App::PropertyVector TextPosition;
App::PropertyLink AnnoParent;
App::PropertyString AnnoText;
// App::PropertyVector TextPosition;
App::PropertyBool ShowFrame;
App::PropertyFloat MaxWidth;
App::PropertyVector AttachPoint;

virtual short mustExecute() const;
virtual App::DocumentObjectExecReturn *execute(void);

virtual const char* getViewProviderName(void) const {
return "TechDrawGui::ViewProviderTextLeader";
return "TechDrawGui::ViewProviderRichAnno";
}
virtual PyObject *getPyObject(void);
virtual QRectF getRect() const { return QRectF(0,0,1,1);}
DrawView* getBaseView(void) const;

protected:
virtual void onChanged(const App::Property* prop);

private:
};

typedef App::FeaturePythonT<DrawTextLeader> DrawTextLeaderPython;
typedef App::FeaturePythonT<DrawRichAnno> DrawRichAnnoPython;

} //namespace TechDraw
#endif
@@ -1,17 +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="DrawLeaderLinePy"
Name="DrawTextLeaderPy"
Twin="DrawTextLeader"
TwinPointer="DrawTextLeader"
Include="Mod/TechDraw/App/DrawTextLeader.h"
Father="DrawViewPy"
Name="DrawRichAnnoPy"
Twin="DrawRichAnno"
TwinPointer="DrawRichAnno"
Include="Mod/TechDraw/App/DrawRichAnno.h"
Namespace="TechDraw"
FatherInclude="Mod/TechDraw/App/DrawLeaderLinePy.h"
FatherInclude="Mod/TechDraw/App/DrawViewPy.h"
FatherNamespace="TechDraw">
<Documentation>
<Author Licence="LGPL" Name="WandererFan" EMail="wandererfan@gmail.com" />
<UserDocu>Feature for adding text leaders to Technical Drawings</UserDocu>
<UserDocu>Feature for adding rich annotation blocks to Technical Drawings</UserDocu>
</Documentation>
<CustomAttributes />
</PythonExport>
Expand Down
Expand Up @@ -28,27 +28,27 @@
#include <Base/PyObjectBase.h>
#include <Base/Vector3D.h>

#include "DrawTextLeader.h"
#include "DrawRichAnno.h"

// inclusion of the generated files (generated out of DrawTextLeaderPy.xml)
// inclusion of the generated files (generated out of DrawRichAnnoPy.xml)
#include <Base/VectorPy.h>
#include <Mod/TechDraw/App/DrawTextLeaderPy.h>
#include <Mod/TechDraw/App/DrawTextLeaderPy.cpp>
#include <Mod/TechDraw/App/DrawRichAnnoPy.h>
#include <Mod/TechDraw/App/DrawRichAnnoPy.cpp>

using namespace TechDraw;

// returns a string which represents the object e.g. when printed in python
std::string DrawTextLeaderPy::representation(void) const
std::string DrawRichAnnoPy::representation(void) const
{
return std::string("<DrawTextLeader object>");
return std::string("<DrawRichAnno object>");
}

PyObject *DrawTextLeaderPy::getCustomAttributes(const char* /*attr*/) const
PyObject *DrawRichAnnoPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}

int DrawTextLeaderPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
int DrawRichAnnoPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}

0 comments on commit 6c69988

Please sign in to comment.