Salome HOME
0022759: [EDF] Creation of a surface from several edges
[modules/geom.git] / src / GEOM_I / GEOM_Gen_i.cc
index 9742087c284700a3e098883e42f1a1ce43453a60..e939d30f10bea24a0f4868cc1e1709a9284b23e0 100755 (executable)
@@ -44,6 +44,7 @@
 #include "GEOMImpl_CopyDriver.hxx"
 #include "GEOMImpl_IInsertOperations.hxx"
 #include "GEOM_wrap.hxx"
+#include "GEOMUtils_XmlHandler.hxx"
 
 // Cascade headers
 #include <BRep_Builder.hxx>
@@ -121,6 +122,18 @@ GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr            orb,
 #endif
     OSD::SetSignal( raiseFPE );
   }
+
+  GEOMUtils::PluginInfo plugins = GEOMUtils::ReadPluginInfo();
+  GEOMUtils::PluginInfo::const_iterator it;
+  for (it = plugins.begin(); it != plugins.end(); ++it)
+  {
+    try {
+      LoadPlugin((*it).serverLib);
+    }
+    catch (...)  {
+      MESSAGE("Warning: can't load plugin library " << (*it).serverLib);
+    }
+  }
 }
 
 //============================================================================
@@ -303,7 +316,26 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr   theStudy,
   } else if ( mytype == GEOM_MARKER ) {
     aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_LCS");
     aNamePrefix = "LocalCS_";
-  } else if ( mytype > ADVANCED_BASE ) {
+  }  else if ( mytype >= USER_TYPE_EX ) {
+      char buf[20];
+      sprintf( buf, "%d", aBaseObj->GetType() );
+      GEOM::CreationInformation_var info = aBaseObj->GetCreationInformation();
+      std::string plgId;
+      for ( size_t i = 0; i < info->params.length(); ++i ) {
+       std::string param_name = info->params[i].name.in();
+       std::string param_value = info->params[i].value.in();   
+       if( param_name == PLUGIN_NAME) {
+         plgId = param_value;
+         break;
+       }
+      }
+      if(plgId.length() > 0 ) {
+       plgId += "::";
+      }
+      plgId +="ICON_OBJBROWSER_"; 
+      plgId += buf;
+      aResultSO->SetAttrString("AttributePixMap",plgId.c_str());
+  } else if ( mytype > USER_TYPE ) {
     char buf[20];
     sprintf( buf, "%d", aBaseObj->GetType() );
     std::string advId = "ICON_OBJBROWSER_ADVANCED_"; advId += buf;
@@ -2405,74 +2437,84 @@ GEOM::GEOM_IOperations_ptr GEOM_Gen_i::GetPluginOperations(CORBA::Long theStudyI
                                                            const char* theLibName)
      throw ( SALOME::SALOME_Exception )
 {
-  std::string aPlatformLibName;
-#ifdef WIN32
-  aPlatformLibName = theLibName;
-  aPlatformLibName += ".dll" ;
-#else
-  aPlatformLibName = "lib";
-  aPlatformLibName += theLibName;
-  aPlatformLibName += ".so";
-#endif
-
   Unexpect aCatch(SALOME_SalomeException);
   MESSAGE( "GEOM_Gen_i::GetPluginOperations" );
 
   GEOM::GEOM_Gen_ptr engine = _this();
 
-  GEOM_IOperations_i* aServant = 0;
   GEOM::GEOM_IOperations_var operations;
 
-  try {
-    // check, if corresponding operations are already created
-    if (myOpCreatorMap.find(std::string(theLibName)) == myOpCreatorMap.end()) {
-      // load plugin library
-      LibHandle libHandle = LoadLib( aPlatformLibName.c_str()/*theLibName*/ );
-      if (!libHandle) {
-        // report any error, if occured
-#ifndef WIN32
-        const char* anError = dlerror();
-        throw(SALOME_Exception(anError));
-#else
-        throw(SALOME_Exception(LOCALIZED( "Can't load server geometry plugin library" )));
-#endif
-      }
-
-      // get method, returning operations creator
-      typedef GEOM_GenericOperationsCreator* (*GetOperationsCreator)();
-      GetOperationsCreator procHandle =
-        (GetOperationsCreator)GetProc( libHandle, "GetOperationsCreator" );
-      if (!procHandle) {
-        throw(SALOME_Exception(LOCALIZED("bad geometry plugin library")));
-        UnLoadLib(libHandle);
-      }
-
-      // get operations creator
-      GEOM_GenericOperationsCreator* aCreator = procHandle();
-      if (!aCreator) {
-        throw(SALOME_Exception(LOCALIZED("bad geometry plugin library implementation")));
-      }
-
-      // map operations creator to a plugin name
-      myOpCreatorMap[std::string(theLibName)] = aCreator;
-    }
+  std::string aLibName = theLibName;
 
+  try {
+    // load plugin library
+    LoadPlugin(aLibName);
     // create a new operations object, store its ref. in engine
-    aServant = myOpCreatorMap[std::string(theLibName)]->Create(_poa, theStudyID, engine, _impl);
-    //??? aServant->SetLibName(aPlatformLibName/*theLibName*/); // for persistency assurance
+    if ( myOpCreatorMap.find(aLibName) != myOpCreatorMap.end() ) {
+      GEOM_IOperations_i* aServant = 0;
+      aServant = myOpCreatorMap[aLibName]->Create(_poa, theStudyID, engine, _impl);
+      // activate the CORBA servant
+      if (aServant)
+       operations = aServant->_this();
+    }
   }
   catch (SALOME_Exception& S_ex) {
     THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
   }
 
-  if (!aServant)
-    return operations._retn();
-
-  // activate the CORBA servant
-  operations = GEOM::GEOM_IOperations::_narrow( aServant->_this() );
   return operations._retn();
 }
 
+//============================================================================
+// function : LoadPlugin
+// purpose  : load plugin library and retrieve an instance of operations creator
+//============================================================================
+void GEOM_Gen_i::LoadPlugin(const std::string& theLibName)
+{
+  std::string aPlatformLibName;
+#ifdef WIN32
+  aPlatformLibName = theLibName;
+  aPlatformLibName += ".dll" ;
+#else
+  aPlatformLibName = "lib";
+  aPlatformLibName += theLibName;
+  aPlatformLibName += ".so";
+#endif
+  
+  // check, if corresponding operations are already created
+  if (myOpCreatorMap.find(theLibName) == myOpCreatorMap.end()) {
+    // load plugin library
+    LibHandle libHandle = LoadLib( aPlatformLibName.c_str() );
+    if (!libHandle) {
+      // report any error, if occured
+#ifndef WIN32
+      throw(SALOME_Exception(dlerror()));
+#else
+      throw(SALOME_Exception(LOCALIZED( "Can't load server geometry plugin library" )));
+#endif
+    }
+    
+    // get method, returning operations creator
+    typedef GEOM_GenericOperationsCreator* (*GetOperationsCreator)();
+    GetOperationsCreator procHandle =
+      (GetOperationsCreator)GetProc( libHandle, "GetOperationsCreator" );
+    if (!procHandle) {
+      UnLoadLib(libHandle);
+      throw(SALOME_Exception(LOCALIZED("bad geometry plugin library")));
+    }
+    
+    // get operations creator
+    GEOM_GenericOperationsCreator* aCreator = procHandle();
+    if (aCreator) {
+      // map operations creator to a plugin name
+      myOpCreatorMap[theLibName] = aCreator;
+    }
+    else {
+      throw(SALOME_Exception(LOCALIZED("bad geometry plugin library implementation")));
+    }
+  }
+}
+
 //=============================================================================
 /*!
  *  AddSubShape
@@ -2925,30 +2967,26 @@ Engines::ListOfIdentifiers* GEOM_Gen_i::importData(
   aFile.write(aBuffer, aFileStream->length());
   aFile.close();
 
-  GEOM::GEOM_Object_var aShapeObj;
-  GEOM::ListOfGO_var aSubShape = new GEOM::ListOfGO;
-  GEOM::ListOfGO_var aGroups = new GEOM::ListOfGO;
-  GEOM::ListOfFields_var aFields = new GEOM::ListOfFields;
-
-  CORBA::Boolean isResultOK = aInsOp->ImportXAO(aFullPath.c_str(), aShapeObj.out(), aSubShape.out(), aGroups.out(), aFields.out());
-
-  if ( isResultOK && !aShapeObj->_is_nil() && aInsOp->IsDone() ) {
-    SALOMEDS::SObject_var aSO = PublishInStudy(aStudy, SALOMEDS::SObject::_nil(), aShapeObj, aShapeObj->GetName());
-    aResult->length(aGroups->length() + 1);
-    aResult[0] = aSO->GetID(); // unioque identifer of the object in GEOM is entry of SObject
-    //Iteration for objects of the group.
-    for (int i = 0; i < aGroups->length(); i++) {
-      SALOMEDS::SObject_var aSOChild = AddInStudy(aStudy, aGroups[i], aGroups[i]->GetName(), aShapeObj);
-      aResult[i+1] = aSOChild->GetID();
+  GEOM::ListOfGBO_var aObjects = aInsOp->ImportFile(aFullPath.c_str(), "XAO");
+
+  if ( aObjects->length() > 0 && aInsOp->IsDone() ) {
+    aResult->length(aObjects->length());
+    // publish main object (first in the list of returned geom objects)
+    CORBA::String_var aName = aObjects[0]->GetName();
+    SALOMEDS::SObject_var aSO = PublishInStudy(aStudy.in(), SALOMEDS::SObject::_nil(), aObjects[0].in(), aName.in());
+    aResult[0] = aSO->GetID();
+    // publish groups && fields
+    for (int i = 1; i < aObjects->length(); i++ ) {
+      aName = aObjects[i]->GetName();
+      aSO = AddInStudy(aStudy.in(), aObjects[0].in(), aName.in(), aObjects[0].in());
+      aResult[i] = aSO->GetID();
     }
   }
   else {
-    if (aShapeObj->_is_nil())
-      MESSAGE("Result of the import operation is incorrect for file "<<aFullPath.c_str());
+    if (aObjects->length() == 0)
+      MESSAGE("ImportXAO operation is failed for file "<<aFullPath.c_str());
     if (!aInsOp->IsDone())
       MESSAGE("Import operation is not done for file "<<aFullPath.c_str());
-    if (!isResultOK)
-      MESSAGE("ImportXAO operation is failed for file "<<aFullPath.c_str());
     return aResult._retn();
   }
 
@@ -2977,21 +3015,24 @@ Engines::ListOfData* GEOM_Gen_i::getModifiedData(CORBA::Long studyId)
 
   CORBA::Object_var aSMObject = name_service->Resolve("/myStudyManager");
   SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
+  if (CORBA::is_nil(aStudyManager))
+    return aResult._retn();
   SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
+  if (CORBA::is_nil(aStudy))
+    return aResult._retn();
   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
 
+  GEOM::GEOM_IInsertOperations_var aInsOp    = GetIInsertOperations(aStudy->StudyId());
+  if (aInsOp->_is_nil()) {
+    MESSAGE("No insert operations!");
+    return aResult._retn();
+  }
+
   GEOM::GEOM_Object_var shapeObj;
-  GEOM::ListOfGO_var groups = new GEOM::ListOfGO;
-  GEOM::ListOfFields_var fields = new GEOM::ListOfFields;
-  std::string anAuthorName = "SIMAN Author";
   
-  GEOM::GEOM_IShapesOperations_var  aShapesOp = GetIShapesOperations(aStudy->StudyId());
-  GEOM::GEOM_IInsertOperations_var aInsOp = GetIInsertOperations(aStudy->StudyId());
-
-  int aSeqLength = 0; // the sequence length
   for(; anIter->More(); anIter->Next()) {
     SALOMEDS::SObject_var aSO = anIter->Value();
     SALOMEDS::SObject_var aRefSO;
@@ -3006,13 +3047,7 @@ Engines::ListOfData* GEOM_Gen_i::getModifiedData(CORBA::Long studyId)
 
           GEOM::shape_type aCORBAShapeType = aCORBAMainShape->GetShapeType();
           if (!aMainShape.IsNull() && !(aCORBAShapeType == GEOM::VERTEX) && !(aCORBAShapeType == GEOM::EDGE)) {
-            aSeqLength++;
             shapeObj = aCORBAMainShape;
-            if (aShapesOp->_is_nil()) {
-              MESSAGE("No shapes operations!");
-              return aResult._retn();
-            }
-            groups = aShapesOp->GetExistingSubObjects(aCORBAMainShape, true);
             break;
           }
         }
@@ -3020,19 +3055,12 @@ Engines::ListOfData* GEOM_Gen_i::getModifiedData(CORBA::Long studyId)
     }
   }
 
-  if (aInsOp->_is_nil()) {
-    MESSAGE("No insert operations!");
-    return aResult._retn();
-  }
-
-  if (aSeqLength > 0) { // Shape is correct, write it to the temporary file
-
-    std::string aFullXaoPath = Kernel_Utils::GetTmpFileName() + ".xao";
-    CORBA::Boolean isResultOK = aInsOp->ExportXAO(shapeObj.in(), groups.in(), fields.in(), anAuthorName.c_str(), aFullXaoPath.c_str());
-
+  if (!CORBA::is_nil(shapeObj)) { // Shape is correct, write it to the temporary file
+    std::string aPath = Kernel_Utils::GetTmpFileName() + ".xao";
+    aInsOp->Export(shapeObj.in(), aPath.c_str(), "XAO");
     aResult->length(1);
     Engines::DataContainer_var aData = (new Engines_DataContainer_i(
-                    aFullXaoPath.c_str(), "", "", true))->_this();
+                    aPath.c_str(), "", "", true))->_this();
     aResult[0] = aData;
   } else {
     MESSAGE("No shapes to export");
@@ -3198,10 +3226,10 @@ void GEOM_Gen_i::getDownwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
 }
 
 //==============================================================================
-// function : GetEntriesToCleanStudy
+// function : GetEntriesToReduceStudy
 // purpose  : Fills 3 lists that is used to clean study of redundant objects
 //==============================================================================
-void GEOM_Gen_i::GetEntriesToCleanStudy(SALOMEDS::Study_ptr theStudy,
+void GEOM_Gen_i::GetEntriesToReduceStudy(SALOMEDS::Study_ptr theStudy,
                                        GEOM::string_array& theSelectedEntries,
                                        GEOM::string_array& theParentEntries,
                                        GEOM::string_array& theSubEntries,