[TechDraw] Add Owner property to Symbols

This commit is contained in:
pavltom
2024-02-11 13:53:48 +01:00
committed by WandererFan
parent 37aba37baf
commit ff14c58ccc
18 changed files with 254 additions and 27 deletions

View File

@@ -375,6 +375,11 @@ bool DrawView::isInClip()
return false;
}
DrawView *DrawView::claimParent() const
{
return nullptr;
}
DrawViewClip* DrawView::getClipGroup()
{
std::vector<App::DocumentObject*> parent = getInList();

View File

@@ -84,6 +84,8 @@ public:
virtual DrawPage* findParentPage() const;
virtual std::vector<DrawPage*> findAllParentPages() const;
virtual DrawView *claimParent() const;
virtual int countParentPages() const;
virtual QRectF getRect() const; //must be overridden by derived class
QRectF getRectAligned() const;

View File

@@ -51,6 +51,9 @@ DrawViewSymbol::DrawViewSymbol()
ADD_PROPERTY_TYPE(Symbol, (""), vgroup, App::Prop_None, "The SVG code defining this symbol");
ADD_PROPERTY_TYPE(EditableTexts, (""), vgroup, App::Prop_None,
"Substitution values for the editable strings in this symbol");
ADD_PROPERTY_TYPE(Owner, (nullptr), vgroup, (App::PropertyType)(App::Prop_None),
"Feature to which this symbol is attached");
ScaleType.setValue("Custom");
Scale.setStatus(App::Property::ReadOnly, false);
Symbol.setStatus(App::Property::Hidden, true);
@@ -58,6 +61,28 @@ DrawViewSymbol::DrawViewSymbol()
DrawViewSymbol::~DrawViewSymbol() {}
void DrawViewSymbol::touchTreeOwner()
{
auto owner = dynamic_cast<DrawView *>(Owner.getValue());
if (owner) {
owner->touch();
}
else { // If no owner is specified, touch all parent pages
for (auto page : findAllParentPages()) {
page->touch();
}
}
}
void DrawViewSymbol::onBeforeChange(const App::Property *prop)
{
if (prop == &Owner && !isRestoring()) {
touchTreeOwner();
}
TechDraw::DrawView::onBeforeChange(prop);
}
void DrawViewSymbol::onChanged(const App::Property* prop)
{
if (prop == &Symbol) {
@@ -72,10 +97,26 @@ void DrawViewSymbol::onChanged(const App::Property* prop)
//1 cycle
updateFieldsInSymbol();
}
else if (prop == &Owner) {
if (!isRestoring()) {
touchTreeOwner();
}
}
TechDraw::DrawView::onChanged(prop);
}
short DrawViewSymbol::mustExecute() const
{
if (!isRestoring()) {
if (Owner.isTouched()) {
return 1;
}
}
return DrawView::mustExecute();
}
App::DocumentObjectExecReturn* DrawViewSymbol::execute()
{
//nothing to do. DVS is just a container for properties.
@@ -83,6 +124,11 @@ App::DocumentObjectExecReturn* DrawViewSymbol::execute()
return DrawView::execute();
}
DrawView *DrawViewSymbol::claimParent() const
{
return dynamic_cast<DrawView *>(Owner.getValue());
}
QRectF DrawViewSymbol::getRect() const
{
double w = 64.0;//must default to something

View File

@@ -48,7 +48,9 @@ public:
App::PropertyString Symbol;
App::PropertyStringList EditableTexts;
App::PropertyLink Owner;
short mustExecute() const override;
/** @name methods override Feature */
//@{
/// recalculate the Feature
@@ -59,6 +61,7 @@ public:
const char* getViewProviderName() const override {
return "TechDrawGui::ViewProviderSymbol";
}
DrawView *claimParent(void) const override;
QRectF getRect() const override;
bool checkFit(TechDraw::DrawPage* p) const override;
@@ -66,6 +69,8 @@ public:
PyObject *getPyObject() override;
protected:
void touchTreeOwner();
void onBeforeChange(const App::Property* prop) override;
void onChanged(const App::Property* prop) override;
Base::BoundBox3d bbox;

View File

@@ -36,6 +36,7 @@
# include <BRepBuilderAPI_MakeVertex.hxx>
# include <BRepBuilderAPI_MakeWire.hxx>
# include <BRepExtrema_DistShapeShape.hxx>
# include <BRepGProp.hxx>
# include <BRepLib.hxx>
# include <BRepLProp_CLProps.hxx>
# include <BRepTools.hxx>
@@ -43,6 +44,7 @@
# include <GC_MakeEllipse.hxx>
# include <gce_MakeCirc.hxx>
# include <GCPnts_AbscissaPoint.hxx>
# include <GProp_GProps.hxx>
# include <Geom_BSplineCurve.hxx>
# include <Geom_BezierCurve.hxx>
# include <Geom_Circle.hxx>
@@ -158,6 +160,14 @@ TopoDS_Face Face::toOccFace() const
return TopoDS_Face();
}
//**** Face
Base::Vector3d Face::getCenter() const {
GProp_GProps faceProps;
BRepGProp::SurfaceProperties(toOccFace(), faceProps);
return DrawUtil::toVector3d(faceProps.CentreOfMass());
}
Face::~Face()
{
for(auto it : wires) {

View File

@@ -347,6 +347,8 @@ class TechDrawExport Face
~Face();
TopoDS_Face toOccFace() const;
std::vector<Wire *> wires;
Base::Vector3d getCenter() const;
};
using FacePtr = std::shared_ptr<Face>;