From d8a0e398a99228cda1bedcc7419fda90a0221994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Fri, 22 May 2015 18:37:37 +0200 Subject: [PATCH] make origin lines usable in groove --- src/Mod/PartDesign/App/FeatureSketchBased.cpp | 17 ++-- .../PartDesign/Gui/TaskGrooveParameters.cpp | 85 ++++++++++++++++--- .../PartDesign/Gui/TaskGrooveParameters.ui | 25 ++++-- 3 files changed, 100 insertions(+), 27 deletions(-) diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.cpp b/src/Mod/PartDesign/App/FeatureSketchBased.cpp index 3a51066bd..aafc88876 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.cpp +++ b/src/Mod/PartDesign/App/FeatureSketchBased.cpp @@ -1041,9 +1041,9 @@ void SketchBased::getAxis(const App::DocumentObject *pcReferenceAxis, const std: base = line->getBasePoint(); dir = line->getDirection(); - // Check that axis is co-planar with sketch plane! - if (!sketchplane.Contains(gp_Lin(gp_Pnt(base.x, base.y, base.z), gp_Dir(dir.x, dir.y, dir.z)), Precision::Confusion(), Precision::Confusion())) - throw Base::Exception("Rotation axis must be coplanar with the sketch plane"); + // Check that axis is perpendicular with sketch plane! + if (sketchplane.Axis().Direction().Angle(gp_Dir(dir.x, dir.y, dir.z))< Precision::Angular()) + throw Base::Exception("Rotation axis must not be perpendicular with the sketch plane"); } else if (pcReferenceAxis->getTypeId().isDerivedFrom(App::Line::getClassTypeId())) { const App::Line* line = static_cast(pcReferenceAxis); @@ -1055,9 +1055,9 @@ void SketchBased::getAxis(const App::DocumentObject *pcReferenceAxis, const std: else if( strcmp(line->getNameInDocument(), App::Part::BaselineTypes[2]) == 0) dir = Base::Vector3d(0,0,1); - // Check that axis is co-planar with sketch plane! - if (!sketchplane.Contains(gp_Lin(gp_Pnt(base.x, base.y, base.z), gp_Dir(dir.x, dir.y, dir.z)), Precision::Confusion(), Precision::Confusion())) - throw Base::Exception("Rotation axis must be coplanar with the sketch plane"); + // Check that axis is perpendicular with sketch plane! + if (sketchplane.Axis().Direction().Angle(gp_Dir(dir.x, dir.y, dir.z)) < Precision::Angular()) + throw Base::Exception("Rotation axis must not be perpendicular with the sketch plane"); } else if (pcReferenceAxis->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId())) { if (subReferenceAxis[0].empty()) @@ -1079,8 +1079,9 @@ void SketchBased::getAxis(const App::DocumentObject *pcReferenceAxis, const std: gp_Dir d = adapt.Line().Direction(); dir = Base::Vector3d(d.X(), d.Y(), d.Z()); // Check that axis is co-planar with sketch plane! - if (!sketchplane.Contains(adapt.Line(), Precision::Confusion(), Precision::Confusion())) - throw Base::Exception("Rotation axis must be coplanar with the sketch plane"); + // Check that axis is perpendicular with sketch plane! + if (sketchplane.Axis().Direction().Angle(d) < Precision::Angular()) + throw Base::Exception("Rotation axis must not be perpendicular with the sketch plane"); } else { throw Base::Exception("Rotation reference must be an edge"); } diff --git a/src/Mod/PartDesign/Gui/TaskGrooveParameters.cpp b/src/Mod/PartDesign/Gui/TaskGrooveParameters.cpp index f2ddee2e2..2652f1698 100644 --- a/src/Mod/PartDesign/Gui/TaskGrooveParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskGrooveParameters.cpp @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include #include #include @@ -39,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -100,6 +103,21 @@ TaskGrooveParameters::TaskGrooveParameters(ViewProviderGroove *GrooveView,QWidge ui->checkBoxReversed->blockSignals(false); setFocus (); + + //show the parts coordinate system axis for selection + for(App::Part* part : App::GetApplication().getActiveDocument()->getObjectsOfType()) { + + if(part->hasObject(vp->getObject(), true)) { + auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId()); + if(!app_origin.empty()) { + ViewProviderOrigin* origin; + origin = static_cast(Gui::Application::Instance->activeDocument()->getViewProvider(app_origin[0])); + origin->setTemporaryVisibilityMode(true, Gui::Application::Instance->activeDocument()); + origin->setTemporaryVisibilityAxis(true); + } + break; + } + } } void TaskGrooveParameters::updateUI() @@ -115,23 +133,30 @@ void TaskGrooveParameters::updateUI() // Add user-defined sketch axes to the reference selection combo box Sketcher::SketchObject *pcSketch = static_cast(pcGroove->Sketch.getValue()); - int maxcount=2; + int maxcount=5; if (pcSketch) maxcount += pcSketch->getAxisCount(); - for (int i=ui->axis->count()-1; i >= 2; i--) + for (int i=ui->axis->count()-1; i >= 5; i--) ui->axis->removeItem(i); for (int i=ui->axis->count(); i < maxcount; i++) ui->axis->addItem(QString::fromAscii("Sketch axis %1").arg(i-5)); - bool undefined = false; - if (pcReferenceAxis != NULL && !sub.empty()) { - if (sub.front() == "H_Axis") + bool undefined = false; + if (pcReferenceAxis != NULL) { + + if(strcmp(pcReferenceAxis->getNameInDocument(), App::Part::BaselineTypes[0])==0) ui->axis->setCurrentIndex(0); - else if (sub.front() == "V_Axis") + else if(strcmp(pcReferenceAxis->getNameInDocument(), App::Part::BaselineTypes[1])==0) ui->axis->setCurrentIndex(1); - else if (sub.front().size() > 4 && sub.front().substr(0,4) == "Axis") { - int pos = 2 + std::atoi(sub.front().substr(4,4000).c_str()); + else if(strcmp(pcReferenceAxis->getNameInDocument(), App::Part::BaselineTypes[2])==0) + ui->axis->setCurrentIndex(2); + else if (!sub.empty() && sub.front() == "H_Axis") + ui->axis->setCurrentIndex(3); + else if (!sub.empty() && sub.front() == "V_Axis") + ui->axis->setCurrentIndex(4); + else if (!sub.empty() && sub.front().size() > 4 && sub.front().substr(0,4) == "Axis") { + int pos = 5 + std::atoi(sub.front().substr(4,4000).c_str()); if (pos <= maxcount) ui->axis->setCurrentIndex(pos); else @@ -203,12 +228,24 @@ void TaskGrooveParameters::onAxisChanged(int num) int maxcount = pcSketch->getAxisCount()+2; if (num == 0) { + pcGroove->ReferenceAxis.setValue(pcGroove->getDocument()->getObject(App::Part::BaselineTypes[0]), + std::vector(1,"")); + } + else if (num == 1) { + pcGroove->ReferenceAxis.setValue(pcGroove->getDocument()->getObject(App::Part::BaselineTypes[1]), + std::vector(1,"")); + } + else if (num == 2) { + pcGroove->ReferenceAxis.setValue(pcGroove->getDocument()->getObject(App::Part::BaselineTypes[2]), + std::vector(1,"")); + } + else if (num == 3) { pcGroove->ReferenceAxis.setValue(pcSketch, std::vector(1,"H_Axis")); exitSelectionMode(); - } else if (num == 1) { + } else if (num == 4) { pcGroove->ReferenceAxis.setValue(pcSketch, std::vector(1,"V_Axis")); exitSelectionMode(); - } else if (num >= 2 && num < maxcount) { + } else if (num >= 5 && num < maxcount) { QString buf = QString::fromUtf8("Axis%1").arg(num-2); std::string str = buf.toStdString(); pcGroove->ReferenceAxis.setValue(pcSketch, std::vector(1,str)); @@ -263,17 +300,23 @@ void TaskGrooveParameters::getReferenceAxis(App::DocumentObject*& obj, std::vect PartDesign::Groove* pcGroove = static_cast(vp->getObject()); obj = static_cast(pcGroove->Sketch.getValue()); sub = std::vector(1,""); - int maxcount=2; + int maxcount=5; if (obj) maxcount += static_cast(obj)->getAxisCount(); if (obj) { int num = ui->axis->currentIndex(); - if (num == 0) + if(num == 0) + obj = pcGroove->getDocument()->getObject(App::Part::BaselineTypes[0]); + else if(num == 1) + obj = pcGroove->getDocument()->getObject(App::Part::BaselineTypes[1]); + else if(num == 2) + obj = pcGroove->getDocument()->getObject(App::Part::BaselineTypes[2]); + else if (num == 3) sub[0] = "H_Axis"; - else if (num == 1) + else if (num == 4) sub[0] = "V_Axis"; - else if (num >= 2 && num < maxcount) { + else if (num >= 5 && num < maxcount) { QString buf = QString::fromUtf8("Axis%1").arg(num-2); sub[0] = buf.toStdString(); } else if (num == maxcount && ui->axis->count() == maxcount + 2) { @@ -301,6 +344,20 @@ bool TaskGrooveParameters::getReversed(void) const TaskGrooveParameters::~TaskGrooveParameters() { + //hide the parts coordinate system axis for selection + for(App::Part* part : App::GetApplication().getActiveDocument()->getObjectsOfType()) { + + if(part->hasObject(vp->getObject(), true)) { + auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId()); + if(!app_origin.empty()) { + ViewProviderOrigin* origin; + origin = static_cast(Gui::Application::Instance->activeDocument()->getViewProvider(app_origin[0])); + origin->setTemporaryVisibilityMode(false); + } + break; + } + } + delete ui; } diff --git a/src/Mod/PartDesign/Gui/TaskGrooveParameters.ui b/src/Mod/PartDesign/Gui/TaskGrooveParameters.ui index 07f78e043..9dec961ff 100644 --- a/src/Mod/PartDesign/Gui/TaskGrooveParameters.ui +++ b/src/Mod/PartDesign/Gui/TaskGrooveParameters.ui @@ -25,6 +25,21 @@ + + + Base X axis + + + + + Base Y axis + + + + + Base Z axis + + Horizontal sketch axis @@ -54,20 +69,20 @@ - + deg - + 0.000000000000000 - + 360.000000000000000 - + 10.000000000000000 - + 360.000000000000000