1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESH_Gen_i_1.cxx
23 // Created : Thu Oct 21 17:24:06 2004
24 // Author : Edward AGAPOV (eap)
27 #include "SMESH_Gen_i.hxx"
29 #include "SMESHDS_Mesh.hxx"
30 #include "SMESH_Algo_i.hxx"
31 #include "SMESH_Comment.hxx"
32 #include "SMESH_Group_i.hxx"
33 #include "SMESH_Hypothesis_i.hxx"
34 #include "SMESH_Mesh_i.hxx"
35 #include "SMESH_subMesh_i.hxx"
37 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
39 #include <utilities.h>
40 #include <Utils_ExceptHandlers.hxx>
41 #include <SALOMEDS_wrap.hxx>
42 #include <SALOMEDS_Attributes_wrap.hxx>
43 #include <SALOME_KernelServices.hxx>
45 #include <TCollection_AsciiString.hxx>
46 #include <TopoDS_Solid.hxx>
51 static int MYDEBUG = 0;
53 static int MYDEBUG = 0;
58 //=============================================================================
60 * Get...Tag [ static ]
62 * Methods which determine SMESH data model structure
64 //=============================================================================
66 long SMESH_Gen_i::GetHypothesisRootTag()
68 return SMESH::Tag_HypothesisRoot;
71 long SMESH_Gen_i::GetAlgorithmsRootTag()
73 return SMESH::Tag_AlgorithmsRoot;
76 long SMESH_Gen_i::GetRefOnShapeTag()
78 return SMESH::Tag_RefOnShape;
81 long SMESH_Gen_i::GetRefOnAppliedHypothesisTag()
83 return SMESH::Tag_RefOnAppliedHypothesis;
86 long SMESH_Gen_i::GetRefOnAppliedAlgorithmsTag()
88 return SMESH::Tag_RefOnAppliedAlgorithms;
91 long SMESH_Gen_i::GetSubMeshOnVertexTag()
93 return SMESH::Tag_SubMeshOnVertex;
96 long SMESH_Gen_i::GetSubMeshOnEdgeTag()
98 return SMESH::Tag_SubMeshOnEdge;
101 long SMESH_Gen_i::GetSubMeshOnFaceTag()
103 return SMESH::Tag_SubMeshOnFace;
106 long SMESH_Gen_i::GetSubMeshOnSolidTag()
108 return SMESH::Tag_SubMeshOnSolid;
111 long SMESH_Gen_i::GetSubMeshOnCompoundTag()
113 return SMESH::Tag_SubMeshOnCompound;
116 long SMESH_Gen_i::GetSubMeshOnWireTag()
118 return SMESH::Tag_SubMeshOnWire;
121 long SMESH_Gen_i::GetSubMeshOnShellTag()
123 return SMESH::Tag_SubMeshOnShell;
126 long SMESH_Gen_i::GetNodeGroupsTag()
128 return SMESH::Tag_NodeGroups;
131 long SMESH_Gen_i::GetEdgeGroupsTag()
133 return SMESH::Tag_EdgeGroups;
136 long SMESH_Gen_i::GetFaceGroupsTag()
138 return SMESH::Tag_FaceGroups;
141 long SMESH_Gen_i::GetVolumeGroupsTag()
143 return SMESH::Tag_VolumeGroups;
146 long SMESH_Gen_i::Get0DElementsGroupsTag()
148 return SMESH::Tag_0DElementsGroups;
151 long SMESH_Gen_i::GetBallElementsGroupsTag()
153 return SMESH::Tag_BallElementsGroups;
156 //=============================================================================
158 * SMESH_Gen_i::CanPublishInStudy
160 * Returns true if object can be published in the study
162 //=============================================================================
164 bool SMESH_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
166 if(MYDEBUG) MESSAGE("CanPublishInStudy - "<<!CORBA::is_nil(getStudyServant()));
168 if ( !myIsEnablePublish )
171 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(theIOR);
172 if( !aMesh->_is_nil() )
175 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(theIOR);
176 if( !aSubMesh->_is_nil() )
179 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(theIOR);
180 if( !aHyp->_is_nil() )
183 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
184 if( !aGroup->_is_nil() )
187 if(MYDEBUG) MESSAGE("CanPublishInStudy--CANT");
191 //=======================================================================
192 //function : ObjectToSObject
193 //purpose : Put a result into a SALOMEDS::SObject_wrap or call UnRegister()!
194 //=======================================================================
196 SALOMEDS::SObject_ptr SMESH_Gen_i::ObjectToSObject(CORBA::Object_ptr theObject)
198 SALOMEDS::SObject_wrap aSO;
199 if ( !CORBA::is_nil( theObject ))
201 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theObject );
202 aSO = getStudyServant()->FindObjectIOR( objStr.in() );
207 //=======================================================================
208 //function : GetStudyPtr
209 //purpose : Get study from naming service
210 //=======================================================================
211 SALOMEDS::Study_var SMESH_Gen_i::getStudyServant()
213 return SALOMEDS::Study::_duplicate(KERNEL::getStudyServant());
216 //=======================================================================
217 //function : objectToServant
219 //=======================================================================
221 template<typename T> static inline T* objectToServant( CORBA::Object_ptr theIOR )
223 return dynamic_cast<T*>( SMESH_Gen_i::GetServant( theIOR ).in() );
226 //=======================================================================
227 //function : ShapeToGeomObject
229 //=======================================================================
231 GEOM::GEOM_Object_ptr SMESH_Gen_i::ShapeToGeomObject (const TopoDS_Shape& theShape )
233 GEOM::GEOM_Object_var aShapeObj;
234 if ( !theShape.IsNull() ) {
235 GEOM_Client* aClient = GetShapeReader();
236 TCollection_AsciiString IOR;
237 if ( aClient && aClient->Find( theShape, IOR ))
239 CORBA::Object_var obj = GetORB()->string_to_object( IOR.ToCString() );
240 aShapeObj = GEOM::GEOM_Object::_narrow ( obj );
243 return aShapeObj._retn();
246 //=======================================================================
247 //function : GeomObjectToShape
249 //=======================================================================
251 TopoDS_Shape SMESH_Gen_i::GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject)
254 if ( !theGeomObject->_is_nil() ) {
255 GEOM_Client* aClient = GetShapeReader();
256 GEOM::GEOM_Gen_ptr aGeomEngine = GetGeomEngine();
257 if ( aClient && !aGeomEngine->_is_nil () )
258 S = aClient->GetShape( aGeomEngine, theGeomObject );
263 //=======================================================================
266 //=======================================================================
268 static SALOMEDS::SObject_ptr publish(CORBA::Object_ptr theIOR,
269 SALOMEDS::SObject_ptr theFatherObject,
270 const int theTag = 0,
271 const char* thePixMap = 0,
272 const bool theSelectable = true)
274 SALOMEDS::Study_var theStudy = SMESH_Gen_i::getStudyServant();
275 SALOMEDS::SObject_wrap SO = SMESH_Gen_i::ObjectToSObject( theIOR );
276 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
277 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = theStudy->GetUseCaseBuilder();
278 bool isNewSO = false, isInUseCaseTree = false;
282 SO = aStudyBuilder->NewObject( theFatherObject );
285 else if ( !theFatherObject->FindSubObject( theTag, SO.inout() ))
287 SO = aStudyBuilder->NewObjectToTag( theFatherObject, theTag );
292 isInUseCaseTree = useCaseBuilder->IsUseCaseNode( SO );
297 isInUseCaseTree = useCaseBuilder->IsUseCaseNode( SO );
300 SALOMEDS::GenericAttribute_wrap anAttr;
301 if ( !CORBA::is_nil( theIOR ))
303 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeIOR" );
304 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theIOR );
305 SALOMEDS::AttributeIOR_wrap iorAttr = anAttr;
306 CORBA::String_var objStrCur = iorAttr->Value();
307 bool sameIOR = ( objStrCur.in() && strcmp( objStr.in(), objStrCur.in() ) == 0 );
310 iorAttr->SetValue( objStr.in() );
311 // UnRegister() !!! --> No: random problems when meshing in parallel (yacs foreach) in distributed python scripts
312 // SALOME::GenericObj_var genObj = SALOME::GenericObj::_narrow( theIOR );
313 // if ( !genObj->_is_nil() )
314 // genObj->UnRegister();
319 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributePixMap" );
320 SALOMEDS::AttributePixMap_wrap pm = anAttr;
321 pm->SetPixMap( thePixMap );
324 if ( !theSelectable ) {
325 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeSelectable" );
326 SALOMEDS::AttributeSelectable_wrap selAttr = anAttr;
327 selAttr->SetSelectable( false );
331 aStudyBuilder->RemoveReference( SO );// remove garbage reference (23336)
333 // add object to the use case tree
334 // (to support tree representation customization and drag-n-drop)
335 if ( isNewSO || !isInUseCaseTree )
337 // define the next tag after given one in the data tree to insert SObject
338 SALOMEDS::SObject_wrap curObj, objAfter;
339 if ( theFatherObject->GetLastChildTag() > theTag && theTag > 0 )
341 SALOMEDS::UseCaseIterator_wrap
342 anUseCaseIter = useCaseBuilder->GetUseCaseIterator(theFatherObject);
343 for ( ; anUseCaseIter->More(); anUseCaseIter->Next() ) {
344 curObj = anUseCaseIter->Value();
345 if ( curObj->Tag() > theTag ) {
351 if ( !CORBA::is_nil( objAfter ))
352 useCaseBuilder->InsertBefore( SO, objAfter ); // insert at given tag
353 else if ( !isInUseCaseTree )
354 useCaseBuilder->AppendTo( theFatherObject, SO ); // append to the end of list
359 //=======================================================================
362 //=======================================================================
364 void SMESH_Gen_i::SetName(SALOMEDS::SObject_ptr theSObject,
366 const char* theDefaultName)
368 if ( !theSObject->_is_nil() ) {
369 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
370 SALOMEDS::GenericAttribute_wrap anAttr =
371 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributeName" );
372 SALOMEDS::AttributeName_wrap aNameAttr = anAttr;
373 if ( theName && theName[0] ) {
374 std::string name( theName ); // trim trailing white spaces
375 for ( size_t i = name.size()-1; i > 0; --i )
376 if ( isspace( name[i] )) name[i] = '\0';
378 aNameAttr->SetValue( name.c_str() );
382 CORBA::String_var curName = aNameAttr->Value();
383 if ( strlen( curName.in() ) == 0 ) {
384 SMESH_Comment aName(theDefaultName);
385 aNameAttr->SetValue( ( aName<< "_" << theSObject->Tag()).c_str() );
391 //=======================================================================
392 //function : SetPixMap
394 //=======================================================================
396 void SMESH_Gen_i::SetPixMap(SALOMEDS::SObject_ptr theSObject,
397 const char* thePixMap)
399 if ( !theSObject->_is_nil() && thePixMap && thePixMap && thePixMap[0] )
401 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
402 SALOMEDS::GenericAttribute_wrap anAttr =
403 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributePixMap" );
404 SALOMEDS::AttributePixMap_wrap aPMAttr = anAttr;
405 aPMAttr->SetPixMap( thePixMap );
409 //=======================================================================
410 //function : addReference
412 //=======================================================================
414 static void addReference (SALOMEDS::SObject_ptr theSObject,
415 CORBA::Object_ptr theToObject,
418 SALOMEDS::Study_var aStudy = SMESH_Gen_i::getStudyServant();
419 SALOMEDS::SObject_wrap aToObjSO = SMESH_Gen_i::ObjectToSObject( theToObject );
420 if ( !aToObjSO->_is_nil() && !theSObject->_is_nil() ) {
421 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
422 SALOMEDS::SObject_wrap aReferenceSO;
424 // check if the reference to theToObject already exists
425 // and find a free label for the reference object
426 bool isReferred = false;
428 SALOMEDS::ChildIterator_wrap anIter = aStudy->NewChildIterator( theSObject );
429 for ( ; !isReferred && anIter->More(); anIter->Next(), ++tag ) {
430 SALOMEDS::SObject_wrap curSO = anIter->Value();
431 if ( curSO->ReferencedObject( aReferenceSO.inout() )) {
432 CORBA::String_var refEntry = aReferenceSO->GetID();
433 CORBA::String_var toEntry = aToObjSO->GetID();
434 if ( strcmp( refEntry, toEntry ) == 0 )
437 else if ( !theTag ) {
438 SALOMEDS::GenericAttribute_wrap anAttr;
439 if ( !curSO->FindAttribute( anAttr.inout(), "AttributeIOR" ))
448 if ( !theSObject->FindSubObject( theTag, aReferenceSO.inout() ))
449 aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
451 aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
453 // add reference to the use case tree
454 // (to support tree representation customization and drag-n-drop)
455 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = aStudy->GetUseCaseBuilder();
456 SALOMEDS::UseCaseIterator_wrap useCaseIter = useCaseBuilder->GetUseCaseIterator(theSObject);
457 for ( ; useCaseIter->More(); useCaseIter->Next() )
459 SALOMEDS::SObject_wrap curSO = useCaseIter->Value();
460 if ( curSO->Tag() == theTag )
463 useCaseBuilder->AppendTo( theSObject, aReferenceSO );
467 //=============================================================================
469 * SMESH_Gen_i::PublishInStudy
471 * Publish object in the study
473 //=============================================================================
475 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::SObject_ptr theSObject,
476 CORBA::Object_ptr theIOR,
478 throw (SALOME::SALOME_Exception)
480 Unexpect aCatch(SALOME_SalomeException);
481 SALOMEDS::SObject_wrap aSO;
482 if ( !myIsEnablePublish )
484 if ( CORBA::is_nil( theIOR ))
486 if(MYDEBUG) MESSAGE("PublishInStudy");
489 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( theIOR );
490 if( !aMesh->_is_nil() )
491 aSO = PublishMesh( aMesh, theName );
493 // Publishing a sub-mesh
494 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( theIOR );
495 if( aSO->_is_nil() && !aSubMesh->_is_nil() ) {
496 GEOM::GEOM_Object_var aShapeObject = aSubMesh->GetSubShape();
497 aMesh = aSubMesh->GetFather();
498 aSO = PublishSubMesh( aMesh, aSubMesh, aShapeObject, theName );
501 // Publishing a hypothesis or algorithm
502 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR );
503 if ( aSO->_is_nil() && !aHyp->_is_nil() )
504 aSO = PublishHypothesis( aHyp, theName );
506 // Publishing a group
507 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
508 if ( aSO->_is_nil() && !aGroup->_is_nil() ) {
509 GEOM::GEOM_Object_var aShapeObject;
510 aMesh = aGroup->GetMesh();
511 aSO = PublishGroup( aMesh, aGroup, aShapeObject, theName );
513 if(MYDEBUG) MESSAGE("PublishInStudy_END");
518 //=======================================================================
519 //function : PublishComponent
521 //=======================================================================
523 SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent()
525 if(MYDEBUG) MESSAGE("PublishComponent");
526 if ( !myIsEnablePublish )
527 return SALOMEDS::SComponent::_nil();
529 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
530 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = getStudyServant()->GetUseCaseBuilder();
532 CORBA::String_var compDataType = ComponentDataType();
533 SALOMEDS::SComponent_wrap father = getStudyServant()->FindComponent( compDataType.in() );
534 if ( !CORBA::is_nil( father ) ) {
535 // check that the component is added to the use case browser
536 if ( !useCaseBuilder->IsUseCaseNode( father ) ) {
537 useCaseBuilder->SetRootCurrent();
538 useCaseBuilder->Append( father ); // component object is added as the top level item
540 return father._retn();
543 SALOME_ModuleCatalog::ModuleCatalog_var aCat =
544 SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
545 if ( CORBA::is_nil( aCat ) )
546 return father._retn();
548 SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( compDataType.in() );
549 if ( CORBA::is_nil( aComp ) )
550 return father._retn();
552 SALOMEDS::GenericAttribute_wrap anAttr;
553 SALOMEDS::AttributePixMap_wrap aPixmap;
555 father = aStudyBuilder->NewComponent( compDataType.in() );
556 aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
557 anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
559 aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
560 CORBA::String_var userName = aComp->componentusername();
561 SetName( father, userName.in(), "MESH" );
562 // add component to the use case tree
563 // (to support tree representation customization and drag-n-drop)
564 useCaseBuilder->SetRootCurrent();
565 useCaseBuilder->Append( father ); // component object is added as the top level item
566 if(MYDEBUG) MESSAGE("PublishComponent--END");
568 return father._retn();
571 //=======================================================================
572 //function : PublishMesh
574 //=======================================================================
576 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SMESH::SMESH_Mesh_ptr theMesh,
579 if ( !myIsEnablePublish )
580 return SALOMEDS::SObject::_nil();
581 if ( CORBA::is_nil( theMesh ))
582 return SALOMEDS::SObject::_nil();
583 if(MYDEBUG) MESSAGE("PublishMesh--IN");
585 // find or publish a mesh
587 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
588 if ( aMeshSO->_is_nil() )
590 SALOMEDS::SComponent_wrap father = PublishComponent();
591 if ( father->_is_nil() )
592 return aMeshSO._retn();
594 // Find correct free tag
595 long aTag = father->GetLastChildTag();
596 if ( aTag <= GetAlgorithmsRootTag() )
597 aTag = GetAlgorithmsRootTag() + 1;
601 aMeshSO = publish ( theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
602 if ( aMeshSO->_is_nil() )
603 return aMeshSO._retn();
605 SetName( aMeshSO, theName, "Mesh" );
607 // Add shape reference
609 GEOM::GEOM_Object_var aShapeObject = theMesh->GetShapeToMesh();
610 if ( !CORBA::is_nil( aShapeObject )) {
611 addReference( aMeshSO, aShapeObject, GetRefOnShapeTag() );
613 // Publish global hypotheses
615 SMESH::ListOfHypothesis_var hypList = theMesh->GetHypothesisList( aShapeObject );
616 for ( CORBA::ULong i = 0; i < hypList->length(); i++ )
618 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( hypList[ i ]);
619 SALOMEDS::SObject_wrap so = PublishHypothesis( aHyp );
620 AddHypothesisToShape( theMesh, aShapeObject, aHyp );
626 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
628 return aMeshSO._retn();
629 map<int, SMESH_subMesh_i*>& subMap = mesh_i->_mapSubMesh_i;
630 map<int, SMESH_subMesh_i*>::iterator subIt = subMap.begin();
631 for ( ; subIt != subMap.end(); subIt++ ) {
632 SMESH::SMESH_subMesh_ptr aSubMesh = (*subIt).second->_this();
633 if ( !CORBA::is_nil( aSubMesh )) {
634 aShapeObject = aSubMesh->GetSubShape();
635 SALOMEDS::SObject_wrap( PublishSubMesh( theMesh, aSubMesh, aShapeObject ));
640 const map<int, SMESH::SMESH_GroupBase_ptr>& grMap = mesh_i->getGroups();
641 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = grMap.begin();
642 for ( ; it != grMap.end(); it++ )
644 SMESH::SMESH_GroupBase_ptr aGroup = (*it).second;
645 if ( !aGroup->_is_nil() ) {
646 GEOM::GEOM_Object_var aShapeObj;
647 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
648 if ( !aGeomGroup->_is_nil() )
649 aShapeObj = aGeomGroup->GetShape();
650 SALOMEDS::SObject_wrap( PublishGroup( theMesh, aGroup, aShapeObj ));
654 if(MYDEBUG) MESSAGE("PublishMesh_END");
655 return aMeshSO._retn();
658 //=======================================================================
659 //function : PublishSubMesh
661 //=======================================================================
663 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SMESH::SMESH_Mesh_ptr theMesh,
664 SMESH::SMESH_subMesh_ptr theSubMesh,
665 GEOM::GEOM_Object_ptr theShapeObject,
668 if ( !myIsEnablePublish )
669 return SALOMEDS::SObject::_nil();
670 if ( theMesh->_is_nil() || theSubMesh->_is_nil() || theShapeObject->_is_nil() )
671 return SALOMEDS::SObject::_nil();
673 SALOMEDS::SObject_wrap aSubMeshSO = ObjectToSObject( theSubMesh );
674 if ( aSubMeshSO->_is_nil() )
676 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
677 if ( aMeshSO->_is_nil() ) {
678 aMeshSO = PublishMesh( theMesh );
679 if ( aMeshSO->_is_nil())
680 return SALOMEDS::SObject::_nil();
682 // Find submesh sub-tree tag
684 const char* aRootName = "";
685 switch ( theShapeObject->GetShapeType() ) {
687 aRootTag = GetSubMeshOnVertexTag();
688 aRootName = "SubMeshes on Vertex";
691 aRootTag = GetSubMeshOnEdgeTag();
692 aRootName = "SubMeshes on Edge";
695 aRootTag = GetSubMeshOnWireTag();
696 aRootName = "SubMeshes on Wire";
699 aRootTag = GetSubMeshOnFaceTag();
700 aRootName = "SubMeshes on Face";
703 aRootTag = GetSubMeshOnShellTag();
704 aRootName = "SubMeshes on Shell";
707 aRootTag = GetSubMeshOnSolidTag();
708 aRootName = "SubMeshes on Solid";
711 aRootTag = GetSubMeshOnCompoundTag();
712 aRootName = "SubMeshes on Compound";
716 // Find or create submesh root
717 SALOMEDS::SObject_wrap aRootSO = publish ( CORBA::Object::_nil(),
718 aMeshSO, aRootTag, 0, false );
719 if ( aRootSO->_is_nil() )
720 return aSubMeshSO._retn();
722 SetName( aRootSO, aRootName );
724 // Add new submesh to corresponding sub-tree
725 SMESH::array_of_ElementType_var elemTypes = theSubMesh->GetTypes();
726 const int isEmpty = ( elemTypes->length() == 0 );
727 const char* pm[2] = { "ICON_SMESH_TREE_MESH", "ICON_SMESH_TREE_MESH_WARN" };
728 aSubMeshSO = publish ( theSubMesh, aRootSO, 0, pm[isEmpty] );
729 if ( aSubMeshSO->_is_nil() )
730 return aSubMeshSO._retn();
732 SetName( aSubMeshSO, theName, "SubMesh" );
734 // Add reference to theShapeObject
736 addReference( aSubMeshSO, theShapeObject, 1 );
738 // Publish hypothesis
740 SMESH::ListOfHypothesis_var hypList = theMesh->GetHypothesisList( theShapeObject );
741 for ( CORBA::ULong i = 0; i < hypList->length(); i++ ) {
742 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( hypList[ i ]);
743 SALOMEDS::SObject_wrap so = PublishHypothesis( aHyp );
744 AddHypothesisToShape( theMesh, theShapeObject, aHyp );
747 return aSubMeshSO._retn();
750 //=======================================================================
751 //function : PublishGroup
753 //=======================================================================
755 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SMESH::SMESH_Mesh_ptr theMesh,
756 SMESH::SMESH_GroupBase_ptr theGroup,
757 GEOM::GEOM_Object_ptr theShapeObject,
760 if ( !myIsEnablePublish )
761 return SALOMEDS::SObject::_nil();
762 if (theMesh->_is_nil() || theGroup->_is_nil() )
763 return SALOMEDS::SObject::_nil();
765 SALOMEDS::SObject_wrap aGroupSO = ObjectToSObject( theGroup );
766 if ( aGroupSO->_is_nil() )
768 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
769 if ( aMeshSO->_is_nil() ) {
770 aMeshSO = PublishInStudy( SALOMEDS::SObject::_nil(), theMesh, "");
771 if ( aMeshSO->_is_nil())
772 return SALOMEDS::SObject::_nil();
774 size_t aType = (int)theGroup->GetType();
775 const char* aRootNames[] = {
776 "Compound Groups", "Groups of Nodes", "Groups of Edges",
777 "Groups of Faces", "Groups of Volumes", "Groups of 0D Elements",
780 // Currently, groups with heterogeneous content are not supported
781 if ( aType != SMESH::ALL )
783 long aRootTag = GetNodeGroupsTag() + aType - 1;
785 // Find or create groups root
786 SALOMEDS::SObject_wrap aRootSO = publish ( CORBA::Object::_nil(),
787 aMeshSO, aRootTag, 0, false );
788 if ( aRootSO->_is_nil() ) return SALOMEDS::SObject::_nil();
790 if ( aType < sizeof(aRootNames)/sizeof(char*) )
791 SetName( aRootSO, aRootNames[aType] );
793 // Add new group to corresponding sub-tree
795 std::string pm[2] = { "ICON_SMESH_TREE_GROUP", "ICON_SMESH_TREE_MESH_WARN" };
796 if ( SMESH::DownCast< SMESH_GroupOnFilter_i* > ( theGroup ))
798 pm[0] = "ICON_SMESH_TREE_GROUP_ON_FILTER";
800 else if ( SMESH::DownCast< SMESH_Group_i* > ( theGroup ))
802 if ( theGroup->GetType() == SMESH::NODE )
803 isEmpty = ( theMesh->NbNodes() == 0 );
806 SMESH::array_of_ElementType_var allElemTypes = theMesh->GetTypes();
807 for ( size_t i =0; i < allElemTypes->length() && isEmpty; ++i )
808 isEmpty = ( allElemTypes[i] != theGroup->GetType() );
811 aGroupSO = publish ( theGroup, aRootSO, 0, pm[isEmpty].c_str() );
813 if ( aGroupSO->_is_nil() )
814 return aGroupSO._retn();
817 SetName( aGroupSO, theName, "Group" );
819 //Add reference to geometry
820 if ( !theShapeObject->_is_nil() )
821 addReference( aGroupSO, theShapeObject, 1 );
823 return aGroupSO._retn();
826 //=======================================================================
827 //function : PublishHypothesis
829 //=======================================================================
831 SALOMEDS::SObject_ptr
832 SMESH_Gen_i::PublishHypothesis (SMESH::SMESH_Hypothesis_ptr theHyp,
835 if(MYDEBUG) MESSAGE("PublishHypothesis")
836 if ( !myIsEnablePublish )
837 return SALOMEDS::SObject::_nil();
838 if (theHyp->_is_nil())
839 return SALOMEDS::SObject::_nil();
841 CORBA::String_var hypType = theHyp->GetName();
843 SALOMEDS::SObject_wrap aHypSO = ObjectToSObject( theHyp );
844 if ( aHypSO->_is_nil() )
846 SALOMEDS::SComponent_wrap father = PublishComponent();
847 if ( father->_is_nil() )
848 return aHypSO._retn();
850 //Find or Create Hypothesis root
851 bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
852 int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
853 SALOMEDS::SObject_wrap aRootSO =
854 publish (CORBA::Object::_nil(),father, aRootTag,
855 isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
856 SetName( aRootSO, isAlgo ? "Algorithms" : "Hypotheses" );
858 // Add New Hypothesis
859 string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
860 aPmName += hypType.in();
861 // prepend plugin name to pixmap name
862 string pluginName = myHypCreatorMap[ hypType.in() ]->GetModuleName();
863 if ( pluginName != "StdMeshers" )
864 aPmName = pluginName + "::" + aPmName;
865 aHypSO = publish( theHyp, aRootSO, 0, aPmName.c_str() );
868 SetName( aHypSO, theName, hypType.in() );
870 if(MYDEBUG) MESSAGE("PublishHypothesis--END")
871 return aHypSO._retn();
874 //=======================================================================
875 //function : UpdateIcons
876 //purpose : update icons of a mesh and its children upon mesh modification
877 //=======================================================================
879 void SMESH_Gen_i::UpdateIcons( SMESH::SMESH_Mesh_ptr theMesh )
881 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh );
885 SALOMEDS::SObject_wrap so = ObjectToSObject( theMesh );
889 // set icon of the mesh
890 if ( mesh_i->NbNodes() == 0 )
891 SetPixMap( so, "ICON_SMESH_TREE_MESH_WARN" );
892 else if ( mesh_i->IsComputedOK() )
893 SetPixMap( so, "ICON_SMESH_TREE_MESH" );
894 else if ( mesh_i->HasShapeToMesh() )
895 SetPixMap( so, "ICON_SMESH_TREE_MESH_PARTIAL" );
897 SetPixMap( so, "ICON_SMESH_TREE_MESH_IMPORTED" );
899 // set icons of sub-objects
900 SALOMEDS::Study_var study = getStudyServant();
901 SALOMEDS::ChildIterator_wrap iter = study->NewChildIterator( so );
902 for ( ; iter->More(); iter->Next() )
904 so = iter->Value(); // 1st level child - root of algos, hyps, sub-meshes or groups
905 if ( so->Tag() < SMESH::Tag_FirstSubMesh )
908 SALOMEDS::ChildIterator_wrap subIter = study->NewChildIterator( so );
909 for ( ; subIter->More(); subIter->Next() )
911 so = subIter->Value(); // 2nd level child - a sub-mesh or group
913 CORBA::Object_var obj = SObjectToObject( so );
914 SMESH::SMESH_IDSource_var idSrc = SMESH::SMESH_IDSource::_narrow( obj );
915 if ( idSrc->_is_nil() )
918 SMESH::SMESH_GroupBase_var grp = SMESH::SMESH_GroupBase::_narrow( obj );
919 SMESH::SMESH_GroupOnFilter_var gof = SMESH::SMESH_GroupOnFilter::_narrow( obj );
920 const bool isGroup = !grp->_is_nil();
921 const bool isGroupOnFilter = !gof->_is_nil();
923 bool isEmpty = ( mesh_i->NbNodes() == 0 );
926 if ( isGroupOnFilter ) // GetTypes() can be very long on GroupOnFilter!
928 SMESH::long_array_var nbByType = mesh_i->GetNbElementsByType();
929 isEmpty = ( nbByType[ grp->GetType() ] == 0 );
933 SMESH::array_of_ElementType_var elemTypes = idSrc->GetTypes();
934 isEmpty = ( elemTypes->length() == 0 );
938 SetPixMap( so, "ICON_SMESH_TREE_MESH_WARN");
940 SetPixMap( so, "ICON_SMESH_TREE_MESH" );
941 else if ( isGroupOnFilter )
942 SetPixMap( so, "ICON_SMESH_TREE_GROUP_ON_FILTER" );
944 SetPixMap( so, "ICON_SMESH_TREE_GROUP" );
949 //=======================================================================
950 //function : GetMeshOrSubmeshByShape
952 //=======================================================================
954 SALOMEDS::SObject_ptr
955 SMESH_Gen_i::GetMeshOrSubmeshByShape (SMESH::SMESH_Mesh_ptr theMesh,
956 GEOM::GEOM_Object_ptr theShape)
958 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
959 SALOMEDS::SObject_wrap aMeshOrSubMesh;
960 if (theMesh->_is_nil() || ( theShape->_is_nil() && theMesh->HasShapeToMesh()))
961 return aMeshOrSubMesh._retn();
964 if(theMesh->HasShapeToMesh())
965 aShape = GeomObjectToShape( theShape );
967 aShape = SMESH_Mesh::PseudoShape();
969 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
971 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
972 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
973 if ( aShape.IsSame( meshDS->ShapeToMesh() ))
974 aMeshOrSubMesh = ObjectToSObject( theMesh );
976 int shapeID = meshDS->ShapeToIndex( aShape );
977 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
978 if ( !aSubMesh->_is_nil() )
979 aMeshOrSubMesh = ObjectToSObject( aSubMesh );
982 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
983 return aMeshOrSubMesh._retn();
986 //=======================================================================
987 //function : AddHypothesisToShape
989 //=======================================================================
991 bool SMESH_Gen_i::AddHypothesisToShape(SMESH::SMESH_Mesh_ptr theMesh,
992 GEOM::GEOM_Object_ptr theShape,
993 SMESH::SMESH_Hypothesis_ptr theHyp)
995 if(MYDEBUG) MESSAGE("AddHypothesisToShape")
996 if (theMesh->_is_nil() ||
997 theHyp->_is_nil() || (theShape->_is_nil()
998 && theMesh->HasShapeToMesh()) )
1001 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
1002 if ( aMeshSO->_is_nil() )
1003 aMeshSO = PublishMesh( theMesh );
1004 SALOMEDS::SObject_wrap aHypSO = PublishHypothesis( theHyp );
1005 if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
1008 // Find a mesh or submesh referring to theShape
1009 SALOMEDS::SObject_wrap aMeshOrSubMesh =
1010 GetMeshOrSubmeshByShape( theMesh, theShape );
1011 if ( aMeshOrSubMesh->_is_nil() )
1014 TopoDS_Shape aShape = GeomObjectToShape( theShape );
1015 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
1016 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
1017 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
1018 int shapeID = meshDS->ShapeToIndex( aShape );
1019 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
1020 aMeshOrSubMesh = PublishSubMesh( theMesh, aSubMesh, theShape );
1022 if ( aMeshOrSubMesh->_is_nil() )
1026 //Find or Create Applied Hypothesis root
1027 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
1028 SALOMEDS::SObject_wrap AHR =
1029 publish (CORBA::Object::_nil(), aMeshOrSubMesh,
1030 aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
1031 aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
1032 SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
1034 addReference( AHR, theHyp );
1036 if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
1040 //=======================================================================
1041 //function : RemoveHypothesisFromShape
1043 //=======================================================================
1045 bool SMESH_Gen_i::RemoveHypothesisFromShape(SMESH::SMESH_Mesh_ptr theMesh,
1046 GEOM::GEOM_Object_ptr theShape,
1047 SMESH::SMESH_Hypothesis_ptr theHyp)
1049 if (theMesh->_is_nil() ||
1050 theHyp->_is_nil() || (theShape->_is_nil()
1051 && theMesh->HasShapeToMesh()))
1054 SALOMEDS::SObject_wrap aHypSO = ObjectToSObject( theHyp );
1055 if ( aHypSO->_is_nil() )
1058 CORBA::String_var hypEntry = aHypSO->GetID();
1060 // Find a mesh or sub-mesh referring to theShape
1061 SALOMEDS::SObject_wrap aMeshOrSubMesh =
1062 GetMeshOrSubmeshByShape( theMesh, theShape );
1063 if ( aMeshOrSubMesh->_is_nil() )
1066 // Find and remove a reference to aHypSO
1067 SALOMEDS::SObject_wrap aRef, anObj;
1068 SALOMEDS::ChildIterator_wrap it = getStudyServant()->NewChildIterator( aMeshOrSubMesh );
1070 for ( it->InitEx( true ); ( it->More() && !found ); it->Next() ) {
1071 anObj = it->Value();
1072 if (anObj->ReferencedObject( aRef.inout() ))
1074 CORBA::String_var refEntry = aRef->GetID();
1075 found = ( strcmp( refEntry, hypEntry ) == 0 );
1079 SALOMEDS::StudyBuilder_var builder = getStudyServant()->NewBuilder();
1080 builder->RemoveObject( anObj );
1087 //================================================================================
1089 * \brief Stores names of variables that WILL be passes as parameters when calling
1090 * some method of a given object.
1091 * \param [in] theObject - the object whose a method WILL be called with \a theParameters.
1092 * \param [in] theParameters - a string containing parameters separated by ':'.
1094 //================================================================================
1096 void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters)
1098 // find variable names within theParameters
1101 myLastParameters.clear();
1102 myLastParamIndex.clear(); /* vector holding indices of virables within the string
1103 of all variables used for theObject */
1105 int pos = 0, prevPos = 0, len = strlen( theParameters );
1106 if ( len == 0 ) return;
1107 while ( pos <= len )
1109 if ( pos == len || theParameters[pos] == ':' )
1111 if ( prevPos < pos )
1113 string val( theParameters + prevPos, theParameters + pos );
1114 if ( !getStudyServant()->IsVariable( val.c_str() ))
1116 myLastParameters.push_back( val );
1117 nbVars += (! myLastParameters.back().empty() );
1121 myLastParameters.push_back("");
1132 // (1) variable names in the string of all variables used for theObject and
1133 // (2) indices of found variables in myLastParamIndex.
1135 // remember theObject
1136 SALOMEDS::SObject_wrap aSObj = ObjectToSObject(theObject);
1137 if ( aSObj->_is_nil() )
1139 CORBA::String_var anObjEntry = aSObj->GetID();
1140 myLastObj = anObjEntry.in();
1142 // get a string of variable names
1143 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
1144 SALOMEDS::GenericAttribute_wrap anAttr =
1145 aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString" );
1146 SALOMEDS::AttributeString_wrap aStringAttr = anAttr;
1147 CORBA::String_var oldVars = aStringAttr->Value();
1148 std::string varStr = oldVars.in();
1150 // add new variables and find indices of variables
1151 for ( size_t i = 0; i < myLastParameters.size(); ++i )
1154 if ( !myLastParameters[i].empty() )
1156 // find index of myLastParameters[i] in varStr
1158 bool varFound = false;
1160 // varStr can be "A|B::C;*=2|D"
1161 const std::string separators(":|;*=");
1162 while ( pos < varStr.size() && !varFound )
1165 while ( separators.find( varStr[ pos ]) != std::string::npos )
1166 if ( ++pos >= varStr.size() )
1168 // skip repetition number following '='
1169 if ( varStr[ pos-1 ] == '=' )
1171 while ( '0' <= varStr[ pos ] && varStr[ pos ] <= '9' )
1173 continue; // to skip next separator
1175 // compare variable name
1176 if ( pos < varStr.size() )
1178 varFound = ( varStr.compare( pos, myLastParameters[i].size(), myLastParameters[i] ) == 0 &&
1179 // same string beginning but is length same?
1180 ( pos + myLastParameters[i].size() >= varStr.size() ||
1181 separators.find( varStr[ pos+1 ]) != std::string::npos ));
1183 varIndex = curIndex;
1185 pos = varStr.find_first_of( separators, pos ); // goto the next separator
1192 varStr += ":" + myLastParameters[i];
1193 varIndex = curIndex;
1196 myLastParamIndex.push_back( varIndex );
1198 aStringAttr->SetValue( varStr.c_str() );
1201 //================================================================================
1203 * \brief Return all variables used to create an object
1204 * \param [in] theObjectEntry - an object entry in the current study
1205 * \return std::vector< std::string > - all variable names (or values of removed variables)
1207 //================================================================================
1209 std::vector< std::string > SMESH_Gen_i::GetAllParameters(const std::string& theObjectEntry) const
1211 std::vector< std::string > varNames;
1213 SALOMEDS::SObject_wrap aSObj = getStudyServant()->FindObjectID( theObjectEntry.c_str() );
1215 // get a string of variable names
1216 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
1217 SALOMEDS::GenericAttribute_wrap anAttr =
1218 aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString" );
1219 SALOMEDS::AttributeString_wrap aStringAttr = anAttr;
1220 CORBA::String_var oldVars = aStringAttr->Value();
1221 std::string varStr = oldVars.in();
1223 // separate variables within varStr;
1224 // varStr can be "A|B::C;*=2|D"
1226 const std::string separators(":|;*=");
1227 while ( pos < varStr.size() )
1230 pos = varStr.find_first_not_of( separators, pos );
1231 // while ( separators.find( varStr[ pos ]) != std::string::npos )
1232 // if ( ++pos >= varStr.size() )
1234 // skip repetition number following '='
1235 if ( varStr[ pos-1 ] == '=' )
1237 while ( '0' <= varStr[ pos ] && varStr[ pos ] <= '9' )
1239 continue; // to skip next separator
1241 // store variable name
1242 if ( pos < varStr.size() )
1244 size_t pos2 = varStr.find_first_of( separators, pos );
1245 varNames.push_back( varStr.substr( pos, pos2 - pos));
1252 //=======================================================================
1253 //function : ParseParameters
1254 //purpose : Replace variables by their values
1255 //=======================================================================
1256 // char* SMESH_Gen_i::ParseParameters(const char* theParameters)
1258 // //const char* aParameters = theParameters;
1259 // // const char* aParameters = CORBA::string_dup(theParameters);
1260 // TCollection_AsciiString anInputParams;
1261 // SALOMEDS::Study_var aStudy = getStudyServant();
1262 // if( !aStudy->_is_nil() ) {
1263 // // SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(theParameters);
1264 // // for(int j=0;j<aSections->length();j++) {
1265 // // SALOMEDS::ListOfStrings aVars= aSections[j];
1266 // // for(int i=0;i<aVars.length();i++ ) {
1267 // // anInputParams += aStudy->IsVariable(aVars[i].in()) ?
1268 // // TCollection_AsciiString(aVars[i].in()) : TCollection_AsciiString("");
1269 // // if(i != aVars.length()-1)
1270 // // anInputParams+=":";
1272 // // if(j!=aSections->length()-1)
1273 // // anInputParams+="|";
1275 // TCollection_AsciiString paramStr( theParameters );
1276 // int beg = 0, end;
1277 // char sep, *pParams = (char*)paramStr.ToCString();
1278 // while ( beg < paramStr.Length() )
1281 // while ( ++end < paramStr.Length() )
1282 // if ( pParams[end] == ':' || pParams[end] == '|')
1284 // if ( end < paramStr.Length())
1286 // sep = pParams[end];
1287 // pParams[end] = '\0';
1289 // if ( aStudy->IsVariable( pParams+beg ))
1290 // anInputParams += pParams+beg;
1291 // if ( end < paramStr.Length() )
1292 // anInputParams += sep;
1298 // return CORBA::string_dup(anInputParams.ToCString());
1301 //=======================================================================
1302 //function : GetParameters
1304 //=======================================================================
1306 char* SMESH_Gen_i::GetParameters(CORBA::Object_ptr theObject)
1308 CORBA::String_var aResult("");
1310 SALOMEDS::SObject_wrap aSObj = ObjectToSObject( theObject );
1311 if ( !aSObj->_is_nil() )
1313 SALOMEDS::GenericAttribute_wrap attr;
1314 if ( aSObj->FindAttribute( attr.inout(), "AttributeString"))
1316 SALOMEDS::AttributeString_wrap strAttr = attr;
1317 aResult = strAttr->Value();
1320 return aResult._retn();
1329 //=======================================================================
1330 //function : addObject
1331 //purpose : register object in the internal map and return its id
1332 //=======================================================================
1334 int StudyContext::addObject( const std::string& theIOR )
1336 int nextId = getNextId();
1337 mapIdToIOR.Bind( nextId, theIOR );
1341 //=======================================================================
1343 //purpose : find the object id in the internal map by the IOR
1344 //=======================================================================
1346 int StudyContext::findId( const std::string& theIOR )
1348 TInt2StringMap::iterator imap;
1349 for ( imap = mapIdToIOR.begin(); imap != mapIdToIOR.end(); ++imap ) {
1350 if ( *imap == theIOR )
1351 return imap.Iterator().Key();
1356 //=======================================================================
1357 //function : getIORbyId
1358 //purpose : get object's IOR by id
1359 //=======================================================================
1361 std::string StudyContext::getIORbyId( const int theId )
1363 if ( mapIdToIOR.IsBound( theId ) )
1364 return mapIdToIOR( theId );
1365 return std::string();
1368 //=======================================================================
1369 //function : getIORbyOldId
1370 //purpose : get object's IOR by old id
1371 //=======================================================================
1373 std::string StudyContext::getIORbyOldId( const int theOldId )
1375 if ( mapIdToId.IsBound( theOldId ) )
1376 return getIORbyId( mapIdToId( theOldId ));
1377 return std::string();
1380 //=======================================================================
1381 //function : mapOldToNew
1382 //purpose : maps old object id to the new one (used when restoring data)
1383 //=======================================================================
1385 void StudyContext::mapOldToNew( const int oldId, const int newId )
1387 mapIdToId.Bind( oldId, newId );
1390 //=======================================================================
1391 //function : getOldId
1392 //purpose : get old id by a new one
1393 //=======================================================================
1395 int StudyContext::getOldId( const int newId )
1397 TInt2IntMap::iterator imap;
1398 for ( imap = mapIdToId.begin(); imap != mapIdToId.end(); ++imap ) {
1399 if ( *imap == newId )
1400 return imap.Iterator().Key();