diff --git a/src/Mod/TechDraw/App/DrawViewSection.cpp b/src/Mod/TechDraw/App/DrawViewSection.cpp index 7aef9787d8..a0e7507339 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.cpp +++ b/src/Mod/TechDraw/App/DrawViewSection.cpp @@ -252,13 +252,13 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void) if(!isReallyInBox(gp_Pnt(orgPnt.x,orgPnt.y,orgPnt.z), centerBox)) { Base::Console().Warning("DVS: SectionOrigin doesn't intersect part in %s\n",getNameInDocument()); - Base::Console().Warning("DVS: Using center of bounding box.\n"); - double Xmin,Ymin,Zmin,Xmax,Ymax,Zmax; - centerBox.Get(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax); - orgPnt = Base::Vector3d((Xmax + Xmin)/2.0, - (Ymax + Ymin)/2.0, - (Zmax + Zmin)/2.0); - SectionOrigin.setValue(orgPnt); +// Base::Console().Warning("DVS: Using center of bounding box.\n"); +// double Xmin,Ymin,Zmin,Xmax,Ymax,Zmax; +// centerBox.Get(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax); +// orgPnt = Base::Vector3d((Xmax + Xmin)/2.0, +// (Ymax + Ymin)/2.0, +// (Zmax + Zmin)/2.0); +// SectionOrigin.setValue(orgPnt); } // Make the extrusion face @@ -281,35 +281,50 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void) } TopoDS_Shape rawShape = mkCut.Shape(); -// BRepTools::Write(myShape, "DVSCopy.brep"); //debug -// BRepTools::Write(prism, "DVSTool.brep"); //debug -// BRepTools::Write(rawShape, "DVSResult.brep"); //debug + if (debugSection()) { + BRepTools::Write(myShape, "DVSCopy.brep"); //debug + BRepTools::Write(aProjFace, "DVSFace.brep"); //debug + BRepTools::Write(prism, "DVSTool.brep"); //debug + BRepTools::Write(rawShape, "DVSResult.brep"); //debug + } Bnd_Box testBox; BRepBndLib::Add(rawShape, testBox); testBox.SetGap(0.0); - if (testBox.IsVoid()) { //prism & input don't intersect. rawShape is garbage, don't bother. - Base::Console().Message("INFO - DVS::execute - prism & input don't intersect\n"); + if (testBox.IsVoid()) { //prism & input don't intersect. rawShape is garbage, don't bother. + Base::Console().Warning("DVS::execute - prism & input don't intersect - %s\n", Label.getValue()); return DrawView::execute(); } m_cutShape = rawShape; - m_cutShape = TechDraw::moveShape(m_cutShape, //centre on origin - -SectionOrigin.getValue()); +// m_cutShape = TechDraw::moveShape(m_cutShape, //centre on origin +// -SectionOrigin.getValue()); + if (debugSection()) { + BRepTools::Write(m_cutShape, "DVSMCut.brep"); //debug + } + gp_Pnt inputCenter; gp_Ax2 viewAxis; try { inputCenter = TechDraw::findCentroid(rawShape, Direction.getValue()); - TopoDS_Shape mirroredShape = TechDraw::mirrorShape(rawShape, - inputCenter, - getScale()); + TopoDS_Shape scaledShape = TechDraw::scaleShape(rawShape, + getScale()); + TopoDS_Shape mirroredShape = TechDraw::mirrorShape(scaledShape, + inputCenter, + 1.0); +// getScale()); viewAxis = getSectionCS(SectionDirection.getValueAsString()); if (!DrawUtil::fpCompare(Rotation.getValue(),0.0)) { mirroredShape = TechDraw::rotateShape(mirroredShape, viewAxis, Rotation.getValue()); } + if (debugSection()) { + BRepTools::Write(scaledShape, "DVSScaled.brep"); //debug + BRepTools::Write(mirroredShape, "DVSMirror.brep"); //debug + DrawUtil::dumpCS("DVS::execute - CS to GO", viewAxis); + } geometryObject = buildGeometryObject(mirroredShape,viewAxis); #if MOD_TECHDRAW_HANDLE_FACES @@ -552,14 +567,75 @@ bool DrawViewSection::isReallyInBox (const gp_Pnt p, const Bnd_Box& bb) const return !bb.IsOut(p); } -void DrawViewSection::setNormalFromBase(const std::string sectionName) +void DrawViewSection::setCSFromBase(const std::string sectionName) { -// Base::Console().Message("DVS::setNormalFromBase(%s)\n", sectionName.c_str()); - Base::Vector3d normal = getSectionVector(sectionName); - Direction.setValue(normal); - SectionNormal.setValue(normal); + gp_Ax2 CS = getCSFromBase(sectionName); + gp_Dir gDir = CS.Direction(); + Base::Vector3d vDir(gDir.X(), + gDir.Y(), + gDir.Z()); + Direction.setValue(vDir); + SectionNormal.setValue(vDir); } +gp_Ax2 DrawViewSection::getCSFromBase(const std::string sectionName) +{ +// Base::Console().Message("DVS::getCSFromBase(%s)\n", sectionName.c_str()); + Base::Vector3d sectionNormal; + Base::Vector3d sectionXDir; + Base::Vector3d origin(0.0, 0.0, 0.0); + Base::Vector3d dvpDir = getBaseDVP()->Direction.getValue(); + gp_Ax2 dvpCS = getBaseDVP()->getViewAxis(origin, + dvpDir); +// flip); //what to do with this!?? + + if (debugSection()) { + DrawUtil::dumpCS("DVS::getCSFromBase - dvp VA", dvpCS); + } + gp_Dir dvpUp = dvpCS.YDirection(); + gp_Dir dvpRight = dvpCS.XDirection(); + Base::Vector3d dir = getBaseDVP()->Direction.getValue(); + Base::Vector3d up(dvpUp.X(), dvpUp.Y(), dvpUp.Z()); + Base::Vector3d right(dvpRight.X(), dvpRight.Y(), dvpRight.Z()); + + if (sectionName == "Up") { +// sectionNormal = up * -1.0; + sectionNormal = up; + sectionXDir = right; // + } else if (sectionName == "Down") { +// sectionNormal = up; + sectionNormal = up * -1.0; + sectionXDir = right; + } else if (sectionName == "Left") { + sectionNormal = right; + sectionXDir = dir * -1.0; + } else if (sectionName == "Right") { + sectionNormal = right * -1.0; + sectionXDir = dir; + } else { + Base::Console().Log("Error - DVS::getCSFromBase - bad sectionName: %s\n",sectionName.c_str()); + sectionNormal = right; + sectionXDir = dir; + } + + gp_Dir dvsDir(sectionNormal.x, + sectionNormal.y, + sectionNormal.z); + gp_Dir dvsXDir(sectionXDir.x, + sectionXDir.y, + sectionXDir.z); + gp_Pnt dvsLoc(0.0, 0.0, 0.0); + gp_Ax2 CS(dvsLoc, + dvsDir, + dvsXDir); + if (debugSection()) { + DrawUtil::dumpCS("DVS::getCSFromBase - sectionCS out", CS); + } + return CS; +} + + + //! calculate the section Normal/Projection Direction given section name //TODO: this should take base view rotation into account. Base::Vector3d DrawViewSection::getSectionVector (const std::string sectionName) @@ -788,6 +864,15 @@ void DrawViewSection::getParameters() FuseBeforeCut.setValue(fuseFirst); } +bool DrawViewSection::debugSection(void) const +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/debug"); + + bool result = hGrp->GetBool("debugSection",false); + return result; +} + // Python Drawing feature --------------------------------------------------------- namespace App { diff --git a/src/Mod/TechDraw/App/DrawViewSection.h b/src/Mod/TechDraw/App/DrawViewSection.h index 96a35958d7..f946ab57a4 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.h +++ b/src/Mod/TechDraw/App/DrawViewSection.h @@ -91,7 +91,8 @@ public: std::vector getFaceGeometry(); Base::Vector3d getSectionVector (const std::string sectionName); - void setNormalFromBase(const std::string sectionName); + void setCSFromBase(const std::string sectionName); + gp_Ax2 getCSFromBase(const std::string sectionName); gp_Ax2 rotateCSCardinal(gp_Ax2 oldCS, int cardinal) const; gp_Ax2 rotateCSArbitrary(gp_Ax2 oldCS, @@ -121,13 +122,14 @@ protected: std::vector sectionFaceWires; std::vector m_lineSets; - gp_Pln getSectionPlane() const; TopoDS_Compound findSectionPlaneIntersections(const TopoDS_Shape& shape); TopoDS_Face projectFace(const TopoDS_Shape &face, gp_Pnt faceCenter, const Base::Vector3d &direction); void getParameters(void); + bool debugSection(void) const; + TopoDS_Shape m_cutShape; }; diff --git a/src/Mod/TechDraw/App/GeometryObject.cpp b/src/Mod/TechDraw/App/GeometryObject.cpp index 9cab71e0a5..549e70a2fc 100644 --- a/src/Mod/TechDraw/App/GeometryObject.cpp +++ b/src/Mod/TechDraw/App/GeometryObject.cpp @@ -810,7 +810,7 @@ TopoDS_Shape TechDraw::rotateShape(const TopoDS_Shape &input, return transShape; } -//!scales a shape about a origin +//!scales a shape about origin TopoDS_Shape TechDraw::scaleShape(const TopoDS_Shape &input, double scale) { diff --git a/src/Mod/TechDraw/Gui/TaskSectionView.cpp b/src/Mod/TechDraw/Gui/TaskSectionView.cpp index ef848afd9e..fcee4d29ff 100644 --- a/src/Mod/TechDraw/Gui/TaskSectionView.cpp +++ b/src/Mod/TechDraw/Gui/TaskSectionView.cpp @@ -98,6 +98,8 @@ TaskSectionView::TaskSectionView(TechDraw::DrawViewPart* base) : this, SLOT(onRightClicked(bool))); connect(ui->pbLeft, SIGNAL(clicked(bool)), this, SLOT(onLeftClicked(bool))); + connect(ui->pbApply, SIGNAL(clicked(bool)), + this, SLOT(onApplyClicked(bool))); setUiPrimary(); } @@ -137,8 +139,10 @@ TaskSectionView::TaskSectionView(TechDraw::DrawViewSection* section) : this, SLOT(onRightClicked(bool))); connect(ui->pbLeft, SIGNAL(clicked(bool)), this, SLOT(onLeftClicked(bool))); + connect(ui->pbApply, SIGNAL(clicked(bool)), + this, SLOT(onApplyClicked(bool))); - m_dirName = m_section->SectionDirection.getValue(); + m_dirName = m_section->SectionDirection.getValueAsString(); saveSectionState(); setUiEdit(); } @@ -193,7 +197,7 @@ void TaskSectionView::saveSectionState() m_saveNormal = m_section->SectionNormal.getValue(); m_saveDirection = m_section->Direction.getValue(); m_saveOrigin = m_section->SectionOrigin.getValue(); - m_saveDirName = m_section->SectionDirection.getValue(); + m_saveDirName = m_section->SectionDirection.getValueAsString(); m_saved = true; } } @@ -253,9 +257,17 @@ void TaskSectionView::onRightClicked(bool b) applyQuick("Right"); } -bool TaskSectionView::apply() +void TaskSectionView::onApplyClicked(bool b) { -// Base::Console().Message("TSV::apply()\n"); +// Base::Console().Message("TSV::onApplyClicked()\n"); + Q_UNUSED(b); + checkAll(false); + apply(); +} + +void TaskSectionView::apply(void) +{ +// Base::Console().Message("TSV::apply() - m_dirName: %s\n", m_dirName.c_str()); if (m_dirName.empty()) { std::string msg = Base::Tools::toStdString(tr("TSV::apply - No section direction picked yet")); Base::Console().Error((msg + "\n").c_str()); @@ -263,7 +275,6 @@ bool TaskSectionView::apply() checkAll(false); applyQuick(m_dirName); } - return true; } void TaskSectionView::checkAll(bool b) @@ -280,13 +291,11 @@ void TaskSectionView::applyQuick(std::string dir) // Base::Console().Message("TSV::applyQuick(%s)\n", dir.c_str()); m_dirName = dir; Gui::Command::openCommand("Apply Quick"); - m_dirName = dir; if (m_section == nullptr) { m_section = createSectionView(); } updateSectionView(); m_section->recomputeFeature(); -// m_section->requestPaint(); m_base->requestPaint(); } @@ -354,18 +363,18 @@ void TaskSectionView::updateSectionView(void) Command::doCommand(Command::Doc,"App.activeDocument().%s.SectionSymbol = '%s'", sectionName.c_str(), temp.c_str()); - m_section->setNormalFromBase(m_dirName.c_str()); + m_section->setCSFromBase(m_dirName.c_str()); } } -void TaskSectionView::saveButtons(QPushButton* btnOK, - QPushButton* btnCancel, - QPushButton* btnApply) -{ - m_btnOK = btnOK; - m_btnCancel = btnCancel; - m_btnApply = btnApply; -} +//void TaskSectionView::saveButtons(QPushButton* btnOK, +// QPushButton* btnCancel, +// QPushButton* btnApply) +//{ +// m_btnOK = btnOK; +// m_btnCancel = btnCancel; +// m_btnApply = btnApply; +//} //std::string TaskSectionView::prefViewSection() //{ @@ -385,12 +394,10 @@ bool TaskSectionView::accept() if (m_section == nullptr) { apply(); } - Gui::Command::updateActive(); - Gui::Command::commitCommand(); } else { Gui::Command::openCommand("Edit SectionView"); try { - updateSectionView(); + apply(); } catch (...) { Base::Console().Error("TSV::accept - failed to update section\n"); @@ -401,7 +408,6 @@ bool TaskSectionView::accept() } Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); if (m_section != nullptr) { -// m_section->recomputeFeature(); m_section->requestPaint(); } if (m_base != nullptr) { @@ -424,13 +430,11 @@ bool TaskSectionView::reject() "App.activeDocument().removeObject('%s')", SectionName.c_str()); } else { - Base::Console().Message("TSV::reject() - edit mode\n"); restoreSectionState(); //check undo stack? m_section->requestPaint(); m_base->requestPaint(); } - } Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().recompute()"); @@ -475,42 +479,17 @@ void TaskDlgSectionView::update() //widget->updateTask(); } -void TaskDlgSectionView::modifyStandardButtons(QDialogButtonBox* box) -{ - QPushButton* btnOK = box->button(QDialogButtonBox::Ok); - QPushButton* btnCancel = box->button(QDialogButtonBox::Cancel); - QPushButton* btnApply = box->button(QDialogButtonBox::Apply); - widget->saveButtons(btnOK, btnCancel, btnApply); -} - - //==== calls from the TaskView =============================================================== void TaskDlgSectionView::open() { } -void TaskDlgSectionView::clicked(int i) -{ -// Q_UNUSED(i); -// Base::Console().Message("TDSV::clicked(%X)\n",i); - if (i == QMessageBox::Apply) { - widget->apply(); - } -} - bool TaskDlgSectionView::accept() { widget->accept(); return true; } -//bool TaskDlgSectionView::apply() -//{ -// Base::Console().Message("TDSV::apply()\n"); -// widget->apply(); -// return true; -//} - bool TaskDlgSectionView::reject() { widget->reject(); diff --git a/src/Mod/TechDraw/Gui/TaskSectionView.h b/src/Mod/TechDraw/Gui/TaskSectionView.h index b9823230b8..f213d9e09c 100644 --- a/src/Mod/TechDraw/Gui/TaskSectionView.h +++ b/src/Mod/TechDraw/Gui/TaskSectionView.h @@ -48,19 +48,14 @@ public: public: virtual bool accept(); - virtual bool apply(); virtual bool reject(); - void modifyStandardButtons(QDialogButtonBox* box); - void saveButtons(QPushButton* btnOK, - QPushButton* btnCancel, - QPushButton* btnApply); - protected Q_SLOTS: void onUpClicked(bool b); void onDownClicked(bool b); void onLeftClicked(bool b); void onRightClicked(bool b); + void onApplyClicked(bool b); protected: void blockButtons(bool b); @@ -69,6 +64,7 @@ protected: void saveSectionState(); void restoreSectionState(); + void apply(void); void applyQuick(std::string dir); void applyAligned(void); @@ -80,8 +76,6 @@ protected: void checkAll(bool b); -// std::string prefViewSection(); - private: Ui_TaskSectionView * ui; TechDraw::DrawViewPart* m_base; @@ -99,10 +93,6 @@ private: std::string m_dirName; - QPushButton* m_btnOK; - QPushButton* m_btnCancel; - QPushButton* m_btnApply; - bool m_createMode; bool m_saved; @@ -121,7 +111,7 @@ public: /// is called the TaskView when the dialog is opened virtual void open(); /// is called by the framework if an button is clicked which has no accept or reject role - virtual void clicked(int); +/* virtual void clicked(int);*/ /// is called by the framework if the dialog is accepted (Ok) virtual bool accept(); /// is called by the framework if the dialog is rejected (Cancel) @@ -133,8 +123,8 @@ public: { return false; } virtual QDialogButtonBox::StandardButtons getStandardButtons() const - { return QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel; } - virtual void modifyStandardButtons(QDialogButtonBox* box); + { return QDialogButtonBox::Ok | QDialogButtonBox::Cancel; } +/* virtual void modifyStandardButtons(QDialogButtonBox* box);*/ void update(); diff --git a/src/Mod/TechDraw/Gui/TaskSectionView.ui b/src/Mod/TechDraw/Gui/TaskSectionView.ui index 0fa2e1758a..861c747e20 100644 --- a/src/Mod/TechDraw/Gui/TaskSectionView.ui +++ b/src/Mod/TechDraw/Gui/TaskSectionView.ui @@ -6,8 +6,8 @@ 0 0 - 434 - 368 + 368 + 450 @@ -19,7 +19,7 @@ 250 - 300 + 450 @@ -37,7 +37,7 @@ 350 - 350 + 400 @@ -49,6 +49,9 @@ + + QFormLayout::AllNonFixedFieldsGrow + @@ -66,7 +69,7 @@ - Symbol + Identifier @@ -77,62 +80,25 @@ - - - - Section Origin X - - - - - - - <html><head/><body><p>Location of section plane in 3D coordinates</p></body></html> - - - - - - - - - - Section Origin Y - - - - - - - <html><head/><body><p>Location of section plane in 3D coordinates</p></body></html> - - - - - - - - - - Section Origin Z - - - - - - - <html><head/><body><p>Location of section plane in 3D coordinates</p></body></html> - - - - - - + + + + Qt::Horizontal + + + + + + + Section Orientation + + + - + Looking right @@ -156,7 +122,7 @@ - + Looking up @@ -186,7 +152,7 @@ - + Looking left @@ -210,7 +176,7 @@ - + Looking down @@ -234,19 +200,199 @@ + + + + + + Qt::Horizontal + + + + + + + Section Plane Location + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + QFormLayout::AllNonFixedFieldsGrow + - - - - 50 - false - + + + + 0 + 0 + + + + 150 + 0 + + + + X + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + + 150 + 24 + + + + <html><head/><body><p>Location of section plane in 3D coordinates</p></body></html> + + + + + + + + + + + 0 + 0 + + + + + 150 + 0 + + + + Y + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + + 150 + 24 + + + + <html><head/><body><p>Location of section plane in 3D coordinates</p></body></html> + + + + + + + + + + + 0 + 0 + + + + + 150 + 0 + + + + Z + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + + 150 + 24 + + + + <html><head/><body><p>Location of section plane in 3D coordinates</p></body></html> + + + + + + + + + + + + Apply + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + +