#include <GeometryGUI.h>
#include "GeometryGUI_Operations.h"
+#include <GEOMBase.h>
#include <GEOM_Operation.h>
#include <GEOM_Displayer.h>
}
}
-//=======================================================================
-// 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<NodeLevel> upLevelList;
- getUpwardDependency( anObj, upLevelList );
- QList<NodeLevel> downLevelList;
- getDownwardDependency( anObj, downLevelList );
- tree.insert( ior, QPair<QList<NodeLevel>, QList<NodeLevel> >( 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<NodeLevel> 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<NodeLevel> 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<NodeLevel> &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<NodeLevel> &downLevelList,
- int level )
-{
- SalomeApp_Application* app =
- dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
- if ( !app )
- return;
-
- SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( 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
//=====================================================================================
#include <ElSLib.hxx>
#include <vector>
+#include <sstream>
#include <Standard_Failure.hxx>
#include <Standard_NullObject.hxx>
#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;
//function : GetVector
//purpose :
//=======================================================================
-gp_Vec GEOMUtils::GetVector (const TopoDS_Shape& theShape,
+gp_Vec GetVector (const TopoDS_Shape& theShape,
Standard_Boolean doConsiderOrientation)
{
if (theShape.IsNull())
//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)) {
//function : SortShapes
//purpose :
//=======================================================================
-void GEOMUtils::SortShapes (TopTools_ListOfShape& SL,
+void SortShapes (TopTools_ListOfShape& SL,
const Standard_Boolean isOldSorting)
{
#ifdef STD_SORT_ALGO
//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;
//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) {
//function : CheckTriangulation
//purpose :
//=======================================================================
-bool GEOMUtils::CheckTriangulation (const TopoDS_Shape& aShape)
+bool CheckTriangulation (const TopoDS_Shape& aShape)
{
bool isTriangulation = true;
//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;
//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;
//function : PreciseBoundingBox
//purpose :
//=======================================================================
-Standard_Boolean GEOMUtils::PreciseBoundingBox
+Standard_Boolean PreciseBoundingBox
(const TopoDS_Shape &theShape, Bnd_Box &theBox)
{
Standard_Real aBound[6];
// 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;
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)
{
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;
//function : GetMinDistance
//purpose :
//=======================================================================
-Standard_Real GEOMUtils::GetMinDistance
+Standard_Real GetMinDistance
(const TopoDS_Shape& theShape1,
const TopoDS_Shape& theShape2,
gp_Pnt& thePnt1, gp_Pnt& thePnt2)
// 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) {
// 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 );
}
//=======================================================================
-// 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<LevelInfo> upLevelList = i->second.first;
+ treeStr.append( "upward" );
+ treeStr.append( "{" );
+ for( std::vector<LevelInfo>::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<std::string>::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<LevelInfo> downLevelList = i->second.second;
+ treeStr.append( "downward" );
+ treeStr.append( "{" );
+ for( std::vector<LevelInfo>::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<std::string>::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<std::string> 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<std::string> 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<std::string> 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 <<std::endl;
+ cursor = objectIndex;
- if (!isShell) {
- // The original shape is a solid.
- TopoDS_Solid aSolid;
+ std::size_t upwardIndexBegin = theData.find("{",cursor) + 1;
+ std::size_t upwardIndexFinish = theData.find("}",upwardIndexBegin);
+ std::cout<<" Upward:" << std::endl ;
+ LevelsList upwardList = parseWard( theData, cursor );
- B.MakeSolid(aSolid);
- B.Add(aSolid, aMShape);
- aMShape = aSolid;
- }
+ std::cout<<" Downward:" << std::endl;
+ LevelsList downwardList = parseWard( theData, cursor );
- 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;
- }
+ tree[objectEntry] = std::pair<LevelsList,LevelsList>( upwardList, downwardList );
}
- else
- theModifiedShape = theShape;
-
- return isModified;
}
+
+} //namespace GEOMUtils
#include <functional>
+#include <map>
+#include <vector>
+#include <string>
+#include <utility>
+
class Bnd_Box;
inline Standard_Boolean IsEqual (const TopoDS_Shape& S1, const TopoDS_Shape& S2)
return S1.IsSame(S2);
}
-class GEOMUtils {
+namespace GEOMUtils {
+
+ typedef std::vector<std::string> NodeLinks;
+ typedef std::map<std::string, NodeLinks> LevelInfo;
+ typedef std::vector<LevelInfo> LevelsList;
+ typedef std::map<std::string,std::pair<LevelsList,LevelsList> > TreeModel;
- public:
/*!
* \brief Get Local Coordinate System, corresponding to the given shape.
*
* 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.
* 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);
/*!
/*!
* \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);
/*!
* \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.
* \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);
/*!
* \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.
* \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);
/*!
* \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);
/*!
* \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);
* \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);
* \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 );
};
// 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<std::string, std::pair<GEOMUtils::LevelsList,GEOMUtils::LevelsList> >(ior, std::pair<GEOMUtils::LevelsList,GEOMUtils::LevelsList>( 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<std::string, GEOMUtils::NodeLinks>(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<std::string, GEOMUtils::NodeLinks>(aGoIOR, anIORs) );
+ }
+ }
+ getDownwardDependency(theStudy, geomObj, downLevelList, level++);
+ }
}
//=====================================================================================