Salome HOME
Correct checking objects.
[modules/geom.git] / src / GEOM_I / GEOM_Gen_i.cc
old mode 100644 (file)
new mode 100755 (executable)
index ff48a03..f6c82c8
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,6 +18,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 #ifdef WIN32
 #pragma warning( disable:4786 )
 #include <TColStd_HArray1OfInteger.hxx>
 #include <TopAbs_ShapeEnum.hxx>
 #include <TopExp.hxx>
+#include <TopTools_SequenceOfShape.hxx>
 #include <OSD.hxx>
+#include <TDataStd_ChildNodeIterator.hxx>
+#include <TDocStd_Owner.hxx>
 
 #include <SALOMEDS_Tool.hxx>
 #include <SALOMEDS_wrap.hxx>
@@ -109,14 +113,11 @@ GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr            orb,
   {
     //work around PAL12004, PAL12628
     //OSD::SetSignal( true );
-    bool raiseFPE;
-#ifdef _DEBUG_
-    raiseFPE = true;
-    char* envDisableFPE = getenv("DISABLE_FPE");
-    if (envDisableFPE && atoi(envDisableFPE))
-      raiseFPE = false;
-#else
-    raiseFPE = false;
+    bool raiseFPE = false;
+#if defined(_DEBUG_) | defined(_DEBUG) //the Last for WIN32 default settings
+    char* envEnableFPE = getenv("ENABLE_FPE");
+    if (envEnableFPE && atoi(envEnableFPE))
+      raiseFPE = true;
 #endif
     OSD::SetSignal( raiseFPE );
   }
@@ -242,9 +243,10 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr   theStudy,
   aResultSO->SetAttrString("AttributeIOR",aGeomObjIOR);
 
   TCollection_AsciiString anObjectName, aNamePrefix("Shape_");
+  CORBA::Long mytype=aBaseObj->GetType();
 
   // BEGIN: try to find existed name for current shape
-  if ( !aShape->_is_nil() )
+  if ( !aShape->_is_nil() && mytype != GEOM_GROUP)
   {
     // recieve current TopoDS shape
     CORBA::String_var entry = aShape->GetEntry();
@@ -278,7 +280,6 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr   theStudy,
   }
   // END: try to find existed name for current shape
 
-  CORBA::Long mytype=aBaseObj->GetType();
   if ( mytype == GEOM_GROUP ) {
     GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
     switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape )) {
@@ -3040,6 +3041,194 @@ Engines::ListOfData* GEOM_Gen_i::getModifiedData(CORBA::Long studyId)
   return aResult._retn();
 }
                                                                
+//=======================================================================
+// function : 
+// purpose  : 
+//=======================================================================
+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_BaseObject_var anObj = GetObject( theStudy->StudyId(), ior.c_str() );
+    if ( anObj->_is_nil() )
+      continue;
+    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);
+
+  //std::cout << "AKL: end of get" << endl;
+  return aStream._retn();
+}
+
+//=======================================================================
+// function : 
+// purpose  : 
+//=======================================================================
+void GEOM_Gen_i::getUpwardDependency( GEOM::GEOM_BaseObject_ptr gbo, 
+                                     GEOMUtils::LevelsList &upLevelList, 
+                                     int level ) {
+  std::string aGboIOR = gbo->GetEntry();
+  for (int i=0; i < upLevelList.size(); i++ ) {
+    GEOMUtils::LevelInfo aMap = upLevelList.at(i);
+    if ( aMap.count( aGboIOR ) > 0 )
+      return;
+  }
+  //std::cout << "\n\nAKL: upnode IOR: " << aGboIOR << endl;
+  //std::cout << "AKL: level: " << level << endl;
+  GEOMUtils::NodeLinks anIORs;
+  GEOMUtils::LevelInfo aLevelMap;
+  if ( level > 0 ) {
+    if ( level-1 >= upLevelList.size() ) {
+      upLevelList.push_back( aLevelMap );
+      //std::cout << "AKL: new map" << endl;
+    } else {
+      aLevelMap = upLevelList.at(level-1);
+      if ( aLevelMap.count( aGboIOR ) > 0 ) {
+       anIORs = aLevelMap[ aGboIOR ];
+       //std::cout << "AKL: get already added iors list: " << endl;
+      }
+    }
+  }
+  GEOM::ListOfGBO_var depList = gbo->GetDependency();
+  for( int j = 0; j < depList->length(); j++ ) {
+    if ( depList[j]->_is_nil() )
+      continue;
+    if ( level > 0 ) {
+      anIORs.push_back( depList[j]->GetEntry() );
+      //std::cout << "AKL: add link ior: " << depList[j]->GetEntry() << endl;
+    }
+    //std::cout << "AKL: <<<<<<<< start next step: " << endl;
+    //if ( !depList[j]->IsSame( gbo ) ) {
+    if ( !depList[j]->_is_equivalent( gbo ) ) {
+      getUpwardDependency(depList[j], upLevelList, level+1);
+    }
+    //std::cout << "AKL: end next step >>>>>>>> : " << endl;
+  }
+  if ( level > 0 ) {
+    //std::cout << "AKL: insert links for node: " << aGboIOR << endl;
+    aLevelMap.insert( std::pair<std::string, GEOMUtils::NodeLinks>(aGboIOR, anIORs) );
+    //std::cout << "AKL: insert level map: " << endl;
+    upLevelList[level-1] = aLevelMap;
+  }
+}
+
+//=======================================================================
+// 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;
+
+  std::string aGboIOR = gbo->GetEntry();
+  //cout << "for " << aGboIOR << " at level " << level << endl;
+  /*if ( level > 0 ) {
+    if ( level >= downLevelList.size() ) {
+      downLevelList.push_back( aLevelMap );
+      //std::cout << "AKL: new map" << endl;
+    } else {
+      aLevelMap = downLevelList.at(level);
+      if ( aLevelMap.count( aGboIOR ) > 0 ) {
+       anIORs = aLevelMap[ aGboIOR ];
+       //std::cout << "AKL: get already added iors list: " << endl;
+      }
+    }
+  }*/
+  Handle(TDocStd_Document) aDoc = GEOM_Engine::GetEngine()->GetDocument(gbo->GetStudyID());
+  Handle(TDataStd_TreeNode) aNode, aRoot;
+  Handle(GEOM_Function) aFunction;
+  if (aDoc->Main().FindAttribute(GEOM_Function::GetFunctionTreeID(), aRoot)) {
+    TDataStd_ChildNodeIterator Itr( aRoot );
+    for (; Itr.More(); Itr.Next()) {
+      aNode = Itr.Value();
+      aFunction = GEOM_Function::GetFunction(aNode->Label());
+      if (aFunction.IsNull()) {
+        //MESSAGE ( "Null function !!!!" );
+        continue;
+      }
+      TDF_Label aLabel  = aFunction->GetOwnerEntry();
+      if(aLabel.IsNull()) continue;
+      TCollection_AsciiString anEntry;
+      TDF_Tool::Entry(aLabel, anEntry);
+      GEOM::GEOM_BaseObject_var geomObj = GetObject( gbo->GetStudyID(), anEntry.ToCString() );
+      /*
+      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 = geomObj->GetEntry();
+      //cout << "check " << aGoIOR << endl;
+
+      for( int i = 0; i < depList->length(); i++ ) {
+        if ( depList[i]->_is_nil() )
+          continue;
+        //cout << "depends on " << depList[i]->GetEntry() << endl;
+        //if ( depList[i]->IsSame( gbo ) ) {
+        if ( depList[i]->_is_equivalent( gbo ) ) {
+          //cout << "  the same! " << endl;
+          //if ( level > 0 ) {
+          GEOMUtils::NodeLinks anIORs;
+          GEOMUtils::LevelInfo aLevelMap;
+          anIORs.push_back( gbo->GetEntry());
+          if ( level >= downLevelList.size() ) {
+            downLevelList.push_back( aLevelMap );
+           //std::cout << "AKL: new map" << endl;
+          } else {
+            aLevelMap = downLevelList.at(level);
+            if ( aLevelMap.count( aGoIOR ) > 0 ) {
+              anIORs = aLevelMap[ aGoIOR ];
+              //std::cout << "AKL: get already added iors list: " << endl;
+            }
+          }
+          aLevelMap.insert( std::pair<std::string, GEOMUtils::NodeLinks>(aGoIOR, anIORs) );
+          downLevelList[level] = aLevelMap;
+          //}
+          //if ( !depList[i]->IsSame( geomObj ) ) {
+          if ( !depList[i]->_is_equivalent( geomObj ) ) {
+            //cout << "  go on! " << endl;
+            getDownwardDependency(theStudy, geomObj, downLevelList, level+1);
+          }
+        }
+      }
+    }
+  }
+  /*if ( level > 0 ) {
+    aLevelMap.insert( std::pair<std::string, GEOMUtils::NodeLinks>(aGboIOR, anIORs) );
+    downLevelList[level-1] = aLevelMap;
+  }*/
+}
+
 //=====================================================================================
 // EXPORTED METHODS
 //=====================================================================================