X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSALOMEDSImpl%2FtestDS.cxx;h=1328442a6c13210939cc93a2c16b3ef7ffed2271;hb=e71062fb69534a43e6762c9b7caea19c33b5e2d6;hp=df4d15d1b3f476ae37949c2edd1c57deffb351e1;hpb=e6bfea36374791cd31c274a2f97df90dc60ddaf3;p=modules%2Fkernel.git diff --git a/src/SALOMEDSImpl/testDS.cxx b/src/SALOMEDSImpl/testDS.cxx index df4d15d1b..1328442a6 100644 --- a/src/SALOMEDSImpl/testDS.cxx +++ b/src/SALOMEDSImpl/testDS.cxx @@ -1,36 +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/ or email : webmaster.salome@opencascade.com +// 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" @@ -39,69 +39,110 @@ #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 << "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 << Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aTDFAttr)->Type() << endl; + cout << dynamic_cast(aTDFAttr)->Type() << 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; + 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; - Handle(SALOMEDSImpl_AttributeParameter) AP = Handle(SALOMEDSImpl_AttributeParameter)::DownCast(aTDFAttr); + SALOMEDSImpl_AttributeParameter* AP = dynamic_cast(aTDFAttr); cout << "AttributeParameter with type : " << AP->Type() << endl; @@ -117,7 +158,7 @@ int main (int argc, char * argv[]) cout << "IsSet for string: " << AP->IsSet("1", PT_STRING) << " value : " << AP->GetString("1") << endl; /* for(int i = 2; i < 5; i++) { - TCollection_AsciiString s((double)(1.0/i)); + string s((double)(1.0/i)); cout << "Setting for " << i << " value : " << s << endl; AP->SetString(i, s); } @@ -154,7 +195,7 @@ int main (int argc, char * argv[]) vs.push_back("world!"); AP->SetStrArray("3", vs); - TCollection_AsciiString as = AP->Save(); + string as = AP->Save(); cout << "AS = " << as << endl; AP->Load(as); @@ -185,6 +226,23 @@ int main (int argc, char * argv[]) 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; }