TechDraw: add Balloons
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
#include "DrawViewMulti.h"
|
||||
#include "DrawViewImage.h"
|
||||
#include "DrawViewDetail.h"
|
||||
#include "DrawViewBalloon.h"
|
||||
|
||||
namespace TechDraw {
|
||||
extern PyObject* initModule();
|
||||
@@ -78,6 +79,7 @@ PyMOD_INIT_FUNC(TechDraw)
|
||||
TechDraw::DrawProjGroup ::init();
|
||||
TechDraw::DrawProjGroupItem ::init();
|
||||
TechDraw::DrawViewDetail ::init();
|
||||
TechDraw::DrawViewBalloon ::init();
|
||||
|
||||
|
||||
TechDraw::DrawTemplate ::init();
|
||||
|
||||
@@ -74,6 +74,8 @@ SET(Draw_SRCS
|
||||
DrawViewCollection.h
|
||||
DrawViewDimension.cpp
|
||||
DrawViewDimension.h
|
||||
DrawViewBalloon.cpp
|
||||
DrawViewBalloon.h
|
||||
DrawViewSection.cpp
|
||||
DrawViewSection.h
|
||||
DrawHatch.cpp
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
#include "DrawViewCollection.h"
|
||||
#include "DrawViewPart.h"
|
||||
#include "DrawViewDimension.h"
|
||||
#include "DrawViewBalloon.h"
|
||||
|
||||
#include <Mod/TechDraw/App/DrawPagePy.h> // generated from DrawPagePy.xml
|
||||
|
||||
@@ -81,9 +82,9 @@ DrawPage::DrawPage(void)
|
||||
|
||||
ADD_PROPERTY_TYPE(KeepUpdated, (autoUpdate), group, (App::PropertyType)(App::Prop_None), "Keep page in sync with model");
|
||||
ADD_PROPERTY_TYPE(Template, (0), group, (App::PropertyType)(App::Prop_None), "Attached Template");
|
||||
Template.setScope(App::LinkScope::Global);
|
||||
Template.setScope(App::LinkScope::Global);
|
||||
ADD_PROPERTY_TYPE(Views, (0), group, (App::PropertyType)(App::Prop_None), "Attached Views");
|
||||
Views.setScope(App::LinkScope::Global);
|
||||
Views.setScope(App::LinkScope::Global);
|
||||
|
||||
// Projection Properties
|
||||
ProjectionType.setEnums(ProjectionTypeEnums);
|
||||
@@ -255,8 +256,9 @@ int DrawPage::addView(App::DocumentObject *docObj)
|
||||
return -1;
|
||||
DrawView* view = static_cast<DrawView*>(docObj);
|
||||
|
||||
//position all new views in center of Page (exceptDVDimension)
|
||||
if (!docObj->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) {
|
||||
//position all new views in center of Page (exceptDVDimension)
|
||||
if (!docObj->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId()) &&
|
||||
!docObj->isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId())) {
|
||||
view->X.setValue(getPageWidth()/2.0);
|
||||
view->Y.setValue(getPageHeight()/2.0);
|
||||
}
|
||||
|
||||
175
src/Mod/TechDraw/App/DrawViewBalloon.cpp
Normal file
175
src/Mod/TechDraw/App/DrawViewBalloon.cpp
Normal file
@@ -0,0 +1,175 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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 <sstream>
|
||||
# include <cstring>
|
||||
# include <cstdlib>
|
||||
# include <exception>
|
||||
# include <QString>
|
||||
# include <QStringList>
|
||||
# include <QRegExp>
|
||||
#include <BRepBuilderAPI_MakeVertex.hxx>
|
||||
#include <BRepBuilderAPI_MakeEdge.hxx>
|
||||
#include <BRepExtrema_DistShapeShape.hxx>
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <TopoDS_Edge.hxx>
|
||||
#endif
|
||||
|
||||
#include <QLocale>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Quantity.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/UnitsApi.h>
|
||||
|
||||
#include <Mod/Measure/App/Measurement.h>
|
||||
|
||||
#include "Geometry.h"
|
||||
#include "DrawViewPart.h"
|
||||
#include "DrawViewBalloon.h"
|
||||
#include "DrawUtil.h"
|
||||
#include "LineGroup.h"
|
||||
|
||||
|
||||
//#include <Mod/TechDraw/App/DrawViewBalloonPy.h> // generated from DrawViewDimensionPy.xml
|
||||
|
||||
using namespace TechDraw;
|
||||
|
||||
//===========================================================================
|
||||
// DrawViewDimension
|
||||
//===========================================================================
|
||||
|
||||
PROPERTY_SOURCE(TechDraw::DrawViewBalloon, TechDraw::DrawView)
|
||||
|
||||
const char* DrawViewBalloon::endTypeEnums[]= {"Arrow",
|
||||
"Dot",
|
||||
NULL};
|
||||
|
||||
const char* DrawViewBalloon::balloonTypeEnums[]= {"Circular",
|
||||
"None",
|
||||
"Triangle",
|
||||
"Inspection",
|
||||
"Hexagon",
|
||||
"Square",
|
||||
"Rectangle",
|
||||
NULL};
|
||||
|
||||
DrawViewBalloon::DrawViewBalloon(void)
|
||||
{
|
||||
ADD_PROPERTY_TYPE(Text , (""),"",App::Prop_None,"The text to be displayed");
|
||||
ADD_PROPERTY_TYPE(sourceView,(0),"",(App::PropertyType)(App::Prop_None),"Source view for balloon");
|
||||
ADD_PROPERTY_TYPE(OriginX,(0),"",(App::PropertyType)(App::Prop_None),"Balloon origin x");
|
||||
ADD_PROPERTY_TYPE(OriginY,(0),"",(App::PropertyType)(App::Prop_None),"Balloon origin y");
|
||||
ADD_PROPERTY_TYPE(OriginIsSet, (false), "",(App::PropertyType)(App::Prop_None),"Balloon origin is set");
|
||||
|
||||
EndType.setEnums(endTypeEnums);
|
||||
ADD_PROPERTY(EndType,((long)0));
|
||||
|
||||
Symbol.setEnums(balloonTypeEnums);
|
||||
ADD_PROPERTY(Symbol,((long)0));
|
||||
|
||||
ADD_PROPERTY_TYPE(SymbolScale,(1),"",(App::PropertyType)(App::Prop_None),"Balloon symbol scale");
|
||||
|
||||
ADD_PROPERTY_TYPE(TextWrapLen,(-1),"",(App::PropertyType)(App::Prop_None),"Balloon symbol scale");
|
||||
|
||||
OriginX.setStatus(App::Property::Hidden,false);
|
||||
OriginY.setStatus(App::Property::Hidden,false);
|
||||
OriginIsSet.setStatus(App::Property::Hidden,false);
|
||||
OriginIsSet.setStatus(App::Property::ReadOnly,true);
|
||||
|
||||
sourceView.setScope(App::LinkScope::Global);
|
||||
sourceView.setStatus(App::Property::Hidden,true);
|
||||
Rotation.setStatus(App::Property::Hidden,true);
|
||||
ScaleType.setStatus(App::Property::Hidden,true);
|
||||
Scale.setStatus(App::Property::Hidden,true);
|
||||
Caption.setStatus(App::Property::Hidden,true);
|
||||
X.setStatus(App::Property::Hidden,true);
|
||||
Y.setStatus(App::Property::Hidden,true);
|
||||
}
|
||||
|
||||
DrawViewBalloon::~DrawViewBalloon()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DrawViewBalloon::onChanged(const App::Property* prop)
|
||||
{
|
||||
DrawView::onChanged(prop);
|
||||
}
|
||||
|
||||
void DrawViewBalloon::onDocumentRestored()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
short DrawViewBalloon::mustExecute() const
|
||||
{
|
||||
bool result = 0;
|
||||
if (!isRestoring()) {
|
||||
result = Text.isTouched();
|
||||
}
|
||||
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
auto dvp = getViewPart();
|
||||
if (dvp != nullptr) {
|
||||
result = dvp->isTouched();
|
||||
}
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return DrawView::mustExecute();
|
||||
}
|
||||
|
||||
DrawViewPart* DrawViewBalloon::getViewPart() const
|
||||
{
|
||||
App::DocumentObject* obj = sourceView.getValue();
|
||||
DrawViewPart* result = dynamic_cast<DrawViewPart*>(obj);
|
||||
return result;
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *DrawViewBalloon::execute(void)
|
||||
{
|
||||
requestPaint();
|
||||
return App::DocumentObject::execute();
|
||||
}
|
||||
/*
|
||||
PyObject *DrawViewBalloon::getPyObject(void)
|
||||
{
|
||||
if (PythonObject.is(Py::_None())) {
|
||||
// ref counter is set to 1
|
||||
PythonObject = Py::Object(new DrawViewBalloonPy(this),true);
|
||||
}
|
||||
return Py::new_reference_to(PythonObject);
|
||||
}
|
||||
*/
|
||||
85
src/Mod/TechDraw/App/DrawViewBalloon.h
Normal file
85
src/Mod/TechDraw/App/DrawViewBalloon.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* 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_DrawViewBalloon_h_
|
||||
#define _TechDraw_DrawViewBalloon_h_
|
||||
#include <tuple>
|
||||
|
||||
# include <App/DocumentObject.h>
|
||||
# include <App/FeaturePython.h>
|
||||
# include <App/PropertyLinks.h>
|
||||
|
||||
#include "DrawView.h"
|
||||
|
||||
class TopoDS_Shape;
|
||||
|
||||
namespace Measure {
|
||||
class Measurement;
|
||||
}
|
||||
namespace TechDraw {
|
||||
|
||||
class DrawViewPart;
|
||||
|
||||
class TechDrawExport DrawViewBalloon : public TechDraw::DrawView
|
||||
{
|
||||
PROPERTY_HEADER(TechDraw::DrawViewBalloon);
|
||||
|
||||
public:
|
||||
/// Constructor
|
||||
DrawViewBalloon();
|
||||
virtual ~DrawViewBalloon();
|
||||
|
||||
App::PropertyLink sourceView;
|
||||
App::PropertyString Text;
|
||||
App::PropertyEnumeration EndType;
|
||||
App::PropertyEnumeration Symbol;
|
||||
App::PropertyFloat SymbolScale;
|
||||
App::PropertyFloat OriginX;
|
||||
App::PropertyFloat OriginY;
|
||||
App::PropertyBool OriginIsSet;
|
||||
App::PropertyFloat TextWrapLen;
|
||||
|
||||
short mustExecute() const;
|
||||
|
||||
DrawViewPart* getViewPart() const;
|
||||
|
||||
//virtual PyObject *getPyObject(void);
|
||||
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
//@}
|
||||
|
||||
/// returns the type name of the ViewProvider
|
||||
virtual const char* getViewProviderName(void) const {
|
||||
return "TechDrawGui::ViewProviderBalloon";
|
||||
}
|
||||
|
||||
protected:
|
||||
void onChanged(const App::Property* prop);
|
||||
virtual void onDocumentRestored();
|
||||
|
||||
private:
|
||||
static const char* endTypeEnums[];
|
||||
static const char* balloonTypeEnums[];
|
||||
};
|
||||
|
||||
} //namespace TechDraw
|
||||
#endif
|
||||
@@ -97,6 +97,7 @@
|
||||
#include "DrawHatch.h"
|
||||
#include "DrawGeomHatch.h"
|
||||
#include "DrawViewDimension.h"
|
||||
#include "DrawViewBalloon.h"
|
||||
#include "DrawViewDetail.h"
|
||||
#include "DrawPage.h"
|
||||
#include "EdgeWalker.h"
|
||||
@@ -559,6 +560,20 @@ std::vector<TechDraw::DrawViewDimension*> DrawViewPart::getDimensions() const
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<TechDraw::DrawViewBalloon*> DrawViewPart::getBalloons() const
|
||||
{
|
||||
std::vector<TechDraw::DrawViewBalloon*> result;
|
||||
std::vector<App::DocumentObject*> children = getInList();
|
||||
std::sort(children.begin(),children.end(),std::less<App::DocumentObject*>());
|
||||
std::vector<App::DocumentObject*>::iterator newEnd = std::unique(children.begin(),children.end());
|
||||
for (std::vector<App::DocumentObject*>::iterator it = children.begin(); it != newEnd; ++it) {
|
||||
if ((*it)->getTypeId().isDerivedFrom(DrawViewBalloon::getClassTypeId())) {
|
||||
TechDraw::DrawViewBalloon* balloon = dynamic_cast<TechDraw::DrawViewBalloon*>(*it);
|
||||
result.push_back(balloon);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const std::vector<TechDrawGeometry::Vertex *> & DrawViewPart::getVertexGeometry() const
|
||||
{
|
||||
@@ -837,6 +852,22 @@ void DrawViewPart::unsetupObject()
|
||||
}
|
||||
}
|
||||
|
||||
// Remove Balloons which reference this DVP
|
||||
// must use page->removeObject first
|
||||
page = findParentPage();
|
||||
if (page != nullptr) {
|
||||
std::vector<TechDraw::DrawViewBalloon*> balloons = getBalloons();
|
||||
std::vector<TechDraw::DrawViewBalloon*>::iterator it3 = balloons.begin();
|
||||
for (; it3 != balloons.end(); it3++) {
|
||||
page->removeView(*it3);
|
||||
const char* name = (*it3)->getNameInDocument();
|
||||
if (name) {
|
||||
Base::Interpreter().runStringArg("App.getDocument(\"%s\").removeObject(\"%s\")",
|
||||
docName.c_str(), name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//! is this an Isometric projection?
|
||||
|
||||
@@ -67,6 +67,7 @@ class DrawViewDimension;
|
||||
class DrawProjectSplit;
|
||||
class DrawViewSection;
|
||||
class DrawViewDetail;
|
||||
class DrawViewBalloon;
|
||||
}
|
||||
|
||||
namespace TechDraw
|
||||
@@ -103,6 +104,7 @@ public:
|
||||
std::vector<TechDraw::DrawHatch*> getHatches(void) const;
|
||||
std::vector<TechDraw::DrawGeomHatch*> getGeomHatches(void) const;
|
||||
std::vector<TechDraw::DrawViewDimension*> getDimensions() const;
|
||||
std::vector<TechDraw::DrawViewBalloon*> getBalloons() const;
|
||||
|
||||
//TODO: are there use-cases for Python access to TechDrawGeometry???
|
||||
|
||||
|
||||
Reference in New Issue
Block a user