Back to index

salome-kernel  6.5.0
testDS.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //File:    testDS.cxx
00024 //Author:  Sergey RUIN
00025 //
00026 #include <stdio.h>
00027 #include <iostream> 
00028 #include <vector>
00029 #include <string>
00030 
00031 #include "DF_Document.hxx"
00032 #include "DF_Attribute.hxx"
00033 #include "DF_Label.hxx"
00034 #include "DF_ChildIterator.hxx"
00035 
00036 #include "SALOMEDSImpl_Attributes.hxx"
00037 #include "SALOMEDSImpl_StudyManager.hxx"
00038 #include "SALOMEDSImpl_Study.hxx"
00039 #include "SALOMEDSImpl_StudyBuilder.hxx"
00040 #include "SALOMEDSImpl_SObject.hxx"
00041 #include "SALOMEDSImpl_SComponent.hxx"
00042 #include "SALOMEDSImpl_AttributeParameter.hxx"
00043 #include "SALOMEDSImpl_UseCaseBuilder.hxx"
00044 #include "SALOMEDSImpl_UseCaseIterator.hxx"
00045 
00046 //#include "SALOMEDSImpl_.hxx"
00047 
00048 int main (int argc, char * argv[])
00049 {
00050   std::cout << "Test started " << std::endl;
00051 
00052   SALOMEDSImpl_StudyManager* aSM = new SALOMEDSImpl_StudyManager();
00053   std::cout << "Manager is created " << std::endl;
00054   SALOMEDSImpl_Study* aStudy = aSM->NewStudy("SRN");
00055   std::cout << "Study with id = " << aStudy->StudyId() << " is created " << std::endl; 
00056 
00057   std::cout << "Check the study lock, locking"   << std::endl;
00058   aStudy->SetStudyLock("SRN");
00059   std::cout << "Is study locked = " << aStudy->IsStudyLocked() << std::endl;
00060   std::vector<std::string> ids = aStudy->GetLockerID();
00061   for(int i = 0; i<ids.size(); i++)
00062     std::cout << "Get study locker : " << ids[i] << std::endl;
00063   aStudy->UnLockStudy("SRN");
00064   std::cout << "Is study locked = " << aStudy->IsStudyLocked()  << std::endl;
00065 
00066   SALOMEDSImpl_StudyBuilder* aBuilder = aStudy->NewBuilder();
00067   std::cout << "StudyBuilder is created " << std::endl;
00068   SALOMEDSImpl_SComponent aSC = aBuilder->NewComponent("TEST");
00069   std::cout << "New component with type " << aSC.ComponentDataType() << " is created " << std::endl;
00070   SALOMEDSImpl_SObject aSO = aBuilder->NewObject(aSC);
00071   std::cout << "New SObject with  ID = " << aSO.GetID() << " is created"  << std::endl;
00072   std::cout << "An entry of newly created SO is "  <<  aSO.GetLabel().Entry() << std::endl;
00073   SALOMEDSImpl_AttributeIOR* aIORA = SALOMEDSImpl_AttributeIOR::Set(aSO.GetLabel(), "ior1234");
00074   std::cout << "New AttributeIOR is created, it contains " << dynamic_cast<SALOMEDSImpl_AttributeIOR*>(aIORA)->Value() << std::endl;
00075   std::cout << "Attribute has type: " << aIORA->Type() << " and value: " << aIORA->Save() << std::endl; 
00076   std::cout << "Just another way to create an attribute: official one :) " << std::endl;
00077   std::cout << "Is SO null : " << aSO.IsNull()<< std::endl;
00078   DF_Attribute* aTDFAttr =  aBuilder->FindOrCreateAttribute(aSO, "AttributeName");  
00079   SALOMEDSImpl_AttributeName* aRN = dynamic_cast<SALOMEDSImpl_AttributeName*>(aTDFAttr);
00080   aRN->SetValue("name_attribute");
00081   std::cout << " The type = " << aRN->Type() << std::endl;
00082   std::cout << "Attribute has type: " << aRN->Type() << " and value: " << aRN->Save() << std::endl;   
00083   std::cout << "Check GetObjectPath: " << aStudy->GetObjectPath(aSO) << std::endl;
00084   
00085   SALOMEDSImpl_SObject aSubSO = aBuilder->NewObject(aSO);
00086   aTDFAttr =  aBuilder->FindOrCreateAttribute(aSubSO, "AttributeIOR");  
00087   SALOMEDSImpl_AttributeIOR* aIOR2 = dynamic_cast<SALOMEDSImpl_AttributeIOR*>(aTDFAttr);
00088   aIOR2->SetValue("some ior");
00089   aBuilder->Addreference(aSubSO, aSO);
00090   SALOMEDSImpl_SObject aRefObject;
00091   aSubSO.ReferencedObject(aRefObject);
00092   std::cout << "Check reference : ReferencedObject is " << aRefObject.GetID() << std::endl;
00093   std::cout << "Check : Remove object: " << std::endl;
00094   aBuilder->RemoveObject(aSubSO);
00095   std::cout << "Remove: done" << std::endl;
00096 
00097   std::cout << "Try invalid attribute creation" << std::endl;
00098   aTDFAttr = aBuilder->FindOrCreateAttribute(aSubSO, "invalid type");
00099   std::cout << "Address of created attribute : " << aTDFAttr << std::endl;
00100 
00101   std::cout << "Check AttributeUserID"   << std::endl;
00102   
00103   aTDFAttr = aBuilder->FindOrCreateAttribute(aSubSO, "AttributeUserID");
00104   if(aTDFAttr) {
00105     std::cout << "Attribute UserID was created succesfully : id = " << dynamic_cast<SALOMEDSImpl_AttributeUserID*>(aTDFAttr)->Value() << std::endl;
00106   }
00107   else std::cout << "Can't create AttributeUserID"   << std::endl;
00108   
00109   std::string id = "0e1c36e6-379b-4d90-ab3b-17a14310e648";
00110   dynamic_cast<SALOMEDSImpl_AttributeUserID*>(aTDFAttr)->SetValue(id);
00111   std::cout << "SetValue id = " << dynamic_cast<SALOMEDSImpl_AttributeUserID*>(aTDFAttr)->Value()  << std::endl;
00112 
00113   std::string id2 = "0e1c36e6-379b-4d90-ab3b-18a14310e648";
00114   aTDFAttr = aBuilder->FindOrCreateAttribute(aSubSO, "AttributeUserID"+id2);
00115   if(aTDFAttr) {
00116     std::cout << "Attribute UserID was created succesfully : id = " << dynamic_cast<SALOMEDSImpl_AttributeUserID*>(aTDFAttr)->Value() << std::endl;
00117   }
00118   else std::cout << "Can't create AttributeUserID"   << std::endl;
00119 
00120   std::cout << "Check AttributeTreeNode " << std::endl;
00121   aTDFAttr =  aBuilder->FindOrCreateAttribute(aSO, "AttributeTreeNode");  
00122   std::cout << dynamic_cast<SALOMEDSImpl_GenericAttribute*>(aTDFAttr)->Type() << std::endl;
00123   std::cout << "Check AttributeTreeNode : done " << std::endl;
00124 
00125   aTDFAttr =  aBuilder->FindOrCreateAttribute(aSO, "AttributeParameter");  
00126   std::cout << dynamic_cast<SALOMEDSImpl_GenericAttribute*>(aTDFAttr)->Type() << std::endl;
00127 
00128   std::cout << "Check the attributes on SObject" << std::endl;
00129   std::vector<DF_Attribute*> aSeq = aSO.GetAllAttributes();
00130   for(int i = 0; i < aSeq.size(); i++) 
00131     std::cout << "Found: " << dynamic_cast<SALOMEDSImpl_GenericAttribute*>(aSeq[i])->Type() << std::endl;
00132 
00133 
00134   std::cout << "Check UseCase"   << std::endl;
00135   SALOMEDSImpl_UseCaseBuilder* ucb = aStudy->GetUseCaseBuilder();
00136   ucb->AddUseCase("use_case1");
00137   ucb->AddUseCase("use_case2");
00138   SALOMEDSImpl_UseCaseIterator ucitr = ucb->GetUseCaseIterator(SALOMEDSImpl_SObject());
00139   ucitr.Init(false);
00140   std::cout << "More? : " << ucitr.More() << std::endl;
00141 
00142   std::cout << "Check AttributeParameter "   << std::endl;
00143 
00144   SALOMEDSImpl_AttributeParameter* AP = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(aTDFAttr);
00145 
00146   std::cout << "AttributeParameter with type : " << AP->Type() << std::endl;
00147   
00148   AP->SetInt("1", 123);
00149   std::cout << "IsSet for int: " << AP->IsSet("1", PT_INTEGER) << " value : " << AP->GetInt("1") << std::endl;
00150   //for(int i = 2; i < 5; i++) AP->SetInt(i, i*i);
00151 
00152   AP->SetReal("1", 123.123);
00153   std::cout << "IsSet for real: " << AP->IsSet("1", PT_REAL) << " value : " << AP->GetReal("1") << std::endl;
00154   //for(int i = 2; i < 5; i++) AP->SetReal(i, 0.1);
00155 
00156   AP->SetString("1", "value is 123.123!");
00157   std::cout << "IsSet for string: " << AP->IsSet("1", PT_STRING) << " value : " << AP->GetString("1") << std::endl; 
00158   /*
00159   for(int i = 2; i < 5; i++) {
00160     std::string s((double)(1.0/i));
00161     std::cout << "Setting for " << i << " value : " << s  << std::endl;
00162     AP->SetString(i, s); 
00163   }
00164   */
00165 
00166   AP->SetBool("1", true);
00167   std::cout << "IsSet for bool: " << AP->IsSet("1", PT_BOOLEAN) << " value : " << AP->GetBool("1") << std::endl;
00168   //for(int i = 2; i < 5; i++) AP->SetBool(i, 0);
00169   
00170   std::vector<double> v;
00171   v.push_back(111.111);
00172   v.push_back(222.22222);
00173   v.push_back(333.3333333);
00174   AP->SetRealArray("1", v);
00175   std::cout << "IsSet for array: " << AP->IsSet("1", PT_REALARRAY);
00176   std::vector<double> v2 = AP->GetRealArray("1");
00177   std::cout.precision(10);
00178   std::cout << " values :  "; 
00179   for(int i = 0; i<v2.size(); i++) std::cout << v2[i] << " ";
00180   std::cout << std::endl;
00181   
00182   v[0] = 211.111;
00183   v[1] = 422.22222;
00184   v[2] = 633.3333333;
00185   AP->SetRealArray("2", v);
00186 
00187   std::vector<int> vi;
00188   vi.push_back(1);
00189   vi.push_back(2);
00190   AP->SetIntArray("2", vi);
00191   
00192   std::vector<std::string> vs;
00193   vs.push_back("hello, ");
00194   vs.push_back("world!");
00195   AP->SetStrArray("3", vs);        
00196 
00197   std::string as = AP->Save();
00198   std::cout << "AS = " << as << std::endl;
00199   AP->Load(as);
00200   
00201   std::cout << "Restored string with id = 1 is: " << AP->GetString("1") << std::endl;
00202   std::cout << "Restored int with id = 2 is: " << AP->GetInt("1")  << std::endl;
00203   std::cout << "Restored real with id = 3 is: " << AP->GetReal("1")  << std::endl;
00204   std::cout << "Restored bool with id = 1 is: " << AP->GetBool("1")  << std::endl;
00205   
00206   v2 = AP->GetRealArray("2");
00207   std::cout << "Restored real array with id = 2 is: ";
00208   for(int i = 0; i<v2.size(); i++) std::cout << v2[i] << " ";
00209   std::cout << std::endl;
00210 
00211   vi = AP->GetIntArray("2");
00212   std::cout << "Restored int array with id = 2 is: ";
00213   for(int i = 0; i<vi.size(); i++) std::cout << vi[i] << " ";
00214   std::cout << std::endl;
00215   
00216   vs = AP->GetStrArray("3");
00217   std::cout << "Restored string array with id = 2 is: ";
00218   for(int i = 0; i<vs.size(); i++) std::cout << vs[i] << " ";
00219   std::cout << std::endl;
00220 
00221   std::cout << "Check RemoveID 1 with type PT_INTEGER" << std::endl;
00222   AP->RemoveID("1", PT_INTEGER);
00223   std::cout << "IsSet with id = 1, type = PT_INTEGER : " << AP->IsSet("1", PT_INTEGER)  << std::endl;
00224   std::cout << "Check RemoveID is done" << std::endl;
00225   
00226   std::cout << "Check AttributeParameter : done"   << std::endl;
00227 
00228   
00229   SALOMEDSImpl_SComponent tst = aBuilder->NewComponent("TEST2");
00230   aSO = aBuilder->NewObject(tst);
00231   SALOMEDSImpl_SObject ss = aBuilder->NewObjectToTag(aSO, 3);
00232   aBuilder->NewObjectToTag(ss, 1);
00233   aBuilder->NewObjectToTag(ss, 3);
00234   SALOMEDSImpl_SObject ss2 = aBuilder->NewObjectToTag(aSO, 2);
00235   aBuilder->NewObjectToTag(ss, 2);
00236 
00237   SALOMEDSImpl_ChildIterator ci=aStudy->NewChildIterator(tst);
00238   for(ci.InitEx(true); ci.More(); ci.Next())
00239     std::cout << "######## " << ci.Value().GetID() << std::endl;
00240 
00241   DF_ChildIterator dci(tst.GetLabel(), true);
00242   for(; dci.More(); dci.Next()) 
00243     std::cout << "###### DF:  " << dci.Value().Entry() << std::endl;
00244 
00245   std::cout << "Test finished " << std::endl;    
00246   return 0;
00247 }
00248