From fa14a07690f382aa725c3b494d903a08ead4df52 Mon Sep 17 00:00:00 2001 From: akl Date: Wed, 21 May 2014 13:24:03 +0400 Subject: [PATCH] Algorithm of dependencies definition was updated and replaced. Auxiliry convertation functions were added. --- idl/GEOM_Gen.idl | 5 +- src/GEOMToolsGUI/GEOMToolsGUI.cxx | 141 +----------- src/GEOMToolsGUI/GEOMToolsGUI.h | 14 -- src/GEOMUtils/GEOMUtils.cxx | 364 +++++++++++++++++++++--------- src/GEOMUtils/GEOMUtils.hxx | 55 +++-- src/GEOM_I/CMakeLists.txt | 1 + src/GEOM_I/GEOM_Gen_i.cc | 101 ++++++++- src/GEOM_I/GEOM_Gen_i.hh | 14 +- 8 files changed, 399 insertions(+), 296 deletions(-) diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 5ab5f679a..01187280d 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -5096,11 +5096,12 @@ module GEOM * \return texture byte array * Example of using: * SALOMEDS::TMPFile_var SeqFile = - * myGeometryGUI->GetGeomGen()->GetDependencyTree( aListOfIORs ); + * myGeometryGUI->GetGeomGen()->GetDependencyTree( aStudy, aListOfIORs ); * char* buf; * buf = (char*) &SeqFile[0]; */ - SALOMEDS::TMPFile GetDependencyTree(in string_array strValues); + SALOMEDS::TMPFile GetDependencyTree(in SALOMEDS::Study theStudy, + in string_array strValues); }; }; diff --git a/src/GEOMToolsGUI/GEOMToolsGUI.cxx b/src/GEOMToolsGUI/GEOMToolsGUI.cxx index ca6f6d3f2..daf888e2d 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI.cxx @@ -29,6 +29,7 @@ #include #include "GeometryGUI_Operations.h" +#include #include #include @@ -1044,146 +1045,6 @@ void GEOMToolsGUI::deactivate() } } -//======================================================================= -// function : -// purpose : -//======================================================================= -std::string GEOMToolsGUI::getDependencyTree( QStringList rootObjectIORs ) -{ - // fill in the tree structure - DependencyTree tree; - foreach( QString ior, rootObjectIORs ) { - GEOM::GEOM_Object_ptr anObj = GEOMBase::GetObjectFromIOR( ior ); - QList upLevelList; - getUpwardDependency( anObj, upLevelList ); - QList downLevelList; - getDownwardDependency( anObj, downLevelList ); - tree.insert( ior, QPair, QList >( upLevelList, downLevelList ) ); - } - // translation the tree into string - std::string treeStr; - DependencyTree::iterator i; - for ( i = tree.begin(); i != tree.end(); ++i ) { - treeStr.append( i.key().toUtf8().constData() ); - treeStr.append( "-" ); - QList upLevelList = i.value().first; - treeStr.append( "upward" ); - treeStr.append( "{" ); - foreach( NodeLevel level, upLevelList ) { - NodeLevel::iterator upIter; - for ( upIter = level.begin(); upIter != level.end(); ++upIter ) { - treeStr.append( upIter.key().toUtf8().constData() ); - treeStr.append( "_" ); - treeStr.append( QStringList(upIter.value()).join("_").toUtf8().constData() ); - treeStr.append( upIter+1 == level.end() ? ";" : "," ); - } - } - treeStr.append( "}" ); - QList downLevelList = i.value().second; - treeStr.append( "downward" ); - treeStr.append( "{" ); - foreach( NodeLevel level, downLevelList ) { - NodeLevel::iterator downIter; - for ( downIter = level.begin(); downIter != level.end(); ++downIter ) { - treeStr.append( downIter.key().toUtf8().constData() ); - treeStr.append( "_" ); - treeStr.append( QStringList(downIter.value()).join("_").toUtf8().constData() ); - treeStr.append( downIter+1 == level.end() ? ";" : "," ); - } - } - treeStr.append("}"); - } - return treeStr; -} - -//======================================================================= -// function : -// purpose : -//======================================================================= -void GEOMToolsGUI::getUpwardDependency( GEOM::GEOM_BaseObject_ptr gbo, - QList &upLevelList, - int level ) -{ - QString aGboIOR = GEOMBase::GetIORFromObject(GEOM::GEOM_Object::_narrow(gbo)); - GEOM::ListOfGBO_var depList = gbo->GetDependency(); - for( int j = 0; j < depList->length(); j++ ) { - if ( level > 0 ) { - QStringList anIORs; - NodeLevel aLevelMap; - if ( level-1 >= upLevelList.size() ) { - upLevelList.append( aLevelMap ); - } else { - aLevelMap = upLevelList.at(level-1); - if ( aLevelMap.contains( aGboIOR ) ) - anIORs = aLevelMap.value( aGboIOR ); - } - anIORs << GEOMBase::GetIORFromObject(GEOM::GEOM_Object::_narrow(depList[j])); - aLevelMap.insert( aGboIOR, anIORs ); - } - getUpwardDependency(depList[j], upLevelList, level++); - } -} - -//======================================================================= -// function : -// purpose : -//======================================================================= -void GEOMToolsGUI::getDownwardDependency( GEOM::GEOM_BaseObject_ptr gbo, - QList &downLevelList, - int level ) -{ - SalomeApp_Application* app = - dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); - if ( !app ) - return; - - SalomeApp_Study* appStudy = dynamic_cast( app->activeStudy() ); - if ( !appStudy ) - return; - - _PTR(Study) aStudy = appStudy->studyDS(); - - // get GEOM component - CORBA::String_var geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() ); - QString geomComp = getParentComponent( aStudy->FindObjectIOR( geomIOR.in() ) ); - - _PTR(SObject) comp = aStudy->FindObjectID( geomComp.toLatin1().data() ); - if ( !comp ) - return; - - _PTR(ChildIterator) it ( aStudy->NewChildIterator( comp ) ); - for ( it->InitEx( true ); it->More(); it->Next() ) { - _PTR(SObject) child( it->Value() ); - CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( child ); - GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj ); - if( CORBA::is_nil( geomObj ) ) - continue; - - GEOM::ListOfGBO_var depList = geomObj->GetDependency(); - if( depList->length() == 0 ) - continue; - QString aGoIOR = GEOMBase::GetIORFromObject( geomObj ); - - for( int i = 0; i < depList->length(); i++ ) { - if ( depList[i]->IsSame( gbo ) ) { - QStringList anIORs; - NodeLevel aLevelMap; - if ( level >= downLevelList.size() ) { - aLevelMap = NodeLevel(); - downLevelList.append( aLevelMap ); - } else { - aLevelMap = downLevelList.at(level); - if ( aLevelMap.contains( aGoIOR ) ) - anIORs = aLevelMap.value( aGoIOR ); - } - anIORs << GEOMBase::GetIORFromObject(GEOM::GEOM_Object::_narrow(depList[i])); - aLevelMap.insert( aGoIOR, anIORs ); - } - } - getDownwardDependency(geomObj, downLevelList, level++); - } -} - //===================================================================================== // EXPORTED METHODS //===================================================================================== diff --git a/src/GEOMToolsGUI/GEOMToolsGUI.h b/src/GEOMToolsGUI/GEOMToolsGUI.h index 4d27b0656..683fffc7c 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI.h +++ b/src/GEOMToolsGUI/GEOMToolsGUI.h @@ -30,7 +30,6 @@ #include "GEOM_ToolsGUI.hxx" #include -#include #include class GEOM_Displayer; @@ -43,11 +42,6 @@ class Handle_SALOME_InteractiveObject; class Handle_AIS_InteractiveContext; #include -#include -#include - -typedef QMap< QString, QStringList > NodeLevel; -typedef QMap< QString, QPair, QList > > DependencyTree; //================================================================================= // class : GEOMToolsGUI @@ -66,14 +60,6 @@ public: enum ActionType { SHOWDLG, INCR, DECR }; - std::string getDependencyTree( QStringList rootObjectIORs ); - void getUpwardDependency( GEOM::GEOM_BaseObject_ptr gbo, - QList &upLevelList, - int level = 0 ); - void getDownwardDependency( GEOM::GEOM_BaseObject_ptr gbo, - QList &downLevelList, - int level = 0 ); - private: // Import and export topology methods bool Import(); diff --git a/src/GEOMUtils/GEOMUtils.cxx b/src/GEOMUtils/GEOMUtils.cxx index 468a7f883..95aca3a39 100644 --- a/src/GEOMUtils/GEOMUtils.cxx +++ b/src/GEOMUtils/GEOMUtils.cxx @@ -87,6 +87,7 @@ #include #include +#include #include #include @@ -94,11 +95,13 @@ #define STD_SORT_ALGO 1 +namespace GEOMUtils { + //======================================================================= //function : GetPosition //purpose : //======================================================================= -gp_Ax3 GEOMUtils::GetPosition (const TopoDS_Shape& theShape) +gp_Ax3 GetPosition (const TopoDS_Shape& theShape) { gp_Ax3 aResult; @@ -158,7 +161,7 @@ gp_Ax3 GEOMUtils::GetPosition (const TopoDS_Shape& theShape) //function : GetVector //purpose : //======================================================================= -gp_Vec GEOMUtils::GetVector (const TopoDS_Shape& theShape, +gp_Vec GetVector (const TopoDS_Shape& theShape, Standard_Boolean doConsiderOrientation) { if (theShape.IsNull()) @@ -227,7 +230,7 @@ std::pair ShapeToDouble (const TopoDS_Shape& S, bool isOldSortin //function : CompareShapes::operator() //purpose : used by std::sort(), called from SortShapes() //======================================================================= -bool GEOMUtils::CompareShapes::operator() (const TopoDS_Shape& theShape1, +bool CompareShapes::operator() (const TopoDS_Shape& theShape1, const TopoDS_Shape& theShape2) { if (!myMap.IsBound(theShape1)) { @@ -287,7 +290,7 @@ bool GEOMUtils::CompareShapes::operator() (const TopoDS_Shape& theShape1, //function : SortShapes //purpose : //======================================================================= -void GEOMUtils::SortShapes (TopTools_ListOfShape& SL, +void SortShapes (TopTools_ListOfShape& SL, const Standard_Boolean isOldSorting) { #ifdef STD_SORT_ALGO @@ -425,7 +428,7 @@ void GEOMUtils::SortShapes (TopTools_ListOfShape& SL, //function : CompsolidToCompound //purpose : //======================================================================= -TopoDS_Shape GEOMUtils::CompsolidToCompound (const TopoDS_Shape& theCompsolid) +TopoDS_Shape CompsolidToCompound (const TopoDS_Shape& theCompsolid) { if (theCompsolid.ShapeType() != TopAbs_COMPSOLID) { return theCompsolid; @@ -452,7 +455,7 @@ TopoDS_Shape GEOMUtils::CompsolidToCompound (const TopoDS_Shape& theCompsolid) //function : AddSimpleShapes //purpose : //======================================================================= -void GEOMUtils::AddSimpleShapes (const TopoDS_Shape& theShape, TopTools_ListOfShape& theList) +void AddSimpleShapes (const TopoDS_Shape& theShape, TopTools_ListOfShape& theList) { if (theShape.ShapeType() != TopAbs_COMPOUND && theShape.ShapeType() != TopAbs_COMPSOLID) { @@ -480,7 +483,7 @@ void GEOMUtils::AddSimpleShapes (const TopoDS_Shape& theShape, TopTools_ListOfSh //function : CheckTriangulation //purpose : //======================================================================= -bool GEOMUtils::CheckTriangulation (const TopoDS_Shape& aShape) +bool CheckTriangulation (const TopoDS_Shape& aShape) { bool isTriangulation = true; @@ -530,7 +533,7 @@ bool GEOMUtils::CheckTriangulation (const TopoDS_Shape& aShape) //function : GetTypeOfSimplePart //purpose : //======================================================================= -TopAbs_ShapeEnum GEOMUtils::GetTypeOfSimplePart (const TopoDS_Shape& theShape) +TopAbs_ShapeEnum GetTypeOfSimplePart (const TopoDS_Shape& theShape) { TopAbs_ShapeEnum aType = theShape.ShapeType(); if (aType == TopAbs_VERTEX) return TopAbs_VERTEX; @@ -551,7 +554,7 @@ TopAbs_ShapeEnum GEOMUtils::GetTypeOfSimplePart (const TopoDS_Shape& theShape) //function : GetEdgeNearPoint //purpose : //======================================================================= -TopoDS_Shape GEOMUtils::GetEdgeNearPoint (const TopoDS_Shape& theShape, +TopoDS_Shape GetEdgeNearPoint (const TopoDS_Shape& theShape, const TopoDS_Vertex& thePoint) { TopoDS_Shape aResult; @@ -619,7 +622,7 @@ TopoDS_Shape GEOMUtils::GetEdgeNearPoint (const TopoDS_Shape& theShape, //function : PreciseBoundingBox //purpose : //======================================================================= -Standard_Boolean GEOMUtils::PreciseBoundingBox +Standard_Boolean PreciseBoundingBox (const TopoDS_Shape &theShape, Bnd_Box &theBox) { Standard_Real aBound[6]; @@ -665,7 +668,7 @@ Standard_Boolean GEOMUtils::PreciseBoundingBox // Get minimal distance between planar face and shape. Standard_Real aMinDist = - GEOMUtils::GetMinDistance(aFace, theShape, aPMin[0], aPMin[1]); + GetMinDistance(aFace, theShape, aPMin[0], aPMin[1]); if (aMinDist < 0.) { return Standard_False; @@ -681,11 +684,128 @@ Standard_Boolean GEOMUtils::PreciseBoundingBox return Standard_True; } +//======================================================================= +// function : ModifyShape +// purpose : This function constructs and returns modified shape +// from the original one for singular cases. +// It is used for the method GetMinDistanceSingular. +// +// \param theShape the original shape +// \param theModifiedShape output parameter. The modified shape. +// \param theAddDist output parameter. The added distance for modified shape. +// \retval true if the shape is modified; false otherwise. +// + +//======================================================================= +Standard_Boolean ModifyShape(const TopoDS_Shape &theShape, + TopoDS_Shape &theModifiedShape, + Standard_Real &theAddDist) +{ + Standard_Boolean isModified = Standard_False; + TopExp_Explorer anExp; + int nbf = 0; + + theAddDist = 0.; + theModifiedShape.Nullify(); + + for ( anExp.Init( theShape, TopAbs_FACE ); anExp.More(); anExp.Next() ) { + nbf++; + theModifiedShape = anExp.Current(); + } + if(nbf==1) { + TopoDS_Shape sh = theShape; + while(sh.ShapeType()==TopAbs_COMPOUND) { + TopoDS_Iterator it(sh); + sh = it.Value(); + } + Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(theModifiedShape)); + if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) || + S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) || + S->IsUPeriodic()) { + const Standard_Boolean isShell = + (sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE); + + if( isShell || S->IsUPeriodic() ) { + // non solid case or any periodic surface (Mantis 22454). + double U1,U2,V1,V2; + // changes for 0020677: EDF 1219 GEOM: MinDistance gives 0 instead of 20.88 + //S->Bounds(U1,U2,V1,V2); changed by + ShapeAnalysis::GetFaceUVBounds(TopoDS::Face(theModifiedShape),U1,U2,V1,V2); + // end of changes for 020677 (dmv) + Handle(Geom_RectangularTrimmedSurface) TrS1 = + new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2); + Handle(Geom_RectangularTrimmedSurface) TrS2 = + new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2); + BRep_Builder B; + TopoDS_Face F1,F2; + TopoDS_Shape aMShape; + + if (isShell) { + B.MakeCompound(TopoDS::Compound(aMShape)); + } else { + B.MakeShell(TopoDS::Shell(aMShape)); + } + + B.MakeFace(F1,TrS1,1.e-7); + B.Add(aMShape,F1); + B.MakeFace(F2,TrS2,1.e-7); + B.Add(aMShape,F2); + Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape; + + if (!isShell) { + // The original shape is a solid. + TopoDS_Solid aSolid; + + B.MakeSolid(aSolid); + B.Add(aSolid, aMShape); + aMShape = aSolid; + } + + sfs->Init(aMShape); + sfs->SetPrecision(1.e-6); + sfs->SetMaxTolerance(1.0); + sfs->Perform(); + theModifiedShape = sfs->Shape(); + isModified = Standard_True; + } + else { + if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) { + Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S); + gp_Pnt PC = SS->Location(); + BRep_Builder B; + TopoDS_Vertex V; + B.MakeVertex(V,PC,1.e-7); + theModifiedShape = V; + theAddDist = SS->Radius(); + isModified = Standard_True; + } + else { + Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S); + gp_Ax3 ax3 = TS->Position(); + Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius()); + BRep_Builder B; + TopoDS_Edge E; + B.MakeEdge(E,C,1.e-7); + theModifiedShape = E; + theAddDist = TS->MinorRadius(); + isModified = Standard_True; + } + } + } else { + theModifiedShape = theShape; + } + } + else + theModifiedShape = theShape; + + return isModified; +} + //======================================================================= //function : GetMinDistanceSingular //purpose : //======================================================================= -double GEOMUtils::GetMinDistanceSingular(const TopoDS_Shape& aSh1, +double GetMinDistanceSingular(const TopoDS_Shape& aSh1, const TopoDS_Shape& aSh2, gp_Pnt& Ptmp1, gp_Pnt& Ptmp2) { @@ -693,8 +813,8 @@ double GEOMUtils::GetMinDistanceSingular(const TopoDS_Shape& aSh1, TopoDS_Shape tmpSh2; Standard_Real AddDist1 = 0.; Standard_Real AddDist2 = 0.; - Standard_Boolean IsChange1 = GEOMUtils::ModifyShape(aSh1, tmpSh1, AddDist1); - Standard_Boolean IsChange2 = GEOMUtils::ModifyShape(aSh2, tmpSh2, AddDist2); + Standard_Boolean IsChange1 = ModifyShape(aSh1, tmpSh1, AddDist1); + Standard_Boolean IsChange2 = ModifyShape(aSh2, tmpSh2, AddDist2); if( !IsChange1 && !IsChange2 ) return -2.0; @@ -754,7 +874,7 @@ double GEOMUtils::GetMinDistanceSingular(const TopoDS_Shape& aSh1, //function : GetMinDistance //purpose : //======================================================================= -Standard_Real GEOMUtils::GetMinDistance +Standard_Real GetMinDistance (const TopoDS_Shape& theShape1, const TopoDS_Shape& theShape2, gp_Pnt& thePnt1, gp_Pnt& thePnt2) @@ -790,7 +910,7 @@ Standard_Real GEOMUtils::GetMinDistance // skl 30.06.2008 // additional workaround for bugs 19899, 19908 and 19910 from Mantis - double dist = GEOMUtils::GetMinDistanceSingular + double dist = GetMinDistanceSingular (theShape1, theShape2, thePnt1, thePnt2); if (dist > -1.0) { @@ -821,7 +941,7 @@ Standard_Real GEOMUtils::GetMinDistance // function : ConvertClickToPoint() // purpose : Returns the point clicked in 3D view //======================================================================= -gp_Pnt GEOMUtils::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView ) +gp_Pnt ConvertClickToPoint( int x, int y, Handle(V3d_View) aView ) { V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt; aView->Eye( XEye, YEye, ZEye ); @@ -844,109 +964,133 @@ gp_Pnt GEOMUtils::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView ) } //======================================================================= -// function : ModifyShape -// purpose : +// function : ConvertTreeToString() +// purpose : Returns the string representation of dependency tree //======================================================================= -Standard_Boolean GEOMUtils::ModifyShape(const TopoDS_Shape &theShape, - TopoDS_Shape &theModifiedShape, - Standard_Real &theAddDist) +void ConvertTreeToString( const TreeModel &tree, + std::string &treeStr ) { - Standard_Boolean isModified = Standard_False; - TopExp_Explorer anExp; - int nbf = 0; - - theAddDist = 0.; - theModifiedShape.Nullify(); + TreeModel::const_iterator i; + for ( i = tree.begin(); i != tree.end(); ++i ) { + treeStr.append( i->first ); + treeStr.append( "-" ); + std::vector upLevelList = i->second.first; + treeStr.append( "upward" ); + treeStr.append( "{" ); + for( std::vector::iterator j = upLevelList.begin(); + j != upLevelList.end(); ++j ) { + LevelInfo level = (*j); + LevelInfo::iterator upIter; + for ( upIter = level.begin(); upIter != level.end(); ++upIter ) { + treeStr.append( upIter->first ); + for ( std::vector::iterator k = upIter->second.begin(); + k != upIter->second.end(); ++k ) { + treeStr.append( "_" ); + treeStr.append( *k ); + } + treeStr.append( upIter++ == level.end() ? ";" : "," ); + upIter--; + } + } + treeStr.append( "}" ); + std::vector downLevelList = i->second.second; + treeStr.append( "downward" ); + treeStr.append( "{" ); + for( std::vector::iterator j = downLevelList.begin(); + j != downLevelList.end(); ++j ) { + LevelInfo level = (*j); + LevelInfo::iterator downIter; + for ( downIter = level.begin(); downIter != level.end(); ++downIter ) { + treeStr.append( downIter->first ); + for ( std::vector::iterator k = downIter->second.begin(); + k != downIter->second.end(); ++k ) { + treeStr.append( "_" ); + treeStr.append( *k ); + } + treeStr.append( downIter++ == level.end() ? ";" : "," ); + downIter--; + } + } + treeStr.append("}"); + } +} - for ( anExp.Init( theShape, TopAbs_FACE ); anExp.More(); anExp.Next() ) { - nbf++; - theModifiedShape = anExp.Current(); +LevelsList parseWard( const std::string& theData, std::size_t& theCursor ) +{ + std::size_t indexStart = theData.find( "{", theCursor ) + 1; + std::size_t indexEnd = theData.find( "}", indexStart ); + + std::string ward = theData.substr( indexStart, indexEnd - indexStart ); + std::stringstream ss(ward); + std::string substr; + std::vector levelsListStr; + while ( std::getline( ss, substr, ';' ) ) { + if ( !substr.empty() ) + levelsListStr.push_back( substr ); } - if(nbf==1) { - TopoDS_Shape sh = theShape; - while(sh.ShapeType()==TopAbs_COMPOUND) { - TopoDS_Iterator it(sh); - sh = it.Value(); + LevelsList levelsListData; + for( int level = 0; level < levelsListStr.size(); level++ ) { + std::cout<<" Level" << level + 1 << ":" << std::endl; + std::vector namesListStr; + ss.str( levelsListStr[level] ); + while ( std::getline( ss, substr, ',' ) ) { + if ( !substr.empty() ) + namesListStr.push_back( substr ); } - Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(theModifiedShape)); - if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) || - S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) || - S->IsUPeriodic()) { - const Standard_Boolean isShell = - (sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE); + LevelInfo levelInfoData; + for( int node = 0; node < namesListStr.size(); node++ ) { + std::vector linksListStr; + ss.str( namesListStr[node] ); + while ( std::getline( ss, substr, '_' ) ) { + if ( !substr.empty() ) + linksListStr.push_back( substr ); + } + std::string nodeItem = linksListStr[0]; + if( !nodeItem.empty() ) { + NodeLinks linksListData; + std::cout<<" " << nodeItem << " - "; + for( int link = 1; link < linksListStr.size(); link++ ) { + std::string linkItem = linksListStr[link]; + linksListData.push_back( linkItem ); + std::cout << linkItem << ", "; + }// Links + levelInfoData[nodeItem] = linksListData; + std::cout << std::endl; + } + }// Level's objects + levelsListData.push_back(levelInfoData); + }// Levels - if( isShell || S->IsUPeriodic() ) { - // non solid case or any periodic surface (Mantis 22454). - double U1,U2,V1,V2; - // changes for 0020677: EDF 1219 GEOM: MinDistance gives 0 instead of 20.88 - //S->Bounds(U1,U2,V1,V2); changed by - ShapeAnalysis::GetFaceUVBounds(TopoDS::Face(theModifiedShape),U1,U2,V1,V2); - // end of changes for 020677 (dmv) - Handle(Geom_RectangularTrimmedSurface) TrS1 = - new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2); - Handle(Geom_RectangularTrimmedSurface) TrS2 = - new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2); - BRep_Builder B; - TopoDS_Face F1,F2; - TopoDS_Shape aMShape; + theCursor = indexEnd + 1; + return levelsListData; +} - if (isShell) { - B.MakeCompound(TopoDS::Compound(aMShape)); - } else { - B.MakeShell(TopoDS::Shell(aMShape)); - } +//======================================================================= +// function : ConvertStringToTree() +// purpose : Returns the dependency tree +//======================================================================= +void ConvertStringToTree( const std::string &theData, + TreeModel &tree ) +{ + std::size_t cursor = 0; - B.MakeFace(F1,TrS1,1.e-7); - B.Add(aMShape,F1); - B.MakeFace(F2,TrS2,1.e-7); - B.Add(aMShape,F2); - Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape; + while( theData.find('-',cursor) != std::string::npos ) //find next selected object + { + std::size_t objectIndex = theData.find( '-', cursor ); + std::string objectEntry = theData.substr( cursor, objectIndex - cursor ); + std::cout<<"\n\nMainObject = " << objectEntry <Init(aMShape); - sfs->SetPrecision(1.e-6); - sfs->SetMaxTolerance(1.0); - sfs->Perform(); - theModifiedShape = sfs->Shape(); - isModified = Standard_True; - } - else { - if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) { - Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S); - gp_Pnt PC = SS->Location(); - BRep_Builder B; - TopoDS_Vertex V; - B.MakeVertex(V,PC,1.e-7); - theModifiedShape = V; - theAddDist = SS->Radius(); - isModified = Standard_True; - } - else { - Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S); - gp_Ax3 ax3 = TS->Position(); - Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius()); - BRep_Builder B; - TopoDS_Edge E; - B.MakeEdge(E,C,1.e-7); - theModifiedShape = E; - theAddDist = TS->MinorRadius(); - isModified = Standard_True; - } - } - } else { - theModifiedShape = theShape; - } + tree[objectEntry] = std::pair( upwardList, downwardList ); } - else - theModifiedShape = theShape; - - return isModified; } + +} //namespace GEOMUtils diff --git a/src/GEOMUtils/GEOMUtils.hxx b/src/GEOMUtils/GEOMUtils.hxx index bbf8a7dbe..b35495b62 100644 --- a/src/GEOMUtils/GEOMUtils.hxx +++ b/src/GEOMUtils/GEOMUtils.hxx @@ -40,6 +40,11 @@ #include +#include +#include +#include +#include + class Bnd_Box; inline Standard_Boolean IsEqual (const TopoDS_Shape& S1, const TopoDS_Shape& S2) @@ -47,9 +52,13 @@ inline Standard_Boolean IsEqual (const TopoDS_Shape& S1, const TopoDS_Shape& S2) return S1.IsSame(S2); } -class GEOMUtils { +namespace GEOMUtils { + + typedef std::vector NodeLinks; + typedef std::map LevelInfo; + typedef std::vector LevelsList; + typedef std::map > TreeModel; - public: /*! * \brief Get Local Coordinate System, corresponding to the given shape. * @@ -57,7 +66,7 @@ class GEOMUtils { * Axes of the LCS are obtained from shape's location or, * if the shape is a planar face, from position of its plane. */ - Standard_EXPORT static gp_Ax3 GetPosition (const TopoDS_Shape& theShape); + Standard_EXPORT gp_Ax3 GetPosition (const TopoDS_Shape& theShape); /*! * \brief Get vector, defined by the given edge. @@ -67,7 +76,7 @@ class GEOMUtils { * the same edge can have different orientation depending on the way it was * extracted from a shape. */ - Standard_EXPORT static gp_Vec GetVector (const TopoDS_Shape& theShape, + Standard_EXPORT gp_Vec GetVector (const TopoDS_Shape& theShape, Standard_Boolean doConsiderOrientation); /*! @@ -89,7 +98,7 @@ class GEOMUtils { /*! * \brief Sort shapes by their centers of mass, using formula X*999 + Y*99 + Z*0.9 */ - Standard_EXPORT static void SortShapes (TopTools_ListOfShape& SL, + Standard_EXPORT void SortShapes (TopTools_ListOfShape& SL, const Standard_Boolean isOldSorting = Standard_True); /*! @@ -100,7 +109,7 @@ class GEOMUtils { * \param theCompsolid The compsolid to be converted. * \retval TopoDS_Shape Returns the resulting compound. */ - Standard_EXPORT static TopoDS_Shape CompsolidToCompound (const TopoDS_Shape& theCompsolid); + Standard_EXPORT TopoDS_Shape CompsolidToCompound (const TopoDS_Shape& theCompsolid); /*! * \brief Recursively extract all shapes from compounds and compsolids of the given shape into theList. @@ -110,7 +119,7 @@ class GEOMUtils { * \param theShape The shape to be exploded. * \param theList Output parameter. */ - Standard_EXPORT static void AddSimpleShapes (const TopoDS_Shape& theShape, + Standard_EXPORT void AddSimpleShapes (const TopoDS_Shape& theShape, TopTools_ListOfShape& theList); /*! @@ -118,14 +127,14 @@ class GEOMUtils { * \param theShape The shape to check/build triangulation on. * \retval bool Returns false if the shape has no faces, i.e. impossible to build triangulation. */ - Standard_EXPORT static bool CheckTriangulation (const TopoDS_Shape& theShape); + Standard_EXPORT bool CheckTriangulation (const TopoDS_Shape& theShape); /*! * \brief Return type of shape for explode. In case of compound it will be a type of its first sub shape. * \param theShape The shape to get type of. * \retval TopAbs_ShapeEnum Return type of shape for explode. */ - Standard_EXPORT static TopAbs_ShapeEnum GetTypeOfSimplePart (const TopoDS_Shape& theShape); + Standard_EXPORT TopAbs_ShapeEnum GetTypeOfSimplePart (const TopoDS_Shape& theShape); /*! * \brief Find an edge of theShape, closest to thePoint. @@ -134,7 +143,7 @@ class GEOMUtils { * \param thePoint The point near the required edge. * \retval TopoDS_Shape Returns the found edge or an empty shape if multiple edges found. */ - Standard_EXPORT static TopoDS_Shape GetEdgeNearPoint (const TopoDS_Shape& theShape, + Standard_EXPORT TopoDS_Shape GetEdgeNearPoint (const TopoDS_Shape& theShape, const TopoDS_Vertex& thePoint); /*! @@ -144,7 +153,7 @@ class GEOMUtils { * \param theBox rough bounding box on input; precise bounding box on output. * \retval Standard_True in case of success; Standard_False otherwise. */ - Standard_EXPORT static Standard_Boolean PreciseBoundingBox + Standard_EXPORT Standard_Boolean PreciseBoundingBox (const TopoDS_Shape &theShape, Bnd_Box &theBox); /*! @@ -157,7 +166,7 @@ class GEOMUtils { * \param Ptmp2 the output result point on the second shape * \retval negative value if it is not a singular case; actual distance for singular case. */ - Standard_EXPORT static Standard_Real GetMinDistanceSingular + Standard_EXPORT Standard_Real GetMinDistanceSingular (const TopoDS_Shape& aSh1, const TopoDS_Shape& aSh2, gp_Pnt& Ptmp1, gp_Pnt& Ptmp2); @@ -171,7 +180,7 @@ class GEOMUtils { * \param thePnt2 the output result point on the second shape * \retval negative value in case of failure; otherwise the real distance. */ - Standard_EXPORT static Standard_Real GetMinDistance + Standard_EXPORT Standard_Real GetMinDistance (const TopoDS_Shape& theShape1, const TopoDS_Shape& theShape2, gp_Pnt& thePnt1, gp_Pnt& thePnt2); @@ -184,23 +193,13 @@ class GEOMUtils { * \param theView View where the given point takes place. * \retval gp_Pnt Returns the point clicked in 3D view */ - Standard_EXPORT static gp_Pnt ConvertClickToPoint( int x, int y, Handle(V3d_View) theView ); - -private: + Standard_EXPORT gp_Pnt ConvertClickToPoint( int x, int y, Handle(V3d_View) theView ); - /** - * This function constructs and returns modified shape from the original one - * for singular cases. It is used for the method GetMinDistanceSingular. - * - * \param theShape the original shape - * \param theModifiedShape output parameter. The modified shape. - * \param theAddDist output parameter. The added distance for modified shape. - * \retval true if the shape is modified; false otherwise. - */ - static Standard_Boolean ModifyShape(const TopoDS_Shape &theShape, - TopoDS_Shape &theModifiedShape, - Standard_Real &theAddDist); + Standard_EXPORT void ConvertTreeToString( const TreeModel &theTree, + std::string &DependencyStr ); + Standard_EXPORT void ConvertStringToTree( const std::string &theDependencyStr, + TreeModel &tree ); }; diff --git a/src/GEOM_I/CMakeLists.txt b/src/GEOM_I/CMakeLists.txt index fb2a677a7..ca49d2aca 100755 --- a/src/GEOM_I/CMakeLists.txt +++ b/src/GEOM_I/CMakeLists.txt @@ -28,6 +28,7 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/GEOMImpl ${PROJECT_SOURCE_DIR}/src/GEOM ${PROJECT_SOURCE_DIR}/src/GEOMAlgo + ${PROJECT_SOURCE_DIR}/src/GEOMUtils ${PROJECT_SOURCE_DIR}/src/XAO ${PROJECT_BINARY_DIR}/idl ${CMAKE_CURRENT_SOURCE_DIR} diff --git a/src/GEOM_I/GEOM_Gen_i.cc b/src/GEOM_I/GEOM_Gen_i.cc index 8ef75a6f0..eca0f4336 100755 --- a/src/GEOM_I/GEOM_Gen_i.cc +++ b/src/GEOM_I/GEOM_Gen_i.cc @@ -3043,8 +3043,107 @@ Engines::ListOfData* GEOM_Gen_i::getModifiedData(CORBA::Long studyId) // function : // purpose : //======================================================================= -SALOMEDS::TMPFile* GEOM_Gen_i::GetDependencyTree(const GEOM::string_array&) { +SALOMEDS::TMPFile* GEOM_Gen_i::GetDependencyTree( SALOMEDS::Study_ptr theStudy, + const GEOM::string_array& theObjectIORs ) { + // fill in the tree structure + GEOMUtils::TreeModel tree; + + // foreach( QString ior, theObjectIORs ) { + std::string ior; + for ( int i = 0; i < theObjectIORs.length(); i++ ) { + ior = theObjectIORs[i].in(); + GEOM::GEOM_Object_ptr anObj = GetIORFromString( ior.c_str() ); + GEOMUtils::LevelsList upLevelList; + getUpwardDependency( anObj, upLevelList ); + GEOMUtils::LevelsList downLevelList; + getDownwardDependency( theStudy, anObj, downLevelList ); + tree.insert( std::pair >(ior, std::pair( upLevelList, downLevelList ) ) ); + } + + // translation the tree into string + std::string treeStr; + GEOMUtils::ConvertTreeToString( tree, treeStr ); + + char* aBuffer = (char*)CORBA::string_dup(treeStr.c_str()); + int aBufferSize = strlen((char*)aBuffer); + + CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer; + + SALOMEDS::TMPFile_var aStream = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1); + + return aStream._retn(); +} + +//======================================================================= +// function : +// purpose : +//======================================================================= +void GEOM_Gen_i::getUpwardDependency( GEOM::GEOM_BaseObject_ptr gbo, + GEOMUtils::LevelsList &upLevelList, + int level ) { + std::string aGboIOR = GetStringFromIOR(GEOM::GEOM_Object::_narrow(gbo)); + GEOM::ListOfGBO_var depList = gbo->GetDependency(); + for( int j = 0; j < depList->length(); j++ ) { + if ( level > 0 ) { + GEOMUtils::NodeLinks anIORs; + GEOMUtils::LevelInfo aLevelMap; + if ( level-1 >= upLevelList.size() ) { + upLevelList.push_back( aLevelMap ); + } else { + aLevelMap = upLevelList.at(level-1); + if ( aLevelMap.count( aGboIOR ) > 0 ) + anIORs = aLevelMap[ aGboIOR ]; + } + anIORs.push_back( GetStringFromIOR(GEOM::GEOM_Object::_narrow(depList[j])) ); + aLevelMap.insert( std::pair(aGboIOR, anIORs) ); + } + getUpwardDependency(depList[j], upLevelList, level++); + } +} +//======================================================================= +// function : +// purpose : +//======================================================================= +void GEOM_Gen_i::getDownwardDependency( SALOMEDS::Study_ptr theStudy, + GEOM::GEOM_BaseObject_ptr gbo, + GEOMUtils::LevelsList &downLevelList, + int level ) { + SALOMEDS::SComponent_var comp = theStudy->FindComponent("GEOM"); + if ( !comp ) + return; + + SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator( comp ); + for ( it->InitEx( true ); it->More(); it->Next() ) { + SALOMEDS::SObject_var child = it->Value(); + CORBA::Object_var corbaObj = child->GetObject(); + GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj ); + if( CORBA::is_nil( geomObj ) ) + continue; + + GEOM::ListOfGBO_var depList = geomObj->GetDependency(); + if( depList->length() == 0 ) + continue; + std::string aGoIOR = GetStringFromIOR( geomObj ); + + for( int i = 0; i < depList->length(); i++ ) { + if ( depList[i]->IsSame( gbo ) ) { + GEOMUtils::NodeLinks anIORs; + GEOMUtils::LevelInfo aLevelMap; + if ( level >= downLevelList.size() ) { + aLevelMap = GEOMUtils::LevelInfo(); + downLevelList.push_back( aLevelMap ); + } else { + aLevelMap = downLevelList.at(level); + if ( aLevelMap.count( aGoIOR ) > 0 ) + anIORs = aLevelMap[ aGoIOR ]; + } + anIORs.push_back( GetStringFromIOR(GEOM::GEOM_Object::_narrow(depList[i]))); + aLevelMap.insert( std::pair(aGoIOR, anIORs) ); + } + } + getDownwardDependency(theStudy, geomObj, downLevelList, level++); + } } //===================================================================================== diff --git a/src/GEOM_I/GEOM_Gen_i.hh b/src/GEOM_I/GEOM_Gen_i.hh index 0a4f42b8f..429e4e2f5 100644 --- a/src/GEOM_I/GEOM_Gen_i.hh +++ b/src/GEOM_I/GEOM_Gen_i.hh @@ -51,11 +51,13 @@ #include "GEOM_IMeasureOperations_i.hh" #include "GEOM_IGroupOperations_i.hh" #include "GEOM_IFieldOperations_i.hh" +#include "GEOMUtils.hxx" #include #include #include +#include #include //#include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC @@ -197,7 +199,8 @@ class GEOM_I_EXPORT GEOM_Gen_i: virtual public POA_GEOM::GEOM_Gen, virtual publi CORBA::Boolean theInheritFirstArg, CORBA::Boolean theAddPrefix); - SALOMEDS::TMPFile* GetDependencyTree(const GEOM::string_array&); + SALOMEDS::TMPFile* GetDependencyTree(SALOMEDS::Study_ptr theStudy, + const GEOM::string_array& theObjectIORs); //-----------------------------------------------------------------------// // Transaction methods // @@ -368,6 +371,15 @@ class GEOM_I_EXPORT GEOM_Gen_i: virtual public POA_GEOM::GEOM_Gen, virtual publi const Standard_CString& GrName, GEOM::ListOfGO_var aResList); + void getUpwardDependency( GEOM::GEOM_BaseObject_ptr gbo, + GEOMUtils::LevelsList &upLevelList, + int level = 0 ); + + void getDownwardDependency( SALOMEDS::Study_ptr theStudy, + GEOM::GEOM_BaseObject_ptr gbo, + GEOMUtils::LevelsList &downLevelList, + int level = 0 ); + private: ::GEOMImpl_Gen* _impl; -- 2.39.2