X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSALOMEDSImpl%2FtestDS.cxx;h=c42bfa2aa97a2a77f7b4f090451b5d4db72ac7b6;hb=e887ad15fe39797f5c0189038938371c74a7abdf;hp=0f8f2f61ba7757d4204443310110063f34b74d3e;hpb=836c34a4e2dd99f1f302a2c3ae93a51cd182368f;p=modules%2Fkernel.git diff --git a/src/SALOMEDSImpl/testDS.cxx b/src/SALOMEDSImpl/testDS.cxx index 0f8f2f61b..c42bfa2aa 100644 --- a/src/SALOMEDSImpl/testDS.cxx +++ b/src/SALOMEDSImpl/testDS.cxx @@ -1,36 +1,37 @@ -// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either +// License as published by the Free Software Foundation; either // version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + //File: testDS.cxx //Author: Sergey RUIN - +// #include #include #include +#include -#include -#include -#include -#include -#include -#include -#include +#include "DF_Document.hxx" +#include "DF_Attribute.hxx" +#include "DF_Label.hxx" +#include "DF_ChildIterator.hxx" #include "SALOMEDSImpl_Attributes.hxx" #include "SALOMEDSImpl_StudyManager.hxx" @@ -39,153 +40,209 @@ #include "SALOMEDSImpl_SObject.hxx" #include "SALOMEDSImpl_SComponent.hxx" #include "SALOMEDSImpl_AttributeParameter.hxx" +#include "SALOMEDSImpl_UseCaseBuilder.hxx" +#include "SALOMEDSImpl_UseCaseIterator.hxx" //#include "SALOMEDSImpl_.hxx" int main (int argc, char * argv[]) { - cout << "Test started " << endl; - - Handle(SALOMEDSImpl_StudyManager) aSM = new SALOMEDSImpl_StudyManager(); - cout << "Manager is created " << endl; - Handle(SALOMEDSImpl_Study) aStudy = aSM->NewStudy("SRN"); - cout << "Study with id = " << aStudy->StudyId() << " is created " << endl; - Handle(SALOMEDSImpl_StudyBuilder) aBuilder = aStudy->NewBuilder(); - cout << "StudyBuilder is created " << endl; - Handle(SALOMEDSImpl_SComponent) aSC = aBuilder->NewComponent("TEST"); - cout << "New component with type " << aSC->ComponentDataType() << " is created " << endl; - Handle(SALOMEDSImpl_SObject) aSO = aBuilder->NewObject(aSC); - cout << "New SObject with ID = " << aSO->GetID() << " is created" << endl; - TCollection_AsciiString anEntry; - TDF_Tool::Entry(aSO->GetLabel(), anEntry); - cout << "An entry of newly created SO is " << anEntry << endl; - Handle(SALOMEDSImpl_AttributeIOR) aIORA = SALOMEDSImpl_AttributeIOR::Set(aSO->GetLabel(), "ior1234"); - cout << "New AttributeIOR is created, it contains " << aIORA->Value() << endl; - Handle(SALOMEDSImpl_GenericAttribute) ga = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aIORA); - cout << "Attribute has type: " << ga->Type() << " and value: " << ga->Save() << endl; - cout << "Just another way to create an attribute: official one :) " << endl; - Handle(TDF_Attribute) aTDFAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName"); - Handle(SALOMEDSImpl_AttributeName) aRN = Handle(SALOMEDSImpl_AttributeName)::DownCast(aTDFAttr); + std::cout << "Test started " << std::endl; + + SALOMEDSImpl_StudyManager* aSM = new SALOMEDSImpl_StudyManager(); + std::cout << "Manager is created " << std::endl; + SALOMEDSImpl_Study* aStudy = aSM->NewStudy("SRN"); + std::cout << "Study with id = " << aStudy->StudyId() << " is created " << std::endl; + + std::cout << "Check the study lock, locking" << std::endl; + aStudy->SetStudyLock("SRN"); + std::cout << "Is study locked = " << aStudy->IsStudyLocked() << std::endl; + std::vector ids = aStudy->GetLockerID(); + for(int i = 0; iUnLockStudy("SRN"); + std::cout << "Is study locked = " << aStudy->IsStudyLocked() << std::endl; + + SALOMEDSImpl_StudyBuilder* aBuilder = aStudy->NewBuilder(); + std::cout << "StudyBuilder is created " << std::endl; + SALOMEDSImpl_SComponent aSC = aBuilder->NewComponent("TEST"); + std::cout << "New component with type " << aSC.ComponentDataType() << " is created " << std::endl; + SALOMEDSImpl_SObject aSO = aBuilder->NewObject(aSC); + std::cout << "New SObject with ID = " << aSO.GetID() << " is created" << std::endl; + std::cout << "An entry of newly created SO is " << aSO.GetLabel().Entry() << std::endl; + SALOMEDSImpl_AttributeIOR* aIORA = SALOMEDSImpl_AttributeIOR::Set(aSO.GetLabel(), "ior1234"); + std::cout << "New AttributeIOR is created, it contains " << dynamic_cast(aIORA)->Value() << std::endl; + std::cout << "Attribute has type: " << aIORA->Type() << " and value: " << aIORA->Save() << std::endl; + std::cout << "Just another way to create an attribute: official one :) " << std::endl; + std::cout << "Is SO null : " << aSO.IsNull()<< std::endl; + DF_Attribute* aTDFAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName"); + SALOMEDSImpl_AttributeName* aRN = dynamic_cast(aTDFAttr); aRN->SetValue("name_attribute"); - cout << " The type = " << aRN->Type() << endl; - ga = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aRN); - cout << "Attribute has type: " << ga->Type() << " and value: " << ga->Save() << endl; - cout << "Check GetObjectPath: " << aStudy->GetObjectPath(aSO) << endl; + std::cout << " The type = " << aRN->Type() << std::endl; + std::cout << "Attribute has type: " << aRN->Type() << " and value: " << aRN->Save() << std::endl; + std::cout << "Check GetObjectPath: " << aStudy->GetObjectPath(aSO) << std::endl; - Handle(SALOMEDSImpl_SObject) aSubSO = aBuilder->NewObject(aSO); + SALOMEDSImpl_SObject aSubSO = aBuilder->NewObject(aSO); aTDFAttr = aBuilder->FindOrCreateAttribute(aSubSO, "AttributeIOR"); - Handle(SALOMEDSImpl_AttributeIOR) aIOR2 = Handle(SALOMEDSImpl_AttributeIOR)::DownCast(aTDFAttr); + SALOMEDSImpl_AttributeIOR* aIOR2 = dynamic_cast(aTDFAttr); aIOR2->SetValue("some ior"); aBuilder->Addreference(aSubSO, aSO); - Handle(SALOMEDSImpl_SObject) aRefObject; - aSubSO->ReferencedObject(aRefObject); - cout << "Check reference : ReferencedObject is " << aRefObject->GetID() << endl; - cout << "Check : Remove object: " << endl; + SALOMEDSImpl_SObject aRefObject; + aSubSO.ReferencedObject(aRefObject); + std::cout << "Check reference : ReferencedObject is " << aRefObject.GetID() << std::endl; + std::cout << "Check : Remove object: " << std::endl; aBuilder->RemoveObject(aSubSO); - cout << "Remove: done" << endl; + std::cout << "Remove: done" << std::endl; + + std::cout << "Try invalid attribute creation" << std::endl; + aTDFAttr = aBuilder->FindOrCreateAttribute(aSubSO, "invalid type"); + std::cout << "Address of created attribute : " << aTDFAttr << std::endl; - cout << "Check AttributeTreeNode " << endl; + std::cout << "Check AttributeUserID" << std::endl; + + aTDFAttr = aBuilder->FindOrCreateAttribute(aSubSO, "AttributeUserID"); + if(aTDFAttr) { + std::cout << "Attribute UserID was created succesfully : id = " << dynamic_cast(aTDFAttr)->Value() << std::endl; + } + else std::cout << "Can't create AttributeUserID" << std::endl; + + std::string id = "0e1c36e6-379b-4d90-ab3b-17a14310e648"; + dynamic_cast(aTDFAttr)->SetValue(id); + std::cout << "SetValue id = " << dynamic_cast(aTDFAttr)->Value() << std::endl; + + std::string id2 = "0e1c36e6-379b-4d90-ab3b-18a14310e648"; + aTDFAttr = aBuilder->FindOrCreateAttribute(aSubSO, "AttributeUserID"+id2); + if(aTDFAttr) { + std::cout << "Attribute UserID was created succesfully : id = " << dynamic_cast(aTDFAttr)->Value() << std::endl; + } + else std::cout << "Can't create AttributeUserID" << std::endl; + + std::cout << "Check AttributeTreeNode " << std::endl; aTDFAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeTreeNode"); - cout << Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aTDFAttr)->Type() << endl; - cout << "Check AttributeTreeNode : done " << endl; + std::cout << dynamic_cast(aTDFAttr)->Type() << std::endl; + std::cout << "Check AttributeTreeNode : done " << std::endl; aTDFAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeParameter"); - cout << Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aTDFAttr)->Type() << endl; + std::cout << dynamic_cast(aTDFAttr)->Type() << std::endl; - cout << "Check the attributes on SObject" << endl; - Handle(TColStd_HSequenceOfTransient) aSeq = aSO->GetAllAttributes(); - for(int i = 1; i <= aSeq->Length(); i++) - cout << "Found: " << Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aSeq->Value(i))->Type() << endl; + std::cout << "Check the attributes on SObject" << std::endl; + std::vector aSeq = aSO.GetAllAttributes(); + for(int i = 0; i < aSeq.size(); i++) + std::cout << "Found: " << dynamic_cast(aSeq[i])->Type() << std::endl; + std::cout << "Check UseCase" << std::endl; + SALOMEDSImpl_UseCaseBuilder* ucb = aStudy->GetUseCaseBuilder(); + ucb->AddUseCase("use_case1"); + ucb->AddUseCase("use_case2"); + SALOMEDSImpl_UseCaseIterator ucitr = ucb->GetUseCaseIterator(SALOMEDSImpl_SObject()); + ucitr.Init(false); + std::cout << "More? : " << ucitr.More() << std::endl; - cout << "Check AttributeParameter " << endl; + std::cout << "Check AttributeParameter " << std::endl; - Handle(SALOMEDSImpl_AttributeParameter) AP = Handle(SALOMEDSImpl_AttributeParameter)::DownCast(aTDFAttr); + SALOMEDSImpl_AttributeParameter* AP = dynamic_cast(aTDFAttr); - cout << "AttributeParameter with type : " << AP->Type() << endl; + std::cout << "AttributeParameter with type : " << AP->Type() << std::endl; AP->SetInt("1", 123); - cout << "IsSet for int: " << AP->IsSet("1", PT_INTEGER) << " value : " << AP->GetInt("1") << endl; + std::cout << "IsSet for int: " << AP->IsSet("1", PT_INTEGER) << " value : " << AP->GetInt("1") << std::endl; //for(int i = 2; i < 5; i++) AP->SetInt(i, i*i); AP->SetReal("1", 123.123); - cout << "IsSet for real: " << AP->IsSet("1", PT_REAL) << " value : " << AP->GetReal("1") << endl; + std::cout << "IsSet for real: " << AP->IsSet("1", PT_REAL) << " value : " << AP->GetReal("1") << std::endl; //for(int i = 2; i < 5; i++) AP->SetReal(i, 0.1); AP->SetString("1", "value is 123.123!"); - cout << "IsSet for string: " << AP->IsSet("1", PT_STRING) << " value : " << AP->GetString("1") << endl; + std::cout << "IsSet for string: " << AP->IsSet("1", PT_STRING) << " value : " << AP->GetString("1") << std::endl; /* for(int i = 2; i < 5; i++) { - TCollection_AsciiString s((double)(1.0/i)); - cout << "Setting for " << i << " value : " << s << endl; + std::string s((double)(1.0/i)); + std::cout << "Setting for " << i << " value : " << s << std::endl; AP->SetString(i, s); } */ AP->SetBool("1", true); - cout << "IsSet for bool: " << AP->IsSet("1", PT_BOOLEAN) << " value : " << AP->GetBool("1") << endl; + std::cout << "IsSet for bool: " << AP->IsSet("1", PT_BOOLEAN) << " value : " << AP->GetBool("1") << std::endl; //for(int i = 2; i < 5; i++) AP->SetBool(i, 0); - vector v; + std::vector v; v.push_back(111.111); v.push_back(222.22222); v.push_back(333.3333333); AP->SetRealArray("1", v); - cout << "IsSet for array: " << AP->IsSet("1", PT_REALARRAY); - vector v2 = AP->GetRealArray("1"); - cout.precision(10); - cout << " values : "; - for(int i = 0; iIsSet("1", PT_REALARRAY); + std::vector v2 = AP->GetRealArray("1"); + std::cout.precision(10); + std::cout << " values : "; + for(int i = 0; iSetRealArray("2", v); - vector vi; + std::vector vi; vi.push_back(1); vi.push_back(2); AP->SetIntArray("2", vi); - vector vs; + std::vector vs; vs.push_back("hello, "); vs.push_back("world!"); AP->SetStrArray("3", vs); - TCollection_AsciiString as = AP->Save(); - cout << "AS = " << as << endl; + std::string as = AP->Save(); + std::cout << "AS = " << as << std::endl; AP->Load(as); - cout << "Restored string with id = 1 is: " << AP->GetString("1") << endl; - cout << "Restored int with id = 2 is: " << AP->GetInt("1") << endl; - cout << "Restored real with id = 3 is: " << AP->GetReal("1") << endl; - cout << "Restored bool with id = 1 is: " << AP->GetBool("1") << endl; + std::cout << "Restored string with id = 1 is: " << AP->GetString("1") << std::endl; + std::cout << "Restored int with id = 2 is: " << AP->GetInt("1") << std::endl; + std::cout << "Restored real with id = 3 is: " << AP->GetReal("1") << std::endl; + std::cout << "Restored bool with id = 1 is: " << AP->GetBool("1") << std::endl; v2 = AP->GetRealArray("2"); - cout << "Restored real array with id = 2 is: "; - for(int i = 0; iGetIntArray("2"); - cout << "Restored int array with id = 2 is: "; - for(int i = 0; iGetStrArray("3"); - cout << "Restored string array with id = 2 is: "; - for(int i = 0; iRemoveID("1", PT_INTEGER); - cout << "IsSet with id = 1, type = PT_INTEGER : " << AP->IsSet("1", PT_INTEGER) << endl; - cout << "Check RemoveID is done" << endl; + std::cout << "IsSet with id = 1, type = PT_INTEGER : " << AP->IsSet("1", PT_INTEGER) << std::endl; + std::cout << "Check RemoveID is done" << std::endl; - cout << "Check AttributeParameter : done" << endl; + std::cout << "Check AttributeParameter : done" << std::endl; - cout << "Test finished " << endl; + + SALOMEDSImpl_SComponent tst = aBuilder->NewComponent("TEST2"); + aSO = aBuilder->NewObject(tst); + SALOMEDSImpl_SObject ss = aBuilder->NewObjectToTag(aSO, 3); + aBuilder->NewObjectToTag(ss, 1); + aBuilder->NewObjectToTag(ss, 3); + SALOMEDSImpl_SObject ss2 = aBuilder->NewObjectToTag(aSO, 2); + aBuilder->NewObjectToTag(ss, 2); + + SALOMEDSImpl_ChildIterator ci=aStudy->NewChildIterator(tst); + for(ci.InitEx(true); ci.More(); ci.Next()) + std::cout << "######## " << ci.Value().GetID() << std::endl; + + DF_ChildIterator dci(tst.GetLabel(), true); + for(; dci.More(); dci.Next()) + std::cout << "###### DF: " << dci.Value().Entry() << std::endl; + + std::cout << "Test finished " << std::endl; return 0; }