From 73f733a3c0d576df3283ddbb9c9767ff752f322d Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 18 Oct 2012 07:06:55 +0000 Subject: [PATCH] Initial integration of SimanIO support and SIMAN study interfaces --- src/GEOM/GEOM_Engine.cxx | 16 +++++ src/GEOM/GEOM_Engine.hxx | 7 ++ src/GEOM/GEOM_IOperations.cxx | 1 + src/GEOM_I/GEOM_Gen_i.cc | 125 ++++++++++++++++++++++++++++++++++ src/GEOM_I/GEOM_Gen_i.hh | 4 ++ 5 files changed, 153 insertions(+) diff --git a/src/GEOM/GEOM_Engine.cxx b/src/GEOM/GEOM_Engine.cxx index 40ac1d97c..2418b6161 100644 --- a/src/GEOM/GEOM_Engine.cxx +++ b/src/GEOM/GEOM_Engine.cxx @@ -944,6 +944,17 @@ std::list 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 //=========================================================================== @@ -1669,3 +1680,8 @@ void ObjectStates::IncrementState() { _dumpstate++; } + + void DocumentModified(const int theDocId, const bool isModified); + + bool DocumentModified(const int theDocId); + \ No newline at end of file diff --git a/src/GEOM/GEOM_Engine.hxx b/src/GEOM/GEOM_Engine.hxx index 4ae37dfec..1d019f320 100644 --- a/src/GEOM/GEOM_Engine.hxx +++ b/src/GEOM/GEOM_Engine.hxx @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -178,6 +179,10 @@ class GEOM_Engine static const Standard_GUID& GetTextureGUID(); + void DocumentModified(const int theDocId, const bool isModified); + + bool DocumentModified(const int theDocId); + protected: Standard_EXPORT static void SetEngine(GEOM_Engine* theEngine); @@ -189,6 +194,8 @@ class GEOM_Engine #else Interface_DataMapOfIntegerTransient _mapIDDocument; #endif + TColStd_MapOfInteger _mapModifiedDocs; // keeps the identifiers of the modified document ids + int _UndoLimit; GEOM_DataMapOfAsciiStringTransient _objects; diff --git a/src/GEOM/GEOM_IOperations.cxx b/src/GEOM/GEOM_IOperations.cxx index d7a381c16..cc90a0599 100644 --- a/src/GEOM/GEOM_IOperations.cxx +++ b/src/GEOM/GEOM_IOperations.cxx @@ -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); } //============================================================================= diff --git a/src/GEOM_I/GEOM_Gen_i.cc b/src/GEOM_I/GEOM_Gen_i.cc index a3184ee93..e58b79a90 100644 --- a/src/GEOM_I/GEOM_Gen_i.cc +++ b/src/GEOM_I/GEOM_Gen_i.cc @@ -61,6 +61,8 @@ #include #include "SALOMEDS_Tool.hxx" +#include "SALOME_DataContainer_i.hxx" +#include "Basics_DirUtils.hxx" //============================================================================ // function : GEOM_Gen_i() @@ -2547,6 +2549,129 @@ char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry) return ret; } +//================================================================================= +// 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 "<IsDone()) + MESSAGE("Import operation is not done for file "<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"); + 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 = _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 "<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 //===================================================================================== diff --git a/src/GEOM_I/GEOM_Gen_i.hh b/src/GEOM_I/GEOM_Gen_i.hh index 9e65dea0c..055a04c25 100644 --- a/src/GEOM_I/GEOM_Gen_i.hh +++ b/src/GEOM_I/GEOM_Gen_i.hh @@ -264,6 +264,10 @@ class GEOM_I_EXPORT GEOM_Gen_i: virtual public POA_GEOM::GEOM_Gen, virtual publi virtual bool hasObjectInfo(); virtual char* getObjectInfo(CORBA::Long studyId, const char* entry); + virtual Engines::ListOfIdentifiers* importData( + CORBA::Long studyId, Engines::DataContainer_ptr data, const Engines::ListOfOptions& options); + virtual Engines::ListOfData* getModifiedData(CORBA::Long studyId); + //-----------------------------------------------------------------------// // Internal methods // //-----------------------------------------------------------------------// -- 2.39.2