]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
Merge from V7_siman 11/10/2013
authorvsr <vsr@opencascade.com>
Fri, 11 Oct 2013 12:50:25 +0000 (12:50 +0000)
committervsr <vsr@opencascade.com>
Fri, 11 Oct 2013 12:50:25 +0000 (12:50 +0000)
src/GEOM/GEOM_Engine.cxx
src/GEOM/GEOM_Engine.hxx
src/GEOM/GEOM_IOperations.cxx
src/GEOM_I/GEOM_Gen_i.cc
src/GEOM_I/GEOM_Gen_i.hh
src/GEOM_SWIG/geomBuilder.py

index f486e24c0a4f1297921dbd0b28382722f441b95c..99e94148f43b51f59759b31aba7c535be0c5f547 100644 (file)
@@ -977,6 +977,17 @@ std::list<int> GEOM_Engine::getAllTextures(int theDocID)
   return id_list;
 }
 
+void GEOM_Engine::DocumentModified(const int theDocId, const bool isModified)
+{
+  if (isModified) _mapModifiedDocs.Add(theDocId);
+  else _mapModifiedDocs.Remove(theDocId);
+}
+bool GEOM_Engine::DocumentModified(const int theDocId)
+{
+  return _mapModifiedDocs.Contains(theDocId);
+}
+
 //===========================================================================
 //                     Internal functions
 //===========================================================================
index b3c9febfe944d82c601cd2bcfdf268185dcb203a..67e2dfe307d5418de0503bfa9ea4893b8139dbd1 100644 (file)
@@ -39,6 +39,7 @@
 #include <TDocStd_Document.hxx>
 #include <TColStd_HArray1OfInteger.hxx>
 #include <TColStd_HSequenceOfAsciiString.hxx>
+#include <TColStd_MapOfInteger.hxx>
 #include <TDF_Label.hxx>
 
 #include <map>
@@ -179,15 +180,21 @@ class GEOM_Engine
                                    const TCollection_AsciiString&            anEntry,
                                    Resource_DataMapOfAsciiStringAsciiString& aNameToEntry);
 
+  void DocumentModified(const int theDocId, const bool isModified);
+  
+  bool DocumentModified(const int theDocId);
+
  protected:
   Standard_EXPORT static void SetEngine(GEOM_Engine* theEngine);       
   
  private:
 
-  Handle(GEOM_Application)                 _OCAFApp;
-  TColStd_DataMapOfIntegerTransient        _mapIDDocument;
-  int                                      _UndoLimit;
-  GEOM_DataMapOfAsciiStringTransient       _objects;
+  Handle(GEOM_Application)  _OCAFApp;
+  TColStd_DataMapOfIntegerTransient _mapIDDocument;
+  TColStd_MapOfInteger _mapModifiedDocs; // keeps the identifiers of the modified document ids
+
+  int _UndoLimit;
+  GEOM_DataMapOfAsciiStringTransient _objects;
 
   Resource_DataMapOfAsciiStringAsciiString _studyEntry2NameMap;
 
index 8f491950d3e9ad4ab1b3a60b177f8fdaa2603279..37073700893a878771c4a56d1f214f9145651324 100644 (file)
@@ -79,6 +79,7 @@ void GEOM_IOperations::FinishOperation()
   Handle(TDocStd_Document) aDoc = _engine->GetDocument(_docID);
   if(aDoc->GetUndoLimit() > 0) 
     aDoc->CommitCommand();
+  _engine->DocumentModified(_docID, true);
 }
 
 //=============================================================================
index 86fca280e0e5f6a7253a067a539e92e9e9004e74..171540f3cb1906903289132df61c5027359b5e4b 100644 (file)
@@ -60,6 +60,8 @@
 
 #include <SALOMEDS_Tool.hxx>
 #include <SALOMEDS_wrap.hxx>
+#include <SALOME_DataContainer_i.hxx>
+#include <Basics_DirUtils.hxx>
 
 #include <set>
 #include <sstream>
@@ -2879,6 +2881,131 @@ void GEOM_Gen_i::Move( const GEOM::object_list& what,
   }
 }
 
+//=================================================================================
+// function : importData
+// purpose  : imports geometrical data file into the GEOM internal data structure
+//=================================================================================
+Engines::ListOfIdentifiers* GEOM_Gen_i::importData(
+  CORBA::Long studyId, Engines::DataContainer_ptr data, const Engines::ListOfOptions& options)
+{
+  CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" );
+  SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
+  SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
+
+  Engines::ListOfIdentifiers_var aResult = new Engines::ListOfIdentifiers;
+  GEOM::GEOM_IInsertOperations_var aInsOp = GetIInsertOperations(aStudy->StudyId());
+  if (aInsOp->_is_nil()) {
+    MESSAGE("No insert operations!");
+    return aResult._retn();
+  }
+
+  // Get a temporary directory to store a file
+  std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
+  std::string aFileName("file");
+  if (aFileName.rfind("/") != std::string::npos) { // remove folders from the name
+    aFileName = aFileName.substr(aFileName.rfind("/") + 1);
+  }
+  std::string anExtension(data->extension());
+  aFileName += "." + anExtension;
+  // convert extension to upper case
+  std::transform(anExtension.begin(), anExtension.end(), anExtension.begin(), ::toupper);
+
+  std::string aFullPath = aTmpDir + aFileName;
+
+  Engines::TMPFile* aFileStream = data->get();
+  const char *aBuffer = (const char*)aFileStream->NP_data();
+#ifdef WIN32
+  std::ofstream aFile(aFullPath.c_str(), std::ios::binary);
+#else
+  std::ofstream aFile(aFullPath.c_str());
+#endif
+  aFile.write(aBuffer, aFileStream->length());
+  aFile.close();
+
+  GEOM::GEOM_Object_var anObj = aInsOp->ImportFile(aFullPath.c_str(), anExtension.c_str());
+  if ( !anObj->_is_nil() && aInsOp->IsDone() ) {
+    SALOMEDS::SObject_var aSO = PublishInStudy(aStudy, SALOMEDS::SObject::_nil(), anObj, data->name());
+    aResult->length(1);
+    aResult[0] = aSO->GetID(); // unioque identifer of the object in GEOM is entry of SObject
+  } else {
+    if (anObj->_is_nil())
+      MESSAGE("Result of the import operation is incorrect for file "<<aFullPath.c_str());
+    if (!aInsOp->IsDone())
+      MESSAGE("Import operation is not done for file "<<aFullPath.c_str());
+    return aResult._retn();
+  }
+
+  // remove temporary file and directory
+  SALOMEDS::ListOfFileNames aTmpFiles;
+  aTmpFiles.length(1);
+  aTmpFiles[0] = aFileName.c_str();
+  SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aTmpFiles, true);
+  
+  _impl->DocumentModified(studyId, false);
+  return aResult._retn();
+}
+
+//=================================================================================
+// function : getModifiedData
+// purpose  : exports all geometry of this GEOM module into one BRep file
+//=================================================================================
+Engines::ListOfData* GEOM_Gen_i::getModifiedData(CORBA::Long studyId)
+{
+  Engines::ListOfData_var aResult = new Engines::ListOfData;
+
+  if (!_impl->DocumentModified(studyId)) {
+    MESSAGE("Document is not modified")
+    return aResult._retn();
+  }
+
+  CORBA::Object_var aSMObject = name_service->Resolve("/myStudyManager");
+  SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
+  SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
+  SALOMEDS::SComponent_var aComponent = aStudy->FindComponent("GEOM");
+  if (CORBA::is_nil(aComponent))
+    return aResult._retn();
+  SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(aComponent); // check only published shapes
+  TopoDS_Compound aResultComp;
+  BRep_Builder aBB;
+  aBB.MakeCompound(aResultComp);
+  int aNumInComp = 0; // number of shapes in resulting compound
+  for(; anIter->More(); anIter->Next()) {
+    SALOMEDS::SObject_var aSO = anIter->Value();
+    SALOMEDS::SObject_var aRefSO;
+    // export only not referenced objects, or referenced outside of GEOM
+    if (!aSO->ReferencedObject(aRefSO) || aRefSO->GetFatherComponent()->GetID() != aComponent->GetID()) {
+      CORBA::Object_var anObj = aSO->GetObject();
+      if (!CORBA::is_nil(anObj)) {
+        GEOM::GEOM_Object_var aCORBAMainShape = GEOM::GEOM_Object::_narrow(anObj);
+        if(!aCORBAMainShape->_is_nil()) {
+          CORBA::String_var entry = aCORBAMainShape->GetEntry();
+          Handle(GEOM_Object) aMainShape = Handle(GEOM_Object)::DownCast( _impl->GetObject(studyId, entry) );
+          if (!aMainShape.IsNull()) {
+            TopoDS_Shape aMainSh = aMainShape->GetValue();
+            if (!aMainSh.IsNull()) {
+              aBB.Add(aResultComp, aMainSh);
+              aNumInComp++;
+            }
+          }
+        }
+      }
+    }
+  }
+  if (aNumInComp > 0) { // compund is correct, write it to the temporary file
+    std::string aFullPath = Kernel_Utils::GetTmpFileName() + ".brep";
+    BRepTools::Write(aResultComp, aFullPath.c_str());
+    MESSAGE("Write compound of "<<aNumInComp<<" shapes to "<<aFullPath.c_str());
+    aResult->length(1);
+    Engines::DataContainer_var aData = (new Engines_DataContainer_i(
+                    aFullPath.c_str(), "", "", true))->_this();
+    aResult[0] = aData;
+  } else {
+    MESSAGE("No shapes to export");
+  }
+  
+  return aResult._retn();
+}
+                                                               
 //=====================================================================================
 // EXPORTED METHODS
 //=====================================================================================
index 8d8e9943d0ddab760fca58bd3500bccfa5ee9841..8633964ca719479d81332cbe44dcdd44f7775800 100644 (file)
@@ -309,6 +309,13 @@ class GEOM_I_EXPORT GEOM_Gen_i: virtual public POA_GEOM::GEOM_Gen, virtual publi
             SALOMEDS::SObject_ptr where,
             CORBA::Long row );
 
+  // SIMAN-related functions (check out/check in) : import data to study
+  virtual Engines::ListOfIdentifiers* importData(CORBA::Long studyId,
+                                                Engines::DataContainer_ptr data,
+                                                const Engines::ListOfOptions& options);
+  // SIMAN-related functions (check out/check in) : get modified data
+  virtual Engines::ListOfData* getModifiedData(CORBA::Long studyId);
+
   //-----------------------------------------------------------------------//
   // Internal methods                                                      //
   //-----------------------------------------------------------------------//
index de5589ca51ad616390f7357f0612df4e65c2cae6..bcf8ef0f4222850b518ce9fe99e39b118e330ab6 100644 (file)
@@ -229,7 +229,11 @@ def _toListOfNames(_names, _size=-1):
 ## @ingroup l1_geomBuilder_auxiliary
 def RaiseIfFailed (Method_name, Operation):
     if Operation.IsDone() == 0 and Operation.GetErrorCode() != "NOT_FOUND_ANY":
+        Operation.AbortOperation()
         raise RuntimeError, Method_name + " : " + Operation.GetErrorCode()
+    else:
+        Operation.FinishOperation()
+        pass
 
 ## Return list of variables value from salome notebook
 ## @ingroup l1_geomBuilder_auxiliary
@@ -4308,6 +4312,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
                 New GEOM.GEOM_Object, containing the created compound.
             """
             # Example: see GEOM_TestAll.py
+            self.ShapesOp.StartOperation()
             anObj = self.ShapesOp.MakeCompound(theShapes)
             RaiseIfFailed("MakeCompound", self.ShapesOp)
             self._autoPublish(anObj, theName, "compound")