From: skv Date: Mon, 24 Mar 2014 09:13:11 +0000 (+0400) Subject: 0022380: EDF 2746 GEOM: Accept compounds of points as an input for "Smoothing surface" X-Git-Tag: V7_4_0a1~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ef20f40494c9ede9394c4465ed565a5a30332611;p=modules%2Fgeom.git 0022380: EDF 2746 GEOM: Accept compounds of points as an input for "Smoothing surface" --- diff --git a/doc/salome/gui/GEOM/input/creating_smoothingsurface.doc b/doc/salome/gui/GEOM/input/creating_smoothingsurface.doc index a4b42cee3..5b102a173 100644 --- a/doc/salome/gui/GEOM/input/creating_smoothingsurface.doc +++ b/doc/salome/gui/GEOM/input/creating_smoothingsurface.doc @@ -7,6 +7,8 @@ Advanced - > SmoothingSurface Specify the \b Name of the surface and the list of \b Points, from which it is approximated and press "Apply" or "Apply & Close" button. +\note The dialog accepts compounds of points as well as single nodes. + The result of the operation will be a GEOM_Object(Surface). TUI Command: geompy.MakeSmoothingSurface(Points) diff --git a/src/AdvancedEngine/GEOMImpl_IAdvancedOperations.cxx b/src/AdvancedEngine/GEOMImpl_IAdvancedOperations.cxx index f486a63f4..6e535e2ac 100644 --- a/src/AdvancedEngine/GEOMImpl_IAdvancedOperations.cxx +++ b/src/AdvancedEngine/GEOMImpl_IAdvancedOperations.cxx @@ -3429,7 +3429,7 @@ Handle(GEOM_Object) GEOMImpl_IAdvancedOperations::MakeDividedCylinder (double th //============================================================================= /*! * Create a smoothing surface from a set of points - * \param thelPoints list of points + * \param thelPoints list of points or compounds of points * \return New GEOM_Object, containing the created shape. */ //============================================================================= @@ -3454,12 +3454,12 @@ Handle(GEOM_Object) GEOMImpl_IAdvancedOperations::MakeSmoothingSurface (std::lis int ind = 1; std::list::iterator it = thelPoints.begin(); for (; it != thelPoints.end(); it++, ind++) { - Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction(); - if (aRefPnt.IsNull()) { - SetErrorCode("NULL point for bSplineFaceShape"); + Handle(GEOM_Function) aRefObj = (*it)->GetLastFunction(); + if (aRefObj.IsNull()) { + SetErrorCode("NULL point or compound for bSplineFaceShape"); return NULL; } - aData.SetPoint(ind, aRefPnt); + aData.SetPntOrComp(ind, aRefObj); } diff --git a/src/AdvancedEngine/GEOMImpl_ISmoothingSurface.hxx b/src/AdvancedEngine/GEOMImpl_ISmoothingSurface.hxx index 412b65bfa..5cd77a502 100644 --- a/src/AdvancedEngine/GEOMImpl_ISmoothingSurface.hxx +++ b/src/AdvancedEngine/GEOMImpl_ISmoothingSurface.hxx @@ -36,8 +36,8 @@ public: void SetLength(int theLen) { _func->SetInteger(SMOOTHINGSURFACE_ARG_LENG, theLen); } int GetLength() { return _func->GetInteger(SMOOTHINGSURFACE_ARG_LENG); } - void SetPoint(int theId, Handle(GEOM_Function) theP) { _func->SetReference(SMOOTHINGSURFACE_ARG_LAST + theId, theP); } - Handle(GEOM_Function) GetPoint(int theId) { return _func->GetReference(SMOOTHINGSURFACE_ARG_LAST + theId); } + void SetPntOrComp(int theId, Handle(GEOM_Function) theP) { _func->SetReference(SMOOTHINGSURFACE_ARG_LAST + theId, theP); } + Handle(GEOM_Function) GetPntOrComp(int theId) { return _func->GetReference(SMOOTHINGSURFACE_ARG_LAST + theId); } private: Handle(GEOM_Function) _func; diff --git a/src/AdvancedEngine/GEOMImpl_SmoothingSurfaceDriver.cxx b/src/AdvancedEngine/GEOMImpl_SmoothingSurfaceDriver.cxx index 61ec99aaa..662df4623 100644 --- a/src/AdvancedEngine/GEOMImpl_SmoothingSurfaceDriver.cxx +++ b/src/AdvancedEngine/GEOMImpl_SmoothingSurfaceDriver.cxx @@ -34,6 +34,9 @@ #include #include #include +#include +#include +#include #include #include @@ -167,22 +170,43 @@ Standard_Integer GEOMImpl_SmoothingSurfaceDriver::Execute(TFunction_Logbook& log // cout << "Youhou : " << aType << endl; GEOMImpl_ISmoothingSurface aData (aFunction); - - Standard_Integer nbPoints = aData.GetLength(); - Handle(TColgp_HArray1OfPnt) anArrayofPnt = new TColgp_HArray1OfPnt(1,nbPoints); - for (int ind=1;ind<=nbPoints;ind++) - { - Handle(GEOM_Function) aPoint = aData.GetPoint(ind); - TopoDS_Shape aShapePnt = aPoint->GetValue(); - TopoDS_Vertex dsPoint; - dsPoint = TopoDS::Vertex( aShapePnt ); - gp_Pnt aPnt = BRep_Tool::Pnt( dsPoint ); - anArrayofPnt->SetValue(ind,aPnt); + // Fill the map of vertices. + Standard_Integer aNbShapes = aData.GetLength(); + TopTools_MapOfShape aMapPoints; + Standard_Integer i; + + for (i = 1; i <= aNbShapes; i++) { + Handle(GEOM_Function) aFShape = aData.GetPntOrComp(i); + TopoDS_Shape aShape = aFShape->GetValue(); + + if (aShape.ShapeType() == TopAbs_VERTEX) { + aMapPoints.Add(aShape); + } else { + TopExp_Explorer anExp(aShape, TopAbs_VERTEX); + + for (; anExp.More(); anExp.Next()) { + aMapPoints.Add(anExp.Current()); + } + } + } + + // Add points to the array of points. + const Standard_Integer aNbPoints = aMapPoints.Extent(); + Handle(TColgp_HArray1OfPnt) anArrayofPnt = + new TColgp_HArray1OfPnt(1, aNbPoints); + TopTools_MapIteratorOfMapOfShape anIter(aMapPoints); + + for (i = 1; anIter.More(); anIter.Next(), i++) { + TopoDS_Vertex aPoint = TopoDS::Vertex(anIter.Key()); + gp_Pnt aPnt = BRep_Tool::Pnt(aPoint); + + anArrayofPnt->SetValue(i, aPnt); } - TopoDS_Shape aShape; - aShape = GEOMImpl_SmoothingSurfaceDriver::MakeSmoothingSurfaceUnClosed(anArrayofPnt); + // Make smoothing surface. + TopoDS_Shape aShape = + GEOMImpl_SmoothingSurfaceDriver::MakeSmoothingSurfaceUnClosed(anArrayofPnt); if (aShape.IsNull()) return 0; @@ -217,7 +241,7 @@ GetCreationInformation(std::string& theOperationName, if ( aCI.GetLength() > 1 ) theParams[0] << aCI.GetLength() << " points: "; for ( int i = 1, nb = aCI.GetLength(); i <= nb; ++i ) - theParams[0] << aCI.GetPoint( i ) << " "; + theParams[0] << aCI.GetPntOrComp( i ) << " "; break; default: return false; diff --git a/src/AdvancedGUI/AdvancedGUI_SmoothingSurfaceDlg.cxx b/src/AdvancedGUI/AdvancedGUI_SmoothingSurfaceDlg.cxx index 8a93ce3de..d8fe39809 100644 --- a/src/AdvancedGUI/AdvancedGUI_SmoothingSurfaceDlg.cxx +++ b/src/AdvancedGUI/AdvancedGUI_SmoothingSurfaceDlg.cxx @@ -31,6 +31,7 @@ // OCCT Includes #include #include +#include #include #include #include @@ -208,16 +209,80 @@ bool AdvancedGUI_SmoothingSurfaceDlg::execute (ObjectList& objects) return res; } +//================================================================================= +// function : getNbPoints() +// purpose : Returns the number of points in myPoints list. +//================================================================================= +int AdvancedGUI_SmoothingSurfaceDlg::getNbPoints() const +{ + TopTools_IndexedMapOfShape aMap; + + foreach (GEOM::GeomObjPtr anObj, myPoints) { + TopoDS_Shape aShape; + + if(anObj && GEOMBase::GetShape(anObj.get(), aShape) && !aShape.IsNull()) { + if (aShape.ShapeType() == TopAbs_VERTEX) { + aMap.Add(aShape); + } else { + // Compound. + TopExp::MapShapes(aShape, TopAbs_VERTEX, aMap); + } + } + } + + const int aNbPoints = aMap.Extent(); + + return aNbPoints; +} + //================================================================================= // function : SelectionIntoArgument() // purpose : Called when selection as changed or other case //================================================================================= void AdvancedGUI_SmoothingSurfaceDlg::SelectionIntoArgument() { - QList points = getSelected( TopAbs_VERTEX, -1 ); + QList aTypes; + + aTypes << TopAbs_VERTEX << TopAbs_COMPOUND; + + QList points = getSelected( aTypes, -1 ); + + // Check the selected compounds if they consist of points only. + foreach (GEOM::GeomObjPtr anObj, points) { + TopoDS_Shape aShape; + + if(anObj && GEOMBase::GetShape(anObj.get(), aShape) && !aShape.IsNull()) { + if (aShape.ShapeType() == TopAbs_COMPOUND) { + // Check if the compound contains vertices only. + TopoDS_Iterator anIter(aShape); + Standard_Boolean isValid = Standard_False; + + for (; anIter.More(); anIter.Next()) { + const TopoDS_Shape &aSubShape = anIter.Value(); + + if (aSubShape.ShapeType() == TopAbs_VERTEX) { + isValid = Standard_True; + } else { + isValid = Standard_False; + break; + } + } + + if (!isValid) { + points.clear(); + break; + } + } + } else { + // NEVERREACHED + points.clear(); + break; + } + } + GEOMBase::Synchronize( myPoints, points ); if ( !myPoints.isEmpty() ) - GroupPoints->LineEdit1->setText( QString::number( myPoints.count() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) ); + GroupPoints->LineEdit1->setText( QString::number( getNbPoints() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) ); else GroupPoints->LineEdit1->setText( "" ); processPreview(); diff --git a/src/AdvancedGUI/AdvancedGUI_SmoothingSurfaceDlg.h b/src/AdvancedGUI/AdvancedGUI_SmoothingSurfaceDlg.h index 3a8a053d8..c12ab5173 100644 --- a/src/AdvancedGUI/AdvancedGUI_SmoothingSurfaceDlg.h +++ b/src/AdvancedGUI/AdvancedGUI_SmoothingSurfaceDlg.h @@ -48,6 +48,7 @@ protected: private: void Init(); void enterEvent( QEvent* ); + int getNbPoints() const; private: DlgRef_1Sel* GroupPoints; diff --git a/src/GEOM_SWIG/geomBuilder.py b/src/GEOM_SWIG/geomBuilder.py old mode 100644 new mode 100755 index 8f2afc126..34fe54d71 --- a/src/GEOM_SWIG/geomBuilder.py +++ b/src/GEOM_SWIG/geomBuilder.py @@ -12629,7 +12629,8 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen): return anObj ## Create a surface from a cloud of points - # @param thelPoints list of points + # @param thelPoints list of points. Compounds of points are + # accepted as well. # @return New GEOM_Object, containing the created shape. # # @ref tui_creation_smoothingsurface "Example"