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() !!! --> random problems when meshing in parallel (yacs foreach) in
312 // distributed python scripts, because simultaneously created meshes are
313 // published into the same SO; as a result the mesh published first dies
314 SALOME::GenericObj_var genObj = SALOME::GenericObj::_narrow( theIOR );
315 if ( !genObj->_is_nil() )
316 genObj->UnRegister();
321 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributePixMap" );
322 SALOMEDS::AttributePixMap_wrap pm = anAttr;
323 pm->SetPixMap( thePixMap );
326 if ( !theSelectable ) {
327 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeSelectable" );
328 SALOMEDS::AttributeSelectable_wrap selAttr = anAttr;
329 selAttr->SetSelectable( false );
333 aStudyBuilder->RemoveReference( SO );// remove garbage reference (23336)
335 // add object to the use case tree
336 // (to support tree representation customization and drag-n-drop)
337 if ( isNewSO || !isInUseCaseTree )
339 // define the next tag after given one in the data tree to insert SObject
340 SALOMEDS::SObject_wrap curObj, objAfter;
341 if ( theFatherObject->GetLastChildTag() > theTag && theTag > 0 )
343 SALOMEDS::UseCaseIterator_wrap
344 anUseCaseIter = useCaseBuilder->GetUseCaseIterator(theFatherObject);
345 for ( ; anUseCaseIter->More(); anUseCaseIter->Next() ) {
346 curObj = anUseCaseIter->Value();
347 if ( curObj->Tag() > theTag ) {
353 if ( !CORBA::is_nil( objAfter ))
354 useCaseBuilder->InsertBefore( SO, objAfter ); // insert at given tag
355 else if ( !isInUseCaseTree )
356 useCaseBuilder->AppendTo( theFatherObject, SO ); // append to the end of list
361 //=======================================================================
364 //=======================================================================
366 void SMESH_Gen_i::SetName(SALOMEDS::SObject_ptr theSObject,
368 const char* theDefaultName)
370 if ( !theSObject->_is_nil() ) {
371 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
372 SALOMEDS::GenericAttribute_wrap anAttr =
373 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributeName" );
374 SALOMEDS::AttributeName_wrap aNameAttr = anAttr;
375 if ( theName && theName[0] ) {
376 std::string name( theName ); // trim trailing white spaces
377 for ( size_t i = name.size()-1; i > 0; --i )
378 if ( isspace( name[i] )) name[i] = '\0';
380 aNameAttr->SetValue( name.c_str() );
384 CORBA::String_var curName = aNameAttr->Value();
385 if ( strlen( curName.in() ) == 0 ) {
386 SMESH_Comment aName(theDefaultName);
387 aNameAttr->SetValue( ( aName<< "_" << theSObject->Tag()).c_str() );
393 //=======================================================================
394 //function : SetPixMap
396 //=======================================================================
398 void SMESH_Gen_i::SetPixMap(SALOMEDS::SObject_ptr theSObject,
399 const char* thePixMap)
401 if ( !theSObject->_is_nil() && thePixMap && thePixMap && thePixMap[0] )
403 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
404 SALOMEDS::GenericAttribute_wrap anAttr =
405 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributePixMap" );
406 SALOMEDS::AttributePixMap_wrap aPMAttr = anAttr;
407 aPMAttr->SetPixMap( thePixMap );
411 //=======================================================================
412 //function : addReference
414 //=======================================================================
416 static void addReference (SALOMEDS::SObject_ptr theSObject,
417 CORBA::Object_ptr theToObject,
420 SALOMEDS::Study_var aStudy = SMESH_Gen_i::getStudyServant();
421 SALOMEDS::SObject_wrap aToObjSO = SMESH_Gen_i::ObjectToSObject( theToObject );
422 if ( !aToObjSO->_is_nil() && !theSObject->_is_nil() ) {
423 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
424 SALOMEDS::SObject_wrap aReferenceSO;
426 // check if the reference to theToObject already exists
427 // and find a free label for the reference object
428 bool isReferred = false;
430 SALOMEDS::ChildIterator_wrap anIter = aStudy->NewChildIterator( theSObject );
431 for ( ; !isReferred && anIter->More(); anIter->Next(), ++tag ) {
432 SALOMEDS::SObject_wrap curSO = anIter->Value();
433 if ( curSO->ReferencedObject( aReferenceSO.inout() )) {
434 CORBA::String_var refEntry = aReferenceSO->GetID();
435 CORBA::String_var toEntry = aToObjSO->GetID();
436 if ( strcmp( refEntry, toEntry ) == 0 )
439 else if ( !theTag ) {
440 SALOMEDS::GenericAttribute_wrap anAttr;
441 if ( !curSO->FindAttribute( anAttr.inout(), "AttributeIOR" ))
450 if ( !theSObject->FindSubObject( theTag, aReferenceSO.inout() ))
451 aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
453 aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
455 // add reference to the use case tree
456 // (to support tree representation customization and drag-n-drop)
457 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = aStudy->GetUseCaseBuilder();
458 SALOMEDS::UseCaseIterator_wrap useCaseIter = useCaseBuilder->GetUseCaseIterator(theSObject);
459 for ( ; useCaseIter->More(); useCaseIter->Next() )
461 SALOMEDS::SObject_wrap curSO = useCaseIter->Value();
462 if ( curSO->Tag() == theTag )
465 useCaseBuilder->AppendTo( theSObject, aReferenceSO );
469 //=============================================================================
471 * SMESH_Gen_i::PublishInStudy
473 * Publish object in the study
475 //=============================================================================
477 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::SObject_ptr theSObject,
478 CORBA::Object_ptr theIOR,
480 throw (SALOME::SALOME_Exception)
482 Unexpect aCatch(SALOME_SalomeException);
483 SALOMEDS::SObject_wrap aSO;
484 if ( !myIsEnablePublish )
486 if ( CORBA::is_nil( theIOR ))
488 if(MYDEBUG) MESSAGE("PublishInStudy");
491 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( theIOR );
492 if( !aMesh->_is_nil() )
493 aSO = PublishMesh( aMesh, theName );
495 // Publishing a sub-mesh
496 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( theIOR );
497 if( aSO->_is_nil() && !aSubMesh->_is_nil() ) {
498 GEOM::GEOM_Object_var aShapeObject = aSubMesh->GetSubShape();
499 aMesh = aSubMesh->GetFather();
500 aSO = PublishSubMesh( aMesh, aSubMesh, aShapeObject, theName );
503 // Publishing a hypothesis or algorithm
504 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR );
505 if ( aSO->_is_nil() && !aHyp->_is_nil() )
506 aSO = PublishHypothesis( aHyp, theName );
508 // Publishing a group
509 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
510 if ( aSO->_is_nil() && !aGroup->_is_nil() ) {
511 GEOM::GEOM_Object_var aShapeObject;
512 aMesh = aGroup->GetMesh();
513 aSO = PublishGroup( aMesh, aGroup, aShapeObject, theName );
515 if(MYDEBUG) MESSAGE("PublishInStudy_END");
520 //=======================================================================
521 //function : PublishComponent
523 //=======================================================================
525 SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent()
527 if(MYDEBUG) MESSAGE("PublishComponent");
528 if ( !myIsEnablePublish )
529 return SALOMEDS::SComponent::_nil();
531 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
532 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = getStudyServant()->GetUseCaseBuilder();
534 CORBA::String_var compDataType = ComponentDataType();
535 SALOMEDS::SComponent_wrap father = getStudyServant()->FindComponent( compDataType.in() );
536 if ( !CORBA::is_nil( father ) ) {
537 // check that the component is added to the use case browser
538 if ( !useCaseBuilder->IsUseCaseNode( father ) ) {
539 useCaseBuilder->SetRootCurrent();
540 useCaseBuilder->Append( father ); // component object is added as the top level item
542 return father._retn();
545 SALOME_ModuleCatalog::ModuleCatalog_var aCat =
546 SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
547 if ( CORBA::is_nil( aCat ) )
548 return father._retn();
550 SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( compDataType.in() );
551 if ( CORBA::is_nil( aComp ) )
552 return father._retn();
554 SALOMEDS::GenericAttribute_wrap anAttr;
555 SALOMEDS::AttributePixMap_wrap aPixmap;
557 father = aStudyBuilder->NewComponent( compDataType.in() );
558 aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
559 anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
561 aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
562 CORBA::String_var userName = aComp->componentusername();
563 SetName( father, userName.in(), "MESH" );
564 // add component to the use case tree
565 // (to support tree representation customization and drag-n-drop)
566 useCaseBuilder->SetRootCurrent();
567 useCaseBuilder->Append( father ); // component object is added as the top level item
568 if(MYDEBUG) MESSAGE("PublishComponent--END");
570 return father._retn();
573 //=======================================================================
574 //function : PublishMesh
576 //=======================================================================
578 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SMESH::SMESH_Mesh_ptr theMesh,
581 if ( !myIsEnablePublish )
582 return SALOMEDS::SObject::_nil();
583 if ( CORBA::is_nil( theMesh ))
584 return SALOMEDS::SObject::_nil();
585 if(MYDEBUG) MESSAGE("PublishMesh--IN");
587 // find or publish a mesh
589 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
590 if ( aMeshSO->_is_nil() )
592 SALOMEDS::SComponent_wrap father = PublishComponent();
593 if ( father->_is_nil() )
594 return aMeshSO._retn();
596 // Find correct free tag
597 long aTag = father->GetLastChildTag();
598 if ( aTag <= GetAlgorithmsRootTag() )
599 aTag = GetAlgorithmsRootTag() + 1;
603 aMeshSO = publish( theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
604 if ( aMeshSO->_is_nil() )
605 return aMeshSO._retn();
607 SetName( aMeshSO, theName, "Mesh" );
609 // Add shape reference
611 GEOM::GEOM_Object_var aShapeObject = theMesh->GetShapeToMesh();
612 if ( !CORBA::is_nil( aShapeObject )) {
613 addReference( aMeshSO, aShapeObject, GetRefOnShapeTag() );
615 // Publish global hypotheses
617 SMESH::ListOfHypothesis_var hypList = theMesh->GetHypothesisList( aShapeObject );
618 for ( CORBA::ULong i = 0; i < hypList->length(); i++ )
620 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( hypList[ i ]);
621 SALOMEDS::SObject_wrap so = PublishHypothesis( aHyp );
622 AddHypothesisToShape( theMesh, aShapeObject, aHyp );
628 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
630 return aMeshSO._retn();
631 map<int, SMESH_subMesh_i*>& subMap = mesh_i->_mapSubMesh_i;
632 map<int, SMESH_subMesh_i*>::iterator subIt = subMap.begin();
633 for ( ; subIt != subMap.end(); subIt++ ) {
634 SMESH::SMESH_subMesh_ptr aSubMesh = (*subIt).second->_this();
635 if ( !CORBA::is_nil( aSubMesh )) {
636 aShapeObject = aSubMesh->GetSubShape();
637 SALOMEDS::SObject_wrap( PublishSubMesh( theMesh, aSubMesh, aShapeObject ));
642 const map<int, SMESH::SMESH_GroupBase_ptr>& grMap = mesh_i->getGroups();
643 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = grMap.begin();
644 for ( ; it != grMap.end(); it++ )
646 SMESH::SMESH_GroupBase_ptr aGroup = (*it).second;
647 if ( !aGroup->_is_nil() ) {
648 GEOM::GEOM_Object_var aShapeObj;
649 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
650 if ( !aGeomGroup->_is_nil() )
651 aShapeObj = aGeomGroup->GetShape();
652 SALOMEDS::SObject_wrap( PublishGroup( theMesh, aGroup, aShapeObj ));
656 if(MYDEBUG) MESSAGE("PublishMesh_END");
657 return aMeshSO._retn();
660 //=======================================================================
661 //function : PublishSubMesh
663 //=======================================================================
665 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SMESH::SMESH_Mesh_ptr theMesh,
666 SMESH::SMESH_subMesh_ptr theSubMesh,
667 GEOM::GEOM_Object_ptr theShapeObject,
670 if ( !myIsEnablePublish )
671 return SALOMEDS::SObject::_nil();
672 if ( theMesh->_is_nil() || theSubMesh->_is_nil() || theShapeObject->_is_nil() )
673 return SALOMEDS::SObject::_nil();
675 SALOMEDS::SObject_wrap aSubMeshSO = ObjectToSObject( theSubMesh );
676 if ( aSubMeshSO->_is_nil() )
678 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
679 if ( aMeshSO->_is_nil() ) {
680 aMeshSO = PublishMesh( theMesh );
681 if ( aMeshSO->_is_nil())
682 return SALOMEDS::SObject::_nil();
684 // Find submesh sub-tree tag
686 const char* aRootName = "";
687 switch ( theShapeObject->GetShapeType() ) {
689 aRootTag = GetSubMeshOnVertexTag();
690 aRootName = "SubMeshes on Vertex";
693 aRootTag = GetSubMeshOnEdgeTag();
694 aRootName = "SubMeshes on Edge";
697 aRootTag = GetSubMeshOnWireTag();
698 aRootName = "SubMeshes on Wire";
701 aRootTag = GetSubMeshOnFaceTag();
702 aRootName = "SubMeshes on Face";
705 aRootTag = GetSubMeshOnShellTag();
706 aRootName = "SubMeshes on Shell";
709 aRootTag = GetSubMeshOnSolidTag();
710 aRootName = "SubMeshes on Solid";
713 aRootTag = GetSubMeshOnCompoundTag();
714 aRootName = "SubMeshes on Compound";
718 // Find or create submesh root
719 SALOMEDS::SObject_wrap aRootSO = publish ( CORBA::Object::_nil(),
720 aMeshSO, aRootTag, 0, false );
721 if ( aRootSO->_is_nil() )
722 return aSubMeshSO._retn();
724 SetName( aRootSO, aRootName );
726 // Add new submesh to corresponding sub-tree
727 SMESH::array_of_ElementType_var elemTypes = theSubMesh->GetTypes();
728 const int isEmpty = ( elemTypes->length() == 0 );
729 const char* pm[2] = { "ICON_SMESH_TREE_MESH", "ICON_SMESH_TREE_MESH_WARN" };
730 aSubMeshSO = publish ( theSubMesh, aRootSO, 0, pm[isEmpty] );
731 if ( aSubMeshSO->_is_nil() )
732 return aSubMeshSO._retn();
734 SetName( aSubMeshSO, theName, "SubMesh" );
736 // Add reference to theShapeObject
738 addReference( aSubMeshSO, theShapeObject, 1 );
740 // Publish hypothesis
742 SMESH::ListOfHypothesis_var hypList = theMesh->GetHypothesisList( theShapeObject );
743 for ( CORBA::ULong i = 0; i < hypList->length(); i++ ) {
744 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( hypList[ i ]);
745 SALOMEDS::SObject_wrap so = PublishHypothesis( aHyp );
746 AddHypothesisToShape( theMesh, theShapeObject, aHyp );
749 return aSubMeshSO._retn();
752 //=======================================================================
753 //function : PublishGroup
755 //=======================================================================
757 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SMESH::SMESH_Mesh_ptr theMesh,
758 SMESH::SMESH_GroupBase_ptr theGroup,
759 GEOM::GEOM_Object_ptr theShapeObject,
762 if ( !myIsEnablePublish )
763 return SALOMEDS::SObject::_nil();
764 if (theMesh->_is_nil() || theGroup->_is_nil() )
765 return SALOMEDS::SObject::_nil();
767 SALOMEDS::SObject_wrap aGroupSO = ObjectToSObject( theGroup );
768 if ( aGroupSO->_is_nil() )
770 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
771 if ( aMeshSO->_is_nil() ) {
772 aMeshSO = PublishInStudy( SALOMEDS::SObject::_nil(), theMesh, "");
773 if ( aMeshSO->_is_nil())
774 return SALOMEDS::SObject::_nil();
776 size_t aType = (int)theGroup->GetType();
777 const char* aRootNames[] = {
778 "Compound Groups", "Groups of Nodes", "Groups of Edges",
779 "Groups of Faces", "Groups of Volumes", "Groups of 0D Elements",
782 // Currently, groups with heterogeneous content are not supported
783 if ( aType != SMESH::ALL )
785 long aRootTag = GetNodeGroupsTag() + aType - 1;
787 // Find or create groups root
788 SALOMEDS::SObject_wrap aRootSO = publish ( CORBA::Object::_nil(),
789 aMeshSO, aRootTag, 0, false );
790 if ( aRootSO->_is_nil() ) return SALOMEDS::SObject::_nil();
792 if ( aType < sizeof(aRootNames)/sizeof(char*) )
793 SetName( aRootSO, aRootNames[aType] );
795 // Add new group to corresponding sub-tree
797 std::string pm[2] = { "ICON_SMESH_TREE_GROUP", "ICON_SMESH_TREE_MESH_WARN" };
798 if ( SMESH::DownCast< SMESH_GroupOnFilter_i* > ( theGroup ))
800 pm[0] = "ICON_SMESH_TREE_GROUP_ON_FILTER";
802 else if ( SMESH::DownCast< SMESH_Group_i* > ( theGroup ))
804 if ( theGroup->GetType() == SMESH::NODE )
805 isEmpty = ( theMesh->NbNodes() == 0 );
808 SMESH::array_of_ElementType_var allElemTypes = theMesh->GetTypes();
809 for ( size_t i =0; i < allElemTypes->length() && isEmpty; ++i )
810 isEmpty = ( allElemTypes[i] != theGroup->GetType() );
813 aGroupSO = publish ( theGroup, aRootSO, 0, pm[isEmpty].c_str() );
815 if ( aGroupSO->_is_nil() )
816 return aGroupSO._retn();
819 SetName( aGroupSO, theName, "Group" );
821 //Add reference to geometry
822 if ( !theShapeObject->_is_nil() )
823 addReference( aGroupSO, theShapeObject, 1 );
825 return aGroupSO._retn();
828 //=======================================================================
829 //function : PublishHypothesis
831 //=======================================================================
833 SALOMEDS::SObject_ptr
834 SMESH_Gen_i::PublishHypothesis (SMESH::SMESH_Hypothesis_ptr theHyp,
837 if(MYDEBUG) MESSAGE("PublishHypothesis")
838 if ( !myIsEnablePublish )
839 return SALOMEDS::SObject::_nil();
840 if (theHyp->_is_nil())
841 return SALOMEDS::SObject::_nil();
843 CORBA::String_var hypType = theHyp->GetName();
845 SALOMEDS::SObject_wrap aHypSO = ObjectToSObject( theHyp );
846 if ( aHypSO->_is_nil() )
848 SALOMEDS::SComponent_wrap father = PublishComponent();
849 if ( father->_is_nil() )
850 return aHypSO._retn();
852 //Find or Create Hypothesis root
853 bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
854 int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
855 SALOMEDS::SObject_wrap aRootSO =
856 publish (CORBA::Object::_nil(),father, aRootTag,
857 isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
858 SetName( aRootSO, isAlgo ? "Algorithms" : "Hypotheses" );
860 // Add New Hypothesis
861 string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
862 aPmName += hypType.in();
863 // prepend plugin name to pixmap name
864 string pluginName = myHypCreatorMap[ hypType.in() ]->GetModuleName();
865 if ( pluginName != "StdMeshers" )
866 aPmName = pluginName + "::" + aPmName;
867 aHypSO = publish( theHyp, aRootSO, 0, aPmName.c_str() );
870 SetName( aHypSO, theName, hypType.in() );
872 if(MYDEBUG) MESSAGE("PublishHypothesis--END")
873 return aHypSO._retn();
876 //=======================================================================
877 //function : UpdateIcons
878 //purpose : update icons of a mesh and its children upon mesh modification
879 //=======================================================================
881 void SMESH_Gen_i::UpdateIcons( SMESH::SMESH_Mesh_ptr theMesh )
883 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh );
887 SALOMEDS::SObject_wrap so = ObjectToSObject( theMesh );
891 // set icon of the mesh
892 if ( mesh_i->NbNodes() == 0 )
893 SetPixMap( so, "ICON_SMESH_TREE_MESH_WARN" );
894 else if ( mesh_i->IsComputedOK() )
895 SetPixMap( so, "ICON_SMESH_TREE_MESH" );
896 else if ( mesh_i->HasShapeToMesh() )
897 SetPixMap( so, "ICON_SMESH_TREE_MESH_PARTIAL" );
899 SetPixMap( so, "ICON_SMESH_TREE_MESH_IMPORTED" );
901 // set icons of sub-objects
902 SALOMEDS::Study_var study = getStudyServant();
903 SALOMEDS::ChildIterator_wrap iter = study->NewChildIterator( so );
904 for ( ; iter->More(); iter->Next() )
906 so = iter->Value(); // 1st level child - root of algos, hyps, sub-meshes or groups
907 if ( so->Tag() < SMESH::Tag_FirstSubMesh )
910 SALOMEDS::ChildIterator_wrap subIter = study->NewChildIterator( so );
911 for ( ; subIter->More(); subIter->Next() )
913 so = subIter->Value(); // 2nd level child - a sub-mesh or group
915 CORBA::Object_var obj = SObjectToObject( so );
916 SMESH::SMESH_IDSource_var idSrc = SMESH::SMESH_IDSource::_narrow( obj );
917 if ( idSrc->_is_nil() )
920 SMESH::SMESH_GroupBase_var grp = SMESH::SMESH_GroupBase::_narrow( obj );
921 SMESH::SMESH_GroupOnFilter_var gof = SMESH::SMESH_GroupOnFilter::_narrow( obj );
922 const bool isGroup = !grp->_is_nil();
923 const bool isGroupOnFilter = !gof->_is_nil();
925 bool isEmpty = ( mesh_i->NbNodes() == 0 );
928 if ( isGroupOnFilter ) // GetTypes() can be very long on GroupOnFilter!
930 SMESH::long_array_var nbByType = mesh_i->GetNbElementsByType();
931 isEmpty = ( nbByType[ grp->GetType() ] == 0 );
935 SMESH::array_of_ElementType_var elemTypes = idSrc->GetTypes();
936 isEmpty = ( elemTypes->length() == 0 );
940 SetPixMap( so, "ICON_SMESH_TREE_MESH_WARN");
942 SetPixMap( so, "ICON_SMESH_TREE_MESH" );
943 else if ( isGroupOnFilter )
944 SetPixMap( so, "ICON_SMESH_TREE_GROUP_ON_FILTER" );
946 SetPixMap( so, "ICON_SMESH_TREE_GROUP" );
951 //=======================================================================
952 //function : GetMeshOrSubmeshByShape
954 //=======================================================================
956 SALOMEDS::SObject_ptr
957 SMESH_Gen_i::GetMeshOrSubmeshByShape (SMESH::SMESH_Mesh_ptr theMesh,
958 GEOM::GEOM_Object_ptr theShape)
960 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
961 SALOMEDS::SObject_wrap aMeshOrSubMesh;
962 if (theMesh->_is_nil() || ( theShape->_is_nil() && theMesh->HasShapeToMesh()))
963 return aMeshOrSubMesh._retn();
966 if(theMesh->HasShapeToMesh())
967 aShape = GeomObjectToShape( theShape );
969 aShape = SMESH_Mesh::PseudoShape();
971 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
973 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
974 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
975 if ( aShape.IsSame( meshDS->ShapeToMesh() ))
976 aMeshOrSubMesh = ObjectToSObject( theMesh );
978 int shapeID = meshDS->ShapeToIndex( aShape );
979 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
980 if ( !aSubMesh->_is_nil() )
981 aMeshOrSubMesh = ObjectToSObject( aSubMesh );
984 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
985 return aMeshOrSubMesh._retn();
988 //=======================================================================
989 //function : AddHypothesisToShape
991 //=======================================================================
993 bool SMESH_Gen_i::AddHypothesisToShape(SMESH::SMESH_Mesh_ptr theMesh,
994 GEOM::GEOM_Object_ptr theShape,
995 SMESH::SMESH_Hypothesis_ptr theHyp)
997 if(MYDEBUG) MESSAGE("AddHypothesisToShape")
998 if (theMesh->_is_nil() ||
999 theHyp->_is_nil() || (theShape->_is_nil()
1000 && theMesh->HasShapeToMesh()) )
1003 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
1004 if ( aMeshSO->_is_nil() )
1005 aMeshSO = PublishMesh( theMesh );
1006 SALOMEDS::SObject_wrap aHypSO = PublishHypothesis( theHyp );
1007 if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
1010 // Find a mesh or submesh referring to theShape
1011 SALOMEDS::SObject_wrap aMeshOrSubMesh =
1012 GetMeshOrSubmeshByShape( theMesh, theShape );
1013 if ( aMeshOrSubMesh->_is_nil() )
1016 TopoDS_Shape aShape = GeomObjectToShape( theShape );
1017 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
1018 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
1019 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
1020 int shapeID = meshDS->ShapeToIndex( aShape );
1021 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
1022 aMeshOrSubMesh = PublishSubMesh( theMesh, aSubMesh, theShape );
1024 if ( aMeshOrSubMesh->_is_nil() )
1028 //Find or Create Applied Hypothesis root
1029 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
1030 SALOMEDS::SObject_wrap AHR =
1031 publish (CORBA::Object::_nil(), aMeshOrSubMesh,
1032 aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
1033 aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
1034 SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
1036 addReference( AHR, theHyp );
1038 if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
1042 //=======================================================================
1043 //function : RemoveHypothesisFromShape
1045 //=======================================================================
1047 bool SMESH_Gen_i::RemoveHypothesisFromShape(SMESH::SMESH_Mesh_ptr theMesh,
1048 GEOM::GEOM_Object_ptr theShape,
1049 SMESH::SMESH_Hypothesis_ptr theHyp)
1051 if (theMesh->_is_nil() ||
1052 theHyp->_is_nil() || (theShape->_is_nil()
1053 && theMesh->HasShapeToMesh()))
1056 SALOMEDS::SObject_wrap aHypSO = ObjectToSObject( theHyp );
1057 if ( aHypSO->_is_nil() )
1060 CORBA::String_var hypEntry = aHypSO->GetID();
1062 // Find a mesh or sub-mesh referring to theShape
1063 SALOMEDS::SObject_wrap aMeshOrSubMesh =
1064 GetMeshOrSubmeshByShape( theMesh, theShape );
1065 if ( aMeshOrSubMesh->_is_nil() )
1068 // Find and remove a reference to aHypSO
1069 SALOMEDS::SObject_wrap aRef, anObj;
1070 SALOMEDS::ChildIterator_wrap it = getStudyServant()->NewChildIterator( aMeshOrSubMesh );
1072 for ( it->InitEx( true ); ( it->More() && !found ); it->Next() ) {
1073 anObj = it->Value();
1074 if (anObj->ReferencedObject( aRef.inout() ))
1076 CORBA::String_var refEntry = aRef->GetID();
1077 found = ( strcmp( refEntry, hypEntry ) == 0 );
1081 SALOMEDS::StudyBuilder_var builder = getStudyServant()->NewBuilder();
1082 builder->RemoveObject( anObj );
1089 //================================================================================
1091 * \brief Stores names of variables that WILL be passes as parameters when calling
1092 * some method of a given object.
1093 * \param [in] theObject - the object whose a method WILL be called with \a theParameters.
1094 * \param [in] theParameters - a string containing parameters separated by ':'.
1096 //================================================================================
1098 void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters)
1100 // find variable names within theParameters
1103 myLastParameters.clear();
1104 myLastParamIndex.clear(); /* vector holding indices of virables within the string
1105 of all variables used for theObject */
1107 int pos = 0, prevPos = 0, len = strlen( theParameters );
1108 if ( len == 0 ) return;
1109 while ( pos <= len )
1111 if ( pos == len || theParameters[pos] == ':' )
1113 if ( prevPos < pos )
1115 string val( theParameters + prevPos, theParameters + pos );
1116 if ( !getStudyServant()->IsVariable( val.c_str() ))
1118 myLastParameters.push_back( val );
1119 nbVars += (! myLastParameters.back().empty() );
1123 myLastParameters.push_back("");
1134 // (1) variable names in the string of all variables used for theObject and
1135 // (2) indices of found variables in myLastParamIndex.
1137 // remember theObject
1138 SALOMEDS::SObject_wrap aSObj = ObjectToSObject(theObject);
1139 if ( aSObj->_is_nil() )
1141 CORBA::String_var anObjEntry = aSObj->GetID();
1142 myLastObj = anObjEntry.in();
1144 // get a string of variable names
1145 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
1146 SALOMEDS::GenericAttribute_wrap anAttr =
1147 aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString" );
1148 SALOMEDS::AttributeString_wrap aStringAttr = anAttr;
1149 CORBA::String_var oldVars = aStringAttr->Value();
1150 std::string varStr = oldVars.in();
1152 // add new variables and find indices of variables
1153 for ( size_t i = 0; i < myLastParameters.size(); ++i )
1156 if ( !myLastParameters[i].empty() )
1158 // find index of myLastParameters[i] in varStr
1160 bool varFound = false;
1162 // varStr can be "A|B::C;*=2|D"
1163 const std::string separators(":|;*=");
1164 while ( pos < varStr.size() && !varFound )
1167 while ( separators.find( varStr[ pos ]) != std::string::npos )
1168 if ( ++pos >= varStr.size() )
1170 // skip repetition number following '='
1171 if ( varStr[ pos-1 ] == '=' )
1173 while ( '0' <= varStr[ pos ] && varStr[ pos ] <= '9' )
1175 continue; // to skip next separator
1177 // compare variable name
1178 if ( pos < varStr.size() )
1180 varFound = ( varStr.compare( pos, myLastParameters[i].size(), myLastParameters[i] ) == 0 &&
1181 // same string beginning but is length same?
1182 ( pos + myLastParameters[i].size() >= varStr.size() ||
1183 separators.find( varStr[ pos+1 ]) != std::string::npos ));
1185 varIndex = curIndex;
1187 pos = varStr.find_first_of( separators, pos ); // goto the next separator
1194 varStr += ":" + myLastParameters[i];
1195 varIndex = curIndex;
1198 myLastParamIndex.push_back( varIndex );
1200 aStringAttr->SetValue( varStr.c_str() );
1203 //================================================================================
1205 * \brief Return all variables used to create an object
1206 * \param [in] theObjectEntry - an object entry in the current study
1207 * \return std::vector< std::string > - all variable names (or values of removed variables)
1209 //================================================================================
1211 std::vector< std::string > SMESH_Gen_i::GetAllParameters(const std::string& theObjectEntry) const
1213 std::vector< std::string > varNames;
1215 SALOMEDS::SObject_wrap aSObj = getStudyServant()->FindObjectID( theObjectEntry.c_str() );
1217 // get a string of variable names
1218 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
1219 SALOMEDS::GenericAttribute_wrap anAttr =
1220 aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString" );
1221 SALOMEDS::AttributeString_wrap aStringAttr = anAttr;
1222 CORBA::String_var oldVars = aStringAttr->Value();
1223 std::string varStr = oldVars.in();
1225 // separate variables within varStr;
1226 // varStr can be "A|B::C;*=2|D"
1228 const std::string separators(":|;*=");
1229 while ( pos < varStr.size() )
1232 pos = varStr.find_first_not_of( separators, pos );
1233 // while ( separators.find( varStr[ pos ]) != std::string::npos )
1234 // if ( ++pos >= varStr.size() )
1236 // skip repetition number following '='
1237 if ( varStr[ pos-1 ] == '=' )
1239 while ( '0' <= varStr[ pos ] && varStr[ pos ] <= '9' )
1241 continue; // to skip next separator
1243 // store variable name
1244 if ( pos < varStr.size() )
1246 size_t pos2 = varStr.find_first_of( separators, pos );
1247 varNames.push_back( varStr.substr( pos, pos2 - pos));
1254 //=======================================================================
1255 //function : ParseParameters
1256 //purpose : Replace variables by their values
1257 //=======================================================================
1258 // char* SMESH_Gen_i::ParseParameters(const char* theParameters)
1260 // //const char* aParameters = theParameters;
1261 // // const char* aParameters = CORBA::string_dup(theParameters);
1262 // TCollection_AsciiString anInputParams;
1263 // SALOMEDS::Study_var aStudy = getStudyServant();
1264 // if( !aStudy->_is_nil() ) {
1265 // // SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(theParameters);
1266 // // for(int j=0;j<aSections->length();j++) {
1267 // // SALOMEDS::ListOfStrings aVars= aSections[j];
1268 // // for(int i=0;i<aVars.length();i++ ) {
1269 // // anInputParams += aStudy->IsVariable(aVars[i].in()) ?
1270 // // TCollection_AsciiString(aVars[i].in()) : TCollection_AsciiString("");
1271 // // if(i != aVars.length()-1)
1272 // // anInputParams+=":";
1274 // // if(j!=aSections->length()-1)
1275 // // anInputParams+="|";
1277 // TCollection_AsciiString paramStr( theParameters );
1278 // int beg = 0, end;
1279 // char sep, *pParams = (char*)paramStr.ToCString();
1280 // while ( beg < paramStr.Length() )
1283 // while ( ++end < paramStr.Length() )
1284 // if ( pParams[end] == ':' || pParams[end] == '|')
1286 // if ( end < paramStr.Length())
1288 // sep = pParams[end];
1289 // pParams[end] = '\0';
1291 // if ( aStudy->IsVariable( pParams+beg ))
1292 // anInputParams += pParams+beg;
1293 // if ( end < paramStr.Length() )
1294 // anInputParams += sep;
1300 // return CORBA::string_dup(anInputParams.ToCString());
1303 //=======================================================================
1304 //function : GetParameters
1306 //=======================================================================
1308 char* SMESH_Gen_i::GetParameters(CORBA::Object_ptr theObject)
1310 CORBA::String_var aResult("");
1312 SALOMEDS::SObject_wrap aSObj = ObjectToSObject( theObject );
1313 if ( !aSObj->_is_nil() )
1315 SALOMEDS::GenericAttribute_wrap attr;
1316 if ( aSObj->FindAttribute( attr.inout(), "AttributeString"))
1318 SALOMEDS::AttributeString_wrap strAttr = attr;
1319 aResult = strAttr->Value();
1322 return aResult._retn();
1331 //=======================================================================
1332 //function : addObject
1333 //purpose : register object in the internal map and return its id
1334 //=======================================================================
1336 int StudyContext::addObject( const std::string& theIOR )
1338 int nextId = getNextId();
1339 mapIdToIOR.Bind( nextId, theIOR );
1343 //=======================================================================
1345 //purpose : find the object id in the internal map by the IOR
1346 //=======================================================================
1348 int StudyContext::findId( const std::string& theIOR )
1350 TInt2StringMap::iterator imap;
1351 for ( imap = mapIdToIOR.begin(); imap != mapIdToIOR.end(); ++imap ) {
1352 if ( *imap == theIOR )
1353 return imap.Iterator().Key();
1358 //=======================================================================
1359 //function : getIORbyId
1360 //purpose : get object's IOR by id
1361 //=======================================================================
1363 std::string StudyContext::getIORbyId( const int theId )
1365 if ( mapIdToIOR.IsBound( theId ) )
1366 return mapIdToIOR( theId );
1367 return std::string();
1370 //=======================================================================
1371 //function : getIORbyOldId
1372 //purpose : get object's IOR by old id
1373 //=======================================================================
1375 std::string StudyContext::getIORbyOldId( const int theOldId )
1377 if ( mapIdToId.IsBound( theOldId ) )
1378 return getIORbyId( mapIdToId( theOldId ));
1379 return std::string();
1382 //=======================================================================
1383 //function : mapOldToNew
1384 //purpose : maps old object id to the new one (used when restoring data)
1385 //=======================================================================
1387 void StudyContext::mapOldToNew( const int oldId, const int newId )
1389 mapIdToId.Bind( oldId, newId );
1392 //=======================================================================
1393 //function : getOldId
1394 //purpose : get old id by a new one
1395 //=======================================================================
1397 int StudyContext::getOldId( const int newId )
1399 TInt2IntMap::iterator imap;
1400 for ( imap = mapIdToId.begin(); imap != mapIdToId.end(); ++imap ) {
1401 if ( *imap == newId )
1402 return imap.Iterator().Key();
1407 //=======================================================================
1409 //purpose : clear data
1410 //=======================================================================
1412 void StudyContext::Clear()