Skip to content

Commit

Permalink
[TD]Handle missing XDirection on old files
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Nov 27, 2019
1 parent cd2764f commit 9381d4c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 9 deletions.
11 changes: 10 additions & 1 deletion src/Mod/TechDraw/App/DrawProjGroupItem.cpp
Expand Up @@ -131,10 +131,19 @@ bool DrawProjGroupItem::showLock(void) const
return result;
}


App::DocumentObjectExecReturn *DrawProjGroupItem::execute(void)
{
// Base::Console().Message("DPGI::execute(%s)\n",Label.getValue());

bool haveX = checkXDirection();
if (!haveX) {
//block touch/onChanged stuff
Base::Vector3d newX = getXDirection();
XDirection.setValue(newX);
XDirection.purgeTouched(); //don't trigger updates!
//unblock
}

if (DrawUtil::checkParallel(Direction.getValue(),
getXDirection())) {
return new App::DocumentObjectExecReturn("DPGI: Direction and XDirection are parallel");
Expand Down
9 changes: 9 additions & 0 deletions src/Mod/TechDraw/App/DrawViewDetail.cpp
Expand Up @@ -216,6 +216,15 @@ App::DocumentObjectExecReturn *DrawViewDetail::execute(void)
return DrawView::execute();
}

bool haveX = checkXDirection();
if (!haveX) {
//block touch/onChanged stuff
Base::Vector3d newX = getXDirection();
XDirection.setValue(newX);
XDirection.purgeTouched(); //don't trigger updates!
//unblock
}

Base::Vector3d anchor = AnchorPoint.getValue(); //this is a 2D point (in unrotated coords)
Base::Vector3d dirDetail = dvp->Direction.getValue();

Expand Down
14 changes: 11 additions & 3 deletions src/Mod/TechDraw/App/DrawViewPart.cpp
Expand Up @@ -241,9 +241,16 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
return App::DocumentObject::StdReturn;
}

checkXDirection();
bool haveX = checkXDirection();
if (!haveX) {
//block touch/onChanged stuff
Base::Vector3d newX = getXDirection();
XDirection.setValue(newX);
XDirection.purgeTouched(); //don't trigger updates!
//unblock
}

m_saveShape = shape;
// m_saveShape = shape;
geometryObject = makeGeometryForShape(shape);

#if MOD_TECHDRAW_HANDLE_FACES
Expand Down Expand Up @@ -321,6 +328,7 @@ GeometryObject* DrawViewPart::makeGeometryForShape(TopoDS_Shape shape)
//center shape on origin
TopoDS_Shape centeredShape = TechDraw::moveShape(shape,
centroid * -1.0);
m_saveShape = centeredShape;

TopoDS_Shape scaledShape = TechDraw::scaleShape(centeredShape,
getScale());
Expand Down Expand Up @@ -919,7 +927,7 @@ bool DrawViewPart::checkXDirection(void) const
Base::Vector3d origin(0.0,0.0,0.0);
Base::Vector3d xDir = getLegacyX(origin,
dir);
Base::Console().Warning("DVP - %s - XDirection property not set. Try %s\n",
Base::Console().Warning("DVP - %s - XDirection property not set. Trying %s\n",
getNameInDocument(),
DrawUtil::formatVector(xDir).c_str());
return false;
Expand Down
43 changes: 39 additions & 4 deletions src/Mod/TechDraw/App/DrawViewSection.cpp
Expand Up @@ -242,7 +242,15 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void)
return new App::DocumentObjectExecReturn("BaseView Source object is Null");
}

checkXDirection();
// checkXDirection();
bool haveX = checkXDirection();
if (!haveX) {
//block touch/onChanged stuff
Base::Vector3d newX = getXDirection();
XDirection.setValue(newX);
XDirection.purgeTouched(); //don't trigger updates!
//unblock
}

//is SectionOrigin valid?
Bnd_Box centerBox;
Expand Down Expand Up @@ -305,7 +313,6 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void)

Base::Vector3d origin(0.0, 0.0, 0.0);
viewAxis = getProjectionCS(origin);

if (!DrawUtil::fpCompare(Rotation.getValue(),0.0)) {
scaledShape = TechDraw::rotateShape(scaledShape,
viewAxis,
Expand Down Expand Up @@ -569,6 +576,35 @@ bool DrawViewSection::isReallyInBox (const gp_Pnt p, const Bnd_Box& bb) const
return !bb.IsOut(p);
}

Base::Vector3d DrawViewSection::getXDirection(void) const
{
// Base::Console().Message("DVS::getXDirection() - %s\n", Label.getValue());
Base::Vector3d result(1.0, 0.0, 0.0); //default X
App::Property* prop = getPropertyByName("XDirection");
if (prop != nullptr) { //have an XDirection property
Base::Vector3d propVal = XDirection.getValue();
if (DrawUtil::fpCompare(propVal.Length(), 0.0)) { //but it has no value
std::string sectName = SectionDirection.getValueAsString();
gp_Ax2 cs = getCSFromBase(sectName);
gp_Dir gXDir = cs.XDirection();
result = Base::Vector3d(gXDir.X(),
gXDir.Y(),
gXDir.Z());
} else {
result = propVal; //normal case. XDirection is set.
}
} else { //no Property. can this happen?
std::string sectName = SectionDirection.getValueAsString();
gp_Ax2 cs = getCSFromBase(sectName);
gp_Dir gXDir = cs.XDirection();
result = Base::Vector3d(gXDir.X(),
gXDir.Y(),
gXDir.Z());

}
return result;
}

void DrawViewSection::setCSFromBase(const std::string sectionName)
{
// Base::Console().Message("DVS::setCSFromBase(%s)\n", sectionName.c_str());
Expand All @@ -586,7 +622,7 @@ void DrawViewSection::setCSFromBase(const std::string sectionName)
XDirection.setValue(vXDir);
}

gp_Ax2 DrawViewSection::getCSFromBase(const std::string sectionName)
gp_Ax2 DrawViewSection::getCSFromBase(const std::string sectionName) const
{
// Base::Console().Message("DVS::getCSFromBase(%s)\n", sectionName.c_str());
Base::Vector3d sectionNormal;
Expand Down Expand Up @@ -663,7 +699,6 @@ gp_Ax2 DrawViewSection::getSectionCS(void) const
catch (...) {
Base::Console().Warning("DVS::getSectionCS - %s - failed to create section CS\n", getNameInDocument());
}

return sectionCS;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Mod/TechDraw/App/DrawViewSection.h
Expand Up @@ -91,12 +91,13 @@ class TechDrawExport DrawViewSection : public DrawViewPart
std::vector<TechDraw::Face*> getFaceGeometry();

void setCSFromBase(const std::string sectionName);
gp_Ax2 getCSFromBase(const std::string sectionName);
gp_Ax2 getCSFromBase(const std::string sectionName) const;

gp_Ax2 rotateCSArbitrary(gp_Ax2 oldCS,
Base::Vector3d axis,
double degAngle) const;
gp_Ax2 getSectionCS() const;
virtual Base::Vector3d getXDirection(void) const override; //don't use XDirection.getValue()

TechDraw::DrawViewPart* getBaseDVP() const;
TechDraw::DrawProjGroupItem* getBaseDPGI() const;
Expand Down

0 comments on commit 9381d4c

Please sign in to comment.