X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSALOMEDSImpl%2FtestDS.cxx;h=1328442a6c13210939cc93a2c16b3ef7ffed2271;hb=e71062fb69534a43e6762c9b7caea19c33b5e2d6;hp=8adcc07b57df3aca835959cac70afc1107d15605;hpb=35960e77d7f9f2a5cac7d6550c23f12943bc4378;p=modules%2Fkernel.git diff --git a/src/SALOMEDSImpl/testDS.cxx b/src/SALOMEDSImpl/testDS.cxx index 8adcc07b5..1328442a6 100644 --- a/src/SALOMEDSImpl/testDS.cxx +++ b/src/SALOMEDSImpl/testDS.cxx @@ -1,35 +1,36 @@ -// Copyright (C) 2005 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 -// 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 -// Lesser General Public License for more details. +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE // -// 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 +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// See http://www.salome-platform.org/ +// 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 +// 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 +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// 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" @@ -37,60 +38,211 @@ #include "SALOMEDSImpl_StudyBuilder.hxx" #include "SALOMEDSImpl_SObject.hxx" #include "SALOMEDSImpl_SComponent.hxx" +#include "SALOMEDSImpl_AttributeParameter.hxx" +#include "SALOMEDSImpl_UseCaseBuilder.hxx" +#include "SALOMEDSImpl_UseCaseIterator.hxx" + //#include "SALOMEDSImpl_.hxx" +using namespace std; + int main (int argc, char * argv[]) { cout << "Test started " << endl; - Handle(SALOMEDSImpl_StudyManager) aSM = new SALOMEDSImpl_StudyManager(); + SALOMEDSImpl_StudyManager* aSM = new SALOMEDSImpl_StudyManager(); cout << "Manager is created " << endl; - Handle(SALOMEDSImpl_Study) aStudy = aSM->NewStudy("SRN"); + SALOMEDSImpl_Study* aStudy = aSM->NewStudy("SRN"); cout << "Study with id = " << aStudy->StudyId() << " is created " << endl; - Handle(SALOMEDSImpl_StudyBuilder) aBuilder = aStudy->NewBuilder(); + + cout << "Check the study lock, locking" << endl; + aStudy->SetStudyLock("SRN"); + cout << "Is study locked = " << aStudy->IsStudyLocked() << endl; + vector ids = aStudy->GetLockerID(); + for(int i = 0; iUnLockStudy("SRN"); + cout << "Is study locked = " << aStudy->IsStudyLocked() << endl; + + 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; + SALOMEDSImpl_SComponent aSC = aBuilder->NewComponent("TEST"); + cout << "New component with type " << aSC.ComponentDataType() << " is created " << endl; + SALOMEDSImpl_SObject aSO = aBuilder->NewObject(aSC); + cout << "New SObject with ID = " << aSO.GetID() << " is created" << endl; + cout << "An entry of newly created SO is " << aSO.GetLabel().Entry() << endl; + SALOMEDSImpl_AttributeIOR* aIORA = SALOMEDSImpl_AttributeIOR::Set(aSO.GetLabel(), "ior1234"); + cout << "New AttributeIOR is created, it contains " << dynamic_cast(aIORA)->Value() << endl; + cout << "Attribute has type: " << aIORA->Type() << " and value: " << aIORA->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); + cout << "Is SO null : " << aSO.IsNull()<< 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 << "Attribute has type: " << aRN->Type() << " and value: " << aRN->Save() << endl; cout << "Check GetObjectPath: " << aStudy->GetObjectPath(aSO) << 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; + SALOMEDSImpl_SObject aRefObject; + aSubSO.ReferencedObject(aRefObject); + cout << "Check reference : ReferencedObject is " << aRefObject.GetID() << endl; cout << "Check : Remove object: " << endl; aBuilder->RemoveObject(aSubSO); cout << "Remove: done" << 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; + cout << "Try invalid attribute creation" << endl; + aTDFAttr = aBuilder->FindOrCreateAttribute(aSubSO, "invalid type"); + cout << "Address of created attribute : " << aTDFAttr << endl; + + cout << "Check AttributeUserID" << endl; + + aTDFAttr = aBuilder->FindOrCreateAttribute(aSubSO, "AttributeUserID"); + if(aTDFAttr) { + cout << "Attribute UserID was created succesfully : id = " << dynamic_cast(aTDFAttr)->Value() << endl; + } + else cout << "Can't create AttributeUserID" << endl; + + string id = "0e1c36e6-379b-4d90-ab3b-17a14310e648"; + dynamic_cast(aTDFAttr)->SetValue(id); + cout << "SetValue id = " << dynamic_cast(aTDFAttr)->Value() << endl; + + string id2 = "0e1c36e6-379b-4d90-ab3b-18a14310e648"; + aTDFAttr = aBuilder->FindOrCreateAttribute(aSubSO, "AttributeUserID"+id2); + if(aTDFAttr) { + cout << "Attribute UserID was created succesfully : id = " << dynamic_cast(aTDFAttr)->Value() << endl; + } + else cout << "Can't create AttributeUserID" << endl; cout << "Check AttributeTreeNode " << endl; aTDFAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeTreeNode"); - cout << Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aTDFAttr)->Type() << endl; + cout << dynamic_cast(aTDFAttr)->Type() << endl; cout << "Check AttributeTreeNode : done " << endl; + aTDFAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeParameter"); + cout << dynamic_cast(aTDFAttr)->Type() << endl; + + cout << "Check the attributes on SObject" << endl; + vector aSeq = aSO.GetAllAttributes(); + for(int i = 0; i < aSeq.size(); i++) + cout << "Found: " << dynamic_cast(aSeq[i])->Type() << endl; + + + cout << "Check UseCase" << endl; + SALOMEDSImpl_UseCaseBuilder* ucb = aStudy->GetUseCaseBuilder(); + ucb->AddUseCase("use_case1"); + ucb->AddUseCase("use_case2"); + SALOMEDSImpl_UseCaseIterator ucitr = ucb->GetUseCaseIterator(SALOMEDSImpl_SObject()); + ucitr.Init(false); + cout << "More? : " << ucitr.More() << endl; + + cout << "Check AttributeParameter " << endl; + + SALOMEDSImpl_AttributeParameter* AP = dynamic_cast(aTDFAttr); + + cout << "AttributeParameter with type : " << AP->Type() << endl; + + AP->SetInt("1", 123); + cout << "IsSet for int: " << AP->IsSet("1", PT_INTEGER) << " value : " << AP->GetInt("1") << 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; + //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; + /* + for(int i = 2; i < 5; i++) { + string s((double)(1.0/i)); + cout << "Setting for " << i << " value : " << s << endl; + AP->SetString(i, s); + } + */ + + AP->SetBool("1", true); + cout << "IsSet for bool: " << AP->IsSet("1", PT_BOOLEAN) << " value : " << AP->GetBool("1") << endl; + //for(int i = 2; i < 5; i++) AP->SetBool(i, 0); + + 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; iSetRealArray("2", v); + + vector vi; + vi.push_back(1); + vi.push_back(2); + AP->SetIntArray("2", vi); + + vector vs; + vs.push_back("hello, "); + vs.push_back("world!"); + AP->SetStrArray("3", vs); + + string as = AP->Save(); + cout << "AS = " << as << 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; + + 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; + + cout << "Check AttributeParameter : done" << 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()) + cout << "######## " << ci.Value().GetID() << endl; + + DF_ChildIterator dci(tst.GetLabel(), true); + for(; dci.More(); dci.Next()) + cout << "###### DF: " << dci.Value().Entry() << endl; + cout << "Test finished " << endl; return 0; }