+//=============================================================================
+/*!
+ * returns true, if can copy the object
+ */
+//=============================================================================
+CORBA::Boolean Med_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
+ // Try to retrieve known by MED component mesh by given IOR
+ SALOMEDS::GenericAttribute_var anAttr;
+ if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
+ CORBA::Object_var anObj = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
+ SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(anObj);
+ // If the object is null one it can't be copied: return false
+ if (aMesh->_is_nil()) return false;
+ return true;
+}
+
+//=============================================================================
+/*!
+ * create copy of the object and put it to the stream
+ */
+//=============================================================================
+SALOMEDS::TMPFile* Med_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
+ // Declare a sequence of the byte to store the copied object
+ SALOMEDS::TMPFile_var aStreamFile;
+
+ // Try to get GEOM_Shape object by given SObject
+ SALOMEDS::GenericAttribute_var anAttr;
+ if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return new SALOMEDS::TMPFile(0);
+ CORBA::String_var anIOR = strdup(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
+ CORBA::Object_var anObj = _orb->string_to_object(anIOR);
+ SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(anObj);
+ if (aMesh->_is_nil()) return new SALOMEDS::TMPFile(0);
+
+ // Get a temporary directory to store a temporary file
+ CORBA::String_var aTmpDir = SALOMEDS_Tool::GetTmpDir();
+ // Create a list to store names of created files
+ SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
+ aSeq->length(1);
+ aSeq[0] = strdup(aMesh->getName());
+ char* aFullName = new char[strlen(aTmpDir)+strlen(aSeq[0])+1];
+ strcpy(aFullName, aTmpDir);
+ strcpy(aFullName+strlen(aTmpDir), aSeq[0]);
+ long driverId = aMesh->addDriver(SALOME_MED::MED_DRIVER,strdup(aFullName) , aMesh->getName());
+ aMesh->write(driverId,"");
+ delete(aFullName);
+
+ aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aSeq.in(), false);
+ SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeq.in(), true);
+
+ // Assign an ID = 1 the the type SALOME_MED::MESH
+ theObjectID = 1;
+
+ return aStreamFile._retn();
+}
+
+//=============================================================================
+/*!
+ * returns true, if can copy the object
+ */
+//=============================================================================
+CORBA::Boolean Med_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
+ // The MED component can paste only objects copied by MED component
+ // and with the object type = 1 (mesh)
+ if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1) return false;
+ return true;
+}
+
+//=============================================================================
+/*!
+ * returns true, if can copy the object
+ */
+//=============================================================================
+SALOMEDS::SObject_ptr Med_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
+ CORBA::Long theObjectID,
+ SALOMEDS::SObject_ptr theObject) {
+ SALOMEDS::SObject_var aResultSO = SALOMEDS::SObject::_duplicate(theObject);
+ if (theStream.length() == 0) return aResultSO._retn();
+
+ SALOMEDS::Study_var aStudy = theObject->GetStudy();
+
+ CORBA::String_var aTmpDir = strdup(SALOMEDS_Tool::GetTmpDir());
+ SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir, false);
+ CORBA::String_var aMeshName = strdup(aSeq[0]);
+ char* aFullName = new char[strlen(aTmpDir)+strlen(aMeshName)+1];
+ strcpy(aFullName, aTmpDir);
+ strcpy(aFullName+strlen(aTmpDir), aMeshName);
+
+ MESH * myMesh= new MESH() ;
+ myMesh->setName((char*)aMeshName);
+ MED_MESH_RDONLY_DRIVER myMeshDriver(aFullName, myMesh);
+ try {
+ myMeshDriver.setMeshName((char*)aMeshName);
+ myMeshDriver.open();
+ } catch (const exception & ex) {
+ MESSAGE("Exception Interceptee : ");
+ SCRUTE(ex.what());
+ delete(aFullName);
+ return aResultSO._retn();
+ };
+ try {
+ myMeshDriver.read();
+ ("apres read");
+ myMeshDriver.close();
+ } catch (const exception & ex) {
+ MESSAGE("Exception Interceptee : ");
+ SCRUTE(ex.what());
+ delete(aFullName);
+ return aResultSO._retn();
+ };
+ // set new mesh name, becouse now there are no possibility to operate meshes with the same names
+// srand((unsigned int)time(NULL));
+ int aRND = rand(); //Get a random number to present a name of a copied mesh
+ char aCopiedMeshName[20];
+ sprintf(aCopiedMeshName,"MESH_COPY_%d",aRND);
+ myMesh->setName(aCopiedMeshName);
+ MESH_i * meshi = new MESH_i(myMesh);
+ SALOME_MED::MESH_ptr mesh = meshi->_this();
+ // add the mesh object in study
+ meshi->addInStudy(aStudy,mesh);
+ // get the IOR attribute of just added mesh
+ CORBA::String_var anIORString = _orb->object_to_string(mesh);
+ aResultSO = aStudy->FindObjectIOR(anIORString);
+
+ SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeq.in(), true);
+ delete(aFullName);
+ return aResultSO._retn();
+}
+
+
+
+
+
+