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 std::string compDataType = ComponentDataType(); // SMESH module's data type
535 std::string ior = SMESH_Gen_i::GetORB()->object_to_string( SMESH_Gen::_this() ); // IOR of this SMESH engine
537 // Find study component which corresponds to this SMESH engine
539 SALOMEDS::SComponent_wrap father;
540 SALOMEDS::SComponentIterator_wrap citer = getStudyServant()->NewComponentIterator();
541 for ( ; citer->More(); citer->Next()) {
542 SALOMEDS::SComponent_wrap f_i = citer->Value();
543 CORBA::String_var ior_i;
544 bool ok = f_i->ComponentIOR(ior_i.out());
545 if ( ok && compDataType == f_i->ComponentDataType() && ior == ior_i.in()) {
551 if ( !CORBA::is_nil( father ) ) {
552 // check that the component is added to the use case browser
553 if ( !useCaseBuilder->IsUseCaseNode( father ) ) {
554 useCaseBuilder->SetRootCurrent();
555 useCaseBuilder->Append( father ); // component object is added as the top level item
557 return father._retn();
560 // If component for this SMESH engine does not exist in the study, create it
562 SALOME_ModuleCatalog::ModuleCatalog_var aCat =
563 SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
564 if ( CORBA::is_nil( aCat ) )
565 return father._retn();
567 SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( compDataType.c_str() );
568 if ( CORBA::is_nil( aComp ) )
569 return father._retn();
571 SALOMEDS::GenericAttribute_wrap anAttr;
572 SALOMEDS::AttributePixMap_wrap aPixmap;
574 father = aStudyBuilder->NewComponent( compDataType.c_str() );
575 aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
576 anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
578 aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
579 CORBA::String_var userName = aComp->componentusername();
580 SetName( father, userName.in(), "MESH" );
581 // add component to the use case tree
582 // (to support tree representation customization and drag-n-drop)
583 useCaseBuilder->SetRootCurrent();
584 useCaseBuilder->Append( father ); // component object is added as the top level item
585 if(MYDEBUG) MESSAGE("PublishComponent--END");
587 return father._retn();
590 //=======================================================================
591 //function : PublishMesh
593 //=======================================================================
595 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SMESH::SMESH_Mesh_ptr theMesh,
598 if ( !myIsEnablePublish )
599 return SALOMEDS::SObject::_nil();
600 if ( CORBA::is_nil( theMesh ))
601 return SALOMEDS::SObject::_nil();
602 if(MYDEBUG) MESSAGE("PublishMesh--IN");
604 // find or publish a mesh
606 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
607 if ( aMeshSO->_is_nil() )
609 SALOMEDS::SComponent_wrap father = PublishComponent();
610 if ( father->_is_nil() )
611 return aMeshSO._retn();
613 // Find correct free tag
614 long aTag = father->GetLastChildTag();
615 if ( aTag <= GetAlgorithmsRootTag() )
616 aTag = GetAlgorithmsRootTag() + 1;
620 aMeshSO = publish( theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
621 if ( aMeshSO->_is_nil() )
622 return aMeshSO._retn();
624 SetName( aMeshSO, theName, "Mesh" );
626 // Add shape reference
628 GEOM::GEOM_Object_var aShapeObject = theMesh->GetShapeToMesh();
629 if ( !CORBA::is_nil( aShapeObject )) {
630 addReference( aMeshSO, aShapeObject, GetRefOnShapeTag() );
632 // Publish global hypotheses
634 SMESH::ListOfHypothesis_var hypList = theMesh->GetHypothesisList( aShapeObject );
635 for ( CORBA::ULong i = 0; i < hypList->length(); i++ )
637 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( hypList[ i ]);
638 SALOMEDS::SObject_wrap so = PublishHypothesis( aHyp );
639 AddHypothesisToShape( theMesh, aShapeObject, aHyp );
645 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
647 return aMeshSO._retn();
648 map<int, SMESH_subMesh_i*>& subMap = mesh_i->_mapSubMesh_i;
649 map<int, SMESH_subMesh_i*>::iterator subIt = subMap.begin();
650 for ( ; subIt != subMap.end(); subIt++ ) {
651 SMESH::SMESH_subMesh_ptr aSubMesh = (*subIt).second->_this();
652 if ( !CORBA::is_nil( aSubMesh )) {
653 aShapeObject = aSubMesh->GetSubShape();
654 SALOMEDS::SObject_wrap( PublishSubMesh( theMesh, aSubMesh, aShapeObject ));
659 const map<int, SMESH::SMESH_GroupBase_ptr>& grMap = mesh_i->getGroups();
660 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = grMap.begin();
661 for ( ; it != grMap.end(); it++ )
663 SMESH::SMESH_GroupBase_ptr aGroup = (*it).second;
664 if ( !aGroup->_is_nil() ) {
665 GEOM::GEOM_Object_var aShapeObj;
666 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
667 if ( !aGeomGroup->_is_nil() )
668 aShapeObj = aGeomGroup->GetShape();
669 SALOMEDS::SObject_wrap( PublishGroup( theMesh, aGroup, aShapeObj ));
673 if(MYDEBUG) MESSAGE("PublishMesh_END");
674 return aMeshSO._retn();
677 //=======================================================================
678 //function : PublishSubMesh
680 //=======================================================================
682 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SMESH::SMESH_Mesh_ptr theMesh,
683 SMESH::SMESH_subMesh_ptr theSubMesh,
684 GEOM::GEOM_Object_ptr theShapeObject,
687 if ( !myIsEnablePublish )
688 return SALOMEDS::SObject::_nil();
689 if ( theMesh->_is_nil() || theSubMesh->_is_nil() || theShapeObject->_is_nil() )
690 return SALOMEDS::SObject::_nil();
692 SALOMEDS::SObject_wrap aSubMeshSO = ObjectToSObject( theSubMesh );
693 if ( aSubMeshSO->_is_nil() )
695 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
696 if ( aMeshSO->_is_nil() ) {
697 aMeshSO = PublishMesh( theMesh );
698 if ( aMeshSO->_is_nil())
699 return SALOMEDS::SObject::_nil();
701 // Find submesh sub-tree tag
703 const char* aRootName = "";
704 switch ( theShapeObject->GetShapeType() ) {
706 aRootTag = GetSubMeshOnVertexTag();
707 aRootName = "SubMeshes on Vertex";
710 aRootTag = GetSubMeshOnEdgeTag();
711 aRootName = "SubMeshes on Edge";
714 aRootTag = GetSubMeshOnWireTag();
715 aRootName = "SubMeshes on Wire";
718 aRootTag = GetSubMeshOnFaceTag();
719 aRootName = "SubMeshes on Face";
722 aRootTag = GetSubMeshOnShellTag();
723 aRootName = "SubMeshes on Shell";
726 aRootTag = GetSubMeshOnSolidTag();
727 aRootName = "SubMeshes on Solid";
730 aRootTag = GetSubMeshOnCompoundTag();
731 aRootName = "SubMeshes on Compound";
735 // Find or create submesh root
736 SALOMEDS::SObject_wrap aRootSO = publish ( CORBA::Object::_nil(),
737 aMeshSO, aRootTag, 0, false );
738 if ( aRootSO->_is_nil() )
739 return aSubMeshSO._retn();
741 SetName( aRootSO, aRootName );
743 // Add new submesh to corresponding sub-tree
744 SMESH::array_of_ElementType_var elemTypes = theSubMesh->GetTypes();
745 const int isEmpty = ( elemTypes->length() == 0 );
746 const char* pm[2] = { "ICON_SMESH_TREE_MESH", "ICON_SMESH_TREE_MESH_WARN" };
747 aSubMeshSO = publish ( theSubMesh, aRootSO, 0, pm[isEmpty] );
748 if ( aSubMeshSO->_is_nil() )
749 return aSubMeshSO._retn();
751 SetName( aSubMeshSO, theName, "SubMesh" );
753 // Add reference to theShapeObject
755 addReference( aSubMeshSO, theShapeObject, GetRefOnShapeTag() );
757 // Publish hypothesis
759 SMESH::ListOfHypothesis_var hypList = theMesh->GetHypothesisList( theShapeObject );
760 for ( CORBA::ULong i = 0; i < hypList->length(); i++ ) {
761 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( hypList[ i ]);
762 SALOMEDS::SObject_wrap so = PublishHypothesis( aHyp );
763 AddHypothesisToShape( theMesh, theShapeObject, aHyp );
766 return aSubMeshSO._retn();
769 //=======================================================================
770 //function : PublishGroup
772 //=======================================================================
774 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SMESH::SMESH_Mesh_ptr theMesh,
775 SMESH::SMESH_GroupBase_ptr theGroup,
776 GEOM::GEOM_Object_ptr theShapeObject,
779 if ( !myIsEnablePublish )
780 return SALOMEDS::SObject::_nil();
781 if (theMesh->_is_nil() || theGroup->_is_nil() )
782 return SALOMEDS::SObject::_nil();
784 SALOMEDS::SObject_wrap aGroupSO = ObjectToSObject( theGroup );
785 if ( aGroupSO->_is_nil() )
787 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
788 if ( aMeshSO->_is_nil() ) {
789 aMeshSO = PublishInStudy( SALOMEDS::SObject::_nil(), theMesh, "");
790 if ( aMeshSO->_is_nil())
791 return SALOMEDS::SObject::_nil();
793 size_t aType = (int)theGroup->GetType();
794 const char* aRootNames[] = {
795 "Compound Groups", "Groups of Nodes", "Groups of Edges",
796 "Groups of Faces", "Groups of Volumes", "Groups of 0D Elements",
799 // Currently, groups with heterogeneous content are not supported
800 if ( aType != SMESH::ALL )
802 long aRootTag = GetNodeGroupsTag() + aType - 1;
804 // Find or create groups root
805 SALOMEDS::SObject_wrap aRootSO = publish ( CORBA::Object::_nil(),
806 aMeshSO, aRootTag, 0, false );
807 if ( aRootSO->_is_nil() ) return SALOMEDS::SObject::_nil();
809 if ( aType < sizeof(aRootNames)/sizeof(char*) )
810 SetName( aRootSO, aRootNames[aType] );
812 // Add new group to corresponding sub-tree
814 std::string pm[2] = { "ICON_SMESH_TREE_GROUP", "ICON_SMESH_TREE_MESH_WARN" };
815 if ( SMESH::DownCast< SMESH_GroupOnFilter_i* > ( theGroup ))
817 pm[0] = "ICON_SMESH_TREE_GROUP_ON_FILTER";
819 else if ( SMESH::DownCast< SMESH_Group_i* > ( theGroup ))
821 if ( theGroup->GetType() == SMESH::NODE )
822 isEmpty = ( theMesh->NbNodes() == 0 );
825 SMESH::array_of_ElementType_var allElemTypes = theMesh->GetTypes();
826 for ( size_t i =0; i < allElemTypes->length() && isEmpty; ++i )
827 isEmpty = ( allElemTypes[i] != theGroup->GetType() );
830 aGroupSO = publish ( theGroup, aRootSO, 0, pm[isEmpty].c_str() );
832 if ( aGroupSO->_is_nil() )
833 return aGroupSO._retn();
836 SetName( aGroupSO, theName, "Group" );
838 //Add reference to geometry
839 if ( !theShapeObject->_is_nil() )
840 addReference( aGroupSO, theShapeObject, GetRefOnShapeTag() );
842 return aGroupSO._retn();
845 //=======================================================================
846 //function : PublishHypothesis
848 //=======================================================================
850 SALOMEDS::SObject_ptr
851 SMESH_Gen_i::PublishHypothesis (SMESH::SMESH_Hypothesis_ptr theHyp,
854 if(MYDEBUG) MESSAGE("PublishHypothesis")
855 if ( !myIsEnablePublish )
856 return SALOMEDS::SObject::_nil();
857 if (theHyp->_is_nil())
858 return SALOMEDS::SObject::_nil();
860 CORBA::String_var hypType = theHyp->GetName();
862 SALOMEDS::SObject_wrap aHypSO = ObjectToSObject( theHyp );
863 if ( aHypSO->_is_nil() )
865 SALOMEDS::SComponent_wrap father = PublishComponent();
866 if ( father->_is_nil() )
867 return aHypSO._retn();
869 //Find or Create Hypothesis root
870 bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
871 int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
872 SALOMEDS::SObject_wrap aRootSO =
873 publish (CORBA::Object::_nil(),father, aRootTag,
874 isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
875 SetName( aRootSO, isAlgo ? "Algorithms" : "Hypotheses" );
877 // Add New Hypothesis
878 string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
879 aPmName += hypType.in();
880 // prepend plugin name to pixmap name
881 string pluginName = myHypCreatorMap[ hypType.in() ]->GetModuleName();
882 if ( pluginName != "StdMeshers" )
883 aPmName = pluginName + "::" + aPmName;
884 aHypSO = publish( theHyp, aRootSO, 0, aPmName.c_str() );
887 SetName( aHypSO, theName, hypType.in() );
889 if(MYDEBUG) MESSAGE("PublishHypothesis--END")
890 return aHypSO._retn();
893 //=======================================================================
894 //function : UpdateIcons
895 //purpose : update icons of a mesh and its children upon mesh modification
896 //=======================================================================
898 void SMESH_Gen_i::UpdateIcons( SMESH::SMESH_Mesh_ptr theMesh )
900 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh );
904 SALOMEDS::SObject_wrap so = ObjectToSObject( theMesh );
908 // set icon of the mesh
909 if ( mesh_i->NbNodes() == 0 )
910 SetPixMap( so, "ICON_SMESH_TREE_MESH_WARN" );
911 else if ( mesh_i->IsComputedOK() )
912 SetPixMap( so, "ICON_SMESH_TREE_MESH" );
913 else if ( mesh_i->HasShapeToMesh() )
914 SetPixMap( so, "ICON_SMESH_TREE_MESH_PARTIAL" );
916 SetPixMap( so, "ICON_SMESH_TREE_MESH_IMPORTED" );
918 // set icons of sub-objects
919 SALOMEDS::Study_var study = getStudyServant();
920 SALOMEDS::ChildIterator_wrap iter = study->NewChildIterator( so );
921 for ( ; iter->More(); iter->Next() )
923 so = iter->Value(); // 1st level child - root of algos, hyps, sub-meshes or groups
924 if ( so->Tag() < SMESH::Tag_FirstSubMesh )
927 SALOMEDS::ChildIterator_wrap subIter = study->NewChildIterator( so );
928 for ( ; subIter->More(); subIter->Next() )
930 so = subIter->Value(); // 2nd level child - a sub-mesh or group
932 CORBA::Object_var obj = SObjectToObject( so );
933 SMESH::SMESH_IDSource_var idSrc = SMESH::SMESH_IDSource::_narrow( obj );
934 if ( idSrc->_is_nil() )
937 SMESH::SMESH_GroupBase_var grp = SMESH::SMESH_GroupBase::_narrow( obj );
938 SMESH::SMESH_GroupOnFilter_var gof = SMESH::SMESH_GroupOnFilter::_narrow( obj );
939 const bool isGroup = !grp->_is_nil();
940 const bool isGroupOnFilter = !gof->_is_nil();
942 bool isEmpty = ( mesh_i->NbNodes() == 0 );
945 if ( isGroupOnFilter ) // GetTypes() can be very long on GroupOnFilter!
947 SMESH::long_array_var nbByType = mesh_i->GetNbElementsByType();
948 isEmpty = ( nbByType[ grp->GetType() ] == 0 );
952 SMESH::array_of_ElementType_var elemTypes = idSrc->GetTypes();
953 isEmpty = ( elemTypes->length() == 0 );
957 SetPixMap( so, "ICON_SMESH_TREE_MESH_WARN");
959 SetPixMap( so, "ICON_SMESH_TREE_MESH" );
960 else if ( isGroupOnFilter )
961 SetPixMap( so, "ICON_SMESH_TREE_GROUP_ON_FILTER" );
963 SetPixMap( so, "ICON_SMESH_TREE_GROUP" );
968 //=======================================================================
969 //function : GetMeshOrSubmeshByShape
971 //=======================================================================
973 SALOMEDS::SObject_ptr
974 SMESH_Gen_i::GetMeshOrSubmeshByShape (SMESH::SMESH_Mesh_ptr theMesh,
975 GEOM::GEOM_Object_ptr theShape)
977 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
978 SALOMEDS::SObject_wrap aMeshOrSubMesh;
979 if (theMesh->_is_nil() || ( theShape->_is_nil() && theMesh->HasShapeToMesh()))
980 return aMeshOrSubMesh._retn();
983 if(theMesh->HasShapeToMesh())
984 aShape = GeomObjectToShape( theShape );
986 aShape = SMESH_Mesh::PseudoShape();
988 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
990 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
991 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
992 if ( aShape.IsSame( meshDS->ShapeToMesh() ))
993 aMeshOrSubMesh = ObjectToSObject( theMesh );
995 int shapeID = meshDS->ShapeToIndex( aShape );
996 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
997 if ( !aSubMesh->_is_nil() )
998 aMeshOrSubMesh = ObjectToSObject( aSubMesh );
1001 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
1002 return aMeshOrSubMesh._retn();
1005 //=======================================================================
1006 //function : AddHypothesisToShape
1008 //=======================================================================
1010 bool SMESH_Gen_i::AddHypothesisToShape(SMESH::SMESH_Mesh_ptr theMesh,
1011 GEOM::GEOM_Object_ptr theShape,
1012 SMESH::SMESH_Hypothesis_ptr theHyp)
1014 if(MYDEBUG) MESSAGE("AddHypothesisToShape")
1015 if (theMesh->_is_nil() ||
1016 theHyp->_is_nil() || (theShape->_is_nil()
1017 && theMesh->HasShapeToMesh()) )
1020 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
1021 if ( aMeshSO->_is_nil() )
1022 aMeshSO = PublishMesh( theMesh );
1023 SALOMEDS::SObject_wrap aHypSO = PublishHypothesis( theHyp );
1024 if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
1027 // Find a mesh or submesh referring to theShape
1028 SALOMEDS::SObject_wrap aMeshOrSubMesh =
1029 GetMeshOrSubmeshByShape( theMesh, theShape );
1030 if ( aMeshOrSubMesh->_is_nil() )
1033 TopoDS_Shape aShape = GeomObjectToShape( theShape );
1034 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
1035 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
1036 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
1037 int shapeID = meshDS->ShapeToIndex( aShape );
1038 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
1039 aMeshOrSubMesh = PublishSubMesh( theMesh, aSubMesh, theShape );
1041 if ( aMeshOrSubMesh->_is_nil() )
1045 //Find or Create Applied Hypothesis root
1046 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
1047 SALOMEDS::SObject_wrap AHR =
1048 publish (CORBA::Object::_nil(), aMeshOrSubMesh,
1049 aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
1050 aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
1051 SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
1053 addReference( AHR, theHyp );
1055 if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
1059 //=======================================================================
1060 //function : RemoveHypothesisFromShape
1062 //=======================================================================
1064 bool SMESH_Gen_i::RemoveHypothesisFromShape(SMESH::SMESH_Mesh_ptr theMesh,
1065 GEOM::GEOM_Object_ptr theShape,
1066 SMESH::SMESH_Hypothesis_ptr theHyp)
1068 if (theMesh->_is_nil() ||
1069 theHyp->_is_nil() || (theShape->_is_nil()
1070 && theMesh->HasShapeToMesh()))
1073 SALOMEDS::SObject_wrap aHypSO = ObjectToSObject( theHyp );
1074 if ( aHypSO->_is_nil() )
1077 CORBA::String_var hypEntry = aHypSO->GetID();
1079 // Find a mesh or sub-mesh referring to theShape
1080 SALOMEDS::SObject_wrap aMeshOrSubMesh =
1081 GetMeshOrSubmeshByShape( theMesh, theShape );
1082 if ( aMeshOrSubMesh->_is_nil() )
1085 // Find and remove a reference to aHypSO
1086 SALOMEDS::SObject_wrap aRef, anObj;
1087 SALOMEDS::ChildIterator_wrap it = getStudyServant()->NewChildIterator( aMeshOrSubMesh );
1089 for ( it->InitEx( true ); ( it->More() && !found ); it->Next() ) {
1090 anObj = it->Value();
1091 if (anObj->ReferencedObject( aRef.inout() ))
1093 CORBA::String_var refEntry = aRef->GetID();
1094 found = ( strcmp( refEntry, hypEntry ) == 0 );
1098 SALOMEDS::StudyBuilder_var builder = getStudyServant()->NewBuilder();
1099 builder->RemoveObject( anObj );
1106 //================================================================================
1108 * \brief Stores names of variables that WILL be passes as parameters when calling
1109 * some method of a given object.
1110 * \param [in] theObject - the object whose a method WILL be called with \a theParameters.
1111 * \param [in] theParameters - a string containing parameters separated by ':'.
1113 //================================================================================
1115 void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters)
1117 // find variable names within theParameters
1120 myLastParameters.clear();
1121 myLastParamIndex.clear(); /* vector holding indices of virables within the string
1122 of all variables used for theObject */
1124 int pos = 0, prevPos = 0, len = strlen( theParameters );
1125 if ( len == 0 ) return;
1126 while ( pos <= len )
1128 if ( pos == len || theParameters[pos] == ':' )
1130 if ( prevPos < pos )
1132 string val( theParameters + prevPos, theParameters + pos );
1133 if ( !getStudyServant()->IsVariable( val.c_str() ))
1135 myLastParameters.push_back( val );
1136 nbVars += (! myLastParameters.back().empty() );
1140 myLastParameters.push_back("");
1151 // (1) variable names in the string of all variables used for theObject and
1152 // (2) indices of found variables in myLastParamIndex.
1154 // remember theObject
1155 SALOMEDS::SObject_wrap aSObj = ObjectToSObject(theObject);
1156 if ( aSObj->_is_nil() )
1158 CORBA::String_var anObjEntry = aSObj->GetID();
1159 myLastObj = anObjEntry.in();
1161 // get a string of variable names
1162 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
1163 SALOMEDS::GenericAttribute_wrap anAttr =
1164 aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString" );
1165 SALOMEDS::AttributeString_wrap aStringAttr = anAttr;
1166 CORBA::String_var oldVars = aStringAttr->Value();
1167 std::string varStr = oldVars.in();
1169 // add new variables and find indices of variables
1170 for ( size_t i = 0; i < myLastParameters.size(); ++i )
1173 if ( !myLastParameters[i].empty() )
1175 // find index of myLastParameters[i] in varStr
1177 bool varFound = false;
1179 // varStr can be "A|B::C;*=2|D"
1180 const std::string separators(":|;*=");
1181 while ( pos < varStr.size() && !varFound )
1184 while ( separators.find( varStr[ pos ]) != std::string::npos )
1185 if ( ++pos >= varStr.size() )
1187 // skip repetition number following '='
1188 if ( varStr[ pos-1 ] == '=' )
1190 while ( '0' <= varStr[ pos ] && varStr[ pos ] <= '9' )
1192 continue; // to skip next separator
1194 // compare variable name
1195 if ( pos < varStr.size() )
1197 varFound = ( varStr.compare( pos, myLastParameters[i].size(), myLastParameters[i] ) == 0 &&
1198 // same string beginning but is length same?
1199 ( pos + myLastParameters[i].size() >= varStr.size() ||
1200 separators.find( varStr[ pos+1 ]) != std::string::npos ));
1202 varIndex = curIndex;
1204 pos = varStr.find_first_of( separators, pos ); // goto the next separator
1211 varStr += ":" + myLastParameters[i];
1212 varIndex = curIndex;
1215 myLastParamIndex.push_back( varIndex );
1217 aStringAttr->SetValue( varStr.c_str() );
1220 //================================================================================
1222 * \brief Return all variables used to create an object
1223 * \param [in] theObjectEntry - an object entry in the current study
1224 * \return std::vector< std::string > - all variable names (or values of removed variables)
1226 //================================================================================
1228 std::vector< std::string > SMESH_Gen_i::GetAllParameters(const std::string& theObjectEntry) const
1230 std::vector< std::string > varNames;
1232 SALOMEDS::SObject_wrap aSObj = getStudyServant()->FindObjectID( theObjectEntry.c_str() );
1234 // get a string of variable names
1235 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
1236 SALOMEDS::GenericAttribute_wrap anAttr =
1237 aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString" );
1238 SALOMEDS::AttributeString_wrap aStringAttr = anAttr;
1239 CORBA::String_var oldVars = aStringAttr->Value();
1240 std::string varStr = oldVars.in();
1242 // separate variables within varStr;
1243 // varStr can be "A|B::C;*=2|D"
1245 const std::string separators(":|;*=");
1246 while ( pos < varStr.size() )
1249 pos = varStr.find_first_not_of( separators, pos );
1250 // while ( separators.find( varStr[ pos ]) != std::string::npos )
1251 // if ( ++pos >= varStr.size() )
1253 // skip repetition number following '='
1254 if ( varStr[ pos-1 ] == '=' )
1256 while ( '0' <= varStr[ pos ] && varStr[ pos ] <= '9' )
1258 continue; // to skip next separator
1260 // store variable name
1261 if ( pos < varStr.size() )
1263 size_t pos2 = varStr.find_first_of( separators, pos );
1264 varNames.push_back( varStr.substr( pos, pos2 - pos));
1271 //=======================================================================
1272 //function : ParseParameters
1273 //purpose : Replace variables by their values
1274 //=======================================================================
1275 // char* SMESH_Gen_i::ParseParameters(const char* theParameters)
1277 // //const char* aParameters = theParameters;
1278 // // const char* aParameters = CORBA::string_dup(theParameters);
1279 // TCollection_AsciiString anInputParams;
1280 // SALOMEDS::Study_var aStudy = getStudyServant();
1281 // if( !aStudy->_is_nil() ) {
1282 // // SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(theParameters);
1283 // // for(int j=0;j<aSections->length();j++) {
1284 // // SALOMEDS::ListOfStrings aVars= aSections[j];
1285 // // for(int i=0;i<aVars.length();i++ ) {
1286 // // anInputParams += aStudy->IsVariable(aVars[i].in()) ?
1287 // // TCollection_AsciiString(aVars[i].in()) : TCollection_AsciiString("");
1288 // // if(i != aVars.length()-1)
1289 // // anInputParams+=":";
1291 // // if(j!=aSections->length()-1)
1292 // // anInputParams+="|";
1294 // TCollection_AsciiString paramStr( theParameters );
1295 // int beg = 0, end;
1296 // char sep, *pParams = (char*)paramStr.ToCString();
1297 // while ( beg < paramStr.Length() )
1300 // while ( ++end < paramStr.Length() )
1301 // if ( pParams[end] == ':' || pParams[end] == '|')
1303 // if ( end < paramStr.Length())
1305 // sep = pParams[end];
1306 // pParams[end] = '\0';
1308 // if ( aStudy->IsVariable( pParams+beg ))
1309 // anInputParams += pParams+beg;
1310 // if ( end < paramStr.Length() )
1311 // anInputParams += sep;
1317 // return CORBA::string_dup(anInputParams.ToCString());
1320 //=======================================================================
1321 //function : GetParameters
1323 //=======================================================================
1325 char* SMESH_Gen_i::GetParameters(CORBA::Object_ptr theObject)
1327 CORBA::String_var aResult("");
1329 SALOMEDS::SObject_wrap aSObj = ObjectToSObject( theObject );
1330 if ( !aSObj->_is_nil() )
1332 SALOMEDS::GenericAttribute_wrap attr;
1333 if ( aSObj->FindAttribute( attr.inout(), "AttributeString"))
1335 SALOMEDS::AttributeString_wrap strAttr = attr;
1336 aResult = strAttr->Value();
1339 return aResult._retn();
1348 //=======================================================================
1349 //function : addObject
1350 //purpose : register object in the internal map and return its id
1351 //=======================================================================
1353 int StudyContext::addObject( const std::string& theIOR )
1355 int nextId = getNextId();
1356 mapIdToIOR.Bind( nextId, theIOR );
1360 //=======================================================================
1362 //purpose : find the object id in the internal map by the IOR
1363 //=======================================================================
1365 int StudyContext::findId( const std::string& theIOR )
1367 TInt2StringMap::iterator imap;
1368 for ( imap = mapIdToIOR.begin(); imap != mapIdToIOR.end(); ++imap ) {
1369 if ( *imap == theIOR )
1370 return imap.Iterator().Key();
1375 //=======================================================================
1376 //function : getIORbyId
1377 //purpose : get object's IOR by id
1378 //=======================================================================
1380 std::string StudyContext::getIORbyId( const int theId )
1382 if ( mapIdToIOR.IsBound( theId ) )
1383 return mapIdToIOR( theId );
1384 return std::string();
1387 //=======================================================================
1388 //function : getIORbyOldId
1389 //purpose : get object's IOR by old id
1390 //=======================================================================
1392 std::string StudyContext::getIORbyOldId( const int theOldId )
1394 if ( mapIdToId.IsBound( theOldId ) )
1395 return getIORbyId( mapIdToId( theOldId ));
1396 return std::string();
1399 //=======================================================================
1400 //function : mapOldToNew
1401 //purpose : maps old object id to the new one (used when restoring data)
1402 //=======================================================================
1404 void StudyContext::mapOldToNew( const int oldId, const int newId )
1406 mapIdToId.Bind( oldId, newId );
1409 //=======================================================================
1410 //function : getOldId
1411 //purpose : get old id by a new one
1412 //=======================================================================
1414 int StudyContext::getOldId( const int newId )
1416 TInt2IntMap::iterator imap;
1417 for ( imap = mapIdToId.begin(); imap != mapIdToId.end(); ++imap ) {
1418 if ( *imap == newId )
1419 return imap.Iterator().Key();
1424 //=======================================================================
1426 //purpose : clear data
1427 //=======================================================================
1429 void StudyContext::Clear()