Index: trunk/SophyaPI/PIext/nobjmgr.cc
===================================================================
--- trunk/SophyaPI/PIext/nobjmgr.cc	(revision 339)
+++ trunk/SophyaPI/PIext/nobjmgr.cc	(revision 344)
@@ -42,5 +42,5 @@
 // include	nobjmgr.h
 //
-//	Cette classe fournit les services nécéssaire àla gestion des objets
+//	Cette classe fournit les services nécéssaires à la gestion des objets
 //	(l'ensemble des objets PPersist de PEIDA++) au sein du programme
 //	d'analyse interactive *piapp* . Elle constitue en outre l'interface
@@ -58,6 +58,8 @@
 // ......  Gestion des objets nommes, variables globales ............
 struct nobj_diritem {
-  int id;
-  int nobj;
+  int id;                 // Directory Id
+  int nobj;               // Number of objects in directory
+  bool lock;              // True -> directory locked, No Add, del or rename
+  bool keepold;           // True -> When duplicate object name, old object moved to /old
 };
 
@@ -65,9 +67,10 @@
 
 struct nobj_item {
-  AnyDataObj* obj;
-  NObjMgrAdapter* obja;
-  int oid;
-  int dirid;
-  list<int> wrsid;
+  AnyDataObj* obj;             // Object pointer
+  NObjMgrAdapter* obja;        // Object adapter pointer
+  int oid;                     // object Id
+  int dirid;                   // Directory Id
+  list<int> wrsid;             // List of Window Resource Id (Drawer, PIBaseWdg, ...) 
+                               // (for PIStdImgApp)
   bool operator==(nobj_item const& b) const
     { return (this->obj ==  b.obj); }
@@ -116,8 +119,11 @@
   string dirn = "home";
   CreateDir(dirn);
+  SetKeepOldDirAtt(dirn, true);
   dirn = "tmp";
   CreateDir(dirn);
+  SetKeepOldDirAtt(dirn, false);
   dirn = "old";
   CreateDir(dirn);
+  SetKeepOldDirAtt(dirn, false);
   dirn = "home";
   SetCurrentDir(dirn);
@@ -179,14 +185,14 @@
 
 /* --Methode-- */
-void NamedObjMgr::CreateDir(string & dirname)
+bool NamedObjMgr::CreateDir(string & dirname)
 {
 if ( !CheckDirName(dirname) ) {
   cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Invalid name !" << endl;
-  return; 
+  return(false); 
   }
 NObjDirList::iterator it = myDirs->find(dirname);
 if (it != myDirs->end()) {
   cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Existing directory !" << endl;
-  return;
+  return(false);
   }
 myDirId++;
@@ -194,4 +200,6 @@
 di.id = myDirId;
 di.nobj = 0;
+di.lock = false;
+di.keepold = false;
 (*myDirs)[dirname] = di;
 if (myImgApp)  { 
@@ -200,25 +208,30 @@
   }
 cout << "NamedObjMgr::CreateDir() " << dirname << " Created " << endl;
-}
-
-/* --Methode-- */
-void NamedObjMgr::DeleteDir(string & dirname)
+return(true);
+}
+
+/* --Methode-- */
+bool NamedObjMgr::DeleteDir(string & dirname)
 {
 if ( !CheckDirName(dirname) ) {
   cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - Invalid name !" << endl;
-  return; 
+  return(false); 
   }
 NObjDirList::iterator it = myDirs->find(dirname);
 if (it == myDirs->end()) {
   cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - No such directory !" << endl;
-  return;
+  return(false);
   }
 if ((*it).second.nobj > 0) {
   cout << "NamedObjMgr::DeleteDir() " << dirname << " not empty ! " << endl;
-  return;
+  return(false);
+  }
+if ((*it).second.lock ) {
+  cout << "NamedObjMgr::DeleteDir() " << dirname << " locked ! " << endl;
+  return(false);
   }
 if ((*it).second.id < 50) {
   cout << "NamedObjMgr::DeleteDir() " << dirname << " cannot be deleted ! " << endl;
-  return;
+  return(false);
   }
 
@@ -227,20 +240,58 @@
 myDirs->erase(it);
 cout << "amedObjMgr::DeleteDir() " << dirname << " deleted " << endl;  
-}
-
-/* --Methode-- */
-void NamedObjMgr::SetCurrentDir(string & dirname)
+return(true);
+}
+
+/* --Methode-- */
+void NamedObjMgr::LockDir(string & dirname)
+{
+if ( !CheckDirName(dirname) ) return;
+NObjDirList::iterator it = myDirs->find(dirname);
+if (it == myDirs->end()) return;
+(*it).second.lock = true;
+cout << "NamedObjMgr::LockDir() " << dirname << " Locked " << endl;
+return;
+}
+
+/* --Methode-- */
+void NamedObjMgr::UnlockDir(string & dirname)
+{
+if ( !CheckDirName(dirname) ) return;
+NObjDirList::iterator it = myDirs->find(dirname);
+if (it == myDirs->end()) return;
+(*it).second.lock = true;
+cout << "NamedObjMgr::UnlockDir() " << dirname << " Unlocked " << endl;
+return;
+}
+
+/* --Methode-- */
+void NamedObjMgr::SetKeepOldDirAtt(string & dirname, bool keepold)
+{
+if ( !CheckDirName(dirname) ) return;
+NObjDirList::iterator it = myDirs->find(dirname);
+if (it == myDirs->end()) return;
+(*it).second.keepold = keepold;
+cout << "NamedObjMgr::SetKeepOldDirAtt() " << dirname << "  ->  ";
+if ( keepold ) cout << " True " << endl;
+else cout << " False " << endl;
+return;
+}
+
+
+/* --Methode-- */
+bool NamedObjMgr::SetCurrentDir(string & dirname)
 {
 if ( !CheckDirName(dirname) ) {
   cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - Invalid name !" << endl;
-  return; 
+  return(false); 
   }
 NObjDirList::iterator it = myDirs->find(dirname);
 if (it == myDirs->end()) {
   cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - No such directory !" << endl;
-  return;
+  return(false);
   }
 *currDir = dirname;
 cout << "NamedObjMgr::SetCurrentDir() -> " << dirname << endl;
+return(true);
 }
 
@@ -262,5 +313,9 @@
   if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
   k++;
-  cout << k << "- " << (*it).first << "  (NbObj= " << (*it).second.nobj << ")" << endl; 
+  cout << k << "- " << (*it).first;
+  if ( (*it).second.lock )  cout << "  Locked " ;
+  if ( (*it).second.keepold )   cout << "  KeepOld " ;
+  cout << "  (Id= " << (*it).second.id << " NbObj= " << (*it).second.nobj << ")" << endl;
+   
   }
 }
@@ -311,8 +366,8 @@
 
 /* --Methode-- */
-void NamedObjMgr::AddObj(AnyDataObj* obj, string & nom, bool crd)
-{
-
-if (obj == NULL)  return;
+bool NamedObjMgr::AddObj(AnyDataObj* obj, string & nom, bool crd)
+{
+
+if (obj == NULL)  return(false);
 // On verifie si l'objet est deja dans la liste 
 NObjList::iterator it;
@@ -320,5 +375,5 @@
   if ((*it).second.obj == obj) {
     cout << "NamedObjMgr::AddObj() Object already present with name " << (*it).first << endl;
-    return;
+    return(false);
     }
   }
@@ -330,5 +385,5 @@
   if (!crd) {
     cout << "NamedObjMgr::AddObj() No " << nrep << " Directory " << endl;
-    return;
+    return(false);
     }
   else { CreateDir(nrep);  did =  myDirId; }
@@ -342,11 +397,12 @@
 
 nom = '/' + nrep + '/' + nobj;  
+NObjDirList::iterator itr = myDirs->find(nrep);
+if ((*itr).second.lock) {
+  cout << "NamedObjMgr::AddObj() " << nrep << " Locked Directory " << endl;
+  return(false);
+  }
 it = myObjs->find(nom);
 if (it != myObjs->end()) { // l'objet existe deja
-  if (nrep == "tmp") {  // Les objets de /tmp sont jetes
-    cout << "NamedObjMgr::AddObj() - Replacing " << nom << endl;
-    DelObj(nom);
-    }
-  else {  // On met l'ancien objet dans /old
+  if ( (*itr).second.keepold ) { // On met l'ancien objet dans /old
     string on,od;
 //    ParseObjectName((*it).first, od, on); 
@@ -355,4 +411,8 @@
     RenameObj(nom, nomnew);
     }
+  else {  // Sinon, on remplace l'objet
+    cout << "NamedObjMgr::AddObj() - Replacing " << nom << endl;
+    DelObj(nom);
+    }
   }
 
@@ -364,21 +424,23 @@
 (*myObjs)[nom] = no;
 
-NObjDirList::iterator itr = myDirs->find(nrep);
 (*itr).second.nobj++;
 
 cout << "NamedObjMgr::AddObj()  Object " << nom << " ( "  
      << typeid(*obj).name() << " ) added (Total= " << myObjs->size() << ")" << endl;  
-return;
-}
-
-/* --Methode-- */
-void NamedObjMgr::RenameObj(string & nom, string& nomnew)
+return(true);
+}
+
+/* --Methode-- */
+bool NamedObjMgr::RenameObj(string & nom, string& nomnew)
 {
 string n1,r1,n2,r2;
-ParseObjectName(nom, r1, n1);
+int dids = ParseObjectName(nom, r1, n1);
+NObjDirList::iterator itr1 = myDirs->find(r1);
 int did = ParseObjectName(nomnew, r2, n2);
+NObjDirList::iterator itr2 = myDirs->find(r2);
+
 if (did == 0) {
   cout << "NamedObjMgr::RenameObj() Error - No " << r2 << " directory !" << endl;
-  return;
+  return(false);
   }
 nom = '/' + r1 + '/' + n1;
@@ -387,11 +449,18 @@
 if (it1 == myObjs->end()) {
   cout << "NamedObjMgr::RenameObj() Error -  No " << nom << " object !" << endl;
-  return;
+  return(false);
   }
 NObjList::iterator it2 = myObjs->find(nomnew);
 if (it2 != myObjs->end()) {
   cout << "NamedObjMgr::RenameObj() Error -  Object " << nomnew << " exist !" << endl;
-  return;
-  }
+  return(false);
+  }
+
+if ( (*itr1).second.lock || (*itr2).second.lock ) {
+  cout << "NamedObjMgr::RenameObj() Error - Source or destination directory locked !" 
+       << endl;
+  return(false);  
+  }
+
 
 nobj_item no = (*it1).second;
@@ -404,9 +473,9 @@
 (*itr).second.nobj++;
 cout << "NamedObjMgr::RenameObj() - Object " << nom << " renamed to " << nomnew << endl;
-return;
-}
-
-/* --Methode-- */
-void NamedObjMgr::DelObj(string & nom, bool fgd)
+return(true);
+}
+
+/* --Methode-- */
+bool NamedObjMgr::DelObj(string & nom, bool fgd)
 {
 string n1,r1;
@@ -414,5 +483,10 @@
 nom = '/' + r1 + '/' + n1;
 NObjList::iterator it = myObjs->find(nom);
-if (it == myObjs->end()) return; 
+if (it == myObjs->end()) return(false); 
+NObjDirList::iterator itr = myDirs->find(r1);
+if ( (*itr).second.lock  ) {
+  cout << "NamedObjMgr::DelObj() Error - Locked directory " << r1 << endl;
+  return(false);
+  }
 list<int>::iterator ii;
 if (myImgApp) {
@@ -425,14 +499,13 @@
 
 myObjs->erase(it);
-NObjDirList::iterator itr = myDirs->find(r1);
 (*itr).second.nobj--;
 
 if (fgd) cout << "NamedObjMgr::DelObj()  Object " << nom << " deleted (Total= " << myObjs->size() << ")" << endl;
 else  cout << "NamedObjMgr::DelObj()  Object " << nom << " removed (Total= " << myObjs->size() << ")" << endl;
-return;  
-}
-
-/* --Methode-- */
-void NamedObjMgr::DelObj_Id(int oid)
+return(true);  
+}
+
+/* --Methode-- */
+bool NamedObjMgr::DelObj_Id(int oid)
 {
 NObjList::iterator it;
@@ -444,5 +517,6 @@
     break;
   }
-if (of) DelObj(nom, true);
+if (of) return(DelObj(nom, true));
+else return(false);
 }
 
@@ -786,10 +860,13 @@
 int opt = servnobjm->DecodeDispOption(dopt, fgsr);
 
+string n1,r1;
+ParseObjectName(nom, r1, n1);
+
 if (dr) { 
   PIDrawer3D * dr3 = dynamic_cast<PIDrawer3D *>(dr);
-  if(dr3)  wrsid = myImgApp->Disp3DDrawer(dr3, nom, opt);
-  else wrsid = myImgApp->DispScDrawer( dr, nom, opt); 
-  }
-else if (arr) wrsid = myImgApp->DispImage(arr, nom, opt);
+  if(dr3)  wrsid = myImgApp->Disp3DDrawer(dr3, n1, opt);
+  else wrsid = myImgApp->DispScDrawer( dr, n1, opt); 
+  }
+else if (arr) wrsid = myImgApp->DispImage(arr, n1, opt);
 
 if(wrsid != 0) {
@@ -821,8 +898,11 @@
   }
 
+string n1,r1;
+ParseObjectName(nom, r1, n1);
+
 int wrsid = 0;
 bool fgsr = true;
 int opt = servnobjm->DecodeDispOption(dopt, fgsr);
-wrsid = myImgApp->DispImage(arr, nom, opt);
+wrsid = myImgApp->DispImage(arr, n1, opt);
 
 if(wrsid != 0) {
@@ -860,9 +940,12 @@
   }
 
+string n1,r1;
+ParseObjectName(nom, r1, n1);
+
 int wrsid = 0;
 bool fgsr = true;
 int opt = servnobjm->DecodeDispOption(dopt, fgsr);
 PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
-wrsid = myImgApp->Disp3DDrawer(sdr, nom, opt);
+wrsid = myImgApp->Disp3DDrawer(sdr, n1, opt);
 if(wrsid >= 0) {
   NObjList::iterator it = myObjs->find(nom);
@@ -899,4 +982,7 @@
 int opt = servnobjm->DecodeDispOption(dopt, fgsr);
 
+string n1,r1;
+ParseObjectName(nom, r1, n1);
+
 if ( fg3d && (nmz.length()>0) )  { // Display 3D
   PINTuple3D* pin = new PINTuple3D(nt, false);
@@ -904,5 +990,5 @@
   pin->SelectErrBar(erx.c_str(), ery.c_str(), erz.c_str());
   string titre = nmz + "%" + nmy + "%" + nmz;
-  wrsid = myImgApp->Disp3DDrawer(pin, nom, opt, titre);  
+  wrsid = myImgApp->Disp3DDrawer(pin, n1, opt, titre);  
 }
 else {
@@ -912,5 +998,5 @@
   if ( nmz.length()>0 ) pin->SelectWt(nmz.c_str());
   string titre = nmy + "%" + nmx;
-  wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, nom, opt, titre);
+  wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, n1, opt, titre);
   }
 
@@ -965,4 +1051,7 @@
  if(numvary.length()>0) numvy = atoi(numvary.c_str());
  
+ string n1,r1;
+ ParseObjectName(nom, r1, n1);
+
  int wrsid = 0;
  if(numvy>=0) {              // display 3D
@@ -970,10 +1059,10 @@
   pigfd->SelectXY(numvx,numvy);
   pigfd->SelectErrBar(errx,erry,errz);
-  wrsid = myImgApp->Disp3DDrawer(pigfd,nom,opt);  
+  wrsid = myImgApp->Disp3DDrawer(pigfd,n1,opt);  
 } else {                   // display 2D
   PIGenFitDat* pigfd = new PIGenFitDat(((GeneralFitData*)obj),false);
   pigfd->SelectX(numvx);
   pigfd->SelectErrBar(errx,erry);
-  wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,nom,opt);
+  wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,n1,opt);
 }
 
