diff --git a/src/Mod/Part/Gui/DlgRevolution.cpp b/src/Mod/Part/Gui/DlgRevolution.cpp index 4e424bd07..a1db0402d 100644 --- a/src/Mod/Part/Gui/DlgRevolution.cpp +++ b/src/Mod/Part/Gui/DlgRevolution.cpp @@ -28,9 +28,12 @@ # include # include # include +# include # include # include # include +# include +# include # include # include #endif @@ -127,6 +130,7 @@ DlgRevolution::DlgRevolution(QWidget* parent, Qt::WindowFlags fl) connect(ui->txtAxisLink, SIGNAL(textChanged(QString)), this, SLOT(on_txtAxisLink_textChanged(QString))); + autoSolid(); } /* @@ -224,6 +228,23 @@ void DlgRevolution::setAxisLink(const char* objname, const char* subname) } } +std::vector DlgRevolution::getShapesToRevolve() const +{ + QList items = ui->treeWidget->selectedItems(); + App::Document* doc = App::GetApplication().getActiveDocument(); + if (!doc) + throw Base::Exception("Document lost"); + + std::vector objects; + for(size_t i = 0 ; i < items.size() ; i++){ + App::DocumentObject* obj = doc->getObject(items[i]->data(0, Qt::UserRole).toString().toLatin1()); + if (!obj) + throw Base::Exception("Object not found"); + objects.push_back(obj); + } + return objects; +} + bool DlgRevolution::validate() { //check source shapes @@ -481,6 +502,44 @@ void DlgRevolution::onSelectionChanged(const Gui::SelectionChanges& msg) } } +App::DocumentObject&DlgRevolution::getShapeToRevolve() const +{ + std::vector objs = this->getShapesToRevolve(); + if (objs.size() == 0) + throw Base::Exception("No shapes selected"); + return *(objs[0]); +} + +void DlgRevolution::autoSolid() +{ + try{ + App::DocumentObject &dobj = this->getShapeToRevolve(); + if (dobj.isDerivedFrom(Part::Feature::getClassTypeId())){ + Part::Feature &feature = static_cast(dobj); + TopoDS_Shape sh = feature.Shape.getValue(); + if (sh.IsNull()) + return; + ShapeExtend_Explorer xp; + Handle_TopTools_HSequenceOfShape leaves = xp.SeqFromCompound(sh, /*recursive= */Standard_True); + int cntClosedWires = 0; + for(int i = 0 ; i < leaves->Length() ; i++){ + const TopoDS_Shape &leaf = leaves->Value(i+1); + if (leaf.IsNull()) + return; + if (leaf.ShapeType() == TopAbs_WIRE || leaf.ShapeType() == TopAbs_EDGE){ + if (BRep_Tool::IsClosed(leaf)){ + cntClosedWires++; + } + } + } + ui->checkSolid->setChecked( cntClosedWires == leaves->Length() ); + } + } catch(...){ + + } + +} + // --------------------------------------- TaskRevolution::TaskRevolution() diff --git a/src/Mod/Part/Gui/DlgRevolution.h b/src/Mod/Part/Gui/DlgRevolution.h index 4ae1958f8..daaadcd60 100644 --- a/src/Mod/Part/Gui/DlgRevolution.h +++ b/src/Mod/Part/Gui/DlgRevolution.h @@ -50,6 +50,8 @@ public: void setAxisLink(const App::PropertyLinkSub &lnk); void setAxisLink(const char* objname, const char* subname); + std::vector getShapesToRevolve() const; + bool validate(); protected: @@ -66,6 +68,12 @@ private: void findShapes(); void onSelectionChanged(const Gui::SelectionChanges& msg); + ///returns link to any of selected source shapes. Throws if nothing is selected for extrusion. + App::DocumentObject& getShapeToRevolve() const; + + ///automatically checks Solid checkbox depending on input shape + void autoSolid(); + private: //typedef Gui::LocationInterfaceComp Ui_RevolutionComp; Ui_DlgRevolution* ui;