[TD]improve ComplexSection handling of bad section normal choice
This commit is contained in:
@@ -161,8 +161,10 @@ DrawViewSection::DrawViewSection()
|
||||
App::Prop_None,
|
||||
"2D View source for this Section");
|
||||
BaseView.setScope(App::LinkScope::Global);
|
||||
|
||||
// default of (0, -1, 0) matches 'Front' direction in DVP
|
||||
ADD_PROPERTY_TYPE(SectionNormal,
|
||||
(0, 0, 1.0),
|
||||
(0, -1, 0),
|
||||
sgroup,
|
||||
App::Prop_None,
|
||||
"Section Plane normal direction");// direction of extrusion
|
||||
@@ -250,8 +252,11 @@ DrawViewSection::DrawViewSection()
|
||||
|
||||
SvgIncluded.setStatus(App::Property::ReadOnly, true);
|
||||
PatIncluded.setStatus(App::Property::ReadOnly, true);
|
||||
|
||||
// SectionNormal is used instead to Direction
|
||||
Direction.setStatus(App::Property::ReadOnly, true);
|
||||
Direction.setValue(SectionNormal.getValue());
|
||||
|
||||
SectionDirection.setStatus(App::Property::Hidden, true);
|
||||
SectionDirection.setStatus(App::Property::ReadOnly, true);
|
||||
}
|
||||
@@ -260,7 +265,6 @@ DrawViewSection::~DrawViewSection()
|
||||
{
|
||||
// don't destroy this object while it has dependent threads running
|
||||
if (m_cutFuture.isRunning()) {
|
||||
Base::Console().Message("%s is waiting for tasks to complete\n", Label.getValue());
|
||||
m_cutFuture.waitForFinished();
|
||||
}
|
||||
}
|
||||
@@ -268,7 +272,7 @@ DrawViewSection::~DrawViewSection()
|
||||
short DrawViewSection::mustExecute() const
|
||||
{
|
||||
if (isRestoring()) {
|
||||
return TechDraw::DrawView::mustExecute();
|
||||
return TechDraw::DrawView::mustExecute(); //NOLINT
|
||||
}
|
||||
|
||||
if (Scale.isTouched() || Direction.isTouched() || BaseView.isTouched()
|
||||
@@ -276,7 +280,7 @@ short DrawViewSection::mustExecute() const
|
||||
return 1;
|
||||
}
|
||||
|
||||
return TechDraw::DrawView::mustExecute();
|
||||
return TechDraw::DrawView::mustExecute(); //NOLINT
|
||||
}
|
||||
|
||||
void DrawViewSection::onChanged(const App::Property* prop)
|
||||
@@ -293,40 +297,47 @@ void DrawViewSection::onChanged(const App::Property* prop)
|
||||
return;
|
||||
}
|
||||
|
||||
if (prop == &SectionNormal) {
|
||||
if (prop == &SectionNormal ||
|
||||
prop == &XDirection) {
|
||||
Direction.setValue(SectionNormal.getValue());
|
||||
return;
|
||||
}
|
||||
else if (prop == &SectionSymbol) {
|
||||
|
||||
if (prop == &SectionSymbol) {
|
||||
if (getBaseDVP()) {
|
||||
getBaseDVP()->requestPaint();
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (prop == &CutSurfaceDisplay) {
|
||||
|
||||
if (prop == &CutSurfaceDisplay) {
|
||||
if (CutSurfaceDisplay.isValue("PatHatch")) {
|
||||
makeLineSets();
|
||||
}
|
||||
requestPaint();
|
||||
return;
|
||||
}
|
||||
else if (prop == &FileHatchPattern) {
|
||||
|
||||
if (prop == &FileHatchPattern) {
|
||||
replaceSvgIncluded(FileHatchPattern.getValue());
|
||||
requestPaint();
|
||||
return;
|
||||
}
|
||||
else if (prop == &FileGeomPattern) {
|
||||
|
||||
if (prop == &FileGeomPattern) {
|
||||
replacePatIncluded(FileGeomPattern.getValue());
|
||||
makeLineSets();
|
||||
requestPaint();
|
||||
return;
|
||||
}
|
||||
else if (prop == &NameGeomPattern) {
|
||||
|
||||
if (prop == &NameGeomPattern) {
|
||||
makeLineSets();
|
||||
requestPaint();
|
||||
return;
|
||||
}
|
||||
else if (prop == &BaseView) {
|
||||
|
||||
if (prop == &BaseView) {
|
||||
// if the BaseView is a Section, then the option of using UsePreviousCut is
|
||||
// valid.
|
||||
if (BaseView.getValue() && BaseView.getValue()->isDerivedFrom<TechDraw::DrawViewSection>()) {
|
||||
@@ -335,17 +346,17 @@ void DrawViewSection::onChanged(const App::Property* prop)
|
||||
else {
|
||||
UsePreviousCut.setStatus(App::Property::ReadOnly, true);
|
||||
}
|
||||
} else if (prop == &SectionLineStretch) {
|
||||
}
|
||||
|
||||
if (prop == &SectionLineStretch) {
|
||||
BaseView.getValue()->touch();
|
||||
}
|
||||
|
||||
DrawView::onChanged(prop);
|
||||
DrawView::onChanged(prop); //NOLINT
|
||||
}
|
||||
|
||||
TopoDS_Shape DrawViewSection::getShapeToCut()
|
||||
{
|
||||
// Base::Console().Message("DVS::getShapeToCut() - %s\n",
|
||||
// getNameInDocument());
|
||||
App::DocumentObject* base = BaseView.getValue();
|
||||
TechDraw::DrawViewPart* dvp = nullptr;
|
||||
TechDraw::DrawViewSection* dvs = nullptr;
|
||||
@@ -368,9 +379,11 @@ TopoDS_Shape DrawViewSection::getShapeToCut()
|
||||
}
|
||||
else if (base->isDerivedFrom<TechDraw::DrawViewPart>()) {
|
||||
dvp = static_cast<TechDraw::DrawViewPart*>(base);
|
||||
shapeToCut = dvp->getSourceShape();
|
||||
constexpr bool fuseBefore{true};
|
||||
constexpr bool allow2d{false};
|
||||
shapeToCut = dvp->getSourceShape(!fuseBefore, allow2d);
|
||||
if (FuseBeforeCut.getValue()) {
|
||||
shapeToCut = dvp->getSourceShape(true);
|
||||
shapeToCut = dvp->getSourceShape(fuseBefore);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -387,7 +400,6 @@ TopoDS_Shape DrawViewSection::getShapeForDetail() const
|
||||
|
||||
App::DocumentObjectExecReturn* DrawViewSection::execute()
|
||||
{
|
||||
// Base::Console().Message("DVS::execute() - %s\n", Label.getValue());
|
||||
if (!keepUpdated()) {
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
@@ -993,29 +1005,27 @@ ChangePointVector DrawViewSection::getChangePointsFromSectionLine()
|
||||
// this should really be in BoundBox.h
|
||||
//! check if point is in box or on boundary of box
|
||||
//! compare to isInBox which doesn't allow on boundary
|
||||
bool DrawViewSection::isReallyInBox(const Base::Vector3d v, const Base::BoundBox3d bb) const
|
||||
bool DrawViewSection::isReallyInBox(const Base::Vector3d vec, const Base::BoundBox3d bb) const
|
||||
{
|
||||
if (v.x <= bb.MinX || v.x >= bb.MaxX) {
|
||||
if (vec.x <= bb.MinX || vec.x >= bb.MaxX) {
|
||||
return false;
|
||||
}
|
||||
if (v.y <= bb.MinY || v.y >= bb.MaxY) {
|
||||
if (vec.y <= bb.MinY || vec.y >= bb.MaxY) {
|
||||
return false;
|
||||
}
|
||||
if (v.z <= bb.MinZ || v.z >= bb.MaxZ) {
|
||||
if (vec.z <= bb.MinZ || vec.z >= bb.MaxZ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DrawViewSection::isReallyInBox(const gp_Pnt p, const Bnd_Box& bb) const
|
||||
bool DrawViewSection::isReallyInBox(const gp_Pnt& point, const Bnd_Box& bb) const
|
||||
{
|
||||
return !bb.IsOut(p);
|
||||
return !bb.IsOut(point);
|
||||
}
|
||||
|
||||
Base::Vector3d DrawViewSection::getXDirection() const
|
||||
{
|
||||
// Base::Console().Message("DVS::getXDirection() - %s\n",
|
||||
// Label.getValue());
|
||||
App::Property* prop = getPropertyByName("XDirection");
|
||||
if (!prop) {
|
||||
// No XDirection property. can this happen?
|
||||
@@ -1038,7 +1048,7 @@ Base::Vector3d DrawViewSection::getXDirection() const
|
||||
return XDirection.getValue();
|
||||
}
|
||||
|
||||
void DrawViewSection::setCSFromBase(const std::string sectionName)
|
||||
void DrawViewSection::setCSFromBase(const std::string& sectionName)
|
||||
{
|
||||
// Base::Console().Message("DVS::setCSFromBase(%s)\n",
|
||||
// sectionName.c_str());
|
||||
@@ -1052,10 +1062,8 @@ void DrawViewSection::setCSFromBase(const std::string sectionName)
|
||||
}
|
||||
|
||||
// set the section CS based on an XY vector in BaseViews CS
|
||||
void DrawViewSection::setCSFromBase(const Base::Vector3d localUnit)
|
||||
void DrawViewSection::setCSFromBase(const Base::Vector3d& localUnit)
|
||||
{
|
||||
// Base::Console().Message("DVS::setCSFromBase(%s)\n",
|
||||
// DrawUtil::formatVector(localUnit).c_str());
|
||||
gp_Ax2 newSectionCS = getBaseDVP()->localVectorToCS(localUnit);
|
||||
|
||||
Base::Vector3d vDir(newSectionCS.Direction().X(),
|
||||
@@ -1070,10 +1078,8 @@ void DrawViewSection::setCSFromBase(const Base::Vector3d localUnit)
|
||||
}
|
||||
|
||||
// reset the section CS based on an XY vector in current section CS
|
||||
void DrawViewSection::setCSFromLocalUnit(const Base::Vector3d localUnit)
|
||||
void DrawViewSection::setCSFromLocalUnit(const Base::Vector3d& localUnit)
|
||||
{
|
||||
// Base::Console().Message("DVS::setCSFromLocalUnit(%s)\n",
|
||||
// DrawUtil::formatVector(localUnit).c_str());
|
||||
gp_Dir verticalDir = getSectionCS().YDirection();
|
||||
gp_Ax1 verticalAxis(Base::convertTo<gp_Pnt>(SectionOrigin.getValue()), verticalDir);
|
||||
gp_Dir oldNormal = getSectionCS().Direction();
|
||||
@@ -1084,10 +1090,8 @@ void DrawViewSection::setCSFromLocalUnit(const Base::Vector3d localUnit)
|
||||
XDirection.setValue(Base::convertTo<Base::Vector3d>(newCS.XDirection()));
|
||||
}
|
||||
|
||||
gp_Ax2 DrawViewSection::getCSFromBase(const std::string sectionName) const
|
||||
gp_Ax2 DrawViewSection::getCSFromBase(const std::string& sectionName) const
|
||||
{
|
||||
// Base::Console().Message("DVS::getCSFromBase(%s)\n",
|
||||
// sectionName.c_str());
|
||||
Base::Vector3d origin(0.0, 0.0, 0.0);
|
||||
Base::Vector3d sectOrigin = SectionOrigin.getValue();
|
||||
|
||||
@@ -1143,7 +1147,6 @@ gp_Ax2 DrawViewSection::getCSFromBase(const std::string sectionName) const
|
||||
// returns current section cs
|
||||
gp_Ax2 DrawViewSection::getSectionCS() const
|
||||
{
|
||||
// Base::Console().Message("DVS::getSectionCS()\n");
|
||||
Base::Vector3d vNormal = SectionNormal.getValue();
|
||||
gp_Dir gNormal(vNormal.x, vNormal.y, vNormal.z);
|
||||
Base::Vector3d vXDir = getXDirection();
|
||||
@@ -1172,7 +1175,6 @@ Base::Vector3d DrawViewSection::getCutCentroid() const
|
||||
|
||||
std::vector<LineSet> DrawViewSection::getDrawableLines(int i)
|
||||
{
|
||||
// Base::Console().Message("DVS::getDrawableLines(%d) - lineSets: %d\n", i, m_lineSets.size());
|
||||
if (m_lineSets.empty()) {
|
||||
makeLineSets();
|
||||
}
|
||||
@@ -1260,12 +1262,38 @@ void DrawViewSection::handleChangedPropertyType(Base::XMLReader &reader, const c
|
||||
}
|
||||
}
|
||||
|
||||
// checks that SectionNormal and XDirection are perpendicular and that Direction is the same as
|
||||
// SectionNormal
|
||||
bool DrawViewSection::checkSectionCS() const
|
||||
{
|
||||
auto vNormal = SectionNormal.getValue();
|
||||
vNormal.Normalize();
|
||||
auto vXDirection = XDirection.getValue();
|
||||
vXDirection.Normalize();
|
||||
auto vDirection = Direction.getValue();
|
||||
|
||||
if (vNormal.Length() == 0 ||
|
||||
vXDirection.Length() == 0 ||
|
||||
vDirection.Length() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!vNormal.IsEqual(vDirection, EWTOLERANCE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto orthoDot = std::fabs(vNormal.Dot(vXDirection));
|
||||
if (orthoDot > EWTOLERANCE) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// hatch file routines
|
||||
|
||||
// create geometric hatch lines
|
||||
void DrawViewSection::makeLineSets(void)
|
||||
{
|
||||
// Base::Console().Message("DVS::makeLineSets()\n");
|
||||
if (PatIncluded.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@@ -1289,8 +1317,6 @@ void DrawViewSection::makeLineSets(void)
|
||||
|
||||
void DrawViewSection::replaceSvgIncluded(std::string newSvgFile)
|
||||
{
|
||||
// Base::Console().Message("DVS::replaceSvgIncluded(%s)\n",
|
||||
// newSvgFile.c_str());
|
||||
if (newSvgFile.empty()) {
|
||||
return;
|
||||
}
|
||||
@@ -1306,7 +1332,6 @@ void DrawViewSection::replaceSvgIncluded(std::string newSvgFile)
|
||||
|
||||
void DrawViewSection::replacePatIncluded(std::string newPatFile)
|
||||
{
|
||||
// Base::Console().Message("DVS::replacePatIncluded(%s)\n", newPatFile.c_str());
|
||||
if (newPatFile.empty()) {
|
||||
return;
|
||||
}
|
||||
@@ -1324,7 +1349,6 @@ void DrawViewSection::replacePatIncluded(std::string newPatFile)
|
||||
|
||||
void DrawViewSection::getParameters()
|
||||
{
|
||||
// Base::Console().Message("DVS::getParameters()\n");
|
||||
bool fuseFirst = Preferences::getPreferenceGroup("General")->GetBool("SectionFuseFirst", false);
|
||||
FuseBeforeCut.setValue(fuseFirst);
|
||||
}
|
||||
@@ -1336,8 +1360,6 @@ bool DrawViewSection::debugSection(void) const
|
||||
|
||||
int DrawViewSection::prefCutSurface(void) const
|
||||
{
|
||||
// Base::Console().Message("DVS::prefCutSurface()\n");
|
||||
|
||||
return Preferences::getPreferenceGroup("Decorations")
|
||||
->GetInt("CutSurfaceDisplay", 2);// default to SvgHatch
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user