Skip to content

Commit

Permalink
PartGui: Revolve: solid checkbox automation
Browse files Browse the repository at this point in the history
Solid checkbox will be checked by default, if the shape being revolved
is closed wires.
  • Loading branch information
DeepSOIC authored and wwmayer committed Sep 1, 2016
1 parent f3a3bd1 commit 616c2f7
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/Mod/Part/Gui/DlgRevolution.cpp
Expand Up @@ -28,9 +28,12 @@
# include <gp_Lin.hxx>
# include <gp_Pnt.hxx>
# include <BRepAdaptor_Curve.hxx>
# include <BRep_Tool.hxx>
# include <TopExp_Explorer.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Edge.hxx>
# include <ShapeExtend_Explorer.hxx>
# include <TopTools_HSequenceOfShape.hxx>
# include <Inventor/system/inttypes.h>
# include <Precision.hxx>
#endif
Expand Down Expand Up @@ -127,6 +130,7 @@ DlgRevolution::DlgRevolution(QWidget* parent, Qt::WindowFlags fl)

connect(ui->txtAxisLink, SIGNAL(textChanged(QString)), this, SLOT(on_txtAxisLink_textChanged(QString)));

autoSolid();
}

/*
Expand Down Expand Up @@ -224,6 +228,23 @@ void DlgRevolution::setAxisLink(const char* objname, const char* subname)
}
}

std::vector<App::DocumentObject*> DlgRevolution::getShapesToRevolve() const
{
QList<QTreeWidgetItem *> items = ui->treeWidget->selectedItems();
App::Document* doc = App::GetApplication().getActiveDocument();
if (!doc)
throw Base::Exception("Document lost");

std::vector<App::DocumentObject*> 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
Expand Down Expand Up @@ -481,6 +502,44 @@ void DlgRevolution::onSelectionChanged(const Gui::SelectionChanges& msg)
}
}

App::DocumentObject&DlgRevolution::getShapeToRevolve() const
{
std::vector<App::DocumentObject*> 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<Part::Feature&>(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()
Expand Down
8 changes: 8 additions & 0 deletions src/Mod/Part/Gui/DlgRevolution.h
Expand Up @@ -50,6 +50,8 @@ class DlgRevolution : public QDialog, public Gui::SelectionObserver
void setAxisLink(const App::PropertyLinkSub &lnk);
void setAxisLink(const char* objname, const char* subname);

std::vector<App::DocumentObject*> getShapesToRevolve() const;

bool validate();

protected:
Expand All @@ -66,6 +68,12 @@ private Q_SLOTS:
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_DlgRevolution> Ui_RevolutionComp;
Ui_DlgRevolution* ui;
Expand Down

0 comments on commit 616c2f7

Please sign in to comment.