Algorithm of dependencies definition was updated and replaced. Auxiliry convertation functions were added.

This commit is contained in:
akl 2014-05-21 13:24:03 +04:00
parent 6f0049749d
commit fa14a07690
8 changed files with 464 additions and 361 deletions

View File

@ -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);
};
};

View File

@ -29,6 +29,7 @@
#include <GeometryGUI.h>
#include "GeometryGUI_Operations.h"
#include <GEOMBase.h>
#include <GEOM_Operation.h>
#include <GEOM_Displayer.h>
@ -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<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
//=====================================================================================

View File

@ -30,7 +30,6 @@
#include "GEOM_ToolsGUI.hxx"
#include <GEOMGUI.h>
#include <GEOMBase.h>
#include <SALOMEDSClient.hxx>
class GEOM_Displayer;
@ -43,11 +42,6 @@ class Handle_SALOME_InteractiveObject;
class Handle_AIS_InteractiveContext;
#include <QList>
#include <QMap>
#include <QPair>
typedef QMap< QString, QStringList > NodeLevel;
typedef QMap< QString, QPair<QList<NodeLevel>, QList<NodeLevel> > > 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<NodeLevel> &upLevelList,
int level = 0 );
void getDownwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
QList<NodeLevel> &downLevelList,
int level = 0 );
private:
// Import and export topology methods
bool Import();

View File

@ -87,6 +87,7 @@
#include <ElSLib.hxx>
#include <vector>
#include <sstream>
#include <Standard_Failure.hxx>
#include <Standard_NullObject.hxx>
@ -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<double, double> 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,173 +684,20 @@ Standard_Boolean GEOMUtils::PreciseBoundingBox
return Standard_True;
}
//=======================================================================
//function : GetMinDistanceSingular
//purpose :
//=======================================================================
double GEOMUtils::GetMinDistanceSingular(const TopoDS_Shape& aSh1,
const TopoDS_Shape& aSh2,
gp_Pnt& Ptmp1, gp_Pnt& Ptmp2)
{
TopoDS_Shape tmpSh1;
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);
if( !IsChange1 && !IsChange2 )
return -2.0;
BRepExtrema_DistShapeShape dst(tmpSh1,tmpSh2);
if (dst.IsDone()) {
double MinDist = 1.e9;
gp_Pnt PMin1, PMin2, P1, P2;
for (int i = 1; i <= dst.NbSolution(); i++) {
P1 = dst.PointOnShape1(i);
P2 = dst.PointOnShape2(i);
Standard_Real Dist = P1.Distance(P2);
if (MinDist > Dist) {
MinDist = Dist;
PMin1 = P1;
PMin2 = P2;
}
}
if(MinDist<1.e-7) {
Ptmp1 = PMin1;
Ptmp2 = PMin2;
}
else {
gp_Dir aDir(gp_Vec(PMin1,PMin2));
if( MinDist > (AddDist1+AddDist2) ) {
Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
PMin1.Y() + aDir.Y()*AddDist1,
PMin1.Z() + aDir.Z()*AddDist1 );
Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
PMin2.Y() - aDir.Y()*AddDist2,
PMin2.Z() - aDir.Z()*AddDist2 );
return (MinDist - AddDist1 - AddDist2);
}
else {
if( AddDist1 > 0 ) {
Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
PMin1.Y() + aDir.Y()*AddDist1,
PMin1.Z() + aDir.Z()*AddDist1 );
Ptmp2 = Ptmp1;
}
else {
Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
PMin2.Y() - aDir.Y()*AddDist2,
PMin2.Z() - aDir.Z()*AddDist2 );
Ptmp1 = Ptmp2;
}
}
}
double res = MinDist - AddDist1 - AddDist2;
if(res<0.) res = 0.0;
return res;
}
return -2.0;
}
//=======================================================================
//function : GetMinDistance
//purpose :
//=======================================================================
Standard_Real GEOMUtils::GetMinDistance
(const TopoDS_Shape& theShape1,
const TopoDS_Shape& theShape2,
gp_Pnt& thePnt1, gp_Pnt& thePnt2)
{
Standard_Real aResult = 1.e9;
// Issue 0020231: A min distance bug with torus and vertex.
// Make GetMinDistance() return zero if a sole VERTEX is inside any of SOLIDs
// which of shapes consists of only one vertex?
TopExp_Explorer exp1(theShape1,TopAbs_VERTEX), exp2(theShape2,TopAbs_VERTEX);
TopoDS_Shape V1 = exp1.More() ? exp1.Current() : TopoDS_Shape();
TopoDS_Shape V2 = exp2.More() ? exp2.Current() : TopoDS_Shape();
exp1.Next(); exp2.Next();
if ( exp1.More() ) V1.Nullify();
if ( exp2.More() ) V2.Nullify();
// vertex and container of solids
TopoDS_Shape V = V1.IsNull() ? V2 : V1;
TopoDS_Shape S = V1.IsNull() ? theShape1 : theShape2;
if ( !V.IsNull() ) {
// classify vertex against solids
gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( V ) );
for ( exp1.Init( S, TopAbs_SOLID ); exp1.More(); exp1.Next() ) {
BRepClass3d_SolidClassifier classifier( exp1.Current(), p, 1e-6);
if ( classifier.State() == TopAbs_IN ) {
thePnt1 = p;
thePnt2 = p;
return 0.0;
}
}
}
// End Issue 0020231
// skl 30.06.2008
// additional workaround for bugs 19899, 19908 and 19910 from Mantis
double dist = GEOMUtils::GetMinDistanceSingular
(theShape1, theShape2, thePnt1, thePnt2);
if (dist > -1.0) {
return dist;
}
BRepExtrema_DistShapeShape dst (theShape1, theShape2);
if (dst.IsDone()) {
gp_Pnt P1, P2;
for (int i = 1; i <= dst.NbSolution(); i++) {
P1 = dst.PointOnShape1(i);
P2 = dst.PointOnShape2(i);
Standard_Real Dist = P1.Distance(P2);
if (aResult > Dist) {
aResult = Dist;
thePnt1 = P1;
thePnt2 = P2;
}
}
}
return aResult;
}
//=======================================================================
// function : ConvertClickToPoint()
// purpose : Returns the point clicked in 3D view
//=======================================================================
gp_Pnt GEOMUtils::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView )
{
V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
aView->Eye( XEye, YEye, ZEye );
aView->At( XAt, YAt, ZAt );
gp_Pnt EyePoint( XEye, YEye, ZEye );
gp_Pnt AtPoint( XAt, YAt, ZAt );
gp_Vec EyeVector( EyePoint, AtPoint );
gp_Dir EyeDir( EyeVector );
gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir );
Standard_Real X, Y, Z;
aView->Convert( x, y, X, Y, Z );
gp_Pnt ConvertedPoint( X, Y, Z );
gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint );
gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView );
return ResultPoint;
}
//=======================================================================
// function : ModifyShape
// purpose :
// 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 GEOMUtils::ModifyShape(const TopoDS_Shape &theShape,
Standard_Boolean ModifyShape(const TopoDS_Shape &theShape,
TopoDS_Shape &theModifiedShape,
Standard_Real &theAddDist)
{
@ -950,3 +800,297 @@ Standard_Boolean GEOMUtils::ModifyShape(const TopoDS_Shape &theShape,
return isModified;
}
//=======================================================================
//function : GetMinDistanceSingular
//purpose :
//=======================================================================
double GetMinDistanceSingular(const TopoDS_Shape& aSh1,
const TopoDS_Shape& aSh2,
gp_Pnt& Ptmp1, gp_Pnt& Ptmp2)
{
TopoDS_Shape tmpSh1;
TopoDS_Shape tmpSh2;
Standard_Real AddDist1 = 0.;
Standard_Real AddDist2 = 0.;
Standard_Boolean IsChange1 = ModifyShape(aSh1, tmpSh1, AddDist1);
Standard_Boolean IsChange2 = ModifyShape(aSh2, tmpSh2, AddDist2);
if( !IsChange1 && !IsChange2 )
return -2.0;
BRepExtrema_DistShapeShape dst(tmpSh1,tmpSh2);
if (dst.IsDone()) {
double MinDist = 1.e9;
gp_Pnt PMin1, PMin2, P1, P2;
for (int i = 1; i <= dst.NbSolution(); i++) {
P1 = dst.PointOnShape1(i);
P2 = dst.PointOnShape2(i);
Standard_Real Dist = P1.Distance(P2);
if (MinDist > Dist) {
MinDist = Dist;
PMin1 = P1;
PMin2 = P2;
}
}
if(MinDist<1.e-7) {
Ptmp1 = PMin1;
Ptmp2 = PMin2;
}
else {
gp_Dir aDir(gp_Vec(PMin1,PMin2));
if( MinDist > (AddDist1+AddDist2) ) {
Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
PMin1.Y() + aDir.Y()*AddDist1,
PMin1.Z() + aDir.Z()*AddDist1 );
Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
PMin2.Y() - aDir.Y()*AddDist2,
PMin2.Z() - aDir.Z()*AddDist2 );
return (MinDist - AddDist1 - AddDist2);
}
else {
if( AddDist1 > 0 ) {
Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
PMin1.Y() + aDir.Y()*AddDist1,
PMin1.Z() + aDir.Z()*AddDist1 );
Ptmp2 = Ptmp1;
}
else {
Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
PMin2.Y() - aDir.Y()*AddDist2,
PMin2.Z() - aDir.Z()*AddDist2 );
Ptmp1 = Ptmp2;
}
}
}
double res = MinDist - AddDist1 - AddDist2;
if(res<0.) res = 0.0;
return res;
}
return -2.0;
}
//=======================================================================
//function : GetMinDistance
//purpose :
//=======================================================================
Standard_Real GetMinDistance
(const TopoDS_Shape& theShape1,
const TopoDS_Shape& theShape2,
gp_Pnt& thePnt1, gp_Pnt& thePnt2)
{
Standard_Real aResult = 1.e9;
// Issue 0020231: A min distance bug with torus and vertex.
// Make GetMinDistance() return zero if a sole VERTEX is inside any of SOLIDs
// which of shapes consists of only one vertex?
TopExp_Explorer exp1(theShape1,TopAbs_VERTEX), exp2(theShape2,TopAbs_VERTEX);
TopoDS_Shape V1 = exp1.More() ? exp1.Current() : TopoDS_Shape();
TopoDS_Shape V2 = exp2.More() ? exp2.Current() : TopoDS_Shape();
exp1.Next(); exp2.Next();
if ( exp1.More() ) V1.Nullify();
if ( exp2.More() ) V2.Nullify();
// vertex and container of solids
TopoDS_Shape V = V1.IsNull() ? V2 : V1;
TopoDS_Shape S = V1.IsNull() ? theShape1 : theShape2;
if ( !V.IsNull() ) {
// classify vertex against solids
gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( V ) );
for ( exp1.Init( S, TopAbs_SOLID ); exp1.More(); exp1.Next() ) {
BRepClass3d_SolidClassifier classifier( exp1.Current(), p, 1e-6);
if ( classifier.State() == TopAbs_IN ) {
thePnt1 = p;
thePnt2 = p;
return 0.0;
}
}
}
// End Issue 0020231
// skl 30.06.2008
// additional workaround for bugs 19899, 19908 and 19910 from Mantis
double dist = GetMinDistanceSingular
(theShape1, theShape2, thePnt1, thePnt2);
if (dist > -1.0) {
return dist;
}
BRepExtrema_DistShapeShape dst (theShape1, theShape2);
if (dst.IsDone()) {
gp_Pnt P1, P2;
for (int i = 1; i <= dst.NbSolution(); i++) {
P1 = dst.PointOnShape1(i);
P2 = dst.PointOnShape2(i);
Standard_Real Dist = P1.Distance(P2);
if (aResult > Dist) {
aResult = Dist;
thePnt1 = P1;
thePnt2 = P2;
}
}
}
return aResult;
}
//=======================================================================
// function : ConvertClickToPoint()
// purpose : Returns the point clicked in 3D view
//=======================================================================
gp_Pnt ConvertClickToPoint( int x, int y, Handle(V3d_View) aView )
{
V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
aView->Eye( XEye, YEye, ZEye );
aView->At( XAt, YAt, ZAt );
gp_Pnt EyePoint( XEye, YEye, ZEye );
gp_Pnt AtPoint( XAt, YAt, ZAt );
gp_Vec EyeVector( EyePoint, AtPoint );
gp_Dir EyeDir( EyeVector );
gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir );
Standard_Real X, Y, Z;
aView->Convert( x, y, X, Y, Z );
gp_Pnt ConvertedPoint( X, Y, Z );
gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint );
gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView );
return ResultPoint;
}
//=======================================================================
// function : ConvertTreeToString()
// purpose : Returns the string representation of dependency tree
//=======================================================================
void ConvertTreeToString( const TreeModel &tree,
std::string &treeStr )
{
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("}");
}
}
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 );
}
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 );
}
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
theCursor = indexEnd + 1;
return levelsListData;
}
//=======================================================================
// function : ConvertStringToTree()
// purpose : Returns the dependency tree
//=======================================================================
void ConvertStringToTree( const std::string &theData,
TreeModel &tree )
{
std::size_t cursor = 0;
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;
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 );
std::cout<<" Downward:" << std::endl;
LevelsList downwardList = parseWard( theData, cursor );
tree[objectEntry] = std::pair<LevelsList,LevelsList>( upwardList, downwardList );
}
}
} //namespace GEOMUtils

View File

@ -40,6 +40,11 @@
#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)
@ -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<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.
*
@ -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 );
Standard_EXPORT gp_Pnt ConvertClickToPoint( int x, int y, Handle(V3d_View) theView );
private:
/**
* 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 );
};

View File

@ -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}

View File

@ -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<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++);
}
}
//=====================================================================================

View File

@ -51,11 +51,13 @@
#include "GEOM_IMeasureOperations_i.hh"
#include "GEOM_IGroupOperations_i.hh"
#include "GEOM_IFieldOperations_i.hh"
#include "GEOMUtils.hxx"
#include <TopTools_IndexedMapOfShape.hxx>
#include <map>
#include <set>
#include <list>
#include <string>
//#include <Standard_ErrorHandler.hxx> // 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;