[TD]Allow balloons to be attached to non-part views

This commit is contained in:
wandererfan
2023-01-10 09:24:12 -05:00
committed by WandererFan
parent 437457e996
commit bc036abb30
15 changed files with 1491 additions and 1453 deletions

View File

@@ -62,16 +62,13 @@ DrawPage::DrawPage(void)
nowUnsetting = false;
forceRedraw(false);
ADD_PROPERTY_TYPE(KeepUpdated,
(Preferences::keepPagesUpToDate()),
group,
(App::PropertyType)(App::Prop_Output),
"Keep page in sync with model");
ADD_PROPERTY_TYPE(
Template, (nullptr), group, (App::PropertyType)(App::Prop_None), "Attached Template");
ADD_PROPERTY_TYPE(KeepUpdated, (Preferences::keepPagesUpToDate()), group,
(App::PropertyType)(App::Prop_Output), "Keep page in sync with model");
ADD_PROPERTY_TYPE(Template, (nullptr), group, (App::PropertyType)(App::Prop_None),
"Attached Template");
Template.setScope(App::LinkScope::Global);
ADD_PROPERTY_TYPE(
Views, (nullptr), group, (App::PropertyType)(App::Prop_None), "Attached Views");
ADD_PROPERTY_TYPE(Views, (nullptr), group, (App::PropertyType)(App::Prop_None),
"Attached Views");
Views.setScope(App::LinkScope::Global);
// Projection Properties
@@ -84,24 +81,16 @@ DrawPage::DrawPage(void)
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/General");
double defScale = hGrp->GetFloat("DefaultScale", 1.0);
ADD_PROPERTY_TYPE(Scale,
(defScale),
group,
(App::PropertyType)(App::Prop_None),
ADD_PROPERTY_TYPE(Scale, (defScale), group, (App::PropertyType)(App::Prop_None),
"Scale factor for this Page");
ADD_PROPERTY_TYPE(NextBalloonIndex,
(1),
group,
(App::PropertyType)(App::Prop_None),
ADD_PROPERTY_TYPE(NextBalloonIndex, (1), group, (App::PropertyType)(App::Prop_None),
"Auto-numbering for Balloons");
Scale.setConstraints(&scaleRange);
balloonParent = nullptr;
}
DrawPage::~DrawPage()
{}
DrawPage::~DrawPage() {}
void DrawPage::onBeforeChange(const App::Property* prop)
{
@@ -113,8 +102,8 @@ void DrawPage::onChanged(const App::Property* prop)
if ((prop == &KeepUpdated) && KeepUpdated.getValue()) {
if (!isRestoring() && !isUnsetting()) {
//would be nice if this message was displayed immediately instead of after the recomputeFeature
Base::Console().Message(
"Rebuilding Views for: %s/%s\n", getNameInDocument(), Label.getValue());
Base::Console().Message("Rebuilding Views for: %s/%s\n", getNameInDocument(),
Label.getValue());
updateAllViews();
purgeTouched();
}
@@ -131,8 +120,7 @@ void DrawPage::onChanged(const App::Property* prop)
if (!isRestoring()) {
const std::vector<App::DocumentObject*>& vals = Views.getValues();
for (std::vector<App::DocumentObject*>::const_iterator it = vals.begin();
it < vals.end();
++it) {
it < vals.end(); ++it) {
TechDraw::DrawView* view = dynamic_cast<TechDraw::DrawView*>(*it);
if (view && view->ScaleType.isValue("Page")) {
if (std::abs(view->Scale.getValue() - Scale.getValue()) > FLT_EPSILON) {
@@ -159,10 +147,7 @@ void DrawPage::onChanged(const App::Property* prop)
}
//Page is just a container. It doesn't "do" anything.
App::DocumentObjectExecReturn* DrawPage::execute(void)
{
return App::DocumentObject::execute();
}
App::DocumentObjectExecReturn* DrawPage::execute(void) { return App::DocumentObject::execute(); }
// this is now irrelevant, b/c DP::execute doesn't do anything.
short DrawPage::mustExecute() const
@@ -329,10 +314,7 @@ int DrawPage::removeView(App::DocumentObject* docObj)
return Views.getSize();
}
void DrawPage::requestPaint(void)
{
signalGuiPaint(this);
}
void DrawPage::requestPaint(void) { signalGuiPaint(this); }
//this doesn't work right because there is no guaranteed of the restoration order
void DrawPage::onDocumentRestored()
@@ -417,8 +399,7 @@ void DrawPage::unsetupObject()
if (v->isAttachedToDocument()) {
std::string viewName = v->getNameInDocument();
Base::Interpreter().runStringArg("App.getDocument(\"%s\").removeObject(\"%s\")",
docName.c_str(),
viewName.c_str());
docName.c_str(), viewName.c_str());
}
}
std::vector<App::DocumentObject*> emptyViews;//probably superfluous
@@ -432,8 +413,8 @@ void DrawPage::unsetupObject()
App::DocumentObject* tmp = Template.getValue();
if (tmp) {
std::string templateName = Template.getValue()->getNameInDocument();
Base::Interpreter().runStringArg(
"App.getDocument(\"%s\").removeObject(\"%s\")", docName.c_str(), templateName.c_str());
Base::Interpreter().runStringArg("App.getDocument(\"%s\").removeObject(\"%s\")",
docName.c_str(), templateName.c_str());
}
Template.setValue(nullptr);
}

View File

@@ -48,31 +48,29 @@ public:
App::PropertyBool KeepUpdated;
App::PropertyFloatConstraint Scale;
App::PropertyEnumeration ProjectionType; // First or Third Angle
App::PropertyEnumeration ProjectionType;// First or Third Angle
App::PropertyInteger NextBalloonIndex;
App::PropertyInteger NextBalloonIndex;
/** @name methods override Feature */
//@{
/// recalculate the Feature
App::DocumentObjectExecReturn *execute() override;
App::DocumentObjectExecReturn* execute() override;
//@}
void handleChangedPropertyType(
Base::XMLReader &reader, const char * TypeName, App::Property * prop) override;
void handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName,
App::Property* prop) override;
int addView(App::DocumentObject *docObj);
int addView(App::DocumentObject* docObj);
int removeView(App::DocumentObject* docObj);
short mustExecute() const override;
boost::signals2::signal<void (const DrawPage*)> signalGuiPaint;
boost::signals2::signal<void(const DrawPage*)> signalGuiPaint;
/// returns the type name of the ViewProvider
const char* getViewProviderName() const override {
return "TechDrawGui::ViewProviderPage";
}
const char* getViewProviderName() const override { return "TechDrawGui::ViewProviderPage"; }
PyObject *getPyObject() override;
PyObject* getPyObject() override;
//App::DocumentObjectExecReturn * recompute(void);
//App::DocumentObjectExecReturn * recompute(void);
/// Check whether we've got a valid template
/*!
@@ -93,8 +91,7 @@ public:
int getOrientation() const;
bool isUnsetting() { return nowUnsetting; }
void requestPaint();
std::vector<App::DocumentObject*> getAllViews() ;
DrawViewPart *balloonParent; //could be many balloons on page?
std::vector<App::DocumentObject*> getAllViews();
int getNextBalloonIndex();
@@ -102,7 +99,7 @@ public:
static bool GlobalUpdateDrawings();
static bool AllowPageOverride();
void forceRedraw(bool b) { m_forceRedraw = b; }
bool forceRedraw() { return m_forceRedraw; }
bool forceRedraw() { return m_forceRedraw; }
void redrawCommand();
bool canUpdate() const;
@@ -121,13 +118,11 @@ private:
static const char* ProjectionTypeEnums[];
bool nowUnsetting;
static App::PropertyFloatConstraint::Constraints scaleRange;
};
using DrawPagePython = App::FeaturePythonT<DrawPage>;
} //namespace TechDraw
}//namespace TechDraw
#endif

View File

@@ -23,27 +23,26 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <cstdlib>
# include <cstring>
# include <sstream>
# include <Precision.hxx>
#include <Precision.hxx>
#include <cstdlib>
#include <cstring>
#include <sstream>
#endif
#include <App/Application.h>
#include <Base/Parameter.h>
#include <Mod/Measure/App/Measurement.h>
#include "DrawViewBalloon.h"
#include "ArrowPropEnum.h"
#include "DrawViewBalloon.h"
#include "DrawViewPart.h"
#include "Preferences.h"
using namespace TechDraw;
App::PropertyFloatConstraint::Constraints DrawViewBalloon::SymbolScaleRange = { Precision::Confusion(),
std::numeric_limits<double>::max(),
(0.1) };
App::PropertyFloatConstraint::Constraints DrawViewBalloon::SymbolScaleRange = {
Precision::Confusion(), std::numeric_limits<double>::max(), (0.1)};
//===========================================================================
// DrawViewBalloon
@@ -58,116 +57,113 @@ App::PropertyFloatConstraint::Constraints DrawViewBalloon::SymbolScaleRange = {
PROPERTY_SOURCE(TechDraw::DrawViewBalloon, TechDraw::DrawView)
const char* DrawViewBalloon::balloonTypeEnums[]= {"Circular",
"None",
"Triangle",
"Inspection",
"Hexagon",
"Square",
"Rectangle",
"Line",
nullptr};
const char* DrawViewBalloon::balloonTypeEnums[] = {"Circular", "None", "Triangle",
"Inspection", "Hexagon", "Square",
"Rectangle", "Line", nullptr};
DrawViewBalloon::DrawViewBalloon()
{
ADD_PROPERTY_TYPE(Text, (""), "", App::Prop_None, "The text to be displayed");
ADD_PROPERTY_TYPE(SourceView, (nullptr), "", (App::PropertyType)(App::Prop_None), "Source view for balloon");
ADD_PROPERTY_TYPE(SourceView, (nullptr), "", (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");
EndType.setEnums(ArrowPropEnum::ArrowTypeEnums);
ADD_PROPERTY_TYPE(EndType, (prefEnd()), "", (App::PropertyType)(App::Prop_None), "End symbol for the balloon line");
ADD_PROPERTY_TYPE(EndType, (prefEnd()), "", (App::PropertyType)(App::Prop_None),
"End symbol for the balloon line");
ADD_PROPERTY_TYPE(EndTypeScale, (1.0), "", (App::PropertyType)(App::Prop_None), "End symbol scale factor");
ADD_PROPERTY_TYPE(EndTypeScale, (1.0), "", (App::PropertyType)(App::Prop_None),
"End symbol scale factor");
EndTypeScale.setConstraints(&SymbolScaleRange);
BubbleShape.setEnums(balloonTypeEnums);
ADD_PROPERTY_TYPE(BubbleShape, (prefShape()), "", (App::PropertyType)(App::Prop_None), "Shape of the balloon bubble");
ADD_PROPERTY_TYPE(BubbleShape, (prefShape()), "", (App::PropertyType)(App::Prop_None),
"Shape of the balloon bubble");
ADD_PROPERTY_TYPE(ShapeScale, (1.0), "", (App::PropertyType)(App::Prop_None), "Balloon shape scale");
ADD_PROPERTY_TYPE(ShapeScale, (1.0), "", (App::PropertyType)(App::Prop_None),
"Balloon shape scale");
ShapeScale.setConstraints(&SymbolScaleRange);
ADD_PROPERTY_TYPE(TextWrapLen, (-1), "", (App::PropertyType)(App::Prop_None), "Text wrap length; -1 means no wrap");
ADD_PROPERTY_TYPE(TextWrapLen, (-1), "", (App::PropertyType)(App::Prop_None),
"Text wrap length; -1 means no wrap");
ADD_PROPERTY_TYPE(KinkLength, (prefKinkLength()), "", (App::PropertyType)(App::Prop_None),
"Distance from symbol to leader kink");
"Distance from symbol to leader kink");
SourceView.setScope(App::LinkScope::Global);
Rotation.setStatus(App::Property::Hidden, true);
Caption.setStatus(App::Property::Hidden, true);
}
DrawViewBalloon::~DrawViewBalloon()
{
}
DrawViewBalloon::~DrawViewBalloon() {}
void DrawViewBalloon::onChanged(const App::Property* prop)
{
if (!isRestoring()) {
if ( (prop == &EndType) ||
(prop == &BubbleShape) ||
(prop == &ShapeScale) ||
(prop == &Text) ||
(prop == &KinkLength) ||
(prop == &EndTypeScale) ||
(prop == &OriginX) ||
(prop == &OriginY) ) {
if ((prop == &EndType) || (prop == &BubbleShape) || (prop == &ShapeScale) || (prop == &Text)
|| (prop == &KinkLength) || (prop == &EndTypeScale) || (prop == &OriginX)
|| (prop == &OriginY)) {
requestPaint();
}
}
DrawView::onChanged(prop);
}
void DrawViewBalloon::handleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName)
void DrawViewBalloon::handleChangedPropertyName(Base::XMLReader& reader, const char* TypeName,
const char* PropName)
{
Base::Type type = Base::Type::fromName(TypeName);
// was sourceView in the past, now is SourceView
if (SourceView.getClassTypeId() == type && strcmp(PropName, "sourceView") == 0) {
SourceView.Restore(reader);
} else if (BubbleShape.getClassTypeId() == type && strcmp(PropName, "Symbol") == 0) {
}
else if (BubbleShape.getClassTypeId() == type && strcmp(PropName, "Symbol") == 0) {
// was Symbol, then Shape in the past, now is BubbleShape
BubbleShape.Restore(reader);
} else if (BubbleShape.getClassTypeId() == type && strcmp(PropName, "Shape") == 0) {
}
else if (BubbleShape.getClassTypeId() == type && strcmp(PropName, "Shape") == 0) {
// was Symbol, then Shape in the past, now is BubbleShape
BubbleShape.Restore(reader);
} else if (ShapeScale.getClassTypeId() == type && strcmp(PropName, "SymbolScale") == 0) {
}
else if (ShapeScale.getClassTypeId() == type && strcmp(PropName, "SymbolScale") == 0) {
// was SymbolScale in the past, now is ShapeScale
ShapeScale.Restore(reader);
} else {
}
else {
DrawView::handleChangedPropertyName(reader, TypeName, PropName);
}
}
void DrawViewBalloon::handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop)
void DrawViewBalloon::handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName,
App::Property* prop)
// transforms properties that had been changed
{
// also check for changed properties of the base class
DrawView::handleChangedPropertyType(reader, TypeName, prop);
// property OriginX had the App::PropertyFloat and was changed to App::PropertyDistance
if ( (prop == &OriginX) &&
(strcmp(TypeName, "App::PropertyFloat") == 0) ) {
if ((prop == &OriginX) && (strcmp(TypeName, "App::PropertyFloat") == 0)) {
App::PropertyFloat OriginXProperty;
// restore the PropertyFloat to be able to set its value
OriginXProperty.Restore(reader);
OriginX.setValue(OriginXProperty.getValue());
} else if ( (prop == &OriginX) &&
(strcmp(TypeName, "App::PropertyLength") == 0) ) {
}
else if ((prop == &OriginX) && (strcmp(TypeName, "App::PropertyLength") == 0)) {
App::PropertyLength OriginXProperty;
// restore the PropertyFloat to be able to set its value
OriginXProperty.Restore(reader);
OriginX.setValue(OriginXProperty.getValue());
// property OriginY had the App::PropertyFloat and was changed to App::PropertyDistance
} else if ( (prop == &OriginY) &&
(strcmp(TypeName, "App::PropertyFloat") == 0) ) {
// property OriginY had the App::PropertyFloat and was changed to App::PropertyDistance
}
else if ((prop == &OriginY) && (strcmp(TypeName, "App::PropertyFloat") == 0)) {
App::PropertyFloat OriginYProperty;
// restore the PropertyFloat to be able to set its value
OriginYProperty.Restore(reader);
OriginY.setValue(OriginYProperty.getValue());
} else if ( (prop == &OriginY) &&
(strcmp(TypeName, "App::PropertyLength") == 0) ) {
}
else if ((prop == &OriginY) && (strcmp(TypeName, "App::PropertyLength") == 0)) {
App::PropertyLength OriginYProperty;
// restore the PropertyLength to be able to set its value
OriginYProperty.Restore(reader);
@@ -182,15 +178,16 @@ short DrawViewBalloon::mustExecute() const
return 1;
}
auto dvp = getViewPart();
if (dvp && dvp->isTouched()) {
auto dv = getParentView();
if (dv && dv->isTouched()) {
return 1;
}
return DrawView::mustExecute();
}
void DrawViewBalloon::handleXYLock() {
void DrawViewBalloon::handleXYLock()
{
bool on = isLocked();
if (!OriginX.testStatus(App::Property::ReadOnly)) {
OriginX.setStatus(App::Property::ReadOnly, on);
@@ -204,14 +201,14 @@ void DrawViewBalloon::handleXYLock() {
}
DrawViewPart* DrawViewBalloon::getViewPart() const
DrawView* DrawViewBalloon::getParentView() const
{
App::DocumentObject* obj = SourceView.getValue();
DrawViewPart* result = dynamic_cast<DrawViewPart*>(obj);
DrawView* result = dynamic_cast<DrawView*>(obj);
return result;
}
App::DocumentObjectExecReturn *DrawViewBalloon::execute()
App::DocumentObjectExecReturn* DrawViewBalloon::execute()
{
requestPaint();
return App::DocumentObject::execute();
@@ -227,23 +224,25 @@ void DrawViewBalloon::setOrigin(Base::Vector3d newOrigin)
double DrawViewBalloon::prefKinkLength() const
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().
GetGroup("BaseApp")->GetGroup("Preferences")->
GetGroup("Mod/TechDraw/Dimensions");
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Dimensions");
return hGrp->GetFloat("BalloonKink", 5.0);
}
int DrawViewBalloon::prefShape() const
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations");
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/TechDraw/Decorations");
return hGrp->GetInt("BalloonShape", 0);
}
int DrawViewBalloon::prefEnd() const
{
return Preferences::balloonArrow();
}
int DrawViewBalloon::prefEnd() const { return Preferences::balloonArrow(); }
QPointF DrawViewBalloon::getOrigin()
{
@@ -268,7 +267,7 @@ Base::Vector3d DrawViewBalloon::getOriginOffset() const
double oy = OriginY.getValue();
Base::Vector3d org(ox, oy, 0.0);
Base::Vector3d offset = pos - org;
return offset;
return offset;
}
/*

View File

@@ -32,14 +32,16 @@
class TopoDS_Shape;
namespace Measure {
namespace Measure
{
class Measurement;
}
namespace TechDraw {
namespace TechDraw
{
class DrawViewPart;
class TechDrawExport DrawViewBalloon : public TechDraw::DrawView
class TechDrawExport DrawViewBalloon: public TechDraw::DrawView
{
PROPERTY_HEADER_WITH_OVERRIDE(TechDraw::DrawViewBalloon);
@@ -48,31 +50,29 @@ public:
DrawViewBalloon();
~DrawViewBalloon() override;
App::PropertyLink SourceView;
App::PropertyString Text;
App::PropertyEnumeration EndType;
App::PropertyEnumeration BubbleShape;
App::PropertyLink SourceView;
App::PropertyString Text;
App::PropertyEnumeration EndType;
App::PropertyEnumeration BubbleShape;
App::PropertyFloatConstraint ShapeScale;
App::PropertyFloatConstraint EndTypeScale;
App::PropertyDistance OriginX;
App::PropertyDistance OriginY;
App::PropertyFloat TextWrapLen;
App::PropertyDistance KinkLength;
App::PropertyDistance OriginX;
App::PropertyDistance OriginY;
App::PropertyFloat TextWrapLen;
App::PropertyDistance KinkLength;
short mustExecute() const override;
DrawViewPart* getViewPart() const;
QPointF origin; //WF never used??
DrawView* getParentView() const;
QPointF origin;//WF never used??
QPointF getOrigin();
void setOrigin(QPointF p);
//virtual PyObject *getPyObject(void);
App::DocumentObjectExecReturn *execute() override;
App::DocumentObjectExecReturn* execute() override;
const char* getViewProviderName() const override {
return "TechDrawGui::ViewProviderBalloon";
}
const char* getViewProviderName() const override { return "TechDrawGui::ViewProviderBalloon"; }
static const char* balloonTypeEnums[];
@@ -87,17 +87,14 @@ public:
protected:
void onChanged(const App::Property* prop) override;
void handleChangedPropertyType(Base::XMLReader &reader,
const char *TypeName,
App::Property * prop) override;
void handleChangedPropertyName(Base::XMLReader &reader,
const char * TypeName,
const char *PropName) override;
void handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName,
App::Property* prop) override;
void handleChangedPropertyName(Base::XMLReader& reader, const char* TypeName,
const char* PropName) override;
private:
static App::PropertyFloatConstraint::Constraints SymbolScaleRange;
};
} //namespace TechDraw
}//namespace TechDraw
#endif