Skip to content

Commit 71843a9

Browse files
authored
Merge pull request FreeCAD#19941 from WandererFan/PropertiesAndSpinBoxes
[TD]Properties and spin boxes
2 parents bfd1fa4 + b343e3c commit 71843a9

File tree

11 files changed

+274
-155
lines changed

11 files changed

+274
-155
lines changed

src/Mod/TechDraw/App/DrawViewDetail.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ void DrawViewDetail::onChanged(const App::Property* prop)
139139

140140
App::DocumentObjectExecReturn* DrawViewDetail::execute()
141141
{
142-
// Base::Console().Message("DVD::execute() - %s\n", getNameInDocument());
143142
if (!keepUpdated()) {
144143
return DrawView::execute();
145144
}
@@ -254,6 +253,7 @@ void DrawViewDetail::makeDetailShape(const TopoDS_Shape& shape3d, DrawViewPart*
254253

255254
TopoDS_Face extrusionFace;
256255
Base::Vector3d extrudeVec = dirDetail * extrudeLength;
256+
257257
gp_Vec extrudeDir(extrudeVec.x, extrudeVec.y, extrudeVec.z);
258258
TopoDS_Shape tool;
259259
if (Preferences::mattingStyle()) {
@@ -381,7 +381,6 @@ void DrawViewDetail::makeDetailShape(const TopoDS_Shape& shape3d, DrawViewPart*
381381

382382
void DrawViewDetail::postHlrTasks(void)
383383
{
384-
// Base::Console().Message("DVD::postHlrTasks()\n");
385384
DrawViewPart::postHlrTasks();
386385

387386
geometryObject->pruneVertexGeom(Base::Vector3d(0.0, 0.0, 0.0),
@@ -465,9 +464,35 @@ bool DrawViewDetail::debugDetail() const
465464
return Preferences::getPreferenceGroup("debug")->GetBool("debugDetail", false);
466465
}
467466

467+
void DrawViewDetail::handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, App::Property * prop)
468+
{
469+
if (prop == &AnchorPoint) {
470+
// AnchorPoint was PropertyVector but is now PropertyPosition
471+
App::PropertyVector tmp;
472+
if (strcmp(tmp.getTypeId().getName(), TypeName)==0) {
473+
tmp.setContainer(this);
474+
tmp.Restore(reader);
475+
auto tmpValue = tmp.getValue();
476+
AnchorPoint.setValue(tmpValue);
477+
}
478+
return;
479+
}
480+
481+
if (prop == &Radius) {
482+
// Radius was PropertyFloat but is now PropertyLength
483+
App::PropertyLength tmp;
484+
if (strcmp(tmp.getTypeId().getName(), TypeName)==0) {
485+
tmp.setContainer(this);
486+
tmp.Restore(reader);
487+
auto tmpValue = tmp.getValue();
488+
Radius.setValue(tmpValue);
489+
}
490+
return;
491+
}
492+
}
493+
468494
void DrawViewDetail::unsetupObject()
469495
{
470-
// Base::Console().Message("DVD::unsetupObject()\n");
471496
App::DocumentObject* baseObj = BaseView.getValue();
472497
DrawView* base = dynamic_cast<DrawView*>(baseObj);
473498
if (base) {

src/Mod/TechDraw/App/DrawViewDetail.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ class TechDrawExport DrawViewDetail : public DrawViewPart
5757
~DrawViewDetail() override;
5858

5959
App::PropertyLink BaseView;
60-
App::PropertyVector AnchorPoint;
61-
App::PropertyFloat Radius;
60+
App::PropertyPosition AnchorPoint;
61+
App::PropertyLength Radius;
6262
App::PropertyString Reference;
6363

6464
App::PropertyBool ShowMatting;
@@ -71,6 +71,8 @@ class TechDrawExport DrawViewDetail : public DrawViewPart
7171
return "TechDrawGui::ViewProviderViewPart";
7272
}
7373
void unsetupObject() override;
74+
void handleChangedPropertyType(
75+
Base::XMLReader &reader, const char * TypeName, App::Property * prop) override;
7476

7577

7678
void detailExec(TopoDS_Shape& s,

src/Mod/TechDraw/App/DrawViewPart.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,7 @@ bool DrawViewPart::hasGeometry() const
10421042

10431043
const std::vector<TechDraw::VertexPtr>& verts = getVertexGeometry();
10441044
const std::vector<TechDraw::BaseGeomPtr>& edges = getEdgeGeometry();
1045+
10451046
return !(verts.empty() && edges.empty());
10461047
}
10471048

@@ -1469,6 +1470,33 @@ void DrawViewPart::resetReferenceVerts()
14691470
addReferencesToGeom();
14701471
}
14711472

1473+
void DrawViewPart::handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, App::Property * prop)
1474+
{
1475+
if (prop == &Direction) {
1476+
// Direction was PropertyVector but is now PropertyDirection
1477+
App::PropertyVector tmp;
1478+
if (strcmp(tmp.getTypeId().getName(), TypeName)==0) {
1479+
tmp.setContainer(this);
1480+
tmp.Restore(reader);
1481+
auto tmpValue = tmp.getValue();
1482+
Direction.setValue(tmpValue);
1483+
}
1484+
return;
1485+
}
1486+
1487+
if (prop == &XDirection) {
1488+
// XDirection was PropertyFloat but is now PropertyLength
1489+
App::PropertyVector tmp;
1490+
if (strcmp(tmp.getTypeId().getName(), TypeName)==0) {
1491+
tmp.setContainer(this);
1492+
tmp.Restore(reader);
1493+
auto tmpValue = tmp.getValue();
1494+
XDirection.setValue(tmpValue);
1495+
}
1496+
return;
1497+
}
1498+
}
1499+
14721500
// debugging ----------------------------------------------------------------------------
14731501

14741502
void DrawViewPart::dumpVerts(std::string text)

src/Mod/TechDraw/App/DrawViewPart.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ class TechDrawExport DrawViewPart: public DrawView, public CosmeticExtension
115115

116116
App::PropertyLinkList Source;
117117
App::PropertyXLinkList XSource;
118-
App::PropertyVector
119-
Direction;//TODO: Rename to YAxisDirection or whatever this actually is (ProjectionDirection)
120-
App::PropertyVector XDirection;
118+
App::PropertyDirection Direction; // the projection direction
119+
App::PropertyDirection XDirection;
121120
App::PropertyBool Perspective;
122121
App::PropertyDistance Focus;
123122

@@ -140,6 +139,8 @@ class TechDrawExport DrawViewPart: public DrawView, public CosmeticExtension
140139
App::DocumentObjectExecReturn* execute() override;
141140
const char* getViewProviderName() const override { return "TechDrawGui::ViewProviderViewPart"; }
142141
PyObject* getPyObject() override;
142+
void handleChangedPropertyType(
143+
Base::XMLReader &reader, const char * TypeName, App::Property * prop) override;
143144

144145
static TopoDS_Shape centerScaleRotate(const DrawViewPart* dvp, TopoDS_Shape& inOutShape,
145146
Base::Vector3d centroid);

src/Mod/TechDraw/App/DrawViewSection.cpp

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
#include <TopoDS_Edge.hxx>
6767
#include <TopoDS_Face.hxx>
6868
#include <TopoDS_Shape.hxx>
69-
#include <chrono>
7069
#include <gp_Ax2.hxx>
7170
#include <gp_Ax3.hxx>
7271
#include <gp_Dir.hxx>
@@ -735,7 +734,7 @@ TopoDS_Compound DrawViewSection::findSectionPlaneIntersections(const TopoDS_Shap
735734
-m_shapeSize,
736735
m_shapeSize);
737736
BRepTools::Write(mkFace.Face(), "DVSSectionPlane.brep");// debug
738-
BRepTools::Write(shape, "DVSShapeToIntersect.brep)");
737+
BRepTools::Write(shape, "DVSShapeToIntersect.brep");
739738
}
740739
BRep_Builder builder;
741740
TopoDS_Compound result;
@@ -759,10 +758,6 @@ TopoDS_Compound DrawViewSection::findSectionPlaneIntersections(const TopoDS_Shap
759758
// move section faces to line up with cut shape
760759
TopoDS_Compound DrawViewSection::alignSectionFaces(TopoDS_Shape faceIntersections)
761760
{
762-
// Base::Console().Message("DVS::alignSectionFaces() - %s -
763-
// faceIntersection.isnull: %d\n",
764-
// getNameInDocument(),
765-
// faceIntersections.IsNull());
766761
TopoDS_Compound sectionFaces;
767762
TopoDS_Shape centeredShape =
768763
ShapeUtils::moveShape(faceIntersections, getOriginalCentroid() * -1.0);
@@ -773,6 +768,10 @@ TopoDS_Compound DrawViewSection::alignSectionFaces(TopoDS_Shape faceIntersection
773768
ShapeUtils::rotateShape(scaledSection, getProjectionCS(), Rotation.getValue());
774769
}
775770

771+
if (debugSection()) {
772+
BRepTools::Write(scaledSection, "DVSScaledSectionFaces.brep");
773+
}
774+
776775
return mapToPage(scaledSection);
777776
}
778777

@@ -796,19 +795,31 @@ TopoDS_Compound DrawViewSection::mapToPage(TopoDS_Shape& shapeToAlign)
796795
TopExp_Explorer expFace(shapeToAlign, TopAbs_FACE);
797796
for (int iFace = 1; expFace.More(); expFace.Next(), iFace++) {
798797
const TopoDS_Face& face = TopoDS::Face(expFace.Current());
798+
if (debugSection()) {
799+
std::stringstream ss;
800+
ss << "DVSFace" << iFace << ".brep";
801+
BRepTools::Write(face, ss.str().c_str());// debug
802+
}
803+
804+
799805
std::vector<TopoDS_Wire> faceWires;
800806
TopExp_Explorer expWires(face, TopAbs_WIRE);
801807
for (; expWires.More(); expWires.Next()) {
802808
const TopoDS_Wire& wire = TopoDS::Wire(expWires.Current());
803-
TopoDS_Shape projectedShape =
804-
GeometryObject::projectSimpleShape(wire, getProjectionCS());
809+
TopoDS_Shape projectedShape = GeometryObject::projectSimpleShape(wire, getProjectionCS());
810+
if (debugSection()) {
811+
std::stringstream ss;
812+
ss << "DVSProjectedWire" << iFace << ".brep";
813+
BRepTools::Write(projectedShape, ss.str().c_str());// debug
814+
}
805815
std::vector<TopoDS_Edge> wireEdges;
806816
// projectedShape is just a bunch of edges. we have to rebuild the wire.
807817
TopExp_Explorer expEdges(projectedShape, TopAbs_EDGE);
808818
for (; expEdges.More(); expEdges.Next()) {
809819
const TopoDS_Edge& edge = TopoDS::Edge(expEdges.Current());
810820
wireEdges.push_back(edge);
811821
}
822+
812823
TopoDS_Wire cleanWire = EdgeWalker::makeCleanWire(wireEdges, 2.0 * EWTOLERANCE);
813824
faceWires.push_back(cleanWire);
814825
}
@@ -1225,6 +1236,33 @@ void DrawViewSection::setupObject()
12251236
DrawViewPart::setupObject();
12261237
}
12271238

1239+
void DrawViewSection::handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, App::Property * prop)
1240+
{
1241+
if (prop == &SectionOrigin) {
1242+
// SectionOrigin was PropertyVector but is now PropertyPosition
1243+
App::PropertyVector tmp;
1244+
if (strcmp(tmp.getTypeId().getName(), TypeName)==0) {
1245+
tmp.setContainer(this);
1246+
tmp.Restore(reader);
1247+
auto tmpValue = tmp.getValue();
1248+
SectionOrigin.setValue(tmpValue);
1249+
}
1250+
return;
1251+
}
1252+
1253+
if (prop == &SectionNormal) {
1254+
// Radius was PropertyVector but is now PropertyDirection
1255+
App::PropertyVector tmp;
1256+
if (strcmp(tmp.getTypeId().getName(), TypeName)==0) {
1257+
tmp.setContainer(this);
1258+
tmp.Restore(reader);
1259+
auto tmpValue = tmp.getValue();
1260+
SectionNormal.setValue(tmpValue);
1261+
}
1262+
return;
1263+
}
1264+
}
1265+
12281266
// hatch file routines
12291267

12301268
// create geometric hatch lines

src/Mod/TechDraw/App/DrawViewSection.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ class TechDrawExport DrawViewSection: public DrawViewPart
8484
~DrawViewSection() override;
8585

8686
App::PropertyLink BaseView;
87-
App::PropertyVector SectionNormal;
88-
App::PropertyVector SectionOrigin;
87+
App::PropertyDirection SectionNormal;
88+
App::PropertyPosition SectionOrigin;
8989
App::PropertyString SectionSymbol;
9090

9191

@@ -118,6 +118,8 @@ class TechDrawExport DrawViewSection: public DrawViewPart
118118
}
119119
void unsetupObject() override;
120120
short mustExecute() const override;
121+
void handleChangedPropertyType(
122+
Base::XMLReader &reader, const char * TypeName, App::Property * prop) override;
121123

122124
void sectionExec(TopoDS_Shape& s);
123125
virtual void makeSectionCut(const TopoDS_Shape& baseShape);

0 commit comments

Comments
 (0)