Skip to content

Commit

Permalink
Text Leader initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed May 6, 2019
1 parent 3be0cbc commit 7f07195
Show file tree
Hide file tree
Showing 56 changed files with 9,642 additions and 50 deletions.
7 changes: 6 additions & 1 deletion src/Mod/TechDraw/App/AppTechDraw.cpp
Expand Up @@ -40,6 +40,8 @@
#include "DrawViewImage.h"
#include "DrawViewDetail.h"
#include "DrawViewBalloon.h"
#include "DrawLeaderLine.h"
#include "DrawTextLeader.h"

namespace TechDraw {
extern PyObject* initModule();
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
17 changes: 15 additions & 2 deletions src/Mod/TechDraw/App/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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})
Expand Down
193 changes: 193 additions & 0 deletions src/Mod/TechDraw/App/DrawLeaderLine.cpp
@@ -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>;
}

75 changes: 75 additions & 0 deletions src/Mod/TechDraw/App/DrawLeaderLine.h
@@ -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
18 changes: 18 additions & 0 deletions src/Mod/TechDraw/App/DrawLeaderLinePy.xml
@@ -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>

0 comments on commit 7f07195

Please sign in to comment.